Commit fe87922c authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Jakub Kicinski

net/mlx5: fix possible stack overflows

A couple of debug functions use a 512 byte temporary buffer and call another
function that has another buffer of the same size, which in turn exceeds the
usual warning limit for excessive stack usage:

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_dbg.c:1073:1: error: stack frame size (1448) exceeds limit (1024) in 'dr_dump_start' [-Werror,-Wframe-larger-than]
dr_dump_start(struct seq_file *file, loff_t *pos)
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_dbg.c:1009:1: error: stack frame size (1120) exceeds limit (1024) in 'dr_dump_domain' [-Werror,-Wframe-larger-than]
dr_dump_domain(struct seq_file *file, struct mlx5dr_domain *dmn)
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_dbg.c:705:1: error: stack frame size (1104) exceeds limit (1024) in 'dr_dump_matcher_rx_tx' [-Werror,-Wframe-larger-than]
dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx,

Rework these so that each of the various code paths only ever has one of
these buffers in it, and exactly the functions that declare one have
the 'noinline_for_stack' annotation that prevents them from all being
inlined into the same caller.

Fixes: 917d1e79 ("net/mlx5: DR, Change SWS usage to debug fs seq_file interface")
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/all/20240219100506.648089-1-arnd@kernel.org/Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarTariq Toukan <tariqt@nvidia.com>
Link: https://lore.kernel.org/r/20240408074142.3007036-1-arnd@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 186abfcd
...@@ -205,12 +205,11 @@ dr_dump_hex_print(char hex[DR_HEX_SIZE], char *src, u32 size) ...@@ -205,12 +205,11 @@ dr_dump_hex_print(char hex[DR_HEX_SIZE], char *src, u32 size)
} }
static int static int
dr_dump_rule_action_mem(struct seq_file *file, const u64 rule_id, dr_dump_rule_action_mem(struct seq_file *file, char *buff, const u64 rule_id,
struct mlx5dr_rule_action_member *action_mem) struct mlx5dr_rule_action_member *action_mem)
{ {
struct mlx5dr_action *action = action_mem->action; struct mlx5dr_action *action = action_mem->action;
const u64 action_id = DR_DBG_PTR_TO_ID(action); const u64 action_id = DR_DBG_PTR_TO_ID(action);
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
u64 hit_tbl_ptr, miss_tbl_ptr; u64 hit_tbl_ptr, miss_tbl_ptr;
u32 hit_tbl_id, miss_tbl_id; u32 hit_tbl_id, miss_tbl_id;
int ret; int ret;
...@@ -488,10 +487,9 @@ dr_dump_rule_action_mem(struct seq_file *file, const u64 rule_id, ...@@ -488,10 +487,9 @@ dr_dump_rule_action_mem(struct seq_file *file, const u64 rule_id,
} }
static int static int
dr_dump_rule_mem(struct seq_file *file, struct mlx5dr_ste *ste, dr_dump_rule_mem(struct seq_file *file, char *buff, struct mlx5dr_ste *ste,
bool is_rx, const u64 rule_id, u8 format_ver) bool is_rx, const u64 rule_id, u8 format_ver)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
char hw_ste_dump[DR_HEX_SIZE]; char hw_ste_dump[DR_HEX_SIZE];
u32 mem_rec_type; u32 mem_rec_type;
int ret; int ret;
...@@ -522,7 +520,8 @@ dr_dump_rule_mem(struct seq_file *file, struct mlx5dr_ste *ste, ...@@ -522,7 +520,8 @@ dr_dump_rule_mem(struct seq_file *file, struct mlx5dr_ste *ste,
} }
static int static int
dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx, dr_dump_rule_rx_tx(struct seq_file *file, char *buff,
struct mlx5dr_rule_rx_tx *rule_rx_tx,
bool is_rx, const u64 rule_id, u8 format_ver) bool is_rx, const u64 rule_id, u8 format_ver)
{ {
struct mlx5dr_ste *ste_arr[DR_RULE_MAX_STES + DR_ACTION_MAX_STES]; struct mlx5dr_ste *ste_arr[DR_RULE_MAX_STES + DR_ACTION_MAX_STES];
...@@ -533,7 +532,7 @@ dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx, ...@@ -533,7 +532,7 @@ dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx,
return 0; return 0;
while (i--) { while (i--) {
ret = dr_dump_rule_mem(file, ste_arr[i], is_rx, rule_id, ret = dr_dump_rule_mem(file, buff, ste_arr[i], is_rx, rule_id,
format_ver); format_ver);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -542,7 +541,8 @@ dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx, ...@@ -542,7 +541,8 @@ dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx,
return 0; return 0;
} }
static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule) static noinline_for_stack int
dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule)
{ {
struct mlx5dr_rule_action_member *action_mem; struct mlx5dr_rule_action_member *action_mem;
const u64 rule_id = DR_DBG_PTR_TO_ID(rule); const u64 rule_id = DR_DBG_PTR_TO_ID(rule);
...@@ -565,19 +565,19 @@ static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule) ...@@ -565,19 +565,19 @@ static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule)
return ret; return ret;
if (rx->nic_matcher) { if (rx->nic_matcher) {
ret = dr_dump_rule_rx_tx(file, rx, true, rule_id, format_ver); ret = dr_dump_rule_rx_tx(file, buff, rx, true, rule_id, format_ver);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
if (tx->nic_matcher) { if (tx->nic_matcher) {
ret = dr_dump_rule_rx_tx(file, tx, false, rule_id, format_ver); ret = dr_dump_rule_rx_tx(file, buff, tx, false, rule_id, format_ver);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
list_for_each_entry(action_mem, &rule->rule_actions_list, list) { list_for_each_entry(action_mem, &rule->rule_actions_list, list) {
ret = dr_dump_rule_action_mem(file, rule_id, action_mem); ret = dr_dump_rule_action_mem(file, buff, rule_id, action_mem);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -586,10 +586,10 @@ static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule) ...@@ -586,10 +586,10 @@ static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule)
} }
static int static int
dr_dump_matcher_mask(struct seq_file *file, struct mlx5dr_match_param *mask, dr_dump_matcher_mask(struct seq_file *file, char *buff,
struct mlx5dr_match_param *mask,
u8 criteria, const u64 matcher_id) u8 criteria, const u64 matcher_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
char dump[DR_HEX_SIZE]; char dump[DR_HEX_SIZE];
int ret; int ret;
...@@ -681,10 +681,10 @@ dr_dump_matcher_mask(struct seq_file *file, struct mlx5dr_match_param *mask, ...@@ -681,10 +681,10 @@ dr_dump_matcher_mask(struct seq_file *file, struct mlx5dr_match_param *mask,
} }
static int static int
dr_dump_matcher_builder(struct seq_file *file, struct mlx5dr_ste_build *builder, dr_dump_matcher_builder(struct seq_file *file, char *buff,
struct mlx5dr_ste_build *builder,
u32 index, bool is_rx, const u64 matcher_id) u32 index, bool is_rx, const u64 matcher_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
int ret; int ret;
ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH, ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH,
...@@ -702,11 +702,10 @@ dr_dump_matcher_builder(struct seq_file *file, struct mlx5dr_ste_build *builder, ...@@ -702,11 +702,10 @@ dr_dump_matcher_builder(struct seq_file *file, struct mlx5dr_ste_build *builder,
} }
static int static int
dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx, dr_dump_matcher_rx_tx(struct seq_file *file, char *buff, bool is_rx,
struct mlx5dr_matcher_rx_tx *matcher_rx_tx, struct mlx5dr_matcher_rx_tx *matcher_rx_tx,
const u64 matcher_id) const u64 matcher_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
enum dr_dump_rec_type rec_type; enum dr_dump_rec_type rec_type;
u64 s_icm_addr, e_icm_addr; u64 s_icm_addr, e_icm_addr;
int i, ret; int i, ret;
...@@ -731,7 +730,7 @@ dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx, ...@@ -731,7 +730,7 @@ dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx,
return ret; return ret;
for (i = 0; i < matcher_rx_tx->num_of_builders; i++) { for (i = 0; i < matcher_rx_tx->num_of_builders; i++) {
ret = dr_dump_matcher_builder(file, ret = dr_dump_matcher_builder(file, buff,
&matcher_rx_tx->ste_builder[i], &matcher_rx_tx->ste_builder[i],
i, is_rx, matcher_id); i, is_rx, matcher_id);
if (ret < 0) if (ret < 0)
...@@ -741,7 +740,7 @@ dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx, ...@@ -741,7 +740,7 @@ dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx,
return 0; return 0;
} }
static int static noinline_for_stack int
dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher) dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher)
{ {
struct mlx5dr_matcher_rx_tx *rx = &matcher->rx; struct mlx5dr_matcher_rx_tx *rx = &matcher->rx;
...@@ -763,19 +762,19 @@ dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher) ...@@ -763,19 +762,19 @@ dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher)
if (ret) if (ret)
return ret; return ret;
ret = dr_dump_matcher_mask(file, &matcher->mask, ret = dr_dump_matcher_mask(file, buff, &matcher->mask,
matcher->match_criteria, matcher_id); matcher->match_criteria, matcher_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (rx->nic_tbl) { if (rx->nic_tbl) {
ret = dr_dump_matcher_rx_tx(file, true, rx, matcher_id); ret = dr_dump_matcher_rx_tx(file, buff, true, rx, matcher_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
if (tx->nic_tbl) { if (tx->nic_tbl) {
ret = dr_dump_matcher_rx_tx(file, false, tx, matcher_id); ret = dr_dump_matcher_rx_tx(file, buff, false, tx, matcher_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -803,11 +802,10 @@ dr_dump_matcher_all(struct seq_file *file, struct mlx5dr_matcher *matcher) ...@@ -803,11 +802,10 @@ dr_dump_matcher_all(struct seq_file *file, struct mlx5dr_matcher *matcher)
} }
static int static int
dr_dump_table_rx_tx(struct seq_file *file, bool is_rx, dr_dump_table_rx_tx(struct seq_file *file, char *buff, bool is_rx,
struct mlx5dr_table_rx_tx *table_rx_tx, struct mlx5dr_table_rx_tx *table_rx_tx,
const u64 table_id) const u64 table_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
enum dr_dump_rec_type rec_type; enum dr_dump_rec_type rec_type;
u64 s_icm_addr; u64 s_icm_addr;
int ret; int ret;
...@@ -829,7 +827,8 @@ dr_dump_table_rx_tx(struct seq_file *file, bool is_rx, ...@@ -829,7 +827,8 @@ dr_dump_table_rx_tx(struct seq_file *file, bool is_rx,
return 0; return 0;
} }
static int dr_dump_table(struct seq_file *file, struct mlx5dr_table *table) static noinline_for_stack int
dr_dump_table(struct seq_file *file, struct mlx5dr_table *table)
{ {
struct mlx5dr_table_rx_tx *rx = &table->rx; struct mlx5dr_table_rx_tx *rx = &table->rx;
struct mlx5dr_table_rx_tx *tx = &table->tx; struct mlx5dr_table_rx_tx *tx = &table->tx;
...@@ -848,14 +847,14 @@ static int dr_dump_table(struct seq_file *file, struct mlx5dr_table *table) ...@@ -848,14 +847,14 @@ static int dr_dump_table(struct seq_file *file, struct mlx5dr_table *table)
return ret; return ret;
if (rx->nic_dmn) { if (rx->nic_dmn) {
ret = dr_dump_table_rx_tx(file, true, rx, ret = dr_dump_table_rx_tx(file, buff, true, rx,
DR_DBG_PTR_TO_ID(table)); DR_DBG_PTR_TO_ID(table));
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
if (tx->nic_dmn) { if (tx->nic_dmn) {
ret = dr_dump_table_rx_tx(file, false, tx, ret = dr_dump_table_rx_tx(file, buff, false, tx,
DR_DBG_PTR_TO_ID(table)); DR_DBG_PTR_TO_ID(table));
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -881,10 +880,10 @@ static int dr_dump_table_all(struct seq_file *file, struct mlx5dr_table *tbl) ...@@ -881,10 +880,10 @@ static int dr_dump_table_all(struct seq_file *file, struct mlx5dr_table *tbl)
} }
static int static int
dr_dump_send_ring(struct seq_file *file, struct mlx5dr_send_ring *ring, dr_dump_send_ring(struct seq_file *file, char *buff,
struct mlx5dr_send_ring *ring,
const u64 domain_id) const u64 domain_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
int ret; int ret;
ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH, ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH,
...@@ -902,13 +901,13 @@ dr_dump_send_ring(struct seq_file *file, struct mlx5dr_send_ring *ring, ...@@ -902,13 +901,13 @@ dr_dump_send_ring(struct seq_file *file, struct mlx5dr_send_ring *ring,
return 0; return 0;
} }
static noinline_for_stack int static int
dr_dump_domain_info_flex_parser(struct seq_file *file, dr_dump_domain_info_flex_parser(struct seq_file *file,
char *buff,
const char *flex_parser_name, const char *flex_parser_name,
const u8 flex_parser_value, const u8 flex_parser_value,
const u64 domain_id) const u64 domain_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
int ret; int ret;
ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH, ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH,
...@@ -925,11 +924,11 @@ dr_dump_domain_info_flex_parser(struct seq_file *file, ...@@ -925,11 +924,11 @@ dr_dump_domain_info_flex_parser(struct seq_file *file,
return 0; return 0;
} }
static noinline_for_stack int static int
dr_dump_domain_info_caps(struct seq_file *file, struct mlx5dr_cmd_caps *caps, dr_dump_domain_info_caps(struct seq_file *file, char *buff,
struct mlx5dr_cmd_caps *caps,
const u64 domain_id) const u64 domain_id)
{ {
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
struct mlx5dr_cmd_vport_cap *vport_caps; struct mlx5dr_cmd_vport_cap *vport_caps;
unsigned long i, vports_num; unsigned long i, vports_num;
int ret; int ret;
...@@ -969,34 +968,35 @@ dr_dump_domain_info_caps(struct seq_file *file, struct mlx5dr_cmd_caps *caps, ...@@ -969,34 +968,35 @@ dr_dump_domain_info_caps(struct seq_file *file, struct mlx5dr_cmd_caps *caps,
} }
static int static int
dr_dump_domain_info(struct seq_file *file, struct mlx5dr_domain_info *info, dr_dump_domain_info(struct seq_file *file, char *buff,
struct mlx5dr_domain_info *info,
const u64 domain_id) const u64 domain_id)
{ {
int ret; int ret;
ret = dr_dump_domain_info_caps(file, &info->caps, domain_id); ret = dr_dump_domain_info_caps(file, buff, &info->caps, domain_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dr_dump_domain_info_flex_parser(file, "icmp_dw0", ret = dr_dump_domain_info_flex_parser(file, buff, "icmp_dw0",
info->caps.flex_parser_id_icmp_dw0, info->caps.flex_parser_id_icmp_dw0,
domain_id); domain_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dr_dump_domain_info_flex_parser(file, "icmp_dw1", ret = dr_dump_domain_info_flex_parser(file, buff, "icmp_dw1",
info->caps.flex_parser_id_icmp_dw1, info->caps.flex_parser_id_icmp_dw1,
domain_id); domain_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dr_dump_domain_info_flex_parser(file, "icmpv6_dw0", ret = dr_dump_domain_info_flex_parser(file, buff, "icmpv6_dw0",
info->caps.flex_parser_id_icmpv6_dw0, info->caps.flex_parser_id_icmpv6_dw0,
domain_id); domain_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = dr_dump_domain_info_flex_parser(file, "icmpv6_dw1", ret = dr_dump_domain_info_flex_parser(file, buff, "icmpv6_dw1",
info->caps.flex_parser_id_icmpv6_dw1, info->caps.flex_parser_id_icmpv6_dw1,
domain_id); domain_id);
if (ret < 0) if (ret < 0)
...@@ -1032,12 +1032,12 @@ dr_dump_domain(struct seq_file *file, struct mlx5dr_domain *dmn) ...@@ -1032,12 +1032,12 @@ dr_dump_domain(struct seq_file *file, struct mlx5dr_domain *dmn)
if (ret) if (ret)
return ret; return ret;
ret = dr_dump_domain_info(file, &dmn->info, domain_id); ret = dr_dump_domain_info(file, buff, &dmn->info, domain_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (dmn->info.supp_sw_steering) { if (dmn->info.supp_sw_steering) {
ret = dr_dump_send_ring(file, dmn->send_ring, domain_id); ret = dr_dump_send_ring(file, buff, dmn->send_ring, domain_id);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment