diff mbox series

[net-next,v1] vlan: skip nested type that is not IFLA_VLAN_QOS_MAPPING

Message ID 20240117153810.1197794-1-linma@zju.edu.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1] vlan: skip nested type that is not IFLA_VLAN_QOS_MAPPING | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1092 this patch: 1092
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1107 this patch: 1107
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1107 this patch: 1107
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-01-18--03-00 (tests: 403)

Commit Message

Lin Ma Jan. 17, 2024, 3:38 p.m. UTC
In the vlan_changelink function, a loop is used to parse the nested
attributes IFLA_VLAN_EGRESS_QOS and IFLA_VLAN_INGRESS_QOS in order to
obtain the struct ifla_vlan_qos_mapping. These two nested attributes are
checked in the vlan_validate_qos_map function, which calls
nla_validate_nested_deprecated with the vlan_map_policy.

However, this deprecated validator applies a LIBERAL strictness, allowing
the presence of an attribute with the type IFLA_VLAN_QOS_UNSPEC.
Consequently, the loop in vlan_changelink may parse an attribute of type
IFLA_VLAN_QOS_UNSPEC and believe it carries a payload of
struct ifla_vlan_qos_mapping, which is not necessarily true.

To address this issue and ensure compatibility, this patch introduces two
type checks that skip attributes whose type is not IFLA_VLAN_QOS_MAPPING.

Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
 net/8021q/vlan_netlink.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Paolo Abeni Jan. 18, 2024, 12:19 p.m. UTC | #1
On Wed, 2024-01-17 at 23:38 +0800, Lin Ma wrote:
> In the vlan_changelink function, a loop is used to parse the nested
> attributes IFLA_VLAN_EGRESS_QOS and IFLA_VLAN_INGRESS_QOS in order to
> obtain the struct ifla_vlan_qos_mapping. These two nested attributes are
> checked in the vlan_validate_qos_map function, which calls
> nla_validate_nested_deprecated with the vlan_map_policy.
> 
> However, this deprecated validator applies a LIBERAL strictness, allowing
> the presence of an attribute with the type IFLA_VLAN_QOS_UNSPEC.
> Consequently, the loop in vlan_changelink may parse an attribute of type
> IFLA_VLAN_QOS_UNSPEC and believe it carries a payload of
> struct ifla_vlan_qos_mapping, which is not necessarily true.
> 
> To address this issue and ensure compatibility, this patch introduces two
> type checks that skip attributes whose type is not IFLA_VLAN_QOS_MAPPING.
> 
> Signed-off-by: Lin Ma <linma@zju.edu.cn>

Why are you targeting net-next? this looks like a fix suitable for
'net' - with a proper fixes tag.

Cheers,

Paolo
Lin Ma Jan. 18, 2024, 12:57 p.m. UTC | #2
Hello Paolo,

> 
> On Wed, 2024-01-17 at 23:38 +0800, Lin Ma wrote:
> > In the vlan_changelink function, a loop is used to parse the nested
> > attributes IFLA_VLAN_EGRESS_QOS and IFLA_VLAN_INGRESS_QOS in order to
> > obtain the struct ifla_vlan_qos_mapping. These two nested attributes are
> > checked in the vlan_validate_qos_map function, which calls
> > nla_validate_nested_deprecated with the vlan_map_policy.
> > 
> > However, this deprecated validator applies a LIBERAL strictness, allowing
> > the presence of an attribute with the type IFLA_VLAN_QOS_UNSPEC.
> > Consequently, the loop in vlan_changelink may parse an attribute of type
> > IFLA_VLAN_QOS_UNSPEC and believe it carries a payload of
> > struct ifla_vlan_qos_mapping, which is not necessarily true.
> > 
> > To address this issue and ensure compatibility, this patch introduces two
> > type checks that skip attributes whose type is not IFLA_VLAN_QOS_MAPPING.
> > 
> > Signed-off-by: Lin Ma <linma@zju.edu.cn>
> 
> Why are you targeting net-next? this looks like a fix suitable for
> 'net' - with a proper fixes tag.
> 

Thanks for your suggestions, sometimes I just mistakenly do the opposite of what I intended to. 

I will send version two with the right tag.

> Cheers,
> 
> Paolo

Thanks
Lin
diff mbox series

Patch

diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index 214532173536..a3b68243fd4b 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -118,12 +118,16 @@  static int vlan_changelink(struct net_device *dev, struct nlattr *tb[],
 	}
 	if (data[IFLA_VLAN_INGRESS_QOS]) {
 		nla_for_each_nested(attr, data[IFLA_VLAN_INGRESS_QOS], rem) {
+			if (nla_type(attr) != IFLA_VLAN_QOS_MAPPING)
+				continue;
 			m = nla_data(attr);
 			vlan_dev_set_ingress_priority(dev, m->to, m->from);
 		}
 	}
 	if (data[IFLA_VLAN_EGRESS_QOS]) {
 		nla_for_each_nested(attr, data[IFLA_VLAN_EGRESS_QOS], rem) {
+			if (nla_type(attr) != IFLA_VLAN_QOS_MAPPING)
+				continue;
 			m = nla_data(attr);
 			err = vlan_dev_set_egress_priority(dev, m->from, m->to);
 			if (err)