Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2015650imm; Thu, 24 May 2018 04:33:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr9bUPUOGbnGRGQBCdpVU64vV3nNqO8KOAFiTJqUd4gmaPl0iTjp8P5A8kMFQspLYjlbTne X-Received: by 2002:a17:902:76c4:: with SMTP id j4-v6mr7073173plt.257.1527161610873; Thu, 24 May 2018 04:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161610; cv=none; d=google.com; s=arc-20160816; b=svTHCsmurTzA7+PQ0En80lgPZW58Tj9ICRmwCp1sU8lzJcUBg8PYpcE/fDTNnbKt8l X0jJFengK+WMv2FFTVk/0vfOQYa6Cdd2nSAR7XzhmLmCEXC7OeCuXsjslTDhSd8Q8H/S AI4LzkR6Mimyc4SER5YaJU42AqoBCagXshDKmcs8/s0E9LmOYqCTTiFtUOTOqDR4qm97 H9OYQDNxVXQXwRv5ojyjbPZAVUt3V8qMlHUAkiBVOOmhfZ1FQq6cYEFUsuaBmRtKP55x aZrI5ILQIFqoz0KyZ8LsJU+SQJgUKMbAbkNRJvNkvYY4IBwuFmoxgA1Fxcr/gi4g30AE eUtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=7j/5KEyQTClOIUn0z7mAtOq3b1Dn5Ef6a6MWtnt+jIQ=; b=E+IhAhIwf1OUUmZ4vzTdiO/eNvXjYSs/TYiv6CLBCiq/NyuWVkP1chgYJfV/gxnbHQ /obkb93JBZPk95ZVm2Kj337AOpE3/XsZ5M9sGSBHH434goH2cktFvlo+E4mi+QjoKpdG DE1vPEWUN9K+/4J3yHmd+swrCmu8NhL26nwAKwWVf8BQOUIl4CPo4KOllqscjCENt4oS iAgwdBa+e/62Rs4IZTILw15G0kITP6hEip3X+anIzPtjJMDV2IQ79P/y6p8l5APW2mzh dovERyR/GbBqyqdhrv/WYJeVkI/2KQVIpEMXfskdj5k3YGOSH0ScImTuZvlhZjgsSoo1 Q7CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d5S4IuA5; 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 v63-v6si812146pgd.82.2018.05.24.04.33.16; Thu, 24 May 2018 04:33:30 -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=d5S4IuA5; 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 S969006AbeEXLcm (ORCPT + 99 others); Thu, 24 May 2018 07:32:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967553AbeEXJul (ORCPT ); Thu, 24 May 2018 05:50:41 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 0AF96208AE; Thu, 24 May 2018 09:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155440; bh=lHwGFal4/PWHVw6MVeFrrM2xDMlD47H6bwAi4f7US/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5S4IuA5hieFTjf1+NhRXc++rG9klqnj+JGxVruzTR5QW+HaYi4JRcZ+MKmNBgH5N Z2NYtynhPQNWZzLJzshLEaWZJudjUuD/jMpZXfWBAWVp/1WGw0xaStv4m6YcwLdCwU ELD+QZIvDh1M4qgarBvy2AOesR52AiLhyYLWxhEI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 86/96] media: cx25821: prevent out-of-bounds read on array card Date: Thu, 24 May 2018 11:39:09 +0200 Message-Id: <20180524093610.326542751@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King [ Upstream commit 67300abdbe9f1717532aaf4e037222762716d0f6 ] Currently an out of range dev->nr is detected by just reporting the issue and later on an out-of-bounds read on array card occurs because of this. Fix this by checking the upper range of dev->nr with the size of array card (removes the hard coded size), move this check earlier and also exit with the error -ENOSYS to avoid the later out-of-bounds array read. Detected by CoverityScan, CID#711191 ("Out-of-bounds-read") Fixes: commit 02b20b0b4cde ("V4L/DVB (12730): Add conexant cx25821 driver") Signed-off-by: Colin Ian King Signed-off-by: Hans Verkuil [hans.verkuil@cisco.com: %ld -> %zd] Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/pci/cx25821/cx25821-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/media/pci/cx25821/cx25821-core.c +++ b/drivers/media/pci/cx25821/cx25821-core.c @@ -871,6 +871,10 @@ static int cx25821_dev_setup(struct cx25 dev->nr = ++cx25821_devcount; sprintf(dev->name, "cx25821[%d]", dev->nr); + if (dev->nr >= ARRAY_SIZE(card)) { + CX25821_INFO("dev->nr >= %zd", ARRAY_SIZE(card)); + return -ENODEV; + } if (dev->pci->device != 0x8210) { pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n", __func__, dev->pci->device); @@ -886,9 +890,6 @@ static int cx25821_dev_setup(struct cx25 dev->channels[i].sram_channels = &cx25821_sram_channels[i]; } - if (dev->nr > 1) - CX25821_INFO("dev->nr > 1!"); - /* board config */ dev->board = 1; /* card[dev->nr]; */ dev->_max_num_decoders = MAX_DECODERS;