Skip to content

Commit 5d0f0d5

Browse files
Update libbpf to support 6.0+ kernels. (#168)
* Untar libbpf v1.1.0 * Add our old library headers and fix compile issues * handle new write_iter iovec handling * code formatting * Add new kernel to ci testing * Use new docker images * Add custom change to ensure the use of fPIC
1 parent d2fd5f6 commit 5d0f0d5

File tree

110 files changed

+90313
-88643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+90313
-88643
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
architecture: x86_64
3939
runner: ubuntu-latest
40-
kernels: '[ "amazonlinux2", "debian", "fedora", "kali1", "kali3", "kali4", "kali5-7", "kali8-9", "mainline", "rocky", "ubuntu-aws", "ubuntu-azure", "ubuntu-gcp", "ubuntu-gke", "ubuntu-oem", "ubuntu-oracle" ]'
40+
kernels: '[ "amazonlinux2", "centos", "debian", "fedora", "kali1", "kali3", "kali4", "kali5-7", "kali8-9", "mainline", "rocky", "ubuntu-aws", "ubuntu-azure", "ubuntu-gcp", "ubuntu-gke", "ubuntu-oem", "ubuntu-oracle" ]'
4141
secrets: inherit
4242
multikernel-tester-aarch64:
4343
name: Test (aarch64)

GPL/Events/Process/Probe.bpf.c

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,51 @@ int BPF_KPROBE(kprobe__commit_creds, struct cred *new)
292292

293293
#define MAX_NR_SEGS 8
294294

295+
static int output_tty_event(struct ebpf_tty_dev *slave, const void *base, size_t base_len)
296+
{
297+
struct ebpf_process_tty_write_event *event;
298+
struct ebpf_varlen_field *field;
299+
const struct task_struct *task;
300+
int ret = 0;
301+
302+
event = get_event_buffer();
303+
if (!event) {
304+
ret = 1;
305+
goto out;
306+
}
307+
308+
task = (struct task_struct *)bpf_get_current_task();
309+
event->hdr.type = EBPF_EVENT_PROCESS_TTY_WRITE;
310+
event->hdr.ts = bpf_ktime_get_ns();
311+
u64 len_cap = base_len > TTY_OUT_MAX ? TTY_OUT_MAX : base_len;
312+
event->tty_out_truncated = base_len > TTY_OUT_MAX ? base_len - TTY_OUT_MAX : 0;
313+
event->tty = *slave;
314+
ebpf_pid_info__fill(&event->pids, task);
315+
ebpf_ctty__fill(&event->ctty, task);
316+
bpf_get_current_comm(event->comm, TASK_COMM_LEN);
317+
318+
// Variable length fields
319+
ebpf_vl_fields__init(&event->vl_fields);
320+
321+
// tty_out
322+
field = ebpf_vl_field__add(&event->vl_fields, EBPF_VL_FIELD_TTY_OUT);
323+
if (bpf_probe_read_user(field->data, len_cap, base)) {
324+
ret = 1;
325+
goto out;
326+
}
327+
328+
ebpf_vl_field__set_size(&event->vl_fields, field, len_cap);
329+
bpf_ringbuf_output(&ringbuf, event, EVENT_SIZE(event), 0);
330+
out:
331+
return ret;
332+
}
333+
295334
static int tty_write__enter(struct kiocb *iocb, struct iov_iter *from)
296335
{
297-
if (is_consumer())
336+
337+
if (is_consumer()) {
298338
goto out;
339+
}
299340

300341
struct file *f = BPF_CORE_READ(iocb, ki_filp);
301342
struct tty_file_private *tfp = (struct tty_file_private *)BPF_CORE_READ(f, private_data);
@@ -327,44 +368,24 @@ static int tty_write__enter(struct kiocb *iocb, struct iov_iter *from)
327368
goto out;
328369
}
329370

330-
const struct task_struct *task = (struct task_struct *)bpf_get_current_task();
331-
u64 nr_segs = BPF_CORE_READ(from, nr_segs);
332-
nr_segs = nr_segs > MAX_NR_SEGS ? MAX_NR_SEGS : nr_segs;
333-
const struct iovec *iov = BPF_CORE_READ(from, iov);
371+
u64 nr_segs = BPF_CORE_READ(from, nr_segs);
372+
nr_segs = nr_segs > MAX_NR_SEGS ? MAX_NR_SEGS : nr_segs;
373+
const struct iovec *iov = BPF_CORE_READ(from, iov);
334374

335-
for (u8 seg = 0; seg < nr_segs; seg++) {
336-
struct ebpf_process_tty_write_event *event = get_event_buffer();
337-
if (!event)
338-
goto out;
375+
if (nr_segs == 0) {
376+
u64 count = BPF_CORE_READ(from, count);
377+
(void)output_tty_event(&slave, (void *)iov, count);
378+
goto out;
379+
}
339380

381+
for (u8 seg = 0; seg < nr_segs; seg++) {
340382
struct iovec *cur_iov = (struct iovec *)&iov[seg];
341383
const char *base = BPF_CORE_READ(cur_iov, iov_base);
342384
size_t len = BPF_CORE_READ(cur_iov, iov_len);
343-
if (len <= 0)
344-
continue;
345-
346-
event->hdr.type = EBPF_EVENT_PROCESS_TTY_WRITE;
347-
event->hdr.ts = bpf_ktime_get_ns();
348-
u64 len_cap = len > TTY_OUT_MAX ? TTY_OUT_MAX : len;
349-
event->tty_out_truncated = len > TTY_OUT_MAX ? len - TTY_OUT_MAX : 0;
350-
event->tty = slave;
351-
ebpf_pid_info__fill(&event->pids, task);
352-
ebpf_ctty__fill(&event->ctty, task);
353-
bpf_get_current_comm(event->comm, TASK_COMM_LEN);
354-
355-
// Variable length fields
356-
ebpf_vl_fields__init(&event->vl_fields);
357-
struct ebpf_varlen_field *field;
358385

359-
// tty_out
360-
field = ebpf_vl_field__add(&event->vl_fields, EBPF_VL_FIELD_TTY_OUT);
361-
if (bpf_probe_read_user(field->data, len_cap, (void *)base)) {
362-
bpf_printk("tty_write__enter: error reading base\n");
386+
if (output_tty_event(&slave, base, len)) {
363387
goto out;
364388
}
365-
ebpf_vl_field__set_size(&event->vl_fields, field, len_cap);
366-
367-
bpf_ringbuf_output(&ringbuf, event, EVENT_SIZE(event), 0);
368389
}
369390

370391
out:

GPL/HostIsolation/TcFilter/BPFTcFilterTests.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,23 @@ class BPFTcFilterTests : public ::testing::Test
5252

5353
virtual void SetUp() override
5454
{
55-
struct bpf_object_load_attr load_attr = {};
56-
struct bpf_program *prog = nullptr;
57-
char *object_path_env = getenv(OBJECT_PATH_ENV_VAR);
58-
int err = 0;
59-
m_obj = object_path_env == NULL ? bpf_object__open(DEFAULT_OBJECT_PATH)
60-
: bpf_object__open(object_path_env);
55+
struct bpf_program *prog = nullptr;
56+
char *object_path_env = getenv(OBJECT_PATH_ENV_VAR);
57+
int err = 0;
58+
m_obj = object_path_env == NULL ? bpf_object__open(DEFAULT_OBJECT_PATH)
59+
: bpf_object__open(object_path_env);
6160

6261
if (libbpf_get_error(m_obj)) {
6362
FAIL() << "Cannot open ELF object to test, you can pass a custom one with the "
6463
<< OBJECT_PATH_ENV_VAR << " environment variable";
6564
}
66-
load_attr.obj = m_obj;
6765

6866
prog = bpf_object__find_program_by_name(m_obj, CLASSIFIER_SECTION_NAME);
6967
ASSERT_FALSE(prog == NULL);
7068

7169
bpf_program__set_type(prog, BPF_PROG_TYPE_SCHED_CLS);
7270

73-
err = bpf_object__load_xattr(&load_attr);
71+
err = bpf_object__load(m_obj);
7472
if (err) {
7573
FAIL() << "Could not load the bpf program, please check your permissions";
7674
return;

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CONTAINER_PULL_TAG ?= 20221121-1315
1919
CONTAINER_LOCAL_TAG ?= ebpf-builder:${USER}-latest
2020

2121
IMAGEPACK_REPOSITORY ?= ghcr.io/elastic/ebpf-imagepack
22-
IMAGEPACK_PULL_TAG ?= 20220829-2307
22+
IMAGEPACK_PULL_TAG ?= 20230310-1158
2323

2424
ifdef BUILD_CONTAINER_IMAGE
2525
CONTAINER_IMAGE = ${CONTAINER_LOCAL_TAG}

contrib/libbpf/.github/actions/build-selftests/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ runs:
1818
steps:
1919
- shell: bash
2020
run: |
21-
echo "::group::Setup Env"
21+
source $GITHUB_ACTION_PATH/../../../ci/vmtest/helpers.sh
22+
foldable start "Setup Env"
2223
sudo apt-get install -y qemu-kvm zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils
23-
echo "::endgroup::"
24+
foldable end
2425
- shell: bash
2526
run: |
2627
export KERNEL=${{ inputs.kernel }}

contrib/libbpf/.github/actions/build-selftests/build_selftests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ THISDIR="$(cd $(dirname $0) && pwd)"
66

77
source ${THISDIR}/helpers.sh
88

9-
travis_fold start prepare_selftests "Building selftests"
9+
foldable start prepare_selftests "Building selftests"
1010

11-
LLVM_VER=15
11+
LLVM_VER=16
1212
LIBBPF_PATH="${REPO_ROOT}"
1313

1414
PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
@@ -39,4 +39,4 @@ cd ${LIBBPF_PATH}
3939
rm selftests/bpf/.gitignore
4040
git add selftests
4141

42-
travis_fold end prepare_selftests
42+
foldable end prepare_selftests

contrib/libbpf/.github/actions/build-selftests/helpers.sh

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1+
# shellcheck shell=bash
2+
13
# $1 - start or end
24
# $2 - fold identifier, no spaces
35
# $3 - fold section description
4-
travis_fold() {
6+
foldable() {
57
local YELLOW='\033[1;33m'
68
local NOCOLOR='\033[0m'
7-
if [ -z ${GITHUB_WORKFLOW+x} ]; then
8-
echo travis_fold:$1:$2
9+
if [ $1 = "start" ]; then
10+
line="::group::$2"
911
if [ ! -z "${3:-}" ]; then
10-
echo -e "${YELLOW}$3${NOCOLOR}"
12+
line="$line - ${YELLOW}$3${NOCOLOR}"
1113
fi
12-
echo
1314
else
14-
if [ $1 = "start" ]; then
15-
line="::group::$2"
16-
if [ ! -z "${3:-}" ]; then
17-
line="$line - ${YELLOW}$3${NOCOLOR}"
18-
fi
19-
else
20-
line="::endgroup::"
21-
fi
22-
echo -e "$line"
15+
line="::endgroup::"
2316
fi
17+
echo -e "$line"
2418
}
2519

2620
__print() {

0 commit comments

Comments
 (0)