Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5648825img; Wed, 27 Mar 2019 12:25:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTdiz7EhgdDsf1myiNuEI9yhYy6BZTKcuAUqg5xOD11G/5qQMYTtCqUJZRFP2kSE9YAY/P X-Received: by 2002:a65:6383:: with SMTP id h3mr35155367pgv.11.1553714702174; Wed, 27 Mar 2019 12:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714702; cv=none; d=google.com; s=arc-20160816; b=loTSeP2Y8Lqy6KHXyalhU2VQonp4m54+vtmqzL3nFxj+lhdp/xyKj1bF6vmdKYSLCy wtuesQqdGTVIluaU53siEv+84PMtKPVXlqIXVGn8KE6JVnmFaA8qh8cjo3J+yqRBM6tL NccEajb0fuGIYEK4t6HGTNDOiuEPcEIL7j+bWqZK5cHl7rtaVPTenICW2IRQWkFdO3Kd yTfteJJ2zf5Xk753L+bGkdspWpp4LIR9Rv69vkLWK6gIhSGUd3pmnpzM4r3BT+16Z5++ W5poyu15lG7cklql6CpVhP0MPedVlAH4RBqimtHfLv02OzTM0ESMP7Age0qcxPZ32XqR KXMw== 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=zJ4EKt+o0ttVz2zwpdMjhVNP4JdhtEVUSrwqpGcgr2U=; b=u8UQNp0QhSgIcm0yKXtflp0SvLyIXj7Vvygs9USDi3tl22pN48TcxfoU4SFCtMbLyC JyCB8iup9OXzEMoqBHGO2NIHHxGwIVUMpOMBZHLVvSwqKa7wYw91LU8SuQ0H+heOngW3 aMEcPHNt8u5Yqg/ONm9aEO9fWizwbPX/+6GNS7MUz92fpJRvKZ463fPqnERru1byagj1 8zER/86/LiVqE4LWATen741jkjWszpgrLigIJUnzZak/UF94EL5h91/biDrxKGp++UCR VVkCIRajgzgMse3ViMXh0ZHCBH1v0vD8Hqfl/3//FACvjFRZDf66xG/D0aH5h4arrtBj spCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uBJfKnAE; 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 14si15523572pgv.248.2019.03.27.12.24.47; Wed, 27 Mar 2019 12:25:02 -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=uBJfKnAE; 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 S2388042AbfC0TW7 (ORCPT + 99 others); Wed, 27 Mar 2019 15:22:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:48908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388086AbfC0SHG (ORCPT ); Wed, 27 Mar 2019 14:07:06 -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 9B7F721850; Wed, 27 Mar 2019 18:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710025; bh=PYJunr7DZonYf/OZbjaiM+S8S8YjIl8g6WUtZd3wjXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uBJfKnAEUdTUJVhUU9SSa6U2UqUSS9dETjBNpBW4SCCCUY6wo+mLxwHXKh9dcMTsw o9bwc90cvsKX7hjGN3pM04eUG/7eW792mQc4xC5Podb8rN+ronIHJu0i96tpG9G3ch 2FrV7ovPmIKGG5Qn5LxmNV/BIiz/0NEqg1BKoiWM= 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 5.0 162/262] bcache: fix potential div-zero error of writeback_rate_i_term_inverse Date: Wed, 27 Mar 2019 14:00:17 -0400 Message-Id: <20190327180158.10245-162-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-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 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 f98cda32065d..28e0d5a5e25b 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -287,7 +287,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