Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3457108pxp; Tue, 8 Mar 2022 15:00:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXbd5HI8YB+HgiaIEQntLYDs5E+ZC9StCm+CDjUBGoz+cxnr98A+5VnJDRHVILff3YWJAV X-Received: by 2002:a63:114:0:b0:380:29f7:a97a with SMTP id 20-20020a630114000000b0038029f7a97amr12213209pgb.361.1646780432317; Tue, 08 Mar 2022 15:00:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646780432; cv=none; d=google.com; s=arc-20160816; b=G72MvO8obit/NMZ80/NsvY458XQgvcrqTOPW7ai6ap7W+ljwGTbBLZoqHJ4hcDj9GT YnQD1KKIgegHlQYqyrYEdHa+PbTcwyF4EgyWXxPLOYnLGfMxi4Zm4mWpBGjxxscUf95V hB4BJRvybOo/QVECbR5Kio/suXsDjeYyFcK1M4tV5S1/Itq44AQCS3C6nLHQcMgKkcc8 rtqTp3tPmkUsmz2XbjiZuKoIB9GIZKv+MbO/WadSgqxtXgiAD6QyLS9Z3Ahf9nVu/tcZ WOI1hzZcTuNnhTnewFrLkp2Xf0kDbfSD8dG6cNHmIeUHDSfI2tG7a7QyXneYjrJr1QGN 5sDQ== 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=wBnAX7K8ngQtsInHOVuAKrj6yT7ykI+P0JzMkq5ro6s=; b=TqHAvHRss9GigJHRibwciaofUq9TsW1G2WTnlXvLXj2+OlgOyDDKFd//ZaXSlbkauE KM1JTJ/NcBF6teYpnQMMAVKTkV+nV2b9+qqqn6Y+OZn27AHK5Hr5gqiWnKZQ/zg8rZTu F06WeVXbnlK+ccDd8CUBLlMWX0AfJapChc+UF4a4G2YM/ay/rQqGM2KH8POOGJOmOvBL wW4MX9d5sGh/COk4FsnZBmq3ScbutYLGaC8cqcT60Bz/sPrK4C24Eh54kAkuUE3+Rpat LR4YeCMt8npqESgUNYUICcU2of265/YquVMbtwBDT2yS6f3LREg40TPHFIb3NBFtjNAD ZPKw== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w63-20020a638242000000b0037ff6686fb1si145749pgd.371.2022.03.08.15.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:00:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6511E5A0B7; Tue, 8 Mar 2022 15:00:28 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245439AbiCGUyn (ORCPT + 99 others); Mon, 7 Mar 2022 15:54:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242490AbiCGUyT (ORCPT ); Mon, 7 Mar 2022 15:54:19 -0500 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3417F289AF for ; Mon, 7 Mar 2022 12:53:24 -0800 (PST) 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 1nRKLy-0002DJ-SO; Mon, 07 Mar 2022 21:53:14 +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 v7 01/13] riscv: prevent null-pointer dereference with sbi_remote_fence_i Date: Mon, 7 Mar 2022 21:52:58 +0100 Message-Id: <20220307205310.1905628-2-heiko@sntech.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220307205310.1905628-1-heiko@sntech.de> References: <20220307205310.1905628-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, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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.30.2