Skip to content

Commit 5a190ae

Browse files
author
Al Viro
committed
[PATCH] pass dentry to audit_inode()/audit_inode_child()
makes caller simpler *and* allows to scan ancestors Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent cfa76f0 commit 5a190ae

8 files changed

Lines changed: 33 additions & 30 deletions

File tree

‎fs/debugfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
413413
d_move(old_dentry, dentry);
414414
fsnotify_move(old_dir->d_inode, new_dir->d_inode, old_name,
415415
old_dentry->d_name.name, S_ISDIR(old_dentry->d_inode->i_mode),
416-
NULL, old_dentry->d_inode);
416+
NULL, old_dentry);
417417
fsnotify_oldname_free(old_name);
418418
unlock_rename(new_dir, old_dir);
419419
dput(dentry);

‎fs/namei.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ static int fastcall do_path_lookup(int dfd, const char *name,
11741174
out:
11751175
if (unlikely(!retval && !audit_dummy_context() && nd->dentry &&
11761176
nd->dentry->d_inode))
1177-
audit_inode(name, nd->dentry->d_inode);
1177+
audit_inode(name, nd->dentry);
11781178
out_fail:
11791179
return retval;
11801180

@@ -1214,7 +1214,7 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
12141214
retval = path_walk(name, nd);
12151215
if (unlikely(!retval && !audit_dummy_context() && nd->dentry &&
12161216
nd->dentry->d_inode))
1217-
audit_inode(name, nd->dentry->d_inode);
1217+
audit_inode(name, nd->dentry);
12181218

12191219
return retval;
12201220

@@ -1469,7 +1469,7 @@ static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
14691469
return -ENOENT;
14701470

14711471
BUG_ON(victim->d_parent->d_inode != dir);
1472-
audit_inode_child(victim->d_name.name, victim->d_inode, dir);
1472+
audit_inode_child(victim->d_name.name, victim, dir);
14731473

14741474
error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
14751475
if (error)
@@ -1783,7 +1783,7 @@ int open_namei(int dfd, const char *pathname, int flag,
17831783
* It already exists.
17841784
*/
17851785
mutex_unlock(&dir->d_inode->i_mutex);
1786-
audit_inode(pathname, path.dentry->d_inode);
1786+
audit_inode(pathname, path.dentry);
17871787

17881788
error = -EEXIST;
17891789
if (flag & O_EXCL)
@@ -2562,7 +2562,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
25622562
if (!error) {
25632563
const char *new_name = old_dentry->d_name.name;
25642564
fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
2565-
new_dentry->d_inode, old_dentry->d_inode);
2565+
new_dentry->d_inode, old_dentry);
25662566
}
25672567
fsnotify_oldname_free(old_name);
25682568

‎fs/open.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
569569
dentry = file->f_path.dentry;
570570
inode = dentry->d_inode;
571571

572-
audit_inode(NULL, inode);
572+
audit_inode(NULL, dentry);
573573

574574
err = -EROFS;
575575
if (IS_RDONLY(inode))
@@ -727,7 +727,7 @@ asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group)
727727
goto out;
728728

729729
dentry = file->f_path.dentry;
730-
audit_inode(NULL, dentry->d_inode);
730+
audit_inode(NULL, dentry);
731731
error = chown_common(dentry, user, group);
732732
fput(file);
733733
out:

