Fix do_pages_stat to use compat_uptr_t
Subsystems (2)
PATCH 1/1 Fix do_pages_stat to use compat_uptr_t
Hi,
PostgreSQL 18 will feature NUMA introspection of its shared memory structures. The regression tests for this are failing on Debian's 32-bit architectures which are nowadays all built on 64-bit hosts (i386, armel, armhf, x32).
Bertrand Drouvot analyzed the issue to be in do_pages_stat:
do_pages_stat() is already handling the input arrays correctly in 32-bit mode, but at the end of the "while (nr_pages)" loop, it incorrectly advances the pages pointer with the wrong word size.
The attached patch fixes the problem.
Christoph
From 70225fb0be382c3fd443e8331688b88d0e52c04c Mon Sep 17 00:00:00 2001
From: Christoph Berg <[email protected]>
Date: Tue, 24 Jun 2025 16:44:27 +0200
Subject: [PATCH] Fix do_pages_stat to use compat_uptr_t
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16 compat_uptr_t.
--- mm/migrate.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/migrate.c +7 -1
@@ -2444,7 +2444,13 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status)))break ; - pages += chunk_nr; +if (in_compat_syscall ()) { +compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages; + + pages32 += chunk_nr; + pages = (const void __user *__user *) pages32; + }else + pages += chunk_nr; status += chunk_nr; nr_pages -= chunk_nr; }
Signature · 1 line
2.47.2
Quoted 11 lines · Christoph Berg
Hi,
PostgreSQL 18 will feature NUMA introspection of its shared memory structures. The regression tests for this are failing on Debian's 32-bit architectures which are nowadays all built on 64-bit hosts (i386, armel, armhf, x32).
Bertrand Drouvot analyzed the issue to be in
do_pages_stat:
Quoted 7 lines
do_pages_stat()is already handling the input arrays correctly in 32-bit mode, but at the end of the "while (nr_pages)" loop, it incorrectly advances the pages pointer with the wrong word size.The attached patch fixes the problem.
Christoph
Hello Christoph,
Thanks for your effort. Please take a look at Documentation/process/submitting-patches.rst and send the patch directly as an email.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
PATCH 1/1 Fix do_pages_stat to use compat_uptr_t
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16 compat_uptr_t.
--- mm/migrate.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/migrate.c +7 -1
@@ -2444,7 +2444,13 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status)))break ; - pages += chunk_nr; +if (in_compat_syscall ()) { +compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages; + + pages32 += chunk_nr; + pages = (const void __user *__user *) pages32; + }else + pages += chunk_nr; status += chunk_nr; nr_pages -= chunk_nr; }
Signature · 1 line
2.47.2
On 25.06.25 17:24, Christoph Berg wrote:
Subject should start with "mm/migrate:"
Quoted 5 lines
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16
compat_uptr_t.Signed-off-by Christoph Berg <[email protected]>Suggested-by Bertrand Drouvot <[email protected]>
Likely we want a
Fixes:
and then this is probably "Reported-by:" paired with a "Closes:" link to any such report.
But I'm wondering how long this has already been like that. :)
Quoted 13 lines
--- mm/migrate.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)mm/migrate.c +0
-1@@ -2444,7 +2444,13 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status)))break ; - pages += chunk_nr;
mm/migrate.c static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, · line 2456
Quoted 10 lines
mm/migrate.c +7
-0+if (in_compat_syscall ()) { +compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages; + + pages32 += chunk_nr; + pages = (const void __user *__user *) pages32; + }else + pages += chunk_nr; status += chunk_nr; nr_pages -= chunk_nr; }
Something a bit more elegant might be:
mm/migrate.c +7 -5
@@ -2398,6 +2398,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,static int get_compat_pages_array (const void __user *chunk_pages[],const void __user *__user *pages, +unsigned long chunk_offs,unsigned long chunk_nr) {compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages;
@@ -2405,7 +2406,7 @@ static int get_compat_pages_array(const void __user *chunk_pages[],int i;for (i =0 ; i < chunk_nr; i++) { -if (get_user (p, pages32 + i)) +if (get_user (p, pages32 + i + chunk_offs))return -EFAULT ; chunk_pages[i] =compat_ptr (p); }
@@ -2424,13 +2425,14 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,#define DO_PAGES_STAT_CHUNK_NR 16ULconst void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR ];int chunk_status[DO_PAGES_STAT_CHUNK_NR ]; +unsigned long chunk_offs =0 ;while (nr_pages) {unsigned long chunk_nr =min (nr_pages,DO_PAGES_STAT_CHUNK_NR );if (in_compat_syscall ()) {if (get_compat_pages_array (chunk_pages, pages, - chunk_nr)) + chunk_offs, chunk_nr))break ; }else { if (copy_from_user(chunk_pages, pages,
@@ -2440,11 +2442,11 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,do_pages_stat_array (mm, chunk_nr, chunk_pages, chunk_status); -if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status))) +if (copy_to_user (status + chunk_offs, chunk_status, + chunk_nr *sizeof (*status)))break ; - pages += chunk_nr; - status += chunk_nr; + chunk_offs += chunk_nr; nr_pages -= chunk_nr; }return nr_pages ? -EFAULT :0 ;
(untested, of course)
Signature · 3 lines
Cheers, David / dhildenb
Andrew Morton
maintainerQuoted 12 lines · On Wed, 25 Jun 2025 17:24:14 +0200 Christoph Berg <[email protected]> wrote:
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16
compat_uptr_t....
mm/migrate.c +0
-1@@ -2444,7 +2444,13 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status)))break ; - pages += chunk_nr;
mm/migrate.c static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, · line 2456
Quoted 10 lines
mm/migrate.c +7
-0+if (in_compat_syscall ()) { +compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages; + + pages32 += chunk_nr; + pages = (const void __user *__user *) pages32; + }else + pages += chunk_nr; status += chunk_nr; nr_pages -= chunk_nr; }
Seems this has been present since 2010.
I'll update the Subject: as David suggests and I'll add a cc:stable, thanks. I'll also add a note that David suggested an alternative, so please let's advance that option.
Also, a coding-style tweak:
mm/migrate.c renamed from mm/migrate.c~fix-do_pages_stat-to-use-compat_uptr_t-fix +2 -1
@@ -2449,8 +2449,9 @@ static int do_pages_stat(struct mm_struc pages32 += chunk_nr; pages = (const void __user *__user *) pages32; - }else + }else { pages += chunk_nr; + } status += chunk_nr; nr_pages -= chunk_nr; }
_
Re: Andrew Morton
Quoted 3 lines
I'll update the Subject: as David suggests and I'll add a cc:stable, thanks. I'll also add a note that David suggested an alternative, so please let's advance that option.
Sorry, I'm new here. Do I have to do anything now? The above sounds like the alternative coding by David would be preferred, but the other mails say the patches have already been pushed to a hotfix branch? Or are we doing both, i.e. stable gets the simple fix and next the pretty one?
Christoph
Andrew Morton
maintainerQuoted 10 lines · On Wed, 25 Jun 2025 23:10:13 +0200 Christoph Berg <[email protected]> wrote:
Re: Andrew Morton
Quoted 3 lines
I'll update the Subject: as David suggests and I'll add a cc:stable, thanks. I'll also add a note that David suggested an alternative, so please let's advance that option.
Sorry, I'm new here. Do I have to do anything now? The above sounds like the alternative coding by David would be preferred, but the other mails say the patches have already been pushed to a hotfix branch? Or are we doing both, i.e. stable gets the simple fix and next the pretty one?
Well I added the v1 patch for testing and so it doesn't get lost - fixing the bug is the most important thing.
But if a nicer v2 patch is sent in the next few days, I can switch to that version.
Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Wed, 25 Jun 2025 23:10:13 +0200 Christoph Berg <[email protected]> wrote:
Re: Andrew Morton
Quoted 3 lines
I'll update the Subject: as David suggests and I'll add a cc:stable, thanks. I'll also add a note that David suggested an alternative, so please let's advance that option.
Sorry, I'm new here. Do I have to do anything now? The above sounds like the alternative coding by David would be preferred
See if my proposal makes sense, and then incorporate+test it.
You can feel free to add my
Signature · 3 lines
Cheers, David / dhildenb
Re: David Hildenbrand
Quoted 5 lines
See if my proposal makes sense, and then incorporate+test it.
You can feel free to add my
Suggested-by David Hildenbrand <[email protected]>
Thanks, will do. But it will be next week, currently busy with the ham radio fair in Friedrichshafen.
Christoph
PATCH v2 1/1 mm/migrate: Fix do_pages_stat in 32-bit mode
In reply to Andrew MortonRe: David Hildenbrand
Quoted 5 lines
Subject should start with "mm/migrate:"
Likely we want a
Fixes:
and then this is probably "Reported-by:" paired with a "Closes:" link to any such report.
I included these now, except for "Closes:" which I have to idea what to put in.
Quoted 1 line
But I'm wondering how long this has already been like that. :)
The now-offending "pages += chunk_nr" line is from 2010, but I think the bug is rather from 5b1b561ba73c8ab9c98e5dfd14dc7ee47efb6530 (2021) which reshuffled the array-vs-32-bit handling.
Quoted 1 line
Something a bit more elegant might be:
Thanks, I used your patch draft with some minor changes.
Quoted 3 lines
static int get_compat_pages_array(const void
__user*chunk_pages[],
const void__user*__user*pages,
+ unsigned longchunk_offs,
I replaced chunk_offs with "chunk_offset" since "offs" looked too much like plural (list of offsets) to me.
Review
Quoted 7 lines
if (
in_compat_syscall()) {
if (get_compat_pages_array(chunk_pages, pages,(quoted diff) +1
-1- chunk_nr)) + chunk_offs, chunk_nr)) break; } else { if (copy_from_user(chunk_pages, pages,
The else branch here needs tweaking as well:
} else {- if (copy_from_user(chunk_pages, pages,
+ if (copy_from_user(chunk_pages, pages + chunk_offset,
chunk_nr * sizeof(*chunk_pages)))
Review static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, · line 2444
Quoted 5 lines
(quoted diff) +2
-1@@ -2440,11 +2442,11 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, do_pages_stat_array(mm, chunk_nr, chunk_pages, chunk_status); - if (copy_to_user(status, chunk_status, chunk_nr * sizeof(*status))) + if (copy_to_user(status + chunk_offs, chunk_status, + chunk_nr * sizeof(*status)))
This seems to work, but honestly I am wondering, if copy_from_user needs a special 32-bit case, doesn't copy_to_user need special casing as well?
Review static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, · line 2445
Quoted 1 line
(quoted diff) +0
-0(untested, of course)
The attached patch makes PG18's new numa test pass on amd64 kernels both in amd64 and i386 userlands.
(In the meantime, PG git head got a workaround that limits the chunk size to the same 16 as used in do_pages_stat; I tested with the version before that.)
Christoph
From fdbcbc88825bc2e857dfeeebc91d62864e0774dd Mon Sep 17 00:00:00 2001
From: Christoph Berg <[email protected]>
Date: Tue, 24 Jun 2025 16:44:27 +0200
Subject: [PATCH v2] mm/migrate: Fix do_pages_stat in 32-bit mode
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16 compat_uptr_t. Fix by doing the pointer arithmetic inside get_compat_pages_array where pages32 is already a correctly-typed pointer.
Discovered while working on PostgreSQL 18's new NUMA introspection code.
--- mm/migrate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
mm/migrate.c +8 -6
@@ -2399,6 +2399,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,static int get_compat_pages_array (const void __user *chunk_pages[],const void __user *__user *pages, +unsigned long chunk_offset,unsigned long chunk_nr) {compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages;
@@ -2406,7 +2407,7 @@ static int get_compat_pages_array(const void __user *chunk_pages[],int i;for (i =0 ; i < chunk_nr; i++) { -if (get_user (p, pages32 + i)) +if (get_user (p, pages32 + chunk_offset + i))return -EFAULT ; chunk_pages[i] =compat_ptr (p); }
@@ -2425,27 +2426,28 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,#define DO_PAGES_STAT_CHUNK_NR 16ULconst void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR ];int chunk_status[DO_PAGES_STAT_CHUNK_NR ]; +unsigned long chunk_offset =0 ;while (nr_pages) {unsigned long chunk_nr =min (nr_pages,DO_PAGES_STAT_CHUNK_NR );if (in_compat_syscall ()) {if (get_compat_pages_array (chunk_pages, pages, - chunk_nr)) + chunk_offset, chunk_nr))break ; }else { -if (copy_from_user (chunk_pages, pages, +if (copy_from_user (chunk_pages, pages + chunk_offset, chunk_nr *sizeof (*chunk_pages)))break ; }do_pages_stat_array (mm, chunk_nr, chunk_pages, chunk_status); -if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status))) +if (copy_to_user (status + chunk_offset, chunk_status, + chunk_nr *sizeof (*status)))break ; - pages += chunk_nr; - status += chunk_nr; + chunk_offset += chunk_nr; nr_pages -= chunk_nr; }return nr_pages ? -EFAULT :0 ;
Signature · 1 line
2.47.2
Zi Yan
reviewerRe: [PATCH v2] mm/migrate: Fix do_pages_stat in 32-bit mode
Quoted 9 lines · Christoph Berg
Re: David Hildenbrand
Quoted 5 lines
Subject should start with "mm/migrate:"
Likely we want a
Fixes:
and then this is probably "Reported-by:" paired with a "Closes:" link to any such report.I included these now, except for "Closes:" which I have to idea what to put in.
Fixes should be:
Closes could be a link to the bug report.
Quoted 134 lines
Quoted 2 lines
But I'm wondering how long this has already been like that. :)
The now-offending "pages +=
chunk_nr" line is from 2010, but I think the bug is rather from5b1b561ba73c8ab9c98e5dfd14dc7ee47efb6530(2021) which reshuffled the array-vs-32-bit handling.Quoted 1 line
Something a bit more elegant might be:
Thanks, I used your patch draft with some minor changes.
Quoted 3 lines
static int get_compat_pages_array(const void
__user*chunk_pages[],
const void__user*__user*pages,
+ unsigned longchunk_offs,I replaced
chunk_offswith "chunk_offset" since "offs" looked too much like plural (list of offsets) to me.mm/migrate.c static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
Quoted 7 lines
if (
in_compat_syscall()) {
if (get_compat_pages_array(chunk_pages, pages,mm/migrate.c +1
-1- chunk_nr)) + chunk_offs, chunk_nr))break ; }else { if (copy_from_user(chunk_pages, pages,The else branch here needs tweaking as well:
} else {mm/migrate.c +1
-1-if (copy_from_user (chunk_pages, pages, +if (copy_from_user (chunk_pages, pages + chunk_offset, chunk_nr *sizeof (*chunk_pages)))mm/migrate.c static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, · line 2444
Quoted 7 lines
mm/migrate.c +2
-1@@ -2440,11 +2442,11 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,do_pages_stat_array (mm, chunk_nr, chunk_pages, chunk_status); -if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status))) +if (copy_to_user (status + chunk_offs, chunk_status, + chunk_nr *sizeof (*status)))This seems to work, but honestly I am wondering, if
copy_from_userneeds a special 32-bit case, doesn'tcopy_to_userneed special casing as well?Review static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, · line 2445
Quoted 1 line
(quoted diff) +0
-0(untested, of course)The attached patch makes PG18's new numa test pass on amd64 kernels both in amd64 and i386 userlands.
(In the meantime, PG git head got a workaround that limits the chunk size to the same 16 as used in
do_pages_stat; I tested with the version before that.)Christoph
From
fdbcbc88825bc2e857dfeeebc91d62864e0774ddMon Sep 17 00:00:00 2001
From: Christoph Berg <[email protected]>
Date: Tue, 24 Jun 2025 16:44:27 +0200
Subject: [PATCH v2] mm/migrate: Fixdo_pages_statin 32-bit modeFor arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16
compat_uptr_t. Fix by doing the pointer arithmetic insideget_compat_pages_arraywhere pages32 is already a correctly-typed pointer.Discovered while working on PostgreSQL 18's new NUMA introspection code.
Signed-off-by Christoph Berg <[email protected]>Reported-by Bertrand Drouvot <[email protected]>Reported-by Tomas Vondra <[email protected]>Suggested-by David Hildenbrand <[email protected]>Fixes 5b1b561ba73c8ab9c98e5dfd14dc7ee47efb6530--- mm/migrate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)mm/migrate.c +8
-6@@ -2399,6 +2399,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,static int get_compat_pages_array (const void __user *chunk_pages[],const void __user *__user *pages, +unsigned long chunk_offset,unsigned long chunk_nr) {compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages;@@ -2406,7 +2407,7 @@ static int get_compat_pages_array(const void __user *chunk_pages[],int i;for (i =0 ; i < chunk_nr; i++) { -if (get_user (p, pages32 + i)) +if (get_user (p, pages32 + chunk_offset + i))return -EFAULT ; chunk_pages[i] =compat_ptr (p); }@@ -2425,27 +2426,28 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,#define DO_PAGES_STAT_CHUNK_NR 16ULconst void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR ];int chunk_status[DO_PAGES_STAT_CHUNK_NR ]; +unsigned long chunk_offset =0 ;while (nr_pages) {unsigned long chunk_nr =min (nr_pages,DO_PAGES_STAT_CHUNK_NR );if (in_compat_syscall ()) {if (get_compat_pages_array (chunk_pages, pages, - chunk_nr)) + chunk_offset, chunk_nr))break ; }else { -if (copy_from_user (chunk_pages, pages, +if (copy_from_user (chunk_pages, pages + chunk_offset, chunk_nr *sizeof (*chunk_pages)))break ; }do_pages_stat_array (mm, chunk_nr, chunk_pages, chunk_status); -if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status))) +if (copy_to_user (status + chunk_offset, chunk_status, + chunk_nr *sizeof (*status)))break ; - pages += chunk_nr; - status += chunk_nr; + chunk_offset += chunk_nr; nr_pages -= chunk_nr; }return nr_pages ? -EFAULT :0 ;Signature · 1 line
2.47.2
Best Regards,
Yan, Zi
Re: [PATCH v3] mm/migrate: Fix do_pages_stat in 32-bit mode
Re: Zi Yan
Quoted 5 lines
Fixes should be:
Fixes 5b1b561ba73c ("mm: simplify compat_sys_move_pages")Closes could be a link to the bug report.
Updated, thanks.
Quoted 3 lines
Quoted 3 lines
This seems to work, but honestly I am wondering, if
copy_from_userneeds a special 32-bit case, doesn'tcopy_to_userneed special casing as well?
Scratch that, it works because an int[] is copied back, and that's always the same size.
So I think the patch is good to go.
Christoph
From 426c93d558572248273cf386ca784626ae431413 Mon Sep 17 00:00:00 2001
From: Christoph Berg <[email protected]>
Date: Tue, 24 Jun 2025 16:44:27 +0200
Subject: [PATCH v3] mm/migrate: Fix do_pages_stat in 32-bit mode
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16 compat_uptr_t. Fix by doing the pointer arithmetic inside get_compat_pages_array where pages32 is already a correctly-typed pointer.
Discovered while working on PostgreSQL 18's new NUMA introspection code.
--- mm/migrate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
mm/migrate.c +8 -6
@@ -2399,6 +2399,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,static int get_compat_pages_array (const void __user *chunk_pages[],const void __user *__user *pages, +unsigned long chunk_offset,unsigned long chunk_nr) {compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages;
@@ -2406,7 +2407,7 @@ static int get_compat_pages_array(const void __user *chunk_pages[],int i;for (i =0 ; i < chunk_nr; i++) { -if (get_user (p, pages32 + i)) +if (get_user (p, pages32 + chunk_offset + i))return -EFAULT ; chunk_pages[i] =compat_ptr (p); }
@@ -2425,27 +2426,28 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,#define DO_PAGES_STAT_CHUNK_NR 16ULconst void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR ];int chunk_status[DO_PAGES_STAT_CHUNK_NR ]; +unsigned long chunk_offset =0 ;while (nr_pages) {unsigned long chunk_nr =min (nr_pages,DO_PAGES_STAT_CHUNK_NR );if (in_compat_syscall ()) {if (get_compat_pages_array (chunk_pages, pages, - chunk_nr)) + chunk_offset, chunk_nr))break ; }else { -if (copy_from_user (chunk_pages, pages, +if (copy_from_user (chunk_pages, pages + chunk_offset, chunk_nr *sizeof (*chunk_pages)))break ; }do_pages_stat_array (mm, chunk_nr, chunk_pages, chunk_status); -if (copy_to_user (status, chunk_status, chunk_nr *sizeof (*status))) +if (copy_to_user (status + chunk_offset, chunk_status, + chunk_nr *sizeof (*status)))break ; - pages += chunk_nr; - status += chunk_nr; + chunk_offset += chunk_nr; nr_pages -= chunk_nr; }return nr_pages ? -EFAULT :0 ;
Signature · 1 line
2.47.2
David Hildenbrand
Acked-byRe: [PATCH v3] mm/migrate: Fix do_pages_stat in 32-bit mode
Quoted 13 lines · Christoph Berg
Re: Zi Yan
Quoted 5 lines
Fixes should be:
Fixes 5b1b561ba73c ("mm: simplify compat_sys_move_pages")Closes could be a link to the bug report.
Updated, thanks.
Quoted 3 lines
Quoted 3 lines
This seems to work, but honestly I am wondering, if
copy_from_userneeds a special 32-bit case, doesn'tcopy_to_userneed special casing as well?
Quoted 8 lines
Scratch that, it works because an int[] is copied back, and that's always the same size.
So I think the patch is good to go.
Christoph
If you have to resend, next time resend the full patch separately, not as reply to the previous version.
Quoted 4 lines
From
426c93d558572248273cf386ca784626ae431413Mon Sep 17 00:00:00 2001
From: Christoph Berg <[email protected]>
Date: Tue, 24 Jun 2025 16:44:27 +0200
Subject: [PATCH v3] mm/migrate: Fixdo_pages_statin 32-bit mode
s/32-bit mode/compat mode/ ?
Because on native 32bit it should be working fine.
Quoted 11 lines
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16
compat_uptr_t. Fix by doing the pointer arithmetic insideget_compat_pages_arraywhere pages32 is already a correctly-typed pointer.Discovered while working on PostgreSQL 18's new NUMA introspection code.
Signed-off-by Christoph Berg <[email protected]>Suggested-by David Hildenbrand <[email protected]>Fixes 5b1b561ba73c ("mm: simplify compat_sys_move_pages")
Hmm, still not sure if 5b1b561ba73c really introduced the issue. I think it only messed with the "pages" pointer, not with the "status" pointer?
Hmmmm
I assume we want to Cc stable. @Andrew can do that.
Quoted 4 lines
Reported-by Bertrand Drouvot <[email protected]>Reported-by Tomas Vondra <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v3] mm/migrate: Fix do_pages_stat in 32-bit mode
Re: David Hildenbrand
Quoted 5 lines
Quoted 5 lines
For arrays with more than 16 entries, the old code would incorrectly advance the pages pointer by 16 words instead of 16
compat_uptr_t. Fix by doing the pointer arithmetic insideget_compat_pages_arraywhere pages32 is already a correctly-typed pointer.
Quoted 8 lines
Quoted 5 lines
Discovered while working on PostgreSQL 18's new NUMA introspection code.
Signed-off-by Christoph Berg <[email protected]>Suggested-by David Hildenbrand <[email protected]>Fixes 5b1b561ba73c ("mm: simplify compat_sys_move_pages")Hmm, still not sure if
5b1b561ba73creally introduced the issue. I think it only messed with the "pages" pointer, not with the "status" pointer?
"pages" was the broken one. "status" isn't affected by compat mode.
Quoted 1 line
Thanks!
Christoph