drm/auth: Only drm_drop_master if it exists
Subsystems (2)
PATCH 1/1 drm/auth: Only drm_drop_master if it exists
It is possible that both dev->master and file_priv->master are NULL when passed to drm_master_release, which would result in dev being passed to drm_drop_master (as NULL == NULL here). This would result in a NULL pointer dereference when passing dev->master to drm_master_put in drm_drop_master.
Only call drm_drop_master if dev->master exists. Also, make sure the original calling requirement is maintained (dev->master == file_priv->master).
This fixes a static analysis issue.
--- drivers/gpu/drm/drm_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_auth.c +1 -1
@@ -347,7 +347,7 @@ void drm_master_release(struct drm_file *file_priv)if (!drm_is_current_master_locked (file_priv)) goto out; -if (dev->master == file_priv->master) +if (dev->master && dev->master == file_priv->master)drm_drop_master (dev, file_priv); out:if (drm_core_check_feature (dev,DRIVER_MODESET ) && file_priv->is_master) {
Signature · 1 line
2.53.0
Quoted 27 lines · Jonathan Cavitt
It is possible that both
dev->masterandfile_priv->masterare NULL when passed todrm_master_release, which would result in dev being passed todrm_drop_master(as NULL == NULL here). This would result in a NULL pointer dereference when passingdev->mastertodrm_master_putindrm_drop_master.Only call
drm_drop_masterifdev->masterexists. Also, make sure the original calling requirement is maintained (dev->master==file_priv->master).This fixes a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>--- drivers/gpu/drm/drm_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_auth.c +0
-0
drivers/gpu/drm/drm_auth.c void drm_master_release(struct drm_file *file_priv) · line 353
Quoted 8 lines
drivers/gpu/drm/drm_auth.c +1
-1@@ -347,7 +347,7 @@ void drm_master_release(struct drm_file *file_priv)if (!drm_is_current_master_locked (file_priv)) goto out; -if (dev->master == file_priv->master) +if (dev->master && dev->master == file_priv->master)drm_drop_master (dev, file_priv); out:if (drm_core_check_feature (dev,DRIVER_MODESET ) && file_priv->is_master) {
This is a good catch.
Signature · 2 lines
Regards, Luben
Quoted 27 lines · Jonathan Cavitt
It is possible that both
dev->masterandfile_priv->masterare NULL when passed todrm_master_release, which would result in dev being passed todrm_drop_master(as NULL == NULL here). This would result in a NULL pointer dereference when passingdev->mastertodrm_master_putindrm_drop_master.Only call
drm_drop_masterifdev->masterexists. Also, make sure the original calling requirement is maintained (dev->master==file_priv->master).This fixes a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>--- drivers/gpu/drm/drm_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_auth.c +0
-0
drivers/gpu/drm/drm_auth.c void drm_master_release(struct drm_file *file_priv) · line 353
Quoted 8 lines
drivers/gpu/drm/drm_auth.c +1
-1@@ -347,7 +347,7 @@ void drm_master_release(struct drm_file *file_priv)if (!drm_is_current_master_locked (file_priv)) goto out; -if (dev->master == file_priv->master) +if (dev->master && dev->master == file_priv->master)drm_drop_master (dev, file_priv); out:if (drm_core_check_feature (dev,DRIVER_MODESET ) && file_priv->is_master) {
Quoted 27 lines · Jonathan Cavitt
It is possible that both
dev->masterandfile_priv->masterare NULL when passed todrm_master_release, which would result in dev being passed todrm_drop_master(as NULL == NULL here). This would result in a NULL pointer dereference when passingdev->mastertodrm_master_putindrm_drop_master.Only call
drm_drop_masterifdev->masterexists. Also, make sure the original calling requirement is maintained (dev->master==file_priv->master).This fixes a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>--- drivers/gpu/drm/drm_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_auth.c +0
-0
drivers/gpu/drm/drm_auth.c void drm_master_release(struct drm_file *file_priv) · line 350
Quoted 4 lines
drivers/gpu/drm/drm_auth.c +0
-1@@ -347,7 +347,7 @@ void drm_master_release(struct drm_file *file_priv)if (!drm_is_current_master_locked (file_priv)) goto out; -if (dev->master == file_priv->master)
The previous call checks that file_priv->master != NULL. So, at this point the NULL == NULL check is not possible.
I'm sorry, but this looks like a false positive.
Quoted 7 lines
drivers/gpu/drm/drm_auth.c +1
-0+if (dev->master && dev->master == file_priv->master)drm_drop_master (dev, file_priv); out:if (drm_core_check_feature (dev,DRIVER_MODESET ) && file_priv->is_master) {Signature · 1 line
2.53.0
Signature · 2 lines
With best wishes Dmitry
-----Original Message-----
From: Dmitry Baryshkov <[email protected]>
Sent: Wednesday, April 22, 2026 12:14 PM
To: Cavitt, Jonathan <[email protected]>
Cc: [email protected]; Gupta, Saurabhg <[email protected]>; Zuo, Alex <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] drm/auth: Only drm_drop_master if it exists
Quoted 32 lines · Jonathan Cavitt
Quoted 30 lines
It is possible that both
dev->masterandfile_priv->masterare NULL when passed todrm_master_release, which would result in dev being passed todrm_drop_master(as NULL == NULL here). This would result in a NULL pointer dereference when passingdev->mastertodrm_master_putindrm_drop_master.Only call
drm_drop_masterifdev->masterexists. Also, make sure the original calling requirement is maintained (dev->master==file_priv->master).This fixes a static analysis issue.
Signed-off-by Jonathan Cavitt <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>--- drivers/gpu/drm/drm_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_auth.c +0
-0@@ -347,7 +347,7 @@ void drm_master_release(struct drm_file *file_priv)if (!drm_is_current_master_locked (file_priv)) goto out;
Quoted 4 lines
drivers/gpu/drm/drm_auth.c void drm_master_release(struct drm_file *file_priv) · line 350
Quoted 1 line
drivers/gpu/drm/drm_auth.c +0
-1-if (dev->master == file_priv->master)The previous call checks that
file_priv->master!= NULL. So, at this point the NULL == NULL check is not possible.
You mean drm_is_current_master_locked?
Internally, that performs the check
"fpriv->is_master && drm_lease_owner(fpriv->master) == fpriv->minor->dev->master"
It doesn't explicitly check for fpriv->master != NULL, but I don't think the current execution path allows for fpriv->is_master && !fpriv->master, so I'm guessing that's what you're referring to? Otherwise, we could be passing a NULL pointer to drm_lease_owner, which would itself be a NULL pointer dereference issue...
Quoted 2 lines
I'm sorry, but this looks like a false positive.
This has already been merged. If you think it necessary, please feel free to file a revert and send the request my way for review.
-Jonathan Cavitt
Quoted 13 lines
Quoted 8 lines
drivers/gpu/drm/drm_auth.c +1
-0+if (dev->master && dev->master == file_priv->master)drm_drop_master (dev, file_priv); out:if (drm_core_check_feature (dev,DRIVER_MODESET ) && file_priv->is_master) {Signature · 1 line
2.53.0Signature · 2 lines
With best wishes Dmitry