linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: akpm@linux-foundation.org, linux-mm@kvack.org
Cc: 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com,
	hch@infradead.org, iamjoonsoo.kim@lge.com, mhocko@suse.com,
	penberg@kernel.org, rientjes@google.com,
	roman.gushchin@linux.dev, torvalds@linux-foundation.org,
	urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz,
	virtualization@lists.linux.dev
Subject: [PATCH v3 0/4] mm: clarify nofail memory allocation
Date: Sat, 17 Aug 2024 18:24:45 +1200	[thread overview]
Message-ID: <20240817062449.21164-1-21cnbao@gmail.com> (raw)

From: Barry Song <v-songbaohua@oppo.com>

-v3:
 * collect reviewed-by, acked-by etc. Michal, Christoph, Vlastimil, Davidlohr,
   thanks!
 * use Jason's patch[1] to fix vdpa and refine his changelog.
 * refine changelogs
[1] https://lore.kernel.org/all/20240808054320.10017-1-jasowang@redhat.com/

-v2:
 https://lore.kernel.org/linux-mm/20240731000155.109583-1-21cnbao@gmail.com/

 * adjust vpda fix according to Jason and Michal's feedback, I would
   expect Jason to test it, thanks!
 * split BUG_ON of unavoidable failure and the case GFP_ATOMIC |
   __GFP_NOFAIL into two patches according to Vlastimil and Michal.
 * collect Michal's acked-by for patch 2 - the doc;
 * remove the new GFP_NOFAIL from this series, that one would be a
   separate enhancement patchset later on.

-v1:
 https://lore.kernel.org/linux-mm/20240724085544.299090-1-21cnbao@gmail.com/

__GFP_NOFAIL carries the semantics of never failing, so its callers
do not check the return value:
  %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
  cannot handle allocation failures. The allocation could block
  indefinitely but will never return with failure. Testing for
  failure is pointless.

However, __GFP_NOFAIL can sometimes fail if it exceeds size limits
or is used with GFP_ATOMIC/GFP_NOWAIT in a non-sleepable context.
This can expose security vulnerabilities due to potential NULL
dereferences.

Since __GFP_NOFAIL does not support non-blocking allocation, we introduce
GFP_NOFAIL with inclusive blocking semantics and encourage using GFP_NOFAIL
as a replacement for __GFP_NOFAIL in non-mm.

If we must still fail a nofail allocation, we should trigger a BUG rather
than exposing NULL dereferences to callers who do not check the return
value.

* The discussion started from this topic:
 [PATCH RFC] mm: warn potential return NULL for kmalloc_array and
             kvmalloc_array with __GFP_NOFAIL

 https://lore.kernel.org/linux-mm/20240717230025.77361-1-21cnbao@gmail.com/

Thank you to Michal, Christoph, Vlastimil, and Hailong for all the
comments.

Barry Song (3):
  mm: document __GFP_NOFAIL must be blockable
  mm: BUG_ON to avoid NULL deference while __GFP_NOFAIL fails
  mm: prohibit NULL deference exposed for unsupported non-blockable
    __GFP_NOFAIL

Jason Wang (1):
  vduse: avoid using __GFP_NOFAIL

 drivers/vdpa/vdpa_user/iova_domain.c | 19 +++++++++++--------
 drivers/vdpa/vdpa_user/iova_domain.h |  1 +
 include/linux/gfp_types.h            |  5 ++++-
 include/linux/slab.h                 |  4 +++-
 mm/page_alloc.c                      | 14 ++++++++------
 mm/util.c                            |  1 +
 6 files changed, 28 insertions(+), 16 deletions(-)

