From patchwork Sat Oct 22 07:20:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1092045wrr; Sat, 22 Oct 2022 00:52:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+Qd74VHWazE/zrCnwN3wWN+O0BV327m7EXLTQoc8YqBh3C4ZnegVv1/Fe+GnctbOWDVv6 X-Received: by 2002:a17:90a:540e:b0:210:1e26:9422 with SMTP id z14-20020a17090a540e00b002101e269422mr18264591pjh.100.1666425167925; Sat, 22 Oct 2022 00:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425167; cv=none; d=google.com; s=arc-20160816; b=0UwnXJGz7ZjhOqVebXC1dm4uJJkanZCMKSvUJtwCFXwiJLBufSsE9HBsQEM4Hvb96O AubxVIb1TZf+OuwkdYcyDitRhnCd5C4XlN5bMQp4IVbOn/7nftdWf7COjQkCnCp94Aws vwQ/+YyzTUrlTTK8nZ3FiMWt5vzBQXc9q91OmMJzWAGvLVP5F11zIdjXjbkvVLI/hA4f VL813duPx7CS8ygdBjt3hDcJenZPg/gPLa5gRyH/zuyWZho/HOsQ7GiQ5SaJaZeOFFDv Ryeahxc4WMjrfIi8OJDZsgYEsL6FfWuPyDu/uiuTtWUzJElWmVTksBVee+S3dS1bD7nE aBGg== 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=ywnzyajHVH5P4coVgM62eanHHKFBJKO0DVFgQNg3oTM=; b=J0y0DLj8PT3VMm3PyVNwHFX4myayZqemRFTwLazEJVWKBL6VtbjHIoR1w08KzAp/lP x1TpVKrx5Pvr+1n2bOMXqbKz9Rl6HVzji7VTUSVXp0w/PoB6A/NvTQqd7i9qq2+0I70S pePoccjUbYtkJXZpLprVz4UUcKOLUe8ayXTHbRGa2T2+oKTu6Rkzb90WH7y3pcTc7AoK ettLiuquHg1rWbR8YXDH9+hd38ecTwnHzT9qo56XS1Ey8HippAYFhP9NAF36rQtmKJ1y 7wouwFbt6fXErgCsMC/m9wdWTXwJrSf6JhpjCAzol4kMfDVDztGCwu706QFW27TihGJd EtpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dOz2zUuV; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a630408000000b0043090081d69si5064694pge.82.2022.10.22.00.52.35; Sat, 22 Oct 2022 00:52:47 -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=@linuxfoundation.org header.s=korg header.b=dOz2zUuV; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231732AbiJVHwQ (ORCPT + 99 others); Sat, 22 Oct 2022 03:52:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiJVHtf (ORCPT ); Sat, 22 Oct 2022 03:49:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650672ACBE1; Sat, 22 Oct 2022 00:46:04 -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 6655360B95; Sat, 22 Oct 2022 07:42:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79CCAC433C1; Sat, 22 Oct 2022 07:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424573; bh=KqCEdkhPcHZPtHS5XUueyb73weNWSVVYIaiahVplhzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dOz2zUuVoAHgieaTu9lB28yF3OskU6GqEKbgU+VE39OXN54ffSzVRRzx1c88BjrDb e7hbFrmeS9nN97ZePN7nw12ogHJbrhWg2QPj9/wW7W3Ib6ur6Of8hlz5pz44jq0XxV CmpsSYxZXh3hZoQb/8F88cm0SdzhxdVNYsUk6ERQ= 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.19 166/717] drm/nouveau: fix a use-after-free in nouveau_gem_prime_import_sg_table() Date: Sat, 22 Oct 2022 09:20:45 +0200 Message-Id: <20221022072444.854325770@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373437141628541?= X-GMAIL-MSGID: =?utf-8?q?1747373437141628541?= 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 @@ -71,7 +71,6 @@ struct drm_gem_object *nouveau_gem_prime 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; }