From nobody Mon Feb 9 17:25:16 2026 Received: from mail-244116.protonmail.ch (mail-244116.protonmail.ch [109.224.244.116]) (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 2C4824219EC for ; Wed, 4 Feb 2026 19:20:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770232807; cv=none; b=I9dIq4Fgp48uqAVV8Yfs8ulLE9IAzR9bLKynmtTbS684IdNIx1e5E6P47nBkTSwB2H49l5mrd4GRMjSi6PmB1tRruIrtIOl2tyLRC7TnMX/rA5ZHRD4S8x1Rdznieb0zQUjOpfrEgr4q+oI0n6Ag6y3BCXz7B+sbqpQ+Rwqr3zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770232807; c=relaxed/simple; bh=ZJ+qkwr5Z/QCS4Aw6YVbBIeKcAmQs66FLiD5jJIFr1o=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s4784oejplnDqt9eW9KyeKLATF79/CZ+xB46TpFybFlAznTd3n7+Nqku3mswDaRwuAYLt+MjqQat5ZALa11dezWT6oC3x6k69ixk1iDAQUqsFkGDJyeEOtRG4hQSMasvxDj0ehYI4OJfZvLPu+0skY3AjDsseRYF20k9SfCBjyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=CcDWouom; arc=none smtp.client-ip=109.224.244.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="CcDWouom" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1770232805; x=1770492005; bh=RmRX77ZIo9OEQe/UggGwGsoPALdXiYThzLUG8/anAWw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=CcDWouomo0M7ZpE+hyJRfvbl5GANIZtOfXmCKpQMMIwcdJrsm2Z/xEqBAvuIKt1ml LzXeeCLz6R41xOPV9s8BByhlorMEwe0ndTQvV9NSx6brRrvtmEpqVFmGRbwDEJSA6L 4Dp76Hcfhi4yMRFGwhWGyACwJC+OrGdDTbZ39PV9tm1KO9qOk616tHmDGdLbCp008K KrEUh4YGgYKUsRfg/UGdRRgOGy2bhqZFS3AxalbLPjtMzDeUrScdxKiv4uiPyfjpi9 6PRG6i7OgdkyXf9TrUeITzDH1HDFGHPmOEznY+7Qw/UuHtNJZANi6F3EBPNTW/v3U8 LDqu07jFBzN+g== Date: Wed, 04 Feb 2026 19:20:01 +0000 To: Andrew Morton , Mike Rapoport , Uladzislau Rezki From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, Maciej Wieczor-Retman , Alexander Potapenko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v10 06/13] mm/execmem: Untag addresses in EXECMEM_ROX related pointer arithmetic Message-ID: <98bfdbf081127ff064565a2c8b72c363f4fc0d5d.1770232424.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 1a4149de5a9cbe996829c30ae1db0bbbc1b883c3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maciej Wieczor-Retman ARCH_HAS_EXECMEM_ROX was re-enabled in x86 at Linux 6.14 release. vm_reset_perms() calculates range's start and end addresses using min() and max() functions. To do that it compares pointers but, with KASAN software tags mode enabled, some are tagged - addr variable is, while start and end variables aren't. This can cause the wrong address to be chosen and result in various errors in different places. Reset tags in the address used as function argument in min(), max(). execmem_cache_add() adds tagged pointers to a maple tree structure, which then are incorrectly compared when walking the tree. That results in different pointers being returned later and page permission violation errors panicking the kernel. Reset tag of the address range inserted into the maple tree inside execmem_vmalloc() which then gets propagated to execmem_cache_add(). Signed-off-by: Maciej Wieczor-Retman Acked-by: Alexander Potapenko Acked-by: Mike Rapoport (Microsoft) --- Changelog v10: - Add Mike's acked-by tag. Changelog v7: - Add Alexander's acked-by tag. - Add comments on why these tag resets are needed (Alexander) Changelog v6: - Move back the tag reset from execmem_cache_add() to execmem_vmalloc() (Mike Rapoport) - Rewrite the changelogs to match the code changes from v6 and v5. Changelog v5: - Remove the within_range() change. - arch_kasan_reset_tag -> kasan_reset_tag. Changelog v4: - Add patch to the series. mm/execmem.c | 9 ++++++++- mm/vmalloc.c | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/execmem.c b/mm/execmem.c index 810a4ba9c924..dc7422222cf7 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -59,7 +59,14 @@ static void *execmem_vmalloc(struct execmem_range *range= , size_t size, return NULL; } =20 - return p; + /* + * Resetting the tag here is necessary to avoid the tagged address + * ending up in the maple tree structure. There it's linear address + * can be incorrectly compared with other addresses which can result in + * a wrong address being picked down the line and for example a page + * permission violation error panicking the kernel. + */ + return kasan_reset_tag(p); } =20 struct vm_struct *execmem_vmap(size_t size) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index e286c2d2068c..2304d095c579 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3354,7 +3354,12 @@ static void vm_reset_perms(struct vm_struct *area) * the vm_unmap_aliases() flush includes the direct map. */ for (i =3D 0; i < area->nr_pages; i +=3D 1U << page_order) { - unsigned long addr =3D (unsigned long)page_address(area->pages[i]); + /* + * Addresses' tag needs resetting so it can be properly used in + * the min() and max() below. Otherwise the start or end values + * might be favoured. + */ + unsigned long addr =3D (unsigned long)kasan_reset_tag(page_address(area-= >pages[i])); =20 if (addr) { unsigned long page_size; --=20 2.53.0