From patchwork Mon Jul 26 15:38:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 486378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4954CC432BE for ; Mon, 26 Jul 2021 16:08:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34E5E60F94 for ; Mon, 26 Jul 2021 16:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbhGZP2S (ORCPT ); Mon, 26 Jul 2021 11:28:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:41244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237820AbhGZPZs (ORCPT ); Mon, 26 Jul 2021 11:25:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8396F60C41; Mon, 26 Jul 2021 16:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315576; bh=wf1OluGBlGsXEEba9/0Ca9aRMkh363c7DOZPWAQGin0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NoBAxQaZKiKJbWg62hm0cyIjsjItPDGAman8lQmZ3qJi61Ic32TpxdeAe65xWzhC+ D4qmOYDVR5MSwcsiL7TZA0LWIWpq+IfR+Jn5zyxPh663J9zbAYU80alx51dIyvmbiS 2cK2Jn+YkU66ggybQTo96MY6cFFP+PCQMgdBEymA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Disseldorp , Thadeu Lima de Souza Cascardo , Marcelo Henrique Cerri , Alexey Dobriyan , Christian Brauner , Michel Lespinasse , Helge Deller , Oleg Nesterov , Lorenzo Stoakes , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 105/167] proc: Avoid mixing integer types in mem_rw() Date: Mon, 26 Jul 2021 17:38:58 +0200 Message-Id: <20210726153842.924190553@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Marcelo Henrique Cerri [ Upstream commit d238692b4b9f2c36e35af4c6e6f6da36184aeb3e ] 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 Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Marcelo Henrique Cerri Cc: Alexey Dobriyan Cc: Souza Cascardo Cc: Christian Brauner Cc: Michel Lespinasse Cc: Helge Deller Cc: Oleg Nesterov Cc: Lorenzo Stoakes Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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 df9b17dd92cb..5d52aea8d7e7 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -855,7 +855,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;