Skip to content

Commit 0781168

Browse files
Wenwen Wangdavem330
authored andcommitted
yam: fix a missing-check bug
In yam_ioctl(), the concrete ioctl command is firstly copied from the user-space buffer 'ifr->ifr_data' to 'ioctl_cmd' and checked through the following switch statement. If the command is not as expected, an error code EINVAL is returned. In the following execution the buffer 'ifr->ifr_data' is copied again in the cases of the switch statement to specific data structures according to what kind of ioctl command is requested. However, after the second copy, no re-check is enforced on the newly-copied command. Given that the buffer 'ifr->ifr_data' is in the user space, a malicious user can race to change the command between the two copies. This way, the attacker can inject inconsistent data and cause undefined behavior. This patch adds a re-check in each case of the switch statement if there is a second copy in that case, to re-check whether the command obtained in the second copy is the same as the one in the first copy. If not, an error code EINVAL will be returned. Signed-off-by: Wenwen Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 33aa8da commit 0781168

File tree

1 file changed

+4
-0
lines changed
  • drivers/net/hamradio

1 file changed

+4
-0
lines changed

drivers/net/hamradio/yam.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,8 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
966966
sizeof(struct yamdrv_ioctl_mcs));
967967
if (IS_ERR(ym))
968968
return PTR_ERR(ym);
969+
if (ym->cmd != SIOCYAMSMCS)
970+
return -EINVAL;
969971
if (ym->bitrate > YAM_MAXBITRATE) {
970972
kfree(ym);
971973
return -EINVAL;
@@ -981,6 +983,8 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
981983
if (copy_from_user(&yi, ifr->ifr_data, sizeof(struct yamdrv_ioctl_cfg)))
982984
return -EFAULT;
983985

986+
if (yi.cmd != SIOCYAMSCFG)
987+
return -EINVAL;
984988
if ((yi.cfg.mask & YAM_IOBASE) && netif_running(dev))
985989
return -EINVAL; /* Cannot change this parameter when up */
986990
if ((yi.cfg.mask & YAM_IRQ) && netif_running(dev))

0 commit comments

Comments
 (0)