Skip to content

Commit 1f440c9

Browse files
hdmdaviespcmoore
authored andcommitted
netlabel: Prevent setsockopt() from changing the hop-by-hop option.
If a socket has a netlabel in place then don't let setsockopt() alter the socket's IPv6 hop-by-hop option. This is in the same spirit as the existing check for IPv4. Signed-off-by: Huw Davies <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent ceba183 commit 1f440c9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

security/selinux/netlabel.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,21 @@ int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec,
409409
return rc;
410410
}
411411

412+
/**
413+
* selinux_netlbl_option - Is this a NetLabel option
414+
* @level: the socket level or protocol
415+
* @optname: the socket option name
416+
*
417+
* Description:
418+
* Returns true if @level and @optname refer to a NetLabel option.
419+
* Helper for selinux_netlbl_socket_setsockopt().
420+
*/
421+
static inline int selinux_netlbl_option(int level, int optname)
422+
{
423+
return (level == IPPROTO_IP && optname == IP_OPTIONS) ||
424+
(level == IPPROTO_IPV6 && optname == IPV6_HOPOPTS);
425+
}
426+
412427
/**
413428
* selinux_netlbl_socket_setsockopt - Do not allow users to remove a NetLabel
414429
* @sock: the socket
@@ -431,7 +446,7 @@ int selinux_netlbl_socket_setsockopt(struct socket *sock,
431446
struct sk_security_struct *sksec = sk->sk_security;
432447
struct netlbl_lsm_secattr secattr;
433448

434-
if (level == IPPROTO_IP && optname == IP_OPTIONS &&
449+
if (selinux_netlbl_option(level, optname) &&
435450
(sksec->nlbl_state == NLBL_LABELED ||
436451
sksec->nlbl_state == NLBL_CONNLABELED)) {
437452
netlbl_secattr_init(&secattr);

0 commit comments

Comments
 (0)