From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 ADFA0C433E0 for ; Wed, 27 Jan 2021 23:19:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4900E61601 for ; Wed, 27 Jan 2021 23:19:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4900E61601 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 560086B0005; Wed, 27 Jan 2021 18:19:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 50F736B0006; Wed, 27 Jan 2021 18:19:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DB1B6B006E; Wed, 27 Jan 2021 18:19:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id ECB596B0005 for ; Wed, 27 Jan 2021 18:19:43 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id ACC068249980 for ; Wed, 27 Jan 2021 23:19:43 +0000 (UTC) X-FDA: 77753124246.28.flesh02_0503df32759a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 90FA26C2D for ; Wed, 27 Jan 2021 23:19:43 +0000 (UTC) X-HE-Tag: flesh02_0503df32759a X-Filterd-Recvd-Size: 3522 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 23:19:43 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DD53B60C41; Wed, 27 Jan 2021 23:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1611789582; bh=MBrLoGb88NS5OcLieayErbUmd6TwC1y0JD7oMRoguBw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pN5gNmsEhEeAa61Ly8h6jPB7PsHQDJkVxIU5+pqh5y+o33YrMmkMTYNQjSju2Uh6z 121NBVWux1fJxQL9DjAx1UpiSnqbawQLNvPt08uZ3RnmAJ/iZGoU0my6bXM4kBFuQX bijbX5ljD7tKzu6FYU/WpDQJ6aMZoznzP4wKXrHI= Date: Wed, 27 Jan 2021 15:19:40 -0800 From: Andrew Morton To: Tetsuo Handa Cc: Michal Hocko , linux-mm@kvack.org, Sabyrzhan Tasbolatov , Casey Schaufler Subject: Re: [PATCH v3] mm: memdup_user*() should use same gfp flags Message-Id: <20210127151940.a9fbbafb890fc769da1525ea@linux-foundation.org> In-Reply-To: <3e01b180-0a5b-f2aa-6247-1c3bbcabe1ed@i-love.sakura.ne.jp> References: <20210126111315.858994-1-snovitoll@gmail.com> <20210127105538.4919-1-penguin-kernel@I-love.SAKURA.ne.jp> <3e01b180-0a5b-f2aa-6247-1c3bbcabe1ed@i-love.sakura.ne.jp> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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: On Wed, 27 Jan 2021 23:03:33 +0900 Tetsuo Handa wrote: > On 2021/01/27 21:17, Michal Hocko wrote: > > On Wed 27-01-21 12:59:28, Michal Hocko wrote: > >> On Wed 27-01-21 19:55:38, Tetsuo Handa wrote: > >>> syzbot is reporting that memdup_user_nul() which receives user-controlled > >>> size (which can be up to (INT_MAX & PAGE_MASK)) via vfs_write() will hit > >>> order >= MAX_ORDER path [1]. > >>> > >>> Making costly allocations (order > PAGE_ALLOC_COSTLY_ORDER) naturally fail > >>> should be better than trying to enforce PAGE_SIZE upper limit, for some of > >>> callers accept space-delimited list arguments. > >>> > >>> Therefore, let's add __GFP_NOWARN to memdup_user_nul() as with > >>> commit 6c8fcc096be9d02f ("mm: don't let userspace spam allocations > >>> warnings"). Also use GFP_USER as with other userspace-controllable > >>> allocations like memdup_user(). > >> > >> I absolutely detest hiding this behind __GFP_NOWARN. There should be no > >> reason to even try hard for memdup_user_nul. Can you explain why this > > > > this should have been "try hard to get a physicaly contiguous memory for memdup_user_nul" > > > >> cannot use kvmalloc instead? > > > > There is no point with allowing userspace to allocate 2GB of physically non-contiguous > memory using kvmalloc(). Size is controlled by userspace, and memdup_user_nul() is used > for allocating temporary memory which will be released before returning to userspace. > > Sane userspace processes should allocate only one or a few pages using memdup_user_nul(). > Just making insane user processes (like fuzzer) fail memory allocation requests is a > reasonable decision. (cc Casey) I'd say that the immediate problem is in smk_write_syslog(). Obviously it was implemented expecting small writes, but the fuzzer is passing it a huge write and things fall apart.