LSM: Module stacking for AppArmor
Subsystems (18)
Casey Schaufler
maintainerPATCH v3 18/24 LSM: Use lsmcontext in security_dentry_init_security
In reply to Casey SchauflerChange the security_dentry_init_security() interface to fill an lsmcontext structure instead of a void * data area and a length. The lone caller of this interface is NFS4, which may make copies of the data using its own mechanisms. A rework of the nfs4 code to use the lsmcontext properly is a significant project, so the coward's way out is taken, and the lsmcontext data from security_dentry_init_security() is copied, then released directly.
--- fs/nfs/nfs4proc.c | 26 ++++++++++++++++---------- include/linux/security.h | 7 +++---- security/security.c | 20 ++++++++++++++++---- 3 files changed, 35 insertions(+), 18 deletions(-)
fs/nfs/nfs4proc.c +16 -10
@@ -113,6 +113,7 @@ static inline struct nfs4_label * nfs4_label_init_security(struct inode *dir, struct dentry *dentry, struct iattr *sattr, struct nfs4_label *label) { + struct lsmcontext context;int err;if (label ==NULL )
@@ -122,21 +123,26 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,return NULL ; err =security_dentry_init_security (dentry, sattr->ia_mode, - &dentry->d_name, (void **)&label->label, &label->len); -if (err ==0 ) -return label; + &dentry->d_name, &context); + +if (err) +return NULL ; + + label->label =kmemdup (context.context, context.len,GFP_KERNEL ); +if (label->label ==NULL ) + label =NULL ; +else + label->len = context.len; + +security_release_secctx (&context); + +return label; -return NULL ; }static inline void nfs4_label_release_security (struct nfs4_label *label) { -struct lsmcontext scaff;/* scaffolding */ - -if (label) { -lsmcontext_init (&scaff, label->label, label->len,0 ); -security_release_secctx (&scaff); - } +kfree (label->label); }static inline u32 *nfs4_bitmask (struct nfs_server *server,struct nfs4_label *label) {
include/linux/security.h +3 -4
@@ -348,8 +348,8 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb,int security_add_mnt_opt (const char *option,const char *val,int len,void **mnt_opts);int security_dentry_init_security (struct dentry *dentry,int mode, -const struct qstr *name,void **ctx, -u32 *ctxlen); +const struct qstr *name, +struct lsmcontext *ctx); int security_dentry_create_files_as(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old,
@@ -720,8 +720,7 @@ static inline void security_inode_free(struct inode *inode)static inline int security_dentry_init_security (struct dentry *dentry,int mode,const struct qstr *name, -void **ctx, -u32 *ctxlen) +struct lsmcontext *ctx) {return -EOPNOTSUPP ; }
security/security.c +16 -4
@@ -453,6 +453,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,* secid in the lsmblob structure. */ if (hooks[i].head == &security_hook_heads.audit_rule_match || + hooks[i].head == + &security_hook_heads.dentry_init_security || hooks[i].head == &security_hook_heads.kernel_act_as || hooks[i].head == &security_hook_heads.socket_getpeersec_dgram ||
@@ -1040,11 +1042,21 @@ void security_inode_free(struct inode *inode) }int security_dentry_init_security (struct dentry *dentry,int mode, -const struct qstr *name,void **ctx, -u32 *ctxlen) +const struct qstr *name, +struct lsmcontext *cp) { -return call_int_hook (dentry_init_security, -EOPNOTSUPP , dentry, mode, - name, ctx, ctxlen); +int *display = current->security; +struct security_hook_list *hp; + +hlist_for_each_entry (hp, &security_hook_heads.dentry_init_security, + list) +if (*display ==0 || *display == hp->slot) { + cp->slot = hp->slot; +return hp->hook.dentry_init_security (dentry, mode, + name, (void **)&cp->context, &cp->len); + } + +return -EOPNOTSUPP ; }EXPORT_SYMBOL (security_dentry_init_security);
Signature · 1 line
2.20.1
Re: [PATCH v3 18/24] LSM: Use lsmcontext in security_dentry_init_security
Quoted 110 lines · Casey Schaufler
Change the
security_dentry_init_security()interface to fill an lsmcontext structure instead of a void * data area and a length. The lone caller of this interface is NFS4, which may make copies of the data using its own mechanisms. A rework of the nfs4 code to use the lsmcontext properly is a significant project, so the coward's way out is taken, and the lsmcontext data fromsecurity_dentry_init_security()is copied, then released directly.Signed-off-by Casey Schaufler <[email protected]>--- fs/nfs/nfs4proc.c | 26 ++++++++++++++++---------- include/linux/security.h | 7 +++---- security/security.c | 20 ++++++++++++++++---- 3 files changed, 35 insertions(+), 18 deletions(-)fs/nfs/nfs4proc.c +16
-10@@ -113,6 +113,7 @@ static inline struct nfs4_label * nfs4_label_init_security(struct inode *dir, struct dentry *dentry, struct iattr *sattr, struct nfs4_label *label) { + struct lsmcontext context;int err;if (label ==NULL )@@ -122,21 +123,26 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,return NULL ; err =security_dentry_init_security (dentry, sattr->ia_mode, - &dentry->d_name, (void **)&label->label, &label->len); -if (err ==0 ) -return label; + &dentry->d_name, &context); + +if (err) +return NULL ; + + label->label =kmemdup (context.context, context.len,GFP_KERNEL ); +if (label->label ==NULL ) + label =NULL ; +else + label->len = context.len; + +security_release_secctx (&context); + +return label; -return NULL ; }static inline void nfs4_label_release_security (struct nfs4_label *label) { -struct lsmcontext scaff;/* scaffolding */ - -if (label) { -lsmcontext_init (&scaff, label->label, label->len,0 ); -security_release_secctx (&scaff); - } +kfree (label->label); }static inline u32 *nfs4_bitmask (struct nfs_server *server,struct nfs4_label *label) {include/linux/security.h +3
-4@@ -348,8 +348,8 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb,int security_add_mnt_opt (const char *option,const char *val,int len,void **mnt_opts);int security_dentry_init_security (struct dentry *dentry,int mode, -const struct qstr *name,void **ctx, -u32 *ctxlen); +const struct qstr *name, +struct lsmcontext *ctx); int security_dentry_create_files_as(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old,@@ -720,8 +720,7 @@ static inline void security_inode_free(struct inode *inode)static inline int security_dentry_init_security (struct dentry *dentry,int mode,const struct qstr *name, -void **ctx, -u32 *ctxlen) +struct lsmcontext *ctx) {return -EOPNOTSUPP ; }security/security.c +3
-2@@ -453,6 +453,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,* secid in the lsmblob structure. */ if (hooks[i].head == &security_hook_heads.audit_rule_match || + hooks[i].head == + &security_hook_heads.dentry_init_security || hooks[i].head == &security_hook_heads.kernel_act_as || hooks[i].head == &security_hook_heads.socket_getpeersec_dgram ||@@ -1040,11 +1042,21 @@ void security_inode_free(struct inode *inode) } int security_dentry_init_security(struct dentry *dentry, int mode, -const struct qstr *name,void **ctx, -u32 *ctxlen) + const struct qstr *name,
security/security.c void security_inode_free(struct inode *inode) · line 1053
Quoted 10 lines
security/security.c +7
-2+ struct lsmcontext *cp) { -return call_int_hook (dentry_init_security, -EOPNOTSUPP , dentry, mode, - name, ctx, ctxlen); +int *display = current->security; +struct security_hook_list *hp; + +hlist_for_each_entry (hp, &security_hook_heads.dentry_init_security, + list) +if (*display ==0 || *display == hp->slot) {
Is this supposed to be == -1 not 0? Isn't 0 an assigned slot?
Otherwise:
-Kees
Quoted 12 lines
security/security.c +6
-0+ cp->slot = hp->slot; +return hp->hook.dentry_init_security (dentry, mode, + name, (void **)&cp->context, &cp->len); + } + +return -EOPNOTSUPP ; }EXPORT_SYMBOL (security_dentry_init_security);Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
John Johansen
maintainerPATCH v3 18/24 LSM: Use lsmcontext in security_dentry_init_security
In reply to Casey SchauflerQuoted 10 lines · Casey Schaufler
Change the
security_dentry_init_security()interface to fill an lsmcontext structure instead of a void * data area and a length. The lone caller of this interface is NFS4, which may make copies of the data using its own mechanisms. A rework of the nfs4 code to use the lsmcontext properly is a significant project, so the coward's way out is taken, and the lsmcontext data fromsecurity_dentry_init_security()is copied, then released directly.Signed-off-by Casey Schaufler <[email protected]>
With the needed fix (below) that Kees already pointed out
Quoted 105 lines
--- fs/nfs/nfs4proc.c | 26 ++++++++++++++++---------- include/linux/security.h | 7 +++---- security/security.c | 20 ++++++++++++++++---- 3 files changed, 35 insertions(+), 18 deletions(-)fs/nfs/nfs4proc.c +16
-10@@ -113,6 +113,7 @@ static inline struct nfs4_label * nfs4_label_init_security(struct inode *dir, struct dentry *dentry, struct iattr *sattr, struct nfs4_label *label) { + struct lsmcontext context;int err;if (label ==NULL )@@ -122,21 +123,26 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,return NULL ; err =security_dentry_init_security (dentry, sattr->ia_mode, - &dentry->d_name, (void **)&label->label, &label->len); -if (err ==0 ) -return label; + &dentry->d_name, &context); + +if (err) +return NULL ; + + label->label =kmemdup (context.context, context.len,GFP_KERNEL ); +if (label->label ==NULL ) + label =NULL ; +else + label->len = context.len; + +security_release_secctx (&context); + +return label; -return NULL ; }static inline void nfs4_label_release_security (struct nfs4_label *label) { -struct lsmcontext scaff;/* scaffolding */ - -if (label) { -lsmcontext_init (&scaff, label->label, label->len,0 ); -security_release_secctx (&scaff); - } +kfree (label->label); }static inline u32 *nfs4_bitmask (struct nfs_server *server,struct nfs4_label *label) {include/linux/security.h +3
-4@@ -348,8 +348,8 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb,int security_add_mnt_opt (const char *option,const char *val,int len,void **mnt_opts);int security_dentry_init_security (struct dentry *dentry,int mode, -const struct qstr *name,void **ctx, -u32 *ctxlen); +const struct qstr *name, +struct lsmcontext *ctx); int security_dentry_create_files_as(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old,@@ -720,8 +720,7 @@ static inline void security_inode_free(struct inode *inode)static inline int security_dentry_init_security (struct dentry *dentry,int mode,const struct qstr *name, -void **ctx, -u32 *ctxlen) +struct lsmcontext *ctx) {return -EOPNOTSUPP ; }security/security.c +5
-4@@ -453,6 +453,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,* secid in the lsmblob structure. */ if (hooks[i].head == &security_hook_heads.audit_rule_match || + hooks[i].head == + &security_hook_heads.dentry_init_security || hooks[i].head == &security_hook_heads.kernel_act_as || hooks[i].head == &security_hook_heads.socket_getpeersec_dgram ||@@ -1040,11 +1042,21 @@ void security_inode_free(struct inode *inode) }int security_dentry_init_security (struct dentry *dentry,int mode, -const struct qstr *name,void **ctx, -u32 *ctxlen) +const struct qstr *name, +struct lsmcontext *cp) { -return call_int_hook (dentry_init_security, -EOPNOTSUPP , dentry, mode, - name, ctx, ctxlen); +int *display = current->security;
security/security.c void security_inode_free(struct inode *inode) · line 1058
Quoted 10 lines
security/security.c +10
-0+struct security_hook_list *hp; + +hlist_for_each_entry (hp, &security_hook_heads.dentry_init_security, + list) +if (*display ==0 || *display == hp->slot) { + cp->slot = hp->slot; +return hp->hook.dentry_init_security (dentry, mode, + name, (void **)&cp->context, &cp->len); + } +
should be
if (*display == LSMBLOB_INVALID || *display == hp->slot)
Quoted 5 lines
security/security.c +1
-0+return -EOPNOTSUPP ; }EXPORT_SYMBOL (security_dentry_init_security);
Casey Schaufler
maintainerPATCH v3 19/24 LSM: Use lsmcontext in security_inode_getsecctx
In reply to Casey SchauflerChange the security_inode_getsecctx() interface to fill a lsmcontext 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. A lsmcontext is used within kernfs to store the security information as well.
--- fs/kernfs/dir.c | 8 ++------ fs/kernfs/inode.c | 34 ++++++++++++---------------------- fs/kernfs/kernfs-internal.h | 3 +-- fs/nfsd/nfs4xdr.c | 23 +++++++++-------------- include/linux/security.h | 5 +++-- security/security.c | 13 +++++++++++-- 6 files changed, 38 insertions(+), 48 deletions(-)
fs/kernfs/dir.c +2 -6
@@ -532,12 +532,8 @@ void kernfs_put(struct kernfs_node *kn)kfree_const (kn->name);if (kn->iattr) { -struct lsmcontext scaff;/* scaffolding */ -if (kn->iattr->ia_secdata) { -lsmcontext_init (&scaff, kn->iattr->ia_secdata, - kn->iattr->ia_secdata_len,0 ); -security_release_secctx (&scaff); - } +if (kn->iattr->ia_context.context) +security_release_secctx (&kn->iattr->ia_context);simple_xattrs_free (&kn->iattr->xattrs);kmem_cache_free (kernfs_iattrs_cache, kn->iattr); }
fs/kernfs/inode.c +12 -22
@@ -135,21 +135,14 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)return error; } -static int kernfs_node_setsecdata (struct kernfs_iattrs *attrs,void **secdata, -u32 *secdata_len) +static void kernfs_node_setsecdata (struct kernfs_iattrs *attrs, +struct lsmcontext *cp) { -void *old_secdata; -size_t old_secdata_len; +struct lsmcontext old_context; - old_secdata = attrs->ia_secdata; - old_secdata_len = attrs->ia_secdata_len; - - attrs->ia_secdata = *secdata; - attrs->ia_secdata_len = *secdata_len; - - *secdata = old_secdata; - *secdata_len = old_secdata_len; -return 0 ; + old_context = attrs->ia_context; + attrs->ia_context = *cp; + *cp = old_context; }ssize_t kernfs_iop_listxattr (struct dentry *dentry,char *buf,size_t size)
@@ -192,8 +185,8 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)* persistent copy in kernfs_node. */ set_inode_attr (inode, &attrs->ia_iattr); -security_inode_notifysecctx (inode, attrs->ia_secdata, - attrs->ia_secdata_len); +security_inode_notifysecctx (inode, attrs->ia_context.context, + attrs->ia_context.len); }if (kernfs_type (kn) ==KERNFS_DIR )
@@ -350,8 +343,6 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler,struct kernfs_node *kn = inode->i_private;struct kernfs_iattrs *attrs;struct lsmcontext context; -void *secdata; -u32 secdata_len =0 ;int error; attrs =kernfs_iattrs (kn);
@@ -361,18 +352,17 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, error =security_inode_setsecurity (inode, suffix, value, size, flags);if (error)return error; - error =security_inode_getsecctx (inode, &secdata, &secdata_len); + error =security_inode_getsecctx (inode, &context);if (error)return error;mutex_lock (&kernfs_mutex); - error =kernfs_node_setsecdata (attrs, &secdata, &secdata_len); +kernfs_node_setsecdata (attrs, &context);mutex_unlock (&kernfs_mutex); -if (secdata) { -lsmcontext_init (&context, secdata, secdata_len,0 ); +if (context.context)security_release_secctx (&context); - } +return error; }
fs/kernfs/kernfs-internal.h +1 -2
@@ -21,8 +21,7 @@struct kernfs_iattrs {struct iattr ia_iattr; -void *ia_secdata; -u32 ia_secdata_len; +struct lsmcontext ia_context;struct simple_xattrs xattrs; };
fs/nfsd/nfs4xdr.c +9 -14
@@ -2304,11 +2304,11 @@ nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types)#ifdef CONFIG_NFSD_V4_SECURITY_LABEL static inline __be32 nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, -void *context,int len) +struct lsmcontext *context) {__be32 *p; - p =xdr_reserve_space (xdr, len +4 +4 +4 ); + p =xdr_reserve_space (xdr, context->len +4 +4 +4 );if (!p)return nfserr_resource;
@@ -2318,13 +2318,13 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,*/ *p++ =cpu_to_be32 (0 );/* lfs */ *p++ =cpu_to_be32 (0 );/* pi */ - p =xdr_encode_opaque (p, context, len); + p =xdr_encode_opaque (p, context->context, context->len); return 0; }#else static inline __be32 nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, -void *context,int len) +struct lsmcontext *context) {return 0 ; }#endif
@@ -2420,9 +2420,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,__be32 status;int err;struct nfs4_acl *acl =NULL ; -struct lsmcontext scaff;/* scaffolding */ -void *context =NULL ; -int contextlen; +struct lsmcontext context;bool contextsupport = false;struct nfsd4_compoundres *resp = rqstp->rq_resp;u32 minorversion = resp->cstate.minorversion;
@@ -2479,7 +2477,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {if (exp->ex_flags &NFSEXP_SECURITY_LABEL ) err =security_inode_getsecctx (d_inode (dentry), - &context, &contextlen); + &context);else err = -EOPNOTSUPP ; contextsupport = (err ==0 );
@@ -2908,8 +2906,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, }if (bmval2 &FATTR4_WORD2_SECURITY_LABEL ) { - status =nfsd4_encode_security_label (xdr, rqstp, context, - contextlen); + status =nfsd4_encode_security_label (xdr, rqstp, &context);if (status) goto out; }
@@ -2920,10 +2917,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, out:#ifdef CONFIG_NFSD_V4_SECURITY_LABEL -if (context) { -lsmcontext_init (&scaff, context, contextlen,0 );/*scaffolding*/ -security_release_secctx (&scaff); - } +if (context.context) +security_release_secctx (&context);#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree (acl);if (tempfh) {
include/linux/security.h +3 -2
@@ -485,7 +485,7 @@ void security_release_secctx(struct lsmcontext *cp);void security_inode_invalidate_secctx (struct inode *inode);int security_inode_notifysecctx (struct inode *inode,void *ctx,u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen); -int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen); +int security_inode_getsecctx (struct inode *inode,struct lsmcontext *cp);#else /* CONFIG_SECURITY */ static inline int call_lsm_notifier (enum lsm_event event,void *data)
@@ -1286,7 +1286,8 @@ static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 {return -EOPNOTSUPP ; } -static inline int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) +static inline int security_inode_getsecctx (struct inode *inode, +struct lsmcontext *cp) {return -EOPNOTSUPP ; }
security/security.c +11 -2
@@ -2139,9 +2139,18 @@ int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) }EXPORT_SYMBOL (security_inode_setsecctx); -int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) +int security_inode_getsecctx (struct inode *inode,struct lsmcontext *cp) { -return call_int_hook (inode_getsecctx, -EOPNOTSUPP , inode, ctx, ctxlen); +int *display = current->security; +struct security_hook_list *hp; + +hlist_for_each_entry (hp, &security_hook_heads.inode_getsecctx, list) +if (*display ==0 || *display == hp->slot) { + cp->slot = hp->slot; +return hp->hook.inode_getsecctx (inode, + (void **)&cp->context, &cp->len); + } +return -EOPNOTSUPP ; }EXPORT_SYMBOL (security_inode_getsecctx);
Signature · 1 line
2.20.1
Re: [PATCH v3 19/24] LSM: Use lsmcontext in security_inode_getsecctx
Quoted 8 lines · Casey Schaufler
Change the
security_inode_getsecctx()interface to fill a lsmcontext structure instead of data and length pointers. This provides the information about which LSM created the context so thatsecurity_release_secctx()can use the correct hook. A lsmcontext is used within kernfs to store the security information as well.Signed-off-by Casey Schaufler <[email protected]>
-Kees
Quoted 245 lines
--- fs/kernfs/dir.c | 8 ++------ fs/kernfs/inode.c | 34 ++++++++++++---------------------- fs/kernfs/kernfs-internal.h | 3 +-- fs/nfsd/nfs4xdr.c | 23 +++++++++-------------- include/linux/security.h | 5 +++-- security/security.c | 13 +++++++++++-- 6 files changed, 38 insertions(+), 48 deletions(-)fs/kernfs/dir.c +2
-6@@ -532,12 +532,8 @@ void kernfs_put(struct kernfs_node *kn)kfree_const (kn->name);if (kn->iattr) { -struct lsmcontext scaff;/* scaffolding */ -if (kn->iattr->ia_secdata) { -lsmcontext_init (&scaff, kn->iattr->ia_secdata, - kn->iattr->ia_secdata_len,0 ); -security_release_secctx (&scaff); - } +if (kn->iattr->ia_context.context) +security_release_secctx (&kn->iattr->ia_context);simple_xattrs_free (&kn->iattr->xattrs);kmem_cache_free (kernfs_iattrs_cache, kn->iattr); }fs/kernfs/inode.c +12
-22@@ -135,21 +135,14 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)return error; } -static int kernfs_node_setsecdata (struct kernfs_iattrs *attrs,void **secdata, -u32 *secdata_len) +static void kernfs_node_setsecdata (struct kernfs_iattrs *attrs, +struct lsmcontext *cp) { -void *old_secdata; -size_t old_secdata_len; +struct lsmcontext old_context; - old_secdata = attrs->ia_secdata; - old_secdata_len = attrs->ia_secdata_len; - - attrs->ia_secdata = *secdata; - attrs->ia_secdata_len = *secdata_len; - - *secdata = old_secdata; - *secdata_len = old_secdata_len; -return 0 ; + old_context = attrs->ia_context; + attrs->ia_context = *cp; + *cp = old_context; }ssize_t kernfs_iop_listxattr (struct dentry *dentry,char *buf,size_t size)@@ -192,8 +185,8 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)* persistent copy in kernfs_node. */ set_inode_attr (inode, &attrs->ia_iattr); -security_inode_notifysecctx (inode, attrs->ia_secdata, - attrs->ia_secdata_len); +security_inode_notifysecctx (inode, attrs->ia_context.context, + attrs->ia_context.len); }if (kernfs_type (kn) ==KERNFS_DIR )@@ -350,8 +343,6 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler,struct kernfs_node *kn = inode->i_private;struct kernfs_iattrs *attrs;struct lsmcontext context; -void *secdata; -u32 secdata_len =0 ;int error; attrs =kernfs_iattrs (kn);@@ -361,18 +352,17 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, error =security_inode_setsecurity (inode, suffix, value, size, flags);if (error)return error; - error =security_inode_getsecctx (inode, &secdata, &secdata_len); + error =security_inode_getsecctx (inode, &context);if (error)return error;mutex_lock (&kernfs_mutex); - error =kernfs_node_setsecdata (attrs, &secdata, &secdata_len); +kernfs_node_setsecdata (attrs, &context);mutex_unlock (&kernfs_mutex); -if (secdata) { -lsmcontext_init (&context, secdata, secdata_len,0 ); +if (context.context)security_release_secctx (&context); - } +return error; }fs/kernfs/kernfs-internal.h +1
-2@@ -21,8 +21,7 @@struct kernfs_iattrs {struct iattr ia_iattr; -void *ia_secdata; -u32 ia_secdata_len; +struct lsmcontext ia_context;struct simple_xattrs xattrs; };fs/nfsd/nfs4xdr.c +9
-14@@ -2304,11 +2304,11 @@ nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types)#ifdef CONFIG_NFSD_V4_SECURITY_LABEL static inline __be32 nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, -void *context,int len) +struct lsmcontext *context) {__be32 *p; - p =xdr_reserve_space (xdr, len +4 +4 +4 ); + p =xdr_reserve_space (xdr, context->len +4 +4 +4 );if (!p)return nfserr_resource;@@ -2318,13 +2318,13 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,*/ *p++ =cpu_to_be32 (0 );/* lfs */ *p++ =cpu_to_be32 (0 );/* pi */ - p =xdr_encode_opaque (p, context, len); + p =xdr_encode_opaque (p, context->context, context->len); return 0; }#else static inline __be32 nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, -void *context,int len) +struct lsmcontext *context) {return 0 ; }#endif @@ -2420,9 +2420,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,__be32 status;int err;struct nfs4_acl *acl =NULL ; -struct lsmcontext scaff;/* scaffolding */ -void *context =NULL ; -int contextlen; +struct lsmcontext context;bool contextsupport = false;struct nfsd4_compoundres *resp = rqstp->rq_resp;u32 minorversion = resp->cstate.minorversion;@@ -2479,7 +2477,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {if (exp->ex_flags &NFSEXP_SECURITY_LABEL ) err =security_inode_getsecctx (d_inode (dentry), - &context, &contextlen); + &context);else err = -EOPNOTSUPP ; contextsupport = (err ==0 );@@ -2908,8 +2906,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, }if (bmval2 &FATTR4_WORD2_SECURITY_LABEL ) { - status =nfsd4_encode_security_label (xdr, rqstp, context, - contextlen); + status =nfsd4_encode_security_label (xdr, rqstp, &context);if (status) goto out; }@@ -2920,10 +2917,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, out:#ifdef CONFIG_NFSD_V4_SECURITY_LABEL -if (context) { -lsmcontext_init (&scaff, context, contextlen,0 );/*scaffolding*/ -security_release_secctx (&scaff); - } +if (context.context) +security_release_secctx (&context);#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree (acl);if (tempfh) {include/linux/security.h +3
-2@@ -485,7 +485,7 @@ void security_release_secctx(struct lsmcontext *cp);void security_inode_invalidate_secctx (struct inode *inode);int security_inode_notifysecctx (struct inode *inode,void *ctx,u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen); -int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen); +int security_inode_getsecctx (struct inode *inode,struct lsmcontext *cp);#else /* CONFIG_SECURITY */ static inline int call_lsm_notifier (enum lsm_event event,void *data)@@ -1286,7 +1286,8 @@ static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 {return -EOPNOTSUPP ; } -static inline int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) +static inline int security_inode_getsecctx (struct inode *inode, +struct lsmcontext *cp) {return -EOPNOTSUPP ; }security/security.c +11
-2@@ -2139,9 +2139,18 @@ int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) }EXPORT_SYMBOL (security_inode_setsecctx); -int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) +int security_inode_getsecctx (struct inode *inode,struct lsmcontext *cp) { -return call_int_hook (inode_getsecctx, -EOPNOTSUPP , inode, ctx, ctxlen); +int *display = current->security; +struct security_hook_list *hp; + +hlist_for_each_entry (hp, &security_hook_heads.inode_getsecctx, list) +if (*display ==0 || *display == hp->slot) { + cp->slot = hp->slot; +return hp->hook.inode_getsecctx (inode, + (void **)&cp->context, &cp->len); + } +return -EOPNOTSUPP ; }EXPORT_SYMBOL (security_inode_getsecctx);Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
John Johansen
maintainerPATCH v3 19/24 LSM: Use lsmcontext in security_inode_getsecctx
In reply to Casey SchauflerQuoted 8 lines · Casey Schaufler
Change the
security_inode_getsecctx()interface to fill a lsmcontext structure instead of data and length pointers. This provides the information about which LSM created the context so thatsecurity_release_secctx()can use the correct hook. A lsmcontext is used within kernfs to store the security information as well.Signed-off-by Casey Schaufler <[email protected]>
with the issue below fixed
Quoted 224 lines
--- fs/kernfs/dir.c | 8 ++------ fs/kernfs/inode.c | 34 ++++++++++++---------------------- fs/kernfs/kernfs-internal.h | 3 +-- fs/nfsd/nfs4xdr.c | 23 +++++++++-------------- include/linux/security.h | 5 +++-- security/security.c | 13 +++++++++++-- 6 files changed, 38 insertions(+), 48 deletions(-)fs/kernfs/dir.c +2
-6@@ -532,12 +532,8 @@ void kernfs_put(struct kernfs_node *kn)kfree_const (kn->name);if (kn->iattr) { -struct lsmcontext scaff;/* scaffolding */ -if (kn->iattr->ia_secdata) { -lsmcontext_init (&scaff, kn->iattr->ia_secdata, - kn->iattr->ia_secdata_len,0 ); -security_release_secctx (&scaff); - } +if (kn->iattr->ia_context.context) +security_release_secctx (&kn->iattr->ia_context);simple_xattrs_free (&kn->iattr->xattrs);kmem_cache_free (kernfs_iattrs_cache, kn->iattr); }fs/kernfs/inode.c +12
-22@@ -135,21 +135,14 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)return error; } -static int kernfs_node_setsecdata (struct kernfs_iattrs *attrs,void **secdata, -u32 *secdata_len) +static void kernfs_node_setsecdata (struct kernfs_iattrs *attrs, +struct lsmcontext *cp) { -void *old_secdata; -size_t old_secdata_len; +struct lsmcontext old_context; - old_secdata = attrs->ia_secdata; - old_secdata_len = attrs->ia_secdata_len; - - attrs->ia_secdata = *secdata; - attrs->ia_secdata_len = *secdata_len; - - *secdata = old_secdata; - *secdata_len = old_secdata_len; -return 0 ; + old_context = attrs->ia_context; + attrs->ia_context = *cp; + *cp = old_context; }ssize_t kernfs_iop_listxattr (struct dentry *dentry,char *buf,size_t size)@@ -192,8 +185,8 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)* persistent copy in kernfs_node. */ set_inode_attr (inode, &attrs->ia_iattr); -security_inode_notifysecctx (inode, attrs->ia_secdata, - attrs->ia_secdata_len); +security_inode_notifysecctx (inode, attrs->ia_context.context, + attrs->ia_context.len); }if (kernfs_type (kn) ==KERNFS_DIR )@@ -350,8 +343,6 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler,struct kernfs_node *kn = inode->i_private;struct kernfs_iattrs *attrs;struct lsmcontext context; -void *secdata; -u32 secdata_len =0 ;int error; attrs =kernfs_iattrs (kn);@@ -361,18 +352,17 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, error =security_inode_setsecurity (inode, suffix, value, size, flags);if (error)return error; - error =security_inode_getsecctx (inode, &secdata, &secdata_len); + error =security_inode_getsecctx (inode, &context);if (error)return error;mutex_lock (&kernfs_mutex); - error =kernfs_node_setsecdata (attrs, &secdata, &secdata_len); +kernfs_node_setsecdata (attrs, &context);mutex_unlock (&kernfs_mutex); -if (secdata) { -lsmcontext_init (&context, secdata, secdata_len,0 ); +if (context.context)security_release_secctx (&context); - } +return error; }fs/kernfs/kernfs-internal.h +1
-2@@ -21,8 +21,7 @@struct kernfs_iattrs {struct iattr ia_iattr; -void *ia_secdata; -u32 ia_secdata_len; +struct lsmcontext ia_context;struct simple_xattrs xattrs; };fs/nfsd/nfs4xdr.c +9
-14@@ -2304,11 +2304,11 @@ nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types)#ifdef CONFIG_NFSD_V4_SECURITY_LABEL static inline __be32 nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, -void *context,int len) +struct lsmcontext *context) {__be32 *p; - p =xdr_reserve_space (xdr, len +4 +4 +4 ); + p =xdr_reserve_space (xdr, context->len +4 +4 +4 );if (!p)return nfserr_resource;@@ -2318,13 +2318,13 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,*/ *p++ =cpu_to_be32 (0 );/* lfs */ *p++ =cpu_to_be32 (0 );/* pi */ - p =xdr_encode_opaque (p, context, len); + p =xdr_encode_opaque (p, context->context, context->len); return 0; }#else static inline __be32 nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, -void *context,int len) +struct lsmcontext *context) {return 0 ; }#endif @@ -2420,9 +2420,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,__be32 status;int err;struct nfs4_acl *acl =NULL ; -struct lsmcontext scaff;/* scaffolding */ -void *context =NULL ; -int contextlen; +struct lsmcontext context;bool contextsupport = false;struct nfsd4_compoundres *resp = rqstp->rq_resp;u32 minorversion = resp->cstate.minorversion;@@ -2479,7 +2477,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {if (exp->ex_flags &NFSEXP_SECURITY_LABEL ) err =security_inode_getsecctx (d_inode (dentry), - &context, &contextlen); + &context);else err = -EOPNOTSUPP ; contextsupport = (err ==0 );@@ -2908,8 +2906,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, }if (bmval2 &FATTR4_WORD2_SECURITY_LABEL ) { - status =nfsd4_encode_security_label (xdr, rqstp, context, - contextlen); + status =nfsd4_encode_security_label (xdr, rqstp, &context);if (status) goto out; }@@ -2920,10 +2917,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, out:#ifdef CONFIG_NFSD_V4_SECURITY_LABEL -if (context) { -lsmcontext_init (&scaff, context, contextlen,0 );/*scaffolding*/ -security_release_secctx (&scaff); - } +if (context.context) +security_release_secctx (&context);#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree (acl);if (tempfh) {include/linux/security.h +3
-2@@ -485,7 +485,7 @@ void security_release_secctx(struct lsmcontext *cp);void security_inode_invalidate_secctx (struct inode *inode);int security_inode_notifysecctx (struct inode *inode,void *ctx,u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen); -int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen); +int security_inode_getsecctx (struct inode *inode,struct lsmcontext *cp);#else /* CONFIG_SECURITY */ static inline int call_lsm_notifier (enum lsm_event event,void *data)@@ -1286,7 +1286,8 @@ static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 {return -EOPNOTSUPP ; } -static inline int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) +static inline int security_inode_getsecctx (struct inode *inode, +struct lsmcontext *cp) {return -EOPNOTSUPP ; }security/security.c +0
-0@@ -2139,9 +2139,18 @@ int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) }EXPORT_SYMBOL (security_inode_setsecctx);
security/security.c int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) · line 2148
Quoted 10 lines
security/security.c +6
-2-int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) +int security_inode_getsecctx (struct inode *inode,struct lsmcontext *cp) { -return call_int_hook (inode_getsecctx, -EOPNOTSUPP , inode, ctx, ctxlen); +int *display = current->security; +struct security_hook_list *hp; + +hlist_for_each_entry (hp, &security_hook_heads.inode_getsecctx, list) +if (*display ==0 || *display == hp->slot) {
should be
if (*display == LSMBLOB_INVALID || *display == hp->slot)
Quoted 9 lines
security/security.c +5
-0+ cp->slot = hp->slot; +return hp->hook.inode_getsecctx (inode, + (void **)&cp->context, &cp->len); + } +return -EOPNOTSUPP ; }EXPORT_SYMBOL (security_inode_getsecctx);
Casey Schaufler
maintainerPATCH v3 20/24 LSM: security_secid_to_secctx in netlink netfilter
In reply to Casey SchauflerChange netlink netfilter interfaces to use lsmcontext pointers, and remove scaffolding.
--- net/netfilter/nfnetlink_queue.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
net/netfilter/nfnetlink_queue.c +13 -19
@@ -305,12 +305,10 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)return -1 ; } -static u32 nfqnl_get_sk_secctx (struct sk_buff *skb,char **secdata) +static u32 nfqnl_get_sk_secctx (struct sk_buff *skb,struct lsmcontext *context) { -u32 seclen =0 ;#if IS_ENABLED (CONFIG_NETWORK_SECMARK )struct lsmblob blob; -struct lsmcontext context;if (!skb || !sk_fullsock (skb->sk))return 0 ;
@@ -318,15 +316,16 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata)read_lock_bh (&skb->sk->sk_callback_lock);if (skb->secmark) { +/* Any LSM might be looking for the secmark */ lsmblob_init (&blob, skb->secmark); -security_secid_to_secctx (&blob, &context); - *secdata = context.context; +security_secid_to_secctx (&blob, context); }read_unlock_bh (&skb->sk->sk_callback_lock); - seclen = context.len; +return context->len; +#else +return 0 ;#endif -return seclen; }static u32 nfqnl_get_bridge_size (struct nf_queue_entry *entry)
@@ -402,8 +401,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,enum ip_conntrack_info uninitialized_var (ctinfo );struct nfnl_ct_hook *nfnl_ct;bool csum_verify; -struct lsmcontext scaff;/* scaffolding */ -char *secdata =NULL ; +struct lsmcontext context;u32 seclen =0 ; size =nlmsg_total_size (sizeof (struct nfgenmsg ))
@@ -470,7 +468,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, }if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { - seclen =nfqnl_get_sk_secctx (entskb, &secdata); + seclen =nfqnl_get_sk_secctx (entskb, &context);if (seclen) size +=nla_total_size (seclen); }
@@ -605,7 +603,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, nfqnl_put_sk_uidgid(skb, entskb->sk) < 0) goto nla_put_failure; -if (seclen &&nla_put (skb,NFQA_SECCTX , seclen, secdata)) +if (seclen &&nla_put (skb,NFQA_SECCTX , context.len, context.context)) goto nla_put_failure;if (ct && nfnl_ct->build (skb, ct, ctinfo,NFQA_CT ,NFQA_CT_INFO ) <0 )
@@ -633,10 +631,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen) { -lsmcontext_init (&scaff, secdata, seclen,0 ); -security_release_secctx (&scaff); - } +if (seclen) +security_release_secctx (&context);return skb; nla_put_failure:
@@ -644,10 +640,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen) { -lsmcontext_init (&scaff, secdata, seclen,0 ); -security_release_secctx (&scaff); - } +if (seclen) +security_release_secctx (&context);return NULL ; }
Signature · 1 line
2.20.1
Re: [PATCH v3 20/24] LSM: security_secid_to_secctx in netlink netfilter
Quoted 4 lines · Casey Schaufler
Change netlink netfilter interfaces to use lsmcontext pointers, and remove scaffolding.
Signed-off-by Casey Schaufler <[email protected]>
-Kees
Quoted 100 lines
--- net/netfilter/nfnetlink_queue.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)net/netfilter/nfnetlink_queue.c +13
-19@@ -305,12 +305,10 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)return -1 ; } -static u32 nfqnl_get_sk_secctx (struct sk_buff *skb,char **secdata) +static u32 nfqnl_get_sk_secctx (struct sk_buff *skb,struct lsmcontext *context) { -u32 seclen =0 ;#if IS_ENABLED (CONFIG_NETWORK_SECMARK )struct lsmblob blob; -struct lsmcontext context;if (!skb || !sk_fullsock (skb->sk))return 0 ;@@ -318,15 +316,16 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata)read_lock_bh (&skb->sk->sk_callback_lock);if (skb->secmark) { +/* Any LSM might be looking for the secmark */ lsmblob_init (&blob, skb->secmark); -security_secid_to_secctx (&blob, &context); - *secdata = context.context; +security_secid_to_secctx (&blob, context); }read_unlock_bh (&skb->sk->sk_callback_lock); - seclen = context.len; +return context->len; +#else +return 0 ;#endif -return seclen; }static u32 nfqnl_get_bridge_size (struct nf_queue_entry *entry)@@ -402,8 +401,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,enum ip_conntrack_info uninitialized_var (ctinfo );struct nfnl_ct_hook *nfnl_ct;bool csum_verify; -struct lsmcontext scaff;/* scaffolding */ -char *secdata =NULL ; +struct lsmcontext context;u32 seclen =0 ; size =nlmsg_total_size (sizeof (struct nfgenmsg ))@@ -470,7 +468,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, }if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { - seclen =nfqnl_get_sk_secctx (entskb, &secdata); + seclen =nfqnl_get_sk_secctx (entskb, &context);if (seclen) size +=nla_total_size (seclen); }@@ -605,7 +603,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, nfqnl_put_sk_uidgid(skb, entskb->sk) < 0) goto nla_put_failure; -if (seclen &&nla_put (skb,NFQA_SECCTX , seclen, secdata)) +if (seclen &&nla_put (skb,NFQA_SECCTX , context.len, context.context)) goto nla_put_failure;if (ct && nfnl_ct->build (skb, ct, ctinfo,NFQA_CT ,NFQA_CT_INFO ) <0 )@@ -633,10 +631,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen) { -lsmcontext_init (&scaff, secdata, seclen,0 ); -security_release_secctx (&scaff); - } +if (seclen) +security_release_secctx (&context);return skb; nla_put_failure:@@ -644,10 +640,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen) { -lsmcontext_init (&scaff, secdata, seclen,0 ); -security_release_secctx (&scaff); - } +if (seclen) +security_release_secctx (&context);return NULL ; }Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
John Johansen
maintainerPATCH v3 20/24 LSM: security_secid_to_secctx in netlink netfilter
In reply to Casey SchauflerQuoted 4 lines · Casey Schaufler
Change netlink netfilter interfaces to use lsmcontext pointers, and remove scaffolding.
Signed-off-by Casey Schaufler <[email protected]>
Quoted 98 lines
--- net/netfilter/nfnetlink_queue.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)net/netfilter/nfnetlink_queue.c +13
-19@@ -305,12 +305,10 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)return -1 ; } -static u32 nfqnl_get_sk_secctx (struct sk_buff *skb,char **secdata) +static u32 nfqnl_get_sk_secctx (struct sk_buff *skb,struct lsmcontext *context) { -u32 seclen =0 ;#if IS_ENABLED (CONFIG_NETWORK_SECMARK )struct lsmblob blob; -struct lsmcontext context;if (!skb || !sk_fullsock (skb->sk))return 0 ;@@ -318,15 +316,16 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata)read_lock_bh (&skb->sk->sk_callback_lock);if (skb->secmark) { +/* Any LSM might be looking for the secmark */ lsmblob_init (&blob, skb->secmark); -security_secid_to_secctx (&blob, &context); - *secdata = context.context; +security_secid_to_secctx (&blob, context); }read_unlock_bh (&skb->sk->sk_callback_lock); - seclen = context.len; +return context->len; +#else +return 0 ;#endif -return seclen; }static u32 nfqnl_get_bridge_size (struct nf_queue_entry *entry)@@ -402,8 +401,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,enum ip_conntrack_info uninitialized_var (ctinfo );struct nfnl_ct_hook *nfnl_ct;bool csum_verify; -struct lsmcontext scaff;/* scaffolding */ -char *secdata =NULL ; +struct lsmcontext context;u32 seclen =0 ; size =nlmsg_total_size (sizeof (struct nfgenmsg ))@@ -470,7 +468,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, }if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { - seclen =nfqnl_get_sk_secctx (entskb, &secdata); + seclen =nfqnl_get_sk_secctx (entskb, &context);if (seclen) size +=nla_total_size (seclen); }@@ -605,7 +603,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, nfqnl_put_sk_uidgid(skb, entskb->sk) < 0) goto nla_put_failure; -if (seclen &&nla_put (skb,NFQA_SECCTX , seclen, secdata)) +if (seclen &&nla_put (skb,NFQA_SECCTX , context.len, context.context)) goto nla_put_failure;if (ct && nfnl_ct->build (skb, ct, ctinfo,NFQA_CT ,NFQA_CT_INFO ) <0 )@@ -633,10 +631,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen) { -lsmcontext_init (&scaff, secdata, seclen,0 ); -security_release_secctx (&scaff); - } +if (seclen) +security_release_secctx (&context);return skb; nla_put_failure:@@ -644,10 +640,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen) { -lsmcontext_init (&scaff, secdata, seclen,0 ); -security_release_secctx (&scaff); - } +if (seclen) +security_release_secctx (&context);return NULL ; }
Casey Schaufler
maintainerPATCH v3 21/24 Audit: Store LSM audit information in an lsmblob
In reply to Casey SchauflerChange the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)
kernel/audit.h +3 -3
@@ -91,7 +91,7 @@ struct audit_names {kuid_t uid;kgid_t gid;dev_t rdev; -u32 osid; +struct lsmblob olsm;struct audit_cap_data fcap;unsigned int fcap_ver;unsigned char type;/* record type */
@@ -148,7 +148,7 @@ struct audit_context {kuid_t target_auid;kuid_t target_uid;unsigned int target_sessionid; -struct lsmblob target_lsm; +struct lsmblob target_lsm;char target_comm[TASK_COMM_LEN ];struct audit_tree_refs *trees, *first_trees;
@@ -165,7 +165,7 @@ struct audit_context {kuid_t uid;kgid_t gid;umode_t mode; -u32 osid; +struct lsmblob olsm;int has_perm;uid_t perm_uid;gid_t perm_gid;
kernel/auditsc.c +11 -27
@@ -646,17 +646,15 @@ static int audit_filter_rules(struct task_struct *tsk,if (f->lsm_rule) {/* Find files that match */ if (name) { -lsmblob_init (&blob, name->osid); result =security_audit_rule_match ( - &blob, + &name->olsm, f->type, f->op, f->lsm_rule); }else if (ctx) {list_for_each_entry (n, &ctx->names_list, list) { -lsmblob_init (&blob, n->osid);if (security_audit_rule_match ( - &blob, + &n->olsm, f->type, f->op, f->lsm_rule)) {
@@ -668,8 +666,7 @@ static int audit_filter_rules(struct task_struct *tsk,/* Find ipc objects that match */ if (!ctx || ctx->type !=AUDIT_IPC )break ; -lsmblob_init (&blob, ctx->ipc.osid); -if (security_audit_rule_match (&blob, +if (security_audit_rule_match (&ctx->ipc.olsm, f->type, f->op, f->lsm_rule)) ++result;
@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm;audit_log_format (ab,"ouid=%u ogid=%u mode=%#ho" ,from_kuid (&init_user_ns, context->ipc.uid),from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid); +if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }
@@ -1346,13 +1340,10 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n,from_kgid (&init_user_ns, n->gid),MAJOR (n->rdev), MINOR(n->rdev)); -if (n->osid !=0 ) { -struct lsmblob blob; +if (lsmblob_is_set (&n->olsm)) {struct lsmcontext lsmctx; -lsmblob_init (&blob, n->osid); -if (security_secid_to_secctx (&blob, &lsmctx)) { -audit_log_format (ab," osid=%u" , n->osid); +if (security_secid_to_secctx (&n->olsm, &lsmctx)) {if (call_panic) *call_panic =2 ; }else {
@@ -1906,17 +1897,13 @@ static inline int audit_copy_fcaps(struct audit_names *name,void audit_copy_inode (struct audit_names *name,const struct dentry *dentry,struct inode *inode,unsigned int flags) { -struct lsmblob blob; - name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; -security_inode_getsecid (inode, &blob); -/* scaffolding until osid is updated */ - name->osid = blob.secid[0 ]; +security_inode_getsecid (inode, &name->olsm);if (flags &AUDIT_INODE_NOEVAL ) { name->fcap_ver =-1 ;return ;
@@ -2266,14 +2253,11 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)void __audit_ipc_obj (struct kern_ipc_perm *ipcp) {struct audit_context *context =audit_context (); -struct lsmblob blob; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm =0 ; -security_ipc_getsecid (ipcp, &blob); -/* scaffolding on the [0] - change "osid" to a lsmblob */ - context->ipc.osid = blob.secid[0 ]; +security_ipc_getsecid (ipcp, &context->ipc.olsm); context->type =AUDIT_IPC ; }
Signature · 1 line
2.20.1
Re: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
Quoted 86 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)kernel/audit.h +3
-3@@ -91,7 +91,7 @@ struct audit_names {kuid_t uid;kgid_t gid;dev_t rdev; -u32 osid; +struct lsmblob olsm;struct audit_cap_data fcap;unsigned int fcap_ver;unsigned char type;/* record type */ @@ -148,7 +148,7 @@ struct audit_context {kuid_t target_auid;kuid_t target_uid;unsigned int target_sessionid; -struct lsmblob target_lsm; +struct lsmblob target_lsm;char target_comm[TASK_COMM_LEN ];struct audit_tree_refs *trees, *first_trees;@@ -165,7 +165,7 @@ struct audit_context {kuid_t uid;kgid_t gid;umode_t mode; -u32 osid; +struct lsmblob olsm;int has_perm;uid_t perm_uid;gid_t perm_gid;kernel/auditsc.c +4
-7@@ -646,17 +646,15 @@ static int audit_filter_rules(struct task_struct *tsk,if (f->lsm_rule) {/* Find files that match */ if (name) { -lsmblob_init (&blob, name->osid); result =security_audit_rule_match ( - &blob, + &name->olsm, f->type, f->op, f->lsm_rule); }else if (ctx) {list_for_each_entry (n, &ctx->names_list, list) { -lsmblob_init (&blob, n->osid);if (security_audit_rule_match ( - &blob, + &n->olsm, f->type, f->op, f->lsm_rule)) {@@ -668,8 +666,7 @@ static int audit_filter_rules(struct task_struct *tsk,/* Find ipc objects that match */ if (!ctx || ctx->type !=AUDIT_IPC )break ; -lsmblob_init (&blob, ctx->ipc.osid); -if (security_audit_rule_match (&blob, +if (security_audit_rule_match (&ctx->ipc.olsm, f->type, f->op, f->lsm_rule)) ++result;@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid),
kernel/auditsc.c static void show_special(struct audit_context *context, int *call_panic) · line 1202
Quoted 10 lines
kernel/auditsc.c +1
-5from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid);
Should this (and the other) audit_log_format() calls actually be removed?
-Kees
Quoted 61 lines
kernel/auditsc.c +6
-15+if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }@@ -1346,13 +1340,10 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n,from_kgid (&init_user_ns, n->gid),MAJOR (n->rdev), MINOR(n->rdev)); -if (n->osid !=0 ) { -struct lsmblob blob; +if (lsmblob_is_set (&n->olsm)) {struct lsmcontext lsmctx; -lsmblob_init (&blob, n->osid); -if (security_secid_to_secctx (&blob, &lsmctx)) { -audit_log_format (ab," osid=%u" , n->osid); +if (security_secid_to_secctx (&n->olsm, &lsmctx)) {if (call_panic) *call_panic =2 ; }else {@@ -1906,17 +1897,13 @@ static inline int audit_copy_fcaps(struct audit_names *name,void audit_copy_inode (struct audit_names *name,const struct dentry *dentry,struct inode *inode,unsigned int flags) { -struct lsmblob blob; - name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; -security_inode_getsecid (inode, &blob); -/* scaffolding until osid is updated */ - name->osid = blob.secid[0 ]; +security_inode_getsecid (inode, &name->olsm);if (flags &AUDIT_INODE_NOEVAL ) { name->fcap_ver =-1 ;return ;@@ -2266,14 +2253,11 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)void __audit_ipc_obj (struct kern_ipc_perm *ipcp) {struct audit_context *context =audit_context (); -struct lsmblob blob; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm =0 ; -security_ipc_getsecid (ipcp, &blob); -/* scaffolding on the [0] - change "osid" to a lsmblob */ - context->ipc.osid = blob.secid[0 ]; +security_ipc_getsecid (ipcp, &context->ipc.olsm); context->type =AUDIT_IPC ; }Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
John Johansen
maintainerRe: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
In reply to Casey SchauflerQuoted 7 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>
I know Kees raised this too, but I haven't seen a reply
Eric (Paul is already CCed): I have directly added you because of the question below.
In summary there isn't necessarily a single secid any more, and we need to know whether dropping the logging of the secid or logging all secids is the correct action.
Quoted 79 lines
--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)kernel/audit.h +3
-3@@ -91,7 +91,7 @@ struct audit_names {kuid_t uid;kgid_t gid;dev_t rdev; -u32 osid; +struct lsmblob olsm;struct audit_cap_data fcap;unsigned int fcap_ver;unsigned char type;/* record type */ @@ -148,7 +148,7 @@ struct audit_context {kuid_t target_auid;kuid_t target_uid;unsigned int target_sessionid; -struct lsmblob target_lsm; +struct lsmblob target_lsm;char target_comm[TASK_COMM_LEN ];struct audit_tree_refs *trees, *first_trees;@@ -165,7 +165,7 @@ struct audit_context {kuid_t uid;kgid_t gid;umode_t mode; -u32 osid; +struct lsmblob olsm;int has_perm;uid_t perm_uid;gid_t perm_gid;kernel/auditsc.c +4
-7@@ -646,17 +646,15 @@ static int audit_filter_rules(struct task_struct *tsk,if (f->lsm_rule) {/* Find files that match */ if (name) { -lsmblob_init (&blob, name->osid); result =security_audit_rule_match ( - &blob, + &name->olsm, f->type, f->op, f->lsm_rule); }else if (ctx) {list_for_each_entry (n, &ctx->names_list, list) { -lsmblob_init (&blob, n->osid);if (security_audit_rule_match ( - &blob, + &n->olsm, f->type, f->op, f->lsm_rule)) {@@ -668,8 +666,7 @@ static int audit_filter_rules(struct task_struct *tsk,/* Find ipc objects that match */ if (!ctx || ctx->type !=AUDIT_IPC )break ; -lsmblob_init (&blob, ctx->ipc.osid); -if (security_audit_rule_match (&blob, +if (security_audit_rule_match (&ctx->ipc.olsm, f->type, f->op, f->lsm_rule)) ++result;@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid),
kernel/auditsc.c static void show_special(struct audit_context *context, int *call_panic) · line 1202
Quoted 10 lines
kernel/auditsc.c +1
-5from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid);
I am not comfortable just dropping this I would think logging all secids is the correct action here.
Quoted 9 lines
kernel/auditsc.c +2
-1+if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }@@ -1346,13 +1340,10 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n, from_kgid(&init_user_ns, n->gid),
kernel/auditsc.c static void audit_log_name(struct audit_context *context, struct audit_names *n, · line 1355
Quoted 10 lines
kernel/auditsc.c +1
-5MAJOR (n->rdev), MINOR(n->rdev)); -if (n->osid !=0 ) { -struct lsmblob blob; +if (lsmblob_is_set (&n->olsm)) {struct lsmcontext lsmctx; -lsmblob_init (&blob, n->osid); -if (security_secid_to_secctx (&blob, &lsmctx)) { -audit_log_format (ab," osid=%u" , n->osid);
and here
Quoted 40 lines
kernel/auditsc.c +3
-9+if (security_secid_to_secctx (&n->olsm, &lsmctx)) {if (call_panic) *call_panic =2 ; }else {@@ -1906,17 +1897,13 @@ static inline int audit_copy_fcaps(struct audit_names *name,void audit_copy_inode (struct audit_names *name,const struct dentry *dentry,struct inode *inode,unsigned int flags) { -struct lsmblob blob; - name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; -security_inode_getsecid (inode, &blob); -/* scaffolding until osid is updated */ - name->osid = blob.secid[0 ]; +security_inode_getsecid (inode, &name->olsm);if (flags &AUDIT_INODE_NOEVAL ) { name->fcap_ver =-1 ;return ;@@ -2266,14 +2253,11 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)void __audit_ipc_obj (struct kern_ipc_perm *ipcp) {struct audit_context *context =audit_context (); -struct lsmblob blob; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm =0 ; -security_ipc_getsecid (ipcp, &blob); -/* scaffolding on the [0] - change "osid" to a lsmblob */ - context->ipc.osid = blob.secid[0 ]; +security_ipc_getsecid (ipcp, &context->ipc.olsm); context->type =AUDIT_IPC ; }
Casey Schaufler
maintainerRe: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
Quoted 8 lines · John Johansen
Quoted 7 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>
Quoted 8 lines
I know Kees raised this too, but I haven't seen a reply
Eric (Paul is already CCed): I have directly added you because of the question below.
In summary there isn't necessarily a single secid any more, and we need to know whether dropping the logging of the secid or logging all secids is the correct action.
It is to be considered that this is an error case. If everything is working normally you should have produced a secctx previously, which you'll have included in the audit record. Including the secid in the record ought to be pointless, as the secid is strictly an internal token with no meaning outside the running kernel. You are providing no security relevant information by providing the secid. I will grant the possibility that the secid might be useful in debugging, but for that a pr_warn is more appropriate than a field in the audit record.
Quoted 156 lines
Quoted 80 lines
--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)kernel/audit.h +3
-3@@ -91,7 +91,7 @@ struct audit_names {kuid_t uid;kgid_t gid;dev_t rdev; -u32 osid; +struct lsmblob olsm;struct audit_cap_data fcap;unsigned int fcap_ver;unsigned char type;/* record type */ @@ -148,7 +148,7 @@ struct audit_context {kuid_t target_auid;kuid_t target_uid;unsigned int target_sessionid; -struct lsmblob target_lsm; +struct lsmblob target_lsm;char target_comm[TASK_COMM_LEN ];struct audit_tree_refs *trees, *first_trees;@@ -165,7 +165,7 @@ struct audit_context {kuid_t uid;kgid_t gid;umode_t mode; -u32 osid; +struct lsmblob olsm;int has_perm;uid_t perm_uid;gid_t perm_gid;kernel/auditsc.c +4
-7@@ -646,17 +646,15 @@ static int audit_filter_rules(struct task_struct *tsk,if (f->lsm_rule) {/* Find files that match */ if (name) { -lsmblob_init (&blob, name->osid); result =security_audit_rule_match ( - &blob, + &name->olsm, f->type, f->op, f->lsm_rule); }else if (ctx) {list_for_each_entry (n, &ctx->names_list, list) { -lsmblob_init (&blob, n->osid);if (security_audit_rule_match ( - &blob, + &n->olsm, f->type, f->op, f->lsm_rule)) {@@ -668,8 +666,7 @@ static int audit_filter_rules(struct task_struct *tsk,/* Find ipc objects that match */ if (!ctx || ctx->type !=AUDIT_IPC )break ; -lsmblob_init (&blob, ctx->ipc.osid); -if (security_audit_rule_match (&blob, +if (security_audit_rule_match (&ctx->ipc.olsm, f->type, f->op, f->lsm_rule)) ++result;@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid),kernel/auditsc.c static void show_special(struct audit_context *context, int *call_panic) · line 1202
Quoted 10 lines
kernel/auditsc.c +1
-5from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid);I am not comfortable just dropping this I would think logging all secids is the correct action here.
Quoted 9 lines
kernel/auditsc.c +2
-1+if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }@@ -1346,13 +1340,10 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n, from_kgid(&init_user_ns, n->gid),kernel/auditsc.c static void audit_log_name(struct audit_context *context, struct audit_names *n, · line 1355
Quoted 10 lines
kernel/auditsc.c +1
-5MAJOR (n->rdev), MINOR(n->rdev)); -if (n->osid !=0 ) { -struct lsmblob blob; +if (lsmblob_is_set (&n->olsm)) {struct lsmcontext lsmctx; -lsmblob_init (&blob, n->osid); -if (security_secid_to_secctx (&blob, &lsmctx)) { -audit_log_format (ab," osid=%u" , n->osid);and here
Quoted 40 lines
kernel/auditsc.c +3
-9+if (security_secid_to_secctx (&n->olsm, &lsmctx)) {if (call_panic) *call_panic =2 ; }else {@@ -1906,17 +1897,13 @@ static inline int audit_copy_fcaps(struct audit_names *name,void audit_copy_inode (struct audit_names *name,const struct dentry *dentry,struct inode *inode,unsigned int flags) { -struct lsmblob blob; - name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; -security_inode_getsecid (inode, &blob); -/* scaffolding until osid is updated */ - name->osid = blob.secid[0 ]; +security_inode_getsecid (inode, &name->olsm);if (flags &AUDIT_INODE_NOEVAL ) { name->fcap_ver =-1 ;return ;@@ -2266,14 +2253,11 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)void __audit_ipc_obj (struct kern_ipc_perm *ipcp) {struct audit_context *context =audit_context (); -struct lsmblob blob; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm =0 ; -security_ipc_getsecid (ipcp, &blob); -/* scaffolding on the [0] - change "osid" to a lsmblob */ - context->ipc.osid = blob.secid[0 ]; +security_ipc_getsecid (ipcp, &context->ipc.olsm); context->type =AUDIT_IPC ; }
Paul Moore
maintainerRe: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
Quoted 18 lines · Casey Schaufler
Quoted 8 lines · John Johansen
Quoted 7 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>Quoted 8 lines
I know Kees raised this too, but I haven't seen a reply
Eric (Paul is already CCed): I have directly added you because of the question below.
In summary there isn't necessarily a single secid any more, and we need to know whether dropping the logging of the secid or logging all secids is the correct action.
Quoted 10 lines
It is to be considered that this is an error case. If everything is working normally you should have produced a secctx previously, which you'll have included in the audit record. Including the secid in the record ought to be pointless, as the secid is strictly an internal token with no meaning outside the running kernel. You are providing no security relevant information by providing the secid. I will grant the possibility that the secid might be useful in debugging, but for that a
pr_warnis more appropriate than a field in the audit record.
FWIW, this probably should have been CC'd to the audit list.
I agree that this is an error case (security_secid_to_secctx() failed to resolve the secid) and further that logging the secid, or a collection of secids, has little value the way things currently work. Since secids are a private kernel implementation detail, we don't really display them outside the context of the kernel, including in the audit logs. Recording a secid in this case doesn't provide anything meaningful since secids aren't recorded in the audit record stream, only the secctxs, and there is no "magic decoder ring" to go between the two in the audit logs, or anywhere else in userspace for that matter.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)
...
Quoted 34 lines
Quoted 34 lines
Quoted 13 lines
kernel/auditsc.c +1
-1@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid),kernel/auditsc.c static void show_special(struct audit_context *context, int *call_panic) · line 1202
Quoted 10 lines
kernel/auditsc.c +1
-5from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid);I am not comfortable just dropping this I would think logging all secids is the correct action here.
Quoted 7 lines
kernel/auditsc.c +2
-1+if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }
Signature · 2 lines
paul moore www.paul-moore.com
John Johansen
maintainerRe: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
Quoted 30 lines · Paul Moore
Quoted 18 lines · Casey Schaufler
Quoted 8 lines · John Johansen
Quoted 7 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>Quoted 8 lines
I know Kees raised this too, but I haven't seen a reply
Eric (Paul is already CCed): I have directly added you because of the question below.
In summary there isn't necessarily a single secid any more, and we need to know whether dropping the logging of the secid or logging all secids is the correct action.
Quoted 10 lines
It is to be considered that this is an error case. If everything is working normally you should have produced a secctx previously, which you'll have included in the audit record. Including the secid in the record ought to be pointless, as the secid is strictly an internal token with no meaning outside the running kernel. You are providing no security relevant information by providing the secid. I will grant the possibility that the secid might be useful in debugging, but for that a
pr_warnis more appropriate than a field in the audit record.
Quoted 2 lines
FWIW, this probably should have been CC'd to the audit list.
hrmm indeed, sorry
Quoted 11 lines
I agree that this is an error case (
security_secid_to_secctx()failed to resolve the secid) and further that logging the secid, or a collection of secids, has little value the way things currently work. Since secids are a private kernel implementation detail, we don't really display them outside the context of the kernel, including in the audit logs. Recording a secid in this case doesn't provide anything meaningful since secids aren't recorded in the audit record stream, only the secctxs, and there is no "magic decoder ring" to go between the two in the audit logs, or anywhere else in userspace for that matter.
Okay, thanks. Casey I am good with just a pr_warn here. I just didn't have context of why it was going to the audit_log and didn't want to change that without some more input.
Quoted 42 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)...
Quoted 34 lines
Quoted 34 lines
Quoted 13 lines
kernel/auditsc.c +1
-1@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid),kernel/auditsc.c static void show_special(struct audit_context *context, int *call_panic) · line 1202
Quoted 10 lines
kernel/auditsc.c +1
-5from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid);I am not comfortable just dropping this I would think logging all secids is the correct action here.
Quoted 7 lines
kernel/auditsc.c +2
-1+if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }
Paul Moore
maintainerRe: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
Quoted 46 lines · John Johansen
Quoted 30 lines · Paul Moore
Quoted 18 lines · Casey Schaufler
Quoted 8 lines · John Johansen
Quoted 7 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>Quoted 8 lines
I know Kees raised this too, but I haven't seen a reply
Eric (Paul is already CCed): I have directly added you because of the question below.
In summary there isn't necessarily a single secid any more, and we need to know whether dropping the logging of the secid or logging all secids is the correct action.
Quoted 10 lines
It is to be considered that this is an error case. If everything is working normally you should have produced a secctx previously, which you'll have included in the audit record. Including the secid in the record ought to be pointless, as the secid is strictly an internal token with no meaning outside the running kernel. You are providing no security relevant information by providing the secid. I will grant the possibility that the secid might be useful in debugging, but for that a
pr_warnis more appropriate than a field in the audit record.Quoted 2 lines
FWIW, this probably should have been CC'd to the audit list.
hrmm indeed, sorry
Quoted 10 lines
I agree that this is an error case (
security_secid_to_secctx()failed to resolve the secid) and further that logging the secid, or a collection of secids, has little value the way things currently work. Since secids are a private kernel implementation detail, we don't really display them outside the context of the kernel, including in the audit logs. Recording a secid in this case doesn't provide anything meaningful since secids aren't recorded in the audit record stream, only the secctxs, and there is no "magic decoder ring" to go between the two in the audit logs, or anywhere else in userspace for that matter.
Quoted 3 lines
Okay, thanks. Casey I am good with just a
pr_warnhere. I just didn't have context of why it was going to theaudit_logand didn't want to change that without some more input.
Hmm. Actually, let me change my comments slightly ... perhaps what we should do here is keep the audit_log_format(), but change it from audit_log_format("osid=%u",...) to audit_log_format("obj=?"). The "?" is used in audit when we can't determine a piece of information, but we normally log it. It wasn't used very widely originally, which is probably why it isn't in this piece of code.
Quoted 41 lines
Quoted 41 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
--- kernel/audit.h | 6 +++--- kernel/auditsc.c | 38 +++++++++++--------------------------- 2 files changed, 14 insertions(+), 30 deletions(-)...
Quoted 34 lines
Quoted 34 lines
Quoted 13 lines
kernel/auditsc.c +1
-1@@ -1187,21 +1184,18 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]);break ; }case AUDIT_IPC : { -u32 osid = context->ipc.osid; +struct lsmblob *olsm = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid),kernel/auditsc.c static void show_special(struct audit_context *context, int *call_panic) · line 1202
Quoted 10 lines
kernel/auditsc.c +1
-5from_kgid (&init_user_ns, context->ipc.gid), context->ipc.mode); -if (osid) { +if (lsmblob_is_set (olsm)) {struct lsmcontext lsmcxt; -struct lsmblob blob; -lsmblob_init (&blob, osid); -if (security_secid_to_secctx (&blob, &lsmcxt)) { -audit_log_format (ab," osid=%u" , osid);I am not comfortable just dropping this I would think logging all secids is the correct action here.
Quoted 7 lines
kernel/auditsc.c +2
-1+if (security_secid_to_secctx (olsm, &lsmcxt)) *call_panic =1 ; - }else { +else {audit_log_format (ab," obj=%s" , lsmcxt.context);security_release_secctx (&lsmcxt); }
Signature · 2 lines
paul moore www.paul-moore.com
Casey Schaufler
maintainerRe: [PATCH v3 21/24] Audit: Store LSM audit information in an lsmblob
Quoted 48 lines · Paul Moore
Quoted 43 lines · John Johansen
Quoted 28 lines · Paul Moore
Quoted 17 lines · Casey Schaufler
Quoted 8 lines · John Johansen
Quoted 7 lines · Casey Schaufler
Change the audit code to store full lsmblob data instead of a single u32 secid. This allows for multiple security modules to use the audit system at the same time. It also allows the removal of scaffolding code that was included during the revision of LSM interfaces.
Signed-off-by Casey Schaufler <[email protected]>Quoted 8 lines
I know Kees raised this too, but I haven't seen a reply
Eric (Paul is already CCed): I have directly added you because of the question below.
In summary there isn't necessarily a single secid any more, and we need to know whether dropping the logging of the secid or logging all secids is the correct action.
Quoted 10 lines
It is to be considered that this is an error case. If everything is working normally you should have produced a secctx previously, which you'll have included in the audit record. Including the secid in the record ought to be pointless, as the secid is strictly an internal token with no meaning outside the running kernel. You are providing no security relevant information by providing the secid. I will grant the possibility that the secid might be useful in debugging, but for that a
pr_warnis more appropriate than a field in the audit record.Quoted 2 lines
FWIW, this probably should have been CC'd to the audit list.
hrmm indeed, sorry
Quoted 10 lines
I agree that this is an error case (
security_secid_to_secctx()failed to resolve the secid) and further that logging the secid, or a collection of secids, has little value the way things currently work. Since secids are a private kernel implementation detail, we don't really display them outside the context of the kernel, including in the audit logs. Recording a secid in this case doesn't provide anything meaningful since secids aren't recorded in the audit record stream, only the secctxs, and there is no "magic decoder ring" to go between the two in the audit logs, or anywhere else in userspace for that matter.Quoted 3 lines
Okay, thanks. Casey I am good with just a
pr_warnhere. I just didn't have context of why it was going to theaudit_logand didn't want to change that without some more input.
Quoted 6 lines
Hmm. Actually, let me change my comments slightly ... perhaps what we should do here is keep the
audit_log_format(), but change it fromaudit_log_format("osid=%u",...)toaudit_log_format("obj=?"). The "?" is used in audit when we can't determine a piece of information, but we normally log it. It wasn't used very widely originally, which is probably why it isn't in this piece of code.
Works for me. I'll make the change. Thank you.
??
Casey Schaufler
maintainerPATCH v3 22/24 LSM: Return the lsmblob slot on initialization
In reply to Casey SchauflerReturn the slot allocated to the calling LSM in the lsmblob structure. This can be used to set lsmblobs explicitly for netlabel interfaces.
--- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/lsm.c | 8 ++++++-- security/security.c | 9 +++++++-- security/selinux/hooks.c | 5 ++++- security/smack/smack_lsm.c | 5 ++++- 5 files changed, 23 insertions(+), 8 deletions(-)
include/linux/lsm_hooks.h +2 -2
@@ -2068,8 +2068,8 @@ struct lsm_blob_sizes {extern struct security_hook_heads security_hook_heads;extern char *lsm_names; -extern void security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm); +extern int security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm);#define LSM_FLAG_LEGACY_MAJOR BIT(0)#define LSM_FLAG_EXCLUSIVE BIT(1)
security/apparmor/lsm.c +6 -2
@@ -47,6 +47,9 @@/* Flag indicating whether initialization completed */ int apparmor_initialized; +/* Slot for the AppArmor secid in the lsmblob structure */ +int apparmor_lsmblob_slot; + DEFINE_PER_CPU(struct aa_buffers, aa_buffers);
@@ -1678,8 +1681,9 @@ static int __init apparmor_init(void)aa_free_root_ns (); goto buffers_out; } -security_add_hooks (apparmor_hooks,ARRAY_SIZE (apparmor_hooks), -"apparmor" ); + apparmor_lsmblob_slot =security_add_hooks (apparmor_hooks, +ARRAY_SIZE (apparmor_hooks), +"apparmor" );/* Report that AppArmor successfully initialized */ apparmor_initialized =1 ;
security/security.c +7 -2
@@ -437,9 +437,12 @@ static int lsm_slot __initdata;* Each LSM has to register its hooks with the infrastructure. * If the LSM is using hooks that export secids allocate a slot * for it in the lsmblob. +* +* Returns the slot number in the lsmblob structure if one is +* allocated or LSMBLOB_INVALID if one was not allocated. */ -void __init security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm) +int __init security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm) {int slot =LSMBLOB_INVALID ;int i;
@@ -479,6 +482,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, }if (lsm_append (lsm, &lsm_names) <0 )panic ("%s - Cannot get early memory.\n" , __func__); + +return slot; }int call_lsm_notifier (enum lsm_event event,void *data)
security/selinux/hooks.c +4 -1
@@ -103,6 +103,7 @@#include "avc_ss.h" struct selinux_state selinux_state; +int selinux_lsmblob_slot;/* SECMARK reference count */ static atomic_t selinux_secmark_refcount =ATOMIC_INIT (0 );
@@ -6877,7 +6878,9 @@ static __init int selinux_init(void)hashtab_cache_init (); -security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks),"selinux" ); + selinux_lsmblob_slot =security_add_hooks (selinux_hooks, +ARRAY_SIZE (selinux_hooks), +"selinux" );if (avc_add_callback (selinux_netcache_avc_callback,AVC_CALLBACK_RESET ))panic ("SELinux: Unable to register AVC netcache callback\n" );
security/smack/smack_lsm.c +4 -1
@@ -60,6 +60,7 @@ static LIST_HEAD(smk_ipv6_port_list);#endif static struct kmem_cache *smack_inode_cache;int smack_enabled; +int smack_lsmblob_slot;#define A (s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s} static struct {
@@ -4749,7 +4750,9 @@ static __init int smack_init(void)/* * Register with LSM */ -security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks),"smack" ); + smack_lsmblob_slot =security_add_hooks (smack_hooks, +ARRAY_SIZE (smack_hooks), +"smack" ); smack_enabled =1 ;pr_info ("Smack: Initializing.\n" );
Signature · 1 line
2.20.1
Re: [PATCH v3 22/24] LSM: Return the lsmblob slot on initialization
Quoted 5 lines · Casey Schaufler
Return the slot allocated to the calling LSM in the lsmblob structure. This can be used to set lsmblobs explicitly for netlabel interfaces.
Signed-off-by Casey Schaufler <[email protected]>
(I have some thoughts on refactoring the slot assignment, but that should happen after this series -- it's nothing more than a storage optimization.)
-Kees
Quoted 126 lines
--- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/lsm.c | 8 ++++++-- security/security.c | 9 +++++++-- security/selinux/hooks.c | 5 ++++- security/smack/smack_lsm.c | 5 ++++- 5 files changed, 23 insertions(+), 8 deletions(-)include/linux/lsm_hooks.h +2
-2@@ -2068,8 +2068,8 @@ struct lsm_blob_sizes {extern struct security_hook_heads security_hook_heads;extern char *lsm_names; -extern void security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm); +extern int security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm);#define LSM_FLAG_LEGACY_MAJOR BIT(0)#define LSM_FLAG_EXCLUSIVE BIT(1)security/apparmor/lsm.c +6
-2@@ -47,6 +47,9 @@/* Flag indicating whether initialization completed */ int apparmor_initialized; +/* Slot for the AppArmor secid in the lsmblob structure */ +int apparmor_lsmblob_slot; + DEFINE_PER_CPU(struct aa_buffers, aa_buffers);@@ -1678,8 +1681,9 @@ static int __init apparmor_init(void)aa_free_root_ns (); goto buffers_out; } -security_add_hooks (apparmor_hooks,ARRAY_SIZE (apparmor_hooks), -"apparmor" ); + apparmor_lsmblob_slot =security_add_hooks (apparmor_hooks, +ARRAY_SIZE (apparmor_hooks), +"apparmor" );/* Report that AppArmor successfully initialized */ apparmor_initialized =1 ;security/security.c +7
-2@@ -437,9 +437,12 @@ static int lsm_slot __initdata;* Each LSM has to register its hooks with the infrastructure. * If the LSM is using hooks that export secids allocate a slot * for it in the lsmblob. +* +* Returns the slot number in the lsmblob structure if one is +* allocated or LSMBLOB_INVALID if one was not allocated. */ -void __init security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm) +int __init security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm) {int slot =LSMBLOB_INVALID ;int i;@@ -479,6 +482,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, }if (lsm_append (lsm, &lsm_names) <0 )panic ("%s - Cannot get early memory.\n" , __func__); + +return slot; }int call_lsm_notifier (enum lsm_event event,void *data)security/selinux/hooks.c +4
-1@@ -103,6 +103,7 @@#include "avc_ss.h" struct selinux_state selinux_state; +int selinux_lsmblob_slot;/* SECMARK reference count */ static atomic_t selinux_secmark_refcount =ATOMIC_INIT (0 );@@ -6877,7 +6878,9 @@ static __init int selinux_init(void)hashtab_cache_init (); -security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks),"selinux" ); + selinux_lsmblob_slot =security_add_hooks (selinux_hooks, +ARRAY_SIZE (selinux_hooks), +"selinux" );if (avc_add_callback (selinux_netcache_avc_callback,AVC_CALLBACK_RESET ))panic ("SELinux: Unable to register AVC netcache callback\n" );security/smack/smack_lsm.c +4
-1@@ -60,6 +60,7 @@ static LIST_HEAD(smk_ipv6_port_list);#endif static struct kmem_cache *smack_inode_cache;int smack_enabled; +int smack_lsmblob_slot;#define A (s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s} static struct {@@ -4749,7 +4750,9 @@ static __init int smack_init(void)/* * Register with LSM */ -security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks),"smack" ); + smack_lsmblob_slot =security_add_hooks (smack_hooks, +ARRAY_SIZE (smack_hooks), +"smack" ); smack_enabled =1 ;pr_info ("Smack: Initializing.\n" );Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
John Johansen
maintainerRe: [PATCH v3 22/24] LSM: Return the lsmblob slot on initialization
Quoted 7 lines · Kees Cook
Quoted 5 lines · Casey Schaufler
Return the slot allocated to the calling LSM in the lsmblob structure. This can be used to set lsmblobs explicitly for netlabel interfaces.
Signed-off-by Casey Schaufler <[email protected]>
Quoted 7 lines
Reviewed-by Kees Cook <[email protected]>(I have some thoughts on refactoring the slot assignment, but that should happen after this series -- it's nothing more than a storage optimization.)
-Kees
haha so do I, now I am curious as to how close they align
Quoted 128 lines
Quoted 127 lines
--- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/lsm.c | 8 ++++++-- security/security.c | 9 +++++++-- security/selinux/hooks.c | 5 ++++- security/smack/smack_lsm.c | 5 ++++- 5 files changed, 23 insertions(+), 8 deletions(-)include/linux/lsm_hooks.h +2
-2@@ -2068,8 +2068,8 @@ struct lsm_blob_sizes {extern struct security_hook_heads security_hook_heads;extern char *lsm_names; -extern void security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm); +extern int security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm);#define LSM_FLAG_LEGACY_MAJOR BIT(0)#define LSM_FLAG_EXCLUSIVE BIT(1)security/apparmor/lsm.c +6
-2@@ -47,6 +47,9 @@/* Flag indicating whether initialization completed */ int apparmor_initialized; +/* Slot for the AppArmor secid in the lsmblob structure */ +int apparmor_lsmblob_slot; + DEFINE_PER_CPU(struct aa_buffers, aa_buffers);@@ -1678,8 +1681,9 @@ static int __init apparmor_init(void)aa_free_root_ns (); goto buffers_out; } -security_add_hooks (apparmor_hooks,ARRAY_SIZE (apparmor_hooks), -"apparmor" ); + apparmor_lsmblob_slot =security_add_hooks (apparmor_hooks, +ARRAY_SIZE (apparmor_hooks), +"apparmor" );/* Report that AppArmor successfully initialized */ apparmor_initialized =1 ;security/security.c +7
-2@@ -437,9 +437,12 @@ static int lsm_slot __initdata;* Each LSM has to register its hooks with the infrastructure. * If the LSM is using hooks that export secids allocate a slot * for it in the lsmblob. +* +* Returns the slot number in the lsmblob structure if one is +* allocated or LSMBLOB_INVALID if one was not allocated. */ -void __init security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm) +int __init security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm) {int slot =LSMBLOB_INVALID ;int i;@@ -479,6 +482,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, }if (lsm_append (lsm, &lsm_names) <0 )panic ("%s - Cannot get early memory.\n" , __func__); + +return slot; }int call_lsm_notifier (enum lsm_event event,void *data)security/selinux/hooks.c +4
-1@@ -103,6 +103,7 @@#include "avc_ss.h" struct selinux_state selinux_state; +int selinux_lsmblob_slot;/* SECMARK reference count */ static atomic_t selinux_secmark_refcount =ATOMIC_INIT (0 );@@ -6877,7 +6878,9 @@ static __init int selinux_init(void)hashtab_cache_init (); -security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks),"selinux" ); + selinux_lsmblob_slot =security_add_hooks (selinux_hooks, +ARRAY_SIZE (selinux_hooks), +"selinux" );if (avc_add_callback (selinux_netcache_avc_callback,AVC_CALLBACK_RESET ))panic ("SELinux: Unable to register AVC netcache callback\n" );security/smack/smack_lsm.c +4
-1@@ -60,6 +60,7 @@ static LIST_HEAD(smk_ipv6_port_list);#endif static struct kmem_cache *smack_inode_cache;int smack_enabled; +int smack_lsmblob_slot;#define A (s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s} static struct {@@ -4749,7 +4750,9 @@ static __init int smack_init(void)/* * Register with LSM */ -security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks),"smack" ); + smack_lsmblob_slot =security_add_hooks (smack_hooks, +ARRAY_SIZE (smack_hooks), +"smack" ); smack_enabled =1 ;pr_info ("Smack: Initializing.\n" );Signature · 1 line
2.20.1
Re: [PATCH v3 22/24] LSM: Return the lsmblob slot on initialization
Quoted 10 lines · John Johansen
Quoted 9 lines · Kees Cook
Quoted 5 lines · Casey Schaufler
Return the slot allocated to the calling LSM in the lsmblob structure. This can be used to set lsmblobs explicitly for netlabel interfaces.
Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>
Quoted 7 lines
Quoted 5 lines
(I have some thoughts on refactoring the slot assignment, but that should happen after this series -- it's nothing more than a storage optimization.)
-Kees
haha so do I, now I am curious as to how close they align
My plan is to create a __ro_after_init "LSM State" structure to hold various things that are needed after init time. All of the lsm_info structures are __initdata, so they can't be retained after init (currently). As far as I can see, there are already a few things that are retained after init:
LSM name (currently a pointer in every hook)
enabled state (technically optional, currently known internally to each LSM) blob size details (currently known internally to each LSM)
and now we'll be adding the "slot". So I was thinking something like:
struct lsm_state {
const char *name;
int enabled;
struct blob_sizes lbs;
int slot;
};And then change the hooks to each carry a pointer to the lsm_state (instead of a name pointer). Also I think it'd be cleanest to define and export the lsm_state instance it via the DEFINE_LSM macro, possibly instead of the existing blob_size pointer. It's possible that lsm_info should just gain some fields and no longer be __initdata, too. We'll see!
Signature · 1 line
Kees Cook
Casey Schaufler
maintainerRe: [PATCH v3 22/24] LSM: Return the lsmblob slot on initialization
In reply to John JohansenQuoted 7 lines · John Johansen
Quoted 6 lines · Kees Cook
Quoted 5 lines · Casey Schaufler
Return the slot allocated to the calling LSM in the lsmblob structure. This can be used to set lsmblobs explicitly for netlabel interfaces.
Signed-off-by Casey Schaufler <[email protected]>
Quoted 8 lines
Quoted 7 lines
Reviewed-by Kees Cook <[email protected]>(I have some thoughts on refactoring the slot assignment, but that should happen after this series -- it's nothing more than a storage optimization.)
-Kees
haha so do I, now I am curious as to how close they align
Plan A: Each LSM has a lsm_id {.name, .slot}, the address of which is passed to security_add_hooks() in place of the current char *lsm. This is added to each hook instead of the *lsm. The slot value is set if the LSM requests one. One slot integer per LSM instead of one per hook.
Quoted 128 lines
Quoted 128 lines
Quoted 128 lines
--- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/lsm.c | 8 ++++++-- security/security.c | 9 +++++++-- security/selinux/hooks.c | 5 ++++- security/smack/smack_lsm.c | 5 ++++- 5 files changed, 23 insertions(+), 8 deletions(-)include/linux/lsm_hooks.h +2
-2@@ -2068,8 +2068,8 @@ struct lsm_blob_sizes {extern struct security_hook_heads security_hook_heads;extern char *lsm_names; -extern void security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm); +extern int security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm);#define LSM_FLAG_LEGACY_MAJOR BIT(0)#define LSM_FLAG_EXCLUSIVE BIT(1)security/apparmor/lsm.c +6
-2@@ -47,6 +47,9 @@/* Flag indicating whether initialization completed */ int apparmor_initialized; +/* Slot for the AppArmor secid in the lsmblob structure */ +int apparmor_lsmblob_slot; + DEFINE_PER_CPU(struct aa_buffers, aa_buffers);@@ -1678,8 +1681,9 @@ static int __init apparmor_init(void)aa_free_root_ns (); goto buffers_out; } -security_add_hooks (apparmor_hooks,ARRAY_SIZE (apparmor_hooks), -"apparmor" ); + apparmor_lsmblob_slot =security_add_hooks (apparmor_hooks, +ARRAY_SIZE (apparmor_hooks), +"apparmor" );/* Report that AppArmor successfully initialized */ apparmor_initialized =1 ;security/security.c +7
-2@@ -437,9 +437,12 @@ static int lsm_slot __initdata;* Each LSM has to register its hooks with the infrastructure. * If the LSM is using hooks that export secids allocate a slot * for it in the lsmblob. +* +* Returns the slot number in the lsmblob structure if one is +* allocated or LSMBLOB_INVALID if one was not allocated. */ -void __init security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm) +int __init security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm) {int slot =LSMBLOB_INVALID ;int i;@@ -479,6 +482,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, }if (lsm_append (lsm, &lsm_names) <0 )panic ("%s - Cannot get early memory.\n" , __func__); + +return slot; }int call_lsm_notifier (enum lsm_event event,void *data)security/selinux/hooks.c +4
-1@@ -103,6 +103,7 @@#include "avc_ss.h" struct selinux_state selinux_state; +int selinux_lsmblob_slot;/* SECMARK reference count */ static atomic_t selinux_secmark_refcount =ATOMIC_INIT (0 );@@ -6877,7 +6878,9 @@ static __init int selinux_init(void)hashtab_cache_init (); -security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks),"selinux" ); + selinux_lsmblob_slot =security_add_hooks (selinux_hooks, +ARRAY_SIZE (selinux_hooks), +"selinux" );if (avc_add_callback (selinux_netcache_avc_callback,AVC_CALLBACK_RESET ))panic ("SELinux: Unable to register AVC netcache callback\n" );security/smack/smack_lsm.c +4
-1@@ -60,6 +60,7 @@ static LIST_HEAD(smk_ipv6_port_list);#endif static struct kmem_cache *smack_inode_cache;int smack_enabled; +int smack_lsmblob_slot;#define A (s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s} static struct {@@ -4749,7 +4750,9 @@ static __init int smack_init(void)/* * Register with LSM */ -security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks),"smack" ); + smack_lsmblob_slot =security_add_hooks (smack_hooks, +ARRAY_SIZE (smack_hooks), +"smack" ); smack_enabled =1 ;pr_info ("Smack: Initializing.\n" );Signature · 1 line
2.20.1
John Johansen
maintainerPATCH v3 22/24 LSM: Return the lsmblob slot on initialization
In reply to Casey SchauflerQuoted 5 lines · Casey Schaufler
Return the slot allocated to the calling LSM in the lsmblob structure. This can be used to set lsmblobs explicitly for netlabel interfaces.
Signed-off-by Casey Schaufler <[email protected]>
Quoted 124 lines
--- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/lsm.c | 8 ++++++-- security/security.c | 9 +++++++-- security/selinux/hooks.c | 5 ++++- security/smack/smack_lsm.c | 5 ++++- 5 files changed, 23 insertions(+), 8 deletions(-)include/linux/lsm_hooks.h +2
-2@@ -2068,8 +2068,8 @@ struct lsm_blob_sizes {extern struct security_hook_heads security_hook_heads;extern char *lsm_names; -extern void security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm); +extern int security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm);#define LSM_FLAG_LEGACY_MAJOR BIT(0)#define LSM_FLAG_EXCLUSIVE BIT(1)security/apparmor/lsm.c +6
-2@@ -47,6 +47,9 @@/* Flag indicating whether initialization completed */ int apparmor_initialized; +/* Slot for the AppArmor secid in the lsmblob structure */ +int apparmor_lsmblob_slot; + DEFINE_PER_CPU(struct aa_buffers, aa_buffers);@@ -1678,8 +1681,9 @@ static int __init apparmor_init(void)aa_free_root_ns (); goto buffers_out; } -security_add_hooks (apparmor_hooks,ARRAY_SIZE (apparmor_hooks), -"apparmor" ); + apparmor_lsmblob_slot =security_add_hooks (apparmor_hooks, +ARRAY_SIZE (apparmor_hooks), +"apparmor" );/* Report that AppArmor successfully initialized */ apparmor_initialized =1 ;security/security.c +7
-2@@ -437,9 +437,12 @@ static int lsm_slot __initdata;* Each LSM has to register its hooks with the infrastructure. * If the LSM is using hooks that export secids allocate a slot * for it in the lsmblob. +* +* Returns the slot number in the lsmblob structure if one is +* allocated or LSMBLOB_INVALID if one was not allocated. */ -void __init security_add_hooks (struct security_hook_list *hooks,int count, -char *lsm) +int __init security_add_hooks (struct security_hook_list *hooks,int count, +char *lsm) {int slot =LSMBLOB_INVALID ;int i;@@ -479,6 +482,8 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, }if (lsm_append (lsm, &lsm_names) <0 )panic ("%s - Cannot get early memory.\n" , __func__); + +return slot; }int call_lsm_notifier (enum lsm_event event,void *data)security/selinux/hooks.c +4
-1@@ -103,6 +103,7 @@#include "avc_ss.h" struct selinux_state selinux_state; +int selinux_lsmblob_slot;/* SECMARK reference count */ static atomic_t selinux_secmark_refcount =ATOMIC_INIT (0 );@@ -6877,7 +6878,9 @@ static __init int selinux_init(void)hashtab_cache_init (); -security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks),"selinux" ); + selinux_lsmblob_slot =security_add_hooks (selinux_hooks, +ARRAY_SIZE (selinux_hooks), +"selinux" );if (avc_add_callback (selinux_netcache_avc_callback,AVC_CALLBACK_RESET ))panic ("SELinux: Unable to register AVC netcache callback\n" );security/smack/smack_lsm.c +4
-1@@ -60,6 +60,7 @@ static LIST_HEAD(smk_ipv6_port_list);#endif static struct kmem_cache *smack_inode_cache;int smack_enabled; +int smack_lsmblob_slot;#define A (s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s} static struct {@@ -4749,7 +4750,9 @@ static __init int smack_init(void)/* * Register with LSM */ -security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks),"smack" ); + smack_lsmblob_slot =security_add_hooks (smack_hooks, +ARRAY_SIZE (smack_hooks), +"smack" ); smack_enabled =1 ;pr_info ("Smack: Initializing.\n" );
Casey Schaufler
maintainerPATCH v3 23/24 NET: Store LSM netlabel data in a lsmblob
In reply to Casey SchauflerNetlabel uses LSM interfaces requiring an lsmblob and the internal storage is used to pass information between these interfaces, so change the internal data from a secid to a lsmblob. Update the netlabel interfaces and their callers to accomodate the change.
--- include/net/netlabel.h | 8 ++-- net/ipv4/cipso_ipv4.c | 6 ++- net/netlabel/netlabel_kapi.c | 6 +-- net/netlabel/netlabel_unlabeled.c | 57 +++++++++++------------------ net/netlabel/netlabel_unlabeled.h | 2 +- security/selinux/include/security.h | 1 + security/selinux/netlabel.c | 2 +- security/selinux/ss/services.c | 4 +- security/smack/smack.h | 1 + security/smack/smack_lsm.c | 3 +- security/smack/smackfs.c | 10 +++-- 11 files changed, 48 insertions(+), 52 deletions(-)
include/net/netlabel.h +4 -4
@@ -180,7 +180,7 @@ struct netlbl_lsm_catmap {* @attr.mls: MLS sensitivity label * @attr.mls.cat: MLS category bitmap * @attr.mls.lvl: MLS sensitivity level -* @attr.secid: LSM specific secid token +* @attr.lsmblob: LSM specific data * * Description: * This structure is used to pass security attributes between NetLabel and the
@@ -215,7 +215,7 @@ struct netlbl_lsm_secattr {struct netlbl_lsm_catmap *cat;u32 lvl; } mls; -u32 secid; +struct lsmblob lsmblob; } attr; };
@@ -429,7 +429,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info); int netlbl_cfg_unlbl_static_del(struct net *net, const char *dev_name,
@@ -537,7 +537,7 @@ static inline int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { return -ENOSYS;
net/ipv4/cipso_ipv4.c +4 -2
@@ -1481,7 +1481,8 @@ static int cipso_v4_gentag_loc(const struct cipso_v4_doi *doi_def, buffer[0 ] =CIPSO_V4_TAG_LOCAL ; buffer[1 ] =CIPSO_V4_TAG_LOC_BLEN ; - *(u32 *)&buffer[2 ] = secattr->attr.secid; +/* only one netlabel user - the first */ + *(u32 *)&buffer[2 ] = secattr->attr.lsmblob.secid[0 ];return CIPSO_V4_TAG_LOC_BLEN ; }
@@ -1501,7 +1502,8 @@ static int cipso_v4_parsetag_loc(const struct cipso_v4_doi *doi_def,const unsigned char *tag, struct netlbl_lsm_secattr *secattr) { - secattr->attr.secid = *(u32 *)&tag[2]; +/* only one netlabel user - the first */ + secattr->attr.lsmblob.secid[0] = *(u32 *)&tag[2]; secattr->flags |=NETLBL_SECATTR_SECID ;return 0 ;
net/netlabel/netlabel_kapi.c +3 -3
@@ -210,7 +210,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain,* @addr: IP address in network byte order (struct in[6]_addr) * @mask: address mask in network byte order (struct in[6]_addr) * @family: address family -* @secid: LSM secid value for the entry +* @lsmblob: LSM data value for the entry * @audit_info: NetLabel audit information * * Description:
@@ -224,7 +224,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { u32 addr_len;
@@ -244,7 +244,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,return netlbl_unlhsh_add (net, dev_name, addr, mask, addr_len, - secid, audit_info); + lsmblob, audit_info); }/**
net/netlabel/netlabel_unlabeled.c +22 -35
207 lines not on this page · raw message
net/netlabel/netlabel_unlabeled.h +1 -1
@@ -225,7 +225,7 @@ int netlbl_unlhsh_add(struct net *net,const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info); int netlbl_unlhsh_remove(struct net *net, const char *dev_name,
security/selinux/include/security.h +1 -0
@@ -68,6 +68,7 @@struct netlbl_lsm_secattr ;extern int selinux_enabled; +extern int selinux_lsmblob_slot;/* Policy capabilities */ enum {
security/selinux/netlabel.c +1 -1
@@ -122,7 +122,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr(return NULL ;if ((secattr->flags &NETLBL_SECATTR_SECID ) && - (secattr->attr.secid == sid)) + (secattr->attr.lsmblob.secid[selinux_lsmblob_slot] == sid))return secattr;return NULL ;
security/selinux/ss/services.c +2 -2
@@ -3593,7 +3593,7 @@ int security_netlbl_secattr_to_sid(struct selinux_state *state,if (secattr->flags &NETLBL_SECATTR_CACHE ) *sid = *(u32 *)secattr->cache->data;else if (secattr->flags &NETLBL_SECATTR_SECID ) - *sid = secattr->attr.secid; + *sid = secattr->attr.lsmblob.secid[selinux_lsmblob_slot];else if (secattr->flags &NETLBL_SECATTR_MLS_LVL ) { rc = -EIDRM ; ctx =sidtab_search (sidtab,SECINITSID_NETMSG );
@@ -3666,7 +3666,7 @@ int security_netlbl_sid_to_secattr(struct selinux_state *state,if (secattr->domain ==NULL ) goto out; - secattr->attr.secid = sid; + secattr->attr.lsmblob.secid[selinux_lsmblob_slot] = sid; secattr->flags |=NETLBL_SECATTR_DOMAIN_CPY |NETLBL_SECATTR_SECID ;mls_export_netlbl_lvl (policydb, ctx, secattr); rc =mls_export_netlbl_cat (policydb, ctx, secattr);
security/smack/smack.h +1 -0
@@ -320,6 +320,7 @@ void smk_destroy_label_list(struct list_head *list);* Shared data. */ extern int smack_enabled; +extern int smack_lsmblob_slot;extern int smack_cipso_direct;extern int smack_cipso_mapped;extern struct smack_known *smack_net_ambient;
security/smack/smack_lsm.c +2 -1
@@ -3742,7 +3742,8 @@ static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,/* * Looks like a fallback, which gives us a secid. */ -return smack_from_secid (sap->attr.secid); +return smack_from_secid ( + sap->attr.lsmblob.secid[smack_lsmblob_slot]);/* * Without guidance regarding the smack value * for the packet fall back on the network
security/smack/smackfs.c +7 -3
@@ -1150,6 +1150,7 @@ static void smk_net4addr_insert(struct smk_net4addr *new)static ssize_t smk_write_net4addr (struct file *file,const char __user *buf,size_t count,loff_t *ppos) { +struct lsmblob lsmblob;struct smk_net4addr *snp;struct sockaddr_in newname;char *smack;
@@ -1281,10 +1282,13 @@ static ssize_t smk_write_net4addr(struct file *file, const char __user *buf,* this host so that incoming packets get labeled. * but only if we didn't get the special CIPSO option */ -if (rc ==0 && skp !=NULL ) +if (rc ==0 && skp !=NULL ) { +lsmblob_init (&lsmblob,0 ); + lsmblob.secid[smack_lsmblob_slot] = snp->smk_label->smk_secid; rc =netlbl_cfg_unlbl_static_add (&init_net,NULL , - &snp->smk_host, &snp->smk_mask,PF_INET , - snp->smk_label->smk_secid, &audit_info); + &snp->smk_host, &snp->smk_mask,PF_INET , &lsmblob, + &audit_info); + }if (rc ==0 ) rc = count;
Signature · 1 line
2.20.1
Re: [PATCH v3 23/24] NET: Store LSM netlabel data in a lsmblob
Quoted 7 lines · Casey Schaufler
Netlabel uses LSM interfaces requiring an lsmblob and the internal storage is used to pass information between these interfaces, so change the internal data from a secid to a lsmblob. Update the netlabel interfaces and their callers to accomodate the change.
Signed-off-by Casey Schaufler <[email protected]>
-Kees
Quoted 462 lines
--- include/net/netlabel.h | 8 ++-- net/ipv4/cipso_ipv4.c | 6 ++- net/netlabel/netlabel_kapi.c | 6 +-- net/netlabel/netlabel_unlabeled.c | 57 +++++++++++------------------ net/netlabel/netlabel_unlabeled.h | 2 +- security/selinux/include/security.h | 1 + security/selinux/netlabel.c | 2 +- security/selinux/ss/services.c | 4 +- security/smack/smack.h | 1 + security/smack/smack_lsm.c | 3 +- security/smack/smackfs.c | 10 +++-- 11 files changed, 48 insertions(+), 52 deletions(-)include/net/netlabel.h +4
-4@@ -180,7 +180,7 @@ struct netlbl_lsm_catmap {* @attr.mls: MLS sensitivity label * @attr.mls.cat: MLS category bitmap * @attr.mls.lvl: MLS sensitivity level -* @attr.secid: LSM specific secid token +* @attr.lsmblob: LSM specific data * * Description: * This structure is used to pass security attributes between NetLabel and the @@ -215,7 +215,7 @@ struct netlbl_lsm_secattr {struct netlbl_lsm_catmap *cat;u32 lvl; } mls; -u32 secid; +struct lsmblob lsmblob; } attr; };@@ -429,7 +429,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info); int netlbl_cfg_unlbl_static_del(struct net *net, const char *dev_name,@@ -537,7 +537,7 @@ static inline int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { return -ENOSYS;net/ipv4/cipso_ipv4.c +4
-2@@ -1481,7 +1481,8 @@ static int cipso_v4_gentag_loc(const struct cipso_v4_doi *doi_def, buffer[0 ] =CIPSO_V4_TAG_LOCAL ; buffer[1 ] =CIPSO_V4_TAG_LOC_BLEN ; - *(u32 *)&buffer[2 ] = secattr->attr.secid; +/* only one netlabel user - the first */ + *(u32 *)&buffer[2 ] = secattr->attr.lsmblob.secid[0 ];return CIPSO_V4_TAG_LOC_BLEN ; }@@ -1501,7 +1502,8 @@ static int cipso_v4_parsetag_loc(const struct cipso_v4_doi *doi_def,const unsigned char *tag, struct netlbl_lsm_secattr *secattr) { - secattr->attr.secid = *(u32 *)&tag[2]; +/* only one netlabel user - the first */ + secattr->attr.lsmblob.secid[0] = *(u32 *)&tag[2]; secattr->flags |=NETLBL_SECATTR_SECID ;return 0 ;net/netlabel/netlabel_kapi.c +3
-3@@ -210,7 +210,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain,* @addr: IP address in network byte order (struct in[6]_addr) * @mask: address mask in network byte order (struct in[6]_addr) * @family: address family -* @secid: LSM secid value for the entry +* @lsmblob: LSM data value for the entry * @audit_info: NetLabel audit information * * Description: @@ -224,7 +224,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { u32 addr_len;@@ -244,7 +244,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,return netlbl_unlhsh_add (net, dev_name, addr, mask, addr_len, - secid, audit_info); + lsmblob, audit_info); }/** net/netlabel/netlabel_unlabeled.c +22
-35@@ -80,7 +80,7 @@ struct netlbl_unlhsh_tbl {#define netlbl_unlhsh_addr4_entry (iter) \ container_of(iter, struct netlbl_unlhsh_addr4, list)struct netlbl_unlhsh_addr4 { -u32 secid; +struct lsmblob lsmblob;struct netlbl_af4list list;struct rcu_head rcu;@@ -88,7 +88,7 @@ struct netlbl_unlhsh_addr4 {#define netlbl_unlhsh_addr6_entry (iter) \ container_of(iter, struct netlbl_unlhsh_addr6, list)struct netlbl_unlhsh_addr6 { -u32 secid; +struct lsmblob lsmblob;struct netlbl_af6list list;struct rcu_head rcu;@@ -233,7 +233,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)* @iface: the associated interface entry * @addr: IPv4 address in network byte order * @mask: IPv4 address mask in network byte order -* @secid: LSM secid value for entry +* @lsmblob: LSM data value for entry * * Description: * Add a new address entry into the unlabeled connection hash table using the @@ -244,7 +244,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)static int netlbl_unlhsh_add_addr4 (struct netlbl_unlhsh_iface *iface,const struct in_addr *addr,const struct in_addr *mask, -u32 secid) +struct lsmblob *lsmblob) {int ret_val;struct netlbl_unlhsh_addr4 *entry;@@ -256,7 +256,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, entry->list.addr = addr->s_addr & mask->s_addr; entry->list.mask = mask->s_addr; entry->list.valid =1 ; - entry->secid = secid; + entry->lsmblob = *lsmblob;spin_lock (&netlbl_unlhsh_lock); ret_val =netlbl_af4list_add (&entry->list, &iface->addr4_list);@@ -273,7 +273,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,* @iface: the associated interface entry * @addr: IPv6 address in network byte order * @mask: IPv6 address mask in network byte order -* @secid: LSM secid value for entry +* @lsmblob: LSM data value for entry * * Description: * Add a new address entry into the unlabeled connection hash table using the @@ -284,7 +284,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,static int netlbl_unlhsh_add_addr6 (struct netlbl_unlhsh_iface *iface,const struct in6_addr *addr,const struct in6_addr *mask, -u32 secid) +struct lsmblob *lsmblob) {int ret_val;struct netlbl_unlhsh_addr6 *entry;@@ -300,7 +300,7 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, entry->list.addr.s6_addr32[3 ] &= mask->s6_addr32[3 ]; entry->list.mask = *mask; entry->list.valid =1 ; - entry->secid = secid; + entry->lsmblob = *lsmblob;spin_lock (&netlbl_unlhsh_lock); ret_val =netlbl_af6list_add (&entry->list, &iface->addr6_list);@@ -379,7 +379,7 @@ int netlbl_unlhsh_add(struct net *net,const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { int ret_val;@@ -388,7 +388,6 @@ int netlbl_unlhsh_add(struct net *net,struct netlbl_unlhsh_iface *iface;struct audit_buffer *audit_buf =NULL ;struct lsmcontext context; -struct lsmblob blob;if (addr_len !=sizeof (struct in_addr ) && addr_len !=sizeof (struct in6_addr ))@@ -421,7 +420,7 @@ int netlbl_unlhsh_add(struct net *net,const struct in_addr *addr4 = addr;const struct in_addr *mask4 = mask; - ret_val =netlbl_unlhsh_add_addr4 (iface, addr4, mask4, secid); + ret_val =netlbl_unlhsh_add_addr4 (iface, addr4, mask4, lsmblob);if (audit_buf !=NULL ) netlbl_af4list_audit_addr(audit_buf, 1, dev_name,@@ -434,7 +433,7 @@ int netlbl_unlhsh_add(struct net *net,const struct in6_addr *addr6 = addr;const struct in6_addr *mask6 = mask; - ret_val =netlbl_unlhsh_add_addr6 (iface, addr6, mask6, secid); + ret_val =netlbl_unlhsh_add_addr6 (iface, addr6, mask6, lsmblob);if (audit_buf !=NULL ) netlbl_af6list_audit_addr(audit_buf, 1, dev_name,@@ -451,8 +450,7 @@ int netlbl_unlhsh_add(struct net *net, unlhsh_add_return:rcu_read_unlock ();if (audit_buf !=NULL ) { -lsmblob_init (&blob, secid); -if (security_secid_to_secctx (&blob, &context) ==0 ) { +if (security_secid_to_secctx (lsmblob, &context) ==0 ) {audit_log_format (audit_buf," sec_obj=%s" , context.context);security_release_secctx (&context);@@ -487,7 +485,6 @@ static int netlbl_unlhsh_remove_addr4(struct net *net,struct audit_buffer *audit_buf;struct net_device *dev;struct lsmcontext context; -struct lsmblob blob;spin_lock (&netlbl_unlhsh_lock); list_entry = netlbl_af4list_remove(addr->s_addr, mask->s_addr,@@ -507,10 +504,8 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, addr->s_addr, mask->s_addr);if (dev !=NULL )dev_put (dev); -if (entry !=NULL ) -lsmblob_init (&blob, entry->secid);if (entry !=NULL && -security_secid_to_secctx (&blob, &context) ==0 ) { +security_secid_to_secctx (&entry->lsmblob, &context) ==0 ) {audit_log_format (audit_buf," sec_obj=%s" , context.context);security_release_secctx (&context);@@ -551,7 +546,6 @@ static int netlbl_unlhsh_remove_addr6(struct net *net,struct audit_buffer *audit_buf;struct net_device *dev;struct lsmcontext context; -struct lsmblob blob;spin_lock (&netlbl_unlhsh_lock); list_entry =netlbl_af6list_remove (addr, mask, &iface->addr6_list);@@ -570,10 +564,8 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, addr, mask);if (dev !=NULL )dev_put (dev); -if (entry !=NULL ) -lsmblob_init (&blob, entry->secid);if (entry !=NULL && -security_secid_to_secctx (&blob, &context) ==0 ) { +security_secid_to_secctx (&entry->lsmblob, &context) ==0 ) {audit_log_format (audit_buf," sec_obj=%s" , context.context);security_release_secctx (&context);@@ -927,9 +919,8 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb,if (ret_val !=0 )return ret_val; -/* scaffolding with the [0] */ return netlbl_unlhsh_add (&init_net, - dev_name, addr, mask, addr_len, blob.secid[0 ], + dev_name, addr, mask, addr_len, &blob, &audit_info); }@@ -977,10 +968,8 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb,if (ret_val !=0 )return ret_val; -/* scaffolding with the [0] */ return netlbl_unlhsh_add (&init_net, -NULL , addr, mask, addr_len, blob.secid[0 ], - &audit_info); +NULL , addr, mask, addr_len, &blob, &audit_info); }/** @@ -1092,8 +1081,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,struct net_device *dev;struct lsmcontext context;void *data; -u32 secid; -struct lsmblob blob; +struct lsmblob *lsmb; data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, cb_arg->seq, &netlbl_unlabel_gnl_family,@@ -1131,7 +1119,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,if (ret_val !=0 ) goto list_cb_failure; - secid = addr4->secid; + lsmb = (struct lsmblob *)&addr4->lsmblob; }else { ret_val = nla_put_in6_addr(cb_arg->skb, NLBL_UNLABEL_A_IPV6ADDR,@@ -1145,11 +1133,10 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,if (ret_val !=0 ) goto list_cb_failure; - secid = addr6->secid; + lsmb = (struct lsmblob *)&addr6->lsmblob; } -lsmblob_init (&blob, secid); - ret_val =security_secid_to_secctx (&blob, &context); + ret_val =security_secid_to_secctx (lsmb, &context);if (ret_val !=0 ) goto list_cb_failure; ret_val = nla_put(cb_arg->skb,@@ -1500,7 +1487,7 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb, &iface->addr4_list);if (addr4 ==NULL ) goto unlabel_getattr_nolabel; - secattr->attr.secid =netlbl_unlhsh_addr4_entry (addr4)->secid; + secattr->attr.lsmblob =netlbl_unlhsh_addr4_entry (addr4)->lsmblob;break ; }#if IS_ENABLED (CONFIG_IPV6 )@@ -1513,7 +1500,7 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb, &iface->addr6_list);if (addr6 ==NULL ) goto unlabel_getattr_nolabel; - secattr->attr.secid =netlbl_unlhsh_addr6_entry (addr6)->secid; + secattr->attr.lsmblob =netlbl_unlhsh_addr6_entry (addr6)->lsmblob; break; }#endif /* IPv6 */ net/netlabel/netlabel_unlabeled.h +1
-1@@ -225,7 +225,7 @@ int netlbl_unlhsh_add(struct net *net,const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info); int netlbl_unlhsh_remove(struct net *net, const char *dev_name,security/selinux/include/security.h +1
-0@@ -68,6 +68,7 @@struct netlbl_lsm_secattr ;extern int selinux_enabled; +extern int selinux_lsmblob_slot;/* Policy capabilities */ enum {security/selinux/netlabel.c +1
-1@@ -122,7 +122,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr(return NULL ;if ((secattr->flags &NETLBL_SECATTR_SECID ) && - (secattr->attr.secid == sid)) + (secattr->attr.lsmblob.secid[selinux_lsmblob_slot] == sid))return secattr;return NULL ;security/selinux/ss/services.c +2
-2@@ -3593,7 +3593,7 @@ int security_netlbl_secattr_to_sid(struct selinux_state *state,if (secattr->flags &NETLBL_SECATTR_CACHE ) *sid = *(u32 *)secattr->cache->data;else if (secattr->flags &NETLBL_SECATTR_SECID ) - *sid = secattr->attr.secid; + *sid = secattr->attr.lsmblob.secid[selinux_lsmblob_slot];else if (secattr->flags &NETLBL_SECATTR_MLS_LVL ) { rc = -EIDRM ; ctx =sidtab_search (sidtab,SECINITSID_NETMSG );@@ -3666,7 +3666,7 @@ int security_netlbl_sid_to_secattr(struct selinux_state *state,if (secattr->domain ==NULL ) goto out; - secattr->attr.secid = sid; + secattr->attr.lsmblob.secid[selinux_lsmblob_slot] = sid; secattr->flags |=NETLBL_SECATTR_DOMAIN_CPY |NETLBL_SECATTR_SECID ;mls_export_netlbl_lvl (policydb, ctx, secattr); rc =mls_export_netlbl_cat (policydb, ctx, secattr);security/smack/smack.h +1
-0@@ -320,6 +320,7 @@ void smk_destroy_label_list(struct list_head *list);* Shared data. */ extern int smack_enabled; +extern int smack_lsmblob_slot;extern int smack_cipso_direct;extern int smack_cipso_mapped;extern struct smack_known *smack_net_ambient;security/smack/smack_lsm.c +2
-1@@ -3742,7 +3742,8 @@ static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,/* * Looks like a fallback, which gives us a secid. */ -return smack_from_secid (sap->attr.secid); +return smack_from_secid ( + sap->attr.lsmblob.secid[smack_lsmblob_slot]);/* * Without guidance regarding the smack value * for the packet fall back on the network security/smack/smackfs.c +7
-3@@ -1150,6 +1150,7 @@ static void smk_net4addr_insert(struct smk_net4addr *new)static ssize_t smk_write_net4addr (struct file *file,const char __user *buf,size_t count,loff_t *ppos) { +struct lsmblob lsmblob;struct smk_net4addr *snp;struct sockaddr_in newname;char *smack;@@ -1281,10 +1282,13 @@ static ssize_t smk_write_net4addr(struct file *file, const char __user *buf,* this host so that incoming packets get labeled. * but only if we didn't get the special CIPSO option */ -if (rc ==0 && skp !=NULL ) +if (rc ==0 && skp !=NULL ) { +lsmblob_init (&lsmblob,0 ); + lsmblob.secid[smack_lsmblob_slot] = snp->smk_label->smk_secid; rc =netlbl_cfg_unlbl_static_add (&init_net,NULL , - &snp->smk_host, &snp->smk_mask,PF_INET , - snp->smk_label->smk_secid, &audit_info); + &snp->smk_host, &snp->smk_mask,PF_INET , &lsmblob, + &audit_info); + }if (rc ==0 ) rc = count;Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
Re: [PATCH v3 23/24] NET: Store LSM netlabel data in a lsmblob
In reply to Casey SchauflerQuoted 7 lines · Casey Schaufler
Netlabel uses LSM interfaces requiring an lsmblob and the internal storage is used to pass information between these interfaces, so change the internal data from a secid to a lsmblob. Update the netlabel interfaces and their callers to accomodate the change.
Signed-off-by Casey Schaufler <[email protected]>
Quoted 460 lines
--- include/net/netlabel.h | 8 ++-- net/ipv4/cipso_ipv4.c | 6 ++- net/netlabel/netlabel_kapi.c | 6 +-- net/netlabel/netlabel_unlabeled.c | 57 +++++++++++------------------ net/netlabel/netlabel_unlabeled.h | 2 +- security/selinux/include/security.h | 1 + security/selinux/netlabel.c | 2 +- security/selinux/ss/services.c | 4 +- security/smack/smack.h | 1 + security/smack/smack_lsm.c | 3 +- security/smack/smackfs.c | 10 +++-- 11 files changed, 48 insertions(+), 52 deletions(-)include/net/netlabel.h +4
-4@@ -180,7 +180,7 @@ struct netlbl_lsm_catmap {* @attr.mls: MLS sensitivity label * @attr.mls.cat: MLS category bitmap * @attr.mls.lvl: MLS sensitivity level -* @attr.secid: LSM specific secid token +* @attr.lsmblob: LSM specific data * * Description: * This structure is used to pass security attributes between NetLabel and the @@ -215,7 +215,7 @@ struct netlbl_lsm_secattr {struct netlbl_lsm_catmap *cat;u32 lvl; } mls; -u32 secid; +struct lsmblob lsmblob; } attr; };@@ -429,7 +429,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info); int netlbl_cfg_unlbl_static_del(struct net *net, const char *dev_name,@@ -537,7 +537,7 @@ static inline int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { return -ENOSYS;net/ipv4/cipso_ipv4.c +4
-2@@ -1481,7 +1481,8 @@ static int cipso_v4_gentag_loc(const struct cipso_v4_doi *doi_def, buffer[0 ] =CIPSO_V4_TAG_LOCAL ; buffer[1 ] =CIPSO_V4_TAG_LOC_BLEN ; - *(u32 *)&buffer[2 ] = secattr->attr.secid; +/* only one netlabel user - the first */ + *(u32 *)&buffer[2 ] = secattr->attr.lsmblob.secid[0 ];return CIPSO_V4_TAG_LOC_BLEN ; }@@ -1501,7 +1502,8 @@ static int cipso_v4_parsetag_loc(const struct cipso_v4_doi *doi_def,const unsigned char *tag, struct netlbl_lsm_secattr *secattr) { - secattr->attr.secid = *(u32 *)&tag[2]; +/* only one netlabel user - the first */ + secattr->attr.lsmblob.secid[0] = *(u32 *)&tag[2]; secattr->flags |=NETLBL_SECATTR_SECID ;return 0 ;net/netlabel/netlabel_kapi.c +3
-3@@ -210,7 +210,7 @@ int netlbl_cfg_unlbl_map_add(const char *domain,* @addr: IP address in network byte order (struct in[6]_addr) * @mask: address mask in network byte order (struct in[6]_addr) * @family: address family -* @secid: LSM secid value for the entry +* @lsmblob: LSM data value for the entry * @audit_info: NetLabel audit information * * Description: @@ -224,7 +224,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,const void *addr, const void *mask, u16 family, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { u32 addr_len;@@ -244,7 +244,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net,return netlbl_unlhsh_add (net, dev_name, addr, mask, addr_len, - secid, audit_info); + lsmblob, audit_info); }/** net/netlabel/netlabel_unlabeled.c +22
-35@@ -80,7 +80,7 @@ struct netlbl_unlhsh_tbl {#define netlbl_unlhsh_addr4_entry (iter) \ container_of(iter, struct netlbl_unlhsh_addr4, list)struct netlbl_unlhsh_addr4 { -u32 secid; +struct lsmblob lsmblob;struct netlbl_af4list list;struct rcu_head rcu;@@ -88,7 +88,7 @@ struct netlbl_unlhsh_addr4 {#define netlbl_unlhsh_addr6_entry (iter) \ container_of(iter, struct netlbl_unlhsh_addr6, list)struct netlbl_unlhsh_addr6 { -u32 secid; +struct lsmblob lsmblob;struct netlbl_af6list list;struct rcu_head rcu;@@ -233,7 +233,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)* @iface: the associated interface entry * @addr: IPv4 address in network byte order * @mask: IPv4 address mask in network byte order -* @secid: LSM secid value for entry +* @lsmblob: LSM data value for entry * * Description: * Add a new address entry into the unlabeled connection hash table using the @@ -244,7 +244,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex)static int netlbl_unlhsh_add_addr4 (struct netlbl_unlhsh_iface *iface,const struct in_addr *addr,const struct in_addr *mask, -u32 secid) +struct lsmblob *lsmblob) {int ret_val;struct netlbl_unlhsh_addr4 *entry;@@ -256,7 +256,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, entry->list.addr = addr->s_addr & mask->s_addr; entry->list.mask = mask->s_addr; entry->list.valid =1 ; - entry->secid = secid; + entry->lsmblob = *lsmblob;spin_lock (&netlbl_unlhsh_lock); ret_val =netlbl_af4list_add (&entry->list, &iface->addr4_list);@@ -273,7 +273,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,* @iface: the associated interface entry * @addr: IPv6 address in network byte order * @mask: IPv6 address mask in network byte order -* @secid: LSM secid value for entry +* @lsmblob: LSM data value for entry * * Description: * Add a new address entry into the unlabeled connection hash table using the @@ -284,7 +284,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface,static int netlbl_unlhsh_add_addr6 (struct netlbl_unlhsh_iface *iface,const struct in6_addr *addr,const struct in6_addr *mask, -u32 secid) +struct lsmblob *lsmblob) {int ret_val;struct netlbl_unlhsh_addr6 *entry;@@ -300,7 +300,7 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, entry->list.addr.s6_addr32[3 ] &= mask->s6_addr32[3 ]; entry->list.mask = *mask; entry->list.valid =1 ; - entry->secid = secid; + entry->lsmblob = *lsmblob;spin_lock (&netlbl_unlhsh_lock); ret_val =netlbl_af6list_add (&entry->list, &iface->addr6_list);@@ -379,7 +379,7 @@ int netlbl_unlhsh_add(struct net *net,const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info) { int ret_val;@@ -388,7 +388,6 @@ int netlbl_unlhsh_add(struct net *net,struct netlbl_unlhsh_iface *iface;struct audit_buffer *audit_buf =NULL ;struct lsmcontext context; -struct lsmblob blob;if (addr_len !=sizeof (struct in_addr ) && addr_len !=sizeof (struct in6_addr ))@@ -421,7 +420,7 @@ int netlbl_unlhsh_add(struct net *net,const struct in_addr *addr4 = addr;const struct in_addr *mask4 = mask; - ret_val =netlbl_unlhsh_add_addr4 (iface, addr4, mask4, secid); + ret_val =netlbl_unlhsh_add_addr4 (iface, addr4, mask4, lsmblob);if (audit_buf !=NULL ) netlbl_af4list_audit_addr(audit_buf, 1, dev_name,@@ -434,7 +433,7 @@ int netlbl_unlhsh_add(struct net *net,const struct in6_addr *addr6 = addr;const struct in6_addr *mask6 = mask; - ret_val =netlbl_unlhsh_add_addr6 (iface, addr6, mask6, secid); + ret_val =netlbl_unlhsh_add_addr6 (iface, addr6, mask6, lsmblob);if (audit_buf !=NULL ) netlbl_af6list_audit_addr(audit_buf, 1, dev_name,@@ -451,8 +450,7 @@ int netlbl_unlhsh_add(struct net *net, unlhsh_add_return:rcu_read_unlock ();if (audit_buf !=NULL ) { -lsmblob_init (&blob, secid); -if (security_secid_to_secctx (&blob, &context) ==0 ) { +if (security_secid_to_secctx (lsmblob, &context) ==0 ) {audit_log_format (audit_buf," sec_obj=%s" , context.context);security_release_secctx (&context);@@ -487,7 +485,6 @@ static int netlbl_unlhsh_remove_addr4(struct net *net,struct audit_buffer *audit_buf;struct net_device *dev;struct lsmcontext context; -struct lsmblob blob;spin_lock (&netlbl_unlhsh_lock); list_entry = netlbl_af4list_remove(addr->s_addr, mask->s_addr,@@ -507,10 +504,8 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, addr->s_addr, mask->s_addr);if (dev !=NULL )dev_put (dev); -if (entry !=NULL ) -lsmblob_init (&blob, entry->secid);if (entry !=NULL && -security_secid_to_secctx (&blob, &context) ==0 ) { +security_secid_to_secctx (&entry->lsmblob, &context) ==0 ) {audit_log_format (audit_buf," sec_obj=%s" , context.context);security_release_secctx (&context);@@ -551,7 +546,6 @@ static int netlbl_unlhsh_remove_addr6(struct net *net,struct audit_buffer *audit_buf;struct net_device *dev;struct lsmcontext context; -struct lsmblob blob;spin_lock (&netlbl_unlhsh_lock); list_entry =netlbl_af6list_remove (addr, mask, &iface->addr6_list);@@ -570,10 +564,8 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, addr, mask);if (dev !=NULL )dev_put (dev); -if (entry !=NULL ) -lsmblob_init (&blob, entry->secid);if (entry !=NULL && -security_secid_to_secctx (&blob, &context) ==0 ) { +security_secid_to_secctx (&entry->lsmblob, &context) ==0 ) {audit_log_format (audit_buf," sec_obj=%s" , context.context);security_release_secctx (&context);@@ -927,9 +919,8 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb,if (ret_val !=0 )return ret_val; -/* scaffolding with the [0] */ return netlbl_unlhsh_add (&init_net, - dev_name, addr, mask, addr_len, blob.secid[0 ], + dev_name, addr, mask, addr_len, &blob, &audit_info); }@@ -977,10 +968,8 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb,if (ret_val !=0 )return ret_val; -/* scaffolding with the [0] */ return netlbl_unlhsh_add (&init_net, -NULL , addr, mask, addr_len, blob.secid[0 ], - &audit_info); +NULL , addr, mask, addr_len, &blob, &audit_info); }/** @@ -1092,8 +1081,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,struct net_device *dev;struct lsmcontext context;void *data; -u32 secid; -struct lsmblob blob; +struct lsmblob *lsmb; data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, cb_arg->seq, &netlbl_unlabel_gnl_family,@@ -1131,7 +1119,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,if (ret_val !=0 ) goto list_cb_failure; - secid = addr4->secid; + lsmb = (struct lsmblob *)&addr4->lsmblob; }else { ret_val = nla_put_in6_addr(cb_arg->skb, NLBL_UNLABEL_A_IPV6ADDR,@@ -1145,11 +1133,10 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,if (ret_val !=0 ) goto list_cb_failure; - secid = addr6->secid; + lsmb = (struct lsmblob *)&addr6->lsmblob; } -lsmblob_init (&blob, secid); - ret_val =security_secid_to_secctx (&blob, &context); + ret_val =security_secid_to_secctx (lsmb, &context);if (ret_val !=0 ) goto list_cb_failure; ret_val = nla_put(cb_arg->skb,@@ -1500,7 +1487,7 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb, &iface->addr4_list);if (addr4 ==NULL ) goto unlabel_getattr_nolabel; - secattr->attr.secid =netlbl_unlhsh_addr4_entry (addr4)->secid; + secattr->attr.lsmblob =netlbl_unlhsh_addr4_entry (addr4)->lsmblob;break ; }#if IS_ENABLED (CONFIG_IPV6 )@@ -1513,7 +1500,7 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb, &iface->addr6_list);if (addr6 ==NULL ) goto unlabel_getattr_nolabel; - secattr->attr.secid =netlbl_unlhsh_addr6_entry (addr6)->secid; + secattr->attr.lsmblob =netlbl_unlhsh_addr6_entry (addr6)->lsmblob; break; }#endif /* IPv6 */ net/netlabel/netlabel_unlabeled.h +1
-1@@ -225,7 +225,7 @@ int netlbl_unlhsh_add(struct net *net,const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsmblob *lsmblob, struct netlbl_audit *audit_info); int netlbl_unlhsh_remove(struct net *net, const char *dev_name,security/selinux/include/security.h +1
-0@@ -68,6 +68,7 @@struct netlbl_lsm_secattr ;extern int selinux_enabled; +extern int selinux_lsmblob_slot;/* Policy capabilities */ enum {security/selinux/netlabel.c +1
-1@@ -122,7 +122,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr(return NULL ;if ((secattr->flags &NETLBL_SECATTR_SECID ) && - (secattr->attr.secid == sid)) + (secattr->attr.lsmblob.secid[selinux_lsmblob_slot] == sid))return secattr;return NULL ;security/selinux/ss/services.c +2
-2@@ -3593,7 +3593,7 @@ int security_netlbl_secattr_to_sid(struct selinux_state *state,if (secattr->flags &NETLBL_SECATTR_CACHE ) *sid = *(u32 *)secattr->cache->data;else if (secattr->flags &NETLBL_SECATTR_SECID ) - *sid = secattr->attr.secid; + *sid = secattr->attr.lsmblob.secid[selinux_lsmblob_slot];else if (secattr->flags &NETLBL_SECATTR_MLS_LVL ) { rc = -EIDRM ; ctx =sidtab_search (sidtab,SECINITSID_NETMSG );@@ -3666,7 +3666,7 @@ int security_netlbl_sid_to_secattr(struct selinux_state *state,if (secattr->domain ==NULL ) goto out; - secattr->attr.secid = sid; + secattr->attr.lsmblob.secid[selinux_lsmblob_slot] = sid; secattr->flags |=NETLBL_SECATTR_DOMAIN_CPY |NETLBL_SECATTR_SECID ;mls_export_netlbl_lvl (policydb, ctx, secattr); rc =mls_export_netlbl_cat (policydb, ctx, secattr);security/smack/smack.h +1
-0@@ -320,6 +320,7 @@ void smk_destroy_label_list(struct list_head *list);* Shared data. */ extern int smack_enabled; +extern int smack_lsmblob_slot;extern int smack_cipso_direct;extern int smack_cipso_mapped;extern struct smack_known *smack_net_ambient;security/smack/smack_lsm.c +2
-1@@ -3742,7 +3742,8 @@ static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,/* * Looks like a fallback, which gives us a secid. */ -return smack_from_secid (sap->attr.secid); +return smack_from_secid ( + sap->attr.lsmblob.secid[smack_lsmblob_slot]);/* * Without guidance regarding the smack value * for the packet fall back on the network security/smack/smackfs.c +7
-3@@ -1150,6 +1150,7 @@ static void smk_net4addr_insert(struct smk_net4addr *new)static ssize_t smk_write_net4addr (struct file *file,const char __user *buf,size_t count,loff_t *ppos) { +struct lsmblob lsmblob;struct smk_net4addr *snp;struct sockaddr_in newname;char *smack;@@ -1281,10 +1282,13 @@ static ssize_t smk_write_net4addr(struct file *file, const char __user *buf,* this host so that incoming packets get labeled. * but only if we didn't get the special CIPSO option */ -if (rc ==0 && skp !=NULL ) +if (rc ==0 && skp !=NULL ) { +lsmblob_init (&lsmblob,0 ); + lsmblob.secid[smack_lsmblob_slot] = snp->smk_label->smk_secid; rc =netlbl_cfg_unlbl_static_add (&init_net,NULL , - &snp->smk_host, &snp->smk_mask,PF_INET , - snp->smk_label->smk_secid, &audit_info); + &snp->smk_host, &snp->smk_mask,PF_INET , &lsmblob, + &audit_info); + }if (rc ==0 ) rc = count;
Casey Schaufler
maintainerPATCH v3 24/24 AppArmor: Remove the exclusive flag
In reply to Casey SchauflerWith the inclusion of the "display" process attribute mechanism AppArmor no longer needs to be treated as an "exclusive" security module. Remove the flag that indicates it is exclusive. Remove the stub getpeersec_dgram AppArmor hook as it has no effect in the single LSM case and interferes in the multiple LSM case.
--- security/apparmor/lsm.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
security/apparmor/lsm.c +1 -19
@@ -1082,22 +1082,6 @@ static int apparmor_socket_getpeersec_stream(struct socket *sock,return error; } -/** -* apparmor_socket_getpeersec_dgram - get security label of packet -* @sock: the peer socket -* @skb: packet data -* @secid: pointer to where to put the secid of the packet -* -* Sets the netlabel socket state on sk from parent -*/ -static int apparmor_socket_getpeersec_dgram (struct socket *sock, -struct sk_buff *skb,u32 *secid) - -{ -/* TODO: requires secid support */ -return -ENOPROTOOPT ; -} -/** * apparmor_sock_graft - Initialize newly created socket * @sk: child sock
@@ -1196,8 +1180,6 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {#endif LSM_HOOK_INIT (socket_getpeersec_stream, apparmor_socket_getpeersec_stream), -LSM_HOOK_INIT (socket_getpeersec_dgram, - apparmor_socket_getpeersec_dgram),LSM_HOOK_INIT (sock_graft, apparmor_sock_graft), #ifdef CONFIG_NETWORK_SECMARK LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request),
@@ -1709,7 +1691,7 @@ static int __init apparmor_init(void)DEFINE_LSM (apparmor) = { .name ="apparmor" , - .flags =LSM_FLAG_LEGACY_MAJOR |LSM_FLAG_EXCLUSIVE , + .flags =LSM_FLAG_LEGACY_MAJOR , .enabled = &apparmor_enabled, .blobs = &apparmor_blob_sizes, .init = apparmor_init,
Signature · 1 line
2.20.1
Re: [PATCH v3 24/24] AppArmor: Remove the exclusive flag
Quoted 8 lines · Casey Schaufler
With the inclusion of the "display" process attribute mechanism AppArmor no longer needs to be treated as an "exclusive" security module. Remove the flag that indicates it is exclusive. Remove the stub
getpeersec_dgramAppArmor hook as it has no effect in the single LSM case and interferes in the multiple LSM case.Signed-off-by Casey Schaufler <[email protected]>
-Kees
Quoted 52 lines
--- security/apparmor/lsm.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)security/apparmor/lsm.c +1
-19@@ -1082,22 +1082,6 @@ static int apparmor_socket_getpeersec_stream(struct socket *sock,return error; } -/** -* apparmor_socket_getpeersec_dgram - get security label of packet -* @sock: the peer socket -* @skb: packet data -* @secid: pointer to where to put the secid of the packet -* -* Sets the netlabel socket state on sk from parent -*/ -static int apparmor_socket_getpeersec_dgram (struct socket *sock, -struct sk_buff *skb,u32 *secid) - -{ -/* TODO: requires secid support */ -return -ENOPROTOOPT ; -} -/** * apparmor_sock_graft - Initialize newly created socket * @sk: child sock @@ -1196,8 +1180,6 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {#endif LSM_HOOK_INIT (socket_getpeersec_stream, apparmor_socket_getpeersec_stream), -LSM_HOOK_INIT (socket_getpeersec_dgram, - apparmor_socket_getpeersec_dgram),LSM_HOOK_INIT (sock_graft, apparmor_sock_graft), #ifdef CONFIG_NETWORK_SECMARK LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request),@@ -1709,7 +1691,7 @@ static int __init apparmor_init(void)DEFINE_LSM (apparmor) = { .name ="apparmor" , - .flags =LSM_FLAG_LEGACY_MAJOR |LSM_FLAG_EXCLUSIVE , + .flags =LSM_FLAG_LEGACY_MAJOR , .enabled = &apparmor_enabled, .blobs = &apparmor_blob_sizes, .init = apparmor_init,Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
Re: [PATCH v3 24/24] AppArmor: Remove the exclusive flag
In reply to Casey SchauflerQuoted 8 lines · Casey Schaufler
With the inclusion of the "display" process attribute mechanism AppArmor no longer needs to be treated as an "exclusive" security module. Remove the flag that indicates it is exclusive. Remove the stub
getpeersec_dgramAppArmor hook as it has no effect in the single LSM case and interferes in the multiple LSM case.Signed-off-by Casey Schaufler <[email protected]>
Quoted 50 lines
--- security/apparmor/lsm.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)security/apparmor/lsm.c +1
-19@@ -1082,22 +1082,6 @@ static int apparmor_socket_getpeersec_stream(struct socket *sock,return error; } -/** -* apparmor_socket_getpeersec_dgram - get security label of packet -* @sock: the peer socket -* @skb: packet data -* @secid: pointer to where to put the secid of the packet -* -* Sets the netlabel socket state on sk from parent -*/ -static int apparmor_socket_getpeersec_dgram (struct socket *sock, -struct sk_buff *skb,u32 *secid) - -{ -/* TODO: requires secid support */ -return -ENOPROTOOPT ; -} -/** * apparmor_sock_graft - Initialize newly created socket * @sk: child sock @@ -1196,8 +1180,6 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {#endif LSM_HOOK_INIT (socket_getpeersec_stream, apparmor_socket_getpeersec_stream), -LSM_HOOK_INIT (socket_getpeersec_dgram, - apparmor_socket_getpeersec_dgram),LSM_HOOK_INIT (sock_graft, apparmor_sock_graft), #ifdef CONFIG_NETWORK_SECMARK LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request),@@ -1709,7 +1691,7 @@ static int __init apparmor_init(void)DEFINE_LSM (apparmor) = { .name ="apparmor" , - .flags =LSM_FLAG_LEGACY_MAJOR |LSM_FLAG_EXCLUSIVE , + .flags =LSM_FLAG_LEGACY_MAJOR , .enabled = &apparmor_enabled, .blobs = &apparmor_blob_sizes, .init = apparmor_init,