From patchwork Sat Oct 22 07:18:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1088714wrr; Sat, 22 Oct 2022 00:41:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71idtYIxLBCFV9gFZqhREshueW8qJVwN1FOw5xX/LcNlgGP+Y3dsbHB6orJ9BiKr+9JGAF X-Received: by 2002:aa7:810a:0:b0:55b:674d:d123 with SMTP id b10-20020aa7810a000000b0055b674dd123mr23823789pfi.52.1666424462305; Sat, 22 Oct 2022 00:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424462; cv=none; d=google.com; s=arc-20160816; b=j7e8FgLf9M5OFoRYDypqYa242taXaZNIrry00NlF1wlusRH6x4RkINE5o3RtCqyyCA as58Julxx2ZN5A4QZI5QHEad25LrSDe1KN7jlmZKcqS6FHCbezKX4IS82eObsQAkPCGA LEIBD8f59noobDv/n6MOTYiO9qblLgx7Qt0Xwlj7PEYcfFIix3VHM0vlOF1aTmU0F/Mv KLAdKQa088ZNJN6yNmCaydZepsF1HhLocre2RgIvaWM7QLp50AWLyvl/JflQYeFsn+yR fByQEg4qjmJ7MhwqkvE64QAW4bFX10178vSj7sA7tAMjLJt+KGGnGReLwdZhhJ8mQvOr AOPA== 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=FMfdQb97UACyYNB65SWfelEPZelDeIuVJUXS3RMT7tHrowCIMpjgk+Bxff0cP46SUM JG+KzHYxuv+qe1kxftkiOrsVUVIjtE2bc5vXJ7BrewKqyGGin4fua3KD3Ss3FTeBwasj AiFbJgMJjKyIMgjSdyPtL6BXeWgaA6iRzvN0wzsvxvLgInvg24MR6YrN5VwsYb3SLyEb 8qPWGXxdVWZOh95lIMypSritEDnSlcO0FjNu5UFyGD0QXnBH4TnhziqVjhVTqUh1VLmp UnX4uaxOewnMYN4jVqPVgbvoPB+Jt7MTP+01J7Q7Q8gbjl1ACd1sw4gLo6ahZqF/HaTk h0mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pNwAHnge; 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 o8-20020a170902bcc800b00182c510591asi25086580pls.246.2022.10.22.00.40.49; Sat, 22 Oct 2022 00:41:02 -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=pNwAHnge; 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 S230461AbiJVHkW (ORCPT + 99 others); Sat, 22 Oct 2022 03:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbiJVHj0 (ORCPT ); Sat, 22 Oct 2022 03:39:26 -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 04E962B322A; Sat, 22 Oct 2022 00:36:52 -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 54773B82D9F; Sat, 22 Oct 2022 07:36:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A90F4C433D6; Sat, 22 Oct 2022 07:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424192; bh=u8jCsQTg+AUQ8MfWiYmhRVCIrhrvAtAfKvtbHgYSGJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pNwAHngeT2MGbN+zJJwpoMa2G4wU6qSxpg36yY3gtZjSfaZuuGodXdzgzDvIJCrJt 2xoqhEFVrb8AVUWHTvd3hVsqdEqjMcF8LPPcETBJAyjqmUAjtjYiQ3vHMHeLM70AA7 X6f3rGx23wnwbRXgDYJi0QIBjbBDkoH8gTCV6cmk= 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.19 056/717] riscv: Allow PROT_WRITE-only mmap() Date: Sat, 22 Oct 2022 09:18:55 +0200 Message-Id: <20221022072424.987680535@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747372696970016469?= X-GMAIL-MSGID: =?utf-8?q?1747372696970016469?= 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)); }