Description
Describe the bug
swap partition encrypted with cryptsetup causes system to reboot as soon as swap is used
To reproduce
In this example there is external disk attached with 2GB swap partition (/dev/sda2)
disable existing swap:
sudo swapoff -a
install cryptsetup:
sudo apt-get install cryptsetup
edit /etc/crypttab and add:
cryptswap /dev/sda2 /dev/urandom swap,cipher=aes-xts-plain64,size=256,hash=sha1,noauto
start encrypted partition:
sudo cryptdisks_start cryptswap
check that above worked:
pi@raspberrypi:~$ ll /dev/mapper
total 0
crw------- 1 root root 10, 236 Oct 16 12:28 control
lrwxrwxrwx 1 root root 7 Oct 16 12:48 cryptswap -> ../dm-0
pi@raspberrypi:~$ sudo cryptsetup status /dev/mapper/cryptswap
/dev/mapper/cryptswap is active.
type: PLAIN
cipher: aes-xts-plain64
keysize: 256 bits
key location: dm-crypt
device: /dev/sda2
sector size: 512
offset: 0 sectors
size: 3911647 sectors
mode: read/write
enable encrypted swap:
sudo swapon /dev/mapper/cryptswap
check that above worked:
pi@raspberrypi:~$ sudo swapon -s
Filename Type Size Used Priority
/dev/dm-0 partition 1955816 0 -2
make use of it, I force it with:
stress -m 2 --vm-bytes 500M
but initially I noticed it during normal usage e.g. when running complex software build.
I observe swap usage using htop
Expected behaviour
system should use encrypted swap.
Actual behaviour
system reboots as soon as swap is being used
System
-
Which model of Raspberry Pi? tested with:
2B, 3 and 3B+ -
Which OS and version (
cat /etc/rpi-issue
)?
Raspberry Pi reference 2019-09-26
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 80d486687ea77d31fc3fc13cf3a2f8b464e129be, stage2 -
Which firmware version (
vcgencmd version
)?
Sep 24 2019 17:37:47
Copyright (c) 2012 Broadcom
version 6820edeee4ef3891b95fc01cf02a7abd7ca52f17 (clean) (release) (start_cd) -
Which kernel version (
uname -a
)?
Linux raspberrypi 4.19.75-v7+ solved issue of mirroring screen after rotation. #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux
Logs
There is nothing in logs related to reboot, no OOM... nothing
The last entries in kern.log
Oct 16 12:28:18 raspberrypi kernel: [ 106.718202] device-mapper: ioctl: 4.39.0-ioctl (2018-04-03) initialised: dm-devel@redhat.com
Oct 16 12:28:18 raspberrypi kernel: [ 107.208600] cryptd: max_cpu_qlen set to 1000
Oct 16 12:28:30 raspberrypi kernel: [ 119.598168] Adding 1955816k swap on /dev/mapper/cryptswap. Priority:-3 extents:1 across:1955816k FS
followed by fresh boot sequence.
Additional context
When swap partition is not using encryption everything works perfectly. I have tried external HDD, memory sticks etc. Using partition or full disk. Results are always the same - as soon as I try encrypt swap system reboots.
To rule out any misconfiguration I have run it with the latest fresh install of raspbian. All updates applied.
I have raised this issue on raspberry pi forum (Encrypted swap crashes all system) but so far no solution/cause have been found.