* [PATCH] kernfs: fix potential NULL dereference in __kernfs_remove
@ 2022-06-30 4:00 zys.zljxml
2022-06-30 7:28 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: zys.zljxml @ 2022-06-30 4:00 UTC (permalink / raw)
To: tj, gregkh, viro; +Cc: linux-kernel, katrinzhou
From: katrinzhou <katrinzhou@tencent.com>
When lockdep is enabled, lockdep_assert_held_write would
cause potential NULL pointer dereference.
Fix the folloeing smatch warnings:
fs/kernfs/dir.c:1353 __kernfs_remove() warn: variable dereferenced before check 'kn' (see line 1346)
Signed-off-by: katrinzhou <katrinzhou@tencent.com>
---
fs/kernfs/dir.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 6eca72cfa1f2..1cc88ba6de90 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -1343,14 +1343,17 @@ static void __kernfs_remove(struct kernfs_node *kn)
{
struct kernfs_node *pos;
+ /* Short-circuit if non-root @kn has already finished removal. */
+ if (!kn)
+ return;
+
lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem);
/*
- * Short-circuit if non-root @kn has already finished removal.
* This is for kernfs_remove_self() which plays with active ref
* after removal.
*/
- if (!kn || (kn->parent && RB_EMPTY_NODE(&kn->rb)))
+ if (kn->parent && RB_EMPTY_NODE(&kn->rb))
return;
pr_debug("kernfs %s: removing\n", kn->name);
--
2.27.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kernfs: fix potential NULL dereference in __kernfs_remove
2022-06-30 4:00 [PATCH] kernfs: fix potential NULL dereference in __kernfs_remove zys.zljxml
@ 2022-06-30 7:28 ` Greg KH
2022-06-30 8:12 ` Katrin Jo
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2022-06-30 7:28 UTC (permalink / raw)
To: zys.zljxml; +Cc: tj, viro, linux-kernel, katrinzhou
On Thu, Jun 30, 2022 at 12:00:47PM +0800, zys.zljxml@gmail.com wrote:
> From: katrinzhou <katrinzhou@tencent.com>
>
> When lockdep is enabled, lockdep_assert_held_write would
> cause potential NULL pointer dereference.
>
> Fix the folloeing smatch warnings:
>
> fs/kernfs/dir.c:1353 __kernfs_remove() warn: variable dereferenced before check 'kn' (see line 1346)
>
> Signed-off-by: katrinzhou <katrinzhou@tencent.com>
Can you please submit this with your legal name that you use to sign
documents?
Also, what commit id does this fix? Did you actually hit this with a
real workload? How can this be reproduced and tested?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kernfs: fix potential NULL dereference in __kernfs_remove
2022-06-30 7:28 ` Greg KH
@ 2022-06-30 8:12 ` Katrin Jo
0 siblings, 0 replies; 3+ messages in thread
From: Katrin Jo @ 2022-06-30 8:12 UTC (permalink / raw)
To: Greg KH; +Cc: tj, viro, LKML, katrinzhou
On Thu, Jun 30, 2022 at 3:28 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Jun 30, 2022 at 12:00:47PM +0800, zys.zljxml@gmail.com wrote:
> > From: katrinzhou <katrinzhou@tencent.com>
> >
> > When lockdep is enabled, lockdep_assert_held_write would
> > cause potential NULL pointer dereference.
> >
> > Fix the folloeing smatch warnings:
> >
> > fs/kernfs/dir.c:1353 __kernfs_remove() warn: variable dereferenced before check 'kn' (see line 1346)
> >
> > Signed-off-by: katrinzhou <katrinzhou@tencent.com>
>
> Can you please submit this with your legal name that you use to sign
> documents?
>
> Also, what commit id does this fix? Did you actually hit this with a
> real workload? How can this be reproduced and tested?
>
> thanks,
>
> greg k-h
Sorry for the formatting issue. I'll submit a new patch soon.
This problem is found via static code analysis, and by now
I have not reproduced / tested it.
Best regards,
Katrin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-30 8:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 4:00 [PATCH] kernfs: fix potential NULL dereference in __kernfs_remove zys.zljxml
2022-06-30 7:28 ` Greg KH
2022-06-30 8:12 ` Katrin Jo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®