From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753154AbdLMNjn (ORCPT ); Wed, 13 Dec 2017 08:39:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41464 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752175AbdLMNjm (ORCPT ); Wed, 13 Dec 2017 08:39:42 -0500 Date: Wed, 13 Dec 2017 14:39:40 +0100 From: Oleg Nesterov To: Andrew Morton Cc: Al Viro , TSUKADA Koutaro , linux-kernel@vger.kernel.org Subject: [PATCH] acct: fix the acct->needcheck check in check_free_space() Message-ID: <20171213133940.GA6554@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 13 Dec 2017 13:39:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 32dc73086015 ("get rid of timer in kern/acct.c") in 2011, then another (correct) commit 795a2f22a8ea ("acct() should honour the limits from the very beginning") made the problem more visible. Fixes: 32dc73086015 ("get rid of timer in kern/acct.c") Cc: stable@vger.kernel.org Reported-by: TSUKADA Koutaro Sugested-by: TSUKADA Koutaro Signed-off-by: Oleg Nesterov --- kernel/acct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/acct.c b/kernel/acct.c index 5b12843..bf90c09 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -101,7 +101,7 @@ static int check_free_space(struct bsd_acct_struct *acct) { struct kstatfs sbuf; - if (time_is_before_jiffies(acct->needcheck)) + if (time_is_after_jiffies(acct->needcheck)) goto out; /* May block */ -- 2.5.0