]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()
authorAlexander Popov <alex.popov@linux.com>
Thu, 19 Apr 2018 12:29:22 +0000 (15:29 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 14 Aug 2018 10:26:19 +0000 (12:26 +0200)
BugLink: http://bugs.launchpad.net/bugs/1780499
commit 23a27722b5292ef0b27403c87a109feea8296a5c upstream.

i2cdev_ioctl_rdwr() allocates i2c_msg.buf using memdup_user(), which
returns ZERO_SIZE_PTR if i2c_msg.len is zero.

Currently i2cdev_ioctl_rdwr() always dereferences the buf pointer in case
of I2C_M_RD | I2C_M_RECV_LEN transfer. That causes a kernel oops in
case of zero len.

Let's check the len against zero before dereferencing buf pointer.

This issue was triggered by syzkaller.

Signed-off-by: Alexander Popov <alex.popov@linux.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
[wsa: use '< 1' instead of '!' for easier readability]
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/i2c/i2c-dev.c

index 2cab27a6847980e5249a9f953cba6e2ce2a5bff7..8b58dfcad4d9dc5c9a8a13c530c6f8012a7e8a5b 100644 (file)
@@ -278,7 +278,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,
                 */
                if (msgs[i].flags & I2C_M_RECV_LEN) {
                        if (!(msgs[i].flags & I2C_M_RD) ||
-                           msgs[i].buf[0] < 1 ||
+                           msgs[i].len < 1 || msgs[i].buf[0] < 1 ||
                            msgs[i].len < msgs[i].buf[0] +
                                             I2C_SMBUS_BLOCK_MAX) {
                                res = -EINVAL;