‎fs/xattr.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ sys_fsetxattr(int fd, char __user *name, void __user *value,
267267
if (!f)
268268
return error;
269269
dentry = f->f_path.dentry;
270-
audit_inode(NULL, dentry->d_inode);
270+
audit_inode(NULL, dentry);
271271
error = setxattr(dentry, name, value, size, flags);
272272
fput(f);
273273
return error;
@@ -349,7 +349,7 @@ sys_fgetxattr(int fd, char __user *name, void __user *value, size_t size)
349349
f = fget(fd);
350350
if (!f)
351351
return error;
352-
audit_inode(NULL, f->f_path.dentry->d_inode);
352+
audit_inode(NULL, f->f_path.dentry);
353353
error = getxattr(f->f_path.dentry, name, value, size);
354354
fput(f);
355355
return error;
@@ -422,7 +422,7 @@ sys_flistxattr(int fd, char __user *list, size_t size)
422422
f = fget(fd);
423423
if (!f)
424424
return error;
425-
audit_inode(NULL, f->f_path.dentry->d_inode);
425+
audit_inode(NULL, f->f_path.dentry);
426426
error = listxattr(f->f_path.dentry, list, size);
427427
fput(f);
428428
return error;
@@ -485,7 +485,7 @@ sys_fremovexattr(int fd, char __user *name)
485485
if (!f)
486486
return error;
487487
dentry = f->f_path.dentry;
488-
audit_inode(NULL, dentry->d_inode);
488+
audit_inode(NULL, dentry);
489489
error = removexattr(dentry, name);
490490
fput(f);
491491
return error;

‎include/linux/audit.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ extern void audit_syscall_entry(int arch,
366366
extern void audit_syscall_exit(int failed, long return_code);
367367
extern void __audit_getname(const char *name);
368368
extern void audit_putname(const char *name);
369-
extern void __audit_inode(const char *name, const struct inode *inode);
370-
extern void __audit_inode_child(const char *dname, const struct inode *inode,
369+
extern void __audit_inode(const char *name, const struct dentry *dentry);
370+
extern void __audit_inode_child(const char *dname, const struct dentry *dentry,
371371
const struct inode *parent);
372372
extern void __audit_ptrace(struct task_struct *t);
373373

@@ -381,15 +381,15 @@ static inline void audit_getname(const char *name)
381381
if (unlikely(!audit_dummy_context()))
382382
__audit_getname(name);
383383
}
384-
static inline void audit_inode(const char *name, const struct inode *inode) {
384+
static inline void audit_inode(const char *name, const struct dentry *dentry) {
385385
if (unlikely(!audit_dummy_context()))
386-
__audit_inode(name, inode);
386+
__audit_inode(name, dentry);
387387
}
388388
static inline void audit_inode_child(const char *dname,
389-
const struct inode *inode,
389+
const struct dentry *dentry,
390390
const struct inode *parent) {
391391
if (unlikely(!audit_dummy_context()))
392-
__audit_inode_child(dname, inode, parent);
392+
__audit_inode_child(dname, dentry, parent);
393393
}
394394
void audit_core_dumps(long signr);
395395

@@ -477,9 +477,9 @@ extern int audit_signals;
477477
#define audit_dummy_context() 1
478478
#define audit_getname(n) do { ; } while (0)
479479
#define audit_putname(n) do { ; } while (0)
480-
#define __audit_inode(n,i) do { ; } while (0)
480+
#define __audit_inode(n,d) do { ; } while (0)
481481
#define __audit_inode_child(d,i,p) do { ; } while (0)
482-
#define audit_inode(n,i) do { ; } while (0)
482+
#define audit_inode(n,d) do { ; } while (0)
483483
#define audit_inode_child(d,i,p) do { ; } while (0)
484484
#define audit_core_dumps(i) do { ; } while (0)
485485
#define auditsc_get_stamp(c,t,s) do { BUG(); } while (0)

‎include/linux/fsnotify.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ static inline void fsnotify_d_move(struct dentry *entry)
4141
*/
4242
static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
4343
const char *old_name, const char *new_name,
44-
int isdir, struct inode *target, struct inode *source)
44+
int isdir, struct inode *target, struct dentry *moved)
4545
{
46+
struct inode *source = moved->d_inode;
4647
u32 cookie = inotify_get_cookie();
4748

4849
if (old_dir == new_dir)
@@ -67,7 +68,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
6768
if (source) {
6869
inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
6970
}
70-
audit_inode_child(new_name, source, new_dir);
71+
audit_inode_child(new_name, moved, new_dir);
7172
}
7273

7374
/*
@@ -98,7 +99,7 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
9899
inode_dir_notify(inode, DN_CREATE);
99100
inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
100101
dentry->d_inode);
101-
audit_inode_child(dentry->d_name.name, dentry->d_inode, inode);
102+
audit_inode_child(dentry->d_name.name, dentry, inode);
102103
}
103104

104105
/*
@@ -109,7 +110,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
109110
inode_dir_notify(inode, DN_CREATE);
110111
inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0,
111112
dentry->d_name.name, dentry->d_inode);
112-
audit_inode_child(dentry->d_name.name, dentry->d_inode, inode);
113+
audit_inode_child(dentry->d_name.name, dentry, inode);
113114
}
114115

115116
/*

‎ipc/mqueue.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode,
676676

677677
if (oflag & O_CREAT) {
678678
if (dentry->d_inode) { /* entry already exists */
679-
audit_inode(name, dentry->d_inode);
679+
audit_inode(name, dentry);
680680
error = -EEXIST;
681681
if (oflag & O_EXCL)
682682
goto out;
@@ -689,7 +689,7 @@ asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode,
689689
error = -ENOENT;
690690
if (!dentry->d_inode)
691691
goto out;
692-
audit_inode(name, dentry->d_inode);
692+
audit_inode(name, dentry);
693693
filp = do_open(dentry, oflag);
694694
}
695695

@@ -837,7 +837,7 @@ asmlinkage long sys_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
837837
if (unlikely(filp->f_op != &mqueue_file_operations))
838838
goto out_fput;
839839
info = MQUEUE_I(inode);
840-
audit_inode(NULL, inode);
840+
audit_inode(NULL, filp->f_path.dentry);
841841

842842
if (unlikely(!(filp->f_mode & FMODE_WRITE)))
843843
goto out_fput;
@@ -921,7 +921,7 @@ asmlinkage ssize_t sys_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
921921
if (unlikely(filp->f_op != &mqueue_file_operations))
922922
goto out_fput;
923923
info = MQUEUE_I(inode);
924-
audit_inode(NULL, inode);
924+
audit_inode(NULL, filp->f_path.dentry);
925925

926926
if (unlikely(!(filp->f_mode & FMODE_READ)))
927927
goto out_fput;

‎kernel/auditsc.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,11 @@ static void audit_copy_inode(struct audit_names *name, const struct inode *inode
14031403
*
14041404
* Called from fs/namei.c:path_lookup().
14051405
*/
1406-
void __audit_inode(const char *name, const struct inode *inode)
1406+
void __audit_inode(const char *name, const struct dentry *dentry)
14071407
{
14081408
int idx;
14091409
struct audit_context *context = current->audit_context;
1410+
const struct inode *inode = inode = dentry->d_inode;
14101411

14111412
if (!context->in_syscall)
14121413
return;
@@ -1443,12 +1444,13 @@ void __audit_inode(const char *name, const struct inode *inode)
14431444
* must be hooked prior, in order to capture the target inode during
14441445
* unsuccessful attempts.
14451446
*/
1446-
void __audit_inode_child(const char *dname, const struct inode *inode,
1447+
void __audit_inode_child(const char *dname, const struct dentry *dentry,
14471448
const struct inode *parent)
14481449
{
14491450
int idx;
14501451
struct audit_context *context = current->audit_context;
14511452
const char *found_parent = NULL, *found_child = NULL;
1453+
const struct inode *inode = dentry->d_inode;
14521454
int dirlen = 0;
14531455

14541456
if (!context->in_syscall)

0 commit comments

Comments
 (0)