Received: by 2002:a05:6520:1682:b0:147:d1a0:b502 with SMTP id ck2csp5596739lkb; Mon, 11 Oct 2021 09:39:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlLCLpQDeTRmO6897FoFWNFIzBrTxLoiPrMm3VeiRu81h/+pa8bm22oWrunURTKi12iF6J X-Received: by 2002:a63:cc49:: with SMTP id q9mr19233320pgi.463.1633970357165; Mon, 11 Oct 2021 09:39:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633970357; cv=none; d=google.com; s=arc-20160816; b=M8KOvzEiEHmUZ0JFdFgKxqi0YCntDcj2x4gQdFxAD9Fzj6VIT0OeAW2Jimb9Vq4c2b z2V1ii7sySjiHxAModXpiWRPSUOxaMN/YiN5Gg1dqI4F1EMoRI/keBUaUFPAxGsL8lW8 OE1bUa38Yvw5fTlseTjn1sS8FqwoWKDQmB2AVJBo09vIy9Z5EK1XKFYZGpRJSgGQSWNE m5gv4gH2qSvO/e+kRCoIWa48KMPLnjLkUSj7S2CSLWB83fc5Rs0vKDhE1fs7i2OKihY5 f91XCxFs/okHped4jLF2QzAOmQtwiJOhBkmHoypRZgKUy0DIz3slDnq2m+KfFJmbBJCg A/IQ== 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=FhTfFFfrlEwGqBmtSNP/IcDe1n3fOdQ9suJP2Z13nRU=; b=aasss9TNMRK4lcbSCJgWFLV/zCT2M1pFluc1HnCFDXiG6A7/sCdPAUbJ/94lOZ39WI Vx5WDujDvb2fdY/Q9InvqnkNgw7+Nyz5I8QmX09qXVNUvmlFcHT9/4ur25UIDZqoC/FA zxK3yWd/bOVNif7XOdqioKnmERFPT3srlGO9U/nHAIEfVR0Y7JJjb/AXUOcrRKv4jkj4 kgJUMRY0e14g150VvJYutKcvS1uUzTqt99J4vVwfSicI99Kc3JQJegeuI6Gm1GqPGLUi ZQ2EFyGbOsouG6q/RvJSna8CO83SlapsB1GlPUDXN6+/WiREWHkAa/unu91eLDoSNwPV sBNw== 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 u4si11764441pgp.53.2021.10.11.09.39.04; Mon, 11 Oct 2021 09:39:17 -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 S242432AbhJKOdw (ORCPT + 99 others); Mon, 11 Oct 2021 10:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231716AbhJKOdp (ORCPT ); Mon, 11 Oct 2021 10:33:45 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90182C061346; Mon, 11 Oct 2021 07:25:41 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1mZwFF-0001Vl-OB; Mon, 11 Oct 2021 16:25:37 +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, Florian Westphal Subject: [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers Date: Mon, 11 Oct 2021 16:24:16 +0200 Message-Id: <20211011142416.26798-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. Signed-off-by: Florian Westphal --- v2: add back '#endif /* CONFIG_NETFILTER */' erronously axed in v1. Applies to 'next' branch of https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/ security/selinux/hooks.c | 52 ++++++++++------------------------------ 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index e7ebd45ca345..831b857d5dd7 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -5746,22 +5746,13 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, return NF_ACCEPT; } -static unsigned int selinux_ipv4_forward(void *priv, +static unsigned int selinux_hook_forward(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { - return selinux_ip_forward(skb, state->in, PF_INET); + return selinux_ip_forward(skb, state->in, state->pf); } -#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) { @@ -5804,21 +5795,12 @@ 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, +static unsigned int selinux_hook_output(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { - return selinux_ip_output(skb, PF_INET6); + return selinux_ip_output(skb, state->pf); } -#endif /* IPV6 */ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, int ifindex, @@ -5994,22 +5976,12 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, return NF_ACCEPT; } -static unsigned int selinux_ipv4_postroute(void *priv, +static unsigned int selinux_hook_postroute(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { - return selinux_ip_postroute(skb, state->out, PF_INET); + return selinux_ip_postroute(skb, state->out, state->pf); } - -#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 +7442,38 @@ DEFINE_LSM(selinux) = { static const struct nf_hook_ops selinux_nf_ops[] = { { - .hook = selinux_ipv4_postroute, + .hook = selinux_hook_postroute, .pf = NFPROTO_IPV4, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP_PRI_SELINUX_LAST, }, { - .hook = selinux_ipv4_forward, + .hook = selinux_hook_forward, .pf = NFPROTO_IPV4, .hooknum = NF_INET_FORWARD, .priority = NF_IP_PRI_SELINUX_FIRST, }, { - .hook = selinux_ipv4_output, + .hook = selinux_hook_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_hook_postroute, .pf = NFPROTO_IPV6, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP6_PRI_SELINUX_LAST, }, { - .hook = selinux_ipv6_forward, + .hook = selinux_hook_forward, .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = NF_IP6_PRI_SELINUX_FIRST, }, { - .hook = selinux_ipv6_output, + .hook = selinux_hook_output, .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP6_PRI_SELINUX_FIRST, -- 2.32.0