From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751271AbeAYHbu (ORCPT ); Thu, 25 Jan 2018 02:31:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38920 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750992AbeAYHbs (ORCPT ); Thu, 25 Jan 2018 02:31:48 -0500 From: Jason Wang To: mst@redhat.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Jason Wang , John Fastabend Subject: [PATCH net-next] ptr_ring: fix integer overflow Date: Thu, 25 Jan 2018 15:31:42 +0800 Message-Id: <1516865502-20835-1-git-send-email-jasowang@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Jason Wang --- 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