Skip to content

Commit 7da596e

Browse files
cschauflerAndrea Righi
authored andcommitted
UBUNTU: SAUCE: apparmor4.0.0 [30/76]: Stacking v38: LSM: Use lsmcontext in security_inode_getsecctx
BugLink: https://bugs.launchpad.net/bugs/2028253 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 that security_release_secctx() can use the correct hook. Acked-by: Stephen Smalley <[email protected]> Acked-by: Paul Moore <[email protected]> Acked-by: Chuck Lever <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: John Johansen <[email protected]> Signed-off-by: Casey Schaufler <[email protected]> Cc: [email protected] Signed-off-by: John Johansen <[email protected]> (cherry picked from https://gitlab.com/jjohansen/apparmor-kernel) Signed-off-by: Andrea Righi <[email protected]>
1 parent 313ddd1 commit 7da596e

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,11 +2845,11 @@ nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types)
28452845
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
28462846
static inline __be32
28472847
nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
2848-
void *context, int len)
2848+
struct lsmcontext *context)
28492849
{
28502850
__be32 *p;
28512851

2852-
p = xdr_reserve_space(xdr, len + 4 + 4 + 4);
2852+
p = xdr_reserve_space(xdr, context->len + 4 + 4 + 4);
28532853
if (!p)
28542854
return nfserr_resource;
28552855

@@ -2859,13 +2859,13 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
28592859
*/
28602860
*p++ = cpu_to_be32(0); /* lfs */
28612861
*p++ = cpu_to_be32(0); /* pi */
2862-
p = xdr_encode_opaque(p, context, len);
2862+
p = xdr_encode_opaque(p, context->context, context->len);
28632863
return 0;
28642864
}
28652865
#else
28662866
static inline __be32
28672867
nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
2868-
void *context, int len)
2868+
struct lsmcontext *context)
28692869
{ return 0; }
28702870
#endif
28712871

@@ -2964,9 +2964,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
29642964
int err;
29652965
struct nfs4_acl *acl = NULL;
29662966
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2967-
struct lsmcontext scaff; /* scaffolding */
2968-
void *context = NULL;
2969-
int contextlen;
2967+
struct lsmcontext context = { };
29702968
#endif
29712969
bool contextsupport = false;
29722970
struct nfsd4_compoundres *resp = rqstp->rq_resp;
@@ -3029,7 +3027,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
30293027
bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
30303028
if (exp->ex_flags & NFSEXP_SECURITY_LABEL)
30313029
err = security_inode_getsecctx(d_inode(dentry),
3032-
&context, &contextlen);
3030+
&context);
30333031
else
30343032
err = -EOPNOTSUPP;
30353033
contextsupport = (err == 0);
@@ -3446,8 +3444,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
34463444

34473445
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
34483446
if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
3449-
status = nfsd4_encode_security_label(xdr, rqstp, context,
3450-
contextlen);
3447+
status = nfsd4_encode_security_label(xdr, rqstp, &context);
34513448
if (status)
34523449
goto out;
34533450
}
@@ -3466,10 +3463,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
34663463

34673464
out:
34683465
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
3469-
if (context) {
3470-
lsmcontext_init(&scaff, context, contextlen, 0); /*scaffolding*/
3471-
security_release_secctx(&scaff);
3472-
}
3466+
if (context.context)
3467+
security_release_secctx(&context);
34733468
#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
34743469
kfree(acl);
34753470
if (tempfh) {

include/linux/security.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ void security_release_secctx(struct lsmcontext *cp);
649649
void security_inode_invalidate_secctx(struct inode *inode);
650650
int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
651651
int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
652-
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
652+
int security_inode_getsecctx(struct inode *inode, struct lsmcontext *cp);
653653
int security_locked_down(enum lockdown_reason what);
654654
int security_lock_kernel_down(const char *where, enum lockdown_reason level);
655655
#else /* CONFIG_SECURITY */
@@ -1556,7 +1556,8 @@ static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32
15561556
{
15571557
return -EOPNOTSUPP;
15581558
}
1559-
static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
1559+
static inline int security_inode_getsecctx(struct inode *inode,
1560+
struct lsmcontext *cp)
15601561
{
15611562
return -EOPNOTSUPP;
15621563
}

security/security.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,17 +4209,25 @@ EXPORT_SYMBOL(security_inode_setsecctx);
42094209
/**
42104210
* security_inode_getsecctx() - Get the security label of an inode
42114211
* @inode: inode
4212-
* @ctx: secctx
4213-
* @ctxlen: length of secctx
4212+
* @cp: lsm context
42144213
*
4215-
* On success, returns 0 and fills out @ctx and @ctxlen with the security
4216-
* context for the given @inode.
4214+
* On success, returns 0 and fills out @cp with the security context for the
4215+
* given @inode.
42174216
*
42184217
* Return: Returns 0 on success, error on failure.
42194218
*/
4220-
int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
4219+
int security_inode_getsecctx(struct inode *inode, struct lsmcontext *cp)
42214220
{
4222-
return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
4221+
struct security_hook_list *hp;
4222+
4223+
memset(cp, 0, sizeof(*cp));
4224+
4225+
hlist_for_each_entry(hp, &security_hook_heads.inode_getsecctx, list) {
4226+
cp->slot = hp->lsmid->slot;
4227+
return hp->hook.inode_getsecctx(inode, (void **)&cp->context,
4228+
&cp->len);
4229+
}
4230+
return -EOPNOTSUPP;
42234231
}
42244232
EXPORT_SYMBOL(security_inode_getsecctx);
42254233

0 commit comments

Comments
 (0)