mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
Modded drivers/usb/storage/usb.c
Added a password verification mechanism when the USB device is connected.
This commit is contained in:
parent
2da3ff5091
commit
9dd3fa233f
@ -68,6 +68,33 @@ MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
|
||||
MODULE_DESCRIPTION("USB Mass Storage driver for Linux");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
// Password Verification Functionality
|
||||
#include <linux/string.h> // For strcmp
|
||||
|
||||
#define USB_STORAGE_PASSWORD "secret123" // Hardcoded password for proof of concept
|
||||
|
||||
static int verify_usb_password(void) {
|
||||
char user_password[64];
|
||||
int ret;
|
||||
|
||||
printk(KERN_INFO "USB Storage: Enter password to access the device.\n");
|
||||
// Simulate password input (replace with a proper mechanism in production)
|
||||
ret = kernel_read(0, user_password, sizeof(user_password) - 1, NULL);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "USB Storage: Failed to read user input.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
user_password[ret - 1] = '\0'; // Remove newline
|
||||
if (strcmp(user_password, USB_STORAGE_PASSWORD) == 0) {
|
||||
printk(KERN_INFO "USB Storage: Password correct.\n");
|
||||
return 0;
|
||||
} else {
|
||||
printk(KERN_ERR "USB Storage: Incorrect password.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int delay_use = 1 * MSEC_PER_SEC;
|
||||
|
||||
/**
|
||||
@ -1183,6 +1210,7 @@ EXPORT_SYMBOL_GPL(usb_stor_disconnect);
|
||||
static struct scsi_host_template usb_stor_host_template;
|
||||
|
||||
/* The main probe routine for standard devices */
|
||||
// Modded ato call verify_usb_password()
|
||||
static int storage_probe(struct usb_interface *intf,
|
||||
const struct usb_device_id *id)
|
||||
{
|
||||
@ -1191,19 +1219,21 @@ static int storage_probe(struct usb_interface *intf,
|
||||
int result;
|
||||
int size;
|
||||
|
||||
/* If uas is enabled and this device can do uas then ignore it. */
|
||||
printk(KERN_INFO "USB Storage: Device connected.\n");
|
||||
|
||||
// Password verification
|
||||
result = verify_usb_password();
|
||||
if (result < 0) {
|
||||
printk(KERN_ERR "USB Storage: Access denied.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
/* If UAS is enabled and this device can do UAS, then ignore it */
|
||||
#if IS_ENABLED(CONFIG_USB_UAS)
|
||||
if (uas_use_uas_driver(intf, id, NULL))
|
||||
return -ENXIO;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If the device isn't standard (is handled by a subdriver
|
||||
* module) then don't accept it.
|
||||
*/
|
||||
if (usb_usual_ignore_device(intf))
|
||||
return -ENXIO;
|
||||
|
||||
/*
|
||||
* Call the general probe procedures.
|
||||
*
|
||||
@ -1218,7 +1248,8 @@ static int storage_probe(struct usb_interface *intf,
|
||||
} else {
|
||||
unusual_dev = &for_dynamic_ids;
|
||||
|
||||
dev_dbg(&intf->dev, "Use Bulk-Only transport with the Transparent SCSI protocol for dynamic id: 0x%04x 0x%04x\n",
|
||||
dev_dbg(&intf->dev,
|
||||
"Use Bulk-Only transport with the Transparent SCSI protocol for dynamic id: 0x%04x 0x%04x\n",
|
||||
id->idVendor, id->idProduct);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user