diff options
author | Xi Wang <xi.wang@gmail.com> | 2011-12-16 07:44:15 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-12-19 16:25:46 -0500 |
commit | 2692ba61a82203404abd7dd2a027bda962861f74 (patch) | |
tree | e39f21131faf42ada263c1969cfa200af2f4b0f9 /net | |
parent | 2ca6cf06d988fea21e812a86be79353352677c9c (diff) |
sctp: fix incorrect overflow check on autoclose
Commit 8ffd3208 voids the previous patches f6778aab and 810c0719 for
limiting the autoclose value. If userspace passes in -1 on 32-bit
platform, the overflow check didn't work and autoclose would be set
to 0xffffffff.
This patch defines a max_autoclose (in seconds) for limiting the value
and exposes it through sysctl, with the following intentions.
1) Avoid overflowing autoclose * HZ.
2) Keep the default autoclose bound consistent across 32- and 64-bit
platforms (INT_MAX / HZ in this patch).
3) Keep the autoclose value consistent between setsockopt() and
getsockopt() calls.
Suggested-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/sctp/associola.c | 2 | ||||
-rw-r--r-- | net/sctp/protocol.c | 3 | ||||
-rw-r--r-- | net/sctp/socket.c | 2 | ||||
-rw-r--r-- | net/sctp/sysctl.c | 13 |
4 files changed, 17 insertions, 3 deletions
diff --git a/net/sctp/associola.c b/net/sctp/associola.c index 152b5b3c3fff..acd2edbc073e 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c | |||
@@ -173,7 +173,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a | |||
173 | asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0; | 173 | asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0; |
174 | asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay; | 174 | asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay; |
175 | asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = | 175 | asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = |
176 | (unsigned long)sp->autoclose * HZ; | 176 | min_t(unsigned long, sp->autoclose, sctp_max_autoclose) * HZ; |
177 | 177 | ||
178 | /* Initializes the timers */ | 178 | /* Initializes the timers */ |
179 | for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) | 179 | for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) |
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 61b9fca5a173..6f6ad8686833 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c | |||
@@ -1285,6 +1285,9 @@ SCTP_STATIC __init int sctp_init(void) | |||
1285 | sctp_max_instreams = SCTP_DEFAULT_INSTREAMS; | 1285 | sctp_max_instreams = SCTP_DEFAULT_INSTREAMS; |
1286 | sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS; | 1286 | sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS; |
1287 | 1287 | ||
1288 | /* Initialize maximum autoclose timeout. */ | ||
1289 | sctp_max_autoclose = INT_MAX / HZ; | ||
1290 | |||
1288 | /* Initialize handle used for association ids. */ | 1291 | /* Initialize handle used for association ids. */ |
1289 | idr_init(&sctp_assocs_id); | 1292 | idr_init(&sctp_assocs_id); |
1290 | 1293 | ||
diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 13bf5fcdbff1..54a7cd2fdd7a 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c | |||
@@ -2200,8 +2200,6 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, | |||
2200 | return -EINVAL; | 2200 | return -EINVAL; |
2201 | if (copy_from_user(&sp->autoclose, optval, optlen)) | 2201 | if (copy_from_user(&sp->autoclose, optval, optlen)) |
2202 | return -EFAULT; | 2202 | return -EFAULT; |
2203 | /* make sure it won't exceed MAX_SCHEDULE_TIMEOUT */ | ||
2204 | sp->autoclose = min_t(long, sp->autoclose, MAX_SCHEDULE_TIMEOUT / HZ); | ||
2205 | 2203 | ||
2206 | return 0; | 2204 | return 0; |
2207 | } | 2205 | } |
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index 6b3952961b85..60ffbd067ff7 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c | |||
@@ -53,6 +53,10 @@ static int sack_timer_min = 1; | |||
53 | static int sack_timer_max = 500; | 53 | static int sack_timer_max = 500; |
54 | static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */ | 54 | static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */ |
55 | static int rwnd_scale_max = 16; | 55 | static int rwnd_scale_max = 16; |
56 | static unsigned long max_autoclose_min = 0; | ||
57 | static unsigned long max_autoclose_max = | ||
58 | (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX) | ||
59 | ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ; | ||
56 | 60 | ||
57 | extern long sysctl_sctp_mem[3]; | 61 | extern long sysctl_sctp_mem[3]; |
58 | extern int sysctl_sctp_rmem[3]; | 62 | extern int sysctl_sctp_rmem[3]; |
@@ -258,6 +262,15 @@ static ctl_table sctp_table[] = { | |||
258 | .extra1 = &one, | 262 | .extra1 = &one, |
259 | .extra2 = &rwnd_scale_max, | 263 | .extra2 = &rwnd_scale_max, |
260 | }, | 264 | }, |
265 | { | ||
266 | .procname = "max_autoclose", | ||
267 | .data = &sctp_max_autoclose, | ||
268 | .maxlen = sizeof(unsigned long), | ||
269 | .mode = 0644, | ||
270 | .proc_handler = &proc_doulongvec_minmax, | ||
271 | .extra1 = &max_autoclose_min, | ||
272 | .extra2 = &max_autoclose_max, | ||
273 | }, | ||
261 | 274 | ||
262 | { /* sentinel */ } | 275 | { /* sentinel */ } |
263 | }; | 276 | }; |