]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
proc: Avoid mixing integer types in mem_rw()
authorMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Wed, 2 Jun 2021 03:53:07 +0000 (13:53 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 2 Jun 2021 03:53:07 +0000 (13:53 +1000)
Use size_t when capping the count argument received by mem_rw(). Since
count is size_t, using min_t(int, ...) can lead to a negative value
that will later be passed to access_remote_vm(), which can cause
unexpected behavior.

Since we are capping the value to at maximum PAGE_SIZE, the conversion
from size_t to int when passing it to access_remote_vm() as "len"
shouldn't be a problem.

Link: https://lkml.kernel.org/r/20210512125215.3348316-1-marcelo.cerri@canonical.com
Reviewed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Souza Cascardo <cascardo@canonical.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
fs/proc/base.c

index 58bbf334265b733f23f3d652931ef8b0e30fc2cb..6859b578d14f4bf83d19b28c2c1d7681f5954a88 100644 (file)
@@ -854,7 +854,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
        flags = FOLL_FORCE | (write ? FOLL_WRITE : 0);
 
        while (count > 0) {
-               int this_len = min_t(int, count, PAGE_SIZE);
+               size_t this_len = min_t(size_t, count, PAGE_SIZE);
 
                if (write && copy_from_user(page, buf, this_len)) {
                        copied = -EFAULT;