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

sctp: Constify struct sctp_sched_ops

'struct sctp_sched_ops' is not modified in these drivers.

Constifying this structure moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.

On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
8019 568 0 8587 218b net/sctp/stream_sched_fc.o

After:
=====
text data bss dec hex filename
8275 312 0 8587 218b net/sctp/stream_sched_fc.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://patch.msgid.link/dce03527eb7b7cc8a3c26d5cdac12bafe3350135.1761377890.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Christophe JAILLET and committed by
Jakub Kicinski
294bfe03 8443c316

+19 -19
+2 -2
include/net/sctp/stream_sched.h
··· 52 52 53 53 void sctp_sched_dequeue_common(struct sctp_outq *q, struct sctp_chunk *ch); 54 54 int sctp_sched_init_sid(struct sctp_stream *stream, __u16 sid, gfp_t gfp); 55 - struct sctp_sched_ops *sctp_sched_ops_from_stream(struct sctp_stream *stream); 55 + const struct sctp_sched_ops *sctp_sched_ops_from_stream(struct sctp_stream *stream); 56 56 57 57 void sctp_sched_ops_register(enum sctp_sched_type sched, 58 - struct sctp_sched_ops *sched_ops); 58 + const struct sctp_sched_ops *sched_ops); 59 59 void sctp_sched_ops_prio_init(void); 60 60 void sctp_sched_ops_rr_init(void); 61 61 void sctp_sched_ops_fc_init(void);
+1 -1
include/net/sctp/structs.h
··· 1073 1073 struct list_head out_chunk_list; 1074 1074 1075 1075 /* Stream scheduler being used */ 1076 - struct sctp_sched_ops *sched; 1076 + const struct sctp_sched_ops *sched; 1077 1077 1078 1078 unsigned int out_qlen; /* Total length of queued data chunks. */ 1079 1079
+4 -4
net/sctp/stream.c
··· 54 54 55 55 static void sctp_stream_free_ext(struct sctp_stream *stream, __u16 sid) 56 56 { 57 - struct sctp_sched_ops *sched; 57 + const struct sctp_sched_ops *sched; 58 58 59 59 if (!SCTP_SO(stream, sid)->ext) 60 60 return; ··· 130 130 int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, 131 131 gfp_t gfp) 132 132 { 133 - struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 133 + const struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 134 134 int i, ret = 0; 135 135 136 136 gfp |= __GFP_NOWARN; ··· 182 182 183 183 void sctp_stream_free(struct sctp_stream *stream) 184 184 { 185 - struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 185 + const struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 186 186 int i; 187 187 188 188 sched->unsched_all(stream); ··· 207 207 208 208 void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new) 209 209 { 210 - struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 210 + const struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 211 211 212 212 sched->unsched_all(stream); 213 213 sctp_stream_outq_migrate(stream, new, new->outcnt);
+8 -8
net/sctp/stream_sched.c
··· 91 91 { 92 92 } 93 93 94 - static struct sctp_sched_ops sctp_sched_fcfs = { 94 + static const struct sctp_sched_ops sctp_sched_fcfs = { 95 95 .set = sctp_sched_fcfs_set, 96 96 .get = sctp_sched_fcfs_get, 97 97 .init = sctp_sched_fcfs_init, ··· 111 111 112 112 /* API to other parts of the stack */ 113 113 114 - static struct sctp_sched_ops *sctp_sched_ops[SCTP_SS_MAX + 1]; 114 + static const struct sctp_sched_ops *sctp_sched_ops[SCTP_SS_MAX + 1]; 115 115 116 116 void sctp_sched_ops_register(enum sctp_sched_type sched, 117 - struct sctp_sched_ops *sched_ops) 117 + const struct sctp_sched_ops *sched_ops) 118 118 { 119 119 sctp_sched_ops[sched] = sched_ops; 120 120 } ··· 130 130 131 131 static void sctp_sched_free_sched(struct sctp_stream *stream) 132 132 { 133 - struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 133 + const struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 134 134 struct sctp_stream_out_ext *soute; 135 135 int i; 136 136 ··· 148 148 int sctp_sched_set_sched(struct sctp_association *asoc, 149 149 enum sctp_sched_type sched) 150 150 { 151 - struct sctp_sched_ops *old = asoc->outqueue.sched; 151 + const struct sctp_sched_ops *old = asoc->outqueue.sched; 152 152 struct sctp_datamsg *msg = NULL; 153 - struct sctp_sched_ops *n; 153 + const struct sctp_sched_ops *n; 154 154 struct sctp_chunk *ch; 155 155 int i, ret = 0; 156 156 ··· 263 263 264 264 int sctp_sched_init_sid(struct sctp_stream *stream, __u16 sid, gfp_t gfp) 265 265 { 266 - struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 266 + const struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); 267 267 struct sctp_stream_out_ext *ext = SCTP_SO(stream, sid)->ext; 268 268 269 269 INIT_LIST_HEAD(&ext->outq); 270 270 return sched->init_sid(stream, sid, gfp); 271 271 } 272 272 273 - struct sctp_sched_ops *sctp_sched_ops_from_stream(struct sctp_stream *stream) 273 + const struct sctp_sched_ops *sctp_sched_ops_from_stream(struct sctp_stream *stream) 274 274 { 275 275 struct sctp_association *asoc; 276 276
+2 -2
net/sctp/stream_sched_fc.c
··· 188 188 list_del_init(&soute->fc_list); 189 189 } 190 190 191 - static struct sctp_sched_ops sctp_sched_fc = { 191 + static const struct sctp_sched_ops sctp_sched_fc = { 192 192 .set = sctp_sched_fc_set, 193 193 .get = sctp_sched_fc_get, 194 194 .init = sctp_sched_fc_init, ··· 206 206 sctp_sched_ops_register(SCTP_SS_FC, &sctp_sched_fc); 207 207 } 208 208 209 - static struct sctp_sched_ops sctp_sched_wfq = { 209 + static const struct sctp_sched_ops sctp_sched_wfq = { 210 210 .set = sctp_sched_wfq_set, 211 211 .get = sctp_sched_wfq_get, 212 212 .init = sctp_sched_fc_init,
+1 -1
net/sctp/stream_sched_prio.c
··· 300 300 sctp_sched_prio_unsched(soute); 301 301 } 302 302 303 - static struct sctp_sched_ops sctp_sched_prio = { 303 + static const struct sctp_sched_ops sctp_sched_prio = { 304 304 .set = sctp_sched_prio_set, 305 305 .get = sctp_sched_prio_get, 306 306 .init = sctp_sched_prio_init,
+1 -1
net/sctp/stream_sched_rr.c
··· 171 171 sctp_sched_rr_unsched(stream, soute); 172 172 } 173 173 174 - static struct sctp_sched_ops sctp_sched_rr = { 174 + static const struct sctp_sched_ops sctp_sched_rr = { 175 175 .set = sctp_sched_rr_set, 176 176 .get = sctp_sched_rr_get, 177 177 .init = sctp_sched_rr_init,