Browse Source

Enable building of netlink_crypto decoder without linux/cryptouser.h

* xlat/crypto_msgs.in: New file.
* configure.ac (AC_CHECK_TYPES): Check for struct crypto_user_alg.
* netlink.c: Include "xlat/crypto_msgs.h" with XLAT_MACROS_ONLY defined.
(netlink_decoders[]): Remove HAVE_LINUX_CRYPTOUSER_H guard around
[NETLINK_CRYPTO] item.
* netlink_crypto.c: Remove HAVE_LINUX_CRYPTOUSER_H guard; include
<linux/cryptouser.h> under HAVE_LINUX_CRYPTOUSER_H; include
"xlat/crypto_msgs.h" with XLAT_MACROS_ONLY defined.
[!CRYPTO_MAX_NAME] (CRYPTO_MAX_NAME): New macro.
(struct_crypto_user_alg, struct_crypto_report_hash,
struct_crypto_report_cipher, struct_crypto_report_blkcipher,
struct_crypto_report_aead, struct_crypto_report_rng): New typedefs.
[HAVE_STRUCT_CRYPTO_USER_ALG]: New static_assert to check
that sizeof(struct crypto_user_alg) has the expected value.
[HAVE_STRUCT_CRYPTO_REPORT_HASH]: New static_assert to check
that sizeof(struct crypto_report_hash) has the expected value.
[HAVE_STRUCT_CRYPTO_REPORT_CIPHER]: New static_assert to check
that sizeof(struct crypto_report_cipher) has the expected value.
[HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER]: New static_assert to check
that sizeof(struct crypto_report_blkcipher) has the expected value.
[HAVE_STRUCT_CRYPTO_REPORT_AEAD]: New static_assert to check
that sizeof(struct crypto_report_aead) has the expected value.
[HAVE_STRUCT_CRYPTO_REPORT_RNG]: New static_assert to check
that sizeof(struct crypto_report_rng) has the expected value.
(decode_crypto_report_hash) [!HAVE_STRUCT_CRYPTO_REPORT_HASH]: Remove.
(decode_crypto_report_hash): Change type of rhash to
struct_crypto_report_hash.
(decode_crypto_report_blkcipher) [!HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER]:
Remove.
(decode_crypto_report_blkcipher): Change type of rblkcipher to
struct_crypto_report_blkcipher.
(decode_crypto_report_aead) [!HAVE_STRUCT_CRYPTO_REPORT_AEAD]: Remove.
(decode_crypto_report_aead): Change type of raead to
struct_crypto_report_aead.
(decode_crypto_report_rng) [!HAVE_STRUCT_CRYPTO_REPORT_RNG]: Remove.
(decode_crypto_report_rng): Change type of rrng to
struct_crypto_report_rng.
(decode_crypto_report_cipher) [!HAVE_STRUCT_CRYPTO_REPORT_CIPHER]:
Remove.
(decode_crypto_report_cipher): Change type of rcipher to
struct_crypto_report_cipher.
(decode_crypto_user_alg): Change type of alg to struct_crypto_user_alg.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1758201
Eugene Syromyatnikov 1 month ago
parent
commit
f1d273a003
4 changed files with 106 additions and 33 deletions
  1. 1
    0
      configure.ac
  2. 4
    2
      netlink.c
  3. 94
    31
      netlink_crypto.c
  4. 7
    0
      xlat/crypto_msgs.in

+ 1
- 0
configure.ac View File

