cryptsetup segfaults upon opening luks device
I have an SD card located at /dev/mmcblk0
that is encrypted using cryptsetup. This device was encrypted using cryptsetup version 1.6.7 (kernel version 3.3.0). I am in the process of upgrading to cryptsetup 1.7.5 (kernel version 4.12.0). I was attempting to use the same script to access the device as I did before the upgrade, but ran in to segfaults with cryptsetup. Here is the script in question:
reformat () {
echo -n $1 | \
cryptsetup -v -c "aes-ecb-plain" -s 128 --use-urandom -h sha1 \
luksFormat /dev/mmcblk0 -
}
SD_ACCESS=`cat /path/to/password`
case "$1" in
start)
echo "Preparing SD card"
if [ -d /sys/block/mmcblk0 ]; then
echo "Checking format"
if ! cryptsetup isLuks /dev/mmcblk0; then
echo "Reformatting"
reformat $SD_ACCESS
fi
echo "Unlocking SD card"
echo $SD_ACCESS | cryptsetup luksOpen /dev/mmcblk0 encr-
if [ $? -ne 0 ]; then
echo "Reformatting"
reformat $SD_ACCESS
fi
echo "Checkin FS type"
if ! blkid /dev/mapper/encr-SD | grep ext4; then
echo "Reformatting to ext4"
mke2fs -t ext4 /dev/mapper/encr-SD
fi
fi
if [ -d /mnt/extra ]; then
rm -rf /mnt/extra/*
fi
echo "Mounting device"
mount /mounted/device
;;
stop)
mount -r -o remount /mounted/device
;;
*)
echo "Usage is $0 {start|stop}"
;;
esac
Under my current configuration, here is the output of the script:
# ./mount_sd.sh start
Preparing SD card
Checking format
Unlocking SD card
Segmentation fault
Reformatting
Segmentation fault
Checkin FS type
Reformatting to ext4
mke2fs 1.43.4 (31-Jan-2017)
The file /dev/mapper/encr-SD does not exist and no size was specified.
Mounting device
mount: mounting /dev/mapper/encr-SD on /mounted/device failed: No such file or directory
It appears that the cryptsetup
calls are segfaulting. Attached as log.txt is the results of cat /path/to/password | strace cryptsetup --debug luksOpen /dev/mmcblk0 encr-SD
.
I'm not sure what happens after the ioctl that causes a segfault, but any help would be greatly appreciated!