diff mbox series

ethtool: stats: Use struct_group() to clear all stats at once

Message ID 20211118203456.1288056-1-keescook@chromium.org (mailing list archive)
State Accepted
Commit 812ad3d270cb900d156a1542360d81f749dbe040
Delegated to: Netdev Maintainers
Headers show
Series ethtool: stats: Use struct_group() to clear all stats at once | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 22 this patch: 22
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6 this patch: 6
netdev/checkpatch warning CHECK: Alignment should match open parenthesis
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Kees Cook Nov. 18, 2021, 8:34 p.m. UTC
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Add struct_group() to mark region of struct stats_reply_data that should
be initialized, which can now be done in a single memset() call.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 net/ethtool/stats.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 19, 2021, noon UTC | #1
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu, 18 Nov 2021 12:34:56 -0800 you wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memset(), avoid intentionally writing across
> neighboring fields.
> 
> Add struct_group() to mark region of struct stats_reply_data that should
> be initialized, which can now be done in a single memset() call.
> 
> [...]

Here is the summary with links:
  - ethtool: stats: Use struct_group() to clear all stats at once
    https://git.kernel.org/netdev/net-next/c/812ad3d270cb

You are awesome, thank you!
Jakub Kicinski Nov. 19, 2021, 2:27 p.m. UTC | #2
On Thu, 18 Nov 2021 12:34:56 -0800 Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memset(), avoid intentionally writing across
> neighboring fields.
> 
> Add struct_group() to mark region of struct stats_reply_data that should
> be initialized, which can now be done in a single memset() call.

No objection to the patch, but the commit message does not work 
for this one ;)

> diff --git a/net/ethtool/stats.c b/net/ethtool/stats.c
> index ec07f5765e03..a20e0a24ff61 100644
> --- a/net/ethtool/stats.c
> +++ b/net/ethtool/stats.c
> @@ -14,10 +14,12 @@ struct stats_req_info {
>  
>  struct stats_reply_data {
>  	struct ethnl_reply_data		base;
> -	struct ethtool_eth_phy_stats	phy_stats;
> -	struct ethtool_eth_mac_stats	mac_stats;
> -	struct ethtool_eth_ctrl_stats	ctrl_stats;
> -	struct ethtool_rmon_stats	rmon_stats;
> +	struct_group(stats,
> +		struct ethtool_eth_phy_stats	phy_stats;
> +		struct ethtool_eth_mac_stats	mac_stats;
> +		struct ethtool_eth_ctrl_stats	ctrl_stats;
> +		struct ethtool_rmon_stats	rmon_stats;
> +	);
>  	const struct ethtool_rmon_hist_range	*rmon_ranges;
>  };
>  
> @@ -117,10 +119,7 @@ static int stats_prepare_data(const struct ethnl_req_info *req_base,
>  	/* Mark all stats as unset (see ETHTOOL_STAT_NOT_SET) to prevent them
>  	 * from being reported to user space in case driver did not set them.
>  	 */
> -	memset(&data->phy_stats, 0xff, sizeof(data->phy_stats));
> -	memset(&data->mac_stats, 0xff, sizeof(data->mac_stats));
> -	memset(&data->ctrl_stats, 0xff, sizeof(data->ctrl_stats));
> -	memset(&data->rmon_stats, 0xff, sizeof(data->rmon_stats));
> +	memset(&data->stats, 0xff, sizeof(data->stats));
>  
>  	if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
>  	    dev->ethtool_ops->get_eth_phy_stats)
diff mbox series

Patch

diff --git a/net/ethtool/stats.c b/net/ethtool/stats.c
index ec07f5765e03..a20e0a24ff61 100644
--- a/net/ethtool/stats.c
+++ b/net/ethtool/stats.c
@@ -14,10 +14,12 @@  struct stats_req_info {
 
 struct stats_reply_data {
 	struct ethnl_reply_data		base;
-	struct ethtool_eth_phy_stats	phy_stats;
-	struct ethtool_eth_mac_stats	mac_stats;
-	struct ethtool_eth_ctrl_stats	ctrl_stats;
-	struct ethtool_rmon_stats	rmon_stats;
+	struct_group(stats,
+		struct ethtool_eth_phy_stats	phy_stats;
+		struct ethtool_eth_mac_stats	mac_stats;
+		struct ethtool_eth_ctrl_stats	ctrl_stats;
+		struct ethtool_rmon_stats	rmon_stats;
+	);
 	const struct ethtool_rmon_hist_range	*rmon_ranges;
 };
 
@@ -117,10 +119,7 @@  static int stats_prepare_data(const struct ethnl_req_info *req_base,
 	/* Mark all stats as unset (see ETHTOOL_STAT_NOT_SET) to prevent them
 	 * from being reported to user space in case driver did not set them.
 	 */
-	memset(&data->phy_stats, 0xff, sizeof(data->phy_stats));
-	memset(&data->mac_stats, 0xff, sizeof(data->mac_stats));
-	memset(&data->ctrl_stats, 0xff, sizeof(data->ctrl_stats));
-	memset(&data->rmon_stats, 0xff, sizeof(data->rmon_stats));
+	memset(&data->stats, 0xff, sizeof(data->stats));
 
 	if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
 	    dev->ethtool_ops->get_eth_phy_stats)