From patchwork Thu Aug 1 12:58:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlos_L=C3=B3pez?= X-Patchwork-Id: 1967669 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=EpLZVOyD; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=HAQsoF4o; 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 4WZTkg6jWWz1ybX for ; Thu, 1 Aug 2024 23:06:51 +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=iX+adjOJGHRAB94QVWQW9LeuEIEG/FEzmzFVXAfyjWY=; b=EpLZVOyDlkxkEK dJbhaPlUy92OL12KW0Z2CVEIbLB/JC160hllBGqyVXoOmjc/f0+drq3psBpmn8qm+soIsjvbyJMre e9L3eiYh4U1ez/tHaljRz+xQekpcfbFm5Nryj+KfyB+FX0itRADZen/O45/SLp87zyEYDc/Dtgxap ZXB4KjN6JNQOfViLuU9w+6t7l4M92tzGJ5ZndsNZV+XWW8QvJKPmBwsOuQmkq3Ig4RQpdYPGcW18A Lx+xuzLlENILFGn3GY/dODTQ7tlzFvNtUCrYpdiU4RNvsPzZ2DQWzXecyn8/JjxteaLl4zc9To0Gi O55HG7PdzRNEv4cE3t1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVW1-00000005NK3-38aR; Thu, 01 Aug 2024 13:06:45 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZVOa-00000005IiW-3YJ6 for opensbi@lists.infradead.org; Thu, 01 Aug 2024 12:59:06 +0000 Received: by mail-wr1-x444.google.com with SMTP id ffacd0b85a97d-3685afd0c56so3541209f8f.1 for ; Thu, 01 Aug 2024 05:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722517143; x=1723121943; 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=JBQVD5etvVSwPVHdHI2LnZisE3IK6GvJ6ZTci+Z1pzw=; b=HAQsoF4oMAOBXbfdwyNUtKM1n4w4oYVYPZnm6LvYlODOwsyVS65fL4lm2K4l3kHtvr 5k2kzYFEU9y1+YAEbOn6n09whqGzQnw4SZS9coCAgmzAhOhOJWkMn6lN5/8wRKGSFi6O zVpdP0iDSm2hgMKIBuLZcjTnseb5QgIe/wv/VDoPQJW5QjrMnKBGQACIy+TLbtRKZzAy xC3Q7hOrHtPRgXYJ1C/SfOn7uGYlSrH8h4gHuAsD5sw+O3IJjuh/6JaF6nJwIB+IeY5j G09x1B48yiIhxhKvif1xklCbTwNnUvWsMCIuwO4NNnXHyppuGYOjIrO7/CUuQ5Iol+9v JwLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722517143; x=1723121943; 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=JBQVD5etvVSwPVHdHI2LnZisE3IK6GvJ6ZTci+Z1pzw=; b=oF36xTeFCSmEshv0yW6ZK3zPHnINDSddvFxrHDOrPwtQHBQ/ZTkkFrRaLoqQaPD3zN 1k0UZvZRAOpfF8NFuDqTTTl4uPDImLeabinq/03U7rZULRzg+jI73u4YiYPYcEcPaD5R YVlGlOzjSWkRSpdTnZaBR5evPBQ0I+m1mKKAQz0nkQGSkzS37loMLQlmOa9GxSTbqY77 uqfMX1o0cIGwx3b/eZ7WfMIU2Ukch993x1VK914wXZM5zw3URcQK+pn4f1x3zaTPRzZR xtgnEeALHwchtA+YtA9tocZbNDp72ZdimWUQzcNZOOmVRaY9swGafIn3JNzzDNRxhs+L cRBg== X-Gm-Message-State: AOJu0YwA7CYuicIsa57Ec+thTAUWoRiUwWpt2i8onU44OmzyvRfmFzg8 XVue4KsAj3/MwZfOVkfursp9F0mSOCJB2KKVRuWjKD7LqoEwoNEegqDM4z2rT+U= X-Google-Smtp-Source: AGHT+IHqG9CL9mJilxJMiLuqnUeQ3+fswHaR+wYKH62brWjV4WuUjzdkS1qPqkClOESZivSpemK+7g== X-Received: by 2002:a5d:620f:0:b0:367:9575:2820 with SMTP id ffacd0b85a97d-36baaf7bd38mr1319177f8f.45.1722517142870; Thu, 01 Aug 2024 05:59:02 -0700 (PDT) Received: from debian.myguest.virtualbox.org (182.red-79-153-116.dynamicip.rima-tde.net. [79.153.116.182]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36b367d93aasm19280555f8f.27.2024.08.01.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 05:59:02 -0700 (PDT) From: =?utf-8?q?Carlos_L=C3=B3pez?= To: opensbi@lists.infradead.org Cc: =?utf-8?q?Carlos_L=C3=B3pez?= Subject: [PATCH] lib: sbi: check result of pmp_get() in is_pmp_entry_mapped() Date: Thu, 1 Aug 2024 14:58:52 +0200 Message-Id: <20240801125852.5361-1-carlos.lopezr4096@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_055904_936940_38C13932 X-CRM114-Status: GOOD ( 12.46 ) X-Spam-Score: -1.8 (-) 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: pmp_get() may return an error if the given entry, given by the caller of is_pmp_entry_mapped(), is invalid. This results in the output parameters for pmp_get() being uninitialized. To avoid using garb [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [carlos.lopezr4096(at)gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [carlos.lopezr4096(at)gmail.com] 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 pmp_get() may return an error if the given entry, given by the caller of is_pmp_entry_mapped(), is invalid. This results in the output parameters for pmp_get() being uninitialized. To avoid using garbage values, check the result and return early if necessary. This issue is not being hit because at the moment is_pmp_entry_mapped() is only being called from a single site with a valid hardcoded value. Signed-off-by: Carlos López Reviewed-by: Anup Patel --- lib/sbi/riscv_asm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 05b8c7c..c7d75ac 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -291,7 +291,8 @@ int is_pmp_entry_mapped(unsigned long entry) unsigned long addr; unsigned long log2len; - pmp_get(entry, &prot, &addr, &log2len); + if (pmp_get(entry, &prot, &addr, &log2len) != 0) + return false; /* If address matching bits are non-zero, the entry is enable */ if (prot & PMP_A)