Skip to content

Commit 1d495f1

Browse files
keesklassert
authored andcommitted
xfrm: Annotate struct xfrm_sec_ctx with __counted_by
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 via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct xfrm_sec_ctx. Cc: Steffen Klassert <steffen.klassert@secunet.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: "David S. Miller" <davem@davemloft.net> Cc: netdev@vger.kernel.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent 5fa4704 commit 1d495f1

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

include/uapi/linux/xfrm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/in6.h>
66
#include <linux/types.h>
7+
#include <linux/stddef.h>
78

89
/* All of the structures in this file may not change size as they are
910
* passed into the kernel from userspace via netlink sockets.
@@ -33,7 +34,7 @@ struct xfrm_sec_ctx {
3334
__u8 ctx_alg;
3435
__u16 ctx_len;
3536
__u32 ctx_sid;
36-
char ctx_str[];
37+
char ctx_str[] __counted_by(ctx_len);
3738
};
3839

3940
/* Security Context Domains of Interpretation */

0 commit comments

Comments
 (0)