Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5004870pxj; Wed, 9 Jun 2021 07:08:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydgxeSJpplotdcZ2sJkvNCZ6JXf9VA5IDRDNjkOFFrCrsVUEYeDZkH9bYaHH04M5llRaDW X-Received: by 2002:a05:6402:1648:: with SMTP id s8mr31282912edx.256.1623247697600; Wed, 09 Jun 2021 07:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623247697; cv=none; d=google.com; s=arc-20160816; b=Go0e5shlMQC/8yfkzWJUxPbpYiydNxNFcmBUx6xNST5XQg0SBJgAE8BAqadEprYTTx Nz0P4bDdi4ln6VXGMoMmI0yDQUZHjmx+QUV9tmiLPhFPXsGplFmpLhMPTBDFBp5W/dzi dU+NrtLY758PaRDGY3TWE8T6H1nP+u7NosrvY0/G5/pC4ZSxAige7jxFQ2IdFGHEJo+w HFrVhB34ErlLiKYdGpf0++sZHtKzOU73l/MOagFYHWNH7oA81x1f6mrE6unS3syBxvzX xxFTRQgbc33Nx7KUCO52YszoqG0VDDz8XKWQSa1xodSjDk0/EPDfpDXCikw/Qk9ya6lE ynNw== 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=1HdeYeZU8aBbB01u3EptGGzTktTYXaU7YZzov/SDA8I=; b=hPkdxi3OCWMJwbh+MSky+uzBaidx4Cx15jp0EsCk/+LcLRbsxq8PETY/u3dQGDI+bz +kttts6zXWfEx2ZMTcmDnNEzXQHKmulGgMhE4OlhUl1NZ2l4ZFWGYjKi9+c8WwEiRBCB vn5KfFkC51WJFEuNOSiRw8d3GoCucnUyVqnbaMhlErdIthXMSS0fXAIIeYhUG3l9LoE4 ybZzvQM1s4sMTGekfR8ejZkJtNm5iynaWGJI3W3ixOT8lWUp/HGAV0pg887KjxLe0mid ICCOVoLPMr7/YbT0bjZJBTRzXySSS3k2ZVXdtn0TyVcCj+lC0x0LeezRvvm49YLRiVxv w5sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b4EpkScI; 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 f23si2280914ejj.287.2021.06.09.07.07.53; Wed, 09 Jun 2021 07:08:17 -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=b4EpkScI; 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 S237988AbhFIJYJ (ORCPT + 99 others); Wed, 9 Jun 2021 05:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237985AbhFIJYH (ORCPT ); Wed, 9 Jun 2021 05:24:07 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7C3CC061574 for ; Wed, 9 Jun 2021 02:22:00 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id o9so16109889pgd.2 for ; Wed, 09 Jun 2021 02:22:00 -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=1HdeYeZU8aBbB01u3EptGGzTktTYXaU7YZzov/SDA8I=; b=b4EpkScIYTfhDr+1DMH9NGb/JEGCVMC9I0UEyR0v35fGLBQSlI8BS1JDdPwEi26sGQ KPb2AUw2GDSNvGJGPErFOeww/av+JYG7UmLiOxZgOlAggtefR5FUeMsoRoDKnhoHtI8u 0E0v05ydQAErk3dBnyG43LsFRo9bYbJkhu+NdLUfvu+vjlDoM3ZknsyBXJ9NjBDzpAcr HLBi/331j1metmaNnix8gGpxm82JMyR1mV18SJZWKZJpLxC2uTO8gup6tbgZ003q4Of5 MznuY50X/r972sJpUhon8MiAZUcUYmgfQTYatvtdKj6f1XI5znqAeyQ7060yHHdxWgGA rSvQ== 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=1HdeYeZU8aBbB01u3EptGGzTktTYXaU7YZzov/SDA8I=; b=ZRiDyb0/jnHrLplZtwRWMuY5MzvdK29lfDFcTAnSe5kpOK1q96NyMLrG7nO1DI3BcC v6tQTdBD9WSrI5SjWjVZR2t9McVeJiOx5S7vOd6O7OIqMjbTIwXlzhS+HGwn6eRbRFCk clPE+efZcWi5ZZFt61ZtsUIXlREmKr27UTb1hLnAJySwd1YY5pTms+XhzEIRblD5mZ1a 2w58jRk0teppcNBnHyZO21I4HrX3+HRV9Bdcm3cF4Q6k2eF1dB2VnkHuVheIzUSQWuXW hz3X5Cn64v8Fm3DHHBosQEVq6hEIxRw/iM4TP30RzjnxPaqKiY5Uw1VU1SZxtPReiR66 r1Mg== X-Gm-Message-State: AOAM530hU3uR0YhMk8vwnOuSZsKYocLdGtlfdg1GZR/wtEtMl1/gK4bO Cp5scliStmKp809KmlsCjdM= X-Received: by 2002:a65:4508:: with SMTP id n8mr2895991pgq.120.1623230520212; Wed, 09 Jun 2021 02:22:00 -0700 (PDT) Received: from localhost.localdomain ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id z22sm13793464pfa.157.2021.06.09.02.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 02:21:59 -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 Cc: Desmond Cheong Zhi Xi , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, Dan Carpenter Subject: [PATCH] drm: Lock pointer access in drm_master_release() Date: Wed, 9 Jun 2021 17:21:19 +0800 Message-Id: <20210609092119.173590-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 eliminates the following smatch warning: drivers/gpu/drm/drm_auth.c:320 drm_master_release() warn: unlocked access 'master' (line 318) expected lock '&dev->master_mutex' The 'file_priv->master' field should be protected by the mutex lock to '&dev->master_mutex'. This is because other processes can concurrently modify this field and free the current 'file_priv->master' pointer. This could result in a use-after-free error when 'master' is dereferenced in subsequent function calls to 'drm_legacy_lock_master_cleanup()' or to 'drm_lease_revoke()'. An example of a scenario that would produce this error can be seen from a similar bug in 'drm_getunique()' that was reported by Syzbot: https://syzkaller.appspot.com/bug?id=148d2f1dfac64af52ffd27b661981a540724f803 In the Syzbot report, another process concurrently acquired the device's master mutex in 'drm_setmaster_ioctl()', then overwrote 'fpriv->master' in 'drm_new_set_master()'. The old value of 'fpriv->master' was subsequently freed before the mutex was unlocked. Reported-by: Dan Carpenter Signed-off-by: Desmond Cheong Zhi Xi --- drivers/gpu/drm/drm_auth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c index f00e5abdbbf4..b59b26a71ad5 100644 --- a/drivers/gpu/drm/drm_auth.c +++ b/drivers/gpu/drm/drm_auth.c @@ -315,9 +315,10 @@ int drm_master_open(struct drm_file *file_priv) void drm_master_release(struct drm_file *file_priv) { struct drm_device *dev = file_priv->minor->dev; - struct drm_master *master = file_priv->master; + struct drm_master *master; mutex_lock(&dev->master_mutex); + master = file_priv->master; if (file_priv->magic) idr_remove(&file_priv->master->magic_map, file_priv->magic); -- 2.25.1