Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1353439imw; Tue, 5 Jul 2022 08:03:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sR+hR6iEk897jK0WLv4NiKiGTZtOOAQ6I52eXl5n9ZojnVDqjjk4e1wFMgBJe9WTmOob2j X-Received: by 2002:a17:90b:224a:b0:1ec:d128:a82d with SMTP id hk10-20020a17090b224a00b001ecd128a82dmr43106802pjb.3.1657033382732; Tue, 05 Jul 2022 08:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657033382; cv=none; d=google.com; s=arc-20160816; b=ze7u+iic0eMVeVIJIp/I7vqESt5Xh/XGIr1Zv4yZwUqJxQCAvKQnAeU0YzUK+iYy7u LU9VGh2YUnlV50vRkkpVJ/LbLZRRiFoZV+r5p0oMjojbYbTtiiFtYJvaWDNFdBrJVC5O zXJTTrFrspVWfasH+uLbUQegFc1eDBgGCtoEXLkEhoByp7qcz7lwK7NROHKSDxGQcWU/ rQe453S2AVwU7nUuaT7Ogwi0yaafjmLsSniQKPenSKTvmI5APyvFmW2MjFo4ac8ky9dL NTNrhceHavXazH1GAToTE52b+FG6AQOccxFzP9DXapo2S849KN3iT8Ug1geC4/ldvj5p ByyQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=gXy/Yz4KCId8SFCAfrVNi5PuBJCfR9XEK9tE4hr3UMk=; b=DNbOoewyqSoExhB3eP7Pglbbcv6e8BdPIeck3PnT2wv3n9h8wyTdYkC7WATZT/9nob Y4gm4czfVMAIZ8eCJTdJqIqJMQtx5GuuvCRD/rkLv5sMRbGovtHYlHwrqbfN6EhJ+yrq I0VhC2hwLB5w+dNGVgnUgPF5/pLmjVyrGedtucRRNtvk4ieyZ42yHkcl//NMkW0XRfSl g7euHSN974YC80wvCfX6nvB9CyP9KH89MgXxoCtR2wiODsvXQ+eRJFeafXSq63lFFPzv GFgREvJMuP4jyd3v6Ze2attQAQCPEPcKNMgs4Z/NlH48IoHIL60sagAGO0oizI7kh5aR Brsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="fp/zwUlI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a056a001a9000b00522c9732f7dsi12145388pfv.322.2022.07.05.08.02.45; Tue, 05 Jul 2022 08:03:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="fp/zwUlI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232480AbiGENv4 (ORCPT + 99 others); Tue, 5 Jul 2022 09:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231788AbiGENve (ORCPT ); Tue, 5 Jul 2022 09:51:34 -0400 Received: from mail-m975.mail.163.com (mail-m975.mail.163.com [123.126.97.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B546223BC8 for ; Tue, 5 Jul 2022 06:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=gXy/Y z4KCId8SFCAfrVNi5PuBJCfR9XEK9tE4hr3UMk=; b=fp/zwUlITCGkn7mKyHq76 3krFugiAzVymSNKB6opO8r/aqqAyx0KMRPca+hoLlf7cD0vyKh3WvQixS6wt7Hu+ StnA0YOMVgm4NIf7pn3PqgsfLAKdAvoeYNclnWAJcPpN8OpiIDc1U5AImG+CbnyU x6VAsFgL4FQSIbf8K3VHRQ= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp5 (Coremail) with SMTP id HdxpCgBXgTLcO8RiQtNIMg--.52057S4; Tue, 05 Jul 2022 21:25:55 +0800 (CST) From: Jianglei Nie To: bskeggs@redhat.com, kherbst@redhat.com, lyude@redhat.com, airlied@linux.ie, daniel@ffwll.ch Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] drm/nouveau: fix a use-after-free in nouveau_gem_prime_import_sg_table() Date: Tue, 5 Jul 2022 21:25:46 +0800 Message-Id: <20220705132546.2247677-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HdxpCgBXgTLcO8RiQtNIMg--.52057S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKFy7tFy5KFyfJFWrJF47urg_yoWkXwb_ur yxZFnxWw1kKFs8ArsFy34UAFy29ay8XrWkuas2qF95t39xJr1ruFW7Zr18u34kurWIgr9x G3Wqvas0krn7WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRGsj8UUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbBOQM1jF-POWd5wwAAs3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/gpu/drm/nouveau/nouveau_prime.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c b/drivers/gpu/drm/nouveau/nouveau_prime.c index 347488685f74..9608121e49b7 100644 --- a/drivers/gpu/drm/nouveau/nouveau_prime.c +++ b/drivers/gpu/drm/nouveau/nouveau_prime.c @@ -71,7 +71,6 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev, ret = nouveau_bo_init(nvbo, size, align, NOUVEAU_GEM_DOMAIN_GART, sg, robj); if (ret) { - nouveau_bo_ref(NULL, &nvbo); obj = ERR_PTR(ret); goto unlock; } -- 2.25.1