Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5613422img; Wed, 27 Mar 2019 11:43:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQTPyM0z6omEyX2+Lu1tKRt/PYZC2IXH6y3+3GTM4Gta5GKua8hKBiGgRSeKWTFOPB1LVX X-Received: by 2002:a17:902:1a9:: with SMTP id b38mr38441770plb.37.1553712207342; Wed, 27 Mar 2019 11:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712207; cv=none; d=google.com; s=arc-20160816; b=TwuQHu1PNfL4tz445ypiU+x5zzgW19d0r1YzQTt0/gEE8KY0shDu6cViE8VGbqWOCP At32rUT0g6lwbb99nNuLzUZWAgfEiuEodXCSolKhtAQDn3sFkKsc9To26clJ73vVUYdk E2WvKlKHpyeQyBsp5flinmngfKrKVXv3F8/SyLJABWkHnyyyC99ufHVNZBQCKJkOuBiq PQI9y3gkCr63mCZyZiNQqfaTn5p66DBPzbleaDnKrHSRvl1C9gdUReXzxQnC6Fnf+ZSG cd+rtSA/eMBLTOavrmK81ZROO7I7KoMhEBuZpxy5G1itfy6195wnz0pnyQCDlGB5S01z UeOw== 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=38QehP8r04caz8aoUuudNUo3Ei+CVKrRY9kua6XFZbM=; b=m/U/f8KCSTDtbOg+V6cAVzYGfb1VFEdlsTYcS0ajM/n8xqRYU/usvh3Os2O57PyI5v ReWIrGIYD79mjGtmS2qKmHbXXKui+o3Q1o2y6WbcdBQ6CoSYqb412gPfMzs2EOQm7gXZ QEMCY1Idwq65gs4YMskyWR7EWB34/3p2nWW+4nIBJ8TtJSS7JJoQJ+oNjxqsXdH6N4BT wo/CsfOBPokwIrGvoCuEwiejBk+qappf9VmZ4PJGHlaAuJlXZj8UWFQO2LxLprVOE1op 84GpfjsrW108/1xtxmX4Nj4fqhSE3oqKwTbIR4tT83AOq8XKu+RjIxIi9elAl+1CeLfh OJug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vlTVq7qF; 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 h9si18549009pgp.280.2019.03.27.11.43.12; Wed, 27 Mar 2019 11:43:27 -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=vlTVq7qF; 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 S2391282AbfC0SWS (ORCPT + 99 others); Wed, 27 Mar 2019 14:22:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:40318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403828AbfC0SWP (ORCPT ); Wed, 27 Mar 2019 14:22:15 -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 4BA7821734; Wed, 27 Mar 2019 18:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710935; bh=G29KAmivEVauUP9kmJQ62V5Z8ACbEWa485xV7vn5CXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vlTVq7qFS6O9iOfAXS3Rd6AIvJ4CJwnT32iv7h1fnljsBDxaNJupa8c0XvC2NPQXf Ik6tpZV8Fr/5wgpxmrh/upfmk53yhk2LDrdqM3TsqlLUgxC6ehG+/e8WIY8tdPDU65 Yik6HhYwyl96r4YT/IIdot4LMxiuL0SkH8brFYv0= 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 52/87] bcache: fix input overflow to cache set sysfs file io_error_halflife Date: Wed, 27 Mar 2019 14:20:05 -0400 Message-Id: <20190327182040.17444-52-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 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