From patchwork Thu Feb 8 01:26:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 20081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2617903dyb; Wed, 7 Feb 2024 17:27:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+FxbZfbcoX+7mJw9EF2YEk6NVUOOk2rOu6E5hoVnpPMUKcawOoetiYxEyMXHpP9K3GoUDcz1v3UDS/1BEE3Zropp2Wg== X-Google-Smtp-Source: AGHT+IGt52gBLfRGifSL5oDk+VTUz1hdUh/LxEk3EkHqqPdtOEtpm2EVzV/Vy/MAUsPRzPd7OBVf X-Received: by 2002:a17:906:6806:b0:a38:a0f6:cd2c with SMTP id k6-20020a170906680600b00a38a0f6cd2cmr1409883ejr.3.1707355655131; Wed, 07 Feb 2024 17:27:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707355655; cv=pass; d=google.com; s=arc-20160816; b=zIQGkdHSd7mrjuDhm6HEYYrvnL+kPmfpeNHv/SyylfXik2WZRDvHPy3kkP3aLzT8JO WgnfF+BHekCDca5UNkbV63mUU6GL+wyIkQLXCqiJHu9hGKMW/wt0HOJ8vA33XClsSEbb krlSq6dALtWIDxI+MP5x718GULgoXakY5OIf3Bk5i2yC8QAFwdp3PyAmMamPAel2rr8w hXm5LmXQAlfZTk0QE8H5QQ2h8pUZIIdBHIgAySJ+E2K3m6Gt7yjy3WTxTeH7XzJlajFS jH5oPYZCvhggWq20kV/6GYhjEFgEbbvZM9Vi9d8NOSoFhYstovm214lJz8u3Hj0HpMyv VBnQ== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=6ONNLssa/JJa3YO5Up1AtekZAzMtVDM0uR/O3aO7Adc=; fh=+aXUOph8BvujcsEM0aHMjGpOotaJhc/ZMrzDaZj1h28=; b=j+LtzzRtAmgsNBIwoDQac6u/jk8b0ISNLoVoFM96hrTXR9GDQqZdlr6uWpEwcm8tHR 3Sh/6QZY5AikftOWYkkmyWh+PsN4Bvu+h5e9cq3ECOFQVeYdjBUTFw2kNoa6Cf7Tz/8h SLv12XRbaya3rcj8x5kuyzd4XC4l84r+zSwxD019Q2ZiAQmTYNHqza5MIk2SiVH3Y1iZ 3l7bw+t4fJRqTq98KTYyfnCrcFVkW5fHNMuv/G6Ft21AjnipyaMfb0AJLPwS+zz9tTMN lwDdvvyD1fao32+S0wwgBChzbwEbnIu4esdF38zRrlaoOYRkiN/HcEJPvULp1TiouKLv MrxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b=irSxI+Fu; 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-57365-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57365-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=bewilderbeest.net X-Forwarded-Encrypted: i=2; AJvYcCXU65j5q6AFW8aCaE6EnYcimTMflEGykfeo4nBAqNVqjnD3M1qL8Gjaoh+MOW/8DxSuDijZ3zOpVOhkkZmMKxb+CPM/hA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j18-20020a170906411200b00a3875415ccdsi1462585ejk.243.2024.02.07.17.27.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 17:27:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57365-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b=irSxI+Fu; 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-57365-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57365-ouuuleilei=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 B9F151F2357F for ; Thu, 8 Feb 2024 01:27:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65A632C185; Thu, 8 Feb 2024 01:26:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.b="irSxI+Fu" 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 982541D6AA; Thu, 8 Feb 2024 01:26:35 +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=1707355598; cv=none; b=dF3x15Z4GqfnUzdnEchVMEfvveN4lF1OcVNpOnrWuyjO2j2c2RCOJdeyq+bHF7IFQq5SKVjR7qrliD63y6OMgLj1ekdHa0abLAVpNqXg1OA2tUmIhb2UxLtwd9FkNJlkVZhz1HcAzuDkMo6gAzMDSRpBX6t2Gd3VMbeyLztAHoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707355598; c=relaxed/simple; bh=j6d/T+9LmwknQyPw9UW66o8FfW4OYtd1tl4c1Kp289Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q8qDgyLVtcgomhI25XuNEoSQbnU0soaYie/qCsx0TA6haSXdrLukY3mJ7AcBr13cvV+xnnd7boMywTYrNepwj8KG6AwWW7ABeVPB8kJ+3sty1Xsrrvh9mlxiXD5NR1zNoOOYGi79wMTfIejfpwnwA1nJilS2NqDUAc4mAtSDU0c= 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=irSxI+Fu; 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 44659C9; Wed, 7 Feb 2024 17:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1707355588; bh=6ONNLssa/JJa3YO5Up1AtekZAzMtVDM0uR/O3aO7Adc=; h=From:To:Cc:Subject:Date:From; b=irSxI+FuU1hFzLtneHeVJ0eyyzW/aD27p1URn43PrNZ3mCJTaF8gG/XgUnNZoO+A/ oZkd4fPJQiT+LDTivSrrTc7wgokOgZn9Kdqxjenj0Yik29OMCIppa5NAZ2AV3SPt0B ma0+vsxmXVNd0y/4K0ylCCx3i+O8juWJez93rPa4= From: Zev Weiss To: linux-parisc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Helge Deller , Florent Revest Cc: Zev Weiss , "James E.J. Bottomley" , "Mike Rapoport (IBM)" , Rick Edgecombe , "Borislav Petkov (AMD)" , Andrew Morton , Yang Shi , Stefan Roesch , Oleg Nesterov , David Hildenbrand , Josh Triplett , Ondrej Mosnacek , Miguel Ojeda , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Russell King , Sam James , stable@vger.kernel.org Subject: [PATCH 0/2] ARM: prctl: Reject PR_SET_MDWE where not supported Date: Wed, 7 Feb 2024 17:26:18 -0800 Message-ID: <20240208012620.32604-4-zev@bewilderbeest.net> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790292162950194061 X-GMAIL-MSGID: 1790292162950194061 Hello, I noticed after a recent kernel update that my ARM926 system started segfaulting on any execve() after calling prctl(PR_SET_MDWE). After some investigation it appears that ARMv5 is incapable of providing the appropriate protections for MDWE, since any readable memory is also implicitly executable. (Note that I'm not an expert in either ARM arch details or the mm subsystem, so please bear with me if I've botched something in the above analysis.) The prctl_set_mdwe() function already had some special-case logic added disabling it on PARISC (commit 793838138c15, "prctl: Disable prctl(PR_SET_MDWE) on parisc"); this patch series (1) generalizes that check to use an arch_*() function, and (2) adds a corresponding override for ARM to disable MDWE on pre-ARMv6 CPUs. With the series applied, prctl(PR_SET_MDWE) is rejected on ARMv5 and subsequent execve() calls (as well as mmap(PROT_READ|PROT_WRITE)) can succeed instead of unconditionally failing; on ARMv6 the prctl works as it did previously. Since this was effectively a userspace-breaking change in v6.3 (with newer MDWE-aware userspace on older pre-MDWE kernels the prctl would simply fail safely) I've CCed -stable for v6.3+, though since the patches depend on the PARISC one above it will only apply cleanly on the linux-6.6.y and linux-6.7.y branches, since at least at time of writing the 6.3 through 6.5 branches don't have that patch backported (due to further missing dependencies [0]). Thanks, Zev [0] https://lore.kernel.org/all/2023112456-linked-nape-bf19@gregkh/ Zev Weiss (2): prctl: Generalize PR_SET_MDWE support check to be per-arch ARM: prctl: Reject PR_SET_MDWE on pre-ARMv6 arch/arm/include/asm/mman.h | 14 ++++++++++++++ arch/parisc/include/asm/mman.h | 14 ++++++++++++++ include/linux/mman.h | 8 ++++++++ kernel/sys.c | 7 +++++-- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/mman.h create mode 100644 arch/parisc/include/asm/mman.h