From nobody Sun Feb 8 17:15:53 2026 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2C8C2E8B8D for ; Thu, 4 Dec 2025 10:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764845622; cv=none; b=n4Gb/AeSsvtvkQwa8iEDnPz5PD0KwIDakf4/h9lE5fBJxW8DdQALGSDYTVHorB4Z2b0BQL5fFIrVNW8ZyjWM1WyTtwpFBbL4TmFE9JOwDd/2akhXy9iWzCpszPaEnW9LxlEmkxMtYbkffHfnUfn0uwEC3VI7Jzh46tuZOygJQFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764845622; c=relaxed/simple; bh=16I3nDkcBxbvAtXGuiPo2PT/0oTSTuFMTpI9q6cIE/U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YxGW934UEKdtsijasb3X8Lyd5TNEJZHceVBZDeokK+EJxQccKdbvb23o3yrhoyQFjytKGu0s6JgP12yzp7Hj48MzFO8eXNstJ6TIEwtesJZ5X3CJaDFX+xZU32vbBSqWx4puB1EadrAGXRR9WPnLOoqfPmYCuhUA9E4PayOQ9lk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ovn.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ovn.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f65.google.com with SMTP id a640c23a62f3a-b73875aa527so113317166b.3 for ; Thu, 04 Dec 2025 02:53:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764845618; x=1765450418; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eDQlS2Gh60c2v9LmiNdNdP2rU4QdLL80GBdE/ODSzRY=; b=vMeDqwMP0aAelxEXpnIKPlQC9VTpRBgDBw5jMxRL8AlboXktiF6K03iHO1bo/NnPGC i1Vmb2c9a/3HPus3HzRh5cFB7RQVsl1bPkc1/FAI+hCXQ2RgPl7o4ElZ5+NrLFsf1Fot TWxcUuZg6Xcez9TY186NiIsij/57YH0kL0QdeHcUXyNvcGQ/wGmxNKroxQemPIr+nD63 hyjvcUr/ip1Up9wk4iSGgGnnU9HDcO7BbG66KghDI40tOl3KV5/i1eyKsCpQdGkFtHNN 63RZHibipWRrYbS2XOrEnX6X1aYjdeAPjT/OFwQPLqsNgsXzKDai0w1nSfA5aSJCXczt YZbg== X-Forwarded-Encrypted: i=1; AJvYcCVeYhIkAi3Bb7Ws+vMKyayis9e3u/w0Q3/8Vg9Ff1kiEcJJCHof7d6tq+IFMSxINQ2L3kYQBlqqo97qbsM=@vger.kernel.org X-Gm-Message-State: AOJu0YxbJq3kQoab26a6MicOductCyfrS6ge7I5kdZHEaYi3YCVNCQpV 7xqz5I1WGCK180lSax7xcIw+W9zKQ+4EK1u4aJ7j/5za0WVrhLUrPXDU X-Gm-Gg: ASbGnctAdjrX2tOJ54vbi766ZcLILfTXDb1DKsE/gRqUNVSbala27/m7GMZpDmhYs23 NTPMkbrmSJr8Dqy8i4F1OxeKUphhbB2N2GaQEPMUkoae2kSG38/KYShWt3vIILjYPbRRiZAk1q4 fBCkQiRIafuMi43Yjj3IK18tApampOGdDVzwfAWpB5fF9vNM/QBOMCFSqnFOM2XoyjqcdT4257P Xu/BZqZ42u7TyNOjMLX17N8ZxCgZ0CK54R9VYxNqmmvBvtN5rv/j1q83UMEXV/pCI3wuzomoHMw IGjleU7PZM7Gl8m2omD2iGv8nkCUPoU1QYVPDSnOVHSeMQ/n6JGEp/P1JzD80p/WdqmJXJYuFEF SdFFQ9z2YdT8NKDUQlTF2Bqr0GWRNau6eJynk5AsXiGyK/rHUftHZ4nQGwGAZiVLkoZK+UB1o6U AAsUjqpZstUHgQEmWd3fi1L+h9EMAfGDdEOFcbJjhZgODM X-Google-Smtp-Source: AGHT+IF3aan31pTIo6uyN/oe6VyITLYnu9MjmTjOZ5Uj/0kxgpfK33GFdR3nXh5J1r++CztSiGlWGQ== X-Received: by 2002:a17:907:1c21:b0:b72:91bc:9b35 with SMTP id a640c23a62f3a-b79dc51d9b3mr502026166b.39.1764845617550; Thu, 04 Dec 2025 02:53:37 -0800 (PST) Received: from im-t490s.redhat.com (89-24-32-14.nat.epc.tmcz.cz. [89.24.32.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b79f426413esm111389966b.0.2025.12.04.02.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 02:53:37 -0800 (PST) From: Ilya Maximets To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org, dev@openvswitch.org, Eelco Chaudron , Aaron Conole , Willy Tarreau , LePremierHomme , Junvy Yang , Ilya Maximets Subject: [PATCH net] net: openvswitch: fix middle attribute validation in push_nsh() action Date: Thu, 4 Dec 2025 11:53:32 +0100 Message-ID: <20251204105334.900379-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.51.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The push_nsh() action structure looks like this: OVS_ACTION_ATTR_PUSH_NSH(OVS_KEY_ATTR_NSH(OVS_NSH_KEY_ATTR_BASE,...)) The outermost OVS_ACTION_ATTR_PUSH_NSH attribute is OK'ed by the nla_for_each_nested() inside __ovs_nla_copy_actions(). The innermost OVS_NSH_KEY_ATTR_BASE/MD1/MD2 are OK'ed by the nla_for_each_nested() inside nsh_key_put_from_nlattr(). But nothing checks if the attribute in the middle is OK. We don't even check that this attribute is the OVS_KEY_ATTR_NSH. We just do a double unwrap with a pair of nla_data() calls - first time directly while calling validate_push_nsh() and the second time as part of the nla_for_each_nested() macro, which isn't safe, potentially causing invalid memory access if the size of this attribute is incorrect. The failure may not be noticed during validation due to larger netlink buffer, but cause trouble later during action execution where the buffer is allocated exactly to the size: BUG: KASAN: slab-out-of-bounds in nsh_hdr_from_nlattr+0x1dd/0x6a0 [openvsw= itch] Read of size 184 at addr ffff88816459a634 by task a.out/22624 CPU: 8 UID: 0 PID: 22624 6.18.0-rc7+ #115 PREEMPT(voluntary) Call Trace: dump_stack_lvl+0x51/0x70 print_address_description.constprop.0+0x2c/0x390 kasan_report+0xdd/0x110 kasan_check_range+0x35/0x1b0 __asan_memcpy+0x20/0x60 nsh_hdr_from_nlattr+0x1dd/0x6a0 [openvswitch] push_nsh+0x82/0x120 [openvswitch] do_execute_actions+0x1405/0x2840 [openvswitch] ovs_execute_actions+0xd5/0x3b0 [openvswitch] ovs_packet_cmd_execute+0x949/0xdb0 [openvswitch] genl_family_rcv_msg_doit+0x1d6/0x2b0 genl_family_rcv_msg+0x336/0x580 genl_rcv_msg+0x9f/0x130 netlink_rcv_skb+0x11f/0x370 genl_rcv+0x24/0x40 netlink_unicast+0x73e/0xaa0 netlink_sendmsg+0x744/0xbf0 __sys_sendto+0x3d6/0x450 do_syscall_64+0x79/0x2c0 entry_SYSCALL_64_after_hwframe+0x76/0x7e Let's add some checks that the attribute is properly sized and it's the only one attribute inside the action. Technically, there is no real reason for OVS_KEY_ATTR_NSH to be there, as we know that we're pushing an NSH header already, it just creates extra nesting, but that's how uAPI works today. So, keeping as it is. Fixes: b2d0f5d5dc53 ("openvswitch: enable NSH support") Reported-by: Junvy Yang Signed-off-by: Ilya Maximets Acked-by: Eelco Chaudron echaudro@redhat.com Reviewed-by: Aaron Conole --- net/openvswitch/flow_netlink.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index 1cb4f97335d8..2d536901309e 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -2802,13 +2802,20 @@ static int validate_and_copy_set_tun(const struct n= lattr *attr, return err; } =20 -static bool validate_push_nsh(const struct nlattr *attr, bool log) +static bool validate_push_nsh(const struct nlattr *a, bool log) { + struct nlattr *nsh_key =3D nla_data(a); struct sw_flow_match match; struct sw_flow_key key; =20 + /* There must be one and only one NSH header. */ + if (!nla_ok(nsh_key, nla_len(a)) || + nla_total_size(nla_len(nsh_key)) !=3D nla_len(a) || + nla_type(nsh_key) !=3D OVS_KEY_ATTR_NSH) + return false; + ovs_match_init(&match, &key, true, NULL); - return !nsh_key_put_from_nlattr(attr, &match, false, true, log); + return !nsh_key_put_from_nlattr(nsh_key, &match, false, true, log); } =20 /* Return false if there are any non-masked bits set. @@ -3389,7 +3396,7 @@ static int __ovs_nla_copy_actions(struct net *net, co= nst struct nlattr *attr, return -EINVAL; } mac_proto =3D MAC_PROTO_NONE; - if (!validate_push_nsh(nla_data(a), log)) + if (!validate_push_nsh(a, log)) return -EINVAL; break; =20 --=20 2.51.1