Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: kaleshsingh@google.com, akpm@linux-foundation.org
Cc: kernel-team@android.com, android-mm@google.com,
	Kees Cook <kees@kernel.org>,
	stable@vger.kernel.org, Chris Li <chrisl@kernel.org>,
	Kairui Song <kasong@tencent.com>,
	Kemeng Shi <shikemeng@huaweicloud.com>,
	Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
	Barry Song <baohua@kernel.org>,
	Youngjun Park <youngjun.park@lge.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm: swap: make swap_header badpages a flexible array
Date: Sat, 21 Nov 2026 09:31:05 +0900	[thread overview]
Message-ID: <7603f730-3607-4c1f-803a-ae501e41b824@embeddedor.com> (raw)
In-Reply-To: <20261120061750.2973004-1-kaleshsingh@google.com>



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


  reply	other threads:[~2026-11-21  0:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-21  0:47 ` SJ Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7603f730-3607-4c1f-803a-ae501e41b824@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=akpm@linux-foundation.org \
    --cc=android-mm@google.com \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=kaleshsingh@google.com \
    --cc=kasong@tencent.com \
    --cc=kees@kernel.org \
    --cc=kernel-team@android.com \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=stable@vger.kernel.org \
    --cc=youngjun.park@lge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox