Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2391901lqp; Sun, 24 Mar 2024 17:24:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjVzE6YeiUQqg+h2lpCRN+tPTIKFrUGFDU+TGTI0Zge5UTmP3XNNNoatVy9h7lrv2Zlpi1osu5Wn2k+qOxiLvKylCWMhKjjNl504w/+A== X-Google-Smtp-Source: AGHT+IGg2DWFI/EWrijyx4n1rGJOZQuGoLJrOkqmN0jNiIIAHJy3MCX6+m7Ei4HByUN2pdIOjy8k X-Received: by 2002:a05:6a20:2d21:b0:1a3:15e8:7e93 with SMTP id g33-20020a056a202d2100b001a315e87e93mr8009734pzl.56.1711326286571; Sun, 24 Mar 2024 17:24:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711326286; cv=pass; d=google.com; s=arc-20160816; b=LKDVSBHzcB3kbxghO0JdeAgcufkwkXMMUZ4IXRUFZ5d2arAstZnn8NhIZk5CImBx4D zD8HmEZp31CoBeKp2zEW58dxLhsorQt8fSLsFtxfKm3oF3IN1XZYq6DO3Vy+L5IwX8f/ FS0eySNRynRp6fZAKpg9OB/ZZlYYlR/Lza9NjaQq87ijNB5eSnffkAeIX5Y0xlZCFI56 5rdOAnbFN+UZEsTxRm0g3gibKS9ONEaUkJJ8R+gfIxusc0UfChcS4Ke5yS40/4fM6jEC /kVgG5y0bVLSk/wvEDLgQtYzDpk3qAfQ2h0CXEWHP5KmVmYqsTbxdqUC7PpChsJhVcil RLcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7dcDFYtMvNiuBSq7sMCa1uK7btef6K0TaIqihmlthXo=; fh=BYpP1RdanclFHaNCEDOMKURGGFZKAe7EK7n2cTd3LzU=; b=hkp2LqAlCckRE7Lk3S0c4O4b9hzRnAXJJNjoDHdv32JFxfE7tQ1wXQk5w7EKDXh22O aZrSmIQyEkENWx1nWN6lRnmezE1w2Yi5YphbV7Z87dJcbaeCMEaxJvGvrNHKmifXupOR OUquSh9ijervJvUsxP9+PUe83xgAy8YnRNnt2Tzhft92aNTWbW5RvjyPB9YkLumrKL0Q OUvpQuvtSB6bnDo6eftyQ/OAh8k40MdU7/QIJtBwWRgt6pcEjcUaQojRUOcXUfsBPUew NFLmPV9tlvuENpcTRZCWE/KUpGIW5B2fF6n44yG7aeJrcaOHhQGha4FVUYC0W702dEFR RZfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Dbq/uSZA"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113389-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w91-20020a17090a6be400b0029bae87c729si10383707pjj.85.2024.03.24.17.24.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:24:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113389-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Dbq/uSZA"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113389-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3D6D328346F for ; Mon, 25 Mar 2024 00:24:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D42211A212A; Sun, 24 Mar 2024 22:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dbq/uSZA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E71291A1A79; Sun, 24 Mar 2024 22:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320191; cv=none; b=Ed3rYTL9EL4414GXK8xvixeSMQ04PPZ+F+1OITMt8M/9gKzVC4fMlAbojDG5noLe+xHXvTiVyBNtPDsKAqoIze2nXwhn+1gJOtmhulK23OhakPi/SlvVzBdqPhbCZFBgQXzmOExIqAkSQsWACHSV9TrsMiUE26Nks4uE4CcY7bY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320191; c=relaxed/simple; bh=U3bsBoW5R9uLm8pCwqeekjmg/fPe++eB4CD1hfRCU+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jzqwdNSEPXAENCiEXDLKLRcU5MuvOBRWko0jDPulx9VyMsKD+oDKLIcqsV1gzLJfu+/KHw6nsofUJX1GZovCw24/aTWTtn+QWiZ97FY7iMZhES2OpRjIlDZa9s70+pW0TknPNIlNTycMzqu1EkP8oqNE4s6uvlOlPV7Ak6jsUiQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dbq/uSZA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A4F0C433B2; Sun, 24 Mar 2024 22:43:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320190; bh=U3bsBoW5R9uLm8pCwqeekjmg/fPe++eB4CD1hfRCU+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dbq/uSZABuahqWdAvBzJrOEZCzFi+FVqkQrPFqSg+uPR9l0juWmTETeKq8vi5/wIc x76tEZcZYVBq5u4VuMupN7w8AOs57S4gegrnEhdPpDilqE51c9+QsmwKkTx4X3ZLUb G9Qjvxiv4uhhznDtkUOlodV/WRLy+ZIMVt2DJZT5ISafUgrD7fejV7u2yAF0FGsDLb SW357jzEnYKEnCX+KG/em4yzM17TBARPJXj6Yxg1LQkzp4yxuTrM6b+AFCW3lNu/hz OFvABkIoLEnsW2s/MqCkjCo9TyQBVZpPqILQnat8lKxGn3wlxnA0ddc+fYW8z5/sLw 9EzGQj8BaTlqw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hsin-Yi Wang , CK Hu , Chun-Kuang Hu , Sasha Levin Subject: [PATCH 6.8 498/715] drm/mediatek: Fix a null pointer crash in mtk_drm_crtc_finish_page_flip Date: Sun, 24 Mar 2024 18:31:17 -0400 Message-ID: <20240324223455.1342824-499-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Hsin-Yi Wang [ Upstream commit c958e86e9cc1b48cac004a6e245154dfba8e163b ] It's possible that mtk_crtc->event is NULL in mtk_drm_crtc_finish_page_flip(). pending_needs_vblank value is set by mtk_crtc->event, but in mtk_drm_crtc_atomic_flush(), it's is not guarded by the same lock in mtk_drm_finish_page_flip(), thus a race condition happens. Consider the following case: CPU1 CPU2 step 1: mtk_drm_crtc_atomic_begin() mtk_crtc->event is not null, step 1: mtk_drm_crtc_atomic_flush: mtk_drm_crtc_update_config( !!mtk_crtc->event) step 2: mtk_crtc_ddp_irq -> mtk_drm_finish_page_flip: lock mtk_crtc->event set to null, pending_needs_vblank set to false unlock pending_needs_vblank set to true, step 2: mtk_crtc_ddp_irq -> mtk_drm_finish_page_flip called again, pending_needs_vblank is still true //null pointer Instead of guarding the entire mtk_drm_crtc_atomic_flush(), it's more efficient to just check if mtk_crtc->event is null before use. Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") Signed-off-by: Hsin-Yi Wang Reviewed-by: CK Hu Link: https://patchwork.kernel.org/project/dri-devel/patch/20240223212404.3709690-1-hsinyi@chromium.org/ Signed-off-by: Chun-Kuang Hu Signed-off-by: Sasha Levin --- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c index c729af3b98224..3d17de34d72bd 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -95,11 +95,13 @@ static void mtk_drm_crtc_finish_page_flip(struct mtk_drm_crtc *mtk_crtc) struct drm_crtc *crtc = &mtk_crtc->base; unsigned long flags; - spin_lock_irqsave(&crtc->dev->event_lock, flags); - drm_crtc_send_vblank_event(crtc, mtk_crtc->event); - drm_crtc_vblank_put(crtc); - mtk_crtc->event = NULL; - spin_unlock_irqrestore(&crtc->dev->event_lock, flags); + if (mtk_crtc->event) { + spin_lock_irqsave(&crtc->dev->event_lock, flags); + drm_crtc_send_vblank_event(crtc, mtk_crtc->event); + drm_crtc_vblank_put(crtc); + mtk_crtc->event = NULL; + spin_unlock_irqrestore(&crtc->dev->event_lock, flags); + } } static void mtk_drm_finish_page_flip(struct mtk_drm_crtc *mtk_crtc) -- 2.43.0