From patchwork Tue Apr 9 14:45:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyan Yang X-Patchwork-Id: 1921452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=em+cnYFR; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=WHRtLNGJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VDTXR4Jy7z1yYT for ; Wed, 10 Apr 2024 00:55:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=v3FnM6C03D8AAoji0if0kJJu8tD6OlCgKjlGjKKFIwI=; b=em+cnYFRPeox1Q xBZELgqkvF++yfd6NxZPPUYCCQos5/vwe9Qrg+q2MBjhE6Gdw9vWUNQSQgt2r8L++HTZJCNmdFoDH vpDdvDXd1OOWyNjNpbSHYb9GwerPxqYt1n2ayoId6XMufgiEqEUy9BA5q1/EW8Pz5NssZrzK5whno dD9P7BFxv+LmrC+Llm/hWjZcLSFRH1F6nEHYNf83+yKmBE5Us8qQjapow8FoYvlzunnnXt9pZwTvA ZPuq6vupRfj+1lKotKd0JBvN4qgFSwGjgpir3SPe3NG3dVwE17lqppoETBm2y7spHhUfzCDaT1u1Q XOZDfOd9smnvxJVOMRvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruCsL-00000002XOZ-2KUg; Tue, 09 Apr 2024 14:55:05 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruCsG-00000002XMe-2kDm for opensbi@lists.infradead.org; Tue, 09 Apr 2024 14:55:02 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6ed054f282aso3280509b3a.0 for ; Tue, 09 Apr 2024 07:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1712674498; x=1713279298; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PRIdZWhgFtQbzGEECFmk8VYe4fPyqPbpsGuX63yXkck=; b=WHRtLNGJNEoFpBZ4nTvAkUIA/7TnVOSPwFoWEX91UIIx93bUYOiVxwyXJVu3EjO80p biBgoESfKtCsK3M1faiJv7aYHs7ym+1uToLDcv2GDEiF0nekzHdACyFICsbiMMLKmLjB roJXBF1N5A4UNSn+YCWoMshFa5iC+1oY55qQbOdhwuQb/1jVYEZZniJ+O2EC+rBh+yUQ s7ubVuUPe68DzSPU/r32IKtde9HXWDFTuLyWRuh4BPM3WhjUCn5tQMU0ysEpPYeZ6WxY SUAXFpAEbYZkoFBGVycWTaGx0ZkFC0Rc4oTJzvpAhnT7UjVZxK7iojnAZD4M1b8MXohv 2njQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712674498; x=1713279298; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PRIdZWhgFtQbzGEECFmk8VYe4fPyqPbpsGuX63yXkck=; b=dc7rxRjdbcmjo9/ar2WM9ZMN2YGSkb57tPnJ/AH8iXjksZUgPC1ISc5nQrO2VlFV7E s+Si+Tj2pO/Az9KE/PIiy3kv6r31MHAJrbxlC2Pm+hZKv8mNq6umk3gauUeUYz2lw5Ed 3/MgPOP8rhtZGd3WztxFkNj08zJd4o+jHQF+Z14SOMRFftGjBXxmQX+HYuE/qAv1PsTJ hfunVUFQuCoLMfPI4NpNry6CFUvS+wna2EdHTwYehOElLuT27m1Uql6fAsLwniBMEf9t lJ9Lz0dnkUq3kDh/xOSCI3FqJpqdlSUNxn7KGaBKVPxmb8wvD7crQeBU1W+qaarJcwPE qZbA== X-Gm-Message-State: AOJu0YyWaZllAho3KFC5xZiFDM0qz2DjW5Z/+rJV52jLRdupvIOVY3d0 iD7+wHSH6EXmqkudef3RL1/YYPkXAxjihlhTMIWJSPfy1RSRD1d3CMNlHWCe0ssTV8eBr/x53gL UR9TyVe6NLuMmEKgAzPPiwD1X1nUsRSVZXIebBTSVO0WpkSvhDleuyY57cxWwRwPO8YY9vq2E9f ecOR/c2PppJzR4Cep0DzyuCGiTgAxGDEIKb8An4s0dVttspXw= X-Google-Smtp-Source: AGHT+IGZs458cmWT9rZvaPfVA8uwy94c88ULKts8bdpsb9JvjGleV5SHEywuXXI8+EGrC4wVo3Ui6g== X-Received: by 2002:a05:6a00:3927:b0:6ed:21cb:13f3 with SMTP id fh39-20020a056a00392700b006ed21cb13f3mr8083959pfb.17.1712674498027; Tue, 09 Apr 2024 07:54:58 -0700 (PDT) Received: from cyan-mbp.internal.sifive.com ([136.226.240.168]) by smtp.gmail.com with ESMTPSA id q23-20020a63e957000000b005f034b4d123sm8380525pgj.24.2024.04.09.07.54.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Apr 2024 07:54:57 -0700 (PDT) From: Cyan Yang To: opensbi@lists.infradead.org Cc: Cyan Yang Subject: [PATCH] lib: utils/irqchip: Add sanity checks to imsic_warm_irqchip_init() Date: Tue, 9 Apr 2024 22:45:47 +0800 Message-Id: <20240409144547.87893-1-cyan.yang@sifive.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240409_075500_737007_67CEC975 X-CRM114-Status: UNSURE ( 9.46 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add sanity checks for per-HART IMSIC pointer in warm init flow, similar to what the cold init flow does. This will help prevent any misuse of the data in scratch space. Signed-off-by: Cyan Yang --- lib/utils/irqchip/imsic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:431 listed in] [list.dnswl.org] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add sanity checks for per-HART IMSIC pointer in warm init flow, similar to what the cold init flow does. This will help prevent any misuse of the data in scratch space. Signed-off-by: Cyan Yang --- lib/utils/irqchip/imsic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c index f2a35c6..e6a3657 100644 --- a/lib/utils/irqchip/imsic.c +++ b/lib/utils/irqchip/imsic.c @@ -243,10 +243,15 @@ void imsic_local_irqchip_init(void) int imsic_warm_irqchip_init(void) { + int rc; struct imsic_data *imsic = imsic_get_data(current_hartid()); /* Sanity checks */ - if (!imsic || !imsic->targets_mmode) + rc = imsic_data_check(imsic); + if (rc) + return rc; + + if (!imsic->targets_mmode) return SBI_EINVAL; /* Disable all interrupts */