Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1936139imm; Thu, 24 May 2018 03:13:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpH9VSsfcIlCCNc4jU71VWoDqMyUYKJ+XkC33Xf71ejTMtmyw8cR6Klb8CGGsWV1iJ09UgD X-Received: by 2002:a65:4bca:: with SMTP id p10-v6mr5363381pgr.114.1527156782680; Thu, 24 May 2018 03:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527156782; cv=none; d=google.com; s=arc-20160816; b=UbMShHJl/h/vzWp6BdpNHbDJwLpnubND4FVa+ebB7cEc3WlSE7XPUH4lQR8n9xhh2f N3H80+xAAEG3ET/5TBlk8NCfuVVOqb5pIlhzxQdFj4ifsNjDwvv7jqukg9PRQ3NVu6xa k6nwTg1NkajHA0BRAxu9FNexUmDFtIrPjy06mHCg9HKlJlk1PTL91vYKz1FBAxHfHAbR DRa6jdI8Zphjr5DzrifmneGuaWxzlV1Ai6viPYmezEJo1VBUdqyKrrtVOxjoHzvlWez7 zHnrrcUd00N0INKWiV1mEfFJxbDamColdDFKbn8Md5w9V7iBvf3zK48Qx8ANOnIA55/s gruw== 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=mjDpBQhHQ+Uaa08PTn8Ul14j1LCoNtuU6NRPzhfImgg=; b=Jh4YEVdxH7RLLaRRdOdveX2bDWfPkzeaF6iYAm++krFdLyaQ71c6soNgh3RTHpTRts B9J90lvGOBbq7ODFGOCMbU3p3piy7a/Tun8mM3RcwSQeQAuI2LRliqCsY1r7L7D8nTH8 KM6H/FGHp4bGjNVctB/FEj23F6M6us7cfb7RixMpgUmBUIkQkHGreFFv6HrtFIjlh0ue nyyuMfMw8exBKQRL5nCN0obts9dEIxklxzYBXAIW+IpZ4v75OAT8mYBrchFVF1kKLBDi k3/A9XHmOZekn+XRJNtJVytN88Gss2uql5Y/oHVjJQuVPJXMRZ9+EQWAxU9hoVQpTYIk Oi5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xb+B5jjt; 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 s5-v6si16468925pgo.12.2018.05.24.03.12.47; Thu, 24 May 2018 03:13:02 -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=xb+B5jjt; 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 S1031777AbeEXKLw (ORCPT + 99 others); Thu, 24 May 2018 06:11:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031545AbeEXKFT (ORCPT ); Thu, 24 May 2018 06:05:19 -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 4F31520896; Thu, 24 May 2018 10:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156318; bh=vuylTvur/bCmXfhFnx+EW2EbgYniYBKaMpahlc224FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xb+B5jjt8Bt9g7Yfcd8VedVC3P9xMIc6cohlHbGIsLjG4KEGCOjtT7B/iJ7MGAdhf Qm4KotY5JnRudh62C4mbV2iWo4Cg3ys08MUj7FRCcCrMsFa7ehw70dkc02PYYiPQUd db77OEPvQtsDKZSJ0ZpS7a6u5KG1g1dLsG5hkjrQ= 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.16 144/161] media: cx25821: prevent out-of-bounds read on array card Date: Thu, 24 May 2018 11:39:29 +0200 Message-Id: <20180524093035.621866005@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@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.16-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;