Skip to content

Commit

Permalink
xfrm: Annotate struct xfrm_sec_ctx with __counted_by
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kees Cook authored and Steffen Klassert committed Oct 5, 2023
1 parent 5fa4704 commit 1d495f1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/uapi/linux/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <linux/in6.h>
#include <linux/types.h>
#include <linux/stddef.h>

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

/* Security Context Domains of Interpretation */
Expand Down

0 comments on commit 1d495f1

Please sign in to comment.