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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/verifier_bounds_deduction.c
Extension
.c
Size
4491 bytes
Lines
175
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/bounds_deduction.c */

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

SEC("socket")
__description("check deducing bounds from const, 1")
__failure __msg("R0 tried to subtract pointer from scalar")
__msg_unpriv("R1 has pointer with unsupported alu operation")
__naked void deducing_bounds_from_const_1(void)
{
	asm volatile ("					\
	r0 = 1;						\
	if r0 s>= 1 goto l0_%=;				\
l0_%=:	r0 -= r1;					\
	exit;						\
"	::: __clobber_all);
}

SEC("socket")
__description("check deducing bounds from const, 2")
__success __failure_unpriv
__msg_unpriv("R1 has pointer with unsupported alu operation")
__retval(1)
__naked void deducing_bounds_from_const_2(void)
{
	asm volatile ("					\
	r0 = 1;						\
	if r0 s>= 1 goto l0_%=;				\
	exit;						\
l0_%=:	if r0 s<= 1 goto l1_%=;				\
	exit;						\
l1_%=:	r1 -= r0;					\
	exit;						\
"	::: __clobber_all);
}

SEC("socket")
__description("check deducing bounds from const, 3")
__failure __msg("R0 tried to subtract pointer from scalar")
__msg_unpriv("R1 has pointer with unsupported alu operation")
__naked void deducing_bounds_from_const_3(void)
{
	asm volatile ("					\
	r0 = 0;						\
	if r0 s<= 0 goto l0_%=;				\
l0_%=:	r0 -= r1;					\
	exit;						\
"	::: __clobber_all);
}

SEC("socket")
__description("check deducing bounds from const, 4")
__success __failure_unpriv
__msg_unpriv("R6 has pointer with unsupported alu operation")
__retval(0)
__naked void deducing_bounds_from_const_4(void)
{
	asm volatile ("					\
	r6 = r1;					\
	r0 = 0;						\
	if r0 s<= 0 goto l0_%=;				\
	exit;						\
l0_%=:	if r0 s>= 0 goto l1_%=;				\
	exit;						\
l1_%=:	r6 -= r0;					\
	exit;						\
"	::: __clobber_all);
}

SEC("socket")
__description("check deducing bounds from const, 5")
__failure __msg("R0 tried to subtract pointer from scalar")
__msg_unpriv("R1 has pointer with unsupported alu operation")
__naked void deducing_bounds_from_const_5(void)
{
	asm volatile ("					\
	r0 = 0;						\
	if r0 s>= 1 goto l0_%=;				\
	r0 -= r1;					\
l0_%=:	exit;						\
"	::: __clobber_all);
}

SEC("socket")
__description("check deducing bounds from const, 6")
__failure __msg("R0 tried to subtract pointer from scalar")
__msg_unpriv("R1 has pointer with unsupported alu operation")

Annotation

Implementation Notes