Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kernfs: fix potential NULL dereference in __kernfs_remove

When lockdep is enabled, lockdep_assert_held_write would
cause potential NULL pointer dereference.

Fix the following smatch warnings:

fs/kernfs/dir.c:1353 __kernfs_remove() warn: variable dereferenced before check 'kn' (see line 1346)

Fixes: 393c3714081a ("kernfs: switch global kernfs_rwsem lock to per-fs lock")
Signed-off-by: Yushan Zhou <katrinzhou@tencent.com>
Link: https://lore.kernel.org/r/20220630082512.3482581-1-zys.zljxml@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Yushan Zhou and committed by
Greg Kroah-Hartman
72b5d5ae c882716b

+5 -2
+5 -2
fs/kernfs/dir.c
··· 1343 1343 { 1344 1344 struct kernfs_node *pos; 1345 1345 1346 + /* Short-circuit if non-root @kn has already finished removal. */ 1347 + if (!kn) 1348 + return; 1349 + 1346 1350 lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem); 1347 1351 1348 1352 /* 1349 - * Short-circuit if non-root @kn has already finished removal. 1350 1353 * This is for kernfs_remove_self() which plays with active ref 1351 1354 * after removal. 1352 1355 */ 1353 - if (!kn || (kn->parent && RB_EMPTY_NODE(&kn->rb))) 1356 + if (kn->parent && RB_EMPTY_NODE(&kn->rb)) 1354 1357 return; 1355 1358 1356 1359 pr_debug("kernfs %s: removing\n", kn->name);