Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3325562rwa; Tue, 23 Aug 2022 02:53:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR6fZedwc5QtPwh5XX2vriKuEGS0gux9alN7NK8ot3jR/SDK9cZsx8uSwHFNlL5g6O2ZBwm0 X-Received: by 2002:a17:907:e8c:b0:73d:8146:9aa1 with SMTP id ho12-20020a1709070e8c00b0073d81469aa1mr6303526ejc.253.1661248417288; Tue, 23 Aug 2022 02:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248417; cv=none; d=google.com; s=arc-20160816; b=IshPqMjIymk3BhBP8WRb2sVcP3776Yyv0u3usWp7eCQUNIFYifLXCybwwccavQrjJs gh+Sx9zA6RNmynxODLgghAWzUJVNeAQSsYnl5k1iG9ecPYbfHXnj4MjaCL+ZQ3EouAcw 86vMHBHZ5Fub1GvSVDBQBTfQQjN6iiKsqH0hkWbuhUY95EEBgSd0l6/Hh2YVO9FaB1uC EOSbUTl8ccbha8A+9SV+o477WEyrtGYAmMd3dZd5ptf4M4We9PZGlOPKn5UlYaSf1IAs poMzZHN+7Lpegq5iOV36MvX15aavvJ5mW7R3hXQaM/44nwSrGpEEKD+9VcNgNbQ5glT3 jBzg== 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=cT1OEU6ewqf3wwApqIP2DAJ4vl9MOgBE0EfdbSHIYr4=; b=Bhsv+gcpLGp/9zJ2XKyeS9D0VW4dyE1fpwtn81DpTxEIDeXL0H4kHJgqHDsr/G4VSn FDu6uzsYfhd2GJl4Gi0A9AR/TTWN8RTQB+xfkg/a3K2/ux+9D/UYdF4Gvy5qn2176M+C tQNZ40tAczn14sM4imBPYo+13E1krVUGRJRdHUEsDKksSuAKyw8tusfsKDwr+09tGX/i 75jmPcDA51pF2AndbZHTlkFXM5rP1JJoTyZl2zCCqUaqCdDCIg9VEHcM7QsVNitl9ru2 +m8TYA2c0iKT6aNkVt62yTl+BKxvGy2DF+n30VkPvoxE2rAOdbFHnyXDtzfzZ123h3U0 rSmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZQWl6apK; 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 b12-20020a056402084c00b0043df391fcbesi2131451edz.583.2022.08.23.02.53.11; Tue, 23 Aug 2022 02:53:37 -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=ZQWl6apK; 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 S1350173AbiHWJ2p (ORCPT + 99 others); Tue, 23 Aug 2022 05:28:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350408AbiHWJZr (ORCPT ); Tue, 23 Aug 2022 05:25:47 -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 1148176771; Tue, 23 Aug 2022 01:36:31 -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 92267B81C59; Tue, 23 Aug 2022 08:35:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0444C433D7; Tue, 23 Aug 2022 08:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243721; bh=ZvgNG1eC9iccsixk7C5q3yyyNPKNAPFVwtvxIcix/aA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQWl6apKiXthWG134NyIRClul97N0SXtG0XfNLtk/VNzutZCTo82wWhzqrFWCwJvN 7ocQL5/rfddbU2tcu4TKM5tbzCKVur2aU0xB3J500EUUL/AulQ5tj2a7Zk8/jjPbtf G7eJFOnvAH845VZAC/7cRYBmFr+FCWiuxGAjZaZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, xctan , dram , Ruizhe Pan , Celeste Liu , Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.19 336/365] riscv: mmap with PROT_WRITE but no PROT_READ is invalid Date: Tue, 23 Aug 2022 10:03:57 +0200 Message-Id: <20220823080132.268502471@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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.1 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,T_SCC_BODY_TEXT_LINE 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: Celeste Liu [ Upstream commit 2139619bcad7ac44cc8f6f749089120594056613 ] As mentioned in Table 4.5 in RISC-V spec Volume 2 Section 4.3, write but not read is "Reserved for future use.". For now, they are not valid. In the current code, -wx is marked as invalid, but -w- is not marked as invalid. This patch refines that judgment. Reported-by: xctan Co-developed-by: dram Signed-off-by: dram Co-developed-by: Ruizhe Pan Signed-off-by: Ruizhe Pan Signed-off-by: Celeste Liu Link: https://lore.kernel.org/r/PH7PR14MB559464DBDD310E755F5B21E8CEDC9@PH7PR14MB5594.namprd14.prod.outlook.com Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/kernel/sys_riscv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 9c0194f176fc..571556bb9261 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -18,9 +18,8 @@ static long riscv_sys_mmap(unsigned long addr, unsigned long len, if (unlikely(offset & (~PAGE_MASK >> page_shift_offset))) return -EINVAL; - if ((prot & PROT_WRITE) && (prot & PROT_EXEC)) - if (unlikely(!(prot & PROT_READ))) - 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.35.1