Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1800965pxb; Mon, 11 Oct 2021 13:27:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykc/Mc4Zr/u5Hb46Jg7dB/abNQVLGzFqqyZfNairygbG1NVTkhuGZ8Hjx95T8RlSys8O6j X-Received: by 2002:a50:cf4d:: with SMTP id d13mr43712137edk.50.1633984038348; Mon, 11 Oct 2021 13:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633984038; cv=none; d=google.com; s=arc-20160816; b=URf6+JrqGs1KRJn7o+uIyTzxccZJ119obW4rLpKcTUzarwsywmPjDSBp1loizNaSp/ IxWsbAMJQnnj0kOWyuICQNObiZ2pFVuAQ7CNYh7WolnV4T9NMIdinwL5g0PT3cxap/Bn 34HpUWiqDbCeJ5RYKVxMZBkA8ttlCg441cTvQrsJktJx/uomt20EP6u625maYJa00t33 7oukawDdvBmnHa5xPuZPPKy/LRJ247lQEWDprGu1ebs2KLK5J3ihLhP3xY9rpHlhhhLj diRD8lKVQGJ/TyeIotXBFqH3QnhGrBhv0b6WiHeFxUsfWJRd8ZJAIioDK1RB46f+KEE9 z/OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qXudaDlz/u2t2xer28JDPaKKE29SKP4Ro2pNhRre07E=; b=m1mX0p52iPdroCGxmjwfgeQNHumqwuZLKMH4rTkUDhJG1xcrJMZ9WE+/+7BBGwBzOL 7gaJ05HtGoTOx92XuiOSIhYuNqXObcw8+hJ6rPzbVOctMj6coxNdpYPex0TfJ4gf7Ybs MTiQOy8BLONXWhyc08mbrVbCTciP4UWWBbeMD7rDSiXoW4PVbQpJidmSW2FxV+IFaveh xFBQ6C/Z54n2PmtuC1x4rEhh6PRvmC2yxWFakFH3txH1ukiDc9NqYHxSsWxNesuQtA2i HfJgpO5oPGZ7X2X5NfL8NWhtvwa7gZv4ywq1o/J5LFGA6+lIpRCobx2Oj8oPLZKKRjoV VBcw== 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 s18si14102275ejx.160.2021.10.11.13.26.49; Mon, 11 Oct 2021 13:27:18 -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; 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 S234911AbhJKUYn (ORCPT + 99 others); Mon, 11 Oct 2021 16:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234845AbhJKUYn (ORCPT ); Mon, 11 Oct 2021 16:24:43 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A124EC061570; Mon, 11 Oct 2021 13:22:42 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1ma1ol-00038Z-0n; Mon, 11 Oct 2021 22:22:39 +0200 From: Florian Westphal To: selinux@vger.kernel.org Cc: paul@paul-moore.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, linux-kernel@vger.kernel.org, omosnace@redhat.com, Florian Westphal Subject: [PATCH selinux v3] selinux: remove unneeded ipv6 hook wrappers Date: Mon, 11 Oct 2021 22:22:29 +0200 Message-Id: <20211011202229.28289-1-fw@strlen.de> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Netfilter places the protocol number the hook function is getting called from in state->pf, so we can use that instead of an extra wrapper. While at it, remove one-line wrappers too and make selinux_ip_{out,forward,postroute} useable as hook function. Signed-off-by: Florian Westphal --- v3: also remove the one-line wrappers, just adjust function signature of the actual functions (Ondrej Mosnacek) security/selinux/hooks.c | 80 +++++++++------------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index e7ebd45ca345..3f6462451921 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -5688,10 +5688,11 @@ static int selinux_tun_dev_open(void *security) #ifdef CONFIG_NETFILTER -static unsigned int selinux_ip_forward(struct sk_buff *skb, - const struct net_device *indev, - u16 family) +static unsigned int selinux_ip_forward(void *priv, struct sk_buff *skb, + const struct nf_hook_state *state) { + const struct net_device *indev = state->in; + u16 family = state->pf; int err; char *addrp; u32 peer_sid; @@ -5746,25 +5747,10 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, return NF_ACCEPT; } -static unsigned int selinux_ipv4_forward(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - return selinux_ip_forward(skb, state->in, PF_INET); -} - -#if IS_ENABLED(CONFIG_IPV6) -static unsigned int selinux_ipv6_forward(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - return selinux_ip_forward(skb, state->in, PF_INET6); -} -#endif /* IPV6 */ - -static unsigned int selinux_ip_output(struct sk_buff *skb, - u16 family) +static unsigned int selinux_ip_output(void *priv, struct sk_buff *skb, + const struct nf_hook_state *state) { + u16 family = state->pf; struct sock *sk; u32 sid; @@ -5804,21 +5790,6 @@ static unsigned int selinux_ip_output(struct sk_buff *skb, return NF_ACCEPT; } -static unsigned int selinux_ipv4_output(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - return selinux_ip_output(skb, PF_INET); -} - -#if IS_ENABLED(CONFIG_IPV6) -static unsigned int selinux_ipv6_output(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - return selinux_ip_output(skb, PF_INET6); -} -#endif /* IPV6 */ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, int ifindex, @@ -5854,10 +5825,12 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, return NF_ACCEPT; } -static unsigned int selinux_ip_postroute(struct sk_buff *skb, - const struct net_device *outdev, - u16 family) +static unsigned int selinux_ip_postroute(void *priv, + struct sk_buff *skb, + const struct nf_hook_state *state) { + const struct net_device *outdev = state->out; + u16 family = state->pf; u32 secmark_perm; u32 peer_sid; int ifindex = outdev->ifindex; @@ -5993,23 +5966,6 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, return NF_ACCEPT; } - -static unsigned int selinux_ipv4_postroute(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - return selinux_ip_postroute(skb, state->out, PF_INET); -} - -#if IS_ENABLED(CONFIG_IPV6) -static unsigned int selinux_ipv6_postroute(void *priv, - struct sk_buff *skb, - const struct nf_hook_state *state) -{ - return selinux_ip_postroute(skb, state->out, PF_INET6); -} -#endif /* IPV6 */ - #endif /* CONFIG_NETFILTER */ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) @@ -7470,38 +7426,38 @@ DEFINE_LSM(selinux) = { static const struct nf_hook_ops selinux_nf_ops[] = { { - .hook = selinux_ipv4_postroute, + .hook = selinux_ip_postroute, .pf = NFPROTO_IPV4, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP_PRI_SELINUX_LAST, }, { - .hook = selinux_ipv4_forward, + .hook = selinux_ip_forward, .pf = NFPROTO_IPV4, .hooknum = NF_INET_FORWARD, .priority = NF_IP_PRI_SELINUX_FIRST, }, { - .hook = selinux_ipv4_output, + .hook = selinux_ip_output, .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_SELINUX_FIRST, }, #if IS_ENABLED(CONFIG_IPV6) { - .hook = selinux_ipv6_postroute, + .hook = selinux_ip_postroute, .pf = NFPROTO_IPV6, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP6_PRI_SELINUX_LAST, }, { - .hook = selinux_ipv6_forward, + .hook = selinux_ip_forward, .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = NF_IP6_PRI_SELINUX_FIRST, }, { - .hook = selinux_ipv6_output, + .hook = selinux_ip_output, .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP6_PRI_SELINUX_FIRST, -- 2.32.0