1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
From ed1e72e2a3aecd894ca1a029996ef70846e30781 Mon Sep 17 00:00:00 2001
From: Cheyenne Wills <cwills@sinenomine.net>
Date: Tue, 25 Feb 2025 20:09:12 -0700
Subject: [PATCH 2/2] afs: Init structures via designated initializers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When the Linux kernel is configured with CONFIG_RANDSTRUCT=y, the
following error occurs when building the openafs kernel module:
src/libafs/MODLOAD-6.12.0-SP/rand-timer-kernel.c:46:5: error: positional initialization of field in ‘struct’ declared with ‘designated_init’ attribute [-Werror=designated-init]
46 | timer_seed,
| ^~~~~~~~~~
When the Linux kernel is configured with CONFIG_RANDSTRUCT=y, the Linux
build uses a Linux kernel-specific GCC plugin
(scripts/gcc-plugins/randomize_layout_plugin.c) that analyzes structures
and will add the designated_init attribute to any structure that is
determined to be a "pure operations struct" (i.e. contains only function
pointers or nested pure ops structs/unions). This is done so the plugin
can then randomize the layout. This causes some of our structures to be
flagged with the designated_init attribute, which triggers
-Werror=designated-init when we don't use designated initializers.
Within the Linux specific directory, src/afs/LINUX, the code already
uses designated initializers, however some of the shared code within
src/afs or that is included in the build for the kernel module still use
positional initialization when initializing pure operations structures.
Update the shared code that is used when building the Linux kernel
module to use designated initializers via the AFS_STRUCT_INIT macro.
Use a consistent alignment, and add trailing comma on the last
element, change 0 to NULL where applicable.
There are no functional changes within this commit.
Note: For consistency, all the initializers for rx_securityOps are being
updated even though not all of the files are part of the Linux kernel
module (e.g. rxkad_server.c).
Note: This error was discovered by an automated process that is used
by the Gentoo organization to test building packages with a hardened
Linux kernel.
Reviewed-on: https://gerrit.openafs.org/16290
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Andrew Deason <adeason@sinenomine.net>
(cherry picked from commit e94c183faef42e5ffe85c157ede008f2817bdefd)
[cwills@sinenomine.net changes to rxgk not applicable to 1.8.x]
Change-Id: I56ebb7d34718eef6c5bfbba98e3fb4e350a5129f
---
src/afs/afs_fetchstore.c | 20 ++++++++---------
src/crypto/hcrypto/kernel/rand-timer.c | 14 ++++++------
src/rxkad/rxkad_client.c | 30 +++++++++++++-------------
src/rxkad/rxkad_server.c | 30 +++++++++++++-------------
4 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/src/afs/afs_fetchstore.c b/src/afs/afs_fetchstore.c
index 5baf371a2c6a..5b9e08c3fdec 100644
--- a/src/afs/afs_fetchstore.c
+++ b/src/afs/afs_fetchstore.c
@@ -844,20 +844,20 @@ rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
static
struct fetchOps rxfs_fetchUfsOps = {
- rxfs_fetchMore,
- rxfs_fetchUfsRead,
- rxfs_fetchUfsWrite,
- rxfs_fetchClose,
- rxfs_fetchDestroy
+ AFS_STRUCT_INIT(.more, rxfs_fetchMore),
+ AFS_STRUCT_INIT(.read, rxfs_fetchUfsRead),
+ AFS_STRUCT_INIT(.write, rxfs_fetchUfsWrite),
+ AFS_STRUCT_INIT(.close, rxfs_fetchClose),
+ AFS_STRUCT_INIT(.destroy, rxfs_fetchDestroy),
};
static
struct fetchOps rxfs_fetchMemOps = {
- rxfs_fetchMore,
- rxfs_fetchMemRead,
- rxfs_fetchMemWrite,
- rxfs_fetchClose,
- rxfs_fetchDestroy
+ AFS_STRUCT_INIT(.more, rxfs_fetchMore),
+ AFS_STRUCT_INIT(.read, rxfs_fetchMemRead),
+ AFS_STRUCT_INIT(.write, rxfs_fetchMemWrite),
+ AFS_STRUCT_INIT(.close, rxfs_fetchClose),
+ AFS_STRUCT_INIT(.destroy, rxfs_fetchDestroy),
};
static afs_int32
diff --git a/src/crypto/hcrypto/kernel/rand-timer.c b/src/crypto/hcrypto/kernel/rand-timer.c
index 3a7023555b67..6ef71737cdeb 100644
--- a/src/crypto/hcrypto/kernel/rand-timer.c
+++ b/src/crypto/hcrypto/kernel/rand-timer.c
@@ -5,7 +5,7 @@
* Contains no copyrightable content.
*/
#include <config.h>
-
+#include <stds.h>
#include <rand.h>
#include "randi.h"
@@ -43,12 +43,12 @@ timer_status(void)
}
const RAND_METHOD hc_rand_timer_method = {
- timer_seed,
- timer_bytes,
- timer_cleanup,
- timer_add,
- timer_pseudorand,
- timer_status
+ AFS_STRUCT_INIT(.seed, timer_seed),
+ AFS_STRUCT_INIT(.bytes, timer_bytes),
+ AFS_STRUCT_INIT(.cleanup, timer_cleanup),
+ AFS_STRUCT_INIT(.add, timer_add),
+ AFS_STRUCT_INIT(.pseudorand, timer_pseudorand),
+ AFS_STRUCT_INIT(.status, timer_status),
};
const RAND_METHOD *
diff --git a/src/rxkad/rxkad_client.c b/src/rxkad/rxkad_client.c
index 1f760b8c0e66..79ea0cf586b3 100644
--- a/src/rxkad/rxkad_client.c
+++ b/src/rxkad/rxkad_client.c
@@ -50,21 +50,21 @@
#endif /* max */
static struct rx_securityOps rxkad_client_ops = {
- rxkad_Close,
- rxkad_NewConnection, /* every new connection */
- rxkad_PreparePacket, /* once per packet creation */
- 0, /* send packet (once per retrans.) */
- 0,
- 0,
- 0,
- rxkad_GetResponse, /* respond to challenge packet */
- 0,
- rxkad_CheckPacket, /* check data packet */
- rxkad_DestroyConnection,
- rxkad_GetStats,
- 0,
- 0,
- 0,
+ AFS_STRUCT_INIT(.op_Close, rxkad_Close),
+ AFS_STRUCT_INIT(.op_NewConnection, rxkad_NewConnection), /* every new connection */
+ AFS_STRUCT_INIT(.op_PreparePacket, rxkad_PreparePacket), /* once per packet creation */
+ AFS_STRUCT_INIT(.op_SendPacket, NULL), /* send packet (once per retrans.) */
+ AFS_STRUCT_INIT(.op_CheckAuthentication, NULL),
+ AFS_STRUCT_INIT(.op_CreateChallenge, NULL),
+ AFS_STRUCT_INIT(.op_GetChallenge, NULL),
+ AFS_STRUCT_INIT(.op_GetResponse, rxkad_GetResponse), /* respond to challenge packet */
+ AFS_STRUCT_INIT(.op_CheckResponse, NULL),
+ AFS_STRUCT_INIT(.op_CheckPacket, rxkad_CheckPacket), /* check data packet */
+ AFS_STRUCT_INIT(.op_DestroyConnection, rxkad_DestroyConnection),
+ AFS_STRUCT_INIT(.op_GetStats, rxkad_GetStats),
+ AFS_STRUCT_INIT(.op_SetConfiguration, NULL),
+ AFS_STRUCT_INIT(.op_Spare2, NULL),
+ AFS_STRUCT_INIT(.op_Spare3, NULL),
};
/* Allocate a new client security object. Called with the encryption level,
diff --git a/src/rxkad/rxkad_server.c b/src/rxkad/rxkad_server.c
index 07e806bcdf36..766904cea562 100644
--- a/src/rxkad/rxkad_server.c
+++ b/src/rxkad/rxkad_server.c
@@ -43,21 +43,21 @@ afs_int32(*rxkad_AlternateTicketDecoder) (afs_int32, char *, afs_int32,
afs_uint32 *);
static struct rx_securityOps rxkad_server_ops = {
- rxkad_Close,
- rxkad_NewConnection,
- rxkad_PreparePacket, /* once per packet creation */
- 0, /* send packet (once per retrans) */
- rxkad_CheckAuthentication,
- rxkad_CreateChallenge,
- rxkad_GetChallenge,
- 0,
- rxkad_CheckResponse,
- rxkad_CheckPacket, /* check data packet */
- rxkad_DestroyConnection,
- rxkad_GetStats,
- rxkad_SetConfiguration,
- 0, /* spare 2 */
- 0, /* spare 3 */
+ AFS_STRUCT_INIT(.op_Close, rxkad_Close),
+ AFS_STRUCT_INIT(.op_NewConnection, rxkad_NewConnection),
+ AFS_STRUCT_INIT(.op_PreparePacket, rxkad_PreparePacket), /* once per packet creation */
+ AFS_STRUCT_INIT(.op_SendPacket, NULL), /* send packet (once per retrans) */
+ AFS_STRUCT_INIT(.op_CheckAuthentication, rxkad_CheckAuthentication),
+ AFS_STRUCT_INIT(.op_CreateChallenge, rxkad_CreateChallenge),
+ AFS_STRUCT_INIT(.op_GetChallenge, rxkad_GetChallenge),
+ AFS_STRUCT_INIT(.op_GetResponse, NULL),
+ AFS_STRUCT_INIT(.op_CheckResponse, rxkad_CheckResponse),
+ AFS_STRUCT_INIT(.op_CheckPacket, rxkad_CheckPacket), /* check data packet */
+ AFS_STRUCT_INIT(.op_DestroyConnection, rxkad_DestroyConnection),
+ AFS_STRUCT_INIT(.op_GetStats, rxkad_GetStats),
+ AFS_STRUCT_INIT(.op_SetConfiguration, rxkad_SetConfiguration),
+ AFS_STRUCT_INIT(.op_Spare2, NULL), /* spare 2 */
+ AFS_STRUCT_INIT(.op_Spare3, NULL), /* spare 3 */
};
extern afs_uint32 rx_MyMaxSendSize;
--
2.45.3
|