Skip to content

Commit f946270

Browse files
committed
ethtool: netlink: always pass genl_info to .prepare_data
We had a number of bugs in the past because developers forgot to fully test dumps, which pass NULL as info to .prepare_data. .prepare_data implementations would try to access info->extack leading to a null-deref. Now that dumps and notifications can access struct genl_info we can pass it in, and remove the info null checks. Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com> # pause Reviewed-by: Jiri Pirko <jiri@nvidia.com> Link: https://lore.kernel.org/r/20230814214723.2924989-11-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ec0e5b0 commit f946270

25 files changed

+47
-47
lines changed

net/ethtool/channels.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const struct nla_policy ethnl_channels_get_policy[] = {
2424

2525
static int channels_prepare_data(const struct ethnl_req_info *req_base,
2626
struct ethnl_reply_data *reply_base,
27-
struct genl_info *info)
27+
const struct genl_info *info)
2828
{
2929
struct channels_reply_data *data = CHANNELS_REPDATA(reply_base);
3030
struct net_device *dev = reply_base->dev;

net/ethtool/coalesce.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ const struct nla_policy ethnl_coalesce_get_policy[] = {
5959

6060
static int coalesce_prepare_data(const struct ethnl_req_info *req_base,
6161
struct ethnl_reply_data *reply_base,
62-
struct genl_info *info)
62+
const struct genl_info *info)
6363
{
6464
struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
65-
struct netlink_ext_ack *extack = info ? info->extack : NULL;
6665
struct net_device *dev = reply_base->dev;
6766
int ret;
6867

@@ -73,7 +72,8 @@ static int coalesce_prepare_data(const struct ethnl_req_info *req_base,
7372
if (ret < 0)
7473
return ret;
7574
ret = dev->ethtool_ops->get_coalesce(dev, &data->coalesce,
76-
&data->kernel_coalesce, extack);
75+
&data->kernel_coalesce,
76+
info->extack);
7777
ethnl_ops_complete(dev);
7878

7979
return ret;

net/ethtool/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const struct nla_policy ethnl_debug_get_policy[] = {
2323

2424
static int debug_prepare_data(const struct ethnl_req_info *req_base,
2525
struct ethnl_reply_data *reply_base,
26-
struct genl_info *info)
26+
const struct genl_info *info)
2727
{
2828
struct debug_reply_data *data = DEBUG_REPDATA(reply_base);
2929
struct net_device *dev = reply_base->dev;

net/ethtool/eee.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const struct nla_policy ethnl_eee_get_policy[] = {
2626

2727
static int eee_prepare_data(const struct ethnl_req_info *req_base,
2828
struct ethnl_reply_data *reply_base,
29-
struct genl_info *info)
29+
const struct genl_info *info)
3030
{
3131
struct eee_reply_data *data = EEE_REPDATA(reply_base);
3232
struct net_device *dev = reply_base->dev;

net/ethtool/eeprom.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ static int fallback_set_params(struct eeprom_req_info *request,
5151
}
5252

5353
static int eeprom_fallback(struct eeprom_req_info *request,
54-
struct eeprom_reply_data *reply,
55-
struct genl_info *info)
54+
struct eeprom_reply_data *reply)
5655
{
5756
struct net_device *dev = reply->base.dev;
5857
struct ethtool_modinfo modinfo = {0};
@@ -103,7 +102,7 @@ static int get_module_eeprom_by_page(struct net_device *dev,
103102

104103
static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
105104
struct ethnl_reply_data *reply_base,
106-
struct genl_info *info)
105+
const struct genl_info *info)
107106
{
108107
struct eeprom_reply_data *reply = MODULE_EEPROM_REPDATA(reply_base);
109108
struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_base);
@@ -124,7 +123,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
124123
if (ret)
125124
goto err_free;
126125

127-
ret = get_module_eeprom_by_page(dev, &page_data, info ? info->extack : NULL);
126+
ret = get_module_eeprom_by_page(dev, &page_data, info->extack);
128127
if (ret < 0)
129128
goto err_ops;
130129

@@ -140,7 +139,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
140139
kfree(page_data.data);
141140

142141
if (ret == -EOPNOTSUPP)
143-
return eeprom_fallback(request, reply, info);
142+
return eeprom_fallback(request, reply);
144143
return ret;
145144
}
146145

net/ethtool/features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void ethnl_features_to_bitmap32(u32 *dest, netdev_features_t src)
3535

3636
static int features_prepare_data(const struct ethnl_req_info *req_base,
3737
struct ethnl_reply_data *reply_base,
38-
struct genl_info *info)
38+
const struct genl_info *info)
3939
{
4040
struct features_reply_data *data = FEATURES_REPDATA(reply_base);
4141
struct net_device *dev = reply_base->dev;

net/ethtool/fec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fec_stats_recalc(struct fec_stat_grp *grp, struct ethtool_fec_stat *stats)
9292

9393
static int fec_prepare_data(const struct ethnl_req_info *req_base,
9494
struct ethnl_reply_data *reply_base,
95-
struct genl_info *info)
95+
const struct genl_info *info)
9696
{
9797
__ETHTOOL_DECLARE_LINK_MODE_MASK(active_fec_modes) = {};
9898
struct fec_reply_data *data = FEC_REPDATA(reply_base);

net/ethtool/linkinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const struct nla_policy ethnl_linkinfo_get_policy[] = {
2323

2424
static int linkinfo_prepare_data(const struct ethnl_req_info *req_base,
2525
struct ethnl_reply_data *reply_base,
26-
struct genl_info *info)
26+
const struct genl_info *info)
2727
{
2828
struct linkinfo_reply_data *data = LINKINFO_REPDATA(reply_base);
2929
struct net_device *dev = reply_base->dev;

net/ethtool/linkmodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const struct nla_policy ethnl_linkmodes_get_policy[] = {
2727

2828
static int linkmodes_prepare_data(const struct ethnl_req_info *req_base,
2929
struct ethnl_reply_data *reply_base,
30-
struct genl_info *info)
30+
const struct genl_info *info)
3131
{
3232
struct linkmodes_reply_data *data = LINKMODES_REPDATA(reply_base);
3333
struct net_device *dev = reply_base->dev;

net/ethtool/linkstate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int linkstate_get_link_ext_state(struct net_device *dev,
8181

8282
static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
8383
struct ethnl_reply_data *reply_base,
84-
struct genl_info *info)
84+
const struct genl_info *info)
8585
{
8686
struct linkstate_reply_data *data = LINKSTATE_REPDATA(reply_base);
8787
struct net_device *dev = reply_base->dev;

0 commit comments

Comments
 (0)