[PATCH LSM 2/2] selinux: Implement mptcp_add_subflow hook
Paul Moore
paul at paul-moore.com
Wed Apr 19 21:30:30 UTC 2023
On Wed, Apr 19, 2023 at 1:44 PM Matthieu Baerts
<matthieu.baerts at tessares.net> wrote:
> From: Paolo Abeni <pabeni at redhat.com>
>
> Newly added subflows should inherit the LSM label from the associated
> msk socket regarless current context.
"... from the associated main MPTCP socket regardless of the current context."
Us SELinux folks may not always be able to make the jump from "msk" to
"main MPTCP socket" when we are looking through the git log in the
future, let's make it easier on us/me ;)
> This patch implements the above copying sid and class from the msk
> context, deleting the existing subflow label, if any, and then
"... from the main MPTCP socket context, deleting ..."
> re-creating a new 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 at redhat.com>
> Acked-by: Matthieu Baerts <matthieu.baerts at tessares.net>
> Signed-off-by: Matthieu Baerts <matthieu.baerts at tessares.net>
> ---
> security/selinux/hooks.c | 16 ++++++++++++++++
> security/selinux/netlabel.c | 8 ++++++--
> 2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 9a5bdfc21314..53cfc1cb67d2 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -5476,6 +5476,21 @@ static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk
> selinux_netlbl_sctp_sk_clone(sk, newsk);
> }
>
> +static int selinux_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
> +{
> + struct sk_security_struct *ssksec = ssk->sk_security;
> + struct sk_security_struct *sksec = sk->sk_security;
> +
> + ssksec->sclass = sksec->sclass;
> + ssksec->sid = sksec->sid;
> +
> + /* replace the existing subflow label deleting the existing one
> + * and re-recrating a new label using the current context
"... new label using the updated context"
Let's avoid the phrase "current context" as that could imply the
current task, which is exactly what we are trying not to do.
> + */
> + selinux_netlbl_sk_security_free(ssksec);
> + return selinux_netlbl_socket_post_create(ssk, ssk->sk_family);
> +}
> +
--
paul-moore.com
More information about the Linux-security-module-archive
mailing list