Page MenuHomeFreeBSD

loader: allow fs modules to use ioctl()
ClosedPublic

Authored by tsoome on Feb 20 2025, 3:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 5, 12:23 PM
Unknown Object (File)
Tue, Mar 4, 5:13 PM
Unknown Object (File)
Tue, Mar 4, 1:57 PM
Unknown Object (File)
Tue, Mar 4, 12:52 AM
Unknown Object (File)
Feb 27 2025, 4:24 PM
Unknown Object (File)
Feb 27 2025, 12:55 AM
Unknown Object (File)
Feb 26 2025, 7:02 PM
Unknown Object (File)
Feb 26 2025, 6:50 PM
Subscribers

Details

Summary

Currently only directly opened disk device is allowed to access
ioctl() - that is, when file has F_RAW flag set.

The problem is, file systems might need to determine the device parameters,
and we could use already opened device descriptor to communicate this
information.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I thought that we checked for raw because we couldn't guarantee that all other implementations had the right pre-req to allow this safely.
I remember getting burned by something similar because we weren't completely consistent... Maybe f->f_dev isn't always set? It's been a while.

In D49077#1120387, @imp wrote:

I thought that we checked for raw because we couldn't guarantee that all other implementations had the right pre-req to allow this safely.
I remember getting burned by something similar because we weren't completely consistent... Maybe f->f_dev isn't always set? It's been a while.

Well, thats why I did add f_dev check - if it is NULL, we can not do much anyhow. And we do return EIO, same as before. We use this feature in dosfs.c to read sector size; of course the alternative would be to take disk name, open with raw flag, get ioctl done and close it... but we already do have fd of open disk device.

In D49077#1120387, @imp wrote:

I thought that we checked for raw because we couldn't guarantee that all other implementations had the right pre-req to allow this safely.
I remember getting burned by something similar because we weren't completely consistent... Maybe f->f_dev isn't always set? It's been a while.

Well, thats why I did add f_dev check - if it is NULL, we can not do much anyhow. And we do return EIO, same as before. We use this feature in dosfs.c to read sector size; of course the alternative would be to take disk name, open with raw flag, get ioctl done and close it... but we already do have fd of open disk device.

Ooops. I missed this coming in during the week...

So I think this will be OK. It will certainly fail safely. It does expose a small hole in our device model (The Filesystem mounted on The Partition: no chance for one to many relationships w/o gymnastics to hide that in the device layer. But even with them, I think this is fine to commit as is. While I can construct weird edge cases, I think moving forward on this will be more useful than ensuring the weird edge cases are taken care of.

This revision is now accepted and ready to land.Sun, Mar 2, 10:12 PM
This revision was automatically updated to reflect the committed changes.