Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3996555pxb; Tue, 10 Nov 2020 05:39:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKA8MkdsUTbmqIFEPVsFOYFg4BcpIzPxOqeBtsDuljdzkj3iqvbyyuSDfDyaAKCPzAmzVs X-Received: by 2002:a05:6402:17ad:: with SMTP id j13mr20178190edy.347.1605015552984; Tue, 10 Nov 2020 05:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605015552; cv=none; d=google.com; s=arc-20160816; b=OnrjUlLuBq7xzlVck+uZZJGBO8o9SXK81kOw7czX3fNUCM1akl41Pke6/FhmCxQdQX xbetvRClVxJ6jCLqspIWwK0Ac64mBfRC4GNevkBzossWC/Uih/IBqEAZukfjwuIy7MlB TQ5YDyqQK1ygTbUPeMpg/c7MuuZAafpsWL9HF2IC3yLWpJBPwlYGTOxivWoA7qZaCB98 9sKl692RQLIMWlGs+Wh1vxferxt9DHK0TN2Relmzfd8n1v3e8YGNO8t/EP16V5acpzy8 JqOIZFwjDQ8Ip5XRYmqYt1qbY0dvp/uglfGWk2whxgvZzg3IMIOfcakgCT9GCx40TLb/ rUrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=0MTJUKiNX/XTmf8qL4qODgn0aizKCH6tSVkTyNnrpME=; b=UyDjRmLuG94cy7AQsiE/yDsRZbqqTq7J+B2rutO7ZL5N8h9u6R0wZ1QgEq07FyvtGe 2F2LRGqmqte2BurPp5lQdcAHYEC62D/BsBnpIl3cRBbZzbgIYPt0FEUcFe5BAdwLsYge xZAOd7vy88ONnMiarelbV2qJqDOLjmFUIue4XfYoWS/Sm3llxEyV4ZEV3IH51dCWhZmA 6dFzryIWOXv5DBHIkFBOg7CNkpHkeeAmRR45OEkqXcqGeb7j4rMdQs/YGDTVQDAIjTNL /0w7zDFA0vDvRUdr1k7r+PVfVzJCp7SzYLRT7LLEKtn6BntuGcFfzbWrwM7VqN+WoQN1 Xasw== ARC-Authentication-Results: i=1; mx.google.com; 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 f2si5424453edc.263.2020.11.10.05.38.49; Tue, 10 Nov 2020 05:39:12 -0800 (PST) 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; 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 S1732351AbgKJNhY (ORCPT + 99 others); Tue, 10 Nov 2020 08:37:24 -0500 Received: from correo.us.es ([193.147.175.20]:36768 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730432AbgKJNhU (ORCPT ); Tue, 10 Nov 2020 08:37:20 -0500 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id 6FABE396274 for ; Tue, 10 Nov 2020 14:37:18 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 53218DA859 for ; Tue, 10 Nov 2020 14:37:18 +0100 (CET) Received: by antivirus1-rhel7.int (Postfix, from userid 99) id 45691DA84F; Tue, 10 Nov 2020 14:37:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on antivirus1-rhel7.int X-Spam-Level: X-Spam-Status: No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50, SMTPAUTH_US2,URIBL_BLOCKED,USER_IN_WELCOMELIST,USER_IN_WHITELIST autolearn=disabled version=3.4.1 Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id ADF1ADA789; Tue, 10 Nov 2020 14:37:15 +0100 (CET) Received: from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int (F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); Tue, 10 Nov 2020 14:37:15 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int) Received: from us.es (unknown [90.77.255.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: 1984lsi) by entrada.int (Postfix) with ESMTPSA id 7CCF642EF9E0; Tue, 10 Nov 2020 14:37:15 +0100 (CET) Date: Tue, 10 Nov 2020 14:37:15 +0100 X-SMTPAUTHUS: auth mail.us.es From: Pablo Neira Ayuso To: Casey Schaufler Cc: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, 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, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org Subject: Re: [PATCH v22 16/23] LSM: security_secid_to_secctx in netlink netfilter Message-ID: <20201110133715.GA1890@salvia> References: <20201105004924.11651-1-casey@schaufler-ca.com> <20201105004924.11651-17-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201105004924.11651-17-casey@schaufler-ca.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Casey, On Wed, Nov 04, 2020 at 04:49:17PM -0800, Casey Schaufler wrote: > Change netlink netfilter interfaces to use lsmcontext > pointers, and remove scaffolding. > > Reviewed-by: Kees Cook > Reviewed-by: John Johansen > Acked-by: Stephen Smalley > Signed-off-by: Casey Schaufler > Cc: netdev@vger.kernel.org > Cc: netfilter-devel@vger.kernel.org You can carry this tag in your follow up patches. Acked-by: Pablo Neira Ayuso Thanks. > --- > 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 84be5a49a157..0d8b83d84422 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)) > @@ -469,9 +463,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); > @@ -604,7 +598,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) > @@ -632,10 +627,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: > @@ -643,10 +636,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; > } > > -- > 2.24.1 >