# \[patch 140/192\] proc: Avoid mixing integer types in mem\_rw()

- From: Andrew Morton \<akpm@linux-foundation.org\>
- Date: 2021-07-01 01:55:42 
- List: linux-mm
- Page: https://ratatoskr.run/linux-mm/2021/07/6509551
- Thread: https://ratatoskr.run/linux-mm/2021/07/6509393/t/3.md

```text
From: Marcelo Henrique Cerri <redacted>
Subject: proc: Avoid mixing integer types in mem_rw()

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 <redacted>
Signed-off-by: Thadeu Lima de Souza Cascardo <redacted>
Signed-off-by: Marcelo Henrique Cerri <redacted>
Cc: Alexey Dobriyan <redacted>
Cc: Souza Cascardo <redacted>
Cc: Christian Brauner <redacted>
Cc: Michel Lespinasse <redacted>
Cc: Helge Deller <deller@gmx.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Lorenzo Stoakes <redacted>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/proc/base.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/fs/proc/base.c~proc-avoid-mixing-integer-types-in-mem_rw
+++ a/fs/proc/base.c
@@ -854,7 +854,7 @@ static ssize_t mem_rw(struct file *file,
 	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;
_

```
