From patchwork Tue Mar 9 23:43:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 396366 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 781D8C433DB for ; Tue, 9 Mar 2021 23:44:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46356650ED for ; Tue, 9 Mar 2021 23:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232115AbhCIXnu (ORCPT ); Tue, 9 Mar 2021 18:43:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232142AbhCIXnV (ORCPT ); Tue, 9 Mar 2021 18:43:21 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEA44C06175F for ; Tue, 9 Mar 2021 15:43:20 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id r17so33013348ejy.13 for ; Tue, 09 Mar 2021 15:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GsAE9rQ8/byOnL6RFD2LPTinVX5mQV+JCW61mQ0cTTQ=; b=ZktZICeZisdyBYhDRK6hJaM2gK5izAhJYXPmRLFGGqbadL1p3Lbdg4C2xqkGURAjQu bnm1Tg5faQWiTWF2WIyIkwJa1dP14JR1okSqTnYtFfydplxVIPwegxj8qfPD1Ue7PusI qdCVBswJlzCU362pnVirE0gUcQC1BeGobl3tI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GsAE9rQ8/byOnL6RFD2LPTinVX5mQV+JCW61mQ0cTTQ=; b=o7ii/t5xvOrI3mwj+tFnusrU2yMz2ABH2WMHKrPQGHt/vWVJvJAYLTvd6BTkIXpVAb bZKJwloohI9zQ4k8Cr0Vfh2Q/vd8m/uDhLS+vT7ZgQ0QdqnMZREqmTtMr/MC7pYxpF3b YLxAqcsut6AmuzPGxqOk+E+R+sfqHPKfJmlBPX3hb0VG8qGMRptq84fJLWRg9jmzBO9m DeBSq9EftHrSdaTMT6gLhyr+npNww/Afs2Pc8Qn9ku+J7rIb3KL3W4BJE/v0VuhsiLhB KyLDZdChJENAXyAfsZbJ0+oIAvpNarFiuIHniYplCh62kA1sf7KzXNjHLv6z1NGJl+8V ASPg== X-Gm-Message-State: AOAM532lGUBfyB49dOGdSBxEUNik3hBVSYKzRRe95Cwn8k1FpL8jHkxG fzTgiEOCikga5zeM91Q0bgJZiw== X-Google-Smtp-Source: ABdhPJxjhykxqKvpWvYUp6HbNeUMu65+sh2gFhOT0+/grLA8X/Ed9CYt6FwWNfjpo2XCj+H3e1jPjA== X-Received: by 2002:a17:907:7692:: with SMTP id jv18mr510464ejc.475.1615333399461; Tue, 09 Mar 2021 15:43:19 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id l1sm5187658edt.59.2021.03.09.15.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 15:43:19 -0800 (PST) From: Ricardo Ribalda To: Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Laurent Pinchart Cc: Ricardo Ribalda , stable@vger.kernel.org Subject: [PATCH] media: videobuf2: Fix integer overrun in allocation Date: Wed, 10 Mar 2021 00:43:17 +0100 Message-Id: <20210309234317.1021588-1-ribalda@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Reviewed-by: Sergey Senozhatsky --- 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; + /* 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)