Skip to content

Commit 6d805af

Browse files
committed
Merge tag 'lsm-pr-20240131' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
Pull lsm fixes from Paul Moore: "Two small patches to fix some problems relating to LSM hook return values and how the individual LSMs interact" * tag 'lsm-pr-20240131' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm: lsm: fix default return value of the socket_getpeersec_*() hooks lsm: fix the logic in security_inode_getsecctx()
2 parents 6764c31 + 5a287d3 commit 6d805af

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ LSM_HOOK(int, 0, socket_getsockopt, struct socket *sock, int level, int optname)
315315
LSM_HOOK(int, 0, socket_setsockopt, struct socket *sock, int level, int optname)
316316
LSM_HOOK(int, 0, socket_shutdown, struct socket *sock, int how)
317317
LSM_HOOK(int, 0, socket_sock_rcv_skb, struct sock *sk, struct sk_buff *skb)
318-
LSM_HOOK(int, 0, socket_getpeersec_stream, struct socket *sock,
318+
LSM_HOOK(int, -ENOPROTOOPT, socket_getpeersec_stream, struct socket *sock,
319319
sockptr_t optval, sockptr_t optlen, unsigned int len)
320-
LSM_HOOK(int, 0, socket_getpeersec_dgram, struct socket *sock,
320+
LSM_HOOK(int, -ENOPROTOOPT, socket_getpeersec_dgram, struct socket *sock,
321321
struct sk_buff *skb, u32 *secid)
322322
LSM_HOOK(int, 0, sk_alloc_security, struct sock *sk, int family, gfp_t priority)
323323
LSM_HOOK(void, LSM_RET_VOID, sk_free_security, struct sock *sk)

security/security.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,7 +4255,19 @@ EXPORT_SYMBOL(security_inode_setsecctx);
42554255
*/
42564256
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
42574257
{
4258-
return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
4258+
struct security_hook_list *hp;
4259+
int rc;
4260+
4261+
/*
4262+
* Only one module will provide a security context.
4263+
*/
4264+
hlist_for_each_entry(hp, &security_hook_heads.inode_getsecctx, list) {
4265+
rc = hp->hook.inode_getsecctx(inode, ctx, ctxlen);
4266+
if (rc != LSM_RET_DEFAULT(inode_getsecctx))
4267+
return rc;
4268+
}
4269+
4270+
return LSM_RET_DEFAULT(inode_getsecctx);
42594271
}
42604272
EXPORT_SYMBOL(security_inode_getsecctx);
42614273

@@ -4612,8 +4624,20 @@ EXPORT_SYMBOL(security_sock_rcv_skb);
46124624
int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval,
46134625
sockptr_t optlen, unsigned int len)
46144626
{
4615-
return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
4616-
optval, optlen, len);
4627+
struct security_hook_list *hp;
4628+
int rc;
4629+
4630+
/*
4631+
* Only one module will provide a security context.
4632+
*/
4633+
hlist_for_each_entry(hp, &security_hook_heads.socket_getpeersec_stream,
4634+
list) {
4635+
rc = hp->hook.socket_getpeersec_stream(sock, optval, optlen,
4636+
len);
4637+
if (rc != LSM_RET_DEFAULT(socket_getpeersec_stream))
4638+
return rc;
4639+
}
4640+
return LSM_RET_DEFAULT(socket_getpeersec_stream);
46174641
}
46184642

46194643
/**
@@ -4633,8 +4657,19 @@ int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval,
46334657
int security_socket_getpeersec_dgram(struct socket *sock,
46344658
struct sk_buff *skb, u32 *secid)
46354659
{
4636-
return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
4637-
skb, secid);
4660+
struct security_hook_list *hp;
4661+
int rc;
4662+
4663+
/*
4664+
* Only one module will provide a security context.
4665+
*/
4666+
hlist_for_each_entry(hp, &security_hook_heads.socket_getpeersec_dgram,
4667+
list) {
4668+
rc = hp->hook.socket_getpeersec_dgram(sock, skb, secid);
4669+
if (rc != LSM_RET_DEFAULT(socket_getpeersec_dgram))
4670+
return rc;
4671+
}
4672+
return LSM_RET_DEFAULT(socket_getpeersec_dgram);
46384673
}
46394674
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
46404675

0 commit comments

Comments
 (0)