Unverified Commit b3e50e56 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15638 CVE-2022-49374

Merge Pull Request from: @ci-robot 
 
PR sync from: Wang Liang <wangliang74@huawei.com>
https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/SYCVKNCTTXMVZIL4E3QVLQIERVYEE5ML/ 
Hoang Le (2):
  tipc: add extack messages for bearer/media failure
  tipc: check attribute length for bearer name

 
https://gitee.com/src-openeuler/kernel/issues/IBP2SM 
 
Link:https://gitee.com/openeuler/kernel/pulls/15638

 

Reviewed-by: default avatarZhang Changzhong <zhangchangzhong@huawei.com>
Reviewed-by: default avatarYuan Can <yuancan@huawei.com>
Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
parents ecd01009 864c3389
Loading
Loading
Loading
Loading
+41 −12
Original line number Diff line number Diff line
@@ -235,7 +235,8 @@ void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest)
 */
static int tipc_enable_bearer(struct net *net, const char *name,
			      u32 disc_domain, u32 prio,
			      struct nlattr *attr[])
			      struct nlattr *attr[],
			      struct netlink_ext_ack *extack)
{
	struct tipc_net *tn = tipc_net(net);
	struct tipc_bearer_names b_names;
@@ -248,18 +249,20 @@ static int tipc_enable_bearer(struct net *net, const char *name,
	char *errstr = "";

	if (!bearer_name_validate(name, &b_names)) {
		errstr = "illegal name";
		goto rejected;
		NL_SET_ERR_MSG(extack, "Illegal name");
		return res;
	}

	if (prio > TIPC_MAX_LINK_PRI && prio != TIPC_MEDIA_LINK_PRI) {
		errstr = "illegal priority";
		NL_SET_ERR_MSG(extack, "Illegal priority");
		goto rejected;
	}

	m = tipc_media_find(b_names.media_name);
	if (!m) {
		errstr = "media not registered";
		NL_SET_ERR_MSG(extack, "Media not registered");
		goto rejected;
	}

@@ -273,6 +276,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
			break;
		if (!strcmp(name, b->name)) {
			errstr = "already enabled";
			NL_SET_ERR_MSG(extack, "Already enabled");
			goto rejected;
		}
		bearer_id++;
@@ -284,6 +288,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
			name, prio);
		if (prio == TIPC_MIN_LINK_PRI) {
			errstr = "cannot adjust to lower";
			NL_SET_ERR_MSG(extack, "Cannot adjust to lower");
			goto rejected;
		}
		pr_warn("Bearer <%s>: trying with adjusted priority\n", name);
@@ -294,6 +299,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,

	if (bearer_id >= MAX_BEARERS) {
		errstr = "max 3 bearers permitted";
		NL_SET_ERR_MSG(extack, "Max 3 bearers permitted");
		goto rejected;
	}

@@ -307,6 +313,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
	if (res) {
		kfree(b);
		errstr = "failed to enable media";
		NL_SET_ERR_MSG(extack, "Failed to enable media");
		goto rejected;
	}

@@ -321,6 +328,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
	if (res) {
		bearer_disable(net, b);
		errstr = "failed to create discoverer";
		NL_SET_ERR_MSG(extack, "Failed to create discoverer");
		goto rejected;
	}

@@ -801,6 +809,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
	bearer = tipc_bearer_find(net, name);
	if (!bearer) {
		err = -EINVAL;
		NL_SET_ERR_MSG(info->extack, "Bearer not found");
		goto err_out;
	}

@@ -840,8 +849,10 @@ int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
	name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);

	bearer = tipc_bearer_find(net, name);
	if (!bearer)
	if (!bearer) {
		NL_SET_ERR_MSG(info->extack, "Bearer not found");
		return -EINVAL;
	}

	bearer_disable(net, bearer);

@@ -899,7 +910,8 @@ int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
			prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
	}

	return tipc_enable_bearer(net, bearer, domain, prio, attrs);
	return tipc_enable_bearer(net, bearer, domain, prio, attrs,
				  info->extack);
}

int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
@@ -938,6 +950,7 @@ int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
	b = tipc_bearer_find(net, name);
	if (!b) {
		rtnl_unlock();
		NL_SET_ERR_MSG(info->extack, "Bearer not found");
		return -EINVAL;
	}

@@ -984,8 +997,10 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
	name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);

	b = tipc_bearer_find(net, name);
	if (!b)
	if (!b) {
		NL_SET_ERR_MSG(info->extack, "Bearer not found");
		return -EINVAL;
	}

	if (attrs[TIPC_NLA_BEARER_PROP]) {
		struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
@@ -1004,12 +1019,18 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
		if (props[TIPC_NLA_PROP_WIN])
			b->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
		if (props[TIPC_NLA_PROP_MTU]) {
			if (b->media->type_id != TIPC_MEDIA_TYPE_UDP)
			if (b->media->type_id != TIPC_MEDIA_TYPE_UDP) {
				NL_SET_ERR_MSG(info->extack,
					       "MTU property is unsupported");
				return -EINVAL;
			}
#ifdef CONFIG_TIPC_MEDIA_UDP
			if (tipc_udp_mtu_bad(nla_get_u32
					     (props[TIPC_NLA_PROP_MTU])))
					     (props[TIPC_NLA_PROP_MTU]))) {
				NL_SET_ERR_MSG(info->extack,
					       "MTU value is out-of-range");
				return -EINVAL;
			}
			b->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]);
			tipc_node_apply_property(net, b, TIPC_NLA_PROP_MTU);
#endif
@@ -1137,6 +1158,7 @@ int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
	rtnl_lock();
	media = tipc_media_find(name);
	if (!media) {
		NL_SET_ERR_MSG(info->extack, "Media not found");
		err = -EINVAL;
		goto err_out;
	}
@@ -1173,9 +1195,10 @@ int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
	name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);

	m = tipc_media_find(name);
	if (!m)
	if (!m) {
		NL_SET_ERR_MSG(info->extack, "Media not found");
		return -EINVAL;

	}
	if (attrs[TIPC_NLA_MEDIA_PROP]) {
		struct nlattr *props[TIPC_NLA_PROP_MAX + 1];

@@ -1191,12 +1214,18 @@ int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
		if (props[TIPC_NLA_PROP_WIN])
			m->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
		if (props[TIPC_NLA_PROP_MTU]) {
			if (m->type_id != TIPC_MEDIA_TYPE_UDP)
			if (m->type_id != TIPC_MEDIA_TYPE_UDP) {
				NL_SET_ERR_MSG(info->extack,
					       "MTU property is unsupported");
				return -EINVAL;
			}
#ifdef CONFIG_TIPC_MEDIA_UDP
			if (tipc_udp_mtu_bad(nla_get_u32
					     (props[TIPC_NLA_PROP_MTU])))
					     (props[TIPC_NLA_PROP_MTU]))) {
				NL_SET_ERR_MSG(info->extack,
					       "MTU value is out-of-range");
				return -EINVAL;
			}
			m->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]);
#endif
		}