Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5639987img; Wed, 27 Mar 2019 12:14:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqySPlk2Ttm5/l757C/jv69wHMdoVlENi7WnU6yhK884jcAwCpqPxwBxKXy2/HB4TKdwKjY8 X-Received: by 2002:a63:78a:: with SMTP id 132mr28686549pgh.196.1553714075118; Wed, 27 Mar 2019 12:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714075; cv=none; d=google.com; s=arc-20160816; b=0TYyI6IcRjicJJn/1vRbhlCrBsPJ8jU4rQmeJlXROT1vUXWSEK9et0zzRUyWj9Aqo4 aTF4i9H7CWAqvTDrM3ilIitqYJY/kz/WPJIIlhHjT0fLiDahfWYvq0ypkf+NPi+hgYof /zic8mG6SrWH86/f13zYdL5mpSTWBukI8lf6GsFf2d9TP6d274N24rgZ55Oy12Rb6pR7 JiCgqM02eD30O2wdVDjhjlVSFbsgjO5XpOYrytstYaIIAWaJiVLFKzE4LOQybXZLy6Pd 5wyNW3KdT6OVzk6zm2rlTPqG9l77m4GJVtRe3ys0Mf+fb6mDBDs8eTGqGURp96REztJp gd5g== 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=TqwFIL6qJBweCnukiyidV6C8cIq97iq+PsvsmKxFwuQ=; b=ptkp55waDSbsYNzPJN/SjU4M2yjjEsvJJ+vD/r8QDPZdlGlYyP65L1qQ6OAdQ1/ozK Zgu+WKSKJmWcIyNrRS1ankIG3IlgRKIkUophdSQ5qTe6VQhjzwQRNJpLnSlu3tzdWqq7 rPxe+vXXrRLOKQ5LVkx22/4fbDbdEyLBrlSCNnx3SFaGrvZAuKdu5thkmZEjXkpPavtK kvQGPtJbhFsS0n9VzPzH0Py1v5B2zMh5ODwe387cBRIBHyOQtYlDZJ6dRioKlHckUnTB w/EsaIe+nMu7WE9HUZj9h9L5IuoeT/Z2/vxLKfqgCPZwXC+nj+JAUmXKrNZ1z23fG2SJ BuOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zQp1jDS7; 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 d8si19520827plo.41.2019.03.27.12.14.19; Wed, 27 Mar 2019 12:14:35 -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=zQp1jDS7; 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 S2389228AbfC0TMg (ORCPT + 99 others); Wed, 27 Mar 2019 15:12:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:52386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388334AbfC0SKY (ORCPT ); Wed, 27 Mar 2019 14:10:24 -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 D724B2147C; Wed, 27 Mar 2019 18:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710223; bh=RwDSvDrJpi9ErNnsHMtIec3eG0IaEYGWG1YrxeSsccQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zQp1jDS7enOstCIGTm+Bq0LrVAjOT9xRXGy0BI0+pbjAlt9NQ6ZPDuS3UIpJpjFUI pVYj2aj2Cfa2Gfa6nmHWA0JdtKkmssht5j7Py9XO0j8ojVBo20ggobz67KbRoXwrtq eyshN7b4iTBCASCBKZi3t4VQC23FII19F+tmBfIc= 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 262/262] bcache: fix potential div-zero error of writeback_rate_p_term_inverse Date: Wed, 27 Mar 2019 14:01:57 -0400 Message-Id: <20190327180158.10245-262-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 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 28e0d5a5e25b..e5daf91310f6 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -290,7 +290,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