Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3314933imm; Sun, 17 Jun 2018 16:45:09 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIFmuOeJKlHn3PT5eeblvWNxFEix1NpZR1DxCgl2nvENAjHCenL7V7NbtOmdjUrKNRCEtv/ X-Received: by 2002:a17:902:b40f:: with SMTP id x15-v6mr11736431plr.270.1529279109615; Sun, 17 Jun 2018 16:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529279109; cv=none; d=google.com; s=arc-20160816; b=S5foSNIvMAkkKu5iGaY3rFU5ds+XM1E5A1omFZzUAQfcB8HjAkcrJwMtAeh1w8WCgR aSwQ/QY4xPve50n+o8JiJrss5w8jEWUPWuuXIWlrn3yAkkeUcZzify5gsbTFk8qm5Ei6 rNGFHRVfvE0LTQDC2KLmo3nIJvOAIGNtwL6cY2SfSQnBzEanwJo4LS3LHlOWKSihrXCl GCUiH5OnyM+82Q5Xbn1F0MLb2FFetRNkt3XjlGGC+ESXmwynxwN1ZQD8T+4sPK0iIsHF K9N4QSeaOg46NBde9lRryPGr0O0OXn9y9wY9xmJHc/kNzCjZgPho00dkAxlFHHZZvtbL /f0g== 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 :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=Heh5YLt+UgyiK4bi+r/joyQrE+t79A56v3sgoDGhxFg=; b=AGP10WZR5Hfmw3BM82VSeJrihbAsavirWRfkdPyXmvkubkM3NvR1SUEf2c6nV8Obsr vuaFeSfkGhpbQTGdzI7yd7whbN0LoMToQpN8etux9ZyfckJJ4qaO/DcZn/VBVTU7IPOI LXEdfa4WI9Dg3LM7s0dpfj3AlvjF7PvENSPuoW95iWZBTtC1t8u9Kro2M8akOXNIGvc9 BW/fF3IHW7F/y7sQhnTC0RAKggEZNeXnIUSFGmRQyXDQYSyIhbo1mBVUaz7gP0VaYRb0 +Z3f3XgkwDZ+yJiJVyV3v/1tiNrU+BxDtmXnDz2SJIMcWtb3sPxAL72IbBUD/Fup93La St2A== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13-v6si11425087pgn.391.2018.06.17.16.44.38; Sun, 17 Jun 2018 16:45:09 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754432AbeFQXnd (ORCPT + 99 others); Sun, 17 Jun 2018 19:43:33 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:48262 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753934AbeFQXnc (ORCPT ); Sun, 17 Jun 2018 19:43:32 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126] helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1fUhKR-0002cw-Vu; Mon, 18 Jun 2018 00:43:28 +0100 Message-ID: <1529279007.2289.246.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 246/268] media: cx25821: prevent out-of-bounds read on array card From: Ben Hutchings To: Colin Ian King , Hans Verkuil , Mauro Carvalho Chehab Cc: stable@vger.kernel.org, Sasha Levin , Greg Kroah-Hartman , LKML Date: Mon, 18 Jun 2018 00:43:27 +0100 In-Reply-To: <20180528100231.196118373@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> <20180528100231.196118373@linuxfoundation.org> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-05-28 at 12:03 +0200, Greg Kroah-Hartman wrote: > 4.4-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. I don't think this is a correct fix. The card[] array and module parameter appear to be completely redundant. Instead of arbitrarily limiting the number of cards that the driver can bind to, we should remove them. Ben. > 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; -- Ben Hutchings, Software Developer   Codethink Ltd https://www.codethink.co.uk/ Dale House, 35 Dale Street Manchester, M1 2HF, United Kingdom