Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4051165pxv; Mon, 28 Jun 2021 20:39:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4qy0TGloQ8FbmzsvfdWrxkGcPJY0BNs3SibSRNXmq2bOA8l0nCEBVv4hrtN0jaqp/pRGE X-Received: by 2002:a17:906:c10f:: with SMTP id do15mr24523931ejc.475.1624937963920; Mon, 28 Jun 2021 20:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624937963; cv=none; d=google.com; s=arc-20160816; b=Oj5QPagT+AKZ1HS8vEo6gu5a9k/HkfaAFRr3VQfU0NDdmKuFIJrx/KfR9XIr4BeFiC 7CXOOHA92x/dJwt0FUPskgrHYI32jQkSJYruUT55HpM7a2UCiY4MyMsFCbGYxXHorpPp 1d2nAySoCtpEJlkxPlZFr6cxe9gIQ3mupKcU5dQGDMW3wen+C0cUb4fWUj9jmT4sXoLX CSoArfMcrBG7sdVOXvGwGSbsT6sM1z9TjfoVgDY28hCMR8sarSx4QTiXbtTxmSaRyFmg cM0Ow9bG0eckmPYSrHvIv2C6rxvp4gtIRb1eLSUKiQjK9OQR697OVAFCEUrTfGOn7G0O W5CQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=SoUId37plhKw69YuEI1Cyszujv1NEWznJi6ghGYjFbs=; b=E5B1KNalZ8qdjOCNELNGgBv6JOoo6VnZsrmtfo95N94pHL8G7+BOkbv5spZo6WF6b3 KQgBvlKmNujiFL+/85eApSDItZV+j09bc5RVIuYpova7tCC9zQBALdtb0DoDKOvNHfbg V5MdFy3KZMiEkt9P5TSh4aaGbbtCOf+GbtyT4XmBTGfqnBCiUNl/rPE7gbKcOMz8UbCP 3HCuKAn437SMEGhwXDNhwbYra0dntv4u+01vZsvtcmSYEFiiYUAKhmCytO/sngF39rwu 8B7wYkRICzD6OHg7mWH77hJaEe9a4m74El019ZKVDWMpFGDIUHrmCdYZ8cMruuolbXmv PL0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q4pwMkmB; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dq7si13650819ejc.675.2021.06.28.20.39.01; Mon, 28 Jun 2021 20:39:23 -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=@gmail.com header.s=20161025 header.b=Q4pwMkmB; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231936AbhF2DkN (ORCPT + 99 others); Mon, 28 Jun 2021 23:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231925AbhF2DkM (ORCPT ); Mon, 28 Jun 2021 23:40:12 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 329E9C061574; Mon, 28 Jun 2021 20:37:45 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id a7so6549364pga.1; Mon, 28 Jun 2021 20:37:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SoUId37plhKw69YuEI1Cyszujv1NEWznJi6ghGYjFbs=; b=Q4pwMkmBbBzJVT1b3P8AnBDL/42B3X9A/D7gU1OejM4J42zknwsi8d8eqBPCMkZmKy sJaYrk0JWaxJuyUnUgSgD190Jw32kUbkkVU2NQAn5RJqcrnAtofREJnjkc93GG+YyUwi 7anbK5WCVBIta0VcFWtpDL9c8Q1rG8Zwv4aPYbSEPC7RzRrKFnYzmRirgaGRkAO9YCMV eATVF1Q4VbR1RJCaYPy245+oFDC8vCwtf5TEn08HcMWcnLSve1xWUu1ayvY1mgTj7uft TWMlDWWIFY04yug8VS0tJfiIpjWCUMIqBpMuvrnPvYkmkPHjG2li2tt3mWyPwf+ikgov TFvQ== 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:mime-version :content-transfer-encoding; bh=SoUId37plhKw69YuEI1Cyszujv1NEWznJi6ghGYjFbs=; b=SG3O+YPOqN4s6M0ar9t+R6fo3Kb/41/2QsuI9uFUDJOyr9eNQ7Rq1yLrMBK8NHjpZJ BmX9xVWqlJCwb4yySDLYcXTDGAUIUzVRkfLzHQn3XRavR5YJuozB8SkXt9gOaXvqyKLI +qT+yIfb7czQQ9bi8262CezLXZWiKm7UahzdQzm6jfCuP8IS2w+ctBcCjsmALdDNDz/4 4OGn1snA5XssU6ETLNKNQKGXZ5lcF08yYdD/EDFxyKRt5SC89npg1VfCjWPUX4sA+Ung I5BBNU7LxItezJmZjLAZbDLxCJ+GvyJknZh8xLJzS3e2Xrd3eML2x3j8JPWXSap6lDLV L6mw== X-Gm-Message-State: AOAM531rM66UhJzlBRANdwpOTCeS8S69cGQI7SfPskybP1MNs2RNXyfn mTTODsg1uhov3OMOiO/W7TA= X-Received: by 2002:a63:e841:: with SMTP id a1mr26038010pgk.197.1624937864620; Mon, 28 Jun 2021 20:37:44 -0700 (PDT) Received: from localhost.localdomain ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id d129sm14769076pfd.218.2021.06.28.20.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 20:37:44 -0700 (PDT) From: Desmond Cheong Zhi Xi To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, sumit.semwal@linaro.org, christian.koenig@amd.com Cc: Desmond Cheong Zhi Xi , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, emil.l.velikov@gmail.com Subject: [PATCH v5 0/3] drm: address potential UAF bugs with drm_master ptrs Date: Tue, 29 Jun 2021 11:37:03 +0800 Message-Id: <20210629033706.20537-1-desmondcheongzx@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series addresses potential use-after-free errors when dereferencing pointers to struct drm_master. These were identified after one such bug was caught by Syzbot in drm_getunique(): https://syzkaller.appspot.com/bug?id=148d2f1dfac64af52ffd27b661981a540724f803 The series is broken up into three patches: 1. Move a call to drm_is_current_master() out from a section locked by &dev->mode_config.mutex in drm_mode_getconnector(). This patch does not apply to stable. 2. Implement a locked version of drm_is_current_master() function that's used within drm_auth.c. 3. Identify areas in drm_lease.c where pointers to struct drm_master are dereferenced, and ensure that the master pointers are not freed during use. Changes in v4 -> v5: - Patch 1: Add patch 1 to the series. The changes in patch 1 do not apply to stable because they apply to new changes in the drm-misc-next branch. This patch moves the call to drm_is_current_master in drm_mode_getconnector out from the section locked by &dev->mode_config.mutex. Additionally, added a missing semicolon to the patch, caught by the intel-gfx CI. - Patch 2: Move changes to drm_connector.c into patch 1. Changes in v3 -> v4: - Patch 2: Move the call to drm_is_current_master in drm_mode_getconnector out from the section locked by &dev->mode_config.mutex. As suggested by Daniel Vetter. This avoids a circular lock lock dependency as reported here https://patchwork.freedesktop.org/patch/440406/ Additionally, inside drm_is_current_master, instead of grabbing &fpriv->master->dev->master_mutex, we grab &fpriv->minor->dev->master_mutex to avoid dereferencing a null ptr if fpriv->master is not set. - Patch 3: Modify kerneldoc formatting. Additionally, add a file_priv->master NULL check inside drm_file_get_master, and handle the NULL result accordingly in drm_lease.c. As suggested by Daniel Vetter. Changes in v2 -> v3: - Patch 2: Move the definition of drm_is_current_master and the _locked version higher up in drm_auth.c to avoid needing a forward declaration of drm_is_current_master_locked. As suggested by Daniel Vetter. - Patch 3: Instead of leaking drm_device.master_mutex into drm_lease.c to protect drm_master pointers, add a new drm_file_get_master() function that returns drm_file->master while increasing its reference count, to prevent drm_file->master from being freed. As suggested by Daniel Vetter. Changes in v1 -> v2: - Patch 3: Move the lock and assignment before the DRM_DEBUG_LEASE in drm_mode_get_lease_ioctl, as suggested by Emil Velikov. Desmond Cheong Zhi Xi (3): drm: avoid circular locks in drm_mode_getconnector drm: add a locked version of drm_is_current_master drm: protect drm_master pointers in drm_lease.c drivers/gpu/drm/drm_auth.c | 76 ++++++++++++++++++++++++-------- drivers/gpu/drm/drm_connector.c | 5 ++- drivers/gpu/drm/drm_lease.c | 77 ++++++++++++++++++++++++--------- include/drm/drm_auth.h | 1 + include/drm/drm_file.h | 15 +++++-- 5 files changed, 131 insertions(+), 43 deletions(-) -- 2.25.1