Skip to content

Commit 5310760

Browse files
Sishuai GongFlorian Westphal
authored andcommitted
ipvs: fix racy memcpy in proc_do_sync_threshold
When two threads run proc_do_sync_threshold() in parallel, data races could happen between the two memcpy(): Thread-1 Thread-2 memcpy(val, valp, sizeof(val)); memcpy(valp, val, sizeof(val)); This race might mess up the (struct ctl_table *) table->data, so we add a mutex lock to serialize them. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://lore.kernel.org/netdev/B6988E90-0A1E-4B85-BF26-2DAF6D482433@gmail.com/ Signed-off-by: Sishuai Gong <sishuai.system@gmail.com> Acked-by: Simon Horman <horms@kernel.org> Acked-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Florian Westphal <fw@strlen.de>
1 parent 9bfab6d commit 5310760

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ static int
18761876
proc_do_sync_threshold(struct ctl_table *table, int write,
18771877
void *buffer, size_t *lenp, loff_t *ppos)
18781878
{
1879+
struct netns_ipvs *ipvs = table->extra2;
18791880
int *valp = table->data;
18801881
int val[2];
18811882
int rc;
@@ -1885,6 +1886,7 @@ proc_do_sync_threshold(struct ctl_table *table, int write,
18851886
.mode = table->mode,
18861887
};
18871888

1889+
mutex_lock(&ipvs->sync_mutex);
18881890
memcpy(val, valp, sizeof(val));
18891891
rc = proc_dointvec(&tmp, write, buffer, lenp, ppos);
18901892
if (write) {
@@ -1894,6 +1896,7 @@ proc_do_sync_threshold(struct ctl_table *table, int write,
18941896
else
18951897
memcpy(valp, val, sizeof(val));
18961898
}
1899+
mutex_unlock(&ipvs->sync_mutex);
18971900
return rc;
18981901
}
18991902

@@ -4321,6 +4324,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct netns_ipvs *ipvs)
43214324
ipvs->sysctl_sync_threshold[0] = DEFAULT_SYNC_THRESHOLD;
43224325
ipvs->sysctl_sync_threshold[1] = DEFAULT_SYNC_PERIOD;
43234326
tbl[idx].data = &ipvs->sysctl_sync_threshold;
4327+
tbl[idx].extra2 = ipvs;
43244328
tbl[idx++].maxlen = sizeof(ipvs->sysctl_sync_threshold);
43254329
ipvs->sysctl_sync_refresh_period = DEFAULT_SYNC_REFRESH_PERIOD;
43264330
tbl[idx++].data = &ipvs->sysctl_sync_refresh_period;

0 commit comments

Comments
 (0)