Skip to content

Commit bfda63f

Browse files
committed
selinux: correct return values in selinux_socket_getpeersec_dgram()
Instead of returning -EINVAL if any type of error occurs, limit -EINVAL to only those errors caused by passing a bad/invalid socket or packet/skb. In other cases where everything is correct but there isn't a valid peer label we return -ENOPROTOOPT. This helps make selinux_socket_getpeersec_dgram() more consistent with selinux_socket_getpeersec_stream(). Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 90593ca commit bfda63f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

security/selinux/hooks.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5193,31 +5193,33 @@ static int selinux_socket_getpeersec_stream(struct socket *sock,
51935193
return err;
51945194
}
51955195

5196-
static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
5196+
static int selinux_socket_getpeersec_dgram(struct socket *sock,
5197+
struct sk_buff *skb, u32 *secid)
51975198
{
51985199
u32 peer_secid = SECSID_NULL;
51995200
u16 family;
5200-
struct inode_security_struct *isec;
52015201

52025202
if (skb && skb->protocol == htons(ETH_P_IP))
52035203
family = PF_INET;
52045204
else if (skb && skb->protocol == htons(ETH_P_IPV6))
52055205
family = PF_INET6;
52065206
else if (sock)
52075207
family = sock->sk->sk_family;
5208-
else
5209-
goto out;
5208+
else {
5209+
*secid = SECSID_NULL;
5210+
return -EINVAL;
5211+
}
52105212

52115213
if (sock && family == PF_UNIX) {
5214+
struct inode_security_struct *isec;
52125215
isec = inode_security_novalidate(SOCK_INODE(sock));
52135216
peer_secid = isec->sid;
52145217
} else if (skb)
52155218
selinux_skb_peerlbl_sid(skb, family, &peer_secid);
52165219

5217-
out:
52185220
*secid = peer_secid;
52195221
if (peer_secid == SECSID_NULL)
5220-
return -EINVAL;
5222+
return -ENOPROTOOPT;
52215223
return 0;
52225224
}
52235225

0 commit comments

Comments
 (0)