Fwd: sign-file.c:149:17: warning: implicit declaration of function ‘ENGINE_load_builtin_engines’

From: Bagas Sanjaya
Date: Thu Nov 16 2023 - 18:41:36 EST


Hi,

I notice a bug report on Bugzilla [1]. Quoting from it:

> This feels like the linker is confused about where to find libssl.so.3
> and/or libcrypto.so.3 for scripts/sign-file.c :
>
> HOSTCC scripts/sign-file
> scripts/sign-file.c: In function ‘read_private_key’:
> scripts/sign-file.c:149:17: warning: implicit declaration of function ‘ENGINE_load_builtin_engines’ [-Wimplicit-function-declaration]
> 149 | ENGINE_load_builtin_engines();
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:151:21: warning: implicit declaration of function ‘ENGINE_by_id’ [-Wimplicit-function-declaration]
> 151 | e = ENGINE_by_id("pkcs11");
> | ^~~~~~~~~~~~
> scripts/sign-file.c:151:19: warning: assignment to ‘ENGINE *’ {aka ‘struct engine_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 151 | e = ENGINE_by_id("pkcs11");
> | ^
> scripts/sign-file.c:153:21: warning: implicit declaration of function ‘ENGINE_init’ [-Wimplicit-function-declaration]
> 153 | if (ENGINE_init(e))
> | ^~~~~~~~~~~
> scripts/sign-file.c:158:30: warning: implicit declaration of function ‘ENGINE_ctrl_cmd_string’ [-Wimplicit-function-declaration]
> 158 | ERR(!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0),
> | ^~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:114:32: note: in definition of macro ‘ERR’
> 114 | bool __cond = (cond); \
> | ^~~~
> scripts/sign-file.c:160:31: warning: implicit declaration of function ‘ENGINE_load_private_key’ [-Wimplicit-function-declaration]
> 160 | private_key = ENGINE_load_private_key(e, private_key_name,
> | ^~~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:160:29: warning: assignment to ‘EVP_PKEY *’ {aka ‘struct evp_pkey_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 160 | private_key = ENGINE_load_private_key(e, private_key_name,
> | ^
> /usr/local/bin/ld: /var/tmp/root/ccqqhtVK.o: in function `main':
> sign-file.c:(.text.startup+0x346): undefined reference to `ENGINE_load_builtin_engines'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x357): undefined reference to `ENGINE_by_id'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x37e): undefined reference to `ENGINE_init'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x3a8): undefined reference to `ENGINE_ctrl_cmd_string'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x3d3): undefined reference to `ENGINE_load_private_key'
> collect2: error: ld returned 1 exit status
> make[1]: *** [scripts/Makefile.host:111: scripts/sign-file] Error 1
> make: *** [Makefile:1273: scripts] Error 2
>
>
> If I try to just deal with the sign-file.c by itself I see that I can compile
> and link fine with OpenSSL 3.1.4 :
>
> e#
> e# which openssl
> /usr/local/bin/openssl
> e#
> e# ldd /usr/local/bin/openssl
> linux-vdso.so.1 (0x00007ffcfb3f7000)
> libssl.so.3 => /usr/local/lib/libssl.so.3 (0x00007f6f3b2fb000)
> libcrypto.so.3 => /usr/local/lib/libcrypto.so.3 (0x00007f6f3ac00000)
> libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f6f3b2d3000)
> libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6f3aa1f000)
> /lib64/ld-linux-x86-64.so.2 (0x00007f6f3b3e5000)
> e#
> e# openssl version
> OpenSSL 3.1.4 24 Oct 2023 (Library: OpenSSL 3.1.4 24 Oct 2023)
> e#
>
> I can compile the source fine ( with strange warnings ) with the
> latest OpenSSL bits :
>
>
> e# /usr/local/gcc13/bin/gcc -c -g -O0 -m64 -I/usr/local/include -I/usr/local/include/openssl -o scripts/sign-file.o scripts/sign-file.c
> scripts/sign-file.c: In function ‘read_private_key’:
> scripts/sign-file.c:149:17: warning: implicit declaration of function ‘ENGINE_load_builtin_engines’ [-Wimplicit-function-declaration]
> 149 | ENGINE_load_builtin_engines();
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:151:21: warning: implicit declaration of function ‘ENGINE_by_id’ [-Wimplicit-function-declaration]
> 151 | e = ENGINE_by_id("pkcs11");
> | ^~~~~~~~~~~~
> scripts/sign-file.c:151:19: warning: assignment to ‘ENGINE *’ {aka ‘struct engine_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 151 | e = ENGINE_by_id("pkcs11");
> | ^
> scripts/sign-file.c:117:25: warning: implicit declaration of function ‘errx’ [-Wimplicit-function-declaration]
> 117 | errx(1, fmt, ## __VA_ARGS__); \
> | ^~~~
> scripts/sign-file.c:152:17: note: in expansion of macro ‘ERR’
> 152 | ERR(!e, "Load PKCS#11 ENGINE");
> | ^~~
> scripts/sign-file.c:153:21: warning: implicit declaration of function ‘ENGINE_init’ [-Wimplicit-function-declaration]
> 153 | if (ENGINE_init(e))
> | ^~~~~~~~~~~
> scripts/sign-file.c:158:30: warning: implicit declaration of function ‘ENGINE_ctrl_cmd_string’ [-Wimplicit-function-declaration]
> 158 | ERR(!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0),
> | ^~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:114:32: note: in definition of macro ‘ERR’
> 114 | bool __cond = (cond); \
> | ^~~~
> scripts/sign-file.c:160:31: warning: implicit declaration of function ‘ENGINE_load_private_key’ [-Wimplicit-function-declaration]
> 160 | private_key = ENGINE_load_private_key(e, private_key_name,
> | ^~~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:160:29: warning: assignment to ‘EVP_PKEY *’ {aka ‘struct evp_pkey_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 160 | private_key = ENGINE_load_private_key(e, private_key_name,
> | ^
> e#
>
> Then we link gently :
>
> e# /usr/local/gcc13/bin/gcc -g -O0 -m64 -L/usr/local/include -L/usr/local/include/openssl -Wl,-rpath=/usr/local/lib,-enable-new-dtags -o scripts/sign-file scripts/sign-file.o -lssl -lcrypto
> e#
>
> e# ls -l scripts/sign-file
> -rwxr-xr-x 1 root root 37800 Nov 16 16:22 scripts/sign-file
> e#
> e# readelf -delV scripts/sign-file | grep -E 'NEED|NAME|PATH'
> [10] .gnu.version_r VERNEED 0000000000400be8 00000be8
> 0x0000000000000001 (NEEDED) Shared library: [libssl.so.3]
> 0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.3]
> 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
> 0x000000000000001d (RUNPATH) Library runpath: [/usr/local/lib]
> 0x000000006ffffffe (VERNEED) 0x400be8
> 0x000000006fffffff (VERNEEDNUM) 2
> e#
> e# ldd scripts/sign-file
> linux-vdso.so.1 (0x00007ffed8579000)
> libssl.so.3 => /usr/local/lib/libssl.so.3 (0x00007fde99d2e000)
> libcrypto.so.3 => /usr/local/lib/libcrypto.so.3 (0x00007fde99800000)
> libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fde9961f000)
> libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fde99600000)
> /lib64/ld-linux-x86-64.so.2 (0x00007fde99e18000)
> e#
> e# scripts/sign-file -foo
> scripts/sign-file: invalid option -- 'f'
> Usage: scripts/sign-file [-dp] <hash algo> <key> <x509> <module> [<dest>]
> scripts/sign-file -s <raw sig> <hash algo> <x509> <module> [<dest>]
> e#
>
> * * * T H E R E F O R E I T C O M P I L E S F I N E * * *
>
> However my Linux kernel compile fails on that :
>
> e# /usr/bin/time -p /usr/bin/nice -n +18 make 2>&1 | tee ../linux-6.1.62.make_j1.log
> HOSTCC scripts/sign-file
> scripts/sign-file.c: In function ‘read_private_key’:
> scripts/sign-file.c:149:17: warning: implicit declaration of function ‘ENGINE_load_builtin_engines’ [-Wimplicit-function-declaration]
> 149 | ENGINE_load_builtin_engines();
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:151:21: warning: implicit declaration of function ‘ENGINE_by_id’ [-Wimplicit-function-declaration]
> 151 | e = ENGINE_by_id("pkcs11");
> | ^~~~~~~~~~~~
> scripts/sign-file.c:151:19: warning: assignment to ‘ENGINE *’ {aka ‘struct engine_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 151 | e = ENGINE_by_id("pkcs11");
> | ^
> scripts/sign-file.c:153:21: warning: implicit declaration of function ‘ENGINE_init’ [-Wimplicit-function-declaration]
> 153 | if (ENGINE_init(e))
> | ^~~~~~~~~~~
> scripts/sign-file.c:158:30: warning: implicit declaration of function ‘ENGINE_ctrl_cmd_string’ [-Wimplicit-function-declaration]
> 158 | ERR(!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0),
> | ^~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:114:32: note: in definition of macro ‘ERR’
> 114 | bool __cond = (cond); \
> | ^~~~
> scripts/sign-file.c:160:31: warning: implicit declaration of function ‘ENGINE_load_private_key’ [-Wimplicit-function-declaration]
> 160 | private_key = ENGINE_load_private_key(e, private_key_name,
> | ^~~~~~~~~~~~~~~~~~~~~~~
> scripts/sign-file.c:160:29: warning: assignment to ‘EVP_PKEY *’ {aka ‘struct evp_pkey_st *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> 160 | private_key = ENGINE_load_private_key(e, private_key_name,
> | ^
> /usr/local/bin/ld: /var/tmp/root/ccqqhtVK.o: in function `main':
> sign-file.c:(.text.startup+0x346): undefined reference to `ENGINE_load_builtin_engines'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x357): undefined reference to `ENGINE_by_id'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x37e): undefined reference to `ENGINE_init'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x3a8): undefined reference to `ENGINE_ctrl_cmd_string'
> /usr/local/bin/ld: sign-file.c:(.text.startup+0x3d3): undefined reference to `ENGINE_load_private_key'
> collect2: error: ld returned 1 exit status
> make[1]: *** [scripts/Makefile.host:111: scripts/sign-file] Error 1
> make: *** [Makefile:1273: scripts] Error 2
> real 0.92
> user 0.74
> sys 0.18
> e#
>
> Looks like some confusion with the linker ?
>
> Setting LDFLAGS=-rpath=/usr/local/openssl/lib -enable-new-dtag seems to mean
> nothing.
>
> Not related to https://bugzilla.kernel.org/show_bug.cgi?id=215750 but I *feel* that
> this code needs a hug.

See Bugzilla for the full thread.

AFAIK, this looks like a bug when the kernel is compiled against custom
(non-system) version of OpenSSL library.

Thanks.

[1]: https://bugzilla.kernel.org/show_bug.cgi?id=218154

--
An old man doll... just what I always wanted! - Clara