Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

get rid of audit_reusename()

Originally we tried to avoid multiple insertions into audit names array
during retry loop by a cute hack - memorize the userland pointer and
if there already is a match, just grab an extra reference to it.

Cute as it had been, it had problems - two identical pointers had
audit aux entries merged, two identical strings did not. Having
different behaviour for syscalls that differ only by addresses of
otherwise identical string arguments is obviously wrong - if nothing
else, compiler can decide to merge identical string literals.

Besides, this hack does nothing for non-audited processes - they get
a fresh copy for retry. It's not time-critical, but having behaviour
subtly differ that way is bogus.

These days we have very few places that import filename more than once
(9 functions total) and it's easy to massage them so we get rid of all
re-imports. With that done, we don't need audit_reusename() anymore.
There's no need to memorize userland pointer either.

Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 41670a59 1ee5220e

+3 -43
+3 -8
fs/namei.c
··· 125 125 126 126 #define EMBEDDED_NAME_MAX (PATH_MAX - offsetof(struct filename, iname)) 127 127 128 - static inline void initname(struct filename *name, const char __user *uptr) 128 + static inline void initname(struct filename *name) 129 129 { 130 - name->uptr = uptr; 131 130 name->aname = NULL; 132 131 atomic_set(&name->refcnt, 1); 133 132 } ··· 137 138 struct filename *result; 138 139 char *kname; 139 140 int len; 140 - 141 - result = audit_reusename(filename); 142 - if (result) 143 - return result; 144 141 145 142 result = __getname(); 146 143 if (unlikely(!result)) ··· 205 210 return ERR_PTR(-ENAMETOOLONG); 206 211 } 207 212 } 208 - initname(result, filename); 213 + initname(result); 209 214 audit_getname(result); 210 215 return result; 211 216 } ··· 263 268 return ERR_PTR(-ENAMETOOLONG); 264 269 } 265 270 memcpy((char *)result->name, filename, len); 266 - initname(result, NULL); 271 + initname(result); 267 272 audit_getname(result); 268 273 return result; 269 274 }
-11
include/linux/audit.h
··· 316 316 extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1, 317 317 unsigned long a2, unsigned long a3); 318 318 extern void __audit_syscall_exit(int ret_success, long ret_value); 319 - extern struct filename *__audit_reusename(const __user char *uptr); 320 319 extern void __audit_getname(struct filename *name); 321 320 extern void __audit_inode(struct filename *name, const struct dentry *dentry, 322 321 unsigned int flags); ··· 378 379 379 380 __audit_syscall_exit(success, return_code); 380 381 } 381 - } 382 - static inline struct filename *audit_reusename(const __user char *name) 383 - { 384 - if (unlikely(!audit_dummy_context())) 385 - return __audit_reusename(name); 386 - return NULL; 387 382 } 388 383 static inline void audit_getname(struct filename *name) 389 384 { ··· 614 621 static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx) 615 622 { } 616 623 static inline struct audit_context *audit_context(void) 617 - { 618 - return NULL; 619 - } 620 - static inline struct filename *audit_reusename(const __user char *name) 621 624 { 622 625 return NULL; 623 626 }
-1
include/linux/fs.h
··· 2411 2411 struct audit_names; 2412 2412 struct filename { 2413 2413 const char *name; /* pointer to actual string */ 2414 - const __user char *uptr; /* original userland pointer */ 2415 2414 atomic_t refcnt; 2416 2415 struct audit_names *aname; 2417 2416 const char iname[];
-23
kernel/auditsc.c
··· 2170 2170 } 2171 2171 2172 2172 /** 2173 - * __audit_reusename - fill out filename with info from existing entry 2174 - * @uptr: userland ptr to pathname 2175 - * 2176 - * Search the audit_names list for the current audit context. If there is an 2177 - * existing entry with a matching "uptr" then return the filename 2178 - * associated with that audit_name. If not, return NULL. 2179 - */ 2180 - struct filename * 2181 - __audit_reusename(const __user char *uptr) 2182 - { 2183 - struct audit_context *context = audit_context(); 2184 - struct audit_names *n; 2185 - 2186 - list_for_each_entry(n, &context->names_list, list) { 2187 - if (!n->name) 2188 - continue; 2189 - if (n->name->uptr == uptr) 2190 - return refname(n->name); 2191 - } 2192 - return NULL; 2193 - } 2194 - 2195 - /** 2196 2173 * __audit_getname - add a name to the list 2197 2174 * @name: name to add 2198 2175 *