* [PATCH] mm: Add conditions to avoid out-of-bounds
@ 2018-06-04 10:37 nixiaoming
2018-06-04 11:20 ` Michal Hocko
0 siblings, 1 reply; 3+ messages in thread
From: nixiaoming @ 2018-06-04 10:37 UTC (permalink / raw)
To: akpm, vdavydov.dev, hannes, garsilva, ktkhai, stummala
Cc: nixiaoming, linux-kernel, linux-mm
In the function memcg_init_list_lru
if call goto fail when i == 0, will cause out-of-bounds at lru->node[i]
The same out-of-bounds access scenario exists in the functions
memcg_update_list_lru and __memcg_init_list_lru_node
Signed-off-by: nixiaoming <nixiaoming@huawei.com>
---
mm/list_lru.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/list_lru.c b/mm/list_lru.c
index fcfb6c8..ec6bdd9 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -298,6 +298,9 @@ static void __memcg_destroy_list_lru_node(struct list_lru_memcg *memcg_lrus,
{
int i;
+ if (unlikely(begin >= end))
+ return;
+
for (i = begin; i < end; i++)
kfree(memcg_lrus->lru[i]);
}
@@ -422,6 +425,8 @@ static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware)
}
return 0;
fail:
+ if (unlikely(i == 0))
+ return -ENOMEM;
for (i = i - 1; i >= 0; i--) {
if (!lru->node[i].memcg_lrus)
continue;
@@ -456,6 +461,8 @@ static int memcg_update_list_lru(struct list_lru *lru,
}
return 0;
fail:
+ if (unlikely(i == 0))
+ return -ENOMEM;
for (i = i - 1; i >= 0; i--) {
if (!lru->node[i].memcg_lrus)
continue;
--
2.10.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mm: Add conditions to avoid out-of-bounds
2018-06-04 10:37 [PATCH] mm: Add conditions to avoid out-of-bounds nixiaoming
@ 2018-06-04 11:20 ` Michal Hocko
2018-06-04 11:27 ` Nixiaoming
0 siblings, 1 reply; 3+ messages in thread
From: Michal Hocko @ 2018-06-04 11:20 UTC (permalink / raw)
To: nixiaoming
Cc: akpm, vdavydov.dev, hannes, garsilva, ktkhai, stummala,
linux-kernel, linux-mm
On Mon 04-06-18 18:37:35, nixiaoming wrote:
> In the function memcg_init_list_lru
> if call goto fail when i == 0, will cause out-of-bounds at lru->node[i]
How? All I can see is that the fail path does
for (i = i - 1; i >= 0; i--)
so it will not do anything for i=0.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] mm: Add conditions to avoid out-of-bounds
2018-06-04 11:20 ` Michal Hocko
@ 2018-06-04 11:27 ` Nixiaoming
0 siblings, 0 replies; 3+ messages in thread
From: Nixiaoming @ 2018-06-04 11:27 UTC (permalink / raw)
To: Michal Hocko
Cc: akpm, vdavydov.dev, hannes, garsilva, ktkhai, stummala,
linux-kernel, linux-mm
I'm very sorry. It was my mistake.
it won't cross the border here.
Thanks
-----Original Message-----
From: Michal Hocko [mailto:mhocko@kernel.org]
Sent: Monday, June 04, 2018 7:20 PM
To: Nixiaoming <nixiaoming@huawei.com>
Cc: akpm@linux-foundation.org; vdavydov.dev@gmail.com; hannes@cmpxchg.org; garsilva@embeddedor.com; ktkhai@virtuozzo.com; stummala@codeaurora.org; linux-kernel@vger.kernel.org; linux-mm@kvack.org
Subject: Re: [PATCH] mm: Add conditions to avoid out-of-bounds
On Mon 04-06-18 18:37:35, nixiaoming wrote:
> In the function memcg_init_list_lru
> if call goto fail when i == 0, will cause out-of-bounds at lru->node[i]
How? All I can see is that the fail path does
for (i = i - 1; i >= 0; i--)
so it will not do anything for i=0.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-04 11:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04 10:37 [PATCH] mm: Add conditions to avoid out-of-bounds nixiaoming
2018-06-04 11:20 ` Michal Hocko
2018-06-04 11:27 ` Nixiaoming
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox