|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* |
| 3 | + * fs/partitions/luks.c |
| 4 | + * LUKS on raw partition; this is important because a LUKS volume may detected |
| 5 | + * as a valid Atari partition table, breaking other detection. |
| 6 | + * |
| 7 | + * Copyright (C) 2025 Robin H. Johnson ([email protected]) |
| 8 | + * |
| 9 | + * Reference: https://gitlab.com/cryptsetup/LUKS2-docs/blob/master/luks2_doc_wip.pdf |
| 10 | + * Page 5, Figure 2: LUKS2 binary header on-disk structure |
| 11 | + * This only looks for the Magic & version; and NOT a UUID that starts at |
| 12 | + * offset 0xA8. |
| 13 | + */ |
| 14 | + |
| 15 | +#include <linux/ctype.h> |
| 16 | +#include <linux/compiler.h> |
| 17 | +#include "check.h" |
| 18 | + |
| 19 | +#define LUKS_MAGIC_1ST_V1 "LUKS\xba\xbe\x00\x01" |
| 20 | +#define LUKS_MAGIC_1ST_V2 "LUKS\xba\xbe\x00\x02" |
| 21 | +#define LUKS_MAGIC_2ND_V1 "SKUL\xba\xbe\x00\x01" |
| 22 | +#define LUKS_MAGIC_2ND_V2 "SKUL\xba\xbe\x00\x02" |
| 23 | + |
| 24 | +int luks_partition(struct parsed_partitions *state) |
| 25 | +{ |
| 26 | + Sector sect; |
| 27 | + int ret = 0; |
| 28 | + unsigned char *data; |
| 29 | + |
| 30 | + data = read_part_sector(state, 0, §); |
| 31 | + |
| 32 | + if (!data) |
| 33 | + return -1; |
| 34 | + |
| 35 | + if (memcmp(data, LUKS_MAGIC_1ST_V1, 8) == 0 |
| 36 | + || memcmp(data, LUKS_MAGIC_2ND_V1, 8) == 0) { |
| 37 | + strlcat(state->pp_buf, "LUKSv1\n", PAGE_SIZE); |
| 38 | + ret = 1; |
| 39 | + } else if (memcmp(data, LUKS_MAGIC_1ST_V2, 8) == 0 |
| 40 | + || memcmp(data, LUKS_MAGIC_2ND_V2, 8) == 0) { |
| 41 | + strlcat(state->pp_buf, "LUKSv2\n", PAGE_SIZE); |
| 42 | + ret = 1; |
| 43 | + } |
| 44 | + put_dev_sector(sect); |
| 45 | + return ret; |
| 46 | +} |
0 commit comments