Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2028674imm; Thu, 14 Jun 2018 07:41:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLP9/6Icu4LKNYCfcWQgJV1qkxUZLbenELsQ3IYtn1Mh8LYbPcdfRU/JPi3MpSDTA76Zhnp X-Received: by 2002:a65:418b:: with SMTP id a11-v6mr2587193pgq.118.1528987303742; Thu, 14 Jun 2018 07:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528987303; cv=none; d=google.com; s=arc-20160816; b=B+eU40BUds9TGz4UD7ZuIJGcsCqoCDwE+Q5bHULtA8K5dIn6Xfdtab1F8FMzCktUv5 6U2rhwT+HoNJNEi1q1MxpqGxL/1ZO6+ZDNmFvOBJJCgTK+Aui6TtH6euriSQHlT4uGfU 7b7X0FtRQlQy743OtLxlcLAmVsC9M7fclBTE6x3Agjowi/K6HJ9T6nTrzeLWpIXyNDpH 1xQzmXHmYR87cDoUHvtLjk6noFhvlwE88PPTaPo84twjGD6pFDg3gq6h2UsFS2sUgy6F f7IP3uksbSQ0BgL8kI8/j1AdxNjhQL1aw882IoOoSZcC3rU58jDL9o+cQY5u5C/gPMQl RlTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=tmTyhO6OIXehQWiorNqeVmCzDlr9Ni0o/0nc+xxAIbA=; b=ynqENt2/DpgiS9we4s+M8+jAmaisUHqYeSKKD0kOsPL2l3htLd2eolUnhzEJl4EKFe W1jU5VBCNUwurWNhyB2uIfBHmIW8P9wr8KRS9diz+czx33KjA+CVFMWMJN772JEEMxjr Y8M+Ta7M5/RV6/jd3LaK0+mzicVhxhZqlvz2aH1vEXUufbqRm95mfreJ/YjBORQMiqv7 EbDL8c7p+lyKOaejZF35BlmqQMa5K3i35zxZ8wGXM4GSRHFjYEacuHs10U0zcPxf32Ik u0kalF77hGorCPoFNvgmyieYHWmCnlnOPnGGnnk0gYiwKcVaVkAwUW5sFMdBKGAKuwjG Q4Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pkoJvsSF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 81-v6si5135546pfz.334.2018.06.14.07.41.29; Thu, 14 Jun 2018 07:41:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pkoJvsSF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965551AbeFNOkb (ORCPT + 99 others); Thu, 14 Jun 2018 10:40:31 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:29290 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965709AbeFNOk1 (ORCPT ); Thu, 14 Jun 2018 10:40:27 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-09.nifty.com with ESMTP id w5EEdw8o010795; Thu, 14 Jun 2018 23:40:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w5EEdw8o010795 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1528987201; bh=tmTyhO6OIXehQWiorNqeVmCzDlr9Ni0o/0nc+xxAIbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pkoJvsSFadrtbAU9Mq8tumtyp4drkxyk1y0sQLym7SkjsolgkVHPrOj4ccV+v5FUC uoOs9x1jU19OQ5Ybdhel62pwZ2xbXTEz+kk1+oZbJm4jkiQ24/8C/MKS0M4Kc/LgAO U4yIzx8B6AX6zkSOkCPohDpaAhylmQLTSNqtJ0At9+aBWXDpgeonELCjhBmVVigfz4 fuG775k1Z8fjhxsau73VskDuhwwVuF3+GprEsV2PrBh0PctoTEXv9jRbYPQkd42mcZ 4KtAFNozAeuSxW8qnsl3JAG/v0opiYHwrDe+URjbq4GFng+T/eG+LqPRWEMjtMGVAP 9FBlsoZgEiNbQ== 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 , Alexei Starovoitov , YueHaibing Subject: [PATCH v2 2/3] bpfilter: include bpfilter_umh in assembly instead of using objcopy Date: Thu, 14 Jun 2018 23:39:31 +0900 Message-Id: <1528987172-19810-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528987172-19810-1-git-send-email-yamada.masahiro@socionext.com> References: <1528987172-19810-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v2: - Rebase 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 e0bbe75..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 `$(OBJDUMP) -f $<|grep format|cut -d' ' -f8` \ - -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 0952257..6de3ae5 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 */ @@ -93,7 +90,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: -- 2.7.4