From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 75DA04399F7 for ; Wed, 22 Jul 2026 21:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784754357; cv=none; b=WDQAOB3CpvnZRQubWUf7udNdCf+vqVC8FfP76mkY9bGnt8pSVPl+1uep5JU4MwluKezZQ/v4oZAH+nQ94RHU+ztrdh+bSq1eeF++sLKJx+GT7yLV/1nau589rmNdimzzXHGcQNQ6e+bhOunO9OnKD7/vAaCksMn7BTSllk5oK3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784754357; c=relaxed/simple; bh=EMtQKYybNj47JrlGfLsjLz+AjZGThwkxH4uO0rS3X/s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iBVV2S7JNWJmGNt4/Ab9z7LQ9GrmEaIjsrQFP6/CCl5j3qPz+B5rtwosBlJa7ATCHhzaK83UOtYT+dNsTU4ciTSR25af+ZEMVY9/ELGZn8jiJGPA4OG8dIBuUmYZhUyhtw9PKU1nEQeQrBioRmaUapqu8U+cxwQbHzkB7jxexxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MIsrGM5O; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MIsrGM5O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3622E1F000E9; Wed, 22 Jul 2026 21:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784754356; bh=VhRBkvEuXDvZWZd33ZCLAU+z1laggCqij2b/PDVKGTI=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=MIsrGM5O8RgbcNXnM3wOfiPMirZv6/c/k2Mb4NjHH6F5URj+nCiKwnokqwRHZYinE GMQuaBlLIbJHPh4LNRXWTV6cGR9dqMo+s6cMXi6sZ1QLQbXXpTeGyt2Xf/tmbuCMBR b6epckj30YeUkPELQ2P6nNAF8FcYuy/qC3d2y+tfrPdenGFpZ6vLbtdwuvxztQ2jYJ V27oz6wkQLhqCjZPFleYW4BACI+xSSSNqCK+OOQft8V7JKC6a9dOMnyN/vnNRtZk3X cEcu3OXnhrbpm2iZQZ2teCkUT8PusQjpD+8I+xfT0vEV9QNylRbUY2pF+ZHCrA+MrO gbzvR6T0xkG7w== From: Vincent Mailhol Date: Wed, 22 Jul 2026 23:04:53 +0200 Subject: [PATCH 2/2] lib/ucs2_string.c: fix out-of-bounds read in ucs2_strnlen() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260722-fix-ucs2_strnlen-v1-2-ba5bade2b026@kernel.org> References: <20260722-fix-ucs2_strnlen-v1-0-ba5bade2b026@kernel.org> In-Reply-To: <20260722-fix-ucs2_strnlen-v1-0-ba5bade2b026@kernel.org> To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Vincent Mailhol X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1494; i=mailhol@kernel.org; h=from:subject:message-id; bh=EMtQKYybNj47JrlGfLsjLz+AjZGThwkxH4uO0rS3X/s=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDFmJButrrXoeH08ulpD5siju3qG9Dh9XWTImpMzc2Cp1g NV0h/fmjoksDGJcDJZiiizLyjm5FToKvcMO/bWEmcPKBDJEWqSBAQhYGPhyE/NKjXSM9Ey1DfUM gQwdIwYuTgGY6t9yDP+TzT0PF36L4K5iVjz9O8T0+M3Q1YyTHFgXxMyucavcGvKDkeHxfB7mRoa 9z7p6zp5REFuxuvZ4Ufpvm5SGNnG7xxsvfGEBAA== X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 ucs2_strnlen() checks the current character before checking whether the caller-provided maximum length has been reached. If the input is not NUL-terminated within that bound, the loop can read one ucs2_char_t past the limit. Test the length before dereferencing to prevent an off-by-one out-of-bounds read. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Vincent Mailhol --- Concerning the Fixes: tag, the ucs2_strnlen() function can be traced as follow: - commit 0635eb8a54cf ("Move utf16 functions to kernel core and rename") renames it from utf16_strnlen() to ucs2_strnlen() as we know it today. - commit a2940908391f ("efivars: String functions") renames utf8_strlen() to utf16_strnlen(). - utf8_strlen() is present since the begining of the git history in commit 1da177e4c3f4 ("Linux-2.6.12-rc2") And that of-by-one issue was present since the beginning and survived all the renamings. This is why I picked 1da177e4c3f4 in the Fixes tag. --- lib/ucs2_string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ucs2_string.c b/lib/ucs2_string.c index f07fcdad764b..1f7dd4eb640a 100644 --- a/lib/ucs2_string.c +++ b/lib/ucs2_string.c @@ -8,7 +8,7 @@ ucs2_strnlen(const ucs2_char_t *s, size_t maxlength) { unsigned long length = 0; - while (*s++ != 0 && length < maxlength) + while (length < maxlength && *s++ != 0) length++; return length; } -- 2.54.0