Skip to content

Commit 4a34860

Browse files
tiwaidavem330
authored andcommitted
net: mlx4: Use scnprintf() for avoiding potential buffer overflow
Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf(). Cc: "David S . Miller" <[email protected]> Cc: Tariq Toukan <[email protected]> To: [email protected] Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 13bde56 commit 4a34860

File tree

1 file changed

+31
-31
lines changed
  • drivers/net/ethernet/mellanox/mlx4

1 file changed

+31
-31
lines changed

drivers/net/ethernet/mellanox/mlx4/mcg.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -906,59 +906,59 @@ static void mlx4_err_rule(struct mlx4_dev *dev, char *str,
906906
int len = 0;
907907

908908
mlx4_err(dev, "%s", str);
909-
len += snprintf(buf + len, BUF_SIZE - len,
910-
"port = %d prio = 0x%x qp = 0x%x ",
911-
rule->port, rule->priority, rule->qpn);
909+
len += scnprintf(buf + len, BUF_SIZE - len,
910+
"port = %d prio = 0x%x qp = 0x%x ",
911+
rule->port, rule->priority, rule->qpn);
912912

913913
list_for_each_entry(cur, &rule->list, list) {
914914
switch (cur->id) {
915915
case MLX4_NET_TRANS_RULE_ID_ETH:
916-
len += snprintf(buf + len, BUF_SIZE - len,
917-
"dmac = %pM ", &cur->eth.dst_mac);
916+
len += scnprintf(buf + len, BUF_SIZE - len,
917+
"dmac = %pM ", &cur->eth.dst_mac);
918918
if (cur->eth.ether_type)
919-
len += snprintf(buf + len, BUF_SIZE - len,
920-
"ethertype = 0x%x ",
921-
be16_to_cpu(cur->eth.ether_type));
919+
len += scnprintf(buf + len, BUF_SIZE - len,
920+
"ethertype = 0x%x ",
921+
be16_to_cpu(cur->eth.ether_type));
922922
if (cur->eth.vlan_id)
923-
len += snprintf(buf + len, BUF_SIZE - len,
924-
"vlan-id = %d ",
925-
be16_to_cpu(cur->eth.vlan_id));
923+
len += scnprintf(buf + len, BUF_SIZE - len,
924+
"vlan-id = %d ",
925+
be16_to_cpu(cur->eth.vlan_id));
926926
break;
927927

928928
case MLX4_NET_TRANS_RULE_ID_IPV4:
929929
if (cur->ipv4.src_ip)
930-
len += snprintf(buf + len, BUF_SIZE - len,
931-
"src-ip = %pI4 ",
932-
&cur->ipv4.src_ip);
930+
len += scnprintf(buf + len, BUF_SIZE - len,
931+
"src-ip = %pI4 ",
932+
&cur->ipv4.src_ip);
933933
if (cur->ipv4.dst_ip)
934-
len += snprintf(buf + len, BUF_SIZE - len,
935-
"dst-ip = %pI4 ",
936-
&cur->ipv4.dst_ip);
934+
len += scnprintf(buf + len, BUF_SIZE - len,
935+
"dst-ip = %pI4 ",
936+
&cur->ipv4.dst_ip);
937937
break;
938938

939939
case MLX4_NET_TRANS_RULE_ID_TCP:
940940
case MLX4_NET_TRANS_RULE_ID_UDP:
941941
if (cur->tcp_udp.src_port)
942-
len += snprintf(buf + len, BUF_SIZE - len,
943-
"src-port = %d ",
944-
be16_to_cpu(cur->tcp_udp.src_port));
942+
len += scnprintf(buf + len, BUF_SIZE - len,
943+
"src-port = %d ",
944+
be16_to_cpu(cur->tcp_udp.src_port));
945945
if (cur->tcp_udp.dst_port)
946-
len += snprintf(buf + len, BUF_SIZE - len,
947-
"dst-port = %d ",
948-
be16_to_cpu(cur->tcp_udp.dst_port));
946+
len += scnprintf(buf + len, BUF_SIZE - len,
947+
"dst-port = %d ",
948+
be16_to_cpu(cur->tcp_udp.dst_port));
949949
break;
950950

951951
case MLX4_NET_TRANS_RULE_ID_IB:
952-
len += snprintf(buf + len, BUF_SIZE - len,
953-
"dst-gid = %pI6\n", cur->ib.dst_gid);
954-
len += snprintf(buf + len, BUF_SIZE - len,
955-
"dst-gid-mask = %pI6\n",
956-
cur->ib.dst_gid_msk);
952+
len += scnprintf(buf + len, BUF_SIZE - len,
953+
"dst-gid = %pI6\n", cur->ib.dst_gid);
954+
len += scnprintf(buf + len, BUF_SIZE - len,
955+
"dst-gid-mask = %pI6\n",
956+
cur->ib.dst_gid_msk);
957957
break;
958958

959959
case MLX4_NET_TRANS_RULE_ID_VXLAN:
960-
len += snprintf(buf + len, BUF_SIZE - len,
961-
"VNID = %d ", be32_to_cpu(cur->vxlan.vni));
960+
len += scnprintf(buf + len, BUF_SIZE - len,
961+
"VNID = %d ", be32_to_cpu(cur->vxlan.vni));
962962
break;
963963
case MLX4_NET_TRANS_RULE_ID_IPV6:
964964
break;
@@ -967,7 +967,7 @@ static void mlx4_err_rule(struct mlx4_dev *dev, char *str,
967967
break;
968968
}
969969
}
970-
len += snprintf(buf + len, BUF_SIZE - len, "\n");
970+
len += scnprintf(buf + len, BUF_SIZE - len, "\n");
971971
mlx4_err(dev, "%s", buf);
972972

973973
if (len >= BUF_SIZE)

0 commit comments

Comments
 (0)