Skip to content

Commit b616856

Browse files
Wenwen Wangdavem330
authored andcommitted
net: socket: fix a missing-check bug
In ethtool_ioctl(), the ioctl command 'ethcmd' is checked through a switch statement to see whether it is necessary to pre-process the ethtool structure, because, as mentioned in the comment, the structure ethtool_rxnfc is defined with padding. If yes, a user-space buffer 'rxnfc' is allocated through compat_alloc_user_space(). One thing to note here is that, if 'ethcmd' is ETHTOOL_GRXCLSRLALL, the size of the buffer 'rxnfc' is partially determined by 'rule_cnt', which is actually acquired from the user-space buffer 'compat_rxnfc', i.e., 'compat_rxnfc->rule_cnt', through get_user(). After 'rxnfc' is allocated, the data in the original user-space buffer 'compat_rxnfc' is then copied to 'rxnfc' through copy_in_user(), including the 'rule_cnt' field. However, after this copy, no check is re-enforced on 'rxnfc->rule_cnt'. So it is possible that a malicious user race to change the value in the 'compat_rxnfc->rule_cnt' between these two copies. Through this way, the attacker can bypass the previous check on 'rule_cnt' and inject malicious data. This can cause undefined behavior of the kernel and introduce potential security risk. This patch avoids the above issue via copying the value acquired by get_user() to 'rxnfc->rule_cn', if 'ethcmd' is ETHTOOL_GRXCLSRLALL. Signed-off-by: Wenwen Wang <wang6495@umn.edu> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3c53ed8 commit b616856

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/socket.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,9 +2875,14 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
28752875
copy_in_user(&rxnfc->fs.ring_cookie,
28762876
&compat_rxnfc->fs.ring_cookie,
28772877
(void __user *)(&rxnfc->fs.location + 1) -
2878-
(void __user *)&rxnfc->fs.ring_cookie) ||
2879-
copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
2880-
sizeof(rxnfc->rule_cnt)))
2878+
(void __user *)&rxnfc->fs.ring_cookie))
2879+
return -EFAULT;
2880+
if (ethcmd == ETHTOOL_GRXCLSRLALL) {
2881+
if (put_user(rule_cnt, &rxnfc->rule_cnt))
2882+
return -EFAULT;
2883+
} else if (copy_in_user(&rxnfc->rule_cnt,
2884+
&compat_rxnfc->rule_cnt,
2885+
sizeof(rxnfc->rule_cnt)))
28812886
return -EFAULT;
28822887
}
28832888

0 commit comments

Comments
 (0)