Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1033724yba; Thu, 4 Apr 2019 02:55:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+58S7wby2KVr5s5m1o3sOlZlfwFFgljIFzUX5izUHz2RKL4SWVx+Aa8JShhNtSFu43TC5 X-Received: by 2002:a17:902:e109:: with SMTP id cc9mr5542357plb.148.1554371709033; Thu, 04 Apr 2019 02:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554371709; cv=none; d=google.com; s=arc-20160816; b=RIDLPkuUPk006fzuPv1ybFZaqx31AtrJ8sVSCFqry9guz6qZxOdZlvdd799P37Mu7M /6WrzVr/vsF1dixmdSEnr9TMzgLCrV9OHimq3EC3fzFwqA6X5i5RdVhCNiZJuJ2nKvrR Ro00EMNS4LoEQNctv3Aeo7ajpeAGRp1BfWUIi8YwNqdR+9HUjfXOmFM6PC6PesXBvk6h YumsfSylceDfE6kXGuhj91lZS2od5Wj86QnRMla7fCvseZt/JuGlXukLAXmOipzr2LA+ OOnvk3KHSQBjlUc7fhBdN1dlLjJmeMXSSZKbGzutLJqr0mmA6hih3VfpDp3mWZkftcsT JYiA== 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=SsYB38BViw8o6UD6aPovbJWBsJn3X3o4EiQzb6Qt83s=; b=WtKLLvQif6wXIgR0lWypkL6XInSMzbeQPpZxKSsy7YGTZCqZMJkLp8N71ZLIwbIEil /ugP52SzpJg+C1Q9hCjcZpmj0iMy+tl7kRmas5tqiMSx1eDSh4iFx2zdk4n9Dn3F4omc 8vUYLEWi4FgykcDRYFEKnnIC/kkTFLoHdx1xPMdNkhLGK4HQyM4CFZ79wQPol2g27qk+ 6wr+NG4wlnD4U0ZTWqVyqyCGpF5MqSP5smECosXf63I6ZsWWmE+f/F7eq0iUg1+43S58 zFzg3LtNbHaxdkiGwHiLcNfzLi2hOTz7y04w+LUvoWryazPfvhxK6Rp3yL5OTqpS94Yq fg0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FEMvygHi; 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 n13si5780117pgl.348.2019.04.04.02.54.53; Thu, 04 Apr 2019 02:55:09 -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=FEMvygHi; 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 S1729640AbfDDIwf (ORCPT + 99 others); Thu, 4 Apr 2019 04:52:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:54708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729614AbfDDIwd (ORCPT ); Thu, 4 Apr 2019 04:52: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 0BA932147C; Thu, 4 Apr 2019 08:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554367952; bh=hwM4/DBT/s0MwM714VrkbFtT8U3R/679Bfp7AHa/bZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FEMvygHi/wygvgFw/VCEfnGHmycfiMIYLMP62ZKxD0cEDtt8oO18uvnYpK10KXxA5 IqZhZ3k4+EckTUzhobUiTShRi5wipiiQZ6iHevB8XyWpRq4KpdULhqq81FAbc439h0 wjNdt7s3cVhwx4hsMv09Dy2jd5j5LyKwhKRKFKo0= 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.9 58/91] bcache: fix input overflow to cache set sysfs file io_error_halflife Date: Thu, 4 Apr 2019 10:47:42 +0200 Message-Id: <20190404084538.798863229@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084535.450029272@linuxfoundation.org> References: <20190404084535.450029272@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.9-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 5a5c1f1bd8a5..87daccbbc61b 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -645,8 +645,17 @@ STORE(__bch_cache_set) c->error_limit = strtoul_or_return(buf) << IO_ERROR_SHIFT; /* 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; + } sysfs_strtoul(journal_delay_ms, c->journal_delay_ms); sysfs_strtoul(verify, c->verify); -- 2.19.1