Skip to content

Commit d7481b2

Browse files
rgbriggspcmoore
authored andcommitted
audit: issue CWD record to accompany LSM_AUDIT_DATA_* records
The LSM_AUDIT_DATA_* records for PATH, FILE, IOCTL_OP, DENTRY and INODE are incomplete without the task context of the AUDIT Current Working Directory record. Add it. This record addition can't use audit_dummy_context to determine whether or not to store the record information since the LSM_AUDIT_DATA_* records are initiated by various LSMs independent of any audit rules. context->in_syscall is used to determine if it was called in user context like audit_getname. Please see the upstream issue linux-audit/audit-kernel#96 Adapted from Vladis Dronov's v2 patch. Signed-off-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 68df2ed commit d7481b2

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

include/linux/audit.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
292292
extern void __audit_syscall_exit(int ret_success, long ret_value);
293293
extern struct filename *__audit_reusename(const __user char *uptr);
294294
extern void __audit_getname(struct filename *name);
295-
295+
extern void __audit_getcwd(void);
296296
extern void __audit_inode(struct filename *name, const struct dentry *dentry,
297297
unsigned int flags);
298298
extern void __audit_file(const struct file *);
@@ -351,6 +351,11 @@ static inline void audit_getname(struct filename *name)
351351
if (unlikely(!audit_dummy_context()))
352352
__audit_getname(name);
353353
}
354+
static inline void audit_getcwd(void)
355+
{
356+
if (unlikely(audit_context()))
357+
__audit_getcwd();
358+
}
354359
static inline void audit_inode(struct filename *name,
355360
const struct dentry *dentry,
356361
unsigned int aflags) {
@@ -579,6 +584,8 @@ static inline struct filename *audit_reusename(const __user char *name)
579584
}
580585
static inline void audit_getname(struct filename *name)
581586
{ }
587+
static inline void audit_getcwd(void)
588+
{ }
582589
static inline void audit_inode(struct filename *name,
583590
const struct dentry *dentry,
584591
unsigned int aflags)

kernel/auditsc.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,20 @@ __audit_reusename(const __user char *uptr)
18911891
return NULL;
18921892
}
18931893

1894+
inline void _audit_getcwd(struct audit_context *context)
1895+
{
1896+
if (!context->pwd.dentry)
1897+
get_fs_pwd(current->fs, &context->pwd);
1898+
}
1899+
1900+
void __audit_getcwd(void)
1901+
{
1902+
struct audit_context *context = audit_context();
1903+
1904+
if (context->in_syscall)
1905+
_audit_getcwd(context);
1906+
}
1907+
18941908
/**
18951909
* __audit_getname - add a name to the list
18961910
* @name: name to add
@@ -1915,8 +1929,7 @@ void __audit_getname(struct filename *name)
19151929
name->aname = n;
19161930
name->refcnt++;
19171931

1918-
if (!context->pwd.dentry)
1919-
get_fs_pwd(current->fs, &context->pwd);
1932+
_audit_getcwd(context);
19201933
}
19211934

19221935
static inline int audit_copy_fcaps(struct audit_names *name,

security/lsm_audit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
241241
audit_log_untrustedstring(ab, inode->i_sb->s_id);
242242
audit_log_format(ab, " ino=%lu", inode->i_ino);
243243
}
244+
audit_getcwd();
244245
break;
245246
}
246247
case LSM_AUDIT_DATA_FILE: {
@@ -254,6 +255,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
254255
audit_log_untrustedstring(ab, inode->i_sb->s_id);
255256
audit_log_format(ab, " ino=%lu", inode->i_ino);
256257
}
258+
audit_getcwd();
257259
break;
258260
}
259261
case LSM_AUDIT_DATA_IOCTL_OP: {
@@ -269,6 +271,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
269271
}
270272

271273
audit_log_format(ab, " ioctlcmd=0x%hx", a->u.op->cmd);
274+
audit_getcwd();
272275
break;
273276
}
274277
case LSM_AUDIT_DATA_DENTRY: {
@@ -283,6 +286,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
283286
audit_log_untrustedstring(ab, inode->i_sb->s_id);
284287
audit_log_format(ab, " ino=%lu", inode->i_ino);
285288
}
289+
audit_getcwd();
286290
break;
287291
}
288292
case LSM_AUDIT_DATA_INODE: {
@@ -300,6 +304,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
300304
audit_log_format(ab, " dev=");
301305
audit_log_untrustedstring(ab, inode->i_sb->s_id);
302306
audit_log_format(ab, " ino=%lu", inode->i_ino);
307+
audit_getcwd();
303308
break;
304309
}
305310
case LSM_AUDIT_DATA_TASK: {

0 commit comments

Comments
 (0)