Skip to content

Commit 1274163

Browse files
iii-iborkmann
authored andcommitted
selftests/bpf: Clobber a lot of registers in tailcall_bpf2bpf_hierarchy tests
Clobbering a lot of registers and stack slots helps exposing tail call counter overwrite bugs in JITs. Signed-off-by: Ilya Leoshkevich <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bc3905a commit 1274163

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __BPF_TEST_UTILS_H__
3+
#define __BPF_TEST_UTILS_H__
4+
5+
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
7+
8+
/* Clobber as many native registers and stack slots as possible. */
9+
static __always_inline void clobber_regs_stack(void)
10+
{
11+
char tmp_str[] = "123456789";
12+
unsigned long tmp;
13+
14+
bpf_strtoul(tmp_str, sizeof(tmp_str), 0, &tmp);
15+
__sink(tmp);
16+
}
17+
18+
#endif

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy1.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/bpf.h>
33
#include <bpf/bpf_helpers.h>
44
#include "bpf_legacy.h"
5+
#include "bpf_test_utils.h"
56

67
struct {
78
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
@@ -24,6 +25,8 @@ int entry(struct __sk_buff *skb)
2425
{
2526
int ret = 1;
2627

28+
clobber_regs_stack();
29+
2730
count++;
2831
subprog_tail(skb);
2932
subprog_tail(skb);

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/bpf.h>
33
#include <bpf/bpf_helpers.h>
44
#include "bpf_misc.h"
5+
#include "bpf_test_utils.h"
56

67
int classifier_0(struct __sk_buff *skb);
78
int classifier_1(struct __sk_buff *skb);
@@ -60,6 +61,8 @@ int tailcall_bpf2bpf_hierarchy_2(struct __sk_buff *skb)
6061
{
6162
int ret = 0;
6263

64+
clobber_regs_stack();
65+
6366
subprog_tail0(skb);
6467
subprog_tail1(skb);
6568

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy3.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/bpf.h>
33
#include <bpf/bpf_helpers.h>
44
#include "bpf_misc.h"
5+
#include "bpf_test_utils.h"
56

67
int classifier_0(struct __sk_buff *skb);
78

@@ -53,6 +54,8 @@ int tailcall_bpf2bpf_hierarchy_3(struct __sk_buff *skb)
5354
{
5455
int ret = 0;
5556

57+
clobber_regs_stack();
58+
5659
bpf_tail_call_static(skb, &jmp_table0, 0);
5760

5861
__sink(ret);

tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy_fentry.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "vmlinux.h"
55
#include <bpf/bpf_helpers.h>
66
#include <bpf/bpf_tracing.h>
7+
#include "bpf_test_utils.h"
78

89
struct {
910
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
@@ -24,6 +25,8 @@ int subprog_tail(void *ctx)
2425
SEC("fentry/dummy")
2526
int BPF_PROG(fentry, struct sk_buff *skb)
2627
{
28+
clobber_regs_stack();
29+
2730
count++;
2831
subprog_tail(ctx);
2932
subprog_tail(ctx);

0 commit comments

Comments
 (0)