| From dafa2d19d9606544a1f0f4d95ce63513960a1da7 Mon Sep 17 00:00:00 2001 |
| From: Arnd Bergmann <arnd@arndb.de> |
| Date: Wed, 8 Apr 2020 21:04:31 +0200 |
| Subject: [PATCH] smack: avoid unused 'sip' variable warning |
| |
| commit 00720f0e7f288d29681d265c23b22bb0f0f4e5b4 upstream. |
| |
| The mix of IS_ENABLED() and #ifdef checks has left a combination |
| that causes a warning about an unused variable: |
| |
| security/smack/smack_lsm.c: In function 'smack_socket_connect': |
| security/smack/smack_lsm.c:2838:24: error: unused variable 'sip' [-Werror=unused-variable] |
| 2838 | struct sockaddr_in6 *sip = (struct sockaddr_in6 *)sap; |
| |
| Change the code to use C-style checks consistently so the compiler |
| can handle it correctly. |
| |
| Fixes: 87fbfffcc89b ("broken ping to ipv6 linklocal addresses on debian buster") |
| Signed-off-by: Arnd Bergmann <arnd@arndb.de> |
| Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/security/smack/smack.h b/security/smack/smack.h |
| index 62529f382942..335d2411abe4 100644 |
| --- a/security/smack/smack.h |
| +++ b/security/smack/smack.h |
| @@ -148,7 +148,6 @@ struct smk_net4addr { |
| struct smack_known *smk_label; /* label */ |
| }; |
| |
| -#if IS_ENABLED(CONFIG_IPV6) |
| /* |
| * An entry in the table identifying IPv6 hosts. |
| */ |
| @@ -159,9 +158,7 @@ struct smk_net6addr { |
| int smk_masks; /* mask size */ |
| struct smack_known *smk_label; /* label */ |
| }; |
| -#endif /* CONFIG_IPV6 */ |
| |
| -#ifdef SMACK_IPV6_PORT_LABELING |
| /* |
| * An entry in the table identifying ports. |
| */ |
| @@ -174,7 +171,6 @@ struct smk_port_label { |
| short smk_sock_type; /* Socket type */ |
| short smk_can_reuse; |
| }; |
| -#endif /* SMACK_IPV6_PORT_LABELING */ |
| |
| struct smack_known_list_elem { |
| struct list_head list; |
| @@ -335,9 +331,7 @@ extern struct smack_known smack_known_web; |
| extern struct mutex smack_known_lock; |
| extern struct list_head smack_known_list; |
| extern struct list_head smk_net4addr_list; |
| -#if IS_ENABLED(CONFIG_IPV6) |
| extern struct list_head smk_net6addr_list; |
| -#endif /* CONFIG_IPV6 */ |
| |
| extern struct mutex smack_onlycap_lock; |
| extern struct list_head smack_onlycap_list; |
| diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c |
| index 260811de3c58..f3781622a04d 100644 |
| --- a/security/smack/smack_lsm.c |
| +++ b/security/smack/smack_lsm.c |
| @@ -51,10 +51,8 @@ |
| #define SMK_RECEIVING 1 |
| #define SMK_SENDING 2 |
| |
| -#ifdef SMACK_IPV6_PORT_LABELING |
| -DEFINE_MUTEX(smack_ipv6_lock); |
| +static DEFINE_MUTEX(smack_ipv6_lock); |
| static LIST_HEAD(smk_ipv6_port_list); |
| -#endif |
| static struct kmem_cache *smack_inode_cache; |
| struct kmem_cache *smack_rule_cache; |
| int smack_enabled; |
| @@ -2330,7 +2328,6 @@ static struct smack_known *smack_ipv4host_label(struct sockaddr_in *sip) |
| return NULL; |
| } |
| |
| -#if IS_ENABLED(CONFIG_IPV6) |
| /* |
| * smk_ipv6_localhost - Check for local ipv6 host address |
| * @sip: the address |
| @@ -2398,7 +2395,6 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip) |
| |
| return NULL; |
| } |
| -#endif /* CONFIG_IPV6 */ |
| |
| /** |
| * smack_netlabel - Set the secattr on a socket |
| @@ -2487,7 +2483,6 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap) |
| return smack_netlabel(sk, sk_lbl); |
| } |
| |
| -#if IS_ENABLED(CONFIG_IPV6) |
| /** |
| * smk_ipv6_check - check Smack access |
| * @subject: subject Smack label |
| @@ -2520,7 +2515,6 @@ static int smk_ipv6_check(struct smack_known *subject, |
| rc = smk_bu_note("IPv6 check", subject, object, MAY_WRITE, rc); |
| return rc; |
| } |
| -#endif /* CONFIG_IPV6 */ |
| |
| #ifdef SMACK_IPV6_PORT_LABELING |
| /** |
| @@ -2609,6 +2603,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address) |
| mutex_unlock(&smack_ipv6_lock); |
| return; |
| } |
| +#endif |
| |
| /** |
| * smk_ipv6_port_check - check Smack port access |
| @@ -2670,7 +2665,6 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address, |
| |
| return smk_ipv6_check(skp, object, address, act); |
| } |
| -#endif /* SMACK_IPV6_PORT_LABELING */ |
| |
| /** |
| * smack_inode_setsecurity - set smack xattrs |
| @@ -2845,24 +2839,21 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap, |
| return 0; |
| if (IS_ENABLED(CONFIG_IPV6) && sap->sa_family == AF_INET6) { |
| struct sockaddr_in6 *sip = (struct sockaddr_in6 *)sap; |
| -#ifdef SMACK_IPV6_SECMARK_LABELING |
| - struct smack_known *rsp; |
| -#endif |
| + struct smack_known *rsp = NULL; |
| |
| if (addrlen < SIN6_LEN_RFC2133) |
| return 0; |
| -#ifdef SMACK_IPV6_SECMARK_LABELING |
| - rsp = smack_ipv6host_label(sip); |
| + if (__is_defined(SMACK_IPV6_SECMARK_LABELING)) |
| + rsp = smack_ipv6host_label(sip); |
| if (rsp != NULL) { |
| struct socket_smack *ssp = sock->sk->sk_security; |
| |
| rc = smk_ipv6_check(ssp->smk_out, rsp, sip, |
| SMK_CONNECTING); |
| } |
| -#endif |
| -#ifdef SMACK_IPV6_PORT_LABELING |
| - rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING); |
| -#endif |
| + if (__is_defined(SMACK_IPV6_PORT_LABELING)) |
| + rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING); |
| + |
| return rc; |
| } |
| if (sap->sa_family != AF_INET || addrlen < sizeof(struct sockaddr_in)) |
| -- |
| 2.7.4 |
| |