mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
ipvs: fix racy memcpy in proc_do_sync_threshold
[ Upstream commit5310760af1] 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:1da177e4c3("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
00ea7eb1c6
commit
7f8a160d40
@@ -1798,6 +1798,7 @@ static int
|
|||||||
proc_do_sync_threshold(struct ctl_table *table, int write,
|
proc_do_sync_threshold(struct ctl_table *table, int write,
|
||||||
void *buffer, size_t *lenp, loff_t *ppos)
|
void *buffer, size_t *lenp, loff_t *ppos)
|
||||||
{
|
{
|
||||||
|
struct netns_ipvs *ipvs = table->extra2;
|
||||||
int *valp = table->data;
|
int *valp = table->data;
|
||||||
int val[2];
|
int val[2];
|
||||||
int rc;
|
int rc;
|
||||||
@@ -1807,6 +1808,7 @@ proc_do_sync_threshold(struct ctl_table *table, int write,
|
|||||||
.mode = table->mode,
|
.mode = table->mode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mutex_lock(&ipvs->sync_mutex);
|
||||||
memcpy(val, valp, sizeof(val));
|
memcpy(val, valp, sizeof(val));
|
||||||
rc = proc_dointvec(&tmp, write, buffer, lenp, ppos);
|
rc = proc_dointvec(&tmp, write, buffer, lenp, ppos);
|
||||||
if (write) {
|
if (write) {
|
||||||
@@ -1816,6 +1818,7 @@ proc_do_sync_threshold(struct ctl_table *table, int write,
|
|||||||
else
|
else
|
||||||
memcpy(valp, val, sizeof(val));
|
memcpy(valp, val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&ipvs->sync_mutex);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4080,6 +4083,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct netns_ipvs *ipvs)
|
|||||||
ipvs->sysctl_sync_threshold[0] = DEFAULT_SYNC_THRESHOLD;
|
ipvs->sysctl_sync_threshold[0] = DEFAULT_SYNC_THRESHOLD;
|
||||||
ipvs->sysctl_sync_threshold[1] = DEFAULT_SYNC_PERIOD;
|
ipvs->sysctl_sync_threshold[1] = DEFAULT_SYNC_PERIOD;
|
||||||
tbl[idx].data = &ipvs->sysctl_sync_threshold;
|
tbl[idx].data = &ipvs->sysctl_sync_threshold;
|
||||||
|
tbl[idx].extra2 = ipvs;
|
||||||
tbl[idx++].maxlen = sizeof(ipvs->sysctl_sync_threshold);
|
tbl[idx++].maxlen = sizeof(ipvs->sysctl_sync_threshold);
|
||||||
ipvs->sysctl_sync_refresh_period = DEFAULT_SYNC_REFRESH_PERIOD;
|
ipvs->sysctl_sync_refresh_period = DEFAULT_SYNC_REFRESH_PERIOD;
|
||||||
tbl[idx++].data = &ipvs->sysctl_sync_refresh_period;
|
tbl[idx++].data = &ipvs->sysctl_sync_refresh_period;
|
||||||
|
|||||||
Reference in New Issue
Block a user