Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5598023img; Wed, 27 Mar 2019 11:24:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGsX/wccQTaUq63c72/Os+hKzqKeNjeJbP3nQ06tAcsZPKVEUlJ+ERCUZb/l0lDDsrec76 X-Received: by 2002:a62:5385:: with SMTP id h127mr35551227pfb.10.1553711064437; Wed, 27 Mar 2019 11:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553711064; cv=none; d=google.com; s=arc-20160816; b=mQYPncRb0tAP3Hh7ObadMqWZkgOZtgDZKLvJqF+pXtI0tNeujsFOetSW1EMCtjq9zy zSCkPWOkaKrOxUXghWVmzH4yDhrJH6IT5b0KA0KSfWfzKkOzsLOE4icXta7LdfmdcUaX lioul33rY9oOw4XQNbSQXx513FTJZ9EeU1/KTbyifS9oENM6HJRjw30nvdWxtmZW1Tkv jZvB0vUCtrqZq+2lxhr96KUlh+Mb/7E9kdz3Map5KsRyNtzSs/Ws9NLT+EBghLnMe5pE rsU+xL4dTUBR3i5xnx7yqPgS2iY+62MYSiyxpe9fftXN2E9FijzDX8P9sLITX7m+tW7F 14IA== 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=v0MswaiteGrZ0JxmTz6FpbOXUCK4QNBCChgRVWF3xMA=; b=Gy6NS8wlJ8TDVsKHVQotZTk6RCxq8O2WoZLLHbHIyaYSjxkK4Q7lj2d0SZPQyfyGwd PprVwfK2QfTQZC6ETc3hP4XhIkcp52K8/28gBSAmBXcspH8+RxILcFb2xf2uaMZFoFvN a1wZEH/IK+cp5dhHmHoowiD4Ox9lKF9zt3VGIriwEWYpC7uCXiEMgRMifxh4y1eVxTk3 5SglMyqJ0g0H2xIdzGXoLWDy8IdBjNMufHJUbWuBysCaZu5mTyYd2OlfrajUXIILWsmM WdbY+aoTf7dP6Xf7qACqm3q4qHJRSols1aJofUf6N8q9ItB5MNojaTZr/FY8AKvCJj5i aKmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EjdRP5zS; 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 m15si16901749pgj.126.2019.03.27.11.24.09; Wed, 27 Mar 2019 11:24:24 -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=EjdRP5zS; 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 S2403848AbfC0SWV (ORCPT + 99 others); Wed, 27 Mar 2019 14:22:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:40330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403831AbfC0SWQ (ORCPT ); Wed, 27 Mar 2019 14:22:16 -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 6486D2070B; Wed, 27 Mar 2019 18:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710936; bh=qUpKSpkOlmi2VkEic6poulyBp84gUtWWBEjZQBMPOlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EjdRP5zS4QCG0Qy/flCUbtfw1nO3+1xB6qvOJ6/4pWqBhNL7taiD/nLzlt0o45hMP anEtRFyxfZJ4ECTMS2326KK0KVd/h4vr3ISgVM4pXoXRvdNc5MJ4oAeU/P77MWPSg5 ATVQ6E+MnHBrPFQDvBzHrJc8iW0wgqYGUHCaRuVs= 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 4.9 53/87] bcache: fix input overflow to sequential_cutoff Date: Wed, 27 Mar 2019 14:20:06 -0400 Message-Id: <20190327182040.17444-53-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-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 8c27a3953e92eb0b22dbb03d599f543a05f9574e ] People may set sequential_cutoff of a cached device via sysfs file, but current code does not check input value overflow. E.g. if value 4294967295 (UINT_MAX) is written to file sequential_cutoff, its value is 4GB, but if 4294967296 (UINT_MAX + 1) is written into, its value will be 0. This is an unexpected behavior. This patch replaces d_strtoi_h() by sysfs_strtoul_clamp() to convert input string to unsigned integer value, and limit its range in [0, UINT_MAX]. Then the input overflow can be fixed. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 87daccbbc61b..463ce6757338 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -215,7 +215,9 @@ STORE(__cached_dev) d_strtoul(writeback_rate_d_term); d_strtoul_nonzero(writeback_rate_p_term_inverse); - d_strtoi_h(sequential_cutoff); + sysfs_strtoul_clamp(sequential_cutoff, + dc->sequential_cutoff, + 0, UINT_MAX); d_strtoi_h(readahead); if (attr == &sysfs_clear_stats) -- 2.19.1