Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp220694ybi; Tue, 2 Jul 2019 19:27:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzq6GIBVLZ1QqJ+uOVGpevI3c2qz2vvzHUoXTjDmHwi8uo4NjbxJ/l6VVZ+aXMRP1dBXqzZ X-Received: by 2002:a17:90a:db44:: with SMTP id u4mr9267468pjx.52.1562120831246; Tue, 02 Jul 2019 19:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562120831; cv=none; d=google.com; s=arc-20160816; b=d3GgHjnUh6WiKGckk1TSedj+NprFsvLs/fBfEMnpsIRPQslreCszDu9tW7JRoDX825 E1WqyDtK1to8utwBEx5sXPzigG7Gh2G7Adwqn5ekVtRnJAuMMm0b2+jAgswZLqYzp7hf JxGg90IDJ1Ta5CWu8BP9tg0ZGU/KbeF4UMqJ6ouVNRmD9qGETdmlRdLSDu8ZCNTbv2XD l5FLtkx2s9nalT8o5j2imrV+SutvfOc1EGh5SfWC8l1HJQ74Xl2QBLzkyo6zqO2U9IKr a+VXEQUBy3My08dBGPs2XzDH8ERW0uFhi3oa+zQieRl9HcwHDlrkNNgCuLSWyVg0bNLb RPrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9LSa6wcOyCAEFmmrefvYQyX7fTvyeHlG+veSDCcI4eE=; b=y15cFOxXZ9YIAKf91y7fSsDzzXkaR1pk5JgTEWCz2mLtLaHg+pjXA18NnLKulhXx/K qXrEZSSh39MxnGxP3a6Dy3zmwpS0sU4jwUGjpqVMT9jPYJd/+zNdF5H9LjaBVFrINx5e UUSm/m8fKYZ4hG8Uw2siWEkzPkCkXXmy2Rd9Ihezq6xNdeBBVRKGzb73U4+UbaBJ5EN+ ZLqourahKLv0/2x+2Xxw93sinJUOPRUJZSkMyRWXhlX9kYgit3Bss6mJw036na1IISH2 F3hr+4eSjMJwYlOLODXfg39dSD2OtXei0LKggfTK1JOnqI1fVO5KpcBjpxUOnZGDvyRq jmsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZGzQGMEI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12si610761plo.68.2019.07.02.19.26.55; Tue, 02 Jul 2019 19:27:11 -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=@chromium.org header.s=google header.b=ZGzQGMEI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727479AbfGCC0f (ORCPT + 99 others); Tue, 2 Jul 2019 22:26:35 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39132 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727220AbfGCC0e (ORCPT ); Tue, 2 Jul 2019 22:26:34 -0400 Received: by mail-pf1-f194.google.com with SMTP id j2so406208pfe.6 for ; Tue, 02 Jul 2019 19:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9LSa6wcOyCAEFmmrefvYQyX7fTvyeHlG+veSDCcI4eE=; b=ZGzQGMEI0xBc+6ht3TyJxLoqzKZvxKS3cyCqFs5aNkK82JwWf02bh1UI6nY7VvlV1d uxCEdDgsuN+DEyiHLBmniA2W8TDStSwHNgznxmpeHL6R2gayEYEOJNRFT2roT+TZEonK aegVewSeCatWM1lQmM9X0xcytloRWyF8MrjaU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9LSa6wcOyCAEFmmrefvYQyX7fTvyeHlG+veSDCcI4eE=; b=lbX7zghtwIEzMVJO0RqA2/zC6VNkhKkRRbTlpzTa8RqX0LrQzk+RUdKVHJEqpuf1J+ u0IF5NWJWLmd1G26rWpWmvmELI1BAX9LugwYI4N4NoDZR1tkqMJeW9I24ElWPTM5fGVD j2LIEn1I/fFB8qArP1e0nx+SVkB4A5Q3tNDbU7VmnuwFMBq4KjhrzpdqqUs4xniTSRbZ PyLRtqzsOrB0urc6k/b2ZI9ZePZpfwHYeSySqHWxfu19HzyVrbi+DIf6kfOIcr5pm7kc 9OxNOT4BT7QMHmC9I+B20SVvaINwsJuaaZx8mYFgWUn4n/0ZWZdkA06AtJAJhe3a4dxP SZgQ== X-Gm-Message-State: APjAAAXAgsfigf9dgkuzAvHcB7GZDcAeeX2+EIWCarlUzg1p9lPFZ+iJ Hwl3JhTkTmpDn0QffzEEjoPy9A== X-Received: by 2002:a63:d756:: with SMTP id w22mr33125752pgi.156.1562120794171; Tue, 02 Jul 2019 19:26:34 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y133sm404949pfb.28.2019.07.02.19.26.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2019 19:26:33 -0700 (PDT) Date: Tue, 2 Jul 2019 19:26:32 -0700 From: Kees Cook To: Phong Tran Cc: andreyknvl@google.com, gregkh@linuxfoundation.org, hans.verkuil@cisco.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-usb@vger.kernel.org, mchehab@kernel.org, skhan@linuxfoundation.org, syzbot+eaaaf38a95427be88f4b@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, glider@google.com Subject: Re: [PATCH V2] media: usb: technisat-usb2: fix buffer overflow Message-ID: <201907021925.1F24D6ADA3@keescook> References: <20190702140211.28399-1-tranmanphong@gmail.com> <20190703021444.19954-1-tranmanphong@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190703021444.19954-1-tranmanphong@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 03, 2019 at 09:14:44AM +0700, Phong Tran wrote: > The buffer will be overflow in case of the while loop can not break. > Add the checking buffer condition in while loop for avoiding > overlooping index. > > This issue was reported by syzbot > > Reported-by: syzbot+eaaaf38a95427be88f4b@syzkaller.appspotmail.com > > Tested-by: > https://groups.google.com/d/msg/syzkaller-bugs/CySBCKuUOOs/t3PvVheSAAAJ > Avoid these blank lines please. (More below...) > Signed-off-by: Phong Tran > --- > Change Log: > * V2: add IR_MAX_BUFFER_INDEX and adjust the while loop condition as comments > --- > drivers/media/usb/dvb-usb/technisat-usb2.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c > index c659e18b358b..cdabff97c1ea 100644 > --- a/drivers/media/usb/dvb-usb/technisat-usb2.c > +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c > @@ -49,6 +49,7 @@ MODULE_PARM_DESC(disable_led_control, > "disable LED control of the device (default: 0 - LED control is active)."); > > /* device private data */ > +#define IR_MAX_BUFFER_INDEX 63 How does this map to the literal "62" used before the loop you're fixing? Otherwise, it's looking good; thanks! -Kees > struct technisat_usb2_state { > struct dvb_usb_device *dev; > struct delayed_work green_led_work; > @@ -56,7 +57,7 @@ struct technisat_usb2_state { > > u16 last_scan_code; > > - u8 buf[64]; > + u8 buf[IR_MAX_BUFFER_INDEX + 1]; > }; > > /* debug print helpers */ > @@ -655,7 +656,7 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d) > #endif > > ev.pulse = 0; > - while (1) { > + while (b <= (buf + IR_MAX_BUFFER_INDEX)) { > ev.pulse = !ev.pulse; > ev.duration = (*b * FIRMWARE_CLOCK_DIVISOR * FIRMWARE_CLOCK_TICK) / 1000; > ir_raw_event_store(d->rc_dev, &ev); > -- > 2.11.0 > -- Kees Cook