Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp3151441lqt; Tue, 23 Apr 2024 11:41:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV57q6chn5BFlSXEPotIIRoLNwF66uwUsVcT5ZOlmYCiWDQfoiFIluKYsD+PmqMfFGmEa8Xe7DFO3x3n8RlJbm73hDyb8sv4mBcW/q0lg== X-Google-Smtp-Source: AGHT+IHtM3ryAbqVFNQW3OWcXYiLInZ2URrQ7tLqsI9BkBQB1RaMScomEDKDEVJpKYG6eqJWEyuk X-Received: by 2002:a17:90a:66cb:b0:2ab:8e59:9da9 with SMTP id z11-20020a17090a66cb00b002ab8e599da9mr465028pjl.6.1713897715601; Tue, 23 Apr 2024 11:41:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713897715; cv=pass; d=google.com; s=arc-20160816; b=o4r1p5pE6kNUCSCsrIWLWLHzWk2QuW529HbhJw49GaO7+1c5HYUGGH3LgpAT7/6mtk 5a9ZQvNLbpklj+ihhUIino8iqIoXdeEDKXBvG6kAg30lMZvQ8WYmjo9OlkvbX+2bzQco svqDTioktLdPUbdyWduaxL/hItJLFPFAYMbzOZsxXRgr4SrIaMfjXRWyHm7S8I78Jnad OrC4xn+l9R9ZOmuUw7S3gf0WgBEP30+7LzJWSStkB0kyRj97Nl2dDJj4DiT/Sd7rN0MD d5laMPVCMa5mWFHV6PL1jsBk+VmhLEJ9uV6sKixbf0IulPSYUd5lVc2VyGLMLoVXNdL1 9Ilw== 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=/HiLWdjQaV8hb1O52W4MiOT+NWSrI3hsRhd3S7MooKM=; fh=6vcrOJJ+08EJoFfdny6MrTLg56368hwZUqOAsXDKN/Q=; b=nh94vJtew4lR8lrIznt79+7FhMm0VTJay8q7oYA4ngvYhkBXLGg046qIYL7DOzdtsA /5nd1jMVqNyfktou3k//vP/sJJwnK+84oq2E9fX3XJe4bfF68ubNnArtLjZV7+d/ylr2 cY+D53JIeJfyA+Af8YLVIFbPORSV5a+xlt+90tC5R4AWjDSgInwKqcfDR6YjHe12M9Dz Geqb9d48Ki74qZDE7+oTguuo9ZppsSWJQmEQtAr9mRWPqKhNAzg9Uxp8kWp0HzpMxFJp F1GPK0Dh5efnovMPdNV2pQ5j6cCdSjjeJCqC7/vp8MvAcGV35PewzUmTKcUQZS8on+bU EyRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mLvgix0o; 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-155757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155757-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 mm2-20020a17090b358200b002a2a95988c1si11709321pjb.161.2024.04.23.11.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 11:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155757-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=mLvgix0o; 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-155757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155757-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 B2ED928D07C for ; Tue, 23 Apr 2024 18:36:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB37313FD7C; Tue, 23 Apr 2024 18:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mLvgix0o" Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 3537E13EFE4; Tue, 23 Apr 2024 18:35:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713897304; cv=none; b=oRPBOSkYHLULBikqNIf2mIxPjiAIkSayr4zqm0FV5ZlkDAn2mYwzxtT93nXt8xUB4iQMMk4wRvulbGjqPzrOwLbazNm06A7fOhhFxDhK8S1fGmYqA3x9YkMKWtzVBzSEesYOMQveNoZdCWh7U/MD0MwXHoafNIK7nTsx5I49VPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713897304; c=relaxed/simple; bh=WYvbuboNOGHAGTYL5eAezP0LLrKAAhKuVSJiY613RAw=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: Mime-Version:Content-Type; b=EEputlIAUfDgbTo8PNL5TFJMvNF52VU+XnfvEstw8gU/mixGzXLODxOszLWAHxRVF+cIrwh6cCBzGo7zdfQrByfMEQ09dkOKSWH3hdUn5ckPdvhESz4qwliI4ZfKd8EApbK/hKv+v3aql7TGFISoGSMltsuLZepgLATV0N7TXP8= 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=mLvgix0o; arc=none smtp.client-ip=209.85.219.54 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-f54.google.com with SMTP id 6a1803df08f44-6a06b12027cso1567176d6.0; Tue, 23 Apr 2024 11:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713897301; x=1714502101; 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=/HiLWdjQaV8hb1O52W4MiOT+NWSrI3hsRhd3S7MooKM=; b=mLvgix0oFK/Y4jcA2Vz5ZFEswodnVB1nVzf1NCxJw3pv1QRPryaEPGsmRmThBhv4Z8 24dmD0RkdX4bjC63Mg6vc0dTQZbhXfGdyH8QbgpdGPvbhuW6FpVZhGA48Tygb/CPBGfz fzZbR2rPoENLwSV3EGGjAoqdR2Uerzbcxli5ZfPAE1Q16SLHo200HVR3F4qgDkiVTBPP EZS7M0ooLb+RjwzP5UoIB2umI/ivp825o3soddPzJyBG9c5vrFrE5+slwm9vbedYvJeX MZL9U0zaPbdTlHWHK9p9HnEsLO4FC9KSN72+K/MOQfadIuorq6zzCcQfyfct766iJ15Z 3Lug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713897301; x=1714502101; 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=/HiLWdjQaV8hb1O52W4MiOT+NWSrI3hsRhd3S7MooKM=; b=klifJUKnOksIdMAMl628US+1vyzSRFD3EPx1gAXGaJrg0Vexx6Z0ZrCfs21CQeO8+M kBn5Ujjg2TbiAh1T2cr4p83n3OFMGQrqgZXS0g5e4HP4Glth8uN9xjiK6J+F0hoKgSq1 lXyUnd8iOJFbj2vp2a16m3SvLk1FehZwEeFraluzPMpvtZcBBtQTcjv9SOATQwORj7kV c/tB2rTflUkDBwGSWu+qdanYuYaIRGn1H8EHYnt65K8S5I52KGGCY9aScw1U4V5Wd1Eu KPfB5CBHdpMN6ki10ALh8Juot04TuSpsw8QVZ1pylJtG/oaLK3oCjDMRRlsF2qWdfQ44 FuSw== X-Forwarded-Encrypted: i=1; AJvYcCXtVWH6/8JO3zCRW7ZfRZN2nybUL8J/Sc37JUpn+yxn//QpJDaZb5MVxKJ2jmCPovOwwh3RKGpeQXl+GQwV2ojkFYBAn2Vo+ziW4IFTp6nL7qUU7w37B6SkWH9W X-Gm-Message-State: AOJu0Yz4f0BhYT56+IKHb3JfPshzWz9mGk40Bsb9/w+LQaMOQxSoJpHe qwVriLZDduCF6a+0xh4m06rHoBA5HC33iMLYwGsw8Jfb6rfR+Ipx X-Received: by 2002:a05:6214:e69:b0:6a0:4756:ce99 with SMTP id jz9-20020a0562140e6900b006a04756ce99mr6817134qvb.21.1713897300995; Tue, 23 Apr 2024 11:35:00 -0700 (PDT) Received: from localhost (164.146.150.34.bc.googleusercontent.com. [34.150.146.164]) by smtp.gmail.com with ESMTPSA id o6-20020a0ce406000000b0069b20891f0dsm5377155qvl.30.2024.04.23.11.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 11:35:00 -0700 (PDT) Date: Tue, 23 Apr 2024 14:35:00 -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: <6627ff5432c3a_1759e929467@willemb.c.googlers.com.notmuch> In-Reply-To: <9f097bcafc5bacead23c769df4c3f63a80dcbad5.camel@mediatek.com> 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> <66227ce6c1898_116a9b294be@willemb.c.googlers.com.notmuch> <6622acdd22168_122c5b2945@willemb.c.googlers.com.notmuch> <9f097bcafc5bacead23c769df4c3f63a80dcbad5.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: 7bit > Hi Willem, > As the discussion, is it OK for the patch below? Thanks for iterating on this. I would like the opinion also of the fraglist and UDP GRO experts. Yes, I think both - protecting skb_segment_list against clearly illegal fraglist packets, and - blocking BPF from constructing such packets are worthwhile stable fixes. I believe they should be two separate patches. Both probably with the same Fixes tag: 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining"). > diff --git a/net/core/filter.c b/net/core/filter.c > index 3a6110ea4009..abc6029c8eef 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -1655,6 +1655,11 @@ static DEFINE_PER_CPU(struct bpf_scratchpad, > bpf_sp); > 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 -ENOMEM; > + } > + Indentation looks off, but I agree with the logic. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) && (write_len > skb_headlen(skb))) > return skb_ensure_writable(skb, write_len); > } > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index 73b1e0e53534..2e90534c1a1e 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -4036,9 +4036,11 @@ struct sk_buff *skb_segment_list(struct sk_buff > *skb, > unsigned int tnl_hlen = skb_tnl_header_len(skb); > unsigned int delta_truesize = 0; > unsigned int delta_len = 0; > + unsigned int mss = skb_shinfo(skb)->gso_size; > struct sk_buff *tail = NULL; > struct sk_buff *nskb, *tmp; > int len_diff, err; > + bool err_len = false; > > skb_push(skb, -skb_network_offset(skb) + offset); > > @@ -4047,6 +4049,14 @@ struct sk_buff *skb_segment_list(struct sk_buff > *skb, > if (err) > goto err_linearize; > > + if (mss != GSO_BY_FRAGS && mss != skb_headlen(skb)) { > + if (!list_skb) { > + goto err_linearize; The label no longer truly covers the meaning. But that is already true since the above (second) jump was added in commit c329b261afe7 ("net: prevent skb corruption on frag list segmentation"). Neither needs the kfree_skb_list, as skb->next is not assigned to until the loop. Can just return ERR_PTR(-EFAULT)? > + } else { > + err_len = true; > + } > + } > + Why the branch? Might as well always fail immediately? > skb_shinfo(skb)->frag_list = NULL; > > while (list_skb) { > @@ -4109,6 +4119,9 @@ struct sk_buff *skb_segment_list(struct sk_buff > *skb, > __skb_linearize(skb)) > goto err_linearize; > > + if (err_len) > + goto err_linearize; > + > skb_get(skb); > > return skb; > > > > > > > > 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.