From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 71A42A00C3; Wed, 15 Dec 2021 09:32:14 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ECE6840688; Wed, 15 Dec 2021 09:32:13 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 29F1540041; Wed, 15 Dec 2021 09:32:13 +0100 (CET) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH] ring: fix overflow in memory size calcuation Date: Wed, 15 Dec 2021 09:32:06 +0100 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D86D76@smartserver.smartshare.dk> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH] ring: fix overflow in memory size calcuation Thread-Index: AdfxifMK5fca4UOWQ72PnRGvOoP6sAAA9J8Q References: <20211214033016.29927-1-wangzhihong.wzh@bytedance.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Liang Ma" , "Zhihong Wang" Cc: , , , X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Liang Ma [mailto:liangma@liangbit.com] > Sent: Wednesday, 15 December 2021 09.01 >=20 > On Tue, Dec 14, 2021 at 11:30:16AM +0800, Zhihong Wang wrote: > > Parameters count and esize are both unsigned int, and their product > can > > legally exceed unsigned int and lead to runtime access violation. > > > > Fixes: cc4b218790f6 ("ring: support configurable element size") > > Cc: stable@dpdk.org > > > > Signed-off-by: Zhihong Wang > > --- > > lib/ring/rte_ring.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/ring/rte_ring.c b/lib/ring/rte_ring.c > > index f17bd966be..d1b80597af 100644 > > --- a/lib/ring/rte_ring.c > > +++ b/lib/ring/rte_ring.c > > @@ -75,7 +75,7 @@ rte_ring_get_memsize_elem(unsigned int esize, > unsigned int count) > > return -EINVAL; > > } > > > > - sz =3D sizeof(struct rte_ring) + count * esize; > > + sz =3D sizeof(struct rte_ring) + (ssize_t)count * esize; > > sz =3D RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE); > > return sz; > > } > > -- > > 2.11.0 > > > Reviewed-by Liang Ma I was wondering about the type conversion to signed (instead of = unsigned), but sz is ssize_t, so the conversion to ssize_t is correct. = Otherwise, sz should be changed from ssize_t to size_t too. No need for further changes. Reviewed-by: Morten Br=F8rup