Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp993241ybt; Fri, 19 Jun 2020 20:54:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0rtrxzgzyVFgLV6U6WvxxeyrJzOglfpjHGrBJk006n0MS+0NmQTjZ/FyTcFviukXHndNT X-Received: by 2002:a05:6402:1746:: with SMTP id v6mr6517307edx.236.1592625254586; Fri, 19 Jun 2020 20:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592625254; cv=none; d=google.com; s=arc-20160816; b=S+loEaoPjlqAGd2P1lijrC9nSzWFzuY2IEPgJRvYYUGJWM+PhX3Iq0gYvdt76Qmj9f GdQFVYIBmSfW+Amxi1Nptq/5m5JKgqsxssu+Ijuv3jDexbDTbvcZ0rfsRuPm/K4m4Z5r o6jkv/eU3UPOjKTG0WF6/OsHK1yauSOw4IxG1CVlXsTHasxbxf4WY8jSb8JTTxHH/l88 rRAJGHK4sjA8qsyrnvTalZ9sWqYamKGyP4MdLHjwjbf9u3vzJHryMoPbsmca7bOgSjFV aDuPtbmvyDlimkCbkX6PyHXkAAMVI3G/CEkWjjpigpaRyYDpI+wHuhW54dDpDOq9T38Q 6qNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HJPnM8eoI+bcV6AiKeQ/zGynYXbL8spqDomx92YNpFE=; b=CjglACxeweDX5aptOWLWt5QfVE+8QLeR01r0rem+IG/8ai4/3OlwUZdIKwmeLzGGJI suH95ICGveUizmbK8/RQ7IEXAP7glpc1g7cws9hVilOE1uv+WDk8TUPIOCKMifcAWr3H SytmxktTtX0Elpt+Pk+MDqRa+RHLYWd5FfpnARiFWVt9UCiqxtqR5Oy8R7I9TSwsCjDa AK2NCR1Gc3v9PykZmFtA8x3Qa2el4FvL7L6MKDIwnfOfOChrslwm9+JDQ0hZarhFcONy 9IJweZ+7FmLSC2LIMrbXtVNrOy7YhpYhkGikJRvV0Ao7juZG1MDOfoPLHpQnd2X1spTn aqmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2JbIz82I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si5459078edm.76.2020.06.19.20.53.53; Fri, 19 Jun 2020 20:54:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2JbIz82I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390390AbgFSQYC (ORCPT + 99 others); Fri, 19 Jun 2020 12:24:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:54474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389148AbgFSO6g (ORCPT ); Fri, 19 Jun 2020 10:58:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6DACA21919; Fri, 19 Jun 2020 14:58:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578717; bh=vtLCcP2wjcsqi53fYNurHfRxCuRQBP/7urNmQOg6zkY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2JbIz82IQPG3Te1ZVaSLLVbFx5Y+7WuNjSihwAxo5QlZkUNEpvYS5GG7ODGN29XEY wAJTvqsTf9pMqNeSkZvrYCi+XpLhcUxr88Q5s8Z+8sy81TzM5kivAN2gjQ8XGL2Zq9 wwudVMCp4yUcsxoMzVzQnrgPMPMUUKLHQg1fFDi4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, teroincn@gmail.com, Richard Guy Briggs , Paul Moore , Sasha Levin Subject: [PATCH 4.19 130/267] audit: fix a net reference leak in audit_list_rules_send() Date: Fri, 19 Jun 2020 16:31:55 +0200 Message-Id: <20200619141655.066772896@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Moore [ Upstream commit 3054d06719079388a543de6adb812638675ad8f5 ] 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 Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- kernel/audit.c | 2 +- kernel/audit.h | 2 +- kernel/auditfilter.c | 16 +++++++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 20c78480d632..45741c3c48a4 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -893,7 +893,7 @@ main_queue: 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; diff --git a/kernel/audit.h b/kernel/audit.h index 214e14948370..99badd7ba56f 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -248,7 +248,7 @@ struct audit_netlink_list { struct sk_buff_head q; }; -int audit_send_list(void *_dest); +int audit_send_list_thread(void *_dest); extern int selinux_audit_rule_update(void); diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 1c8a48abda80..b2cc63ca0068 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1157,11 +1157,8 @@ int audit_rule_change(int type, int seq, void *data, size_t datasz) */ 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 @@ -1169,25 +1166,26 @@ 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->portid = portid; + dest->net = get_net(sock_net(NETLINK_CB(request_skb).sk)); + dest->portid = NETLINK_CB(request_skb).portid; skb_queue_head_init(&dest->q); mutex_lock(&audit_filter_mutex); audit_list_rules(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) -- 2.25.1