Skip to content

Commit 3054d06

Browse files
committed
audit: fix a net reference leak in audit_list_rules_send()
If audit_list_rules_send() fails when trying to create a new thread to send the rules it also fails to cleanup properly, leaking a reference to a net structure. This patch fixes the error patch and renames audit_send_list() to audit_send_list_thread() to better match its cousin, audit_send_reply_thread(). Reported-by: [email protected] Reviewed-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent a48b284 commit 3054d06

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

kernel/audit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ static int kauditd_thread(void *dummy)
880880
return 0;
881881
}
882882

883-
int audit_send_list(void *_dest)
883+
int audit_send_list_thread(void *_dest)
884884
{
885885
struct audit_netlink_list *dest = _dest;
886886
struct sk_buff *skb;

kernel/audit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct audit_netlink_list {
229229
struct sk_buff_head q;
230230
};
231231

232-
int audit_send_list(void *_dest);
232+
int audit_send_list_thread(void *_dest);
233233

234234
extern int selinux_audit_rule_update(void);
235235

kernel/auditfilter.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,37 +1161,35 @@ int audit_rule_change(int type, int seq, void *data, size_t datasz)
11611161
*/
11621162
int audit_list_rules_send(struct sk_buff *request_skb, int seq)
11631163
{
1164-
u32 portid = NETLINK_CB(request_skb).portid;
1165-
struct net *net = sock_net(NETLINK_CB(request_skb).sk);
11661164
struct task_struct *tsk;
11671165
struct audit_netlink_list *dest;
1168-
int err = 0;
11691166

11701167
/* We can't just spew out the rules here because we might fill
11711168
* the available socket buffer space and deadlock waiting for
11721169
* auditctl to read from it... which isn't ever going to
11731170
* happen if we're actually running in the context of auditctl
11741171
* trying to _send_ the stuff */
11751172

1176-
dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL);
1173+
dest = kmalloc(sizeof(*dest), GFP_KERNEL);
11771174
if (!dest)
11781175
return -ENOMEM;
1179-
dest->net = get_net(net);
1180-
dest->portid = portid;
1176+
dest->net = get_net(sock_net(NETLINK_CB(request_skb).sk));
1177+
dest->portid = NETLINK_CB(request_skb).portid;
11811178
skb_queue_head_init(&dest->q);
11821179

11831180
mutex_lock(&audit_filter_mutex);
11841181
audit_list_rules(seq, &dest->q);
11851182
mutex_unlock(&audit_filter_mutex);
11861183

1187-
tsk = kthread_run(audit_send_list, dest, "audit_send_list");
1184+
tsk = kthread_run(audit_send_list_thread, dest, "audit_send_list");
11881185
if (IS_ERR(tsk)) {
11891186
skb_queue_purge(&dest->q);
1187+
put_net(dest->net);
11901188
kfree(dest);
1191-
err = PTR_ERR(tsk);
1189+
return PTR_ERR(tsk);
11921190
}
11931191

1194-
return err;
1192+
return 0;
11951193
}
11961194

11971195
int audit_comparator(u32 left, u32 op, u32 right)

0 commit comments

Comments
 (0)