cryptsetup status reports wrong size in its total byte count

Hello there,

I was configuring an encrypted swap partition using dm-crypt. The partition I'm trying to use for my swap space is the following:

/dev/nvme0n1p2: PARTUUID="6588817b-63c8-47cc-8306-6672adeafeb1"

Such partition is roughly 4GiB in size, as confirmed by lsblk.

NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
nvme0n1     259:5    0 465.8G  0 disk
├─nvme0n1p1 259:6    0     1G  0 part  /boot
├─nvme0n1p2 259:7    0     4G  0 part
│ └─swap    254:1    0     4G  0 crypt
└─nvme0n1p3 259:8    0 460.8G  0 part
  └─root    254:0    0 460.7G  0 crypt /

I'm re-encrypting it upon every boot with a fresh key thanks to the following line in my /etc/crypttab:

# <name>    <device>                                             <password>          <options>
swap        PARTUUID=6588817b-63c8-47cc-8306-6672adeafeb1        /dev/urandom        swap,cipher=aes-xts-plain64,size=512,sector-size=4096

Trying to inspect my swap volume mapper with the following command apparently reports the wrong size in total byte count:

# cryptsetup status swap
/dev/mapper/swap is active.
type:    PLAIN
cipher:  aes-xts-plain64
keysize: 512 [bits]
key location: dm-crypt
device:  /dev/nvme0n1p2
sector size:  4096 [bytes]
offset:  0 [512-byte units] (0 [bytes])
size:    8392704 [512-byte units] (34376515584 [bytes])
mode:    read/write

Specifically, it says 8392704 [512-byte units] which adds up to the exact size in bytes of my swap partition, multiplying 8392704 by 512, so the size in 512-byte units is correct.

However, the other size - 34376515584 [bytes] - is roughly 32GiB but it's obviously incorrect.

My root volume is also encrypted and it shows the same behavior.

# cryptsetup status root
/dev/mapper/root is active and is in use.
type:    LUKS2
cipher:  aes-xts-plain64
keysize: 512 [bits]
key location: keyring
device:  /dev/nvme0n1p3
sector size:  4096 [bytes]
offset:  32768 [512-byte units] (134217728 [bytes])
size:    966248448 [512-byte units] (3957753643008 [bytes])
mode:    read/write
flags:   discards no_read_workqueue no_write_workqueue

My root partition is 460.7 GiB but the real byte count in cryptsetup status shows up as roughly 3685 GiB.


I posted this inconsistency in the Arch forums, looking for clarification and a user spotted the lines of code that could be the culprit.

It looks like the real sector size (4096 in my case) is being multiplied by the 512-byte sector size, which gives a wrong byte count.

Edited by Gianluca Recchia