Skip to content

Fix readonly_rootfs blocking writes to device files#2135

Open
niklasfemerstrand wants to merge 1 commit intonanovms:masterfrom
niklasfemerstrand:readonly_rootfs
Open

Fix readonly_rootfs blocking writes to device files#2135
niklasfemerstrand wants to merge 1 commit intonanovms:masterfrom
niklasfemerstrand:readonly_rootfs

Conversation

@niklasfemerstrand
Copy link

@niklasfemerstrand niklasfemerstrand commented Feb 12, 2026

Fixes #2134

open() with O_WRONLY or O_RDWR on device files like /dev/null returns EROFS when readonly_rootfs is enabled. Device writes go to the driver, not the filesystem, so special files should be exempt from the read-only check.

open() with O_WRONLY or O_RDWR on device files like /dev/null
returns EROFS when readonly_rootfs is enabled. Device writes go
to the driver, not the filesystem, so special files should be
exempt from the read-only check.

nanovms#2134
Copy link
Member

@francescolavra francescolavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a sensible fix, but I would like to take this opportunity to do some cleanup.
The get() call is somewhat expensive, as is does a table lookup, and we already have a couple of similarly expensive lookups in the same function in the form of is_dir() calls; then we have a file_type_from_tuple() call which can potentially re-do the same lookups again. It would be better to move the file_type_from_tuple() call at the top of the function, so we have the type variable which we can compare against known values in the rest of the function: so the is_dir() calls become type == FDESC_TYPE_DIRECTORY, and your fix would become if (type == FDESC_TYPE_REGULAR && filesystem_is_readonly(fs)) (regular files are the only file types where a write modifies the filesystem, so this is more accurate than testing against special files).

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readonly_rootfs blocks open(O_WRONLY|O_RDWR) on device files

2 participants