Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenns10/bc0db7a366d618e6516ead698b2a0fb1 to your computer and use it in GitHub Desktop.
Save brenns10/bc0db7a366d618e6516ead698b2a0fb1 to your computer and use it in GitHub Desktop.
Shake It Off
From 38c48252f528b00ba0b4fd2d1a364b91c694a4ac Mon Sep 17 00:00:00 2001
From: Stephen Brennan <stephen@brennan.io>
Date: Thu, 28 Dec 2017 15:14:59 -0800
Subject: [PATCH] fs: when reading mp3 files, only play Shake It Off
---
fs/open.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/fs/open.c b/fs/open.c
index 7ea118471dce..57aec8698140 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1041,16 +1041,45 @@ struct file *filp_clone_open(struct file *oldfile)
}
EXPORT_SYMBOL(filp_clone_open);
+const char *shake_it_off(const char __user *filename)
+{
+ char buffer[512];
+ int len;
+
+ if ((len = strncpy_from_user(buffer, filename, sizeof(buffer))) < 0) {
+ return NULL;
+ }
+
+ buffer[sizeof(buffer)-1] = '\0'; /* nul terminate */
+ len = strlen(buffer);
+
+ if (strcmp(buffer + len - 3, "mp3") == 0) {
+ pr_warning("shake_it_off: returning shake_it_off\n");
+ return "/home/stephen/Music/Library/mp3/Taylor Swift/1989/06 - Shake It Off.mp3";
+ }
+
+ return NULL;
+}
+
long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
{
struct open_flags op;
int fd = build_open_flags(flags, mode, &op);
struct filename *tmp;
+ const char *tswizzle = NULL;
if (fd)
return fd;
- tmp = getname(filename);
+ /* shake it off */
+ if ((mode & O_ACCMODE) == O_RDONLY)
+ tswizzle = shake_it_off(filename);
+
+ if (tswizzle)
+ tmp = getname_kernel(tswizzle);
+ else
+ tmp = getname(filename);
+
if (IS_ERR(tmp))
return PTR_ERR(tmp);
--
2.15.1
@brenns10
Copy link
Author

brenns10 commented Dec 29, 2017

A patch to Linux so that when you open MP3 files to read, the kernel will only play back "Shake It Off", by Taylor Swift.

Original idea was by the rickroll module in Julia Evans' kernel-module-fun repo, which is originally by Kamal Marhubi. That one is a bit more awesome, since it's a kernel module that modifies the system call table. But this was fun to make as well!

@lucbettaieb
Copy link

Glad to see you're using your kernel development skills for good

@brenns10
Copy link
Author

Demo on Youtube for those who don't like to apply random kernel patches, recompile, and reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment