From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) (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 95353385514 for ; Sun, 5 Apr 2026 23:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775433270; cv=none; b=NUkK7DaKV81pmwNSgbakB6dSaLT3xxMQiKEJ6JyHFahj6g9RV8mDg7bKMIyH3hA/N70hFtbEkbGy1Tk267WJcg5GNNTGKR8RhSfBNz4lWdEYqTTjxgDaC1I+YxPoFgRNVEDhwpC8boxedelpEKcLNFsUdsRM1RBgYJy5vM6yt4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775433270; c=relaxed/simple; bh=nnE0n3Olzcs3ikXxyvwZtpvMfL9A+g+9v/5VhawH40A=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=o+y+80SnG1EDo0qtYWoNbPmQKdkBJxqmzuxLNX6rqlnKMS6rRkN9giTiM4zUOSI7zstT/Jgca05v7YDqNvaGpm+YbpJtdz7EYtOiCPyrJqgnXGXUz5TVL0msLH0aaZdxa/ovrbK0oufVZp8VFWwPbvue3fcOls26bravWQbGbvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b=U9LzxMCU; arc=none smtp.client-ip=209.85.210.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b="U9LzxMCU" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-82c20b9fb15so1438028b3a.3 for ; Sun, 05 Apr 2026 16:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20251104.gappssmtp.com; s=20251104; t=1775433269; x=1776038069; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Qw6TUPdhywhOpcOC9GSGOxp4/imbBV1U3y0bPk5X3cQ=; b=U9LzxMCUK5K16ZcZB7U0D/DbvcJEUt1UxaY93bJCFmc3iRVYJ+FerNMjAxWiw7DRSU ixfH2HkFIPPFgqcwUVoIeVO6TaJBq/kBmiV6EyZ5HitJ5aGRX9E9JZ1HaqBxgvT/ivU9 S2gcXAB2C5zoHL0JB34zljHilBxfR7jLGBuK9Ujb6av7289FABXjAK/A3CW0p2WLHrP5 9xvwsQaYOs59XYlcWAxuHEu4h85CdpblfYVRAk+6LDiZBzmpI0FrWEdG1IVOGVAYL2l2 gOeeTUt1nsIkp4sJPOfjVMyjqGlbV/I0cj55M3muht3lhR+/8OnF792NfoiFFPW00Bqw Yh1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775433269; x=1776038069; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Qw6TUPdhywhOpcOC9GSGOxp4/imbBV1U3y0bPk5X3cQ=; b=VIsX1qgNDSZuT2ET5f4zX05cLXEBBQZJeXJfYwQtH8YO4VVhKybUeVgzLYad0I3iGt jPXW+0t+8DXJADeiwajSHpIj5Ry5ja1Qfen366ARjF2aFo0SoevLAbjevbx18HIoc94C 7OLHM5v5cDNB/Xf5RGc9wpMfZiiRjxC/KXYopAosqLH3iY33IddDO2ubDXMNlGq3EZWZ +3LwJEwMWx60chT5CTEk2cimTVGfGaupvrsY63A9uU8IVxqn/CfQManW3twQ8suTPM65 ZUUBmnJDxaWV2/pFcWvB8lF9G7LREKYH02rxnFNnx9kvv+C72YdI2l3+QtujH4KyJS62 G/Gw== X-Forwarded-Encrypted: i=1; AJvYcCVT9yIGsOqNpAYHBVasiO1H3XzosvkNkAC0bq3rgw19E+lOG//huPMllWt+NC/NCrlQlmyxP4i20JaMCcA=@vger.kernel.org X-Gm-Message-State: AOJu0YxfhR4NmQHL16L9YqTxKZjBFNNI91xqzntdZKqiyPycvOsJnb6a ZSbKpXraqyVIgLABCdiMkfbDA56vkU79Vg0vdtPr1KZj9Gz3gYLNWXofYnyHqk5v9ME= X-Gm-Gg: AeBDievd9IBSyktA5CGYmqat6s7fOKzjx/kxsnEn7OIBftAcW4mKkCb18qb4OnqxRIT MCmTlp28KnYPeYYYgt7wgYBfGL82+1EjMNuYs9U8I30rczPp0OumUtZqAiWSc2C06tPgSmsNFRk 6aYHpyTanwrMA9i3B+R81eaOEw/92kzshxqjt9xcocduCOp1myuLjgS/KWcXDSi/gMS0utCSDeq HfGUXcgkoANIQ0Mrt3fba7X63+W+83xdY+RffWWoHw0T28hEl7y4vJSQwJxECZlF/rtNGTer01c jlUhJJWkQeEbXtFVyQk4xLJC20vJeHx7+puI5xj9g2FgGzO+hTY11bIv8yx8XY1bGCf5I8dYpAD 018H26MCi5Gzo6jSW2v13OuoNJeNxkNAOztapRXJupLWC8+lcXzwq3rwpJ/UFzFcUYWi/roKmtO QmEuUUli4= X-Received: by 2002:a05:6a20:7f8d:b0:39b:f026:6f79 with SMTP id adf61e73a8af0-39f2f0f86e1mr9364005637.21.1775433268959; Sun, 05 Apr 2026 16:54:28 -0700 (PDT) Received: from localhost ([2604:3d08:487d:cd00::5517]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c76c6561fe9sm10324516a12.15.2026.04.05.16.54.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 Apr 2026 16:54:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sun, 05 Apr 2026 19:54:27 -0400 Message-Id: Cc: "Quan Sun" <2022090917019@std.uestc.edu.cn>, "Yinhao Hu" , "Kaiyan Mei" , "Dongliang Mu" , "Martin KaFai Lau" , "Daniel Borkmann" , "John Fastabend" , "Stanislav Fomichev" , "Alexei Starovoitov" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , "Shuah Khan" , , , Subject: Re: [PATCH bpf v1 1/2] bpf: Fix SOCK_OPS_GET_SK same-register OOB read in sock_ops From: "Emil Tsalapatis" To: "Emil Tsalapatis" , "Jiayuan Chen" , X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260404141010.247536-1-jiayuan.chen@linux.dev> In-Reply-To: On Sun Apr 5, 2026 at 7:49 PM EDT, Emil Tsalapatis wrote: > On Sat Apr 4, 2026 at 10:09 AM EDT, Jiayuan Chen wrote: >> When a BPF sock_ops program reads ctx->sk with dst_reg =3D=3D src_reg >> (e.g., r1 =3D *(u64 *)(r1 + offsetof(sk))), the SOCK_OPS_GET_SK() macro >> fails to zero the destination register in the is_fullsock =3D=3D 0 path. >> >> The macro saves/restores a temporary register and checks is_fullsock. >> When is_fullsock =3D=3D 0 (e.g., TCP_NEW_SYN_RECV state with a request_s= ock), >> it should set dst_reg =3D 0 (NULL) so the verifier's PTR_TO_SOCKET_OR_NU= LL >> type is correct at runtime. Instead, dst_reg retains the original ctx >> pointer, which passes subsequent NULL checks and can be used as a bogus >> socket pointer, leading to stack-out-of-bounds access in helpers like >> bpf_skc_to_tcp6_sock(). >> >> Fix by: >> - Changing JMP_A(1) to JMP_A(2) in the fullsock path to skip the >> added instruction. >> - Adding BPF_MOV64_IMM(si->dst_reg, 0) after the temp register >> restore in the !fullsock path, placed after the restore because >> dst_reg =3D=3D src_reg means we need src_reg intact to read ctx->temp= . >> >> Fixes: 84f44df664e9 ("bpf: sock_ops sk access may stomp registers when d= st_reg =3D src_reg") >> Reported-by: Quan Sun <2022090917019@std.uestc.edu.cn> >> Reported-by: Yinhao Hu >> Reported-by: Kaiyan Mei >> Reported-by: Dongliang Mu >> Closes: https://lore.kernel.org/bpf/6fe1243e-149b-4d3b-99c7-fcc9e2f75787= @std.uestc.edu.cn/T/#u >> Signed-off-by: Jiayuan Chen > > This patch only seems to fix the problem when dst_reg =3D=3D src_reg. > Why is this not an issue when is_fullsock =3D=3D 0, but dst_reg !=3D src_= reg? > In that case the dst_reg is unmodified by the whole macro but is still > marked as PTR_TO_SOCKET_OR_NULL. Isn't that a problem? Can you add > a test case for is_fullsock =3D=3D 0 but dst_reg !=3D src_reg in patch 2? Sorry for the double post, but also check sashiko.dev: SOSK_OPTS_GET_FIELD seems to have the same issue as the SOCK_OPTS_GET_SK. Can you add the same fix to it? > >> --- >> Apologies for the Easter timing! >> --- >> net/core/filter.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/net/core/filter.c b/net/core/filter.c >> index 78b548158fb05..8fee00e6adef4 100644 >> --- a/net/core/filter.c >> +++ b/net/core/filter.c >> @@ -10618,10 +10618,11 @@ static u32 sock_ops_convert_ctx_access(enum bp= f_access_type type, >> si->dst_reg, si->src_reg, \ >> offsetof(struct bpf_sock_ops_kern, sk));\ >> if (si->dst_reg =3D=3D si->src_reg) { \ >> - *insn++ =3D BPF_JMP_A(1); \ >> + *insn++ =3D BPF_JMP_A(2); \ >> *insn++ =3D BPF_LDX_MEM(BPF_DW, reg, si->src_reg, \ >> offsetof(struct bpf_sock_ops_kern, \ >> temp)); \ >> + *insn++ =3D BPF_MOV64_IMM(si->dst_reg, 0); \ >> } \ >> } while (0) >> =20