Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11791347pjo; Thu, 2 Jan 2020 14:20:45 -0800 (PST) X-Google-Smtp-Source: APXvYqycCVeY3ua0nI7BEvDXoRI8KVz+EsVWuuT6mXItREflAh4hs6sxIjbroBEQQCoAB0bLiv4e X-Received: by 2002:a9d:7c8f:: with SMTP id q15mr82227276otn.140.1578003645482; Thu, 02 Jan 2020 14:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003645; cv=none; d=google.com; s=arc-20160816; b=fsPn7u1OmcIf/ou33zeBseW12MUU7q3wJwey3Mpg2mw1psg7wD6bxNs0phs/9pC0q4 +33O+8NjIdSd6INf5u0g/LyM2UXVFc2wAW6/6kNAgV+8TafeDlg8yhy689+BVtJK5f6L ZAlw5kKqM76S6ag/HYtrsNPuw1cHOz5+joeXnKituHUgLwDmfWzXfwZG1lKeRLg+Z++l jScDKTcKMjvbnqiZBgPUhOPIwDH7nPKBVE1lVLDiQFLj9U8Z75dRkOKprFLzGZXhJvzw I752fXIoekmuS0mzvIUYhesx6Z4e3DnzVlpF0N6y0/07Tu2ghQwV2qrPbOb/JMivyH61 WIzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QoO1hosfH33USYDjwQEC2rEORb4lw1bkfs0ZFmRvhK4=; b=DP7es5pqeq4e6UJDQJXAEErEEqYtxHze78BvEGZxIeQaK6Mg3RhZSUhfGwwUycbfQ4 MmyOXH4OM4fVDJwriiidFFkshZ+Qn3b0gw59INdFg1fQePwhwmfnGjzcTGsZaFdyBjcJ 1c3T4OMoQWBXXHft2KG51uGnCfTV7+uj8cqaJ/jZJXgML4wVraiuqrXLUOi6uTU3njP5 jplrrr4dzJgVc0PekrJZyG2gf65jciswu56ayI60wfLqsbmaCJ08AnfbXzqBmQ/+mKd9 gGngjB3I1BKLTELBCoWbjW6Ji3VcPPP8Yfli6MHQrVXHYXbGwYeW0sJPIJ5esVw3ysoG /HcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o744GzGh; 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 g25si29628034otp.20.2020.01.02.14.20.33; Thu, 02 Jan 2020 14:20:45 -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; dkim=pass header.i=@kernel.org header.s=default header.b=o744GzGh; 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 S1727657AbgABWT4 (ORCPT + 99 others); Thu, 2 Jan 2020 17:19:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:36490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728676AbgABWTw (ORCPT ); Thu, 2 Jan 2020 17:19:52 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C5F522314; Thu, 2 Jan 2020 22:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003591; bh=aKoVp1fFTmbei8yNdC7WmKvRg5U49w3VdGw0AxHGVZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o744GzGhHKjS/ViB5zGAvNKZtNHUhPYhylMdPvVMLCioncx13XXdIOtQDjfN7D+tQ 24DWiYMgMlzaSWAjY7r9aR+Ah/4FdHZcrBrS+kYY21Slh/9y5QU7u7UMR0r3+0IPE1 tgHxd7iqPwHYiQYCtOB3OlIEdPg7Vd5SAuewJxB0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konstantin Khlebnikov , Jan Kara , Sasha Levin Subject: [PATCH 4.19 033/114] fs/quota: handle overflows of sysctl fs.quota.* and report as unsigned long Date: Thu, 2 Jan 2020 23:06:45 +0100 Message-Id: <20200102220032.428103847@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Konstantin Khlebnikov [ Upstream commit 6fcbcec9cfc7b3c6a2c1f1a23ebacedff7073e0a ] Quota statistics counted as 64-bit per-cpu counter. Reading sums per-cpu fractions as signed 64-bit int, filters negative values and then reports lower half as signed 32-bit int. Result may looks like: fs.quota.allocated_dquots = 22327 fs.quota.cache_hits = -489852115 fs.quota.drops = -487288718 fs.quota.free_dquots = 22083 fs.quota.lookups = -486883485 fs.quota.reads = 22327 fs.quota.syncs = 335064 fs.quota.writes = 3088689 Values bigger than 2^31-1 reported as negative. All counters except "allocated_dquots" and "free_dquots" are monotonic, thus they should be reported as is without filtering negative values. Kernel doesn't have generic helper for 64-bit sysctl yet, let's use at least unsigned long. Link: https://lore.kernel.org/r/157337934693.2078.9842146413181153727.stgit@buzz Signed-off-by: Konstantin Khlebnikov Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/quota/dquot.c | 29 +++++++++++++++++------------ include/linux/quota.h | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 59b00d8db22c..154f175066b3 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -2853,68 +2853,73 @@ EXPORT_SYMBOL(dquot_quotactl_sysfile_ops); static int do_proc_dqstats(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - unsigned int type = (int *)table->data - dqstats.stat; + unsigned int type = (unsigned long *)table->data - dqstats.stat; + s64 value = percpu_counter_sum(&dqstats.counter[type]); + + /* Filter negative values for non-monotonic counters */ + if (value < 0 && (type == DQST_ALLOC_DQUOTS || + type == DQST_FREE_DQUOTS)) + value = 0; /* Update global table */ - dqstats.stat[type] = - percpu_counter_sum_positive(&dqstats.counter[type]); - return proc_dointvec(table, write, buffer, lenp, ppos); + dqstats.stat[type] = value; + return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); } static struct ctl_table fs_dqstats_table[] = { { .procname = "lookups", .data = &dqstats.stat[DQST_LOOKUPS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "drops", .data = &dqstats.stat[DQST_DROPS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "reads", .data = &dqstats.stat[DQST_READS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "writes", .data = &dqstats.stat[DQST_WRITES], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "cache_hits", .data = &dqstats.stat[DQST_CACHE_HITS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "allocated_dquots", .data = &dqstats.stat[DQST_ALLOC_DQUOTS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "free_dquots", .data = &dqstats.stat[DQST_FREE_DQUOTS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, { .procname = "syncs", .data = &dqstats.stat[DQST_SYNCS], - .maxlen = sizeof(int), + .maxlen = sizeof(unsigned long), .mode = 0444, .proc_handler = do_proc_dqstats, }, diff --git a/include/linux/quota.h b/include/linux/quota.h index f32dd270b8e3..27aab84fcbaa 100644 --- a/include/linux/quota.h +++ b/include/linux/quota.h @@ -263,7 +263,7 @@ enum { }; struct dqstats { - int stat[_DQST_DQSTAT_LAST]; + unsigned long stat[_DQST_DQSTAT_LAST]; struct percpu_counter counter[_DQST_DQSTAT_LAST]; }; -- 2.20.1