Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1103059pxa; Thu, 20 Aug 2020 02:32:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC7idN/iOMuMt9LhDq+rMfsPAe0A7JH3vZ5GwzT587DTbgH4P/KH3qer3bhWiszZ+LZSUx X-Received: by 2002:a50:d9c6:: with SMTP id x6mr2101609edj.56.1597915929972; Thu, 20 Aug 2020 02:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597915929; cv=none; d=google.com; s=arc-20160816; b=Xfaw6GThNIkaLUwQUUpTKH1vttZMBYpnLjWkhBiMcw76fKlO5Kl8jthnB+iSf4PKJv PDspcQPL9d3kDgTZG8IGPhf4NYbUOfFdZZN47iVbikWG6GO0qujCeqb9vYQAdyK1qTce pheyWzkIKyIe3ePCsZ5Fut4vW4duY4ROMj5yhAms88bwqkXwzGq2EOkWYv1fMGwGvOXg GHnIXldK3zRaPDu9pT1ZL6G0wYvOpODS5FDRQ794zpZ40NA3fO/txK+n7OqjhuMAbJR/ 1uvsS9HBL8Xjv7HJ+9ppKiIQZbKViHJtKFARFo6QfvkZVGWbCci5XbayfADYA0fYQaQc pbpw== 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=qHwUWqd+ssWLjjfM7I2Q9IIR85mCDGvJePelhPY43ts=; b=d66Gvnb8AHSrdggSuXKhBcRdStAv/mZ+fNwzOBsTA8GOdm6JOLS0hjlD0BSIi7yi30 gAYE0JSFaX+CVpam2+AUX4XiUTb35k5Vd7cP3lcAA6WOUFoaNP/zmEK5LkNRPm4/gwfY 2/0gpYm3PbPB5NHYY6FuGFK+E5mNyQcj3//04U/kEyecLsZBPbqKnmrYV+AYsPHPEp/G +Qqhf7r5Ksb4uMAqTY5FXwxv1cLRceJnWwCAvkdtP+kr2qyy02SxHnU1IQSrbtzV3dfv Snahb116L1grLVKfSidfbbEi53qafh46GvYOhaxRUywz07N9TCI7BPq16lyu42v7er9l U4Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ku5VpqWh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si1044974eds.470.2020.08.20.02.31.45; Thu, 20 Aug 2020 02:32:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ku5VpqWh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728037AbgHTJ3C (ORCPT + 99 others); Thu, 20 Aug 2020 05:29:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:37768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbgHTJ15 (ORCPT ); Thu, 20 Aug 2020 05:27:57 -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 7F22E22D2B; Thu, 20 Aug 2020 09:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915677; bh=38NG1pLsR1xbT2PYTatK5byj3+e/BDO/FjEFfRGY0Zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ku5VpqWhEGKChEvsB7DRQYTc4gutAWsDoZNVifKOOZCNScYugEQ4t9ibYRpVCmAHr VBs2C8V75cOkDykobbpxKEPcc05UVh+VhdOrrW6qw8ALf4S+qkXZLC4ueinEBHUuOL 5OmtyMJVcoI3GZm9nQdEwD9yJKpKohWZeQt8mKXY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Jens Axboe , Ken Raeburn Subject: [PATCH 5.8 067/232] bcache: avoid nr_stripes overflow in bcache_device_init() Date: Thu, 20 Aug 2020 11:18:38 +0200 Message-Id: <20200820091616.044644356@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Coly Li commit 65f0f017e7be8c70330372df23bcb2a407ecf02d upstream. For some block devices which large capacity (e.g. 8TB) but small io_opt size (e.g. 8 sectors), in bcache_device_init() the stripes number calcu- lated by, DIV_ROUND_UP_ULL(sectors, d->stripe_size); might be overflow to the unsigned int bcache_device->nr_stripes. This patch uses the uint64_t variable to store DIV_ROUND_UP_ULL() and after the value is checked to be available in unsigned int range, sets it to bache_device->nr_stripes. Then the overflow is avoided. Reported-and-tested-by: Ken Raeburn Signed-off-by: Coly Li Cc: stable@vger.kernel.org Link: https://bugzilla.redhat.com/show_bug.cgi?id=1783075 Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/super.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -826,19 +826,19 @@ static int bcache_device_init(struct bca struct request_queue *q; const size_t max_stripes = min_t(size_t, INT_MAX, SIZE_MAX / sizeof(atomic_t)); - size_t n; + uint64_t n; int idx; if (!d->stripe_size) d->stripe_size = 1 << 31; - d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size); - - if (!d->nr_stripes || d->nr_stripes > max_stripes) { - pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)\n", - (unsigned int)d->nr_stripes); + n = DIV_ROUND_UP_ULL(sectors, d->stripe_size); + if (!n || n > max_stripes) { + pr_err("nr_stripes too large or invalid: %llu (start sector beyond end of disk?)\n", + n); return -ENOMEM; } + d->nr_stripes = n; n = d->nr_stripes * sizeof(atomic_t); d->stripe_sectors_dirty = kvzalloc(n, GFP_KERNEL);