Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7520622rwi; Mon, 24 Oct 2022 16:09:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7bmsrHGaeBiQz1C02NN8K7mC4sI01TZJaP/Q4r1yCBGa/PNtONqz5jNI0Ehtjvc3nOCQni X-Received: by 2002:a17:907:744:b0:741:36b9:d2cc with SMTP id xc4-20020a170907074400b0074136b9d2ccmr28677216ejb.613.1666652945332; Mon, 24 Oct 2022 16:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666652945; cv=none; d=google.com; s=arc-20160816; b=dSdmaNwf+LUqYQjeh7cpa27zKewxuzSFJ1AaxMTLb9gYgYxPfWf8hvily/LX2WJhLk NcV0HeKQYKEww9w45yAhWQ2nJRRBod7al1oEKTiegO8z1W+Q3NNISx2rbC4EadyZF0Sp F2YVnjH1J3pzYwu4ew2TsZNl0wK14dqt3wWTax5EVHQ/Bo7VyINciOBke9TIs0tDPsFD 1QYxUjtE7Op+wmKB8JCKsqzVjjDvUXy32Wc/w7SLkuOyV3Hb4SUteWhWH0ZV3Ccma/Ut mnvWgtw8qrGGye49yM/1R2KnJFXd1FCMg0PQklDHIkrQVKjcahZw39Pvy+uMlAAWsusC xe6w== 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=Tvv9N3anvXFsLXvkC+3K0jhRXV62vUZzAXdu3sdHIMdPmOQ632Zh5DP+130eSWNbb4 5Z9DJ4iWrzrjV0fCf2bOV47zdbIkxyJo+j6zxcMzsymz9OCJGAf6WT1YDAqSPo6kSBOG PKZmh7yOagNIEiA2tvMnGhZQcD6uqneCYsBm2TxKFQMdpaD3JObnbi4rjE55a4amIV1u hOy9dgaxVMjr7WQrmWvmmUUZSRif2ppBGDHrweoMLYcnb9tpp/xsPQUk+sWLMoTN9mdp D57JoI+RbEQnHjSCU9cfwDCdwqXdD/YYO9LTcsvBc0n5mBfxCHfIofBbOxzBQGbb9lcJ mbow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="btM/N0s+"; 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 11-20020a170906310b00b0078dad42f75dsi802221ejx.475.2022.10.24.16.08.39; Mon, 24 Oct 2022 16:09:05 -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="btM/N0s+"; 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 S231927AbiJXWvS (ORCPT + 99 others); Mon, 24 Oct 2022 18:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231714AbiJXWup (ORCPT ); Mon, 24 Oct 2022 18:50:45 -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 3ECBC3200D6; Mon, 24 Oct 2022 14:12:42 -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 C89DCB81367; Mon, 24 Oct 2022 12:17:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27F31C433D6; Mon, 24 Oct 2022 12:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613839; bh=u8jCsQTg+AUQ8MfWiYmhRVCIrhrvAtAfKvtbHgYSGJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=btM/N0s+PIiLZQmqKVPV4MLgrgtZ1sdQQbf3JqezH8yJwDyaiRZohVRulUIWHxpJl IpZpNOiqkwmgV4Cv+hBh8y1xNji+tw/jWmagqoOTOWlnq7d/dOPvXNfIYJ8XgYZvHw SyhbVFbZFD6A7m+v8g/CL0+qosQ9SfMkAUQlXg0Q= 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 5.10 034/390] riscv: Allow PROT_WRITE-only mmap() Date: Mon, 24 Oct 2022 13:27:11 +0200 Message-Id: <20221024113024.063589708@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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 @@ -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)); }