From patchwork Sun Apr 12 14:46:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 18892 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9984844BD8C for ; Sun, 12 Apr 2020 17:46:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 768F868B8C0; Sun, 12 Apr 2020 17:46:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F56568B8B4 for ; Sun, 12 Apr 2020 17:46:27 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id a201so7268138wme.1 for ; Sun, 12 Apr 2020 07:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=1EkZAFQHkxC3Dc+u8h2VGEBeKnZcfGESdJN4PzA7z0s=; b=Sg6Yj19ZsfX/5GTRemvps7m1dVTTPhqAMdTdYA2p/vGPLHxB+DC1qjcXI3+dPa7UEG LBH+mEYo5kJG74G4lXMxE59Q/kTYyz8XPnrfpvH0ZxYXR7tESLzIYH29MaPZWgdZkFTf 4rVgVHJjc4vaP+40aRhbFeb4hjtv/4eg0BDcWQxqzYHRHJQYY8ejZwzESfroQsZZwTfw jUJEvohjcaxfmPv9OVfhS1qewdUpU51SG741/G7uYnspTU/wlj7R9boCFd2FJtJiq7nw khxJzxhZRzzCl07P9mpl9ybjvE3OnPYGnpQF7QJWm/YSInd42/4GnYrxnw5Y0a09pj6x ttxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=1EkZAFQHkxC3Dc+u8h2VGEBeKnZcfGESdJN4PzA7z0s=; b=sTOKACg68O4Nza1uxeJ8LV89kU5VFdHLGFVjTZtIvTFzCmGEgBEBjSkPMKhCHBVkF3 8044z/n8u5j4blMWTRthB8Q1s+VdRGfoN22388Qp068AzQour/mjFkpzQVAjBKGvvnrY gfcK5Dmgsu3NHUeVbKc2fR0o/uJQ58ieB344R+rn0HaCKV37nab7OW1iUZRwmFliLfsQ esA24MIadmi9J9hDCSpgC/8kjyNXS5WTZVRDHQ9cZRnMf6WH+5D8ArmVDQVbWs2ACIpz LlWVOmzT8Enq2KFWR4QryQkDKlzdQtK5MD6KkXyuMU3xWxFyboyF0pZhc5sDaQTccV9v XaiQ== X-Gm-Message-State: AGi0PuYpHKHHGBwfAv966cJ78A63yRcryNLzvc2UYE2E+AAYAjC/RRBc USI985168ijllcuWaczGlesLZpjqoWc= X-Google-Smtp-Source: APiQypJXHCPezcL40NsexW48bHiO7yEImEOCgN3GeKaJ0MMkCQowWRtc2P27L8KxqUiVcMsaNCrhSw== X-Received: by 2002:a7b:ce13:: with SMTP id m19mr10870774wmc.76.1586702786249; Sun, 12 Apr 2020 07:46:26 -0700 (PDT) Received: from [192.168.0.3] (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id b4sm6044387wrv.42.2020.04.12.07.46.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Apr 2020 07:46:25 -0700 (PDT) To: FFmpeg development discussions and patches From: Mark Thompson Message-ID: <4e96dd48-088b-f9a5-f2e7-6d1b4bf9c42c@jkqxz.net> Date: Sun, 12 Apr 2020 15:46:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] kmsgrab: Drop DRM master if running as root X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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) {