Skip to content

Commit fe87922

Browse files
arndbkuba-moo
authored andcommitted
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: 917d1e7 ("net/mlx5: DR, Change SWS usage to debug fs seq_file interface") Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Link: https://lore.kernel.org/all/20240219100506.648089-1-arnd@kernel.org/ Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Tariq Toukan <tariqt@nvidia.com> Link: https://lore.kernel.org/r/20240408074142.3007036-1-arnd@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 186abfc commit fe87922

1 file changed

Lines changed: 41 additions & 41 deletions

File tree

  • drivers/net/ethernet/mellanox/mlx5/core/steering

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_dbg.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,11 @@ dr_dump_hex_print(char hex[DR_HEX_SIZE], char *src, u32 size)
205205
}
206206

207207
static int
208-
dr_dump_rule_action_mem(struct seq_file *file, const u64 rule_id,
208+
dr_dump_rule_action_mem(struct seq_file *file, char *buff, const u64 rule_id,
209209
struct mlx5dr_rule_action_member *action_mem)
210210
{
211211
struct mlx5dr_action *action = action_mem->action;
212212
const u64 action_id = DR_DBG_PTR_TO_ID(action);
213-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
214213
u64 hit_tbl_ptr, miss_tbl_ptr;
215214
u32 hit_tbl_id, miss_tbl_id;
216215
int ret;
@@ -488,10 +487,9 @@ dr_dump_rule_action_mem(struct seq_file *file, const u64 rule_id,
488487
}
489488

490489
static int
491-
dr_dump_rule_mem(struct seq_file *file, struct mlx5dr_ste *ste,
490+
dr_dump_rule_mem(struct seq_file *file, char *buff, struct mlx5dr_ste *ste,
492491
bool is_rx, const u64 rule_id, u8 format_ver)
493492
{
494-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
495493
char hw_ste_dump[DR_HEX_SIZE];
496494
u32 mem_rec_type;
497495
int ret;
@@ -522,7 +520,8 @@ dr_dump_rule_mem(struct seq_file *file, struct mlx5dr_ste *ste,
522520
}
523521

524522
static int
525-
dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx,
523+
dr_dump_rule_rx_tx(struct seq_file *file, char *buff,
524+
struct mlx5dr_rule_rx_tx *rule_rx_tx,
526525
bool is_rx, const u64 rule_id, u8 format_ver)
527526
{
528527
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,
533532
return 0;
534533

535534
while (i--) {
536-
ret = dr_dump_rule_mem(file, ste_arr[i], is_rx, rule_id,
535+
ret = dr_dump_rule_mem(file, buff, ste_arr[i], is_rx, rule_id,
537536
format_ver);
538537
if (ret < 0)
539538
return ret;
@@ -542,7 +541,8 @@ dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx,
542541
return 0;
543542
}
544543

545-
static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule)
544+
static noinline_for_stack int
545+
dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule)
546546
{
547547
struct mlx5dr_rule_action_member *action_mem;
548548
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)
565565
return ret;
566566

567567
if (rx->nic_matcher) {
568-
ret = dr_dump_rule_rx_tx(file, rx, true, rule_id, format_ver);
568+
ret = dr_dump_rule_rx_tx(file, buff, rx, true, rule_id, format_ver);
569569
if (ret < 0)
570570
return ret;
571571
}
572572

573573
if (tx->nic_matcher) {
574-
ret = dr_dump_rule_rx_tx(file, tx, false, rule_id, format_ver);
574+
ret = dr_dump_rule_rx_tx(file, buff, tx, false, rule_id, format_ver);
575575
if (ret < 0)
576576
return ret;
577577
}
578578

579579
list_for_each_entry(action_mem, &rule->rule_actions_list, list) {
580-
ret = dr_dump_rule_action_mem(file, rule_id, action_mem);
580+
ret = dr_dump_rule_action_mem(file, buff, rule_id, action_mem);
581581
if (ret < 0)
582582
return ret;
583583
}
@@ -586,10 +586,10 @@ static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule)
586586
}
587587

588588
static int
589-
dr_dump_matcher_mask(struct seq_file *file, struct mlx5dr_match_param *mask,
589+
dr_dump_matcher_mask(struct seq_file *file, char *buff,
590+
struct mlx5dr_match_param *mask,
590591
u8 criteria, const u64 matcher_id)
591592
{
592-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
593593
char dump[DR_HEX_SIZE];
594594
int ret;
595595

@@ -681,10 +681,10 @@ dr_dump_matcher_mask(struct seq_file *file, struct mlx5dr_match_param *mask,
681681
}
682682

683683
static int
684-
dr_dump_matcher_builder(struct seq_file *file, struct mlx5dr_ste_build *builder,
684+
dr_dump_matcher_builder(struct seq_file *file, char *buff,
685+
struct mlx5dr_ste_build *builder,
685686
u32 index, bool is_rx, const u64 matcher_id)
686687
{
687-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
688688
int ret;
689689

690690
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,
702702
}
703703

704704
static int
705-
dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx,
705+
dr_dump_matcher_rx_tx(struct seq_file *file, char *buff, bool is_rx,
706706
struct mlx5dr_matcher_rx_tx *matcher_rx_tx,
707707
const u64 matcher_id)
708708
{
709-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
710709
enum dr_dump_rec_type rec_type;
711710
u64 s_icm_addr, e_icm_addr;
712711
int i, ret;
@@ -731,7 +730,7 @@ dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx,
731730
return ret;
732731

733732
for (i = 0; i < matcher_rx_tx->num_of_builders; i++) {
734-
ret = dr_dump_matcher_builder(file,
733+
ret = dr_dump_matcher_builder(file, buff,
735734
&matcher_rx_tx->ste_builder[i],
736735
i, is_rx, matcher_id);
737736
if (ret < 0)
@@ -741,7 +740,7 @@ dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx,
741740
return 0;
742741
}
743742

744-
static int
743+
static noinline_for_stack int
745744
dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher)
746745
{
747746
struct mlx5dr_matcher_rx_tx *rx = &matcher->rx;
@@ -763,19 +762,19 @@ dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher)
763762
if (ret)
764763
return ret;
765764

766-
ret = dr_dump_matcher_mask(file, &matcher->mask,
765+
ret = dr_dump_matcher_mask(file, buff, &matcher->mask,
767766
matcher->match_criteria, matcher_id);
768767
if (ret < 0)
769768
return ret;
770769

771770
if (rx->nic_tbl) {
772-
ret = dr_dump_matcher_rx_tx(file, true, rx, matcher_id);
771+
ret = dr_dump_matcher_rx_tx(file, buff, true, rx, matcher_id);
773772
if (ret < 0)
774773
return ret;
775774
}
776775

777776
if (tx->nic_tbl) {
778-
ret = dr_dump_matcher_rx_tx(file, false, tx, matcher_id);
777+
ret = dr_dump_matcher_rx_tx(file, buff, false, tx, matcher_id);
779778
if (ret < 0)
780779
return ret;
781780
}
@@ -803,11 +802,10 @@ dr_dump_matcher_all(struct seq_file *file, struct mlx5dr_matcher *matcher)
803802
}
804803

805804
static int
806-
dr_dump_table_rx_tx(struct seq_file *file, bool is_rx,
805+
dr_dump_table_rx_tx(struct seq_file *file, char *buff, bool is_rx,
807806
struct mlx5dr_table_rx_tx *table_rx_tx,
808807
const u64 table_id)
809808
{
810-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
811809
enum dr_dump_rec_type rec_type;
812810
u64 s_icm_addr;
813811
int ret;
@@ -829,7 +827,8 @@ dr_dump_table_rx_tx(struct seq_file *file, bool is_rx,
829827
return 0;
830828
}
831829

832-
static int dr_dump_table(struct seq_file *file, struct mlx5dr_table *table)
830+
static noinline_for_stack int
831+
dr_dump_table(struct seq_file *file, struct mlx5dr_table *table)
833832
{
834833
struct mlx5dr_table_rx_tx *rx = &table->rx;
835834
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)
848847
return ret;
849848

850849
if (rx->nic_dmn) {
851-
ret = dr_dump_table_rx_tx(file, true, rx,
850+
ret = dr_dump_table_rx_tx(file, buff, true, rx,
852851
DR_DBG_PTR_TO_ID(table));
853852
if (ret < 0)
854853
return ret;
855854
}
856855

857856
if (tx->nic_dmn) {
858-
ret = dr_dump_table_rx_tx(file, false, tx,
857+
ret = dr_dump_table_rx_tx(file, buff, false, tx,
859858
DR_DBG_PTR_TO_ID(table));
860859
if (ret < 0)
861860
return ret;
@@ -881,10 +880,10 @@ static int dr_dump_table_all(struct seq_file *file, struct mlx5dr_table *tbl)
881880
}
882881

883882
static int
884-
dr_dump_send_ring(struct seq_file *file, struct mlx5dr_send_ring *ring,
883+
dr_dump_send_ring(struct seq_file *file, char *buff,
884+
struct mlx5dr_send_ring *ring,
885885
const u64 domain_id)
886886
{
887-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
888887
int ret;
889888

890889
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,
902901
return 0;
903902
}
904903

905-
static noinline_for_stack int
904+
static int
906905
dr_dump_domain_info_flex_parser(struct seq_file *file,
906+
char *buff,
907907
const char *flex_parser_name,
908908
const u8 flex_parser_value,
909909
const u64 domain_id)
910910
{
911-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
912911
int ret;
913912

914913
ret = snprintf(buff, MLX5DR_DEBUG_DUMP_BUFF_LENGTH,
@@ -925,11 +924,11 @@ dr_dump_domain_info_flex_parser(struct seq_file *file,
925924
return 0;
926925
}
927926

928-
static noinline_for_stack int
929-
dr_dump_domain_info_caps(struct seq_file *file, struct mlx5dr_cmd_caps *caps,
927+
static int
928+
dr_dump_domain_info_caps(struct seq_file *file, char *buff,
929+
struct mlx5dr_cmd_caps *caps,
930930
const u64 domain_id)
931931
{
932-
char buff[MLX5DR_DEBUG_DUMP_BUFF_LENGTH];
933932
struct mlx5dr_cmd_vport_cap *vport_caps;
934933
unsigned long i, vports_num;
935934
int ret;
@@ -969,34 +968,35 @@ dr_dump_domain_info_caps(struct seq_file *file, struct mlx5dr_cmd_caps *caps,
969968
}
970969

971970
static int
972-
dr_dump_domain_info(struct seq_file *file, struct mlx5dr_domain_info *info,
971+
dr_dump_domain_info(struct seq_file *file, char *buff,
972+
struct mlx5dr_domain_info *info,
973973
const u64 domain_id)
974974
{
975975
int ret;
976976

977-
ret = dr_dump_domain_info_caps(file, &info->caps, domain_id);
977+
ret = dr_dump_domain_info_caps(file, buff, &info->caps, domain_id);
978978
if (ret < 0)
979979
return ret;
980980

981-
ret = dr_dump_domain_info_flex_parser(file, "icmp_dw0",
981+
ret = dr_dump_domain_info_flex_parser(file, buff, "icmp_dw0",
982982
info->caps.flex_parser_id_icmp_dw0,
983983
domain_id);
984984
if (ret < 0)
985985
return ret;
986986

987-
ret = dr_dump_domain_info_flex_parser(file, "icmp_dw1",
987+
ret = dr_dump_domain_info_flex_parser(file, buff, "icmp_dw1",
988988
info->caps.flex_parser_id_icmp_dw1,
989989
domain_id);
990990
if (ret < 0)
991991
return ret;
992992

993-
ret = dr_dump_domain_info_flex_parser(file, "icmpv6_dw0",
993+
ret = dr_dump_domain_info_flex_parser(file, buff, "icmpv6_dw0",
994994
info->caps.flex_parser_id_icmpv6_dw0,
995995
domain_id);
996996
if (ret < 0)
997997
return ret;
998998

999-
ret = dr_dump_domain_info_flex_parser(file, "icmpv6_dw1",
999+
ret = dr_dump_domain_info_flex_parser(file, buff, "icmpv6_dw1",
10001000
info->caps.flex_parser_id_icmpv6_dw1,
10011001
domain_id);
10021002
if (ret < 0)
@@ -1032,12 +1032,12 @@ dr_dump_domain(struct seq_file *file, struct mlx5dr_domain *dmn)
10321032
if (ret)
10331033
return ret;
10341034

1035-
ret = dr_dump_domain_info(file, &dmn->info, domain_id);
1035+
ret = dr_dump_domain_info(file, buff, &dmn->info, domain_id);
10361036
if (ret < 0)
10371037
return ret;
10381038

10391039
if (dmn->info.supp_sw_steering) {
1040-
ret = dr_dump_send_ring(file, dmn->send_ring, domain_id);
1040+
ret = dr_dump_send_ring(file, buff, dmn->send_ring, domain_id);
10411041
if (ret < 0)
10421042
return ret;
10431043
}

0 commit comments

Comments
 (0)