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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 E50FCC433E0 for ; Thu, 28 Jan 2021 08:19:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 52EB16146D for ; Thu, 28 Jan 2021 08:19:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52EB16146D 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 339326B0070; Thu, 28 Jan 2021 03:19:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EB1E6B0071; Thu, 28 Jan 2021 03:19:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D9796B0072; Thu, 28 Jan 2021 03:19:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id F28D86B0070 for ; Thu, 28 Jan 2021 03:19:43 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B34543638 for ; Thu, 28 Jan 2021 08:19:43 +0000 (UTC) X-FDA: 77754485046.11.plane40_1713c772759e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 92920180F8B81 for ; Thu, 28 Jan 2021 08:19:43 +0000 (UTC) X-HE-Tag: plane40_1713c772759e X-Filterd-Recvd-Size: 4596 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 Jan 2021 08:19:42 +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=1611821981; 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=2KD+fMrZPztbHYdkD13DQztr6mij3uWoS93FCndx72k=; b=jkIybX4tVGOVauWJ2gnA7C16tsSL1zHzbGVhxTSEMrlGu0+eLXTp9pvS0XpNlJj+Hdo70w HFe0VKiYId32g/QDH8Jle9v9D/iIeCpcn5uIcNpvFNY7jLHwKQ7OukLUMaOqOFlqY1fyos uYQltq/5BvZWF7nLVZv4y8ymwkgNAFI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9307DAF00; Thu, 28 Jan 2021 08:19:41 +0000 (UTC) Date: Thu, 28 Jan 2021 09:06:56 +0100 From: Michal Hocko To: Andrew Morton Cc: Tetsuo Handa , linux-mm@kvack.org, Sabyrzhan Tasbolatov , Casey Schaufler 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> <3e01b180-0a5b-f2aa-6247-1c3bbcabe1ed@i-love.sakura.ne.jp> <20210127151940.a9fbbafb890fc769da1525ea@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210127151940.a9fbbafb890fc769da1525ea@linux-foundation.org> 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 15:19:40, Andrew Morton wrote: > 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. I am not familiar with this particular caller and having a limit check which suits that particular usage is a reasonable thing to do. I do argue two things - using NOWARN to work around potentially buggy callers is just sweeping the mess under the rug and opens - these helper functions are to help copy user input and that doesn't really need physically contiguous pages. This can even become dangerous as a higher order depleting vector and DoS via OOM in the worst case. >From that it sounds natural that the helper should be using kvmalloc. This will not solve a due size check on the caller side but that is not possible from a generic helper library function anyway. But it will provide a reasonable allocation policy. -- Michal Hocko SUSE Labs