From patchwork Mon Oct 24 11:27:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp689216wru; Mon, 24 Oct 2022 15:52:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vHLndVZtRbd0+ecth7WgEF8oY9BENfz9GblgYUEk59Vj15NHgQajm8Cju5wsc+pTr9Y92 X-Received: by 2002:a62:fb14:0:b0:56b:de9f:10ba with SMTP id x20-20020a62fb14000000b0056bde9f10bamr6304915pfm.30.1666651974730; Mon, 24 Oct 2022 15:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666651974; cv=none; d=google.com; s=arc-20160816; b=E9HdrvnOWWYTXc6FAIytWCBRXNjxL/M6/qaDSfy+HliWuBW12NHXxFDtB4mKF8vAMF 1LpxCsp3/42Ci+N2oN+hvGKtdVmHKArFTXSWpkLsJ+Eb5fMYDskvKi2zn2FQtBRpI08m qssah/vLwu7Miypdn/y5EHdVOyBJkTTlKhP8j0kg6n6BgBJBL0DBhSznwF6tazLHwXza FpAQqtCOGMBG8ITf3C2yW9fzl5CSK90p8ahWuLH5LCZvdXoRPXBUO3acDxwNlty73LB4 pwISQ3R1vLGpdPnTuprznQEHEk6XSnakidu1EvfKRBKu6bgHThJEmVAeo2JlA9BfR8WY bPTA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q18-20020a170902eb9200b00182bccf6195si786925plg.596.2022.10.24.15.52.40; Mon, 24 Oct 2022 15:52:54 -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 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?1747611261298777160?= X-GMAIL-MSGID: =?utf-8?q?1747611261298777160?= 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)); }