* [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* Re: [PATCH] mm: swap: make swap_header badpages a flexible array
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
1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2026-11-21 0:31 UTC (permalink / raw)
To: kaleshsingh, akpm
Cc: kernel-team, android-mm, Kees Cook, stable, Chris Li, Kairui Song,
Kemeng Shi, Nhat Pham, Baoquan He, Barry Song, Youngjun Park,
Gustavo A. R. Silva, linux-mm
On 11/20/26 15:17, kaleshsingh@google.com wrote:
> 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>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
-Gustavo
> ---
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mm: swap: make swap_header badpages a flexible array
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
1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-11-21 0:47 UTC (permalink / raw)
To: kaleshsingh
Cc: SJ Park, akpm, kernel-team, android-mm, Kees Cook, stable,
Chris Li, Kairui Song, Kemeng Shi, Nhat Pham, Baoquan He,
Barry Song, Youngjun Park, Gustavo A. R. Silva, linux-mm
On Fri, 20 Nov 2026 06:17:49 +0000 kaleshsingh@google.com wrote:
> 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.
Makes sense to me.
>
> 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>
Reviewed-by: SJ Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox