@@ -965,6 +965,7 @@ int netlbl_enabled(void)
965965 * @sk: the socket to label
966966 * @family: protocol family
967967 * @secattr: the security attributes
968+ * @sk_locked: true if caller holds the socket lock
968969 *
969970 * Description:
970971 * Attach the correct label to the given socket using the security attributes
@@ -977,7 +978,8 @@ int netlbl_enabled(void)
977978 */
978979int netlbl_sock_setattr (struct sock * sk ,
979980 u16 family ,
980- const struct netlbl_lsm_secattr * secattr )
981+ const struct netlbl_lsm_secattr * secattr ,
982+ bool sk_locked )
981983{
982984 int ret_val ;
983985 struct netlbl_dom_map * dom_entry ;
@@ -997,7 +999,7 @@ int netlbl_sock_setattr(struct sock *sk,
997999 case NETLBL_NLTYPE_CIPSOV4 :
9981000 ret_val = cipso_v4_sock_setattr (sk ,
9991001 dom_entry -> def .cipso ,
1000- secattr );
1002+ secattr , sk_locked );
10011003 break ;
10021004 case NETLBL_NLTYPE_UNLABELED :
10031005 ret_val = 0 ;
@@ -1090,6 +1092,28 @@ int netlbl_sock_getattr(struct sock *sk,
10901092 return ret_val ;
10911093}
10921094
1095+ /**
1096+ * netlbl_sk_lock_check - Check if the socket lock has been acquired.
1097+ * @sk: the socket to be checked
1098+ *
1099+ * Return: true if socket @sk is locked or if lock debugging is disabled at
1100+ * runtime or compile-time; false otherwise
1101+ *
1102+ */
1103+ #ifdef CONFIG_LOCKDEP
1104+ bool netlbl_sk_lock_check (struct sock * sk )
1105+ {
1106+ if (debug_locks )
1107+ return lockdep_sock_is_held (sk );
1108+ return true;
1109+ }
1110+ #else
1111+ bool netlbl_sk_lock_check (struct sock * sk )
1112+ {
1113+ return true;
1114+ }
1115+ #endif
1116+
10931117/**
10941118 * netlbl_conn_setattr - Label a connected socket using the correct protocol
10951119 * @sk: the socket to label
@@ -1126,7 +1150,8 @@ int netlbl_conn_setattr(struct sock *sk,
11261150 switch (entry -> type ) {
11271151 case NETLBL_NLTYPE_CIPSOV4 :
11281152 ret_val = cipso_v4_sock_setattr (sk ,
1129- entry -> cipso , secattr );
1153+ entry -> cipso , secattr ,
1154+ netlbl_sk_lock_check (sk ));
11301155 break ;
11311156 case NETLBL_NLTYPE_UNLABELED :
11321157 /* just delete the protocols we support for right now
0 commit comments