Skip to content

Commit 910949a

Browse files
Venkat YekkiralaJames Morris
Venkat Yekkirala
authored and
James Morris
committed
SELinux: null-terminate context string in selinux_xfrm_sec_ctx_alloc
xfrm_audit_log() expects the context string to be null-terminated which currently doesn't happen with user-supplied contexts. Signed-off-by: Venkat Yekkirala <[email protected]> Acked-by: Stephen Smalley <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent 0de085b commit 910949a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

security/selinux/xfrm.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,
216216
return -ENOMEM;
217217

218218
*ctxp = ctx = kmalloc(sizeof(*ctx) +
219-
uctx->ctx_len,
219+
uctx->ctx_len + 1,
220220
GFP_KERNEL);
221221

222222
if (!ctx)
@@ -229,6 +229,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,
229229
memcpy(ctx->ctx_str,
230230
uctx+1,
231231
ctx->ctx_len);
232+
ctx->ctx_str[ctx->ctx_len] = 0;
232233
rc = security_context_to_sid(ctx->ctx_str,
233234
ctx->ctx_len,
234235
&ctx->ctx_sid);

0 commit comments

Comments
 (0)