歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> LSM在Linux中的實現方式

LSM在Linux中的實現方式

日期:2017/2/28 16:21:45   编辑:Linux教程

LSM(Linux Secure Model)一種輕量級訪問控制機制.

其實現方式有如在系統調用中加入一個後門....

方式如下:

static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
struct file *f,
int (*open)(struct inode *, struct file *),
const struct cred *cred)
{
struct inode *inode;
int error;

...............................................................

error = security_dentry_open(f, cred); //LSM機制實現方式,在此加入了一個LSM函數.

//security_dentry_open的實現如下,相當於一個接口,對一個函數指針再

//封裝一下.

//只返回是與否,這樣的控制信息.
if (error)
goto cleanup_all;

................................................................

return f;

cleanup_all:
.................................................................
return ERR_PTR(error);
}
//========簡單封裝一個指針結構體===========================

int security_dentry_open(struct file *file, const struct cred *cred)
{
int ret;

ret = security_ops->dentry_open(file, cred);
if (ret)
return ret;

return fsnotify_perm(file, MAY_OPEN);
}

Copyright © Linux教程網 All Rights Reserved