Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp115782ybg; Mon, 8 Jun 2020 18:03:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSXUoLqVeB3WOJ3OV2f0QcXX4xZhrQkTPmiFQ/cEm9rfUYFLOqu0FV0pmKi9j1oomXQVxO X-Received: by 2002:a17:906:c831:: with SMTP id dd17mr19356328ejb.40.1591664591726; Mon, 08 Jun 2020 18:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591664591; cv=none; d=google.com; s=arc-20160816; b=s6rL+q2+LdAac+VghQUNCW9QAmWQpjj6Ze37p7866O6ZAI2Ud1gjhO6M6ICZOe/+Cl PZaeQoSqTn6t0YBWf3CfTBmAzea6qYIQZyDZOXMQSLMYSMsLEi7lQCQYeSkbSYk92HXR u7AZSj8tJWQecjrnmoL/py7Hy7EgIuCpfc4V4UacTk599qLXuV96h7bZwA0h4jMUzxt8 yTI+J7w1qlj01flOIC281Kw3hU2hAE6Yes11Sm7AHuoG5B+urtCnDFZ6ThTDwMVS8kjJ yFDg2UsLkaP4t1clNWtvV2SoD6FNtQ1FdFFT3ElxsSWssW1kJP8i91xfTWrgBR+OGaR/ i02A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sXOtd8fsz4ISPED52ax4nCvo1gnCm6t01NMQLgUTO7Y=; b=pcU45K8AC92bf/1bOXr2PXvq/5Tih7wgg2lAfFMyfBEZdwnpq5F+NnRcyO8BJBUOBO rrE6COe0KGa3TZ6jeGmIfOoL9G63Q+kRO0tU/cLK/xxKvY5RvEA92JKhAEPpchYbZQ2U yAO7Kl7fkI0xeskxw/hqRKDaXxdkbEkcG8z8bh38B72zQciaxbb5H8uJClKqbfdd3+oN Iiiih4sHqvDgO7UhEiNKP+J7IZ5mLVAWTIWBl/mtjl8VUAkcELjT5wZTF9tjSRS4E19c h50OSEHpOYECEnKSQcygxebA9og+fybL3HfCzWS942eaeZTYKTg7Z22WXaSShdDR+mad 3qcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Zz1q5QWE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l24si10133591ejr.561.2020.06.08.18.02.46; Mon, 08 Jun 2020 18:03:11 -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=Zz1q5QWE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733002AbgFIA6w (ORCPT + 99 others); Mon, 8 Jun 2020 20:58:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728227AbgFHXIn (ORCPT ); Mon, 8 Jun 2020 19:08:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 88CF52086A; Mon, 8 Jun 2020 23:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657722; bh=fMiqwzuk4vvw9yMwklyaFMiZEVHBhDB1iwoQv9tfwCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zz1q5QWExXqC9oCBSXau0BjJa1fgaNeoPLVH5ZI1fVE24DhIMaCKCh4F+oVpHZOA8 LUzN6EYVD5zLyG3qfoVJmI+qkARgSsyo3iDi8fUTPUmo/RLc/mn8q54PVG2wV1Q3nL kfevFUa4iCLd+mEDIaq3IPL5mCi8AeW3wclgLitc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Paul Moore , teroincn@gmail.com, Richard Guy Briggs , Sasha Levin , linux-audit@redhat.com Subject: [PATCH AUTOSEL 5.7 115/274] audit: fix a net reference leak in audit_list_rules_send() Date: Mon, 8 Jun 2020 19:03:28 -0400 Message-Id: <20200608230607.3361041-115-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 033b14712340..f711f424a28a 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -880,7 +880,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; diff --git a/kernel/audit.h b/kernel/audit.h index 2eed4d231624..f0233dc40b17 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -229,7 +229,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 026e34da4ace..a10e2997aa6c 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1161,11 +1161,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 @@ -1173,25 +1170,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