#13 volume_Key fails to build against cryptsetup-2.0.0_rc0
Closed: Fixed 6 years ago Opened 6 years ago by lawe.

During build:

libtool: compile:  x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I/usr/include/blkid 
-I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I
/usr/include/nss -I/usr/include/nspr -DLOCALEDIR=\"/usr/share/locale\" 
-march=native -mtune=native -O2 -pipe -Wall -W -Wcast-align -Wmissing-noreturn 
-Wnested-externs -Wpointer-arith -Wshadow -Wundef -Wwrite-strings -c 
lib/volume_luks.c  -fPIC -DPIC -o lib/.libs/lib_libvolume_key_la-volume_luks.o
lib/volume_luks.c: In function ‘error_from_cryptsetup’:
lib/volume_luks.c:72:3: warning: implicit declaration of function ‘crypt_get_error’ 
[-Wimplicit-function-declaration]
   crypt_get_error (crypt_msg, sizeof (crypt_msg));
   ^~~~~~~~~~~~~~~
lib/volume_luks.c:72:3: warning: nested extern declaration of ‘crypt_get_error’ 
[-Wnested-externs]

and later during linking:

libtool: link: x86_64-pc-linux-gnu-gcc -march=native -mtune=native -O2 -pipe -Wall 
-W -Wcast-align -Wmissing-noreturn -Wnested-externs -Wpointer-arith -Wshadow 
-Wundef -Wwrite-strings -Wl,-O1 -Wl,--hash-style=gnu -Wl,--sort-common -o 
src/.libs/volume_key src/src_volume_key-volume_key.o  -Wl,--as-needed 
lib/.libs/libvolume_key.so -L/usr/lib64 -lblkid -lgpgme -lassuan -lgpg-error 
-lcryptsetup -lglib-2.0 -lssl3 -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 
lib/.libs/libvolume_key.so: undefined reference to `crypt_get_error'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:953: src/volume_key] Error 1

Thanks for your report.

The alternatives to crypt_get_error are a bit unpalatable, let’s hope for a better error reporting mechanism before libcryptsetup hits 2.0 final.

Try to use this patch (should work both old & new libcryptsetup)
https://github.com/mbroz/volume_key/commit/a41c53d35b594a7fd8d5b92501b4fe52d7252909

Only slightly tested, but the idea is there :)

Thanks, that’s a good starting point.

  • A GError should be set to non-NULL only if the called function fails; this seems like it could (in principle at least, no idea whether in practice) set a GError on success if something is logged.
  • There’s conceptually no guarantee that the error passed to open_crypt_device will be live as long as the returned struct crypt_device *. Yes, it seems to work out that way in the existing callers, but that’s a very risky trap to set up for the future.

I think GError is always set in error_from_cryptsetup() - if it is not set by callback, my_strerror() should set it.
The crypt_device lifetime is always embedded inside your high-level functions that have error as parameter (luks_volume_open, luks_get_secret, luks_load_packet, luks_apply_secret, luks_add_secret, luks_open_with_packet) - IOW inside these function cd is always created and destructed. The GError is available inside of this function scope (and libcryptsetup log callback that set GError is per cd context, after context is destroyed, nobody can call it).

So, I really do not see problem here. The code is not perfect, opening crypt_device for every call is not the best idea as well (it is kind of race) - so I think that patch is adequate for the code.

Anyway, we need to rebuild rawhide now, It would be nice if you accept or modify that patch (volume_key is unfortunately the only package that cannot be rebuild clearly).
Thanks!

I think GError is always set in error_from_cryptsetup() - if it is not set by callback, my_strerror() should set it.

Sure; I was worried about the opposite, error_from_cryptsetup() never being called, everything succeeding, but error still set to non-NULL.

The crypt_device lifetime is always embedded inside your high-level functions that have error as parameter

Right, but that’s not how GErrors usually work. The callee is not supposed to hold on to them. “Yes, it seems to work out that way in the existing callers, but that’s a very risky trap to set up for the future.”

See how luks_get_secret now needs to g_clear_error(error) after nothing ostensibly modifies error.

(Working on this now, based on your patch.)

Commit ecef526 fixes this issue

Login to comment on this ticket.

Metadata