Commit 29ed76fd authored by Geliang Tang's avatar Geliang Tang
Browse files

mptcp: set error messages for set_flags

mainline inclusion
from mainline-v6.9-rc1
commit a4d68b160240815d7ca2f935ba690df33a525dd9
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VYQ9
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=a4d68b160240815d7ca2f935ba690df33a525dd9



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

In addition to returning the error value, this patch also sets an error
messages with GENL_SET_ERR_MSG or NL_SET_ERR_MSG_ATTR both for pm_netlink.c
and pm_userspace.c. It will help the userspace to identify the issue.

Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-3-c436ba5e569b@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJackie Liu <liuyun01@kylinos.cn>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
parent 3e2e3a5a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -2025,9 +2025,11 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)

	if (addr.addr.family == AF_UNSPEC) {
		lookup_by_id = 1;
		if (!addr.addr.id)
		if (!addr.addr.id) {
			GENL_SET_ERR_MSG(info, "missing required inputs");
			return -EOPNOTSUPP;
		}
	}

	if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
		bkup = 1;
@@ -2036,11 +2038,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
	entry = __lookup_addr(pernet, &addr.addr, lookup_by_id);
	if (!entry) {
		spin_unlock_bh(&pernet->lock);
		GENL_SET_ERR_MSG(info, "address not found");
		return -EINVAL;
	}
	if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
	    (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
		spin_unlock_bh(&pernet->lock);
		GENL_SET_ERR_MSG(info, "invalid addr flags");
		return -EINVAL;
	}

+7 −2
Original line number Diff line number Diff line
@@ -562,13 +562,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
	token_val = nla_get_u32(token);

	msk = mptcp_token_get_sock(net, token_val);
	if (!msk)
	if (!msk) {
		NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
		return ret;
	}

	sk = (struct sock *)msk;

	if (!mptcp_pm_is_userspace(msk))
	if (!mptcp_pm_is_userspace(msk)) {
		GENL_SET_ERR_MSG(info, "userspace PM not selected");
		goto set_flags_err;
	}

	ret = mptcp_pm_parse_entry(attr, info, false, &loc);
	if (ret < 0)
@@ -582,6 +586,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)

	if (loc.addr.family == AF_UNSPEC ||
	    rem.addr.family == AF_UNSPEC) {
		GENL_SET_ERR_MSG(info, "invalid address families");
		ret = -EINVAL;
		goto set_flags_err;
	}