From patchwork Tue Mar 9 14:42:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12125697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 694C3C433E9 for ; Tue, 9 Mar 2021 15:03:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25C606527B for ; Tue, 9 Mar 2021 15:03:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231892AbhCIPDW (ORCPT ); Tue, 9 Mar 2021 10:03:22 -0500 Received: from sonic309-26.consmr.mail.ne1.yahoo.com ([66.163.184.152]:37492 "EHLO sonic309-26.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbhCIPCy (ORCPT ); Tue, 9 Mar 2021 10:02:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1615302173; bh=q3I4/eiRbkYu2f0b01JDmqntb1ptAUIyC93pJ+71rvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=fgUAcYfSFGqEAR/K4chnb0vzS7/Fib0OKjDBEvRPPLcyBGV+d3ZMpCtEHi7jiPeOt/kY+SSBAuLMX3Tn9DTx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IyECzH5Ca3jX5MKQwzAVxHVM3s4BGP60pXW1d3F92i y8gEsvFZnMr8lv_sijfJhRFMfhMlQXKLH_vR3GfOyqKOMhn5A0Rm9DyhXzc50eV4RBy.5dTh1H2V lc0BuB4Au8ZTnU17JioYGLeZIPD.2aUB5Lg3Px.sAPC.RQxQzrYvOKk4YQyHIImUM43Q5z1xr2GK 5aLPYTtut5uIFeduGSXUzXWpiz1YSQGmR5q6FSJCV_BgdyUr1JgTdzQS0ilb_b0qNGzJb2j9cnPM l2V8KjKXd95C0ZwZYBS9VfNHQWU9mHk8ly4oUDLMtM2ueBFWpa_AYWSponI_2vU_JfdPOHe48h1x V_PTZAkwc53yrEUizgbZXG69ZKfq_KX2hVho_6.uoPzQfvAD2qsqGOa0L4RMjsz1KCkklCPniPXu aagXoAquTmzwIhc0GX8tHmgCb5qzp.TALy6lsZ0qqGWUv3eYycUdR23rD9ghSI.knmkM1YhFWRwq awnuNgoBJoNxeR84ZtT1dYlVfyMVC_KcJohY9lNulo60aB6hWwG6zTkBfI.uaw4IPPSJxKl9MRt0 R3DKVRCXbKyf8Cij8LSEpxZKj6ZaOPqI4dk.k_gunXOojNDKejSwDY42hZZmqN3kXjcO5dSmljRG tyoKc6yfuBByr7y1F42ju.OtrTT6JTXr4M8haz6lFyluY62zrr_Lx.CRrbmsb8EDqjYe2XNMft1g m3QntwndazmROZUxX1TRJQ4iA_k3rYVg6isLPx.Mcw3A8ZWggCiCo9JUtCQOLrfTt01kuv.uPuUP uLkeQMGmLdE28jso7.wuRdq5CRQAd8dCE8qDLeSHJlswpsYHxGg9RkXvdjRCh8VC4Tzijsuus2gu w4fKpXwS6yp2pHOZSlAY7BtaWSZz86.7WfZifH3C_GgcrSSKh6aoRkXN2dX76QmxwG.zhZQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Mar 2021 15:02:53 +0000 Received: by smtp412.mail.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 0b0b60e1a865012f293c98f03ce575b1; Tue, 09 Mar 2021 15:02:48 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org, Pablo Neira Ayuso , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org Subject: [PATCH v25 18/25] LSM: security_secid_to_secctx in netlink netfilter Date: Tue, 9 Mar 2021 06:42:36 -0800 Message-Id: <20210309144243.12519-19-casey@schaufler-ca.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210309144243.12519-1-casey@schaufler-ca.com> References: <20210309144243.12519-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: Change netlink netfilter interfaces to use lsmcontext pointers, and remove scaffolding. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Stephen Smalley Acked-by: Pablo Neira Ayuso Signed-off-by: Casey Schaufler Cc: netdev@vger.kernel.org Cc: netfilter-devel@vger.kernel.org --- net/netfilter/nfnetlink_queue.c | 37 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 449c2c7c7b27..56784592c820 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -301,15 +301,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 lsmcontext *context) { - u32 seclen = 0; #if IS_ENABLED(CONFIG_NETWORK_SECMARK) struct lsmblob blob; - struct lsmcontext context = { }; if (!skb || !sk_fullsock(skb->sk)) - return 0; + return; read_lock_bh(&skb->sk->sk_callback_lock); @@ -318,14 +316,12 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) * blob. security_secid_to_secctx() will know which security * module to use to create the secctx. */ lsmblob_init(&blob, skb->secmark); - security_secid_to_secctx(&blob, &context); - *secdata = context.context; + security_secid_to_secctx(&blob, context); } read_unlock_bh(&skb->sk->sk_callback_lock); - seclen = context.len; #endif - return seclen; + return; } static u32 nfqnl_get_bridge_size(struct nf_queue_entry *entry) @@ -398,12 +394,10 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, struct net_device *indev; struct net_device *outdev; struct nf_conn *ct = NULL; + struct lsmcontext context = { }; enum ip_conntrack_info ctinfo; struct nfnl_ct_hook *nfnl_ct; bool csum_verify; - struct lsmcontext scaff; /* scaffolding */ - char *secdata = NULL; - u32 seclen = 0; size = nlmsg_total_size(sizeof(struct nfgenmsg)) + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr)) @@ -471,9 +465,9 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) { - seclen = nfqnl_get_sk_secctx(entskb, &secdata); - if (seclen) - size += nla_total_size(seclen); + nfqnl_get_sk_secctx(entskb, &context); + if (context.len) + size += nla_total_size(context.len); } skb = alloc_skb(size, GFP_ATOMIC); @@ -606,7 +600,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, nfqnl_put_sk_uidgid(skb, entskb->sk) < 0) goto nla_put_failure; - if (seclen && nla_put(skb, NFQA_SECCTX, seclen, secdata)) + if (context.len && + nla_put(skb, NFQA_SECCTX, context.len, context.context)) goto nla_put_failure; if (ct && nfnl_ct->build(skb, ct, ctinfo, NFQA_CT, NFQA_CT_INFO) < 0) @@ -634,10 +629,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; - if (seclen) { - lsmcontext_init(&scaff, secdata, seclen, 0); - security_release_secctx(&scaff); - } + if (context.len) + security_release_secctx(&context); return skb; nla_put_failure: @@ -645,10 +638,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, kfree_skb(skb); net_err_ratelimited("nf_queue: error creating packet message\n"); nlmsg_failure: - if (seclen) { - lsmcontext_init(&scaff, secdata, seclen, 0); - security_release_secctx(&scaff); - } + if (context.len) + security_release_secctx(&context); return NULL; }