Skip to content

Commit f6c009d

Browse files
keessmb49
authored andcommitted
exit: Use READ_ONCE() for all oops/warn limit reads
BugLink: https://bugs.launchpad.net/bugs/2011226 commit 7535b83 upstream. Use a temporary variable to take full advantage of READ_ONCE() behavior. Without this, the report (and even the test) might be out of sync with the initial test. Reported-by: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/lkml/Y5x7GXeluFmZ8E0E@hirez.programming.kicks-ass.net Fixes: 9fc9e27 ("panic: Introduce warn_limit") Fixes: d4ccd54 ("exit: Put an upper limit on how often we can oops") Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Jann Horn <jannh@google.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Petr Mladek <pmladek@suse.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Marco Elver <elver@google.com> Cc: tangmeng <tangmeng@uniontech.com> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> Acked-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kamal Mostafa <kamal@canonical.com>
1 parent ef8f10a commit f6c009d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

kernel/exit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ void __noreturn make_task_dead(int signr)
917917
* Take the task off the cpu after something catastrophic has
918918
* happened.
919919
*/
920+
unsigned int limit;
920921

921922
/*
922923
* Every time the system oopses, if the oops happens while a reference
@@ -928,8 +929,9 @@ void __noreturn make_task_dead(int signr)
928929
* To make sure this can't happen, place an upper bound on how often the
929930
* kernel may oops without panic().
930931
*/
931-
if (atomic_inc_return(&oops_count) >= READ_ONCE(oops_limit) && oops_limit)
932-
panic("Oopsed too often (kernel.oops_limit is %d)", oops_limit);
932+
limit = READ_ONCE(oops_limit);
933+
if (atomic_inc_return(&oops_count) >= limit && limit)
934+
panic("Oopsed too often (kernel.oops_limit is %d)", limit);
933935

934936
do_exit(signr);
935937
}

kernel/panic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,15 @@ static void panic_print_sys_info(void)
199199

200200
void check_panic_on_warn(const char *origin)
201201
{
202+
unsigned int limit;
203+
202204
if (panic_on_warn)
203205
panic("%s: panic_on_warn set ...\n", origin);
204206

205-
if (atomic_inc_return(&warn_count) >= READ_ONCE(warn_limit) && warn_limit)
207+
limit = READ_ONCE(warn_limit);
208+
if (atomic_inc_return(&warn_count) >= limit && limit)
206209
panic("%s: system warned too often (kernel.warn_limit is %d)",
207-
origin, warn_limit);
210+
origin, limit);
208211
}
209212

210213
/**

0 commit comments

Comments
 (0)