Skip to contentSkip to conversation

Root_plug device check

PATCH In review Fabian Frederick 2 participants 2 messages Apr 3, 2004 – Apr 7, 2004 Security (LSM)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Root_plug device check

Hi,

Here's a patch to check device in root_plug to avoid box freeze
when user gives bad ids.

Regards,
Fabian

security/root_plug.c +19 -2
diff -Naur orig/security/root_plug.c edited/security/root_plug.c
@@ -20,6 +20,9 @@
  *	modify it under the terms of the GNU General Public License as
  *	published by the Free Software Foundation, version 2 of the
  *	License.
+ *
+ * 03/2004 : (Fabian Frederick) 
+ *		-Make sure we have device if defined through module call
  */
 
 #include <linux/config.h>
@@ -33,8 +36,11 @@
 static int secondary;
 
 /* default is a generic type of usb to serial converter */
-static int vendor_id = 0x0557;
-static int product_id = 0x2008;
+#define DEFAULT_VENDOR 0x0557
+#define DEFAULT_PRODUCT 0x2008
+
+static int vendor_id = DEFAULT_VENDOR;
+static int product_id = DEFAULT_PRODUCT;
 
 MODULE_PARM(vendor_id, "h");
 MODULE_PARM_DESC(vendor_id, "USB Vendor ID of device to look for");
@@ -101,6 +107,17 @@
 
 static int __init rootplug_init (void)
 {
+	struct usb_device *dev;
+
+	/* check we have device featuring in usb list to avoid any trouble*/
+	if((vendor_id!=DEFAULT_VENDOR) || (product_id!=DEFAULT_PRODUCT)){
+		dev = usb_find_device(vendor_id, product_id);
+		if (!dev) {
+			printk (KERN_INFO "Unable to find USB device "
+				" We won't start to avoid box freeze.\n");
+			return -EINVAL;
+		}
+	}
 	/* register ourselves with the security framework */
 	if (register_security (&rootplug_security_ops)) {
 		printk (KERN_INFO 
#1 lore raw
Quoted 4 lines · Fabian Frederick

Hi,

Here's a patch to check device in root_plug to avoid box freeze
when user gives bad ids.

No, this patch is not acceptable. It's fine if the USB device is not present when the module is loaded, any future programs run as root will just not run.

So the current behavior is correct.

thanks,

greg k-h