-- 
2.39.3 (Apple Git-146)



             reply	other threads:[~2024-08-17  6:25 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-17  6:24 Barry Song [this message]
2024-08-17  6:24 ` [PATCH v3 1/4] vduse: avoid using __GFP_NOFAIL Barry Song
2024-08-17  6:24 ` [PATCH v3 2/4] mm: document __GFP_NOFAIL must be blockable Barry Song
2024-08-17  6:24 ` [PATCH v3 3/4] mm: BUG_ON to avoid NULL deference while __GFP_NOFAIL fails Barry Song
2024-08-19  9:43   ` David Hildenbrand
2024-08-19  9:47     ` Barry Song
2024-08-19  9:55       ` David Hildenbrand
2024-08-19 10:02         ` Barry Song
2024-08-19 12:33           ` David Hildenbrand
2024-08-19 12:48             ` Barry Song
2024-08-19 12:49               ` David Hildenbrand
2024-08-19 17:12                 ` Michal Hocko
2024-08-19 17:17                   ` Linus Torvalds
2024-08-19 20:24                   ` David Hildenbrand
2024-08-19 20:35                     ` Linus Torvalds
2024-08-19 21:57                       ` David Hildenbrand
2024-08-19 22:13                         ` Linus Torvalds
2024-08-20  6:17                         ` Michal Hocko
2024-08-19 12:49             ` Christoph Hellwig
2024-08-19 12:51               ` David Hildenbrand
2024-08-19 12:53                 ` Christoph Hellwig
2024-08-19 13:14                   ` David Hildenbrand
2024-08-19 13:05                 ` Barry Song
2024-08-19 13:10                   ` David Hildenbrand
2024-08-19 13:19                     ` Barry Song
2024-08-19 13:22                       ` David Hildenbrand
2024-08-17  6:24 ` [PATCH v3 4/4] mm: prohibit NULL deference exposed for unsupported non-blockable __GFP_NOFAIL Barry Song
2024-08-18  2:55   ` Yafang Shao
2024-08-18  3:48     ` Barry Song
2024-08-18  5:51       ` Yafang Shao
2024-08-18  6:27         ` Barry Song
2024-08-18  6:45           ` Barry Song
2024-08-18  7:07             ` Yafang Shao
2024-08-18  7:25               ` Barry Song
2024-08-19  7:51               ` Michal Hocko
2024-08-19  7:50     ` Michal Hocko
2024-08-19  9:25       ` Yafang Shao
2024-08-19  9:39         ` Barry Song
2024-08-19  9:45           ` Yafang Shao
2024-08-19 10:10             ` Barry Song
2024-08-19 11:56               ` Yafang Shao
2024-08-19 12:09                 ` Michal Hocko
2024-08-19 12:17                   ` Yafang Shao
2024-08-19 14:01                     ` Michal Hocko
2024-08-19 10:17         ` Michal Hocko
2024-08-19 11:56           ` Yafang Shao
2024-08-19 12:04             ` Michal Hocko
2024-08-19  9:44   ` David Hildenbrand
2024-08-19 10:19     ` Michal Hocko
2024-08-19 12:48       ` David Hildenbrand
2024-08-19 13:02 ` [PATCH v3 0/4] mm: clarify nofail memory allocation David Hildenbrand
2024-08-19 16:05   ` Linus Torvalds
2024-08-19 19:23     ` Barry Song
2024-08-19 19:33       ` Linus Torvalds
2024-08-19 21:48         ` Barry Song
2024-08-20  6:24         ` Michal Hocko
2024-08-21 12:40     ` Yafang Shao
2024-08-21 22:59       ` Linus Torvalds
2024-08-22  6:21         ` Michal Hocko
2024-08-22  6:40           ` Linus Torvalds
2024-08-22  6:56             ` Linus Torvalds
2024-08-22  7:47               ` Michal Hocko
2024-08-22  7:57                 ` Barry Song
2024-08-22  8:24                   ` Michal Hocko
2024-08-22  8:39                     ` David Hildenbrand
2024-08-22  9:08                       ` Linus Torvalds
2024-08-22  9:16                         ` Michal Hocko
2024-08-22  9:24                           ` Linus Torvalds
2024-08-22  9:11                       ` Michal Hocko
2024-08-22  9:18                         ` Linus Torvalds
2024-08-22  9:33                           ` Michal Hocko
2024-08-22  9:44                             ` Linus Torvalds
2024-08-22  9:59                               ` Michal Hocko
2024-08-22 10:30                                 ` Linus Torvalds
2024-08-22 10:46                                   ` Michal Hocko
2024-08-22  9:27                         ` David Hildenbrand
2024-08-22  9:34                           ` Linus Torvalds
2024-08-22  9:43                             ` David Hildenbrand
2024-08-22  9:53                               ` Linus Torvalds
2024-08-22 11:58                                 ` Johannes Weiner
2024-08-26 12:10                             ` Vlastimil Babka
2024-08-27  6:57                               ` Linus Torvalds
2024-08-27  7:15                               ` Barry Song
2024-08-27  7:38                                 ` Vlastimil Babka
2024-08-27  7:50                                   ` Barry Song
2024-08-29 10:24                                     ` Vlastimil Babka
2024-08-29 11:53                                       ` Barry Song
2024-08-29 13:20                                         ` Michal Hocko
2024-08-29 21:27                                           ` Barry Song
2024-08-29 22:31                                             ` Barry Song
2024-08-30  7:24                                               ` Michal Hocko
2024-08-30  7:37                                                 ` Vlastimil Babka
2024-08-22  9:41                           ` Michal Hocko
2024-08-22  9:42                             ` David Hildenbrand
2024-08-22  7:01             ` Gao Xiang
2024-08-22  7:54               ` Michal Hocko
2024-08-22  8:04                 ` Gao Xiang
2024-08-22 14:35                   ` Yafang Shao
2024-08-22 15:02                     ` Gao Xiang
2024-08-22  6:37       ` Barry Song
2024-08-22 14:22         ` Yafang Shao

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=20240817062449.21164-1-21cnbao@gmail.com \
    --to=21cnbao@gmail.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=hailong.liu@oppo.com \
    --cc=hch@infradead.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=torvalds@linux-foundation.org \
    --cc=urezki@gmail.com \
    --cc=v-songbaohua@oppo.com \
    --cc=vbabka@suse.cz \
    --cc=virtualization@lists.linux.dev \
    /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).