Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1615698pxb; Mon, 11 Oct 2021 09:32:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaigHw/qiJbe4PdN2Znjdr8xzYltzPS/+cEO/4LbeH4m6OcmoZmdME/Tml0goZl9xqJotE X-Received: by 2002:a17:90a:4812:: with SMTP id a18mr20401pjh.40.1633969954607; Mon, 11 Oct 2021 09:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969954; cv=none; d=google.com; s=arc-20160816; b=rtEStUA7c1/v7Yq2GFr90PBb86xM5LqPcWTcnI9r1WU8V/y/2/lXs+4WHghVZDQtXD i3d7sjon+EDtVxJwWVXVrxpuXMqe382rkSdKO+9XMljjEpm9+rTzugjGR81dQl1sh5AH 5ZstnYY5wzGufGzsiOb6GKHkPpXGcg67avUUUG+Ghv15dEDbt6sZEiAMcaXLdJ69VF/Y jY6Gs4eLriclsnJpeqcZN/hvh+F0RKMhMIvTg7BHpGbzBBFlteEy+29EmrHsUpBRV/OS YHGdRl1OR4mpEUvEzKg3KOIM3kPuY5EJJ+4jounH6RBofH8ZEWmOeHZvhZie0UJpRg+4 /l1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1YyKIohDn6g7BLMNglnLyN4YfipSZ8QIYzcCBwLxWmA=; b=Uy6UE53eJttTfY5vJr/fFh4/36Hbh+ZRx99SERWIKPCGrBR6PLiPqYt+URDiCO3G8r SjamYDHZwyuNv2di/WAwDUA8hCaOdds0j+oyE79AKNv3yQEfk0EQmukEPVizA6SK0i85 KQR21/6lHDDMNrpn0KFFmJusRZTatwbTkVidqgEUcADdWRSuykR9qv+JOGBigmVLGqXD tr7uU2SShU1vK0ZFqpScI6bmH96MzgzIFDHFhhXAGSi0Hk59sS3VEaS+SMMA4w/c1gB9 UqR7cHPVLB2fa5MRmAleaqjos4AFElmPDusRP/Z5bv6tyFVKMYKSSljjY9HqkrS/Cw8q Oc8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cB9NLwVF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si14632819pfj.327.2021.10.11.09.32.19; Mon, 11 Oct 2021 09:32:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cB9NLwVF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238517AbhJKN7G (ORCPT + 99 others); Mon, 11 Oct 2021 09:59:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:40706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237871AbhJKN4n (ORCPT ); Mon, 11 Oct 2021 09:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E0F06113E; Mon, 11 Oct 2021 13:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960425; bh=/0tBGpF2fMEpWCmF9dekE4Dd8i04Y0hi+ckxHaw3qD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cB9NLwVFu788WJD8iSxRhqhmgWUJPlOk2JsgpG/khFiEMsnHdKSYNPQ72aRd4ugUV dTMG25UB5m0KpVszbdYsDyl693EDIMLLiTPlmoY7+rz2RvTtWMfBms/sP4SsGo8aB0 p8IDJsanqiOKSThrH75yNpXFEhNWjwTAaRemGsIk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thierry Reding , Jeremy Cline , Lyude Paul , Karol Herbst , Maarten Lankhorst , Sasha Levin Subject: [PATCH 5.10 56/83] drm/nouveau: avoid a use-after-free when BO init fails Date: Mon, 11 Oct 2021 15:46:16 +0200 Message-Id: <20211011134510.328120161@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeremy Cline [ Upstream commit bcf34aa5082ee2343574bc3f4d1c126030913e54 ] nouveau_bo_init() is backed by ttm_bo_init() and ferries its return code back to the caller. On failures, ttm_bo_init() invokes the provided destructor which should de-initialize and free the memory. Thus, when nouveau_bo_init() returns an error the gem object has already been released and the memory freed by nouveau_bo_del_ttm(). Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object") Cc: Thierry Reding Signed-off-by: Jeremy Cline Reviewed-by: Lyude Paul Reviewed-by: Karol Herbst Signed-off-by: Karol Herbst Link: https://patchwork.freedesktop.org/patch/msgid/20201203000220.18238-1-jcline@redhat.com Signed-off-by: Maarten Lankhorst Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nouveau_gem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c index c2051380d18c..6504ebec1190 100644 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c @@ -196,10 +196,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain, } ret = nouveau_bo_init(nvbo, size, align, domain, NULL, NULL); - if (ret) { - nouveau_bo_ref(NULL, &nvbo); + if (ret) return ret; - } /* we restrict allowed domains on nv50+ to only the types * that were requested at creation time. not possibly on -- 2.33.0