summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSudeep Dutt <sudeep.dutt@intel.com>2014-02-03 14:53:19 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-22 13:34:57 -0800
commitea751ea7a0fef5e60ac9a876d383983b827fd05d (patch)
treef0080e0b67b5e2240676f1248ef65e9525aca1a2
parent2ae24ea8ea78574ba0af8e21f8b7584023397bef (diff)
downloadlwn-ea751ea7a0fef5e60ac9a876d383983b827fd05d.tar.gz
lwn-ea751ea7a0fef5e60ac9a876d383983b827fd05d.zip
misc: mic: fix possible signed underflow (undefined behavior) in userspace API
commit 3b1cc9b9622a022208ec95b1259b05bbdf712eb7 upstream. iovcnt is declared as a signed integer in both the userspace API and as a local variable in mic_virtio.c. The while() loop in mic_virtio.c iterates until the local variable iovcnt reaches the value 0. If userspace passes e.g. INT_MIN as iovcnt field, this loop then appears to depend on an undefined behavior (signed underflow) to complete. The fix is to use unsigned integers in both the userspace API and the local variable. This issue was reported @ https://lkml.org/lkml/2014/1/10/10 Reported-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com> Signed-off-by: Sudeep Dutt <sudeep.dutt@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/mic/host/mic_virtio.c3
-rw-r--r--include/uapi/linux/mic_ioctl.h2
2 files changed, 3 insertions, 2 deletions
diff --git a/drivers/misc/mic/host/mic_virtio.c b/drivers/misc/mic/host/mic_virtio.c
index 752ff873f891..7e1ef0ebbb80 100644
--- a/drivers/misc/mic/host/mic_virtio.c
+++ b/drivers/misc/mic/host/mic_virtio.c
@@ -156,7 +156,8 @@ static int mic_vringh_copy(struct mic_vdev *mvdev, struct vringh_kiov *iov,
static int _mic_virtio_copy(struct mic_vdev *mvdev,
struct mic_copy_desc *copy)
{
- int ret = 0, iovcnt = copy->iovcnt;
+ int ret = 0;
+ u32 iovcnt = copy->iovcnt;
struct iovec iov;
struct iovec __user *u_iov = copy->iov;
void __user *ubuf = NULL;
diff --git a/include/uapi/linux/mic_ioctl.h b/include/uapi/linux/mic_ioctl.h
index 7fabba5059cf..feb0b4c0814c 100644
--- a/include/uapi/linux/mic_ioctl.h
+++ b/include/uapi/linux/mic_ioctl.h
@@ -39,7 +39,7 @@ struct mic_copy_desc {
#else
struct iovec *iov;
#endif
- int iovcnt;
+ __u32 iovcnt;
__u8 vr_idx;
__u8 update_used;
__u32 out_len;