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 032A1606A32C for ; Fri, 4 Dec 2026 09:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=owNHFUM3 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4FF7D112E2F; Fri, 4 Dec 2026 09:22:48 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C480112E04 for ; Fri, 4 Dec 2026 09:22:41 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 4940E436D5; Fri, 4 Dec 2026 09:22:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AD5B1F000C2; Fri, 4 Dec 2026 09:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796376161; bh=t8XM+gTjmN94L7+2rojJlCOvkfqOEWdRLdQZ23pUgck=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=owNHFUM3J5Fggkd8o8pZO1yEkJ8sNmGA6XS8QxZuSSOhxBepHnA8nsi5JeD/elrse /xjIezhcKVVRP13R+KaLwJxTZCIt9CnGaTCWLPQH2X823NaYeokBqW/AkSiR02rwPZ isEuXkqPS6+0uv5x/4WNCgc5VSkaBz1fRBayMfFrHIiAu4vtJE946t4QtC+4UlwNqU dKXPJswsoGqoidrmRw+XB2j3X4z/m7yIItTyCDJyL8828Su7hllGsQoMaCi+GaW+oJ sq1rrbYFuZ0v9ZtNPtJLkoPJ+cTS3U+HfEQ+ZVLvZ+w3FUgba+sspmNhSBAnHPbhYb 48qjuf7fMQI8A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn> Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261204090457.7130-2-25031212351@stu.xidian.edu.cn> References: <20261204090457.7130-1-25031212351@stu.xidian.edu.cn> <20261204090457.7130-2-25031212351@stu.xidian.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:22:40 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] fbdev: udlfb: unsynchronized backing_buffer clear races with render_hline() - [Medium] fbdev: udlfb: dlfb_deferred_vfree() on OOM path leaks or pins shadow buffer -- commit 8f1d574fcc8d77dc56b4c4144bf3b2dcaee63c24 Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> fbdev: udlfb: drop stale shadow buffer when the framebuffer grows This commit drops dlfb->backing_buffer via dlfb_deferred_vfree() and clears it to NULL in dlfb_realloc_framebuffer() when a new shadow buffer is not allocated. > diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c > index 8b7b4bdac4fbf..917bcef4bb695 100644 > --- a/drivers/video/fbdev/udlfb.c > +++ b/drivers/video/fbdev/udlfb.c > @@ -1248,10 +1248,18 @@ static int dlfb_realloc_framebuffer(struct dlfb_d= ata *dlfb, struct fb_info *info > */ > if (shadow) > new_back =3D vzalloc(new_len); > - if (!new_back) > + if (!new_back) { > dev_info(info->dev, > "No shadow/backing buffer allocated\n"); > - else { > + /* > + * The old shadow buffer is smaller than the new > + * framebuffer and can no longer be used for comparing. > + */ > + if (dlfb->backing_buffer) { > + dlfb_deferred_vfree(dlfb, dlfb->backing_buffer); > + dlfb->backing_buffer =3D NULL; > + } [Severity: High] Can clearing dlfb->backing_buffer without holding dlfb->render_mutex race with dlfb_render_hline() and cause a NULL pointer dereference? dlfb_realloc_framebuffer() runs without dlfb->render_mutex, while dlfb_damage_work() -> dlfb_handle_damage() -> dlfb_render_hline() runs under dlfb->render_mutex without info->lock. dlfb_render_hline() reads dlfb->backing_buffer twice without caching it: CPU0 CPU1 fb_set_var() dlfb_ops_set_par() dlfb_realloc_framebuffer() dlfb_damage_work() dlfb_handle_damage() mutex_lock(&dlfb->render_mutex) dlfb_render_hline() if (dlfb->backing_buffer) dlfb->backing_buffer =3D NULL back_start =3D dlfb->backing_buffer + byte_offset dlfb_trim_hline(back_start, ...) <-- NULL+offset dereference There is also an out-of-bounds window before dlfb->backing_buffer is updated: fb_set_var() publishes the larger info->var and dlfb_realloc_framebuffer() updates info->fix.smem_len before sleeping in vzalloc(), so concurrent rendering can still index past the smaller buffer. Updating the buffer pointers under dlfb->render_mutex (nested inside info->lock, matching dlfb_ops_set_par()) would close both races. [Severity: Medium] Can calling dlfb_deferred_vfree() here leak the old dlfb->backing_buffer under memory pressure? dlfb_deferred_vfree() allocates a tracking struct with kmalloc_obj() and returns silently on failure. When !new_back is reached because vzalloc() failed under memory pressure, kmalloc_obj() can fail too, permanently leaking the old shadow buffer once dlfb->backing_buffer is cleared. Even when kmalloc_obj() succeeds, deferring vfree() keeps the unused shadow buffer pinned until device teardown. Unlike info->screen_buffer, dlfb->backing_buffer is driver-internal, so synchronizing the swap with dlfb->render_mutex allows freeing it directly with vfree() after unlocking. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204090457.7130= -1-25031212351@stu.xidian.edu.cn?part=3D1