Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77C1AC61DF4 for ; Fri, 24 Nov 2023 10:04:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 91D2910E7CF; Fri, 24 Nov 2023 10:04:43 +0000 (UTC) Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C5C610E7CF for ; Fri, 24 Nov 2023 10:04:40 +0000 (UTC) Received: from lvc-arm12.ispras.local (unknown [83.149.199.78]) by mail.ispras.ru (Postfix) with ESMTPSA id E3AB240F1DC5; Fri, 24 Nov 2023 10:04:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru E3AB240F1DC5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1700820277; bh=bv7wrxAb8THNXxecm6v9BJx9SpSabyHKXEhGbn925+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TpzycoP6tkRg1Xo+5wm2DG/F1XZvBKTIuCe6gNC6tLzDVSOd7nIq8eLFaVKDNTMiT XHLjeyW9Kf3e/w2Voyv9B2WVYULjdoUQKMU5Pt9PYGFXO+Twsmm8+09qn+c90nBAKN TU2pzUc/EM/HGrL7bPTp+ImA1hqbLMbsisw4ePp4= From: Katya Orlova To: Raphael Gallais-Pou Subject: [PATCH v2] drm/stm: Avoid use-after-free issues with crtc and plane Date: Fri, 24 Nov 2023 13:04:15 +0300 Message-Id: <20231124100415.21713-1-e.orlova@ispras.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <8ec28237-8641-4c4c-b448-824ac01f313b@foss.st.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yannick Fertre , Alexandre Torgue , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Philippe Cornu , Maxime Coquelin , Katya Orlova , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, lvc-project@linuxtesting.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" ltdc_load() calls functions drm_crtc_init_with_planes(), drm_universal_plane_init() and drm_encoder_init(). These functions should not be called with parameters allocated with devm_kzalloc() to avoid use-after-free issues [1]. Use allocations managed by the DRM framework. Found by Linux Verification Center (linuxtesting.org). [1] https://lore.kernel.org/lkml/u366i76e3qhh3ra5oxrtngjtm2u5lterkekcz6y2jkndhuxzli@diujon4h7qwb/ Signed-off-by: Katya Orlova --- v2: use allocations managed by the DRM as Raphael Gallais-Pou suggested. Also add a fix for encoder. drivers/gpu/drm/stm/drv.c | 3 +- drivers/gpu/drm/stm/ltdc.c | 68 +++++++++----------------------------- 2 files changed, 18 insertions(+), 53 deletions(-) diff --git a/drivers/gpu/drm/stm/drv.c b/drivers/gpu/drm/stm/drv.c index e8523abef27a..152bec2c0238 100644 --- a/drivers/gpu/drm/stm/drv.c +++ b/drivers/gpu/drm/stm/drv.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ltdc.h" @@ -75,7 +76,7 @@ static int drv_load(struct drm_device *ddev) DRM_DEBUG("%s\n", __func__); - ldev = devm_kzalloc(ddev->dev, sizeof(*ldev), GFP_KERNEL); + ldev = drmm_kzalloc(ddev, sizeof(*ldev), GFP_KERNEL); if (!ldev) return -ENOMEM; diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c index 5576fdae4962..02a7c8375f44 100644 --- a/drivers/gpu/drm/stm/ltdc.c +++ b/drivers/gpu/drm/stm/ltdc.c @@ -36,6 +36,7 @@ #include #include #include +#include #include