Messages in this thread Patch in this message | | | Date | Sat, 08 Jan 2011 06:58:16 -0500 | From | William Allen Simpson <> | Subject | Re: [058/152] tcp: protect sysctl_tcp_cookie_size reads |
| |
On 1/7/11 8:36 AM, Pekka Enberg wrote: > On Fri, Jan 7, 2011 at 3:05 PM, William Allen Simpson > <william.allen.simpson@gmail.com> wrote: >> My instructors would have flunked me for not including braces around >> multi-line sequences; it was one of the great no-no's of the '70s. Perhaps >> that's not the case anymore with modern colorful visual syntax checkers? > > That's because your instructors hadn't read Documentation/CodingStyle > which didn't appear until the '90s. > Hi, Pekka.
OTOH, I *have* read Documentation/CodingStyle a cople year back, and then re-checked it again today.... Out of curiosity, as I haven't done a Linux patch in many months, I cloned linux-2.6 and checked out v2.6.36-rc8 (I don't know where 2.6.36-stable is kept).
Note this patch is cleaner and more readable; lines that are changed have one-to-one correspondence.
Eric was *not* *truthful* saying there were "checkpatch.pl errors/warnings" in my code.
===
scripts/checkpatch.pl ~/sysctl_tcp_cookie_size-read-once.patch total: 0 errors, 0 warnings, 36 lines checked
/home/test/sysctl_tcp_cookie_size-read-once.patch has no obvious style problems and is ready for submission. From bd6f04cbee4c924e07cf3a1819a24acc3cc2490b Mon Sep 17 00:00:00 2001 From: William Allen Simpson <william.allen.simpson@gmail.com> Date: Sat, 8 Jan 2011 05:58:21 -0500 Subject: [PATCH] sysctl_tcp_cookie_size read once
Read sysctl_tcp_cookie_size only once in tcp_cookie_size_check(), as it might be concurrently changed by another cpu.
Signed-off-by: William.Allen.Simpson@gmail.com --- net/ipv4/tcp_output.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index de3bd84..49be4e3 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -392,27 +392,30 @@ struct tcp_out_options { */ static u8 tcp_cookie_size_check(u8 desired) { + 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 & 0x1) { /* 8-bit multiple, illegal, fix it */ - return (u8)(sysctl_tcp_cookie_size + 0x1); + cookie_size += 0x1; } - return (u8)sysctl_tcp_cookie_size; + return (u8)cookie_size; } /* Write previously computed TCP options to the packet. -- 1.7.1
| |