Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y \
libbfd-dev libcap-dev libelf-dev libiberty-dev python3-docutils
libbfd-dev libcap-dev libelf-dev libiberty-dev libssl-dev \
python3-docutils
# clang/LLVM are already installed, but we're missing some aliases.
CLANG_VERSION="$(echo '__clang_major__' | clang -E - | tail -n 1)"
sudo update-alternatives \
Expand Down Expand Up @@ -79,11 +80,11 @@ jobs:
# FIXME - See #73
echo "... building bootstrap bpftool"
EXTRA_LDFLAGS=-static make -j -C src V=1 \
LIBS="./bootstrap/libbpf/libbpf.a -lelf -lz -lzstd -lcap -lbfd -ldl -liberty -lz -lzstd -lsframe -lopcodes" \
LIBS="./bootstrap/libbpf/libbpf.a -lelf -lz -lcrypto -lzstd -lcap -lbfd -ldl -liberty -lz -lzstd -lsframe -lopcodes" \
bootstrap
echo "... building main bpftool binary"
EXTRA_LDFLAGS=-static make -j -C src V=1 \
LIBS="./libbpf/libbpf.a -lelf -lz -lzstd -lcap -lbfd -ldl -liberty -lz -lzstd -lsframe -lopcodes"
LIBS="./libbpf/libbpf.a -lelf -lz -lcrypto -lzstd -lcap -lbfd -ldl -liberty -lz -lzstd -lsframe -lopcodes"
else
EXTRA_LDFLAGS=-static make -j -C src V=1
fi
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
if: matrix.arch == 'amd64'
run: |
sudo apt-get update
sudo apt-get install -y libelf-dev libcap-dev
sudo apt-get install -y libelf-dev libcap-dev libssl-dev

- name: Download and extract compiled LLVM release
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libelf-dev
sudo apt-get install -y libelf-dev libssl-dev

- name: Download and extract compiled LLVM release
run: |
Expand Down
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Quentin Monnet <qmo@kernel.org> <quentin@isovalent.com>
Stanislav Fomichev <sdf@fomichev.me> <sdf@google.com>
Thorsten Blum <thorsten.blum@linux.dev> <thorsten.blum@toblux.com>
Vadim Fedorenko <vadim.fedorenko@linux.dev> <vadfed@meta.com>
Vincent Mailhol <mailhol@kernel.org> <mailhol.vincent@wanadoo.fr>
Yanteng Si <si.yanteng@linux.dev> <siyanteng@loongson.cn>
2 changes: 1 addition & 1 deletion BPF-CHECKPOINT-COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27861fc720be2c39b861d8bdfb68287f54de6855
4d920ed684392ae064af62957d6f5a90312dfaf6
2 changes: 1 addition & 1 deletion CHECKPOINT-COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21aeabb68258ce17b91af113a768760b3a491d93
de7342228b7343774d6a9981c2ddbfb5e201044b
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN \
libelf-dev \
libz-dev \
libcap-dev \
libssl-dev \
clang llvm llvm-dev lld \
binutils-dev \
pkg-config && \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Dependencies
Required:

- libelf
- libssl-dev
- zlib

Optional:
Expand Down
26 changes: 17 additions & 9 deletions bash-completion/bpftool
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ _bpftool()
# Deal with options
if [[ ${words[cword]} == -* ]]; then
local c='--version --json --pretty --bpffs --mapcompat --debug \
--use-loader --base-btf'
--use-loader --base-btf --sign -i -k'
COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
return 0
fi
Expand All @@ -283,7 +283,7 @@ _bpftool()
_sysfs_get_netdevs
return 0
;;
file|pinned|-B|--base-btf)
file|pinned|-B|--base-btf|-i|-k)
_filedir
return 0
;;
Expand All @@ -296,13 +296,21 @@ _bpftool()
# Remove all options so completions don't have to deal with them.
local i pprev
for (( i=1; i < ${#words[@]}; )); do
if [[ ${words[i]::1} == - ]] &&
[[ ${words[i]} != "-B" ]] && [[ ${words[i]} != "--base-btf" ]]; then
words=( "${words[@]:0:i}" "${words[@]:i+1}" )
[[ $i -le $cword ]] && cword=$(( cword - 1 ))
else
i=$(( ++i ))
fi
case ${words[i]} in
# Remove option and its argument
-B|--base-btf|-i|-k)
words=( "${words[@]:0:i}" "${words[@]:i+2}" )
[[ $i -le $(($cword + 1)) ]] && cword=$(( cword - 2 ))
;;
# No argument, remove option only
-*)
words=( "${words[@]:0:i}" "${words[@]:i+1}" )
[[ $i -le $cword ]] && cword=$(( cword - 1 ))
;;
*)
i=$(( ++i ))
;;
esac
done
cur=${words[cword]}
prev=${words[cword - 1]}
Expand Down
13 changes: 12 additions & 1 deletion docs/bpftool-gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SYNOPSIS

