From nobody Sat Oct 11 12:15:09 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E29BE28B3FF for ; Tue, 10 Jun 2025 09:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749547190; cv=none; b=jnJTDIwe3eacCLmz9I34ke8BByROHRRNlZ2dCkdv5ST919jINRRlymI1FUrSC91tACzVylMnj26moThNTczdMKcnqTce0cD2SRbLwVsZOxpDkXK2J/NQm6rZXl0x5MpBtIRZliHfwJfjxp7pb6/W7svb+Vf48UqNnjE1GYRwpyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749547190; c=relaxed/simple; bh=ltjpKWi1t7lbiS/wQUL0JGtR6xxe81f0cE/kMQ+SMZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=leu8x+I21fbmJmHyHGOqVTPFzJ0Gmnj/F7G/8iYY9dl7QUTA0J2JhL4wQdhHsm4NR8Q4VzML00zbghImlI1qp0IRvuNZOttcaGjjAMZ9SZbd9BN9nlxYobw0QRQeqKJSXXP1y+fdEJCOvhCmEDlzgIq3lhZ0slImM7whr1JJn1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XyznDC6i; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XyznDC6i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749547187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QIyeiHyJh2LLkv/UD+/4q8cYY7zOw5NP6NFKW3iCjws=; b=XyznDC6i9VP8+T+daLm6yOZmNOojQYOhQjbei1Q1/HQeVRnRobSRjnanTfVKkFKGhFal/S hPq973EwVtMIpcq7x4Ms43lmu880YFkL6StDzngXif0bULZRJkgo45a4zb2Zx3duQGOJHc T5TNr7PtY0VCYL2JsG3Joj+WNFX/cDc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-h22P7FUaMCq4i0r-ayQMAQ-1; Tue, 10 Jun 2025 05:19:44 -0400 X-MC-Unique: h22P7FUaMCq4i0r-ayQMAQ-1 X-Mimecast-MFC-AGG-ID: h22P7FUaMCq4i0r-ayQMAQ_1749547183 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F393818002EC; Tue, 10 Jun 2025 09:19:42 +0000 (UTC) Received: from fedora (unknown [10.45.225.84]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 7E3C530001B1; Tue, 10 Jun 2025 09:19:39 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Tue, 10 Jun 2025 11:19:38 +0200 From: "Jerome Marchand" To: bpf@vger.kernel.org Cc: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , linux-kernel@vger.kernel.org, Yonghong Song , Eduard Zingerman , Jerome Marchand Subject: [PATCH v2 1/2] bpf: Specify access type of bpf_sysctl_get_name args Date: Tue, 10 Jun 2025 11:19:32 +0200 Message-ID: <20250610091933.717824-2-jmarchan@redhat.com> In-Reply-To: <20250610091933.717824-1-jmarchan@redhat.com> References: <20250527165412.533335-1-jmarchan@redhat.com> <20250610091933.717824-1-jmarchan@redhat.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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" The second argument of bpf_sysctl_get_name() helper is a pointer to a buffer that is being written to. However that isn't specify in the prototype. Until commit 37cce22dbd51a ("bpf: verifier: Refactor helper access type tracking"), all helper accesses were considered as a possible write access by the verifier, so no big harm was done. However, since then, the verifier might make wrong asssumption about the content of that address which might lead it to make faulty optimizations (such as removing code that was wrongly labeled dead). This is what happens in test_sysctl selftest to the tests related to sysctl_get_name. Add MEM_WRITE flag the second argument of bpf_sysctl_get_name(). Signed-off-by: Jerome Marchand Acked-by: Yonghong Song --- kernel/bpf/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 84f58f3d028a3..76994c204b503 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -2104,7 +2104,7 @@ static const struct bpf_func_proto bpf_sysctl_get_nam= e_proto =3D { .gpl_only =3D false, .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_CTX, - .arg2_type =3D ARG_PTR_TO_MEM, + .arg2_type =3D ARG_PTR_TO_MEM | MEM_WRITE, .arg3_type =3D ARG_CONST_SIZE, .arg4_type =3D ARG_ANYTHING, }; --=20 2.49.0 From nobody Sat Oct 11 12:15:09 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F7ED28B519 for ; Tue, 10 Jun 2025 09:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749547195; cv=none; b=tVmcpSL4zO/6LKd3PkwzQ7HPENWvtIL/W+BWTEFFbskyJW9fnClPN7dZUSC4Me7546sofuwEFp8MdXYgiidjIik6NZTJCk6OEPrGaXiv8ofa52RIG0RNxEucZusy+CBdU4z9vqIwD4qr85a293hecQ2KVV+j3iMwHKoC+Ej744E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749547195; c=relaxed/simple; bh=m3QPIf1lS1FLCWqYBfYXmXH8UzK5MkjHUdqx0zJoLdw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UpyCyPPqc/73slVnf3iho1x4TNY83A8vUKJdeWO+VVAeYmFPVXOpW51NxgTkDBWvNmDKNkLSQgjRZFijrqAjoNEDgfBelO/0NjrWI2qLOSwiqOchxACJrQ2IfQTE2DhZCgHY/DY6qyhXOUeQ53ZsRX1Ytq1wC4A+5w5YpTKp6xQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VLMHVjU7; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VLMHVjU7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749547193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2YfGEaES37tUIdfNDtsElA5nBwIdrKb6uYDOTFUqS6Y=; b=VLMHVjU7yVrFP9Rvg18Wv9AQegfVh7xYpJwq60s6vQEEJRetXQcnozUI/UwHODc6s8LoE6 79uQL2JvcutEsuR0dOiFd24hgCEAU39rVDBQFni3oBHsaABACVkH5M5EblRDAnLapu9EDf v0P8LBdMwT4DPTA9+xPnsOkmXGs1sqc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-z6xL1PvxMzaAe3irMX5X7g-1; Tue, 10 Jun 2025 05:19:49 -0400 X-MC-Unique: z6xL1PvxMzaAe3irMX5X7g-1 X-Mimecast-MFC-AGG-ID: z6xL1PvxMzaAe3irMX5X7g_1749547188 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC4C11800287; Tue, 10 Jun 2025 09:19:47 +0000 (UTC) Received: from fedora (unknown [10.45.225.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 7FC8E195608D; Tue, 10 Jun 2025 09:19:44 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Tue, 10 Jun 2025 11:19:43 +0200 From: "Jerome Marchand" To: bpf@vger.kernel.org Cc: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , linux-kernel@vger.kernel.org, Yonghong Song , Eduard Zingerman , Jerome Marchand Subject: [PATCH v2 2/2] selftests/bpf: Convert test_sysctl to prog_tests Date: Tue, 10 Jun 2025 11:19:33 +0200 Message-ID: <20250610091933.717824-3-jmarchan@redhat.com> In-Reply-To: <20250610091933.717824-1-jmarchan@redhat.com> References: <20250527165412.533335-1-jmarchan@redhat.com> <20250610091933.717824-1-jmarchan@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Convert test_sysctl test to prog_tests with minimal change to the tests themselves. Signed-off-by: Jerome Marchand --- tools/testing/selftests/bpf/.gitignore | 1 - tools/testing/selftests/bpf/Makefile | 5 ++- .../bpf/{ =3D> prog_tests}/test_sysctl.c | 32 ++++--------------- 3 files changed, 9 insertions(+), 29 deletions(-) rename tools/testing/selftests/bpf/{ =3D> prog_tests}/test_sysctl.c (98%) diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftes= ts/bpf/.gitignore index e2a2c46c008b1..3d8378972d26c 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore @@ -21,7 +21,6 @@ test_lirc_mode2_user flow_dissector_load test_tcpnotify_user test_libbpf -test_sysctl xdping test_cpp *.d diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index 66bb50356be08..53dc08d905bd1 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -70,7 +70,7 @@ endif # Order correspond to 'make run_tests' order TEST_GEN_PROGS =3D test_verifier test_tag test_maps test_lru_map test_prog= s \ test_sockmap \ - test_tcpnotify_user test_sysctl \ + test_tcpnotify_user \ test_progs-no_alu32 TEST_INST_SUBDIRS :=3D no_alu32 =20 @@ -215,7 +215,7 @@ ifeq ($(VMLINUX_BTF),) $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PAT= HS)") endif =20 -# Define simple and short `make test_progs`, `make test_sysctl`, etc targe= ts +# Define simple and short `make test_progs`, `make test_maps`, etc targets # to build individual tests. # NOTE: Semicolon at the end is critical to override lib.mk's default stat= ic # rule for binaries. @@ -324,7 +324,6 @@ NETWORK_HELPERS :=3D $(OUTPUT)/network_helpers.o $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRAC= E_HELPERS) $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS) -$(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_tag: $(TESTING_HELPERS) $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS) $(OUTPUT)/xdping: $(TESTING_HELPERS) diff --git a/tools/testing/selftests/bpf/test_sysctl.c b/tools/testing/self= tests/bpf/prog_tests/test_sysctl.c similarity index 98% rename from tools/testing/selftests/bpf/test_sysctl.c rename to tools/testing/selftests/bpf/prog_tests/test_sysctl.c index bcdbd27f22f08..049671361f8fa 100644 --- a/tools/testing/selftests/bpf/test_sysctl.c +++ b/tools/testing/selftests/bpf/prog_tests/test_sysctl.c @@ -1,22 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2019 Facebook =20 -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include "bpf_util.h" +#include "test_progs.h" #include "cgroup_helpers.h" -#include "testing_helpers.h" =20 #define CG_PATH "/foo" #define MAX_INSNS 512 @@ -1608,26 +1594,22 @@ static int run_tests(int cgfd) return fails ? -1 : 0; } =20 -int main(int argc, char **argv) +void test_sysctl(void) { int cgfd =3D -1; - int err =3D 0; =20 cgfd =3D cgroup_setup_and_join(CG_PATH); - if (cgfd < 0) - goto err; + if (CHECK_FAIL(cgfd < 0)) + goto out; =20 /* Use libbpf 1.0 API mode */ libbpf_set_strict_mode(LIBBPF_STRICT_ALL); =20 - if (run_tests(cgfd)) - goto err; + if (CHECK_FAIL(run_tests(cgfd))) + goto out; =20 - goto out; -err: - err =3D -1; out: close(cgfd); cleanup_cgroup_environment(); - return err; + return; } --=20 2.49.0