A later patch in this series adds __GFP_SKIP_KASAN to GFP_HIGHUSER, so that with CONFIG_KASAN_HW_TAGS its pages are neither tagged on allocation nor poisoned on free. That suits pages whose contents belong to userspace and are mapped there. Some GFP_HIGHUSER users allocate buffers that the kernel itself fills and drains through kmap_local_page(), such as pipe buffers. While such pages are tagged, KASAN can report a linear overflow out of the page and an access to it while it is free. Add GFP_HIGHUSER_KASAN for these users, so that they can be converted before GFP_HIGHUSER changes. It has the value GFP_HIGHUSER has today and will not gain __GFP_SKIP_KASAN. The two stay identical without CONFIG_KASAN_HW_TAGS, where __GFP_SKIP_KASAN is 0. GFP_HIGHUSER_KASAN must not be used for memory that userspace can map with PROT_MTE (anonymous, shmem and hugetlb pages). Userspace sets the memory tags of such a page, while the kernel keeps accessing it through page_address() with the KASAN tag from page->flags. The two do not match, and kernel accesses are reported as KASAN faults. arm64 does not reset the tag in page->flags when the page is mapped; it relies on the page having been allocated with __GFP_SKIP_KASAN. Nothing checks for misuse at allocation or mapping time. No functional change. The kernel-doc describes GFP_HIGHUSER as it will be once it skips KASAN tagging. Assisted-by: LLM Signed-off-by: Jeff Xu --- include/linux/gfp_types.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index c1331bf0b239..567c93fc1cfb 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -356,6 +356,16 @@ enum { * move once in use. An example may be a hardware allocation that maps * data directly into userspace but has no addressing limitations. * + * %GFP_HIGHUSER_KASAN is %GFP_HIGHUSER for pages that the kernel itself reads + * and writes, such as pipe buffers. Unlike %GFP_HIGHUSER it does not skip + * KASAN tagging: with CONFIG_KASAN_HW_TAGS the pages get a KASAN tag, which + * page_address() and kmap_local_page() return in the pointer. It must not be + * used for memory that userspace can map with PROT_MTE (anonymous, shmem and + * hugetlb pages). Userspace sets the memory tags of such a page, so the + * kernel's tagged pointer no longer matches them and kernel accesses to the + * page are reported as KASAN faults. Nothing checks for this at allocation + * or mapping time; those reports are the only sign of misuse. + * * %GFP_HIGHUSER_MOVABLE is for userspace allocations that the kernel does not * need direct access to but can use kmap() when access is required. They * are expected to be movable via page reclaim or page migration. Typically, @@ -377,6 +387,7 @@ enum { #define GFP_DMA __GFP_DMA #define GFP_DMA32 __GFP_DMA32 #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) +#define GFP_HIGHUSER_KASAN (GFP_USER | __GFP_HIGHMEM) #define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKIP_KASAN) #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) base-commit: 4b028d0cedf95f66b8c5294fde2d7d698bf830da -- 2.56.0.611.g1030f0b940-goog