From patchwork Mon Oct 24 11:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp642978wru; Mon, 24 Oct 2022 13:40:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nOMqP2FWE74310CE2JNE0mw+oKcdYpRrbcMZMbeuQp2iSmri5E4tBAWiTGR/4rGQGfmRy X-Received: by 2002:a05:6402:440f:b0:435:2e63:aca9 with SMTP id y15-20020a056402440f00b004352e63aca9mr31539419eda.162.1666643918987; Mon, 24 Oct 2022 13:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643918; cv=none; d=google.com; s=arc-20160816; b=wSFZDaidpkz07a4D+Yn9qoGaCHm5VEQRplHkJdJXX80KnieaZ04YoTmGHB2EjcS1km F7TlxMQ0YphRxbp8gES363B1MG6haTHW3qVwFv2T+k2kMeTs/xdkQ3/A0r+/V5jInT9b FqhZXqPORz/im78O3uspQue0aRYDp8A0ZtTYVMgHy7MS2g2TaDmHRQsiIh7ri/zkQ1av YukEHQf2el6vvCYZZ9RiicqIiHeJ3L37U/I+iDZ1T0+bPdaxiWjqg/41XDk20QRSBB01 UDbL3OozP85AqtxTG1mIfBuG+hA2a1WhdbnzxzzqJEmLWLPqovyRYk4muIqhLaD0sKNe rGLA== 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 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.38.10; Mon, 24 Oct 2022 13:38:38 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747602814152766282?= X-GMAIL-MSGID: =?utf-8?q?1747602814152766282?= 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; }