Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3025712ybt; Mon, 29 Jun 2020 13:14:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP8VKXONzrJiFQt5R9xmyVow90Yxyan4c/EdmXz7eCVe7JQoHvSTgsXKYwB5RTxTx+8ozM X-Received: by 2002:aa7:c816:: with SMTP id a22mr2371446edt.28.1593461654685; Mon, 29 Jun 2020 13:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593461654; cv=none; d=google.com; s=arc-20160816; b=Xbrz15RwobT5GGxt9Sza1WbIa4cwYgl2EfnEb1R9nrVkHowk/dOp/+Ymy8LZv2FmQ9 UVFV3OmLeLPviKncWcyLHro2sMuKJFXPAjLojdGYeyaWCeWKncrG+FLFPa2Sx91LnRHI sNxq8nsvMruPfyqI5QjJzIev3yzDY9l5zWATDMowt6I5JKU7IzTumZOrPnvKzm0RETpp +R610Jd9kSxzOUziFgNBcoYEcUoL6gewGmUBonikrgC/KeRMBsum0GIbbBxQYWN73lJ9 EZumNzCAjfoRO2disDY3ACRrTHILuKqqJy1gQLttfqd6SomNwI7o93zisW/CAvihvUKY ZdYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k/wzpoNusVM8C+BCcMT+eAKqfqDrJ+5yA+MElYBai24=; b=WWLlca2CX+uGj9F9X1e+Wqb7wBW7Za2QizYcfzvDpEx0XvbpYbYjNs+VWLSC5AY+gW 2uab/gIud4OkizcB8sJg80unhUNlBZWqO7ainNZ+PgA3Z7Dcppt5Xygp5IcivWha97tb 0aO2FRXHj64gbWhhKloAVekUOiVdfI1hcI4bbGQmMkaNvm6vmFg6UjXY+F9jy2G57xtE Jaej4af6WAHxCKD2jjLgdun9J/gC48cPI+rejKL2vPxyKoxCLMRKI14cvHHm9MZxl7W+ 6vfWAof2kOw/avaBnxfvxmD291A9+25vzZVpTaoXMRxxk/jRBxXrrM/AhqnnA8dychrd tf0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1EgqCQVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf2si306673edb.288.2020.06.29.13.13.51; Mon, 29 Jun 2020 13:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1EgqCQVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729306AbgF2UKp (ORCPT + 99 others); Mon, 29 Jun 2020 16:10:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:40574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732907AbgF2TaW (ORCPT ); Mon, 29 Jun 2020 15:30:22 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59A6625294; Mon, 29 Jun 2020 15:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593445003; bh=lxhKP8mUk7NWPWZ5S591OwGbHEUQgWTP8rlI4jSLJjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1EgqCQVtceaIXlgoCZqKpXCb+tyYdMtu1iWa1BW76C7IauegyFC7JTzThVGk1fXmC T+fxSRNpLyBJtMbntxlGJryN3wSKUeFkxe7BiCqLn7ae+AeUirhoNStF07jD+ben/j hCYhu0r2tXO2a9RY12pKupILOi8g8+82qeBfFXnU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yash Shah , David Abdurachmanov , Palmer Dabbelt , Sasha Levin Subject: [PATCH 4.19 103/131] RISC-V: Don't allow write+exec only page mapping request in mmap Date: Mon, 29 Jun 2020 11:34:34 -0400 Message-Id: <20200629153502.2494656-104-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629153502.2494656-1-sashal@kernel.org> References: <20200629153502.2494656-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.131-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.131-rc1 X-KernelTest-Deadline: 2020-07-01T15:34+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yash Shah [ Upstream commit e0d17c842c0f824fd4df9f4688709fc6907201e1 ] As per the table 4.4 of version "20190608-Priv-MSU-Ratified" of the RISC-V instruction set manual[0], the PTE permission bit combination of "write+exec only" is reserved for future use. Hence, don't allow such mapping request in mmap call. An issue is been reported by David Abdurachmanov, that while running stress-ng with "sysbadaddr" argument, RCU stalls are observed on RISC-V specific kernel. This issue arises when the stress-sysbadaddr request for pages with "write+exec only" permission bits and then passes the address obtain from this mmap call to various system call. For the riscv kernel, the mmap call should fail for this particular combination of permission bits since it's not valid. [0]: http://dabbelt.com/~palmer/keep/riscv-isa-manual/riscv-privileged-20190608-1.pdf Signed-off-by: Yash Shah Reported-by: David Abdurachmanov [Palmer: Refer to the latest ISA specification at the only link I could find, and update the terminology.] Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/kernel/sys_riscv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index fb03a4482ad60..db44da32701f2 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -16,6 +16,7 @@ #include #include #include +#include static long riscv_sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, @@ -24,6 +25,11 @@ 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; + return ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> (PAGE_SHIFT - page_shift_offset)); } -- 2.25.1