Skip to contentSkip to conversation

Documentation: Document the kernel flag bdev_allow_write_mounted

PATCH Superseded Guilherme G. Piccoli 3 participants 4 messages Aug 23, 2024

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Documentation: Document the kernel flag bdev_allow_write_mounted

Commit ed5cc702d311 ("block: Add config option to not allow writing to mounted devices") added a Kconfig option along with a kernel command-line tuning to control writes to mounted block devices, as a means to deal with fuzzers like Syzkaller, that provokes kernel crashes by directly writing on block devices bypassing the filesystem (so the FS has no awareness and cannot cope with that).

The patch just missed adding such kernel command-line option to the kernel documentation, so let's fix that.

---

V2: Improved wording (thanks Darrick!)

V1 link: https://lore.kernel.org/r/[email protected]

 Documentation/admin-guide/kernel-parameters.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +12 -0
index 09126bb8cc9f..7c5283f11308 100644
@@ -517,6 +517,18 @@
 			Format: <io>,<irq>,<mode>
 			See header of drivers/net/hamradio/baycom_ser_hdx.c.
 
+	bdev_allow_write_mounted=
+			Format: <bool>
+			Control the ability of directly writing to mounted block
+			devices' page cache, i.e., allow / disallow writes that
+			bypasses the FS. This was implemented as a means to
+			prevent fuzzers from crashing the kernel by overwriting
+			the metadata underneath a mounted FS without its awareness.
+			This also prevents destructive formatting of mounted
+			filesystems by naive storage tooling that don't use
+			O_EXCL. Default is Y and can be changed through the
+			Kconfig option CONFIG_BLK_DEV_WRITE_MOUNTED.
+
 	bert_disable	[ACPI]
 			Disable BERT OS support on buggy BIOSes.
 
Signature · 1 line
2.46.0
#1 lore raw

Documentation/admin-guide/kernel-parameters.txt line 531

Quoted 12 lines · Guilherme G. Piccoli
Documentation/admin-guide/kernel-parameters.txt +12 -0
+	bdev_allow_write_mounted=
+			Format: <bool>
+			Control the ability of directly writing to mounted block
+			devices' page cache, i.e., allow / disallow writes that
+			bypasses the FS. This was implemented as a means to
+			prevent fuzzers from crashing the kernel by overwriting
+			the metadata underneath a mounted FS without its awareness.
+			This also prevents destructive formatting of mounted
+			filesystems by naive storage tooling that don't use
+			O_EXCL. Default is Y and can be changed through the
+			Kconfig option CONFIG_BLK_DEV_WRITE_MOUNTED.
+

Does this flag also affect direct I/O? If so, does this mean that the reference to the page cache should be left out?

Thanks,

Bart.

#2 lore raw
Quoted 16 lines · Bart Van Assche

Documentation/admin-guide/kernel-parameters.txt line 531

Quoted 12 lines · Guilherme G. Piccoli
Documentation/admin-guide/kernel-parameters.txt +12 -0
+	bdev_allow_write_mounted=
+			Format: <bool>
+			Control the ability of directly writing to mounted block
+			devices' page cache, i.e., allow / disallow writes that
+			bypasses the FS. This was implemented as a means to
+			prevent fuzzers from crashing the kernel by overwriting
+			the metadata underneath a mounted FS without its awareness.
+			This also prevents destructive formatting of mounted
+			filesystems by naive storage tooling that don't use
+			O_EXCL. Default is Y and can be changed through the
+			Kconfig option CONFIG_BLK_DEV_WRITE_MOUNTED.
+

Does this flag also affect direct I/O? If so, does this mean that the reference to the page cache should be left out?

I think it does affect directio, since the validation is done at open time via bdev_may_open, right?

--D

Quoted 3 lines

Thanks,

Bart.

#3 lore raw
Quoted 18 lines · Darrick J. Wong
Quoted 16 lines · Bart Van Assche

Documentation/admin-guide/kernel-parameters.txt line 531

Quoted 12 lines · Guilherme G. Piccoli
Documentation/admin-guide/kernel-parameters.txt +12 -0
+	bdev_allow_write_mounted=
+			Format: <bool>
+			Control the ability of directly writing to mounted block
+			devices' page cache, i.e., allow / disallow writes that
+			bypasses the FS. This was implemented as a means to
+			prevent fuzzers from crashing the kernel by overwriting
+			the metadata underneath a mounted FS without its awareness.
+			This also prevents destructive formatting of mounted
+			filesystems by naive storage tooling that don't use
+			O_EXCL. Default is Y and can be changed through the
+			Kconfig option CONFIG_BLK_DEV_WRITE_MOUNTED.
+

Does this flag also affect direct I/O? If so, does this mean that the reference to the page cache should be left out?

Quoted 3 lines

I think it does affect directio, since the validation is done at open time via bdev_may_open, right?

Indeed, good point! It does affect direct I/O, I've just tested in 6.11-rc3 using dd (with and w/o oflags=direct), same result.

I'll resend, dropping the mention to page cache - thanks!

Guilherme