From nobody Fri Jul 24 04:50:44 2026 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 DD11A37189B; Thu, 23 Jul 2026 19:41:38 +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=1784835704; cv=none; b=iu2Jy+yRSbFVB1s9vkPW+h0zFOEQAq6oV0IJcYMC7rfV83jIEOooqnWqeGbVIiPmhW4I5FA2ZeDr4TN0P/m5dH7Aq/1r1sMk6HaKDmy61W/S+RwJdO2xZYhZSxkbpZHz5rqSqGt5UQnjIsDm6N0StrW9AGO+sw3Pf8gaIk9tPM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784835704; c=relaxed/simple; bh=QGkr6kMYxTIOGLgPwf9kKss/butys9/PHDAItokYYcM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YH5+WxcCb7rPr2dgksiCc1r7oM6KJ6U2O32Bh4wxUgHbXHEW0VkzeaTQKJYHEPaGLWcVLwgVWo27UJPQ6DPrHG5AsbfUvTVMa0vBOEaAun4qSv1SCeendZ8eeNVWEs4iBVZWhBJcxeTc87siYx4BfUbiwMRleIhKUDarKKrQKE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jZpC1tMv; 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="jZpC1tMv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EB1C1F00A3A; Thu, 23 Jul 2026 19:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784835696; bh=HuPV/HvdnWZhkNJmLIUMIUrFXjwDSzBAyxtVSe9Qpz8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=jZpC1tMvdr5yaSy2s51PhAnH3vNv5O0Z7T7NiBnIg77y0LRrwkJP5FIuoXmp/JOtv c9GYpA2j4Q6pSA+TNwpHa6ytP0Dg0Y+DZfPfXzDZCopBevbiXbOI3B3c5oNSkDUDwu fbOxki2+gQPT9t9kzU2e3WFPS6N1FoAHUqRtLt8XMlYz8En3toNr31iLM3ZKqA+JrP UqJ62gZ01Q6t6ucOU2+pNd09pEBDLGmI6v4V/FDCBQk0PxP7G/acdr3Afcy6kCPI6Z C6ixtu2qyvbWsyG2ZXmC65KNVy4pMWqgTIUnY2L24baK4GVinsBdrhanODLoe12Wcw a5IHaVu0WHr+g== From: Vincent Mailhol Date: Thu, 23 Jul 2026 21:40:31 +0200 Subject: [PATCH v2 1/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: quoted-printable Message-Id: <20260723-fix-ucs2_strnlen-v2-1-9ea94e32a358@kernel.org> References: <20260723-fix-ucs2_strnlen-v2-0-9ea94e32a358@kernel.org> In-Reply-To: <20260723-fix-ucs2_strnlen-v2-0-9ea94e32a358@kernel.org> To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Vincent Mailhol , stable@vger.kernel.org, Kees Cook X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1592; i=mailhol@kernel.org; h=from:subject:message-id; bh=QGkr6kMYxTIOGLgPwf9kKss/butys9/PHDAItokYYcM=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDFlJeTmTa468Trbed/q8jfjGsuJam4iLnTuZAxO+sHz87 +sZ+3Z/x0QWBjEuBksxRZZl5ZzcCh2F3mGH/lrCzGFlAhkiLdLAAAQsDHy5iXmlRjpGeqbahnqG QIaOEQMXpwBM9cV+hj88sjzvGr+6VZvtunX2slVLe9RFRZ6NR28vvrPNZqX4wswORobfZ75zMj7 vXe8w7a/w1DUeZTtOzOW4emST0Ca7VLe/4jMYAQ== 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 --- Cc: stable@vger.kernel.org Cc: Kees Cook 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 dfb4f2358cab..ca5c615d5bef 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 =3D 0; =20 - while (*s++ !=3D 0 && length < maxlength) + while (length < maxlength && *s++ !=3D 0) length++; return length; } --=20 2.54.0 From nobody Fri Jul 24 04:50:44 2026 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 208873B27F9 for ; Thu, 23 Jul 2026 19:41:41 +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=1784835709; cv=none; b=p5SpUw2e2qwD5icKBIUBL2vZDxftRFuvE40IYbD5PDF274uiaMIZ9fY8ZcNHG/nvXcVZlQusZTdOtCb5Q2edcvw0cx7fI7Jc6kJNSgLtqJYxVHLlxssw79VFDisrzy3VP/S7PY72JXzeMGyvKdwBcHN5REWE8/Jb+o52j6X7APM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784835709; c=relaxed/simple; bh=p3G4A3W+WpkIhUPIKbwAgrgeL4Iw69kDa8JFqYuOZzs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Yfac44CUGb97G8gmrGVJ2cW85tTm0NjWrDV5HxeUMjd7ZCVHh/+x5EqRKBR7MfJS3lZodY3U1EqfSDAxPAHxKrjIVDQYpZ/9Ul/kNSZK6htd1vAYsyXU8fqbwSwVpj4oQc5wUPzfWqn+dcFC76ylDvxFR//4j679tTbeVUoSp5Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KSzq6Ol9; 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="KSzq6Ol9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 196E21F00A3D; Thu, 23 Jul 2026 19:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784835698; bh=ep7Hgvn2HlB6B/AaoKwDKQdlAyZDnf5BViegLUgpw9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=KSzq6Ol9YxQybnLZRFIbu3UxkR2+5x7IS6jZ86Ggtjvqppq93kF6ol916+qMeXLlU FkJDkHlly0cCnDyXZJhfDlTZmDKKA18wh8gGTwvs0G+S3mizeE+rZco498n805RUCB c2hsTJcD/gRXo8C3YsvEGY28lwf+acTl6BjYUnZbtndHezBR2imbBv5frtE5dI1OKC NCOCnTxs+EF7vNc/d7keWox+x9jPRHTpQ8rjNOWqCTmdF5oFCBt6ZsR2XZLFcrxH4V IRfKkX6Gq/IhVZBLM0EpU9MfYe2SjSV8CyVG5HNHtlXp/lYgk1t2QYxeomlatQm4kD ypAXnEqNqlAhw== From: Vincent Mailhol Date: Thu, 23 Jul 2026 21:40:32 +0200 Subject: [PATCH v2 2/2] lib/ucs2_string.c: fix indentation 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: quoted-printable Message-Id: <20260723-fix-ucs2_strnlen-v2-2-9ea94e32a358@kernel.org> References: <20260723-fix-ucs2_strnlen-v2-0-9ea94e32a358@kernel.org> In-Reply-To: <20260723-fix-ucs2_strnlen-v2-0-9ea94e32a358@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=2135; i=mailhol@kernel.org; h=from:subject:message-id; bh=p3G4A3W+WpkIhUPIKbwAgrgeL4Iw69kDa8JFqYuOZzs=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDFlJebmS+cz+wtumqm5x1cl3+qqaVDB7//SzaTnnei0P2 j4SNJ/XMZGFQYyLwVJMkWVZOSe3Qkehd9ihv5Ywc1iZQIZIizQwAAELA19uYl6pkY6Rnqm2oZ4h kKFjxMDFKQBT/TCG4X+90oXZbcordNWarb+JC+v8OXtZ4oBjBONWxv7UyydWFkkzMizO2Pfc+cm j9Dv7nmz/v6njRfeJtya+/75xXtdT7YqYu4IbAA== X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 checkpatch.pl reports a total of 18 incorrect use of spaces instead of tabulations in lib/ucs2_string.c. Apply ./scripts/checkpatch.pl --fix-inplace lib/ucs2_string.c to fix them all. Signed-off-by: Vincent Mailhol --- lib/ucs2_string.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/ucs2_string.c b/lib/ucs2_string.c index ca5c615d5bef..1f7dd4eb640a 100644 --- a/lib/ucs2_string.c +++ b/lib/ucs2_string.c @@ -6,18 +6,18 @@ unsigned long ucs2_strnlen(const ucs2_char_t *s, size_t maxlength) { - unsigned long length =3D 0; + unsigned long length =3D 0; =20 while (length < maxlength && *s++ !=3D 0) - length++; - return length; + length++; + return length; } EXPORT_SYMBOL(ucs2_strnlen); =20 unsigned long ucs2_strlen(const ucs2_char_t *s) { - return ucs2_strnlen(s, ~0UL); + return ucs2_strnlen(s, ~0UL); } EXPORT_SYMBOL(ucs2_strlen); =20 @@ -28,7 +28,7 @@ EXPORT_SYMBOL(ucs2_strlen); unsigned long ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) { - return ucs2_strnlen(data, maxlength/sizeof(ucs2_char_t)) * sizeof(= ucs2_char_t); + return ucs2_strnlen(data, maxlength/sizeof(ucs2_char_t)) * sizeof(ucs2_ch= ar_t); } EXPORT_SYMBOL(ucs2_strsize); =20 @@ -87,19 +87,19 @@ EXPORT_SYMBOL(ucs2_strscpy); int ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len) { - while (1) { - if (len =3D=3D 0) - return 0; - if (*a < *b) - return -1; - if (*a > *b) - return 1; - if (*a =3D=3D 0) /* implies *b =3D=3D 0 */ - return 0; - a++; - b++; - len--; - } + while (1) { + if (len =3D=3D 0) + return 0; + if (*a < *b) + return -1; + if (*a > *b) + return 1; + if (*a =3D=3D 0) /* implies *b =3D=3D 0 */ + return 0; + a++; + b++; + len--; + } } EXPORT_SYMBOL(ucs2_strncmp); =20 --=20 2.54.0