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 925A7606A6B0 for ; Mon, 30 Nov 2026 13:59:14 +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 3B3EA10F056; Mon, 30 Nov 2026 13:59:06 +0000 (UTC) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by gabe.freedesktop.org (Postfix) with ESMTPS id 420C010E0F5 for ; Sat, 28 Nov 2026 10:04:41 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-3b4021b572dso5440962a91.2 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=gX8etGcXpdVpBO8syrK0aeA3FDfC25yBobfNrVJE+hm9Lv9vvWCfOJRSEQ4aVB5bav xVwL32WAkX8QRaNfuL6lbux4ATyj+QInJee7H6Ez54dnjHnXKDGEJhy4freU1QrsO1OQ eyJXaWEGoZn94RLh7lPc3wzbBxi0xNubjePBNpi1Db6lV57pGwqKLjkjVTtvoO/ICONp +zX/zRn9HvhkS4GSbMiu1unF1aBj7S1j616Hv6T57+J3eIXyAz6UWmOEQhKER7O31bkO CDCz6tfV4019UN3nZ24SoTcjhI9unLSZXmEi5vZLaWXe6SonKbIrsX4Z74/C7veZpy/F UCBQ== X-Forwarded-Encrypted: i=1; AL+hErE/8Lum+y6tKgBc64oTVKmmajc7iX00nPYQRlkBCnNatLDvSKt9CXqWjyKDQrcc0xfoO7EtQqNz7fw=@lists.freedesktop.org X-Gm-Message-State: APuU4Z/glUDcChcJ4Vy8ABLgM8R9tNG+By0avGnaaQcOKSyaLoJizuBj /jyfyaB+zCB/O3B0I7z1JC4cHZKb5pH3JfhV/B7+BbgePPW+0kkVfLfT X-Gm-Gg: AZFdTZeWPZU/AaEmUIDGcS7yCoMMvIkfsJrYM7bbP8QkEZSiT7yCZBVVm71yCR8AO+z uyXkp69Hk2u2gFCA3xPx4mZkywlfjasK/Ekm2yD04OG41W9reL+4VMjZxtOa4kpzO8DRigLqvLo 3zCS/zC2/AOcH0AwCEv5jk9UiLVr/nK+r5XodIC4Y6wNCr/R3LquCw4yy3N+0BDuAZU+rRTKSC5 WfWkCFZLjK57T10VpTC7riHkWjTHBj9mDrQTZQJPivWAj/6/LOVoQypB6YM/798FV+7mQgn6HGe 6t86hRxgRS3nUYvJy7D2HTOzRNh/NMFC7xOvj1PaBo/rBc6aW09kH9HhnnKxAvE8BGfLjE5uylF eFilrzoSNsbdfE6VuDn0oCPuRGtq+/uxEJ6hA+0elgATXu2NCN/fpzNNUuUHIhcAtJdn0LtSHOP WTT0j2WZhWLYmzYfUbOeAFdFYLm4Jv0cu+f1cjwQ0vgZ/iqT2qJOYUVqyMsmqdFxycCJWUankoo 0PIWcw8TBAuno1ipJ431KckIEk43aCsp5tTSaHL8Ih3fSVRRdCVbVTPTVLoSteIKZ2HF/SVZ8oo Ft5E6lEkh37skIcp3aFJQQnzU93j49f/WwE14p+KDHfwj54nu5KzS+q+dLBMCjuDHTeOikmQbVn YecvZD71A6EQoJm0d9r6ulJ4JuPqMnaw0gEjIT20/3CTVL+A4AuUlg4K2E4JXcLGX0zkK5MT22D V7WFIE0SzL6Ywt36BEeNYZOjz5zoDSEXY7pvdA7po= 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:58:59 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-gfx" 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