Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1677037

Re: [media] uvcvideo: Prevent heap overflow in uvc driver

Path csiph.com!weretis.net!feeder4.news.weretis.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Newsgroups linux.kernel
Subject Re: [media] uvcvideo: Prevent heap overflow in uvc driver
Date Wed, 28 Jun 2017 20:20:03 +0200
Message-ID <tXpJh-Rv-29@gated-at.bofh.it> (permalink)
References <tK1v3-1nY-9@gated-at.bofh.it> <tXmil-7Xs-5@gated-at.bofh.it> <tXpq5-t5-213@gated-at.bofh.it>
X-Original-To Guenter Roeck <linux@roeck-us.net>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1498673904; bh=OMyGne8LEiw94K2rLtSyI8Cubu+UaSjqvys1VSR+RjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X5sEkee1jXaiyZFfigtXh1XgleQIXa9U6g2QYACcevSLf1pnF+XtyEVQVS8fpwGWK U8TPDbiKwHCiVrKyNfgb9jAQhKDXH8tj4hcOxM/uO8wCjKPXaEoJYHuuSUV0GfbmKH EtCNFnd0jQP2/Q5nQqQMpsksoKH4e8n99pJ0eQYY=
User-Agent KMail/4.14.10 (Linux/4.9.16-gentoo; KDE/4.14.32; x86_64; ; )
MIME-Version 1.0
Content-Transfer-Encoding 7Bit
Content-Type text/plain; charset="us-ascii"
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 64
Organization linux.* mail to news gateway
X-Original-Cc Mauro Carvalho Chehab <mchehab@kernel.org>, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Robb Glasser <rglasser@google.com>
X-Original-Date Wed, 28 Jun 2017 21:18:37 +0300
X-Original-Message-ID <1612560.vxfrDdQTFq@avalon>
X-Original-References <1495482484-32125-1-git-send-email-linux@roeck-us.net> <20170628143643.GA30654@roeck-us.net> <1797631.lsAEjhpLaU@avalon>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1677037

Show key headers only | View raw


Hi Guenter,

On Wednesday 28 Jun 2017 20:59:17 Laurent Pinchart wrote:
> On Wednesday 28 Jun 2017 07:36:43 Guenter Roeck wrote:
> > On Mon, May 22, 2017 at 12:48:04PM -0700, Guenter Roeck wrote:
> >> From: Robb Glasser <rglasser@google.com>
> >> 
> >> The size of uvc_control_mapping is user controlled leading to a
> >> potential heap overflow in the uvc driver. This adds a check to verify
> >> the user provided size fits within the bounds of the defined buffer
> >> size.
> >> 
> >> Signed-off-by: Robb Glasser <rglasser@google.com>
> >> [groeck: cherry picked from
> >> 
> >>  https://source.codeaurora.org/quic/la/kernel/msm-3.10
> >>  commit b7b99e55bc7770187913ed092990852ea52d7892;
> >>  updated subject]
> >> 
> >> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> >> ---
> >> Fixes CVE-2017-0627.
> > 
> > Please do not apply this patch. It is buggy.
> 
> I apologize for not noticing the initial patch, even if it looks like it was
> all for the best. Will you send a new version ?
> 
> >>  drivers/media/usb/uvc/uvc_ctrl.c | 3 +++
> >>  1 file changed, 3 insertions(+)
> >> 
> >> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c
> >> b/drivers/media/usb/uvc/uvc_ctrl.c index c2ee6e39fd0c..252ab991396f
> >> 100644
> >> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> >> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> >> @@ -1992,6 +1992,9 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain
> >> *chain,
> >>  	if (!found)
> >>  		return -ENOENT;
> >> 
> >> +	if (ctrl->info.size < mapping->size)
> >> +		return -EINVAL;
> >> +

By the way, I believe the right fix should be

	if (mapping->offset + mapping->size > ctrl->info.size * 8)
		return -EINVAL;

Both mapping->offset and mapping->size are 8-bit integers, so there's no risk 
of overflow in the addition. If we want to safeguard against a possible future 
bug if the type of the fields change, we could add

	if (mapping->offset + mapping->size < mapping->offset)
		return -EINVAL;

> >>  	if (mutex_lock_interruptible(&chain->ctrl_mutex))
> >>  		return -ERESTARTSYS;

-- 
Regards,

Laurent Pinchart

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [media] uvcvideo: Prevent heap overflow in uvc driver Guenter Roeck <linux@roeck-us.net> - 2017-06-28 16:40 +0200
  Re: [media] uvcvideo: Prevent heap overflow in uvc driver Laurent Pinchart <laurent.pinchart@ideasonboard.com> - 2017-06-28 20:00 +0200
    Re: [media] uvcvideo: Prevent heap overflow in uvc driver Laurent Pinchart <laurent.pinchart@ideasonboard.com> - 2017-06-28 20:20 +0200
      Re: [media] uvcvideo: Prevent heap overflow in uvc driver Guenter Roeck <linux@roeck-us.net> - 2017-06-28 22:30 +0200

csiph-web