Skip to content

Commit 812ad3d

Browse files
keesdavem330
authored andcommitted
ethtool: stats: Use struct_group() to clear all stats at once
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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b5d8cf0 commit 812ad3d

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

net/ethtool/stats.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ struct stats_req_info {
1414

1515
struct stats_reply_data {
1616
struct ethnl_reply_data base;
17-
struct ethtool_eth_phy_stats phy_stats;
18-
struct ethtool_eth_mac_stats mac_stats;
19-
struct ethtool_eth_ctrl_stats ctrl_stats;
20-
struct ethtool_rmon_stats rmon_stats;
17+
struct_group(stats,
18+
struct ethtool_eth_phy_stats phy_stats;
19+
struct ethtool_eth_mac_stats mac_stats;
20+
struct ethtool_eth_ctrl_stats ctrl_stats;
21+
struct ethtool_rmon_stats rmon_stats;
22+
);
2123
const struct ethtool_rmon_hist_range *rmon_ranges;
2224
};
2325

@@ -117,10 +119,7 @@ static int stats_prepare_data(const struct ethnl_req_info *req_base,
117119
/* Mark all stats as unset (see ETHTOOL_STAT_NOT_SET) to prevent them
118120
* from being reported to user space in case driver did not set them.
119121
*/
120-
memset(&data->phy_stats, 0xff, sizeof(data->phy_stats));
121-
memset(&data->mac_stats, 0xff, sizeof(data->mac_stats));
122-
memset(&data->ctrl_stats, 0xff, sizeof(data->ctrl_stats));
123-
memset(&data->rmon_stats, 0xff, sizeof(data->rmon_stats));
122+
memset(&data->stats, 0xff, sizeof(data->stats));
124123

125124
if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
126125
dev->ethtool_ops->get_eth_phy_stats)

0 commit comments

Comments
 (0)