* [PATCH] mm: mempolicy: Fix wrong use of maxnode in mempolicy API
@ 2019-11-08 15:49 Li Xinhai
2019-11-08 16:04 ` Michal Hocko
0 siblings, 1 reply; 4+ messages in thread
From: Li Xinhai @ 2019-11-08 15:49 UTC (permalink / raw)
To: linux-mm; +Cc: Andrew Morton, Michal Hocko, Vlastimil Babka, Hugh Dickins
The maxnode used by mbind(), set_mempolicy() and migrate_pages() is not
correctly handled in get_nodes(), where --maxnode cause the calculation
endmask = (1UL << (maxnode % BITS_PER_LONG)) - 1;
ignores the highest node ID bit. Then, at
nodes_addr(*nodes)[nlongs-1] &= endmask;
the highest node ID bit is cleared. Finally, cause mpol_new() think user
does not pass in any node ID, and return EINVAL.
The results are:
- Application receives EINVAL when only the highest node ID bit is set.
- Application recevies no error when other bits set together with the
highest node ID bit, but that highest ID is ignored.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
---
mm/mempolicy.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 4ae967b..2bdc365 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1328,7 +1328,6 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask,
unsigned long nlongs;
unsigned long endmask;
- --maxnode;
nodes_clear(*nodes);
if (maxnode == 0 || !nmask)
return 0;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: mempolicy: Fix wrong use of maxnode in mempolicy API
2019-11-08 15:49 [PATCH] mm: mempolicy: Fix wrong use of maxnode in mempolicy API Li Xinhai
@ 2019-11-08 16:04 ` Michal Hocko
2019-11-08 16:48 ` lixinhai.lxh
0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2019-11-08 16:04 UTC (permalink / raw)
To: Li Xinhai; +Cc: linux-mm, Andrew Morton, Vlastimil Babka, Hugh Dickins
On Fri 08-11-19 23:49:29, Li Xinhai wrote:
> The maxnode used by mbind(), set_mempolicy() and migrate_pages() is not
> correctly handled in get_nodes(), where --maxnode cause the calculation
> endmask = (1UL << (maxnode % BITS_PER_LONG)) - 1;
> ignores the highest node ID bit. Then, at
> nodes_addr(*nodes)[nlongs-1] &= endmask;
> the highest node ID bit is cleared. Finally, cause mpol_new() think user
> does not pass in any node ID, and return EINVAL.
>
> The results are:
> - Application receives EINVAL when only the highest node ID bit is set.
> - Application recevies no error when other bits set together with the
> highest node ID bit, but that highest ID is ignored.
A similar patch has been posted [1] and rejected [2].
[1] http://lkml.kernel.org/r/1570882789-20579-1-git-send-email-zhangpan26@huawei.com
[2] http://lkml.kernel.org/r/20191014091243.GD317@dhcp22.suse.cz
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Hugh Dickins <hughd@google.com>
> Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
> ---
> mm/mempolicy.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 4ae967b..2bdc365 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1328,7 +1328,6 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask,
> unsigned long nlongs;
> unsigned long endmask;
>
> - --maxnode;
> nodes_clear(*nodes);
> if (maxnode == 0 || !nmask)
> return 0;
> --
> 1.8.3.1
>
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: mempolicy: Fix wrong use of maxnode in mempolicy API
2019-11-08 16:04 ` Michal Hocko
@ 2019-11-08 16:48 ` lixinhai.lxh
2019-11-11 10:04 ` Michal Hocko
0 siblings, 1 reply; 4+ messages in thread
From: lixinhai.lxh @ 2019-11-08 16:48 UTC (permalink / raw)
To: mhocko; +Cc: linux-mm, akpm, Vlastimil Babka, Hugh Dickins
On 2019-11-09 at 00:04 Michal Hocko wrote:
>On Fri 08-11-19 23:49:29, Li Xinhai wrote:
>> The maxnode used by mbind(), set_mempolicy() and migrate_pages() is not
>> correctly handled in get_nodes(), where --maxnode cause the calculation
>> endmask = (1UL << (maxnode % BITS_PER_LONG)) - 1;
>> ignores the highest node ID bit. Then, at
>> nodes_addr(*nodes)[nlongs-1] &= endmask;
>> the highest node ID bit is cleared. Finally, cause mpol_new() think user
>> does not pass in any node ID, and return EINVAL.
>>
>> The results are:
>> - Application receives EINVAL when only the highest node ID bit is set.
>> - Application recevies no error when other bits set together with the
>> highest node ID bit, but that highest ID is ignored.
>
>A similar patch has been posted [1] and rejected [2].
>
>[1] http://lkml.kernel.org/r/1570882789-20579-1-git-send-email-zhangpan26@huawei.com
>[2] http://lkml.kernel.org/r/20191014091243.GD317@dhcp22.suse.cz
>
>
>--
>Michal Hocko
>SUSE Labs
I just checked the code in 'history' log for curiosity, this --maxnode seems
appeared since the very first commit. Mention about this special point of
maxnode in manpage of these three APIs would be one solution, :).
Xinhai
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: mempolicy: Fix wrong use of maxnode in mempolicy API
2019-11-08 16:48 ` lixinhai.lxh
@ 2019-11-11 10:04 ` Michal Hocko
0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2019-11-11 10:04 UTC (permalink / raw)
To: lixinhai.lxh; +Cc: linux-mm, akpm, Vlastimil Babka, Hugh Dickins
On Sat 09-11-19 00:48:01, lixinhai.lxh@gmail.com wrote:
> On 2019-11-09 at 00:04 Michal Hocko wrote:
> >On Fri 08-11-19 23:49:29, Li Xinhai wrote:
> >> The maxnode used by mbind(), set_mempolicy() and migrate_pages() is not
> >> correctly handled in get_nodes(), where --maxnode cause the calculation
> >> endmask = (1UL << (maxnode % BITS_PER_LONG)) - 1;
> >> ignores the highest node ID bit. Then, at
> >> nodes_addr(*nodes)[nlongs-1] &= endmask;
> >> the highest node ID bit is cleared. Finally, cause mpol_new() think user
> >> does not pass in any node ID, and return EINVAL.
> >>
> >> The results are:
> >> - Application receives EINVAL when only the highest node ID bit is set.
> >> - Application recevies no error when other bits set together with the
> >> highest node ID bit, but that highest ID is ignored.
> >
> >A similar patch has been posted [1] and rejected [2].
> >
> >[1] http://lkml.kernel.org/r/1570882789-20579-1-git-send-email-zhangpan26@huawei.com
> >[2] http://lkml.kernel.org/r/20191014091243.GD317@dhcp22.suse.cz
> >
> >
> >--
> >Michal Hocko
> >SUSE Labs
>
> I just checked the code in 'history' log for curiosity, this --maxnode seems
> appeared since the very first commit. Mention about this special point of
> maxnode in manpage of these three APIs would be one solution, :).
Yes documenting this would be preferable.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-11-11 10:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 15:49 [PATCH] mm: mempolicy: Fix wrong use of maxnode in mempolicy API Li Xinhai
2019-11-08 16:04 ` Michal Hocko
2019-11-08 16:48 ` lixinhai.lxh
2019-11-11 10:04 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).