Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/rapidio/rio_cm.c: prevent possible heap overwrite

In

riocm_cdev_ioctl(RIO_CM_CHAN_SEND)
-> cm_chan_msg_send()
-> riocm_ch_send()

cm_chan_msg_send() checks that userspace didn't send too much data but
riocm_ch_send() failed to check that userspace sent sufficient data. The
result is that riocm_ch_send() can write to fields in the rio_ch_chan_hdr
which were outside the bounds of the space which cm_chan_msg_send()
allocated.

Address this by teaching riocm_ch_send() to check that the entire
rio_ch_chan_hdr was copied in from userspace.

Reported-by: maher azz <maherazz04@gmail.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Alexandre Bounine <alex.bou9@gmail.com>
Cc: Linus Torvalds <torvalds@linuxfoundation.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

+3
+3
drivers/rapidio/rio_cm.c
··· 783 783 if (buf == NULL || ch_id == 0 || len == 0 || len > RIO_MAX_MSG_SIZE) 784 784 return -EINVAL; 785 785 786 + if (len < sizeof(struct rio_ch_chan_hdr)) 787 + return -EINVAL; /* insufficient data from user */ 788 + 786 789 ch = riocm_get_channel(ch_id); 787 790 if (!ch) { 788 791 riocm_error("%s(%d) ch_%d not found", current->comm,