**bpftool** [*OPTIONS*] **gen** *COMMAND*

*OPTIONS* := { |COMMON_OPTIONS| | { **-L** | **--use-loader** } }
*OPTIONS* := { |COMMON_OPTIONS| | { **-L** | **--use-loader** } | [ { **-S** | **--sign** } {**-k** <private_key.pem>} **-i** <certificate.x509> ] }

*COMMAND* := { **object** | **skeleton** | **help** }

Expand Down Expand Up @@ -186,6 +186,17 @@ OPTIONS
skeleton). A light skeleton contains a loader eBPF program. It does not use
the majority of the libbpf infrastructure, and does not need libelf.

-S, --sign
For skeletons, generate a signed skeleton. This option must be used with
**-k** and **-i**. Using this flag implicitly enables **--use-loader**.

-k <private_key.pem>
Path to the private key file in PEM format, required for signing.

-i <certificate.x509>
Path to the X.509 certificate file in PEM or DER format, required for
signing.

EXAMPLES
========
**$ cat example1.bpf.c**
Expand Down
14 changes: 13 additions & 1 deletion docs/bpftool-prog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SYNOPSIS

*OPTIONS* := { |COMMON_OPTIONS| |
{ **-f** | **--bpffs** } | { **-m** | **--mapcompat** } | { **-n** | **--nomount** } |
{ **-L** | **--use-loader** } }
{ **-L** | **--use-loader** } | [ { **-S** | **--sign** } **-k** <private_key.pem> **-i** <certificate.x509> ] }

