From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D36C81AD3FA; Mon, 23 Jun 2025 21:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715682; cv=none; b=NSTeZN3WjLDwcSjWywepe0SUNo8IY6+bPWDAS08qDskJLQCizcqgahXP/tFQCRkV1FTE/i+pddco8Lg9pJv8UtbMW148D7IUocAIaUSkxz5gfHiQvtlujx3kOXV0YVNdJFzYJ8TRv7IIGvuHZx58f6r2hUQmMqtO3a9/VgK7SQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715682; c=relaxed/simple; bh=n/QwTgqSgd1EZVzc2FwoHuIj/yBLXtH1LaUQgbOfpZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U4Hx9UXMJ4hynTuGOcg++KrQpl1o6Eiu2iinv8vuR1OMSffjVgdPkFOJ+T1lLVSay0sMWb66GArPFXiPGmH1zvCFhSD3ex+w9zh5OLRkWHMQlOvlFI/3NXv+0N6n6F9e4TWL0L9Gnrqm5lhk1gY2X0fZADIqAV4KHTlTCWxUkYE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nUpllGOR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="nUpllGOR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C21CC4CEEA; Mon, 23 Jun 2025 21:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715682; bh=n/QwTgqSgd1EZVzc2FwoHuIj/yBLXtH1LaUQgbOfpZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nUpllGORJGES58cfa6IdkxphN82XeqJ/9PHvp3z1/MJNsyXUi5+J9uprPX7r6Ydk5 CUBQEtOV6309b9nT3LKM+44aQD6UjhxPyuLpLerBgAb37XKOSn9F/SWAv5yvRg/pJ9 PKz3fRi+qdvL9e/4fHQ+qZhM9T0XKPskAslM7lXc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Christian=20G=C3=B6ttsche?= , Stephen Smalley , Paul Moore Subject: [PATCH 5.10 290/355] selinux: fix selinux_xfrm_alloc_user() to set correct ctx_len Date: Mon, 23 Jun 2025 15:08:11 +0200 Message-ID: <20250623130635.492416164@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130626.716971725@linuxfoundation.org> References: <20250623130626.716971725@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephen Smalley commit 86c8db86af43f52f682e53a0f2f0828683be1e52 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 Link: https://lore.kernel.org/selinux/CAEjxPJ6tA5+LxsGfOJokzdPeRomBHjKLBVR6zbrg+_w3ZZbM3A@mail.gmail.com/ Signed-off-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/xfrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/security/selinux/xfrm.c +++ b/security/selinux/xfrm.c @@ -95,7 +95,7 @@ static int selinux_xfrm_alloc_user(struc 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(&selinux_state, ctx->ctx_str, str_len,