Skip to content

Commit ea751ea

Browse files
sudeepduttgregkh
authored andcommitted
misc: mic: fix possible signed underflow (undefined behavior) in userspace API
commit 3b1cc9b 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>
1 parent 2ae24ea commit ea751ea

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎drivers/misc/mic/host/mic_virtio.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ static int mic_vringh_copy(struct mic_vdev *mvdev, struct vringh_kiov *iov,
156156
static int _mic_virtio_copy(struct mic_vdev *mvdev,
157157
struct mic_copy_desc *copy)
158158
{
159-
int ret = 0, iovcnt = copy->iovcnt;
159+
int ret = 0;
160+
u32 iovcnt = copy->iovcnt;
160161
struct iovec iov;
161162
struct iovec __user *u_iov = copy->iov;
162163
void __user *ubuf = NULL;

‎include/uapi/linux/mic_ioctl.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct mic_copy_desc {
3939
#else
4040
struct iovec *iov;
4141
#endif
42-
int iovcnt;
42+
__u32 iovcnt;
4343
__u8 vr_idx;
4444
__u8 update_used;
4545
__u32 out_len;

0 commit comments

Comments
 (0)