Skip to content

Commit f198725

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: protect sysctl_tcp_cookie_size reads
Make sure sysctl_tcp_cookie_size is read once in tcp_cookie_size_check(), or we might return an illegal value to caller if sysctl_tcp_cookie_size is changed by another cpu. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Cc: Ben Hutchings <bhutchings@solarflare.com> Cc: William Allen Simpson <william.allen.simpson@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ad9f4f5 commit f198725

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

‎net/ipv4/tcp_output.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,27 +385,30 @@ struct tcp_out_options {
385385
*/
386386
static u8 tcp_cookie_size_check(u8 desired)
387387
{
388-
if (desired > 0) {
388+
int cookie_size;
389+
390+
if (desired > 0)
389391
/* previously specified */
390392
return desired;
391-
}
392-
if (sysctl_tcp_cookie_size <= 0) {
393+
394+
cookie_size = ACCESS_ONCE(sysctl_tcp_cookie_size);
395+
if (cookie_size <= 0)
393396
/* no default specified */
394397
return 0;
395-
}
396-
if (sysctl_tcp_cookie_size <= TCP_COOKIE_MIN) {
398+
399+
if (cookie_size <= TCP_COOKIE_MIN)
397400
/* value too small, specify minimum */
398401
return TCP_COOKIE_MIN;
399-
}
400-
if (sysctl_tcp_cookie_size >= TCP_COOKIE_MAX) {
402+
403+
if (cookie_size >= TCP_COOKIE_MAX)
401404
/* value too large, specify maximum */
402405
return TCP_COOKIE_MAX;
403-
}
404-
if (0x1 & sysctl_tcp_cookie_size) {
406+
407+
if (cookie_size & 1)
405408
/* 8-bit multiple, illegal, fix it */
406-
return (u8)(sysctl_tcp_cookie_size + 0x1);
407-
}
408-
return (u8)sysctl_tcp_cookie_size;
409+
cookie_size++;
410+
411+
return (u8)cookie_size;
409412
}
410413

411414
/* Write previously computed TCP options to the packet.

0 commit comments

Comments
 (0)