Skip to content

Browser AVD integration: enable hardware decode with the media sandbox retained #44

Open

Description

@chriskearney

J516S AV1 now matches software through ffmpeg; the reported browser hardware-decode tests require disabling the RDD sandbox because it denies /dev/media* to libva-v4l2-request. Normal sandboxed playback falls back to software. The plane-offset color corruption has passed standalone and browser pixel retests.

Priority: P2 · Readiness: investigation · Implementation owner: userspace

Baseline: Aurora 2026.10.11.13, development commit 5dcdeb8cda8dafe203d4d2f03952ade392c3fe23. Earlier reproductions retain the exact versions above.

Code: drivers/media/platform/apple/avd/avd-drv.c

Completion criteria: Coordinate the browser/device-broker and libva owners for narrowly admitted media-device access. Test H264/VP9/AV1 playback with the normal sandbox, pixel correctness and no GPU fault; retain software fallback. Disabling sandbox globally is not the delivered solution.

Original reports/candidate: original #49 · original #84 · original #54

This ticket carries forward the remaining work; source inclusion, release delivery and hardware acceptance are recorded separately.

Activity

  1. added
    priority:P2
    status:investigation
    area:video
    owner:userspace
    launch:follow-up
    on Oct 11, 2026
  2. cb2206 commented on Oct 12, 2026

    @cb2206

    J314S (14" M1 Pro, AVD hw 30001), Aurora 2026.10.11.15, libva-v4l2_request-avd 1.3.r11.r164.g5b5046c-1. I traced the sandbox block to two missing rules in Firefox, patched both and tested a build with the RDD sandbox on.

    Baseline on the M1. ffmpeg VA-API through AVD matches software decode on testsrc2 1080p H.264, VP9 and HEVC (120/120 frames each). The M1 has no AV1 decoder. Stock Firefox 157.0.1 (Arch) with the sandbox on fails as reported: Failed errno -13 op access path /dev/media0 (and every other /dev/mediaN), Failed to create VA-API device context, software decode. With MOZ_DISABLE_RDD_SANDBOX=1 (diagnostic only) all three codecs decode through VA-API with correct colours. The M1 renders through native GL, not zink, so #54 doesn't show up here.

    Chromium isn't affected by the sandbox question: Arch ARM's Chromium 153 has no VA-API compiled in (video_decode: disabled_software in DevTools, even with --disable-gpu-sandbox), so Firefox/Zen are the only browsers this applies to.

    Why the sandbox blocks it. Firefox's RDD policy (built with MOZ_ENABLE_V4L2 on arm/aarch64) has two gaps:

    1. Broker (SandboxBrokerPolicyFactory.cpp, AddV4l2Dependencies()): only M2M /dev/video* nodes are admitted. There's no rule for the media controller, and libva-v4l2-request needs /dev/mediaN (MEDIA_IOC_G_TOPOLOGY, MEDIA_IOC_REQUEST_ALLOC), plus /sys/dev/char/<maj>:<min>/uevent to map the topology's video node back to its path.
    2. seccomp (SandboxFilter.cpp, RDDSandboxPolicy): ioctls are allowed only for types 'd' (DRM), 'b' (dma-buf) and 'V' (V4L2). The media controller and its request fds use type '|'.

    Neither can be changed with prefs. The content-process path prefs don't apply to RDD, so the narrow fix has to go into Firefox.

    Patch (81 lines added, against 157.0.1): AddV4l2Dependencies() remembers the device numbers of the M2M nodes it admits, then admits a /dev/mediaN only if its topology has a MEDIA_INTF_T_V4L_VIDEO interface for one of those nodes, together with that node's sysfs uevent. The RDD filter additionally allows ioctl type '|' under MOZ_ENABLE_V4L2. Webcam and camera media devices stay blocked: on this Mac /dev/media1 (apple-isp) is still denied.

    Result, sandbox on (patched 157.0.1, local 1080p clips):

    Codec VA-API frames in ~25 s Decoder
    H.264 701 VA-API FFmpeg init successful
    VP9 704 same (FFVPX)
    HEVC 713 same

    The RDD process ran with Seccomp: 2, NoNewPrivs: 1 and its own user namespace. Its only device fds were /dev/dri/renderD128, /dev/media0 and /dev/video0. The broker still denied /dev/media1 and all other /dev/mediaN. Colours were correct and there was no AVD error or GPU fault. Software fallback is unchanged, since a system without such a media device gets no new rules.

    Not tested: AV1 (no hardware on M1), YouTube or other MSE playback, 10-bit, Zen. The next step is upstream. I'll file the patch with Mozilla (Core :: Security: Process Sandboxing) and link the bug here.

    Patch against Firefox 157.0.1
    diff --git i/security/sandbox/linux/SandboxFilter.cpp w/security/sandbox/linux/SandboxFilter.cpp
    index 4be1eff0cf..2c8a4401ab 100644
    --- i/security/sandbox/linux/SandboxFilter.cpp
    +++ w/security/sandbox/linux/SandboxFilter.cpp
    @@ -2092,6 +2092,10 @@ class RDDSandboxPolicy final : public SandboxPolicyCommon {
             // Type 'V' for V4L2, used for hw accelerated decode
             static constexpr unsigned long kVideoType =
                 static_cast<unsigned long>('V') << _IOC_TYPESHIFT;
    +        // Type '|' for the media controller and its request fds, used by
    +        // stateless (Request API) V4L2 decoders
    +        static constexpr unsigned long kMediaType =
    +            static_cast<unsigned long>('|') << _IOC_TYPESHIFT;
     #endif
     #ifdef MOZ_ENABLE_VULKAN_VIDEO
             static constexpr unsigned long kNvidiaRmType =
    @@ -2125,6 +2129,7 @@ class RDDSandboxPolicy final : public SandboxPolicyCommon {
     #endif
     #ifdef MOZ_ENABLE_V4L2
                 .ElseIf(shifted_type == kVideoType, Allow())
    +            .ElseIf(shifted_type == kMediaType, Allow())
     #endif
             // NVIDIA decoder from Linux4Tegra, this is specific to Tegra ARM64 SoC
     #if defined(__aarch64__)
    diff --git i/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp w/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
    index 5db7560cf6..012de03425 100644
    --- i/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
    +++ w/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
    @@ -17,8 +17,12 @@
     #endif
     #ifdef MOZ_ENABLE_V4L2
     #  include <fcntl.h>
    +#  include <algorithm>
    +#  include <linux/media.h>
     #  include <linux/videodev2.h>
     #  include <sys/ioctl.h>
    +#  include "mozilla/UniquePtr.h"
    +#  include "nsTArray.h"
     #endif  // MOZ_ENABLE_V4L2
     #ifdef MOZ_ENABLE_VULKAN_VIDEO
     #  include "mozilla/Components.h"
    @@ -882,6 +886,71 @@ UniquePtr<SandboxBroker::Policy> SandboxBrokerPolicyFactory::GetContentPolicy(
     }
     
     #ifdef MOZ_ENABLE_V4L2
    +// Stateless V4L2 decoders (the Request API, used e.g. by libva-v4l2-request)
    +// also need the media controller device that owns the decoder's video node,
    +// to allocate requests (MEDIA_IOC_REQUEST_ALLOC). Only admit /dev/media*
    +// devices whose topology exposes one of the M2M video nodes allowed above,
    +// plus that video node's sysfs uevent (used to map the topology's devnode
    +// back to its /dev path), so webcam and capture media devices stay blocked.
    +static void AddV4l2RequestMediaDevices(SandboxBroker::Policy* policy,
    +                                       const nsTArray<dev_t>& aM2mDevices) {
    +  if (aM2mDevices.IsEmpty()) {
    +    return;
    +  }
    +  DIR* dir = opendir("/dev");
    +  if (!dir) {
    +    return;
    +  }
    +  struct dirent* dir_entry;
    +  while ((dir_entry = readdir(dir))) {
    +    if (strncmp(dir_entry->d_name, "media", 5)) {
    +      continue;
    +    }
    +    nsCString path = "/dev/"_ns;
    +    path += nsDependentCString(dir_entry->d_name);
    +    int fd = open(path.get(), O_RDWR | O_NONBLOCK | O_CLOEXEC, 0);
    +    if (fd < 0) {
    +      continue;
    +    }
    +    struct media_v2_topology topology = {};
    +    if (ioctl(fd, MEDIA_IOC_G_TOPOLOGY, &topology) < 0 ||
    +        topology.num_interfaces == 0 || topology.num_interfaces > 256) {
    +      close(fd);
    +      continue;
    +    }
    +    uint32_t count = topology.num_interfaces;
    +    auto interfaces = MakeUnique<media_v2_interface[]>(count);
    +    topology = {};
    +    topology.num_interfaces = count;
    +    topology.ptr_interfaces = reinterpret_cast<uintptr_t>(interfaces.get());
    +    if (ioctl(fd, MEDIA_IOC_G_TOPOLOGY, &topology) < 0) {
    +      close(fd);
    +      continue;
    +    }
    +    close(fd);
    +    bool allowed = false;
    +    for (uint32_t i = 0; i < std::min(count, topology.num_interfaces); ++i) {
    +      const media_v2_interface& intf = interfaces[i];
    +      if (intf.intf_type != MEDIA_INTF_T_V4L_VIDEO) {
    +        continue;
    +      }
    +      dev_t devnum = makedev(intf.devnode.major, intf.devnode.minor);
    +      if (!aM2mDevices.Contains(devnum)) {
    +        continue;
    +      }
    +      allowed = true;
    +      policy->AddPath(rdonly, nsPrintfCString("/sys/dev/char/%u:%u/uevent",
    +                                              intf.devnode.major,
    +                                              intf.devnode.minor)
    +                                  .get());
    +    }
    +    if (allowed) {
    +      policy->AddPath(rdwr, path.get());
    +    }
    +  }
    +  closedir(dir);
    +}
    +
     static void AddV4l2Dependencies(SandboxBroker::Policy* policy) {
       // For V4L2 hardware-accelerated video decode, RDD needs access to certain
       // /dev/video* devices but don't want to allow it access to webcams etc.
    @@ -892,6 +961,7 @@ static void AddV4l2Dependencies(SandboxBroker::Policy* policy) {
         return;
       }
     
    +  nsTArray<dev_t> m2mDevices;
       struct dirent* dir_entry;
       while ((dir_entry = readdir(dir))) {
         if (strncmp(dir_entry->d_name, "video", 5)) {
    @@ -923,6 +993,10 @@ static void AddV4l2Dependencies(SandboxBroker::Policy* policy) {
             (cap.device_caps & V4L2_CAP_VIDEO_M2M_MPLANE)) {
           // This is an M2M device (i.e. not a webcam), so allow access
           policy->AddPath(rdwr, path.get());
    +      struct stat st;
    +      if (fstat(fd, &st) == 0 && S_ISCHR(st.st_mode)) {
    +        m2mDevices.AppendElement(st.st_rdev);
    +      }
         }
     
         close(fd);
    @@ -931,6 +1005,8 @@ static void AddV4l2Dependencies(SandboxBroker::Policy* policy) {
     
       // FFmpeg V4L2 needs to list /dev to find V4L2 devices.
       policy->AddPath(rdonly, "/dev");
    +
    +  AddV4l2RequestMediaDevices(policy, m2mDevices);
     }
     #endif  // MOZ_ENABLE_V4L2
     
  3. cb2206 commented on Oct 12, 2026

    @cb2206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:videolaunch:follow-upowner:userspacepriority:P2status:investigation

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions