keyctl: Fix struct keyctl_dh_params build on Bionic
PATCH 1/1 keyctl: Fix struct keyctl_dh_params build on Bionic
Bionic generates its copy of the UAPI headers with the C++ keyword 'private' renamed to '__linux_private', so its struct keyctl_dh_params only provides the 'priv' alias added in kernel 4.20. Since keyctl25-28 were switched to 'private', they fail to build on Android:
error: no member named 'private' in 'struct keyctl_dh_params'
Detect the 'private' member in configure and access the member via a new KEYCTL_DH_PRIVATE() macro, which falls back to 'priv' when 'private' is not available, similar to FSID_VAL_MEMBER() in lapi/fanotify.h.
Checking for 'private' rather than 'priv' leaves every build whose UAPI headers provide 'private' unchanged, including headers older than 4.20 which lack 'priv'. It also makes 'priv' the default when configure is not run, as in the Android build, which uses a hand-maintained config.h. The LTP fallback definition provides both members.
--- configure.ac | 1 + include/lapi/keyctl.h | 14 ++++++++++++++ testcases/kernel/syscalls/keyctl/keyctl25.c | 5 +++-- testcases/kernel/syscalls/keyctl/keyctl26.c | 5 +++-- testcases/kernel/syscalls/keyctl/keyctl27.c | 5 +++-- testcases/kernel/syscalls/keyctl/keyctl28.c | 2 +- 6 files changed, 25 insertions(+), 7 deletions(-)
configure.ac +1 -0
@@ -302,6 +302,7 @@ AC_CHECK_TYPES([struct uffdio_writeprotect],,,[#include <linux/userfaultfd.h>]) AC_CHECK_TYPES([struct keyctl_dh_params, struct keyctl_kdf_params, struct keyctl_pkey_query, struct keyctl_pkey_params],,, [#include <linux/keyctl.h>]) +AC_CHECK_MEMBERS([struct keyctl_dh_params.private],,,[#include <linux/keyctl.h>]) # Tools knobs
include/lapi/keyctl.h +14 -0
@@ -67,6 +67,20 @@ struct keyctl_dh_params { };#endif +/** +* KEYCTL_DH_PRIVATE - Access the private key in struct keyctl_dh_params. +* @params: Pointer to struct keyctl_dh_params. +* +* Uses 'private' if the UAPI headers provide it, 'priv' otherwise. UAPI +* headers older than 4.20 provide only 'private'. Bionic renames 'private' +* (a C++ keyword) to '__linux_private', so only 'priv' is usable there. +*/ +#ifdef HAVE_STRUCT_KEYCTL_DH_PARAMS_PRIVATE +# define KEYCTL_DH_PRIVATE (params) ((params)->private) +#else +# define KEYCTL_DH_PRIVATE (params) ((params)->priv) +#endif +#ifndef HAVE_STRUCT_KEYCTL_KDF_PARAMS struct keyctl_kdf_params { char *hashname;
testcases/kernel/syscalls/keyctl/keyctl25.c +3 -2
@@ -22,8 +22,9 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); - dh_params->private =SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), -KEY_SPEC_PROCESS_KEYRING ); +KEYCTL_DH_PRIVATE (dh_params) = +SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), +KEY_SPEC_PROCESS_KEYRING ); dh_params->prime =SAFE_NEW_USER_KEY ("dh_prime" , dh_prime,sizeof (dh_prime),KEY_SPEC_PROCESS_KEYRING ); dh_params->base = SAFE_NEW_USER_KEY("dh_base", dh_base, sizeof(dh_base),
testcases/kernel/syscalls/keyctl/keyctl26.c +3 -2
@@ -21,8 +21,9 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); - dh_params->private =SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), -KEY_SPEC_PROCESS_KEYRING ); +KEYCTL_DH_PRIVATE (dh_params) = +SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), +KEY_SPEC_PROCESS_KEYRING ); dh_params->prime =SAFE_NEW_USER_KEY ("dh_prime" , dh_prime,sizeof (dh_prime),KEY_SPEC_PROCESS_KEYRING ); dh_params->base = SAFE_NEW_USER_KEY("dh_base", dh_base, sizeof(dh_base),
testcases/kernel/syscalls/keyctl/keyctl27.c +3 -2
@@ -27,8 +27,9 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); - dh_params->private =SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), -KEY_SPEC_PROCESS_KEYRING ); +KEYCTL_DH_PRIVATE (dh_params) = +SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), +KEY_SPEC_PROCESS_KEYRING ); dh_params->prime =SAFE_NEW_USER_KEY ("dh_prime" , dh_prime,sizeof (dh_prime),KEY_SPEC_PROCESS_KEYRING ); dh_params->base = SAFE_NEW_USER_KEY("dh_base", dh_base, sizeof(dh_base),
testcases/kernel/syscalls/keyctl/keyctl28.c +1 -1
@@ -78,7 +78,7 @@ static void setup(void) key_base =SAFE_NEW_USER_KEY ("dh_base" , dh_base,sizeof (dh_base),KEY_SPEC_PROCESS_KEYRING ); - dh_params->private = key_priv; +KEYCTL_DH_PRIVATE (dh_params) = key_priv; dh_params->prime = key_prime; dh_params->base = key_base;
Signature · 5 lines
2.56.0.rc1.315.gc6ed9934b7-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wake,
Quoted 1 line · Wake Liu
keyctl: Fix struct
keyctl_dh_paramsbuild on Bionic
Verdict - Reviewed
Pre-existing issue (low severity, not introduced by this patch):
In include/lapi/keyctl.h:55-56, keyctl_join_session_keyring() uses KEYCTL_JOIN_SESSION_KEYRING before its fallback definition. When HAVE_LINUX_KEYCTL_H is unset, including this header fails to compile; the same failure occurs with the parent commit. Move the fallback definition before the helper in a separate change.
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wake Liu, Cyril,
Quoted 1 line
Bionic generates its copy of the UAPI headers with the C++ keyword
Ah, we forget on the most used C++ libc when we prepared 71353a6c009b.
Quoted 11 lines
'private' renamed to '
__linux_private', so its structkeyctl_dh_paramsonly provides the 'priv' alias added in kernel 4.20. Since keyctl25-28 were switched to 'private', they fail to build on Android:error: no member named 'private' in 'struct
keyctl_dh_params'Detect the 'private' member in configure and access the member via a new
KEYCTL_DH_PRIVATE()macro, which falls back to 'priv' when 'private' is not available, similar toFSID_VAL_MEMBER()inlapi/fanotify.h.
Quoted 8 lines
Checking for 'private' rather than 'priv' leaves every build whose UAPI headers provide 'private' unchanged, including headers older than 4.20 which lack 'priv'. It also makes 'priv' the default when configure is not run, as in the Android build, which uses a hand-maintained
config.h. The LTP fallback definition provides both members.Fixes 71353a6c009b ("keyctl: Use struct keyctl_dh_params 'private' instead of 'priv'")Signed-off-by Wake Liu <[email protected]>
Looks like we cannot avoid struct keyctl_dh_params.private. Make sense. Cc Cyril just in case he has some different idea.
Kind regards,
Petr
Quoted 62 lines
--- configure.ac | 1 + include/lapi/keyctl.h | 14 ++++++++++++++ testcases/kernel/syscalls/keyctl/keyctl25.c | 5 +++-- testcases/kernel/syscalls/keyctl/keyctl26.c | 5 +++-- testcases/kernel/syscalls/keyctl/keyctl27.c | 5 +++-- testcases/kernel/syscalls/keyctl/keyctl28.c | 2 +- 6 files changed, 25 insertions(+), 7 deletions(-)configure.ac +1
-0@@ -302,6 +302,7 @@ AC_CHECK_TYPES([struct uffdio_writeprotect],,,[#include <linux/userfaultfd.h>]) AC_CHECK_TYPES([struct keyctl_dh_params, struct keyctl_kdf_params, struct keyctl_pkey_query, struct keyctl_pkey_params],,, [#include <linux/keyctl.h>]) +AC_CHECK_MEMBERS([struct keyctl_dh_params.private],,,[#include <linux/keyctl.h>]) # Tools knobsinclude/lapi/keyctl.h +14
-0@@ -67,6 +67,20 @@ struct keyctl_dh_params { };#endif +/** +* KEYCTL_DH_PRIVATE - Access the private key in struct keyctl_dh_params. +* @params: Pointer to struct keyctl_dh_params. +* +* Uses 'private' if the UAPI headers provide it, 'priv' otherwise. UAPI +* headers older than 4.20 provide only 'private'. Bionic renames 'private' +* (a C++ keyword) to '__linux_private', so only 'priv' is usable there. +*/ +#ifdef HAVE_STRUCT_KEYCTL_DH_PARAMS_PRIVATE +# define KEYCTL_DH_PRIVATE (params) ((params)->private) +#else +# define KEYCTL_DH_PRIVATE (params) ((params)->priv) +#endif +#ifndef HAVE_STRUCT_KEYCTL_KDF_PARAMS struct keyctl_kdf_params { char *hashname;testcases/kernel/syscalls/keyctl/keyctl25.c +3
-2@@ -22,8 +22,9 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); - dh_params->private =SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), -KEY_SPEC_PROCESS_KEYRING ); +KEYCTL_DH_PRIVATE (dh_params) = +SAFE_NEW_USER_KEY ("dh_priv" , dh_priv,sizeof (dh_priv), +KEY_SPEC_PROCESS_KEYRING ); dh_params->prime =SAFE_NEW_USER_KEY ("dh_prime" , dh_prime,sizeof (dh_prime),KEY_SPEC_PROCESS_KEYRING ); dh_params->base = SAFE_NEW_USER_KEY("dh_base", dh_base, sizeof(dh_base),
...
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 23 lines
Hi Wake Liu, Cyril,
Quoted 1 line
Bionic generates its copy of the UAPI headers with the C++ keyword
Ah, we forget on the most used C++ libc when we prepared
71353a6c009b.Quoted 16 lines
'private' renamed to '
__linux_private', so its structkeyctl_dh_paramsonly provides the 'priv' alias added in kernel 4.20. Since keyctl25-28 were switched to 'private', they fail to build on Android:error: no member named 'private' in 'struct
keyctl_dh_params'Detect the 'private' member in configure and access the member via a new
KEYCTL_DH_PRIVATE()macro, which falls back to 'priv' when 'private' is not available, similar toFSID_VAL_MEMBER()inlapi/fanotify.h.Checking for 'private' rather than 'priv' leaves every build whose UAPI headers provide 'private' unchanged, including headers older than 4.20 which lack 'priv'. It also makes 'priv' the default when configure is not run, as in the Android build, which uses a hand-maintained
config.h. The LTP fallback definition provides both members.
Quoted 5 lines
Quoted 2 lines
Fixes 71353a6c009b ("keyctl: Use struct keyctl_dh_params 'private' instead of 'priv'")Signed-off-by Wake Liu <[email protected]>Looks like we cannot avoid struct keyctl_dh_params.private. Make sense. Cc Cyril just in case he has some different idea.
Thank you. Indeed this autotools fix is the safest way. I verified the it did not break the original fix in 71353a6c009b (SLE12-SP5) and merged as 6262a5fc31 ("keyctl: Fix struct keyctl_dh_params build on Bionic")
I'm also going to send a follow up to simplify struct keyctl_dh_params again. (Probably union is not needed any more.)
Kind regards,
Petr
Quoted 4 lines
Reviewed-by Petr Vorel <[email protected]>Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp