From patchwork Thu Apr 4 01:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 13616866 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 DDE684C7D; Thu, 4 Apr 2024 01:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712192606; cv=none; b=ucUhqeBAE/E7bry/VDYTSTkVm0kxS1dL4awgjC6pqnZTML1c8O6sRollN7vOlox3YO9DH9xcliz9MZgppP80mmvAxOIrdCF9kP7Ziq+guvHxAvO3Mv+AC8FooYsWGUEu8ldpvEUDviOx/Fp9bKQMgRChyrgfmhTgeAqR+Iy/UHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712192606; c=relaxed/simple; bh=LGd6saAhTNRNk6SUdRvYglHLJ9GcARn88XlV4Fy2oe4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=W4/aDxOU01nI0pmhdEeA66b29u3GUZ6d/TZ6HOPzpAnWC6D4ZsBviXxl+iCNaSbAbsmC5KcZ1LOoVPBxufQhDJTLPeXxVjtCyffKVALTBucv8SNH3qQLgGQQPhAgty7qFPNxHeSfBt6g9h5o8E47IQlAAQ9zCEd5F55gSXIe62c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=manifault.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.166.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=manifault.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-7c89cd8df36so14454939f.1; Wed, 03 Apr 2024 18:03:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712192603; x=1712797403; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g6vxAkr4s6qgE7mbwQ5Lwv040fqC5GXe0Ujo9eHHndY=; b=NT74vLcIT4iO54SVR8NL0G6kkftLRnxzYj4qhv8hN04e8QUzWenY3d9Q3GJPDx+ezT vXgk1kxZg8l5LE5RljDYT3vW93fW3TqlN8sPtxV5o18W5lZEe2Rw/Tzy95svAMKx5iIt 7/XcZ70Hh3pi93OV4rVy4n7l2F4c/djUIvkTh+XdTan8LKbXSisWJRJSD5H5hK2WCeiU wRPA08eIF8hZLPlqYxIRkp/BlxWRxJg2gau6niV9985+z0WTt5DI5zoxymUMj1GvjzZR 1p55AmaGbplhLamYx9uzD+j+svst2uPgmSHnjZBOnYrtn6QLSR2mfDI/Vigi1X4D+6zH UYfQ== X-Forwarded-Encrypted: i=1; AJvYcCVYo9VxQm3vvYg9gGI9FSH0NEcc4E2bvJ7s+JF9GShZjPKrUwgXmz0IYyRYXM+WTb2cIEI16zx2pDGkG1yI49p1gcnUs1fEYvs4Xa+7 X-Gm-Message-State: AOJu0Yxhufz21zniE7aE/ihY7faYTWSb0+lkcY86tEORO+mg92IvmYqY OpCxpuR4IbrM+94P9bURsn/iXZB8l4X8rGWZg1rDCpxaZKBtcewe5NnyhBzNi68= X-Google-Smtp-Source: AGHT+IHod2TfUcFpAwmb9wyGSXQqLBEZQypuU88VQILclSgT27zEVtPrfMXvG4Qt52wNhtvfP/Nutw== X-Received: by 2002:a05:6602:2195:b0:7d0:895b:5352 with SMTP id b21-20020a056602219500b007d0895b5352mr1414812iob.10.1712192603593; Wed, 03 Apr 2024 18:03:23 -0700 (PDT) Received: from localhost (c-76-136-75-40.hsd1.il.comcast.net. [76.136.75.40]) by smtp.gmail.com with ESMTPSA id f23-20020a056638023700b00476def848f1sm4132719jaq.131.2024.04.03.18.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 18:03:23 -0700 (PDT) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH bpf-next 1/2] bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs Date: Wed, 3 Apr 2024 20:03:07 -0500 Message-ID: <20240404010308.334604-1-void@manifault.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Currently, a set of core BPF kfuncs (e.g. bpf_task_*, bpf_cgroup_*, bpf_cpumask_*, etc) cannot be invoked from BPF_PROG_TYPE_SYSCALL programs. The whitelist approach taken for enabling kfuncs makes sense: it not safe to call these kfuncs from every program type. For example, it may not be safe to call bpf_task_acquire() in an fentry to free_task(). BPF_PROG_TYPE_SYSCALL, on the other hand, is a perfectly safe program type from which to invoke these kfuncs, as it's a very controlled environment, and we should never be able to run into any of the typical problems such as recursive invoations, acquiring references on freeing kptrs, etc. Being able to invoke these kfuncs would be useful, as BPF_PROG_TYPE_SYSCALL can be invoked with BPF_PROG_RUN, and would therefore enable user space programs to synchronously call into BPF to manipulate these kptrs. This patch therefore enables invoking the aforementioned core kfuncs from BPF_PROG_TYPE_SYSCALL progs. Signed-off-by: David Vernet Acked-by: Yonghong Song Acked-by: Andrii Nakryiko --- kernel/bpf/cpumask.c | 1 + kernel/bpf/helpers.c | 1 + 2 files changed, 2 insertions(+) diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c index dad0fb1c8e87..33c473d676a5 100644 --- a/kernel/bpf/cpumask.c +++ b/kernel/bpf/cpumask.c @@ -474,6 +474,7 @@ static int __init cpumask_kfunc_init(void) ret = bpf_mem_alloc_init(&bpf_cpumask_ma, sizeof(struct bpf_cpumask), false); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &cpumask_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &cpumask_kfunc_set); + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &cpumask_kfunc_set); return ret ?: register_btf_id_dtor_kfuncs(cpumask_dtors, ARRAY_SIZE(cpumask_dtors), THIS_MODULE); diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index d9e7aca8ae9e..8cde717137bd 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2653,6 +2653,7 @@ static int __init kfunc_init(void) ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &generic_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &generic_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &generic_kfunc_set); + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &generic_kfunc_set); ret = ret ?: register_btf_id_dtor_kfuncs(generic_dtors, ARRAY_SIZE(generic_dtors), THIS_MODULE); From patchwork Thu Apr 4 01:03:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 13616867 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) (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 686A69474; Thu, 4 Apr 2024 01:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712192609; cv=none; b=GqPyffPBYmeoi9XjkUlEVR5WQ37DYvP3Iv1iWn/ahETeZ420p0L7001Q+R6Bz1SC0x0mPizJaZy3Sy/kSUc6s/gpZ4IxIt2Rrkng6zM05M1L2BtVlcp07qhHBTP07wQSfzWY1OhDvJj4Q4hV9yLLUtPAgNUju0ZbnafQO0kZHn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712192609; c=relaxed/simple; bh=hw0ZgXnZn633Jb7sa9cehqutZWFVRlRXEoTD2rY1i0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b+foPIIJBI4zsh/9JD7Yc7QMCNZd2+2eejNmZQe/oxLRSNGjBu0/tSmMWlsgCJa6f5LovTHUVs/POV3w2hK5Bps11jZkx59lWzIZ2vXniFE7ojy9DGftCnIXJ0AjYlTbWAsNBrjBADzOo8DNuW5bjTECXqPlYdDukgYbHMkh1nk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=manifault.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.166.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=manifault.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f44.google.com with SMTP id ca18e2360f4ac-7cc0e0dba0fso21125339f.3; Wed, 03 Apr 2024 18:03:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712192605; x=1712797405; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TqgkjiLPZEySCieINTLvJdfXgLnfsvtRLoK1+mECOEQ=; b=M7LNpv/yPcsXt689mWRoQSq6/xFyqphYTiP3CJcEkbQzCdgbq5V2RgA35iv0EE4eUY xmYJDA23pxR9D4DTbx7f1szfwn4Entjt13yTbMK4YufdombQZ/w079NuGp5HsDMK33wG Tr7DcRbjylYGPtQj4yLmFh1YZvIKxvMiEyj96+K18omzxe42iHhNAsGw+nrZbRC6B54S 8KfZI2t/skJHfr2LiYWSkKHYk+fZyIQL2osiEUNp5PJwDzoMcDvP7I7ntYK8F3zX03I+ hbLOjm4XaJgy16Ema4DMEz4xkr1+XktddMpPDsvJ0BHAoSX8GrDIhdtmSk8GmaFeX2A1 fS0g== X-Forwarded-Encrypted: i=1; AJvYcCUQgn0+noBhZr6amEmG0dPU0dOx5T4Pg7F+NrA/RjpnbCldAXcNaBuRlIWG8IiJA1Fn5g6cuyOrJLzc6PKUVWsaeen5ynzAbMqLaLJn X-Gm-Message-State: AOJu0YzITkIrNfth85FECVXp1Qvf46AvqppYqNZ3zbBGUMU+CGDakyPH sBclQw7yLbyrlqvq6VjQ+aAIZDNGp6kJLphx6iWkJK41EoJz4V7tO1OcRls3/jw= X-Google-Smtp-Source: AGHT+IH5qzIJzadOeB7Uvs69Zd8gU3gaydcPSSV5dE3jL/hxKR+3djzl2v+BvXIVEXLmhoY9l42eXA== X-Received: by 2002:a6b:cf18:0:b0:7d0:85c7:dd61 with SMTP id o24-20020a6bcf18000000b007d085c7dd61mr1416699ioa.7.1712192605140; Wed, 03 Apr 2024 18:03:25 -0700 (PDT) Received: from localhost (c-76-136-75-40.hsd1.il.comcast.net. [76.136.75.40]) by smtp.gmail.com with ESMTPSA id ay19-20020a056638411300b0047f48f10459sm39881jab.100.2024.04.03.18.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 18:03:24 -0700 (PDT) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH bpf-next 2/2] selftests/bpf: Verify calling core kfuncs from BPF_PROG_TYPE_SYCALL Date: Wed, 3 Apr 2024 20:03:08 -0500 Message-ID: <20240404010308.334604-2-void@manifault.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404010308.334604-1-void@manifault.com> References: <20240404010308.334604-1-void@manifault.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Now that we can call some kfuncs from BPF_PROG_TYPE_SYSCALL progs, let's add some selftests that verify as much. As a bonus, let's also verify that we can't call the progs from raw tracepoints. Signed-off-by: David Vernet --- .../selftests/bpf/prog_tests/cgrp_kfunc.c | 1 + .../selftests/bpf/prog_tests/task_kfunc.c | 1 + .../selftests/bpf/progs/cgrp_kfunc_common.h | 21 +++++++++++++++++++ .../selftests/bpf/progs/cgrp_kfunc_failure.c | 4 ++++ .../selftests/bpf/progs/cgrp_kfunc_success.c | 4 ++++ .../selftests/bpf/progs/cpumask_common.h | 19 +++++++++++++++++ .../selftests/bpf/progs/cpumask_failure.c | 4 ++++ .../selftests/bpf/progs/cpumask_success.c | 3 +++ .../selftests/bpf/progs/task_kfunc_common.h | 18 ++++++++++++++++ .../selftests/bpf/progs/task_kfunc_failure.c | 4 ++++ .../selftests/bpf/progs/task_kfunc_success.c | 4 ++++ 11 files changed, 83 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/cgrp_kfunc.c b/tools/testing/selftests/bpf/prog_tests/cgrp_kfunc.c index adda85f97058..73f0ec4f4eb7 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgrp_kfunc.c +++ b/tools/testing/selftests/bpf/prog_tests/cgrp_kfunc.c @@ -102,6 +102,7 @@ void test_cgrp_kfunc(void) run_success_test(success_tests[i]); } + RUN_TESTS(cgrp_kfunc_success); RUN_TESTS(cgrp_kfunc_failure); cleanup: diff --git a/tools/testing/selftests/bpf/prog_tests/task_kfunc.c b/tools/testing/selftests/bpf/prog_tests/task_kfunc.c index d4579f735398..3db4c8601b70 100644 --- a/tools/testing/selftests/bpf/prog_tests/task_kfunc.c +++ b/tools/testing/selftests/bpf/prog_tests/task_kfunc.c @@ -94,5 +94,6 @@ void test_task_kfunc(void) run_success_test(success_tests[i]); } + RUN_TESTS(task_kfunc_success); RUN_TESTS(task_kfunc_failure); } diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h b/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h index 22914a70db54..b9972ce4e4dc 100644 --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h @@ -27,6 +27,27 @@ struct cgroup *bpf_cgroup_from_id(u64 cgid) __ksym; void bpf_rcu_read_lock(void) __ksym; void bpf_rcu_read_unlock(void) __ksym; +#define CGRP_KFUNC_LOAD_TEST(__name) \ +int BPF_PROG(cgroup_kfunc_load_test_##__name) \ +{ \ + struct cgroup *cgrp, *ref; \ + \ + cgrp = bpf_cgroup_from_id(0); \ + if (!cgrp) \ + return 0; \ + ref = bpf_cgroup_acquire(cgrp); \ + if (!ref) { \ + bpf_cgroup_release(cgrp); \ + return 0; \ + } \ + \ + bpf_cgroup_release(ref); \ + bpf_cgroup_release(cgrp); \ + \ + return 0; \ +} + + static inline struct __cgrps_kfunc_map_value *cgrps_kfunc_map_value_lookup(struct cgroup *cgrp) { s32 id; diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c b/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c index 9fe9c4a4e8f6..ff67d4632dfa 100644 --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c @@ -245,3 +245,7 @@ int BPF_PROG(cgrp_kfunc_release_unacquired, struct cgroup *cgrp, const char *pat return 0; } + +SEC("raw_tp") +__failure __msg("calling kernel function") +CGRP_KFUNC_LOAD_TEST(raw_tp) diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c b/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c index 5354455a01be..ff1beb29f3f5 100644 --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c @@ -5,6 +5,7 @@ #include #include +#include "bpf_misc.h" #include "cgrp_kfunc_common.h" char _license[] SEC("license") = "GPL"; @@ -221,3 +222,6 @@ int BPF_PROG(test_cgrp_from_id, struct cgroup *cgrp, const char *path) return 0; } + +SEC("syscall") __success +CGRP_KFUNC_LOAD_TEST(syscall) diff --git a/tools/testing/selftests/bpf/progs/cpumask_common.h b/tools/testing/selftests/bpf/progs/cpumask_common.h index c705d8112a35..5178d62c5c9f 100644 --- a/tools/testing/selftests/bpf/progs/cpumask_common.h +++ b/tools/testing/selftests/bpf/progs/cpumask_common.h @@ -60,6 +60,25 @@ u32 bpf_cpumask_weight(const struct cpumask *cpumask) __ksym __weak; void bpf_rcu_read_lock(void) __ksym __weak; void bpf_rcu_read_unlock(void) __ksym __weak; +#define CPUMASK_KFUNC_LOAD_TEST(__name) \ +int BPF_PROG(cpumask_kfunc_load_test_##__name) \ +{ \ + struct bpf_cpumask *alloc, *ref; \ + \ + alloc = bpf_cpumask_create(); \ + if (!alloc) \ + return 0; \ + \ + ref = bpf_cpumask_acquire(alloc); \ + if (ref) \ + bpf_cpumask_release(ref); \ + bpf_cpumask_set_cpu(0, alloc); \ + bpf_cpumask_test_cpu(0, (const struct cpumask *)alloc); \ + bpf_cpumask_release(alloc); \ + \ + return 0; \ +} + static inline const struct cpumask *cast(struct bpf_cpumask *cpumask) { return (const struct cpumask *)cpumask; diff --git a/tools/testing/selftests/bpf/progs/cpumask_failure.c b/tools/testing/selftests/bpf/progs/cpumask_failure.c index a9bf6ea336cf..55815df8000f 100644 --- a/tools/testing/selftests/bpf/progs/cpumask_failure.c +++ b/tools/testing/selftests/bpf/progs/cpumask_failure.c @@ -190,3 +190,7 @@ int BPF_PROG(test_global_mask_rcu_no_null_check, struct task_struct *task, u64 c return 0; } + +SEC("raw_tp") +__failure __msg("calling kernel function") +CPUMASK_KFUNC_LOAD_TEST(raw_tp) diff --git a/tools/testing/selftests/bpf/progs/cpumask_success.c b/tools/testing/selftests/bpf/progs/cpumask_success.c index 7a1e64c6c065..a4f32a5a26d1 100644 --- a/tools/testing/selftests/bpf/progs/cpumask_success.c +++ b/tools/testing/selftests/bpf/progs/cpumask_success.c @@ -525,3 +525,6 @@ int BPF_PROG(test_refcount_null_tracking, struct task_struct *task, u64 clone_fl bpf_cpumask_release(mask2); return 0; } + +SEC("syscall") __success +CPUMASK_KFUNC_LOAD_TEST(syscall) diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_common.h b/tools/testing/selftests/bpf/progs/task_kfunc_common.h index 41f2d44f49cb..2278325ca902 100644 --- a/tools/testing/selftests/bpf/progs/task_kfunc_common.h +++ b/tools/testing/selftests/bpf/progs/task_kfunc_common.h @@ -26,6 +26,24 @@ struct task_struct *bpf_task_from_pid(s32 pid) __ksym; void bpf_rcu_read_lock(void) __ksym; void bpf_rcu_read_unlock(void) __ksym; +#define TASK_KFUNC_LOAD_TEST(__name) \ +int BPF_PROG(task_kfunc_load_test_##__name) \ +{ \ + struct task_struct *current, *ref_1, *ref_2; \ + \ + current = bpf_get_current_task_btf(); \ + ref_1 = bpf_task_from_pid(current->pid); \ + if (!ref_1) \ + return 0; \ + \ + ref_2 = bpf_task_acquire(ref_1); \ + if (ref_2) \ + bpf_task_release(ref_2); \ + bpf_task_release(ref_1); \ + \ + return 0; \ +} + static inline struct __tasks_kfunc_map_value *tasks_kfunc_map_value_lookup(struct task_struct *p) { s32 pid; diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c index ad88a3796ddf..57ec25463d80 100644 --- a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c +++ b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c @@ -324,3 +324,7 @@ int BPF_PROG(task_kfunc_release_in_map, struct task_struct *task, u64 clone_flag return 0; } + +SEC("raw_tp") +__failure __msg("calling kernel function") +TASK_KFUNC_LOAD_TEST(raw_tp) diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_success.c b/tools/testing/selftests/bpf/progs/task_kfunc_success.c index 70df695312dc..203ff461a92c 100644 --- a/tools/testing/selftests/bpf/progs/task_kfunc_success.c +++ b/tools/testing/selftests/bpf/progs/task_kfunc_success.c @@ -5,6 +5,7 @@ #include #include +#include "bpf_misc.h" #include "task_kfunc_common.h" char _license[] SEC("license") = "GPL"; @@ -314,3 +315,6 @@ int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl return 0; } + +SEC("syscall") __success +TASK_KFUNC_LOAD_TEST(syscall)