Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1252726rwn; Thu, 15 Sep 2022 12:44:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CNkjl+SI4XNUq+AE4mJE5/QkFJfczKzyVWu1Ad4712riIERgjW2196GN5aNKK/yfn29PL X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr1098108ejt.4.1663271076066; Thu, 15 Sep 2022 12:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663271076; cv=none; d=google.com; s=arc-20160816; b=oYtwo/XuJ1bswmwYmEqhK11CESCqkG0zDEStqRx8xwx+2SwmjWFJz8aUeF303rK9gA 0vI61GrqevMtnxNPwGqE+qCHxYAeRuvJzlx+s9xnXD48YYEyiCJcW0/+kTQxI/unQDIT qSpHWXtBq12BHwkHkjg3jep1FsYSblkeQMJOLkqtl3f9dlUzJE9FY+IgDsDiQXINO1Mb 3FpWR9QnLLrBWeSHOO93RXui8jKd6nVtauf3zMIMIcYVoMIb2XBwiY/90bCJGvfWshyD fdyX+5c7RSiwzro+kGsvUYwbVJjRiDV4uv86E2NV7ALfwVPn/cNTQrOv2DBZy99u49EP 5zKQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zpt9GCRbl8GSu+mNKxtCSxN/ut26bIT0MJANl4282eY=; b=oxCtyxNG/GrLkG41nPiUX52yFjQ7LVVPopgXRHvdamKLrBefnIJ392As0pEFrF+08T q+BMKcrbrYgC4z00nd1WO/zVEK7uG2afobKrCYoKN6BuXO7Gg+8F6cAQ6wBMs+cJGBUG SeTaniNZVFBNNOuhr1+wE+XrR6rn4WED80UGNJMBQxEod4rDfyAknCnnlDKU6a8wUgzq nhc6eAKAOJCuom9HzmmNpdIAPiIrX+15iDw0YLpEYyr+k9ova10F62f5elGukyit9brc HxBHvIntGBI7H9LgwCFmyvrXA4Pu3BaHeBKRCdIegE/J117VJNyhScoYoIYfCBKr/yZ+ LViQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b="3dVH8/Yo"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb3-20020a1709071c8300b0077c1b2f8299si14737369ejc.819.2022.09.15.12.44.09; Thu, 15 Sep 2022 12:44:36 -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=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b="3dVH8/Yo"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbiIOTlw (ORCPT + 99 others); Thu, 15 Sep 2022 15:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbiIOTlY (ORCPT ); Thu, 15 Sep 2022 15:41:24 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB439F75B for ; Thu, 15 Sep 2022 12:38:17 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id r20so13725011qtn.12 for ; Thu, 15 Sep 2022 12:38:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=zpt9GCRbl8GSu+mNKxtCSxN/ut26bIT0MJANl4282eY=; b=3dVH8/YoiU0dPRG8tjjiauIameUd3EPLECdbMuaVAgYEeXgQqnkOWsfagAVQj4AyhE rYDwsvzV8Anf9tgVloy2RgFUI8qZHyJxKyKeESW9yc9Ud+AzAuvo4N8MnGjaops3ajsK lkR9nQ1iz+2cWO6g49vHE0hJjzduH94Gni1CbaKzWXGPhGn+PyeLPw5KecGYJZGqvfmR HlnUCYFrrY7x0NIpiHg6H4mXck0En0bXbhNMDnkT/2pSkphAQ8ChMha+nK2l92MIW0E/ agPr54IRRiHhKHgWkiB6uJ0fGrgrFuYVWngrJTCctsLAkCNXUsh4t+4Xm0QY6i+cO3/e WcaQ== 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; bh=zpt9GCRbl8GSu+mNKxtCSxN/ut26bIT0MJANl4282eY=; b=QOgJoUTMMdcL8fcCb4rZqcHnf/J+IppNDdEQN6rpsNqh5IzIZh/Yku9+gTmRKj2Rae KTGGF2jLWF6cQJao4wJ1jVhQn3Yv/y0Gyhj7uvv/gNG2fgl9BS4WwIGi8AUKINvzXAHt oieswT9TdPBSdSplolOm4sWwrcJAeF3QEAd8LH3zXRLzbrHdvjdNLxx1E6niTeNrbEvc ABFo6C6eSF4vKlN8b/GzjqbEAOUPfm+uUIyME2ASrmLUun6XTCi3ydF8B4ANXr40/UcW 0BQq/RBdy7JFGJbFX/lhNGPniY1rmQwWQaQpT64ttubF2CZ87dPfyjYNNm31g8FwGb6+ JXcA== X-Gm-Message-State: ACrzQf3lrOYLInjyqo40HzXDKRJGwUBQxMRrhmAvQRXnPvpdVTdnrFL7 svXy0vWUPT/BOqNdGu6C1aFr/g== X-Received: by 2002:a05:622a:296:b0:35c:c846:d714 with SMTP id z22-20020a05622a029600b0035cc846d714mr1430238qtw.58.1663270636969; Thu, 15 Sep 2022 12:37:16 -0700 (PDT) Received: from abrestic-xps.ba.rivosinc.com (pool-71-105-112-35.nycmny.fios.verizon.net. [71.105.112.35]) by smtp.gmail.com with ESMTPSA id r1-20020ae9d601000000b006b872b606b1sm4596459qkk.128.2022.09.15.12.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:37:16 -0700 (PDT) From: Andrew Bresticker To: Palmer Dabbelt Cc: Paul Walmsley , Celeste Liu , dram , Ruizhe Pan , Conor.Dooley@microchip.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Bresticker , stable@vger.kernel.org, Atish Patra Subject: [PATCH v4 2/2] riscv: Allow PROT_WRITE-only mmap() Date: Thu, 15 Sep 2022 15:37:02 -0400 Message-Id: <20220915193702.2201018-3-abrestic@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220915193702.2201018-1-abrestic@rivosinc.com> References: <20220915193702.2201018-1-abrestic@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 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") Cc: # v4.19+ Reviewed-by: Atish Patra Signed-off-by: Andrew Bresticker --- v1 -> v2: Update access_error() to account for write-implies-read v2 -> v3: Separate into two commits --- arch/riscv/kernel/sys_riscv.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 571556bb9261..5d3f2fbeb33c 100644 --- 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 addr, unsigned long len, 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)); } -- 2.25.1