Skip to content

Commit bfcf400

Browse files
goongascschaufler
authored andcommitted
smack: dont compile ipv6 code unless ipv6 is configured
I want to be sure that ipv6-specific code is not compiled in kernel binaries if ipv6 is not configured. [1] was getting rid of "unused variable" warning, but, with that, it also mandated compilation of a handful ipv6- specific functions in ipv4-only kernel configurations: smk_ipv6_localhost, smack_ipv6host_label, smk_ipv6_check. Their compiled bodies are likely to be removed by compiler from the resulting binary, but, to be on the safe side, I remove them from the compiler view. [1] Fixes: 00720f0 ("smack: avoid unused 'sip' variable warning") Signed-off-by: Konstantin Andreev <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent 2aad5cd commit bfcf400

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

security/smack/smack.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ struct smk_net4addr {
152152
struct smack_known *smk_label; /* label */
153153
};
154154

155+
#if IS_ENABLED(CONFIG_IPV6)
155156
/*
156157
* An entry in the table identifying IPv6 hosts.
157158
*/
@@ -162,7 +163,9 @@ struct smk_net6addr {
162163
int smk_masks; /* mask size */
163164
struct smack_known *smk_label; /* label */
164165
};
166+
#endif /* CONFIG_IPV6 */
165167

168+
#ifdef SMACK_IPV6_PORT_LABELING
166169
/*
167170
* An entry in the table identifying ports.
168171
*/
@@ -175,6 +178,7 @@ struct smk_port_label {
175178
short smk_sock_type; /* Socket type */
176179
short smk_can_reuse;
177180
};
181+
#endif /* SMACK_IPV6_PORT_LABELING */
178182

179183
struct smack_known_list_elem {
180184
struct list_head list;
@@ -315,7 +319,9 @@ extern struct smack_known smack_known_web;
315319
extern struct mutex smack_known_lock;
316320
extern struct list_head smack_known_list;
317321
extern struct list_head smk_net4addr_list;
322+
#if IS_ENABLED(CONFIG_IPV6)
318323
extern struct list_head smk_net6addr_list;
324+
#endif /* CONFIG_IPV6 */
319325

320326
extern struct mutex smack_onlycap_lock;
321327
extern struct list_head smack_onlycap_list;

security/smack/smack_lsm.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,7 @@ static struct smack_known *smack_ipv4host_label(struct sockaddr_in *sip)
24922492
return NULL;
24932493
}
24942494

2495+
#if IS_ENABLED(CONFIG_IPV6)
24952496
/*
24962497
* smk_ipv6_localhost - Check for local ipv6 host address
24972498
* @sip: the address
@@ -2559,6 +2560,7 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip)
25592560

25602561
return NULL;
25612562
}
2563+
#endif /* CONFIG_IPV6 */
25622564

25632565
/**
25642566
* smack_netlbl_add - Set the secattr on a socket
@@ -2663,6 +2665,7 @@ static int smk_ipv4_check(struct sock *sk, struct sockaddr_in *sap)
26632665
return rc;
26642666
}
26652667

2668+
#if IS_ENABLED(CONFIG_IPV6)
26662669
/**
26672670
* smk_ipv6_check - check Smack access
26682671
* @subject: subject Smack label
@@ -2695,6 +2698,7 @@ static int smk_ipv6_check(struct smack_known *subject,
26952698
rc = smk_bu_note("IPv6 check", subject, object, MAY_WRITE, rc);
26962699
return rc;
26972700
}
2701+
#endif /* CONFIG_IPV6 */
26982702

26992703
#ifdef SMACK_IPV6_PORT_LABELING
27002704
/**
@@ -3027,7 +3031,9 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
30273031
return 0;
30283032
if (addrlen < offsetofend(struct sockaddr, sa_family))
30293033
return 0;
3030-
if (IS_ENABLED(CONFIG_IPV6) && sap->sa_family == AF_INET6) {
3034+
3035+
#if IS_ENABLED(CONFIG_IPV6)
3036+
if (sap->sa_family == AF_INET6) {
30313037
struct sockaddr_in6 *sip = (struct sockaddr_in6 *)sap;
30323038
struct smack_known *rsp = NULL;
30333039

@@ -3047,6 +3053,8 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
30473053

30483054
return rc;
30493055
}
3056+
#endif /* CONFIG_IPV6 */
3057+
30503058
if (sap->sa_family != AF_INET || addrlen < sizeof(struct sockaddr_in))
30513059
return 0;
30523060
rc = smk_ipv4_check(sock->sk, (struct sockaddr_in *)sap);

0 commit comments

Comments
 (0)