From c4c441fb17a1af34ca77401f6c4982da19b0882d Mon Sep 17 00:00:00 2001 From: Saeed Mahameed Date: Sun, 13 Apr 2014 11:58:36 +0300 Subject: [PATCH] mlx4_vnic: fix potential data corruption in sprintf Signed-off-by: Saeed Mahameed (Ported from Mellanox OFED 2.4) Signed-off-by: Mukesh Kacker --- drivers/net/ethernet/mellanox/mlx4_vnic/vnic.h | 3 ++- drivers/net/ethernet/mellanox/mlx4_vnic/vnic_fip_discover.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4_vnic/vnic.h b/drivers/net/ethernet/mellanox/mlx4_vnic/vnic.h index 03c12e93d211..afdb7b73c2d4 100644 --- a/drivers/net/ethernet/mellanox/mlx4_vnic/vnic.h +++ b/drivers/net/ethernet/mellanox/mlx4_vnic/vnic.h @@ -155,6 +155,7 @@ extern struct ib_sa_client vnic_sa_client; #define VNIC_SYSFS_FLEN (VNIC_NAME_LEN * 2) /* SYSFS file name len, allow pre/suffix (32)*/ #define VNIC_SYSFS_LLEN 64 #define VNIC_VENDOR_LEN 8 +#define DISCOVER_NAME_LEN (VNIC_DESC_LEN + 5) /* VNIC_DESC_LEN + pkey len */ #define GID_LEN 16 #define GUID_LEN 8 #define IPV4_LEN 4 @@ -934,7 +935,7 @@ struct pkt_rcv_list { }; struct fip_discover { - char name[VNIC_NAME_LEN]; + char name[DISCOVER_NAME_LEN]; struct vnic_port *port; struct list_head discover_list; spinlock_t lock; diff --git a/drivers/net/ethernet/mellanox/mlx4_vnic/vnic_fip_discover.c b/drivers/net/ethernet/mellanox/mlx4_vnic/vnic_fip_discover.c index 3b87a4426637..86f5cc78ce83 100644 --- a/drivers/net/ethernet/mellanox/mlx4_vnic/vnic_fip_discover.c +++ b/drivers/net/ethernet/mellanox/mlx4_vnic/vnic_fip_discover.c @@ -231,7 +231,8 @@ int fip_discover_init(struct vnic_port *port, struct fip_discover *discover, discover->pkey = pkey; INIT_LIST_HEAD(&discover->gw_list); init_rwsem(&discover->l_rwsem); - sprintf(discover->name, "%s_P%x", port->name, discover->pkey); + snprintf(discover->name, DISCOVER_NAME_LEN, + "%s_P%x", port->name, discover->pkey); } INIT_LIST_HEAD(&discover->hadmin_cache); vnic_mcast_root_init(&discover->mcast_tree); -- 2.50.1