audit: clean up AUDIT_GET/SET local variables and future-proof API

Re-named confusing local variable names (status_set and status_get didn't agree
with their command type name) and reduced their scope.

Future-proof API changes by not depending on the exact size of the audit_status
struct and by adding an API version field.

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
This commit is contained in:
Richard Guy Briggs 2013-09-18 09:32:24 -04:00 committed by Eric Paris
parent f910fde730
commit 09f883a902
2 changed files with 30 additions and 25 deletions

View file

@ -376,6 +376,7 @@ 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 */
}; };
struct audit_features { struct audit_features {

View file

@ -743,7 +743,6 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{ {
u32 seq; u32 seq;
void *data; void *data;
struct audit_status *status_get, status_set;
int err; int err;
struct audit_buffer *ab; struct audit_buffer *ab;
u16 msg_type = nlh->nlmsg_type; u16 msg_type = nlh->nlmsg_type;
@ -769,34 +768,38 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
data = nlmsg_data(nlh); data = nlmsg_data(nlh);
switch (msg_type) { switch (msg_type) {
case AUDIT_GET: case AUDIT_GET: {
memset(&status_set, 0, sizeof(status_set)); struct audit_status s;
status_set.enabled = audit_enabled; memset(&s, 0, sizeof(s));
status_set.failure = audit_failure; s.enabled = audit_enabled;
status_set.pid = audit_pid; s.failure = audit_failure;
status_set.rate_limit = audit_rate_limit; s.pid = audit_pid;
status_set.backlog_limit = audit_backlog_limit; s.rate_limit = audit_rate_limit;
status_set.lost = atomic_read(&audit_lost); s.backlog_limit = audit_backlog_limit;
status_set.backlog = skb_queue_len(&audit_skb_queue); s.lost = atomic_read(&audit_lost);
s.backlog = skb_queue_len(&audit_skb_queue);
s.version = 1;
audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
&status_set, sizeof(status_set)); &s, sizeof(s));
break; break;
case AUDIT_SET: }
if (nlmsg_len(nlh) < sizeof(struct audit_status)) case AUDIT_SET: {
return -EINVAL; struct audit_status s;
status_get = (struct audit_status *)data; memset(&s, 0, sizeof(s));
if (status_get->mask & AUDIT_STATUS_ENABLED) { /* guard against past and future API changes */
err = audit_set_enabled(status_get->enabled); memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
if (s.mask & AUDIT_STATUS_ENABLED) {
err = audit_set_enabled(s.enabled);
if (err < 0) if (err < 0)
return err; return err;
} }
if (status_get->mask & AUDIT_STATUS_FAILURE) { if (s.mask & AUDIT_STATUS_FAILURE) {
err = audit_set_failure(status_get->failure); err = audit_set_failure(s.failure);
if (err < 0) if (err < 0)
return err; return err;
} }
if (status_get->mask & AUDIT_STATUS_PID) { if (s.mask & AUDIT_STATUS_PID) {
int new_pid = status_get->pid; int new_pid = s.pid;
if (audit_enabled != AUDIT_OFF) if (audit_enabled != AUDIT_OFF)
audit_log_config_change("audit_pid", new_pid, audit_pid, 1); audit_log_config_change("audit_pid", new_pid, audit_pid, 1);
@ -804,14 +807,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
audit_nlk_portid = NETLINK_CB(skb).portid; audit_nlk_portid = NETLINK_CB(skb).portid;
audit_sock = NETLINK_CB(skb).sk; audit_sock = NETLINK_CB(skb).sk;
} }
if (status_get->mask & AUDIT_STATUS_RATE_LIMIT) { if (s.mask & AUDIT_STATUS_RATE_LIMIT) {
err = audit_set_rate_limit(status_get->rate_limit); err = audit_set_rate_limit(s.rate_limit);
if (err < 0) if (err < 0)
return err; return err;
} }
if (status_get->mask & AUDIT_STATUS_BACKLOG_LIMIT) if (s.mask & AUDIT_STATUS_BACKLOG_LIMIT)
err = audit_set_backlog_limit(status_get->backlog_limit); err = audit_set_backlog_limit(s.backlog_limit);
break; break;
}
case AUDIT_GET_FEATURE: case AUDIT_GET_FEATURE:
err = audit_get_feature(skb); err = audit_get_feature(skb);
if (err) if (err)