Centos-kernel-stream-9/block/partitions
Ming Lei 7d9bd218c6 block: fix conversion of GPT partition name to 7-bit
JIRA: https://issues.redhat.com/browse/RHEL-79409

commit e06472bab2a5393430cc2fbc3211cd3602422c1e
Author: Olivier Gayot <olivier.gayot@canonical.com>
Date:   Wed Mar 5 10:21:54 2025 +0800

    block: fix conversion of GPT partition name to 7-bit

    The utf16_le_to_7bit function claims to, naively, convert a UTF-16
    string to a 7-bit ASCII string. By naively, we mean that it:
     * drops the first byte of every character in the original UTF-16 string
     * checks if all characters are printable, and otherwise replaces them
       by exclamation mark "!".

    This means that theoretically, all characters outside the 7-bit ASCII
    range should be replaced by another character. Examples:

     * lower-case alpha (ɒ) 0x0252 becomes 0x52 (R)
     * ligature OE (œ) 0x0153 becomes 0x53 (S)
     * hangul letter pieup (ㅂ) 0x3142 becomes 0x42 (B)
     * upper-case gamma (Ɣ) 0x0194 becomes 0x94 (not printable) so gets
       replaced by "!"

    The result of this conversion for the GPT partition name is passed to
    user-space as PARTNAME via udev, which is confusing and feels questionable.

    However, there is a flaw in the conversion function itself. By dropping
    one byte of each character and using isprint() to check if the remaining
    byte corresponds to a printable character, we do not actually guarantee
    that the resulting character is 7-bit ASCII.

    This happens because we pass 8-bit characters to isprint(), which
    in the kernel returns 1 for many values > 0x7f - as defined in ctype.c.

    This results in many values which should be replaced by "!" to be kept
    as-is, despite not being valid 7-bit ASCII. Examples:

     * e with acute accent (é) 0x00E9 becomes 0xE9 - kept as-is because
       isprint(0xE9) returns 1.
     * euro sign (€) 0x20AC becomes 0xAC - kept as-is because isprint(0xAC)
       returns 1.

    This way has broken pyudev utility[1], fixes it by using a mask of 7 bits
    instead of 8 bits before calling isprint.

    Link: https://github.com/pyudev/pyudev/issues/490#issuecomment-2685794648 [1]
    Link: https://lore.kernel.org/linux-block/4cac90c2-e414-4ebb-ae62-2a4589d9dc6e@canonical.com/
    Cc: Mulhern <amulhern@redhat.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: stable@vger.kernel.org
    Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
    Signed-off-by: Ming Lei <ming.lei@redhat.com>
    Link: https://lore.kernel.org/r/20250305022154.3903128-1-ming.lei@redhat.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Ming Lei <ming.lei@redhat.com>
2025-03-17 12:51:18 +08:00
..
Kconfig block: add support for partition table defined in OF 2025-03-14 16:48:11 +08:00
Makefile block: add support for partition table defined in OF 2025-03-14 16:48:11 +08:00
acorn.c
aix.c
amiga.c
atari.c
atari.h
check.h block: add support for partition table defined in OF 2025-03-14 16:48:11 +08:00
cmdline.c
core.c block: add partition uuid into uevent as "PARTUUID" 2025-03-14 16:48:11 +08:00
efi.c block: fix conversion of GPT partition name to 7-bit 2025-03-17 12:51:18 +08:00
efi.h
ibm.c
karma.c
ldm.c
ldm.h partitions: ldm: remove the initial kernel-doc notation 2025-03-14 16:48:41 +08:00
mac.c partitions: mac: fix handling of bogus partition table 2025-03-14 16:48:44 +08:00
mac.h
msdos.c
of.c block: add support for partition table defined in OF 2025-03-14 16:48:11 +08:00
osf.c
sgi.c
sun.c
sysv68.c
ultrix.c