Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpfilter: include bpfilter_umh in assembly instead of using objcopy

What we want here is to embed a user-space program into the kernel.
Instead of the complex ELF magic, let's simply wrap it in the assembly
with the '.incbin' directive.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Masahiro Yamada and committed by
David S. Miller
8e75887d 977c7114

+14 -21
+2 -15
net/bpfilter/Makefile
··· 15 15 HOSTLDFLAGS += -static 16 16 endif 17 17 18 - # a bit of elf magic to convert bpfilter_umh binary into a binary blob 19 - # inside bpfilter_umh.o elf file referenced by 20 - # _binary_net_bpfilter_bpfilter_umh_start symbol 21 - # which bpfilter_kern.c passes further into umh blob loader at run-time 22 - quiet_cmd_copy_umh = GEN $@ 23 - cmd_copy_umh = echo ':' > $(obj)/.bpfilter_umh.o.cmd; \ 24 - $(OBJCOPY) -I binary \ 25 - `LC_ALL=C $(OBJDUMP) -f net/bpfilter/bpfilter_umh \ 26 - |awk -F' |,' '/file format/{print "-O",$$NF} \ 27 - /^architecture:/{print "-B",$$2}'` \ 28 - --rename-section .data=.init.rodata $< $@ 29 - 30 - $(obj)/bpfilter_umh.o: $(obj)/bpfilter_umh 31 - $(call cmd,copy_umh) 18 + $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh 32 19 33 20 obj-$(CONFIG_BPFILTER_UMH) += bpfilter.o 34 - bpfilter-objs += bpfilter_kern.o bpfilter_umh.o 21 + bpfilter-objs += bpfilter_kern.o bpfilter_umh_blob.o
+5 -6
net/bpfilter/bpfilter_kern.c
··· 10 10 #include <linux/file.h> 11 11 #include "msgfmt.h" 12 12 13 - #define UMH_start _binary_net_bpfilter_bpfilter_umh_start 14 - #define UMH_end _binary_net_bpfilter_bpfilter_umh_end 15 - 16 - extern char UMH_start; 17 - extern char UMH_end; 13 + extern char bpfilter_umh_start; 14 + extern char bpfilter_umh_end; 18 15 19 16 static struct umh_info info; 20 17 /* since ip_getsockopt() can run in parallel, serialize access to umh */ ··· 90 93 int err; 91 94 92 95 /* fork usermode process */ 93 - err = fork_usermode_blob(&UMH_start, &UMH_end - &UMH_start, &info); 96 + err = fork_usermode_blob(&bpfilter_umh_start, 97 + &bpfilter_umh_end - &bpfilter_umh_start, 98 + &info); 94 99 if (err) 95 100 return err; 96 101 pr_info("Loaded bpfilter_umh pid %d\n", info.pid);
+7
net/bpfilter/bpfilter_umh_blob.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + .section .init.rodata, "a" 3 + .global bpfilter_umh_start 4 + bpfilter_umh_start: 5 + .incbin "net/bpfilter/bpfilter_umh" 6 + .global bpfilter_umh_end 7 + bpfilter_umh_end: