All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Peilin Ye <yepeilin.cs@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Navid Emamdoost <navid.emamdoost@gmail.com>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [Linux-kernel-mentees] [PATCH net] qrtr: Fix ZERO_SIZE_PTR deref in qrtr_tun_write_iter()
Date: Mon, 13 Jul 2020 12:13:29 +0300	[thread overview]
Message-ID: <20200713091329.GP2571@kadam> (raw)
In-Reply-To: <20200712213631.GA809@sol.localdomain>

On Sun, Jul 12, 2020 at 02:36:31PM -0700, Eric Biggers wrote:
> On Sun, Jul 12, 2020 at 05:03:00PM -0400, Peilin Ye wrote:
> > qrtr_tun_write_iter() is dereferencing `ZERO_SIZE_PTR`s when `from->count`
> > equals to zero. Fix it by rejecting zero-length kzalloc() requests.
> > 
> > This patch fixes the following syzbot bug:
> > 
> >     https://syzkaller.appspot.com/bug?id=f56bbe6668873ee245986bbd23312b895fa5a50a
> > 
> > Reported-by: syzbot+03e343dbccf82a5242a2@syzkaller.appspotmail.com
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> > ---
> >  net/qrtr/tun.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/qrtr/tun.c b/net/qrtr/tun.c
> > index 15ce9b642b25..5465e94ba8e5 100644
> > --- a/net/qrtr/tun.c
> > +++ b/net/qrtr/tun.c
> > @@ -80,6 +80,9 @@ static ssize_t qrtr_tun_write_iter(struct kiocb *iocb, struct iov_iter *from)
> >  	ssize_t ret;
> >  	void *kbuf;
> >  
> > +	if (!len)
> > +		return -EINVAL;
> > +
> >  	kbuf = kzalloc(len, GFP_KERNEL);
> >  	if (!kbuf)
> >  		return -ENOMEM;
> 
> Wasn't this already fixed by:
> 
>     commit 8ff41cc21714704ef0158a546c3c4d07fae2c952
>     Author: Dan Carpenter <dan.carpenter@oracle.com>
>     Date:   Tue Jun 30 14:46:15 2020 +0300
> 
>         net: qrtr: Fix an out of bounds read qrtr_endpoint_post()


Yep.  If you're using kmalloc() you can allocate a zero byte buffer but
you just can't access the array.  for (i = 0; i < 0; i++) works.

It's interesting because at the time, I wrote the patch I thought "len"
probably couldn't be zero but I just checked it for completeness and
readability.

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
	linux-kernel-mentees@lists.linuxfoundation.org,
	Peilin Ye <yepeilin.cs@gmail.com>,
	Navid Emamdoost <navid.emamdoost@gmail.com>
Subject: Re: [Linux-kernel-mentees] [PATCH net] qrtr: Fix ZERO_SIZE_PTR deref in qrtr_tun_write_iter()
Date: Mon, 13 Jul 2020 12:13:29 +0300	[thread overview]
Message-ID: <20200713091329.GP2571@kadam> (raw)
In-Reply-To: <20200712213631.GA809@sol.localdomain>

On Sun, Jul 12, 2020 at 02:36:31PM -0700, Eric Biggers wrote:
> On Sun, Jul 12, 2020 at 05:03:00PM -0400, Peilin Ye wrote:
> > qrtr_tun_write_iter() is dereferencing `ZERO_SIZE_PTR`s when `from->count`
> > equals to zero. Fix it by rejecting zero-length kzalloc() requests.
> > 
> > This patch fixes the following syzbot bug:
> > 
> >     https://syzkaller.appspot.com/bug?id=f56bbe6668873ee245986bbd23312b895fa5a50a
> > 
> > Reported-by: syzbot+03e343dbccf82a5242a2@syzkaller.appspotmail.com
> > Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> > ---
> >  net/qrtr/tun.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/qrtr/tun.c b/net/qrtr/tun.c
> > index 15ce9b642b25..5465e94ba8e5 100644
> > --- a/net/qrtr/tun.c
> > +++ b/net/qrtr/tun.c
> > @@ -80,6 +80,9 @@ static ssize_t qrtr_tun_write_iter(struct kiocb *iocb, struct iov_iter *from)
> >  	ssize_t ret;
> >  	void *kbuf;
> >  
> > +	if (!len)
> > +		return -EINVAL;
> > +
> >  	kbuf = kzalloc(len, GFP_KERNEL);
> >  	if (!kbuf)
> >  		return -ENOMEM;
> 
> Wasn't this already fixed by:
> 
>     commit 8ff41cc21714704ef0158a546c3c4d07fae2c952
>     Author: Dan Carpenter <dan.carpenter@oracle.com>
>     Date:   Tue Jun 30 14:46:15 2020 +0300
> 
>         net: qrtr: Fix an out of bounds read qrtr_endpoint_post()


Yep.  If you're using kmalloc() you can allocate a zero byte buffer but
you just can't access the array.  for (i = 0; i < 0; i++) works.

It's interesting because at the time, I wrote the patch I thought "len"
probably couldn't be zero but I just checked it for completeness and
readability.

regards,
dan carpenter
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2020-07-13  9:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-12 21:03 [Linux-kernel-mentees] [PATCH net] qrtr: Fix ZERO_SIZE_PTR deref in qrtr_tun_write_iter() Peilin Ye
2020-07-12 21:03 ` Peilin Ye
2020-07-12 21:36 ` Eric Biggers
2020-07-12 21:36   ` Eric Biggers
2020-07-13  9:13   ` Dan Carpenter [this message]
2020-07-13  9:13     ` Dan Carpenter

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=20200713091329.GP2571@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=navid.emamdoost@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=yepeilin.cs@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.