Add a hook to invalidate an inode's security label when the cached information becomes invalid. Add the new hook in selinux: set a flag when a security label becomes invalid.
Unified · Split
| @@ -1261,6 +1261,10 @@ · 1260 unmodified lines | |||
| 1261 | * audit_rule_init. | 1261 | * audit_rule_init. |
| 1262 | * @rule contains the allocated rule | 1262 | * @rule contains the allocated rule |
| 1263 | * | 1263 | * |
| 1264 | * @inode_invalidate_secctx: | ||
| 1265 | * Notify the security module that it must revalidate the security context | ||
| 1266 | * of an inode. | ||
| 1267 | * | ||
| 1264 | * @inode_notifysecctx: | 1268 | * @inode_notifysecctx: |
| 1265 | * Notify the security module of what the security context of an inode | 1269 | * Notify the security module of what the security context of an inode |
| 1266 | * should be. Initializes the incore security context managed by the | 1270 | * should be. Initializes the incore security context managed by the |
| @@ -1516,6 +1520,7 @@ union security_list_options { · 249 unmodified lines | |||
| 1516 | int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); | 1520 | int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); |
| 1517 | void (*release_secctx)(char *secdata, u32 seclen); | 1521 | void (*release_secctx)(char *secdata, u32 seclen); |
| 1518 | 1522 | ||
| 1523 | void (*inode_invalidate_secctx)(struct inode *inode); | ||
| 1519 | int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); | 1524 | int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); |
| 1520 | int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); | 1525 | int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); |
| 1521 | int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); | 1526 | int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); |
| @@ -1757,6 +1762,7 @@ struct security_hook_heads { · 235 unmodified lines | |||
| 1757 | struct list_head secid_to_secctx; | 1762 | struct list_head secid_to_secctx; |
| 1758 | struct list_head secctx_to_secid; | 1763 | struct list_head secctx_to_secid; |
| 1759 | struct list_head release_secctx; | 1764 | struct list_head release_secctx; |
| 1765 | struct list_head inode_invalidate_secctx; | ||
| 1760 | struct list_head inode_notifysecctx; | 1766 | struct list_head inode_notifysecctx; |
| 1761 | struct list_head inode_setsecctx; | 1767 | struct list_head inode_setsecctx; |
| 1762 | struct list_head inode_getsecctx; | 1768 | struct list_head inode_getsecctx; |
| @@ -353,6 +353,7 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); · 352 unmodified lines | |||
| 353 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); | 353 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); |
| 354 | void security_release_secctx(char *secdata, u32 seclen); | 354 | void security_release_secctx(char *secdata, u32 seclen); |
| 355 | 355 | ||
| 356 | void security_inode_invalidate_secctx(struct inode *inode); | ||
| 356 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); | 357 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); |
| 357 | int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); | 358 | int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); |
| 358 | int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); | 359 | int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); |
| @@ -1093,6 +1094,10 @@ static inline void security_release_secctx(char *secdata, u32 seclen) · 734 unmodified lines | |||
| 1093 | { | 1094 | { |
| 1094 | } | 1095 | } |
| 1095 | 1096 | ||
| 1097 | static inline void security_inode_invalidate_secctx(struct inode *inode) | ||
| 1098 | { | ||
| 1099 | } | ||
| 1100 | |||
| 1096 | static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) | 1101 | static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) |
| 1097 | { | 1102 | { |
| 1098 | return -EOPNOTSUPP; | 1103 | return -EOPNOTSUPP; |
| @@ -1161,6 +1161,12 @@ void security_release_secctx(char *secdata, u32 seclen) · 1160 unmodified lines | |||
| 1161 | } | 1161 | } |
| 1162 | EXPORT_SYMBOL(security_release_secctx); | 1162 | EXPORT_SYMBOL(security_release_secctx); |
| 1163 | 1163 | ||
| 1164 | void security_inode_invalidate_secctx(struct inode *inode) | ||
| 1165 | { | ||
| 1166 | call_void_hook(inode_invalidate_secctx, inode); | ||
| 1167 | } | ||
| 1168 | EXPORT_SYMBOL(security_inode_invalidate_secctx); | ||
| 1169 | |||
| 1164 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) | 1170 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) |
| 1165 | { | 1171 | { |
| 1166 | return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen); | 1172 | return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen); |
| @@ -1763,6 +1769,8 @@ struct security_hook_heads security_hook_heads = { · 596 unmodified lines | |||
| 1763 | LIST_HEAD_INIT(security_hook_heads.secctx_to_secid), | 1769 | LIST_HEAD_INIT(security_hook_heads.secctx_to_secid), |
| 1764 | .release_secctx = | 1770 | .release_secctx = |
| 1765 | LIST_HEAD_INIT(security_hook_heads.release_secctx), | 1771 | LIST_HEAD_INIT(security_hook_heads.release_secctx), |
| 1772 | .inode_invalidate_secctx = | ||
| 1773 | LIST_HEAD_INIT(security_hook_heads.inode_invalidate_secctx), | ||
| 1766 | .inode_notifysecctx = | 1774 | .inode_notifysecctx = |
| 1767 | LIST_HEAD_INIT(security_hook_heads.inode_notifysecctx), | 1775 | LIST_HEAD_INIT(security_hook_heads.inode_notifysecctx), |
| 1768 | .inode_setsecctx = | 1776 | .inode_setsecctx = |
| @@ -820,7 +820,7 @@ static int selinux_set_mnt_opts(struct super_block *sb, · 819 unmodified lines | |||
| 820 | goto out; | 820 | goto out; |
| 821 | 821 | ||
| 822 | root_isec->sid = rootcontext_sid; | 822 | root_isec->sid = rootcontext_sid; |
| 823 | root_isec->initialized = 1; | 823 | root_isec->initialized = LABEL_INITIALIZED; |
| 824 | } | 824 | } |
| 825 | 825 | ||
| 826 | if (defcontext_sid) { | 826 | if (defcontext_sid) { |
| @@ -1308,11 +1308,11 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent · 481 unmodified lines | |||
| 1308 | unsigned len = 0; | 1308 | unsigned len = 0; |
| 1309 | int rc = 0; | 1309 | int rc = 0; |
| 1310 | 1310 | ||
| 1311 | if (isec->initialized) | 1311 | if (isec->initialized == LABEL_INITIALIZED) |
| 1312 | goto out; | 1312 | goto out; |
| 1313 | 1313 | ||
| 1314 | mutex_lock(&isec->lock); | 1314 | mutex_lock(&isec->lock); |
| 1315 | if (isec->initialized) | 1315 | if (isec->initialized == LABEL_INITIALIZED) |
| 1316 | goto out_unlock; | 1316 | goto out_unlock; |
| 1317 | 1317 | ||
| 1318 | sbsec = inode->i_sb->s_security; | 1318 | sbsec = inode->i_sb->s_security; |
| @@ -1484,7 +1484,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent · 165 unmodified lines | |||
| 1484 | break; | 1484 | break; |
| 1485 | } | 1485 | } |
| 1486 | 1486 | ||
| 1487 | isec->initialized = 1; | 1487 | isec->initialized = LABEL_INITIALIZED; |
| 1488 | 1488 | ||
| 1489 | out_unlock: | 1489 | out_unlock: |
| 1490 | mutex_unlock(&isec->lock); | 1490 | mutex_unlock(&isec->lock); |
| @@ -2790,7 +2790,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, · 1299 unmodified lines | |||
| 2790 | struct inode_security_struct *isec = inode->i_security; | 2790 | struct inode_security_struct *isec = inode->i_security; |
| 2791 | isec->sclass = inode_mode_to_security_class(inode->i_mode); | 2791 | isec->sclass = inode_mode_to_security_class(inode->i_mode); |
| 2792 | isec->sid = newsid; | 2792 | isec->sid = newsid; |
| 2793 | isec->initialized = 1; | 2793 | isec->initialized = LABEL_INITIALIZED; |
| 2794 | } | 2794 | } |
| 2795 | 2795 | ||
| 2796 | if (!ss_initialized || !(sbsec->flags & SBLABEL_MNT)) | 2796 | if (!ss_initialized || !(sbsec->flags & SBLABEL_MNT)) |
| @@ -3089,7 +3089,7 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name, · 292 unmodified lines | |||
| 3089 | 3089 | ||
| 3090 | isec->sclass = inode_mode_to_security_class(inode->i_mode); | 3090 | isec->sclass = inode_mode_to_security_class(inode->i_mode); |
| 3091 | isec->sid = newsid; | 3091 | isec->sid = newsid; |
| 3092 | isec->initialized = 1; | 3092 | isec->initialized = LABEL_INITIALIZED; |
| 3093 | 3093 | ||
| 3094 | return; | 3094 | return; |
| 3095 | } | 3095 | } |
| @@ -3183,7 +3183,7 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name, · 87 unmodified lines | |||
| 3183 | 3183 | ||
| 3184 | isec->sclass = inode_mode_to_security_class(inode->i_mode); | 3184 | isec->sclass = inode_mode_to_security_class(inode->i_mode); |
| 3185 | isec->sid = newsid; | 3185 | isec->sid = newsid; |
| 3186 | isec->initialized = 1; | 3186 | isec->initialized = LABEL_INITIALIZED; |
| 3187 | return 0; | 3187 | return 0; |
| 3188 | } | 3188 | } |
| 3189 | 3189 | ||
| @@ -3761,7 +3761,7 @@ static void selinux_task_to_inode(struct task_struct *p, · 571 unmodified lines | |||
| 3761 | u32 sid = task_sid(p); | 3761 | u32 sid = task_sid(p); |
| 3762 | 3762 | ||
| 3763 | isec->sid = sid; | 3763 | isec->sid = sid; |
| 3764 | isec->initialized = 1; | 3764 | isec->initialized = LABEL_INITIALIZED; |
| 3765 | } | 3765 | } |
| 3766 | 3766 | ||
| 3767 | /* Returns error only if unable to parse addresses */ | 3767 | /* Returns error only if unable to parse addresses */ |
| @@ -4092,7 +4092,7 @@ static int selinux_socket_post_create(struct socket *sock, int family, · 324 unmodified lines | |||
| 4092 | return err; | 4092 | return err; |
| 4093 | } | 4093 | } |
| 4094 | 4094 | ||
| 4095 | isec->initialized = 1; | 4095 | isec->initialized = LABEL_INITIALIZED; |
| 4096 | 4096 | ||
| 4097 | if (sock->sk) { | 4097 | if (sock->sk) { |
| 4098 | sksec = sock->sk->sk_security; | 4098 | sksec = sock->sk->sk_security; |
| @@ -4283,7 +4283,7 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock) · 184 unmodified lines | |||
| 4283 | isec = inode_security(SOCK_INODE(sock)); | 4283 | isec = inode_security(SOCK_INODE(sock)); |
| 4284 | newisec->sclass = isec->sclass; | 4284 | newisec->sclass = isec->sclass; |
| 4285 | newisec->sid = isec->sid; | 4285 | newisec->sid = isec->sid; |
| 4286 | newisec->initialized = 1; | 4286 | newisec->initialized = LABEL_INITIALIZED; |
| 4287 | 4287 | ||
| 4288 | return 0; | 4288 | return 0; |
| 4289 | } | 4289 | } |
| @@ -5775,6 +5775,15 @@ static void selinux_release_secctx(char *secdata, u32 seclen) · 1485 unmodified lines | |||
| 5775 | kfree(secdata); | 5775 | kfree(secdata); |
| 5776 | } | 5776 | } |
| 5777 | 5777 | ||
| 5778 | static void selinux_inode_invalidate_secctx(struct inode *inode) | ||
| 5779 | { | ||
| 5780 | struct inode_security_struct *isec = inode->i_security; | ||
| 5781 | |||
| 5782 | mutex_lock(&isec->lock); | ||
| 5783 | isec->initialized = LABEL_INVALID; | ||
| 5784 | mutex_unlock(&isec->lock); | ||
| 5785 | } | ||
| 5786 | |||
| 5778 | /* | 5787 | /* |
| 5779 | * called with inode->i_mutex locked | 5788 | * called with inode->i_mutex locked |
| 5780 | */ | 5789 | */ |
| @@ -6006,6 +6015,7 @@ static struct security_hook_list selinux_hooks[] = { · 225 unmodified lines | |||
| 6006 | LSM_HOOK_INIT(secid_to_secctx, selinux_secid_to_secctx), | 6015 | LSM_HOOK_INIT(secid_to_secctx, selinux_secid_to_secctx), |
| 6007 | LSM_HOOK_INIT(secctx_to_secid, selinux_secctx_to_secid), | 6016 | LSM_HOOK_INIT(secctx_to_secid, selinux_secctx_to_secid), |
| 6008 | LSM_HOOK_INIT(release_secctx, selinux_release_secctx), | 6017 | LSM_HOOK_INIT(release_secctx, selinux_release_secctx), |
| 6018 | LSM_HOOK_INIT(inode_invalidate_secctx, selinux_inode_invalidate_secctx), | ||
| 6009 | LSM_HOOK_INIT(inode_notifysecctx, selinux_inode_notifysecctx), | 6019 | LSM_HOOK_INIT(inode_notifysecctx, selinux_inode_notifysecctx), |
| 6010 | LSM_HOOK_INIT(inode_setsecctx, selinux_inode_setsecctx), | 6020 | LSM_HOOK_INIT(inode_setsecctx, selinux_inode_setsecctx), |
| 6011 | LSM_HOOK_INIT(inode_getsecctx, selinux_inode_getsecctx), | 6021 | LSM_HOOK_INIT(inode_getsecctx, selinux_inode_getsecctx), |
| @@ -37,6 +37,12 @@ struct task_security_struct { · 36 unmodified lines | |||
| 37 | u32 sockcreate_sid; /* fscreate SID */ | 37 | u32 sockcreate_sid; /* fscreate SID */ |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | enum label_initialized { | ||
| 41 | LABEL_MISSING, /* not initialized */ | ||
| 42 | LABEL_INITIALIZED, /* inizialized */ | ||
| 43 | LABEL_INVALID /* invalid */ | ||
| 44 | }; | ||
| 45 | |||
| 40 | struct inode_security_struct { | 46 | struct inode_security_struct { |
| 41 | struct inode *inode; /* back pointer to inode object */ | 47 | struct inode *inode; /* back pointer to inode object */ |
| 42 | union { | 48 | union { |