linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] mm: clarify nofail memory allocation
@ 2024-07-31  0:01 Barry Song
  2024-07-31  0:01 ` [PATCH RFT v2 1/4] vpda: try to fix the potential crash due to misusing __GFP_NOFAIL Barry Song
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Barry Song @ 2024-07-31  0:01 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: 42.hyeyoo, cl, hailong.liu, hch, iamjoonsoo.kim, lstoakes, mhocko,
	penberg, rientjes, roman.gushchin, torvalds, urezki, v-songbaohua,
	vbabka, virtualization

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


-v2:
 * 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 (4):
  vpda: try to fix the potential crash due to misusing __GFP_NOFAIL
  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

 drivers/vdpa/vdpa_user/iova_domain.c | 31 +++++++++++++++++++++++-----
 drivers/vdpa/vdpa_user/iova_domain.h |  5 ++++-
 drivers/vdpa/vdpa_user/vduse_dev.c   |  4 +++-
 include/linux/gfp_types.h            |  5 ++++-
 include/linux/slab.h                 |  4 +++-
 mm/page_alloc.c                      | 14 +++++++------
 mm/util.c                            |  1 +
 7 files changed, 49 insertions(+), 15 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2024-08-05  8:19 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-31  0:01 [PATCH v2 0/4] mm: clarify nofail memory allocation Barry Song
2024-07-31  0:01 ` [PATCH RFT v2 1/4] vpda: try to fix the potential crash due to misusing __GFP_NOFAIL Barry Song
2024-07-31  3:09   ` Jason Wang
2024-07-31  3:15     ` Barry Song
2024-07-31  3:58       ` Jason Wang
2024-07-31  4:11         ` Barry Song
2024-07-31  4:13           ` Jason Wang
2024-07-31  5:05             ` Barry Song
2024-07-31 10:20               ` Tetsuo Handa
2024-08-01  2:37                 ` Jason Wang
2024-08-05  1:32                   ` Barry Song
2024-08-05  8:19                     ` Jason Wang
2024-08-01  2:30               ` Jason Wang
2024-07-31  0:01 ` [PATCH v2 2/4] mm: Document __GFP_NOFAIL must be blockable Barry Song
2024-07-31 10:18   ` Vlastimil Babka
2024-07-31 16:26   ` Christoph Hellwig
2024-07-31  0:01 ` [PATCH v2 3/4] mm: BUG_ON to avoid NULL deference while __GFP_NOFAIL fails Barry Song
2024-07-31  7:11   ` Michal Hocko
2024-07-31 10:29   ` Vlastimil Babka
2024-07-31 10:44     ` Tetsuo Handa
2024-07-31 10:48       ` Vlastimil Babka
2024-07-31 10:57         ` Barry Song
2024-07-31 16:28   ` Christoph Hellwig
2024-07-31  0:01 ` [PATCH v2 4/4] mm: prohibit NULL deference exposed for unsupported non-blockable __GFP_NOFAIL Barry Song
2024-07-31  7:15   ` Michal Hocko
2024-07-31 10:55   ` Vlastimil Babka
2024-07-31 11:08     ` Barry Song
2024-07-31 11:31       ` Michal Hocko

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).