*COMMANDS* :=
{ **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** |
Expand Down Expand Up @@ -248,6 +248,18 @@ OPTIONS
creating the maps, and loading the programs (see **bpftool prog tracelog**
as a way to dump those messages).

-S, --sign
Enable signing of the BPF program before loading. This option must be
used with **-k** and **-i**. Using this flag implicitly enables
**--use-loader**.

-k <private_key.pem>
Path to the private key file in PEM format, required when signing.

-i <certificate.x509>
Path to the X.509 certificate file in PEM or DER format, required when
signing.

EXAMPLES
========
**# bpftool prog show**
Expand Down
24 changes: 23 additions & 1 deletion include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,12 @@ union bpf_attr {
* If provided, map_flags should have BPF_F_TOKEN_FD flag set.
*/
__s32 map_token_fd;

/* Hash of the program that has exclusive access to the map.
*/
__aligned_u64 excl_prog_hash;
/* Size of the passed excl_prog_hash. */
__u32 excl_prog_hash_size;
};

struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */
Expand Down Expand Up @@ -1605,6 +1611,16 @@ union bpf_attr {
* continuous.
*/
__u32 fd_array_cnt;
/* Pointer to a buffer containing the signature of the BPF
* program.
*/
__aligned_u64 signature;
/* Size of the signature buffer in bytes. */
__u32 signature_size;
/* ID of the kernel keyring to be used for signature
* verification.
*/
__s32 keyring_id;
};

struct { /* anonymous struct used by BPF_OBJ_* commands */
Expand Down Expand Up @@ -4875,7 +4891,7 @@ union bpf_attr {
*
* **-ENOENT** if the bpf_local_storage cannot be found.
*
* long bpf_d_path(struct path *path, char *buf, u32 sz)
* long bpf_d_path(const struct path *path, char *buf, u32 sz)
* Description
* Return full path for given **struct path** object, which
* needs to be the kernel BTF *path* object. The path is
Expand Down Expand Up @@ -6666,6 +6682,8 @@ struct bpf_map_info {
__u32 btf_value_type_id;
__u32 btf_vmlinux_id;
__u64 map_extra;
__aligned_u64 hash;
__u32 hash_size;
} __attribute__((aligned(8)));

struct bpf_btf_info {
Expand Down Expand Up @@ -7418,6 +7436,10 @@ struct bpf_timer {
__u64 __opaque[2];
} __attribute__((aligned(8)));

struct bpf_task_work {
__u64 __opaque;
} __attribute__((aligned(8)));

struct bpf_wq {
__u64 __opaque[2];
} __attribute__((aligned(8)));
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ ifeq ($(check_feat),1)
include Makefile.feature
endif

LIBS = $(LIBBPF) -lelf -lz
LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
LIBS = $(LIBBPF) -lelf -lz -lcrypto
LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz -lcrypto

ifeq ($(feature-libelf-zstd),1)
LIBS += -lzstd
Expand Down Expand Up @@ -188,7 +188,7 @@ endif

BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftool

BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o)
BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT),main.o common.o json_writer.o gen.o btf.o sign.o)
$(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP)

OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Expand Down
2 changes: 1 addition & 1 deletion src/btf_dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
__u32 info_len = sizeof(info);
const char *prog_name = NULL;
struct btf *prog_btf = NULL;
struct bpf_func_info finfo;
struct bpf_func_info finfo = {};
__u32 finfo_rec_size;
char prog_str[1024];
int err;
Expand Down
4 changes: 4 additions & 0 deletions src/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Copyright (C) 2017 Facebook
// Author: Roman Gushchin <guro@fb.com>

#undef GCC_VERSION
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#define _XOPEN_SOURCE 500
#include <errno.h>
#include <fcntl.h>
Expand Down
93 changes: 93 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/utsname.h>

#include <linux/filter.h>
#include <linux/limits.h>
Expand All @@ -31,6 +32,7 @@
#include <bpf/hashmap.h>
#include <bpf/libbpf.h> /* libbpf_num_possible_cpus */
#include <bpf/btf.h>
#include <zlib.h>

#include "main.h"

Expand Down Expand Up @@ -1208,3 +1210,94 @@ int pathname_concat(char *buf, int buf_sz, const char *path,

return 0;
}

static bool read_next_kernel_config_option(gzFile file, char *buf, size_t n,
char **value)
{
char *sep;

while (gzgets(file, buf, n)) {
if (strncmp(buf, "CONFIG_", 7))
continue;

sep = strchr(buf, '=');
if (!sep)
continue;

/* Trim ending '\n' */
buf[strlen(buf) - 1] = '\0';

/* Split on '=' and ensure that a value is present. */
*sep = '\0';
if (!sep[1])
continue;

*value = sep + 1;
return true;
}

return false;
}

int read_kernel_config(const struct kernel_config_option *requested_options,
size_t num_options, char **out_values,
const char *define_prefix)
{
struct utsname utsn;
char path[PATH_MAX];
gzFile file = NULL;
char buf[4096];
char *value;
size_t i;
int ret = 0;

if (!requested_options || !out_values || num_options == 0)
return -1;

if (!uname(&utsn)) {
snprintf(path, sizeof(path), "/boot/config-%s", utsn.release);

/* gzopen also accepts uncompressed files. */
file = gzopen(path, "r");
}

if (!file) {
/* Some distributions build with CONFIG_IKCONFIG=y and put the
* config file at /proc/config.gz.
*/
file = gzopen("/proc/config.gz", "r");
}

if (!file) {
p_info("skipping kernel config, can't open file: %s",
strerror(errno));
return -1;
}

if (!gzgets(file, buf, sizeof(buf)) || !gzgets(file, buf, sizeof(buf))) {
p_info("skipping kernel config, can't read from file: %s",
strerror(errno));
ret = -1;
goto end_parse;
}

if (strcmp(buf, "# Automatically generated file; DO NOT EDIT.\n")) {
p_info("skipping kernel config, can't find correct file");
ret = -1;
goto end_parse;
}

while (read_next_kernel_config_option(file, buf, sizeof(buf), &value)) {
for (i = 0; i < num_options; i++) {
if ((define_prefix && !requested_options[i].macro_dump) ||
out_values[i] || strcmp(buf, requested_options[i].name))
continue;

out_values[i] = strdup(value);
}
}

end_parse:
gzclose(file);
return ret;
}
Loading
Loading