Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5064287pxb; Mon, 15 Feb 2021 08:34:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHSs2JVSdzNgrJRfDacW7lD825zf9IQIz0yHVdt5ZnYYo+fJny0IZw8yCLnuQWU/4UL9vK X-Received: by 2002:a17:906:55d5:: with SMTP id z21mr5074260ejp.248.1613406852301; Mon, 15 Feb 2021 08:34:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613406852; cv=none; d=google.com; s=arc-20160816; b=IzmhYjXsyP7eGj3hhGRtW/VfeBhd1tIWX0p47W75lW7ftlbfpICHKkAZi+qRWS4FKo mD1MYkt9+NULuQGz2Cm2ELL1E03Q8fTLOxtECZFHyWHG/1AKQZLfT3uBzhy5xn42OPmt MyXeRX6KeNpLm6S3SC6VewMWtZjMPTdGVTxzZWDw0ontglmbw3HH2u90SGlKS/wA1Sgf CtfTUYjc/gTAvbSeGTHwunvwOxEb3C0vzy4mLKn9yFmYVCTDW4rOWK/L0ck4gF6uu4tz iP6U5VGrms3xtnhRF783F64J+2BrUQKeOTPjKjUp4EiRJ/WBTC6elMOQYSvtc1rHfeLV DKNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VIKNqjwQXbaWxDyKd5aI/Qtd89WPJWKvwqlc5FvCHno=; b=Vp3pCBn0ayGT8rvUhRSus811LiY14pjuuL05HuuotWhVs8h7vblP3TaIER3ZmO60jL 8vkFIQm14fDlPoS0eY8cFAchdqzbyQxWnnQzlTfVLvTfQs227+NL7Zs1TJ/yq9yOwDq/ wmRb4Ani1tbWjI1nktIlLZGmec28lVFBKOSrN4fRQuW6veAMnIy3pXQohCKFLW2mLWAf AS2j08MhmdBvvPDOHAod/cc1GMWisBDCVcajQq8PYoDeA9Ntgk4KUmH6wepN7tF3TSaY gse4YLM7srs7itXVnEuyWEE8iIeyofsW0DToVEaeLAo1n2ZumWkyBNJiWQOWEfAqlTiD vW/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ci/q9QQc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q9si4981581eji.495.2021.02.15.08.33.48; Mon, 15 Feb 2021 08:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ci/q9QQc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbhBOQa0 (ORCPT + 99 others); Mon, 15 Feb 2021 11:30:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:49648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbhBOPhO (ORCPT ); Mon, 15 Feb 2021 10:37:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5FEFE64EE1; Mon, 15 Feb 2021 15:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403164; bh=kAABYYgnm3eDTzaiVQSmhvnBVlVRUqcHETZxpS0fzWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ci/q9QQc3mJTvW+zRj/6nfDJcmA+tN9nY4DY75pySLNPnbDC2AVLb/7/UQku6orRP tQaxhMmnj2CnDIITf9LvRBuUn+TByXD/HRJxTlkT5UmTlgH4DE9JmoDDJ0cXmiO4eS 274hfpuf8srru1qAKWp8411Os2qVhfw5Biy5Voc4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boris Brezillon , Eric Anholt , Maxime Ripard , Thomas Zimmermann , Dave Stevenson , Sasha Levin Subject: [PATCH 5.10 053/104] drm/vc4: hvs: Fix buffer overflow with the dlist handling Date: Mon, 15 Feb 2021 16:27:06 +0100 Message-Id: <20210215152721.190120902@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxime Ripard [ Upstream commit facd93f4285c405f9a91b05166147cb39e860666 ] Commit 0a038c1c29a7 ("drm/vc4: Move LBM creation out of vc4_plane_mode_set()") changed the LBM allocation logic from first allocating the LBM memory for the plane to running mode_set, adding a gap in the LBM, and then running the dlist allocation filling that gap. The gap was introduced by incrementing the dlist array index, but was never checking whether or not we were over the array length, leading eventually to memory corruptions if we ever crossed this limit. vc4_dlist_write had that logic though, and was reallocating a larger dlist array when reaching the end of the buffer. Let's share the logic between both functions. Cc: Boris Brezillon Cc: Eric Anholt Fixes: 0a038c1c29a7 ("drm/vc4: Move LBM creation out of vc4_plane_mode_set()") Signed-off-by: Maxime Ripard Acked-by: Thomas Zimmermann Reviewed-by: Dave Stevenson Link: https://patchwork.freedesktop.org/patch/msgid/20210129160647.128373-1-maxime@cerno.tech Signed-off-by: Sasha Levin --- drivers/gpu/drm/vc4/vc4_plane.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index 5612cab552270..af4b8944a6032 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -220,7 +220,7 @@ static void vc4_plane_reset(struct drm_plane *plane) __drm_atomic_helper_plane_reset(plane, &vc4_state->base); } -static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val) +static void vc4_dlist_counter_increment(struct vc4_plane_state *vc4_state) { if (vc4_state->dlist_count == vc4_state->dlist_size) { u32 new_size = max(4u, vc4_state->dlist_count * 2); @@ -235,7 +235,15 @@ static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val) vc4_state->dlist_size = new_size; } - vc4_state->dlist[vc4_state->dlist_count++] = val; + vc4_state->dlist_count++; +} + +static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val) +{ + unsigned int idx = vc4_state->dlist_count; + + vc4_dlist_counter_increment(vc4_state); + vc4_state->dlist[idx] = val; } /* Returns the scl0/scl1 field based on whether the dimensions need to @@ -978,8 +986,10 @@ static int vc4_plane_mode_set(struct drm_plane *plane, * be set when calling vc4_plane_allocate_lbm(). */ if (vc4_state->y_scaling[0] != VC4_SCALING_NONE || - vc4_state->y_scaling[1] != VC4_SCALING_NONE) - vc4_state->lbm_offset = vc4_state->dlist_count++; + vc4_state->y_scaling[1] != VC4_SCALING_NONE) { + vc4_state->lbm_offset = vc4_state->dlist_count; + vc4_dlist_counter_increment(vc4_state); + } if (num_planes > 1) { /* Emit Cb/Cr as channel 0 and Y as channel -- 2.27.0