Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2633238pxj; Mon, 14 Jun 2021 03:35:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6xaQ3RiRpSBmp+FRcq83sW5taz+Qi1a5S8IrqxdeQKGHoVO1OOsBq+V3LI6NmcZHMbHdu X-Received: by 2002:a17:906:eca7:: with SMTP id qh7mr14971951ejb.143.1623666926285; Mon, 14 Jun 2021 03:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623666926; cv=none; d=google.com; s=arc-20160816; b=0UMA2SJ/uoNrZIT0HjfIpbqK1vXxbSsaRJbkHsDMyjemxD3nxru4MFhVkPzB5u84Wk yVh2m23M8mobOFZ/dGmhvR15P9xSk1WCsYLW0kl3c0xBja1rKl6TgzrI02Nk1ISIyII9 EOBSS32zNHTBftsF83K8lAGsJMeqrqWwb/CANz6VjPE11nSfyIIBY1vUJYw5PMGdYzhG hdxAkcl/mwApPXNkmDTbcB5lUpkA181SkoXeNEfupBr5nfmBTrfTvmdF1M9g6Fld9GnS AGZEZM0P3+DLOMpB+t7gAqwZUxmAKTHg5zk3nI/gAmrq+GgqafmllNLwCz5aanr6dgmU 3vkw== 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=8OmKsZxyzOBSF97TzM6F2vaXBJIN3GU1KfhwcMcXzZ0=; b=McYzkgR77XoORFllZ4EckPCs9y0wVJQROjZLFy/dThLDW4sNmVLq4oQqNmuDCziVSr 38VFqqP/A4tzsWLoR+J2J9atuWQa6yqVKRHbARBcRtdw6Gn2VPcz0xOaSUl564aiXuyC gipTLtafEQGHdv06CA/v4WJug3YIweWKw1exap/dGeIYcTShiTak1RUAxJrGDW8ZsopI m7CrJl9bCWgA6Qum7W2DRUcZAwbVfpXcBMlbVz82RLgXQABS5R4NRIsTVXy1mH5LZTIM oAY64WAnFNxl5h5oP2H8LBVS+NX7uHEzZZ0WQBVe7IARIp0CiJLOETRisPTjI9/pflIH J9mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=obB8FVNw; 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 o4si10300191edc.544.2021.06.14.03.35.03; Mon, 14 Jun 2021 03:35:26 -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=obB8FVNw; 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 S233462AbhFNKfI (ORCPT + 99 others); Mon, 14 Jun 2021 06:35:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:39012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233163AbhFNKdE (ORCPT ); Mon, 14 Jun 2021 06:33:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1CF1161356; Mon, 14 Jun 2021 10:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623666650; bh=40kVcWgnvBimhoFzDYPi4F2elgKnaZM7NJhHSYDJPII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obB8FVNwKtzXBVa8N+dLFnGsqTemp4nx1UsXiLk3n+0Cim72uC1jWY2joSRxycjWA mvEv0zIFh+lzQp6wZ8LhS2Pt0DyMbqKJ7SSuKBU7+9+B6kBUkDDVl9VGYMSwhOAjGh KRyOfLKynrH31lC4zyzFlA7lE1FZGKzwEv+Ag1u0= 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 4.9 21/42] drm: Lock pointer access in drm_master_release() Date: Mon, 14 Jun 2021 12:27:12 +0200 Message-Id: <20210614102643.386644937@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102642.700712386@linuxfoundation.org> References: <20210614102642.700712386@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 @@ -244,9 +244,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);