From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 4190B3B6356 for ; Mon, 17 Aug 2026 08:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786956599; cv=none; b=BEB8yvJ0saX/kVNzyHi50zFDhOScOdDrwTAMozzC6PhzSazlrB7rVJjgcsCdipeW3LNXRyXWQogA77QZfUvHBJqAkHauXr605U9BhPpfqCBzPW/TgHJGmcfJfo5QsmVUbIgqU7D2R1bbHJomrp3h9XcGCHs4l/u1vvusGuAxN1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786956599; c=relaxed/simple; bh=as2SDlcdmZszLVLpp6U0wTu9/8GUPviDLNz+v3rqc6U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QC7juJzb12G9R8DjcGP3pXpeIGa/04sda85i1DPMfWBPhllzG3oHw9HT77sivlyM8NSOTl1zAN3tNhyHTHSKVInQMNg7hhCZ0h2DHp6/PDlYspGgh8PzF+s6gyTaKlNswTfgjErwwX6DU7KsTyTyonCBN104KqErBkuttL3ebrI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=BxIpjygb; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="BxIpjygb" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-5218927884fso30880011cf.3 for ; Mon, 17 Aug 2026 01:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1786956597; x=1787561397; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=6lLhWIiCgpmicN480/UwG2uhnEik8ZpJA1z/kNF7n0I=; b=BxIpjygbPBsERGuqYa65TdvDLAtwrPMxEugGngYmCrYOzDhdHE1Mcruipw1JP8Clb5 6liZ75ZtWhzFUW1mHjkiihQnNEb27cQNugUHVO8JoyXEWc6ss20S2LBvGui9TBABY5RB jnUIaSOOswXGOACCJyhSl5I3S5J+xlYzG95UyU2f43Cmp4IAUZdv5dfkWqkL5hoNVQfq XzkDowMZrDNSEczKjPTxgHY2ItLi1/dtrRs16a5hxoVHk2bOF+V9ZOSobX33rH+yIqDL 9RMvyHBHzqrHzNpdW/U0QjOddYLYk5So0WezB5jFW2ED/GMpzLuIDAlxoUQaVnxQx0QU Xw1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786956597; x=1787561397; 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:content-type; bh=6lLhWIiCgpmicN480/UwG2uhnEik8ZpJA1z/kNF7n0I=; b=UpsRrGLsMSGnjADr5W5a7LUuZX8/kSaZNdk1tUv3y0DhGLmgyQ/QWY+mglOXUHzwu9 fh8j6aaMENiepKGcsEZrRRaPRwFrs+BRTEwmejrI7gnxhf/E7n1wQg9/fkmDdhD+82v+ +PLO7RSE9CuY84DiHNHNBWoCv3Jy6M0WsjJDwTUQbHM3GCp0nReolmFvTe7pvhUIDusM EJ+LiB3rQ7Utz9byNaPOMPvVO/dBqpwEcXcERec4I3/RAFhE2pYr0tY5T0GgtiU7T/ov t4z7fSkMIzKtxJALmEQIYIoOx6DtYmzac/eGmw9qlJcYV3ZEDSy7yBaluTWRT3TCqnNS oBvg== X-Forwarded-Encrypted: i=1; AHgh+RrR0CMFxhYCLyg/ry2+hvEcKG3V39ZD267xuYYnrWpbwBQCNtmQDFXJYQYRghhJ5dtMfq5i83aSEBQH1tg=@vger.kernel.org X-Gm-Message-State: AOJu0YzcXCblcC35tTHgyLVAsFaA7Yj3fmTp/uUuMkEQY+IOh9fWA7KY r4IRMAQ+lbqj76Jnu7G3KDGTDQfRYRM+HSiuKsCnBsebcWQ/p49QY6u8eT48tz998vM= X-Gm-Gg: AR+sD11zDHkCSKfsniL3nGQ5wJyivOLj798sQZoH3GL2fhMgAcD4+go3XLkA88Ue4xq VsDLitoXtJhqYPYFVxNhhAcRxR76Qhyz5F5EaAkac16HegfUPIsOecBxhmWE2e3LN6KZyGCvTiL 8suB8U0dPg/HqiAZLIme9i7SMcofIfYRk6eyF7tUascQx1enCdafcCm3iu0DBxueAxinOp+/Muz F3a5IritGHs56KgTeBgBrbyMaHVgcCqrdEU2lXzyT2lHfoWuxlSiKaTXqlPDcDJw5wM0IUlx2Kh 4h4rEl26EBazsuRM1/jD9GW5dCIzScO7V4uFm9cbjuy7XCLfo0rJ8FXRz886E2UaTmuchoEsgpx O9bpPnmTs0VwSPVoxW4kQw6fmMuVcYD0cnX+ybeoXCB7Wm7tjPbMLdinG0jJKeV18D8ebSgsW7G D2XMMbcWTaf+ridGhQmJzIKHfgRog1FxHFXa0DVKMjYX5mikAB9KaDmz0iirsUudYQWxw= X-Received: by 2002:a05:622a:3d4:b0:51b:fb82:67d1 with SMTP id d75a77b69052e-52d8542c8e8mr204942221cf.20.1786956597000; Mon, 17 Aug 2026 01:49:57 -0700 (PDT) Received: from localhost ([146.190.222.192]) by smtp.gmail.com with UTF8SMTPSA id d75a77b69052e-52db60eb85csm9405991cf.4.2026.08.17.01.49.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Aug 2026 01:49:56 -0700 (PDT) From: David Lee To: marek.lindner@mailbox.org, sw@simonwunderlich.de, antonio@mandelbit.com, sven@narfation.org Cc: Kyle Zeng , davem@davemloft.net, linus.luessing@c0d3.blue, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, Dominik 'Disconnect3d' Czarnota , netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, David Lee Subject: [PATCH net v3] batman-adv: reject unrepresentable multicast TVLV offsets Date: Mon, 17 Aug 2026 08:49:54 +0000 Message-ID: <20260817084955.944189-1-david.lee@trailofbits.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kyle Zeng The network and transport header fields in struct sk_buff are 16-bit offsets from skb->head, and U16_MAX is reserved as the unset transport header value. batadv_tvlv_call_handler() sets both fields from a received multicast TVLV without checking whether the TVLV end is representable. If the end offset exceeds the field's range, skb_set_transport_header() truncates it so that the transport header precedes the network header. The negative difference is then returned by skb_network_header_len() as a large u32. batadv_mcast_forw_packet() consequently accepts an oversized multicast tracker and accesses memory beyond the skb data. Add skb_set_transport_header_careful(), an offset-aware counterpart to skb_reset_transport_header_careful(), which validates the final head-relative offset before assigning it. Use the new helper in batadv_tvlv_call_handler() and reject unrepresentable TVLVs before setting the network header. Fixes: 07afe1ba288c ("batman-adv: mcast: implement multicast packet reception and forwarding") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.6-sol Codex:gpt-5.5-cyber Signed-off-by: Kyle Zeng Co-developed-by: David Lee Signed-off-by: David Lee --- Changes in v3: - Rename transport_offset to thoff so the comparisons fit on one line. v2: https://lore.kernel.org/netdev/20260810145754.828936-1-david.lee@trailofbits.com/ Changes in v2: - Add an offset-aware careful transport-header setter and make batman-adv handle its failure, as suggested by Sven Eckelmann. - Restore Kyle Zeng as the patch author and correct the sign-off chain. - Move the research credit below the commit-message separator. v1: https://lore.kernel.org/all/20260731135222.566367-1-david.lee@trailofbits.com/ Bug found and triaged by OpenAI Security Research and validated by Trail of Bits. Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can share if needed. include/linux/skbuff.h | 24 ++++++++++++++++++++++++ net/batman-adv/tvlv.c | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 22eda1d54a0e..ed6a2bc23db5 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3126,6 +3126,30 @@ static inline void skb_set_transport_header(struct sk_buff *skb, skb->transport_header += offset; } +/** + * skb_set_transport_header_careful - conditionally set transport header + * @skb: buffer to alter + * @offset: offset to add to skb->data + * + * Hardened version of skb_set_transport_header(). + * + * Returns: true if the operation was a success. + */ +static inline bool __must_check +skb_set_transport_header_careful(struct sk_buff *skb, const int offset) +{ + long thoff = skb->data - skb->head + offset; + + if (unlikely(thoff != (typeof(skb->transport_header))thoff)) + return false; + + if (unlikely(thoff == (typeof(skb->transport_header))~0U)) + return false; + + skb->transport_header = thoff; + return true; +} + static inline unsigned char *skb_network_header(const struct sk_buff *skb) { return skb->head + skb->network_header; diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c index 1c9fb21985f6..c384db16bcac 100644 --- a/net/batman-adv/tvlv.c +++ b/net/batman-adv/tvlv.c @@ -433,8 +433,11 @@ static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv, return NET_RX_SUCCESS; tvlv_offset = (unsigned char *)tvlv_value - skb->data; + if (!skb_set_transport_header_careful(skb, + tvlv_offset + tvlv_value_len)) + return -EINVAL; + skb_set_network_header(skb, tvlv_offset); - skb_set_transport_header(skb, tvlv_offset + tvlv_value_len); return tvlv_handler->mcast_handler(bat_priv, skb); } -- 2.53.0