Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7368984rwi; Mon, 24 Oct 2022 13:39:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7cEXdHA9XPVpOXOrMhRlsHKz01qaMnIfKM+qNmzUPcl7kzH6LHgHDWh1K0ZegbfyslrWDi X-Received: by 2002:a17:906:8457:b0:78d:b793:5511 with SMTP id e23-20020a170906845700b0078db7935511mr29019506ejy.393.1666643969387; Mon, 24 Oct 2022 13:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643969; cv=none; d=google.com; s=arc-20160816; b=zHo8cyBhVKTBLBR+i2yA8blFteHOEO6d0zMS2n/51/s1AHAxqMVDH9+3XBOoL8FK39 /ntpkp9a8krshKKvaS0OF8vzbk7UD017CcMZSOjXFpbZbJD9aLsjfEm3JSwh7ez8N4E0 6Mut4KK4tbG/OOgpmlC2vIJYsiax7OLletq4dH1Hm1SYTMEtvwtRag+ShoaNVBeXd2q+ EaZ+4f6SzfIXDgaeMXa06bgDKgLtMrpzB+gYusq+YFJOegtKNsbhMMgLSyrhQVc/sICh mKIa0d3AcKEFop8ljW5noKpFaCsIOZX473gRPxyZdaC0/I74Jg79efU2hgVlkRbV9XOh lVRw== 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=EhEpLBwEPkfop66jDBN5rBKzoJ28+Ssv1y7gIb05C80=; b=iVSIjkCbEI99DpM8R26YLWn5ud9L27CrLA/XQZRkpplfMPqK1YGqzdPTfxevXVsBBh vzpN3vsTpK3Ee1f6GYNrAlB9/RK4Kr5tTzFDh5P0uL4lzNHSjEi+WkTOEF7Z3l5w+q9C EpgtZTBgFjfXO1NhdJY71YWET/iJ3p6+kGFYnnTrfdQvWfawTVVpjKAJLWwhrMQQSowl K3qqgm19RR8LXc/yC+cmpI80YgZS/kv1h1s6/lx+F6wg9MAEniboF3VI9mx4wRKcn+7H OR8mrNjVd+FMC2tuaZZH0N/n0dCztiVQSIZNhvNyat4nqUTwBFqinVgrBPrmd/9x5Ixx 8QNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ENc/ghuX"; 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 y9-20020a056402358900b00458d1c48708si816576edc.303.2022.10.24.13.39.04; Mon, 24 Oct 2022 13:39:29 -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="ENc/ghuX"; 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 S234398AbiJXUgp (ORCPT + 99 others); Mon, 24 Oct 2022 16:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbiJXUgO (ORCPT ); Mon, 24 Oct 2022 16:36:14 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51EFD11A94C; Mon, 24 Oct 2022 11:47:53 -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 sin.source.kernel.org (Postfix) with ESMTPS id A884ACE1361; Mon, 24 Oct 2022 12:21:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2A3C433D7; Mon, 24 Oct 2022 12:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614061; bh=eVeasfURuMgmaTvvToTss6SexbhGhp6bCKFrrjPznQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ENc/ghuXYOmQuslo5vEbfLIFNnbAUyIdP6ltAktPYGVwKZBZFY+m/PclSdEQv+SgR GKJrVh0g0+3ZruQGthTZbco9DnmvADvcyPdvx6HSswH5kmKVEUIWzoyHYh8Z9XZb1x eA6PwycAA6Q9aKd9mJJut/G12nmLcT2QGaloFTJ0= 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.10 087/390] drm/nouveau: fix a use-after-free in nouveau_gem_prime_import_sg_table() Date: Mon, 24 Oct 2022 13:28:04 +0200 Message-Id: <20221024113026.324682327@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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.6 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 @@ -89,7 +89,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; }