Skip to content

Commit 643bb5d

Browse files
mihalicyndavem330
authored andcommitted
ipvs: add READ_ONCE barrier for ipvs->sysctl_amemthresh
Cc: Julian Anastasov <[email protected]> Cc: Simon Horman <[email protected]> Cc: Pablo Neira Ayuso <[email protected]> Cc: Jozsef Kadlecsik <[email protected]> Cc: Florian Westphal <[email protected]> Suggested-by: Julian Anastasov <[email protected]> Signed-off-by: Alexander Mikhalitsyn <[email protected]> Acked-by: Julian Anastasov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent abb45a2 commit 643bb5d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static void update_defense_level(struct netns_ipvs *ipvs)
9494
{
9595
struct sysinfo i;
9696
int availmem;
97+
int amemthresh;
9798
int nomem;
9899
int to_change = -1;
99100

@@ -105,7 +106,8 @@ static void update_defense_level(struct netns_ipvs *ipvs)
105106
/* si_swapinfo(&i); */
106107
/* availmem = availmem - (i.totalswap - i.freeswap); */
107108

108-
nomem = (availmem < ipvs->sysctl_amemthresh);
109+
amemthresh = max(READ_ONCE(ipvs->sysctl_amemthresh), 0);
110+
nomem = (availmem < amemthresh);
109111

110112
local_bh_disable();
111113

@@ -145,19 +147,17 @@ static void update_defense_level(struct netns_ipvs *ipvs)
145147
break;
146148
case 1:
147149
if (nomem) {
148-
ipvs->drop_rate = ipvs->drop_counter
149-
= ipvs->sysctl_amemthresh /
150-
(ipvs->sysctl_amemthresh-availmem);
150+
ipvs->drop_counter = amemthresh / (amemthresh - availmem);
151+
ipvs->drop_rate = ipvs->drop_counter;
151152
ipvs->sysctl_drop_packet = 2;
152153
} else {
153154
ipvs->drop_rate = 0;
154155
}
155156
break;
156157
case 2:
157158
if (nomem) {
158-
ipvs->drop_rate = ipvs->drop_counter
159-
= ipvs->sysctl_amemthresh /
160-
(ipvs->sysctl_amemthresh-availmem);
159+
ipvs->drop_counter = amemthresh / (amemthresh - availmem);
160+
ipvs->drop_rate = ipvs->drop_counter;
161161
} else {
162162
ipvs->drop_rate = 0;
163163
ipvs->sysctl_drop_packet = 1;

0 commit comments

Comments
 (0)