Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2657917pxj; Mon, 14 Jun 2021 04:13:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwea50ur65uaS9zUmE0TvRDCb0xOx769sqbaFk4EA76CFlP2weqWTvHIX+XlAaaMVoTiYI4 X-Received: by 2002:a05:6402:40c3:: with SMTP id z3mr16203533edb.187.1623669199986; Mon, 14 Jun 2021 04:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623669199; cv=none; d=google.com; s=arc-20160816; b=YRFelPjbFRw5elUprRPPwtg0gsHNEe2YX8DBXYWmgmexYYh2kIgzQz/lhI3x0iqOFI tliIn+7gRMV3a6MOBaOVuN2H74SOmktPcMp5zFxAeCWI7N54zLG+4gvmuKCoEcxizaq2 G1GJznVt7aqg/L52FFDGLodIqphLwwpI1h4Z0cspuowURgeGQdo2UpDoQ7YXLAZuZdzX iHBI1tasu98SOCzAnDBCvcKshtXfFn/qKTcqtc33UAUhorqetjCckPRqTUm0IWqpBaBr SUdO+B/9T/EecICfS7LYZMJ02+BcThY9guc9quBeOPSwmqra2kZMKB3B4OoFTq99YfLH c2KA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r+kD+48EC0feezqoGPE1Fo+Dc6qMAXOPh1iIvsZMDZc=; b=Y7hL25zsn6g1UJWnZN79Pde1wQDnFFrXcb2ooYrK0/OtQ0T+UKS0sbVRxtidK7yfM/ 8aNCv6rdbmX1k1xEKR/ei070DkrVH9N9lxO3p7zWI1S/9iwer8jdVmkZh+lO0UjFHafu xMj7V0P1qOXYOexmtn2PUplZqVZAK4x+1Ay5zZPO74kIiMqp4B/wk8tTZQcEPvMNzrv2 mNjYZbzgnz/4xbhzZfJVD4L+qVDgfflzbo+oQjlw6wC3fUTRX03Zl23XirnVvHlhVMew g44RR/W/EgJZ5JRnbqCGFg6gRIgsoy2a7oMexih7jWU3FpMSwGKUSP1xCfXXWfWpLJnM /ZQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pHM+3LH4; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si10914057edw.414.2021.06.14.04.12.57; Mon, 14 Jun 2021 04:13:19 -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=@linuxfoundation.org header.s=korg header.b=pHM+3LH4; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234991AbhFNLMd (ORCPT + 99 others); Mon, 14 Jun 2021 07:12:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:35836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234016AbhFNLAx (ORCPT ); Mon, 14 Jun 2021 07:00:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 956C86162E; Mon, 14 Jun 2021 10:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667396; bh=Ijj6w/xRH62dLAhfw625MvzJ53wokV09FozBDVbrmOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pHM+3LH4ms8m5FACUk+DN1H3QAg+BxIPgLj5y5TfQvV5MK0IEkSB7i0ACVipljqkm 7NbszLX85VVqMgLZjU/NcNa5h8Iw6tqEng+xWjmb5jBSJZ0mWLLRCS7Ish+jhHXj3C k/DDYaiMNMkgfnwsrrHqJYF7SJcGPM2jlhgDkSY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Desmond Cheong Zhi Xi , Daniel Vetter Subject: [PATCH 5.10 055/131] drm: Lock pointer access in drm_master_release() Date: Mon, 14 Jun 2021 12:26:56 +0200 Message-Id: <20210614102654.894773297@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Desmond Cheong Zhi Xi commit c336a5ee984708db4826ef9e47d184e638e29717 upstream. 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 Cc: stable@vger.kernel.org Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20210609092119.173590-1-desmondcheongzx@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_auth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/drm_auth.c +++ b/drivers/gpu/drm/drm_auth.c @@ -314,9 +314,10 @@ int drm_master_open(struct drm_file *fil 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);