Skip to content

Commit

Permalink
kernel/acct.c: fix the acct->needcheck check in check_free_space()
Browse files Browse the repository at this point in the history
commit 4d95701 upstream.

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 32dc730 ("get rid of timer in
kern/acct.c") in 2011, then another (correct) commit 795a2f2
("acct() should honour the limits from the very beginning") made the
problem more visible.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: 32dc730 ("get rid of timer in kern/acct.c")
Reported-by: TSUKADA Koutaro <[email protected]>
Suggested-by: TSUKADA Koutaro <[email protected]>
Signed-off-by: Oleg Nesterov <[email protected]>
Cc: Al Viro <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <[email protected]>
  • Loading branch information
oleg-nesterov authored and bwhacks committed Mar 3, 2018
1 parent 631fcf6 commit 275927c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/acct.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int check_free_space(struct bsd_acct_struct *acct, struct file *file)

spin_lock(&acct_lock);
res = acct->active;
if (!file || time_is_before_jiffies(acct->needcheck))
if (!file || time_is_after_jiffies(acct->needcheck))
goto out;
spin_unlock(&acct_lock);

Expand Down

0 comments on commit 275927c

Please sign in to comment.