From patchwork Mon Oct 24 11:28:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp441339wru; Mon, 24 Oct 2022 06:05:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DJbfZzE2rhY2HNc73YLax13RW6cw5mXf2Z4NvT68xjYL9xAGKMAHieh23WHIypw/7rw9P X-Received: by 2002:a17:903:120e:b0:179:fe49:a952 with SMTP id l14-20020a170903120e00b00179fe49a952mr33238434plh.21.1666616746965; Mon, 24 Oct 2022 06:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616746; cv=none; d=google.com; s=arc-20160816; b=cBtOmLNjZdk+FVO1WACutJ2ShicG90DCQ6TU9AjfZ/YBGroUq2l97UpwCnN4v8xMHs oIVKTYrN4Rz1U6NhfR6mmtmZ4jZTKF9+soSM8RXQrUwAA3FxhAFoEgGZZ/r0o6k11eGW AWjlhuwTh+6yUSEYrMsafOKBwXtb68dbxKKykZ5I6bZMkVkGHd+a3yGrSWbq6OaxCDqq 5yOc9oMvmJKmNtwnXC8vzhrCMCmSHdpzs0r3Yq8pkSD3XYu5dRzm0ulGEqc2M+9qFbJi uOXEY6xcwtzVt2L4W2FFt6e+tlbmI0r+KQTsYLTWMFRpQsr3/lSybHTmWMpkE/tHzxBM z4bw== 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=Ra7tQvXg+mPh6POSh4X3v198kIaP5bX5qn0iAOcqX4UkcywhaMOqM+rk5CBmsHCZcz +Pp5hwsrPXXQRClcAQtOw37ExPHGZPd0/XT9/LTYFpaUEFCIk4ZoNA4HBN12nFnhcRe8 SDx4D+H+xnzylYRIhrnN5cOT+GcPdXzzTEBa+qD6NrhkiDYvm6/v26g9F/VmBCVkixCv pgKGMiF6TD8X03Bk/OSG7jOzmpzPmODQToQCOq7ULUSV+NL3ZS/0utCTa8AXwV4MPIvU Q2mK3YMqbtUFrmRBzLBeRaFic/8KCuUEOl+Ae6RSEZfpRP06vBJFezzTzRflrqZGMZG+ q9Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="OXZ5/6Nw"; 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 t24-20020a056a00139800b0056bdae22580si3291719pfg.338.2022.10.24.06.05.08; Mon, 24 Oct 2022 06:05:46 -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="OXZ5/6Nw"; 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 S235297AbiJXNEO (ORCPT + 99 others); Mon, 24 Oct 2022 09:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235398AbiJXNAP (ORCPT ); Mon, 24 Oct 2022 09:00:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26EFF13DE7; Mon, 24 Oct 2022 05:19:33 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 15C29612F0; Mon, 24 Oct 2022 12:07:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D0E1C433D6; Mon, 24 Oct 2022 12:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613232; bh=u8jCsQTg+AUQ8MfWiYmhRVCIrhrvAtAfKvtbHgYSGJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXZ5/6NwDMPjcaEKA1bYzXWZb9W8vYpe4u1+k88/ahSKIe10v1VU84iy7dBaB3giE Ix5Y4h13BsXiLLsqKDcoTdcMMBzAqJhhuOd4jPrbAs83XB17xQlvmA+mVLYukUDf9m US8zG0Atez6zc4rRRI9EISdzO+zH/Sz+H7cIc3QU= 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.4 029/255] riscv: Allow PROT_WRITE-only mmap() Date: Mon, 24 Oct 2022 13:28:59 +0200 Message-Id: <20221024113003.412136922@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747574321624028792?= X-GMAIL-MSGID: =?utf-8?q?1747574321624028792?= 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)); }