netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCH net-next] ptr_ring: fix integer overflow
Date: Thu, 25 Jan 2018 15:45:25 +0200	[thread overview]
Message-ID: <20180125154255-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1516865502-20835-1-git-send-email-jasowang@redhat.com>

On Thu, Jan 25, 2018 at 03:31:42PM +0800, Jason Wang wrote:
> We try to allocate one more entry for lockless peeking. The adding
> operation may overflow which causes zero to be passed to kmalloc().
> In this case, it returns ZERO_SIZE_PTR without any notice by ptr
> ring. Try to do producing or consuming on such ring will lead NULL
> dereference. Fix this detect and fail early.
> 
> Fixes: bcecb4bbf88a ("net: ptr_ring: otherwise safe empty checks can overrun array bounds")
> Reported-by: syzbot+87678bcf753b44c39b67@syzkaller.appspotmail.com
> Cc: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Ugh that's just way too ugly.
I'll work on dropping the extra + 1 - but calling this
function with -1 size is the real source of the bug.
Do you know how come we do that?

> ---
>  include/linux/ptr_ring.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
> index 9ca1726..3f99484 100644
> --- a/include/linux/ptr_ring.h
> +++ b/include/linux/ptr_ring.h
> @@ -453,6 +453,8 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,
>  
>  static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp)
>  {
> +	if (unlikely(size + 1 == 0))
> +		return NULL;
>  	/* Allocate an extra dummy element at end of ring to avoid consumer head
>  	 * or produce head access past the end of the array. Possible when
>  	 * producer/consumer operations and __ptr_ring_peek operations run in
> -- 
> 2.7.4

  reply	other threads:[~2018-01-25 13:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25  7:31 [PATCH net-next] ptr_ring: fix integer overflow Jason Wang
2018-01-25 13:45 ` Michael S. Tsirkin [this message]
2018-01-25 14:17   ` Jason Wang
2018-01-25 17:31     ` Michael S. Tsirkin
2018-01-26  3:44       ` Jason Wang
2018-01-26 13:51         ` Michael S. Tsirkin
2018-01-29 17:01 ` David Miller
2018-01-30  6:56   ` Jason Wang

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=20180125154255-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 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).