* [to-be-updated] mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch removed from -mm tree
@ 2020-09-16 22:59 akpm
0 siblings, 0 replies; only message in thread
From: akpm @ 2020-09-16 22:59 UTC (permalink / raw)
To: mm-commits, vdavydov.dev, shakeelb, mhocko, hannes, songmuchun
The patch titled
Subject: mm: memcontrol: fix out-of-bounds on the buf returned by memory_stat_format
has been removed from the -mm tree. Its filename was
mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Muchun Song <songmuchun@bytedance.com>
Subject: mm: memcontrol: fix out-of-bounds on the buf returned by memory_stat_format
The memory_stat_format() returns a format string, but the return buf may
not including the trailing '\0', so the users may read the buf out of
bounds.
Link: https://lkml.kernel.org/r/20200912155100.25578-1-songmuchun@bytedance.com
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/memcontrol.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
--- a/mm/memcontrol.c~mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format
+++ a/mm/memcontrol.c
@@ -1456,12 +1456,13 @@ static bool mem_cgroup_wait_acct_move(st
return false;
}
-static char *memory_stat_format(struct mem_cgroup *memcg)
+static const char *memory_stat_format(struct mem_cgroup *memcg)
{
struct seq_buf s;
int i;
- seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
+ /* Reserve a byte for the trailing null */
+ seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE - 1);
if (!s.buffer)
return NULL;
@@ -1570,7 +1571,8 @@ static char *memory_stat_format(struct m
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
/* The above should easily fit into one page */
- WARN_ON_ONCE(seq_buf_has_overflowed(&s));
+ if (WARN_ON_ONCE(seq_buf_putc(&s, '\0')))
+ s.buffer[PAGE_SIZE - 1] = '\0';
return s.buffer;
}
@@ -1608,7 +1610,7 @@ void mem_cgroup_print_oom_context(struct
*/
void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg)
{
- char *buf;
+ const char *buf;
pr_info("memory: usage %llukB, limit %llukB, failcnt %lu\n",
K((u64)page_counter_read(&memcg->memory)),
@@ -6373,7 +6375,7 @@ static int memory_events_local_show(stru
static int memory_stat_show(struct seq_file *m, void *v)
{
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
- char *buf;
+ const char *buf;
buf = memory_stat_format(memcg);
if (!buf)
_
Patches currently in -mm which might be from songmuchun@bytedance.com are
kprobes-fix-kill-kprobe-which-has-been-marked-as-gone.patch
mm-memcontrol-fix-missing-suffix-of-workingset_restore.patch
mmhwpoison-refactor-soft_offline_huge_page-and-__soft_offline_page-fix-2.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-16 22:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 22:59 [to-be-updated] mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch removed from -mm tree akpm
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).