From patchwork Tue May 23 19:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 98156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2390444vqo; Tue, 23 May 2023 13:09:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58zWxfPTTTOwIYaBo4sIBscH08TORfnNvp87hIHTonoLINwEuOutl80cniyt2Lq9+CZAJn X-Received: by 2002:a17:902:d504:b0:1af:d19a:a67b with SMTP id b4-20020a170902d50400b001afd19aa67bmr2225508plg.33.1684872550066; Tue, 23 May 2023 13:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684872550; cv=none; d=google.com; s=arc-20160816; b=WeeJMKORojbEroCCwthDTPdkx8NFo3RjrvCu8HTZidOKzmvGTkFLr7rp26M8WCHj09 QvRXoIC+91wN0aA5YBtgA5u+HMELPZomJb3fChhG0sfWSr4Nq4wjcJQh2/3czh5YWPPT zpR1hLifWgvRSJqypaCfZ4EsyR4+BmSc3Fsabbvb/mHzSdYGrZ+4NfZN11s9E2J/6A5r S6GbS2mplel6RZGvHzf8E9EBligaZGVnT8tICLMYTE/uNR+A/rft0Jf3AUiEve7Ztjyn x7AiSXwodD4hEydXnbWLxyAsO4rIfBW4aNbpTWMUqqgMx+/Eo5zDESKfz7aQfW2RHM1J jOOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Bl6pRDDZOVD4/aU6DjrpsuXdhJzQ2AzCYc1yewqByow=; b=tpDRVITeGCOHPAGMir+v7AZET1Xw4GAUd+j678iR0xbICmxbZy8Y5pPequGm+arnuk HKB+URQNy1XGWaHO1UxAIDjPdaw1iJ5TNxlivtJ5+i2BGhCpS08zJBwOq9WduESs6chf fRKGB7EARwIDJ606H89sPYqw/Gf6I+nk5dEKTd+gH7MXbMSC/6tRdsk70LRPDtkT5h+F GmJj6yo5wc1Z4NdmUHHrMN0mcA+nV+kg8a1nf/iLHPbbWVwRkUIG1XQl0Q5zIUp9tcA+ qmZ3I40kG5e0GeDrFteAPDyaWHkTsMl5L8a5MhBJzypDpNWU5sAhYwGeecCj9Ovxxjng OZ/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oMQbKI0N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902ec8100b001afb96f4b8fsi325241plg.519.2023.05.23.13.08.55; Tue, 23 May 2023 13:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oMQbKI0N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238488AbjEWTtl (ORCPT + 99 others); Tue, 23 May 2023 15:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjEWTtj (ORCPT ); Tue, 23 May 2023 15:49:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E26E2119 for ; Tue, 23 May 2023 12:49:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7C81162701 for ; Tue, 23 May 2023 19:49:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3827C433D2; Tue, 23 May 2023 19:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684871377; bh=wGtFDXPE8CltQmJ9Fbh/aecZq2T4bSX/gGoZYsF+49Q=; h=From:To:Cc:Subject:Date:From; b=oMQbKI0Nj0UwqawJ3TbFjDbSkvvztGzzZjp2YrN7OJvYD+vJFcZCyydU6kdAJQjhu NAlf2lrJzRw5flZWTMAMVarPR/j+i1+s333STkNgcKC2cmhqD+TV/lxHwaAyeRWBqH PRfd5PM1IShFAHDWpWoSLNJVVA0y3J/bpB5eLiyu4bdEVMMrA65OVDUwgFr05NZUFT u8C+RcCuK4Knv0x+eE6T3SxhPx50u5Mncc97c4i2rY4v9dMbN2QRaj4dFiP8oDHsC9 kaDktqxoy/vLFovbKxqjj00KfGQLlupsY3cYfXtMJNNNst74ncHlF+ag5Vyt0i3npL cASbX5JTIUp/Q== From: Arnd Bergmann To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Arnd Bergmann , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "Jason A. Donenfeld" , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] [v2] bpf: hide unused bpf_patch_call_args Date: Tue, 23 May 2023 21:43:06 +0200 Message-Id: <20230523194930.2116181-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766716919281016793?= X-GMAIL-MSGID: =?utf-8?q?1766716919281016793?= From: Arnd Bergmann This function has no callers and no declaration when CONFIG_BPF_JIT_ALWAYS_ON is enabled: kernel/bpf/core.c:2075:6: error: no previous prototype for 'bpf_patch_call_args' [-Werror=missing-prototypes] Hide the definition as well. Signed-off-by: Arnd Bergmann --- v2: change indentation to align arguments better. Still not great as the line is just too long --- kernel/bpf/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 7421487422d4..0926714641eb 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2064,14 +2064,16 @@ EVAL4(PROG_NAME_LIST, 416, 448, 480, 512) }; #undef PROG_NAME_LIST #define PROG_NAME_LIST(stack_size) PROG_NAME_ARGS(stack_size), -static u64 (*interpreters_args[])(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5, - const struct bpf_insn *insn) = { +static __maybe_unused +u64 (*interpreters_args[])(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5, + const struct bpf_insn *insn) = { EVAL6(PROG_NAME_LIST, 32, 64, 96, 128, 160, 192) EVAL6(PROG_NAME_LIST, 224, 256, 288, 320, 352, 384) EVAL4(PROG_NAME_LIST, 416, 448, 480, 512) }; #undef PROG_NAME_LIST +#ifdef CONFIG_BPF_SYSCALL void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth) { stack_depth = max_t(u32, stack_depth, 1); @@ -2080,6 +2082,7 @@ void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth) __bpf_call_base_args; insn->code = BPF_JMP | BPF_CALL_ARGS; } +#endif #else static unsigned int __bpf_prog_ret0_warn(const void *ctx, From patchwork Tue May 23 19:43:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 98157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2390647vqo; Tue, 23 May 2023 13:09:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7EFVft9hJoizsGYKVrwDUecD7AWD3Ts33KqK1cUTRNN3iMuoecyV1COEGab/jAYFCS8KHs X-Received: by 2002:a17:902:fe18:b0:1aa:e5cd:6478 with SMTP id g24-20020a170902fe1800b001aae5cd6478mr14675872plj.58.1684872579359; Tue, 23 May 2023 13:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684872579; cv=none; d=google.com; s=arc-20160816; b=dRz7yznD9KOW/D3j1ztm3YTXBtphnL/nUruu1+DfeB1ZKY1eGwPcSdq2YW8VqYkmda f6GJlIg28gWh5UEgJehZV7m0Z3eWd/r8kmr/SH280BxZ1LhzQO/t6/aKCBbhHt6Rq7k2 YcVpyFDSgPYM+DbOYqrjO3/zrTftEs0BmNz5Cpn/E0C8AEt2xDHmtUrwI+WoZHUWDDAX eZCEYjAcozSRyxSiTZ1WEeOCd0COeicHpsTwcYY51X6lQbqFqfl2bCrNRWZ/ahl2V16T /+lo/aazLVBN5TkfIzBI8BCjHU17tn81V6ovkJBsaveIH3F6hbj08cRPqBQS6l0YCt+z u3Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d+zcwsA0Oq4H5oxu1j18Hgr/NnVWCXOIPjWNz7p4uIo=; b=wp8LZ09XVWF//088TJrE6dbyZg8mxZU3Vayajxw4Eu+YlTHKcK2zf7iw/WbE3wYHYS K0X0WrXLITvuqqAWOE0TRfQrBNPH8cg3PL64onQ+Cf1FE2B8S2aOJ3PDAnvluLcXvPew KMWtbkf7J9dwSEmGs4W2bENkFTFxtlHOSWbqMC7nIq7ySgWIArIRhfT8Y6tMvOiLuKay EqHO6QvaDbIw9CyF4AkGMdSNwlIWu9cx2dTrMfrT1BwYzJfWZyU88A6ZIRCA/4kES/jW 6R2zlQtVLDm/W34o/uUiY+Pln8cVZXh1ZReG061rhfJrl4KPR79ur5f5tZaFsqzMNsUd +/YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NG455Tl0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a170902eaca00b001adbfba9c29si1278866pld.409.2023.05.23.13.09.26; Tue, 23 May 2023 13:09:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NG455Tl0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238503AbjEWTuK (ORCPT + 99 others); Tue, 23 May 2023 15:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238492AbjEWTuG (ORCPT ); Tue, 23 May 2023 15:50:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C9D184; Tue, 23 May 2023 12:50:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5C13D629C6; Tue, 23 May 2023 19:50:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB75C433D2; Tue, 23 May 2023 19:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684871402; bh=fBS/TFMmP5wWRy24F52O1gwfStwYk0nNfHkwST2oexI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NG455Tl0vWLpNic92+yDmnydWpWAOAAxtUmp/dTwFggd4/CtMVMKZIqB6o9vFVF7p 8ZDXi/cDVJA+QrAgVNU7tQMV9jCFKsRMWPLtUSJ+xCfIELMXFWu1TRAbynXFmudQgG aiILmeO+z++iOIYl7sPUdbqKgBD4n1b94lSXjEpFUVd1qahQuPj5FItjnq7Jc3NJF0 zWet0be6sE9jG5K99mRyWsiTFKPy/Nusdokl4atQTRDYWZ+Oy4QZnfzAjR9q/3OKRs 7E/1vAWF3Hx8Eo7hMopeUmge8NDk8zlNHs8cjjORHyVNWUOsZUbb670U8CMOqTpidz XARRjGUWtsBRw== From: Arnd Bergmann To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Steven Rostedt , Masami Hiramatsu Cc: Arnd Bergmann , stable@vger.kernel.org, Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Kumar Kartikeya Dwivedi , Dave Marchevsky , Joanne Koong , Delyan Kratunov , Peter Zijlstra , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 2/2] [v2] bpf: fix bpf_probe_read_kernel prototype mismatch Date: Tue, 23 May 2023 21:43:07 +0200 Message-Id: <20230523194930.2116181-2-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523194930.2116181-1-arnd@kernel.org> References: <20230523194930.2116181-1-arnd@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766716949616018739?= X-GMAIL-MSGID: =?utf-8?q?1766716949616018739?= From: Arnd Bergmann bpf_probe_read_kernel() has a __weak definition in core.c and another definition with an incompatible prototype in kernel/trace/bpf_trace.c, when CONFIG_BPF_EVENTS is enabled. Since the two are incompatible, there cannot be a shared declaration in a header file, but the lack of a prototype causes a W=1 warning: kernel/bpf/core.c:1638:12: error: no previous prototype for 'bpf_probe_read_kernel' [-Werror=missing-prototypes] Change the core.c file to only reference the inner bpf_probe_read_kernel_common() helper and provide a prototype for that. Aside from the warning, this addresses a bug on 32-bit architectures from incorrect argument passing with the mismatched prototype. Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann --- v2: rewrite completely to fix the mismatch. --- include/linux/bpf.h | 2 ++ kernel/bpf/core.c | 9 ++++++--- kernel/trace/bpf_trace.c | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 36e4b2d8cca2..6a231ec61a87 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2619,6 +2619,8 @@ static inline void bpf_dynptr_set_rdonly(struct bpf_dynptr_kern *ptr) } #endif /* CONFIG_BPF_SYSCALL */ +int bpf_probe_read_kernel_common(void *dst, u32 size, const void *unsafe_ptr); + void __bpf_free_used_btfs(struct bpf_prog_aux *aux, struct btf_mod_pair *used_btfs, u32 len); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 0926714641eb..e7f0d5f146fa 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -1635,11 +1636,13 @@ bool bpf_opcode_in_insntable(u8 code) } #ifndef CONFIG_BPF_JIT_ALWAYS_ON -u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr) +#ifndef CONFIG_BPF_EVENTS +int bpf_probe_read_kernel_common(void * dst, u32 size, const void *unsafe_ptr) { memset(dst, 0, size); return -EFAULT; } +#endif /** * ___bpf_prog_run - run eBPF program on a given context @@ -1931,8 +1934,8 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) DST = *(SIZE *)(unsigned long) (SRC + insn->off); \ CONT; \ LDX_PROBE_MEM_##SIZEOP: \ - bpf_probe_read_kernel(&DST, sizeof(SIZE), \ - (const void *)(long) (SRC + insn->off)); \ + bpf_probe_read_kernel_common(&DST, sizeof(SIZE), \ + (const void *)(long) (SRC + insn->off)); \ DST = *((SIZE *)&DST); \ CONT; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 2bc41e6ac9fe..290fdce2ce53 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -223,8 +223,7 @@ const struct bpf_func_proto bpf_probe_read_user_str_proto = { .arg3_type = ARG_ANYTHING, }; -static __always_inline int -bpf_probe_read_kernel_common(void *dst, u32 size, const void *unsafe_ptr) +int bpf_probe_read_kernel_common(void *dst, u32 size, const void *unsafe_ptr) { int ret;