* [PATCH] mm/kfence: fix null pointer dereference on pointer meta
@ 2021-10-23 17:18 Chengfeng Ye
2021-10-23 18:47 ` Marco Elver
0 siblings, 1 reply; 2+ messages in thread
From: Chengfeng Ye @ 2021-10-23 17:18 UTC (permalink / raw)
To: glider, elver, akpm
Cc: dvyukov, kasan-dev, linux-mm, linux-kernel, Chengfeng Ye
The pointer meta return from addr_to_metadata could be null, so
there is a potential null pointer dereference issue. Fix this
by adding a null check before dereference.
Fixes: 0ce20dd8 ("mm: add Kernel Electric-Fence infrastructure")
Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
---
mm/kfence/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index 7a97db8bc8e7..7d2ec787e921 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -811,7 +811,7 @@ void __kfence_free(void *addr)
* objects once it has been freed. meta->cache may be NULL if the cache
* was destroyed.
*/
- if (unlikely(meta->cache && (meta->cache->flags & SLAB_TYPESAFE_BY_RCU)))
+ if (unlikely(meta && meta->cache && (meta->cache->flags & SLAB_TYPESAFE_BY_RCU)))
call_rcu(&meta->rcu_head, rcu_guarded_free);
else
kfence_guarded_free(addr, meta, false);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/kfence: fix null pointer dereference on pointer meta
2021-10-23 17:18 [PATCH] mm/kfence: fix null pointer dereference on pointer meta Chengfeng Ye
@ 2021-10-23 18:47 ` Marco Elver
0 siblings, 0 replies; 2+ messages in thread
From: Marco Elver @ 2021-10-23 18:47 UTC (permalink / raw)
To: Chengfeng Ye; +Cc: glider, akpm, dvyukov, kasan-dev, linux-mm, linux-kernel
On Sat, 23 Oct 2021 at 19:20, Chengfeng Ye <cyeaa@connect.ust.hk> wrote:
> The pointer meta return from addr_to_metadata could be null, so
> there is a potential null pointer dereference issue. Fix this
> by adding a null check before dereference.
>
> Fixes: 0ce20dd8 ("mm: add Kernel Electric-Fence infrastructure")
> Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
> ---
> mm/kfence/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> index 7a97db8bc8e7..7d2ec787e921 100644
> --- a/mm/kfence/core.c
> +++ b/mm/kfence/core.c
> @@ -811,7 +811,7 @@ void __kfence_free(void *addr)
> * objects once it has been freed. meta->cache may be NULL if the cache
> * was destroyed.
> */
> - if (unlikely(meta->cache && (meta->cache->flags & SLAB_TYPESAFE_BY_RCU)))
> + if (unlikely(meta && meta->cache && (meta->cache->flags & SLAB_TYPESAFE_BY_RCU)))
> call_rcu(&meta->rcu_head, rcu_guarded_free);
> else
> kfence_guarded_free(addr, meta, false);
Sorry -- Nack. What bug did you encounter?
Please see [1], and I'm afraid this attempt makes even less sense
because if it were (hypothetically) NULL like you say we just call
kfence_guarded_free() and crash there.
[1] https://lkml.kernel.org/r/CANpmjNMcgUsdvXrvQHn+-y1w-z-6QAS+WJ27RB2DCnVxORRcuw@mail.gmail.com
However, what I wrote in [1] equally applies here:
> [...]
> 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.
May I ask which static analysis tool keeps flagging this?
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-23 18:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-23 17:18 [PATCH] mm/kfence: fix null pointer dereference on pointer meta Chengfeng Ye
2021-10-23 18:47 ` 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).