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
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202402271953.18758AD3@keescook>
Date: Tue, 27 Feb 2024 19:56:04 -0800
From: Kees Cook <keescook@...omium.org>
To: Petr Machata <petrm@...dia.com>
Cc: "David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	netdev@...r.kernel.org, Ido Schimmel <idosch@...dia.com>,
	David Ahern <dsahern@...nel.org>, mlxsw@...dia.com,
	"Gustavo A . R . Silva" <gustavoars@...nel.org>
Subject: Re: [PATCH net-next 7/7] net: nexthop: Expose nexthop group HW stats
 to user space

On Tue, Feb 27, 2024 at 07:17:32PM +0100, Petr Machata wrote:
> [...]
> diff --git a/include/net/nexthop.h b/include/net/nexthop.h
> index 20cd337b4a9c..235f94ab16a8 100644
> --- a/include/net/nexthop.h
> +++ b/include/net/nexthop.h
> [...]
> @@ -214,6 +217,17 @@ struct nh_notifier_res_table_info {
>  	struct nh_notifier_single_info nhs[] __counted_by(num_nh_buckets);
>  };
>  
> +struct nh_notifier_grp_hw_stats_entry_info {
> +	u32 id;
> +	u64 packets;
> +};
> +
> +struct nh_notifier_grp_hw_stats_info {
> +	u16 num_nh;
> +	bool hw_stats_used;
> +	struct nh_notifier_grp_hw_stats_entry_info stats[] __counted_by(num_nh);
> +};
> +
>  struct nh_notifier_info {
>  	struct net *net;
>  	struct netlink_ext_ack *extack;
> [...]
> @@ -685,8 +687,95 @@ static void nh_grp_entry_stats_read(struct nh_grp_entry *nhge,
>  	}
>  }
>  
> +static int nh_notifier_grp_hw_stats_init(struct nh_notifier_info *info,
> +					 const struct nexthop *nh)
> +{
> +	struct nh_group *nhg;
> +	int i;
> +
> +	ASSERT_RTNL();
> +	nhg = rtnl_dereference(nh->nh_grp);
> +
> +	info->id = nh->id;
> +	info->type = NH_NOTIFIER_INFO_TYPE_GRP_HW_STATS;
> +	info->nh_grp_hw_stats = kzalloc(struct_size(info->nh_grp_hw_stats,
> +						    stats, nhg->num_nh),
> +					GFP_KERNEL);
> +	if (!info->nh_grp_hw_stats)
> +		return -ENOMEM;
> +
> +	info->nh_grp_hw_stats->num_nh = nhg->num_nh;
> +	for (i = 0; i < nhg->num_nh; i++) {
> +		struct nh_grp_entry *nhge = &nhg->nh_entries[i];
> +
> +		info->nh_grp_hw_stats->stats[i].id = nhge->nh->id;
> +	}

The order of operations using __counted_by looks good to me: allocate,
assign counter (num_nh), access flex array (stats).

Reviewed-by: Kees Cook <keescook@...omium.org>

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