From patchwork Fri Jun 8 17:12:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 926926 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=socionext.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="1X4ti/Vi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 412Td674ypz9s3q for ; Sat, 9 Jun 2018 03:18:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752734AbeFHRSA (ORCPT ); Fri, 8 Jun 2018 13:18:00 -0400 Received: from condef-02.nifty.com ([202.248.20.67]:48618 "EHLO condef-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752609AbeFHRSA (ORCPT ); Fri, 8 Jun 2018 13:18:00 -0400 Received: from conuserg-10.nifty.com ([10.126.8.73])by condef-02.nifty.com with ESMTP id w58HD11U017382 for ; Sat, 9 Jun 2018 02:13:01 +0900 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w58HCbWD008555; Sat, 9 Jun 2018 02:12:38 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w58HCbWD008555 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1528477959; bh=Sd1Qm6teZwiLGXhmsz3xxi5lf/RE2OzLHlD/svAXNgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1X4ti/ViTRN2s8Nu38NgXgI4zrDwizOminDyNHlH7gQl3OgFnzHpt+MHohh7vaYLu Jij8VoIjpOS/cZKbG3eCFhr+6SP8GpTTHDWfVxF7HHc671pwQAap36LF/tJLuCppTi tBBQQ0GoqexokPrtfeVRuOIYzLCesOzAorxk9lO/ANHpKtQuuFXZY6p5Jo6mc2Llhv QQqnJSNwRdSNPOxRSxd+OqfW7MIexM48uSkIXMbfIhJjuU0D9WjzAgA4XFmjXv6sN0 Dy4EBMJTNVDkqpZKf9muTlaZeThG10338kHp/E6N/4GIVY4HhZdqBm2BuxWFQLEsG5 m8A6D1e6terGw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: netdev@vger.kernel.org, Alexei Starovoitov , "David S . Miller" Cc: Arnd Bergmann , Geert Uytterhoeven , linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 1/3] bpfilter: add bpfilter_umh to .gitignore Date: Sat, 9 Jun 2018 02:12:08 +0900 Message-Id: <1528477930-7342-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528477930-7342-1-git-send-email-yamada.masahiro@socionext.com> References: <1528477930-7342-1-git-send-email-yamada.masahiro@socionext.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org bpfilter_umh is a generated file. It should be ignored by git. Signed-off-by: Masahiro Yamada --- net/bpfilter/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 net/bpfilter/.gitignore diff --git a/net/bpfilter/.gitignore b/net/bpfilter/.gitignore new file mode 100644 index 0000000..e97084e --- /dev/null +++ b/net/bpfilter/.gitignore @@ -0,0 +1 @@ +bpfilter_umh From patchwork Fri Jun 8 17:12:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 926929 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=socionext.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="HlpMIzZr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 412Tdg4VlWz9s1B for ; Sat, 9 Jun 2018 03:18:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752774AbeFHRS3 (ORCPT ); Fri, 8 Jun 2018 13:18:29 -0400 Received: from condef-01.nifty.com ([202.248.20.66]:53835 "EHLO condef-01.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752428AbeFHRS2 (ORCPT ); Fri, 8 Jun 2018 13:18:28 -0400 Received: from conuserg-10.nifty.com ([10.126.8.73])by condef-01.nifty.com with ESMTP id w58HD287013111 for ; Sat, 9 Jun 2018 02:13:02 +0900 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w58HCbWE008555; Sat, 9 Jun 2018 02:12:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w58HCbWE008555 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1528477959; bh=3fLffJiYmwD8bzV7ahcnO+qtPUZUdR4W/9XZvG6Vxts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HlpMIzZrH1qoHQJxIiXlbpgC8JD0mWn4HnynCvA1B+aMTnHlaQOy8Kmndx8KlsK14 qZCCeDFPksGVALc6SVJPSihpHmsWuA+GYPtN/dszSlsgNB2gY41wwSleGtokW4jRm+ 0CGbIasK1nIVC5FG3SbMI/eWAlAXdUv49X+J2c95oGizMrADtJ9c5V6CsU0wiVZfMX OzrhhMtxIBb8ARLEiCfpgt834zH2ypRHOYrAnrLq4ExZW1V/WLprLxGd6Pbf+bDhBf Az2OypVeoRqO1CdZvqtM05N8IrBL10kh5ZJEMcuR7B2w4VJcEYjMHvtvFHXUGmInIS RikyHQrtuHxIg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: netdev@vger.kernel.org, Alexei Starovoitov , "David S . Miller" Cc: Arnd Bergmann , Geert Uytterhoeven , linux-kernel@vger.kernel.org, Masahiro Yamada , YueHaibing Subject: [PATCH 2/3] bpfilter: include bpfilter_umh in assembly instead of using objcopy Date: Sat, 9 Jun 2018 02:12:09 +0900 Message-Id: <1528477930-7342-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528477930-7342-1-git-send-email-yamada.masahiro@socionext.com> References: <1528477930-7342-1-git-send-email-yamada.masahiro@socionext.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Do not use the troublesome ELF magic. What is happening here is to embed a user-space program into the kernel. Simply wrap it in the assembly with the '.incbin' directive. Signed-off-by: Masahiro Yamada --- net/bpfilter/Makefile | 15 ++------------- net/bpfilter/bpfilter_kern.c | 11 +++++------ net/bpfilter/bpfilter_umh_blob.S | 7 +++++++ 3 files changed, 14 insertions(+), 19 deletions(-) create mode 100644 net/bpfilter/bpfilter_umh_blob.S diff --git a/net/bpfilter/Makefile b/net/bpfilter/Makefile index aafa720..39c6980 100644 --- a/net/bpfilter/Makefile +++ b/net/bpfilter/Makefile @@ -15,18 +15,7 @@ ifeq ($(CONFIG_BPFILTER_UMH), y) HOSTLDFLAGS += -static endif -# a bit of elf magic to convert bpfilter_umh binary into a binary blob -# inside bpfilter_umh.o elf file referenced by -# _binary_net_bpfilter_bpfilter_umh_start symbol -# which bpfilter_kern.c passes further into umh blob loader at run-time -quiet_cmd_copy_umh = GEN $@ - cmd_copy_umh = echo ':' > $(obj)/.bpfilter_umh.o.cmd; \ - $(OBJCOPY) -I binary -O $(CONFIG_OUTPUT_FORMAT) \ - -B `$(OBJDUMP) -f $<|grep architecture|cut -d, -f1|cut -d' ' -f2` \ - --rename-section .data=.init.rodata $< $@ - -$(obj)/bpfilter_umh.o: $(obj)/bpfilter_umh - $(call cmd,copy_umh) +$(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh obj-$(CONFIG_BPFILTER_UMH) += bpfilter.o -bpfilter-objs += bpfilter_kern.o bpfilter_umh.o +bpfilter-objs += bpfilter_kern.o bpfilter_umh_blob.o diff --git a/net/bpfilter/bpfilter_kern.c b/net/bpfilter/bpfilter_kern.c index b13d058..fcc1a7c 100644 --- a/net/bpfilter/bpfilter_kern.c +++ b/net/bpfilter/bpfilter_kern.c @@ -10,11 +10,8 @@ #include #include "msgfmt.h" -#define UMH_start _binary_net_bpfilter_bpfilter_umh_start -#define UMH_end _binary_net_bpfilter_bpfilter_umh_end - -extern char UMH_start; -extern char UMH_end; +extern char bpfilter_umh_start; +extern char bpfilter_umh_end; static struct umh_info info; /* since ip_getsockopt() can run in parallel, serialize access to umh */ @@ -89,7 +86,9 @@ static int __init load_umh(void) int err; /* fork usermode process */ - err = fork_usermode_blob(&UMH_start, &UMH_end - &UMH_start, &info); + err = fork_usermode_blob(&bpfilter_umh_end, + &bpfilter_umh_end - &bpfilter_umh_start, + &info); if (err) return err; pr_info("Loaded bpfilter_umh pid %d\n", info.pid); diff --git a/net/bpfilter/bpfilter_umh_blob.S b/net/bpfilter/bpfilter_umh_blob.S new file mode 100644 index 0000000..40311d1 --- /dev/null +++ b/net/bpfilter/bpfilter_umh_blob.S @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + .section .init.rodata, "a" + .global bpfilter_umh_start +bpfilter_umh_start: + .incbin "net/bpfilter/bpfilter_umh" + .global bpfilter_umh_end +bpfilter_umh_end: From patchwork Fri Jun 8 17:12:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 926932 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=socionext.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="XyXVS+t7"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 412ThG1B1Bz9s1B for ; Sat, 9 Jun 2018 03:20:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932181AbeFHRUn (ORCPT ); Fri, 8 Jun 2018 13:20:43 -0400 Received: from condef-03.nifty.com ([202.248.20.68]:44446 "EHLO condef-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932130AbeFHRUl (ORCPT ); Fri, 8 Jun 2018 13:20:41 -0400 Received: from conuserg-10.nifty.com ([10.126.8.73])by condef-03.nifty.com with ESMTP id w58HD1xA021319 for ; Sat, 9 Jun 2018 02:13:01 +0900 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w58HCbWF008555; Sat, 9 Jun 2018 02:12:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w58HCbWF008555 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1528477960; bh=sFOR8yPtAuS5GqeUxlJjV5u9vMKxeK8qrl3vZ67e+B8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XyXVS+t7bL0S4pTNtX4JYs8XZw7iQqbNG/93vjhxGbk4g0299O91tGr2RyE0RRPfN 9CyEpQ/4nLuTtTupdchKKmiIeLbK/1Vc5AUikQNk7/UaAMuuWA+OtZ7U+cAwk7t118 aTSP6XnA7hFZSLxJgg58BvL3moI75Rz+xNASLUCaVAZcSuRNTVBC4CzTbgtCChaByJ BL3K28mJT6kqNO+qdGCx+sN4Ru9g01AilX6E3r6PP58TdLoixZSecu+TANRk9XFi+E ch3lJM043w/GXpL2NJYsb4LIdDFXQKFS5YfXd4ARxGCdYjDB3k2v7Il/1tJ7+U6upn XcjEAyvQ3Of2w== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: netdev@vger.kernel.org, Alexei Starovoitov , "David S . Miller" Cc: Arnd Bergmann , Geert Uytterhoeven , linux-kernel@vger.kernel.org, Masahiro Yamada , YueHaibing Subject: [PATCH 3/3] bpfilter: do not (ab)use host-program build rule Date: Sat, 9 Jun 2018 02:12:10 +0900 Message-Id: <1528477930-7342-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528477930-7342-1-git-send-email-yamada.masahiro@socionext.com> References: <1528477930-7342-1-git-send-email-yamada.masahiro@socionext.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It is an ugly hack to overwrite $(HOSTCC) with $(CC) to reuse the build rules from scripts/Makefile.host. It should not be tedious to write a build rule for its own. Signed-off-by: Masahiro Yamada --- net/bpfilter/Makefile | 17 +++++++++++------ net/bpfilter/{main.c => bpfilter_umh.c} | 0 2 files changed, 11 insertions(+), 6 deletions(-) rename net/bpfilter/{main.c => bpfilter_umh.c} (100%) diff --git a/net/bpfilter/Makefile b/net/bpfilter/Makefile index 39c6980..6571b30 100644 --- a/net/bpfilter/Makefile +++ b/net/bpfilter/Makefile @@ -3,18 +3,23 @@ # Makefile for the Linux BPFILTER layer. # -hostprogs-y := bpfilter_umh -bpfilter_umh-objs := main.o -HOSTCFLAGS += -I. -Itools/include/ -Itools/include/uapi -HOSTCC := $(CC) - ifeq ($(CONFIG_BPFILTER_UMH), y) # builtin bpfilter_umh should be compiled with -static # since rootfs isn't mounted at the time of __init # function is called and do_execv won't find elf interpreter -HOSTLDFLAGS += -static +STATIC := -static endif +quiet_cmd_cc_user = CC $@ + cmd_cc_user = $(CC) -Wall -Wmissing-prototypes -O2 -std=gnu89 \ + -I$(srctree) -I$(srctree)/tools/include/ \ + -I$(srctree)/tools/include/uapi $(STATIC) -o $@ $< + +$(obj)/bpfilter_umh: $(src)/bpfilter_umh.c FORCE + $(call if_changed,cc_user) + +targets += bpfilter_umh + $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh obj-$(CONFIG_BPFILTER_UMH) += bpfilter.o diff --git a/net/bpfilter/main.c b/net/bpfilter/bpfilter_umh.c similarity index 100% rename from net/bpfilter/main.c rename to net/bpfilter/bpfilter_umh.c