From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 AF7DF40B6EC for ; Thu, 26 Feb 2026 15:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772119093; cv=none; b=s0IS8N5yklXgdHhR7oJlcJ87eL4MEEoIfDppBAVt0q+tKww6Ld7j06++LcMNbtkfgSOYOevD6vc71DDJIfEg4NKrhbGy3qtPzP3L717uqOvaDBYnY2RnGks8HA8rG/w39d0tEGj/vhVQeQKfwWZiq7YWv/pIeSJSw+2bNMy9oKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772119093; c=relaxed/simple; bh=UtOhj8tACoqtlw1hMQBUUKvYaf1dX1kM+5j0nTLO5r4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=a3JWHOoqx2wQi+OGN+OQ52AEyDV+VoBy2jKdeiE9Ol6ih135RLeCXzBtMXok1VXz5qVu5W9AqZoXJvo/7Ewfjztri+OT3Y35y265tsGXYTq9owz6Qqb8VWo6BIBawa9x/EV+h9AsuMBHvFW75vOzTJC6k+wDQnXiwAD+Y6zUWhI= 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=JuXU6Kbl; arc=none smtp.client-ip=209.85.128.41 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="JuXU6Kbl" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-48379a42f76so8126935e9.0 for ; Thu, 26 Feb 2026 07:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772119090; x=1772723890; darn=vger.kernel.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=hXMv97b9KNqAU0cNnpTqpEvgdSSxZvM5f/4DMEg70Dk=; b=JuXU6Kbl6tU+d/b4+DTt1+J3xPCTEDSaGo5UBHdD+R/fWLWO9+G9Yzxn3q7owIdON/ uNKFykF/JfkFiAf/VJsoKH04vdwVQZAO0HlLQ60bQZPI1Wa5wHGQ0Wji7LkOOZIxnW0+ YEvKPJt/dZjAKPitMpvkmBxL93y+RJr6MbJv9XFa/K0usHYpphbGm4dCaO//ful6R4sg GsSHHncBsSztba1jRNOUTI9DP9y0pb63uHBRhVrXCcEUuzXziT/jNaGV18wKx/EB9oiY Q65VBPCjJ9G6pv+tyyvcw7QJeZ0tUGI4Nrf+YOTZ0GrKBYLtiOo3R4bftG+bN+PsEnH9 v53g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772119090; x=1772723890; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hXMv97b9KNqAU0cNnpTqpEvgdSSxZvM5f/4DMEg70Dk=; b=xCWJRKjnwSt0rznGEmKWgq1Y89fdoqD1QkXQ9r8u35ffiLf78he5rAt+FeyDNJTovC d+bL3u1k3JpswqpQCSr6jgBAAMOJkCDf3E9zOogtLaqYkPRpo8PObWLcoyYNVyo/2i1n I9wT1gDbm27yegaD5GCLjAu4RU2ztvN3Qzdgbqd8qz3CrtZQUH8jo/NJ/+MXqfXWjpHe AOY2pb7VgnsfNLt2BKVeqXtVDwrBzPY3fnvnB1AXb1ETOf7TQS890zEv6XR8ZhuX7cfL odtTZwhZbfp+dGIZrcXnCJO/KDCKyVb6knKBCud6JyP5upq7kY136ULSr08YbtDyXrcY auHQ== X-Forwarded-Encrypted: i=1; AJvYcCXd11dcejkGZ7yUQkiGMtzptgbTSbYjPnEXZcdLfttsaDwm/4zmpFTVLAuzixykvTXMBoV4BvQKjdcBrSw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8US/XdwoT54cJn4Qo01gmzNPEUK0H5eA7af4wyyMlwGEpTR4G eoLgsxR5OHosZWDjpAJWYUmUptK81IbVpogOfqiqYBLMKThjs4QqgTOm5Rt+oyAqEbkIxg== X-Gm-Gg: ATEYQzx6p1e3IPRxzUAXLc8GcrrJOE6I1z+Fm7fKwh5NTwmSQWBxfqDnfG2yTRYhExy 3C8nYDcr6m/VQU4Cgh+v84WW6hCRqzbQKqhpI7QpXd6kfX2aqQenNWODkl4HROSXV0+/MZITd5e bHufZj5w0+qxh1SbwQ+WESF6/gY2f5VAo5bvYyDIWzUjP3ttaeUBWJNd/RaAo4H5ucImHPj5WFt cBg6mbeLZRQ3M9ATFImzax7+bHd1FVyNFl8jiBGB/fn5YRbckbuQ3Q6VoF8MrJioY2fslkaU6T7 QjRDN6mSRE19YfPjfnnNOe6S/hygsfTY2tv9UzU+oURyFAm9AacxpdgPO8ubAYFDyu7UwprtLqP c3qzW1+1LmECvNeWH96Dl2QUpw2h1m/+gCH+l9Zx9OmtIw9HItgwouMT9l+R1PcJ/pnqmHYbf4p jSLbbFF1Feo385upUjLGg= X-Received: by 2002:a05:600c:628d:b0:483:7020:864 with SMTP id 5b1f17b1804b1-483c21a59aemr62238595e9.25.1772119089813; Thu, 26 Feb 2026 07:18:09 -0800 (PST) Received: from localhost ([2620:10d:c092:500::5:5405]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bd75df9fsm162765655e9.13.2026.02.26.07.18.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 07:18:09 -0800 (PST) From: Mykyta Yatsenko To: Sun Jian , 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: Re: [PATCH v2 1/2] selftests/bpf: probe_user: filter by pid to avoid cross-test interference In-Reply-To: <20260226093132.437206-2-sun.jian.kdev@gmail.com> References: <20260226093132.437206-1-sun.jian.kdev@gmail.com> <20260226093132.437206-2-sun.jian.kdev@gmail.com> Date: Thu, 26 Feb 2026 15:18:08 +0000 Message-ID: <87ikbjpm8f.fsf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Sun Jian writes: > 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/testing/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 = 0; > + struct test_pro_bss { > + struct sockaddr_in old; > + __u32 test_pid; > + }; > + struct test_pro_bss results = {}; > size_t i; > > obj = bpf_object__open_file(obj_file, &opts); > @@ -34,6 +39,24 @@ void serial_test_probe_user(void) > goto cleanup; > } > > + { > + struct bpf_map *bss_map; > + struct test_pro_bss bss_init = {}; > + > + bss_init.test_pid = getpid(); > + bss_map = 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) != sizeof(bss_init), > + "bss_size", "bss value_size %u != %zu\n", > + bpf_map__value_size(bss_map), sizeof(bss_init))) > + goto cleanup; > + err = 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 = 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); > > - err = bpf_map_lookup_elem(results_map_fd, &zero, &tmp); > + err = 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; > > + memcpy(&tmp, &results.old, sizeof(tmp)); > + > in = (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/testing/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" > > -static struct sockaddr_in old; > +struct test_pro_bss { > + struct sockaddr_in old; > + __u32 test_pid; > +}; > + > +struct test_pro_bss bss; > > static int handle_sys_connect_common(struct sockaddr_in *uservaddr) > { > struct sockaddr_in new; > + __u32 cur = bpf_get_current_pid_tgid() >> 32; > + > + if (bss.test_pid && cur != bss.test_pid) > + return 0; > > - 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)); > > -- > 2.43.0