Skip to content

Commit e3d9387

Browse files
Paolo Abenipcmoore
authored andcommitted
security, lsm: Introduce security_mptcp_add_subflow()
MPTCP can create subflows in kernel context, and later indirectly expose them to user-space, via the owning MPTCP socket. As discussed in the reported link, the above causes unexpected failures for server, MPTCP-enabled applications. Let's introduce a new LSM hook to allow the security module to relabel the subflow according to the owning user-space process, via the MPTCP socket owning the subflow. Note that the new hook requires both the MPTCP socket and the new subflow. This could allow future extensions, e.g. explicitly validating the MPTCP <-> subflow linkage. Link: https://lore.kernel.org/mptcp/CAHC9VhTNh-YwiyTds=P1e3rixEDqbRTFj22bpya=+qJqfcaMfg@mail.gmail.com/ 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 c52df19 commit e3d9387

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ LSM_HOOK(void, LSM_RET_VOID, sctp_sk_clone, struct sctp_association *asoc,
343343
struct sock *sk, struct sock *newsk)
344344
LSM_HOOK(int, 0, sctp_assoc_established, struct sctp_association *asoc,
345345
struct sk_buff *skb)
346+
LSM_HOOK(int, 0, mptcp_add_subflow, struct sock *sk, struct sock *ssk)
346347
#endif /* CONFIG_SECURITY_NETWORK */
347348

348349
#ifdef CONFIG_SECURITY_INFINIBAND

include/linux/security.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk,
14651465
struct sock *newsk);
14661466
int security_sctp_assoc_established(struct sctp_association *asoc,
14671467
struct sk_buff *skb);
1468+
int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk);
14681469

14691470
#else /* CONFIG_SECURITY_NETWORK */
14701471
static inline int security_unix_stream_connect(struct sock *sock,
@@ -1692,6 +1693,11 @@ static inline int security_sctp_assoc_established(struct sctp_association *asoc,
16921693
{
16931694
return 0;
16941695
}
1696+
1697+
static inline int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
1698+
{
1699+
return 0;
1700+
}
16951701
#endif /* CONFIG_SECURITY_NETWORK */
16961702

16971703
#ifdef CONFIG_SECURITY_INFINIBAND

net/mptcp/subflow.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,10 @@ int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
16941694

16951695
lock_sock_nested(sf->sk, SINGLE_DEPTH_NESTING);
16961696

1697+
err = security_mptcp_add_subflow(sk, sf->sk);
1698+
if (err)
1699+
goto release_ssk;
1700+
16971701
/* the newly created socket has to be in the same cgroup as its parent */
16981702
mptcp_attach_cgroup(sk, sf->sk);
16991703

@@ -1706,6 +1710,8 @@ int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
17061710
get_net_track(net, &sf->sk->ns_tracker, GFP_KERNEL);
17071711
sock_inuse_add(net, 1);
17081712
err = tcp_set_ulp(sf->sk, "mptcp");
1713+
1714+
release_ssk:
17091715
release_sock(sf->sk);
17101716

17111717
if (err) {

security/security.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,6 +4667,23 @@ int security_sctp_assoc_established(struct sctp_association *asoc,
46674667
}
46684668
EXPORT_SYMBOL(security_sctp_assoc_established);
46694669

4670+
/**
4671+
* security_mptcp_add_subflow() - Inherit the LSM label from the MPTCP socket
4672+
* @sk: the owning MPTCP socket
4673+
* @ssk: the new subflow
4674+
*
4675+
* Update the labeling for the given MPTCP subflow, to match the one of the
4676+
* owning MPTCP socket. This hook has to be called after the socket creation and
4677+
* initialization via the security_socket_create() and
4678+
* security_socket_post_create() LSM hooks.
4679+
*
4680+
* Return: Returns 0 on success or a negative error code on failure.
4681+
*/
4682+
int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
4683+
{
4684+
return call_int_hook(mptcp_add_subflow, 0, sk, ssk);
4685+
}
4686+
46704687
#endif /* CONFIG_SECURITY_NETWORK */
46714688

46724689
#ifdef CONFIG_SECURITY_INFINIBAND

0 commit comments

Comments
 (0)