Skip to content

Commit 222a96b

Browse files
Sebastian Andrzej Siewiorcschaufler
authored andcommitted
smack: Guard smack_ipv6_lock definition within a SMACK_IPV6_PORT_LABELING block
The mutex smack_ipv6_lock is only used with the SMACK_IPV6_PORT_LABELING block but its definition is outside of the block. This leads to a defined-but-not-used warning on PREEMPT_RT. Moving smack_ipv6_lock down to the block where it is used where it used raises the question why is smk_ipv6_port_list read if nothing is added to it. Turns out, only smk_ipv6_port_check() is using it outside of an ifdef SMACK_IPV6_PORT_LABELING block. However two of three caller invoke smk_ipv6_port_check() from a ifdef block and only one is using __is_defined() macro which requires the function and smk_ipv6_port_list to be around. Put the lock and list inside an ifdef SMACK_IPV6_PORT_LABELING block to avoid the warning regarding unused mutex. Extend the ifdef-block to also cover smk_ipv6_port_check(). Make smack_socket_connect() use ifdef instead of __is_defined() to avoid complains about missing function. Cc: Casey Schaufler <[email protected]> Cc: James Morris <[email protected]> Cc: "Serge E. Hallyn" <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent 0817534 commit 222a96b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

security/smack/smack_lsm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
#define SMK_RECEIVING 1
5252
#define SMK_SENDING 2
5353

54+
#ifdef SMACK_IPV6_PORT_LABELING
5455
static DEFINE_MUTEX(smack_ipv6_lock);
5556
static LIST_HEAD(smk_ipv6_port_list);
57+
#endif
5658
struct kmem_cache *smack_rule_cache;
5759
int smack_enabled __initdata;
5860

@@ -2603,7 +2605,6 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
26032605
mutex_unlock(&smack_ipv6_lock);
26042606
return;
26052607
}
2606-
#endif
26072608

26082609
/**
26092610
* smk_ipv6_port_check - check Smack port access
@@ -2666,6 +2667,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
26662667

26672668
return smk_ipv6_check(skp, object, address, act);
26682669
}
2670+
#endif
26692671

26702672
/**
26712673
* smack_inode_setsecurity - set smack xattrs
@@ -2852,8 +2854,9 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
28522854
rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
28532855
SMK_CONNECTING);
28542856
}
2855-
if (__is_defined(SMACK_IPV6_PORT_LABELING))
2856-
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2857+
#ifdef SMACK_IPV6_PORT_LABELING
2858+
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2859+
#endif
28572860

28582861
return rc;
28592862
}

0 commit comments

Comments
 (0)