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, 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 824FEC433DB for ; Mon, 25 Jan 2021 13:32:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 114B520449 for ; Mon, 25 Jan 2021 13:32:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 114B520449 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 6CD218D0002; Mon, 25 Jan 2021 08:32:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 67D888D0001; Mon, 25 Jan 2021 08:32:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5932C8D0002; Mon, 25 Jan 2021 08:32:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 408858D0001 for ; Mon, 25 Jan 2021 08:32:48 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F32BF8249980 for ; Mon, 25 Jan 2021 13:32:47 +0000 (UTC) X-FDA: 77744387616.10.day18_3d0892f27586 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id AC4DE16A4B4 for ; Mon, 25 Jan 2021 13:32:47 +0000 (UTC) X-HE-Tag: day18_3d0892f27586 X-Filterd-Recvd-Size: 4142 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 25 Jan 2021 13:32:46 +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=1611581565; 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=ZGWkNwyvxb8FKAPDCr07KZCslDGGl252+qSpdlQyZbU=; b=BEJljo97Gy70I7Uz5LZMEjyMRqVs/FEXuvuvt5f5LsUacFLui0b4wSHZnYlPle5rB61O/u fYaNgCl3+Ic5oIxCuVUOtEdUNPLMH5FZz22e57f+X0+4kXJ3e1HY3y0lO9TxfrY5nt8PGd /k2+DDIkKlt7XqoFbPXAVKJUwlqhaKg= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B9F24AC45; Mon, 25 Jan 2021 13:32:45 +0000 (UTC) Date: Mon, 25 Jan 2021 14:32:44 +0100 From: Michal Hocko To: Tetsuo Handa Cc: Andrew Morton , Alexander Viro , linux-mm@kvack.org Subject: Re: [PATCH v2] mm: memdup_user*() should use same gfp flags Message-ID: <20210125133244.GK827@dhcp22.suse.cz> References: <20210120041843.5090-1-penguin-kernel@I-love.SAKURA.ne.jp> <20210120103436.11830-1-penguin-kernel@I-love.SAKURA.ne.jp> <20210121173538.166e8b27408d4525360fbb70@linux-foundation.org> <5346de21-a404-8476-f2a3-c98c191a2ef9@i-love.sakura.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5346de21-a404-8476-f2a3-c98c191a2ef9@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 Fri 22-01-21 19:47:42, Tetsuo Handa wrote: > On 2021/01/22 10:35, Andrew Morton wrote: > > On Wed, 20 Jan 2021 19:34:36 +0900 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]. That is nasty! > >> 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 commit 6c2c97a24f096e32 ("memdup_user(): switch to GFP_USER"). No, this is papering over a more troubling underlying problem. Userspace shouldn't be able to trigger an aribitrary higher order allocations. Those users with a large size to copy should be really using kvmalloc based (e.g vmemdup_user). > > That commit failed to explain why a switch to GFP_USER was performed, > > so that commit isn't a good substitute for an explanation of this > > change. > > For example, commit 2f77d107050abc14 ("Fix incorrect user space access locking > in mincore()") silently converted GFP_KERNEL to GFP_USER. > > #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) > #define GFP_USER (__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_HARDWALL) > > * %GFP_KERNEL is typical for kernel-internal allocations. The caller requires > * %ZONE_NORMAL or a lower zone for direct access but can direct reclaim. > > * %GFP_USER is for userspace allocations that also need to be directly > * accessibly by the kernel or hardware. It is typically used by hardware > * for buffers that are mapped to userspace (e.g. graphics) that hardware > * still must DMA to. cpuset limits are enforced for these allocations. > > * %__GFP_HARDWALL enforces the cpuset memory allocation policy. > > > > > So... please fully describe the reason for this change right here in > > this patch's changelog. > > I guess that GFP_USER is chosen by cautious developers when memory is > allocated by userspace request. Is there a guideline for when to use GFP_USER ? I do not think we have anything better than the above. GFP_USER is indeed used for userspace controlable allocations. So they can be a subject to a more strict cpu policy. memdup_user_nul looks like a good fit for GFP_USER to me. memdup_user and other variant already does this. -- Michal Hocko SUSE Labs