From patchwork Wed Oct 19 08:22:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp204267wrs; Wed, 19 Oct 2022 01:45:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM674CJ94rly9CtiO5+pbNsVme1H4eS/OkK6vpBXhSyPbIL/5XlCzcBQckFAyr3APFCwyNep X-Received: by 2002:a17:902:7c97:b0:17f:5abf:9450 with SMTP id y23-20020a1709027c9700b0017f5abf9450mr7125037pll.19.1666169138441; Wed, 19 Oct 2022 01:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169138; cv=none; d=google.com; s=arc-20160816; b=zBPHRZ0YkrmS5rxDu5kpSmX2rkihzLoll44bUgbQDgvDJs8jSHq7kx1bksZigBC8IW msgTxHANj1i1Eviwrd2ZHPsFUM8IfruYeKIm6XPsx8QaOV+yTY4xY5eJVzV1xs3m060z WQrmDaGf6FwN3wOkDPBd5Hlu3KDWkigy2gsYJN1npEz9Zy/weDUL9epTGeIhWxw/Xv4b RCK0SvGnxflxEQ/o7tNJS5pjhI1E7tYVG/AdZ6R1xEim/Yt7xakig/0IKBMsrkUUsy7U JaofwHREd+DFDYYfint84nxRM9DUHgUg+7b8oj0DdvGmgTOZD+7pwCCgVdkjCajro9ad KLQA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TGsirIwj7n+/+mXu8Rw17nBfDG9OmYMcF6WaG/CsWPk=; b=a7n6nZg9REk4Q31NadSIla8gMnrWhkHvi2QHUFlnb0c+ZmIcfdYPdWBE3pk1Y/Gtt7 3x6wa18nLOq1QcH6X7Dn4m1IggxIoZcVtoXaFwHMBPfC8ZHjlwBq6AC0dOZXhkNIc4P4 LabAOUtDCjdCu+VSKL8iKAN90/lVeoHjWhZQsl/IJomUb8t8WRVg2+TA0HWE1Hpe5O3t +alyUtxxcWhbbtpcH0TfQ0v/S4+p8nXUCketL7s7+i2e0sM8fJdgmE3nkPQjUUPh3fH3 HIwHZqY/SGKqJy0JO+rfq5410pbGHjCShKMEGQq4dzAOQWPG7VLlZ7K19UhoskLST0UD KRBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="HShpK+/J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a170902c64300b001865a9586c1si156442pls.59.2022.10.19.01.45.25; Wed, 19 Oct 2022 01:45:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="HShpK+/J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbiJSIou (ORCPT + 99 others); Wed, 19 Oct 2022 04:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231229AbiJSInl (ORCPT ); Wed, 19 Oct 2022 04:43:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6922457BE4; Wed, 19 Oct 2022 01:41:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 19EFC617E2; Wed, 19 Oct 2022 08:40:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24831C433C1; Wed, 19 Oct 2022 08:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168817; bh=u8jCsQTg+AUQ8MfWiYmhRVCIrhrvAtAfKvtbHgYSGJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HShpK+/JSNjThVg8MQG+4fpzS29Z0ItC2FWH4UQveGLRSx+BkSzOrbpK6Dacnbczi 4MZJ7OGgqaydxGk48agOSprhTSwDJNso2WvqXORJWYxoHwLErPNawFQDvuWMfsnKSn pcsgU+G2fdTl11UU8unXMEcdTZYdS2/VlqyVNzSg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Atish Patra , Andrew Bresticker , Palmer Dabbelt Subject: [PATCH 6.0 062/862] riscv: Allow PROT_WRITE-only mmap() Date: Wed, 19 Oct 2022 10:22:29 +0200 Message-Id: <20221019083252.695471466@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104970635883475?= X-GMAIL-MSGID: =?utf-8?q?1747104970635883475?= From: Andrew Bresticker commit 9e2e6042a7ec6504fe8e366717afa2f40cf16488 upstream. Commit 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is invalid") made mmap() return EINVAL if PROT_WRITE was set wihtout PROT_READ with the justification that a write-only PTE is considered a reserved PTE permission bit pattern in the privileged spec. This check is unnecessary since we let VM_WRITE imply VM_READ on RISC-V, and it is inconsistent with other architectures that don't support write-only PTEs, creating a potential software portability issue. Just remove the check altogether and let PROT_WRITE imply PROT_READ as is the case on other architectures. Note that this also allows PROT_WRITE|PROT_EXEC mappings which were disallowed prior to the aforementioned commit; PROT_READ is implied in such mappings as well. Fixes: 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is invalid") Reviewed-by: Atish Patra Signed-off-by: Andrew Bresticker Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220915193702.2201018-3-abrestic@rivosinc.com/ Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/kernel/sys_riscv.c | 3 --- 1 file changed, 3 deletions(-) --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -18,9 +18,6 @@ static long riscv_sys_mmap(unsigned long if (unlikely(offset & (~PAGE_MASK >> page_shift_offset))) return -EINVAL; - if (unlikely((prot & PROT_WRITE) && !(prot & PROT_READ))) - return -EINVAL; - return ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> (PAGE_SHIFT - page_shift_offset)); }