From: nixiaoming <nixiaoming@huawei.com>
To: akpm@linux-foundation.org, vdavydov.dev@gmail.com,
hannes@cmpxchg.org, garsilva@embeddedor.com,
ktkhai@virtuozzo.com, stummala@codeaurora.org
Cc: nixiaoming@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH] mm: Add conditions to avoid out-of-bounds
Date: Mon, 4 Jun 2018 18:37:35 +0800 [thread overview]
Message-ID: <20180604103735.42781-1-nixiaoming@huawei.com> (raw)
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
next reply other threads:[~2018-06-04 11:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 10:37 nixiaoming [this message]
2018-06-04 11:20 ` Michal Hocko
2018-06-04 11:27 ` Nixiaoming
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=20180604103735.42781-1-nixiaoming@huawei.com \
--to=nixiaoming@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=garsilva@embeddedor.com \
--cc=hannes@cmpxchg.org \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stummala@codeaurora.org \
--cc=vdavydov.dev@gmail.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