All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: swap: make swap_header badpages a flexible array
@ 2026-11-20  6:17 kaleshsingh
  2026-11-21  0:31 ` Gustavo A. R. Silva
  2026-11-21  0:47 ` SJ Park
  0 siblings, 2 replies; 3+ messages in thread
From: kaleshsingh @ 2026-11-20  6:17 UTC (permalink / raw)
  To: akpm
  Cc: kernel-team, android-mm, Kalesh Singh, Kees Cook, stable,
	Chris Li, Kairui Song, Kemeng Shi, Nhat Pham, Baoquan He,
	Barry Song, Youngjun Park, Gustavo A. R. Silva, linux-mm

From: Kalesh Singh <kaleshsingh@google.com>

The swap header declares its list of bad pages as a one-element array,
even though the list can fill the rest of the header page. Since the
kernel is built with -fstrict-flex-arrays=3, the compiler takes that
size literally, so with UBSAN bounds checking, swapon() of a swap area
with two or more bad pages reports an out-of-bounds access:

  UBSAN: array-index-out-of-bounds in mm/swapfile.c:3674:26
  index 1 is out of range for type '__u32[1]' (aka 'unsigned int[1]')

Kernels that trap on UBSAN reports and panic on oops, such as Android
GKI kernels, crash instead.

Declare the list as a flexible array. The layout of the swap header
does not change.

Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kees Cook <kees@kernel.org>
Cc: stable@vger.kernel.org # 6.6.y, 6.12.y, 6.18.y
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
 include/linux/swap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 4f686709d71f..a3a98dc474c3 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -129,7 +129,7 @@ union swap_header {
 		unsigned char	sws_uuid[16];
 		unsigned char	sws_volume[16];
 		__u32		padding[117];
-		__u32		badpages[1];
+		__u32		badpages[];
 	} info;
 };
 

base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-21  0:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  6:17 [PATCH] mm: swap: make swap_header badpages a flexible array kaleshsingh
2026-11-21  0:31 ` Gustavo A. R. Silva
2026-11-21  0:47 ` SJ Park

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.