From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D9FA606A33A for ; Mon, 30 Nov 2026 14:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=MhPY3cau Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1BA7510F0AE; Mon, 30 Nov 2026 14:00:10 +0000 (UTC) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by gabe.freedesktop.org (Postfix) with ESMTPS id 48C9F10E5DD for ; Sat, 28 Nov 2026 10:04:41 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3b41188c8b9so5991422a91.0 for ; Sat, 28 Nov 2026 02:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795860281; x=1796465081; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wJHu2Cmp5m4NLvlBcGUsPCjvAUhFeSDFqDBREkjtkr8=; b=MhPY3cauQPm6btNXWA1H8GWjeOjj1HG8dEtiEwGpOp6Vq/32aN0pIMSXv+gb5Fbrtd 9eXxWBUBBn6/RGDYCYL43SbKKST/zq6zEj0mip+1aCFoE7p2L6C/PBE0Q1iLEu2G4eqB wpZjPgv1otDm7YwZnbKmShXj37rErkU6+cfMlpHQMcI5jaKF5j+zdkLBwlo7c4/De77V R7ZgdYc+ViEg3HjI6U6I3qz5FpJUbGqZKt2yvbeDmx7xiSCx4sZlMmAYyolEUsNz9rUL c5o8M7WParfJksqZz62rToBsVung1gVTkSePpwZbkBBkHykWvLcrqdoiUQzOjR71/X+E UgWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795860281; x=1796465081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=wJHu2Cmp5m4NLvlBcGUsPCjvAUhFeSDFqDBREkjtkr8=; b=WLqk7yVYn8FL2ruPiTvAss8KxvDP1gL5bTe+UjKLSQpvKqPRzhVFN1voE/YxC3Kc4m l6CyZkdCRCsuEyvbGv1FX2UOwt/n+X+C0aZZlQPMEX6toMr946IiaoxfNv0WKYM/TJkC vzpJ13rrEYCYCf2xf7+cN2AMpHTl4W47Z9fyjYvJeEul1SGvNZuAwpWYCuKqCwIGJJGx s+QokDwoVWKdL9u+jEjZcM53f25NXC9lCNdPqOKFgurpcB7OcBHmvLePEz9NeAEK27rr dcytmaizzUWRhjyUBFUmmT7kT0M7zU3+Uh7EzKTJAr0BZ9Qr8UR1CGLJABjIjDYDXKO/ FVhQ== X-Forwarded-Encrypted: i=1; AL+hErGuyVPTEdriyJ6ZK5JmGg/UIPB6/uoezD7/RARI/JtBaamF12CQVUg+OdnjXAd8WTpaheXTIW+/yg==@lists.freedesktop.org X-Gm-Message-State: APuU4Z86EtSoXztQ4ZofAddchNe0YGUsSh7HdZmt+eE316SXB5LJrn2L V/VvbESuqWsUZYhfPBV9JpW6Qo1QfNtEztbAfFR3vTlkfNREpsfg5btC X-Gm-Gg: AZFdTZfuIB5VwHQJibl81urA+IpG/Row84GRa+yZdQcKFpjzs4g5sIRzgqEBxvewOeJ Z2MjGjA+Rl+9cOJxPDRQPTdvkFvuAHbcOaPwa7gzhjg/cDL4+4mXPqy6y/O57VZ9zWDFxMHHDk2 lN3F9oIDFDlacRzXiMTsk2EgvWLJOJ4DSp5/MFU5qn5alw6hOBPonLWJ1Q1k+IGnTr9B7QCqu2n auW0pOPCWU7Qhi/nCuliZs258YXCc9niMo7tzCTH7HXEVvhb+oy+ndTLrnVZS0Yc6olGhPv4d32 bnNR1wo/g2MtNkwdXIVaXZO/dmKAWr+W2XtE3azLZ+JXshRTqBuqMjBgAFQwyH71fMZHCjZmNkl cLrq/AWVpKbQhmfR2SNUjWIYNY+OyFjQDnpjr6jOJgiLJGsaFA2AAgJJlogfxdl6CqgRUdxZqZI 0H9nJLQmlC0WritI1wj0WIVogP3poZoe7L6uTrk+qm96p0Z+F89wOo08Xgy2KCU0YQ9Cu2sXYor RPQW9mXfGAPQX61mheMoe2pHdL8K8Af8O8QTSx+aOLQpHh2wofixghMK8J86jcRjYLyp8AI2Tg/ TmOYMtYur1kxHCu0ehLXWNYgB+hT2elC9pO7TbHZWTkrUNDKyp5BgftFBL3NQzth4de8rxpYYLb 6NoveRh7GGsOToHx1844qx7ONkV075dKkdvowTarGx4pYiWj2lp5icfF+6q5aZvYYL+eaEVnxJB x/Z9TwEx0psqbI1R3NDArNgJYPm1BuddSuwtoRy5Y= X-Received: by 2002:a17:90b:3891:b0:3b4:127a:2bc2 with SMTP id 98e67ed59e1d1-3b41c8d9bfamr26559585a91.14.1795860280740; Sat, 28 Nov 2026 02:04:40 -0800 (PST) Received: from LAPTOP-3B99V33A (ec2-18-138-229-8.ap-southeast-1.compute.amazonaws.com. [18.138.229.8]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b73b2b3sm20556526a91.2.2026.11.28.02.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 02:04:39 -0800 (PST) From: "Bin Luo (University of Electronic Science and Technology of China)" To: jani.nikula@linux.intel.com Cc: rodrigo.vivi@intel.com, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] drm/i915/display: hold frontbuffer ref across dirtyfb fence callback Date: Sat, 28 Nov 2026 18:04:29 +0800 Message-ID: <20261128100429.689-1-luob87709@gmail.com> X-Mailer: git-send-email 2.51.0.windows.1 In-Reply-To: <8247d106ca535db291d2f85a3b8bea7956c6ccd8@intel.com> References: <20261127133935.1461-1-luob87709@gmail.com> <8247d106ca535db291d2f85a3b8bea7956c6ccd8@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 30 Nov 2026 13:59:48 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Jani, On Fri, Nov 27, 2026 at 04:17:21PM +0200, Jani Nikula wrote: > On Fri, 27 Nov 2026, "Bin Luo (University of Electronic Science and Technology of China)" wrote: > > intel_user_framebuffer_dirty() stores the raw intel_frontbuffer pointer > > in frontbuffer_fence_cb without taking a frontbuffer reference. If the > > framebuffer is destroyed and its owner frontbuffer reference is dropped > > before the reservation dma_fence signals, > > intel_user_framebuffer_fence_wake() passes a freed intel_frontbuffer > > pointer to intel_frontbuffer_queue_flush(), causing a use-after-free. > > Please describe a real world scenario where this "if" can happen. 1. Framebuffer fb1 is currently scanned out on a plane (so atomic_read(&front->bits) != 0), and its BO has an unsignaled write dma_fence in obj->resv: - On xe, any normal in-flight GPU render job to fb1's BO suffices, because xe_frontbuffer has no i915_active front->write tracker holding a reference to front. - On i915 (as well as xe), an imported DMA-BUF / PRIME fence from another GPU or a sync_file imported via DMA_BUF_IOCTL_IMPORT_SYNC_FILE likewise does not take a frontbuffer reference via front->write. 2. Userspace issues DRM_IOCTL_MODE_DIRTYFB on fb1: - intel_user_framebuffer_dirty() fetches the unsignaled singleton fence from obj->resv, attaches intel_user_framebuffer_fence_wake() with the raw cb->front pointer, and returns 0. - drm_mode_dirtyfb_ioctl() immediately drops its temporary fb1 reference via drm_framebuffer_put(fb1). 3. Before that fence signals (e.g., a render job taking >1 vblank or a slow/stalled external DMA-BUF fence), userspace flips the plane to another framebuffer fb2 (or disables the CRTC / closes the DRM fd) and removes fb1 via DRM_IOCTL_MODE_RMFB (or drm_fb_release()). - The atomic commit only waits on fb2's fence (if any) and the vblank, not on the old fb1's obj->resv fences. 4. Once vblank completes, intel_cleanup_plane_fb() drops the plane's reference to fb1, fb1's refcount hits zero, and intel_user_framebuffer_destroy() calls intel_parent_frontbuffer_put(display, intel_fb->frontbuffer). - Because nothing else holds a reference to front (on xe, intel_fb->frontbuffer is the sole reference until intel_frontbuffer_queue_flush() runs; on i915, foreign DMA-BUF fences do not hold front->write), frontbuffer_release() frees front (kfree() on xe, kfree_rcu() on i915) while cb->base is still attached to the unsignaled fence. 5. When the fence later signals (normal completion or GPU reset), intel_user_framebuffer_fence_wake() passes the freed cb->front to intel_frontbuffer_queue_flush(). If you agree this scenario is worth fixing, I can also send a v3 that includes this scenario in the commit message and removes the now-unused intel_frontbuffer_queue_flush() / intel_frontbuffer_flush_work() / flush_work dead code noted by Sashiko. Best regards, Bin Luo