Re: [PATCH] NFS: sysfs: fix use-after-free on delayed kobject release

From: Unsung Lee

Date: Sat Nov 21 2026 - 05:36:05 EST


On Mon, Aug 03, 2026, Vasileios Almpanis wrote:
> struct nfs_netns_client embeds two kobjects and is freed by
> nfs_netns_object_release(), the release function of nfs_net_kobj.
> Despite that the first one, p->kobject lives in the same allocation.
> Nothing keeps the allocation from being freed before p->kobject
> has been released.

[...]

I ran into the same KASAN report with CONFIG_DEBUG_KOBJECT_RELEASE=y:
a slab-use-after-free in __run_timers() on memory allocated by
nfs_netns_sysfs_setup() and freed by kobject_delayed_cleanup(), after
a network namespace was torn down.

Tested on v7.3.1 and v7.4-rc3 in a QEMU guest with KASAN, running
"for i in $(seq 16); do unshare -n true; done; sleep 20" after boot.
Without the patch, 3 of 3 boots hit the report on each kernel (on
v7.4-rc3 already during boot). With the patch, 10 boots on each kernel
gave no KASAN reports, and lockdep stayed enabled.

The test runs were automated with an LLM coding assistant.

Tested-by: Unsung Lee <unsung0317@xxxxxxxxx>