Received: by 10.223.185.116 with SMTP id b49csp6352200wrg; Wed, 28 Feb 2018 08:02:35 -0800 (PST) X-Google-Smtp-Source: AH8x224v66qI524EPn6Iz9bzoH5g7Nwyk1a2OvPFOQe3NwU0CX9Lhyc50GhWNR1rbS7sEpNPtOLC X-Received: by 2002:a17:902:ab89:: with SMTP id f9-v6mr18140828plr.369.1519833755847; Wed, 28 Feb 2018 08:02:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833755; cv=none; d=google.com; s=arc-20160816; b=pAfqRWFynDJXc7uGoRtfQAwD+8+JhU8i4VPJifXbtmNLCBidFcblhpjnnChH+wfWBl yUHZzw0sxRHXIsFO1f2AvbnP0R7LM8tPifm3Tp82fXGQNYERI860gk76f96dI7zy6wS8 odQ+BSb+1z712biqko+KGpklf/HlRxr18ae2hrEW8fTV1pem13ZOJl9gbDwDzixVnzpl PubryU1NlamxmHVeLRZp0I4sP2AM6FR86yb8/a6K5e55Xm7wIL1sIxjl7MGMGlQiCOcG S2k3hHwz8NumKXlRlpKV82LFKNXHORfCXTut8aTMUozlNN0jsdfynzsxX+PvFmmdKhUy DmCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=o/xQcggaxGMUuTQhS+/yA3blO93FIQgFJz5N2wtTLQc=; b=M1R7ELPOdCfqC9dcyrLDU/UzmuTlecXPv8LfC0J1dOB2bEPKRqZr6HOJ9ChsxUgeRI ZJ/IEUZ2PIWzW7bPyDL1nzwWZGkS9pIHaOeXwXsEc3N9qf68qZAgF2XAtK8spXVAcmuV CIlvwEqus9/x5QSjY3fXAaNILwKaYduoPn5/TrFDitaOP/TfTjy8gPrYC/KiQt+DFrh/ x74+6N7pVNaeGsj+DRgogrg3zg8W1Rkn35U3zu/nnvuklqlRmWEYnfodvatoGu/IKwH2 FhxZg1IFxeiRsW5iY0uS5F24y5zOTMIo3CudAi/cBAxnGd0dDYkoc0A3ITLu/RSEIsTG VAfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si1408109plb.717.2018.02.28.08.02.16; Wed, 28 Feb 2018 08:02:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933014AbeB1QBJ (ORCPT + 99 others); Wed, 28 Feb 2018 11:01:09 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34688 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932120AbeB1QBG (ORCPT ); Wed, 28 Feb 2018 11:01:06 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yj-0006Xm-Lq; Wed, 28 Feb 2018 15:22:22 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yi-0000Bu-Ht; Wed, 28 Feb 2018 15:22:20 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Oleg Nesterov" , "TSUKADA Koutaro" , "Al Viro" , "Linus Torvalds" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 169/254] kernel/acct.c: fix the acct->needcheck check in check_free_space() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Oleg Nesterov commit 4d9570158b6260f449e317a5f9ed030c2504a615 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 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. Link: http://lkml.kernel.org/r/20171213133940.GA6554@redhat.com Fixes: 32dc73086015 ("get rid of timer in kern/acct.c") Reported-by: TSUKADA Koutaro Suggested-by: TSUKADA Koutaro Signed-off-by: Oleg Nesterov Cc: Al Viro Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- kernel/acct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/acct.c +++ b/kernel/acct.c @@ -107,7 +107,7 @@ static int check_free_space(struct bsd_a 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);