Skip to contentSkip to conversation

fix a leak in fcntl_dirnotify()

PATCH In review Al Viro 2 participants 3 messages Jul 12, 2025 – Jul 14, 2025

Subsystems (3)
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

PATCH 1/1 fix a leak in fcntl_dirnotify()

[into #fixes, unless somebody objects]

Lifetime of new_dn_mark is controlled by that of its ->fsn_mark, pointed to by new_fsn_mark. Unfortunately, a failure exit had been inserted between the allocation of new_dn_mark and the call of fsnotify_init_mark(), ending up with a leak.

Fixes 1934b212615d "file: reclaim 24 bytes from f_owner"

---

fs/notify/dnotify/dnotify.c +4 -4
index c4cdaf5fa7ed..9fb73bafd41d 100644
@@ -308,6 +308,10 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned int arg)
 		goto out_err;
 	}
 
+	error = file_f_owner_allocate(filp);
+	if (error)
+		goto out_err;
+
 	/* new fsnotify mark, we expect most fcntl calls to add a new mark */
 	new_dn_mark = kmem_cache_alloc(dnotify_mark_cache, GFP_KERNEL);
 	if (!new_dn_mark) {
@@ -315,10 +319,6 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned int arg)
 		goto out_err;
 	}
 
-	error = file_f_owner_allocate(filp);
-	if (error)
-		goto out_err;
-
 	/* set up the new_fsn_mark and new_dn_mark */
 	new_fsn_mark = &new_dn_mark->fsn_mark;
 	fsnotify_init_mark(new_fsn_mark, dnotify_group);
#1 lore raw
Quoted 10 lines · Al Viro

[into #fixes, unless somebody objects]

Lifetime of new_dn_mark is controlled by that of its ->fsn_mark, pointed to by new_fsn_mark. Unfortunately, a failure exit had been inserted between the allocation of new_dn_mark and the call of fsnotify_init_mark(), ending up with a leak.

Fixes 1934b212615d "file: reclaim 24 bytes from f_owner"

---

I'll grab this into vfs.fixes and send it with the batch I have in there this week.

author maintainer
#2 lore raw
Quoted 8 lines · Christian Brauner
Quoted 7 lines · Al Viro

[into #fixes, unless somebody objects]

Lifetime of new_dn_mark is controlled by that of its ->fsn_mark, pointed to by new_fsn_mark. Unfortunately, a failure exit had been inserted between the allocation of new_dn_mark and the call of fsnotify_init_mark(), ending up with a leak.

Quoted 6 lines
Quoted 3 lines
Fixes 1934b212615d "file: reclaim 24 bytes from f_owner"

---

I'll grab this into vfs.fixes and send it with the batch I have in there this week.

OK... Again, the only things I've got in the vicinity are post-rc1 fodder, so I've no preferences re which branch does that go through.