Commit bfda63fa authored by Paul Moore's avatar Paul Moore

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: default avatarPaul Moore <paul@paul-moore.com>
parent 90593caf
...@@ -5193,11 +5193,11 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, ...@@ -5193,11 +5193,11 @@ static int selinux_socket_getpeersec_stream(struct socket *sock,
return err; return err;
} }
static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) static int selinux_socket_getpeersec_dgram(struct socket *sock,
struct sk_buff *skb, u32 *secid)
{ {
u32 peer_secid = SECSID_NULL; u32 peer_secid = SECSID_NULL;
u16 family; u16 family;
struct inode_security_struct *isec;
if (skb && skb->protocol == htons(ETH_P_IP)) if (skb && skb->protocol == htons(ETH_P_IP))
family = PF_INET; family = PF_INET;
...@@ -5205,19 +5205,21 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff * ...@@ -5205,19 +5205,21 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
family = PF_INET6; family = PF_INET6;
else if (sock) else if (sock)
family = sock->sk->sk_family; family = sock->sk->sk_family;
else else {
goto out; *secid = SECSID_NULL;
return -EINVAL;
}
if (sock && family == PF_UNIX) { if (sock && family == PF_UNIX) {
struct inode_security_struct *isec;
isec = inode_security_novalidate(SOCK_INODE(sock)); isec = inode_security_novalidate(SOCK_INODE(sock));
peer_secid = isec->sid; peer_secid = isec->sid;
} else if (skb) } else if (skb)
selinux_skb_peerlbl_sid(skb, family, &peer_secid); selinux_skb_peerlbl_sid(skb, family, &peer_secid);
out:
*secid = peer_secid; *secid = peer_secid;
if (peer_secid == SECSID_NULL) if (peer_secid == SECSID_NULL)
return -EINVAL; return -ENOPROTOOPT;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment