@@ -965,6 +965,7 @@ int netlbl_enabled(void)
965
965
* @sk: the socket to label
966
966
* @family: protocol family
967
967
* @secattr: the security attributes
968
+ * @sk_locked: true if caller holds the socket lock
968
969
*
969
970
* Description:
970
971
* Attach the correct label to the given socket using the security attributes
@@ -977,7 +978,8 @@ int netlbl_enabled(void)
977
978
*/
978
979
int netlbl_sock_setattr (struct sock * sk ,
979
980
u16 family ,
980
- const struct netlbl_lsm_secattr * secattr )
981
+ const struct netlbl_lsm_secattr * secattr ,
982
+ bool sk_locked )
981
983
{
982
984
int ret_val ;
983
985
struct netlbl_dom_map * dom_entry ;
@@ -997,7 +999,7 @@ int netlbl_sock_setattr(struct sock *sk,
997
999
case NETLBL_NLTYPE_CIPSOV4 :
998
1000
ret_val = cipso_v4_sock_setattr (sk ,
999
1001
dom_entry -> def .cipso ,
1000
- secattr );
1002
+ secattr , sk_locked );
1001
1003
break ;
1002
1004
case NETLBL_NLTYPE_UNLABELED :
1003
1005
ret_val = 0 ;
@@ -1090,6 +1092,28 @@ int netlbl_sock_getattr(struct sock *sk,
1090
1092
return ret_val ;
1091
1093
}
1092
1094
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
+
1093
1117
/**
1094
1118
* netlbl_conn_setattr - Label a connected socket using the correct protocol
1095
1119
* @sk: the socket to label
@@ -1126,7 +1150,8 @@ int netlbl_conn_setattr(struct sock *sk,
1126
1150
switch (entry -> type ) {
1127
1151
case NETLBL_NLTYPE_CIPSOV4 :
1128
1152
ret_val = cipso_v4_sock_setattr (sk ,
1129
- entry -> cipso , secattr );
1153
+ entry -> cipso , secattr ,
1154
+ netlbl_sk_lock_check (sk ));
1130
1155
break ;
1131
1156
case NETLBL_NLTYPE_UNLABELED :
1132
1157
/* just delete the protocols we support for right now
0 commit comments