Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp3165457qtb; Mon, 24 Oct 2022 07:12:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VEuh+aKBtuGpcMO+rD/L/IkigVMrQP4kMkhiEzo/XZ7r3J/ycOs1z3cRQFfl7YSbAFc7W X-Received: by 2002:a05:6402:254b:b0:45d:b117:90f0 with SMTP id l11-20020a056402254b00b0045db11790f0mr30446928edb.57.1666620730758; Mon, 24 Oct 2022 07:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666620730; cv=none; d=google.com; s=arc-20160816; b=DtqYbbjfnP9rylt/1kvisx+3SiRKWOjispgD9SC0NcWks5RgJ41bRQk4wc3bGghquN zU1g8kMVH7nSeK9rxrTMTuCaQnsK1Qf52H66HXozJkDb+5DEKe6WeNiwiJnrZLkKGoK0 glkderQ4UbjCq1bex4SiLk1bZ0TzNH2tXNsolov7OUdJtf9jq95kwdrwll9G6YEbpJV0 nahCWDSscdYxwzjIBXcw0lTlo2BZ2/6nGrC8ZVC/8KWV73jxXdibDRX33u+XHoM/HHbM sDm00MJFEEj5Lq3FBB+tjdQd/eow0MW5G8Qo8LzFjRvpuIbegNOtTda99Sd+ae7A89ky ICKw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt19-20020a170907729300b00732fcbcfedesi29568816ejc.623.2022.10.24.07.11.46; Mon, 24 Oct 2022 07:12:10 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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)); }