Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9979801ybi; Wed, 24 Jul 2019 13:27:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvxK6KQdkC9Na883Sm6s5+etRrE212M6Srgg0o3tr4FH9x91dWes2XXI6c6LI8yoKBkDlQ X-Received: by 2002:a17:90a:9dca:: with SMTP id x10mr90152261pjv.100.1564000038263; Wed, 24 Jul 2019 13:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000038; cv=none; d=google.com; s=arc-20160816; b=FNnD9m1QFPtToMIFgx0cBkYpfOQJZYBup3g/KvKzEeo5gD39i9Fz7L7KrQJXofS9yg 13/o4PwrcuswM75Hce5N1zB+SQ4XtZ338wRzn3zdtBbX81UpwBbHabXaApiWFuSrTWNn KXz5gZHm+A0R1JzidDJlBiEhQmmOVzRVQGdGIBmijm/nLwRFSthG2N2xtP+eXmHo5gGr 7VozTQ0NX0uIxvZKy8ISrqUuixlTIzByH/uu+Qo93Lb2+6LWkx2JS8vXz/gzZei5MdbO Ce5VcHyrwzGW6PhHJSgER6Prq5K0I7aokkwhCQvQBBF4hm2MzDLLbI/zkcxeZC5seSgG H6Qg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ExmdOR0/8/73gKMXrVaZpEPRcY1pNwJdMRnT9VGUeW8=; b=EAn9pzyWnbVW4Dm96Uq7Jq18udW/zktaVe16oHqv1NVHWH6Tui2ivKb5d/GQx8JzDL rRmG9/5VZJjO/nMg6XuXPayIQJP5ulNec37G7EWUV29zHnRTLrKGJ98VHlx+vCtw7Fk7 2xsJUsqIwBdVysFmUmvGE6gN8YaTemEtG+fjC+d3B9cL/W6bWzNNVngROtJPuLCziSKP NhQgtLEukgLwbkJQPQr9SPbA/b+B2t7G3f97q082Thaowkr6qH6+fR0yM2C74AU76U/n ouoob5TE/AjQWBZXOrBOMJZF6HMOmGGWrTjjQMZxDTOVproyq9nkWnWxJdRHdStfBgcM ESSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ICG8CEUQ; 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 b92si13744667pjc.17.2019.07.24.13.27.03; Wed, 24 Jul 2019 13:27:18 -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=@kernel.org header.s=default header.b=ICG8CEUQ; 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 S2388365AbfGXUZu (ORCPT + 99 others); Wed, 24 Jul 2019 16:25:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:39176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389193AbfGXTib (ORCPT ); Wed, 24 Jul 2019 15:38:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAB9B20665; Wed, 24 Jul 2019 19:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997110; bh=x5cBvB+ePUbEneL3+6RDnFsAOd6tOD2Z+cdqbyRCV1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICG8CEUQegaYP2wpW83032ZSIWlpDUjZp4HyMZo0zPWCrUfiLbNNYm9BhV+H+HOUR +wMVTvTeJJEbC8/YLZ345On2W5q/XppQvWpb4RyXJ1EtUhsUYZdTHAEMfUZZdhHVMy S18gtYYkwO8mAdFE/yfPBFln+L5Hi40NbOh5+nt0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sakari Ailus , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 5.2 324/413] media: videobuf2-core: Prevent size alignment wrapping buffer size to 0 Date: Wed, 24 Jul 2019 21:20:15 +0200 Message-Id: <20190724191759.052586448@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sakari Ailus commit defcdc5d89ced780fb45196d539d6570ec5b1ba5 upstream. PAGE_ALIGN() may wrap the buffer size around to 0. Prevent this by checking that the aligned value is not smaller than the unaligned one. Note on backporting to stable: the file used to be under drivers/media/v4l2-core, it was moved to the current location after 4.14. Signed-off-by: Sakari Ailus Cc: stable@vger.kernel.org Reviewed-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/common/videobuf2/videobuf2-core.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -207,6 +207,10 @@ static int __vb2_buf_mem_alloc(struct vb for (plane = 0; plane < vb->num_planes; ++plane) { unsigned long size = PAGE_ALIGN(vb->planes[plane].length); + /* Did it wrap around? */ + if (size < vb->planes[plane].length) + goto free; + mem_priv = call_ptr_memop(vb, alloc, q->alloc_devs[plane] ? : q->dev, q->dma_attrs, size, q->dma_dir, q->gfp_flags);