Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1020687yba; Thu, 4 Apr 2019 02:35:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyENdDYU+qt+3vjrsSWrqn1QzDVf4pcdrx3C7QRPFzp/JkZ64xPYmpYahBeKYIHURP+m0ij X-Received: by 2002:a65:524a:: with SMTP id q10mr4650734pgp.224.1554370538828; Thu, 04 Apr 2019 02:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370538; cv=none; d=google.com; s=arc-20160816; b=EPOIoJJDxv08/kuRRtntdmr7ZeVC3Hqm7BN250s/wYb4sub5FCswbHYAFoAwDvjMlL m1UqcslYjuTxouNz/ilBQTMKakIUhu68QWq9qLDtyTkrppIf4If97Ln403hn0L2hlCmy IF/JGc5SOiMPgbCjx1dFqWVFwapi8YGJ+/yslzEv9LYQIJd/63T7liKodEumrfRUIVXk oYkjSKr/OZVld1pmwsKP3mFCdWUfzYkohD1u9bDrMzYnMtBomyMgdrSv70TVnijkXyA8 cchz9rvy0JgbUKB5U+6ioRzDiPIbzIMYqSCneQnGnmJvaYzriDpUdbdEoHTXtLnt8bmf JxGw== 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=J+TTo9SGOfIgpZqYCxh05NwbKMTZ9ysNBtv6Cvblvmk=; b=FCE5Xb+cEYOlInNzmumRmZ3qv/h6H/7Vlnby97pVdaBBRVkoxohSuzsm8UKtIyc4fu dc3cwtPp249Dpfp+dc5TiFyXIx5sUEcoUE+6yLETCXD8AeQ3wYX9ALXrlN30suZKd7Ct PpUi/LXTP54LeYfoKPUYGtpq7nzN4pJfftAVxEsdmLa87YcBXh1QZZiSAWGU+t/u2qoJ 9KypMJlKgiR6GzUKNoxc3yugaOKtjrF59D8LPjKtECv1lFCwgPvz33XfC3R0ytM/VU2h 6WG4NS2BTjdztmBHJHNAI02T1209ZXTx3xLrq/zi1Z4K4Gyz8eRbQR7wMTSf2Oy965Kn 18cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hmKEArm8; 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 e11si15530451pfd.88.2019.04.04.02.35.23; Thu, 04 Apr 2019 02:35:38 -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=hmKEArm8; 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 S1732530AbfDDJHg (ORCPT + 99 others); Thu, 4 Apr 2019 05:07:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:46374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732485AbfDDJHe (ORCPT ); Thu, 4 Apr 2019 05:07:34 -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 0C8F5218D4; Thu, 4 Apr 2019 09:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368853; bh=SzXhmpQOktA0XK80I1zBgGCtw3HvpI1Jmek0Q6Qb0+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hmKEArm8jDhXi3NJIntbjKXu+G5tNZSqA8zlsW8pi0rk4nVRUc2A7nogr2tqTSYZw UR4YmZuok4yVQhd4CHKtez8icZfU1CAS3EEPo2Np2tn/AhUCH33WPCBOoI31DkByWz WgfmSJeG1WnFkJrGDhniWxOG9P/4GjfoPipIgrQQ= 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 186/187] bcache: fix potential div-zero error of writeback_rate_p_term_inverse Date: Thu, 4 Apr 2019 10:48:43 +0200 Message-Id: <20190404084611.875407024@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 5b5fd3c94eef69dcfaa8648198e54c92e5687d6d ] Current code already uses d_strtoul_nonzero() to convert input string to an unsigned integer, to make sure writeback_rate_p_term_inverse won't be zero value. But overflow may happen when converting input string to an unsigned integer value by d_strtoul_nonzero(), then dc->writeback_rate_p_term_inverse can still be set to 0 even if the sysfs file input value is not zero, e.g. 4294967296 (a.k.a UINT_MAX+1). If dc->writeback_rate_p_term_inverse is set to 0, it might cause a dev-zero error in following code from __update_writeback_rate(), int64_t proportional_scaled = div_s64(error, dc->writeback_rate_p_term_inverse); This patch replaces d_strtoul_nonzero() by sysfs_strtoul_clamp() and limit the value range in [1, UINT_MAX]. Then the unsigned integer overflow and dev-zero error can be avoided. 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 503ad954ccc0..d9481640b3e1 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -286,7 +286,9 @@ STORE(__cached_dev) sysfs_strtoul_clamp(writeback_rate_i_term_inverse, dc->writeback_rate_i_term_inverse, 1, UINT_MAX); - d_strtoul_nonzero(writeback_rate_p_term_inverse); + sysfs_strtoul_clamp(writeback_rate_p_term_inverse, + dc->writeback_rate_p_term_inverse, + 1, UINT_MAX); d_strtoul_nonzero(writeback_rate_minimum); sysfs_strtoul_clamp(io_error_limit, dc->error_limit, 0, INT_MAX); -- 2.19.1