[PATCH] sysctl_tcp_cookie_size read once

From: William Allen Simpson
Date: Sat Jan 08 2011 - 05:58:21 EST


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@xxxxxxxxx
---
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


--------------080802060801050500010402--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/