aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWenwen Wang <wang6495@umn.edu>2018-10-05 11:59:36 -0400
committerDavid S. Miller <davem@davemloft.net>2018-10-05 14:54:55 -0400
commit0781168e23a2fc8dceb989f11fc5b39b3ccacc35 (patch)
tree2712d98048d8297fa79067427e0a251e5fc72f90
parent33aa8da1f8a7dc050b9d68f1db761ab787621065 (diff)
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 <wang6495@umn.edu> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/hamradio/yam.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 16ec7af6ab7b..ba9df430fca6 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -966,6 +966,8 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
966 sizeof(struct yamdrv_ioctl_mcs)); 966 sizeof(struct yamdrv_ioctl_mcs));
967 if (IS_ERR(ym)) 967 if (IS_ERR(ym))
968 return PTR_ERR(ym); 968 return PTR_ERR(ym);
969 if (ym->cmd != SIOCYAMSMCS)
970 return -EINVAL;
969 if (ym->bitrate > YAM_MAXBITRATE) { 971 if (ym->bitrate > YAM_MAXBITRATE) {
970 kfree(ym); 972 kfree(ym);
971 return -EINVAL; 973 return -EINVAL;
@@ -981,6 +983,8 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
981 if (copy_from_user(&yi, ifr->ifr_data, sizeof(struct yamdrv_ioctl_cfg))) 983 if (copy_from_user(&yi, ifr->ifr_data, sizeof(struct yamdrv_ioctl_cfg)))
982 return -EFAULT; 984 return -EFAULT;
983 985
986 if (yi.cmd != SIOCYAMSCFG)
987 return -EINVAL;
984 if ((yi.cfg.mask & YAM_IOBASE) && netif_running(dev)) 988 if ((yi.cfg.mask & YAM_IOBASE) && netif_running(dev))
985 return -EINVAL; /* Cannot change this parameter when up */ 989 return -EINVAL; /* Cannot change this parameter when up */
986 if ((yi.cfg.mask & YAM_IRQ) && netif_running(dev)) 990 if ((yi.cfg.mask & YAM_IRQ) && netif_running(dev))