tcp_metrics: fix data-race in tcpm_suck_dst() vs fastopen
[ Upstream commit ddf251fa2bc1d3699eec0bae6ed0bc373b8fda79 ]
Whenever tcpm_new() reclaims an old entry, tcpm_suck_dst()
would overwrite data that could be read from tcp_fastopen_cache_get()
or tcp_metrics_fill_info().
We need to acquire fastopen_seqlock to maintain consistency.
For newly allocated objects, tcpm_new() can switch to kzalloc()
to avoid an extra fastopen_seqlock acquisition.
Fixes: 1fe4c481ba
("net-tcp: Fast Open client - cookie cache")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20230802131500.1478140-7-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
e53917e7ef
commit
cd4bdf8f98
@ -93,6 +93,7 @@ static struct tcpm_hash_bucket *tcp_metrics_hash __read_mostly;
|
|||||||
static unsigned int tcp_metrics_hash_log __read_mostly;
|
static unsigned int tcp_metrics_hash_log __read_mostly;
|
||||||
|
|
||||||
static DEFINE_SPINLOCK(tcp_metrics_lock);
|
static DEFINE_SPINLOCK(tcp_metrics_lock);
|
||||||
|
static DEFINE_SEQLOCK(fastopen_seqlock);
|
||||||
|
|
||||||
static void tcpm_suck_dst(struct tcp_metrics_block *tm,
|
static void tcpm_suck_dst(struct tcp_metrics_block *tm,
|
||||||
const struct dst_entry *dst,
|
const struct dst_entry *dst,
|
||||||
@ -129,11 +130,13 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
|
|||||||
tcp_metric_set(tm, TCP_METRIC_REORDERING,
|
tcp_metric_set(tm, TCP_METRIC_REORDERING,
|
||||||
dst_metric_raw(dst, RTAX_REORDERING));
|
dst_metric_raw(dst, RTAX_REORDERING));
|
||||||
if (fastopen_clear) {
|
if (fastopen_clear) {
|
||||||
|
write_seqlock(&fastopen_seqlock);
|
||||||
tm->tcpm_fastopen.mss = 0;
|
tm->tcpm_fastopen.mss = 0;
|
||||||
tm->tcpm_fastopen.syn_loss = 0;
|
tm->tcpm_fastopen.syn_loss = 0;
|
||||||
tm->tcpm_fastopen.try_exp = 0;
|
tm->tcpm_fastopen.try_exp = 0;
|
||||||
tm->tcpm_fastopen.cookie.exp = false;
|
tm->tcpm_fastopen.cookie.exp = false;
|
||||||
tm->tcpm_fastopen.cookie.len = 0;
|
tm->tcpm_fastopen.cookie.len = 0;
|
||||||
|
write_sequnlock(&fastopen_seqlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +197,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
|
|||||||
}
|
}
|
||||||
tm = oldest;
|
tm = oldest;
|
||||||
} else {
|
} else {
|
||||||
tm = kmalloc(sizeof(*tm), GFP_ATOMIC);
|
tm = kzalloc(sizeof(*tm), GFP_ATOMIC);
|
||||||
if (!tm)
|
if (!tm)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
@ -204,7 +207,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
|
|||||||
tm->tcpm_saddr = *saddr;
|
tm->tcpm_saddr = *saddr;
|
||||||
tm->tcpm_daddr = *daddr;
|
tm->tcpm_daddr = *daddr;
|
||||||
|
|
||||||
tcpm_suck_dst(tm, dst, true);
|
tcpm_suck_dst(tm, dst, reclaim);
|
||||||
|
|
||||||
if (likely(!reclaim)) {
|
if (likely(!reclaim)) {
|
||||||
tm->tcpm_next = tcp_metrics_hash[hash].chain;
|
tm->tcpm_next = tcp_metrics_hash[hash].chain;
|
||||||
@ -556,8 +559,6 @@ bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEFINE_SEQLOCK(fastopen_seqlock);
|
|
||||||
|
|
||||||
void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
|
void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
|
||||||
struct tcp_fastopen_cookie *cookie)
|
struct tcp_fastopen_cookie *cookie)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user