linux-stable/block
Olivier Gayot 51e0101ab9 block: fix conversion of GPT partition name to 7-bit
commit e06472bab2 upstream.

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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 12:51:03 +01:00
..
partitions block: fix conversion of GPT partition name to 7-bit 2025-03-13 12:51:03 +01:00
badblocks.c
bdev.c block: deprecate autoloading based on dev_t 2025-03-13 12:49:51 +01:00
bfq-cgroup.c
bfq-iosched.c block, bfq: fix waker_bfqq UAF after bfq_split_bfqq() 2025-01-23 17:15:55 +01:00
bfq-iosched.h
bfq-wf2q.c
bio-integrity.c block: initialize integrity buffer to zero before writing it to media 2024-08-19 05:44:50 +02:00
bio.c
blk-cgroup-rwstat.c
blk-cgroup-rwstat.h
blk-cgroup.c blk-cgroup: Fix class @block_class's subsystem refcount leakage 2025-03-13 12:50:26 +01:00
blk-core.c
blk-crypto-fallback.c
blk-crypto-internal.h
blk-crypto.c
blk-exec.c
blk-flush.c
blk-integrity.c blk-integrity: register sysfs attributes on struct device 2024-10-17 15:11:33 +02:00
blk-ioc.c
blk-iocost.c blk-iocost: Avoid using clamp() on inuse in __propagate_weights() 2024-12-19 18:07:21 +01:00
blk-iolatency.c
blk-ioprio.c
blk-ioprio.h
blk-lib.c
blk-map.c
blk-merge.c
blk-mq-cpumap.c
blk-mq-debugfs-zoned.c
blk-mq-debugfs.c
blk-mq-debugfs.h
blk-mq-pci.c
blk-mq-rdma.c
blk-mq-sched.c
blk-mq-sched.h
blk-mq-sysfs.c
blk-mq-tag.c
blk-mq-tag.h
blk-mq-virtio.c
blk-mq.c block: fix ordering between checking BLK_MQ_S_STOPPED request adding 2024-12-14 19:51:17 +01:00
blk-mq.h block: fix ordering between checking BLK_MQ_S_STOPPED request adding 2024-12-14 19:51:17 +01:00
blk-pm.c
blk-pm.h
blk-rq-qos.c blk-rq-qos: fix crash on rq_qos_wait vs. rq_qos_wake_function race 2024-10-22 15:40:43 +02:00
blk-rq-qos.h
blk-settings.c
blk-stat.c
blk-stat.h
blk-sysfs.c
blk-throttle.c
blk-timeout.c
blk-wbt.c
blk-wbt.h
blk-zoned.c
blk.h blk-integrity: register sysfs attributes on struct device 2024-10-17 15:11:33 +02:00
bounce.c
bsg-lib.c
bsg.c
disk-events.c
elevator.c block: Fix elevator_get_default() checking for NULL q->tag_set 2024-11-17 15:06:24 +01:00
fops.c
genhd.c block: retry call probe after request_module in blk_request_module 2025-03-13 12:49:51 +01:00
holder.c
ioctl.c
ioprio.c
Kconfig block: deprecate autoloading based on dev_t 2025-03-13 12:49:51 +01:00
Kconfig.iosched
keyslot-manager.c
kyber-iosched.c
Makefile
mq-deadline.c
opal_proto.h
sed-opal.c
t10-pi.c