lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Message-ID: <1bcde585-f740-8959-6e2e-19793795b60e@embeddedor.com> Date: Sun, 1 Oct 2023 09:49:16 +0200 From: "Gustavo A. R. Silva" <gustavo@...eddedor.com> To: Christophe JAILLET <christophe.jaillet@...adoo.fr>, Miquel Raynal <miquel.raynal@...tlin.com>, Richard Weinberger <richard@....at>, Vignesh Raghavendra <vigneshr@...com>, Heiko Stuebner <heiko@...ech.de>, Kees Cook <keescook@...omium.org>, "Gustavo A. R. Silva" <gustavoars@...nel.org>, Nathan Chancellor <nathan@...nel.org>, Nick Desaulniers <ndesaulniers@...gle.com>, Tom Rix <trix@...hat.com> Cc: linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org, linux-mtd@...ts.infradead.org, linux-arm-kernel@...ts.infradead.org, linux-rockchip@...ts.infradead.org, linux-hardening@...r.kernel.org, llvm@...ts.linux.dev Subject: Re: [PATCH] mtd: rawnand: rockchip: Use struct_size() On 10/1/23 09:44, Christophe JAILLET wrote: > Use struct_size() instead of hand writing it. > This is less verbose and more robust. > > While at it, prepare for the coming implementation by GCC and Clang of the > __counted_by attribute. Flexible array members annotated with __counted_by > can have their accesses bounds-checked at run-time checking via > CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for > strcpy/memcpy-family functions). Again, I'd prefer this as two separate patches. > > Also remove a useless comment about the position of a flex-array in a > structure. > > Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr> In any case: Reviewed-by: Gustavo A. R. Silva <gustavoars@...nel.org> Thanks -- Gustavo > --- > This patch is part of a work done in parallel of what is currently worked > on by Kees Cook. > > My patches are only related to corner cases that do NOT match the > semantic of his Coccinelle script[1]. > > In this case, struct_size() was not used to compute the size needed for the > structure and its flex array. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > --- > drivers/mtd/nand/raw/rockchip-nand-controller.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/nand/raw/rockchip-nand-controller.c b/drivers/mtd/nand/raw/rockchip-nand-controller.c > index 5bc90ffa721f..596cf9a78274 100644 > --- a/drivers/mtd/nand/raw/rockchip-nand-controller.c > +++ b/drivers/mtd/nand/raw/rockchip-nand-controller.c > @@ -158,8 +158,7 @@ struct rk_nfc_nand_chip { > u32 timing; > > u8 nsels; > - u8 sels[]; > - /* Nothing after this field. */ > + u8 sels[] __counted_by(nsels); > }; > > struct rk_nfc { > @@ -1119,7 +1118,7 @@ static int rk_nfc_nand_chip_init(struct device *dev, struct rk_nfc *nfc, > return -EINVAL; > } > > - rknand = devm_kzalloc(dev, sizeof(*rknand) + nsels * sizeof(u8), > + rknand = devm_kzalloc(dev, struct_size(rknand, sels, nsels), > GFP_KERNEL); > if (!rknand) > return -ENOMEM;
Powered by blists - more mailing lists