Skip to content

Commit 85c3222

Browse files
Paolo Abenipcmoore
authored andcommitted
selinux: Implement mptcp_add_subflow hook
Newly added subflows should inherit the LSM label from the associated MPTCP socket regardless of the current context. This patch implements the above copying sid and class from the MPTCP socket context, deleting the existing subflow label, if any, and then re-creating the correct one. The new helper reuses the selinux_netlbl_sk_security_free() function, and the latter can end-up being called multiple times with the same argument; we additionally need to make it idempotent. Signed-off-by: Paolo Abeni <pabeni@redhat.com> Acked-by: Matthieu Baerts <matthieu.baerts@tessares.net> Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent e3d9387 commit 85c3222

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

security/selinux/hooks.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,6 +5379,21 @@ static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk
53795379
selinux_netlbl_sctp_sk_clone(sk, newsk);
53805380
}
53815381

5382+
static int selinux_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
5383+
{
5384+
struct sk_security_struct *ssksec = ssk->sk_security;
5385+
struct sk_security_struct *sksec = sk->sk_security;
5386+
5387+
ssksec->sclass = sksec->sclass;
5388+
ssksec->sid = sksec->sid;
5389+
5390+
/* replace the existing subflow label deleting the existing one
5391+
* and re-recreating a new label using the updated context
5392+
*/
5393+
selinux_netlbl_sk_security_free(ssksec);
5394+
return selinux_netlbl_socket_post_create(ssk, ssk->sk_family);
5395+
}
5396+
53825397
static int selinux_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
53835398
struct request_sock *req)
53845399
{
@@ -7074,6 +7089,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
70747089
LSM_HOOK_INIT(sctp_sk_clone, selinux_sctp_sk_clone),
70757090
LSM_HOOK_INIT(sctp_bind_connect, selinux_sctp_bind_connect),
70767091
LSM_HOOK_INIT(sctp_assoc_established, selinux_sctp_assoc_established),
7092+
LSM_HOOK_INIT(mptcp_add_subflow, selinux_mptcp_add_subflow),
70777093
LSM_HOOK_INIT(inet_conn_request, selinux_inet_conn_request),
70787094
LSM_HOOK_INIT(inet_csk_clone, selinux_inet_csk_clone),
70797095
LSM_HOOK_INIT(inet_conn_established, selinux_inet_conn_established),

security/selinux/netlabel.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,12 @@ void selinux_netlbl_err(struct sk_buff *skb, u16 family, int error, int gateway)
154154
*/
155155
void selinux_netlbl_sk_security_free(struct sk_security_struct *sksec)
156156
{
157-
if (sksec->nlbl_secattr != NULL)
158-
netlbl_secattr_free(sksec->nlbl_secattr);
157+
if (!sksec->nlbl_secattr)
158+
return;
159+
160+
netlbl_secattr_free(sksec->nlbl_secattr);
161+
sksec->nlbl_secattr = NULL;
162+
sksec->nlbl_state = NLBL_UNSET;
159163
}
160164

161165
/**

0 commit comments

Comments
 (0)