Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2072040pxb; Sun, 5 Sep 2021 07:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCJY9SLNux/8oSKkZzl01wwZmRcBmjEWGwrVwgOuHg0qY+6arTuW5pM8LDzuYPNHrfUtkf X-Received: by 2002:a05:6e02:503:: with SMTP id d3mr5618743ils.107.1630853943448; Sun, 05 Sep 2021 07:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630853943; cv=none; d=google.com; s=arc-20160816; b=iBdkXA31wynJ+4BCJ83NjdxdmkHx10jDS9bMS2FwhK0s973JVdhQTfYBE+lhmpy47A ppSzInPfY1tnkVtvYlLjNU4xeAkw4qz6MrhnVHfgH4hRbvclxUgwp1zDmAYVb6bE+Qno 3fCXfQckmP97OL2sHWHvo/ndVhRd46+GuVlWpdGLvkQJ6sHxELbDnfEAqUBpjrQtVPFF EA8Wz2YexRN0SInGv1PJ+YBKRJEriZDdEJlJ5QVpTbwCTnIZ8BZI2HxhPzaz8lzDTVFJ pRVjqqWk7au2GfZhGyE7r+MaLKhLFvIIxcUMAhiNmulvTwrWZHvqkt1OGwhj++4K7Sh/ jlvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ynbTRZJrrd6U7ROO+BW3wZEfmYLCo0vWTa9ilYnrSQc=; b=g3Ve/TI0gtYNjWVOTziJJEZE7EImKFb7zYxqnkUu9LeR87i9reSibdB2ONX25v/ZPB VEDO4gR38n3BQCWF16HzcNBXbPhHWmNyFKdoLYb5CHVd9BzC3+gvn9ylQWJCeKjy19og ArT9+qXFZ2RNyOJExqSzzEpPExFQ8NEZG1SEB94tOp/U9Ll0o4OJTkSz8SNdaPCPuFNp QxFTQpoM9nvoMc7oNnuUaFd4Qe07+zuCU1R/IL5u5nvj4yx8cIr0QmecFPFI+l6yC3P5 uOqgh4EPne+Z07R+sz67Zn/YF+LRIo5u5OI0vwQsA3nrR0FLtdYYEuX/GY6RoD+19P9Q TpHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=I7++3TSR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k35si5277956jac.46.2021.09.05.07.58.51; Sun, 05 Sep 2021 07:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=I7++3TSR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234574AbhIEOme (ORCPT + 99 others); Sun, 5 Sep 2021 10:42:34 -0400 Received: from mout.gmx.net ([212.227.17.20]:44691 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbhIEOmc (ORCPT ); Sun, 5 Sep 2021 10:42:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1630852879; bh=/yNWBRvqjRvVJvu5VKkCkojXul/mjGRN/XfiECWSJkM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=I7++3TSRXjsTIoUO0U+ZzEorASnxONpYE0w7wjyv8St9DR0Dpgenh3Lz4sKgYrDkF QXOJ2bhZ3Zlmuln1CFrDnwKlwqXNnA43RRjP9frPBn4cSl8d5QABO0F0Vc/ew5ZiVm QpFmC2lH/i7zaS7Ya7sWB4UuHkJaFlhj+eoxUWe8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([79.150.72.99]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1N79u8-1n1PAx1eMG-017V9e; Sun, 05 Sep 2021 16:41:19 +0200 From: Len Baker To: Boris Brezillon , Nicolas Pitre Cc: Len Baker , Kees Cook , linux-i3c@lists.infradead.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] i3c/master/mipi-i3c-hci: Prefer struct_size over open coded arithmetic Date: Sun, 5 Sep 2021 16:40:54 +0200 Message-Id: <20210905144054.5124-1-len.baker@gmx.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Yc2GaUmluNaGyeUBD5O7eBSPVcxb2yxz/cdqXlCbWGPG4AzBvIx swPL75n8TCf1Dh4Mq7gXJOusgv/FFSN+3EHxwyRKa/mKG8lIb0zIjLAlXTl7Sg7A8rY/sF1 Tiycvr8QMT51Y4Oi2f9ba8iEwhXcTholcGrPp1e0NzzU+SH3ik/uWYWdJMRQ1c+6E9enyYE TQ3HcftPZ06G6rFOLgoAQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:zYDDzlJ3NSw=:GnvIasji+IGndezvkoibuS 4ZravIVL7n+M5ACFaaA5OCTuhuXNa/uOvA2IIRONr/29qzrwjZkaEmanGZ0piUuCiVShq3Pcj ryVsYGurW6Sw0hv6ze1K26F0vl3J6P8ZFRg9tNYJIn2x9bucitUm3aonIN2y915kKnfyzcntx c1O8+TjUC+7ZEGitpZkdWUvFUDpF54ID7fhFntoNDp5UkOwmLJhDVec7fSl3k9+i2LP9d+sIM k7q3Q66cWSV9SB64aQyCoCkKiXz2RJFlvxZ3fxJawbMrs+UMqJmQDRWlH2orb5n648YFFFxNP Ct1S5KaY88iGMQK1OfFM6gxIH+5pCw+AIq+zWl3WUkNFRWa1nUdAZA/+gvHc0NW5eyabMydCe xYvRX13+i1wEUtrHBuXgBjLKdXMdthzr3ohTzqr/xyC0Ww2N6mCH3SZaB0IEQZlnTLDm0LwD8 /74yJLyh6PCAaTQsQ/X7qwbfPB9NNaz68F2oUnT6jkTFUrbO40Eg60QeG8RhtT96jm4PcdJky gPI4EQDYbGuZwUGENF8gp/uQaBZhUejhbrjiW7TRq81plTD3jG2xK2YoeBKT8+VYI1MFxzdEx zz5tVlACh7Ia6VFCB53wV2jAY/DwEB3P2Ks5nIwtG/ASGu4sIxuwZJ9TvmNCkucOAgcHtxjSv fh4J2lKxLDTO3VmreCP+R1DqfH7NjV95yRHFavmeqBGHWgW3J7PFylGti4JgVT0Y3JJJJ23GH auo9uc/dIl6Fqsd+afZrBk5uVhMnEzRewelyCQQ77IWcjPmOIPZkS7AvYA2D65lOQeNv4hWhs YNizgGcOQw7e+NhLF5XwhnaoMAUzLoYmxK9IAM04gCnHZtmDu8YbFp7kUX8oeFQERvPKhdUb9 DnwOjrs0hmpmPRvu95rG07cWkiLEx/h52ouftJ0r7c4K6hciAhT5GkBL35TIwiNEfz8CX1qIf rdd6/HpPBtY/pq4GKEJTMJ2Grh0oRvjy0Z8m6iG7JTe/Go2V/uL+qLnNGS7FDLdxbj8ztmM2D yEVFEb9A7wHJ5VO6FRlbaFuJp7YEbegrhj4C7TzJa9vfFTat6CI8RKLKfSRw7JYYerxUSnfEl He02EeJDVlzNrrXVmOGDv4z2DwD5qwiKeEMF29NzZhxlSKGjJQe8vcXRw== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, use the struct_size() helper to do the arithmetic instead of the argument "size + count * size" in the kzalloc() function. [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-cod= ed-arithmetic-in-allocator-arguments Signed-off-by: Len Baker =2D-- drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mi= pi-i3c-hci/dma.c index af873a9be050..2990ac9eaade 100644 =2D-- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -223,7 +223,7 @@ static int hci_dma_init(struct i3c_hci *hci) } if (nr_rings > XFER_RINGS) nr_rings =3D XFER_RINGS; - rings =3D kzalloc(sizeof(*rings) + nr_rings * sizeof(*rh), GFP_KERNEL); + rings =3D kzalloc(struct_size(rings, headers, nr_rings), GFP_KERNEL); if (!rings) return -ENOMEM; hci->io_data =3D rings; =2D- 2.25.1