Skip to content

Commit

Permalink
security, lsm: Introduce security_mptcp_add_subflow()
Browse files Browse the repository at this point in the history
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 owing process.

Link: https://lore.kernel.org/mptcp/CAHC9VhTNh-YwiyTds=P1e3rixEDqbRTFj22bpya=+qJqfcaMfg@mail.gmail.com/
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Paolo Abeni authored and intel-lab-lkp committed Dec 14, 2022
1 parent 93761c9 commit 2ea8d62
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/lsm_hook_defs.h
Expand Up @@ -343,6 +343,7 @@ LSM_HOOK(void, LSM_RET_VOID, sctp_sk_clone, struct sctp_association *asoc,
struct sock *sk, struct sock *newsk)
LSM_HOOK(int, 0, sctp_assoc_established, struct sctp_association *asoc,
struct sk_buff *skb)
LSM_HOOK(int, 0, mptcp_add_subflow, struct sock *sk, struct sock *ssk)
#endif /* CONFIG_SECURITY_NETWORK */

#ifdef CONFIG_SECURITY_INFINIBAND
Expand Down
9 changes: 9 additions & 0 deletions include/linux/lsm_hooks.h
Expand Up @@ -1096,6 +1096,15 @@
* @skb pointer to skbuff of association packet.
* Return 0 if permission is granted.
*
* Security hooks for MPTCP
*
* @mptcp_add_subflow
* Update the labeling for the given MPTCP subflow, to match to
* owning MPTCP socket.
* @sk: the owning MPTCP socket
* @ssk: the new subflow
* Return 0 if successful, otherwise < 0 error code.
*
* Security hooks for Infiniband
*
* @ib_pkey_access:
Expand Down
6 changes: 6 additions & 0 deletions include/linux/security.h
Expand Up @@ -1479,6 +1479,7 @@ void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk,
struct sock *newsk);
int security_sctp_assoc_established(struct sctp_association *asoc,
struct sk_buff *skb);
int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk);

#else /* CONFIG_SECURITY_NETWORK */
static inline int security_unix_stream_connect(struct sock *sock,
Expand Down Expand Up @@ -1706,6 +1707,11 @@ static inline int security_sctp_assoc_established(struct sctp_association *asoc,
{
return 0;
}

int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
{
return 0;
}
#endif /* CONFIG_SECURITY_NETWORK */

#ifdef CONFIG_SECURITY_INFINIBAND
Expand Down
6 changes: 6 additions & 0 deletions net/mptcp/subflow.c
Expand Up @@ -1680,6 +1680,10 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)

lock_sock(sf->sk);

err = security_mptcp_add_subflow(sk, sf->sk);
if (err)
goto release_ssk;

/* the newly created socket has to be in the same cgroup as its parent */
mptcp_attach_cgroup(sk, sf->sk);

Expand All @@ -1692,6 +1696,8 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
get_net_track(net, &sf->sk->ns_tracker, GFP_KERNEL);
sock_inuse_add(net, 1);
err = tcp_set_ulp(sf->sk, "mptcp");

release_ssk:
release_sock(sf->sk);

if (err) {
Expand Down
5 changes: 5 additions & 0 deletions security/security.c
Expand Up @@ -2493,6 +2493,11 @@ int security_sctp_assoc_established(struct sctp_association *asoc,
}
EXPORT_SYMBOL(security_sctp_assoc_established);

int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
{
return call_int_hook(mptcp_add_subflow, 0, sk, ssk);
}

#endif /* CONFIG_SECURITY_NETWORK */

#ifdef CONFIG_SECURITY_INFINIBAND
Expand Down

0 comments on commit 2ea8d62

Please sign in to comment.