diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2014-02-28 13:49:05 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2014-03-20 10:10:53 -0400 |
commit | 638a0fd2a062568c568661be0a780be8e8836d03 (patch) | |
tree | e250ef6ef5ddf0ff6c189362b5e125c3a7bc402e /kernel | |
parent | 3f1c82502c299da08b7b7f08b435212e51166ed9 (diff) |
audit: Use struct net not pid_t to remember the network namespce to reply in
While reading through 3.14-rc1 I found a pretty siginficant mishandling
of network namespaces in the recent audit changes.
In struct audit_netlink_list and audit_reply add a reference to the
network namespace of the caller and remove the userspace pid of the
caller. This cleanly remembers the callers network namespace, and
removes a huge class of races and nasty failure modes that can occur
when attempting to relook up the callers network namespace from a pid_t
(including the caller's network namespace changing, pid wraparound, and
the pid simply not being present).
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/audit.c | 10 | ||||
-rw-r--r-- | kernel/audit.h | 2 | ||||
-rw-r--r-- | kernel/auditfilter.c | 3 |
3 files changed, 9 insertions, 6 deletions
diff --git a/kernel/audit.c b/kernel/audit.c index 34c5a2310fbf..71fb41f393d7 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -182,7 +182,7 @@ struct audit_buffer { | |||
182 | 182 | ||
183 | struct audit_reply { | 183 | struct audit_reply { |
184 | __u32 portid; | 184 | __u32 portid; |
185 | pid_t pid; | 185 | struct net *net; |
186 | struct sk_buff *skb; | 186 | struct sk_buff *skb; |
187 | }; | 187 | }; |
188 | 188 | ||
@@ -500,7 +500,7 @@ int audit_send_list(void *_dest) | |||
500 | { | 500 | { |
501 | struct audit_netlink_list *dest = _dest; | 501 | struct audit_netlink_list *dest = _dest; |
502 | struct sk_buff *skb; | 502 | struct sk_buff *skb; |
503 | struct net *net = get_net_ns_by_pid(dest->pid); | 503 | struct net *net = dest->net; |
504 | struct audit_net *aunet = net_generic(net, audit_net_id); | 504 | struct audit_net *aunet = net_generic(net, audit_net_id); |
505 | 505 | ||
506 | /* wait for parent to finish and send an ACK */ | 506 | /* wait for parent to finish and send an ACK */ |
@@ -510,6 +510,7 @@ int audit_send_list(void *_dest) | |||
510 | while ((skb = __skb_dequeue(&dest->q)) != NULL) | 510 | while ((skb = __skb_dequeue(&dest->q)) != NULL) |
511 | netlink_unicast(aunet->nlsk, skb, dest->portid, 0); | 511 | netlink_unicast(aunet->nlsk, skb, dest->portid, 0); |
512 | 512 | ||
513 | put_net(net); | ||
513 | kfree(dest); | 514 | kfree(dest); |
514 | 515 | ||
515 | return 0; | 516 | return 0; |
@@ -543,7 +544,7 @@ out_kfree_skb: | |||
543 | static int audit_send_reply_thread(void *arg) | 544 | static int audit_send_reply_thread(void *arg) |
544 | { | 545 | { |
545 | struct audit_reply *reply = (struct audit_reply *)arg; | 546 | struct audit_reply *reply = (struct audit_reply *)arg; |
546 | struct net *net = get_net_ns_by_pid(reply->pid); | 547 | struct net *net = reply->net; |
547 | struct audit_net *aunet = net_generic(net, audit_net_id); | 548 | struct audit_net *aunet = net_generic(net, audit_net_id); |
548 | 549 | ||
549 | mutex_lock(&audit_cmd_mutex); | 550 | mutex_lock(&audit_cmd_mutex); |
@@ -552,6 +553,7 @@ static int audit_send_reply_thread(void *arg) | |||
552 | /* Ignore failure. It'll only happen if the sender goes away, | 553 | /* Ignore failure. It'll only happen if the sender goes away, |
553 | because our timeout is set to infinite. */ | 554 | because our timeout is set to infinite. */ |
554 | netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); | 555 | netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); |
556 | put_net(net); | ||
555 | kfree(reply); | 557 | kfree(reply); |
556 | return 0; | 558 | return 0; |
557 | } | 559 | } |
@@ -583,8 +585,8 @@ static void audit_send_reply(__u32 portid, int seq, int type, int done, | |||
583 | if (!skb) | 585 | if (!skb) |
584 | goto out; | 586 | goto out; |
585 | 587 | ||
588 | reply->net = get_net(current->nsproxy->net_ns); | ||
586 | reply->portid = portid; | 589 | reply->portid = portid; |
587 | reply->pid = task_pid_vnr(current); | ||
588 | reply->skb = skb; | 590 | reply->skb = skb; |
589 | 591 | ||
590 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); | 592 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); |
diff --git a/kernel/audit.h b/kernel/audit.h index 38c967d28de5..7bb65730c890 100644 --- a/kernel/audit.h +++ b/kernel/audit.h | |||
@@ -253,7 +253,7 @@ extern void audit_panic(const char *message); | |||
253 | 253 | ||
254 | struct audit_netlink_list { | 254 | struct audit_netlink_list { |
255 | __u32 portid; | 255 | __u32 portid; |
256 | pid_t pid; | 256 | struct net *net; |
257 | struct sk_buff_head q; | 257 | struct sk_buff_head q; |
258 | }; | 258 | }; |
259 | 259 | ||
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 3152d1aea164..a0d470131fd0 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/sched.h> | 31 | #include <linux/sched.h> |
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/security.h> | 33 | #include <linux/security.h> |
34 | #include <net/net_namespace.h> | ||
34 | #include "audit.h" | 35 | #include "audit.h" |
35 | 36 | ||
36 | /* | 37 | /* |
@@ -1085,8 +1086,8 @@ int audit_list_rules_send(__u32 portid, int seq) | |||
1085 | dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL); | 1086 | dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL); |
1086 | if (!dest) | 1087 | if (!dest) |
1087 | return -ENOMEM; | 1088 | return -ENOMEM; |
1089 | dest->net = get_net(current->nsproxy->net_ns); | ||
1088 | dest->portid = portid; | 1090 | dest->portid = portid; |
1089 | dest->pid = task_pid_vnr(current); | ||
1090 | skb_queue_head_init(&dest->q); | 1091 | skb_queue_head_init(&dest->q); |
1091 | 1092 | ||
1092 | mutex_lock(&audit_filter_mutex); | 1093 | mutex_lock(&audit_filter_mutex); |