Blob Blame History Raw
From 96c0a9035a0513a9e60c7a6b42e1f9c7b15bbbf6 Mon Sep 17 00:00:00 2001
From: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Date: Tue, 4 May 2021 14:46:27 -0300
Subject: [PATCH] proc: Avoid mixing integer types in mem_rw()
Patch-mainline: Submitted, embargo ended 20210511 17:00 UTC.
References: CVE-2021-3491 bsc#1185642

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.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Reviewed-by: David Disseldorp <ddiss@suse.de>
---
 fs/proc/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 4cf48f248464..1f61f1baf201 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -837,7 +837,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;
-- 
2.26.2