Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lsm: use lsm_context in security_inode_getsecctx

Change the security_inode_getsecctx() interface to fill a lsm_context
structure instead of data and length pointers. This provides
the information about which LSM created the context so that
security_release_secctx() can use the correct hook.

Cc: linux-nfs@vger.kernel.org
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
[PM: subject tweak]
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Casey Schaufler and committed by
Paul Moore
76ecf306 2d470c77

+31 -33
+10 -16
fs/nfsd/nfs4xdr.c
··· 2818 2818 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 2819 2819 static inline __be32 2820 2820 nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, 2821 - void *context, int len) 2821 + const struct lsm_context *context) 2822 2822 { 2823 2823 __be32 *p; 2824 2824 2825 - p = xdr_reserve_space(xdr, len + 4 + 4 + 4); 2825 + p = xdr_reserve_space(xdr, context->len + 4 + 4 + 4); 2826 2826 if (!p) 2827 2827 return nfserr_resource; 2828 2828 ··· 2832 2832 */ 2833 2833 *p++ = cpu_to_be32(0); /* lfs */ 2834 2834 *p++ = cpu_to_be32(0); /* pi */ 2835 - p = xdr_encode_opaque(p, context, len); 2835 + p = xdr_encode_opaque(p, context->context, context->len); 2836 2836 return 0; 2837 2837 } 2838 2838 #else 2839 2839 static inline __be32 2840 2840 nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, 2841 - void *context, int len) 2841 + struct lsm_context *context) 2842 2842 { return 0; } 2843 2843 #endif 2844 2844 ··· 2920 2920 struct kstatfs statfs; 2921 2921 struct nfs4_acl *acl; 2922 2922 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 2923 - void *context; 2924 - int contextlen; 2923 + struct lsm_context context; 2925 2924 #endif 2926 2925 u32 rdattr_err; 2927 2926 bool contextsupport; ··· 3375 3376 static __be32 nfsd4_encode_fattr4_sec_label(struct xdr_stream *xdr, 3376 3377 const struct nfsd4_fattr_args *args) 3377 3378 { 3378 - return nfsd4_encode_security_label(xdr, args->rqstp, 3379 - args->context, args->contextlen); 3379 + return nfsd4_encode_security_label(xdr, args->rqstp, &args->context); 3380 3380 } 3381 3381 #endif 3382 3382 ··· 3525 3527 args.ignore_crossmnt = (ignore_crossmnt != 0); 3526 3528 args.acl = NULL; 3527 3529 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 3528 - args.context = NULL; 3530 + args.context.context = NULL; 3529 3531 #endif 3530 3532 3531 3533 /* ··· 3605 3607 attrmask[0] & FATTR4_WORD0_SUPPORTED_ATTRS) { 3606 3608 if (exp->ex_flags & NFSEXP_SECURITY_LABEL) 3607 3609 err = security_inode_getsecctx(d_inode(dentry), 3608 - &args.context, &args.contextlen); 3610 + &args.context); 3609 3611 else 3610 3612 err = -EOPNOTSUPP; 3611 3613 args.contextsupport = (err == 0); ··· 3642 3644 3643 3645 out: 3644 3646 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 3645 - if (args.context) { 3646 - struct lsm_context scaff; /* scaffolding */ 3647 - 3648 - lsmcontext_init(&scaff, args.context, args.contextlen, 0); 3649 - security_release_secctx(&scaff); 3650 - } 3647 + if (args.context.context) 3648 + security_release_secctx(&args.context); 3651 3649 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ 3652 3650 kfree(args.acl); 3653 3651 if (tempfh) {
+2 -2
include/linux/lsm_hook_defs.h
··· 303 303 LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode) 304 304 LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen) 305 305 LSM_HOOK(int, 0, inode_setsecctx, struct dentry *dentry, void *ctx, u32 ctxlen) 306 - LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode, void **ctx, 307 - u32 *ctxlen) 306 + LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode, 307 + struct lsm_context *cp) 308 308 309 309 #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE) 310 310 LSM_HOOK(int, 0, post_notification, const struct cred *w_cred,
+3 -2
include/linux/security.h
··· 591 591 void security_inode_invalidate_secctx(struct inode *inode); 592 592 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); 593 593 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); 594 - int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); 594 + int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp); 595 595 int security_locked_down(enum lockdown_reason what); 596 596 int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 *uctx_len, 597 597 void *val, size_t val_len, u64 id, u64 flags); ··· 1591 1591 { 1592 1592 return -EOPNOTSUPP; 1593 1593 } 1594 - static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) 1594 + static inline int security_inode_getsecctx(struct inode *inode, 1595 + struct lsm_context *cp) 1595 1596 { 1596 1597 return -EOPNOTSUPP; 1597 1598 }
+6 -6
security/security.c
··· 4426 4426 /** 4427 4427 * security_inode_getsecctx() - Get the security label of an inode 4428 4428 * @inode: inode 4429 - * @ctx: secctx 4430 - * @ctxlen: length of secctx 4429 + * @cp: security context 4431 4430 * 4432 - * On success, returns 0 and fills out @ctx and @ctxlen with the security 4433 - * context for the given @inode. 4431 + * On success, returns 0 and fills out @cp with the security context 4432 + * for the given @inode. 4434 4433 * 4435 4434 * Return: Returns 0 on success, error on failure. 4436 4435 */ 4437 - int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) 4436 + int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp) 4438 4437 { 4439 - return call_int_hook(inode_getsecctx, inode, ctx, ctxlen); 4438 + memset(cp, 0, sizeof(*cp)); 4439 + return call_int_hook(inode_getsecctx, inode, cp); 4440 4440 } 4441 4441 EXPORT_SYMBOL(security_inode_getsecctx); 4442 4442
+6 -4
security/selinux/hooks.c
··· 6711 6711 ctx, ctxlen, 0, NULL); 6712 6712 } 6713 6713 6714 - static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) 6714 + static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp) 6715 6715 { 6716 - int len = 0; 6716 + int len; 6717 6717 len = selinux_inode_getsecurity(&nop_mnt_idmap, inode, 6718 - XATTR_SELINUX_SUFFIX, ctx, true); 6718 + XATTR_SELINUX_SUFFIX, 6719 + (void **)&cp->context, true); 6719 6720 if (len < 0) 6720 6721 return len; 6721 - *ctxlen = len; 6722 + cp->len = len; 6723 + cp->id = LSM_ID_SELINUX; 6722 6724 return 0; 6723 6725 } 6724 6726 #ifdef CONFIG_KEYS
+4 -3
security/smack/smack_lsm.c
··· 4898 4898 ctx, ctxlen, 0, NULL); 4899 4899 } 4900 4900 4901 - static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) 4901 + static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp) 4902 4902 { 4903 4903 struct smack_known *skp = smk_of_inode(inode); 4904 4904 4905 - *ctx = skp->smk_known; 4906 - *ctxlen = strlen(skp->smk_known); 4905 + cp->context = skp->smk_known; 4906 + cp->len = strlen(skp->smk_known); 4907 + cp->id = LSM_ID_SMACK; 4907 4908 return 0; 4908 4909 } 4909 4910