mirror of
https://github.com/torvalds/linux.git
synced 2026-05-27 08:33:17 +02:00
bpf: change prototype of bpf_session_{cookie,is_return}
Add the function argument of "void *ctx" to bpf_session_cookie() and bpf_session_is_return(), which is a preparation of the next patch. The two kfunc is seldom used now, so it will not introduce much effect to change their function prototype. Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20260124062008.8657-4-dongml2@chinatelecom.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
f1b56b3cbd
commit
8fe4dc4f64
|
|
@ -12484,6 +12484,7 @@ enum special_kfunc_type {
|
||||||
KF_bpf_arena_alloc_pages,
|
KF_bpf_arena_alloc_pages,
|
||||||
KF_bpf_arena_free_pages,
|
KF_bpf_arena_free_pages,
|
||||||
KF_bpf_arena_reserve_pages,
|
KF_bpf_arena_reserve_pages,
|
||||||
|
KF_bpf_session_is_return,
|
||||||
};
|
};
|
||||||
|
|
||||||
BTF_ID_LIST(special_kfunc_list)
|
BTF_ID_LIST(special_kfunc_list)
|
||||||
|
|
@ -12561,6 +12562,7 @@ BTF_ID(func, bpf_task_work_schedule_resume)
|
||||||
BTF_ID(func, bpf_arena_alloc_pages)
|
BTF_ID(func, bpf_arena_alloc_pages)
|
||||||
BTF_ID(func, bpf_arena_free_pages)
|
BTF_ID(func, bpf_arena_free_pages)
|
||||||
BTF_ID(func, bpf_arena_reserve_pages)
|
BTF_ID(func, bpf_arena_reserve_pages)
|
||||||
|
BTF_ID(func, bpf_session_is_return)
|
||||||
|
|
||||||
static bool is_task_work_add_kfunc(u32 func_id)
|
static bool is_task_work_add_kfunc(u32 func_id)
|
||||||
{
|
{
|
||||||
|
|
@ -12615,7 +12617,9 @@ get_kfunc_ptr_arg_type(struct bpf_verifier_env *env,
|
||||||
struct bpf_reg_state *reg = ®s[regno];
|
struct bpf_reg_state *reg = ®s[regno];
|
||||||
bool arg_mem_size = false;
|
bool arg_mem_size = false;
|
||||||
|
|
||||||
if (meta->func_id == special_kfunc_list[KF_bpf_cast_to_kern_ctx])
|
if (meta->func_id == special_kfunc_list[KF_bpf_cast_to_kern_ctx] ||
|
||||||
|
meta->func_id == special_kfunc_list[KF_bpf_session_is_return] ||
|
||||||
|
meta->func_id == special_kfunc_list[KF_bpf_session_cookie])
|
||||||
return KF_ARG_PTR_TO_CTX;
|
return KF_ARG_PTR_TO_CTX;
|
||||||
|
|
||||||
if (argno + 1 < nargs &&
|
if (argno + 1 < nargs &&
|
||||||
|
|
|
||||||
|
|
@ -3323,7 +3323,7 @@ static u64 bpf_uprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
|
||||||
|
|
||||||
__bpf_kfunc_start_defs();
|
__bpf_kfunc_start_defs();
|
||||||
|
|
||||||
__bpf_kfunc bool bpf_session_is_return(void)
|
__bpf_kfunc bool bpf_session_is_return(void *ctx)
|
||||||
{
|
{
|
||||||
struct bpf_session_run_ctx *session_ctx;
|
struct bpf_session_run_ctx *session_ctx;
|
||||||
|
|
||||||
|
|
@ -3331,7 +3331,7 @@ __bpf_kfunc bool bpf_session_is_return(void)
|
||||||
return session_ctx->is_return;
|
return session_ctx->is_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
__bpf_kfunc __u64 *bpf_session_cookie(void)
|
__bpf_kfunc __u64 *bpf_session_cookie(void *ctx)
|
||||||
{
|
{
|
||||||
struct bpf_session_run_ctx *session_ctx;
|
struct bpf_session_run_ctx *session_ctx;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,6 @@ extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,
|
||||||
struct bpf_dynptr *sig_ptr,
|
struct bpf_dynptr *sig_ptr,
|
||||||
struct bpf_key *trusted_keyring) __ksym;
|
struct bpf_key *trusted_keyring) __ksym;
|
||||||
|
|
||||||
extern bool bpf_session_is_return(void) __ksym __weak;
|
|
||||||
extern __u64 *bpf_session_cookie(void) __ksym __weak;
|
|
||||||
|
|
||||||
struct dentry;
|
struct dentry;
|
||||||
/* Description
|
/* Description
|
||||||
* Returns xattr of a dentry
|
* Returns xattr of a dentry
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include <linux/bpf.h>
|
#include <vmlinux.h>
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <bpf/bpf_tracing.h>
|
#include <bpf/bpf_tracing.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "bpf_kfuncs.h"
|
|
||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
||||||
|
|
@ -23,16 +22,16 @@ int BPF_PROG(trigger)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_cookie(__u64 val, __u64 *result)
|
static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result)
|
||||||
{
|
{
|
||||||
__u64 *cookie;
|
__u64 *cookie;
|
||||||
|
|
||||||
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
cookie = bpf_session_cookie();
|
cookie = bpf_session_cookie(ctx);
|
||||||
|
|
||||||
if (bpf_session_is_return())
|
if (bpf_session_is_return(ctx))
|
||||||
*result = *cookie == val ? val : 0;
|
*result = *cookie == val ? val : 0;
|
||||||
else
|
else
|
||||||
*cookie = val;
|
*cookie = val;
|
||||||
|
|
@ -42,17 +41,17 @@ static int check_cookie(__u64 val, __u64 *result)
|
||||||
SEC("kprobe.session/bpf_fentry_test1")
|
SEC("kprobe.session/bpf_fentry_test1")
|
||||||
int test_kprobe_1(struct pt_regs *ctx)
|
int test_kprobe_1(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return check_cookie(1, &test_kprobe_1_result);
|
return check_cookie(ctx, 1, &test_kprobe_1_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("kprobe.session/bpf_fentry_test1")
|
SEC("kprobe.session/bpf_fentry_test1")
|
||||||
int test_kprobe_2(struct pt_regs *ctx)
|
int test_kprobe_2(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return check_cookie(2, &test_kprobe_2_result);
|
return check_cookie(ctx, 2, &test_kprobe_2_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("kprobe.session/bpf_fentry_test1")
|
SEC("kprobe.session/bpf_fentry_test1")
|
||||||
int test_kprobe_3(struct pt_regs *ctx)
|
int test_kprobe_3(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return check_cookie(3, &test_kprobe_3_result);
|
return check_cookie(ctx, 3, &test_kprobe_3_result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include <linux/bpf.h>
|
#include <vmlinux.h>
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <bpf/bpf_tracing.h>
|
#include <bpf/bpf_tracing.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "bpf_kfuncs.h"
|
|
||||||
#include "bpf_misc.h"
|
#include "bpf_misc.h"
|
||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
@ -51,7 +50,7 @@ static int uprobe_multi_check(void *ctx, bool is_return)
|
||||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_*")
|
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_*")
|
||||||
int uprobe(struct pt_regs *ctx)
|
int uprobe(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return uprobe_multi_check(ctx, bpf_session_is_return());
|
return uprobe_multi_check(ctx, bpf_session_is_return(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __always_inline bool verify_sleepable_user_copy(void)
|
static __always_inline bool verify_sleepable_user_copy(void)
|
||||||
|
|
@ -67,5 +66,5 @@ int uprobe_sleepable(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
if (verify_sleepable_user_copy())
|
if (verify_sleepable_user_copy())
|
||||||
uprobe_multi_sleep_result++;
|
uprobe_multi_sleep_result++;
|
||||||
return uprobe_multi_check(ctx, bpf_session_is_return());
|
return uprobe_multi_check(ctx, bpf_session_is_return(ctx));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include <linux/bpf.h>
|
#include <vmlinux.h>
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <bpf/bpf_tracing.h>
|
#include <bpf/bpf_tracing.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "bpf_kfuncs.h"
|
|
||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
||||||
|
|
@ -13,16 +12,16 @@ __u64 test_uprobe_1_result = 0;
|
||||||
__u64 test_uprobe_2_result = 0;
|
__u64 test_uprobe_2_result = 0;
|
||||||
__u64 test_uprobe_3_result = 0;
|
__u64 test_uprobe_3_result = 0;
|
||||||
|
|
||||||
static int check_cookie(__u64 val, __u64 *result)
|
static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result)
|
||||||
{
|
{
|
||||||
__u64 *cookie;
|
__u64 *cookie;
|
||||||
|
|
||||||
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
cookie = bpf_session_cookie();
|
cookie = bpf_session_cookie(ctx);
|
||||||
|
|
||||||
if (bpf_session_is_return())
|
if (bpf_session_is_return(ctx))
|
||||||
*result = *cookie == val ? val : 0;
|
*result = *cookie == val ? val : 0;
|
||||||
else
|
else
|
||||||
*cookie = val;
|
*cookie = val;
|
||||||
|
|
@ -32,17 +31,17 @@ static int check_cookie(__u64 val, __u64 *result)
|
||||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
|
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
|
||||||
int uprobe_1(struct pt_regs *ctx)
|
int uprobe_1(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return check_cookie(1, &test_uprobe_1_result);
|
return check_cookie(ctx, 1, &test_uprobe_1_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_2")
|
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_2")
|
||||||
int uprobe_2(struct pt_regs *ctx)
|
int uprobe_2(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return check_cookie(2, &test_uprobe_2_result);
|
return check_cookie(ctx, 2, &test_uprobe_2_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_3")
|
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_3")
|
||||||
int uprobe_3(struct pt_regs *ctx)
|
int uprobe_3(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
return check_cookie(3, &test_uprobe_3_result);
|
return check_cookie(ctx, 3, &test_uprobe_3_result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include <linux/bpf.h>
|
#include <vmlinux.h>
|
||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <bpf/bpf_tracing.h>
|
#include <bpf/bpf_tracing.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "bpf_kfuncs.h"
|
|
||||||
#include "bpf_misc.h"
|
#include "bpf_misc.h"
|
||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|
@ -16,11 +15,11 @@ int idx_return = 0;
|
||||||
__u64 test_uprobe_cookie_entry[6];
|
__u64 test_uprobe_cookie_entry[6];
|
||||||
__u64 test_uprobe_cookie_return[3];
|
__u64 test_uprobe_cookie_return[3];
|
||||||
|
|
||||||
static int check_cookie(void)
|
static int check_cookie(struct pt_regs *ctx)
|
||||||
{
|
{
|
||||||
__u64 *cookie = bpf_session_cookie();
|
__u64 *cookie = bpf_session_cookie(ctx);
|
||||||
|
|
||||||
if (bpf_session_is_return()) {
|
if (bpf_session_is_return(ctx)) {
|
||||||
if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return))
|
if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return))
|
||||||
return 1;
|
return 1;
|
||||||
test_uprobe_cookie_return[idx_return++] = *cookie;
|
test_uprobe_cookie_return[idx_return++] = *cookie;
|
||||||
|
|
@ -40,5 +39,5 @@ int uprobe_recursive(struct pt_regs *ctx)
|
||||||
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return check_cookie();
|
return check_cookie(ctx);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user