From: Junxin Chen chenjunxin1@huawei.com
driver inclusion category: bugfix bugzilla: NA CVE: NA
----------------------------------
Nowadays, we have checked device name at user tool, and have limited length of device name at kernel driver. But when get_netdev_by_ifname return NULL, it would cause print device name without check terminator.
This patch fixes this bug, when device name's last character isn't a '\0', kernel driver would return -EINVAL to user.
Signed-off-by: Junxin Chen chenjunxin1@huawei.com Reviewed-by: Weiwei Deng dengweiwei@huawei.com Reviewed-by: Shengzui You youshengzui@huawei.com Reviewed-by: Zhaohui Zhong zhongzhaohui@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/net/ethernet/hisilicon/hns3/hns3_cae/hns3_cae_init.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_cae/hns3_cae_init.c b/drivers/net/ethernet/hisilicon/hns3/hns3_cae/hns3_cae_init.c index 7c084a6fbe18..1e012917e010 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_cae/hns3_cae_init.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_cae/hns3_cae_init.c @@ -335,6 +335,11 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd, * code yet, so we don't need lock. */ rtnl_lock(); + if (nt_msg.device_name[IFNAMSIZ - 1] != '\0') { + pr_err("the device name is invalid.\n"); + ret = -EINVAL; + goto out_invalid; + } ret = hns3_cae_k_get_netdev_by_ifname(nt_msg.device_name, &nic_dev); if (ret) { pr_err("can not get the netdevice correctly\n");