Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5646303img; Wed, 27 Mar 2019 12:21:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqw91RL8iO40wgXhpU5UzkT6cGhfDOqsaOlKUXJFex+Yo2Gujm2vdp8eCSUfYr47q/Pbx69m X-Received: by 2002:a17:902:501:: with SMTP id 1mr37693341plf.72.1553714503012; Wed, 27 Mar 2019 12:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714503; cv=none; d=google.com; s=arc-20160816; b=CcX2+WmbIPLA2IOP48Es/AcFb9oAhLoi+AO5J6JMAfF2ZMly0mknefNl0r+WIwe79+ A+D2Zt+1HZ28MaX0A7c+oWnN35YNujNaHpyXJUTnlM9wnSY0ye/DjfJgFGHqRyWGxsz5 UN46v8+f1vUXpKmprOM4lAWBVa0x2aKqEqBQXxqwO8FU4ZTp3dwyoOxE/hfgMAVVfxwz yGkbIAApDD2bgVxFl/rIEFnyqG2Iu6hf+OdC29WZdFc5BCQo3/RPVJ4v8YFn5izU75Lj MpWnKJSFE7CoEPV2JpOYTL9cWQBD9SRgufZHUjQ4nr7e1vXlYbbbPtnsVrDj8q5EbMhh AI4Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m8SNM7jY+0w13pSIN/Uwb73BAJC2kc1Zd2ms2RUGQmQ=; b=Gn5r7ndUG1gwRb6WMaDNuVoMjQNARkonOombNRRodcSLerqHN28nMmiOs2+ggqZUzd id5jvZ//sVKlcKcO/cauRbRtZ4IU0SBKK36iy/YZ4tqqdldVRiL8X7Io2/QjzcX6IunJ gvpM5An9RbvRF4dXSX/WpjSlJEaS9fzudbHI9ZxKn03M/r4WU+JpxIKeProHO/n48pg6 DBILb5N0awxcMC3yfXhg6lGaIc5HVmZOMZ5eisYlbpePOkM8fd8DLWlZkXjKvMno5Cuc hM/iXVrQORq/WH6siP+21AD77OgUnHcQidYK7GmmLjXstt34a4KlE96oaX16wrSWdDNR K69Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y608N6ix; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a95si21707874pla.350.2019.03.27.12.21.27; Wed, 27 Mar 2019 12:21:43 -0700 (PDT) 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=Y608N6ix; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388096AbfC0SHH (ORCPT + 99 others); Wed, 27 Mar 2019 14:07:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:48866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732924AbfC0SHE (ORCPT ); Wed, 27 Mar 2019 14:07:04 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 738EF2183F; Wed, 27 Mar 2019 18:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710023; bh=Jw8eDUIkLSCnQ+qMp6q1tOK7drPUgkAwHackCAwhMJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y608N6ixKv6HgHoZQZkrFC7F+pjbKMU5BP/tAo32ke/e/kJ0e4heKTwARLMCO2xlu 7vxQ6HMADOYNcJHvfq87CM2i8L6ySrcPPAXPeb4/WR/Hk0yLXjDjvQEtxjgas7P8iy i/zsenvtEO1zA63CUo3uU2DFUauIoKlKOAU3BXk8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Coly Li , Jens Axboe , Sasha Levin , linux-bcache@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 160/262] bcache: fix input overflow to cache set sysfs file io_error_halflife Date: Wed, 27 Mar 2019 14:00:15 -0400 Message-Id: <20190327180158.10245-160-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li [ Upstream commit a91fbda49f746119828f7e8ad0f0aa2ab0578f65 ] Cache set sysfs entry io_error_halflife is used to set c->error_decay. c->error_decay is in type unsigned int, and it is converted by strtoul_or_return(), therefore overflow to c->error_decay is possible for a large input value. This patch fixes the overflow by using strtoul_safe_clamp() to convert input string to an unsigned long value in range [0, UINT_MAX], then divides by 88 and set it to c->error_decay. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/sysfs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 557a8a3270a1..3b287f974fd9 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -778,8 +778,17 @@ STORE(__bch_cache_set) c->error_limit = strtoul_or_return(buf); /* See count_io_errors() for why 88 */ - if (attr == &sysfs_io_error_halflife) - c->error_decay = strtoul_or_return(buf) / 88; + if (attr == &sysfs_io_error_halflife) { + unsigned long v = 0; + ssize_t ret; + + ret = strtoul_safe_clamp(buf, v, 0, UINT_MAX); + if (!ret) { + c->error_decay = v / 88; + return size; + } + return ret; + } if (attr == &sysfs_io_disable) { v = strtoul_or_return(buf); -- 2.19.1