Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: zstd - Annotate struct zstd_ctx with __counted_by

Add the __counted_by() compiler attribute to the flexible array member
'wksp' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.

Use struct_size(), which provides additional compile-time checks for
structures with flexible array members (e.g., __must_be_array()), for
the allocation size for a new 'zstd_ctx' while we're at it.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Thorsten Blum and committed by
Herbert Xu
6cf32607 af3852cd

+3 -2
+3 -2
crypto/zstd.c
··· 10 10 #include <linux/mm.h> 11 11 #include <linux/module.h> 12 12 #include <linux/net.h> 13 + #include <linux/overflow.h> 13 14 #include <linux/vmalloc.h> 14 15 #include <linux/zstd.h> 15 16 #include <crypto/internal/acompress.h> ··· 26 25 zstd_dctx *dctx; 27 26 size_t wksp_size; 28 27 zstd_parameters params; 29 - u8 wksp[] __aligned(8); 28 + u8 wksp[] __aligned(8) __counted_by(wksp_size); 30 29 }; 31 30 32 31 static DEFINE_MUTEX(zstd_stream_lock); ··· 45 44 if (!wksp_size) 46 45 return ERR_PTR(-EINVAL); 47 46 48 - ctx = kvmalloc(sizeof(*ctx) + wksp_size, GFP_KERNEL); 47 + ctx = kvmalloc(struct_size(ctx, wksp, wksp_size), GFP_KERNEL); 49 48 if (!ctx) 50 49 return ERR_PTR(-ENOMEM); 51 50