From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796193250; b=LtTRz7tXGCail1qSVNabXUPfzeEncdRDqJMOLN4eqOd5fvE9I+Dax7vhXpzP4LWXnrKW 7GkW6VGDi2u89hxCs9Y8bLeJlKWBntWndrMi6DqZobTFFKKs7yO9Wj07J4A9nChPnXqbi en8P449LOGr2hCJeYKWPcFCb38ZDniYOlCsRSCrShgaiCqZT0JphZoYFPVKFMUp3+DL0j oZwRnXsEv9lBjRUWZst4Xwfw2qe7/ER04KzzoYlZd+bW6SiHqUHTX5M1iFlv5Z3F5N15I YlyaErI8xbYybnhzzY4Ty7Hxc/e+nJ+iydaYIgcYsIb6Swh0SuwH4b22+WVz0uoF9+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796193250; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=JlQm0Dr+YXRn1KbKs+r1UyunqY89HviJtmKhg3pRFX0=; b=TY8vgiY+bhzwjt8l3O9EJi9i9ehRhAdIA2+WUDab9FCQwbitvJSjGSUw7VR9M2nnGJYp nbP6AnP7lPjx0mfiXqQf/wWbQEHKFDwkEK1vAGJEVqHcpC8Y3+9C9WM+O/+FWnQhtD7Cs 5JS0/849OddEdDB+XjXu/T0Nl8Wba8ePXCmSAw/eUBUymzzh2M3tRC3nN+DNrjnj+qaTE eNcR1LdZiSGt09vZgz/R0Og52Yr9yUDVfsLJlo7I7VEbxN5mU1q/OV0nhcYxsM1QnlW+f UZl6MUxQQPyNHloVUAubLe4uZkIp7P3YKKMgQ3NLl3Bdwgvn1w6TEAeQZKtWqcIVbCA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=R5AzM3rK; arc=none smtp.remote-ip=209.85.128.172 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADC3F606A31A for ; Wed, 2 Dec 2026 06:34:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ADC3F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=R5AzM3rK Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-8b30cbfa628so93845907b3.0 for ; Tue, 01 Dec 2026 22:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796193249; x=1796798049; 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=JlQm0Dr+YXRn1KbKs+r1UyunqY89HviJtmKhg3pRFX0=; b=R5AzM3rK0A3yF9NG3bNtUEfBqxMrGBF8rZyQY0/WxRS6vqyneMouZkcj++9k146iuT f1m+nbxTxJxTaXhImAbUi208cx3NFq0DLBIOvlRpCCosLVbzAlELf4v/VZlwWj2yyrXC tSq8uYJjygQDq5MKgGdyBTuSgcPToCu1h+PsmBO+ixe7WchDn+tw7RnMYL+V45CwMQxE GpSBM+JMDFtoBeU+8dq/JCStm4/cLMknGJvU8WRSCeyG6wX1iyn4E0Jt8pXkAiqemmdD j3qDm/Ic37rAQEikPsZQXLlzt2/pEIJ1qwq0nY/xSHJy2Ht6symJV58rbXNjyZbKZFuh qLLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796193249; x=1796798049; 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=JlQm0Dr+YXRn1KbKs+r1UyunqY89HviJtmKhg3pRFX0=; b=KQ1W/7dpHj2TSa2VJanymdGC4vZVqR81R+PgJgHXWTY75canYIN+hCxGXsYUn7eMuE QA1WxlL/57pAHAiRf3C/UggbYMYtcpsIASEDdL+okc0AwdkGOvCfotdsP0JFXeKcp46m L9chXgKC1oBSMWT+9MZT/lNd3PWkjMd4cir4K5u1w3F5atpEy8HWwOAY5aGr36IN4Fvh GOajtQawwSD9SX81rLKLd89fAx1oAqZx+tZENXfICFsJcvTAOCWqA3+sMQe5PA47DcVo vTbUtwkJU6By8J2g/qJOpkNSn3qFRvijydGVmjDsdTWYldLbmnRmaXLJ9y0ej/9IMF4B d0Vg== X-Gm-Message-State: APuU4Z+yp08C7b1v83GKMMnQIM4n3qRu5n7wYoFQqTkCsixfAhQoG9VM mafaBoEXZh5HhsTaZRAJSUIOdwrIClxbghLinzepuIRQPX6v3HzaAL9z X-Gm-Gg: AZFdTZds3Q13IWPYV6uNzjl2P35A+HaSAO6uAuf/pEza+VS/xUkykyJdn6UnUVETokn vK5+U6cMVuw8gBxFVSRLBi3WpnnOH8hfB85jkVr2ts/s5Ve71TZfrvUM9twgv5BurOCx0fPkCgR K2zOWUz1boyAwCTC0MGKs93SslEzV8JIXQ7IU3bqxbMp8CyCBuyKuRNBOTQG46VMCT2u/nJrwgY sOf1+ri9gshgIopdTJfhtPfoLr8NholdmEmTsI7fQLp6pnST0AVOhlREqqh7uhOMDEyfbWxBNwU yYNvusV89uYv24Oi/PCxnI4mKfN0uGqi3d6IQMX103UK2Bc8hEFzH+ulNykczOvh1xprZtCBOsL 010LVHntMVWXbTmqFjINXXpEdkV31y7cDIMDTaX+uuM4KnbmcU+FSCzkDQfQoKSFPfbFmFcXX2o 0nplNpQ+4wDT00IYk+hQnkPhk1qTzw3I1CWqg8dkdjTpMI0RSvrFXs5KCT4ha3ZpByimGhP5IOR pC0eGrFnIgZdSCmy0UBOuppTCQS7VAlBnfWkQQfMnOPcwM1JW57D1XgXbuH/OIsZ51ApjNK90Se De79qbJlfSa1xjh6gL3HdImu4SMOOp9VHtsCeDXOY7Gf+cnfVscztA== X-Received: by 2002:a05:690c:6307:b0:8b3:ade4:a30e with SMTP id 00721157ae682-8b5203294c9mr182366237b3.2.1796193248805; Tue, 01 Dec 2026 22:34:08 -0800 (PST) Received: from VPN-158-165.vpn.usf.edu ([2607:fe50:0:f802::4046]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b52028c80dsm156468697b3.13.2026.12.01.22.34.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 22:34:07 -0800 (PST) From: Juan Agustin Niccolini To: Andrea Mayer , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: netdev@vger.kernel.org, Simon Horman , Hangbin Liu , Gabriel Goller , David Ahern , Julien Massonneau Subject: [PATCH net v2] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read Date: Wed, 2 Dec 2026 01:34:04 -0500 Message-ID: <20261202063404.6809-1-juanagusnicco@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit get_and_validate_srh() relies on ipv6_find_hdr() and IP6_FH_F_SKIP_RH to ignore a routing header whose segments_left is 0. ipv6_find_hdr() reads the field where the packet data is, which can be a page fragment. seg6_get_srh() then pulls the header into the linear area, and nothing checks the field in that copy. A sender that can still write to the fragment, as with an AF_PACKET TX ring, can change the field from 1 to 0 between the two reads. advance_nextseg() then decrements it to 255 and copies srh->segments[255] into the IPv6 destination address, an out-of-bounds read 4088 bytes past the start of the SRH: BUG: KASAN: slab-out-of-bounds in advance_nextseg+0x2a7/0x2b0 Read of size 16 at addr ff110000128e9030 by task seg6_sl_race/289 An unprivileged user can trigger this from a user and network namespace, with a seg6local End route and a TX ring on loopback. The 16 bytes are returned in the ICMPv6 error sent for the new destination address: a kernel heap memory disclosure. get_and_validate_srh() used to check the pulled header. Commit fbbc5bc2ab8c ("seg6: ignore routing header with segments left equal to 0") replaced that check with the lookup flag. Fix this by checking segments_left in the pulled header again. The other SRH fields are already validated there, by seg6_validate_srh(). A header that the lookup skips is still skipped, so a packet with a second SRH is handled as before. Fixes: fbbc5bc2ab8c ("seg6: ignore routing header with segments left equal to 0") Cc: stable@vger.kernel.org Reviewed-by: Gabriel Goller Signed-off-by: Juan Agustin Niccolini --- v2: - add a comment above the check (Gabriel Goller) - say that the other SRH fields are validated in the pulled header (question from Hangbin Liu) - add Gabriel's Reviewed-by tag v1: https://lore.kernel.org/netdev/20261130031647.45247-1-juanagusnicco@gmail.com/ Reproducer: github.com/AgusNicco/seg6local-oob-read/blob/main/seg6_sl_race.c The code is unchanged since v1, which was tested on mainline f4585067150b (same seg6_local.c as net) with KASAN: the reproducer gets the report above on 100 of 100 runs as an unprivileged user, and on none of 20 with the patch, with about 300,000 frames sent in each of those runs. The repository above also has the full KASAN report. net/ipv6/seg6_local.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index 82207da08dfd..27157a4456b5 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -235,6 +235,13 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb) if (!srh) return NULL; + /* IP6_FH_F_SKIP_RH makes ipv6_find_hdr() check segments_left in place, + * possibly in a page fragment that the sender can still write to. + * Check it again now that the SRH is in the linear area. + */ + if (srh->segments_left == 0) + return NULL; + #ifdef CONFIG_IPV6_SEG6_HMAC if (!seg6_hmac_validate_skb(skb, srh)) return NULL; -- 2.53.0