Skip to content

Instantly share code, notes, and snippets.

@aronsky
Created October 27, 2016 08:48
Show Gist options
  • Save aronsky/05de2cb06859c2c5c7e69c27db7354b9 to your computer and use it in GitHub Desktop.
Save aronsky/05de2cb06859c2c5c7e69c27db7354b9 to your computer and use it in GitHub Desktop.

Revisions

  1. aronsky created this gist Oct 27, 2016.
    46 changes: 46 additions & 0 deletions wp_mod.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/version.h>
    #include <linux/kallsyms.h>

    #include <../fs/mount.h>
    #include <linux/namei.h>
    #include <linux/blkdev.h>

    #define DRIVER_AUTHOR "mr47"
    #define DRIVER_DESCRIPTION "KnoxOut"
    #define DRIVER_VERSION "1.0"

    static int __init wp_mod_init(void)
    {
    struct path path;
    struct super_block *sb;

    pr_info("wp_mod: %s version %s\n", DRIVER_DESCRIPTION, DRIVER_VERSION);
    pr_info("wp_mod: by %s\n", DRIVER_AUTHOR);


    if (kern_path("/system", LOOKUP_FOLLOW, &path)) {
    pr_info("wp_mod: kern_path failed!\n");
    }

    sb = path.mnt->mnt_sb;
    pr_info("wp_mod: block device superblock policy: 0x%08x\n", sb->s_bdev->bd_part->policy);
    sb->s_bdev->bd_part->policy = 0;

    return 0;
    }

    static void __exit wp_mod_exit(void)
    {
    return;
    }

    module_init(wp_mod_init);
    module_exit(wp_mod_exit);

    MODULE_AUTHOR(DRIVER_AUTHOR);
    MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
    MODULE_VERSION(DRIVER_VERSION);
    MODULE_LICENSE("GPL");