linux-stable/include
David Hildenbrand 6564b014af mm/secretmem: fix GUP-fast succeeding on secretmem folios
commit 65291dcfcf upstream.

folio_is_secretmem() currently relies on secretmem folios being LRU
folios, to save some cycles.

However, folios might reside in a folio batch without the LRU flag set, or
temporarily have their LRU flag cleared.  Consequently, the LRU flag is
unreliable for this purpose.

In particular, this is the case when secretmem_fault() allocates a fresh
page and calls filemap_add_folio()->folio_add_lru().  The folio might be
added to the per-cpu folio batch and won't get the LRU flag set until the
batch was drained using e.g., lru_add_drain().

Consequently, folio_is_secretmem() might not detect secretmem folios and
GUP-fast can succeed in grabbing a secretmem folio, crashing the kernel
when we would later try reading/writing to the folio, because the folio
has been unmapped from the directmap.

Fix it by removing that unreliable check.

Link: https://lkml.kernel.org/r/20240326143210.291116-2-david@redhat.com
Fixes: 1507f51255 ("mm: introduce memfd_secret system call to create "secret" memory areas")
Signed-off-by: David Hildenbrand <david@redhat.com>
Reported-by: xingwei lee <xrivendell7@gmail.com>
Reported-by: yue sun <samsun1006219@gmail.com>
Closes: https://lore.kernel.org/lkml/CABOYnLyevJeravW=QrH0JUPYEcDN160aZFb7kwndm-J2rmz0HQ@mail.gmail.com/
Debugged-by: Miklos Szeredi <miklos@szeredi.hu>
Tested-by: Miklos Szeredi <mszeredi@redhat.com>
Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-10 16:19:43 +02:00
..
acpi
asm-generic arch: Introduce CONFIG_FUNCTION_ALIGNMENT 2024-04-10 16:18:49 +02:00
clocksource
crypto crypto: af_alg - Disallow multiple in-flight AIO requests 2024-01-25 14:52:34 -08:00
drm drm/ttm: add ttm_resource_fini v2 2024-03-26 18:21:25 -04:00
dt-bindings dt-bindings: clocks: imx8mp: Add ID for usb suspend clock 2024-03-01 13:21:53 +01:00
keys
kunit
kvm
linux mm/secretmem: fix GUP-fast succeeding on secretmem folios 2024-04-10 16:19:43 +02:00
math-emu
media
memory
misc
net tcp: properly terminate timers for kernel sockets 2024-04-10 16:19:35 +02:00
pcmcia
ras
rdma RDMA/core: Fix umem iterator when PAGE_SIZE is greater then HCA pgsz 2023-12-13 18:36:40 +01:00
scsi
soc soc: fsl: qbman: Add CGR update function 2024-04-10 16:18:42 +02:00
sound ASoC: soc-card: Add storage for PCI SSID 2023-11-28 16:56:17 +00:00
target
trace NFSD: add CB_RECALL_ANY tracepoints 2024-04-10 16:19:24 +02:00
uapi fanotify: introduce FAN_MARK_IGNORE 2024-04-10 16:19:07 +02:00
vdso
video
xen