From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D20CC433E0 for ; Wed, 10 Mar 2021 08:13:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43A5A64FCE for ; Wed, 10 Mar 2021 08:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbhCJINf (ORCPT ); Wed, 10 Mar 2021 03:13:35 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:59210 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbhCJIM4 (ORCPT ); Wed, 10 Mar 2021 03:12:56 -0500 Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A9743F3; Wed, 10 Mar 2021 09:12:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615363974; bh=p4o+P+DQ74y4yqjC73QioWWOWOlWjgSrnbi5iNTpD28=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TpnC23MxTmNMaLkZ3tij641VlgTTGnCgUNjbOiCc7L+sNkIAPGVxUwhGTFkIdyN8Q Rw0Dow8jOSx0h9HL3nSrHhnF1a/AGlvn4plGxD+9n0tj6htyFIQQktnOy1GcfTj9zV vTEwR7Ezm/GZKPYRYr+SidWcBQ5ATtOSmVkhPPZ4= Date: Wed, 10 Mar 2021 10:12:22 +0200 From: Laurent Pinchart To: Ricardo Ribalda Cc: Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Linux Media Mailing List , Linux Kernel Mailing List , stable@vger.kernel.org Subject: Re: [PATCH] media: videobuf2: Fix integer overrun in allocation Message-ID: References: <20210309234317.1021588-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ricardo, On Wed, Mar 10, 2021 at 08:58:39AM +0100, Ricardo Ribalda wrote: > On Wed, Mar 10, 2021 at 8:49 AM Laurent Pinchart wrote: > > On Wed, Mar 10, 2021 at 12:43:17AM +0100, Ricardo Ribalda wrote: > > > The plane_length is an unsigned integer. So, if we have a size of > > > 0xffffffff bytes we incorrectly allocate 0 bytes instead of 1 << 32. > > > > > > Cc: stable@vger.kernel.org > > > Fixes: 7f8414594e47 ("[media] media: videobuf2: fix the length check for mmap") > > > Signed-off-by: Ricardo Ribalda > > > --- > > > drivers/media/common/videobuf2/videobuf2-core.c | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > > > index 02281d13505f..543da515c761 100644 > > > --- a/drivers/media/common/videobuf2/videobuf2-core.c > > > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > > > @@ -223,8 +223,10 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) > > > * NOTE: mmapped areas should be page aligned > > > */ > > > for (plane = 0; plane < vb->num_planes; ++plane) { > > > + unsigned long size = vb->planes[plane].length; > > > > unsigned long is still 32-bit on 32-bit platforms. > > > > > + > > > /* Memops alloc requires size to be page aligned. */ > > > - unsigned long size = PAGE_ALIGN(vb->planes[plane].length); > > > + size = PAGE_ALIGN(size); > > > > > > /* Did it wrap around? */ > > > if (size < vb->planes[plane].length) > > > > Doesn't this address the issue already ? > > Yes and no. If you need to allocate 0xffffffff you are still affected > by the underrun. The core will return an error instead of doing the > allocation. > > (yes, I know it is a lot of memory for a buffer) That's my point, I don't think there's a need for this :-) Especially with v4l2_buffer.m.offset being a __u32, we are limited to 4GB for *all* buffers. -- Regards, Laurent Pinchart