Skip to content

ZFS_READONLY flag is not enforced on write #16508

Open
@tuxoko

Description

@tuxoko

System information

Type Version/Name
Distribution Name ubuntu
Distribution Version
Kernel Version
Architecture
OpenZFS Version master

Describe the problem you're observing

The dos attribute ZFS_READONLY is enforced on truncate but not on write.

There was a change that moved the ZFS_READONLY check from zfs_write() to zfs_zaccess_common().
https://github.com/openzfs/zfs/pull/11693/files
From the commit message, the intention seems to be allowing write if open is before readonly flag is set.
However, currently write will succeed no matter open is before or after.
Note, there's an issue in the change where it checks S_ISDIR(ZTOI(zp)->i_mode) instead of !S_ISDIR(ZTOI(zp)->i_mode).
However, even if this check is fixed, it makes no difference.
It doesn't seem like zfs_zaccess_common is ever called during open(2) or write(2) at all, I added a kprobe on it but nothing showed up.

Describe how to reproduce the problem

$ rm -f /pp/asdf
$ touch /pp/asdf
$ /usr/local/share/zfs/zfs-tests/bin/write_dos_attributes readonly /pp/asdf
0x900000000
$ truncate -s 0 /pp/asdf
truncate: failed to truncate '/pp/asdf' at 0 bytes: Operation not permitted
$ ~/test_write /pp/asdf
$ cat /pp/asdf
test
append

Include any warning/errors/backtraces from the system logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: DefectIncorrect behavior (e.g. crash, hang)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions