mlxsw: core_env: Fix stack info leak in mlxsw_env_linecard_modules_power_mode_apply
Subsystems (3)
PATCH 1/1 mlxsw: core_env: Fix stack info leak in mlxsw_env_linecard_modules_power_mode_apply
The extack was declared on the stack without initialization. If mlxsw_env_set_module_power_mode_apply() fails to set extack, accessing extack._msg could leak information.
--- drivers/net/ethernet/mellanox/mlxsw/core_env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/core_env.c +1 -1
@@ -1332,7 +1332,7 @@ mlxsw_env_linecard_modules_power_mode_apply(struct mlxsw_core *mlxsw_core,for (i =0 ; i < env->line_cards[slot_index]->module_count; i++) {enum ethtool_module_power_mode_policy policy;struct mlxsw_env_module_info *module_info; -struct netlink_ext_ack extack; +struct netlink_ext_ack extack = {};int err; module_info = &env->line_cards[slot_index]->module_info[i];
Signature · 1 line
2.39.5 (Apple Git-154)
Ido Schimmel
maintainerQuoted 3 lines · Miaoqian Lin
The extack was declared on the stack without initialization. If
mlxsw_env_set_module_power_mode_apply()fails to set extack, accessing extack._msg could leak information.
Unless I'm missing something, I don't see a case where mlxsw_env_set_module_power_mode_apply() returns an error without setting extack. IOW, I don't see how this info leak can happen with existing code.
Quoted 23 lines
Fixes 06a0fc43bb10 ("mlxsw: core_env: Add interfaces for line card initialization and de-initialization")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/net/ethernet/mellanox/mlxsw/core_env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mellanox/mlxsw/core_env.c +1
-1@@ -1332,7 +1332,7 @@ mlxsw_env_linecard_modules_power_mode_apply(struct mlxsw_core *mlxsw_core,for (i =0 ; i < env->line_cards[slot_index]->module_count; i++) {enum ethtool_module_power_mode_policy policy;struct mlxsw_env_module_info *module_info; -struct netlink_ext_ack extack; +struct netlink_ext_ack extack = {};int err; module_info = &env->line_cards[slot_index]->module_info[i];Signature · 1 line
2.39.5 (Apple Git-154)
Petr Machata
maintainerQuoted 9 lines · Ido Schimmel
Quoted 3 lines · Miaoqian Lin
The extack was declared on the stack without initialization. If
mlxsw_env_set_module_power_mode_apply()fails to set extack, accessing extack._msg could leak information.Unless I'm missing something, I don't see a case where
mlxsw_env_set_module_power_mode_apply()returns an error without setting extack. IOW, I don't see how this info leak can happen with existing code.
Yeah, I agree it all looks initialized.
The patch still makes sense to me, it will make the code less prone to footguns in the future. The expectation with extack is that it's optional, though functions that take the argument typically also take care to set it (or propagate further). But here it is mandatory to initialize it, or else things break. With the patch we'd get a "(null)\n" instead of garbage. Not great, but better.
Quoted 3 lines
Quoted 3 lines
Fixes 06a0fc43bb10 ("mlxsw: core_env: Add interfaces for line card initialization and de-initialization")
Yeah, it doesn't really fix anything, it's a cleanup if anything, so this tag should go away.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Miaoqian Lin <[email protected]>--- drivers/net/ethernet/mellanox/mlxsw/core_env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mellanox/mlxsw/core_env.c +1
-1@@ -1332,7 +1332,7 @@ mlxsw_env_linecard_modules_power_mode_apply(struct mlxsw_core *mlxsw_core,for (i =0 ; i < env->line_cards[slot_index]->module_count; i++) {enum ethtool_module_power_mode_policy policy;struct mlxsw_env_module_info *module_info; -struct netlink_ext_ack extack; +struct netlink_ext_ack extack = {};int err; module_info = &env->line_cards[slot_index]->module_info[i];Signature · 1 line
2.39.5 (Apple Git-154)
Ido Schimmel
maintainerQuoted 13 lines · Petr Machata
Quoted 9 lines · Ido Schimmel
Quoted 3 lines · Miaoqian Lin
The extack was declared on the stack without initialization. If
mlxsw_env_set_module_power_mode_apply()fails to set extack, accessing extack._msg could leak information.Unless I'm missing something, I don't see a case where
mlxsw_env_set_module_power_mode_apply()returns an error without setting extack. IOW, I don't see how this info leak can happen with existing code.
Quoted 8 lines
Yeah, I agree it all looks initialized.
The patch still makes sense to me, it will make the code less prone to footguns in the future. The expectation with extack is that it's optional, though functions that take the argument typically also take care to set it (or propagate further). But here it is mandatory to initialize it, or else things break. With the patch we'd get a "(null)\n" instead of garbage. Not great, but better.
Can be solved with this diff:
drivers/net/ethernet/mellanox/mlxsw/core_env.c +2 -2
@@ -1332,7 +1332,7 @@ mlxsw_env_linecard_modules_power_mode_apply(struct mlxsw_core *mlxsw_core,for (i =0 ; i < env->line_cards[slot_index]->module_count; i++) {enum ethtool_module_power_mode_policy policy;struct mlxsw_env_module_info *module_info; -struct netlink_ext_ack extack; +struct netlink_ext_ack extack = {};int err; module_info = &env->line_cards[slot_index]->module_info[i];
@@ -1340,7 +1340,7 @@ mlxsw_env_linecard_modules_power_mode_apply(struct mlxsw_core *mlxsw_core, err =mlxsw_env_set_module_power_mode_apply (mlxsw_core, slot_index, i, policy, &extack); -if (err) +if (err && extack._msg)dev_err (env->bus_info->dev,"%s\n" , extack._msg); } }