Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2004776pxb; Fri, 25 Mar 2022 09:25:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2UFaPyj9gy55vxlextnuzl+Zc4vS3Nuh6jr2cDp5ZeDpPpyo8Z1zXPsBIH096FdkyX014 X-Received: by 2002:a50:cfc4:0:b0:413:b19d:d9c0 with SMTP id i4-20020a50cfc4000000b00413b19dd9c0mr14254050edk.384.1648225512910; Fri, 25 Mar 2022 09:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648225512; cv=none; d=google.com; s=arc-20160816; b=S9qxyJ3zihBn7iZdbCAFBHrf9YTwajeXbvA/gdHUkQ+kTu8i1KxLLLquo3DyXvqOXv Rj6WD4aKxcNfUGT/07bhHyqpd9Cd0Jr6llkxiPpdqPf2LcG8VJdqe80h/E909qQBBmIw 4Pn64C9J8tqgSaCdSB1OQgBDiG0Af2Xnzsu9LzAYXcP+KgM45EOEaMxpZ203sHl2bGuy UmTSRLpIC5TXW3gNS7NcAsFGA+bqv7NBYjcALujre2HGi978OtftO8nGe++jwfw5f5Um aroglPkVXx0Zz7tN5NM9kDUEhUjD9B18LXago2amcwZrWxxl6LNbUNum2j6jGWO1rJ+L z9zw== 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; bh=kmytIE62XnfcP/MqxOfthe95cErybQOMwyQ9iIgfboY=; b=Nr/b5paNZG4VVhejZPAyTfkR/YgBFGk8cm9UE3O+d+j5pSQHDCHkpYRrlGQgekgFj0 SaeYlhMIIwdVnPVAG6XMvcArHdkucigIT1Sf7xE01oOf2/hHdc678imIgSphJNaH844v MU+hwy1nFo6TIzImzQ7n9mCluRjEFMS3tBRJbNk4oyX7GYDPmC849+2wG4td9R6jfsiG MX5Y6Rr2E5PbMLTRmNh96LaR1XctpqsEbQeqrRsw4/1/nYLXFcxEEn8efVBgVJWMnXiq GGZTVJuBLkGGUk3ompMrANGFP23oUL/3l+47UCTu/KEXDIc+kUEQJH786dNsJ/zS13Xw g1Sg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020a509b50000000b00418d8b5b7easi3267690edj.449.2022.03.25.09.24.32; Fri, 25 Mar 2022 09:25:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346623AbiCXAJN (ORCPT + 99 others); Wed, 23 Mar 2022 20:09:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240367AbiCXAJK (ORCPT ); Wed, 23 Mar 2022 20:09:10 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 206C28CCD1 for ; Wed, 23 Mar 2022 17:07:38 -0700 (PDT) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=phil.lan) by gloria.sntech.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nXB0k-00055s-Ts; Thu, 24 Mar 2022 01:07:30 +0100 From: Heiko Stuebner To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, wefu@redhat.com, liush@allwinnertech.com, guoren@kernel.org, atishp@atishpatra.org, anup@brainfault.org, drew@beagleboard.org, hch@lst.de, arnd@arndb.de, wens@csie.org, maxime@cerno.tech, gfavor@ventanamicro.com, andrea.mondelli@huawei.com, behrensj@mit.edu, xinhaoqu@huawei.com, mick@ics.forth.gr, allen.baum@esperantotech.com, jscheid@ventanamicro.com, rtrauben@gmail.com, samuel@sholland.org, cmuellner@linux.com, philipp.tomsich@vrull.eu, Heiko Stuebner , Atish Patra Subject: [PATCH v8 01/14] riscv: prevent null-pointer dereference with sbi_remote_fence_i Date: Thu, 24 Mar 2022 01:06:57 +0100 Message-Id: <20220324000710.575331-2-heiko@sntech.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324000710.575331-1-heiko@sntech.de> References: <20220324000710.575331-1-heiko@sntech.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 The callback used inside sbi_remote_fence_i is set at sbi probe time to the needed variant. Before that it is a NULL pointer. Some users like the flush_icache_*() functions suggest a generic functionality, that doesn't depend on a specific boot-stage but uses sbi_remote_fence_i as one option to flush other cpu cores. So they definitely shouldn't run into null-pointer dereference issues when called "too early" during boot. So introduce an empty function to be the standard for the __sbi_rfence function pointer until sbi_init has run. Users of sbi_remote_fence_i will have separate code for the local cpu and sbi_init() is called before other cpus are brought up. So there are no other cpus present at the time when the issue might happen. Signed-off-by: Heiko Stuebner Reviewed-by: Atish Patra --- arch/riscv/kernel/sbi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 775d3322b422..5a60a458c0b7 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -16,11 +16,19 @@ unsigned long sbi_spec_version __ro_after_init = SBI_SPEC_VERSION_DEFAULT; EXPORT_SYMBOL(sbi_spec_version); +static int __sbi_rfence_none(int fid, const struct cpumask *cpu_mask, + unsigned long start, unsigned long size, + unsigned long arg4, unsigned long arg5) +{ + return -EOPNOTSUPP; +} + static void (*__sbi_set_timer)(uint64_t stime) __ro_after_init; static int (*__sbi_send_ipi)(const struct cpumask *cpu_mask) __ro_after_init; static int (*__sbi_rfence)(int fid, const struct cpumask *cpu_mask, unsigned long start, unsigned long size, - unsigned long arg4, unsigned long arg5) __ro_after_init; + unsigned long arg4, unsigned long arg5) + __ro_after_init = __sbi_rfence_none; struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, -- 2.35.1