LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Alexander Popov <alex.popov@linux.com>
Cc: Wolfram Sang <wsa@the-dreams.de>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	sil2review@lists.osadl.org, Dmitry Vyukov <dvyukov@google.com>,
	syzkaller@googlegroups.com
Subject: Re: [v2 1/1] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()
Date: Fri, 20 Apr 2018 07:58:22 +0200	[thread overview]
Message-ID: <20180420055822.qjs2hpkik5dr2fnp@pengutronix.de> (raw)
In-Reply-To: <22fe9bbe-f1d7-3a92-9528-df66c34816a5@linux.com>

Hello,

On Thu, Apr 19, 2018 at 08:01:46PM +0300, Alexander Popov wrote:
> On 19.04.2018 16:49, Uwe Kleine-König wrote:
> >> @@ -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
> 
> Excuse me, it will be wrong. We stop if len is 0 to avoid the following
> ZERO_SIZE_PTR dereference.

right you are. I missed the negation.
 
> > here instead of
> > 
> > 			!msgs[i].len
> 
> I can change it to "msgs[i].len == 0". But is it really important?
> 
> I've carefully tested the current version with the original repro. It works correct.

I don't doubt it, and the code generated is maybe even the same. The
point I wanted to make is that

	!len

is harder to read for a human than

	len < 1

(or another suitable arithmetic expression). But feel free to disagree
and keep the code as is.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  reply	other threads:[~2018-04-20  5:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 12:29 Alexander Popov
2018-04-19 13:49 ` Uwe Kleine-König
2018-04-19 17:01   ` Alexander Popov
2018-04-20  5:58     ` Uwe Kleine-König [this message]
2018-04-23 20:18   ` Alexander Popov
2018-04-27 12:06 ` Wolfram Sang
2018-04-30  7:13   ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180420055822.qjs2hpkik5dr2fnp@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=alex.popov@linux.com \
    --cc=dvyukov@google.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sil2review@lists.osadl.org \
    --cc=syzkaller@googlegroups.com \
    --cc=wsa@the-dreams.de \
    --subject='Re: [v2 1/1] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).