From nobody Fri Dec 19 22:01:13 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24F1DC38A2D for ; Mon, 24 Oct 2022 12:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234225AbiJXMsF (ORCPT ); Mon, 24 Oct 2022 08:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231810AbiJXMnL (ORCPT ); Mon, 24 Oct 2022 08:43:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 656907F0AC; Mon, 24 Oct 2022 05:09:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 179CC6128E; Mon, 24 Oct 2022 12:07:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A6C1C433D7; Mon, 24 Oct 2022 12:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613245; bh=yT4I2SIf6prmOQ5TA2r4Sm95rU2zqmrlMEcsNxaDwgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r3RrXqRPzlxM9pdJHzgbzcDs3K1eK22R6nWAREfmOF/nrQxoBbYsuqGwdNfGNI7LO UFKqKTH3te7j57yDYZcwALeke/hPFsi1XfUa4tjea0yo1CMiklguYb1JMCiFRaX/ZX cF8tWkebIImraliiPEEyKitYB0p5cKogUggNac7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , Lyude Paul , Thierry Reding Subject: [PATCH 5.4 056/255] drm/nouveau: fix a use-after-free in nouveau_gem_prime_import_sg_table() Date: Mon, 24 Oct 2022 13:29:26 +0200 Message-Id: <20221024113004.362252810@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jianglei Nie commit 540dfd188ea2940582841c1c220bd035a7db0e51 upstream. nouveau_bo_init() is backed by ttm_bo_init() and ferries its return code back to the caller. On failures, ttm will call nouveau_bo_del_ttm() and free the memory.Thus, when nouveau_bo_init() returns an error, the gem object has already been released. Then the call to nouveau_bo_ref() will use the freed "nvbo->bo" and lead to a use-after-free bug. We should delete the call to nouveau_bo_ref() to avoid the use-after-free. Signed-off-by: Jianglei Nie Reviewed-by: Lyude Paul Signed-off-by: Lyude Paul Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object") Cc: Thierry Reding Cc: # v5.4+ Link: https://patchwork.freedesktop.org/patch/msgid/20220705132546.2247677-= 1-niejianglei2021@163.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/nouveau/nouveau_prime.c | 1 - 1 file changed, 1 deletion(-) --- a/drivers/gpu/drm/nouveau/nouveau_prime.c +++ b/drivers/gpu/drm/nouveau/nouveau_prime.c @@ -90,7 +90,6 @@ struct drm_gem_object *nouveau_gem_prime =20 ret =3D nouveau_bo_init(nvbo, size, align, flags, sg, robj); if (ret) { - nouveau_bo_ref(NULL, &nvbo); obj =3D ERR_PTR(ret); goto unlock; }