Commit e50e10ae authored by Eric Dumazet's avatar Eric Dumazet Committed by Paolo Abeni

inet_diag: annotate data-races around inet_diag_table[]

inet_diag_lock_handler() reads inet_diag_table[proto] locklessly.

Use READ_ONCE()/WRITE_ONCE() annotations to avoid potential issues.

Fixes: d523a328 ("[INET]: Fix inet_diag dead-lock regression")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarGuillaume Nault <gnault@redhat.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent efd40253
...@@ -57,7 +57,7 @@ static const struct inet_diag_handler *inet_diag_lock_handler(int proto) ...@@ -57,7 +57,7 @@ static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
if (!inet_diag_table[proto]) if (!READ_ONCE(inet_diag_table[proto]))
sock_load_diag_module(AF_INET, proto); sock_load_diag_module(AF_INET, proto);
mutex_lock(&inet_diag_table_mutex); mutex_lock(&inet_diag_table_mutex);
...@@ -1503,7 +1503,7 @@ int inet_diag_register(const struct inet_diag_handler *h) ...@@ -1503,7 +1503,7 @@ int inet_diag_register(const struct inet_diag_handler *h)
mutex_lock(&inet_diag_table_mutex); mutex_lock(&inet_diag_table_mutex);
err = -EEXIST; err = -EEXIST;
if (!inet_diag_table[type]) { if (!inet_diag_table[type]) {
inet_diag_table[type] = h; WRITE_ONCE(inet_diag_table[type], h);
err = 0; err = 0;
} }
mutex_unlock(&inet_diag_table_mutex); mutex_unlock(&inet_diag_table_mutex);
...@@ -1520,7 +1520,7 @@ void inet_diag_unregister(const struct inet_diag_handler *h) ...@@ -1520,7 +1520,7 @@ void inet_diag_unregister(const struct inet_diag_handler *h)
return; return;
mutex_lock(&inet_diag_table_mutex); mutex_lock(&inet_diag_table_mutex);
inet_diag_table[type] = NULL; WRITE_ONCE(inet_diag_table[type], NULL);
mutex_unlock(&inet_diag_table_mutex); mutex_unlock(&inet_diag_table_mutex);
} }
EXPORT_SYMBOL_GPL(inet_diag_unregister); EXPORT_SYMBOL_GPL(inet_diag_unregister);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment