Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sgi-xp: Use designated initializers

Prepare to mark sensitive kernel structures for randomization by making
sure they're using designated initializers. In this case, no initializers
are needed (they can be NULL initialized and callers adjusted to check
for NULL, which is more efficient than an indirect call).

Cc: Robin Holt <robinmholt@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Christoph Hellwig <hch@infradead.org>

+18 -30
+11 -1
drivers/misc/sgi-xp/xp.h
··· 309 309 xpc_send(short partid, int ch_number, u32 flags, void *payload, 310 310 u16 payload_size) 311 311 { 312 + if (!xpc_interface.send) 313 + return xpNotLoaded; 314 + 312 315 return xpc_interface.send(partid, ch_number, flags, payload, 313 316 payload_size); 314 317 } ··· 320 317 xpc_send_notify(short partid, int ch_number, u32 flags, void *payload, 321 318 u16 payload_size, xpc_notify_func func, void *key) 322 319 { 320 + if (!xpc_interface.send_notify) 321 + return xpNotLoaded; 322 + 323 323 return xpc_interface.send_notify(partid, ch_number, flags, payload, 324 324 payload_size, func, key); 325 325 } ··· 330 324 static inline void 331 325 xpc_received(short partid, int ch_number, void *payload) 332 326 { 333 - return xpc_interface.received(partid, ch_number, payload); 327 + if (xpc_interface.received) 328 + xpc_interface.received(partid, ch_number, payload); 334 329 } 335 330 336 331 static inline enum xp_retval 337 332 xpc_partid_to_nasids(short partid, void *nasids) 338 333 { 334 + if (!xpc_interface.partid_to_nasids) 335 + return xpNotLoaded; 336 + 339 337 return xpc_interface.partid_to_nasids(partid, nasids); 340 338 } 341 339
+7 -29
drivers/misc/sgi-xp/xp_main.c
··· 69 69 EXPORT_SYMBOL_GPL(xpc_registrations); 70 70 71 71 /* 72 - * Initialize the XPC interface to indicate that XPC isn't loaded. 72 + * Initialize the XPC interface to NULL to indicate that XPC isn't loaded. 73 73 */ 74 - static enum xp_retval 75 - xpc_notloaded(void) 76 - { 77 - return xpNotLoaded; 78 - } 79 - 80 - struct xpc_interface xpc_interface = { 81 - (void (*)(int))xpc_notloaded, 82 - (void (*)(int))xpc_notloaded, 83 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded, 84 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func, 85 - void *))xpc_notloaded, 86 - (void (*)(short, int, void *))xpc_notloaded, 87 - (enum xp_retval(*)(short, void *))xpc_notloaded 88 - }; 74 + struct xpc_interface xpc_interface = { }; 89 75 EXPORT_SYMBOL_GPL(xpc_interface); 90 76 91 77 /* ··· 101 115 void 102 116 xpc_clear_interface(void) 103 117 { 104 - xpc_interface.connect = (void (*)(int))xpc_notloaded; 105 - xpc_interface.disconnect = (void (*)(int))xpc_notloaded; 106 - xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16)) 107 - xpc_notloaded; 108 - xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *, 109 - u16, xpc_notify_func, 110 - void *))xpc_notloaded; 111 - xpc_interface.received = (void (*)(short, int, void *)) 112 - xpc_notloaded; 113 - xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *)) 114 - xpc_notloaded; 118 + memset(&xpc_interface, 0, sizeof(xpc_interface)); 115 119 } 116 120 EXPORT_SYMBOL_GPL(xpc_clear_interface); 117 121 ··· 164 188 165 189 mutex_unlock(&registration->mutex); 166 190 167 - xpc_interface.connect(ch_number); 191 + if (xpc_interface.connect) 192 + xpc_interface.connect(ch_number); 168 193 169 194 return xpSuccess; 170 195 } ··· 214 237 registration->assigned_limit = 0; 215 238 registration->idle_limit = 0; 216 239 217 - xpc_interface.disconnect(ch_number); 240 + if (xpc_interface.disconnect) 241 + xpc_interface.disconnect(ch_number); 218 242 219 243 mutex_unlock(&registration->mutex); 220 244