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

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_raw_stack.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/verifier_raw_stack.c
Extension
.c
Size
8604 bytes
Lines
373
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/raw_stack.c */

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

SEC("socket")
__description("raw_stack: no skb_load_bytes")
__success
__failure_unpriv __msg_unpriv("invalid read from stack R6 off=-8 size=8")
__naked void stack_no_skb_load_bytes(void)
{
	asm volatile ("					\
	r2 = 4;						\
	r6 = r10;					\
	r6 += -8;					\
	r3 = r6;					\
	r4 = 8;						\
	/* Call to skb_load_bytes() omitted. */		\
	r0 = *(u64*)(r6 + 0);				\
	exit;						\
"	::: __clobber_all);
}

SEC("tc")
__description("raw_stack: skb_load_bytes, negative len")
__failure __msg("R4 min value is negative")
__naked void skb_load_bytes_negative_len(void)
{
	asm volatile ("					\
	r2 = 4;						\
	r6 = r10;					\
	r6 += -8;					\
	r3 = r6;					\
	r4 = -8;					\
	call %[bpf_skb_load_bytes];			\
	r0 = *(u64*)(r6 + 0);				\
	exit;						\
"	:
	: __imm(bpf_skb_load_bytes)
	: __clobber_all);
}

SEC("tc")
__description("raw_stack: skb_load_bytes, negative len 2")
__failure __msg("R4 min value is negative")
__naked void load_bytes_negative_len_2(void)
{
	asm volatile ("					\
	r2 = 4;						\
	r6 = r10;					\
	r6 += -8;					\
	r3 = r6;					\
	r4 = %[__imm_0];				\
	call %[bpf_skb_load_bytes];			\
	r0 = *(u64*)(r6 + 0);				\
	exit;						\
"	:
	: __imm(bpf_skb_load_bytes),
	  __imm_const(__imm_0, ~0)
	: __clobber_all);
}

SEC("tc")
__description("raw_stack: skb_load_bytes, zero len")
__failure __msg("R4 invalid zero-sized read: u64=[0,0]")
__naked void skb_load_bytes_zero_len(void)
{
	asm volatile ("					\
	r2 = 4;						\
	r6 = r10;					\
	r6 += -8;					\
	r3 = r6;					\
	r4 = 0;						\
	call %[bpf_skb_load_bytes];			\
	r0 = *(u64*)(r6 + 0);				\
	exit;						\
"	:
	: __imm(bpf_skb_load_bytes)
	: __clobber_all);
}

SEC("tc")
__description("raw_stack: skb_load_bytes, no init")
__success __retval(0)
__naked void skb_load_bytes_no_init(void)
{
	asm volatile ("					\
	r2 = 4;						\

Annotation

Implementation Notes