From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeremy Cline Subject: [PATCH v2 0/3] drm/nouveau: fix a use-after-free in postclose() Date: Wed, 25 Nov 2020 15:26:45 -0500 Message-ID: <20201125202648.5220-1-jcline@redhat.com> References: <20201103194912.184413-1-jcline@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20201103194912.184413-1-jcline-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org Sender: "Nouveau" To: Ben Skeggs Cc: David Airlie , nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org List-Id: nouveau.vger.kernel.org This series fixes a number of use-after-frees in nouveau's postclose() handler. It was discovered by pointing IGT's core_hotunplug tests at a nouveau device, but the steps to reproduce it are simple: 1. Open the device file 2. Unbind the driver or remove the device 3. Close the file opened in step 1. During the device removal, the nouveau_drm structure is de-allocated, but is dereferenced in the postclose() handler. One obvious solution is to ensure all the operations in the postclose() handler are valid by extending the lifetime of the nouveau_drm structure. This is possible with the new devm_drm_dev_alloc() interface, but the change is somewhat invasive so I thought it best to submit that work separately. Instead, we make use of the drm_dev_unplug() API, clean up all clients in the device removal call, and check to make sure the device has not been unplugged in the postclose() handler. While this does not enable hot-unplug support for nouveau, it's enough to avoid crashing the kernel and leads to all the core_hotunplug tests to pass. This series reroll addresses a missing mutex_destroy() call and a typo in a commit message. Jeremy Cline (3): drm/nouveau: use drm_dev_unplug() during device removal drm/nouveau: Add a dedicated mutex for the clients list drm/nouveau: clean up all clients on device removal drivers/gpu/drm/nouveau/nouveau_drm.c | 42 +++++++++++++++++++++++---- drivers/gpu/drm/nouveau/nouveau_drv.h | 5 ++++ 2 files changed, 42 insertions(+), 5 deletions(-) -- 2.28.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FDE8C56202 for ; Wed, 25 Nov 2020 20:27:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9756E206F7 for ; Wed, 25 Nov 2020 20:27:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bi3YK0Mx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9756E206F7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E0B56EA80; Wed, 25 Nov 2020 20:27:11 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A77D6E902 for ; Wed, 25 Nov 2020 20:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606336028; 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=vosBqspdw7JmFXivYdUDySO0pSWDCWmE9V9Dch1o6C4=; b=bi3YK0Mx8gJaGkzt1q56wetsmkVq99HEJuau6bmhesNZv91qadpuWClIpJImxArxNrDzHv enyMhE0mhW7AtJJidQ9OBSBxWZV5kqjkGJg646U90BlX1/bpGqnasNDl6BZF6oFldo2kXu 9RNSBRc3HULOU/oRByopu6sUv3XS5a4= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-LvYqnrOdMdCpff8O5jqMIQ-1; Wed, 25 Nov 2020 15:27:07 -0500 X-MC-Unique: LvYqnrOdMdCpff8O5jqMIQ-1 Received: by mail-qt1-f197.google.com with SMTP id 100so3261277qtf.14 for ; Wed, 25 Nov 2020 12:27:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vosBqspdw7JmFXivYdUDySO0pSWDCWmE9V9Dch1o6C4=; b=UFDJOY874Bgd0LPK26ue5L/Hx+Q004/TdiLE39mfqAUuTcDeW2/Bl3ABe54wx2fV0K D+pfwAN73Sp+2BwiLLrE3CLlWo2+j7XWBY0c+jGjleHgqYU88bCByUdK6qvRDGrAp0K9 eg3FEymXRvUMQiS1VCoTreGnrlmwC+ccEPQl+9vzNs5sxFL8BZtHymZcthqhMkHASWKR 33hLjFtooDQktRPNpLJl5S+p8IOCwISiMRTBghU6CUDAI4vn1SPGs07UCphPCdCFHUcj Ia63GSPSLuyZGPee1gzFauLeBJ9ApZpxlXFHgVuzz+Mj4tATOaBl16n/cKlwjO8SrrJM BRtg== X-Gm-Message-State: AOAM533SXJbssOKkVMAKwSXqjx6gChCZngKmbmtc8urJd6/JkvE5V5/x xowtWs9zNJ9RQfZVzCW8rctSi6U0C+pF8ZyF3+AiM2FApyOm6Ku8UKjPdw6hc454CqeAVkelkV1 NaxxD4lK0Rd6zMdwP9vpgwv5vV9SK X-Received: by 2002:ac8:ec8:: with SMTP id w8mr621876qti.371.1606336026759; Wed, 25 Nov 2020 12:27:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyT78zpa38ZcqRtOpdxdblr3H4mlGuN8etlAySSZYr1uSsG5rPx8jYrid33ovUycVEA93aYXg== X-Received: by 2002:ac8:ec8:: with SMTP id w8mr621855qti.371.1606336026552; Wed, 25 Nov 2020 12:27:06 -0800 (PST) Received: from dev.jcline.org ([2605:a601:a638:b301:9966:d978:493:6a3d]) by smtp.gmail.com with ESMTPSA id o187sm431772qkb.120.2020.11.25.12.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 12:27:05 -0800 (PST) From: Jeremy Cline To: Ben Skeggs Subject: [PATCH v2 0/3] drm/nouveau: fix a use-after-free in postclose() Date: Wed, 25 Nov 2020 15:26:45 -0500 Message-Id: <20201125202648.5220-1-jcline@redhat.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103194912.184413-1-jcline@redhat.com> References: <20201103194912.184413-1-jcline@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jcline@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Karol Herbst , David Airlie , nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jeremy Cline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This series fixes a number of use-after-frees in nouveau's postclose() handler. It was discovered by pointing IGT's core_hotunplug tests at a nouveau device, but the steps to reproduce it are simple: 1. Open the device file 2. Unbind the driver or remove the device 3. Close the file opened in step 1. During the device removal, the nouveau_drm structure is de-allocated, but is dereferenced in the postclose() handler. One obvious solution is to ensure all the operations in the postclose() handler are valid by extending the lifetime of the nouveau_drm structure. This is possible with the new devm_drm_dev_alloc() interface, but the change is somewhat invasive so I thought it best to submit that work separately. Instead, we make use of the drm_dev_unplug() API, clean up all clients in the device removal call, and check to make sure the device has not been unplugged in the postclose() handler. While this does not enable hot-unplug support for nouveau, it's enough to avoid crashing the kernel and leads to all the core_hotunplug tests to pass. This series reroll addresses a missing mutex_destroy() call and a typo in a commit message. Jeremy Cline (3): drm/nouveau: use drm_dev_unplug() during device removal drm/nouveau: Add a dedicated mutex for the clients list drm/nouveau: clean up all clients on device removal drivers/gpu/drm/nouveau/nouveau_drm.c | 42 +++++++++++++++++++++++---- drivers/gpu/drm/nouveau/nouveau_drv.h | 5 ++++ 2 files changed, 42 insertions(+), 5 deletions(-) -- 2.28.0 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 350F1C56201 for ; Wed, 25 Nov 2020 20:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE987206F7 for ; Wed, 25 Nov 2020 20:27:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ctQ118Eu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729340AbgKYU1K (ORCPT ); Wed, 25 Nov 2020 15:27:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60027 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbgKYU1K (ORCPT ); Wed, 25 Nov 2020 15:27:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606336028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vosBqspdw7JmFXivYdUDySO0pSWDCWmE9V9Dch1o6C4=; b=ctQ118EuOGio0oUVlLHD9Ym1fCutQXFJXGtgmQKFbTbAQyuSDu7iG5jGJLqgH1XFrqRoeS Y7ZziBkWSLwHicNpD1W67GWk2zvjR9W23dTJi7fmrt8ROUv/39tjrE+5ugfV2z53j/4xzA e8rgXJoa663VqGw6uMwT6XyrKCA6c3g= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-pPqC7REHNaa1stUMJZsM6A-1; Wed, 25 Nov 2020 15:27:07 -0500 X-MC-Unique: pPqC7REHNaa1stUMJZsM6A-1 Received: by mail-qv1-f69.google.com with SMTP id i11so2090181qvo.11 for ; Wed, 25 Nov 2020 12:27:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vosBqspdw7JmFXivYdUDySO0pSWDCWmE9V9Dch1o6C4=; b=L/aqq/4Qn19EyECv8n8ZsUGhmbsGsBrcf3452qNkjhhQ2QTYkUgqXHCZW0y5004AvI 2ZamtRyaY/h6MxeCNGBQdtpfakRy57pr2xbfm1dFAJwVrAI3CUabT9mEiFS6wEgS/lLE KCDmojYV6HZmtCYTQDBXeV8iy8X892wz/K52PsCsyr2a33W3IXNKJ6XOeJ0rHwgW1InO lVR7k3yTa49SEkaoFUAdKOsGulz/QyGbVgdQBiEzcn7eMrPfQd9Mw8QPgVyixKXcEvuf i9ZDCNZHOWtSOYEx64THsL+jh69qINsqyPaUPycnj8b/r4PImeSLXjKY+xbC8Q4+qc9h 07oA== X-Gm-Message-State: AOAM531m/R2wDWgNzSjPaCtCEwqBmNrll5Xa0t2ShB7xsx8wVkQGi0PH VKBvxyY0eoGNwwy5CofQtHGpgggasCfmiwjvNmMo8LTvgGKpJSytOkXrRu0lWHcSMX71tG5UGx7 yzhwxFQgGFPLD4KL9NDwrg+Ed X-Received: by 2002:ac8:ec8:: with SMTP id w8mr621872qti.371.1606336026756; Wed, 25 Nov 2020 12:27:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyT78zpa38ZcqRtOpdxdblr3H4mlGuN8etlAySSZYr1uSsG5rPx8jYrid33ovUycVEA93aYXg== X-Received: by 2002:ac8:ec8:: with SMTP id w8mr621855qti.371.1606336026552; Wed, 25 Nov 2020 12:27:06 -0800 (PST) Received: from dev.jcline.org ([2605:a601:a638:b301:9966:d978:493:6a3d]) by smtp.gmail.com with ESMTPSA id o187sm431772qkb.120.2020.11.25.12.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 12:27:05 -0800 (PST) From: Jeremy Cline To: Ben Skeggs Cc: Lyude Paul , Karol Herbst , David Airlie , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jeremy Cline Subject: [PATCH v2 0/3] drm/nouveau: fix a use-after-free in postclose() Date: Wed, 25 Nov 2020 15:26:45 -0500 Message-Id: <20201125202648.5220-1-jcline@redhat.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103194912.184413-1-jcline@redhat.com> References: <20201103194912.184413-1-jcline@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series fixes a number of use-after-frees in nouveau's postclose() handler. It was discovered by pointing IGT's core_hotunplug tests at a nouveau device, but the steps to reproduce it are simple: 1. Open the device file 2. Unbind the driver or remove the device 3. Close the file opened in step 1. During the device removal, the nouveau_drm structure is de-allocated, but is dereferenced in the postclose() handler. One obvious solution is to ensure all the operations in the postclose() handler are valid by extending the lifetime of the nouveau_drm structure. This is possible with the new devm_drm_dev_alloc() interface, but the change is somewhat invasive so I thought it best to submit that work separately. Instead, we make use of the drm_dev_unplug() API, clean up all clients in the device removal call, and check to make sure the device has not been unplugged in the postclose() handler. While this does not enable hot-unplug support for nouveau, it's enough to avoid crashing the kernel and leads to all the core_hotunplug tests to pass. This series reroll addresses a missing mutex_destroy() call and a typo in a commit message. Jeremy Cline (3): drm/nouveau: use drm_dev_unplug() during device removal drm/nouveau: Add a dedicated mutex for the clients list drm/nouveau: clean up all clients on device removal drivers/gpu/drm/nouveau/nouveau_drm.c | 42 +++++++++++++++++++++++---- drivers/gpu/drm/nouveau/nouveau_drv.h | 5 ++++ 2 files changed, 42 insertions(+), 5 deletions(-) -- 2.28.0