 net: openvswitch: reject negative ifindex · gregkh/linux@881faff · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 686 Star 644 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit 881faff Browse files Browse files kuba-moo authored and gregkh committed net: openvswitch: reject negative ifindex [ Upstream commit a552bfa ] Recent changes in net-next (commit 759ab1e ("net: store netdevs in an xarray")) refactored the handling of pre-assigned ifindexes and let syzbot surface a latent problem in ovs. ovs does not validate ifindex, making it possible to create netdev ports with negative ifindex values. It's easy to repro with YNL: $ ./cli.py --spec netlink/specs/ovs_datapath.yaml \ --do new \ --json '{"upcall-pid": 1, "name":"my-dp"}' $ ./cli.py --spec netlink/specs/ovs_vport.yaml \ --do new \ --json '{"upcall-pid": "00000001", "name": "some-port0", "dp-ifindex":3,"ifindex":4294901760,"type":2}' $ ip link show -65536: some-port0: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 7a:48:21:ad:0b:fb brd ff:ff:ff:ff:ff:ff ... Validate the inputs. Now the second command correctly returns: $ ./cli.py --spec netlink/specs/ovs_vport.yaml \ --do new \ --json '{"upcall-pid": "00000001", "name": "some-port0", "dp-ifindex":3,"ifindex":4294901760,"type":2}' lib.ynl.NlError: Netlink error: Numerical result out of range nl_len = 108 (92) nl_flags = 0x300 nl_type = 2 error: -34 extack: {'msg': 'integer out of range', 'unknown': [[type:4 len:36] b'\x0c\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x03\x00\xff\xff\xff\x7f\x00\x00\x00\x00\x08\x00\x01\x00\x08\x00\x00\x00'], 'bad-attr': '.ifindex'} Accept 0 since it used to be silently ignored. Fixes: 54c4ef3 ("openvswitch: allow specifying ifindex of new interfaces") Reported-by: syzbot+7456b5dcf65111553320@syzkaller.appspotmail.com Reviewed-by: Leon Romanovsky &lt;leonro@nvidia.com&gt; Reviewed-by: Aaron Conole &lt;aconole@redhat.com&gt; Link: https://lore.kernel.org/r/20230814203840.2908710-1-kuba@kernel.org Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt; Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent 1ac3729 commit 881faff Copy full SHA for 881faff 1 file changed + 4 - 4 Lines changed: 4 additions &amp; 4 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options net/openvswitch datapath.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ net/openvswitch/datapath.c ‎ Copy file name to clipboard Expand all lines: net/openvswitch/datapath.c + 4 - 4 Lines changed: 4 additions &amp; 4 deletions Original file line number Diff line number Diff line change @@ -1829,7 +1829,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) 1829 1829 parms . port_no = OVSP_LOCAL ; 1830 1830 parms . upcall_portids = a [ OVS_DP_ATTR_UPCALL_PID ]; 1831 1831 parms . desired_ifindex = a [ OVS_DP_ATTR_IFINDEX ] 1832 - ? nla_get_u32 ( a [ OVS_DP_ATTR_IFINDEX ]) : 0 ; 1832 + ? nla_get_s32 ( a [ OVS_DP_ATTR_IFINDEX ]) : 0 ; 1833 1833 1834 1834 /* So far only local changes have been made, now need the lock. */ 1835 1835 ovs_lock (); @@ -2049,7 +2049,7 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { 2049 2049 [ OVS_DP_ATTR_USER_FEATURES ] = { . type = NLA_U32 }, 2050 2050 [ OVS_DP_ATTR_MASKS_CACHE_SIZE ] = NLA_POLICY_RANGE ( NLA_U32 , 0 , 2051 2051 PCPU_MIN_UNIT_SIZE / sizeof ( struct mask_cache_entry )), 2052 - [ OVS_DP_ATTR_IFINDEX ] = {. type = NLA_U32 } , 2052 + [ OVS_DP_ATTR_IFINDEX ] = NLA_POLICY_MIN ( NLA_S32 , 0 ) , 2053 2053 }; 2054 2054 2055 2055 static const struct genl_small_ops dp_datapath_genl_ops [] = { @@ -2302,7 +2302,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) 2302 2302 parms . port_no = port_no ; 2303 2303 parms . upcall_portids = a [ OVS_VPORT_ATTR_UPCALL_PID ]; 2304 2304 parms . desired_ifindex = a [ OVS_VPORT_ATTR_IFINDEX ] 2305 - ? nla_get_u32 ( a [ OVS_VPORT_ATTR_IFINDEX ]) : 0 ; 2305 + ? nla_get_s32 ( a [ OVS_VPORT_ATTR_IFINDEX ]) : 0 ; 2306 2306 2307 2307 vport = new_vport ( &amp; parms ); 2308 2308 err = PTR_ERR ( vport ); @@ -2539,7 +2539,7 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { 2539 2539 [ OVS_VPORT_ATTR_TYPE ] = { . type = NLA_U32 }, 2540 2540 [ OVS_VPORT_ATTR_UPCALL_PID ] = { . type = NLA_UNSPEC }, 2541 2541 [ OVS_VPORT_ATTR_OPTIONS ] = { . type = NLA_NESTED }, 2542 - [ OVS_VPORT_ATTR_IFINDEX ] = { . type = NLA_U32 } , 2542 + [ OVS_VPORT_ATTR_IFINDEX ] = NLA_POLICY_MIN ( NLA_S32 , 0 ) , 2543 2543 [ OVS_VPORT_ATTR_NETNSID ] = { . type = NLA_S32 }, 2544 2544 [ OVS_VPORT_ATTR_UPCALL_STATS ] = { . type = NLA_NESTED }, 2545 2545 }; 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 