Re: [9fans] ramfs bug

2022-08-15 Thread adr

On Mon, 15 Aug 2022, Richard Miller wrote:

A simple fix is to add a reference count to the Ram struct, to
keep track of how many Fids point to it, and only allow a Ram to
be re-used if both busy==0 and ref==0. The new 9legacy patch
ramfs-refcount makes this change.


Thanks for sharing this with the list. It is really hard to keep
track of what and when with 9legacy.

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tc364b766ff6473bc-Mc0e95938ae16096f4aaad0b7
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


[9fans] ramfs bug

2022-08-15 Thread Richard Miller
Deleting an open file on ramfs(4) can have surpising results.

Here's how it's supposed to behave. When a file is removed, the
Ram struct which represents the in-memory file has its busy flag
reset, so a subsequent i/o will see that it's been deleted.

cpu% ramfs
cpu% echo this is x >/tmp/x
cpu% { sleep 10; cat } : file does not exist

However, before the i/o takes place, it's possible for another
file to be created and re-use the same Ram struct, setting
the busy flag again. The process which had the deleted file open
is now doing i/o to a different file, without any checks on its
permissions, exclusive use flag, etc.

cpu% ramfs
cpu% echo this is x >/tmp/x
cpu% { sleep 10; cat } /tmp/y
cpu% actually this is y

A simple fix is to add a reference count to the Ram struct, to
keep track of how many Fids point to it, and only allow a Ram to
be re-used if both busy==0 and ref==0. The new 9legacy patch
ramfs-refcount makes this change.

Note to 9front users: don't worry, your ramfs is a completely
different program using the 9p(2) library, which doesn't have
this flaw.


--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tc364b766ff6473bc-M52976e87f40d78ae095f576e
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription