From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D791C282E1 for ; Wed, 24 Apr 2019 17:20:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C59521907 for ; Wed, 24 Apr 2019 17:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126415; bh=mTJrMbc6Gv05gm2p9P/9C6siabrpryr8zrGHqRBAy3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nCH08kaoOisgJQ7OT31vSUmiYShk1AF10r5sfMWPvUUgGCy8wrghA2GtGho0pQUIi OgFTvXAZOjU+j/uHF0vOQcuanQojpD/JB2BiNWnshghZi5YlOMpegTtPo67F4phdPU upqbyzqOSUtE2h6H30TtK2BsbBRgjYt7hKjvuR0E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387998AbfDXRUJ (ORCPT ); Wed, 24 Apr 2019 13:20:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:45436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388488AbfDXRUH (ORCPT ); Wed, 24 Apr 2019 13:20:07 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (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 894B7205ED; Wed, 24 Apr 2019 17:20:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126403; bh=mTJrMbc6Gv05gm2p9P/9C6siabrpryr8zrGHqRBAy3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHH5l+3lrjZyeokQ31X5WBAkjNBnzDLsZMqyqC47SePhrtK39YgeDi7ZAjwl8WNLQ Iam+qb18NPdPIAXtwRFPI+hhpcXyNBJYrfP9lGRbSVNbRKIg0PEXmm8rh1zfe4C/HR THXaq5aQhFxXpq6o4aqBEeebEBmx43nGvaV3e1fg= 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.4 046/168] bcache: fix input overflow to cache set sysfs file io_error_halflife Date: Wed, 24 Apr 2019 19:08:10 +0200 Message-Id: <20190424170926.522591722@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170923.452349382@linuxfoundation.org> References: <20190424170923.452349382@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 [ 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