Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp666793ybl; Wed, 21 Aug 2019 03:48:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOYPtXkWkz632Nhw+/uGsLl0kXEQswIsPqLaEl4SCgUJjbrpLatcm3NpVpew4qFol4b4hL X-Received: by 2002:a62:f245:: with SMTP id y5mr35002086pfl.156.1566384536805; Wed, 21 Aug 2019 03:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566384536; cv=none; d=google.com; s=arc-20160816; b=yoel5DeuqJh6MSRElr/Os2w83V8x0KnwsIVtZTQ6cxfLya4E+WJg57gqIS7t8g9QBa 893vhVD7OAh7CjbddKxEy3lwVKeBPHxv6ZdHGw0FuHYwf6bIsPtafN6agz56ge38Tstb 73nQmWHkzB9PzR2KgW+NXrCs6kn3HAVM6nNwzGlajZby+juDcH2aWIsbnJ0PTlI+qGQ+ BaVeZnQilCbKcU8UcNJsHxaauGyhaiuYzIZ7bBR0ahahI1C5b3R2bEZYPlZb9y5NbsFq 2EflIch+4oB14evQOgE2CnJeZDZLD+yBLMOJkyhgL8MgeYSp8lA18uUKqAgkybZLa2yQ EMsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nxCanKA66UeOAwwamDYL52rHh7wdLo4UnoGNd0y/cO8=; b=YO0vZtvL8YDT/rdVnpu1Ptp3D4JJ2zr47ce2zFsZda6DC2YEhOBJUymGb8JHGHdeeU Yl+wlGPk0T8M4TyODdHKjgAyzGOyeCHj2KilObBm4eB+IaaAtiNJK6C8X0S7E1ZUh+JE ud0jli6i3OWOnFHx/9fnJek3dB4+IpmEKEncvsO0PLvM2nrBYlKvCX5poPPK2ZRWOcmQ 1JnTamATWHF6AyFabVrUC7CicpCPAgh5RzuIYkbXOfCRESr0Wa94efYEtRyFeBxdEFed VEM8c3hV26drTlgZ/s39VbcCCGwxHd51Y7VZ4YoRKSThyua6K722QXNxMbem8FBMozr0 YRjw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si14208666plj.194.2019.08.21.03.48.42; Wed, 21 Aug 2019 03:48:56 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728482AbfHUKoM (ORCPT + 99 others); Wed, 21 Aug 2019 06:44:12 -0400 Received: from gofer.mess.org ([88.97.38.141]:56295 "EHLO gofer.mess.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbfHUKoL (ORCPT ); Wed, 21 Aug 2019 06:44:11 -0400 Received: by gofer.mess.org (Postfix, from userid 1000) id CE6D660628; Wed, 21 Aug 2019 11:44:08 +0100 (BST) Date: Wed, 21 Aug 2019 11:44:08 +0100 From: Sean Young To: Hui Peng Cc: security@kernel.org, Mathias Payer , Mauro Carvalho Chehab , Hans Verkuil , Kees Cook , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Fix an OOB access bug in technisat_usb2_get_ir Message-ID: <20190821104408.w7krumcglxo6fz5q@gofer.mess.org> References: <20190820181921.7921-1-benquike@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190820181921.7921-1-benquike@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 20, 2019 at 02:19:16PM -0400, Hui Peng wrote: > In the while loop of technisat_usb2_get_ir, it scans through > a fix-sized buffer read from the device side, the termination > condition of the loop is `*b == 0xff`. If no `0xff` byte is read > from the device side, OOB access happens. > > This patch fixes the bug by adding an upper bound in the while loop. This issue was fixed in: https://git.linuxtv.org/media_tree.git/commit/drivers/media/usb/dvb-usb/technisat-usb2.c?id=0c4df39e504bf925ab666132ac3c98d6cbbe380b Note this limits the loop to the size of the buffer; using the ret return value might be better. Sean > > Reported-by: Hui Peng > Reported-by: Mathias Payer > Signed-off-by: Hui Peng > --- > drivers/media/usb/dvb-usb/technisat-usb2.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c > index c659e18b358b..181f5f97af45 100644 > --- a/drivers/media/usb/dvb-usb/technisat-usb2.c > +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c > @@ -612,6 +612,7 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d) > u8 *b; > int ret; > struct ir_raw_event ev; > + int i = 0; > > buf[0] = GET_IR_DATA_VENDOR_REQUEST; > buf[1] = 0x08; > @@ -656,11 +657,15 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d) > > ev.pulse = 0; > while (1) { > + // only `ret` bytes are read from the device side > + if (i >= ret) > + break; > ev.pulse = !ev.pulse; > ev.duration = (*b * FIRMWARE_CLOCK_DIVISOR * FIRMWARE_CLOCK_TICK) / 1000; > ir_raw_event_store(d->rc_dev, &ev); > > b++; > + i++; > if (*b == 0xff) { > ev.pulse = 0; > ev.duration = 888888*2; > -- > 2.23.0