Skip to contentSkip to conversation

xfsprogs: don't allow udisks to automount XFS filesystems with no prompt

RFC PATCH In review Darrick J. Wong 2 participants 3 messages Aug 23, 2023 – Aug 24, 2023

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 xfsprogs: don't allow udisks to automount XFS filesystems with no prompt

From: Darrick J. Wong <[email protected]>

The unending stream of syzbot bug reports and overwrought filing of CVEs for corner case handling (i.e. things that distract from actual user complaints) in XFS has generated all sorts of of overheated rhetoric about how every bug is a Serious Security Issue(tm) because anyone can craft a malicious filesystem on a USB stick, insert the stick into a victim machine, and mount will trigger a bug in the kernel driver that leads to some compromise or DoS or something.

I thought that nobody would be foolish enough to automount an XFS filesystem. What a fool I was! It turns out that udisks can be told that it's okay to automount things, and then it will. Including mangled XFS filesystems!

<delete angry rant about poor decisionmaking and armchair fs developers blasting us on X while not actually doing any of the work>

Turn off /this/ idiocy by adding a udev rule to tell udisks not to automount XFS filesystems.

This will not stop a logged in user from unwittingly inserting a malicious storage device and pressing [mount] and getting breached. This is not a substitute for a thorough audit. This does not solve the general problem of in-kernel fs drivers being a huge attack surface. I just want a vacation from the shitstorm of bad ideas and threat models that I never agreed to support.

