]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selinux: fix selinux_xfrm_alloc_user() to set correct ctx_len
authorStephen Smalley <stephen.smalley.work@gmail.com>
Fri, 13 Jun 2025 19:37:05 +0000 (15:37 -0400)
committerPaul Moore <paul@paul-moore.com>
Mon, 16 Jun 2025 23:02:22 +0000 (19:02 -0400)
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>
security/selinux/xfrm.c

index 90ec4ef1b082f9021f686adb4e0ed3b14f282727..61d56b0c2be138296ad44aa5c31484b28ba6fe62 100644 (file)
@@ -94,7 +94,7 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
 
        ctx->ctx_doi = XFRM_SC_DOI_LSM;
        ctx->ctx_alg = XFRM_SC_ALG_SELINUX;
-       ctx->ctx_len = str_len;
+       ctx->ctx_len = str_len + 1;
        memcpy(ctx->ctx_str, &uctx[1], str_len);
        ctx->ctx_str[str_len] = '\0';
        rc = security_context_to_sid(ctx->ctx_str, str_len,