From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83D7435F5E3 for ; Thu, 23 Apr 2026 08:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776933961; cv=none; b=aXbi7CEq06S32eP1EuvQ+TXt/5605TJRiDmKVpUaFAqntBqWF2oCP3I1eitSdSOpBaa3YaycUjIHjns6OX9xOvdUMLN2rcEdTyjAL119HK/bKLAEbRkxxrneGGOsdtBXQcAhCZGCCr9+/r7KHFpFudPaSin28snQ/7AXHLZJUfA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776933961; c=relaxed/simple; bh=Hl3hSmH93Bqev331kDF8KjK2ERB5SGQ0m/HhaWWR8Dk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EMQiliDnu5KV9Gu90yBF27r1w1ErOOUMSCXmF04iifwf8+0Rl82F3+J6j2lBfiU/HqFe5CL30Xb2sHL7+rmtWVN3FjN9XPq3T/NBz228DQEJVlycH3ZSlwq8fXRg1ote96ZSXfTO/ReOdAKp41vLENgOzvH/3xC38PhRcT+9j8c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Thd0PYsi; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=sZ9HH/wA; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Thd0PYsi"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="sZ9HH/wA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776933957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m1tx9VCvrtYdimdcJctan93WIkq+ToiKW1leQ49VU+c=; b=Thd0PYsimBEJ8EqaJHjolDMenuGCP1Yv1mJhqjU1nySIZEwfdSjBn2KIv5BsbpXEPkvhKt Z55pP1KfNOQjvAJH8Z01ck0V72WVTP5YsDxwKNwGlwSaF/VI4iXtFsjOVEPnAZHNPi0bND YST1azrCoHk1cFbLYcnVRsftj5SFMcc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-aCTBgLKjONKtnlJkrp0wVw-1; Thu, 23 Apr 2026 04:45:56 -0400 X-MC-Unique: aCTBgLKjONKtnlJkrp0wVw-1 X-Mimecast-MFC-AGG-ID: aCTBgLKjONKtnlJkrp0wVw_1776933955 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48a5fb71a84so2615895e9.1 for ; Thu, 23 Apr 2026 01:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776933955; x=1777538755; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=m1tx9VCvrtYdimdcJctan93WIkq+ToiKW1leQ49VU+c=; b=sZ9HH/wAcgcTmgicHZx/TiQ/fpCYPkwMgGLhXiGmLy5EB/aYPprRomWi6GddpyWGO9 qfW7+++yS5qubn9KUsZLqZiUPNqqJJlcRSB//dt2gBlE329Q5InOr3ve2lptCymWAMdv tfUbQYUZYu+oLZGx6XDykpFdmkZFoRbUx4wE+BOAPByIoMMwpxF+6HPnq/K0wTZJhhgf ctAA+YqTCPiJqOhEB4K6NuQ2WpShISR5ZUQL4cKi+3AReH/vkWDd9IBwiKpuOnuVNuFl hRsbpFZGVFBxqjHAVI0GVl4IMOVIqhJFD6jJ6OXnXscfkmg5iIKb7WRhovyl7nXmt77i SoeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776933955; x=1777538755; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m1tx9VCvrtYdimdcJctan93WIkq+ToiKW1leQ49VU+c=; b=F2Dj4LWoM5FkuFSc+13IHmnexuLxcEJSWfw/ljfvsyFqP4qCoEQPL/kqeb+SVOkEta HwKVqTHTjMvveyg2EKpRbGfKez5xe7J4LnevaTN3S1mr+3ZHyeqBrcPLnrP2Cpiw2O6f Mwgw7upzfbMn8ZzyKhtWvzLN0oKjEK05DhXqF7+BU1Sn6pdNGyZz6jO5wXV0qS8sW8GH piTRRju2qbQd/UF/nKLOucIfiKdJY/XkDVCsV2tOTz/XAzx9FunE6gtugk9G1HOi3w2i R+14NqkGa0JfzLf7IjVgvt41g1yx7kBn0gtGTke2RgZXbpFNExj7JY7wwNsQD30vY56G S7ww== X-Forwarded-Encrypted: i=1; AFNElJ9hrOZ5sqgp1le/bCSmHNIPGMXIV+3LwivT7FOT0sHmVOSql6bw5CMFqxyCg51pLzElwZ+0aAof2eLhIiE=@vger.kernel.org X-Gm-Message-State: AOJu0YzlU7KOtNesPzRJqUP4kDPB08jhqKdKH3f+smMMNOTEiaCKgaM8 T84xLgh3Ood0p0sRo2Bt3qINXMwx0Zuvrc9A78od1oTmZcFz1uvxqyYJihH5lWV0AxJOkxZfqWJ 8xxdnSb6WbS6H2fb93J166yWwQvClRbYetmEW3hzHX+TTk08kSmH02N6vnAqEWrJq+g== X-Gm-Gg: AeBDiesYqzLktybB9smRYwlg1qKEXL5uKbc42G8uaXo/pIIoivmaxFELd1iXUOiZDtp zW44gnzk/Tm/a2bKHvaSH9wX1aLfObW8gNkHsHn3BnwvERStmBDbg3TQh+cOP2iuSQVEAzbJIO5 xL5SYQ5uC0vWzDa4DeMEFZ1h4Gqa218WoFW4WUfH/1FNIX2ZB6ETnoz+EkBlQF4oIkv/HxUSXds UVY98exmZpoDY0YMuts3efTstFXdLIQl96Ev6YL18VMwcI3lB3Avn7/FvjYy7B1CP/Hawq36L5j Vn50uX5cXPbxLvueM/3HdToxcL4lBqL4ixukbKjkdxopVI6eCU8PeRCNKQMnhVayJQr2tnMR6Bn 1eUdFXvOhLkmmYdBfE79E/HOidhl0baq10n1lu70NzcStyHdBDYfrnK36/9PWLj1O2is= X-Received: by 2002:a05:600c:1d05:b0:489:1baf:8c03 with SMTP id 5b1f17b1804b1-4891baf8d2cmr221491325e9.11.1776933954942; Thu, 23 Apr 2026 01:45:54 -0700 (PDT) X-Received: by 2002:a05:600c:1d05:b0:489:1baf:8c03 with SMTP id 5b1f17b1804b1-4891baf8d2cmr221490965e9.11.1776933954462; Thu, 23 Apr 2026 01:45:54 -0700 (PDT) Received: from [192.168.88.32] ([150.228.93.216]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a55dc9f58sm415049885e9.6.2026.04.23.01.45.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Apr 2026 01:45:53 -0700 (PDT) Message-ID: <01e90b44-88c8-4e29-86db-b9258d8271b2@redhat.com> Date: Thu, 23 Apr 2026 10:45:52 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] ipv6: validate extension header length before copying to cmsg To: Qi Tang , davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, horms@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260419150344.624673-1-tpluszz77@gmail.com> Content-Language: en-US From: Paolo Abeni In-Reply-To: <20260419150344.624673-1-tpluszz77@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/19/26 5:03 PM, Qi Tang wrote: > ip6_datagram_recv_specific_ctl() builds IPV6_{HOPOPTS,DSTOPTS,RTHDR} > cmsgs (and their IPV6_2292* legacy counterparts) by trusting the > on-wire hdrlen byte (ptr[1]) when computing the put_cmsg() length. > The length was validated only at parse time (ipv6_parse_hopopts(), > etc.). An nftables payload-write expression can rewrite hdrlen after > parsing and before the skb reaches recvmsg; the write itself is > in-bounds but put_cmsg() then reads up to ((hdrlen+1) << 3) = 2040 > bytes from an 8-byte header. nftables is reachable from an unprivi- > leged user namespace, so this is an unprivileged slab-out-of-bounds > read: > > BUG: KASAN: slab-out-of-bounds in put_cmsg+0x3ac/0x540 > put_cmsg+0x3ac/0x540 > udpv6_recvmsg+0xca0/0x1250 > sock_recvmsg+0xdf/0x190 > ____sys_recvmsg+0x1b1/0x620 > > Clamp each cmsg length against skb_tail_pointer(skb) before calling > put_cmsg(). Extension headers are kept in the linear skb area by > pskb_may_pull() during input, so skb_tail_pointer() is the correct > bound. The check is replicated at each call site (one HbH, four > RFC2292 sites, and four switch cases in the DSTOPTS/RTHDR/AH walk) > rather than hoisted out of the switch, to keep the fix minimal and > backportable; a follow-up cleanup can factor it out. In the walk > loop a failed check also aborts the walk, since subsequent offsets > depend on the tampered length. > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Signed-off-by: Qi Tang > --- > net/ipv6/datagram.c | 35 ++++++++++++++++++++++++++++++----- > 1 file changed, 30 insertions(+), 5 deletions(-) > > diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c > index ca3605acb..a7b9f5a24 100644 > --- a/net/ipv6/datagram.c > +++ b/net/ipv6/datagram.c > @@ -643,7 +643,10 @@ void ip6_datagram_recv_specific_ctl(struct sock *sk, struct msghdr *msg, > /* HbH is allowed only once */ > if (np->rxopt.bits.hopopts && (opt->flags & IP6SKB_HOPBYHOP)) { > u8 *ptr = nh + sizeof(struct ipv6hdr); > - put_cmsg(msg, SOL_IPV6, IPV6_HOPOPTS, (ptr[1]+1)<<3, ptr); > + u16 hbhlen = (ptr[1] + 1) << 3; > + > + if (ptr + hbhlen <= skb_tail_pointer(skb)) > + put_cmsg(msg, SOL_IPV6, IPV6_HOPOPTS, hbhlen, ptr); The patch looks functionally correct to me, but the above 3 statements are repeated multiple times. You can put them in a local helper and avoud a lot of duplicate code. > } > > if (opt->lastopt && > @@ -668,27 +671,37 @@ void ip6_datagram_recv_specific_ctl(struct sock *sk, struct msghdr *msg, > case IPPROTO_DSTOPTS: > nexthdr = ptr[0]; > len = (ptr[1] + 1) << 3; > + if (ptr + len > skb_tail_pointer(skb)) > + goto ext_hdr_done; The packet is corrupted, allowing processing of later rxopt requires the IMHO not nice empty label. I think it would be better just returning from this function. /P