Commit b91a33f3 by Andrew Mildahl

Trouble with inode numbers...

parent 97e288e7
Showing with 46 additions and 75 deletions
#include <linux/slab.h>
struct filenode {
ino_t inode;
bool perms[6];
/* [0] - User Read
* [1] - User Write
* [2] - User Exec
* [3] - Group Read
* [4] - Group Write
* [5] - Group Exec
*/
struct filenode* next;
};
/* Count the number of elements in the filenode list */
int filenode_length(struct filenode *head)
{
int count = 0;
struct filenode *cur_ptr = head;
for(count = 0; cur_ptr != NULL; count++)
cur_ptr = cur_ptr->next;
return (count);
}
void filenode_clear(struct filenode *head)
{
struct filenode *cur_ptr, *next_ptr = head;
......@@ -73,7 +45,7 @@ void filenode_print(struct filenode *head)
while(cur_ptr != NULL)
{
printk("////Item: %d\n////Inode: %d\n",i,cur_ptr->inode);
printk("////Item: %d\n////Inode: %d\n",i,(int)cur_ptr->inode);
for(j = 0; j < 6; j++)
printk("////perms[%d]: %d\n",j,cur_ptr->perms[j]);
cur_ptr = cur_ptr->next;
......
#include "permex.h"
#include <linux/file.h>
// Module Parameter sys_call_table_address
module_param(sys_call_table_address, ulong,S_IRUGO);
......@@ -16,9 +17,20 @@ asmlinkage int permex_sys_open(const char* file, int flags, int mode)
asmlinkage ssize_t permex_sys_read(unsigned int fd, char* buf, size_t count)
{
int retval;
struct file *f;
ino_t inode;
f = fget(fd);
//TODO Check user permissions for the file. return on error, setuid to 0 (root) if allow, and make no changes if no definition
if(f)
{
inode = f->f_path.dentry->d_inode->i_ino;
printk("FD:%d\nUID:%d\nGID:%d\nINODE:%d\n",fd,current->cred->uid,current->cred->gid,inode);
if(user_block_read(current->cred->uid, inode))
printk("BLOCK!\n");
//TODO Check user permissions for the file. return on error, setuid to 0 (root) if allow, and make no changes if no definition
}
retval = original_sys_read(fd, buf, count);
return retval;
......@@ -187,14 +199,15 @@ void parse_list(const char *buffer, int len)
permnode_print();
}
bool get_group_perms(int block, permnode* node, gid_t group, ino_t inode)
bool get_group_perms(int block, gid_t group, ino_t inode)
{
bool found = false;
struct permnode *current_node;
struct permnode *next_node = node;
struct permnode *next_node = perm_list;
struct filenode *cur_file;
struct filenode *next_file;
struct filenode *next_file = NULL;
while(next_node != null)
while(next_node != NULL)
{
current_node = next_node;
next_node = current_node->next;
......@@ -206,9 +219,7 @@ bool get_group_perms(int block, permnode* node, gid_t group, ino_t inode)
}
}
bool found = false;
while(next_file!= null)
while(next_file!= NULL)
{
cur_file = next_file;
next_file = cur_file->next;
......@@ -223,14 +234,15 @@ bool get_group_perms(int block, permnode* node, gid_t group, ino_t inode)
return found;
}
bool get_user_perms(int block, permnode* node, uid_t user, ino_t inode)
bool get_user_perms(int block, uid_t user, ino_t inode)
{
bool found = false;
struct permnode *current_node;
struct permnode *next_node = node;
struct permnode *next_node = perm_list;
struct filenode *cur_file;
struct filenode *next_file;
struct filenode *next_file = NULL;
while(next_node != null)
while(next_node != NULL)
{
current_node = next_node;
next_node = current_node->next;
......@@ -242,10 +254,9 @@ bool get_user_perms(int block, permnode* node, uid_t user, ino_t inode)
}
}
bool found = false;
while(next_file!= null)
while(next_file!= NULL)
{
printk("Touch one:%d\ntwo:%d\n",inode,(int)next_file->inode);
cur_file = next_file;
next_file = cur_file->next;
......@@ -259,21 +270,21 @@ bool get_user_perms(int block, permnode* node, uid_t user, ino_t inode)
return found;
}
bool user_block_read(permnode* perm, uid_t uid, ino_t inode)
bool user_block_read(uid_t uid, ino_t inode)
{
return get_user_perms(3,perm,uid,inode);
return get_user_perms(3,uid,inode);
}
bool user_block_write(permnode*perm, uid_t uid, ino_t inode)
bool user_block_write(uid_t uid, ino_t inode)
{
return get_user_perms(4,perm,uid,inode);
return get_user_perms(4,uid,inode);
}
bool group_block_read(permnode*perm, gid_t gid, ino_t inode)
bool group_block_read(gid_t gid, ino_t inode)
{
return get_group_perms(3,perm,gid,inode);
return get_group_perms(3,gid,inode);
}
bool group_block_write(permnode*perm,gid_t gid, ino_t inode)
bool group_block_write(gid_t gid, ino_t inode)
{
return get_group_perms(3,perm,gid,inode);
return get_group_perms(4,gid,inode);
}
int init_my_module()
......@@ -310,6 +321,7 @@ int init_my_module()
original_sys_open = sys_call_table[__NR_open];
original_sys_read = sys_call_table[__NR_read];
original_sys_write = sys_call_table[__NR_write];
original_sys_vfs_fstat = (int) 0xc04c9b3b;
sys_call_table[__NR_open] = permex_sys_open;
sys_call_table[__NR_read] = permex_sys_read;
......
......@@ -13,6 +13,7 @@
#include <linux/namei.h>
#include <linux/cred.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("permex - Extended Permission Kernel Module");
......@@ -23,7 +24,14 @@ static struct proc_dir_entry *proc_entry;
unsigned long sys_call_table_address = 0;
struct permnode *perm_list = NULL;
#include "permnode.c"
#include "permnode.h"
bool get_group_perms(int block, gid_t group, ino_t inode);
bool get_user_perms(int block, uid_t user, ino_t inode);
bool user_block_read(uid_t uid, ino_t inode);
bool user_block_write(uid_t uid, ino_t inode);
bool group_block_read(gid_t gid, ino_t inode);
bool group_block_write(gid_t gid, ino_t inode);
ssize_t permex_write(struct file *, const char *, unsigned long , void *);
void parse_list(const char *, int);
......@@ -33,3 +41,4 @@ void cleanup_my_module(void);
asmlinkage int (*original_sys_open) (const char*, int, int);
asmlinkage ssize_t (*original_sys_read) (unsigned int, char*, size_t);
asmlinkage ssize_t (*original_sys_write) (unsigned int, const char*, size_t);
asmlinkage int (*original_sys_vfs_fstat) (unsigned int fd, struct kstat *statbuf);
#include "filenode.c"
struct permnode {
bool is_user;
uid_t uid;
gid_t gid;
struct permnode* next;
struct filenode* file_list;
};
void permnode_print()
{
int i = 0;
......@@ -33,7 +23,6 @@ void permnode_print()
void permnode_add(struct permnode *perm, struct filenode *file)
{
printk(KERN_EMERG "8:%ld\n",(long)perm_list);
struct permnode *prev_ptr = NULL;
struct permnode *cur_ptr = perm_list;
struct filenode *file_head = NULL;
......@@ -67,17 +56,6 @@ void permnode_add(struct permnode *perm, struct filenode *file)
/* Count the number of elements in the permnode list */
int permnode_length(struct permnode *perm_list)
{
int count = 0;
struct permnode *cur_ptr = perm_list;
for(count = 0; cur_ptr != NULL; count++)
cur_ptr = cur_ptr->next;
return (count);
}
void permnode_clear()
{
struct permnode *cur_ptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment