Skip to contentSkip to conversation

virtio: nsm: require CAP_SYS_ADMIN for raw messages

PATCH In review Yousef Alhouseen 2 participants 3 messages Jun 24 – Jun 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: nsm: require CAP_SYS_ADMIN for raw messages

NSM_IOCTL_RAW is documented as CAP_SYS_ADMIN-only.

/dev/nsm is mode 0666, but the ioctl handler did not check that capability.

Reject unprivileged raw messages before sending them to the device.

---
 drivers/misc/nsm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/nsm.c +4 -0
index e39ff0071..8153edff3 100644
@@ -9,6 +9,7 @@
  * space can use to issue these commands.
  */
 
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
@@ -361,6 +362,9 @@ static long nsm_dev_ioctl(struct file *file, unsigned int cmd,
 	if (cmd != NSM_IOCTL_RAW)
 		return -EINVAL;
 
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
 	if (_IOC_SIZE(cmd) != sizeof(raw))
 		return -EINVAL;
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 7 lines · Yousef Alhouseen

NSM_IOCTL_RAW is documented as CAP_SYS_ADMIN-only.

/dev/nsm is mode 0666, but the ioctl handler did not check that capability.

Reject unprivileged raw messages before sending them to the device.

This looks like a direct duplicate of
https://lore.kernel.org/lkml/[email protected]/?

Alex

Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597

#2 lore raw

Thanks for catching that. You are right; this duplicates the earlier patch.

Please drop this one. Sorry for the noise.

Yousef

Quoted 21 lines · Alexander
Quoted 7 lines · Yousef Alhouseen

NSM_IOCTL_RAW is documented as CAP_SYS_ADMIN-only.

/dev/nsm is mode 0666, but the ioctl handler did not check that capability.

Reject unprivileged raw messages before sending them to the device.

This looks like a direct duplicate of
https://lore.kernel.org/lkml/[email protected]/?

Alex

Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597