lsm: fix default return value of the socket_getpeersec_*() hooks
For these hooks the true "neutral" value is -EOPNOTSUPP, which is currently what is returned when no LSM provides this hook and what LSMs return when there is no security context set on the socket. Correct the value in <linux/lsm_hooks.h> and adjust the dispatch functions in security/security.c to avoid issues when the BPF LSM is enabled. Cc: stable@vger.kernel.org Fixes: 98e828a0650f ("security: Refactor declaration of LSM hooks") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> [PM: subject line tweak] Signed-off-by: Paul Moore <paul@paul-moore.com>
This commit is contained in:
parent
99b817c173
commit
5a287d3d2b
@ -315,9 +315,9 @@ LSM_HOOK(int, 0, socket_getsockopt, struct socket *sock, int level, int optname)
|
|||||||
LSM_HOOK(int, 0, socket_setsockopt, struct socket *sock, int level, int optname)
|
LSM_HOOK(int, 0, socket_setsockopt, struct socket *sock, int level, int optname)
|
||||||
LSM_HOOK(int, 0, socket_shutdown, struct socket *sock, int how)
|
LSM_HOOK(int, 0, socket_shutdown, struct socket *sock, int how)
|
||||||
LSM_HOOK(int, 0, socket_sock_rcv_skb, struct sock *sk, struct sk_buff *skb)
|
LSM_HOOK(int, 0, socket_sock_rcv_skb, struct sock *sk, struct sk_buff *skb)
|
||||||
LSM_HOOK(int, 0, socket_getpeersec_stream, struct socket *sock,
|
LSM_HOOK(int, -ENOPROTOOPT, socket_getpeersec_stream, struct socket *sock,
|
||||||
sockptr_t optval, sockptr_t optlen, unsigned int len)
|
sockptr_t optval, sockptr_t optlen, unsigned int len)
|
||||||
LSM_HOOK(int, 0, socket_getpeersec_dgram, struct socket *sock,
|
LSM_HOOK(int, -ENOPROTOOPT, socket_getpeersec_dgram, struct socket *sock,
|
||||||
struct sk_buff *skb, u32 *secid)
|
struct sk_buff *skb, u32 *secid)
|
||||||
LSM_HOOK(int, 0, sk_alloc_security, struct sock *sk, int family, gfp_t priority)
|
LSM_HOOK(int, 0, sk_alloc_security, struct sock *sk, int family, gfp_t priority)
|
||||||
LSM_HOOK(void, LSM_RET_VOID, sk_free_security, struct sock *sk)
|
LSM_HOOK(void, LSM_RET_VOID, sk_free_security, struct sock *sk)
|
||||||
|
@ -4624,8 +4624,20 @@ EXPORT_SYMBOL(security_sock_rcv_skb);
|
|||||||
int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval,
|
int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval,
|
||||||
sockptr_t optlen, unsigned int len)
|
sockptr_t optlen, unsigned int len)
|
||||||
{
|
{
|
||||||
return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
|
struct security_hook_list *hp;
|
||||||
optval, optlen, len);
|
int rc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only one module will provide a security context.
|
||||||
|
*/
|
||||||
|
hlist_for_each_entry(hp, &security_hook_heads.socket_getpeersec_stream,
|
||||||
|
list) {
|
||||||
|
rc = hp->hook.socket_getpeersec_stream(sock, optval, optlen,
|
||||||
|
len);
|
||||||
|
if (rc != LSM_RET_DEFAULT(socket_getpeersec_stream))
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
return LSM_RET_DEFAULT(socket_getpeersec_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4645,8 +4657,19 @@ int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval,
|
|||||||
int security_socket_getpeersec_dgram(struct socket *sock,
|
int security_socket_getpeersec_dgram(struct socket *sock,
|
||||||
struct sk_buff *skb, u32 *secid)
|
struct sk_buff *skb, u32 *secid)
|
||||||
{
|
{
|
||||||
return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
|
struct security_hook_list *hp;
|
||||||
skb, secid);
|
int rc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only one module will provide a security context.
|
||||||
|
*/
|
||||||
|
hlist_for_each_entry(hp, &security_hook_heads.socket_getpeersec_dgram,
|
||||||
|
list) {
|
||||||
|
rc = hp->hook.socket_getpeersec_dgram(sock, skb, secid);
|
||||||
|
if (rc != LSM_RET_DEFAULT(socket_getpeersec_dgram))
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
return LSM_RET_DEFAULT(socket_getpeersec_dgram);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user