aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed S. Darwish <darwish.07@gmail.com>2008-03-01 14:51:09 -0500
committerJames Morris <jmorris@namei.org>2008-04-18 19:52:32 -0400
commit8a076191f373abaeb4aa5f6755d22e49db98940f (patch)
tree1311a11332abb0828999a7347a07509a68dffb5f
parentd1a4be630fb068f251d64b62919f143c49ca8057 (diff)
LSM: Introduce inode_getsecid and ipc_getsecid hooks
Introduce inode_getsecid(inode, secid) and ipc_getsecid(ipcp, secid) LSM hooks. These hooks will be used instead of similar exported SELinux interfaces. Let {inode,ipc,task}_getsecid hooks set the secid to 0 by default if CONFIG_SECURITY is not defined or if the hook is set to NULL (dummy). This is done to notify the caller that no valid secid exists. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com> Acked-by: James Morris <jmorris@namei.org> Reviewed-by: Paul Moore <paul.moore@hp.com>
-rw-r--r--include/linux/security.h30
-rw-r--r--security/dummy.c16
-rw-r--r--security/security.c10
3 files changed, 54 insertions, 2 deletions
diff --git a/include/linux/security.h b/include/linux/security.h
index c673dfd4dffc..45717d9d9656 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -468,6 +468,11 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
468 * @dentry is the dentry being changed. 468 * @dentry is the dentry being changed.
469 * Return 0 on success. If error is returned, then the operation 469 * Return 0 on success. If error is returned, then the operation
470 * causing setuid bit removal is failed. 470 * causing setuid bit removal is failed.
471 * @inode_getsecid:
472 * Get the secid associated with the node.
473 * @inode contains a pointer to the inode.
474 * @secid contains a pointer to the location where result will be saved.
475 * In case of failure, @secid will be set to zero.
471 * 476 *
472 * Security hooks for file operations 477 * Security hooks for file operations
473 * 478 *
@@ -636,6 +641,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
636 * @task_getsecid: 641 * @task_getsecid:
637 * Retrieve the security identifier of the process @p. 642 * Retrieve the security identifier of the process @p.
638 * @p contains the task_struct for the process and place is into @secid. 643 * @p contains the task_struct for the process and place is into @secid.
644 * In case of failure, @secid will be set to zero.
645 *
639 * @task_setgroups: 646 * @task_setgroups:
640 * Check permission before setting the supplementary group set of the 647 * Check permission before setting the supplementary group set of the
641 * current process. 648 * current process.
@@ -997,6 +1004,11 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
997 * @ipcp contains the kernel IPC permission structure 1004 * @ipcp contains the kernel IPC permission structure
998 * @flag contains the desired (requested) permission set 1005 * @flag contains the desired (requested) permission set
999 * Return 0 if permission is granted. 1006 * Return 0 if permission is granted.
1007 * @ipc_getsecid:
1008 * Get the secid associated with the ipc object.
1009 * @ipcp contains the kernel IPC permission structure.
1010 * @secid contains a pointer to the location where result will be saved.
1011 * In case of failure, @secid will be set to zero.
1000 * 1012 *
1001 * Security hooks for individual messages held in System V IPC message queues 1013 * Security hooks for individual messages held in System V IPC message queues
1002 * @msg_msg_alloc_security: 1014 * @msg_msg_alloc_security:
@@ -1317,6 +1329,7 @@ struct security_operations {
1317 int (*inode_getsecurity)(const struct inode *inode, const char *name, void **buffer, bool alloc); 1329 int (*inode_getsecurity)(const struct inode *inode, const char *name, void **buffer, bool alloc);
1318 int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags); 1330 int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags);
1319 int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size); 1331 int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size);
1332 void (*inode_getsecid)(const struct inode *inode, u32 *secid);
1320 1333
1321 int (*file_permission) (struct file * file, int mask); 1334 int (*file_permission) (struct file * file, int mask);
1322 int (*file_alloc_security) (struct file * file); 1335 int (*file_alloc_security) (struct file * file);
@@ -1369,6 +1382,7 @@ struct security_operations {
1369 void (*task_to_inode)(struct task_struct *p, struct inode *inode); 1382 void (*task_to_inode)(struct task_struct *p, struct inode *inode);
1370 1383
1371 int (*ipc_permission) (struct kern_ipc_perm * ipcp, short flag); 1384 int (*ipc_permission) (struct kern_ipc_perm * ipcp, short flag);
1385 void (*ipc_getsecid) (struct kern_ipc_perm *ipcp, u32 *secid);
1372 1386
1373 int (*msg_msg_alloc_security) (struct msg_msg * msg); 1387 int (*msg_msg_alloc_security) (struct msg_msg * msg);
1374 void (*msg_msg_free_security) (struct msg_msg * msg); 1388 void (*msg_msg_free_security) (struct msg_msg * msg);
@@ -1578,6 +1592,7 @@ int security_inode_killpriv(struct dentry *dentry);
1578int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc); 1592int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
1579int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags); 1593int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
1580int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size); 1594int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
1595void security_inode_getsecid(const struct inode *inode, u32 *secid);
1581int security_file_permission(struct file *file, int mask); 1596int security_file_permission(struct file *file, int mask);
1582int security_file_alloc(struct file *file); 1597int security_file_alloc(struct file *file);
1583void security_file_free(struct file *file); 1598void security_file_free(struct file *file);
@@ -1622,6 +1637,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
1622void security_task_reparent_to_init(struct task_struct *p); 1637void security_task_reparent_to_init(struct task_struct *p);
1623void security_task_to_inode(struct task_struct *p, struct inode *inode); 1638void security_task_to_inode(struct task_struct *p, struct inode *inode);
1624int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); 1639int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
1640void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
1625int security_msg_msg_alloc(struct msg_msg *msg); 1641int security_msg_msg_alloc(struct msg_msg *msg);
1626void security_msg_msg_free(struct msg_msg *msg); 1642void security_msg_msg_free(struct msg_msg *msg);
1627int security_msg_queue_alloc(struct msg_queue *msq); 1643int security_msg_queue_alloc(struct msg_queue *msq);
@@ -2022,6 +2038,11 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer,
2022 return 0; 2038 return 0;
2023} 2039}
2024 2040
2041static inline void security_inode_getsecid(const struct inode *inode, u32 *secid)
2042{
2043 *secid = 0;
2044}
2045
2025static inline int security_file_permission (struct file *file, int mask) 2046static inline int security_file_permission (struct file *file, int mask)
2026{ 2047{
2027 return 0; 2048 return 0;
@@ -2137,7 +2158,9 @@ static inline int security_task_getsid (struct task_struct *p)
2137} 2158}
2138 2159
2139static inline void security_task_getsecid (struct task_struct *p, u32 *secid) 2160static inline void security_task_getsecid (struct task_struct *p, u32 *secid)
2140{ } 2161{
2162 *secid = 0;
2163}
2141 2164
2142static inline int security_task_setgroups (struct group_info *group_info) 2165static inline int security_task_setgroups (struct group_info *group_info)
2143{ 2166{
@@ -2216,6 +2239,11 @@ static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
2216 return 0; 2239 return 0;
2217} 2240}
2218 2241
2242static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
2243{
2244 *secid = 0;
2245}
2246
2219static inline int security_msg_msg_alloc (struct msg_msg * msg) 2247static inline int security_msg_msg_alloc (struct msg_msg * msg)
2220{ 2248{
2221 return 0; 2249 return 0;
diff --git a/security/dummy.c b/security/dummy.c
index 78d8f92310a4..fb2e942efbb6 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -424,6 +424,11 @@ static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t bu
424 return 0; 424 return 0;
425} 425}
426 426
427static void dummy_inode_getsecid(const struct inode *inode, u32 *secid)
428{
429 *secid = 0;
430}
431
427static int dummy_file_permission (struct file *file, int mask) 432static int dummy_file_permission (struct file *file, int mask)
428{ 433{
429 return 0; 434 return 0;
@@ -542,7 +547,9 @@ static int dummy_task_getsid (struct task_struct *p)
542} 547}
543 548
544static void dummy_task_getsecid (struct task_struct *p, u32 *secid) 549static void dummy_task_getsecid (struct task_struct *p, u32 *secid)
545{ } 550{
551 *secid = 0;
552}
546 553
547static int dummy_task_setgroups (struct group_info *group_info) 554static int dummy_task_setgroups (struct group_info *group_info)
548{ 555{
@@ -616,6 +623,11 @@ static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
616 return 0; 623 return 0;
617} 624}
618 625
626static void dummy_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
627{
628 *secid = 0;
629}
630
619static int dummy_msg_msg_alloc_security (struct msg_msg *msg) 631static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
620{ 632{
621 return 0; 633 return 0;
@@ -1058,6 +1070,7 @@ void security_fixup_ops (struct security_operations *ops)
1058 set_to_dummy_if_null(ops, inode_getsecurity); 1070 set_to_dummy_if_null(ops, inode_getsecurity);
1059 set_to_dummy_if_null(ops, inode_setsecurity); 1071 set_to_dummy_if_null(ops, inode_setsecurity);
1060 set_to_dummy_if_null(ops, inode_listsecurity); 1072 set_to_dummy_if_null(ops, inode_listsecurity);
1073 set_to_dummy_if_null(ops, inode_getsecid);
1061 set_to_dummy_if_null(ops, file_permission); 1074 set_to_dummy_if_null(ops, file_permission);
1062 set_to_dummy_if_null(ops, file_alloc_security); 1075 set_to_dummy_if_null(ops, file_alloc_security);
1063 set_to_dummy_if_null(ops, file_free_security); 1076 set_to_dummy_if_null(ops, file_free_security);
@@ -1094,6 +1107,7 @@ void security_fixup_ops (struct security_operations *ops)
1094 set_to_dummy_if_null(ops, task_reparent_to_init); 1107 set_to_dummy_if_null(ops, task_reparent_to_init);
1095 set_to_dummy_if_null(ops, task_to_inode); 1108 set_to_dummy_if_null(ops, task_to_inode);
1096 set_to_dummy_if_null(ops, ipc_permission); 1109 set_to_dummy_if_null(ops, ipc_permission);
1110 set_to_dummy_if_null(ops, ipc_getsecid);
1097 set_to_dummy_if_null(ops, msg_msg_alloc_security); 1111 set_to_dummy_if_null(ops, msg_msg_alloc_security);
1098 set_to_dummy_if_null(ops, msg_msg_free_security); 1112 set_to_dummy_if_null(ops, msg_msg_free_security);
1099 set_to_dummy_if_null(ops, msg_queue_alloc_security); 1113 set_to_dummy_if_null(ops, msg_queue_alloc_security);
diff --git a/security/security.c b/security/security.c
index 9beecac933b4..290482bdbbb0 100644
--- a/security/security.c
+++ b/security/security.c
@@ -523,6 +523,11 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer
523 return security_ops->inode_listsecurity(inode, buffer, buffer_size); 523 return security_ops->inode_listsecurity(inode, buffer, buffer_size);
524} 524}
525 525
526void security_inode_getsecid(const struct inode *inode, u32 *secid)
527{
528 security_ops->inode_getsecid(inode, secid);
529}
530
526int security_file_permission(struct file *file, int mask) 531int security_file_permission(struct file *file, int mask)
527{ 532{
528 return security_ops->file_permission(file, mask); 533 return security_ops->file_permission(file, mask);
@@ -712,6 +717,11 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
712 return security_ops->ipc_permission(ipcp, flag); 717 return security_ops->ipc_permission(ipcp, flag);
713} 718}
714 719
720void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
721{
722 security_ops->ipc_getsecid(ipcp, secid);
723}
724
715int security_msg_msg_alloc(struct msg_msg *msg) 725int security_msg_msg_alloc(struct msg_msg *msg)
716{ 726{
717 return security_ops->msg_msg_alloc_security(msg); 727 return security_ops->msg_msg_alloc_security(msg);