From patchwork Tue Dec 20 10:46:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Chauhan X-Patchwork-Id: 1717784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=OP/B/vfb; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=ZsJdkTWj; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NbtYx0fCJz1ydZ for ; Tue, 20 Dec 2022 21:47:17 +1100 (AEDT) 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:References:In-Reply-To: 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: List-Owner; bh=VwWjivkFlZGSfdCJJCJqZTeL5NC6bW+1GDlK/QnG7Jg=; b=OP/B/vfb+LRyw0 ZGacmoxzaIs3TYuV44W1vnOkaFJOiRDqj50h2hr9dT0rV08UPzpyr5TfUYe2R5P1O3AwsIBzsNNRy Qs09piVrsEPKsc+S8VmFrfSZsfE814YHf8jW1oGKZJ60ti++gAkn4VuROP82nWcCHtGei0P6qCmXp Mg7/NYZxe1FFcEsrZ6QU8iehA/7257qRHV4Jj4uQj00v2v6qud+ZeVK5q3qd0MHwVVwJILyARIG5V xIgOdhPJfS9IYjn6217zgzCE4oXEi0pRMB4RTD8Qo9ljIzMa51G3xmMRP9xK0zB4RPtizfrb7PvA8 gx/0z/DpINH6/18zwTtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7a9C-00DRLs-JF; Tue, 20 Dec 2022 10:46:58 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7a8x-00DRAk-Se for opensbi@lists.infradead.org; Tue, 20 Dec 2022 10:46:48 +0000 Received: by mail-pj1-x102b.google.com with SMTP id k88-20020a17090a4ce100b00219d0b857bcso11736596pjh.1 for ; Tue, 20 Dec 2022 02:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jZGXiXaSka/bxU4025VFWb1Gg1IlrW6jz8gaVow1hTs=; b=ZsJdkTWjh1H0XfykRL6DesXQzeBaGt0KNHiwj1zKqDKbFBBsa/1GEeGjqewlP4a/Nz t6teAiW9mMVyJkN0SdrBGSSdcFVGkq7lIv6QVOZQLYrLz1UKphAyOAwdyURjKCTXO8/W E6Eaq7Ml5XR4pSkBeOhR6//6TbU6HC1FIFCrgXu7Js/cNQMq/TDsXNeM/u5e+IWKR0xr WaTauTQN8gdtnQyQXDD8IdtSAJCCnwncxIGcFxsaxlN0eR/mSBEM/VB+s83H9CqH4Deq HpMTIQkUPZ+xrUKl1E0HOVTDbzwW0eq00oyYNR0rsk/xTJi7znJl6JBIdIK/LWGEx1CT NYjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jZGXiXaSka/bxU4025VFWb1Gg1IlrW6jz8gaVow1hTs=; b=1OysbIgytIIkfEPe0nzw51XJtX2Dwga/y1zX32VQ4SZEx/kKJNoYKJ3r5P7TYxGpp6 sHq7MthURE/e2FdIE6osQDfSXigK6k4O2O9/N49nW0gkD7TPyovr7UpTA1urqLOhv9eU LbEGnM3id6bVbR1o9WKbakT/v+FvzMDD+F4NfHgrpkJI+Q9mO5T0bi+VgbytR8iIACEs 5BYC+jiMbeb3Xd/V/kJ/DkyURouLlQti1TApWvx4cvUL9VTTLvm/51Q3r+hF91GpMdxF mS71QfvqmBR0eSA71Y6E+cpTQBivzOXPNEiEDb5glXsb4JGQ7b2gocMl5R13WPYrm1tU Xzaw== X-Gm-Message-State: ANoB5pmPUqAe+V4tPlzi+TLZa437qS4UV5fsXKidILf39TPOyvZuDuyR oxvWp8FfhYYOIpwSSW3FjNOuA21pENxELrABXnbBpg== X-Google-Smtp-Source: AA0mqf501Mkg+k3pRGkMLBh5Cq3JsRJOZkZZVSPhcGqtqtJeYSnlPRf7Pz960X1v2X4MEKisSwjbjg== X-Received: by 2002:a17:902:efc7:b0:189:812f:48a8 with SMTP id ja7-20020a170902efc700b00189812f48a8mr43304393plb.63.1671533200354; Tue, 20 Dec 2022 02:46:40 -0800 (PST) Received: from yoga6.thechauhan.dev ([2405:201:d019:c0a2:9958:7bb7:7663:ccd9]) by smtp.gmail.com with ESMTPSA id ik30-20020a170902ab1e00b001897d30143asm8923550plb.289.2022.12.20.02.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 02:46:39 -0800 (PST) From: Himanshu Chauhan To: opensbi@lists.infradead.org Cc: Himanshu Chauhan Subject: [PATCH 2/9] lib: sbi: Use finer permission semantics for address validation Date: Tue, 20 Dec 2022 16:16:18 +0530 Message-Id: <20221220104625.80667-3-hchauhan@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221220104625.80667-1-hchauhan@ventanamicro.com> References: <20221220104625.80667-1-hchauhan@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221220_024644_263105_211E8A65 X-CRM114-Status: GOOD ( 11.67 ) 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: Use the fine grained permisssion semantics for address validation of a given region. Signed-off-by: Himanshu Chauhan --- lib/sbi/sbi_domain.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 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 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 Use the fine grained permisssion semantics for address validation of a given region. Signed-off-by: Himanshu Chauhan Reviewed-by: Anup Patel --- lib/sbi/sbi_domain.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 3205595..8f9306c 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -107,24 +107,33 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, { bool rmmio, mmio = FALSE; struct sbi_domain_memregion *reg; - unsigned long rstart, rend, rflags, rwx = 0; + unsigned long rstart, rend, rflags, rwx = 0, rrwx = 0; if (!dom) return FALSE; + /* + * Use M_{R/W/X} bits because the SU-bits are at the + * same relative offsets. If the mode is not M, the SU + * bits will fall at same offsets after the shift. + */ if (access_flags & SBI_DOMAIN_READ) - rwx |= SBI_DOMAIN_MEMREGION_READABLE; + rwx |= SBI_DOMAIN_MEMREGION_M_READABLE; + if (access_flags & SBI_DOMAIN_WRITE) - rwx |= SBI_DOMAIN_MEMREGION_WRITEABLE; + rwx |= SBI_DOMAIN_MEMREGION_M_WRITABLE; + if (access_flags & SBI_DOMAIN_EXECUTE) - rwx |= SBI_DOMAIN_MEMREGION_EXECUTABLE; + rwx |= SBI_DOMAIN_MEMREGION_M_EXECUTABLE; + if (access_flags & SBI_DOMAIN_MMIO) mmio = TRUE; sbi_domain_for_each_memregion(dom, reg) { rflags = reg->flags; - if (mode == PRV_M && !(rflags & SBI_DOMAIN_MEMREGION_MMODE)) - continue; + rrwx = (mode == PRV_M ? (rflags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) + : (rflags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) + >> SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT); rstart = reg->base; rend = (reg->order < __riscv_xlen) ? @@ -133,7 +142,7 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? TRUE : FALSE; if (mmio != rmmio) return FALSE; - return ((rflags & rwx) == rwx) ? TRUE : FALSE; + return ((rrwx & rwx) == rwx) ? TRUE : FALSE; } }