Students should fill in the sections marked /* TODO */. #inc…
Students should fill in the sections marked /* TODO */. #include #include #include #include #define MAX_SIZE 256static char kernel_vault[MAX_SIZE];static int message_len = 0;/* * Function called when you ‘echo’ to the device * Should ENCRYPT the data (+1) before storing it */ssize_t vault_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) { int i; message_len = (count < MAX_SIZE) ? count : MAX_SIZE - 1; if (copy_from_user(kernel_vault, buf, message_len)) { return -EFAULT; } // TODO: Loop through kernel_vault and shift characters +1 // Hint: Check if character is between 'a'-'y' or 'A'-'Y' before adding 1 // Handle 'z' and 'Z' separately to wrap them to 'a' and 'A' printk(KERN_INFO "Vault: Data encrypted and stored.\n"); return count;}/* * Function called when you 'cat' the device * Should DECRYPT the data (-1) before showing it to user */ssize_t vault_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { static int completed = 0; char decrypt_temp[MAX_SIZE]; int i; if (completed) { completed = 0; return 0; } if (message_len == 0) { char *empty = "Vault is empty.\n"; copy_to_user(buf, empty, strlen(empty)); completed = 1; return strlen(empty); } // Copy to a temp buffer so we don't ruin the encrypted data in the vault memcpy(decrypt_temp, kernel_vault, message_len); // TODO: Loop through decrypt_temp and shift characters -1 // Hint: (char - 'a' - 1 + 26) % 26 + 'a' handles the wrap-around safely if (copy_to_user(buf, decrypt_temp, message_len)) { return -EFAULT; } completed = 1; return message_len;}static struct proc_ops v_ops = { .proc_read = vault_read, .proc_write = vault_write,};int init_module(void) { proc_create("vault", 0, NULL, &v_ops); printk(KERN_INFO "Vault Module Loaded.\n"); return 0;}void cleanup_module(void) { remove_proc_entry("vault", NULL); printk(KERN_INFO "Vault Module Unloaded.\n");}MODULE_LICENSE("GPL");
Read DetailsThe Secure Kernel Vault 1. Background: What is a Caesar Ciph…
The Secure Kernel Vault 1. Background: What is a Caesar Cipher? The Caesar Cipher is one of the oldest and simplest encryption techniques. It is a substitution cipher where each letter in the original message (plaintext) is replaced by a letter some fixed number of positions down the alphabet. In this assignment, we will use a Shift of 1: Enciphering (Writing to Kernel): We move +1 forward. (‘A’ becomes ‘B’, ‘h’ becomes ‘i’). Deciphering (Reading from Kernel): We move -1 backward. (‘B’ becomes ‘A’, ‘i’ becomes ‘h’). Example: Input: Hello Stored in Kernel (Scrambled): Ifmmp Output to User: Hello 2. Your Task Create a Loadable Kernel Module (LKM) that manages a /proc/vault entry. Your module must: On Write: Receive a string from the user, shift every alphabetic character by +1, and store it in a kernel buffer. On Read: Take the scrambled string, shift every character back by -1, and display the original message to the user. Persistence: The scrambled message should remain in memory until a new write overwrites it. 3. Implementation Requirements Use copy_from_user and copy_to_user for safe data transfer. Use a buffer of size 256 to store the message. Implement the “completed” toggle logic in proc_read to prevent cat from looping infinitely. Circular Logic: If a user writes ‘z’, it should wrap around to ‘a’. 4. Testing Steps for Students Compile and Insert: Run make and sudo insmod vault.ko. Write Data: Run echo “Attack at Dawn” > /proc/vault. Check Scrambled Data: Run dmesg | tail. Print Sramble text in Kernel log: Add a printk in write to show the scrambled string. Read Data: Run cat /proc/vault. It should correctly show Attack at Dawn.
Read Details