Skip to content

Commit 3eaded8

Browse files
committed
Merge git://git.infradead.org/users/eparis/audit
Pull audit updates from Eric Paris: "Nothing amazing. Formatting, small bug fixes, couple of fixes where we didn't get records due to some old VFS changes, and a change to how we collect execve info..." Fixed conflict in fs/exec.c as per Eric and linux-next. * git://git.infradead.org/users/eparis/audit: (28 commits) audit: fix type of sessionid in audit_set_loginuid() audit: call audit_bprm() only once to add AUDIT_EXECVE information audit: move audit_aux_data_execve contents into audit_context union audit: remove unused envc member of audit_aux_data_execve audit: Kill the unused struct audit_aux_data_capset audit: do not reject all AUDIT_INODE filter types audit: suppress stock memalloc failure warnings since already managed audit: log the audit_names record type audit: add child record before the create to handle case where create fails audit: use given values in tty_audit enable api audit: use nlmsg_len() to get message payload length audit: use memset instead of trying to initialize field by field audit: fix info leak in AUDIT_GET requests audit: update AUDIT_INODE filter rule to comparator function audit: audit feature to set loginuid immutable audit: audit feature to only allow unsetting the loginuid audit: allow unsetting the loginuid (with priv) audit: remove CONFIG_AUDIT_LOGINUID_IMMUTABLE audit: loginuid functions coding style selinux: apply selinux checks on new audit message types ...
2 parents 527d151 + 9175c9d commit 3eaded8

12 files changed

Lines changed: 259 additions & 113 deletions

File tree

‎fs/exec.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,10 +1380,6 @@ int search_binary_handler(struct linux_binprm *bprm)
13801380
if (retval)
13811381
return retval;
13821382

1383-
retval = audit_bprm(bprm);
1384-
if (retval)
1385-
return retval;
1386-
13871383
retval = -ENOENT;
13881384
retry:
13891385
read_lock(&binfmt_lock);
@@ -1431,6 +1427,7 @@ static int exec_binprm(struct linux_binprm *bprm)
14311427

14321428
ret = search_binary_handler(bprm);
14331429
if (ret >= 0) {
1430+
audit_bprm(bprm);
14341431
trace_sched_process_exec(current, old_pid, bprm);
14351432
ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
14361433
current->did_exec = 1;

‎fs/namei.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
24352435
*/
24362436
static inline int may_create(struct inode *dir, struct dentry *child)
24372437
{
2438+
audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
24382439
if (child->d_inode)
24392440
return -EEXIST;
24402441
if (IS_DEADDIR(dir))

‎fs/proc/base.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,16 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
11511151
goto out_free_page;
11521152

11531153
}
1154-
kloginuid = make_kuid(file->f_cred->user_ns, loginuid);
1155-
if (!uid_valid(kloginuid)) {
1156-
length = -EINVAL;
1157-
goto out_free_page;
1154+
1155+
/* is userspace tring to explicitly UNSET the loginuid? */
1156+
if (loginuid == AUDIT_UID_UNSET) {
1157+
kloginuid = INVALID_UID;
1158+
} else {
1159+
kloginuid = make_kuid(file->f_cred->user_ns, loginuid);
1160+
if (!uid_valid(kloginuid)) {
1161+
length = -EINVAL;
1162+
goto out_free_page;
1163+
}
11581164
}
11591165

11601166
length = audit_set_loginuid(kloginuid);

‎include/linux/audit.h‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct audit_field {
7373
void *lsm_rule;
7474
};
7575

76+
extern int is_audit_feature_set(int which);
77+
7678
extern int __init audit_register_class(int class, unsigned *list);
7779
extern int audit_classify_syscall(int abi, unsigned syscall);
7880
extern int audit_classify_arch(int arch);
@@ -207,7 +209,7 @@ static inline int audit_get_sessionid(struct task_struct *tsk)
207209

208210
extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
209211
extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
210-
extern int __audit_bprm(struct linux_binprm *bprm);
212+
extern void __audit_bprm(struct linux_binprm *bprm);
211213
extern int __audit_socketcall(int nargs, unsigned long *args);
212214
extern int __audit_sockaddr(int len, void *addr);
213215
extern void __audit_fd_pair(int fd1, int fd2);
@@ -236,11 +238,10 @@ static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid
236238
if (unlikely(!audit_dummy_context()))
237239
__audit_ipc_set_perm(qbytes, uid, gid, mode);
238240
}
239-
static inline int audit_bprm(struct linux_binprm *bprm)
241+
static inline void audit_bprm(struct linux_binprm *bprm)
240242
{
241243
if (unlikely(!audit_dummy_context()))
242-
return __audit_bprm(bprm);
243-
return 0;
244+
__audit_bprm(bprm);
244245
}
245246
static inline int audit_socketcall(int nargs, unsigned long *args)
246247
{
@@ -367,10 +368,8 @@ static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
367368
static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
368369
gid_t gid, umode_t mode)
369370
{ }
370-
static inline int audit_bprm(struct linux_binprm *bprm)
371-
{
372-
return 0;
373-
}
371+
static inline void audit_bprm(struct linux_binprm *bprm)
372+
{ }
374373
static inline int audit_socketcall(int nargs, unsigned long *args)
375374
{
376375
return 0;

‎include/uapi/linux/audit.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
#define AUDIT_MAKE_EQUIV 1015 /* Append to watched tree */
6969
#define AUDIT_TTY_GET 1016 /* Get TTY auditing status */
7070
#define AUDIT_TTY_SET 1017 /* Set TTY auditing status */
71+
#define AUDIT_SET_FEATURE 1018 /* Turn an audit feature on or off */
72+
#define AUDIT_GET_FEATURE 1019 /* Get which features are enabled */
73+
#define AUDIT_FEATURE_CHANGE 1020 /* audit log listing feature changes */
7174

7275
#define AUDIT_FIRST_USER_MSG 1100 /* Userspace messages mostly uninteresting to kernel */
7376
#define AUDIT_USER_AVC 1107 /* We filter this differently */
@@ -357,6 +360,12 @@ enum {
357360
#define AUDIT_PERM_READ 4
358361
#define AUDIT_PERM_ATTR 8
359362

363+
/* MAX_AUDIT_MESSAGE_LENGTH is set in audit:lib/libaudit.h as:
364+
* 8970 // PATH_MAX*2+CONTEXT_SIZE*2+11+256+1
365+
* max header+body+tailer: 44 + 29 + 32 + 262 + 7 + pad
366+
*/
367+
#define AUDIT_MESSAGE_TEXT_MAX 8560
368+
360369
struct audit_status {
361370
__u32 mask; /* Bit mask for valid entries */
362371
__u32 enabled; /* 1 = enabled, 0 = disabled */
@@ -368,11 +377,28 @@ struct audit_status {
368377
__u32 backlog; /* messages waiting in queue */
369378
};
370379

380+
struct audit_features {
381+
#define AUDIT_FEATURE_VERSION 1
382+
__u32 vers;
383+
__u32 mask; /* which bits we are dealing with */
384+
__u32 features; /* which feature to enable/disable */
385+
__u32 lock; /* which features to lock */
386+
};
387+
388+
#define AUDIT_FEATURE_ONLY_UNSET_LOGINUID 0
389+
#define AUDIT_FEATURE_LOGINUID_IMMUTABLE 1
390+
#define AUDIT_LAST_FEATURE AUDIT_FEATURE_LOGINUID_IMMUTABLE
391+
392+
#define audit_feature_valid(x) ((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
393+
#define AUDIT_FEATURE_TO_MASK(x) (1 << ((x) & 31)) /* mask for __u32 */
394+
371395
struct audit_tty_status {
372396
__u32 enabled; /* 1 = enabled, 0 = disabled */
373397
__u32 log_passwd; /* 1 = enabled, 0 = disabled */
374398
};
375399

400+
#define AUDIT_UID_UNSET (unsigned int)-1
401+
376402
/* audit_rule_data supports filter rules with both integer and string
377403
* fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and
378404
* AUDIT_LIST_RULES requests.

‎init/Kconfig‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,6 @@ config AUDIT_TREE
301301
depends on AUDITSYSCALL
302302
select FSNOTIFY
303303

304-
config AUDIT_LOGINUID_IMMUTABLE
305-
bool "Make audit loginuid immutable"
306-
depends on AUDIT
307-
help
308-
The config option toggles if a task setting its loginuid requires
309-
CAP_SYS_AUDITCONTROL or if that task should require no special permissions
310-
but should instead only allow setting its loginuid if it was never
311-
previously set. On systems which use systemd or a similar central
312-
process to restart login services this should be set to true. On older
313-
systems in which an admin would typically have to directly stop and
314-
start processes this should be set to false. Setting this to true allows
315-
one to drop potentially dangerous capabilites from the login tasks,
316-
but may not be backwards compatible with older init systems.
317-
318304
source "kernel/irq/Kconfig"
319305
source "kernel/time/Kconfig"
320306

0 commit comments

Comments
 (0)