linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: Michal Hocko <mhocko@suse.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	 Barry Song <v-songbaohua@oppo.com>,
	Uladzislau Rezki <urezki@gmail.com>,
	 Christoph Hellwig <hch@infradead.org>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	Christoph Lameter <cl@linux.com>,
	 Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	 Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	 Roman Gushchin <roman.gushchin@linux.dev>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>
Subject: Re: [PATCH RFC] mm: warn potential return NULL for kmalloc_array and kvmalloc_array with __GFP_NOFAIL
Date: Thu, 18 Jul 2024 20:18:02 +1200	[thread overview]
Message-ID: <CAGsJ_4wzpSLbteULhnTrQa_p5ETjiCTRHfF9Ph34=WZiub3irA@mail.gmail.com> (raw)
In-Reply-To: <ZpjJpvu5xWlDx4gD@tiehlicka>

On Thu, Jul 18, 2024 at 7:55 PM Michal Hocko <mhocko@suse.com> wrote:
>
> On Thu 18-07-24 19:41:33, Barry Song wrote:
> > On Thu, Jul 18, 2024 at 7:27 PM Michal Hocko <mhocko@suse.com> wrote:
> > >
> > > On Thu 18-07-24 19:22:37, Barry Song wrote:
> > > [...]
> > > > For future-proofing and security reasons, returning NULL for NOFAIL
> > > > still seems incorrect as the callers won't check the ret. If any future or
> > > > existing in-tree code has a potential bug which might be exploited by
> > > > hackers, for example
> > > >
> > > > ptr = kvmalloc_array(NOFAIL);
> > > > ptr->callback(); //ptr=NULL;
> > > >
> > > > callback could be a privilege escalation?
> > >
> > > Only if you allow to map zero page AFAIK. Nobody reasonable should be
> > > doing that.
> >
> > ptr->callback could be above /proc/sys/vm/mmap_min_addr ?
>
> Yes, it can of course but this would require quite a stretch to trigger,
> no?
>
> Look at this from a real life code POV. You are allocating an array of
> callbacks (or structure of callbacks). In order to have this exploitable
> you need to direct the first dereference above mmap_min_addr.
>
> If you really want to protect from a code like that then WARN_ON doesn't
> buy you anything because it will stop the exploit only when
> panic_on_warn. You would need BUG_ON as mentioned by Christoph.
>

I actually also mentioned BUG_ON in the changelog "Likely BUG_ON()
seems better as anyway we can't fix it?" though the code is WARN_ON.

> So the real question is, do you want to stop exploits or do you want to
> debug potentially incorrect but mostly harmless buggy code?

I want to ensure that GFP_NOFAIL has consistent semantics—we don't
check the return value, and it must succeed, although allocating a large
amount of NOFAIL(I mean a number less than overflow) memory might
make the system "unusable". While GFP_NOFAIL itself behaves correctly,
it's inappropriate for the caller.

So the purpose is making sure the semantics - NOFAIL means no failure
and we don't need to check ret.  If we can't really succeed, it should throw
a BUG to stop any potential exploits.

> --
> Michal Hocko
> SUSE Labs

Thanks
Barry


  reply	other threads:[~2024-07-18  8:18 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17 23:00 [PATCH RFC] mm: warn potential return NULL for kmalloc_array and kvmalloc_array with __GFP_NOFAIL Barry Song
2024-07-18  6:58 ` Michal Hocko
2024-07-18  7:04   ` Christoph Hellwig
2024-07-18  7:12     ` Michal Hocko
2024-07-18  8:16       ` Vlastimil Babka
2024-07-18  7:22   ` Barry Song
2024-07-18  7:27     ` Michal Hocko
2024-07-18  7:41       ` Barry Song
2024-07-18  7:53         ` Michal Hocko
2024-07-18  8:18           ` Barry Song [this message]
2024-07-18  8:32             ` Michal Hocko
2024-07-18  8:43               ` Barry Song
2024-07-18  8:50                 ` Michal Hocko
2024-07-19  0:35                   ` Barry Song
2024-07-19  7:02                     ` Michal Hocko
2024-07-19  7:07                       ` Barry Song
2024-07-19  7:42                         ` Michal Hocko
2024-07-19  7:51                           ` Barry Song
2024-07-19  8:01                             ` Michal Hocko
2024-07-19  8:28                               ` Barry Song
2024-07-19  8:40                                 ` Michal Hocko
2024-07-19  9:36                                   ` Barry Song
2024-07-19  9:45                                     ` Michal Hocko
2024-07-19  9:58                                       ` Barry Song
2024-07-19 10:57                                         ` Michal Hocko
2024-07-19 11:05                                           ` Barry Song
2024-07-19 11:19                                             ` Michal Hocko
2024-07-19  8:50                               ` Vlastimil Babka
2024-07-19  9:33                                 ` Michal Hocko
2024-07-19 10:10                                   ` Vlastimil Babka
2024-07-19 10:52                                     ` Michal Hocko
2024-07-19 11:13                                       ` Vlastimil Babka
2024-07-19 11:26                                         ` Michal Hocko
2024-07-19 13:02                                           ` Barry Song
2024-07-19 13:30                                             ` Michal Hocko
2024-07-20  0:36                                               ` Barry Song
2024-07-22  7:23                                                 ` Michal Hocko
2024-07-22  7:34                                                   ` Vlastimil Babka
2024-07-19  7:37                       ` Christoph Hellwig
2024-07-19  7:43                         ` Barry Song
2024-07-19  7:53                           ` Christoph Hellwig
2024-07-20 22:14                             ` Barry Song
2024-07-22  7:26                               ` Michal Hocko
2024-07-22  8:09                                 ` Barry Song
2024-07-22  9:01                                   ` Michal Hocko
2024-07-22 23:18                                     ` Christoph Hellwig
2024-07-22 23:22                                       ` Barry Song
2024-07-19  8:35                     ` Vlastimil Babka
2024-07-18  7:48 ` Hailong Liu
2024-07-18  8:33   ` Barry Song

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='CAGsJ_4wzpSLbteULhnTrQa_p5ETjiCTRHfF9Ph34=WZiub3irA@mail.gmail.com' \
    --to=21cnbao@gmail.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=hch@infradead.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=mhocko@suse.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=urezki@gmail.com \
    --cc=v-songbaohua@oppo.com \
    --cc=vbabka@suse.cz \
    /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;
as well as URLs for NNTP newsgroup(s).