Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp465703pxx; Wed, 28 Oct 2020 08:59:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQX1HSjS66fGjrHvzkZgwuGJkBfSUUbNfNUNb+w9BUZdFc62SdqA8wo84GfGxDQUIrVTKw X-Received: by 2002:a17:906:141b:: with SMTP id p27mr8531924ejc.205.1603900750117; Wed, 28 Oct 2020 08:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603900750; cv=none; d=google.com; s=arc-20160816; b=ZtYG2deYWnW0pnqXfdZ0vNeOzI7phHbLiNXBKgplFJt7MnolVo3g8hymsgCPPR961K XdfuzPCI/kNHTW3MYa3VMkgaX63Q4wPic6VA9S7Jnx1PfC4tHgZup4XMMlCVovb/h6b7 cr1093BorDRtAzXrD4X0E7MEAMl8mbJo+0hSUthKOszBy0xuByuqOIRYy9DS7f3f6DLW f3kX9XbZ2mS0TIGPnKAPxr0CvtVT+e9aK6gNeymToW3sAN3HbITY1/FUR1TPIkhASYPq nGoYsPirTGEE/Q7oK58vSdOtxUbzhZpdEjIkNPk0w9TZVtnbS4DK8JoDrJn5Evgl+fkm 1rFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=004QFyhYPqhBye7NnoB7A2iXc4/Am/lwhm0GRepPNfY=; b=HKx/+72J3AqmtN/hecmHu9C+X3ntFpqxyfAWyU5F4CBrQiPr08wZ1/v9TszNkEFVu2 Ue75/a0hgAqfRLC/dayFQB/WJmAfGIfP1txlIcPeQj3WNq7WXDN3lGQ1G31OakzdMbxk y8qM5POQLnpOucewwesONk7PNrvfH1ybdk7UYK49C7vGx71IYLucMn6nAQydIcgfsyoU mV9r4X9QgJNDacdU9zQyveffv+XLJLkQsuiGOVmf0A2mTY3dZoYemy6cFmAg2sZ4aZh+ MakLCdBq1aFknwc7ApYFGvyyk/n9UtmIvUPHKlk4EhQqB/Ee8lARN2PQV7J5weWdkWEU bEBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cafMEkyU; 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 q18si2524555edb.466.2020.10.28.08.58.47; Wed, 28 Oct 2020 08:59:10 -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=cafMEkyU; 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 S1813659AbgJ0QxE (ORCPT + 99 others); Tue, 27 Oct 2020 12:53:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1794728AbgJ0PNO (ORCPT ); Tue, 27 Oct 2020 11:13:14 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 864DE20657; Tue, 27 Oct 2020 15:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811594; bh=fw2+3HObc/6dhZY7E+lLxPRYmfiS4/B+F6GDPGTuqpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cafMEkyUQ6TG5GEGinfE6xXaCHFfeJHyMSc35zmoba/EW175fPfYaKgs2rQ8aF68S JMlHphyt5kcvgNXKwurx+4hm4dcwPUmoU+WCKbedIzWGbhpEjjJdSMliJDtYsdbS05 vMHYsaDUyzhHilFxgVoUiXuP2O1Q0C0Xv4Z97BFk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Jens Axboe , Sasha Levin Subject: [PATCH 5.8 517/633] lightnvm: fix out-of-bounds write to array devices->info[] Date: Tue, 27 Oct 2020 14:54:20 +0100 Message-Id: <20201027135547.013386193@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit a48faebe65b0db55a73b9220c3d919eee849bb79 ] There is an off-by-one array check that can lead to a out-of-bounds write to devices->info[i]. Fix this by checking by using >= rather than > for the size check. Also replace hard-coded array size limit with ARRAY_SIZE on the array. Addresses-Coverity: ("Out-of-bounds write") Fixes: cd9e9808d18f ("lightnvm: Support for Open-Channel SSDs") Signed-off-by: Colin Ian King Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/lightnvm/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index db38a68abb6c0..a6f4ca438bca1 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -1315,8 +1315,9 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg) strlcpy(info->bmname, "gennvm", sizeof(info->bmname)); i++; - if (i > 31) { - pr_err("max 31 devices can be reported.\n"); + if (i >= ARRAY_SIZE(devices->info)) { + pr_err("max %zd devices can be reported.\n", + ARRAY_SIZE(devices->info)); break; } } -- 2.25.1