linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	linux-mm@kvack.org, Sabyrzhan Tasbolatov <snovitoll@gmail.com>,
	Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: [PATCH v3] mm: memdup_user*() should use same gfp flags
Date: Thu, 28 Jan 2021 09:06:56 +0100	[thread overview]
Message-ID: <YBJwoA3oXCW16UAn@dhcp22.suse.cz> (raw)
In-Reply-To: <20210127151940.a9fbbafb890fc769da1525ea@linux-foundation.org>

On Wed 27-01-21 15:19:40, Andrew Morton wrote:
> On Wed, 27 Jan 2021 23:03:33 +0900 Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> 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


      parent reply	other threads:[~2021-01-28  8:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20  4:18 [PATCH] mm: add __GFP_NOWARN to memdup_user_nul() Tetsuo Handa
2021-01-20 10:34 ` [PATCH v2] mm: memdup_user*() should use same gfp flags Tetsuo Handa
2021-01-22  1:35   ` Andrew Morton
2021-01-22 10:47     ` Tetsuo Handa
2021-01-25 13:32       ` Michal Hocko
2021-01-25 14:20         ` Tetsuo Handa
2021-01-25 15:44           ` Michal Hocko
2021-01-26 11:13             ` Sabyrzhan Tasbolatov
2021-01-27 10:55               ` [PATCH v3] " Tetsuo Handa
2021-01-27 11:59                 ` Michal Hocko
2021-01-27 12:17                   ` Michal Hocko
     [not found]                     ` <3e01b180-0a5b-f2aa-6247-1c3bbcabe1ed@i-love.sakura.ne.jp>
2021-01-27 23:19                       ` Andrew Morton
2021-01-27 23:27                         ` Casey Schaufler
2021-01-28  7:42                           ` Tetsuo Handa
2021-01-28  8:06                         ` Michal Hocko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YBJwoA3oXCW16UAn@dhcp22.suse.cz \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=casey@schaufler-ca.com \
    --cc=linux-mm@kvack.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=snovitoll@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox