Skip to content

Commit 7b87d18

Browse files
stephensmalleypopcornmix
authored andcommitted
selinux: fix selinux_xfrm_alloc_user() to set correct ctx_len
commit 86c8db8 upstream. We should count the terminating NUL byte as part of the ctx_len. Otherwise, UBSAN logs a warning: UBSAN: array-index-out-of-bounds in security/selinux/xfrm.c:99:14 index 60 is out of range for type 'char [*]' The allocation itself is correct so there is no actual out of bounds indexing, just a warning. Cc: stable@vger.kernel.org Suggested-by: Christian Göttsche <cgzones@googlemail.com> Link: https://lore.kernel.org/selinux/CAEjxPJ6tA5+LxsGfOJokzdPeRomBHjKLBVR6zbrg+_w3ZZbM3A@mail.gmail.com/ Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b5a3163 commit 7b87d18

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

security/selinux/xfrm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
9494

9595
ctx->ctx_doi = XFRM_SC_DOI_LSM;
9696
ctx->ctx_alg = XFRM_SC_ALG_SELINUX;
97-
ctx->ctx_len = str_len;
97+
ctx->ctx_len = str_len + 1;
9898
memcpy(ctx->ctx_str, &uctx[1], str_len);
9999
ctx->ctx_str[str_len] = '\0';
100100
rc = security_context_to_sid(ctx->ctx_str, str_len,

0 commit comments

Comments
 (0)