Message ID | 20231121160637.3856-1-jszhang@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp738744vqb; Tue, 21 Nov 2023 08:19:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1RZjfnEGyGwXOLc62LkOGCarbMKs0IOOYPfGGVgVlBG9D5/BP95u98cl+wyo7vJPcm7XX X-Received: by 2002:a17:90b:3504:b0:27d:61ff:3d3b with SMTP id ls4-20020a17090b350400b0027d61ff3d3bmr9410956pjb.38.1700583547513; Tue, 21 Nov 2023 08:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700583547; cv=none; d=google.com; s=arc-20160816; b=leDp1j9BgSklpRCYULhYX/k88AMBi7X1c+y15A5irVrhjGYqPmQL+MCN9fYDZWtffW OIQn7lPjyKMJiB+8wwJ4xl+eB6NTmjzR4HwDbLTpNFYukgW5lHLfVfkxwmJ9vbOwOU/c FnSJt1kOJ/yNMjfOMyiCCnusTBjRTMhAn7EuyHFXUzxNNnAP/1Wb5lP2Z5re1bKuvWcH OzbUi/c/QPrVhPv/o/B7+7BYfTAslEijTGyjGCvhd/Q/h2MtXA8FnKl8qWuLyCwlTLeH k+HID/wsYOPsrwOdWbNoFgbnN2Kk2AtASzdqE7Xgen8aK1ffufsWwuKV3rxUuUUSeFDM cy3w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WFqNUgYlEmeyI2jMz7oftmQGDudnV4XcWjYIJzI7HY0=; fh=srb/EijQIrMEdOeqn3qQX6qrsAGyqHAqeSFkl/qDdLM=; b=nWPTNvKsHm2o3HXkKbYaN1lhFKAN5/GbEMYy4rkrXWsxkQKGhgCBvH6833yWg8sLrt lHnmNEyciMRWYevh2b7udVGSxPGgK6Y7B4Mo4bJSpowvaVQL4MKqZOEBsjEA8eUNEfzK XsZN6mGXvzOuxTEYUaSabuDb788aLjkDkPW80T1V2cqUPx/pk+VLCKMWa4MBPL4SGeVx v+Au59KW+fh/Pqp+4oSEKaOaHGRCMqzapFrwur7uOxR15wbPjbSjSUTPbbdIx25qEmm2 DSRjTB4fcE8oK9i3PPbhUSqr19UDUeVZdcCWjSmxIIDEBuf9SP15saPt13zb+ssHtMxA ooPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hwSMC2wp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id pt11-20020a17090b3d0b00b0026b52571571si858067pjb.1.2023.11.21.08.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 08:19:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hwSMC2wp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 60E51808652C; Tue, 21 Nov 2023 08:19:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230464AbjKUQTE (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Tue, 21 Nov 2023 11:19:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230348AbjKUQTD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Nov 2023 11:19:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C8E3112 for <linux-kernel@vger.kernel.org>; Tue, 21 Nov 2023 08:19:00 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA4FC433C8; Tue, 21 Nov 2023 16:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700583540; bh=+NPX7FyBwDK3KyfbI/LU1WpPwCOApvDfHFYotMW+iEQ=; h=From:To:Cc:Subject:Date:From; b=hwSMC2wphiYqVQTwwY7y4jEPXdini07VezqwCyCKhS31YxQKVmd9qNUlNElupHfWL hSu1OAR8NlVtmKi1Pawxe6gvzMrwlXmMRfiDmrhdyREeY3ByVllyqMVsDDeTvXKXGW r4ZvU71anuIdaRU4IjH1cr3A7cO4oSyEqvkWMgE+NtrY+Xe820ZQzvsxKG8t/Jaa28 gAAjpqSeuNfAnLzRF+agtkbFk0DeJCo6Fi2HDOJtz4Sc1hvWRvI1wRmSRTZxbFRCG4 DJ5/ZcSsAoHnyFhzEUfHgXPBOdBD+uq547K2rj8ENsoeb3WXTPHVqZ3xcLNGrQXTZn HVkf/EjKwexiA== From: Jisheng Zhang <jszhang@kernel.org> To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu> Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: mm: implement pgprot_nx Date: Wed, 22 Nov 2023 00:06:37 +0800 Message-Id: <20231121160637.3856-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 21 Nov 2023 08:19:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783191093324665075 X-GMAIL-MSGID: 1783191093324665075 |
Series |
riscv: mm: implement pgprot_nx
|
|
Commit Message
Jisheng Zhang
Nov. 21, 2023, 4:06 p.m. UTC
commit cca98e9f8b5e ("mm: enforce that vmap can't map pages
executable") enforces the W^X protection by not allowing remapping
existing pages as executable. Add riscv bits so that riscv can benefit
the same protection.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/include/asm/pgtable.h | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On 2023-11-21 10:06 AM, Jisheng Zhang wrote: > commit cca98e9f8b5e ("mm: enforce that vmap can't map pages > executable") enforces the W^X protection by not allowing remapping > existing pages as executable. Add riscv bits so that riscv can benefit > the same protection. > > Signed-off-by: Jisheng Zhang <jszhang@kernel.org> > --- > arch/riscv/include/asm/pgtable.h | 6 ++++++ > 1 file changed, 6 insertions(+) Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
On Wed, Nov 22, 2023 at 12:06:37AM +0800, Jisheng Zhang wrote: > commit cca98e9f8b5e ("mm: enforce that vmap can't map pages > executable") enforces the W^X protection by not allowing remapping > existing pages as executable. Add riscv bits so that riscv can benefit > the same protection. And this simple patch to enforce W^X protection is also missed ;) Thanks in advance > > Signed-off-by: Jisheng Zhang <jszhang@kernel.org> > --- > arch/riscv/include/asm/pgtable.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index 294044429e8e..4fc6ee5226fb 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma, > return ptep_test_and_clear_young(vma, address, ptep); > } > > +#define pgprot_nx pgprot_nx > +static inline pgprot_t pgprot_nx(pgprot_t _prot) > +{ > + return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC); > +} > + > #define pgprot_noncached pgprot_noncached > static inline pgprot_t pgprot_noncached(pgprot_t _prot) > { > -- > 2.42.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
On 21/11/2023 17:06, Jisheng Zhang wrote: > commit cca98e9f8b5e ("mm: enforce that vmap can't map pages > executable") enforces the W^X protection by not allowing remapping > existing pages as executable. Add riscv bits so that riscv can benefit > the same protection. > > Signed-off-by: Jisheng Zhang <jszhang@kernel.org> > --- > arch/riscv/include/asm/pgtable.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index 294044429e8e..4fc6ee5226fb 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma, > return ptep_test_and_clear_young(vma, address, ptep); > } > > +#define pgprot_nx pgprot_nx > +static inline pgprot_t pgprot_nx(pgprot_t _prot) > +{ > + return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC); > +} > + > #define pgprot_noncached pgprot_noncached > static inline pgprot_t pgprot_noncached(pgprot_t _prot) > { This one looks good too: Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Thanks, Alex
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 294044429e8e..4fc6ee5226fb 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma, return ptep_test_and_clear_young(vma, address, ptep); } +#define pgprot_nx pgprot_nx +static inline pgprot_t pgprot_nx(pgprot_t _prot) +{ + return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC); +} + #define pgprot_noncached pgprot_noncached static inline pgprot_t pgprot_noncached(pgprot_t _prot) {