Skip to content

readonly_rootfs blocks open(O_WRONLY|O_RDWR) on device files #2134

@niklasfemerstrand

Description

@niklasfemerstrand

When readonly_rootfs is enabled, open() with O_WRONLY or O_RDWR on device files like /dev/null returns EROFS. Such kernel interfaces should be exempt from the read-only filesystem checks because writes are to the device driver, not the readonly filesystem.

To reproduce, manifest with readonly_rootfs:true then build and run with QEMU:

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int main() {
    int fd;
    fd = open("/dev/null", O_WRONLY);
    if (fd < 0) printf("FAIL: open(/dev/null, O_WRONLY) = %s (errno %d)\n", strerror(errno), errno);
    else { printf("OK: open(/dev/null, O_WRONLY) = fd %d\n", fd); close(fd); }

    fd = open("/dev/null", O_RDWR);
    if (fd < 0) printf("FAIL: open(/dev/null, O_RDWR) = %s (errno %d)\n", strerror(errno), errno);
    else { printf("OK: open(/dev/null, O_RDWR) = fd %d\n", fd); close(fd); }

    fd = open("/dev/null", O_RDONLY);
    if (fd < 0) printf("FAIL: open(/dev/null, O_RDONLY) = %s (errno %d)\n", strerror(errno), errno);
    else { printf("OK: open(/dev/null, O_RDONLY) = fd %d\n", fd); close(fd); }

    return 0;
}

This incorrectly prints:

FAIL: open(/dev/null, O_WRONLY) = Read-only file system (errno 30)
FAIL: open(/dev/null, O_RDWR) = Read-only file system (errno 30)
OK: open(/dev/null, O_RDONLY) = fd 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions