From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 157BD12CD8B; Thu, 7 May 2026 16:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778171373; cv=none; b=G8kkD6br8ndXJvq2gkDBQPSUNgOO/hmpElus4DnE2vwRNXN3cyDxfznY7dBu1YbNdkTiUUdtN7lqRDfmGK/zIZw1k2VdqKhENl4lyHxWnhVmeJ0lTBwONL6YTWAVIIG61jMaHeqeeXnMIJ+lyZkuXGzfXBXhaNIwoMrBH3ZY3rU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778171373; c=relaxed/simple; bh=Hy5SuLRSXLgfZuxhMrGS91YnCLOlh5SkFRV5Xq9Mknc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=I6Nv4GEe3Ir5/SO9ocRbEYhv0KrOkjPsW0Z/phk7lFEXZTDD7kDMQ552tm8gwyt3CvRCVkX49ezpblIgHISG55fupx+qMRHlxu5rzpBNU4PBvbeQa2SOhVHBL/6XGzWrAB2B3zlc9HSKP/mrisam3bYJr7b9ZQYs/QKfHpIzx7Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=Igalia.com; spf=pass smtp.mailfrom=Igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=YnJZZNG0; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=Igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=Igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="YnJZZNG0" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=BEYSRI1ts1Dc483/vmuXrRD78Mho4nYcEd4Ou4NeA0A=; b=YnJZZNG0vG4tdTbGQ++0CB6Tyl 8UwltCtqFmANdPxH2EBYKetnWs89YA9zL5X/8MRBi+lTPRB//vBFl7pvJ+SM9StO141lULmEQQbRn 0quDkK3xBpObFYxnxBj/k0DwDCns4xfKOQDWwWwrVxnRRXcMleWS1reBRN+BILx4Zd6iYsh9ZFK5v xVRj4GFSEthCeL+uBq+MrHrJzkS0El3jkTm3Y0vNn2LqIiWEJHpzTkAFB+ccDthLbSgWq2myiC7Q6 cpRHF/O9ZPFx0ZCVxQOTAzmAvI3z6vMZNthcmChmQsFgIkavbiUh941D+xiimR4EXRKpTVYFDMkbD sBf9+GVg==; Received: from c-73-157-168-91.hsd1.or.comcast.net ([73.157.168.91] helo=[192.168.1.133]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) id 1wL1au-007UD1-ET; Thu, 07 May 2026 18:28:59 +0200 Message-ID: Date: Thu, 7 May 2026 09:28:45 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 1/8] drm/msm/dpu: don't mix devm and drmm functions To: rob.clark@oss.qualcomm.com, Dmitry Baryshkov Cc: Jani Nikula , "Kandpal, Suraj" , Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , David Airlie , Simona Vetter , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Dmitry Baryshkov , Abhinav Kumar , Sean Paul , Marijn Suijten , Laurent Pinchart , Tomi Valkeinen , Kieran Bingham , Geert Uytterhoeven , Magnus Damm , Dave Stevenson , =?UTF-8?Q?Ma=C3=ADra_Canal?= , Raspberry Pi Kernel Maintenance , Christophe JAILLET , Jessica Zhang , Louis Chauvet , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-renesas-soc@vger.kernel.org References: <20260505-wb-drop-encoder-v5-0-42567b7c7af2@oss.qualcomm.com> <20260505-wb-drop-encoder-v5-1-42567b7c7af2@oss.qualcomm.com> Content-Language: en-GB From: John Harrison In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Resending because apparently it got sent as HTML and was rejected by the mailing lists... On 5/5/26 14:49, Rob Clark wrote: > On Mon, May 4, 2026 at 5:25 PM Dmitry Baryshkov > wrote: >> Mixing devm and drmm functions will result in a use-after-free on msm >> driver teardown if userspace keeps a reference on the drm device: >> The WB connector data will be destroyed because of the use of >> devm_kzalloc()), while the usersoace still can try interacting with the >> WB connector (which uses drmm_ functions). >> >> Change dpu_writeback_init() to use drmm_. > From [1] it doesn't sound like userspace holding the drm device open > is the issue (if that were possible, it seems like it would go badly), > but rather the order of managed cleanup? > > [1] https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/gpu/drm/xe/xe_hwmon.c?id=3a13c2de442d6bfaef9c102cd1092e6cae22b753 So is this not an actual issue that has been seen in the wild? It is just a theoretical issue based on code observation? If so, then maybe the comment should just be something like: dpu_writeback_init() was mixing devm and drmm functions - allocating using devm and then passing to drmm to manage. This creates the potential for a use-after-free bug as drmm and devm have different lifetimes. Fix that by consistently using drmm management. John. > >> Fixes: 0b37ac63fc9d ("drm/msm/dpu: use drmm_writeback_connector_init()") >> Reported-by: Christophe JAILLET >> Closes: https://lore.kernel.org/r/78c764b8-44cf-4db5-88e7-807a85954518@wanadoo.fr >> Signed-off-by: Dmitry Baryshkov >> --- >> drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c >> index 7545c0293efb..6f2370c9dd98 100644 >> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c >> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c >> @@ -5,6 +5,7 @@ >> >> #include >> #include >> +#include >> >> #include "dpu_writeback.h" >> >> @@ -125,7 +126,7 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc, >> struct dpu_wb_connector *dpu_wb_conn; >> int rc = 0; >> >> - dpu_wb_conn = devm_kzalloc(dev->dev, sizeof(*dpu_wb_conn), GFP_KERNEL); >> + dpu_wb_conn = drmm_kzalloc(dev, sizeof(*dpu_wb_conn), GFP_KERNEL); >> if (!dpu_wb_conn) >> return -ENOMEM; >> >> >> -- >> 2.47.3 >>