Commit 9cf3db3c authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'net-warn-about-attempts-to-register-negative-ifindex'

Jakub Kicinski says:

====================
net: warn about attempts to register negative ifindex

Follow up to the recently posted fix for OvS lacking input
validation:
https://lore.kernel.org/all/20230814203840.2908710-1-kuba@kernel.org/

Warn about negative ifindex more explicitly and misc YNL updates.
====================

Link: https://lore.kernel.org/r/20230814205627.2914583-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents cf74eb5a 7582113c
......@@ -81,6 +81,10 @@ attribute-sets:
name-prefix: ovs-vport-attr-
enum-name: ovs-vport-attr
attributes:
-
name: unspec
type: unused
value: 0
-
name: port-no
type: u32
......@@ -120,6 +124,20 @@ attribute-sets:
operations:
name-prefix: ovs-vport-cmd-
list:
-
name: new
doc: Create a new OVS vport
attribute-set: vport
fixed-header: ovs-header
do:
request:
attributes:
- name
- type
- upcall-pid
- dp-ifindex
- ifindex
- options
-
name: get
doc: Get / dump OVS vport configuration and state
......
......@@ -9589,6 +9589,11 @@ static int dev_index_reserve(struct net *net, u32 ifindex)
{
int err;
if (ifindex > INT_MAX) {
DEBUG_NET_WARN_ON_ONCE(1);
return -EINVAL;
}
if (!ifindex)
err = xa_alloc_cyclic(&net->dev_by_index, &ifindex, NULL,
xa_limit_31b, &net->ifindex, GFP_KERNEL);
......
......@@ -395,7 +395,10 @@ class YnlFamily(SpecFamily):
self.family.genl_family['mcast'][mcast_name])
def _add_attr(self, space, name, value):
try:
attr = self.attr_sets[space][name]
except KeyError:
raise Exception(f"Space '{space}' has no attribute '{name}'")
nl_type = attr.value
if attr["type"] == 'nest':
nl_type |= Netlink.NLA_F_NESTED
......@@ -450,7 +453,10 @@ class YnlFamily(SpecFamily):
attr_space = self.attr_sets[space]
rsp = dict()
for attr in attrs:
try:
attr_spec = attr_space.attrs_by_val[attr.type]
except KeyError:
raise Exception(f"Space '{space}' has no attribute with value '{attr.type}'")
if attr_spec["type"] == 'nest':
subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'])
decoded = subdict
......@@ -479,7 +485,10 @@ class YnlFamily(SpecFamily):
def _decode_extack_path(self, attrs, attr_set, offset, target):
for attr in attrs:
try:
attr_spec = attr_set.attrs_by_val[attr.type]
except KeyError:
raise Exception(f"Space '{attr_set.name}' has no attribute with value '{attr.type}'")
if offset > target:
break
if offset == target:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment