... or visible outside of audit, really. Note that references held in delayed_filename always have refcount 1, and from the moment of complete_getname() or equivalent point in getname...() there won't be any references to struct filename instance left in places visible to other threads. Acked-by: Paul Moore Signed-off-by: Al Viro --- fs/namei.c | 10 +++++----- include/linux/fs.h | 8 +------- kernel/auditsc.c | 6 ++++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 4faaae0239ad..192d31acb4ff 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -150,7 +150,7 @@ static inline void free_filename(struct filename *p) static inline void initname(struct filename *name) { name->aname = NULL; - atomic_set(&name->refcnt, 1); + name->refcnt = 1; } static int getname_long(struct filename *name, const char __user *filename) @@ -294,13 +294,13 @@ void putname(struct filename *name) if (IS_ERR_OR_NULL(name)) return; - refcnt = atomic_read(&name->refcnt); + refcnt = name->refcnt; if (unlikely(refcnt != 1)) { if (WARN_ON_ONCE(!refcnt)) return; - if (!atomic_dec_and_test(&name->refcnt)) - return; + name->refcnt--; + return; } if (unlikely(name->name != name->iname)) @@ -332,7 +332,7 @@ int putname_to_delayed(struct delayed_filename *v, struct filename *__name) { struct filename *name __free(putname) = no_free_ptr(__name); - if (likely(atomic_read(&name->refcnt) == 1)) { + if (likely(name->refcnt == 1)) { v->__incomplete_filename = no_free_ptr(name); return 0; } diff --git a/include/linux/fs.h b/include/linux/fs.h index e446cb8c1e37..b711f46ba8f5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2412,7 +2412,7 @@ struct audit_names; struct __filename_head { const char *name; /* pointer to actual string */ - atomic_t refcnt; + int refcnt; struct audit_names *aname; }; #define EMBEDDED_NAME_MAX 192 - sizeof(struct __filename_head) @@ -2527,12 +2527,6 @@ void dismiss_delayed_filename(struct delayed_filename *); int putname_to_delayed(struct delayed_filename *, struct filename *); struct filename *complete_getname(struct delayed_filename *); -static inline struct filename *refname(struct filename *name) -{ - atomic_inc(&name->refcnt); - return name; -} - extern int finish_open(struct file *file, struct dentry *dentry, int (*open)(struct inode *, struct file *)); extern int finish_no_open(struct file *file, struct dentry *dentry); diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 67d8da927381..b1dc9284550a 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2169,6 +2169,12 @@ static struct audit_names *audit_alloc_name(struct audit_context *context, return aname; } +static inline struct filename *refname(struct filename *name) +{ + name->refcnt++; + return name; +} + /** * __audit_getname - add a name to the list * @name: name to add -- 2.47.3