* [PATCH] mm/kfence: Null check is added for return value of addr_to_metadata
[not found] <CGME20210924121457epcas5p39266266f9cef79177f2301a6a4f7d79a@epcas5p3.samsung.com>
@ 2021-09-24 12:14 ` Manjeet Pawar
2021-09-24 14:13 ` Marco Elver
0 siblings, 1 reply; 2+ messages in thread
From: Manjeet Pawar @ 2021-09-24 12:14 UTC (permalink / raw)
To: glider, elver, dvyukov, akpm, kasan-dev, linux-mm, linux-kernel
Cc: r.thapliyal, a.sahrawat, v.narang, Manjeet Pawar
This patch add null check for return value of addr_to_metadata().
currently 'meta' is geting accessed without any NULL check but it is
usually checked for this function.
Signed-off-by: Manjeet Pawar <manjeet.p@samsung.com>
---
mm/kfence/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index 575c685aa642..9b953cfa7fee 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -802,6 +802,9 @@ void __kfence_free(void *addr)
{
struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr);
+ if (unlikely(!meta))
+ return;
+
/*
* If the objects of the cache are SLAB_TYPESAFE_BY_RCU, defer freeing
* the object, as the object page may be recycled for other-typed
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/kfence: Null check is added for return value of addr_to_metadata
2021-09-24 12:14 ` [PATCH] mm/kfence: Null check is added for return value of addr_to_metadata Manjeet Pawar
@ 2021-09-24 14:13 ` Marco Elver
0 siblings, 0 replies; 2+ messages in thread
From: Marco Elver @ 2021-09-24 14:13 UTC (permalink / raw)
To: Manjeet Pawar
Cc: glider, dvyukov, akpm, kasan-dev, linux-mm, linux-kernel,
r.thapliyal, a.sahrawat, v.narang
On Fri, 24 Sept 2021 at 15:55, Manjeet Pawar <manjeet.p@samsung.com> wrote:
> This patch add null check for return value of addr_to_metadata().
> currently 'meta' is geting accessed without any NULL check but it is
> usually checked for this function.
>
> Signed-off-by: Manjeet Pawar <manjeet.p@samsung.com>
Your commit message does not make sense -- what bug did you encounter?
"usually checked for this function" is not a reason to add the check.
Adding a check like this could also hide genuine bugs, as meta should
never be NULL in __kfence_free(). If it is, we'd like to see a crash.
Did you read kfence_free() in include/linux/kfence.h? It already
prevents __kfence_free() being called with a non-KFENCE address.
Without a more thorough explanation, Nack.
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-24 14:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20210924121457epcas5p39266266f9cef79177f2301a6a4f7d79a@epcas5p3.samsung.com>
2021-09-24 12:14 ` [PATCH] mm/kfence: Null check is added for return value of addr_to_metadata Manjeet Pawar
2021-09-24 14:13 ` Marco Elver
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).