Skip to contentSkip to conversation

configfs: fix NULL dereference in configfs_depend_item_unlocked()

PATCH In review [email protected] 2 participants 3 messages Sep 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configfs: fix NULL dereference in configfs_depend_item_unlocked()

From: Yalagada Pavan Kumar <[email protected]>

configfs_depend_item_unlocked() can dereference a NULL parent when the configfs item is still being created.

The item can be found before it is linked to its parent group, so ci_group can still be NULL. Check ci_group before using it and return -ENOENT if it is NULL.

Reported-by [email protected]
Fixes 4bb8548df632 ("usb: gadget: f_tcm: add configfs support")
---
 fs/configfs/dir.c | 3 +++
 1 file changed, 3 insertions(+)
fs/configfs/dir.c +3 -0
index eda80c2a2d38..301a64f41887 100644
@@ -1244,6 +1244,9 @@ int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
 		return -EINVAL;
 
 	parent = target->ci_group;
+	if (!parent)
+		return -ENOENT;
+
 	/*
 	 * This may happen when someone is trying to depend root
 	 * directory of some subsystem
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · On Mon, Sep 14, 2026 at 03:14:26PM +0530, [email protected] wrote:

From: Yalagada Pavan Kumar <[email protected]>

configfs_depend_item_unlocked() can dereference a NULL parent when the configfs item is still being created.

The item can be found before it is linked to its parent group, so ci_group can still be NULL. Check ci_group before using it and return -ENOENT if it is NULL.

The crash itself looks real, but this reads like a fix in the wrong place. include/linux/configfs.h already documents the opposite contract for this API:

/*
* These functions can sleep and can alloc with GFP_KERNEL
* NOTE: These should be called only underneath configfs callbacks.
* NOTE: First parameter is a caller's subsystem, not target's.
* WARNING: These cannot be called on newly created item
* (in make_group()/make_item() callback)
*/
int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,

                                   struct config_item *target);

"cannot be called on newly created item" is exactly the case being patched here.

If configfs is now going to accept a not-yet-linked item and return -ENOENT for it, shouldn't that comment be updated in the same patch?

And if the contract is meant to stand, shouldn't the caller stop handing over an unlinked item instead?

Quoted 1 line
Fixes 4bb8548df632 ("usb: gadget: f_tcm: add configfs support")

This tag and the diff do not agree. 4bb8548df632 only touches Documentation/ABI, drivers/usb/gadget/Kconfig and drivers/usb/gadget/function/f_tcm.c; it does not add or modify anything under fs/configfs.

--breno

#2 lore raw
Quoted 6 lines · Breno Leitao
Quoted 5 lines · On Mon, Sep 14, 2026 at 03:14:26PM +0530, [email protected] wrote:

From: Yalagada Pavan Kumar <[email protected]>

configfs_depend_item_unlocked() can dereference a NULL parent when the configfs item is still being created.

Quoted 7 lines
Quoted 3 lines

The item can be found before it is linked to its parent group, so ci_group can still be NULL. Check ci_group before using it and return -ENOENT if it is NULL.

The crash itself looks real, but this reads like a fix in the wrong place. include/linux/configfs.h already documents the opposite contract for this API:

I agree, I checked the code path again. The race is in f_tcm. The function instace is published before its configfs item is linked, so usbg_make_tpg() can see it while ci_group is NULL and pass it to configfs_depend_item_unlocked().

For v2, I will fix the caller in f_tcm.c by checking ci_group before calling configfs_depend_item_unlocked().

Quoted 11 lines

/*
* These functions can sleep and can alloc with GFP_KERNEL
* NOTE: These should be called only underneath configfs callbacks.
* NOTE: First parameter is a caller's subsystem, not target's.
* WARNING: These cannot be called on newly created item
* (in make_group()/make_item() callback)
*/
int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,

                                   struct config_item *target);
Quoted 8 lines

"cannot be called on newly created item" is exactly the case being patched here.

If configfs is now going to accept a not-yet-linked item and return -ENOENT for it, shouldn't that comment be updated in the same patch?

And if the contract is meant to stand, shouldn't the caller stop handing over an unlinked item instead?

Yes, the existing configfs API contract should remain unchanged. I will not modify it.

Instead, in v2 i will add check before passing it to configfs_depend_item_unlocked().

Quoted 7 lines
Quoted 2 lines
Fixes 4bb8548df632 ("usb: gadget: f_tcm: add configfs support")

This tag and the diff do not agree. 4bb8548df632 only touches Documentation/ABI, drivers/usb/gadget/Kconfig and drivers/usb/gadget/function/f_tcm.c; it does not add or modify anything under fs/configfs.

You're right. My previous fix was in wrong place.

For v2, i will move the fix to drivers/usb/gadget/function/f_tcm. I will keep the

Fixes 4bb8548df632 ("usb: gadget: f_tcm: add configfs support") tag because this

commit introduced the f_tcm configfs dependency handling involved in this bug.

Thanks,
Pavan

Quoted 2 lines

--breno