Commit f408b376 authored by Junxin Chen's avatar Junxin Chen Committed by mufengyan
Browse files

unic: fix issue that return value is not processed

driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4


CVE: NA

-----------------------------------------------------------

The current code implementation has some functions that do not handle
return values, which may pose security risks.
This patch adds return value handling and removes redundant return
value processing.

Fixes: 97d2f809 ("UNIC: Debugfs supports query of ip and guid table's list and specification")
Signed-off-by: default avatarHaibin Lu <luhaibin10@hisilicon.com>
Signed-off-by: default avatarJunxin Chen <chenjunxin1@huawei.com>
parent 82dc8c56
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -274,6 +274,9 @@ static int hns3_unic_add_mc_guid(struct net_device *netdev,
	struct hnae3_handle *h = hns3_get_handle(netdev);
	u8 mguid[UBL_ALEN] = {0};

	if (!h->ae_algo->ops->add_addr)
		return -EOPNOTSUPP;

	if (!hns3_unic_mguid_valid_check(addr)) {
		hns3_unic_format_sim_guid_addr(format_simple_guid_addr, addr);
		netdev_err(netdev, "Add mc guid err! invalid guid: %s\n",
@@ -282,11 +285,9 @@ static int hns3_unic_add_mc_guid(struct net_device *netdev,
	}

	hns3_unic_extern_mc_guid(mguid, addr);
	if (h->ae_algo->ops->add_addr)

	return h->ae_algo->ops->add_addr(h, (const u8 *)mguid,
					 HNAE3_UNIC_MCGUID_ADDR);

	return 0;
}

static int hns3_unic_del_mc_guid(struct net_device *netdev,
@@ -296,6 +297,9 @@ static int hns3_unic_del_mc_guid(struct net_device *netdev,
	struct hnae3_handle *h = hns3_get_handle(netdev);
	u8 mguid[UBL_ALEN] = {0};

	if (!h->ae_algo->ops->rm_addr)
		return -EOPNOTSUPP;

	if (!hns3_unic_mguid_valid_check(addr)) {
		hns3_unic_format_sim_guid_addr(format_simple_guid_addr, addr);
		netdev_err(netdev, "Del mc guid err! invalid guid: %s\n",
@@ -304,11 +308,9 @@ static int hns3_unic_del_mc_guid(struct net_device *netdev,
	}

	hns3_unic_extern_mc_guid(mguid, addr);
	if (h->ae_algo->ops->rm_addr)

	return h->ae_algo->ops->rm_addr(h, (const u8 *)mguid,
					HNAE3_UNIC_MCGUID_ADDR);

	return 0;
}

static u8 hns3_unic_get_netdev_flags(struct net_device *netdev)
+25 −9
Original line number Diff line number Diff line
@@ -20,9 +20,6 @@
#include "hns3_enet.h"
#include "hns3_unic_debugfs.h"

static const char ub_dbg_root_name[] = "ub";
static struct dentry *ub_dbg_root;

static struct hns3_dbg_dentry_info ub_dbg_dentry[] = {
	{
		.name = "ip_tbl"
@@ -172,26 +169,34 @@ static const struct file_operations ub_dbg_fops = {
	.read  = hns3_unic_dbg_read,
};

static int hns3_unic_dbg_file_init(struct hnae3_handle *handle, u32 cmd)
static int hns3_unic_dbg_file_init(struct hnae3_handle *handle, u32 index)
{
	struct hns3_dbg_data *data;
	struct dentry *entry_dir;
	struct dentry *file;

	data = devm_kzalloc(&handle->pdev->dev, sizeof(*data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	data->handle = handle;
	data->cmd = ub_dbg_cmd[cmd].cmd;
	entry_dir = ub_dbg_dentry[ub_dbg_cmd[cmd].dentry].dentry;
	debugfs_create_file(ub_dbg_cmd[cmd].name, 0400, entry_dir,
	data->cmd = ub_dbg_cmd[index].cmd;
	entry_dir = ub_dbg_dentry[ub_dbg_cmd[index].dentry].dentry;
	file = debugfs_create_file(ub_dbg_cmd[index].name, 0400, entry_dir,
				   data, &ub_dbg_fops);
	if (IS_ERR_OR_NULL(file)) {
		dev_err(&handle->pdev->dev, "failed to create %s file.\n",
			ub_dbg_cmd[index].name);
		return -EFAULT;
	}

	return 0;
}

int hns3_unic_dbg_init(struct hnae3_handle *handle, struct dentry *parent)
{
	char ub_dbg_root_name[] = "ub";
	struct dentry *ub_dbg_root;
	int ret = 0;
	u32 i;

@@ -206,10 +211,21 @@ int hns3_unic_dbg_init(struct hnae3_handle *handle, struct dentry *parent)
		return -ENOMEM;

	ub_dbg_root = debugfs_create_dir(ub_dbg_root_name, parent);
	if (IS_ERR_OR_NULL(ub_dbg_root)) {
		dev_err(&handle->pdev->dev,
			"failed to create unic debugfs root dir.\n");
		return -EFAULT;
	}

	for (i = 0; i < UB_DBG_DENTRY_END; i++)
	for (i = 0; i < ARRAY_SIZE(ub_dbg_dentry); i++) {
		ub_dbg_dentry[i].dentry =
			debugfs_create_dir(ub_dbg_dentry[i].name, ub_dbg_root);
		if (IS_ERR_OR_NULL(ub_dbg_dentry[i].dentry)) {
			dev_err(&handle->pdev->dev, "failed to create %s dir.\n",
				ub_dbg_dentry[i].name);
			return -EFAULT;
		}
	}

	for (i = 0; i < ARRAY_SIZE(ub_dbg_cmd); i++) {
		if (!ub_dbg_cmd[i].init) {
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ enum hns3_dbg_ub_dentry_type {
	UB_DBG_DENTRY_IP,
	UB_DBG_DENTRY_GUID,
	UB_DBG_DENTRY_FASTPATH,
	UB_DBG_DENTRY_END,
};

int hns3_unic_dbg_init(struct hnae3_handle *handle, struct dentry *parent);
+2 −5
Original line number Diff line number Diff line
@@ -12543,11 +12543,8 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
		goto err_mdiobus_unreg;

#ifdef CONFIG_HNS3_UBL
	if (hnae3_dev_ubl_supported(ae_dev)) {
		ret = hclge_unic_init_iptbl_info(hdev);
		if (ret)
			goto err_mdiobus_unreg;
	}
	if (hnae3_dev_ubl_supported(ae_dev))
		hclge_unic_init_iptbl_info(hdev);
#endif

	ret = hclge_mac_init(hdev);
+2 −2
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@
#define HCLGE_UMV_TBL_SIZE		3072
#define HCLGE_DEFAULT_UMV_SPACE_PER_PF \
	(HCLGE_UMV_TBL_SIZE / HCLGE_MAX_PF_NUM)
#define HCLGE_DEFAULT_GUID_TBL_SIZE	64
#define HCLGE_DEFAULT_GUID_TBL_SIZE	320
#define HCLGE_DEFAULT_IP_TBL_SIZE	1024

#define HCLGE_TQP_RESET_TRY_TIMES	200
Loading