]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
audit: fix a net reference leak in audit_list_rules_send()
authorPaul Moore <paul@paul-moore.com>
Tue, 21 Apr 2020 13:10:56 +0000 (09:10 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Apr 2021 10:05:41 +0000 (12:05 +0200)
commit 3054d06719079388a543de6adb812638675ad8f5 upstream.

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: teroincn@gmail.com
Reviewed-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Cc: <stable@vger.kernel.org> # 4.9.x
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/audit.c
kernel/audit.h
kernel/auditfilter.c

index 55ccd8421df7bb5948a003c0a3f649da3744f5ee..7fa9020e728ea2c15d235a0e162381d10ce1827f 100644 (file)
@@ -535,7 +535,7 @@ static int kauditd_thread(void *dummy)
        return 0;
 }
 
-int audit_send_list(void *_dest)
+int audit_send_list_thread(void *_dest)
 {
        struct audit_netlink_list *dest = _dest;
        struct sk_buff *skb;
index 431444c3708bf4634568b9a8d83318de7c0fa22f..2eaf450188374d780e3bb2e3c5455017bda03e82 100644 (file)
@@ -245,7 +245,7 @@ struct audit_netlink_list {
        struct sk_buff_head q;
 };
 
-int audit_send_list(void *);
+int audit_send_list_thread(void *);
 
 struct audit_net {
        struct sock *nlsk;
index a71ff9965cba671865a82defdc98686be864b284..cd12d79d1b176b3b4e503aec3ae18362f953ef5f 100644 (file)
@@ -1139,10 +1139,8 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data,
 int audit_list_rules_send(struct sk_buff *request_skb, int seq)
 {
        u32 portid = NETLINK_CB(request_skb).portid;
-       struct net *net = sock_net(NETLINK_CB(request_skb).sk);
        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
@@ -1150,10 +1148,10 @@ int audit_list_rules_send(struct sk_buff *request_skb, int seq)
         * 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);
+       dest = kmalloc(sizeof(*dest), GFP_KERNEL);
        if (!dest)
                return -ENOMEM;
-       dest->net = get_net(net);
+       dest->net = get_net(sock_net(NETLINK_CB(request_skb).sk));
        dest->portid = portid;
        skb_queue_head_init(&dest->q);
 
@@ -1161,14 +1159,15 @@ int audit_list_rules_send(struct sk_buff *request_skb, int seq)
        audit_list_rules(portid, seq, &dest->q);
        mutex_unlock(&audit_filter_mutex);
 
-       tsk = kthread_run(audit_send_list, dest, "audit_send_list");
+       tsk = kthread_run(audit_send_list_thread, dest, "audit_send_list");
        if (IS_ERR(tsk)) {
                skb_queue_purge(&dest->q);
+               put_net(dest->net);
                kfree(dest);
-               err = PTR_ERR(tsk);
+               return PTR_ERR(tsk);
        }
 
-       return err;
+       return 0;
 }
 
 int audit_comparator(u32 left, u32 op, u32 right)