Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1776526pxf; Fri, 26 Mar 2021 14:44:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEmyuG/Wy8BAcLrWBObc5NeYKU0bYq5Vlwjbd308FPW+0dErFxQ8EdVUqTmKASxFdJOBoK X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr17388211edb.204.1616795088669; Fri, 26 Mar 2021 14:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616795088; cv=none; d=google.com; s=arc-20160816; b=SieSc9k0EjFDhzDlMJHiXntem8ByvMafraHNDs3GI+tDX0VQVY5tqq/KyokDhRStYY eLo/9FgN6RuXP46JG54bajPIoUDvnj/b4FY1wToZY/jGPBRUdRr1Y5908u4b87kKpgh3 ti8Ix/9wszjhPowJZFKwBSvBt8yBnemlrEqYDrIGGckoQ2UDmG4N0LH33QfVyB5ONNS3 hYO8p1H0wuerrWwxTKnvjcbqrn781DrykZrAsCn+reUkXX3UfVv+ZXNIN3o2naTu4mVd 5VTjuGRv7oPrFCeB7mO/PBjghiQZCNB/oZg+TCRSbicJjvGM88/N5Nc2RV5SGc0IOO+7 VFLg== 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:reply-to :from:subject:message-id:dkim-signature; bh=2KYq2FimxUUOirhAHH7Y6K62w8Nvf75VdOPqqjNoVNY=; b=ZpISsxXPXprlyAfReopQV8+fv0sffQvCFm1aVHL1H+2tb9e9iqC7MI6iIp+rgAp0lP IWl5DCykjCPwUkfx1TfW/hMNpm3MDMNNM+V/K7CNyTb7hO+0+rwT5L9p6Vq6dn0hLNCz dZaZ8oFC1jfOA4Hq88KeERRxFFNPDi6dlIoOb21GDPIu6CD7H+p/DV86u4cVIa3wAuuP DivwMItH5WoFVikEPxo50XgIFtjCkdXosuir7ZB6sLtDiw9VCfIbL3iqeSVbB+D7yUCs PUmtld1RrKel39BZpXkWm5JhOOoFIguwVN6FTKhLDgJEdRV8sicttF1tc85jTslu/ugg SZbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P568CWIA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si7807778edr.603.2021.03.26.14.44.26; Fri, 26 Mar 2021 14:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P568CWIA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230139AbhCZVl1 (ORCPT + 99 others); Fri, 26 Mar 2021 17:41:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29297 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbhCZVlL (ORCPT ); Fri, 26 Mar 2021 17:41:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616794869; h=from:from:reply-to: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=2KYq2FimxUUOirhAHH7Y6K62w8Nvf75VdOPqqjNoVNY=; b=P568CWIASQHyVW765vVDWKQJdZRpEbzxzylzNY8K7gejdzKWiUWAm9bMHRo1/zIObfzsoI 6ZKKgSeeZQAw+44y0SpcN9usokON9TFKb38WtC9MoB3xLGLTKEHT2W+v0IR22f6S4iEimo 6cxEiL60B+iKaY+zp+7a6x12mMAZFfA= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-380-lTENdUMjNESBc0CIb7npVQ-1; Fri, 26 Mar 2021 17:41:07 -0400 X-MC-Unique: lTENdUMjNESBc0CIb7npVQ-1 Received: by mail-qk1-f200.google.com with SMTP id y9so7139206qki.14 for ; Fri, 26 Mar 2021 14:41:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:organization:user-agent:mime-version :content-transfer-encoding; bh=2KYq2FimxUUOirhAHH7Y6K62w8Nvf75VdOPqqjNoVNY=; b=HmuJZOFzE624Frm0K0rDZ9cknYVRVUsxOD33T5lRqWnSFQqfEER6BLN3smxnw6GC+q 4rc8YOQDaoJb0pS+ywIswgS7/D8cs1aSVFxtSgKj5DvQ2Dmn7wDReRpbA5nmjLzTdGSl gGTv83Sq1Hilzwxp8jDWEIWpyF+JZ6h6Ospq1E6OBNLogo4BSFYaO8xqQ6BD8S+g2/qB FOw/giZ9Ziuc77fGp7M9wEXocCFmB3w44kjUGeXGFFc9ekevM4bnHXH7+WxSsS6ke67k f109+IXPvT7nVON7gd4U1yrkVWccVE9OMPg3/Ikjj0iVYxpoK9Krju2h/GWi5OlRO10/ Ki4Q== X-Gm-Message-State: AOAM530Zx2YY5AZC/x35wdU4KFKaNlkpBbL+dZbNaNyI0DGrXUOY2o2E 2T2RDWhEWKcn7tKTmuMnd0HRgTMS0GaTY0ukT2zKNlPrb8EoTpGDdUmNEiVTM0Ft2vDbN9QNfe+ saiYgPNbcy4szfOZLr01v7lwN X-Received: by 2002:ac8:6789:: with SMTP id b9mr13776310qtp.103.1616794866613; Fri, 26 Mar 2021 14:41:06 -0700 (PDT) X-Received: by 2002:ac8:6789:: with SMTP id b9mr13776303qtp.103.1616794866456; Fri, 26 Mar 2021 14:41:06 -0700 (PDT) Received: from Whitewolf.lyude.net (pool-108-49-102-102.bstnma.fios.verizon.net. [108.49.102.102]) by smtp.gmail.com with ESMTPSA id l9sm6725962qtv.65.2021.03.26.14.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 14:41:05 -0700 (PDT) Message-ID: <7f51dbe3dac85f692e01bb5cecdf4454a40b1893.camel@redhat.com> Subject: Re: [PATCH] drm/nouveau: avoid a use-after-free when BO init fails From: Lyude Paul Reply-To: lyude@redhat.com To: Jeremy Cline , Ben Skeggs Cc: David Airlie , nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Thierry Reding Date: Fri, 26 Mar 2021 17:41:05 -0400 In-Reply-To: <20201203000220.18238-1-jcline@redhat.com> References: <20201203000220.18238-1-jcline@redhat.com> Organization: Red Hat Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reviewed-by: Lyude Paul On Wed, 2020-12-02 at 19:02 -0500, Jeremy Cline wrote: > nouveau_bo_init() is backed by ttm_bo_init() and ferries its return code > back to the caller. On failures, ttm_bo_init() invokes the provided > destructor which should de-initialize and free the memory. > > Thus, when nouveau_bo_init() returns an error the gem object has already > been released and the memory freed by nouveau_bo_del_ttm(). > > Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object") > Cc: Thierry Reding > Signed-off-by: Jeremy Cline > --- >  drivers/gpu/drm/nouveau/nouveau_gem.c | 4 +--- >  1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c > b/drivers/gpu/drm/nouveau/nouveau_gem.c > index 787d05eefd9c..d30157cc7169 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_gem.c > +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c > @@ -211,10 +211,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int > align, uint32_t domain, >         } >   >         ret = nouveau_bo_init(nvbo, size, align, domain, NULL, NULL); > -       if (ret) { > -               nouveau_bo_ref(NULL, &nvbo); > +       if (ret) >                 return ret; > -       } >   >         /* we restrict allowed domains on nv50+ to only the types >          * that were requested at creation time.  not possibly on -- Sincerely, Lyude Paul (she/her) Software Engineer at Red Hat Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've asked me a question, are waiting for a review/merge on a patch, etc. and I haven't responded in a while, please feel free to send me another email to check on my status. I don't bite!