Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1967789imm; Thu, 24 May 2018 03:45:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrftMR240rK1g+hnXE/keO3fqeOM8SNPO7lnlfuUhpsMy0x/NSJazcExeekTSsG4zw6l3CJ X-Received: by 2002:a63:89c2:: with SMTP id v185-v6mr3501232pgd.196.1527158721446; Thu, 24 May 2018 03:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158721; cv=none; d=google.com; s=arc-20160816; b=a8EEvfqlJU495nGzLofWwqvMTG+6jrKiCztvBEqGl/a5D+1Ws5qOAqnuqZJps069rO DH8RDFkDdVGbyqcg2QjwIO53/zErf653CKj8eCtm/bRaEQJf/M+1rFi1XahZvvDhbzE9 RDsOXPFRfzyKn/Kee9Kt0+y12302w+SwAJ8g11oXh5ogBKP3CnEvPR3sTh5WEhh98rt1 HftOXVnaXxV1xRHSGAiSUPg3Rmd0kAl+eU2hqAwfW8kgEDSYj7/3Rd30dCMTTuiE/SxO V5hwOX1GreazpepVrBb9dS7TWoj4wowBGCxeBcuhsgpDqJOFZuJeyOS64i/U26eLkVfB 4Kig== 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=0kanH7gnXUZiVLUzEiBdFHbYzM4MWIfCz2HEFr6cp1U=; b=LrM91Khbet1x8CeabEwotQYJTMP5PvjctVsU1tbdOVmOsZ21aFBb2xoCPSJVosTo2k TNktiY+uG4MMjECwIVxDwnP8hcukqW8jtYOIg8QWjMzgY25Et9SSM+dB65hyVo2D9xlj oAZovDDUa1yivEKHEZLtHcNe93f1aGNDq82VGS/qMNY7e5ASpkvhIE9zSXyZwpyJzMcP 6MIHBtPxYAarqHqFjNcCQs8HT7WMh4pjiCoVelMdvsK9ICBi/A9FK5rGGjNR3sm+Mq3P LgenvvDEDL1mKmjc0JrJJQJv/KhnyHDKMTCaRGdiBBMECv71zrpl2GEcVnrq4Ag4NjTF YzFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uu2TGceR; 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 a6-v6si762134plz.351.2018.05.24.03.45.06; Thu, 24 May 2018 03:45:21 -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=uu2TGceR; 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 S1032379AbeEXKoY (ORCPT + 99 others); Thu, 24 May 2018 06:44:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:37738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030545AbeEXJ6A (ORCPT ); Thu, 24 May 2018 05:58:00 -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 F360720870; Thu, 24 May 2018 09:57:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155879; bh=f8Nn0Dmcs5ZVHkuNcZs23Ss3Y2XLXcGL5K3YF0z/L8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uu2TGceRRaVI78qhyEP66klDA9F8tmoJ7/+WtB7Q4ip/a6u7Ti4nBRLlB03oENmeG tlF31Zu5ImEtlNC2IHJAxquKPNeY/RE+OLF3JsIIKR4N0J3/igQiQbDufuhmgf20oq FPAEW5NXA+J8rQj8gIQt5sfF7QEIvqN0KLIhu1fU= 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.14 149/165] media: cx25821: prevent out-of-bounds read on array card Date: Thu, 24 May 2018 11:39:15 +0200 Message-Id: <20180524093628.098045813@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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.14-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 @@ -867,6 +867,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); @@ -882,9 +886,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;