Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp998722yba; Thu, 4 Apr 2019 02:05:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUiHoYS7vV2r+mhDLkp+0vQzl4cg6w+uiTTIaq2929jIFjpJjt9x82Zyj4CyJaesA23ofs X-Received: by 2002:a17:902:7892:: with SMTP id q18mr5088164pll.163.1554368727931; Thu, 04 Apr 2019 02:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368727; cv=none; d=google.com; s=arc-20160816; b=XGQGg2NHR/d7NiR7bjpJVEGytAM6yRUpV41t3IEErI5LPHspkHjSs3N+FwYQ/xM7ZD /aT5d1VzI+AuzUurUfD3T7xCTID874HNzIhtFtwplEUc7pvZGDzo9CPDYzqERoHyDCVn JPwOe0rlDCdH2Xid0xMWI2LeOBkSm5jhPaO4ocr9sU2dGAN3fE8x8qZHKEnJKTbCyW0V Dtf3MekR3tgsxr0lmSAfV8FyRRcR6r3EebkeJSnjQma/YQQJDw/yMpznV+0w0r7PVXOH 9+qhAsuj3RV8pul6AmX4FhmcyPqQKFNk2PCTZmHJTriKS/fWzZcCb7iYfyGEizi3cEsJ ej0g== 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=B2sVr3L4dwfcCyuOWajDioQSKO1ZmTy3zKmKVp3ZCj4=; b=Cj9RCJKZWurGb4N2m7WZvtTT3Hsn0lCzByiPAOg99/mWQ4h/8E4wDdE+5XyhnouO+L UQapwhZ/G1txCR59hwj8/2rLaKcvSZAvqD4jUueKNngbCY5LORGUjkbbu87MQicVfK7b tDfHKIjN3Fk04nVMs6aTMAMxMMjPo1lwLJnBViWn3VhTttmrl6knBe7gnYP5PLfNhhtQ APhOwyjkcykUhI7zw2vKWOtAAahCsSFkG1vqsdM0+JkRnmWvOORfxjISz8hwMgUHw08p V67u6YsFktCrVzWOrrCjvM1wSru1BvCnfClKVN9G2LEAjpEN6DH4jVQROhoOJfcx+uwE JBhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=knQkPARM; 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 l71si90982pge.428.2019.04.04.02.05.12; Thu, 04 Apr 2019 02:05: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=knQkPARM; 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 S1731733AbfDDJEk (ORCPT + 99 others); Thu, 4 Apr 2019 05:04:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:42522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732009AbfDDJEi (ORCPT ); Thu, 4 Apr 2019 05:04:38 -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 67A62214AF; Thu, 4 Apr 2019 09:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368677; bh=jHqBwz2Zx7vHf+6B1phBX8R1CsZv/hTjJc4DOPHUreQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knQkPARM/1/5OWp+gOwKzmLOWM24EYUimmQDVMe0evtFacLgWz76XesRsWhgRklc7 3eQCz1D+6lDttYqjlb54wIYc0QOJ0pvKlomnXgIgOH4HZ3c3gef3j3xhmuUohOskKt v7qdh8YLWSnRA7cW2BkOWiDUrVK168YKRMsS6IqY= 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 113/187] bcache: fix potential div-zero error of writeback_rate_i_term_inverse Date: Thu, 4 Apr 2019 10:47:30 +0200 Message-Id: <20190404084608.592582747@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 c3b75a2199cdbfc1c335155fe143d842604b1baa ] dc->writeback_rate_i_term_inverse can be set via sysfs interface. It is in type unsigned int, and convert from input string by d_strtoul(). The problem is d_strtoul() does not check valid range of the input, if 4294967296 is written into sysfs file writeback_rate_i_term_inverse, an overflow of unsigned integer will happen and value 0 is set to dc->writeback_rate_i_term_inverse. In writeback.c:__update_writeback_rate(), there are following lines of code, integral_scaled = div_s64(dc->writeback_rate_integral, dc->writeback_rate_i_term_inverse); If dc->writeback_rate_i_term_inverse is set to 0 via sysfs interface, a div-zero error might be triggered in the above code. Therefore we need to add a range limitation in the sysfs interface, this is what this patch does, use sysfs_stroul_clamp() to replace d_strtoul() and restrict the input range in [1, UINT_MAX]. 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 01c7c4452a26..503ad954ccc0 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -283,7 +283,9 @@ STORE(__cached_dev) sysfs_strtoul_clamp(writeback_rate_update_seconds, dc->writeback_rate_update_seconds, 1, WRITEBACK_RATE_UPDATE_SECS_MAX); - d_strtoul(writeback_rate_i_term_inverse); + 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); d_strtoul_nonzero(writeback_rate_minimum); -- 2.19.1