block/partitions: detect LUKS-formatted disks
Subsystems (2)
PATCH 1/1 block/partitions: detect LUKS-formatted disks
If an entire device is formatted as LUKS, there is a small chance it maybe be detected as an Atari/AHDI disk - causing the kernel to create partitions, and confusing other systems.
Detect the LUKS header before the Atari partition table to prevent this from creating partitions on top of the LUKS volume.
--- block/partitions/Kconfig | 8 +++++++ block/partitions/Makefile | 1 + block/partitions/check.h | 1 + block/partitions/core.c | 3 +++ block/partitions/luks.c | 46 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 block/partitions/luks.c
block/partitions/Kconfig +8 -0
@@ -96,6 +96,14 @@ config AMIGA_PARTITION Say Y here if you would like to use hard disks under Linux which were partitioned under AmigaOS. +config LUKS_PARTITION + bool "LUKS partition support" if PARTITION_ADVANCED + default y if ATARI_PARTITION + help + Say Y here to detect hard disks which have a LUKS header instead of a + partition table. This is valuable as LUKS header may also be wrongly + detected as other partition types. + config ATARI_PARTITION bool "Atari partition table support" if PARTITION_ADVANCED default y if ATARI
block/partitions/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_AIX_PARTITION) += aix.o obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o obj-$(CONFIG_MAC_PARTITION) += mac.o obj-$(CONFIG_LDM_PARTITION) += ldm.o +obj-$(CONFIG_LUKS_PARTITION) += luks.o obj-$(CONFIG_MSDOS_PARTITION) += msdos.o obj-$(CONFIG_OF_PARTITION) += of.o obj-$(CONFIG_OSF_PARTITION) += osf.o
block/partitions/check.h +1 -0
@@ -60,6 +60,7 @@ int efi_partition(struct parsed_partitions *state);int ibm_partition (struct parsed_partitions *);int karma_partition (struct parsed_partitions *state);int ldm_partition (struct parsed_partitions *state); +int luks_partition (struct parsed_partitions *state);int mac_partition (struct parsed_partitions *state);int msdos_partition (struct parsed_partitions *state);int of_partition (struct parsed_partitions *state);
block/partitions/core.c +3 -0
@@ -67,6 +67,9 @@ static int (*const check_part[])(struct parsed_partitions *) = {#ifdef CONFIG_AMIGA_PARTITION amiga_partition,#endif +#ifdef CONFIG_LUKS_PARTITION + luks_partition, /* this must come before atari */ +#endif #ifdef CONFIG_ATARI_PARTITION atari_partition,#endif
block/partitions/luks.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.47.0
I'm not sure this is the best way to approach it, as what you add is not really a partition format.
I'd suggest checking for the LUKS signature in the atari partition parser instead - that way the code is automatically built when the atari partition parser is built in, and not built when not needed.
Minor nitpick:
block/partitions/luks.c line 36
Quoted 2 lines
block/partitions/luks.c new file +2
-0+if (memcmp (data,LUKS_MAGIC_1ST_V1 ,8 ) ==0 + ||memcmp (data,LUKS_MAGIC_2ND_V1 ,8 ) ==0 ) {
The || goes at the end of the line for the linux coding style, and the continuing line is indented either after the opening brace or by an extra tab vs the following code:
if (memcmp(data, LUKS_MAGIC_1ST_V1, 8) == 0 ||
memcmp(data, LUKS_MAGIC_2ND_V1, 8) == 0) {Quoted 6 lines · Robin H. Johnson
If an entire device is formatted as LUKS, there is a small chance it maybe be detected as an Atari/AHDI disk - causing the kernel to create partitions, and confusing other systems.
Detect the LUKS header before the Atari partition table to prevent this from creating partitions on top of the LUKS volume.
Please, no. This is a horrible hack.
LUKS is not a partition. It is a completely userspace concept, detection should not be in the kernel at all. Moreover, the detection below is oversimplified; the second header can be on multiple offsets.
The same problem can happen with Veracrypt or other systems that randomize data.
The Atari partition is known to use very weak detection, but I think blkid added some more hints to check validity in userspace - why is it not enough? Is anything from this logic missing in the kernel?
If it is not solvable, you should turn off Atari partition detection as it is unreliable.
Milan