Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp673884lqt; Fri, 19 Apr 2024 07:18:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWMrIANzatIlJTvv5uujErkdQBZ1TyDL24huXolEXeiwThJRUE0jy8lLUO2rEn0AeRBudgqEZ4A3BcNG70JhX0UAlW34ibgxSPQ4S5SA== X-Google-Smtp-Source: AGHT+IFX4zymMZP0CUxJdTMBGYWt+kb4zeEYpXxwr9PY/dI4kWcCMklvHo+gXJ3ZyeJSSRV6mxkT X-Received: by 2002:a92:c241:0:b0:36a:f9e8:5e7d with SMTP id k1-20020a92c241000000b0036af9e85e7dmr2747771ilo.7.1713536309006; Fri, 19 Apr 2024 07:18:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713536308; cv=pass; d=google.com; s=arc-20160816; b=gIjsNpjyBJspXcon9WZ9W4wGdkPsNQct+5KBEX/wlMjBw1U6Wy/4BOSrDRiqCtYAsi lZUoce40X4M6a1UrWKj9ghBEAzk+OGvDt06lydevMQnxE1wOUDCkXHiql8WCeBk/gzHC J/Dnl/krfUa056h21JAOtcX3Mg/d/iUUtXy7Wno6hRGOq/70PwS7WUQKxFtY8B8J/OL4 D7OK7ioNGRUuh/mCdO9pXRUk12CCHVmuIWsTPTY7AsPO/hJGE7e1fBcxKOpTM8uHwSMR TxB9n7LMOBJPE/Z4fzHnkjfoRYiCASqIxz0gjEuqo2uU5BVjX36GoqJMVw4Bhi3dmeZL aHwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:references:in-reply-to :message-id:cc:to:from:date:dkim-signature; bh=JTXvfmS2qR6Ir1vYAUrlQKPmC+TTAVl7HcrdLRbgBYI=; fh=Pq7PkhvtTWjQW8r5M4yPdjBUF2ITnJUZWpr7d7deaSs=; b=RjKho2JKAfVwZ7mBANWj0x4yZOX45inKU/pUW99WO3jCatj9vfjesyhFsI7ObH44/V KWqiI8hLQqXC0v7Smz5hZ0kmFR0w0IG7Ymc3dLO5IOrlBAkNoLo5dQ8dDnIMnW8qLlY9 L+qlPS5YNmNPa04GvqwOhrVTGqKIei37uAPhULLyPhJZs1uMAdcik/4RRtAkUX9LEhI9 MzqubyNip0xZYdgLxPbc7y/o+iOc6FuksCsbzq9yVYY4Y/2JlbneurXpTLcHR7PlafMr SC1IZkPCisHKMZc2/V/kY9BYNloIyBNX3XbEXK1qEMnRELe1M2o2g7uAdk4wOFHNcC2i RrIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="eQmE/Xnr"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-151569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m22-20020a63ed56000000b005dbe38b2cfdsi3391084pgk.494.2024.04.19.07.18.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 07:18:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="eQmE/Xnr"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-151569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3BC53282221 for ; Fri, 19 Apr 2024 14:17:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E987D12DDB8; Fri, 19 Apr 2024 14:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eQmE/Xnr" Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 534538562A; Fri, 19 Apr 2024 14:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713536233; cv=none; b=CCZTdqF6TnKSS8sRBI+OltMzyNti5AeIxgiIBeCjKDhAyouXzhtdJqRO1z6V0ZeFkM6PQM9dQNUA5jkLC55tkOcH1/Xli9OceyckVYmmmD9oWGYp3AbG8G1uFMIF18Ob02NQoeoOTG+hBSahMKZO1RpxEbpQg6lHa4JIH+VNMBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713536233; c=relaxed/simple; bh=sJIqAxmp0MkI+0Rle3MPmTH/t6Q5u46iHaETUAfB5/s=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: Mime-Version:Content-Type; b=i0Aq+kqtGSMsQQvifAry/wx7crMlfqgjYft8DPRW8tSuW6H1nEgZtzxrtCP0HxYKRznNvr/FAfV/tBpUX0BbwEpYu34FF9tbiI/tp9zS4et5zdOrIAs91YW8y4hP2gi6j6vJx35dP/0cJCsirsN2TztpD2xxyW6VSKmq+bgDoVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eQmE/Xnr; arc=none smtp.client-ip=209.85.219.47 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 Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-69b5ece41dfso9001766d6.2; Fri, 19 Apr 2024 07:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713536231; x=1714141031; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=JTXvfmS2qR6Ir1vYAUrlQKPmC+TTAVl7HcrdLRbgBYI=; b=eQmE/XnrZcdmKG/rhobsYJFoDvWrig/PI9QMKAbqhQjCnbkyssQyWoOswTqqcjZTcy nLLBdQu5XOEbflyQyCwn6dMcY4MisIzGcGG05iVGpDB2EpnjJq0Ct6SAgAuybW9ze5Uv gC4GGMbM1omHLZZMq9ozxAt2nVW8og71xowM2fy4ljTMc3Wt0r3Lxzf1ZRO9QiyTYXSn gbn4ojz8mtxqh04GXzJRrxWSZuiKKlhse3/TtCseDO9iFTSjZxMKP58a478zG1yDIX/m +jt6eUZ/KRQLg5hiVeg3HhA4Cwolxqb6l0FU8T3QL/aHqzyvsLb0CuoGHd1fmaTII+aH /sdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713536231; x=1714141031; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=JTXvfmS2qR6Ir1vYAUrlQKPmC+TTAVl7HcrdLRbgBYI=; b=g/Y4g5j0VgmUmfBuSAVtH86nOtkOJ+IR73jBPE6ABFhHGyz/mS+OnyujeKz3WE4vx/ PkcPFYifY8tsAg2vCaoTNCpvxo9rDBFEXxRioi4RkDlUw9FdTcffvL4mJfAorKyJdNUy oYibhUZFR6zSdLiS3C+41nYAJPDQ3J1eW6t5My2azlMIAYTSgy/W5s1fN0sf1NnKRF9B aFX+C7gVNQuolcrTpQYyvU0viPSDvjup7BISfkluyLtBqBoDpo4YTLEg9IOtu9kHKNOO YLuQPdmN+nrT/2J08fndAvgNzAbPPaNIxZcrhKUjVX9ejTB+hhNpX1nuqfY0bwKo3+CQ QEmw== X-Forwarded-Encrypted: i=1; AJvYcCXsIW0aJZ4ELlRJxqbN5hvVmGUyRy7CK18OiKFVEN78sYNtPvtQmiPnpIU1bLRXOR0JwAxWKfbZoks7A37nb6FCssQLyz+Bm0qHKOay9iy6UYC1/AfQd3pdiz+p X-Gm-Message-State: AOJu0Yxnxhp4sFJK7doVTe55ll1kzfa3uKcX8RLaxn9OIZxgv0h/Lp0H v4n9DjD6rVBlVUeuNMag6Aq23uQ5ScmJd+4HkmhXhi7wKCaqhyAlkiIvhg== X-Received: by 2002:ad4:538c:0:b0:69b:fb9:9a75 with SMTP id i12-20020ad4538c000000b0069b0fb99a75mr1677835qvv.49.1713536231400; Fri, 19 Apr 2024 07:17:11 -0700 (PDT) Received: from localhost (73.84.86.34.bc.googleusercontent.com. [34.86.84.73]) by smtp.gmail.com with ESMTPSA id b17-20020a0cc991000000b006a0488c5cd1sm1568268qvk.83.2024.04.19.07.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 07:17:11 -0700 (PDT) Date: Fri, 19 Apr 2024 10:17:10 -0400 From: Willem de Bruijn To: =?UTF-8?B?TGVuYSBXYW5nICjnjovlqJwp?= , "maze@google.com" , "willemdebruijn.kernel@gmail.com" Cc: "linux-kernel@vger.kernel.org" , "bpf@vger.kernel.org" , "steffen.klassert@secunet.com" , "kuba@kernel.org" , =?UTF-8?B?U2hpbWluZyBDaGVuZyAo5oiQ6K+X5piOKQ==?= , "pabeni@redhat.com" , "edumazet@google.com" , "netdev@vger.kernel.org" , "matthias.bgg@gmail.com" , "davem@davemloft.net" , yan@cloudflare.com Message-ID: <66227ce6c1898_116a9b294be@willemb.c.googlers.com.notmuch> In-Reply-To: References: <20240415150103.23316-1-shiming.cheng@mediatek.com> <661d93b4e3ec3_3010129482@willemb.c.googlers.com.notmuch> <65e3e88a53d466cf5bad04e5c7bc3f1648b82fd7.camel@mediatek.com> <661eb25eeb09e_6672129490@willemb.c.googlers.com.notmuch> <661f066060ab4_7a39f2945d@willemb.c.googlers.com.notmuch> <77068ef60212e71b270281b2ccd86c8c28ee6be3.camel@mediatek.com> <662027965bdb1_c8647294b3@willemb.c.googlers.com.notmuch> <11395231f8be21718f89981ffe3703da3f829742.camel@mediatek.com> Subject: Re: [PATCH net] udp: fix segmentation crash for GRO packet without fraglist Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Lena Wang (=E7=8E=8B=E5=A8=9C) wrote: > On Wed, 2024-04-17 at 21:15 -0700, Maciej =C5=BBenczykowski wrote: > > = > > External email : Please do not click links or open attachments until > > you have verified the sender or the content. > > On Wed, Apr 17, 2024 at 7:53=E2=80=AFPM Lena Wang (=E7=8E=8B=E5=A8=9C= ) < > > Lena.Wang@mediatek.com> wrote: > > > > > > On Wed, 2024-04-17 at 15:48 -0400, Willem de Bruijn wrote: > > > > > > > > External email : Please do not click links or open attachments > > until > > > > you have verified the sender or the content. > > > > Lena Wang (=E7=8E=8B=E5=A8=9C) wrote: > > > > > On Tue, 2024-04-16 at 19:14 -0400, Willem de Bruijn wrote: > > > > > > > > > > > > External email : Please do not click links or open > > attachments > > > > until > > > > > > you have verified the sender or the content. > > > > > > > > > > Personally, I think bpf_skb_pull_data() should have > > > > > > automatically > > > > > > > > > > (ie. in kernel code) reduced how much it pulls so > > that it > > > > > > would pull > > > > > > > > > > headers only, > > > > > > > > > > > > > > > > > > That would be a helper that parses headers to discover > > > > header > > > > > > length. > > > > > > > > > > > > > > > > Does it actually need to? Presumably the bpf pull > > function > > > > could > > > > > > > > notice that it is > > > > > > > > a packet flagged as being of type X (UDP GSO FRAGLIST) > > and > > > > reduce > > > > > > the pull > > > > > > > > accordingly so that it doesn't pull anything from the > > non- > > > > linear > > > > > > > > fraglist portion??? > > > > > > > > > > > > > > > > I know only the generic overview of what udp gso is, not > > any > > > > > > details, so I am > > > > > > > > assuming here that there's some sort of guarantee to how > > > > these > > > > > > packets > > > > > > > > are structured... But I imagine there must be or we > > wouldn't > > > > be > > > > > > hitting these > > > > > > > > issues deeper in the stack? > > > > > > > > > > > > > > Perhaps for a packet of this type we're already guaranteed > > the > > > > > > headers > > > > > > > are in the linear portion, > > > > > > > and the pull should simply be ignored? > > > > > > > > > > > > > > > > > > > > > > > > Parsing is better left to the BPF program. > > > > > > > > > > > > I do prefer adding sanity checks to the BPF helpers, over > > having > > > > to > > > > > > add then in the net hot path only to protect against > > dangerous > > > > BPF > > > > > > programs. > > > > > > > > > > > Is it OK to ignore or decrease pull length for udp gro fraglist= > > > > packet? > > > > > It could save the normal packet and sent to user correctly. > > > > > > > > > > In common/net/core/filter.c > > > > > static inline int __bpf_try_make_writable(struct sk_buff *skb, > > > > > unsigned int write_len) > > > > > { > > > > > +if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type & > > > > > +(SKB_GSO_UDP |SKB_GSO_UDP_L4)) { > > > > > > > > The issue is not with SKB_GSO_UDP_L4, but with SKB_GSO_FRAGLIST. > > > > > > > Current in kernel just UDP uses SKB_GSO_FRAGLIST to do GRO. In > > > udp_offload.c udp4_gro_complete gso_type adds "SKB_GSO_FRAGLIST| > > > SKB_GSO_UDP_L4". Here checking these two flags is to limit the > > packet > > > as "UDP + need GSO + fraglist". > > > > > > We could remove SKB_GSO_UDP_L4 check for more packet that may > > addrive > > > skb_segment_list. > > > > > > > > +return 0; > > > > > > > > Failing for any pull is a bit excessive. And would kill a sane > > > > workaround of pulling only as many bytes as needed. > > > > > > > > > + or if (write_len > skb_headlen(skb)) > > > > > +write_len =3D skb_headlen(skb); > > > > > > > > Truncating requests would be a surprising change of behavior > > > > for this function. > > > > > > > > Failing for a pull > skb_headlen is arguably reasonable, as > > > > the alternative is that we let it go through but have to drop > > > > the now malformed packets on segmentation. > > > > > > > > > > > Is it OK as below? > > > > > > In common/net/core/filter.c > > > static inline int __bpf_try_make_writable(struct sk_buff *skb, > > > unsigned int write_len) > > > { > > > + if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type & > > > + SKB_GSO_FRAGLIST) && (write_len > > > skb_headlen(skb))) { > > > + return 0; > > = > > please limit write_len to skb_headlen() instead of just returning 0 > > = > = > Hi Maze & Willem, > Maze's advice is: > In common/net/core/filter.c > static inline int __bpf_try_make_writable(struct sk_buff *skb, > unsigned int write_len) > { = > + if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type & > + SKB_GSO_FRAGLIST) && (write_len > skb_headlen(skb))) { > + write_len =3D skb_headlen(skb); > + } > return skb_ensure_writable(skb, write_len); > } > = > Willem's advice is to "Failing for a pull > skb_headlen is arguably = > reasonable...". It prefers to return 0 : > + if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type & > + SKB_GSO_FRAGLIST) && (write_len > skb_headlen(skb))) { > + return 0; > + } > = > It seems a bit conflict. However I am not sure if my understanding is > right and hope to get your further guide. I did not mean to return 0. But to fail a request that would pull an unsafe amount. The caller must get a clear error signal. Back to the original report: the issue should already have been fixed by commit 876e8ca83667 ("net: fix NULL pointer in skb_segment_list"). But that commit is in the kernel for which you report the error. Turns out that the crash is not in skb_segment_list, but later in __udpv4_gso_segment_list_csum. Which unconditionally dereferences udp_hdr(seg). The above fix also mentions skb pull as the culprit, but does not include a BPF program. If this can be reached in other ways, then we do need a stronger test in skb_segment_list, as you propose. I don't want to narrowly check whether udp_hdr is safe. Essentially, an SKB_GSO_FRAGLIST skb layout cannot be trusted at all if even one byte would get pulled.=