linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/kasan: Fix null pointer dereference warning in qlink_to_cache()
@ 2022-06-26 17:03 Gautam Menghani
  2022-06-27 14:30 ` Andrey Ryabinin
  0 siblings, 1 reply; 2+ messages in thread
From: Gautam Menghani @ 2022-06-26 17:03 UTC (permalink / raw)
  To: ryabinin.a.a, glider, andreyknvl, dvyukov, vincenzo.frascino,
	akpm
  Cc: Gautam Menghani, kasan-dev, linux-mm, linux-kernel, skhan

The function virt_to_slab() declared in slab.h can return NULL if the
address does not belong to a slab. This case is not handled in the
function qlink_to_cache() in the file quarantine.c, which can cause a
NULL pointer dereference in "virt_to_slab(qlink)->slab_cache". 
This issue was discovered by fanalyzer (my gcc version: 12.1.1 20220507)

Signed-off-by: Gautam Menghani <gautammenghani201@gmail.com>
---
 mm/kasan/quarantine.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
index 75585077eb6d..c7554f5b9fb6 100644
--- a/mm/kasan/quarantine.c
+++ b/mm/kasan/quarantine.c
@@ -128,7 +128,13 @@ static unsigned long quarantine_batch_size;
 
 static struct kmem_cache *qlink_to_cache(struct qlist_node *qlink)
 {
-	return virt_to_slab(qlink)->slab_cache;
+	struct slab *folio_slab = virt_to_slab(qlink);
+
+	if (!folio_slab) {
+		pr_warn("The address %p does not belong to a slab", qlink);
+		return NULL;
+	}
+	return folio_slab->slab_cache;
 }
 
 static void *qlink_to_object(struct qlist_node *qlink, struct kmem_cache *cache)
-- 
2.36.1



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

* Re: [PATCH] mm/kasan: Fix null pointer dereference warning in qlink_to_cache()
  2022-06-26 17:03 [PATCH] mm/kasan: Fix null pointer dereference warning in qlink_to_cache() Gautam Menghani
@ 2022-06-27 14:30 ` Andrey Ryabinin
  0 siblings, 0 replies; 2+ messages in thread
From: Andrey Ryabinin @ 2022-06-27 14:30 UTC (permalink / raw)
  To: Gautam Menghani, glider, andreyknvl, dvyukov, vincenzo.frascino,
	akpm
  Cc: kasan-dev, linux-mm, linux-kernel, skhan



On 6/26/22 20:03, Gautam Menghani wrote:
> The function virt_to_slab() declared in slab.h can return NULL if the
> address does not belong to a slab. This case is not handled in the
> function qlink_to_cache() in the file quarantine.c, which can cause a
> NULL pointer dereference in "virt_to_slab(qlink)->slab_cache". 

qlink is always slab address, so I don't think this patch makes sense.
NAK. 


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

end of thread, other threads:[~2022-06-27 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-26 17:03 [PATCH] mm/kasan: Fix null pointer dereference warning in qlink_to_cache() Gautam Menghani
2022-06-27 14:30 ` Andrey Ryabinin

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