Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3463827rwa; Tue, 23 Aug 2022 05:18:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Yo7xMoTI1soqCR5fMx1XJztt5DhFKUtm5cKg2MlzrqkB4NdrMArxiAdhyyDbq8M9W3EMi X-Received: by 2002:a17:902:b94b:b0:170:c9d6:a06d with SMTP id h11-20020a170902b94b00b00170c9d6a06dmr24487269pls.105.1661257126350; Tue, 23 Aug 2022 05:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257126; cv=none; d=google.com; s=arc-20160816; b=vHhUQnOtTcZLPvqoioc3+yUfNysWINn1YdwrosKaZmfZS0a2P7zdRrBIBJqD4/jjP8 SW5iDtbK9jAgiTc34U4tcHPOR/8LUt3OrdL7zSeasoyvYitBpPNRp/IouuBWP7nbH6Xv g4XIJZ4Z2URGKZgen+TMpoeB0JGmfVgXWw0WcDfi7kHz6PRbqMT5FLnDxL7chwqYIKGn 2x3B9V6x7SSLxCunMh3N0ZxoJYDLfLxtGQwvIm2wdQmOqaLAvcTZRhYbAW+BR1GmWGRp ezzkej6PRbLgtEB2G3irXcSPnv+tJ+ArBnQ6zReTNLLKrVRtXIL/c2gmOoeKStgXfeyG URfQ== 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=z/+Zms7HNsYwEvWhpCfcsZhuYvT2X1oK8hVNOA5C208=; b=tZAIEgiHYvCFFOo3SAgYF66RY32ZMAy2Q6mLHhy+pAY5/3yvnGIkDEMCVFKiVJoXJt JIYBSa6P1G+oNza4zpGQXXiTe+SPn8KzycxbqlAj2UwK5LGDEekQZxUVmBhESkTWsgRt i+RXB/zpUxrTpiuFTm1mUjHNGVcR+HRVwkHXkvOnSnUs8IFoPb8rNuNuL/rBV89adbc6 Y9K2tfdvctO5f+GgvG/hwZBHf6wk6p76nCAuT9BVGch+e1mXxFWBIqId4R4zl8S5QOQY A3rTKb/XShU2FDfJyt9rDaRhLUUtNc0uY+v95sX+0UgWiL7ylGXhyxqeZZTeMdAPkizt sgCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="b/Cq8yg7"; 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 u20-20020a056a00159400b0052b8da96658si16336384pfk.26.2022.08.23.05.18.35; Tue, 23 Aug 2022 05:18: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="b/Cq8yg7"; 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 S243824AbiHWKa3 (ORCPT + 99 others); Tue, 23 Aug 2022 06:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353054AbiHWKOR (ORCPT ); Tue, 23 Aug 2022 06:14:17 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB8457390D; Tue, 23 Aug 2022 01:59:57 -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 sin.source.kernel.org (Postfix) with ESMTPS id 4BD62CE1B45; Tue, 23 Aug 2022 08:59:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56448C433D6; Tue, 23 Aug 2022 08:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245194; bh=19IgdIE9ZrUrSbXsW+/oPm9vunuXvHYium+mpiIAJ+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b/Cq8yg71mixSskqs7sRDC7iHdhSd9LLgzUoeBpz9ukNfl1MsU2ZAWNYSY8kmqgiP 97Wl+/0RgEHebJT7d09af2Ju22CBxLVeE6Hh6As8XzglmbIMhAGVfuruZp7R8ZAZ+R V2jw9XDHPBl/LfwdOVQc5lckCyv4OnCjE2xaW9kE= 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.15 217/244] riscv: mmap with PROT_WRITE but no PROT_READ is invalid Date: Tue, 23 Aug 2022 10:26:16 +0200 Message-Id: <20220823080106.769520439@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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 12f8a7fce78b..8a7880b9c433 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