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=-15.7 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_BLOCKED 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 8E8EFC433E0 for ; Wed, 27 Jan 2021 11:59:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EED7620770 for ; Wed, 27 Jan 2021 11:59:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EED7620770 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2FF2F6B0007; Wed, 27 Jan 2021 06:59:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 289156B0008; Wed, 27 Jan 2021 06:59:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12B486B000A; Wed, 27 Jan 2021 06:59:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id EDC1D6B0007 for ; Wed, 27 Jan 2021 06:59:29 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B251A8249980 for ; Wed, 27 Jan 2021 11:59:29 +0000 (UTC) X-FDA: 77751410058.02.leg86_1a03ecc27596 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 940CB10097AA0 for ; Wed, 27 Jan 2021 11:59:29 +0000 (UTC) X-HE-Tag: leg86_1a03ecc27596 X-Filterd-Recvd-Size: 3332 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 11:59:29 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611748768; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xCPh9I/5DSXSJTIT3Fu5DPGkUfjGwx7qPDSoY6crpeo=; b=eSuhSsMWWqS5s9YiEft86+ReX4BLWsNKFUqSdN7gg/l6S8kvv66bpiSIoc1nv4DvUNg5r/ eoSgJpTQUYlKTykrHUJWvmgvQ6Nf/a2WFIo5rTx1RLACjWCxR00xYJ0dzVZw1qpjb1Ibu7 1j9+0Sn9dbl/a6v2qQnczUQv8QAn4zI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EF403AC9B; Wed, 27 Jan 2021 11:59:27 +0000 (UTC) Date: Wed, 27 Jan 2021 12:59:26 +0100 From: Michal Hocko To: Tetsuo Handa Cc: Andrew Morton , linux-mm@kvack.org, Sabyrzhan Tasbolatov Subject: Re: [PATCH v3] mm: memdup_user*() should use same gfp flags Message-ID: References: <20210126111315.858994-1-snovitoll@gmail.com> <20210127105538.4919-1-penguin-kernel@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210127105538.4919-1-penguin-kernel@I-love.SAKURA.ne.jp> 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-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 cannot use kvmalloc instead? > [1] https://syzkaller.appspot.com/bug?id=8bf7efb3db19101b4008dc9198522ef977d098a6 > > Reported-by: syzbot > Signed-off-by: Tetsuo Handa > --- > mm/util.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/mm/util.c b/mm/util.c > index 8c9b7d1e7c49..265b40a86856 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -252,12 +252,7 @@ void *memdup_user_nul(const void __user *src, size_t len) > { > char *p; > > - /* > - * Always use GFP_KERNEL, since copy_from_user() can sleep and > - * cause pagefault, which makes it pointless to use GFP_NOFS > - * or GFP_ATOMIC. > - */ > - p = kmalloc_track_caller(len + 1, GFP_KERNEL); > + p = kmalloc_track_caller(len + 1, GFP_USER | __GFP_NOWARN); > if (!p) > return ERR_PTR(-ENOMEM); > > -- > 2.18.4 > -- Michal Hocko SUSE Labs