Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #1082

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Linux - Modified USB Driver

Forked from https://github.com/torvalds/linux/tree/master.

For COSC439 final report, our team's goal is to To reverse engineer the
Linux USB driver by identifying system calls, finding the
implementation of these calls, and understanding how their implementation
works. The driver will be modified to implement automatic encryption of
files added to a USB flash drive and introduce user authentication for
accessing the files.



Linux kernel
============

Expand Down
115 changes: 73 additions & 42 deletions drivers/usb/storage/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -1183,54 +1210,58 @@ 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)
const struct usb_device_id *id)
{
const struct us_unusual_dev *unusual_dev;
struct us_data *us;
int result;
int size;

/* 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;
const struct us_unusual_dev *unusual_dev;
struct us_data *us;
int result;
int size;

/*
* Call the general probe procedures.
*
* The unusual_dev_list array is parallel to the usb_storage_usb_ids
* table, so we use the index of the id entry to find the
* corresponding unusual_devs entry.
*/

size = ARRAY_SIZE(us_unusual_dev_list);
if (id >= usb_storage_usb_ids && id < usb_storage_usb_ids + size) {
unusual_dev = (id - usb_storage_usb_ids) + us_unusual_dev_list;
} 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",
id->idVendor, id->idProduct);
}
printk(KERN_INFO "USB Storage: Device connected.\n");

result = usb_stor_probe1(&us, intf, id, unusual_dev,
&usb_stor_host_template);
if (result)
return result;
// Password verification
result = verify_usb_password();
if (result < 0) {
printk(KERN_ERR "USB Storage: Access denied.\n");
return result;
}

/* No special transport or protocol settings in the main module */
/* 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

result = usb_stor_probe2(us);
return result;
/*
* Call the general probe procedures.
*
* The unusual_dev_list array is parallel to the usb_storage_usb_ids
* table, so we use the index of the id entry to find the
* corresponding unusual_devs entry.
*/

size = ARRAY_SIZE(us_unusual_dev_list);
if (id >= usb_storage_usb_ids && id < usb_storage_usb_ids + size) {
unusual_dev = (id - usb_storage_usb_ids) + us_unusual_dev_list;
} 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",
id->idVendor, id->idProduct);
}

result = usb_stor_probe1(&us, intf, id, unusual_dev,
&usb_stor_host_template);
if (result)
return result;

/* No special transport or protocol settings in the main module */

result = usb_stor_probe2(us);
return result;
}

static struct usb_driver usb_storage_driver = {
Expand Down