Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4110417imw; Thu, 7 Jul 2022 12:57:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vRYtgVXEHxdao4wgOxWw8lmx4Tv1bHZwmkxuBZ0bXtqfIuL6vIZOX3ZEKx6cNqpRsAaPRP X-Received: by 2002:a17:902:f688:b0:16a:81d4:17e0 with SMTP id l8-20020a170902f68800b0016a81d417e0mr55542178plg.174.1657223861909; Thu, 07 Jul 2022 12:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657223861; cv=none; d=google.com; s=arc-20160816; b=TRImsBazECTiJu4nOC3p/rYwHOy58MPa1t637d+5ls15HdBBphym0y9rkj88T2S8+c CXBOq3BIbMc9OjV29plM0ZUb9FXxEv2F1v2bChHTfgTENxylbT4V/OOpTfqrqT8SrR4A mqo7qO0S6NXYlmrWyxd1GL2h22taleuniCkQLHt6RdQnDquDVTrkMELhm8u+PRK9mqG9 Tjtmf6+MKddEFTl7IVsW4RXjr+aG+SUN7e3IlsFwqPC6rgMhYuNB6v0ShnEkJH+023yW fAb9e/uF9hKpBshHfGRsw8bZj4dI521bhtiVJYhI+OQhVYqQiDZilCEkR7esQlbSp7aE ZTBg== 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:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=b/09duIaIEFfbOfOoFpBzJ/OHB5C+OhETNK1haqEKUI=; b=UMX+A/eO6KtYxEX58IwRmgVyaQ9UsRV2ZGw78szz7v9WHAL1vW3F463PTg/ZA++KAh 6QSpnGkBRN6N57ZvC5ZKUQbmSivInnaaqEb93zC3FZaLoD2KbYd1Ym60dbU7+Wkm+EpI mTcOInV+G8VOn+TCHp76vmeXzy86idlaj/8s/jIFb9Vo8NKK65c+mROMm6tq4zi3HlyU FK2Sq8yMsxTf+VdZ4JRyyHHnGAhWfJugV3f6XuW9One51+3H5nAzkFZdc2ReT8hhr8FC HKyZ01gnTDg8mlf1NTydIsA6iFHeMG5IncS5yu56xWaFs/tkRuwQ6tYhVR1nMoI9UAtM Plkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JssJj4Od; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020aa78884000000b005188ba74699si1726615pfe.196.2022.07.07.12.57.28; Thu, 07 Jul 2022 12:57:41 -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=@redhat.com header.s=mimecast20190719 header.b=JssJj4Od; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236631AbiGGTtV (ORCPT + 99 others); Thu, 7 Jul 2022 15:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236629AbiGGTtS (ORCPT ); Thu, 7 Jul 2022 15:49:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6CB0CE083 for ; Thu, 7 Jul 2022 12:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657223355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b/09duIaIEFfbOfOoFpBzJ/OHB5C+OhETNK1haqEKUI=; b=JssJj4Od/GVA/d2hi3cXTasM9SCztaB0WtIBuxDGQdQ2fnOrwy8kHEn7twFQhdQVhPThK3 14dIbYqRpGXi314qZkMAA0KSrZ7A38iW4dVJuLHFN2HOfzFhNbLMxjJoMiditFoF7KifSE u0BVR04sYXs+Peap+MOo6m8woP/rNxI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-tVX5ULRyO8yPU7Pd4PZbiA-1; Thu, 07 Jul 2022 15:49:14 -0400 X-MC-Unique: tVX5ULRyO8yPU7Pd4PZbiA-1 Received: by mail-qt1-f200.google.com with SMTP id fw9-20020a05622a4a8900b0031e7a2ed350so11061379qtb.0 for ; Thu, 07 Jul 2022 12:49:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=b/09duIaIEFfbOfOoFpBzJ/OHB5C+OhETNK1haqEKUI=; b=NFnmQ1dzRaYAMsK3OPDyqEi9BuOnJfnMEhInBGCdrMz4ptUIJasgJVMZmGSItKlwTb fK8KR8CpDCoX2sRyOvxf9cdp/wn0MQ9Djg8k0ugqneUDx/elWt/FX2Jy1U9UnrGWVtZd tAnChXAxKAN1i6r26YYg7+LTRn0XwqAlAjAH7G0kEehW0/fltgdnPT032PZ9FRrbFwAi 3a2Bd4CDsn5hEChuw4yhlWWIOqI45tYEnY+TU3N+pdrEMgtgqLU9YSaoo4UFn6tWuwsT ExVnc4y6yclZXZ50GVrVLF7jjVUChWFOqF+lBrC60HmWODEIWhFoG0IWMItRvQ0F3OUU H+8g== X-Gm-Message-State: AJIora9iUQqGVTJ9bDuoL7RCgZIeWo4d1VKVl3cxr8jhw23adcL64LA5 kG3hy+Nv6uivd3k+0r3z3qi7LNum62tGDLYn81tj5tKLLCA0eAjdGCRqsKBF3p4c95AJDGHVwLS TEA7Xl3GvhZsc1YisRYPkYExy X-Received: by 2002:a05:6214:2027:b0:473:2d58:7ce9 with SMTP id 7-20020a056214202700b004732d587ce9mr4481194qvf.107.1657223353553; Thu, 07 Jul 2022 12:49:13 -0700 (PDT) X-Received: by 2002:a05:6214:2027:b0:473:2d58:7ce9 with SMTP id 7-20020a056214202700b004732d587ce9mr4481163qvf.107.1657223353007; Thu, 07 Jul 2022 12:49:13 -0700 (PDT) Received: from [192.168.8.138] ([141.154.49.182]) by smtp.gmail.com with ESMTPSA id dm15-20020a05620a1d4f00b006b555509398sm1582726qkb.136.2022.07.07.12.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 12:49:12 -0700 (PDT) Message-ID: Subject: Re: [PATCH] drm/nouveau: fix a use-after-free in nouveau_gem_prime_import_sg_table() From: Lyude Paul To: Jianglei Nie , bskeggs@redhat.com, kherbst@redhat.com, airlied@linux.ie, daniel@ffwll.ch Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org Date: Thu, 07 Jul 2022 15:49:11 -0400 In-Reply-To: <20220705132546.2247677-1-niejianglei2021@163.com> References: <20220705132546.2247677-1-niejianglei2021@163.com> Organization: Red Hat Inc. Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 Reviewed-by: Lyude Paul Will push to the appropriate branch in a moment On Tue, 2022-07-05 at 21:25 +0800, Jianglei Nie wrote: > 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; >         } -- Cheers, Lyude Paul (she/her) Software Engineer at Red Hat