Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3711977pxv; Mon, 26 Jul 2021 10:01:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzctvqYkpf8igydapNZZgzjOTw1bXpiiHlHEiiflp/p6wVliEVC/bW4qCOZwrUfVATaEkyX X-Received: by 2002:a17:906:af7c:: with SMTP id os28mr18127129ejb.341.1627318871708; Mon, 26 Jul 2021 10:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318871; cv=none; d=google.com; s=arc-20160816; b=KYRS7tzQTZ5JRJRl5D937IDw5C363lhrX3YT8SnFLvrbdGNMiltf26n+KXpeFxze9b IaBt2pzPpfeDR4Q9eBgaSRYk+hZ0mRFgzsfMot7vQuVHSW429iM615Q1J9m/wPJ+6cmA U0Vi7tTEVLr5xKZU1uc60ogqOQbqOLRmw5ijobe6hAtop8xCaPHGOFTCteIAke8ugB7/ nQd1OwtOEvw0W0qWAVMrJ+Q1YmDcs/nonmfZX+2mE9du10D39Gu59ETRqtR6F9Ixpnzt l3NRbjoU0Dl2RkAUQ+or8O2ALuGv7MImPA5ic8YjB47NRSNICD/vCG8MOI3swHZDcZ0g Yd7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6ytSb/IJthQmB95tgt7VN16fBV7zD6PNS3tlvf2fxGw=; b=dhHHEoIc+m+d4oIYkEwnlNvEugiTLxQp7XX4EKzqTkbt3DFP9RtgiLGwmoDAgqoVU8 dCH0sAXM0cFPbIjXUuePSZdzEsTsOiTKxigwEAi72x54DqmfHIiQAstkM/vq7u62tofX juce7CTD6tDAD5IOpMrh+nMlEaYxxOsw/tguT6wtU/41uketlKWtk9d/087RJ7Yazczv 6LEBILHR993/z1c0DzC/09zuCAUIkLDFlBT125rU190TBZgvBqNqUuE4QRZmCipm+4Z4 JcwREjieFExG2Y1wO46TuFb6alUVhDI1uhaI8yqezg2jDvRQN5GCLYDYrfyCyEsxQex4 JiFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y17YcLJ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc15si481431edb.281.2021.07.26.10.00.46; Mon, 26 Jul 2021 10:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y17YcLJ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235610AbhGZPeL (ORCPT + 99 others); Mon, 26 Jul 2021 11:34:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:60114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236628AbhGZPTK (ORCPT ); Mon, 26 Jul 2021 11:19:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 53FD460F90; Mon, 26 Jul 2021 15:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315178; bh=8P7AE3po74BQD2rAm8tguHt+UpMWiyZEXNSoOJjiipk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y17YcLJ5pz/tGJ+/o1T6qqIFxvSbbd+pIVD2K2d75184AsuBV32S61BkD2Dv6LsH2 30CRza4GbDrErp6TDB5tTa86jLKbTnrLUIoz1ZxYnMCP4BCyXUXZd5WMhCvTqvT02o TQD//v8RVMmy7kdbXqKpVBmMZsIQYSSyTU2JXlQg= 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.4 068/108] proc: Avoid mixing integer types in mem_rw() Date: Mon, 26 Jul 2021 17:39:09 +0200 Message-Id: <20210726153833.875008890@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 75e786684a4e..90d2f62a9672 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -836,7 +836,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.30.2