From nobody Tue Apr 7 17:12:35 2026 Received: from mail-dl1-f42.google.com (mail-dl1-f42.google.com [74.125.82.42]) (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 375722F12BB for ; Thu, 26 Feb 2026 09:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772098313; cv=none; b=uG4M75wyvarYxRP7qej7PzRwgG8XJ6ttBawMaA+LTLhdeBDQuvuCaoFskuu6zRSJodtVN7YhO3/v2FxHp4ad9h6+i8XJTjIJhejdu6jzCOP62wtdTYQzKSukTGMHwVdV+9HwPJ2O4HL8aLO5cD5Gci3b2TOBJiMD920wPeTGD68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772098313; c=relaxed/simple; bh=XMrM4+Hj3SghIxgdaOrFD80PkaSmAH1qWcfG8RAykiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dYcDene5VJRaediKws1GkfBEmUWiqCpo7EuFFr59MVaav4NCSzrSOZL1iC8fDyngNS6hZI2TprX54fQ+RrQxMvQXz6opdNZ62cAhSU2BMKgO8IxFlb75/mjSJYMZSp+QmooE4rCVeh1gbigMCeKiDvZn12qhGSfR2NgOsp07Zjg= 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=GCjcbDBh; arc=none smtp.client-ip=74.125.82.42 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.b="GCjcbDBh" Received: by mail-dl1-f42.google.com with SMTP id a92af1059eb24-12732e6a123so165014c88.1 for ; Thu, 26 Feb 2026 01:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772098311; x=1772703111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tec9IvX19mzXZCyeb8uc2mz6TaJdE7CZsee6blSRk3g=; b=GCjcbDBhkNYLlpLHsBCqhIl7sZfJ8iuflzVpx+VT5yx3N0OJL6u7uipNviFbKjAruS 5tcmeAqVkyBWbeaEbnTRDQmkL3VwDWYdsnLi/O7484GMEvOnI9qracTspZIkjT6BOyDR yIs4fdBtSqi+2Dn1AaxPGO0aOGe3dDtR/jX7zExIB1jalXmzxbBxSyUp7adZuYe6PK4k zYYapSw65E/Z/5k3gS9vp9BJ8bD4eCzMNR4u1YpZoufmnsRHrVeJfhooqHDwLwqDkvb5 A9Gz1029sXvaUDQogW2xFlKT0WWfjCBkxgu2mD2ZNYJyXwv2WUPCOrmEAiTGjln4EsIw 9h9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772098311; x=1772703111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Tec9IvX19mzXZCyeb8uc2mz6TaJdE7CZsee6blSRk3g=; b=N9X3jmd1Kvsmto/eEEyBv/DOIwTjBB+hYAOKQHsEG9LjOyRlywWVylg+e8aAqgxsDy /+E18sBsqE5e9rYcY8VGLel044tehGzuYWmJweeu8+eiJSPtWecGf6hghX/1hL+ilB89 dINMG/j9Gm1zXpFBFR41XJ4ps7fUsw66FWGeRD7mt53UAfF9c+adk9UMcHlJMgofRRI3 xCugEM3oWa5z72Dlw8ITfvChX5jAJzKVz2PCaGxnmpri5e3qWd/aRRyUHBP5I8Pzlu6Z yIEOGOZZjt6LaV90KVLCaJQyA3vq7lkKZ2OqLwB6fZkBPjq/rG+DCwIEf6NqISYcDj6G xiYw== X-Forwarded-Encrypted: i=1; AJvYcCUu9lB7auCL/UWl8VE4WdCA+E1bEAX/b5zWu28uE6fxZKpahlUNcgiTLLXPAN0Jxmjgjx75XljA0pl2kbI=@vger.kernel.org X-Gm-Message-State: AOJu0YyV/kBuQ4/l3hjYHstN29L+JwtwTTXaoP8ra395YAFnGIZA/5bG lNzVF3A0+RHVssjiYVoTdnW6XeGoy+cJmg140Ng+mwyjtzASOOZPeKlb X-Gm-Gg: ATEYQzy3Bb9fGmw+Zw33Al2K1ZsZXnYtcsRLgSQXlToyF4oddu5ZPKdh+QKzx/7sG2r KjU3tp3WQVb7MY77RJwJ3KzMg4DyLh28foBXxUlcMQJtOXlESXcgzvJMLjUCq/n9gn7vWM94L6F jLI0a/ta5tihs+9B0BfQOsVQ4jFpn0ge4RnDXB/v1cVQAtdW1jzgF4uDdERJdYazLNj6m13tws4 WtSLo65+7j7XM6oajUEOG6/zLe2uUGQe50nHv0yNLqshbvjSZDV6VxMwXBaRruIhgITk08b21BT H3r3/qN1qKyvrt9Xxo+vLaFmxYeW6S2PoyjRbD7bRrIxM9qqz5HS0FOaywFcmM+079ILJIyzjSu Ew85liOdcXDb+xcQAkKTyazUJ4Ja7tInQ1rLGQrdUwHSX4cA1wgtJeWT9mQJKah9rVJRpLUhHUu dXiVovLpyxmSyScEU4gvhaqQZBOpyZuEaA/f+oSgHSDu8omLzXCW+ay6auRW/FLPjoFchpj2HrY rn0XN1HFG6cDr2CgiTH4OA= X-Received: by 2002:a05:7022:608e:b0:119:e569:fb96 with SMTP id a92af1059eb24-1276acda68bmr9380442c88.5.1772098311330; Thu, 26 Feb 2026 01:31:51 -0800 (PST) Received: from localhost.localdomain (108-214-96-168.lightspeed.sntcca.sbcglobal.net. [108.214.96.168]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a43c12sm1771904c88.14.2026.02.26.01.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 01:31:50 -0800 (PST) From: Sun Jian To: Andrii Nakryiko , Shuah Khan Cc: Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sun Jian Subject: [PATCH v2 1/2] selftests/bpf: probe_user: filter by pid to avoid cross-test interference Date: Thu, 26 Feb 2026 17:31:31 +0800 Message-ID: <20260226093132.437206-2-sun.jian.kdev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260226093132.437206-1-sun.jian.kdev@gmail.com> References: <20260226093132.437206-1-sun.jian.kdev@gmail.com> 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" The test installs a kprobe on __sys_connect and checks that bpf_probe_write_user() can modify the syscall argument. However, any concurrent thread in any other test that calls connect() will also trigger the kprobe and have its sockaddr silently overwritten, causing flaky failures in unrelated tests. Constrain the hook to the current test process by filtering on a PID stored as a global variable in .bss. Initialize the .bss value from user space before bpf_object__load() using bpf_map__set_initial_value(), and validate the bss map value size to catch layout mismatches. No new map is introduced and the test keeps the existing non-skeleton flow. Signed-off-by: Sun Jian Acked-by: Mykyta Yatsenko --- .../selftests/bpf/prog_tests/probe_user.c | 27 ++++++++++++++++++- .../selftests/bpf/progs/test_probe_user.c | 13 +++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/probe_user.c b/tools/te= sting/selftests/bpf/prog_tests/probe_user.c index 8721671321de..280dcdb5ddef 100644 --- a/tools/testing/selftests/bpf/prog_tests/probe_user.c +++ b/tools/testing/selftests/bpf/prog_tests/probe_user.c @@ -20,6 +20,11 @@ void serial_test_probe_user(void) struct bpf_program *kprobe_progs[prog_count]; struct bpf_object *obj; static const int zero =3D 0; + struct test_pro_bss { + struct sockaddr_in old; + __u32 test_pid; + }; + struct test_pro_bss results =3D {}; size_t i; =20 obj =3D bpf_object__open_file(obj_file, &opts); @@ -34,6 +39,24 @@ void serial_test_probe_user(void) goto cleanup; } =20 + { + struct bpf_map *bss_map; + struct test_pro_bss bss_init =3D {}; + + bss_init.test_pid =3D getpid(); + bss_map =3D bpf_object__find_map_by_name(obj, "test_pro.bss"); + if (CHECK(!bss_map, "find_bss_map", "no bss map\n")) + goto cleanup; + if (CHECK(bpf_map__value_size(bss_map) !=3D sizeof(bss_init), + "bss_size", "bss value_size %u !=3D %zu\n", + bpf_map__value_size(bss_map), sizeof(bss_init))) + goto cleanup; + err =3D bpf_map__set_initial_value(bss_map, &bss_init, + sizeof(bss_init)); + if (CHECK(err, "set_bss_init", "err %d\n", err)) + goto cleanup; + } + err =3D bpf_object__load(obj); if (CHECK(err, "obj_load", "err %d\n", err)) goto cleanup; @@ -62,11 +85,13 @@ void serial_test_probe_user(void) connect(sock_fd, &curr, sizeof(curr)); close(sock_fd); =20 - err =3D bpf_map_lookup_elem(results_map_fd, &zero, &tmp); + err =3D bpf_map_lookup_elem(results_map_fd, &zero, &results); if (CHECK(err, "get_kprobe_res", "failed to get kprobe res: %d\n", err)) goto cleanup; =20 + memcpy(&tmp, &results.old, sizeof(tmp)); + in =3D (struct sockaddr_in *)&tmp; if (CHECK(memcmp(&tmp, &orig, sizeof(orig)), "check_kprobe_res", "wrong kprobe res from probe read: %s:%u\n", diff --git a/tools/testing/selftests/bpf/progs/test_probe_user.c b/tools/te= sting/selftests/bpf/progs/test_probe_user.c index a8e501af9604..4bc86c7654b1 100644 --- a/tools/testing/selftests/bpf/progs/test_probe_user.c +++ b/tools/testing/selftests/bpf/progs/test_probe_user.c @@ -5,13 +5,22 @@ #include #include "bpf_misc.h" =20 -static struct sockaddr_in old; +struct test_pro_bss { + struct sockaddr_in old; + __u32 test_pid; +}; + +struct test_pro_bss bss; =20 static int handle_sys_connect_common(struct sockaddr_in *uservaddr) { struct sockaddr_in new; + __u32 cur =3D bpf_get_current_pid_tgid() >> 32; + + if (bss.test_pid && cur !=3D bss.test_pid) + return 0; =20 - bpf_probe_read_user(&old, sizeof(old), uservaddr); + bpf_probe_read_user(&bss.old, sizeof(bss.old), uservaddr); __builtin_memset(&new, 0xab, sizeof(new)); bpf_probe_write_user(uservaddr, &new, sizeof(new)); =20 --=20 2.43.0