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 2AC7B3537FF; Sat, 12 Sep 2026 12:01:31 +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=1789214493; cv=none; b=kf9ln5/ZbQ7o4bMo4soZvCsPzIR6xPTgH6Ge+MRTSAvnCL4NfMz+rdNe81tyn770dZ6UrZfW9N6K6AQahsOpKtQYICbsEb9Ko+AIN2xPMyzAyjwmGHP6yVyYFR26rTRNJ95u0ZlFSdjnbfyRMHcXzKgPgXhfS/mhI4fqR4Dg/mA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789214493; c=relaxed/simple; bh=y4XppHz2EfH7udtGa+6wpTKTG90a4aipvDSW6N2ZGes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dDehkuj2ItAyfYWQhQ8AW7DvXN60RaRSi1+RchcjdLd0mpRsDYOgwKJC/LDFbrL0UpkJaxVPUkWn5C2GSHEnjJMgADn+EIX9TTMl9kjLPWHS1iIXBv7pwo2gLK2twL9j+BZfB0b+05sXYGv7fC535txHxlxfFlMJSWIig1SmGWc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0hVLN7ae; 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="0hVLN7ae" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9049C1F000FF; Sat, 12 Sep 2026 12:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789214491; bh=DCh3cKHR2is/xAdwuGC6mHY8l1dBH2NptetAZggYs48=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0hVLN7aeyYqtEiwwfcMunlHSbENzY5zOsK9buDHVdxXc6CHCrK3H9jTgqgFXN+uzl /tnzfiJVN09kla4qZsObxvbhmjie9LpLakpBfa7VV3PJ4z2firLysx6apz4NzlhrpJ F/iR4ToggpRCbz2bdwnm2v2sDF+Z2nWmrQMNs0vk= 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.12 0284/1376] drm/nouveau/uvmm: fix premature region free on failed OP_UNMAP_SPARSE Date: Sat, 12 Sep 2026 08:45:10 +0200 Message-ID: <20260912065613.876095243@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 @@ -1251,6 +1251,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; } @@ -1259,6 +1260,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; }