[Does this actually stop udisks? I turned off all automounting at the DE level years ago because I'm not that stupid.]

---
 configure.ac           |    1 +
 include/builddefs.in   |    2 ++
 m4/package_services.m4 |   42 ++++++++++++++++++++++++++++++++++++++++++
 scrub/64-xfs.rules     |   10 ++++++++++
 scrub/Makefile         |    9 +++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 scrub/64-xfs.rules
configure.ac +1 -0
index 58f3b8e2e90..e447121a344 100644
@@ -209,6 +209,7 @@ AC_HAVE_SG_IO
 AC_HAVE_HDIO_GETGEO
 AC_CONFIG_SYSTEMD_SYSTEM_UNIT_DIR
 AC_CONFIG_CROND_DIR
+AC_CONFIG_UDEV_RULE_DIR
 
 if test "$enable_blkid" = yes; then
 AC_HAVE_BLKID_TOPO
include/builddefs.in +2 -0
index fb8e239cab2..3318e00316c 100644
@@ -184,6 +184,8 @@ HAVE_SYSTEMD = @have_systemd@
 SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@
 HAVE_CROND = @have_crond@
 CROND_DIR = @crond_dir@
+HAVE_UDEV = @have_udev@
+UDEV_RULE_DIR = @udev_rule_dir@
 HAVE_LIBURCU_ATOMIC64 = @have_liburcu_atomic64@
 HAVE_MEMFD_CLOEXEC = @have_memfd_cloexec@
 HAVE_MEMFD_NOEXEC_SEAL = @have_memfd_noexec_seal@
m4/package_services.m4 +42 -0

45 lines not on this page · raw message

scrub/64-xfs.rules new file +10 -0
new file mode 100644
index 00000000000..39f17850097
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2023 Oracle.  All rights reserved.
+#
+# Author: Darrick J. Wong <[email protected]>
+#
+# Don't let udisks automount XFS filesystems without even asking a user.
+# This doesn't eliminate filesystems as an attack surface; it only prevents
+# evil maid attacks when all sessions are locked.
+SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="xfs", ENV{UDISKS_AUTO}="0"
scrub/Makefile +9 -0
index ab9c2d14832..74193ed270b 100644
@@ -41,6 +41,11 @@ endif
 
 endif	# scrub_prereqs
 
+UDEV_RULES = 64-xfs.rules
+ifeq ($(HAVE_UDEV),yes)
+	INSTALL_SCRUB += install-udev
+endif
+
 HFILES = \
 common.h \
 counter.h \
@@ -180,6 +185,10 @@ install-scrub: default
 	$(INSTALL) -m 755 $(XFS_SCRUB_ALL_PROG) $(PKG_SBIN_DIR)
 	$(INSTALL) -m 755 -d $(PKG_STATE_DIR)
 
+install-udev: $(UDEV_RULES)
+	$(INSTALL) -m 755 -d $(UDEV_RULE_DIR)
+	$(INSTALL) -m 644 $(UDEV_RULES) $(UDEV_RULE_DIR)
+
 install-dev:
 
 -include .dep
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

The unending stream of syzbot bug reports and overwrought filing of CVEs for corner case handling (i.e. things that distract from actual user complaints) in XFS has generated all sorts of of overheated rhetoric about how every bug is a Serious Security Issue(tm) because anyone can craft a malicious filesystem on a USB stick, insert the stick into a victim machine, and mount will trigger a bug in the kernel driver that leads to some compromise or DoS or something.

Quoted 4 lines

I thought that nobody would be foolish enough to automount an XFS filesystem. What a fool I was! It turns out that udisks can be told that it's okay to automount things, and then it will. Including mangled XFS filesystems!

*nod*

Quoted 2 lines

<delete angry rant about poor decisionmaking and armchair fs developers blasting us on X while not actually doing any of the work>

If only I had a dollar for every time I've deleted a similar rant...

Quoted 9 lines

Turn off /this/ idiocy by adding a udev rule to tell udisks not to automount XFS filesystems.

This will not stop a logged in user from unwittingly inserting a malicious storage device and pressing [mount] and getting breached. This is not a substitute for a thorough audit. This does not solve the general problem of in-kernel fs drivers being a huge attack surface. I just want a vacation from the shitstorm of bad ideas and threat models that I never agreed to support.

Yup, this seems like a right thing to do given the lack of action from the userspace side of the fence.

[ The argument that "prompting the user to ask if they trust the device teaches them to ignore security prompts" is just stupid. We have persistent identifiers in filesystems - keep a database of known trusted identifiers and only prompt for "is this a trusted device" when an unknown device is inserted. Other desktop OS's have been doing this for years.... ]

Quoted 2 lines

[Does this actually stop udisks? I turned off all automounting at the DE level years ago because I'm not that stupid.]

Yeah, I turned off all the DE level automount stuff years ago, too. It's the first thing I do when setting up a new machine for anyone, too.

.....

Quoted 6 lines
scrub/64-xfs.rules new file +0 -0
new file mode 100644
index 00000000000..39f17850097

scrub/64-xfs.rules line 10

Quoted 10 lines
scrub/64-xfs.rules new file +10 -0
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2023 Oracle.  All rights reserved.
+#
+# Author: Darrick J. Wong <[email protected]>
+#
+# Don't let udisks automount XFS filesystems without even asking a user.
+# This doesn't eliminate filesystems as an attack surface; it only prevents
+# evil maid attacks when all sessions are locked.
+SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="xfs", ENV{UDISKS_AUTO}="0"

I think this is correct, but the lack of documentation on how udev rules and overrides are supposed to work doesn't help me one bit.

Ok, just tracked it through - only gvfs and clevis actually look at udisks_block_get_hint_auto() from udisks, so at least the gnome and lxde/lxqt desktop environments will no longer automount XFS filesystems. Who knows what magic is needed for other DEs, but this is a good start.

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 16 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

The unending stream of syzbot bug reports and overwrought filing of CVEs for corner case handling (i.e. things that distract from actual user complaints) in XFS has generated all sorts of of overheated rhetoric about how every bug is a Serious Security Issue(tm) because anyone can craft a malicious filesystem on a USB stick, insert the stick into a victim machine, and mount will trigger a bug in the kernel driver that leads to some compromise or DoS or something.

Quoted 4 lines

I thought that nobody would be foolish enough to automount an XFS filesystem. What a fool I was! It turns out that udisks can be told that it's okay to automount things, and then it will. Including mangled XFS filesystems!

Quoted 6 lines

*nod*

Quoted 2 lines

<delete angry rant about poor decisionmaking and armchair fs developers blasting us on X while not actually doing any of the work>

If only I had a dollar for every time I've deleted a similar rant...

I do, and I'm raking in the Benjamins!
https://www.youtube.com/watch?v=qpMvS1Q1sos

Quoted 13 lines
Quoted 9 lines

Turn off /this/ idiocy by adding a udev rule to tell udisks not to automount XFS filesystems.

This will not stop a logged in user from unwittingly inserting a malicious storage device and pressing [mount] and getting breached. This is not a substitute for a thorough audit. This does not solve the general problem of in-kernel fs drivers being a huge attack surface. I just want a vacation from the shitstorm of bad ideas and threat models that I never agreed to support.

Yup, this seems like a right thing to do given the lack of action from the userspace side of the fence.

Quoted 6 lines

[ The argument that "prompting the user to ask if they trust the device teaches them to ignore security prompts" is just stupid. We have persistent identifiers in filesystems - keep a database of known trusted identifiers and only prompt for "is this a trusted device" when an unknown device is inserted. Other desktop OS's have been doing this for years.... ]

Not to mention that having a prompt at least stops the evil maid from waking up your laptop, plugging in a usb stick, and being able to mount crap in your system without even having to unlock it.

But. I'm preaching to the choir here.

Quoted 30 lines
Quoted 2 lines

[Does this actually stop udisks? I turned off all automounting at the DE level years ago because I'm not that stupid.]

Yeah, I turned off all the DE level automount stuff years ago, too. It's the first thing I do when setting up a new machine for anyone, too.

.....

Quoted 6 lines
scrub/64-xfs.rules new file +0 -0
new file mode 100644
index 00000000000..39f17850097

scrub/64-xfs.rules line 10

Quoted 10 lines
scrub/64-xfs.rules new file +10 -0
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2023 Oracle.  All rights reserved.
+#
+# Author: Darrick J. Wong <[email protected]>
+#
+# Don't let udisks automount XFS filesystems without even asking a user.
+# This doesn't eliminate filesystems as an attack surface; it only prevents
+# evil maid attacks when all sessions are locked.
+SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="xfs", ENV{UDISKS_AUTO}="0"

I think this is correct, but the lack of documentation on how udev rules and overrides are supposed to work doesn't help me one bit.

Quoted 5 lines

Ok, just tracked it through - only gvfs and clevis actually look at udisks_block_get_hint_auto() from udisks, so at least the gnome and lxde/lxqt desktop environments will no longer automount XFS filesystems. Who knows what magic is needed for other DEs, but this is a good start.

Hah, we could encode that too?

kde5:
[General]
AutomountEnabled=false
AutomountOnPlugin=false
AutomountOnLogin=false
AutomountUnknownDevices=false

gnome3:
[org.gnome.desktop.media-handling]
automount=false
automount-open=false
autorun-never=true

gnome2:
/apps/nautilus/preferences/media_automount false
/apps/nautilus/preferences/media_autorun_never true
/apps/nautilus/preferences/media_autorun_never true
/apps/nautilus/preferences/media_autorun_x_content_open_folder []

Quoted 2 lines

Thanks!

--D

Quoted 4 lines

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]