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;