Skip to content

eBPF-based security platform

1.4 KB
Raw Blame
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
/*
 * CVE-2026-31675 source-derived detector.
 *
 * The vulnerable netem corruption path selected an offset using
 * get_random_u32_below(skb_headlen(skb)) when the linear head was empty.
 * At netem_enqueue entry this records that source-described input shape.
 * It is intentionally labelled an entry-shape predicate: the kernel may
 * linearize or replace the skb later in the function.
 */

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#ifndef __TARGET_ARCH_x86
#define __TARGET_ARCH_x86
#endif
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>

char _license[] SEC("license") = "Dual BSD/GPL";

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, __u64);
} hits SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, __u64);
} activity SEC(".maps");

static __always_inline void count_event(void *map)
{
	__u32 zero = 0;
	__u64 *count = bpf_map_lookup_elem(map, &zero);

	if (count)
		(*count)++;
}

SEC("kprobe/netem_enqueue")
int BPF_KPROBE(cve_2026_31675_netem, const struct sk_buff *skb,
	       void *sch, void *to_free)
{
	__u32 len;
	__u32 data_len;

	count_event(&activity);
	if (!skb)
		return 0;
	len = BPF_CORE_READ(skb, len);
	data_len = BPF_CORE_READ(skb, data_len);
	if (len >= data_len && len - data_len == 0)
		count_event(&hits);
	return 0;
}