* [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon()
@ 2026-11-18 11:26 Oleksandr Natalenko
2026-11-18 13:40 ` Youngjun Park
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Oleksandr Natalenko @ 2026-11-18 11:26 UTC (permalink / raw)
To: linux-mm
Cc: Rafael Aquini, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park
One of the enterprise customers uses 6 TiB of swap, and the values
reported in /proc/swaps as well as in dmesg are still not correct.
Cast si->pages to long explicitly so that the bitshift in K() doesn't
truncate the value to 32 bits.
Also do the same in swapon() for the same reason.
Fixes: 642929a2ded0 ("mm/swapfile: fix an integer overflow in swap_show()")
Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name>
---
mm/swapfile.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 626f3e9afc01e..3eadddc49a9d4 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3450,7 +3450,7 @@ static int swap_show(struct seq_file *swap, void *v)
return 0;
}
- bytes = K(si->pages);
+ bytes = K((unsigned long)si->pages);
inuse = K(swap_usage_in_pages(si));
file = si->swap_file;
@@ -3959,8 +3959,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
/* Sets SWP_WRITEOK, resurrect the percpu ref, expose the swap device */
enable_swap_info(si);
- pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s\n",
- K(si->pages), name->name, si->prio, nr_extents,
+ pr_info("Adding %luk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s\n",
+ K((unsigned long)si->pages), name->name, si->prio, nr_extents,
K((unsigned long long)span),
(si->flags & SWP_SOLIDSTATE) ? "SS" : "",
(si->flags & SWP_DISCARDABLE) ? "D" : "",
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon()
2026-11-18 11:26 [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon() Oleksandr Natalenko
@ 2026-11-18 13:40 ` Youngjun Park
2026-11-18 13:42 ` Oleksandr Natalenko
2026-11-18 16:07 ` Nhat Pham
2026-11-23 6:25 ` [merged mm-hotfixes-stable] mm-swapfile-really-fix-integer-overflow-in-swap_show-and-swapon.patch removed from -mm tree Andrew Morton
2 siblings, 1 reply; 5+ messages in thread
From: Youngjun Park @ 2026-11-18 13:40 UTC (permalink / raw)
To: Oleksandr Natalenko
Cc: linux-mm, Rafael Aquini, Andrew Morton, Chris Li, Kairui Song,
Kemeng Shi, Nhat Pham, Baoquan He, Barry Song
Hi Oleksandr,
> Cast si->pages to long explicitly so that the bitshift in K() doesn't
> truncate the value to 32 bits.
Nice catch. 642929a2ded0 widened bytes but left the shift in 32 bits.
> Fixes: 642929a2ded0 ("mm/swapfile: fix an integer overflow in swap_show()")
stable kernels show the same wrong size, should this also
carry Cc: stable@vger.kernel.org?
Reviewed-by: Youngjun Park <youngjun.park@lge.com>
Thanks,
Youngjun
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon()
2026-11-18 13:40 ` Youngjun Park
@ 2026-11-18 13:42 ` Oleksandr Natalenko
0 siblings, 0 replies; 5+ messages in thread
From: Oleksandr Natalenko @ 2026-11-18 13:42 UTC (permalink / raw)
To: Youngjun Park
Cc: linux-mm, Rafael Aquini, Andrew Morton, Chris Li, Kairui Song,
Nhat Pham, Baoquan He, Barry Song
[-- Attachment #1: Type: text/plain, Size: 681 bytes --]
Hello.
On středa 18. listopadu 2026 14:40:20, středoevropský standardní čas Youngjun Park wrote:
> Hi Oleksandr,
>
> > Cast si->pages to long explicitly so that the bitshift in K() doesn't
> > truncate the value to 32 bits.
>
> Nice catch. 642929a2ded0 widened bytes but left the shift in 32 bits.
>
> > Fixes: 642929a2ded0 ("mm/swapfile: fix an integer overflow in swap_show()")
>
> stable kernels show the same wrong size, should this also
> carry Cc: stable@vger.kernel.org?
Yes, picking this for stable@ is a good idea.
> Reviewed-by: Youngjun Park <youngjun.park@lge.com>
Thank you!
> Thanks,
> Youngjun
>
--
Oleksandr Natalenko, MSE
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon()
2026-11-18 11:26 [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon() Oleksandr Natalenko
2026-11-18 13:40 ` Youngjun Park
@ 2026-11-18 16:07 ` Nhat Pham
2026-11-23 6:25 ` [merged mm-hotfixes-stable] mm-swapfile-really-fix-integer-overflow-in-swap_show-and-swapon.patch removed from -mm tree Andrew Morton
2 siblings, 0 replies; 5+ messages in thread
From: Nhat Pham @ 2026-11-18 16:07 UTC (permalink / raw)
To: Oleksandr Natalenko
Cc: linux-mm, Rafael Aquini, Andrew Morton, Chris Li, Kairui Song,
Kemeng Shi, Baoquan He, Barry Song, Youngjun Park
On Wed, Nov 18, 2026 at 3:26 AM Oleksandr Natalenko
<oleksandr@natalenko.name> wrote:
>
> One of the enterprise customers uses 6 TiB of swap, and the values
> reported in /proc/swaps as well as in dmesg are still not correct.
>
> Cast si->pages to long explicitly so that the bitshift in K() doesn't
> truncate the value to 32 bits.
>
> Also do the same in swapon() for the same reason.
>
> Fixes: 642929a2ded0 ("mm/swapfile: fix an integer overflow in swap_show()")
> Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [merged mm-hotfixes-stable] mm-swapfile-really-fix-integer-overflow-in-swap_show-and-swapon.patch removed from -mm tree
2026-11-18 11:26 [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon() Oleksandr Natalenko
2026-11-18 13:40 ` Youngjun Park
2026-11-18 16:07 ` Nhat Pham
@ 2026-11-23 6:25 ` Andrew Morton
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-11-23 6:25 UTC (permalink / raw)
To: mm-commits, youngjun.park, stable, shikemeng, nphamcs, kasong,
chrisl, baoquan.he, baohua, aquini, oleksandr, akpm
The quilt patch titled
Subject: mm/swapfile: really fix integer overflow in swap_show() and swapon()
has been removed from the -mm tree. Its filename was
mm-swapfile-really-fix-integer-overflow-in-swap_show-and-swapon.patch
This patch was dropped because it was merged into the mm-hotfixes-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Oleksandr Natalenko <oleksandr@natalenko.name>
Subject: mm/swapfile: really fix integer overflow in swap_show() and swapon()
Date: Wed, 18 Nov 2026 12:26:10 +0100
One of the enterprise customers uses 6 TiB of swap, and the values
reported in /proc/swaps as well as in dmesg are still not correct.
Cast si->pages to long explicitly so that the bitshift in K() doesn't
truncate the value to 32 bits.
Also do the same in swapon() for the same reason.
Link: https://patch.msgid.link/20261118112610.122799-1-oleksandr@natalenko.name
Fixes: 642929a2ded0 ("mm/swapfile: fix an integer overflow in swap_show()")
Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
Reviewed-by: Youngjun Park <youngjun.park@lge.com>
Cc: Rafael Aquini <aquini@redhat.com>
Cc: Christopher Li <chrisl@kernel.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Barry Song <baohua@kernel.org>
Cc: <stable@vger.kernel.org>
mm/swapfile.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--- a/mm/swapfile.c~mm-swapfile-really-fix-integer-overflow-in-swap_show-and-swapon
+++ a/mm/swapfile.c
@@ -3452,7 +3452,7 @@ static int swap_show(struct seq_file *sw
return 0;
}
- bytes = K(si->pages);
+ bytes = K((unsigned long)si->pages);
inuse = K(swap_usage_in_pages(si));
file = si->swap_file;
@@ -3968,8 +3968,8 @@ SYSCALL_DEFINE2(swapon, const char __use
/* Sets SWP_WRITEOK, resurrect the percpu ref, expose the swap device */
enable_swap_info(si);
- pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s\n",
- K(si->pages), name->name, si->prio, nr_extents,
+ pr_info("Adding %luk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s\n",
+ K((unsigned long)si->pages), name->name, si->prio, nr_extents,
K((unsigned long long)span),
(si->flags & SWP_SOLIDSTATE) ? "SS" : "",
(si->flags & SWP_DISCARDABLE) ? "D" : "",
_
Patches currently in -mm which might be from oleksandr@natalenko.name are
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-23 6:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 11:26 [PATCH] mm/swapfile: really fix integer overflow in swap_show() and swapon() Oleksandr Natalenko
2026-11-18 13:40 ` Youngjun Park
2026-11-18 13:42 ` Oleksandr Natalenko
2026-11-18 16:07 ` Nhat Pham
2026-11-23 6:25 ` [merged mm-hotfixes-stable] mm-swapfile-really-fix-integer-overflow-in-swap_show-and-swapon.patch removed from -mm tree Andrew Morton
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.