Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1652461rbb; Mon, 26 Feb 2024 17:36:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWCcIx7PolwMVk4H8dA6+Y+iElZTVj5cg/JLqcU8lsinJ3//dx5q7YqtKfYhqW38bzSbGr8AZvAqlBETzWdcqIQz/f9rsONh5qlAN84oA== X-Google-Smtp-Source: AGHT+IFeXc0ubavbyQGUxqWOZvJGV1nnSthevVhAObV81xZKt/msd3KMZ4lXkB1v+xvFFbYjF7/O X-Received: by 2002:a17:906:4e90:b0:a3e:d450:d3e2 with SMTP id v16-20020a1709064e9000b00a3ed450d3e2mr5667654eju.47.1708997772680; Mon, 26 Feb 2024 17:36:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708997772; cv=pass; d=google.com; s=arc-20160816; b=1DtLgoimVuQdWXSH0fPjo1isyMmd8SQ8/0AMz9RM3lRsmtkyohhEN0K6eLIYe0W+Mh 7mI0QpXQlMjR1vyD5dOMw2ft9jbPAwM6TXu5X9haDkO/iZccxVMsHWBke1wYkpwjiNyZ /xWDXIyzeaASTDRLXssizmTnJyH7jTH5AHOJFrCDtFxGyDEgD612WDOrqRYH2rQLeKuJ JxzOs5+lUPJ9xCl/ijmxKeZVbuUf54EImW9qj+5qYZCazIN6Fucc1st5/x5U8kHYmTct tTn3mlHYEIVJrHpOTA+l1XbsRdCH9KH0TCQtwaMn+0uuNoF5X6WXvGkuLcQvPAm71YpN Ds4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=djflHMn74Aoza7I3oyPhQDEGULANvQSmtPsfFrwIYIA=; fh=Q7vCzlRPJqbijdGCMcfQJMqFdj4BSllMtbPRSmFCmYI=; b=my+Jw+5VAWk6/D82Vbbr1y03DCGkCu3fq5b/YNiK+3wf004Fz2W0ZBbxi594bV7HtL /YVgk2sNlTK9TzdPn3wXk12z7TgsS/OSi5y9aC3C35tz8QeREkqDbYYNhUCb0yBMiD45 sa/9kCr9WyNcU+TRESbS/T0fMpLCGg7UeEIid0fEL9TWhvhJchVeYos3WLFEykivYlwa E7hpp0Fe3c+jY4WsPgZb2qEQFifsr6q8dnXlMvlSUifB07mps503rbwYzfFim7+cuk9s j0aMGux/Speal95MRrukJEnhK8iZr5dzIeYMjGXPciiNljrABG0K2KY8IBWLSM3GZgVg TQ9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b=AxLlMvyX; arc=pass (i=1 spf=pass spfdomain=bewilderbeest.net dkim=pass dkdomain=bewilderbeest.net dmarc=pass fromdomain=bewilderbeest.net); spf=pass (google.com: domain of linux-kernel+bounces-82538-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82538-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=bewilderbeest.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id sh20-20020a1709076e9400b00a42e3bdb7ccsi245708ejc.623.2024.02.26.17.36.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 17:36:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82538-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b=AxLlMvyX; arc=pass (i=1 spf=pass spfdomain=bewilderbeest.net dkim=pass dkdomain=bewilderbeest.net dmarc=pass fromdomain=bewilderbeest.net); spf=pass (google.com: domain of linux-kernel+bounces-82538-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82538-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=bewilderbeest.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6A2141F24CAD for ; Tue, 27 Feb 2024 01:36:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E80DEAE5; Tue, 27 Feb 2024 01:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.b="AxLlMvyX" Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EADF53A7; Tue, 27 Feb 2024 01:35:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=71.19.156.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708997757; cv=none; b=BBd6brvpNXgobFymLQhG/dF4YcvgHaL2tpZP3ihWqJYzjYH3vgHiunkkChq9Sd2K1LKIk5SOCbRoc5UItKjR+1Ivxzglb+f5iDoIrGJxmVBVVnc0yjL1fl/6iy6iLTfavduDb2d4NohMI8BHiFPZaZBo9s80LpljsHm+GR5qWpA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708997757; c=relaxed/simple; bh=cskhCraRLUN/8AG+y2v+YigFt0ecsFqLjy2QTRPHqrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dvEP0PRnTBtXYUFXuk2i4YYa+7hQclkO1v0HC9N90V4+K8JssQ1Q5Cgn77kTv9+8ZIiT89ghwFoS37+FWxklBTRyawh2tlSBPr/sp3H48XbVYthOnt9NtnKwtDXznUpGYrakUxSaANFvbbT/7hZdzPKhm7pPWO3PqSSAeo28jvc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bewilderbeest.net; spf=pass smtp.mailfrom=bewilderbeest.net; dkim=pass (1024-bit key) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.b=AxLlMvyX; arc=none smtp.client-ip=71.19.156.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bewilderbeest.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bewilderbeest.net Received: from hatter.bewilderbeest.net (unknown [IPv6:2602:61:712b:6300::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id BAB8642BE; Mon, 26 Feb 2024 17:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1708997755; bh=djflHMn74Aoza7I3oyPhQDEGULANvQSmtPsfFrwIYIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AxLlMvyXHvt14ldDBhIa4S0wWMk7ibuO9rV2OF7ak9xXdpCJTaFgDzP64nK/sv6Gm Fowrni/G+U1w2BihQcqwfrtfhR1BA4Cl1XVSXbu659qFAh+yQDK1nNCqPM1hssMDdE bWpi/y082Tr2j+A0xZ8/9iE6fD6FJJPTY1hpF18o= From: Zev Weiss To: Russell King , linux-parisc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Helge Deller , Florent Revest Cc: Zev Weiss , "James E.J. Bottomley" , "Borislav Petkov (AMD)" , Yin Fengwei , "Mike Rapoport (IBM)" , Andrew Morton , Kees Cook , Yang Shi , Rick Edgecombe , Oleg Nesterov , David Hildenbrand , Stefan Roesch , Josh Triplett , Ondrej Mosnacek , Miguel Ojeda , linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Sam James , stable@vger.kernel.org Subject: [PATCH RESEND 1/2] prctl: Generalize PR_SET_MDWE support check to be per-arch Date: Mon, 26 Feb 2024 17:35:41 -0800 Message-ID: <20240227013546.15769-5-zev@bewilderbeest.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227013546.15769-4-zev@bewilderbeest.net> References: <20240227013546.15769-4-zev@bewilderbeest.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There exist systems other than PARISC where MDWE may not be feasible to support; rather than cluttering up the generic code with additional arch-specific logic let's add a generic function for checking MDWE support and allow each arch to override it as needed. Signed-off-by: Zev Weiss Cc: # v6.3+ --- arch/parisc/include/asm/mman.h | 14 ++++++++++++++ include/linux/mman.h | 8 ++++++++ kernel/sys.c | 7 +++++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 arch/parisc/include/asm/mman.h diff --git a/arch/parisc/include/asm/mman.h b/arch/parisc/include/asm/mman.h new file mode 100644 index 000000000000..47c5a1991d10 --- /dev/null +++ b/arch/parisc/include/asm/mman.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MMAN_H__ +#define __ASM_MMAN_H__ + +#include + +/* PARISC cannot allow mdwe as it needs writable stacks */ +static inline bool arch_memory_deny_write_exec_supported(void) +{ + return false; +} +#define arch_memory_deny_write_exec_supported arch_memory_deny_write_exec_supported + +#endif /* __ASM_MMAN_H__ */ diff --git a/include/linux/mman.h b/include/linux/mman.h index dc7048824be8..bcb201ab7a41 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -162,6 +162,14 @@ calc_vm_flag_bits(unsigned long flags) unsigned long vm_commit_limit(void); +#ifndef arch_memory_deny_write_exec_supported +static inline bool arch_memory_deny_write_exec_supported(void) +{ + return true; +} +#define arch_memory_deny_write_exec_supported arch_memory_deny_write_exec_supported +#endif + /* * Denies creating a writable executable mapping or gaining executable permissions. * diff --git a/kernel/sys.c b/kernel/sys.c index f8e543f1e38a..8bb106a56b3a 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2408,8 +2408,11 @@ static inline int prctl_set_mdwe(unsigned long bits, unsigned long arg3, if (bits & PR_MDWE_NO_INHERIT && !(bits & PR_MDWE_REFUSE_EXEC_GAIN)) return -EINVAL; - /* PARISC cannot allow mdwe as it needs writable stacks */ - if (IS_ENABLED(CONFIG_PARISC)) + /* + * EOPNOTSUPP might be more appropriate here in principle, but + * existing userspace depends on EINVAL specifically. + */ + if (!arch_memory_deny_write_exec_supported()) return -EINVAL; current_bits = get_current_mdwe(); -- 2.43.2