Received: by 10.192.165.156 with SMTP id m28csp658159imm; Thu, 19 Apr 2018 05:32:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/lQSELOr2zCmU0zlT4zHVHhtUMmc2tgUPuDeQIDFqDo+pVRUfwNgFVSz9FfjoZTbPJQeKJ X-Received: by 2002:a17:902:380c:: with SMTP id l12-v6mr3961168plc.19.1524141138349; Thu, 19 Apr 2018 05:32:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524141138; cv=none; d=google.com; s=arc-20160816; b=qnWt+IdDPzU+Z2j8aTwtNP5W+EeCnoONqwH1FZdvyOCp+pIsoy9BKI7mmBGOnkhFBq qk5STnd0T+RD1nRM0KkUSxYAOGPfXbwqMOyDRrsmVRx4mNUB9ehlcDN8uhZQd7D2kpEF 88zgpzEpX8VYVaUWuO7d9P7O1u1BuDFIpc8++KNkuG8W4uCiQirEFlyXLkjVjivndwbA lihy6yDpJLvqcGQ97P+/1Qb8FEd7MrySuxTIeLL1s+NbBpEsephIBprPRIP1LAiooTtk zbTfzF6bsJscm1SSgrLUqTKA9VtNVBq6pAc4QnKdhkUEGLyMXDUl0sdhFl044ZGPnB5H JnnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :arc-authentication-results; bh=TT6MZBlgqam8xFUpo95w3ES391MTiB4SVTwg1+kwdNM=; b=RHfxbhSU0W7VS5oBTiB8LbDETSrH2lS8jo3MEeuNoYAvnNpa3yryscwsQZbfzBz4B+ IqyT05d5FLTxRniLyQFkXu0kulj6b2LCG05E/QQ8JjtiiPalCH1ROjpwq1rb4BMofLFc 0BkFEatp9UhrUK8/BCX4AjWohOjEvAtjnLqz5RST/XdYEzeBi4or+//sG7ey73QKEUCP RLu3PEKNq/il+S0gw+9cK4wxj95B3RYx/McnLDqF5VPKMKvE46AiojhGPiCP+p1clBt4 TM2EmXcXicHTLXk//nsPcthhd8skxQEvjjvWszYK1rfj60x6V/EHFm3A7yyKStTR+Cyy 93UA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12-v6si3282687plt.175.2018.04.19.05.32.04; Thu, 19 Apr 2018 05:32:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752391AbeDSM3m (ORCPT + 99 others); Thu, 19 Apr 2018 08:29:42 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:45418 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751953AbeDSM3l (ORCPT ); Thu, 19 Apr 2018 08:29:41 -0400 Received: by mail-wr0-f194.google.com with SMTP id u11-v6so13534697wri.12; Thu, 19 Apr 2018 05:29:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=TT6MZBlgqam8xFUpo95w3ES391MTiB4SVTwg1+kwdNM=; b=OSlC5K1qarAUHkFwgc4u1Bu6xJRS19LVUfuzODhTAVecVlms77CZmRyVZDpuIEcrEp MCz6RgnOrvwkdHh2jJO4Djr8qxNwqRa7zHWaVy3ZekmEfhejC/m/9Y0qmq4E0qhnNtYe 5P7doxE3ax7aLJOWEzC7Sgs0RxtejA5AO6aBFM0cPGvy+dfRC8XHGnJFgGCbvwa7kqFd j1uDgSdKyXFldanyRfuNc7Q4HKshW/SEFiZSbu/o7Ey+DVyICJ3onWPM+VsH28FjDluk FoLQcznGDEMaXY6G5A+ejigk8O5WxY3zAcoF4ueMOfJ8kCdwbHGb7Mc68Dg6ceH/i2CP 42IA== X-Gm-Message-State: ALQs6tCRJkJmQuBKHelxZhS2a+FPgNeCtYDE8xvr95esCjflLW7S4HBJ GTCFXseLtA/hLhfrB9MLX1FBHQ== X-Received: by 10.28.92.82 with SMTP id q79mr4165685wmb.130.1524140980225; Thu, 19 Apr 2018 05:29:40 -0700 (PDT) Received: from localhost.localdomain ([46.166.128.205]) by smtp.gmail.com with ESMTPSA id 6sm4941068wmf.31.2018.04.19.05.29.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Apr 2018 05:29:39 -0700 (PDT) From: Alexander Popov To: Wolfram Sang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, sil2review@lists.osadl.org, Dmitry Vyukov , syzkaller@googlegroups.com, Alexander Popov Subject: [v2 1/1] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr() Date: Thu, 19 Apr 2018 15:29:22 +0300 Message-Id: <1524140962-25639-1-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/i2c/i2c-dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 036a03f..5790bc8 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -280,6 +280,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].len || msgs[i].buf[0] < 1 || msgs[i].len < msgs[i].buf[0] + I2C_SMBUS_BLOCK_MAX) { -- 2.7.4