@@ -333,6 +333,7 @@ AC_CHECK_TYPES(m4_normalize([
333 333
 #include <linux/fcntl.h>])
334 334
 
335 335
 AC_CHECK_TYPES(m4_normalize([
336
+	struct crypto_user_alg,
336 337
 	struct crypto_report_aead,
337 338
 	struct crypto_report_blkcipher,
338 339
 	struct crypto_report_cipher,

+ 4
- 2
netlink.c View File

@@ -40,6 +40,10 @@
40 40
 #include "xlat/nl_xfrm_types.h"
41 41
 #include "xlat/nlmsgerr_attrs.h"
42 42
 
43
+# define XLAT_MACROS_ONLY
44
+#  include "xlat/crypto_msgs.h"
45
+# undef XLAT_MACROS_ONLY
46
+
43 47
 /*
44 48
  * Fetch a struct nlmsghdr from the given address.
45 49
  */
@@ -533,9 +537,7 @@ decode_nlmsgerr(struct tcb *const tcp,
533 537
 }
534 538
 
535 539
 static const netlink_decoder_t netlink_decoders[] = {
536
-#ifdef HAVE_LINUX_CRYPTOUSER_H
537 540
 	[NETLINK_CRYPTO] = decode_netlink_crypto,
538
-#endif
539 541
 #ifdef HAVE_LINUX_NETFILTER_NFNETLINK_H
540 542
 	[NETLINK_NETFILTER] = decode_netlink_netfilter,
541 543
 #endif

+ 94
- 31
netlink_crypto.c View File

@@ -8,16 +8,101 @@
8 8
 
9 9
 #include "defs.h"
10 10
 
11
-#ifdef HAVE_LINUX_CRYPTOUSER_H
12
-
13 11
 # include "netlink.h"
14 12
 # include "nlattr.h"
15 13
 # include "print_fields.h"
16 14
 
17
-# include <linux/cryptouser.h>
15
+# if HAVE_LINUX_CRYPTOUSER_H
16
+#  include <linux/cryptouser.h>
17
+# endif
18 18
 
19 19
 # include "xlat/crypto_nl_attrs.h"
20 20
 
21
+# define XLAT_MACROS_ONLY
22
+#  include "xlat/crypto_msgs.h"
23
+# undef XLAT_MACROS_ONLY
24
+
25
+
26
+# ifndef CRYPTO_MAX_NAME
27
+#  define CRYPTO_MAX_NAME 64
28
+# endif
29
+
30
+typedef struct {
31
+	char cru_name[CRYPTO_MAX_NAME];
32
+	char cru_driver_name[CRYPTO_MAX_NAME];
33
+	char cru_module_name[CRYPTO_MAX_NAME];
34
+	uint32_t cru_type;
35
+	uint32_t cru_mask;
36
+	uint32_t cru_refcnt;
37
+	uint32_t cru_flags;
38
+} struct_crypto_user_alg;
39
+
40
+typedef struct {
41
+	char type[CRYPTO_MAX_NAME];
42
+	uint32_t blocksize;
43
+	uint32_t digestsize;
44
+} struct_crypto_report_hash;
45
+
46
+typedef struct {
47
+	char type[CRYPTO_MAX_NAME];
48
+	uint32_t blocksize;
49
+	uint32_t min_keysize;
50
+	uint32_t max_keysize;
51
+} struct_crypto_report_cipher;
52
+
53
+typedef struct {
54
+	char type[CRYPTO_MAX_NAME];
55
+	char geniv[CRYPTO_MAX_NAME];
56
+	uint32_t blocksize;
57
+	uint32_t min_keysize;
58
+	uint32_t max_keysize;
59
+	uint32_t ivsize;
60
+} struct_crypto_report_blkcipher;
61
+
62
+typedef struct {
63
+	char type[CRYPTO_MAX_NAME];
64
+	char geniv[CRYPTO_MAX_NAME];
65
+	uint32_t blocksize;
66
+	uint32_t maxauthsize;
67
+	uint32_t ivsize;
68
+} struct_crypto_report_aead;
69
+
70
+typedef struct {
71
+	char type[CRYPTO_MAX_NAME];
72
+	uint32_t seedsize;
73
+} struct_crypto_report_rng;
74
+
75
+# ifdef HAVE_STRUCT_CRYPTO_USER_ALG
76
+static_assert(sizeof(struct_crypto_user_alg) == sizeof(struct crypto_user_alg),
77
+	      "struct crypto_user_alg mismatch, please update the decoder");
78
+# endif
79
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_HASH
80
+static_assert(sizeof(struct_crypto_report_hash)
81
+	      == sizeof(struct crypto_report_hash),
82
+	      "struct crypto_report_hash mismatch, please update the decoder");
83
+# endif
84
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_CIPHER
85
+static_assert(sizeof(struct_crypto_report_cipher)
86
+	      == sizeof(struct crypto_report_cipher),
87
+	      "struct crypto_report_cipher mismatch, please update the decoder");
88
+# endif
89
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER
90
+static_assert(sizeof(struct_crypto_report_blkcipher)
91
+	      == sizeof(struct crypto_report_blkcipher),
92
+	      "struct crypto_report_blkcipher mismatch, please update the decoder");
93
+# endif
94
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_AEAD
95
+static_assert(sizeof(struct_crypto_report_aead)
96
+	      == sizeof(struct crypto_report_aead),
97
+	      "struct crypto_report_aead mismatch, please update the decoder");
98
+# endif
99
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_RNG
100
+static_assert(sizeof(struct_crypto_report_rng)
101
+	      == sizeof(struct crypto_report_rng),
102
+	      "struct crypto_report_rng mismatch, please update the decoder");
103
+# endif
104
+
105
+
21 106
 static bool
22 107
 decode_crypto_report_generic(struct tcb *const tcp,
23 108
 			     const kernel_ulong_t addr,
@@ -37,8 +122,7 @@ decode_crypto_report_hash(struct tcb *const tcp,
37 122
 			  const unsigned int len,
38 123
 			  const void *const opaque_data)
39 124
 {
40
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_HASH
41
-	struct crypto_report_hash rhash;
125
+	struct_crypto_report_hash rhash;
42 126
 
43 127
 	if (len < sizeof(rhash))
44 128
 		printstrn(tcp, addr, len);
@@ -48,9 +132,6 @@ decode_crypto_report_hash(struct tcb *const tcp,
48 132
 		PRINT_FIELD_U(", ", rhash, digestsize);
49 133
 		tprints("}");
50 134
 	}
51
-# else
52
-	printstrn(tcp, addr, len);
53
-# endif
54 135
 
55 136
 	return true;
56 137
 }
@@ -61,8 +142,7 @@ decode_crypto_report_blkcipher(struct tcb *const tcp,
61 142
 			       const unsigned int len,
62 143
 			       const void *const opaque_data)
63 144
 {
64
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER
65
-	struct crypto_report_blkcipher rblkcipher;
145
+	struct_crypto_report_blkcipher rblkcipher;
66 146
 
67 147
 	if (len < sizeof(rblkcipher))
68 148
 		printstrn(tcp, addr, len);
@@ -75,9 +155,6 @@ decode_crypto_report_blkcipher(struct tcb *const tcp,
75 155
 		PRINT_FIELD_U(", ", rblkcipher, ivsize);
76 156
 		tprints("}");
77 157
 	}
78
-# else
79
-	printstrn(tcp, addr, len);
80
-# endif
81 158
 
82 159
 	return true;
83 160
 }
@@ -88,8 +165,7 @@ decode_crypto_report_aead(struct tcb *const tcp,
88 165
 			  const unsigned int len,
89 166
 			  const void *const opaque_data)
90 167
 {
91
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_AEAD
92
-	struct crypto_report_aead raead;
168
+	struct_crypto_report_aead raead;
93 169
 
94 170
 	if (len < sizeof(raead))
95 171
 		printstrn(tcp, addr, len);
@@ -101,9 +177,6 @@ decode_crypto_report_aead(struct tcb *const tcp,
101 177
 		PRINT_FIELD_U(", ", raead, ivsize);
102 178
 		tprints("}");
103 179
 	}
104
-# else
105
-	printstrn(tcp, addr, len);
106
-# endif
107 180
 
108 181
 	return true;
109 182
 }
@@ -114,8 +187,7 @@ decode_crypto_report_rng(struct tcb *const tcp,
114 187
 			 const unsigned int len,
115 188
 			 const void *const opaque_data)
116 189
 {
117
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_RNG
118
-	struct crypto_report_rng rrng;
190
+	struct_crypto_report_rng rrng;
119 191
 
120 192
 	if (len < sizeof(rrng))
121 193
 		printstrn(tcp, addr, len);
@@ -124,9 +196,6 @@ decode_crypto_report_rng(struct tcb *const tcp,
124 196
 		PRINT_FIELD_U(", ", rrng, seedsize);
125 197
 		tprints("}");
126 198
 	}
127
-# else
128
-	printstrn(tcp, addr, len);
129
-# endif
130 199
 
131 200
 	return true;
132 201
 }
@@ -137,8 +206,7 @@ decode_crypto_report_cipher(struct tcb *const tcp,
137 206
 			    const unsigned int len,
138 207
 			    const void *const opaque_data)
139 208
 {
140
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_CIPHER
141
-	struct crypto_report_cipher rcipher;
209
+	struct_crypto_report_cipher rcipher;
142 210
 
143 211
 	if (len < sizeof(rcipher))
144 212
 		printstrn(tcp, addr, len);
@@ -149,9 +217,6 @@ decode_crypto_report_cipher(struct tcb *const tcp,
149 217
 		PRINT_FIELD_U(", ", rcipher, max_keysize);
150 218
 		tprints("}");
151 219
 	}
152
-# else
153
-	printstrn(tcp, addr, len);
154
-# endif
155 220
 
156 221
 	return true;
157 222
 }
@@ -175,7 +240,7 @@ decode_crypto_user_alg(struct tcb *const tcp,
175 240
 		       const kernel_ulong_t addr,
176 241
 		       const unsigned int len)
177 242
 {
178
-	struct crypto_user_alg alg;
243
+	struct_crypto_user_alg alg;
179 244
 
180 245
 	if (len < sizeof(alg))
181 246
 		printstrn(tcp, addr, len);
@@ -220,5 +285,3 @@ decode_netlink_crypto(struct tcb *const tcp,
220 285
 
221 286
 	return true;
222 287
 }
223
-
224
-#endif /* HAVE_LINUX_CRYPTOUSER_H */

+ 7
- 0
xlat/crypto_msgs.in View File

@@ -0,0 +1,7 @@
1
+#sorted
2
+CRYPTO_MSG_NEWALG	0x10
3
+CRYPTO_MSG_DELALG	0x11
4
+CRYPTO_MSG_UPDATEALG	0x12
5
+CRYPTO_MSG_GETALG	0x13
6
+CRYPTO_MSG_DELRNG	0x14
7
+CRYPTO_MSG_GETSTAT	0x15

Loading…
Cancel
Save