linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] mm: fix potential NULL pointer dereference in pagetable_alloc_noprof
       [not found] ` <206c6dc2-792b-4c73-a922-eebd03864d2c@lucifer.local>
@ 2025-05-21 12:48   ` Lorenzo Stoakes
  2025-05-22  6:58     ` Qi Zheng
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Stoakes @ 2025-05-21 12:48 UTC (permalink / raw)
  To: Ye Chey
  Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
	linux-mm, linux-kernel

+cc mailing lists

Please ensure you always cc these when submitting patches by the way :)

On Wed, May 21, 2025 at 01:46:48PM +0100, Lorenzo Stoakes wrote:
> On Wed, May 21, 2025 at 08:40:08PM +0800, Ye Chey wrote:
> > The pagetable_alloc_noprof function does not check the return value of
> > alloc_pages_noprof, which could lead to a NULL pointer dereference when
> > memory allocation fails. Add a NULL check to prevent this issue.
> >
> > Signed-off-by: Ye Chey <yechey@ai-sast.com>
> > ---
> >  include/linux/mm.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index bf5520693..9052bb531 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -3000,7 +3000,8 @@ static inline bool pagetable_is_reserved(struct ptdesc *pt)
> >  static inline struct ptdesc *pagetable_alloc_noprof(gfp_t gfp, unsigned int order)
> >  {
> >  	struct page *page = alloc_pages_noprof(gfp | __GFP_COMP, order);
> > -
> > +	if (!page)
> > +		return NULL;
> >  	return page_ptdesc(page);
>
> Doesn't page_ptdesc() just cast the page to the appropriate type? And thus can
> handle it being NULL?
>
> >  }
> >  #define pagetable_alloc(...)	alloc_hooks(pagetable_alloc_noprof(__VA_ARGS__))
> > --
> > 2.44.0
> >


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

* Re: [PATCH] mm: fix potential NULL pointer dereference in pagetable_alloc_noprof
  2025-05-21 12:48   ` [PATCH] mm: fix potential NULL pointer dereference in pagetable_alloc_noprof Lorenzo Stoakes
@ 2025-05-22  6:58     ` Qi Zheng
  0 siblings, 0 replies; 2+ messages in thread
From: Qi Zheng @ 2025-05-22  6:58 UTC (permalink / raw)
  To: Lorenzo Stoakes, Ye Chey
  Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
	linux-mm, linux-kernel



On 5/21/25 8:48 PM, Lorenzo Stoakes wrote:
> +cc mailing lists
> 
> Please ensure you always cc these when submitting patches by the way :)
> 
> On Wed, May 21, 2025 at 01:46:48PM +0100, Lorenzo Stoakes wrote:
>> On Wed, May 21, 2025 at 08:40:08PM +0800, Ye Chey wrote:
>>> The pagetable_alloc_noprof function does not check the return value of
>>> alloc_pages_noprof, which could lead to a NULL pointer dereference when
>>> memory allocation fails. Add a NULL check to prevent this issue.
>>>
>>> Signed-off-by: Ye Chey <yechey@ai-sast.com>
>>> ---
>>>   include/linux/mm.h | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>>> index bf5520693..9052bb531 100644
>>> --- a/include/linux/mm.h
>>> +++ b/include/linux/mm.h
>>> @@ -3000,7 +3000,8 @@ static inline bool pagetable_is_reserved(struct ptdesc *pt)
>>>   static inline struct ptdesc *pagetable_alloc_noprof(gfp_t gfp, unsigned int order)
>>>   {
>>>   	struct page *page = alloc_pages_noprof(gfp | __GFP_COMP, order);
>>> -
>>> +	if (!page)
>>> +		return NULL;
>>>   	return page_ptdesc(page);
>>
>> Doesn't page_ptdesc() just cast the page to the appropriate type? And thus can
>> handle it being NULL?

Right, no NULL check is needed here.

>>
>>>   }
>>>   #define pagetable_alloc(...)	alloc_hooks(pagetable_alloc_noprof(__VA_ARGS__))
>>> --
>>> 2.44.0
>>>



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

end of thread, other threads:[~2025-05-22  6:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20250521124008.36139-1-yechey@ai-sast.com>
     [not found] ` <206c6dc2-792b-4c73-a922-eebd03864d2c@lucifer.local>
2025-05-21 12:48   ` [PATCH] mm: fix potential NULL pointer dereference in pagetable_alloc_noprof Lorenzo Stoakes
2025-05-22  6:58     ` Qi Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox