[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250326003303.GA2394@ax162>
Date: Tue, 25 Mar 2025 17:33:03 -0700
From: Nathan Chancellor <nathan@...nel.org>
To: Andy Shevchenko <andy@...nel.org>
Cc: Kees Cook <kees@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>,
Ard Biesheuvel <ardb@...nel.org>, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org, llvm@...ts.linux.dev,
linux-efi@...r.kernel.org
Subject: Re: [PATCH RFC 2/2] wcslen() prototype in string.h
On Tue, Mar 25, 2025 at 02:45:21PM -0700, Nathan Chancellor wrote:
> Okay, sounds reasonable to me. This is what I ended up with for that
> change, which will become patch one of the series.
...
> diff --git a/drivers/firmware/efi/libstub/printk.c b/drivers/firmware/efi/libstub/printk.c
> index 3a67a2cea7bd..334f7e89845c 100644
> --- a/drivers/firmware/efi/libstub/printk.c
> +++ b/drivers/firmware/efi/libstub/printk.c
> @@ -24,7 +24,7 @@ void efi_char16_puts(efi_char16_t *str)
> }
>
> static
> -u32 utf8_to_utf32(const u8 **s8)
> +u32 efi_utf8_to_utf32(const u8 **s8)
> {
> u32 c32;
> u8 c0, cx;
> @@ -82,7 +82,7 @@ void efi_puts(const char *str)
> while (*s8) {
> if (*s8 == '\n')
> buf[pos++] = L'\r';
> - c32 = utf8_to_utf32(&s8);
> + c32 = efi_utf8_to_utf32(&s8);
> if (c32 < 0x10000) {
> /* Characters in plane 0 use a single word. */
> buf[pos++] = c32;
> --
> 2.49.0
>
> Then the first patch (which becomes the second) becomes:
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 0403a4ca4c11..45e01cf3434c 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -7,6 +7,7 @@
> #include <linux/cleanup.h> /* for DEFINE_FREE() */
> #include <linux/compiler.h> /* for inline */
> #include <linux/types.h> /* for size_t */
> +#include <linux/nls.h> /* for wchar_t */
Good thing I waited :) This include makes s390 unhappy:
https://lore.kernel.org/202503260611.MDurOUhF-lkp@intel.com/
It is possible that should be fixed by adding -Wno-pointer-sign to
KBUILD_CFLAGS_DECOMPRESSOR so that arch/s390/boot matches the rest of
the kernel but...
> diff --git a/lib/string.c b/lib/string.c
> index eb4486ed40d2..1aa09925254b 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -21,6 +21,7 @@
> #include <linux/errno.h>
> #include <linux/limits.h>
> #include <linux/linkage.h>
> +#include <linux/nls.h>
> #include <linux/stddef.h>
> #include <linux/string.h>
> #include <linux/types.h>
I wonder if would be better to do something like the below patch in lieu
of the EFI change above (since there is no chance for a collision) then
change both of the includes for wchar_t in this diff to nls_types.h? I
have no strong opinion but this seems like it would be cleaner for the
sake of backports while not being a bad solution upstream?
Subject: [PATCH] include: Move typedefs in nls.h to their own header
In order to allow commonly included headers such as string.h to access
typedefs such as wchar_t without running into issues with the rest of
the NLS library, refactor the typedefs out into their own header that
can be included in a much safer manner.
Cc: stable@...r.kernel.org
Signed-off-by: Nathan Chancellor <nathan@...nel.org>
---
include/linux/nls.h | 19 +------------------
include/linux/nls_types.h | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 18 deletions(-)
create mode 100644 include/linux/nls_types.h
diff --git a/include/linux/nls.h b/include/linux/nls.h
index e0bf8367b274..3d416d1f60b6 100644
--- a/include/linux/nls.h
+++ b/include/linux/nls.h
@@ -3,24 +3,7 @@
#define _LINUX_NLS_H
#include <linux/init.h>
-
-/* Unicode has changed over the years. Unicode code points no longer
- * fit into 16 bits; as of Unicode 5 valid code points range from 0
- * to 0x10ffff (17 planes, where each plane holds 65536 code points).
- *
- * The original decision to represent Unicode characters as 16-bit
- * wchar_t values is now outdated. But plane 0 still includes the
- * most commonly used characters, so we will retain it. The newer
- * 32-bit unicode_t type can be used when it is necessary to
- * represent the full Unicode character set.
- */
-
-/* Plane-0 Unicode character */
-typedef u16 wchar_t;
-#define MAX_WCHAR_T 0xffff
-
-/* Arbitrary Unicode character */
-typedef u32 unicode_t;
+#include <linux/nls_types.h>
struct nls_table {
const char *charset;
diff --git a/include/linux/nls_types.h b/include/linux/nls_types.h
new file mode 100644
index 000000000000..8caefdba19b1
--- /dev/null
+++ b/include/linux/nls_types.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_NLS_TYPES_H
+#define _LINUX_NLS_TYPES_H
+
+#include <linux/types.h>
+
+/* Unicode has changed over the years. Unicode code points no longer
+ * fit into 16 bits; as of Unicode 5 valid code points range from 0
+ * to 0x10ffff (17 planes, where each plane holds 65536 code points).
+ *
+ * The original decision to represent Unicode characters as 16-bit
+ * wchar_t values is now outdated. But plane 0 still includes the
+ * most commonly used characters, so we will retain it. The newer
+ * 32-bit unicode_t type can be used when it is necessary to
+ * represent the full Unicode character set.
+ */
+
+/* Plane-0 Unicode character */
+typedef u16 wchar_t;
+#define MAX_WCHAR_T 0xffff
+
+/* Arbitrary Unicode character */
+typedef u32 unicode_t;
+
+#endif /* _LINUX_NLS_TYPES_H */
--
2.49.0
diff --git a/include/linux/string.h b/include/linux/string.h
index 45e01cf3434c..4a48f8eac301 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -7,7 +7,7 @@
#include <linux/cleanup.h> /* for DEFINE_FREE() */
#include <linux/compiler.h> /* for inline */
#include <linux/types.h> /* for size_t */
-#include <linux/nls.h> /* for wchar_t */
+#include <linux/nls_types.h> /* for wchar_t */
#include <linux/stddef.h> /* for NULL */
#include <linux/err.h> /* for ERR_PTR() */
#include <linux/errno.h> /* for E2BIG */
diff --git a/lib/string.c b/lib/string.c
index 1aa09925254b..2c6f8c8f4159 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -21,7 +21,7 @@
#include <linux/errno.h>
#include <linux/limits.h>
#include <linux/linkage.h>
-#include <linux/nls.h>
+#include <linux/nls_types.h>
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/types.h>
Powered by blists - more mailing lists