From patchwork Mon Oct 24 11:29:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430332wru; Mon, 24 Oct 2022 05:41:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lLGmBio8srreZi7eC2mOD46bNxA/gPEWHng9jwgGZjQU6b0/Mv4MpFcB4YtCcOlB7QHQa X-Received: by 2002:a05:6a02:202:b0:42b:d711:f27c with SMTP id bh2-20020a056a02020200b0042bd711f27cmr27806194pgb.246.1666615275362; Mon, 24 Oct 2022 05:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615275; cv=none; d=google.com; s=arc-20160816; b=WPHh/gf8Ai0+NP9V4pU4K9A1jD/swdAn5+KM/QBnKj3JLGedEKmGzFaTXjkCdUcTRx KOeKOrN2TCn0U5a5QunNRsZUVAfT25MNFFs3hqFnOJ2q7jThu2sXyZSpYIm/9ZTEJJan gW8V0TBcEzXNMj8WVjyVRNC0R9YnS8ltk35u7lMeQBn/GTBlPiEWdqkc8TmOvNcIgWBt 4+cvArL/qK7vNS1+SWQbITeaJ+xDDl2Uy3MZR3Tm0iGxY4SwPt0SRvp+Abi1FgeivYd9 wfHFOOOQ1ura6Wm475Va8faUkCIzdXBcITNK8+O2K30xW2dUyAc4zQyw43AtC7X+LlQU j9ig== 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=2AQ7MYtE3QoUFGdmr3gg1JQ4Z6jFVQa8U7HPr+G9wkg=; b=W5IzOmFx2lVW/ThBTIo58NQcBxiikXmpoHWl68ZINDLhUzjlcnFCYZjg3oiVBen2Kh zJNi+fajfjwbLDGmWyhrLwFvoj7+kPsrHtFFwGkgZNxAq6GUucGY7Y/OuIJlMLB7O8e1 5+bSoutOE5qPL5CHoXSaHszVk/9F1nHzbyNav60s0PQrX2FQKHzHfkSxAxwRY/qdZWt1 NwG9GvTQdKjorwNsjN426bf4BbiOvJ+7ZST01yDtbqW5wm5Dlvs/MEXVHnBtOVMOBBId BonHt1kOPmJqY1diXxOo5GalKPbC5I4KCdlauseokROxJOVQZLyP6KXm6dW7RWVMLqyW Rpsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BpECCjjV; 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 hk13-20020a17090b224d00b0020adba9ec02si10569397pjb.82.2022.10.24.05.41.01; Mon, 24 Oct 2022 05:41:15 -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=BpECCjjV; 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 S233980AbiJXM3I (ORCPT + 99 others); Mon, 24 Oct 2022 08:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233803AbiJXM2S (ORCPT ); Mon, 24 Oct 2022 08:28:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62A285A81; Mon, 24 Oct 2022 05:01:53 -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 ams.source.kernel.org (Postfix) with ESMTPS id 18DBEB811EA; Mon, 24 Oct 2022 11:57:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66FA2C433C1; Mon, 24 Oct 2022 11:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612653; bh=aM3Ys8VR9L5UWxe/PM64/AlbhVXkGSXjpofOLl/w2Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpECCjjVDEkt3TbJ6aOhLUSqvys/UJsnK0NojcezSShh+iDPGwDwpUSCJP+V3tvWT 4Z3N2x2xGYcPnOFVQ7mWUcBX/MXAcHeD15QQGkkybwG9dGkYR6hn85EI+mi7vnyIjf tr95N1ytGa1yPD3VFYoJQ2CdyS64U1fwmEJ26lZU= 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 4.19 051/229] riscv: Allow PROT_WRITE-only mmap() Date: Mon, 24 Oct 2022 13:29:30 +0200 Message-Id: <20221024113000.729572803@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747572778794879218?= X-GMAIL-MSGID: =?utf-8?q?1747572778794879218?= 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 @@ -26,9 +26,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)); }