From patchwork Thu Jan 15 00:44:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saladin EL Ouali X-Patchwork-Id: 2184577 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=saladin.su header.i=@saladin.su header.a=rsa-sha256 header.s=saladin2 header.b=QwKz48o5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4dsLkH3sL7z1xtD for ; Thu, 15 Jan 2026 22:44:39 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id EE3D060ED1; Thu, 15 Jan 2026 11:44:37 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id JG4HMgE-hNoo; Thu, 15 Jan 2026 11:44:35 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 88B2F60EC0 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=saladin.su header.i=@saladin.su header.a=rsa-sha256 header.s=saladin2 header.b=QwKz48o5 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 88B2F60EC0; Thu, 15 Jan 2026 11:44:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 618B2C02A6; Thu, 15 Jan 2026 11:44:35 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D8428C02A5 for ; Thu, 15 Jan 2026 11:44:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id BCFBD4024B for ; Thu, 15 Jan 2026 11:44:34 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id t-qiB6ry8rVT for ; Thu, 15 Jan 2026 11:44:34 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a01:4f8:1c1a:51e4::1; helo=mail.saladin.su; envelope-from=me@saladin.su; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org E7EA7401F2 Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=saladin.su DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org E7EA7401F2 Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=saladin.su header.i=@saladin.su header.a=rsa-sha256 header.s=saladin2 header.b=QwKz48o5 Received: from mail.saladin.su (mail.saladin.su [IPv6:2a01:4f8:1c1a:51e4::1]) by smtp2.osuosl.org (Postfix) with ESMTPS id E7EA7401F2 for ; Thu, 15 Jan 2026 11:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=saladin.su; s=saladin2; t=1768477471; bh=DgnqALJI6fctlws5FMHFxGKChkmCpiCbyfzIV/Hk6T4=; h=From:To:Cc:Subject:Date; b=QwKz48o5qHZGGgBupArOileplN05t4p5t8Gk1hLe27pkdexa8YtSuXinlioU7+3kO DmjjUE0ENmmtLhj36I4VYKA1xePm44Hwb9shZRzCeaUafOUppva7IG7lUt5lymyThv 9vzZfGiRXHcIvyNM0/WFKJ/9aK7ht+4AlSSBZc8N1Y8kw12ja56LcKEf7rjASXKKUr 7Y/vv2w6ojFWWqmprZUMG2HJjUtLYLs3WW8FZP/rBXPRjr97pWKAiEKhcg+vnKU8VT gZeqgm/KSyRRz4kdwSpwwNJ1z3jcKXtwSkgg8ajOxlRrK0bESk1DM9u/qX9Gd9vyR+ 0EXzz1Ge7Q/sA== Received: from localhost.localdomain (unknown [IPv6:2a09:bac5:48bf:3032::4cd:12]) by mail.saladin.su (Postfix) with ESMTPSA id 67ADB3FD30; Thu, 15 Jan 2026 11:44:31 +0000 (UTC) From: Saladin EL Ouali To: ovs-dev@openvswitch.org Cc: "salaheddine.elouali@emsi-edu.ma"@lists.linuxfoundation.org, "i.maximets@ovn.org"@lists.linuxfoundation.org Date: Thu, 15 Jan 2026 12:44:30 +0100 Message-ID: <20260115114430.10384-1-me@saladin.su> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH] tun-metadata: Add bounds check for Geneve TLV options X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: saladin0x1 This adds a bounds check in tun_metadata_from_geneve_nlattr() to ensure that attr_len does not exceed the destination buffer size (256 bytes) before performing memcpy(). While the kernel module validates Geneve option lengths before passing data to userspace via netlink, adding redundant validation in userspace provides defense-in-depth. If the kernel were to pass a malformed netlink message (due to a bug or compromise), userspace would previously overflow the tun->metadata.opts.gnv buffer. This was discussed with Ilya Maximets, who noted: "In general, we trust the kernel to give us correct data. If we can't trust the kernel, there is not much we can do. It makes sense to add a check in userspace parsing, but it's not a security concern." The function now returns -EINVAL on overflow and 0 on success, with callers in odp-util.c handling the error appropriately. Signed-off-by: Saladin EL Ouali --- lib/odp-util.c | 6 +++++- lib/tun-metadata.c | 7 ++++++- lib/tun-metadata.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/odp-util.c b/lib/odp-util.c index ee1868202..d87506193 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -3255,7 +3255,11 @@ odp_tun_key_from_attr__(const struct nlattr *attr, bool is_mask, break; } case OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS: - tun_metadata_from_geneve_nlattr(a, is_mask, tun); + if (tun_metadata_from_geneve_nlattr(a, is_mask, tun)) { + odp_parse_error(&rl, errorp, + "Geneve options length exceeds maximum"); + return ODP_FIT_ERROR; + } break; case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS: { const struct erspan_metadata *opts = nl_attr_get(a); diff --git a/lib/tun-metadata.c b/lib/tun-metadata.c index af0bcbde8..1561da35f 100644 --- a/lib/tun-metadata.c +++ b/lib/tun-metadata.c @@ -605,12 +605,15 @@ tun_metadata_del_entry(struct tun_table *map, uint8_t idx) * on the wire. By always using UDPIF format, this allows us to process the * flow key without any knowledge of the mapping table. We can do the * conversion later if necessary. */ -void +int tun_metadata_from_geneve_nlattr(const struct nlattr *attr, bool is_mask, struct flow_tnl *tun) { int attr_len = nl_attr_get_size(attr); + if (attr_len > sizeof(tun->metadata.opts.gnv)) { + return -EINVAL; + } memcpy(tun->metadata.opts.gnv, nl_attr_get(attr), attr_len); tun->flags |= FLOW_TNL_F_UDPIF; @@ -622,6 +625,8 @@ tun_metadata_from_geneve_nlattr(const struct nlattr *attr, bool is_mask, * at the beginning but with additional options after. */ tun->metadata.present.len = 0xff; } + + return 0; } /* Converts from the flat Geneve options representation extracted directly diff --git a/lib/tun-metadata.h b/lib/tun-metadata.h index 67dedae25..affc8c268 100644 --- a/lib/tun-metadata.h +++ b/lib/tun-metadata.h @@ -54,7 +54,7 @@ void tun_metadata_set_match(const struct mf_field *, char **err_str); void tun_metadata_get_fmd(const struct flow_tnl *, struct match *flow_metadata); -void tun_metadata_from_geneve_nlattr(const struct nlattr *attr, bool is_mask, +int tun_metadata_from_geneve_nlattr(const struct nlattr *attr, bool is_mask, struct flow_tnl *tun); void tun_metadata_to_geneve_nlattr(const struct flow_tnl *tun, const struct flow_tnl *flow,