dazuko_linux26.c File Reference

#include "dazuko_linux26.h"
#include "dazuko_core.h"
#include "dazuko_linux26_device_def.h"
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/vermagic.h>
#include <linux/security.h>
#include <linux/namei.h>
#include <linux/dcache.h>
#include <linux/mount.h>
#include <linux/devfs_fs_kernel.h>
#include <linux/device.h>
#include <linux/suspend.h>
#include <asm/uaccess.h>

Go to the source code of this file.

Defines

#define DAZUKO_DM   0
#define CHROOT_EVENT_STRING   "chroot:"
#define CHROOT_EVENT_LENGTH   7

Functions

char * __d_path (struct dentry *, struct vfsmount *, struct dentry *, struct vfsmount *, char *, int)
ssize_t linux_dazuko_device_read (struct file *, char __user *, size_t, loff_t *)
ssize_t linux_dazuko_device_write (struct file *, const char __user *, size_t, loff_t *)
int linux_dazuko_device_open (struct inode *, struct file *)
int linux_dazuko_device_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long param)
int linux_dazuko_device_release (struct inode *, struct file *)
static int dazuko_sys_generic (struct inode *inode, int mask, struct nameidata *nd)
int dazuko_register_security (const char *name, struct security_operations *ops)
int dazuko_unregister_security (const char *name, struct security_operations *ops)
void xp_init_mutex (struct xp_mutex *mutex)
void xp_down (struct xp_mutex *mutex)
void xp_up (struct xp_mutex *mutex)
void xp_destroy_mutex (struct xp_mutex *mutex)
void xp_init_rwlock (struct xp_rwlock *rwlock)
void xp_write_lock (struct xp_rwlock *rwlock)
void xp_write_unlock (struct xp_rwlock *rwlock)
void xp_read_lock (struct xp_rwlock *rlock)
void xp_read_unlock (struct xp_rwlock *rlock)
void xp_destroy_rwlock (struct xp_rwlock *rwlock)
int xp_init_queue (struct xp_queue *queue)
int xp_wait_until_condition (struct xp_queue *queue, int(*cfunction)(void *), void *cparam, int allow_interrupt)
int xp_notify (struct xp_queue *queue)
int xp_destroy_queue (struct xp_queue *queue)
void * xp_malloc (size_t size)
int xp_free (void *ptr)
int xp_copyin (const void *user_src, void *kernel_dest, size_t size)
int xp_copyout (const void *kernel_src, void *user_dest, size_t size)
int xp_verify_user_writable (const void *user_ptr, size_t size)
int xp_verify_user_readable (const void *user_ptr, size_t size)
int xp_is_absolute_path (const char *path)
int xp_atomic_set (struct xp_atomic *atomic, int value)
int xp_atomic_inc (struct xp_atomic *atomic)
int xp_atomic_dec (struct xp_atomic *atomic)
int xp_atomic_read (struct xp_atomic *atomic)
static int dazuko_get_full_filename (struct xp_file_struct *xfs)
static int dazuko_fill_file_struct_cleanup (struct dazuko_file_struct *dfs)
int xp_fill_file_struct (struct dazuko_file_struct *dfs)
static int dazuko_file_struct_cleanup (struct dazuko_file_struct **dfs)
static int check_parent (struct task_struct *parent, struct task_struct *child)
int xp_id_compare (struct xp_daemon_id *id1, struct xp_daemon_id *id2, int check_related)
int xp_id_free (struct xp_daemon_id *id)
xp_daemon_idxp_id_copy (struct xp_daemon_id *id)
int xp_set_event_properties (struct event_properties *event_p, struct xp_daemon_id *xp_id)
int xp_init_cache (unsigned long ttl)
int xp_sys_hook ()
int xp_sys_unhook ()
int xp_print (const char *fmt,...)
ssize_t linux_dazuko_device_read (struct file *file, char *buffer, size_t length, loff_t *pos)
ssize_t linux_dazuko_device_write (struct file *file, const char *buffer, size_t length, loff_t *pos)
static int __init linux_dazuko_init (void)
static void __exit linux_dazuko_exit (void)
 MODULE_AUTHOR ("H+BEDV Datentechnik GmbH <linux_support@antivir.de>")
 MODULE_DESCRIPTION ("allow 3rd-party file access control")
 MODULE_LICENSE ("GPL")
 MODULE_INFO (vermagic, VERMAGIC_STRING)
 security_initcall (linux_dazuko_init)
 module_exit (linux_dazuko_exit)

Variables

static struct class_simple * dazuko_class = NULL
static struct vfsmount * orig_rootmnt = NULL
static struct dentry * orig_root = NULL
static int dev_major = -1
security_operations dazuko_security_ops
security_operations dazuko_register_security_ops
static struct security_operations dazuko_security_default_ops
static int secondary_register = 0
static struct file_operations fops


Define Documentation

#define CHROOT_EVENT_LENGTH   7
 

Definition at line 47 of file dazuko_linux26.c.

Referenced by dazuko_get_full_filename(), and xp_is_absolute_path().

#define CHROOT_EVENT_STRING   "chroot:"
 

Definition at line 46 of file dazuko_linux26.c.

Referenced by dazuko_get_full_filename(), and xp_is_absolute_path().

#define DAZUKO_DM   0
 

Definition at line 42 of file dazuko_linux26.c.


Function Documentation

char* __d_path struct dentry *  ,
struct vfsmount *  ,
struct dentry *  ,
struct vfsmount *  ,
char *  ,
int 
 

static int check_parent struct task_struct *  parent,
struct task_struct *  child
[inline, static]
 

Definition at line 581 of file dazuko_linux26.c.

References NULL.

00582 {
00583         struct task_struct      *ts = child;
00584 
00585         if (parent == NULL || child == NULL)
00586                 return -1;
00587 
00588         while (1)
00589         {
00590                 if (ts == parent)
00591                         return 0;
00592 
00593                 if (ts->parent == NULL)
00594                         break;
00595 
00596                 if (ts == ts->parent)
00597                         break;
00598 
00599                 ts = ts->parent;
00600         }
00601 
00602         return -1;
00603 }

