Commit 4d957015 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

kernel/acct.c: fix the acct->needcheck check in check_free_space()

As Tsukada explains, the time_is_before_jiffies(acct->needcheck) check
is very wrong, we need time_is_after_jiffies() to make sys_acct() work.

Ignoring the overflows, the code should "goto out" if needcheck >
jiffies, while currently it checks "needcheck < jiffies" and thus in the
likely case check_free_space() does nothing until jiffies overflow.

In particular this means that sys_acct() is simply broken, acct_on()
sets acct->needcheck = jiffies and expects that check_free_space()
should set acct->active = 1 after the free-space check, but this won't
happen if jiffies increments in between.

This was broken by commit 32dc7308 ("get rid of timer in
kern/acct.c") in 2011, then another (correct) commit 795a2f22
("acct() should honour the limits from the very beginning") made the
problem more visible.

Link: http://lkml.kernel.org/r/20171213133940.GA6554@redhat.com
Fixes: 32dc7308 ("get rid of timer in kern/acct.c")
Reported-by: default avatarTSUKADA Koutaro <tsukada@ascade.co.jp>
Suggested-by: default avatarTSUKADA Koutaro <tsukada@ascade.co.jp>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e8c24773
...@@ -102,7 +102,7 @@ static int check_free_space(struct bsd_acct_struct *acct) ...@@ -102,7 +102,7 @@ static int check_free_space(struct bsd_acct_struct *acct)
{ {
struct kstatfs sbuf; struct kstatfs sbuf;
if (time_is_before_jiffies(acct->needcheck)) if (time_is_after_jiffies(acct->needcheck))
goto out; goto out;
/* May block */ /* May block */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment