Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp603844rdb; Thu, 22 Feb 2024 13:29:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqgPYwjo44VAYaeA4lECssdvd+YFYc2OqT5hmMXRBCZiwD9OmnlKyd1+TV8MrdUxdRAtBDKljZ3qC3YG9G8norKNVuLZYjfhb9OyVsEA== X-Google-Smtp-Source: AGHT+IHGDTZuhB4pBPtxiQthTB/T1MqYdOoaSoUBjNjCmI+Ing8jdzk8lEWwjzP8Atg1N5tnJDHz X-Received: by 2002:a05:6a20:9006:b0:1a0:d0ef:c652 with SMTP id d6-20020a056a20900600b001a0d0efc652mr71397pzc.29.1708637355619; Thu, 22 Feb 2024 13:29:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708637355; cv=pass; d=google.com; s=arc-20160816; b=Uz/1XbLq5Kk0CmCxKeTGaST0XXqnm+2CdZw0O78QdJJnp7hPoJxVeWp4nGw1pe40fv BGT8x1zau/3tjuhEZBRjG4K8NRf/K8OjetbRly7eVI+Iryna61olVqzS7K+QWOod22Rz GQqF4mjNIJvC19HnfRrO84FQc8oaakj9fAky2fRi0d1TqKQYMl79fYnp8MFsfmQqLZ/Y puEm0P5YZHxHOJ+a7LI4pXP0HVTcRhEPKJSlMsqPiAzP5UVsACSZHpch5+XZy7R+mKZn QU7GhuXrzTpo61q6KEQRuEb8ZtsGNSDclsFEcufp2cLkpB77LZdTXKbADw++XmxSIs0l 7ufA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=KISjjhinzIu3kIcQRpPQsw9fHAQrHUvQiIbfDFbxHeA=; fh=tR5cTKxwkTFCn8evc9uAulI0jDcn7ywRasH1+G//PDk=; b=CRqMsbEvHjllpM2a/OTc3fkgv+jblznHwtPQEcV67tEm86BHGyiVcBLI7YWwcekVRS mQBfLI0YP2XDuDCmFnG1KnpvkWvyOTEyJEh9hH2nv4sSEOujEpi6UdPjkfwRWw4obb48 v7L0H90Xeu2so2NXlomf39V7m5Y5O9bna0Rpan+3bF1aVpGx2NpptlGmkAGzxDN7ScxJ FwqmYl7xzNMfZkkHmada3n5WFb8crL8ChPCmZpxMWS1RNIe69T5QqmZXMKsjjBpCyUkL DMHJPD7ChedCPB6VoZ1Ai1QF6Gb9yi+BBUtONBnZFRp0uaQ/51YQZ95enYZGuENNp94J 7BCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pep7f0Zl; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-77369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fb14-20020a056a002d8e00b006e444ed29edsi9315362pfb.200.2024.02.22.13.29.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:29:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pep7f0Zl; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-77369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 87F50B295C8 for ; Thu, 22 Feb 2024 21:11:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C207D73F1C; Thu, 22 Feb 2024 21:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Pep7f0Zl" Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4115312D211 for ; Thu, 22 Feb 2024 21:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636236; cv=none; b=E9svDVPtCKrwC3TC8W4ODIN+9e0YIj7gfuWULlEbBKhQQL4vuKUzxmY3JqkrxPQy6CIt1ldYe6knERuc0bj5ewQYGoslNVIXDMA3Bj8SSSHDLXa2YP119gPvYngcqce0xObCyPcyEEGmn0MKSvV5U5UuF/jhtIALG9UHuH3JLNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636236; c=relaxed/simple; bh=Y7aa4EPdQeDb/k5BX8LnNG73kjPd5qiN00vjE6nM2RQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DAlquIQKkXX0bqkOELXNQDg9Bs2KvNb9mXkcgXsneiWVQ2P9RaBZBztf6Pz2FbpRY7MwyJ2MGPJwqmz4NvmRpUVpp4CFGoLiz+J4gy5Vzrutkz6NFEGMltKMhHzWw5nrukdDt5Mtk8V9CYc+2KUc+FlUk54YR6ocCSYfjulBJkQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Pep7f0Zl; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-db4364ecd6aso160453276.2 for ; Thu, 22 Feb 2024 13:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708636222; x=1709241022; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KISjjhinzIu3kIcQRpPQsw9fHAQrHUvQiIbfDFbxHeA=; b=Pep7f0ZlR80pDJXadhbCse5Qn0egw+++lgbATNgSL6evXNjeaqMctvxpkr3t0JbVDX XddISI1lj6IxtqS3Wl09G5HLRhbiFsDWAIEJ/xbiaZ2dfnu/ZfB9vjXZKmGgI909rZM6 m+AyAXcZo8cxDeyKJd6LUJzs08XAMwlUG5gBjaE+jLhycUxGYs7n1+PnXsoGZMm2itGh 4sOg+hm2ew7n9q8FKnhV3LzbKszZe0ZnJgxlebUO17I8qGDYT3dZF7pbNteialiFkXpS Oy166qxxbyrTz8d0APfzThbM7y3l8EHCSaNUnFjPsGkzb8qSM8AGIFuPppwyeDZCWSSR uZIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708636222; x=1709241022; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KISjjhinzIu3kIcQRpPQsw9fHAQrHUvQiIbfDFbxHeA=; b=M3EjDtC2Q4o5qHoxtpkVRYw1h13kcO6M6Jabq351sIaTCucJafFOcrS9qKnbLfxyOd vhCkyUOsKj/9LyD6pj6xSusQW/9sCgQWRKYxbDTFuIV8jH3d+kOP4wZ5qVrNvqfUgs0j BYoE2bju3YQjjRzUowdB5SxRlQ2RPm09E7cjBTwlJfoM3ywL/ytyorKjuvdYXOrH3CX5 oJFnX2J+rt43HdXfTT9qBQowQOE8N+CDdUHYKYWEHme7B8ImmsnZEAR17QgIyWsSMcHe sKdi9mje3hE13EOIbZiIA8i8OoLtOPlM8Dt6mYBfbczkjOLU09xZTGCE0CEH06KtEbrA fDmw== X-Forwarded-Encrypted: i=1; AJvYcCVespHwuulGNSfgi7pTGok+/ZsemC9Pj7UJQi8S2MI/J+dGivgHBhYGfpo8txhyjnKd+VUgyihXOjeEIlHRBXXcbhQvK7XOjPPlNJhG X-Gm-Message-State: AOJu0YyUr6LKhjseyQlCJ1jU6RLVawpyuoMFmN91HiQMxK3JP36i/WRz eAGD7A9INeMM4DVxNLFV69FAzEJdeqiGpQQ04ipTWFCvo53lM49Y+l6IUPCbOc45xt74fgWJX5w j36X3h4Ddbu9ff0W4nEFFiAbLvqVmqTn6QHJk2g== X-Received: by 2002:a25:888f:0:b0:dcc:aa1f:af3c with SMTP id d15-20020a25888f000000b00dccaa1faf3cmr366027ybl.40.1708636222326; Thu, 22 Feb 2024 13:10:22 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240217150228.5788-1-johan+linaro@kernel.org> <20240217150228.5788-4-johan+linaro@kernel.org> In-Reply-To: <20240217150228.5788-4-johan+linaro@kernel.org> From: Dmitry Baryshkov Date: Thu, 22 Feb 2024 23:10:11 +0200 Message-ID: Subject: Re: [PATCH 3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free To: Johan Hovold Cc: Bjorn Andersson , Andrzej Hajda , Neil Armstrong , Robert Foss , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Vinod Koul , Jonas Karlman , Laurent Pinchart , Jernej Skrabec , Konrad Dybcio , Kishon Vijay Abraham I , Rob Clark , Abhinav Kumar , Kuogee Hsieh , freedreno@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Sat, 17 Feb 2024 at 17:03, Johan Hovold wrote: > > A recent DRM series purporting to simplify support for "transparent > bridges" and handling of probe deferrals ironically exposed a > use-after-free issue on pmic_glink_altmode probe deferral. > > This has manifested itself as the display subsystem occasionally failing > to initialise and NULL-pointer dereferences during boot of machines like > the Lenovo ThinkPad X13s. > > Specifically, the dp-hpd bridge is currently registered before all > resources have been acquired which means that it can also be > deregistered on probe deferrals. > > In the meantime there is a race window where the new aux bridge driver > (or PHY driver previously) may have looked up the dp-hpd bridge and > stored a (non-reference-counted) pointer to the bridge which is about to > be deallocated. > > When the display controller is later initialised, this triggers a > use-after-free when attaching the bridges: > > dp -> aux -> dp-hpd (freed) > > which may, for example, result in the freed bridge failing to attach: > > [drm:drm_bridge_attach [drm]] *ERROR* failed to attach bridge /soc@0/phy@88eb000 to encoder TMDS-31: -16 > > or a NULL-pointer dereference: > > Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 > ... > Call trace: > drm_bridge_attach+0x70/0x1a8 [drm] > drm_aux_bridge_attach+0x24/0x38 [aux_bridge] > drm_bridge_attach+0x80/0x1a8 [drm] > dp_bridge_init+0xa8/0x15c [msm] > msm_dp_modeset_init+0x28/0xc4 [msm] > > The DRM bridge implementation is clearly fragile and implicitly built on > the assumption that bridges may never go away. In this case, the fix is > to move the bridge registration in the pmic_glink_altmode driver to > after all resources have been looked up. > > Incidentally, with the new dp-hpd bridge implementation, which registers > child devices, this is also a requirement due to a long-standing issue > in driver core that can otherwise lead to a probe deferral loop (see > fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")). > > Fixes: 080b4e24852b ("soc: qcom: pmic_glink: Introduce altmode support") > Fixes: 2bcca96abfbf ("soc: qcom: pmic-glink: switch to DRM_AUX_HPD_BRIDGE") > Cc: stable@vger.kernel.org # 6.3 > Cc: Bjorn Andersson > Cc: Dmitry Baryshkov > Signed-off-by: Johan Hovold > --- > drivers/soc/qcom/pmic_glink_altmode.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > Reviewed-by: Dmitry Baryshkov -- With best wishes Dmitry