Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3881161rwi; Sat, 22 Oct 2022 01:28:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4HTHhdrClm1Ywkd0tQfntg7Y6FwXeps/i/iDkSQhfx3e2jKVe/u8Pn6gdP4EhUm+O+8RVW X-Received: by 2002:a17:90b:1644:b0:20d:459b:9d81 with SMTP id il4-20020a17090b164400b0020d459b9d81mr26563050pjb.196.1666427313965; Sat, 22 Oct 2022 01:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427313; cv=none; d=google.com; s=arc-20160816; b=Ckwyra9WX/B4noQ9Sg9T4rsM5ziNn7fwRdEUNJq0slhxUR/Tr4/3Nk3+2YvAcy5YM9 E6/nUsaG4+bWRSwhr5lD0QijUPHd79HeSkg80ypzXx17b0BqzhHTlq6Tskre2Qsr0cJE S+JFVBhzWm8C8CSxveSbZ2GnWsp1EpJrCGT1qxmXA4mBPgVz0vIhwu9pmunbIOhqU6yD ZrWjc69Us6gSl4w0ZQfEdfjibpiYXQxSIrcZIOfjrfgarV1qcCLaz6G+SfQf3KUGoE0I fVPzLaGHmzs8YhGbb1A3AAQF8OMoUj/esCt57tr4gDfJQ3AbvRFS7vDPYtZji4Uozrpk znIQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j192-20020a638bc9000000b00462c469b730si27353032pge.648.2022.10.22.01.28.21; Sat, 22 Oct 2022 01:28:33 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; }