Skip to contentSkip to conversation

Make udev rules more robust

PATCH New Demi Marie Obenour 1 participant 4 messages Apr 4, 2022

lore
Share & tools
lore
#0 lore raw

cover Make udev rules more robust

This makes the udev rules more robust against various unsafe error conditions.

Demi Marie Obenour (3):
dmsetup: return non-zero on stdio I/O error Disable lvm2 udev rules if dmsetup splitname fails Disable udev rules if udev flags can't be obtained

 libdm/dm-tools/dmsetup.c | 2 ++
 udev/10-dm.rules.in      | 2 +-
 udev/11-dm-lvm.rules.in  | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
Signature · 3 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab

_______________________________________________
linux-lvm mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/

#3 lore raw

PATCH 3/3 Disable udev rules if udev flags can't be obtained

In this cased the safest option is to disable most udev rules.

---
 udev/10-dm.rules.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
udev/10-dm.rules.in +1 -1
index b4fa52a..9fae8df 100644
@@ -50,7 +50,7 @@ ACTION!="add|change", GOTO="dm_end"
 # These flags are encoded in DM_COOKIE variable that was introduced in
 # kernel version 2.6.31. Therefore, we can use this feature with
 # kernels >= 2.6.31 only. Cookie is not decoded for remove event.
-ENV{DM_COOKIE}=="?*", IMPORT{program}="(DM_EXEC)/dmsetup udevflags $env{DM_COOKIE}"
+ENV{DM_COOKIE}=="?*", IMPORT{program}!="(DM_EXEC)/dmsetup udevflags $env{DM_COOKIE}", GOTO="dm_disable"
 
 # Rule out easy-to-detect inappropriate events first.
 ENV{DISK_RO}=="1", GOTO="dm_disable"
Signature · 3 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab

_______________________________________________
linux-lvm mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/

#1 lore raw

PATCH 1/3 dmsetup: return non-zero on stdio I/O error

In reply to Demi Marie Obenour

If there is an I/O error on stdout, return a non-zero status so that udev can avoid trusting the values printed. Deeper changes to the log code are out of scope for this patch.

---
 libdm/dm-tools/dmsetup.c | 2 ++
 1 file changed, 2 insertions(+)
libdm/dm-tools/dmsetup.c +2 -0
index d01b8f2..0449e40 100644
@@ -7491,5 +7491,7 @@ out:
 	if (_initial_timestamp)
 		dm_timestamp_destroy(_initial_timestamp);
 
+        if (fflush(stdout) || ferror(stdout))
+            return 1;
 	return (_switches[HELP_ARG] || _switches[VERSION_ARG]) ? 0 : ret;
 }
Signature · 3 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab

_______________________________________________
linux-lvm mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/

#2 lore raw

PATCH 2/3 Disable lvm2 udev rules if `dmsetup splitname` fails

In reply to Demi Marie Obenour

If the output of dmsetup splitname cannot be trusted, the safest option is to disable all lvm2 rules.

---
 udev/11-dm-lvm.rules.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
udev/11-dm-lvm.rules.in +1 -1
index 7c58994..f7066b7 100644
@@ -18,7 +18,7 @@ ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="lvm_end"
 ENV{DM_UUID}!="LVM-?*", GOTO="lvm_end"
 
 # Use DM name and split it up into its VG/LV/layer constituents.
-IMPORT{program}="(DM_EXEC)/dmsetup splitname --nameprefixes --noheadings --rows $env{DM_NAME}"
+IMPORT{program}!="(DM_EXEC)/dmsetup splitname --nameprefixes --noheadings --rows $env{DM_NAME}", GOTO="lvm_disable"
 
 # DM_SUBSYSTEM_UDEV_FLAG0 is the 'NOSCAN' flag for LVM subsystem.
 # This flag is used to temporarily disable selected rules to prevent any
Signature · 3 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab

_______________________________________________
linux-lvm mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/