From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 9E40524CEEA; Sat, 12 Sep 2026 14:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789222142; cv=none; b=kR0ogMUp8jHxDwiVmq2VMXO4HWlILtfJsVnIfyqdV+e2TgXtkxyfYiX5i2R08a8z5FMYmtFUFkz5eUbKS4qeHfbakRwLOw71HrVWA+xroGkZL0aYFJvBb57pLJOAvF+ou0KrLyeAS1lCDPLZR6DZIcHY71UiyznAp50Job1SQiw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789222142; c=relaxed/simple; bh=Y3mt8SCBhEqPbF56YclaQsl4kjGdi+WYPXkbVOOVCsk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RxtuzmSYp9Qd/r6wGTqBUlQEpGGf/qWlg/VTVNgmg9cKxZOx50BKSnI46bUjUCPbxQuie2EPpAQJsATRS/FX7+RazkrzxAFjw/xNIm+qm7cU+jzKmsQMfjfRf43Fj9FKmGPlfIkz+xQODjlUAwrKoIVH15yXuhS7Q5yYZjtW/7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cBoQ9r51; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cBoQ9r51" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3BE01F000FF; Sat, 12 Sep 2026 14:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789222141; bh=aSF2DkeflrDIxNo5Od4LldhnTOTSsdEZ8uFgslhZ7ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cBoQ9r51dgnvpE1vgMgoXoDvxJA+etUhz3a4dEU4xoNumQKmAAnYiKMKkCNVecX7g C8zjuo+YtdnMx+EJMXZMj0HTjnCLESHfaz7Jtfv8ORPBz+ghSzN6SbXWCe28nTUkMR wzmVvFerLEgPicRYKCBdL3ec/LNOzL8DuFcrsTMM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuhao Jiang , Zhenhao Wan , Lyude Paul , Danilo Krummrich Subject: [PATCH 6.6 0526/1424] drm/nouveau/uvmm: fix premature region free on failed OP_UNMAP_SPARSE Date: Sat, 12 Sep 2026 08:49:18 +0200 Message-ID: <20260912065619.071477768@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhenhao Wan commit ccf930812f23b8259ef64fd3394d53b093e4651a upstream. In nouveau_uvmm_bind_job_submit()'s OP_UNMAP_SPARSE arm, op->reg is set from nouveau_uvma_region_find(), which only looks the region up and takes no reference; a region's sole reference is its membership in uvmm->region_mt. Two failure paths leave op->reg set: the -ENOENT check when the region is busy, and the drm_gpuvm_sm_unmap_ops_create() failure. The sibling nouveau_uvmm_sm_unmap_prepare() failure just below clears op->reg; these two do not. unwind_continue steps back one op, so the failing op is skipped by the unwind loop and its op->reg stays set. nouveau_uvmm_bind_job_cleanup() then enters its if (op->reg) branch and calls nouveau_uvma_region_remove() and nouveau_uvma_region_put() on it, dropping the tree's sole reference and freeing a region this job never created. The comment above the cleanup loop documents the broken invariant: op->reg must be NULL on submit failure. This frees a live region on an unrelated failure, reachable single-job when drm_gpuvm_sm_unmap_ops_create() returns -ENOMEM; if another job owns the same region, its cleanup then removes and puts the freed region, a use-after-free. Clear op->reg on both failure paths. Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI") Reported-by: Yuhao Jiang Assisted-by: Claude:claude-opus-5 Cc: stable@vger.kernel.org Signed-off-by: Zhenhao Wan Reviewed-by: Lyude Paul Link: https://patch.msgid.link/20260811-nouveau-uvmm-vmbind-fixes-v2-2-aaee4b395d04@gmail.com Signed-off-by: Danilo Krummrich Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c @@ -1191,6 +1191,7 @@ nouveau_uvmm_bind_job_submit(struct nouv op->va.range); if (!op->reg || op->reg->dirty) { ret = -ENOENT; + op->reg = NULL; goto unwind_continue; } @@ -1199,6 +1200,7 @@ nouveau_uvmm_bind_job_submit(struct nouv op->va.range); if (IS_ERR(op->ops)) { ret = PTR_ERR(op->ops); + op->reg = NULL; goto unwind_continue; }