switchtec: off by one in ioctl_event_ctl()
Subsystems (3)
PATCH 1/2 switchtec: off by one in ioctl_event_ctl()
The > should be >= SWITCHTEC_IOCTL_MAX_EVENTS. Otherwise we probably read one space beyond the end of the loop, hit a sanity check and return -EINVAL. This bug doesn't look super serious.
drivers/pci/switch/switchtec.c +1 -1
@@ -1049,7 +1049,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,if (copy_from_user (&ctl, uctl,sizeof (ctl)))return -EFAULT ; -if (ctl.event_id >SWITCHTEC_IOCTL_MAX_EVENTS ) +if (ctl.event_id >=SWITCHTEC_IOCTL_MAX_EVENTS )return -EINVAL ;if (ctl.flags &SWITCHTEC_IOCTL_EVENT_FLAG_UNUSED )
Hi Dan,
Thanks for catching these!
(for both patches)
Logan
Quoted 21 lines · Dan Carpenter
The > should be >=
SWITCHTEC_IOCTL_MAX_EVENTS. Otherwise we probably read one space beyond the end of the loop, hit a sanity check and return-EINVAL. This bug doesn't look super serious.Fixes 61c2e02154a9 ("switchtec: Add IOCTLs to the Switchtec driver")Signed-off-by Dan Carpenter <[email protected]>drivers/pci/switch/switchtec.c +1
-1@@ -1049,7 +1049,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,if (copy_from_user (&ctl, uctl,sizeof (ctl)))return -EFAULT ; -if (ctl.event_id >SWITCHTEC_IOCTL_MAX_EVENTS ) +if (ctl.event_id >=SWITCHTEC_IOCTL_MAX_EVENTS )return -EINVAL ;if (ctl.flags &SWITCHTEC_IOCTL_EVENT_FLAG_UNUSED )
Quoted 6 lines · Dan Carpenter
The > should be >=
SWITCHTEC_IOCTL_MAX_EVENTS. Otherwise we probably read one space beyond the end of the loop, hit a sanity check and return-EINVAL. This bug doesn't look super serious.Fixes 61c2e02154a9 ("switchtec: Add IOCTLs to the Switchtec driver")Signed-off-by Dan Carpenter <[email protected]>
Since these patches are on my "next" branch but haven't been merged anywhere else, I folded both patches into the initial commits and added a changelog note to credit Dan.
Quoted 13 lines
drivers/pci/switch/switchtec.c +1
-1@@ -1049,7 +1049,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,if (copy_from_user (&ctl, uctl,sizeof (ctl)))return -EFAULT ; -if (ctl.event_id >SWITCHTEC_IOCTL_MAX_EVENTS ) +if (ctl.event_id >=SWITCHTEC_IOCTL_MAX_EVENTS )return -EINVAL ;if (ctl.flags &SWITCHTEC_IOCTL_EVENT_FLAG_UNUSED )