Commit 6dd9158a authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.infradead.org/users/eparis/audit

Pull audit update from Eric Paris:
 "Again we stayed pretty well contained inside the audit system.
  Venturing out was fixing a couple of function prototypes which were
  inconsistent (didn't hurt anything, but we used the same value as an
  int, uint, u32, and I think even a long in a couple of places).

  We also made a couple of minor changes to when a couple of LSMs called
  the audit system.  We hoped to add aarch64 audit support this go
  round, but it wasn't ready.

  I'm disappearing on vacation on Thursday.  I should have internet
  access, but it'll be spotty.  If anything goes wrong please be sure to
  cc rgb@redhat.com.  He'll make fixing things his top priority"

* git://git.infradead.org/users/eparis/audit: (50 commits)
  audit: whitespace fix in kernel-parameters.txt
  audit: fix location of __net_initdata for audit_net_ops
  audit: remove pr_info for every network namespace
  audit: Modify a set of system calls in audit class definitions
  audit: Convert int limit uses to u32
  audit: Use more current logging style
  audit: Use hex_byte_pack_upper
  audit: correct a type mismatch in audit_syscall_exit()
  audit: reorder AUDIT_TTY_SET arguments
  audit: rework AUDIT_TTY_SET to only grab spin_lock once
  audit: remove needless switch in AUDIT_SET
  audit: use define's for audit version
  audit: documentation of audit= kernel parameter
  audit: wait_for_auditd rework for readability
  audit: update MAINTAINERS
  audit: log task info on feature change
  audit: fix incorrect set of audit_sock
  audit: print error message when fail to create audit socket
  audit: fix dangling keywords in audit_log_set_loginuid() output
  audit: log on errors from filter user rules
  ...
parents 90804ed6 f3411cb2
...@@ -463,6 +463,22 @@ bytes respectively. Such letter suffixes can also be entirely omitted. ...@@ -463,6 +463,22 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
atkbd.softrepeat= [HW] atkbd.softrepeat= [HW]
Use software keyboard repeat Use software keyboard repeat
audit= [KNL] Enable the audit sub-system
Format: { "0" | "1" } (0 = disabled, 1 = enabled)
0 - kernel audit is disabled and can not be enabled
until the next reboot
unset - kernel audit is initialized but disabled and
will be fully enabled by the userspace auditd.
1 - kernel audit is initialized and partially enabled,
storing at most audit_backlog_limit messages in
RAM until it is fully enabled by the userspace
auditd.
Default: unset
audit_backlog_limit= [KNL] Set the audit queue size limit.
Format: <int> (must be >=0)
Default: 64
baycom_epp= [HW,AX25] baycom_epp= [HW,AX25]
Format: <io>,<mode> Format: <io>,<mode>
......
...@@ -1597,11 +1597,10 @@ S: Supported ...@@ -1597,11 +1597,10 @@ S: Supported
F: drivers/scsi/esas2r F: drivers/scsi/esas2r
AUDIT SUBSYSTEM AUDIT SUBSYSTEM
M: Al Viro <viro@zeniv.linux.org.uk>
M: Eric Paris <eparis@redhat.com> M: Eric Paris <eparis@redhat.com>
L: linux-audit@redhat.com (subscribers-only) L: linux-audit@redhat.com (subscribers-only)
W: http://people.redhat.com/sgrubb/audit/ W: http://people.redhat.com/sgrubb/audit/
T: git git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current.git T: git git://git.infradead.org/users/eparis/audit.git
S: Maintained S: Maintained
F: include/linux/audit.h F: include/linux/audit.h
F: include/uapi/linux/audit.h F: include/uapi/linux/audit.h
......
...@@ -67,7 +67,7 @@ static void tty_audit_log(const char *description, int major, int minor, ...@@ -67,7 +67,7 @@ static void tty_audit_log(const char *description, int major, int minor,
struct task_struct *tsk = current; struct task_struct *tsk = current;
uid_t uid = from_kuid(&init_user_ns, task_uid(tsk)); uid_t uid = from_kuid(&init_user_ns, task_uid(tsk));
uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(tsk)); uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(tsk));
u32 sessionid = audit_get_sessionid(tsk); unsigned int sessionid = audit_get_sessionid(tsk);
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY);
if (ab) { if (ab) {
......
...@@ -4,9 +4,11 @@ __NR_chmod, ...@@ -4,9 +4,11 @@ __NR_chmod,
__NR_fchmod, __NR_fchmod,
#ifdef __NR_chown #ifdef __NR_chown
__NR_chown, __NR_chown,
__NR_fchown,
__NR_lchown, __NR_lchown,
#endif #endif
#ifdef __NR_fchown
__NR_fchown,
#endif
__NR_setxattr, __NR_setxattr,
__NR_lsetxattr, __NR_lsetxattr,
__NR_fsetxattr, __NR_fsetxattr,
......
...@@ -10,6 +10,12 @@ __NR_truncate, ...@@ -10,6 +10,12 @@ __NR_truncate,
#ifdef __NR_truncate64 #ifdef __NR_truncate64
__NR_truncate64, __NR_truncate64,
#endif #endif
#ifdef __NR_ftruncate
__NR_ftruncate,
#endif
#ifdef __NR_ftruncate64
__NR_ftruncate64,
#endif
#ifdef __NR_bind #ifdef __NR_bind
__NR_bind, /* bind can affect fs object only in one way... */ __NR_bind, /* bind can affect fs object only in one way... */
#endif #endif
...@@ -137,7 +137,7 @@ static inline void audit_syscall_exit(void *pt_regs) ...@@ -137,7 +137,7 @@ static inline void audit_syscall_exit(void *pt_regs)
{ {
if (unlikely(current->audit_context)) { if (unlikely(current->audit_context)) {
int success = is_syscall_success(pt_regs); int success = is_syscall_success(pt_regs);
int return_code = regs_return_value(pt_regs); long return_code = regs_return_value(pt_regs);
__audit_syscall_exit(success, return_code); __audit_syscall_exit(success, return_code);
} }
...@@ -202,7 +202,7 @@ static inline kuid_t audit_get_loginuid(struct task_struct *tsk) ...@@ -202,7 +202,7 @@ static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
return tsk->loginuid; return tsk->loginuid;
} }
static inline int audit_get_sessionid(struct task_struct *tsk) static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
{ {
return tsk->sessionid; return tsk->sessionid;
} }
...@@ -220,7 +220,7 @@ extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat); ...@@ -220,7 +220,7 @@ extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm, extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
const struct cred *new, const struct cred *new,
const struct cred *old); const struct cred *old);
extern void __audit_log_capset(pid_t pid, const struct cred *new, const struct cred *old); extern void __audit_log_capset(const struct cred *new, const struct cred *old);
extern void __audit_mmap_fd(int fd, int flags); extern void __audit_mmap_fd(int fd, int flags);
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp) static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
...@@ -285,11 +285,11 @@ static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm, ...@@ -285,11 +285,11 @@ static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
return 0; return 0;
} }
static inline void audit_log_capset(pid_t pid, const struct cred *new, static inline void audit_log_capset(const struct cred *new,
const struct cred *old) const struct cred *old)
{ {
if (unlikely(!audit_dummy_context())) if (unlikely(!audit_dummy_context()))
__audit_log_capset(pid, new, old); __audit_log_capset(new, old);
} }
static inline void audit_mmap_fd(int fd, int flags) static inline void audit_mmap_fd(int fd, int flags)
...@@ -359,7 +359,7 @@ static inline kuid_t audit_get_loginuid(struct task_struct *tsk) ...@@ -359,7 +359,7 @@ static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
{ {
return INVALID_UID; return INVALID_UID;
} }
static inline int audit_get_sessionid(struct task_struct *tsk) static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
{ {
return -1; return -1;
} }
...@@ -397,8 +397,8 @@ static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm, ...@@ -397,8 +397,8 @@ static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
{ {
return 0; return 0;
} }
static inline void audit_log_capset(pid_t pid, const struct cred *new, static inline void audit_log_capset(const struct cred *new,
const struct cred *old) const struct cred *old)
{ } { }
static inline void audit_mmap_fd(int fd, int flags) static inline void audit_mmap_fd(int fd, int flags)
{ } { }
...@@ -461,9 +461,11 @@ extern int audit_update_lsm_rules(void); ...@@ -461,9 +461,11 @@ extern int audit_update_lsm_rules(void);
/* Private API (for audit.c only) */ /* Private API (for audit.c only) */
extern int audit_filter_user(int type); extern int audit_filter_user(int type);
extern int audit_filter_type(int type); extern int audit_filter_type(int type);
extern int audit_receive_filter(int type, int pid, int seq, extern int audit_rule_change(int type, __u32 portid, int seq,
void *data, size_t datasz); void *data, size_t datasz);
extern int audit_enabled; extern int audit_list_rules_send(__u32 portid, int seq);
extern u32 audit_enabled;
#else /* CONFIG_AUDIT */ #else /* CONFIG_AUDIT */
static inline __printf(4, 5) static inline __printf(4, 5)
void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type, void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
......
...@@ -97,7 +97,7 @@ extern struct group_info init_groups; ...@@ -97,7 +97,7 @@ extern struct group_info init_groups;
#ifdef CONFIG_AUDITSYSCALL #ifdef CONFIG_AUDITSYSCALL
#define INIT_IDS \ #define INIT_IDS \
.loginuid = INVALID_UID, \ .loginuid = INVALID_UID, \
.sessionid = -1, .sessionid = (unsigned int)-1,
#else #else
#define INIT_IDS #define INIT_IDS
#endif #endif
......
...@@ -111,7 +111,7 @@ struct cipso_v4_doi; ...@@ -111,7 +111,7 @@ struct cipso_v4_doi;
struct netlbl_audit { struct netlbl_audit {
u32 secid; u32 secid;
kuid_t loginuid; kuid_t loginuid;
u32 sessionid; unsigned int sessionid;
}; };
/* /*
......
...@@ -681,7 +681,7 @@ struct xfrm_spi_skb_cb { ...@@ -681,7 +681,7 @@ struct xfrm_spi_skb_cb {
struct xfrm_audit { struct xfrm_audit {
u32 secid; u32 secid;
kuid_t loginuid; kuid_t loginuid;
u32 sessionid; unsigned int sessionid;
}; };
#ifdef CONFIG_AUDITSYSCALL #ifdef CONFIG_AUDITSYSCALL
...@@ -699,7 +699,7 @@ static inline struct audit_buffer *xfrm_audit_start(const char *op) ...@@ -699,7 +699,7 @@ static inline struct audit_buffer *xfrm_audit_start(const char *op)
return audit_buf; return audit_buf;
} }
static inline void xfrm_audit_helper_usrinfo(kuid_t auid, u32 ses, u32 secid, static inline void xfrm_audit_helper_usrinfo(kuid_t auid, unsigned int ses, u32 secid,
struct audit_buffer *audit_buf) struct audit_buffer *audit_buf)
{ {
char *secctx; char *secctx;
...@@ -716,13 +716,13 @@ static inline void xfrm_audit_helper_usrinfo(kuid_t auid, u32 ses, u32 secid, ...@@ -716,13 +716,13 @@ static inline void xfrm_audit_helper_usrinfo(kuid_t auid, u32 ses, u32 secid,
} }
void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, kuid_t auid, void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, kuid_t auid,
u32 ses, u32 secid); unsigned int ses, u32 secid);
void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result, kuid_t auid, void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result, kuid_t auid,
u32 ses, u32 secid); unsigned int ses, u32 secid);
void xfrm_audit_state_add(struct xfrm_state *x, int result, kuid_t auid, void xfrm_audit_state_add(struct xfrm_state *x, int result, kuid_t auid,
u32 ses, u32 secid); unsigned int ses, u32 secid);
void xfrm_audit_state_delete(struct xfrm_state *x, int result, kuid_t auid, void xfrm_audit_state_delete(struct xfrm_state *x, int result, kuid_t auid,
u32 ses, u32 secid); unsigned int ses, u32 secid);
void xfrm_audit_state_replay_overflow(struct xfrm_state *x, void xfrm_audit_state_replay_overflow(struct xfrm_state *x,
struct sk_buff *skb); struct sk_buff *skb);
void xfrm_audit_state_replay(struct xfrm_state *x, struct sk_buff *skb, void xfrm_audit_state_replay(struct xfrm_state *x, struct sk_buff *skb,
...@@ -735,22 +735,22 @@ void xfrm_audit_state_icvfail(struct xfrm_state *x, struct sk_buff *skb, ...@@ -735,22 +735,22 @@ void xfrm_audit_state_icvfail(struct xfrm_state *x, struct sk_buff *skb,
#else #else
static inline void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, static inline void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
kuid_t auid, u32 ses, u32 secid) kuid_t auid, unsigned int ses, u32 secid)
{ {
} }
static inline void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result, static inline void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
kuid_t auid, u32 ses, u32 secid) kuid_t auid, unsigned int ses, u32 secid)
{ {
} }
static inline void xfrm_audit_state_add(struct xfrm_state *x, int result, static inline void xfrm_audit_state_add(struct xfrm_state *x, int result,
kuid_t auid, u32 ses, u32 secid) kuid_t auid, unsigned int ses, u32 secid)
{ {
} }
static inline void xfrm_audit_state_delete(struct xfrm_state *x, int result, static inline void xfrm_audit_state_delete(struct xfrm_state *x, int result,
kuid_t auid, u32 ses, u32 secid) kuid_t auid, unsigned int ses, u32 secid)
{ {
} }
......
...@@ -319,6 +319,12 @@ enum { ...@@ -319,6 +319,12 @@ enum {
#define AUDIT_STATUS_PID 0x0004 #define AUDIT_STATUS_PID 0x0004
#define AUDIT_STATUS_RATE_LIMIT 0x0008 #define AUDIT_STATUS_RATE_LIMIT 0x0008
#define AUDIT_STATUS_BACKLOG_LIMIT 0x0010 #define AUDIT_STATUS_BACKLOG_LIMIT 0x0010
#define AUDIT_STATUS_BACKLOG_WAIT_TIME 0x0020
#define AUDIT_VERSION_BACKLOG_LIMIT 1
#define AUDIT_VERSION_BACKLOG_WAIT_TIME 2
#define AUDIT_VERSION_LATEST AUDIT_VERSION_BACKLOG_WAIT_TIME
/* Failure-to-log actions */ /* Failure-to-log actions */
#define AUDIT_FAIL_SILENT 0 #define AUDIT_FAIL_SILENT 0
#define AUDIT_FAIL_PRINTK 1 #define AUDIT_FAIL_PRINTK 1
...@@ -375,6 +381,8 @@ struct audit_status { ...@@ -375,6 +381,8 @@ struct audit_status {
__u32 backlog_limit; /* waiting messages limit */ __u32 backlog_limit; /* waiting messages limit */
__u32 lost; /* messages lost */ __u32 lost; /* messages lost */
__u32 backlog; /* messages waiting in queue */ __u32 backlog; /* messages waiting in queue */
__u32 version; /* audit api version number */
__u32 backlog_wait_time;/* message queue wait timeout */
}; };
struct audit_features { struct audit_features {
......
This diff is collapsed.
...@@ -209,7 +209,7 @@ struct audit_context { ...@@ -209,7 +209,7 @@ struct audit_context {
#endif #endif
}; };
extern int audit_ever_enabled; extern u32 audit_ever_enabled;
extern void audit_copy_inode(struct audit_names *name, extern void audit_copy_inode(struct audit_names *name,
const struct dentry *dentry, const struct dentry *dentry,
...@@ -240,18 +240,23 @@ extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right); ...@@ -240,18 +240,23 @@ extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right);
extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right); extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right);
extern int parent_len(const char *path); extern int parent_len(const char *path);
extern int audit_compare_dname_path(const char *dname, const char *path, int plen); extern int audit_compare_dname_path(const char *dname, const char *path, int plen);
extern struct sk_buff * audit_make_reply(int pid, int seq, int type, extern struct sk_buff *audit_make_reply(__u32 portid, int seq, int type,
int done, int multi, int done, int multi,
const void *payload, int size); const void *payload, int size);
extern void audit_panic(const char *message); extern void audit_panic(const char *message);
struct audit_netlink_list { struct audit_netlink_list {
int pid; __u32 portid;
pid_t pid;
struct sk_buff_head q; struct sk_buff_head q;
}; };
int audit_send_list(void *); int audit_send_list(void *);
struct audit_net {
struct sock *nlsk;
};
extern int selinux_audit_rule_update(void); extern int selinux_audit_rule_update(void);
extern struct mutex audit_filter_mutex; extern struct mutex audit_filter_mutex;
......
...@@ -972,7 +972,7 @@ static inline int audit_del_rule(struct audit_entry *entry) ...@@ -972,7 +972,7 @@ static inline int audit_del_rule(struct audit_entry *entry)
} }
/* List rules using struct audit_rule_data. */ /* List rules using struct audit_rule_data. */
static void audit_list_rules(int pid, int seq, struct sk_buff_head *q) static void audit_list_rules(__u32 portid, int seq, struct sk_buff_head *q)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct audit_krule *r; struct audit_krule *r;
...@@ -987,14 +987,15 @@ static void audit_list_rules(int pid, int seq, struct sk_buff_head *q) ...@@ -987,14 +987,15 @@ static void audit_list_rules(int pid, int seq, struct sk_buff_head *q)
data = audit_krule_to_data(r); data = audit_krule_to_data(r);
if (unlikely(!data)) if (unlikely(!data))
break; break;
skb = audit_make_reply(pid, seq, AUDIT_LIST_RULES, 0, 1, skb = audit_make_reply(portid, seq, AUDIT_LIST_RULES,
data, sizeof(*data) + data->buflen); 0, 1, data,
sizeof(*data) + data->buflen);
if (skb) if (skb)
skb_queue_tail(q, skb); skb_queue_tail(q, skb);
kfree(data); kfree(data);
} }
} }
skb = audit_make_reply(pid, seq, AUDIT_LIST_RULES, 1, 1, NULL, 0); skb = audit_make_reply(portid, seq, AUDIT_LIST_RULES, 1, 1, NULL, 0);
if (skb) if (skb)
skb_queue_tail(q, skb); skb_queue_tail(q, skb);
} }
...@@ -1004,7 +1005,7 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re ...@@ -1004,7 +1005,7 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re
{ {
struct audit_buffer *ab; struct audit_buffer *ab;
uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current)); uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current));
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
if (!audit_enabled) if (!audit_enabled)
return; return;
...@@ -1022,45 +1023,20 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re ...@@ -1022,45 +1023,20 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re
} }
/** /**
* audit_receive_filter - apply all rules to the specified message type * audit_rule_change - apply all rules to the specified message type
* @type: audit message type * @type: audit message type
* @pid: target pid for netlink audit messages * @portid: target port id for netlink audit messages
* @seq: netlink audit message sequence (serial) number * @seq: netlink audit message sequence (serial) number
* @data: payload data * @data: payload data
* @datasz: size of payload data * @datasz: size of payload data
*/ */
int audit_receive_filter(int type, int pid, int seq, void *data, size_t datasz) int audit_rule_change(int type, __u32 portid, int seq, void *data,
size_t datasz)
{ {
struct task_struct *tsk;
struct audit_netlink_list *dest;
int err = 0; int err = 0;
struct audit_entry *entry; struct audit_entry *entry;
switch (type) { switch (type) {
case AUDIT_LIST_RULES:
/* We can't just spew out the rules here because we might fill
* the available socket buffer space and deadlock waiting for
* auditctl to read from it... which isn't ever going to
* happen if we're actually running in the context of auditctl
* trying to _send_ the stuff */
dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL);
if (!dest)
return -ENOMEM;
dest->pid = pid;
skb_queue_head_init(&dest->q);
mutex_lock(&audit_filter_mutex);
audit_list_rules(pid, seq, &dest->q);
mutex_unlock(&audit_filter_mutex);
tsk = kthread_run(audit_send_list, dest, "audit_send_list");
if (IS_ERR(tsk)) {
skb_queue_purge(&dest->q);
kfree(dest);
err = PTR_ERR(tsk);
}
break;
case AUDIT_ADD_RULE: case AUDIT_ADD_RULE:
entry = audit_data_to_entry(data, datasz); entry = audit_data_to_entry(data, datasz);
if (IS_ERR(entry)) if (IS_ERR(entry))
...@@ -1087,6 +1063,44 @@ int audit_receive_filter(int type, int pid, int seq, void *data, size_t datasz) ...@@ -1087,6 +1063,44 @@ int audit_receive_filter(int type, int pid, int seq, void *data, size_t datasz)
return err; return err;
} }
/**
* audit_list_rules_send - list the audit rules
* @portid: target portid for netlink audit messages
* @seq: netlink audit message sequence (serial) number
*/
int audit_list_rules_send(__u32 portid, int seq)
{
struct task_struct *tsk;
struct audit_netlink_list *dest;
int err = 0;
/* We can't just spew out the rules here because we might fill
* the available socket buffer space and deadlock waiting for
* auditctl to read from it... which isn't ever going to
* happen if we're actually running in the context of auditctl
* trying to _send_ the stuff */
dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL);
if (!dest)
return -ENOMEM;
dest->portid = portid;
dest->pid = task_pid_vnr(current);
skb_queue_head_init(&dest->q);
mutex_lock(&audit_filter_mutex);
audit_list_rules(portid, seq, &dest->q);
mutex_unlock(&audit_filter_mutex);
tsk = kthread_run(audit_send_list, dest, "audit_send_list");
if (IS_ERR(tsk)) {
skb_queue_purge(&dest->q);
kfree(dest);
err = PTR_ERR(tsk);
}
return err;
}
int audit_comparator(u32 left, u32 op, u32 right) int audit_comparator(u32 left, u32 op, u32 right)
{ {
switch (op) { switch (op) {
...@@ -1276,19 +1290,22 @@ int audit_filter_user(int type) ...@@ -1276,19 +1290,22 @@ int audit_filter_user(int type)
{ {
enum audit_state state = AUDIT_DISABLED; enum audit_state state = AUDIT_DISABLED;
struct audit_entry *e; struct audit_entry *e;
int ret = 1; int rc, ret;
ret = 1; /* Audit by default */
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_USER], list) { list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_USER], list) {
if (audit_filter_user_rules(&e->rule, type, &state)) { rc = audit_filter_user_rules(&e->rule, type, &state);
if (state == AUDIT_DISABLED) if (rc) {
if (rc > 0 && state == AUDIT_DISABLED)
ret = 0; ret = 0;
break; break;
} }
} }
rcu_read_unlock(); rcu_read_unlock();
return ret; /* Audit by default */ return ret;
} }
int audit_filter_type(int type) int audit_filter_type(int type)
......
...@@ -1969,18 +1969,24 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid, ...@@ -1969,18 +1969,24 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
int rc) int rc)
{ {
struct audit_buffer *ab; struct audit_buffer *ab;
uid_t uid, ologinuid, nloginuid; uid_t uid, oldloginuid, loginuid;
if (!audit_enabled)
return;
uid = from_kuid(&init_user_ns, task_uid(current)); uid = from_kuid(&init_user_ns, task_uid(current));
ologinuid = from_kuid(&init_user_ns, koldloginuid); oldloginuid = from_kuid(&init_user_ns, koldloginuid);
nloginuid = from_kuid(&init_user_ns, kloginuid), loginuid = from_kuid(&init_user_ns, kloginuid),
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN); ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
if (!ab) if (!ab)
return; return;
audit_log_format(ab, "pid=%d uid=%u old auid=%u new auid=%u old " audit_log_format(ab, "pid=%d uid=%u"
"ses=%u new ses=%u res=%d", current->pid, uid, ologinuid, " old-auid=%u new-auid=%u old-ses=%u new-ses=%u"
nloginuid, oldsessionid, sessionid, !rc); " res=%d",
current->pid, uid,
oldloginuid, loginuid, oldsessionid, sessionid,
!rc);
audit_log_end(ab); audit_log_end(ab);
} }
...@@ -2008,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid) ...@@ -2008,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
/* are we setting or clearing? */ /* are we setting or clearing? */
if (uid_valid(loginuid)) if (uid_valid(loginuid))
sessionid = atomic_inc_return(&session_id); sessionid = (unsigned int)atomic_inc_return(&session_id);
task->sessionid = sessionid; task->sessionid = sessionid;
task->loginuid = loginuid; task->loginuid = loginuid;
...@@ -2321,18 +2327,16 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm, ...@@ -2321,18 +2327,16 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
/** /**
* __audit_log_capset - store information about the arguments to the capset syscall * __audit_log_capset - store information about the arguments to the capset syscall
* @pid: target pid of the capset call
* @new: the new credentials * @new: the new credentials
* @old: the old (current) credentials * @old: the old (current) credentials
* *
* Record the aguments userspace sent to sys_capset for later printing by the * Record the aguments userspace sent to sys_capset for later printing by the
* audit system if applicable * audit system if applicable
*/ */
void __audit_log_capset(pid_t pid, void __audit_log_capset(const struct cred *new, const struct cred *old)
const struct cred *new, const struct cred *old)
{ {
struct audit_context *context = current->audit_context; struct audit_context *context = current->audit_context;
context->capset.pid = pid; context->capset.pid = task_pid_nr(current);
context->capset.cap.effective = new->cap_effective; context->capset.cap.effective = new->cap_effective;
context->capset.cap.inheritable = new->cap_effective; context->capset.cap.inheritable = new->cap_effective;
context->capset.cap.permitted = new->cap_permitted; context->capset.cap.permitted = new->cap_permitted;
...@@ -2352,6 +2356,7 @@ static void audit_log_task(struct audit_buffer *ab) ...@@ -2352,6 +2356,7 @@ static void audit_log_task(struct audit_buffer *ab)
kuid_t auid, uid; kuid_t auid, uid;
kgid_t gid; kgid_t gid;
unsigned int sessionid; unsigned int sessionid;
struct mm_struct *mm = current->mm;
auid = audit_get_loginuid(current); auid = audit_get_loginuid(current);
sessionid = audit_get_sessionid(current); sessionid = audit_get_sessionid(current);
...@@ -2365,15 +2370,15 @@ static void audit_log_task(struct audit_buffer *ab) ...@@ -2365,15 +2370,15 @@ static void audit_log_task(struct audit_buffer *ab)
audit_log_task_context(ab); audit_log_task_context(ab);
audit_log_format(ab, " pid=%d comm=", current->pid); audit_log_format(ab, " pid=%d comm=", current->pid);
audit_log_untrustedstring(ab, current->comm); audit_log_untrustedstring(ab, current->comm);
if (mm) {
down_read(&mm->mmap_sem);
if (mm->exe_file)
audit_log_d_path(ab, " exe=", &mm->exe_file->f_path);
up_read(&mm->mmap_sem);
} else
audit_log_format(ab, " exe=(null)");
} }
static void audit_log_abend(struct audit_buffer *ab, char *reason, long signr)
{
audit_log_task(ab);
audit_log_format(ab, " reason=");
audit_log_string(ab, reason);
audit_log_format(ab, " sig=%ld", signr);
}
/** /**
* audit_core_dumps - record information about processes that end abnormally * audit_core_dumps - record information about processes that end abnormally
* @signr: signal value * @signr: signal value
...@@ -2394,7 +2399,8 @@ void audit_core_dumps(long signr) ...@@ -2394,7 +2399,8 @@ void audit_core_dumps(long signr)
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND); ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
if (unlikely(!ab)) if (unlikely(!ab))
return; return;
audit_log_abend(ab, "memory violation", signr); audit_log_task(ab);
audit_log_format(ab, " sig=%ld", signr);
audit_log_end(ab); audit_log_end(ab);
} }
......
...@@ -277,7 +277,7 @@ SYSCALL_DEFINE2(capset, cap_user_header_t, header, const cap_user_data_t, data) ...@@ -277,7 +277,7 @@ SYSCALL_DEFINE2(capset, cap_user_header_t, header, const cap_user_data_t, data)
if (ret < 0) if (ret < 0)
goto error; goto error;
audit_log_capset(pid, new, current_cred()); audit_log_capset(new, current_cred());
return commit_creds(new); return commit_creds(new);
......
...@@ -2906,12 +2906,12 @@ static void xfrm_policy_fini(struct net *net) ...@@ -2906,12 +2906,12 @@ static void xfrm_policy_fini(struct net *net)
flush_work(&net->xfrm.policy_hash_work); flush_work(&net->xfrm.policy_hash_work);
#ifdef CONFIG_XFRM_SUB_POLICY #ifdef CONFIG_XFRM_SUB_POLICY
audit_info.loginuid = INVALID_UID; audit_info.loginuid = INVALID_UID;
audit_info.sessionid = -1; audit_info.sessionid = (unsigned int)-1;
audit_info.secid = 0; audit_info.secid = 0;
xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, &audit_info); xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, &audit_info);
#endif #endif
audit_info.loginuid = INVALID_UID; audit_info.loginuid = INVALID_UID;
audit_info.sessionid = -1; audit_info.sessionid = (unsigned int)-1;
audit_info.secid = 0; audit_info.secid = 0;
xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info); xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info);
...@@ -3017,7 +3017,7 @@ static void xfrm_audit_common_policyinfo(struct xfrm_policy *xp, ...@@ -3017,7 +3017,7 @@ static void xfrm_audit_common_policyinfo(struct xfrm_policy *xp,
} }
void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
kuid_t auid, u32 sessionid, u32 secid) kuid_t auid, unsigned int sessionid, u32 secid)
{ {
struct audit_buffer *audit_buf; struct audit_buffer *audit_buf;
...@@ -3032,7 +3032,7 @@ void xfrm_audit_policy_add(struct xfrm_policy *xp, int result, ...@@ -3032,7 +3032,7 @@ void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
EXPORT_SYMBOL_GPL(xfrm_audit_policy_add); EXPORT_SYMBOL_GPL(xfrm_audit_policy_add);
void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result, void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
kuid_t auid, u32 sessionid, u32 secid) kuid_t auid, unsigned int sessionid, u32 secid)
{ {
struct audit_buffer *audit_buf; struct audit_buffer *audit_buf;
......
...@@ -2043,7 +2043,7 @@ void xfrm_state_fini(struct net *net) ...@@ -2043,7 +2043,7 @@ void xfrm_state_fini(struct net *net)
flush_work(&net->xfrm.state_hash_work); flush_work(&net->xfrm.state_hash_work);
audit_info.loginuid = INVALID_UID; audit_info.loginuid = INVALID_UID;
audit_info.sessionid = -1; audit_info.sessionid = (unsigned int)-1;
audit_info.secid = 0; audit_info.secid = 0;
xfrm_state_flush(net, IPSEC_PROTO_ANY, &audit_info); xfrm_state_flush(net, IPSEC_PROTO_ANY, &audit_info);
flush_work(&net->xfrm.state_gc_work); flush_work(&net->xfrm.state_gc_work);
...@@ -2109,7 +2109,7 @@ static void xfrm_audit_helper_pktinfo(struct sk_buff *skb, u16 family, ...@@ -2109,7 +2109,7 @@ static void xfrm_audit_helper_pktinfo(struct sk_buff *skb, u16 family,
} }
void xfrm_audit_state_add(struct xfrm_state *x, int result, void xfrm_audit_state_add(struct xfrm_state *x, int result,
kuid_t auid, u32 sessionid, u32 secid) kuid_t auid, unsigned int sessionid, u32 secid)
{ {
struct audit_buffer *audit_buf; struct audit_buffer *audit_buf;
...@@ -2124,7 +2124,7 @@ void xfrm_audit_state_add(struct xfrm_state *x, int result, ...@@ -2124,7 +2124,7 @@ void xfrm_audit_state_add(struct xfrm_state *x, int result,
EXPORT_SYMBOL_GPL(xfrm_audit_state_add); EXPORT_SYMBOL_GPL(xfrm_audit_state_add);
void xfrm_audit_state_delete(struct xfrm_state *x, int result, void xfrm_audit_state_delete(struct xfrm_state *x, int result,
kuid_t auid, u32 sessionid, u32 secid) kuid_t auid, unsigned int sessionid, u32 secid)
{ {
struct audit_buffer *audit_buf; struct audit_buffer *audit_buf;
......
...@@ -600,7 +600,7 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -600,7 +600,7 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
int err; int err;
struct km_event c; struct km_event c;
kuid_t loginuid = audit_get_loginuid(current); kuid_t loginuid = audit_get_loginuid(current);
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
u32 sid; u32 sid;
err = verify_newsa_info(p, attrs); err = verify_newsa_info(p, attrs);
...@@ -679,7 +679,7 @@ static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -679,7 +679,7 @@ static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
struct km_event c; struct km_event c;
struct xfrm_usersa_id *p = nlmsg_data(nlh); struct xfrm_usersa_id *p = nlmsg_data(nlh);
kuid_t loginuid = audit_get_loginuid(current); kuid_t loginuid = audit_get_loginuid(current);
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
u32 sid; u32 sid;
x = xfrm_user_state_lookup(net, p, attrs, &err); x = xfrm_user_state_lookup(net, p, attrs, &err);
...@@ -1405,7 +1405,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1405,7 +1405,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
int err; int err;
int excl; int excl;
kuid_t loginuid = audit_get_loginuid(current); kuid_t loginuid = audit_get_loginuid(current);
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
u32 sid; u32 sid;
err = verify_newpolicy_info(p); err = verify_newpolicy_info(p);
...@@ -1663,7 +1663,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1663,7 +1663,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
} }
} else { } else {
kuid_t loginuid = audit_get_loginuid(current); kuid_t loginuid = audit_get_loginuid(current);
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
u32 sid; u32 sid;
security_task_getsecid(current, &sid); security_task_getsecid(current, &sid);
...@@ -1959,7 +1959,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1959,7 +1959,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
err = 0; err = 0;
if (up->hard) { if (up->hard) {
kuid_t loginuid = audit_get_loginuid(current); kuid_t loginuid = audit_get_loginuid(current);
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
u32 sid; u32 sid;
security_task_getsecid(current, &sid); security_task_getsecid(current, &sid);
...@@ -2002,7 +2002,7 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2002,7 +2002,7 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
if (ue->hard) { if (ue->hard) {
kuid_t loginuid = audit_get_loginuid(current); kuid_t loginuid = audit_get_loginuid(current);
u32 sessionid = audit_get_sessionid(current); unsigned int sessionid = audit_get_sessionid(current);
u32 sid; u32 sid;
security_task_getsecid(current, &sid); security_task_getsecid(current, &sid);
......
...@@ -2948,25 +2948,21 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule, ...@@ -2948,25 +2948,21 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
struct selinux_audit_rule *rule = vrule; struct selinux_audit_rule *rule = vrule;
int match = 0; int match = 0;
if (!rule) { if (unlikely(!rule)) {
audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR, WARN_ONCE(1, "selinux_audit_rule_match: missing rule\n");
"selinux_audit_rule_match: missing rule\n");
return -ENOENT; return -ENOENT;
} }
read_lock(&policy_rwlock); read_lock(&policy_rwlock);
if (rule->au_seqno < latest_granting) { if (rule->au_seqno < latest_granting) {
audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
"selinux_audit_rule_match: stale rule\n");
match = -ESTALE; match = -ESTALE;
goto out; goto out;
} }
ctxt = sidtab_search(&sidtab, sid); ctxt = sidtab_search(&sidtab, sid);
if (!ctxt) { if (unlikely(!ctxt)) {
audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR, WARN_ONCE(1, "selinux_audit_rule_match: unrecognized SID %d\n",
"selinux_audit_rule_match: unrecognized SID %d\n",
sid); sid);
match = -ENOENT; match = -ENOENT;
goto out; goto out;
......
...@@ -3616,9 +3616,8 @@ static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule, ...@@ -3616,9 +3616,8 @@ static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
struct smack_known *skp; struct smack_known *skp;
char *rule = vrule; char *rule = vrule;
if (!rule) { if (unlikely(!rule)) {
audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR, WARN_ONCE(1, "Smack: missing rule\n");
"Smack: missing rule\n");
return -ENOENT; return -ENOENT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment