Skip to content

Commit

Permalink
SMACK: Add sk_clone_security LSM hook
Browse files Browse the repository at this point in the history
Using smk_of_current() during sk_alloc_security hook leads in
rare cases to a faulty initialization of the security context
of the created socket.

By adding the LSM hook sk_clone_security to SMACK this initialization
fault is corrected by copying the security context of the old socket
pointer to the newly cloned one.

Co-authored-by: Martin Ostertag: <[email protected]>
Signed-off-by: Lontke Michael <[email protected]>
Signed-off-by: Casey Schaufler <[email protected]>
  • Loading branch information
2 people authored and cschaufler committed Sep 27, 2022
1 parent b90cb10 commit 4ca165f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,21 @@ static void smack_sk_free_security(struct sock *sk)
kfree(sk->sk_security);
}

/**
* smack_sk_clone_security - Copy security context
* @sk: the old socket
* @newsk: the new socket
*
* Copy the security context of the old socket pointer to the cloned
*/
static void smack_sk_clone_security(const struct sock *sk, struct sock *newsk)
{
struct socket_smack *ssp_old = sk->sk_security;
struct socket_smack *ssp_new = newsk->sk_security;

*ssp_new = *ssp_old;
}

/**
* smack_ipv4host_label - check host based restrictions
* @sip: the object end
Expand Down Expand Up @@ -4851,6 +4866,7 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
LSM_HOOK_INIT(socket_getpeersec_dgram, smack_socket_getpeersec_dgram),
LSM_HOOK_INIT(sk_alloc_security, smack_sk_alloc_security),
LSM_HOOK_INIT(sk_free_security, smack_sk_free_security),
LSM_HOOK_INIT(sk_clone_security, smack_sk_clone_security),
LSM_HOOK_INIT(sock_graft, smack_sock_graft),
LSM_HOOK_INIT(inet_conn_request, smack_inet_conn_request),
LSM_HOOK_INIT(inet_csk_clone, smack_inet_csk_clone),
Expand Down

0 comments on commit 4ca165f

Please sign in to comment.