Subject: Re: [PATCH net-next v2 05/15] netlink: add macro for checking dump ctx size

From: Ido Schimmel <[email-masked]>
Date: Mon, 23 Jan 2023 16:20:21 +0200

On Wed, Jan 04, 2023 at 08:05:21PM -0800, Jakub Kicinski wrote:
> We encourage casting struct netlink_callback::ctx to a local
> struct (in a comment above the field). Provide a convenience
> macro for checking if the local struct fits into the ctx.
> 
> Reviewed-by: Jacob Keller <[email-masked]>
> Reviewed-by: Jiri Pirko <[email-masked]>
> Signed-off-by: Jakub Kicinski <[email-masked]>
> ---
>  include/linux/netlink.h              | 4 ++++
>  net/netfilter/nf_conntrack_netlink.c | 2 +-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/netlink.h b/include/linux/netlink.h
> index d81bde5a5844..38f6334f408c 100644
> --- a/include/linux/netlink.h
> +++ b/include/linux/netlink.h
> @@ -263,6 +263,10 @@ struct netlink_callback {
>  	};
>  };
>  
> +#define NL_ASSET_DUMP_CTX_FITS(type_name)				\

Wanted to use this macro, but the name doesn't make sense to me. Should
it be NL_ASSERT_DUMP_CTX_FITS() ?

> +	BUILD_BUG_ON(sizeof(type_name) >				\
> +		     sizeof_field(struct netlink_callback, ctx))
> +
>  struct netlink_notify {
>  	struct net *net;
>  	u32 portid;
> diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
> index 1286ae7d4609..90672e293e57 100644
> --- a/net/netfilter/nf_conntrack_netlink.c
> +++ b/net/netfilter/nf_conntrack_netlink.c
> @@ -3866,7 +3866,7 @@ static int __init ctnetlink_init(void)
>  {
>  	int ret;
>  
> -	BUILD_BUG_ON(sizeof(struct ctnetlink_list_dump_ctx) > sizeof_field(struct netlink_callback, ctx));
> +	NL_ASSET_DUMP_CTX_FITS(struct ctnetlink_list_dump_ctx);
>  
>  	ret = nfnetlink_subsys_register(&ctnl_subsys);
>  	if (ret < 0) {
> -- 
> 2.38.1
>