* + mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch added to -mm tree
@ 2020-09-13 0:46 akpm
0 siblings, 0 replies; only message in thread
From: akpm @ 2020-09-13 0:46 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 added to the -mm tree. Its filename is
mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch
This patch should soon appear at
https://ozlabs.org/~akpm/mmots/broken-out/mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch
and later at
https://ozlabs.org/~akpm/mmotm/broken-out/mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
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
Fixes: c8713d0b2312 ("mm: memcontrol: dump memory.stat during cgroup OOM")
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-add-the-missing-numa_stat-interface-for-cgroup-v2.patch
mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.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-13 0:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13 0:46 + mm-memcontrol-fix-out-of-bounds-on-the-buf-returned-by-memory_stat_format.patch added to -mm tree akpm
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.