Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1626fc29 authored by Krishna Manikandan's avatar Krishna Manikandan Committed by Alexander Grund
Browse files

disp: msm: sde: add null check for drm file in msm_release

Drm file is not set to NULL after freeing it from drm
release. This can result in use-after-free issues in
some scenarios. Add a mutex lock and other proper null
checks to prevent such issues.

Change-Id: Ic35b0a76166b0f47a354b1737e6f4c3ac1437ed4
parent f2ee0b1f
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
/*
 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
@@ -97,6 +97,8 @@ static void msm_drm_helper_hotplug_event(struct drm_device *dev)
	kfree(event_string);
}

static DEFINE_MUTEX(msm_release_lock);

static void msm_fb_output_poll_changed(struct drm_device *dev)
{
	struct msm_drm_private *priv = NULL;
@@ -1850,11 +1852,22 @@ static int msm_ioctl_submitqueue_close(struct drm_device *dev, void *data,
int msm_release(struct inode *inode, struct file *filp)
{
	struct drm_file *file_priv = filp->private_data;
	struct drm_minor *minor = file_priv->minor;
	struct drm_device *dev = minor->dev;
	struct msm_drm_private *priv = dev->dev_private;
	struct drm_minor *minor;
	struct drm_device *dev;
	struct msm_drm_private *priv;
	struct msm_drm_event *v, *vt;
	unsigned long flags;
	int ret = 0;

	mutex_lock(&msm_release_lock);

	if (!file_priv) {
		ret = -EINVAL;
		goto end;
	}
	minor = file_priv->minor;
	dev = minor->dev;
	priv = dev->dev_private;

	spin_lock_irqsave(&dev->event_lock, flags);
	list_for_each_entry_safe(v, vt, &priv->client_event_list, base.link) {
@@ -1866,7 +1879,11 @@ int msm_release(struct inode *inode, struct file *filp)
	}
	spin_unlock_irqrestore(&dev->event_lock, flags);

	return drm_release(inode, filp);
	ret = drm_release(inode, filp);
	filp->private_data = NULL;
end:
	mutex_unlock(&msm_release_lock);
	return ret;
}

/**