Skip to contentSkip to conversation

keyctl: Fix struct keyctl_dh_params build on Bionic

PATCH In review Wake Liu via ltp 3 participants 5 messages Oct 2 – Oct 13

lore
Share & tools
lore
#0 lore raw

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.

Fixes 71353a6c009b ("keyctl: Use struct keyctl_dh_params 'private' instead of 'priv'")
---
 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
index e979de0e7..4087856c8 100644
@@ -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
index eb4d25c42..788c4d509 100644
@@ -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
index 84e76c019..80a341cf3 100644
@@ -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
index 9488e736f..3d693e0ec 100644
@@ -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
index e69b52064..1ba338dcb 100644
@@ -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
index 15ca3b8fe..4e7710d25 100644
@@ -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
#1 lore raw

Hi Wake,

Quoted 1 line · Wake Liu

keyctl: Fix struct keyctl_dh_params build 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
Reviewed-by on v1 1/1
#2 lore raw
In reply to Wake Liu via 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 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.

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'")

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
index e979de0e7..4087856c8 100644
@@ -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
index eb4d25c42..788c4d509 100644
@@ -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
index 84e76c019..80a341cf3 100644
@@ -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
#3 lore raw

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 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.

Quoted 5 lines
Quoted 2 lines
Fixes 71353a6c009b ("keyctl: Use struct keyctl_dh_params 'private' instead of 'priv'")

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

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp