diff options
author | Eric Paris <eparis@redhat.com> | 2014-01-13 21:12:34 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2014-01-13 22:33:41 -0500 |
commit | 0e23baccaae4f752cfa89cca44e84a439ed8bd13 (patch) | |
tree | 82defea35efa77b91dc15bc11510f890db7db8c2 /kernel/audit.c | |
parent | 3f0c5fad89c2c287baee0f314177b82aeafa7363 (diff) |
audit: rework AUDIT_TTY_SET to only grab spin_lock once
We can simplify the AUDIT_TTY_SET code to only grab the spin_lock one
time. We need to determine if the new values are valid and if so, set
the new values at the same time we grab the old onces. While we are
here get rid of 'res' and just use err.
Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'kernel/audit.c')
-rw-r--r-- | kernel/audit.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/kernel/audit.c b/kernel/audit.c index ab2e3d8288f2..b1d24a035ec9 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -991,19 +991,24 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
991 | struct audit_tty_status s, old; | 991 | struct audit_tty_status s, old; |
992 | struct task_struct *tsk = current; | 992 | struct task_struct *tsk = current; |
993 | struct audit_buffer *ab; | 993 | struct audit_buffer *ab; |
994 | int res = 0; | 994 | |
995 | memset(&s, 0, sizeof(s)); | ||
996 | /* guard against past and future API changes */ | ||
997 | memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh))); | ||
998 | /* check if new data is valid */ | ||
999 | if ((s.enabled != 0 && s.enabled != 1) || | ||
1000 | (s.log_passwd != 0 && s.log_passwd != 1)) | ||
1001 | err = -EINVAL; | ||
995 | 1002 | ||
996 | spin_lock(&tsk->sighand->siglock); | 1003 | spin_lock(&tsk->sighand->siglock); |
997 | old.enabled = tsk->signal->audit_tty; | 1004 | old.enabled = tsk->signal->audit_tty; |
998 | old.log_passwd = tsk->signal->audit_tty_log_passwd; | 1005 | old.log_passwd = tsk->signal->audit_tty_log_passwd; |
1006 | if (!err) { | ||
1007 | tsk->signal->audit_tty = s.enabled; | ||
1008 | tsk->signal->audit_tty_log_passwd = s.log_passwd; | ||
1009 | } | ||
999 | spin_unlock(&tsk->sighand->siglock); | 1010 | spin_unlock(&tsk->sighand->siglock); |
1000 | 1011 | ||
1001 | memset(&s, 0, sizeof(s)); | ||
1002 | /* guard against past and future API changes */ | ||
1003 | memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh))); | ||
1004 | if ((s.enabled == 0 || s.enabled == 1) && | ||
1005 | (s.log_passwd == 0 || s.log_passwd == 1)) | ||
1006 | res = 1; | ||
1007 | audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE); | 1012 | audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE); |
1008 | audit_log_format(ab, " op=tty_set" | 1013 | audit_log_format(ab, " op=tty_set" |
1009 | " old-enabled=%d old-log_passwd=%d" | 1014 | " old-enabled=%d old-log_passwd=%d" |
@@ -1011,15 +1016,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
1011 | " res=%d", | 1016 | " res=%d", |
1012 | old.enabled, old.log_passwd, | 1017 | old.enabled, old.log_passwd, |
1013 | s.enabled, s.log_passwd, | 1018 | s.enabled, s.log_passwd, |
1014 | res); | 1019 | !err); |
1015 | audit_log_end(ab); | 1020 | audit_log_end(ab); |
1016 | if (res) { | ||
1017 | spin_lock(&tsk->sighand->siglock); | ||
1018 | tsk->signal->audit_tty = s.enabled; | ||
1019 | tsk->signal->audit_tty_log_passwd = s.log_passwd; | ||
1020 | spin_unlock(&tsk->sighand->siglock); | ||
1021 | } else | ||
1022 | return -EINVAL; | ||
1023 | break; | 1021 | break; |
1024 | } | 1022 | } |
1025 | default: | 1023 | default: |