Linux 安全模組開發¶
基於 https://lore.kernel.org/r/20071026073721.618b4778@laptopd505.fenrus.org,當 LSM 的意圖(描述它試圖防禦的內容以及在何種情況下期望使用它)已在 Documentation/admin-guide/LSM/ 中得到適當記錄時,新的 LSM 將被核心接受。這使得 LSM 的程式碼可以輕鬆地與其目標進行比較,以便終端使用者和發行版可以就哪些 LSM 適合他們的需求做出更明智的決定。
有關可用 LSM 鉤子介面的詳細文件,請參閱 security/security.c 和相關結構
-
void security_free_mnt_opts(void **mnt_opts)¶
釋放與掛載選項關聯的記憶體
引數
void **mnt_optsLSM 處理的掛載選項
描述
釋放與 mnt_ops 關聯的記憶體。
-
int security_sb_eat_lsm_opts(char *options, void **mnt_opts)¶
使用 LSM 掛載選項
引數
char *options掛載選項
void **mnt_optsLSM 處理的掛載選項
描述
使用(掃描 options)並將它們儲存在 mnt_opts 中。
返回
成功時返回 0,失敗時返回負值。
-
int security_sb_mnt_opts_compat(struct super_block *sb, void *mnt_opts)¶
檢查是否允許新的掛載選項
引數
struct super_block *sb檔案系統超級塊
void *mnt_opts新的掛載選項
描述
確定是否允許 mnt_opts 中的新掛載選項,給定 sb 上現有的掛載檔案系統。正在比較的 sb 超級塊。
返回
如果選項相容,則返回 0。
-
int security_sb_remount(struct super_block *sb, void *mnt_opts)¶
驗證重新掛載期間沒有不相容的掛載更改
引數
struct super_block *sb檔案系統超級塊
void *mnt_opts(重新)掛載選項
描述
提取安全系統特定的掛載選項,並驗證是否正在對這些選項進行任何更改。
返回
如果授予許可權,則返回 0。
-
int security_sb_set_mnt_opts(struct super_block *sb, void *mnt_opts, unsigned long kern_flags, unsigned long *set_kern_flags)¶
設定檔案系統的掛載選項
引數
struct super_block *sb檔案系統超級塊
void *mnt_opts二進位制掛載選項
unsigned long kern_flags核心標誌(輸入)
unsigned long *set_kern_flags核心標誌(輸出)
描述
設定用於超級塊的安全相關掛載選項。
返回
成功時返回 0,失敗時返回錯誤。
-
int security_sb_clone_mnt_opts(const struct super_block *oldsb, struct super_block *newsb, unsigned long kern_flags, unsigned long *set_kern_flags)¶
複製超級塊掛載選項
引數
const struct super_block *oldsb源超級塊
struct super_block *newsb目標超級塊
unsigned long kern_flags核心標誌(輸入)
unsigned long *set_kern_flags核心標誌(輸出)
描述
將所有安全選項從給定的超級塊複製到另一個超級塊。
返回
成功時返回 0,失敗時返回錯誤。
-
int security_dentry_init_security(struct dentry *dentry, int mode, const struct qstr *name, const char **xattr_name, struct lsm_context *lsmctx)¶
執行 dentry 初始化
引數
struct dentry *dentry要初始化的 dentry
int mode用於確定資源型別的模式
const struct qstr *name最後一個路徑元件的名稱
const char **xattr_namesecurity/LSM xattr 的名稱
struct lsm_context *lsmctx指向結果 LSM 上下文的指標
描述
為 dentry 計算上下文,因為 inode 尚不可用,因為 NFSv4 無論如何都沒有由 EA 支援的標籤。需要注意的是,xattr_name 不需要由呼叫者釋放,它是一個靜態字串。
返回
成功時返回 0,失敗時返回負值。
-
int security_dentry_create_files_as(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old, struct cred *new)¶
執行 dentry 初始化
引數
struct dentry *dentry要初始化的 dentry
int mode用於確定資源型別的模式
struct qstr *name最後一個路徑元件的名稱
const struct cred *old用於 LSM 上下文計算的憑據
struct cred *new要修改的憑據
描述
為 dentry 計算上下文,因為 inode 尚不可用,並在傳入的憑據中設定該上下文,以便使用該上下文建立新檔案。上下文是使用傳入的憑據而不是呼叫者的憑據計算的。
返回
成功時返回 0,失敗時返回錯誤。
-
int security_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr, const initxattrs initxattrs, void *fs_data)¶
初始化 inode 的 LSM 上下文
引數
struct inode *inodeinode
struct inode *dir父目錄
const struct qstr *qstr路徑名的最後一個元件
const initxattrs initxattrs用於寫入 xattr 的回撥函式
void *fs_data檔案系統特定資料
描述
獲取要設定在新建立的 inode 上的安全屬性名稱字尾和值,併為新 inode 設定 incore 安全欄位。此掛鉤由 fs 程式碼作為 inode 建立事務的一部分呼叫,並提供 inode 的原子標記,這與 VFS 呼叫的 post_create/mkdir/... 掛鉤不同。
預計掛鉤函式會填充 xattrs 陣列,方法是呼叫 lsm_get_xattr_slot() 來檢索安全模組使用 lsm_blob_sizes 結構的 lbs_xattr_count 欄位保留的槽。對於每個槽,掛鉤函式應將 ->name 設定為屬性名稱字尾(例如 selinux),分配 ->value(將由呼叫者釋放)並將其設定為屬性值,將 ->value_len 設定為值的長度。如果安全模組不使用安全屬性,或者不希望在此特定 inode 上放置安全屬性,則應返回 -EOPNOTSUPP 以跳過此處理。
返回
- 如果 LSM 成功初始化所有必需的 inode,則返回 0
否則返回負值。
-
int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode, unsigned int dev)¶
檢查是否允許建立特殊檔案
引數
const struct path *dir父目錄
struct dentry *dentry新檔案
umode_t mode新檔案模式
unsigned int dev裝置號
描述
檢查建立檔案時的許可權。請注意,即使對於常規檔案執行 mknod 操作,也會呼叫此掛鉤。
返回
如果授予許可權,則返回 0。
引數
const struct path *dir父目錄
struct dentry *dentry新目錄
umode_t mode新目錄模式
描述
檢查在現有目錄中建立新目錄的許可權。
返回
如果授予許可權,則返回 0。
引數
const struct path *dir父目錄
struct dentry *dentry檔案
描述
檢查刪除檔案的硬連結的許可權。
返回
如果授予許可權,則返回 0。
-
int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, const struct path *new_dir, struct dentry *new_dentry, unsigned int flags)¶
檢查是否允許重新命名檔案
引數
const struct path *old_dir舊檔案的父目錄
struct dentry *old_dentry舊檔案
const struct path *new_dir新檔案的父目錄
struct dentry *new_dentry新檔案
unsigned int flags標誌
描述
檢查重新命名檔案或目錄的許可權。
返回
如果授予許可權,則返回 0。
引數
struct inode *dir父目錄
struct dentry *dentry正在建立的檔案
umode_t mode請求的檔案模式
描述
檢查建立常規檔案的許可權。
返回
如果授予許可權,則返回 0。
引數
struct inode *dir父目錄
struct dentry *dentry新目錄
umode_t mode新目錄模式
描述
檢查在與 inode 結構 dir 關聯的現有目錄中建立新目錄的許可權。
返回
如果授予許可權,則返回 0。
-
int security_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)¶
檢查是否允許設定檔案屬性
引數
struct mnt_idmap *idmap掛載的 idmap
struct dentry *dentry檔案
struct iattr *attr新屬性
描述
在設定檔案屬性之前檢查許可權。請注意,每當檔案屬性發生更改時(例如,當檔案被截斷、chown/chmod 操作、傳輸磁碟配額等時),都會從多個位置執行核心對 notify_change 的呼叫。
返回
如果授予許可權,則返回 0。
-
int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)¶
列出 xattr 安全標籤名稱
引數
struct inode *inodeinode
char *buffer緩衝區
size_t buffer_size緩衝區大小
描述
將與 inode 關聯的安全標籤的擴充套件屬性名稱複製到 buffer 中。buffer 的最大大小由 buffer_size 指定。buffer 可以為 NULL 以請求所需緩衝區的大小。
返回
成功時返回已使用/所需的位元組數。
-
int security_inode_copy_up(struct dentry *src, struct cred **new)¶
為 overlayfs 複製操作建立新憑據
引數
struct dentry *src複製檔案的聯合 dentry
struct cred **new新建立的憑據
描述
檔案即將從 overlay 檔案系統的較低層複製到較高層。安全模組可以準備一組新憑據並根據需要進行修改,然後返回新憑據。呼叫者將臨時切換到新憑據以建立新檔案並釋放新分配的憑據。
返回
成功時返回 0,出錯時返回負錯誤程式碼。
-
int security_inode_copy_up_xattr(struct dentry *src, const char name)¶
過濾 overlayfs 複製操作中的 xattr
引數
struct dentry *src複製檔案的聯合 dentry
const char *namexattr 名稱
描述
當聯合檔案從較低層複製到聯合/覆蓋層時,過濾要複製的 xattr。呼叫者負責讀取和寫入 xattr,此掛鉤僅是一個過濾器。
返回
- 返回 0 以接受 xattr,返回 -ECANCELED 以放棄 xattr,
如果安全模組不知道該屬性,則返回 -EOPNOTSUPP,如果中止複製,則返回負錯誤程式碼。
-
int security_inode_setintegrity(const struct inode *inode, enum lsm_integrity_type type, const void *value, size_t size)¶
設定 inode 的完整性資料
引數
const struct inode *inodeinode
enum lsm_integrity_type type完整性的型別,例如雜湊摘要、簽名等
const void *value完整性值
size_t size完整性值的大小
描述
向 LSM 註冊 inode 的已驗證完整性度量。如果 value 為 NULL,LSM 應該釋放先前儲存的資料。
返回
成功時返回 0,失敗時返回負值。
引數
struct file *file關聯檔案
unsigned int cmdioctl 命令
unsigned long argioctl 引數
描述
檢查對 file 執行 ioctl 操作的許可權。請注意,arg 有時表示使用者空間指標;在其他情況下,它可能只是一個簡單的整數值。當 arg 表示使用者空間指標時,安全模組永遠不應使用它。
返回
如果授予許可權,則返回 0。
-
int security_file_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)¶
檢查是否允許在相容模式下使用 ioctl
引數
struct file *file關聯檔案
unsigned int cmdioctl 命令
unsigned long argioctl 引數
描述
security_file_ioctl() 的相容版本,可以正確處理在 64 位核心上執行的 32 位程序。
返回
如果授予許可權,則返回 0。
引數
struct file *file檔案
int mask訪問掩碼
描述
評估已開啟的檔案以及透過 open() 請求的訪問掩碼。對於需要檔案內容才能做出決策的 LSM 來說,此掛鉤很有用。
返回
如果授予許可權,則返回 0。
-
void security_cred_getsecid(const struct cred *c, u32 *secid)¶
從一組憑據中獲取 secid
引數
const struct cred *c憑據
u32 *secidsecid 值
描述
檢索 cred 結構 c 的安全識別符號。如果失敗,secid 將設定為零。
-
void security_cred_getlsmprop(const struct cred *c, struct lsm_prop *prop)¶
從一組憑據中獲取 LSM 資料
引數
const struct cred *c憑據
struct lsm_prop *propLSM 資料的目標
描述
檢索 cred 結構 c 的安全資料。如果失敗,prop 將被清除。
-
int security_kernel_read_file(struct file *file, enum kernel_read_file_id id, bool contents)¶
讀取使用者空間指定的檔案
引數
struct file *file檔案
enum kernel_read_file_id id檔案識別符號
bool contents如果將呼叫
security_kernel_post_read_file(),則信任
描述
讀取使用者空間指定的檔案。
返回
如果授予許可權,則返回 0。
-
int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, enum kernel_read_file_id id)¶
讀取使用者空間指定的檔案
引數
struct file *file檔案
char *buf檔案內容
loff_t size檔案內容的大小
enum kernel_read_file_id id檔案識別符號
描述
讀取使用者空間指定的檔案。這必須與先前呼叫 security_kernel_read_file() 配對,該呼叫指示也將呼叫此掛鉤,有關更多資訊,請參見 security_kernel_read_file()。
返回
如果授予許可權,則返回 0。
-
int security_kernel_load_data(enum kernel_load_data_id id, bool contents)¶
載入使用者空間提供的資料
引數
enum kernel_load_data_id id資料識別符號
bool contents如果將呼叫
security_kernel_post_load_data(),則為 true
描述
載入使用者空間提供的資料。
返回
如果授予許可權,則返回 0。
-
int security_kernel_post_load_data(char *buf, loff_t size, enum kernel_load_data_id id, char *description)¶
從非檔案源載入使用者空間資料
引數
char *buf資料
loff_t size資料大小
enum kernel_load_data_id id資料識別符號
char *description資料的文字描述,特定於 id 值
描述
載入非檔案源(通常是使用者空間緩衝區)提供的資料。這必須與先前的 security_kernel_load_data() 呼叫配對,該呼叫指示也將呼叫此掛鉤,有關更多資訊,請參見 security_kernel_load_data()。
返回
如果授予許可權,則返回 0。
-
void security_current_getlsmprop_subj(struct lsm_prop *prop)¶
當前任務的主觀 LSM 資料
引數
struct lsm_prop *proplsm 特定資訊
描述
檢索當前任務的主觀安全識別符號,並在 prop 中返回它。
-
void security_task_getlsmprop_obj(struct task_struct *p, struct lsm_prop *prop)¶
獲取任務的客觀 LSM 資料
引數
struct task_struct *p目標任務
struct lsm_prop *proplsm 特定資訊
描述
檢索 p 中 task_struct 的客觀安全識別符號,並在 prop 中返回它。
-
void security_d_instantiate(struct dentry *dentry, struct inode *inode)¶
基於 dentry 填充 inode 的 LSM 狀態
引數
struct dentry *dentrydentry
struct inode *inodeinode
描述
如果允許,填寫 dentry 的 inode 安全資訊。
-
int security_ismaclabel(const char *name)¶
檢查命名的屬性是否為 MAC 標籤
引數
const char *name完整的擴充套件屬性名稱
描述
檢查由 name 指定的擴充套件屬性是否表示 MAC 標籤。
返回
如果 name 是 MAC 屬性,則返回 1;否則返回 0。
-
int security_secid_to_secctx(u32 secid, struct lsm_context *cp)¶
將 secid 轉換為 secctx
引數
u32 secidsecid
struct lsm_context *cpLSM 上下文
描述
將 secid 轉換為安全上下文。如果 cp 為 NULL,則將返回結果的長度,但不返回資料。這意味著長度可能會在檢查長度的呼叫和實際分配和返回資料的下一個呼叫之間發生變化。
返回
成功時返回資料長度,失敗時返回錯誤。
-
int security_lsmprop_to_secctx(struct lsm_prop *prop, struct lsm_context *cp)¶
將 lsm_prop 轉換為 secctx
引數
struct lsm_prop *proplsm 特定資訊
struct lsm_context *cpLSM 上下文
描述
將 prop 條目轉換為安全上下文。如果 cp 為 NULL,則將返回結果的長度。這意味著長度可能會在檢查長度的呼叫和實際分配和返回 cp 的下一個呼叫之間發生變化。
返回
成功時返回資料長度,失敗時返回錯誤。
-
int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)¶
將 secctx 轉換為 secid
引數
const char *secdatasecctx
u32 seclensecctx 的長度
u32 *secidsecid
描述
將安全上下文轉換為 secid。
返回
成功時返回 0,失敗時返回錯誤。
-
void security_release_secctx(struct lsm_context *cp)¶
釋放 secctx 緩衝區
引數
struct lsm_context *cp安全上下文
描述
釋放安全上下文。
引數
struct inode *inodeinode
描述
通知安全模組必須重新驗證 inode 的安全上下文。
引數
struct inode *inodeinode
void *ctxsecctx
u32 ctxlensecctx 的長度
描述
通知安全模組 inode 的安全上下文應該是什麼。初始化由安全模組為此 inode 管理的核心安全上下文。用法示例:NFS 客戶端呼叫此掛鉤以將其核心 inode 中的安全上下文初始化為伺服器為檔案提供的值,當伺服器將檔案的屬性返回給客戶端時。必須使用 inode->i_mutex 鎖定來呼叫。
返回
成功時返回 0,失敗時返回錯誤。
引數
struct dentry *dentryinode
void *ctxsecctx
u32 ctxlensecctx 的長度
描述
更改 inode 的安全上下文。更新由安全模組管理的核心安全上下文,並根據需要呼叫 fs 程式碼(透過 __vfs_setxattr_noperm)以更新表示上下文的任何後備 xattrs。用法示例:NFS 伺服器呼叫此掛鉤以將其核心 inode 和後備檔案系統中的安全上下文更改為客戶端在 SETATTR 操作上提供的值。必須使用 inode->i_mutex 鎖定來呼叫。
返回
成功時返回 0,失敗時返回錯誤。
引數
struct inode *inodeinode
struct lsm_context *cp安全上下文
描述
成功時,返回 0 並使用給定 inode 的安全上下文填充 cp。
返回
成功時返回 0,失敗時返回錯誤。
-
int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)¶
檢查是否允許 AF_UNIX 流
引數
struct sock *sock原始套接字
struct sock *other對等套接字
struct sock *newsk新套接字
描述
在 sock 和 other 之間建立 Unix 域流連線之前,檢查許可權。
之所以需要 unix_stream_connect 和 unix_may_send 掛鉤,是因為 Linux 為 Unix 域套接字提供了一個替代傳統檔案名稱空間的方法。在檔案名稱空間中繫結和連線到套接字的操作由典型的檔案許可權進行調解(並由 inode_security_ops 中的 mknod 和許可權掛鉤捕獲),而在抽象名稱空間中繫結和連線到套接字的操作完全不受調解。僅使用套接字層掛鉤無法充分控制抽象名稱空間中的 Unix 域套接字,因為我們需要知道實際目標套接字,該套接字直到我們在 af_unix 程式碼內部才會被查詢。
返回
如果授予許可權,則返回 0。
引數
struct socket *sock原始套接字
struct socket *other對等套接字
描述
在將資料報從 sock 連線或傳送到 other 之前,檢查許可權。
之所以需要 unix_stream_connect 和 unix_may_send 掛鉤,是因為 Linux 為 Unix 域套接字提供了一個替代傳統檔案名稱空間的方法。在檔案名稱空間中繫結和連線到套接字的操作由典型的檔案許可權進行調解(並由 inode_security_ops 中的 mknod 和許可權掛鉤捕獲),而在抽象名稱空間中繫結和連線到套接字的操作完全不受調解。僅使用套接字層掛鉤無法充分控制抽象名稱空間中的 Unix 域套接字,因為我們需要知道實際目標套接字,該套接字直到我們在 af_unix 程式碼內部才會被查詢。
返回
如果授予許可權,則返回 0。
引數
struct socket *socka第一個套接字
struct socket *sockb第二個套接字
描述
在建立一對新的套接字之前,檢查許可權。
返回
- 如果授予許可權並且建立了連線,則返回 0。
已建立。
引數
struct sock *sk目標套接字
struct sk_buff *skb傳入資料包
描述
檢查傳入網路資料包的許可權。此掛鉤與 Netfilter 的 IP 輸入掛鉤不同,因為這是傳入的 sk_buff skb 首次與特定套接字 sk 關聯。在此掛鉤內部不能休眠,因為某些呼叫方持有自旋鎖。
返回
如果授予許可權,則返回 0。
-
int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)¶
獲取遠端對等標籤
引數
struct socket *sock套接字
struct sk_buff *skb資料報包
u32 *secid遠端對等標籤 secid
描述
此掛鉤允許安全模組透過 getsockopt SO_GETPEERSEC 為每個資料包的使用者空間提供 udp 套接字的對等套接字安全狀態。應用程式必須首先透過 getsockopt 指示 IP_PASSSEC 選項。然後,它可以檢索透過 SCM_SECURITY 輔助訊息型別從此掛鉤返回的資料包的安全狀態。
返回
成功時返回 0,失敗時返回錯誤。
引數
const struct sock *sk原始套接字
struct sock *newsk目標套接字
描述
克隆/複製安全結構。
引數
const struct sock *sk原始套接字
struct flowi_common *flic目標流
描述
將目標流的 secid 設定為套接字的 secid。
-
void security_req_classify_flow(const struct request_sock *req, struct flowi_common *flic)¶
基於 request_sock 設定流的 secid
引數
const struct request_sock *reqrequest_sock
struct flowi_common *flic目標流
描述
將 flic 的 secid 設定為 req 的 secid。
引數
struct sock *sk正在嫁接的套接字
struct socket *parent目標父套接字
描述
將 parent 的 inode secid 設定為 sk 的 secid,並使用來自 parent 的任何必要的 LSM 狀態更新 sk。
-
int security_inet_conn_request(const struct sock *sk, struct sk_buff *skb, struct request_sock *req)¶
使用傳入的連線設定 request_sock 狀態
引數
const struct sock *sk父監聽套接字
struct sk_buff *skb傳入連線
struct request_sock *req新 request_sock
描述
基於 sk 和 skb 中的傳入連線初始化 req LSM 狀態。
返回
如果授予許可權,則返回 0。
引數
struct sock *sk套接字
struct sk_buff *skb連線包
描述
更新 sock 的 LSM 狀態以表示來自 skb 的新連線。
-
int security_secmark_relabel_packet(u32 secid)¶
檢查是否允許設定 secmark
引數
u32 secid新的 secmark 值
描述
檢查是否應允許該程序將資料包重新標記為 secid。
返回
如果授予許可權,則返回 0。
-
void security_secmark_refcount_inc(void)¶
遞增 secmark 標記規則計數
引數
void無引數
描述
告訴 LSM 遞增載入的 secmark 標記規則的數量。
-
void security_secmark_refcount_dec(void)¶
遞減 secmark 標記規則計數
引數
void無引數
描述
告訴 LSM 遞減載入的 secmark 標記規則的數量。
-
int security_tun_dev_alloc_security(void **security)¶
為 TUN 裝置分配 LSM blob
引數
void **security指向 LSM blob 的指標
描述
此掛鉤允許模組為 TUN 裝置分配安全結構,並在 security 中返回指標。
返回
成功時返回零,失敗時返回負值。
-
void security_tun_dev_free_security(void *security)¶
釋放 TUN 裝置 LSM blob
引數
void *securityLSM blob
描述
此掛鉤允許模組釋放 TUN 裝置的安全性結構。
-
int security_tun_dev_create(void)¶
檢查是否允許建立 TUN 裝置
引數
void無引數
描述
在建立新的 TUN 裝置之前檢查許可權。
返回
如果授予許可權,則返回 0。
-
int security_tun_dev_attach_queue(void *security)¶
檢查是否允許附加 TUN 佇列
引數
void *securityTUN 裝置 LSM blob
描述
在附加到 TUN 裝置佇列之前檢查許可權。
返回
如果授予許可權,則返回 0。
引數
struct sock *sk關聯的套接字
void *securityTUN 裝置 LSM blob
描述
模組可以使用此掛鉤來更新與 TUN 裝置的套接字結構關聯的任何安全狀態。
返回
如果授予許可權,則返回 0。
-
int security_tun_dev_open(void *security)¶
在開啟時更新 TUN 裝置 LSM 狀態
引數
void *securityTUN 裝置 LSM blob
描述
模組可以使用此掛鉤來更新與 TUN 裝置的安全性結構關聯的任何安全狀態。
返回
如果授予許可權,則返回 0。
-
int security_sctp_assoc_request(struct sctp_association *asoc, struct sk_buff *skb)¶
在 SCTP 關聯請求時更新 LSM
引數
struct sctp_association *asocSCTP 關聯
struct sk_buff *skb請求關聯的資料包
描述
將關聯的 INIT 資料包的 asoc 和 chunk->skb 傳遞給 LSM。
返回
成功時返回 0,失敗時返回錯誤。
-
int security_sctp_bind_connect(struct sock *sk, int optname, struct sockaddr *address, int addrlen)¶
驗證 SCTP 選項的地址列表
引數
struct sock *sk套接字
int optname要驗證的 SCTP 選項
struct sockaddr *address要驗證的 IP 地址列表
int addrlen地址列表的長度
描述
驗證與套接字 sk 關聯的每個地址所需的許可權。根據 optname,這些地址將被視為連線或繫結服務。使用 sizeof(struct sockaddr_in) 或 sizeof(struct sockaddr_in6) 在每個 IPv4 和 IPv6 地址上計算 addrlen。
返回
成功時返回 0,失敗時返回錯誤。
-
void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk, struct sock *newsk)¶
克隆 SCTP 套接字的 LSM 狀態
引數
struct sctp_association *asocSCTP 關聯
struct sock *sk原始套接字
struct sock *newsk目標套接字
描述
每當透過 accept(2) 建立新套接字(即 TCP 樣式套接字)或套接字被“剝離”時呼叫,例如使用者空間呼叫 sctp_peeloff(3)。
-
int security_sctp_assoc_established(struct sctp_association *asoc, struct sk_buff *skb)¶
關聯建立時更新 LSM 狀態
引數
struct sctp_association *asocSCTP 關聯
struct sk_buff *skb建立關聯的資料包
描述
將關聯的 COOKIE_ACK 資料包的 asoc 和 chunk->skb 傳遞給安全模組。
返回
如果授予許可權,則返回 0。
-
int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)¶
檢查是否允許訪問 IB pkey
引數
void *secLSM blob
u64 subnet_prefix埠的子網字首
u16 pkeyIB pkey
描述
檢查在修改 QP 時訪問 pkey 的許可權。
返回
如果授予許可權,則返回 0。
-
int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)¶
檢查是否允許 SMPs 流量
引數
void *secLSM blob
const char *dev_nameIB 裝置名稱
u8 port_num埠號
描述
檢查在端埠上傳送和接收 SMP 的許可權。
返回
如果授予許可權,則返回 0。
-
int security_ib_alloc_security(void **sec)¶
分配 Infiniband LSM blob
引數
void **secLSM blob
描述
為 Infiniband 物件分配安全結構。
返回
成功時返回 0,失敗時返回非零值。
-
void security_ib_free_security(void *sec)¶
釋放 Infiniband LSM blob
引數
void *secLSM blob
描述
取消分配 Infiniband 安全結構。
-
int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp)¶
分配 xfrm 策略 LSM blob
引數
struct xfrm_sec_ctx **ctxp正在新增到 SPD 的 xfrm 安全上下文
struct xfrm_user_sec_ctx *sec_ctx使用者空間提供的安全標籤
gfp_t gfpgfp 標誌
描述
為 xp->security 欄位分配安全結構;當分配 xfrm_policy 時,安全欄位初始化為 NULL。
返回
如果操作成功,則返回 0。
-
void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)¶
釋放 xfrm 安全上下文
引數
struct xfrm_sec_ctx *ctxxfrm 安全上下文
描述
釋放與 ctx 關聯的 LSM 資源。
-
int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx)¶
分配 xfrm 狀態 LSM blob
引數
struct xfrm_state *x正在新增到 SAD 的 xfrm 狀態
struct xfrm_user_sec_ctx *sec_ctx使用者空間提供的安全標籤
描述
為 x->security 欄位分配安全結構;當分配 xfrm_state 時,安全欄位初始化為 NULL。將上下文設定為對應於 sec_ctx。
返回
如果操作成功,則返回 0。
-
int security_xfrm_state_delete(struct xfrm_state *x)¶
檢查是否允許刪除 xfrm 狀態
引數
struct xfrm_state *xxfrm 狀態
描述
授權刪除 x->security。
返回
如果授予許可權,則返回 0。
-
int security_locked_down(enum lockdown_reason what)¶
檢查是否允許核心功能
引數
enum lockdown_reason what請求的核心功能
描述
確定是否應允許潛在地在核心空間中啟用任意程式碼執行的核心功能。
返回
如果授予許可權,則返回 0。
-
int security_bdev_alloc(struct block_device *bdev)¶
分配塊裝置 LSM blob
引數
struct block_device *bdev塊裝置
描述
分配安全結構並將其附加到 bdev->bd_security。當分配 bdev 結構時,安全欄位初始化為 NULL。
返回
如果操作成功,則返回 0。
-
void security_bdev_free(struct block_device *bdev)¶
釋放塊裝置的 LSM blob
引數
struct block_device *bdev塊裝置
描述
取消分配 bdev 安全結構並將 bdev->bd_security 設定為 NULL。
-
int security_bdev_setintegrity(struct block_device *bdev, enum lsm_integrity_type type, const void *value, size_t size)¶
設定裝置的完整性資料
引數
struct block_device *bdev塊裝置
enum lsm_integrity_type type完整性的型別,例如雜湊摘要、簽名等
const void *value完整性值
size_t size完整性值的大小
描述
向 LSM 註冊 bdev 的經過驗證的完整性測量。如果 value 為 NULL,LSM 應釋放先前儲存的資料。請注意,每次更新安全資訊時都應呼叫新掛鉤,以使這些資料保持最新。例如,在 dm-verity 中,如果重新載入對映表並配置為使用具有新 roothash 和簽名信息的不同 dm-verity 目標,則 LSM blob 中先前儲存的資料將變得過時。重新呼叫掛鉤以重新整理這些資料並確保它們是最新的至關重要。這種必要性源於裝置對映器的設計,其中首先建立一個裝置對映器裝置,然後將目標載入到其中。這些目標可以在裝置的生命週期內多次修改。因此,雖然在建立塊裝置期間分配了 LSM blob,但其實際內容並未在此階段初始化,並且可能會隨著時間的推移發生重大變化。這包括從 LSM“信任”的資料到他們不信任的資料的更改,因此必須正確處理這些更改。未能解決這種動態方面可能會允許繞過 LSM 檢查。
返回
成功時返回 0,失敗時返回負值。