Skip to content

Commit 00720f0

Browse files
arndbcschaufler
authored andcommitted
smack: avoid unused 'sip' variable warning
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: 87fbfff ("broken ping to ipv6 linklocal addresses on debian buster") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent 7111951 commit 00720f0

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

security/smack/smack.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ struct smk_net4addr {
148148
struct smack_known *smk_label; /* label */
149149
};
150150

151-
#if IS_ENABLED(CONFIG_IPV6)
152151
/*
153152
* An entry in the table identifying IPv6 hosts.
154153
*/
@@ -159,9 +158,7 @@ struct smk_net6addr {
159158
int smk_masks; /* mask size */
160159
struct smack_known *smk_label; /* label */
161160
};
162-
#endif /* CONFIG_IPV6 */
163161

164-
#ifdef SMACK_IPV6_PORT_LABELING
165162
/*
166163
* An entry in the table identifying ports.
167164
*/
@@ -174,7 +171,6 @@ struct smk_port_label {
174171
short smk_sock_type; /* Socket type */
175172
short smk_can_reuse;
176173
};
177-
#endif /* SMACK_IPV6_PORT_LABELING */
178174

179175
struct smack_known_list_elem {
180176
struct list_head list;
@@ -335,9 +331,7 @@ extern struct smack_known smack_known_web;
335331
extern struct mutex smack_known_lock;
336332
extern struct list_head smack_known_list;
337333
extern struct list_head smk_net4addr_list;
338-
#if IS_ENABLED(CONFIG_IPV6)
339334
extern struct list_head smk_net6addr_list;
340-
#endif /* CONFIG_IPV6 */
341335

342336
extern struct mutex smack_onlycap_lock;
343337
extern struct list_head smack_onlycap_list;

security/smack/smack_lsm.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@
5050
#define SMK_RECEIVING 1
5151
#define SMK_SENDING 2
5252

53-
#ifdef SMACK_IPV6_PORT_LABELING
54-
DEFINE_MUTEX(smack_ipv6_lock);
53+
static DEFINE_MUTEX(smack_ipv6_lock);
5554
static LIST_HEAD(smk_ipv6_port_list);
56-
#endif
5755
static struct kmem_cache *smack_inode_cache;
5856
struct kmem_cache *smack_rule_cache;
5957
int smack_enabled;
@@ -2320,7 +2318,6 @@ static struct smack_known *smack_ipv4host_label(struct sockaddr_in *sip)
23202318
return NULL;
23212319
}
23222320

2323-
#if IS_ENABLED(CONFIG_IPV6)
23242321
/*
23252322
* smk_ipv6_localhost - Check for local ipv6 host address
23262323
* @sip: the address
@@ -2388,7 +2385,6 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip)
23882385

23892386
return NULL;
23902387
}
2391-
#endif /* CONFIG_IPV6 */
23922388

23932389
/**
23942390
* smack_netlabel - Set the secattr on a socket
@@ -2477,7 +2473,6 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
24772473
return smack_netlabel(sk, sk_lbl);
24782474
}
24792475

2480-
#if IS_ENABLED(CONFIG_IPV6)
24812476
/**
24822477
* smk_ipv6_check - check Smack access
24832478
* @subject: subject Smack label
@@ -2510,7 +2505,6 @@ static int smk_ipv6_check(struct smack_known *subject,
25102505
rc = smk_bu_note("IPv6 check", subject, object, MAY_WRITE, rc);
25112506
return rc;
25122507
}
2513-
#endif /* CONFIG_IPV6 */
25142508

25152509
#ifdef SMACK_IPV6_PORT_LABELING
25162510
/**
@@ -2599,6 +2593,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
25992593
mutex_unlock(&smack_ipv6_lock);
26002594
return;
26012595
}
2596+
#endif
26022597

26032598
/**
26042599
* smk_ipv6_port_check - check Smack port access
@@ -2661,7 +2656,6 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
26612656

26622657
return smk_ipv6_check(skp, object, address, act);
26632658
}
2664-
#endif /* SMACK_IPV6_PORT_LABELING */
26652659

26662660
/**
26672661
* smack_inode_setsecurity - set smack xattrs
@@ -2836,24 +2830,21 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
28362830
return 0;
28372831
if (IS_ENABLED(CONFIG_IPV6) && sap->sa_family == AF_INET6) {
28382832
struct sockaddr_in6 *sip = (struct sockaddr_in6 *)sap;
2839-
#ifdef SMACK_IPV6_SECMARK_LABELING
2840-
struct smack_known *rsp;
2841-
#endif
2833+
struct smack_known *rsp = NULL;
28422834

28432835
if (addrlen < SIN6_LEN_RFC2133)
28442836
return 0;
2845-
#ifdef SMACK_IPV6_SECMARK_LABELING
2846-
rsp = smack_ipv6host_label(sip);
2837+
if (__is_defined(SMACK_IPV6_SECMARK_LABELING))
2838+
rsp = smack_ipv6host_label(sip);
28472839
if (rsp != NULL) {
28482840
struct socket_smack *ssp = sock->sk->sk_security;
28492841

28502842
rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
28512843
SMK_CONNECTING);
28522844
}
2853-
#endif
2854-
#ifdef SMACK_IPV6_PORT_LABELING
2855-
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2856-
#endif
2845+
if (__is_defined(SMACK_IPV6_PORT_LABELING))
2846+
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2847+
28572848
return rc;
28582849
}
28592850
if (sap->sa_family != AF_INET || addrlen < sizeof(struct sockaddr_in))

0 commit comments

Comments
 (0)