static int dazuko_file_struct_cleanup struct dazuko_file_struct **  dfs  )  [static]
 

Definition at line 555 of file dazuko_linux26.c.

References NULL, and xp_free().

00556 {
00557         if (dfs == NULL)
00558                 return 0;
00559 
00560         if (*dfs == NULL)
00561                 return 0;
00562 
00563         if ((*dfs)->extra_data)
00564         {
00565                 if ((*dfs)->extra_data->free_full_filename)
00566                         xp_free((*dfs)->extra_data->full_filename);
00567 
00568                 xp_free((*dfs)->extra_data);
00569         }
00570 
00571         xp_free(*dfs);
00572 
00573         *dfs = NULL;
00574 
00575         return 0;
00576 }

static int dazuko_fill_file_struct_cleanup struct dazuko_file_struct dfs  )  [static]
 

Definition at line 488 of file dazuko_linux26.c.

References xp_file_struct::buffer, xp_file_struct::dentry, xp_file_struct::dput_dentry, dazuko_file_struct::extra_data, xp_file_struct::free_page_buffer, xp_file_struct::mntput_vfsmount, NULL, and xp_file_struct::vfsmount.

00489 {
00490         if (dfs == NULL)
00491                 return 0;
00492 
00493         if (dfs->extra_data == NULL)
00494                 return 0;
00495 
00496         if (dfs->extra_data->free_page_buffer)
00497         {
00498                 free_page((unsigned long)dfs->extra_data->buffer);
00499                 dfs->extra_data->free_page_buffer = 0;
00500         }
00501 
00502         if (dfs->extra_data->dput_dentry)
00503         {
00504                 dput(dfs->extra_data->dentry);
00505                 dfs->extra_data->dput_dentry = 0;
00506         }
00507 
00508         if (dfs->extra_data->mntput_vfsmount)
00509         {
00510                 mntput(dfs->extra_data->vfsmount);
00511                 dfs->extra_data->mntput_vfsmount = 0;
00512         }
00513 
00514         return 0;
00515 }

static int dazuko_get_full_filename struct xp_file_struct xfs  )  [static]
 

Definition at line 381 of file dazuko_linux26.c.

References __d_path(), xp_file_struct::buffer, CHROOT_EVENT_LENGTH, CHROOT_EVENT_STRING, dazuko_get_filename_length(), xp_file_struct::dentry, xp_file_struct::dput_dentry, xp_file_struct::free_full_filename, xp_file_struct::free_page_buffer, xp_file_struct::full_filename, xp_file_struct::full_filename_length, xp_file_struct::inode, xp_file_struct::mntput_vfsmount, xp_file_struct::nd, NULL, orig_root, orig_rootmnt, xp_file_struct::vfsmount, and xp_malloc().

00382 {
00383         struct vfsmount *rootmnt;
00384         struct dentry *root;
00385         char *temp;
00386 #ifdef USE_CHROOT
00387         int chrooted = 0;
00388 #endif
00389 
00390         if (xfs == NULL)
00391                 return 0;
00392 
00393         if (xfs->inode == NULL)
00394                 return 0;
00395 
00396 #ifndef DAZUKO_FIST
00397         if (S_ISDIR(xfs->inode->i_mode))
00398                 return 0;
00399 #endif
00400 
00401         if (xfs->nd == NULL || xfs->free_full_filename)
00402                 return 0;
00403         
00404         if (xfs->nd->mnt == NULL || xfs->nd->dentry == NULL)
00405                 return 0;
00406 
00407         /* check if we need to allocate a buffer */
00408         if (!xfs->free_page_buffer)
00409         {
00410                 /* get pre-requisites for d_path function */
00411                 xfs->buffer = (char *)__get_free_page(GFP_USER);
00412 
00413                 /* make sure we got a page */
00414                 if (xfs->buffer == NULL)
00415                         return 0;
00416 
00417                 /* the buffer will need to be freed */
00418                 xfs->free_page_buffer = 1;
00419         }
00420 
00421         /* make sure we don't already have a vfsmount */
00422         if (!xfs->mntput_vfsmount)
00423         {
00424                 xfs->vfsmount = mntget(xfs->nd->mnt);
00425 
00426                 /* the vfsmount will need to be put back */
00427                 xfs->mntput_vfsmount = 1;
00428         }
00429 
00430         /* make sure we don't already have a dentry */
00431         if (!xfs->dput_dentry)
00432         {
00433                 xfs->dentry = dget(xfs->nd->dentry);
00434 
00435                 /* the dentry will need to be put back */
00436                 xfs->dput_dentry = 1;
00437         }
00438 
00439         rootmnt = mntget(orig_rootmnt);
00440         root = dget(orig_root);
00441 
00442 #ifdef USE_CHROOT
00443         temp = d_path(xfs->dentry, xfs->vfsmount, xfs->buffer, PAGE_SIZE);
00444 
00445         if (orig_root != current->fs->root)
00446                 chrooted = 1;
00447 #else
00448         spin_lock(&dcache_lock);
00449         temp = __d_path(xfs->dentry, xfs->vfsmount, root, rootmnt, xfs->buffer, PAGE_SIZE);
00450         spin_unlock(&dcache_lock);
00451 #endif
00452 
00453         dput(root);
00454         mntput(rootmnt);
00455 
00456         /* make sure we really got a new filename */
00457         if (temp == NULL)
00458                 return 0;
00459         
00460         xfs->full_filename_length = dazuko_get_filename_length(temp);
00461 
00462 #ifdef USE_CHROOT
00463         if (chrooted)
00464                 xfs->full_filename_length += CHROOT_EVENT_LENGTH;
00465 #endif
00466         xfs->full_filename = (char *)xp_malloc(xfs->full_filename_length + 1);
00467         if (xfs->full_filename == NULL)
00468                 return 0;
00469         
00470         /* the char array will need to be freed */
00471         xfs->free_full_filename = 1;
00472 
00473 #ifdef USE_CHROOT
00474         if (chrooted)
00475         {
00476                 memcpy(xfs->full_filename, CHROOT_EVENT_STRING, CHROOT_EVENT_LENGTH + 1);
00477                 memcpy(xfs->full_filename + CHROOT_EVENT_LENGTH, temp, xfs->full_filename_length - CHROOT_EVENT_LENGTH + 1);
00478         }
00479         else
00480 #endif
00481         memcpy(xfs->full_filename, temp, xfs->full_filename_length + 1);
00482 
00483         /* we have a filename with the full path */
00484 
00485         return 1;
00486 }

int dazuko_register_security const char *  name,
struct security_operations *  ops
 

Definition at line 687 of file dazuko_linux26.c.

References dazuko_security_default_ops, dazuko_security_ops, NULL, XP_ERROR_FAULT, and XP_ERROR_PERMISSION.

00688 {
00689         char *daz_p;
00690         char *ext_p;
00691         char *def_p;
00692         char *end_p;
00693         void **ext_func_p;
00694         void **def_func_p;
00695         void **daz_func_p;
00696         void *ext_func;
00697         void *def_func;
00698         void *daz_func;
00699         int error = 0;
00700 
00701         if (name == NULL || ops == NULL)
00702                 return XP_ERROR_PERMISSION;
00703 
00704         /* basic allignment checking (there should only be function
00705          * pointers in this structure)
00706          */
00707         if (sizeof(struct security_operations) % sizeof(void *) != 0)
00708                 return XP_ERROR_FAULT;
00709 
00710         /* first check if all requested hooks are available */
00711 
00712         /* note: ops is filled with default functions for functions
00713          *       that were specified with NULL
00714          */
00715 
00716 #ifdef NO_CAPABILITIES
00717         /* we have do do an extra check if there are no capabilities
00718          * because we never hooked these functions (see dazuko_linux26_lsm.h)
00719          */
00720 
00721         if (lsm_capability_compare(ops, &dazuko_security_default_ops) != 0)
00722                 return XP_ERROR_PERMISSION;
00723 #endif
00724 
00725         ext_p = (char *)ops;
00726         def_p = (char *)&dazuko_security_default_ops;
00727         daz_p = (char *)&dazuko_security_ops;
00728         end_p = daz_p + sizeof(dazuko_security_ops);
00729 
00730         while (daz_p < end_p)
00731         {
00732                 daz_func_p = (void **)daz_p;
00733                 ext_func_p = (void **)ext_p;
00734                 def_func_p = (void **)def_p;
00735 
00736                 daz_func = *daz_func_p;
00737                 ext_func = *ext_func_p;
00738                 def_func = *def_func_p;
00739 
00740                 if (ext_func != def_func && daz_func != NULL)
00741                 {
00742                         error = 1;
00743                         break;
00744                 }
00745 
00746                 daz_p += sizeof(void *);
00747                 ext_p += sizeof(void *);
00748                 def_p += sizeof(void *);
00749         }
00750 
00751         if (error)
00752         {
00753                 /* some requested hooks are not available */
00754 
00755                 return XP_ERROR_PERMISSION;
00756         }
00757 
00758         /* install the requested hooks */
00759 
00760         ext_p = (char *)ops;
00761         def_p = (char *)&dazuko_security_default_ops;
00762         daz_p = (char *)&dazuko_security_ops;
00763         end_p = daz_p + sizeof(dazuko_security_ops);
00764 
00765         while (daz_p < end_p)
00766         {
00767                 daz_func_p = (void **)daz_p;
00768                 ext_func_p = (void **)ext_p;
00769                 def_func_p = (void **)def_p;
00770 
00771                 daz_func = *daz_func_p;
00772                 ext_func = *ext_func_p;
00773                 def_func = *def_func_p;
00774                 
00775                 if (ext_func != def_func && daz_func == NULL)
00776                 {
00777                         *daz_func_p = ext_func;
00778                 }
00779 
00780                 daz_p += sizeof(void *);
00781                 ext_p += sizeof(void *);
00782                 def_p += sizeof(void *);
00783         }
00784 
00785         return 0;
00786 }

static int dazuko_sys_generic struct inode *  inode,
int  mask,
struct nameidata *  nd
[inline, static]
 

Definition at line 846 of file dazuko_linux26.c.

References dazuko_bzero(), dazuko_check_access(), dazuko_file_struct_cleanup(), DAZUKO_ON_EXEC, DAZUKO_ON_OPEN, dazuko_process_access(), xp_daemon_id::file, xp_file_struct::inode, xp_file_struct::nd, NULL, xp_daemon_id::pid, XP_ERROR_PERMISSION, xp_free(), and xp_malloc().

Referenced by xp_sys_hook().

