Received: by 10.192.165.156 with SMTP id m28csp739484imm; Thu, 19 Apr 2018 06:50:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx49YVYmK5LH7K7szWp/997MQFQbDwl3aknXf0zeTzzAlLgTox2xUmjYJnxKUGptkTyXryRjA X-Received: by 2002:a17:902:8692:: with SMTP id g18-v6mr6256192plo.152.1524145852214; Thu, 19 Apr 2018 06:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524145852; cv=none; d=google.com; s=arc-20160816; b=PhlO0/AzeyVn6NHJj9wuSNxsTO9SR9gpqSBtbDJa8R+dMo7hsgzYWSQIbaG/Yzfwmf sE+l4ild/X82fi+YvA+osR2oejZFFIMhhEkS+zbMU3wtsymqSC4InIksGFpBCJtgwq+R mDJrWSE118f1gCGw09MswQmRdvgJYED3xWCJSoznees87A5J9Xv/sINtln/aePtfb87W 3+ubKebEtQUAMM/YslAXNq8DNCplkJOidDBkb9/oloAEhukmmPBap3WAW42DBZpRLHSb 1qvtPYa71rEMQa9DQf8j7depfVRTAuxwEmNZQGc9RkcIJHT5a9dt3k+L+ouRH+JzHn76 E11Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Bcpi6dMBTKbWAYODqYXWS13jsgQx5FH6kGniQ/Z+U1I=; b=ITMW+/VbiSvstqgMrHTi0wEeVZmFe83e3o6WGx73yWivATgqo3a//UPFc2SCQBu+8d vrnXTS0b40HmhvFdrBLrLmGbNgflYPSgq2YDSZxmxuZOlhwvrZFbb0SHH1rURuGQpzLj qlz6L9KtqUeKQ6yQfXO/2/ZS0PZsVsALfVc2hgQ7hqvDIVdthDeNdw8+uXaFA0oTYF3m dyZCcxN3yrJhrQqQsnP0wLmovPFpIi3mQSJUieD+ddaXzxxO1EkMLn2smQ//AhnGku3Y DRmEhBG8Fjk6uTV1ozKx6NPgt/VXHM3X4kioEfe+E158Ka8GWZrk5egT2sKg4G52TJWx xyJQ== 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 f35-v6si1144267plh.193.2018.04.19.06.50.37; Thu, 19 Apr 2018 06:50:52 -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 S1753431AbeDSNtJ (ORCPT + 99 others); Thu, 19 Apr 2018 09:49:09 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:34573 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753411AbeDSNtH (ORCPT ); Thu, 19 Apr 2018 09:49:07 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1f99vs-0002Xp-3B; Thu, 19 Apr 2018 15:49:04 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1f99vq-0006Zs-Pc; Thu, 19 Apr 2018 15:49:02 +0200 Date: Thu, 19 Apr 2018 15:49:02 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Alexander Popov Cc: Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, sil2review@lists.osadl.org, Dmitry Vyukov , syzkaller@googlegroups.com Subject: Re: [v2 1/1] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr() Message-ID: <20180419134902.6l5jsf4wpqfiaskj@pengutronix.de> References: <1524140962-25639-1-git-send-email-alex.popov@linux.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1524140962-25639-1-git-send-email-alex.popov@linux.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 19, 2018 at 03:29:22PM +0300, Alexander Popov wrote: > 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 || I'd prefer msgs[i].len > 0 here instead of !msgs[i].len because I can parse that more easily. Semantically the patch is fine and can have my Reviewed-by: Uwe Kleine-K?nig > msgs[i].buf[0] < 1 || > msgs[i].len < msgs[i].buf[0] + > I2C_SMBUS_BLOCK_MAX) { Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |