From: Dan Carpenter Date: Tue, 25 Jul 2023 17:03:16 +0000 (+0300) Subject: proc/vmcore: fix signedness bug in read_from_oldmem() X-Git-Tag: v6.6.7~2275^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=641db40f3afe7998011bfabc726dba3e698f8196;p=platform%2Fkernel%2Flinux-starfive.git proc/vmcore: fix signedness bug in read_from_oldmem() The bug is the error handling: if (tmp < nr_bytes) { "tmp" can hold negative error codes but because "nr_bytes" is type size_t the negative error codes are treated as very high positive values (success). Fix this by changing "nr_bytes" to type ssize_t. The "nr_bytes" variable is used to store values between 1 and PAGE_SIZE and they can fit in ssize_t without any issue. Link: https://lkml.kernel.org/r/b55f7eed-1c65-4adc-95d1-6c7c65a54a6e@moroto.mountain Fixes: 5d8de293c224 ("vmcore: convert copy_oldmem_page() to take an iov_iter") Signed-off-by: Dan Carpenter Reviewed-by: Matthew Wilcox (Oracle) Acked-by: Baoquan He Cc: Dave Young Cc: Vivek Goyal Cc: Alexey Dobriyan Cc: Signed-off-by: Andrew Morton --- diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index cb80a77..1fb213f 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -132,7 +132,7 @@ ssize_t read_from_oldmem(struct iov_iter *iter, size_t count, u64 *ppos, bool encrypted) { unsigned long pfn, offset; - size_t nr_bytes; + ssize_t nr_bytes; ssize_t read = 0, tmp; int idx;