#1033551 cryptsetup-bin: cryptsetup -v isLuks: doesn't work as documented

Package:
cryptsetup-bin
Source:
cryptsetup-bin
Description:
disk encryption support - command line tools
Submitter:
Alexis Huxley
Date:
2023-03-27 12:33:03 UTC
Severity:
normal
Tags:
#1033551#5
Date:
2023-03-27 10:35:39 UTC
From:
To:
Dear Maintainer,

Allocate a volume (in my case my only Debian 12 system uses
ZFS, but the result is the same with Debian 11 on LVM):

	testaroli# zfs create -V 100m zpool0/test
	testaroli#

Check if it is Luks device, which of course it is not
as it's only just been created:

	testaroli# cryptsetup isLuks /dev/zvol/zpool0/test
	testaroli# echo $?
	1
	testaroli#

The cryptsetup-isLuks man page says regarding isLuks that
the synopsis is:

	cryptsetup isLuks [<options>] <device>

and states:

	Use option -v to get human-readable feedback.

So here's are three calls with the '-v' first in the documented
position relative to other args and then in every other conceivable
place:

	testaroli# cryptsetup isLuks -v /dev/zvol/zpool0/test
	Command failed with code -1 (wrong or missing parameters).
	testaroli# cryptsetup -v isLuks /dev/zvol/zpool0/test
	Command failed with code -1 (wrong or missing parameters).
	testaroli# cryptsetup isLuks /dev/zvol/zpool0/test -v
	Command failed with code -1 (wrong or missing parameters).
	testaroli#

All fail.

I'm happy to test new versions, etc.

Alexis

#1033551#10
Date:
2023-03-27 11:15:39 UTC
From:
To:
Hi,

All 3 work for me in a bookworm VM, please try with `--debug` (with and
without `-v`).

    ~# dpkg -l | grep cryptsetup
    ii  cryptsetup-bin               2:2.6.1-3~deb12u1  amd64        disk encryption support - command line tools
    ii  libcryptsetup12:amd64        2:2.6.1-3~deb12u1  amd64        disk encryption support - shared library
    ~# dd if=/dev/zero bs=1M count=64 of=/tmp/disk.img
    ~# losetup -f /tmp/disk.img
    ~# cryptsetup luksFormat -q /dev/loop0 <<<test
    ~# cryptsetup isLuks /dev/loop0; echo "\`cryptsetup isLuks\` exited with status $?"
    `cryptsetup isLuks` exited with status 0
    ~# cryptsetup isLuks -v /dev/loop0
    Command successful.
    ~# cryptsetup -v isLuks /dev/loop0
    Command successful.
    ~# cryptsetup isLuks /dev/loop0 -v
    Command successful.

#1033551#17
Date:
2023-03-27 12:06:32 UTC
From:
To:
and it works for me *if* - as you did - I format the device.
But if I *don't* format it then I still get the same result,
even with newer packages:

testaroli# dpkg -l | grep cryptsetup
ii  cryptsetup-bin          2:2.6.1-3  amd64  disk encryption support - command line tools
ii  libcryptsetup12:amd64   2:2.6.1-3  amd64  disk encryption support - shared library
testaroli#
testaroli# dd if=/dev/zero bs=1M count=64 of=/tmp/disk.img
64+0 records in
64+0 records out
67108864 bytes (67 MB, 64 MiB) copied, 0.0806509 s, 832 MB/s
testaroli# cryptsetup isLuks /dev/loop0; echo "\`cryptsetup isLuks\` exited with status $?"
`cryptsetup isLuks` exited with status 1
testaroli# cryptsetup isLuks -v /dev/loop0
Command failed with code -1 (wrong or missing parameters).
testaroli#

It should say "not Luks" or perhaps "invalid device", but
"wrong or missing parameters" is wrong.

With --debug:

testaroli# cryptsetup isLuks --debug -v /dev/loop0
# cryptsetup 2.6.1 processing "cryptsetup isLuks --debug -v /dev/loop0"
# Verifying parameters for command isLuks.
# Running command isLuks.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /dev/loop0.
# Trying to open and read device /dev/loop0 with direct-io.
# Trying to open device /dev/loop0 without direct-io.
# Initialising device-mapper backend library.
# Trying to load any crypt type from device /dev/loop0.
# Crypto backend (OpenSSL 3.0.8 7 Feb 2023 [default][legacy]) initialized in cryptsetup library version 2.6.1.
# Detected kernel Linux 6.1.0-6-amd64 x86_64.
# Loading LUKS2 header (repair disabled).
# Acquiring read lock for device /dev/loop0.
# Opening lock resource file /run/cryptsetup/L_7:0
# Verifying lock handle for /dev/loop0.
# Device /dev/loop0 READ lock taken.
# Trying to read primary LUKS2 header at offset 0x0.
# Opening locked device /dev/loop0
# Verifying locked device handle (bdev)
# Trying to read secondary LUKS2 header at offset 0x4000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x8000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x10000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x20000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x40000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x80000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x100000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x200000.
# Reusing open ro fd on device /dev/loop0
# Trying to read secondary LUKS2 header at offset 0x400000.
# Reusing open ro fd on device /dev/loop0
# LUKS2 header read failed (-5).
# Device /dev/loop0 READ lock released.
# Releasing crypt device /dev/loop0 context.
# Releasing device-mapper backend.
# Closing read only fd for /dev/loop0.
Command failed with code -1 (wrong or missing parameters).
testaroli#

Alexis

#1033551#22
Date:
2023-03-27 12:29:39 UTC
From:
To:
Control: tag -1 - moreinfo unreproducible
Control: tag -1 + upstream
Control: retitle -1 cryptsetup-bin: `cryptsetup -v isLuks` produces misleading output when the device isn't LUKS

Ah I see, it works as documented then.  The error message could arguably
be improved, but I guess the return status can't be changed anymore, and
show_status() maps it as follows:

    if (errcode == 1)
        crypt_error = _("wrong or missing parameters");
    else if (errcode == 2)
        crypt_error = _("no permission or bad passphrase");
    else if (errcode == 3)
        crypt_error = _("out of memory");
    else if (errcode == 4)
        crypt_error = _("wrong device or file specified");
    else if (errcode == 5)
        crypt_error = _("device already exists or device is busy");
    else
        crypt_error = _("unknown error");

FWIW error code 1 (wrong or missing parameters) is also returned when
trying to format/open a device using an unsupported cipher.