linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] mm/folio-compat: fix potential NULL pointer access
@ 2021-09-13  8:11 cgel.zte
  2021-10-09 19:35 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2021-09-13  8:11 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, xu xin, Zeal Robot

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>
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
 mm/folio-compat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index 5b6ae1da314e..a1b60310c7ba 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -123,7 +123,9 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
 	struct folio *folio;
 
 	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;
 	return folio_file_page(folio, index);
 }
-- 
2.25.1



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

* Re: [PATCH linux-next] mm/folio-compat: fix potential NULL pointer access
  2021-09-13  8:11 [PATCH linux-next] mm/folio-compat: fix potential NULL pointer access cgel.zte
@ 2021-10-09 19:35 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2021-10-09 19:35 UTC (permalink / raw)
  To: cgel.zte; +Cc: akpm, linux-mm, linux-kernel, xu xin, Zeal Robot

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;



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

end of thread, other threads:[~2021-10-09 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-13  8:11 [PATCH linux-next] mm/folio-compat: fix potential NULL pointer access cgel.zte
2021-10-09 19:35 ` Matthew Wilcox

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