From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2F47B644 for ; Thu, 9 Jan 2025 17:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736444302; cv=none; b=KUi94osySrhy5wXqhoHZrvfvxzCgphisHlcXjzQBu0+Xd1K+leuY7nmrZpMLQskEoPB4EDhSAMK2jfUk7JRb7OECNydFkPYNZVgtSR1sM3MFe1Xz3gA98CJsIU9Xc0WzTvJvUMIhTLScpQ7m+7jrTtzGy02Gr9LIhyI3BK9nRDY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736444302; c=relaxed/simple; bh=WWIoVKPFDT+9Xb4E514UjnGjhipnnFzs8qUipUlb1p0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nB996aeLwbJTfr6yXn8sram1E9OFikCx3F7YLygjuQ5kdvqn6JnrDKKNAT97zGDefkh658wQ94ajO6m+ZSV7xLsewt4ZcaK+MKy8rSrEK62RA99qwk+aVW9SXiFsPhU0lzxRvq3LeXoixQ1kvTL/slOmx8vmz/p+Uw+GdY5HI64= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OR6CtrMy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OR6CtrMy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4529DC4CED2; Thu, 9 Jan 2025 17:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736444302; bh=WWIoVKPFDT+9Xb4E514UjnGjhipnnFzs8qUipUlb1p0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OR6CtrMyxd1Z+5iO7Hv2ssq0rj4tInpiLXOHekiIBwb/YeDYw746Zw1WzNFdwScek O57e0v8xAwFIzR4SS4n8Alx8RU4zkP3aTFBY4cpAm7nUpbJ1sHBUavF8dRGFIOakIJ rxt5nVX0A3lI4DYBO5nu4fY8x1cdLfegQQESUk2+6J5spsytGwoMwnLvfhXgJ3gwmD yHaw9jRkuwHqlTdToEsiyHjvURQBvAOAYXNYiT6W7jz78JUKNdFPn10D7bsJteXipI 4fjoI6J1ijS0/v4GSyXzEbpTAaRxgz6By7HzrCMmk4jlq0WhnEAIiQG9cdJE9E1cxY af/t9EoSimxmw== Date: Thu, 9 Jan 2025 09:38:19 -0800 From: Kees Cook To: Tetsuo Handa Cc: Andrew Morton , linux-mm , LKML Subject: Re: [PATCH] mm/util: make memdup_user_nul() similar to memdup_user() Message-ID: <202501090937.221C3F6BA@keescook> References: <014cd694-cc27-4a07-a34a-2ae95d744515@I-love.SAKURA.ne.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <014cd694-cc27-4a07-a34a-2ae95d744515@I-love.SAKURA.ne.jp> On Sat, Dec 21, 2024 at 04:47:29PM +0900, Tetsuo Handa wrote: > Since the string data to copy from userspace is likely less than PAGE_SIZE > bytes, replace GFP_KERNEL with GFP_USER like commit 6c2c97a24f09 > ("memdup_user(): switch to GFP_USER") does and add __GFP_NOWARN like commit > 6c8fcc096be9 ("mm: don't let userspace spam allocations warnings") does. > Also, use dedicated slab buckets like commit d73778e4b867 ("mm/util: Use > dedicated slab buckets for memdup_user()") does. > > Reported-by: syzbot+7e12e97b36154c54414b@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=7e12e97b36154c54414b > Signed-off-by: Tetsuo Handa Thanks for this! Yes, please. With the commit log updated to answer akpm's questions: Acked-by: Kees Cook -Kees > --- > mm/util.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/mm/util.c b/mm/util.c > index c1c3b06ab4f9..60aa40f612b8 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -297,12 +297,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 = kmem_buckets_alloc_track_caller(user_buckets, len + 1, GFP_USER | __GFP_NOWARN); > if (!p) > return ERR_PTR(-ENOMEM); > > -- > 2.43.5 -- Kees Cook