From nobody Tue Apr 14 14:18:15 2026 Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) (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 B6FD32264D9 for ; Tue, 14 Apr 2026 05:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776145801; cv=none; b=fbG5SeDdAG8d16ZaP74Pm1ghUooRjTppdJ2HxD1AIh1UGrh+n8+G056v7zcyRlgb9U15y0xG2zK46cZ7YLHD+cI7DWtIaO3aNHdDRr7A15yjAIwN8ImC5AvAuYXH3mre2PuDftY4vW+Rbn/y58Kzis0UoES9MwIvQLYbvSnSDgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776145801; c=relaxed/simple; bh=y/g0/q+Dw9EYDwPdek3zpspjqjnC8wdV0sSifVn2U3w=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=ADSB1TCniBvoLhMQgYFUqyOh3bA7zVxXa+Sxc/liN0oRd4Du1BJhtAETMrYOQUCQxC+tqVlv7tDmW71tU2FD4w4haz4U4ExXfWLQTYhA7pKmeKV4vdGoIBBiTLiQg3recPp+PR2ZFs3MsWJcAXWy1o9eeun9L8N2Bj18IFW6wrg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-683b4edaab1so8902308eaf.3 for ; Mon, 13 Apr 2026 22:49:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776145798; x=1776750598; h=content-transfer-encoding:to:from:subject:message-id:in-reply-to :date:mime-version:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tOclBOsj8L250PjHN8+zr0Al1OXQX88POHBP9s5oPoc=; b=ElSJmHV1vZ/hk2Iff1a9vNmS78oI11Z1fBfQszTn1KDl/V5jbEw2OXTG3uAAqmmUZj YfNju7d+Iy/uxMAlDNzJA1iW8B995y+8U2wWTG2B7YFbg3do9K+k4p2wbrPtn2PNKZcz HFlqmiQarFut+2+cu4XQ+uSZop1CefB8P158+CGQjuRFudxMjKdJ90WBv0qNtxYjRD3u JTl3UtHInrjCj74kW3R0BwxybyxN/gDMXbIl0pedxourq1gUTng4QefAf5jDgK06Gq5I 1hWWeSEYK/hzapxKPMANXOzEKru2W1sSiKgzYEGFaV9+CEJQO+3bolGlbABNtd9kIjVF oX6w== X-Gm-Message-State: AOJu0Yz7WYEOLOJNgnnMu7DyY3YZ3ANM3CX0Af00Rf0c1LoZ+JG87Wzu ihBIcirSAD9yB25aO3D9uwXDcavcSLgPK+DANUtThh6BRv3eXtiqRqeohR2SlRB3604Yf9rm7p1 YQww44Od6me8zA5UUkTuX3eGodNgT3JiOrMSeSxBLFePRHda9WHCIfhgQy4I= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a4a:ef09:0:b0:683:63f2:a42a with SMTP id 006d021491bc7-68be7ee3977mr5794155eaf.33.1776145798573; Mon, 13 Apr 2026 22:49:58 -0700 (PDT) Date: Mon, 13 Apr 2026 22:49:58 -0700 In-Reply-To: <69dd24f4.a00a0220.468cb.004a.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69ddd586.a00a0220.475f0.0036.GAE@google.com> Subject: Forwarded: [PATCH] drm/gem: fix use-after-free in drm_gem_release From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] drm/gem: fix use-after-free in drm_gem_release Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git= master drm_gem_release() calls idr_for_each() to iterate over all GEM handles and release them during file close. However, idr_for_each() does not hold file_priv->table_lock while reading object pointers from the IDR, which means it can race with a concurrent drm_gem_handle_delete() from a GEM_CLOSE ioctl on another thread sharing the same file descriptor. The race is as follows: Thread A (close fd) Thread B (GEM_CLOSE ioctl) drm_gem_release() idr_for_each() reads obj ptr from IDR drm_gem_handle_delete() idr_replace(NULL) drm_gem_object_release_handle() handle_put -> kfree(obj) drm_gem_object_release_handle() obj->funcs->close() <- UAF! Fix this by replacing idr_for_each() with a manual iteration loop that holds table_lock while reading each pointer and uses idr_replace(NULL) to claim the handle, mirroring the pattern used by drm_gem_handle_delete(). This ensures mutual exclusion: whichever path claims the handle first (sets it to NULL) gets to process it, and the other path safely skips it. Reported-by: syzbot+b2e951687503f32f74ce@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- drivers/gpu/drm/drm_gem.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 891c3bff5ae0..b878f82146f1 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1085,8 +1085,28 @@ drm_gem_open(struct drm_device *dev, struct drm_file= *file_private) void drm_gem_release(struct drm_device *dev, struct drm_file *file_private) { - idr_for_each(&file_private->object_idr, - &drm_gem_object_release_handle, file_private); + struct drm_gem_object *obj; + int next_id; + + next_id =3D 0; + while (1) { + spin_lock(&file_private->table_lock); + obj =3D idr_get_next(&file_private->object_idr, &next_id); + if (!obj) { + spin_unlock(&file_private->table_lock); + break; + } + /* Claim the handle =E2=80=94 same pattern as drm_gem_handle_delete */ + idr_replace(&file_private->object_idr, NULL, next_id); + spin_unlock(&file_private->table_lock); + + drm_gem_object_release_handle(next_id, obj, file_private); + + spin_lock(&file_private->table_lock); + idr_remove(&file_private->object_idr, next_id); + spin_unlock(&file_private->table_lock); + next_id++; + } idr_destroy(&file_private->object_idr); } =20 --=20 2.43.0