From patchwork Thu Jul 1 01:54:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12353375 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=-15.8 required=3.0 tests=BAYES_00,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_RED autolearn=ham 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 142ADC11F66 for ; Thu, 1 Jul 2021 01:55:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BBAA06141A for ; Thu, 1 Jul 2021 01:55:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBAA06141A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D67D38D026A; Wed, 30 Jun 2021 21:55:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7B998D024F; Wed, 30 Jun 2021 21:55:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA6818D026A; Wed, 30 Jun 2021 21:55:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 704978D024F for ; Wed, 30 Jun 2021 21:55:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 40B4A181AF5CA for ; Thu, 1 Jul 2021 01:55:40 +0000 (UTC) X-FDA: 78312352440.25.42F2C29 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf30.hostedemail.com (Postfix) with ESMTP id E2EC1E00304F for ; Thu, 1 Jul 2021 01:54:39 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DF7EB61418; Thu, 1 Jul 2021 01:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1625104479; bh=fRvBNWulQUko4aPaQqRgmopGLIhUL/UCkKdhIKskUfc=; h=Date:From:To:Subject:In-Reply-To:From; b=blizlUI6AJeKi8buonZMv6YsGoqH6P/ttq+yyg1qw9H1itlzVXRvFXxCf/wzvBQSF 4bpNWA2CaD5oPBmTf9bsThQePY+g/djfoZt2dxXMmhoQqGK9Yol0Oh8yhuiH2u7185 0e6ev8Nc2X9Ei6/zsCNifQ8aUxYGemvM3JJD9H2I= Date: Wed, 30 Jun 2021 18:54:38 -0700 From: Andrew Morton To: adobriyan@gmail.com, akpm@linux-foundation.org, cascardo@canonical.com, christian.brauner@ubuntu.com, ddiss@suse.de, deller@gmx.de, linux-mm@kvack.org, lstoakes@gmail.com, marcelo.cerri@canonical.com, mm-commits@vger.kernel.org, oleg@redhat.com, torvalds@linux-foundation.org, walken@google.com Subject: [patch 140/192] proc: Avoid mixing integer types in mem_rw() Message-ID: <20210701015438.0zNDxEvkA%akpm@linux-foundation.org> In-Reply-To: <20210630184624.9ca1937310b0dd5ce66b30e7@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E2EC1E00304F Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=blizlUI6; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Stat-Signature: k83ohr9hr4tq636k8wsfgmi51zwr5uyr X-HE-Tag: 1625104479-323729 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Marcelo Henrique Cerri 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 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 --- 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;