00848 {
00849         struct dazuko_file_struct *dfs = NULL;
00850         int error = 0;
00851         int check_error = 0;
00852         struct event_properties event_p;
00853         struct xp_daemon_id xp_id;
00854         struct slot_list *sl = NULL;
00855 #ifndef DAZUKO_FIST
00856         int event = DAZUKO_ON_OPEN;
00857         int daemon_is_allowed = 1;
00858 #endif
00859 
00860         dazuko_bzero(&event_p, sizeof(event_p));
00861 
00862 #ifdef DAZUKO_FIST
00863         if (inode == NULL || nd == NULL)
00864                 return XP_ERROR_PERMISSION;
00865 #else
00866         if ((mask & MAY_EXEC) != 0)
00867         {
00868                 event = DAZUKO_ON_EXEC;
00869                 daemon_is_allowed = 0;
00870         }
00871         else
00872         {
00873                 /* mask == 0 is passed in when a file is created */
00874                 if (mask == 0 || (mask & (MAY_WRITE|MAY_APPEND)) != 0)
00875                 {
00876                         if ((mask & MAY_READ) != 0)
00877                         {
00878                                 event_p.flags = O_RDWR;
00879                         }
00880                         else
00881                         {
00882                                 event_p.flags = O_WRONLY;
00883                         }
00884 
00885                         event_p.set_flags = 1;
00886                 }
00887                 else if ((mask & MAY_READ) != 0)
00888                 {
00889                         event_p.flags = O_RDONLY;
00890                         event_p.set_flags = 1;
00891                 }
00892         }
00893 #endif
00894 
00895         xp_id.pid = current->pid;
00896         xp_id.file = NULL;
00897         xp_id.current_p = current;
00898         xp_id.files = current->files;
00899 
00900         check_error = dazuko_check_access(event, daemon_is_allowed, &xp_id, &sl);
00901 
00902         if (!check_error)
00903         {
00904                 event_p.mode = inode->i_mode;
00905                 event_p.set_mode = 1;
00906                 event_p.pid = current->pid;
00907                 event_p.set_pid = 1;
00908                 event_p.uid = current->uid;
00909                 event_p.set_uid = 1;
00910 
00911                 dfs = (struct dazuko_file_struct *)xp_malloc(sizeof(struct dazuko_file_struct));
00912                 if (dfs != NULL)
00913                 {
00914                         dazuko_bzero(dfs, sizeof(struct dazuko_file_struct));
00915 
00916                         dfs->extra_data = (struct xp_file_struct *)xp_malloc(sizeof(struct xp_file_struct));
00917                         if (dfs->extra_data != NULL)
00918                         {
00919                                 dazuko_bzero(dfs->extra_data, sizeof(struct xp_file_struct));
00920 
00921                                 dfs->extra_data->nd = nd;
00922                                 dfs->extra_data->inode = inode;
00923 
00924                                 error = dazuko_process_access(event, dfs, &event_p, sl);
00925                         }
00926                         else
00927                         {
00928                                 xp_free(dfs);
00929                                 dfs = NULL;
00930                         }
00931 
00932                         dazuko_file_struct_cleanup(&dfs);
00933                 }
00934         }
00935 
00936         if (error)
00937                 return XP_ERROR_PERMISSION;
00938 
00939         return 0;
00940 }

int dazuko_unregister_security const char *  name,
struct security_operations *  ops
 

Definition at line 788 of file dazuko_linux26.c.

References dazuko_security_default_ops, dazuko_security_ops, NULL, XP_ERROR_FAULT, and XP_ERROR_PERMISSION.

00789 {
00790         char *daz_p;
00791         char *ext_p;
00792         char *def_p;
00793         char *end_p;
00794         void **ext_func_p;
00795         void **def_func_p;
00796         void **daz_func_p;
00797         void *ext_func;
00798         void *def_func;
00799         void *daz_func;
00800 
00801         if (name == NULL || ops == NULL)
00802                 return XP_ERROR_PERMISSION;
00803 
00804         /* basic allignment checking (there should only be function
00805          * pointers in this structure)
00806          */
00807         if (sizeof(struct security_operations) % sizeof(void *) != 0)
00808                 return XP_ERROR_FAULT;
00809 
00810         /* first check if all requested hooks are available */
00811 
00812         ext_p = (char *)ops;
00813         def_p = (char *)&dazuko_security_default_ops;
00814         daz_p = (char *)&dazuko_security_ops;
00815         end_p = daz_p + sizeof(dazuko_security_ops);
00816 
00817         while (daz_p < end_p)
00818         {
00819                 daz_func_p = (void **)daz_p;
00820                 ext_func_p = (void **)ext_p;
00821                 def_func_p = (void **)def_p;
00822 
00823                 daz_func = *daz_func_p;
00824                 ext_func = *ext_func_p;
00825                 def_func = *def_func_p;
00826 
00827                 if (ext_func != def_func && daz_func == ext_func)
00828                 {
00829                         *daz_func_p = NULL;
00830                 }
00831 
00832                 daz_p += sizeof(void *);
00833                 ext_p += sizeof(void *);
00834                 def_p += sizeof(void *);
00835         }
00836 
00837         return 0;
00838 }

int linux_dazuko_device_ioctl struct inode *  inode,
struct file *  file,
unsigned int  cmd,
unsigned long  param
 

int linux_dazuko_device_open struct inode *  ,
struct file * 
 

ssize_t linux_dazuko_device_read struct file *  file,
char *  buffer,
size_t  length,
loff_t *  pos
 

Definition at line 1137 of file dazuko_linux26.c.

References dazuko_bzero(), dazuko_snprintf(), dev_major, DPRINT, xp_copyout(), XP_ERROR_FAULT, XP_ERROR_INVALID, XP_ERROR_NODEVICE, and xp_print().

01138 {
01139         /* Reading from the dazuko device simply
01140          * returns the device number. This is to
01141          * help out the daemon. */
01142 
01143         char    tmp[20];
01144         size_t  dev_major_len;
01145 
01146         DPRINT(("dazuko: linux_dazuko_device_read() [%d]\n", current->pid));
01147         
01148         if (*pos != 0)
01149                 return 0;
01150 
01151         if (dev_major < 0)
01152                 return XP_ERROR_NODEVICE;
01153 
01154         /* print dev_major to a string
01155          * and get length (with terminator) */
01156         dazuko_bzero(tmp, sizeof(tmp));
01157 
01158         dev_major_len = dazuko_snprintf(tmp, sizeof(tmp), "%d", dev_major) + 1;
01159 
01160         if (tmp[sizeof(tmp)-1] != 0)
01161         {
01162                 xp_print("dazuko: failing device_read, device number overflow for dameon %d (dev_major=%d)\n", current->pid, dev_major);
01163                 return XP_ERROR_FAULT;
01164         }
01165 
01166         if (length < dev_major_len)
01167                 return XP_ERROR_INVALID;
01168 
01169         /* copy dev_major string to userspace */
01170         if (xp_copyout(tmp, buffer, dev_major_len) != 0)
01171                 return XP_ERROR_FAULT;
01172 
01173         *pos += dev_major_len;
01174 
01175         return dev_major_len;
01176 }

ssize_t linux_dazuko_device_read struct file *  ,
char __user *  ,
size_t  ,
loff_t * 
 

int linux_dazuko_device_release struct inode *  ,
struct file * 
 

ssize_t linux_dazuko_device_write struct file *  file,
const char *  buffer,
size_t  length,
loff_t *  pos
 

Definition at line 1178 of file dazuko_linux26.c.

References dazuko_handle_user_request(), xp_daemon_id::file, xp_daemon_id::pid, xp_copyin(), XP_ERROR_FAULT, and XP_ERROR_INTERRUPT.

01179 {
01180         struct xp_daemon_id     xp_id;
01181         char                    tmpbuffer[32];
01182         int                     size;
01183 
01184         size = length;
01185         if (length >= sizeof(tmpbuffer))
01186                 size = sizeof(tmpbuffer) -1;
01187 
01188         /* copy request pointer string to kernelspace */
01189         if (xp_copyin(buffer, tmpbuffer, size) != 0)
01190                 return XP_ERROR_FAULT;
01191 
01192         tmpbuffer[size] = 0;
01193 
01194         xp_id.pid = current->pid;
01195         xp_id.file = file;
01196         xp_id.current_p = current;
01197         xp_id.files = current->files;
01198 
01199         if (dazuko_handle_user_request(tmpbuffer, &xp_id) == 0)
01200                 return size;
01201 
01202         return XP_ERROR_INTERRUPT;
01203 }

ssize_t linux_dazuko_device_write struct file *  ,
const char __user *  ,
size_t  ,
loff_t * 
 

static void __exit linux_dazuko_exit void   )  [static]
 

Definition at line 1259 of file dazuko_linux26.c.

References dazuko_exit().

01260 {
01261         dazuko_exit();
01262 }

static int __init linux_dazuko_init void   )  [static]
 

Definition at line 1254 of file dazuko_linux26.c.

References dazuko_init().

01255 {
01256         return dazuko_init();
01257 }

MODULE_AUTHOR "H+BEDV Datentechnik GmbH <linux_support@antivir.de>"   ) 
 

MODULE_DESCRIPTION "allow 3rd-party file access control"   ) 
 

module_exit linux_dazuko_exit   ) 
 

MODULE_INFO vermagic  ,
VERMAGIC_STRING 
 

MODULE_LICENSE "GPL"   ) 
 

security_initcall linux_dazuko_init   ) 
 

int xp_atomic_dec struct xp_atomic atomic  )  [inline]
 

Definition at line 281 of file dazuko_linux26.c.

References xp_atomic::atomic.

00282 {
00283         atomic_dec(&(atomic->atomic));
00284         return 0;
00285 }

int xp_atomic_inc struct xp_atomic atomic  )  [inline]
 

Definition at line 275 of file dazuko_linux26.c.

References xp_atomic::atomic.

00276 {
00277         atomic_inc(&(atomic->atomic));
00278         return 0;
00279 }

int xp_atomic_read struct xp_atomic atomic  )  [inline]
 

Definition at line 287 of file dazuko_linux26.c.

References xp_atomic::atomic.

00288 {
00289         return atomic_read(&(atomic->atomic));
00290 }

int xp_atomic_set struct xp_atomic atomic,
int  value
[inline]
 

Definition at line 269 of file dazuko_linux26.c.

References xp_atomic::atomic.

00270 {
00271         atomic_set(&(atomic->atomic), value);
00272         return 0;
00273 }

int xp_copyin const void *  user_src,
void *  kernel_dest,
size_t  size
[inline]
 

Definition at line 227 of file dazuko_linux26.c.

00228 {
00229         return copy_from_user(kernel_dest, user_src, size);
00230 }

int xp_copyout const void *  kernel_src,
void *  user_dest,
size_t  size
[inline]
 

Definition at line 232 of file dazuko_linux26.c.

00233 {
00234         return copy_to_user(user_dest, kernel_src, size);
00235 }

void xp_destroy_mutex struct xp_mutex mutex  )  [inline]
 

Definition at line 120 of file dazuko_linux26.c.

00121 {
00122 }

int xp_destroy_queue struct xp_queue queue  )  [inline]
 

Definition at line 208 of file dazuko_linux26.c.

00209 {
00210         return 0;
00211 }

void xp_destroy_rwlock struct xp_rwlock rwlock  )  [inline]
 

Definition at line 152 of file dazuko_linux26.c.

00153 {
00154 }

void xp_down struct xp_mutex mutex  )  [inline]
 

Definition at line 110 of file dazuko_linux26.c.

References xp_mutex::mutex.

00111 {
00112         down(&(mutex->mutex));
00113 }

int xp_fill_file_struct struct dazuko_file_struct dfs  )  [inline]
 

Definition at line 517 of file dazuko_linux26.c.

References dazuko_fill_file_struct_cleanup(), dazuko_get_full_filename(), file_properties::device_type, dazuko_file_struct::extra_data, dazuko_file_struct::file_p, dazuko_file_struct::filename, dazuko_file_struct::filename_length, xp_file_struct::full_filename, xp_file_struct::full_filename_length, file_properties::gid, xp_file_struct::inode, file_properties::mode, NULL, file_properties::set_device_type, file_properties::set_gid, file_properties::set_mode, file_properties::set_size, file_properties::set_uid, file_properties::size, and file_properties::uid.

00518 {
00519         int     error = -1;
00520 
00521         if (dfs == NULL)
00522                 return error;
00523 
00524         /* check if filename has already been filled in */
00525         if (dfs->filename != NULL)
00526                 return 0;
00527 
00528         /* make sure we can get the full path */
00529         if (dazuko_get_full_filename(dfs->extra_data))
00530         {
00531                 /* reference copy of full path */
00532                 dfs->filename = dfs->extra_data->full_filename;
00533 
00534                 dfs->filename_length = dfs->extra_data->full_filename_length;
00535 
00536                 dfs->file_p.size = dfs->extra_data->inode->i_size;
00537                 dfs->file_p.set_size = 1;
00538                 dfs->file_p.uid = dfs->extra_data->inode->i_uid;
00539                 dfs->file_p.set_uid = 1;
00540                 dfs->file_p.gid = dfs->extra_data->inode->i_gid;
00541                 dfs->file_p.set_gid = 1;
00542                 dfs->file_p.mode = dfs->extra_data->inode->i_mode;
00543                 dfs->file_p.set_mode = 1;
00544                 dfs->file_p.device_type = dfs->extra_data->inode->i_rdev;
00545                 dfs->file_p.set_device_type = 1;
00546 
00547                 error = 0;
00548         }
00549 
00550         dazuko_fill_file_struct_cleanup(dfs);
00551 
00552         return error;
00553 }

int xp_free void *  ptr  )  [inline]
 

Definition at line 221 of file dazuko_linux26.c.

00222 {
00223         kfree(ptr);
00224         return 0;
00225 }

int xp_id_compare struct xp_daemon_id id1,
struct xp_daemon_id id2,
int  check_related
[inline]
 

Definition at line 605 of file dazuko_linux26.c.

References check_parent, DAZUKO_CHILD, DAZUKO_DIFFERENT, DAZUKO_SAME, DAZUKO_SUSPICIOUS, xp_daemon_id::file, NULL, and xp_daemon_id::pid.

00606 {
00607         if (id1 == NULL || id2 == NULL)
00608                 return DAZUKO_DIFFERENT;
00609 
00610         /* if file's are available and they match,
00611          * then we say that the id's match
00612          * ("file" is only used to unregister daemons and
00613          * here we allow other processes to do this)
00614          * Note: this is a Linux-only "hack" */
00615         if (id1->file != NULL && id1->file == id2->file)
00616                 return DAZUKO_SAME;
00617 
00618         if (id1->pid == id2->pid && id1->current_p == id2->current_p && id1->files == id2->files)
00619                 return DAZUKO_SAME;
00620 
00621         if (check_related)
00622         {
00623                 if (check_parent(id1->current_p, id2->current_p) == 0)
00624                 {
00625                         return DAZUKO_CHILD;
00626                 }
00627                 else if (id1->pid == id2->pid || id1->current_p == id2->current_p || id1->files == id2->files)
00628                 {
00629                         return DAZUKO_SUSPICIOUS;
00630                 }
00631         }
00632 
00633         return DAZUKO_DIFFERENT;
00634 }

struct xp_daemon_id* xp_id_copy struct xp_daemon_id id  )  [inline]
 

Definition at line 643 of file dazuko_linux26.c.

References xp_daemon_id::file, NULL, xp_daemon_id::pid, and xp_malloc().

00644 {
00645         struct xp_daemon_id     *ptr;
00646 
00647         if (id == NULL)
00648                 return NULL;
00649 
00650         ptr = (struct xp_daemon_id *)xp_malloc(sizeof(struct xp_daemon_id));
00651 
00652         if (ptr != NULL)
00653         {
00654                 ptr->pid = id->pid;
00655                 ptr->file = id->file;
00656                 ptr->current_p = id->current_p;
00657                 ptr->files = id->files;
00658         }
00659 
00660         return ptr;
00661 }

int xp_id_free struct xp_daemon_id id  )  [inline]
 

Definition at line 636 of file dazuko_linux26.c.

References xp_free().

00637 {
00638         xp_free(id);
00639 
00640         return 0;
00641 }

int xp_init_cache unsigned long  ttl  ) 
 

Definition at line 677 of file dazuko_linux26.c.

00678 {
00679         return -1;
00680 }

void xp_init_mutex struct xp_mutex mutex  )  [inline]
 

Definition at line 105 of file dazuko_linux26.c.

References xp_mutex::mutex.

00106 {
00107         init_MUTEX(&(mutex->mutex));
00108 }

int xp_init_queue struct xp_queue queue  )  [inline]
 

Definition at line 159 of file dazuko_linux26.c.

References xp_queue::queue.

00160 {
00161         init_waitqueue_head(&(queue->queue));
00162         return 0;
00163 }

void xp_init_rwlock struct xp_rwlock rwlock  )  [inline]
 

Definition at line 127 of file dazuko_linux26.c.

References xp_rwlock::rwlock.

00128 {
00129         rwlock_init(&(rwlock->rwlock));
00130 }

int xp_is_absolute_path const char *  path  )  [inline]
 

Definition at line 250 of file dazuko_linux26.c.

References CHROOT_EVENT_LENGTH, CHROOT_EVENT_STRING, and dazuko_get_filename_length().

00251 {
00252         if (path[0] == '/')
00253                 return 1;
00254 
00255 #ifdef USE_CHROOT
00256         if (dazuko_get_filename_length(path) >= CHROOT_EVENT_LENGTH)
00257         {
00258                 if (memcmp(CHROOT_EVENT_STRING, path, CHROOT_EVENT_LENGTH) == 0)
00259                         return 1;
00260         }
00261 #endif
00262 
00263         return 0;
00264 }

void* xp_malloc size_t  size  )  [inline]
 

Definition at line 216 of file dazuko_linux26.c.

00217 {
00218         return kmalloc(size, GFP_ATOMIC);
00219 }

int xp_notify struct xp_queue queue  )  [inline]
 

Definition at line 202 of file dazuko_linux26.c.

References xp_queue::queue.

00203 {
00204         wake_up(&(queue->queue));
00205         return 0;
00206 }

int xp_print const char *  fmt,
  ...
 

Definition at line 1099 of file dazuko_linux26.c.

References dazuko_get_filename_length(), NULL, xp_free(), and xp_malloc().

01100 {
01101         va_list args;
01102         char *p;
01103         size_t size = 1024;
01104         int length;
01105 
01106         p = (char *)xp_malloc(size);
01107         if (p == NULL)
01108                 return -1;
01109 
01110         length = dazuko_get_filename_length(KERN_INFO);
01111 
01112         memcpy(p, KERN_INFO, length);
01113 
01114         va_start(args, fmt);
01115         vsnprintf(p + length, size - length, fmt, args);
01116         va_end(args);
01117 
01118         p[size-1] = 0;
01119 
01120         printk(p);
01121 
01122         xp_free(p);
01123 
01124         return 0;
01125 }

void xp_read_lock struct xp_rwlock rlock  )  [inline]
 

Definition at line 142 of file dazuko_linux26.c.

References xp_rwlock::rwlock.

00143 {
00144         read_lock(&(rlock->rwlock));
00145 }

void xp_read_unlock struct xp_rwlock rlock  )  [inline]
 

Definition at line 147 of file dazuko_linux26.c.

References xp_rwlock::rwlock.

00148 {
00149         read_unlock(&(rlock->rwlock));
00150 }

int xp_set_event_properties struct event_properties event_p,
struct xp_daemon_id xp_id
 

Definition at line 666 of file dazuko_linux26.c.

References xp_daemon_id::pid.

00667 {
00668         event_p->pid = xp_id->pid;
00669         event_p->set_pid = 1;
00670 
00671         return 0;
00672 }

int xp_sys_hook void   )  [inline]
 

Definition at line 942 of file dazuko_linux26.c.

References dazuko_class, DAZUKO_DM, dazuko_register_security_ops, dazuko_security_default_ops, dazuko_security_ops, dazuko_sys_generic(), dev_major, DEVICE_NAME, fops, NULL, orig_root, orig_rootmnt, secondary_register, XP_ERROR_INVALID, and xp_print().

00943 {
00944 #ifndef DAZUKO_FIST
00945 #ifndef NO_STACKING_SUPPORT
00946         struct security_operations dummy_ops;
00947         int got_dummy = 0;
00948 #endif
00949 
00950         /* Make sure we have a valid task_struct. */
00951 
00952         if (current == NULL)
00953         {
00954                 xp_print("dazuko: panic (current == NULL)\n");
00955                 return -1;
00956         }
00957         if (current->fs == NULL)
00958         {
00959                 xp_print("dazuko: panic (current->fs == NULL)\n");
00960                 return -1;
00961         }
00962         if (current->fs->root == NULL)
00963         {
00964                 xp_print("dazuko: panic (current->fs->root == NULL)\n");
00965                 return -1;
00966         }
00967         if (current->fs->rootmnt == NULL)
00968         {
00969                 xp_print("dazuko: panic (current->fs->rootmnt == NULL)\n");
00970                 return -1;
00971         }
00972 
00973 
00974 #ifdef USE_CHROOT
00975         xp_print("dazuko: info: using chroot events for chroot'd processes\n");
00976 #endif
00977 #if defined(CONFIG_SMP) && defined(WITH_LOCAL_DPATH)
00978         xp_print("dazuko: warning: using local __dpath() dangerous for SMP kernels\n");
00979 #endif
00980 #endif
00981 
00982         /* Grab the current root. This is assumed to be the real.
00983          * If it is not the real root, we could have problems
00984          * looking up filenames. */
00985 
00986         read_lock(&current->fs->lock);
00987         orig_rootmnt = current->fs->rootmnt;
00988         orig_root = current->fs->root;
00989         read_unlock(&current->fs->lock);
00990 
00991 #ifndef DAZUKO_FIST
00992 #ifdef NO_STACKING_SUPPORT
00993         memset(&dazuko_security_ops, 0, sizeof(dazuko_security_ops));
00994         dazuko_security_ops.inode_permission = dazuko_sys_generic;
00995 
00996         if (register_security(&dazuko_security_ops) != 0)
00997         {
00998                 if (mod_reg_security(DEVICE_NAME, &dazuko_security_ops) != 0)
00999                 {
01000                         xp_print("dazuko: failed to register\n");
01001                         return XP_ERROR_INVALID;
01002                 }
01003 
01004                 secondary_register = 1;
01005                 xp_print("dazuko: warning: registered as secondary module\n");
01006         }
01007 #else
01008         /* grab security defaults if we can */
01009 
01010         memset(&dazuko_security_default_ops, 0, sizeof(dazuko_security_default_ops));
01011 
01012         memset(&dummy_ops, 0, sizeof(dummy_ops));
01013         if (register_security(&dummy_ops) == 0)
01014         {
01015                 memcpy(&dazuko_security_default_ops, &dummy_ops, sizeof(dazuko_security_default_ops));
01016                 unregister_security(&dummy_ops);
01017 
01018                 got_dummy = 1;
01019         }
01020 
01021         /* register with the security manager */
01022 
01023         memset(&dazuko_security_ops, 0, sizeof(dazuko_security_ops));
01024         dazuko_security_ops.inode_permission = dazuko_sys_generic;
01025 
01026         if (!got_dummy || register_security(&dazuko_register_security_ops) != 0)
01027         {
01028                 /* register as secondary, but with no stacking support */
01029                 if (mod_reg_security(DEVICE_NAME, &dazuko_security_ops) != 0)
01030                 {
01031                         xp_print("dazuko: failed to register\n");
01032                         return XP_ERROR_INVALID;
01033                 }
01034 
01035                 secondary_register = 1;
01036                 xp_print("dazuko: warning: registered as secondary module\n");
01037         }
01038 #endif
01039 #endif
01040 
01041         dev_major = register_chrdev(DAZUKO_DM, DEVICE_NAME, &fops);
01042         if (dev_major < 0)
01043         {
01044                 xp_print("dazuko: unable to register device, err=%d\n", dev_major);
01045                 return dev_major;
01046         }
01047 
01048         devfs_mk_cdev(MKDEV(dev_major, 0), S_IFCHR | S_IRUSR | S_IWUSR, DEVICE_NAME);
01049 
01050 #ifdef USE_CLASS
01051         dazuko_class = class_create(THIS_MODULE, "dazuko");
01052 #ifdef CLASS_class_device_create_2_6_15
01053         class_device_create(dazuko_class, NULL, MKDEV(dev_major, 0), NULL, "dazuko");
01054 #else
01055         class_device_create(dazuko_class, MKDEV(dev_major, 0), NULL, "dazuko");
01056 #endif
01057 #else
01058         dazuko_class = class_simple_create(THIS_MODULE, "dazuko");
01059         class_simple_device_add(dazuko_class, MKDEV(dev_major, 0), NULL, "dazuko");
01060 #endif
01061 
01062         return 0;
01063 }

int xp_sys_unhook void   )  [inline]
 

Definition at line 1065 of file dazuko_linux26.c.

References dazuko_class, dazuko_register_security_ops, dazuko_security_ops, dev_major, DEVICE_NAME, and secondary_register.

01066 {
01067         unregister_chrdev(dev_major, DEVICE_NAME);
01068 
01069         devfs_remove(DEVICE_NAME);
01070 
01071 #ifdef USE_CLASS
01072         class_device_destroy(dazuko_class, MKDEV(dev_major, 0));
01073         class_destroy(dazuko_class);
01074 #else
01075         class_simple_device_remove(MKDEV(dev_major, 0));
01076         class_simple_destroy(dazuko_class);
01077 #endif
01078 
01079 #ifndef DAZUKO_FIST
01080 #ifdef NO_STACKING_SUPPORT
01081         if (secondary_register)
01082                 mod_unreg_security(DEVICE_NAME, &dazuko_security_ops);
01083         else
01084                 unregister_security(&dazuko_security_ops);
01085 #else
01086         if (secondary_register)
01087                 mod_unreg_security(DEVICE_NAME, &dazuko_security_ops);
01088         else
01089                 unregister_security(&dazuko_register_security_ops);
01090 #endif
01091 #endif
01092 
01093         return 0;
01094 }

void xp_up struct xp_mutex mutex  )  [inline]
 

Definition at line 115 of file dazuko_linux26.c.

References xp_mutex::mutex.

00116 {
00117         up(&(mutex->mutex));
00118 }

int xp_verify_user_readable const void *  user_ptr,
size_t  size
[inline]
 

Definition at line 242 of file dazuko_linux26.c.

00243 {
00244         return 0;
00245 }

int xp_verify_user_writable const void *  user_ptr,
size_t  size
[inline]
 

Definition at line 237 of file dazuko_linux26.c.

00238 {
00239         return 0;
00240 }

int xp_wait_until_condition struct xp_queue queue,
int(*)(void *)  cfunction,
void *  cparam,
int  allow_interrupt
[inline]
 

Definition at line 165 of file dazuko_linux26.c.

References xp_queue::queue, wait_event, and wait_event_interruptible.

00166 {
00167         /* wait until cfunction(cparam) != 0 (condition is true) */
00168         int     ret = 0;
00169 
00170         if (allow_interrupt)
00171         {
00172                 while (1)
00173                 {
00174                         ret = wait_event_interruptible(queue->queue, cfunction(cparam) != 0);
00175 
00176 #ifdef USE_SUSPEND2
00177                         if (try_todo_list() == 0)
00178                                 break;
00179 #elif defined (USE_TRYTOFREEZEVOID)
00180                         if (try_to_freeze() == 0)
00181                                 break;
00182 #else
00183                         if (current->flags & PF_FREEZE)
00184                         {
00185                                 refrigerator(PF_FREEZE);
00186                         }
00187                         else
00188                         {
00189                                 break;
00190                         }
00191 #endif
00192                 }
00193         }
00194         else
00195         {
00196                 wait_event(queue->queue, cfunction(cparam) != 0);
00197         }
00198 
00199         return ret;
00200 }

void xp_write_lock struct xp_rwlock rwlock  )  [inline]
 

Definition at line 132 of file dazuko_linux26.c.

References xp_rwlock::rwlock.

00133 {
00134         write_lock(&(rwlock->rwlock));
00135 }

void xp_write_unlock struct xp_rwlock rwlock  )  [inline]
 

Definition at line 137 of file dazuko_linux26.c.

References xp_rwlock::rwlock.

00138 {
00139         write_unlock(&(rwlock->rwlock));
00140 }


Variable Documentation

struct class_simple* dazuko_class = NULL [static]
 

Definition at line 63 of file dazuko_linux26.c.

Referenced by xp_sys_hook(), and xp_sys_unhook().

struct security_operations dazuko_register_security_ops
 

Referenced by xp_sys_hook(), and xp_sys_unhook().

struct security_operations dazuko_security_default_ops [static]
 

Definition at line 76 of file dazuko_linux26.c.

Referenced by dazuko_register_security(), dazuko_unregister_security(), and xp_sys_hook().

struct security_operations dazuko_security_ops
 

Referenced by dazuko_register_security(), dazuko_unregister_security(), xp_sys_hook(), and xp_sys_unhook().

int dev_major = -1 [static]
 

Definition at line 68 of file dazuko_linux26.c.

struct file_operations fops [static]
 

Initial value:

Definition at line 93 of file dazuko_linux26.c.

struct dentry* orig_root = NULL [static]
 

Definition at line 67 of file dazuko_linux26.c.

struct vfsmount* orig_rootmnt = NULL [static]
 

Definition at line 66 of file dazuko_linux26.c.

Referenced by dazuko_get_full_filename(), and xp_sys_hook().

int secondary_register = 0 [static]
 

Definition at line 79 of file dazuko_linux26.c.

Referenced by xp_sys_hook(), and xp_sys_unhook().


Generated on Sun May 21 14:31:01 2006 for RSBAC by  doxygen 1.4.2