|
LIDS精通与进阶(一)(3) struct secure_ino { unsigned long int ino; /* the inode number */ kdev_t dev; /* the dev number /* int type; /* the file type */ };
上面的结构用一对来存储保护文件或目录的结点。type是用来标明保护结点文件类型的。
LIDS有4种类型:
在/usr/src/linux/include/linux/fs.h
#define LIDS_APPEND 1 /* APPEND ONLY FILE */ #define LIDS_READONLY 2 /* Read Only File */ #define LIDS_DEVICE 3 /* Protect MBR Writing to device */ #define LIDS_IGNORE 4 /* Ignore the protection */
通过secure_ino结构,我们能很容易的初使化保护的文件或是在内核里执行以下函数。
在/usr/src/linux/fs/lids.c
int lids_add_inode(unsigned long int inode ,kdev_t dev , int type) {
if ( last_secure == (LIDS_MAX_INODE-1)) return 0;
secure[last_secure].ino = inode; secure[last_secure].dev = dev; secure[last_secure].type = type; secure[++last_secure].ino = 0;
#ifdef VFS_SECURITY_DEBUG printk(lids_add_inode : return %dn,last_secure); #endif return last_secure; }
就象你在上面代码上可以看到的,给secure_ino加到一个结点上是非常容易的。被保护的结点会在系统启动的时候初使化。初使化程序在/usr/src/linux/fs/lids.c的init_vfs_security()里。
现在,让我们看看LIDS是如何来检查是否一个结点已经受到保护。 在/usr/src/linux/fs/open.c
int do_truncate(struct dentry *dentry, unsigned long length) { struct inode *inode = dentry->d_inode; int error; struct iattr newattrs; /* Not pretty: inode->i_size shouldn't really be off_t. But it is. */ if ((off_t) length < 0) return -EINVAL;
#ifdef CONFIG_LIDS if (lids_load && lids_local_load) { error = lids_check_base(dentry,LIDS_READONLY); if (error) { lids_security_alert(Try to truncate a protected file (dev %d %d,inode %ld), MAJOR(dentry->d_inode->i_dev), MINOR(dentry->d_inode->i_dev),
|