Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp998628yba; Thu, 4 Apr 2019 02:05:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQLcZhgKBZre/0tN03UcdhnXjZZUeR7NCqRTHxott0SaR42tPu//MkmDbFP6BWBVfg4IlD X-Received: by 2002:a63:c242:: with SMTP id l2mr4686972pgg.138.1554368721989; Thu, 04 Apr 2019 02:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368721; cv=none; d=google.com; s=arc-20160816; b=upYMMSRnkGTFZ42+abkAU47h44uh+WYi+y2HDVww9ZFhYEGq2QCM+e2J6R/JwOjwsr NK8hLZ5H4kLXSNAhdZXXQvXHJOZ4B30VpqqAWJO0GANHun+OOjyJd1toUk6Rxwyq9x90 vCsYExNZRfGFy2hCxnPK6IB4WkBjKb3SWtyuMAd3cTS3q2QF38pm7JmSJzT01xMkeJUb MnHxGbGs5yq75KVws3lLtk033GrljYETZ70ATK8XvJW3cgtz/TzB3D5v5fEOmZCQnAP3 //1Z3d6nDTHTbwXTqYRi3vVJlUyJe3+RqlDBErWrcITzNpbBi8pu6D4jwMqEIOu416dK 5bYA== 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=A+Ygg39Kxwh846wkND4L7gE4q9wsC2E+yuCVJodJSZY=; b=tyFpy+FGqPTC3B3DsiX3aVxqLa7eANH967VGeUeMPOo52dtMz0UgWLmOlFozGAmd6z DwhbHU0UmwBmff3AaFVOUUtMvqN6yoIhJqzpnl8fWRbRbqvPORolUAl9YVsDIcKUGra3 6yikgN5vjgvBqIDJuDLaqpb/YY1rWqn2naSUt7e8qiVXFkqiFzBjfTmkqy6C7DDuyG+O y/963wGFQEtir6KMQl0YRwBGbAkTOCRsGljJchipTD33b0GxeV3CWgRBgxVrzb4ginig XgI31QmK/y1bFRnc7pRs+RqjW3AK5cZrncoC8ZvhM/T/ShY9ZNPDHU/e/zoIekF28cp/ XP9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nAS8Jcei; 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 g123si16974626pfb.24.2019.04.04.02.05.06; Thu, 04 Apr 2019 02:05:21 -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=nAS8Jcei; 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 S1732000AbfDDJEe (ORCPT + 99 others); Thu, 4 Apr 2019 05:04:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:42412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731990AbfDDJEd (ORCPT ); Thu, 4 Apr 2019 05:04:33 -0400 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 1A0C22186A; Thu, 4 Apr 2019 09:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368672; bh=IMQ6ktOIPPWCpzfVuw7zEZnL1rByMbqFfqY0bqvg3Eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nAS8JceiGUCIVvxm+p4JbhKhlX1LiTPFjwxEKXT919WP3fmtnEK35QK7awiRdF5X2 7Mkou1KY2I3BUlxg71SNgavofqHi7jVcYeO6ZjDII7MB7kW3GNmczshBjHx1TPtR3U WTOPMfxzzg7uGlTvbP9JuzALSlcenazGJMrQpqxY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 111/187] bcache: fix input overflow to cache set sysfs file io_error_halflife Date: Thu, 4 Apr 2019 10:47:28 +0200 Message-Id: <20190404084608.500905090@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 26f035a0c5b9..59bf13faf752 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -766,8 +766,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