Skip to content

Commit ea1cc20

Browse files
committed
Merge tag 'v6.6-rc7.vfs.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs fix from Christian Brauner: "An openat() call from io_uring triggering an audit call can apparently cause the refcount of struct filename to be incremented from multiple threads concurrently during async execution, triggering a refcount underflow and hitting a BUG_ON(). That bug has been lurking around since at least v5.16 apparently. Switch to an atomic counter to fix that. The underflow check is downgraded from a BUG_ON() to a WARN_ON_ONCE() but we could easily remove that check altogether tbh" * tag 'v6.6-rc7.vfs.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: audit,io_uring: io_uring openat triggers audit reference count underflow
2 parents f69d00d + 03adc61 commit ea1cc20

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

fs/namei.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ getname_flags(const char __user *filename, int flags, int *empty)
188188
}
189189
}
190190

191-
result->refcnt = 1;
191+
atomic_set(&result->refcnt, 1);
192192
/* The empty path is special. */
193193
if (unlikely(!len)) {
194194
if (empty)
@@ -249,7 +249,7 @@ getname_kernel(const char * filename)
249249
memcpy((char *)result->name, filename, len);
250250
result->uptr = NULL;
251251
result->aname = NULL;
252-
result->refcnt = 1;
252+
atomic_set(&result->refcnt, 1);
253253
audit_getname(result);
254254

255255
return result;
@@ -261,9 +261,10 @@ void putname(struct filename *name)
261261
if (IS_ERR(name))
262262
return;
263263

264-
BUG_ON(name->refcnt <= 0);
264+
if (WARN_ON_ONCE(!atomic_read(&name->refcnt)))
265+
return;
265266

266-
if (--name->refcnt > 0)
267+
if (!atomic_dec_and_test(&name->refcnt))
267268
return;
268269

269270
if (name->name != name->iname) {

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ struct audit_names;
24032403
struct filename {
24042404
const char *name; /* pointer to actual string */
24052405
const __user char *uptr; /* original userland pointer */
2406-
int refcnt;
2406+
atomic_t refcnt;
24072407
struct audit_names *aname;
24082408
const char iname[];
24092409
};

kernel/auditsc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ __audit_reusename(const __user char *uptr)
22122212
if (!n->name)
22132213
continue;
22142214
if (n->name->uptr == uptr) {
2215-
n->name->refcnt++;
2215+
atomic_inc(&n->name->refcnt);
22162216
return n->name;
22172217
}
22182218
}
@@ -2241,7 +2241,7 @@ void __audit_getname(struct filename *name)
22412241
n->name = name;
22422242
n->name_len = AUDIT_NAME_FULL;
22432243
name->aname = n;
2244-
name->refcnt++;
2244+
atomic_inc(&name->refcnt);
22452245
}
22462246

22472247
static inline int audit_copy_fcaps(struct audit_names *name,
@@ -2373,7 +2373,7 @@ void __audit_inode(struct filename *name, const struct dentry *dentry,
23732373
return;
23742374
if (name) {
23752375
n->name = name;
2376-
name->refcnt++;
2376+
atomic_inc(&name->refcnt);
23772377
}
23782378

23792379
out:
@@ -2500,7 +2500,7 @@ void __audit_inode_child(struct inode *parent,
25002500
if (found_parent) {
25012501
found_child->name = found_parent->name;
25022502
found_child->name_len = AUDIT_NAME_FULL;
2503-
found_child->name->refcnt++;
2503+
atomic_inc(&found_child->name->refcnt);
25042504
}
25052505
}
25062506

0 commit comments

Comments
 (0)