lkml.org 
[lkml]   [2021]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH linux-next] mm/folio-compat: fix potential NULL pointer access
On Mon, Sep 13, 2021 at 08:11:13AM +0000, cgel.zte@gmail.com wrote:
> From: xu xin <xu.xin16@zte.com.cn>
>
> The pointer 'folio' might be NULL, but the structure it points to is accessed.
> Accordingly, we add a check of NULL pointer by 'if (!folio)'.
> Secondly, there is no need to check if folio is pointer or value with 'xa_is_value(folio)'
> because folio is alwayse pointer.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>

Your robot is garbage.

> folio = __filemap_get_folio(mapping, index, fgp_flags, gfp);
> - if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio))
> + if (!folio)
> + return NULL;
> + if ((fgp_flags & FGP_HEAD))
> return &folio->page;

&folio->page *does not access folio*. It does pointer arithmetic on
folio. Specifically, it adds zero to folio, because page is the first
element of folio.

Secondly, __filemap_get_folio() absolutely can return an xa_is_value()
result if FGP_ENTRY entry is set. It's right there in the first few
lines:

folio = mapping_get_entry(mapping, index);
if (xa_is_value(folio)) {
if (fgp_flags & FGP_ENTRY)
return folio;

\
 
 \ /
  Last update: 2021-10-09 21:37    [W:0.038 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site