From patchwork Thu Feb 28 22:19:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10834037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 841C417EF for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782CE2FC8A for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 768682F34F; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 295642FC90 for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732148AbfB1WUd (ORCPT ); Thu, 28 Feb 2019 17:20:33 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:34097 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732195AbfB1WUb (ORCPT ); Thu, 28 Feb 2019 17:20:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392430; bh=f8K6YGqPGEJWPQrpWKi0AaWdcZaQR+kZDh+aYC77/lU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject;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tbJoPP4OHL 5WJu0QsPxxARhlZhRf3El6e9JIu06xXJTv5WY265a9qOhtOQOXWJCwu6Me8FtPyGJzmpSKxG36qz eJ.Gkd86ZyI67J.IVd_6jZFjFHG_fppakYgOn2vBhxul6Bo.tcYwqg9XNfoJ7p.UgGRGLOoa3w6s L.xcNGHMfiNTYgKnT0TY9G2htgOiHugDvsaTCwLhF7bBbcFBAa7mh41bJIWQVOV_lwGI9hhveeV2 huP_.R2IDo3JXBwbrM8WWgCI1FX8rvkh08rkVTGvI._NhvpG0Om1uYsOuJr0L9nOW8D96lOt.8q7 Ot4dnCqc80M3LBA.a3C8qQ6XfkyXgDPAZ6uThUJB_H03cUC9aF09IL0G6Q16mguohP1qyqh3JKWQ 43IQT9RDtEEE4lSVcjCUDmTV0OPFug0NXl7yKXCnbKjrLvM7ZC9xQmwB4uw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:30 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 68/97] netfilter: Fix memory leak introduced with lsm_context Date: Thu, 28 Feb 2019 14:19:04 -0800 Message-Id: <20190228221933.2551-69-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Fix a memory leak introduced by the scaffolding around the introduction of lsm_context structures. Signed-off-by: Casey Schaufler --- net/netfilter/nfnetlink_queue.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 4a3d4b52caef..7a095b9d0a10 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -305,14 +305,13 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk) return -1; } -static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) +static void nfqnl_get_sk_secctx(struct sk_buff *skb, struct lsm_context *cp) { #if IS_ENABLED(CONFIG_NETWORK_SECMARK) struct lsm_export le; - struct lsm_context lc = { .context = NULL, .len = 0, }; if (!skb || !sk_fullsock(skb->sk)) - return 0; + return; read_lock_bh(&skb->sk->sk_callback_lock); @@ -322,14 +321,10 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; le.selinux = skb->secmark; le.smack = skb->secmark; - security_secid_to_secctx(&le, &lc); - *secdata = lc.context; + security_secid_to_secctx(&le, cp); } read_unlock_bh(&skb->sk->sk_callback_lock); - return lc.len; -#else - return 0; #endif } @@ -406,7 +401,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, enum ip_conntrack_info uninitialized_var(ctinfo); struct nfnl_ct_hook *nfnl_ct; bool csum_verify; - struct lsm_context lc = { .context = NULL, }; + struct lsm_context lc; size = nlmsg_total_size(sizeof(struct nfgenmsg)) + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr)) @@ -472,7 +467,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) { - lc.len = nfqnl_get_sk_secctx(entskb, &lc.context); + nfqnl_get_sk_secctx(entskb, &lc); if (lc.len) size += nla_total_size(lc.len); } @@ -635,8 +630,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; - if (lc.context) - security_release_secctx(&lc); + security_release_secctx(&lc); return skb; nla_put_failure: