Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: d523a328fb02 ("[INET]: Fix inet_diag dead-lock regression")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Eric Dumazet and committed by
Paolo Abeni
e50e10ae efd40253

+3 -3
+3 -3
net/ipv4/inet_diag.c
··· 57 57 return ERR_PTR(-ENOENT); 58 58 } 59 59 60 - if (!inet_diag_table[proto]) 60 + if (!READ_ONCE(inet_diag_table[proto])) 61 61 sock_load_diag_module(AF_INET, proto); 62 62 63 63 mutex_lock(&inet_diag_table_mutex); ··· 1503 1503 mutex_lock(&inet_diag_table_mutex); 1504 1504 err = -EEXIST; 1505 1505 if (!inet_diag_table[type]) { 1506 - inet_diag_table[type] = h; 1506 + WRITE_ONCE(inet_diag_table[type], h); 1507 1507 err = 0; 1508 1508 } 1509 1509 mutex_unlock(&inet_diag_table_mutex); ··· 1520 1520 return; 1521 1521 1522 1522 mutex_lock(&inet_diag_table_mutex); 1523 - inet_diag_table[type] = NULL; 1523 + WRITE_ONCE(inet_diag_table[type], NULL); 1524 1524 mutex_unlock(&inet_diag_table_mutex); 1525 1525 } 1526 1526 EXPORT_SYMBOL_GPL(inet_diag_unregister);