isjerryxiao / kmsvnc

A VNC server for DRM/KMS capable GNU/Linux devices
GNU General Public License v3.0
49 stars 6 forks source link

No handle set on framebuffer: maybe you need some additional capabilities? #18

Open genpfault opened 2 weeks ago

genpfault commented 2 weeks ago

Trying to run kmsvnc without root fails with:

No handle set on framebuffer: maybe you need some additional capabilities?

Full log:

$ ./kmsvnc --debug
No keyboard layout set from environment variables, use US layout by default
See https://xkbcommon.org/doc/current/structxkb__rule__names.html
drm driver is amdgpu
Plane 40 CRTC 0 FB 0 Type primary
Plane 45 CRTC 0 FB 0 Type primary
Plane 50 CRTC 0 FB 0 Type primary
Plane 55 CRTC 0 FB 0 Type primary
Plane 60 CRTC 80 FB 133 Type primary
Using plane 60 to locate framebuffers
Template framebuffer is 133: 1920x1200 fourcc:875713089 mod:144115188488370947 flags:2
handles 0 0 0 0
offsets 0 9830400 9879552 0
pitches 7680 2048 2048 0
format AR24, modifier AMD:GFX10_RBPLUS,GFX9_64K_R_X,DCC,DCC_RETILE,DCC_INDEPENDENT_128B,DCC_MAX_COMPRESSED_BLOCK=128B,DCC_CONSTANT_ENCODE,PIPE_XOR_BITS=4,PACKERS=3
No handle set on framebuffer: maybe you need some additional capabilities?

Which capabilities does kmsvnc need?

For what it's worth granting cap_sys_admin to kmsvnc via:

sudo setcap cap_sys_admin=ep kmsvnc

...fixes it on my system (Debian Bookworm, KDE Wayland session).

genpfault commented 1 week ago

Looks like the No handle set on framebuffer: maybe you need some additional capabilities? message is generated by this block in response to drmModeGetFB2() neglecting to fill out the handles member of drm->mfb.

drmModeGetFB2() is a thin wrapper around the DRM_IOCTL_MODE_GETFB2 ioctl.

The DRM_IOCTL_MODE_GETFB2 docs have these notes (emphasis mine):

If the client is DRM master or has CAP_SYS_ADMIN, drm_mode_fb_cmd2.handles will be filled with GEM buffer handles. Planes are valid until one has a zero handle – this can be used to compute the number of planes.

Otherwise, drm_mode_fb_cmd2.handles will be zeroed and planes are valid until one has a zero drm_mode_fb_cmd2.pitches.