Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11809871pjo; Thu, 2 Jan 2020 14:40:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwesvkqNbXNCVv8NuqpiU+rocj8ozDrgbFkrvBztWOm2NJln5LMgBFH4L1IqR6l5YKq0AUG X-Received: by 2002:a05:6830:14d9:: with SMTP id t25mr86675285otq.258.1578004804788; Thu, 02 Jan 2020 14:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004804; cv=none; d=google.com; s=arc-20160816; b=GstzQxgf5HQ1fbA72AlAU3Th7EOTuyZMS+Tgi/T9VViolfAvgehxSJJlWhvlFtBrqh Guxaj6rsp3/9RX5uLNc5KNlrNJxzO7NS5gONzGPyZGw/hD+abmWEKLD10vOVboj5l2XY IbhA854iD/fPQBc6sZ1IpWlqHwaU8VmSEphHBKygswUeISo9JRXzlSh6Oh2Fc55b8ch3 Pq30gF9uDfF+UxNRy837sik3o6g+vLmuNdVQTwItu9n4Jey7zXw+ovvFTGAp1ZAiaobE EiWTbq8InBVN93Pmr0pakauwa5fmtd4xgg5Ev7/hRk/UD+UtO9f6gS4tQR4uKVXxR62h CkSg== 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=giOI33wDhEGCibMvJXT7pYzyCREQ4zRwGBTaMNZYtkY=; b=c6XThvsc9ya7ZZFGA6ENUCHFUXeJtOSPS8V8d676pDHIApngctcS4EUpRVuVDXLrsa zppPld3ekrv5auxgy6B/Ffnm7cLWxN4akq2HAGCBqamY70RgIEuJXEVZBMmKIteEEqBw RF8C6dLERjvRlmu37MJcpZilVD2qqf+dLcbtlmBzLdYx8hsTCsi9O20D2EZ1KUF3pALI b9ANKno6z2WV4HwolUrJJZzCZUAt0tS6d6fTiSW0qNmsPm9WtEkY93aNBDHwPMu4OBIs +5vfTIGNSCxTyZrCTqSpFHT6opFXTYj4v+2/jF00WQkus325pAOS1kRu4dUX7pDipd1F zefQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ilEI+U56; 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 l204si27883059oig.31.2020.01.02.14.39.52; Thu, 02 Jan 2020 14:40:04 -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=ilEI+U56; 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 S1731271AbgABWiK (ORCPT + 99 others); Thu, 2 Jan 2020 17:38:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:51406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730880AbgABWiC (ORCPT ); Thu, 2 Jan 2020 17:38:02 -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 430DD20863; Thu, 2 Jan 2020 22:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004681; bh=fHxR6C7OqNi0ftmc0Q2dWb7WLoPSSTDn/Z/2G4v/5uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ilEI+U5622iiw8kovbLjx4UTdhFH/bYEXmKLp1HPOQWy6VSprGSRjp/y6czc6elKQ igZ4OYafGTGu6AruVpdiSSuhLwqW/FTVp58OuxshYTM7fHqtAglPD6SczocS9iSfVB TWIsdClNNrLin2v4w4bZNwWqN3ZS+8ERNUWta77c= 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.4 108/137] fs/quota: handle overflows of sysctl fs.quota.* and report as unsigned long Date: Thu, 2 Jan 2020 23:08:01 +0100 Message-Id: <20200102220601.703297133@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@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 7430cb0e21a7..b7d5e254792c 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -2783,68 +2783,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 b2505acfd3c0..b34412df1542 100644 --- a/include/linux/quota.h +++ b/include/linux/quota.h @@ -253,7 +253,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