From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: Martin Steigerwald <Martin@lichtvoll.de>,
netdev <netdev@vger.kernel.org>,
Ben Hutchings <bhutchings@solarflare.com>,
William Allen Simpson <william.allen.simpson@gmail.com>
Subject: [PATCH] tcp: protect sysctl_tcp_cookie_size reads
Date: Tue, 07 Dec 2010 23:20:47 +0100 [thread overview]
Message-ID: <1291760447.5324.31.camel@edumazet-laptop> (raw)
In-Reply-To: <1291757288.5324.18.camel@edumazet-laptop>
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>
---
net/ipv4/tcp_output.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 05b1ecf..8cecb30 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -386,27 +386,30 @@ struct tcp_out_options {
*/
static u8 tcp_cookie_size_check(u8 desired)
{
- if (desired > 0) {
+ int cookie_size;
+
+ if (desired > 0)
/* previously specified */
return desired;
- }
- if (sysctl_tcp_cookie_size <= 0) {
+
+ cookie_size = ACCESS_ONCE(sysctl_tcp_cookie_size);
+ if (cookie_size <= 0)
/* no default specified */
return 0;
- }
- if (sysctl_tcp_cookie_size <= TCP_COOKIE_MIN) {
+
+ if (cookie_size <= TCP_COOKIE_MIN)
/* value too small, specify minimum */
return TCP_COOKIE_MIN;
- }
- if (sysctl_tcp_cookie_size >= TCP_COOKIE_MAX) {
+
+ if (cookie_size >= TCP_COOKIE_MAX)
/* value too large, specify maximum */
return TCP_COOKIE_MAX;
- }
- if (0x1 & sysctl_tcp_cookie_size) {
+
+ if (cookie_size & 1)
/* 8-bit multiple, illegal, fix it */
- return (u8)(sysctl_tcp_cookie_size + 0x1);
- }
- return (u8)sysctl_tcp_cookie_size;
+ cookie_size++;
+
+ return (u8)cookie_size;
}
/* Write previously computed TCP options to the packet.
next prev parent reply other threads:[~2010-12-07 22:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <201012071639.58884.Martin@lichtvoll.de>
2010-12-07 16:12 ` bugs/regressions: report in LKML or in bugzilla? Eric Dumazet
2010-12-07 21:02 ` Ben Hutchings
2010-12-07 21:28 ` [PATCH] tcp: avoid a possible divide by zero Eric Dumazet
2010-12-07 21:32 ` Ben Hutchings
2010-12-07 22:03 ` Eric Dumazet
2010-12-08 8:23 ` Martin Steigerwald
2010-12-08 8:33 ` Eric Dumazet
2010-12-08 20:35 ` David Miller
2010-12-07 22:20 ` Eric Dumazet [this message]
2010-12-08 20:35 ` [PATCH] tcp: protect sysctl_tcp_cookie_size reads David Miller
2010-12-07 21:28 ` bugs/regressions: report in LKML or in bugzilla? Martin Steigerwald
2010-12-07 21:11 ` Martin Steigerwald
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291760447.5324.31.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=Martin@lichtvoll.de \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=william.allen.simpson@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox