[FFmpeg-devel] [PATCH] kmsgrab: Drop DRM master if running as root

Mark Thompson sw at jkqxz.net
Sun Apr 12 17:46:25 EEST 2020


If we have both root and DRM master then drop the latter because we
don't need both and holding onto it can interfere with running other
programs.

>From a discussion with deltasquared on IRC.
---
It would be marginally better to check whether we have CAP_SYS_ADMIN rather than just whether we are effectively root, but the capabilities interface is a lot more complex to query and this is already sufficient to cover the reported case.

 libavdevice/kmsgrab.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavdevice/kmsgrab.c b/libavdevice/kmsgrab.c
index d0de774871..53280da0f5 100644
--- a/libavdevice/kmsgrab.c
+++ b/libavdevice/kmsgrab.c
@@ -263,6 +263,13 @@ static av_cold int kmsgrab_read_header(AVFormatContext *avctx)
     ctx->device = (AVHWDeviceContext*) ctx->device_ref->data;
     ctx->hwctx  = (AVDRMDeviceContext*)ctx->device->hwctx;
 
+    if (geteuid() == 0 && drmIsMaster(ctx->hwctx->fd)) {
+        // If we have both root and DRM master then drop the latter
+        // because we don't need both and holding onto it can interfere
+        // with running other programs.
+        drmDropMaster(ctx->hwctx->fd);
+    }
+
     err = drmSetClientCap(ctx->hwctx->fd,
                           DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
     if (err < 0) {
-- 
2.25.1


More information about the ffmpeg-devel mailing list