Skip to content

Commit 1af092e

Browse files
tititiou36NipaLocal
authored andcommitted
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> Signed-off-by: NipaLocal <nipa@local>
1 parent 461178b commit 1af092e

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

include/net/sctp/stream_sched.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ void sctp_sched_dequeue_done(struct sctp_outq *q, struct sctp_chunk *ch);
5252

5353
void sctp_sched_dequeue_common(struct sctp_outq *q, struct sctp_chunk *ch);
5454
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);
5656

5757
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);
5959
void sctp_sched_ops_prio_init(void);
6060
void sctp_sched_ops_rr_init(void);
6161
void sctp_sched_ops_fc_init(void);

include/net/sctp/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ struct sctp_outq {
10731073
struct list_head out_chunk_list;
10741074

10751075
/* Stream scheduler being used */
1076-
struct sctp_sched_ops *sched;
1076+
const struct sctp_sched_ops *sched;
10771077

10781078
unsigned int out_qlen; /* Total length of queued data chunks. */
10791079

net/sctp/stream.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void sctp_stream_shrink_out(struct sctp_stream *stream, __u16 outcnt)
5454

5555
static void sctp_stream_free_ext(struct sctp_stream *stream, __u16 sid)
5656
{
57-
struct sctp_sched_ops *sched;
57+
const struct sctp_sched_ops *sched;
5858

5959
if (!SCTP_SO(stream, sid)->ext)
6060
return;
@@ -130,7 +130,7 @@ static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt,
130130
int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
131131
gfp_t gfp)
132132
{
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);
134134
int i, ret = 0;
135135

136136
gfp |= __GFP_NOWARN;
@@ -182,7 +182,7 @@ int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)
182182

183183
void sctp_stream_free(struct sctp_stream *stream)
184184
{
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);
186186
int i;
187187

188188
sched->unsched_all(stream);
@@ -207,7 +207,7 @@ void sctp_stream_clear(struct sctp_stream *stream)
207207

208208
void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new)
209209
{
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);
211211

212212
sched->unsched_all(stream);
213213
sctp_stream_outq_migrate(stream, new, new->outcnt);

net/sctp/stream_sched.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void sctp_sched_fcfs_unsched_all(struct sctp_stream *stream)
9191
{
9292
}
9393

94-
static struct sctp_sched_ops sctp_sched_fcfs = {
94+
static const struct sctp_sched_ops sctp_sched_fcfs = {
9595
.set = sctp_sched_fcfs_set,
9696
.get = sctp_sched_fcfs_get,
9797
.init = sctp_sched_fcfs_init,
@@ -111,10 +111,10 @@ static void sctp_sched_ops_fcfs_init(void)
111111

112112
/* API to other parts of the stack */
113113

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];
115115

116116
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)
118118
{
119119
sctp_sched_ops[sched] = sched_ops;
120120
}
@@ -130,7 +130,7 @@ void sctp_sched_ops_init(void)
130130

131131
static void sctp_sched_free_sched(struct sctp_stream *stream)
132132
{
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);
134134
struct sctp_stream_out_ext *soute;
135135
int i;
136136

@@ -148,9 +148,9 @@ static void sctp_sched_free_sched(struct sctp_stream *stream)
148148
int sctp_sched_set_sched(struct sctp_association *asoc,
149149
enum sctp_sched_type sched)
150150
{
151-
struct sctp_sched_ops *old = asoc->outqueue.sched;
151+
const struct sctp_sched_ops *old = asoc->outqueue.sched;
152152
struct sctp_datamsg *msg = NULL;
153-
struct sctp_sched_ops *n;
153+
const struct sctp_sched_ops *n;
154154
struct sctp_chunk *ch;
155155
int i, ret = 0;
156156

@@ -263,14 +263,14 @@ void sctp_sched_dequeue_common(struct sctp_outq *q, struct sctp_chunk *ch)
263263

264264
int sctp_sched_init_sid(struct sctp_stream *stream, __u16 sid, gfp_t gfp)
265265
{
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);
267267
struct sctp_stream_out_ext *ext = SCTP_SO(stream, sid)->ext;
268268

269269
INIT_LIST_HEAD(&ext->outq);
270270
return sched->init_sid(stream, sid, gfp);
271271
}
272272

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)
274274
{
275275
struct sctp_association *asoc;
276276

net/sctp/stream_sched_fc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void sctp_sched_fc_unsched_all(struct sctp_stream *stream)
188188
list_del_init(&soute->fc_list);
189189
}
190190

191-
static struct sctp_sched_ops sctp_sched_fc = {
191+
static const struct sctp_sched_ops sctp_sched_fc = {
192192
.set = sctp_sched_fc_set,
193193
.get = sctp_sched_fc_get,
194194
.init = sctp_sched_fc_init,
@@ -206,7 +206,7 @@ void sctp_sched_ops_fc_init(void)
206206
sctp_sched_ops_register(SCTP_SS_FC, &sctp_sched_fc);
207207
}
208208

209-
static struct sctp_sched_ops sctp_sched_wfq = {
209+
static const struct sctp_sched_ops sctp_sched_wfq = {
210210
.set = sctp_sched_wfq_set,
211211
.get = sctp_sched_wfq_get,
212212
.init = sctp_sched_fc_init,

net/sctp/stream_sched_prio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static void sctp_sched_prio_unsched_all(struct sctp_stream *stream)
300300
sctp_sched_prio_unsched(soute);
301301
}
302302

303-
static struct sctp_sched_ops sctp_sched_prio = {
303+
static const struct sctp_sched_ops sctp_sched_prio = {
304304
.set = sctp_sched_prio_set,
305305
.get = sctp_sched_prio_get,
306306
.init = sctp_sched_prio_init,

net/sctp/stream_sched_rr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void sctp_sched_rr_unsched_all(struct sctp_stream *stream)
171171
sctp_sched_rr_unsched(stream, soute);
172172
}
173173

174-
static struct sctp_sched_ops sctp_sched_rr = {
174+
static const struct sctp_sched_ops sctp_sched_rr = {
175175
.set = sctp_sched_rr_set,
176176
.get = sctp_sched_rr_get,
177177
.init = sctp_sched_rr_init,

0 commit comments

Comments
 (0)