net, sk_msg: Don't use RCU_INIT_POINTER on sk_user_data
Subsystems (4)
PATCH 1/1 net, sk_msg: Don't use RCU_INIT_POINTER on sk_user_data
sparse reports an error due to use of RCU_INIT_POINTER helper to assign to sk_user_data pointer, which is not tagged with __rcu:
net/core/sock.c:1875:25: error: incompatible types in comparison expression (different address spaces):net/core/sock.c:1875:25: void [noderef] <asn:4> *net/core/sock.c:1875:25: void *
... and rightfully so. sk_user_data is not always treated as a pointer to an RCU-protected data. When it is used to point at an RCU-protected object, we access it with __sk_user_data to inform sparse about it.
In this case, when the child socket does not inherit sk_user_data from the parent, there is no reason to treat it as an RCU-protected pointer.
Use a regular assignment to clear the pointer value.
--- net/core/sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +1 -1
@@ -1872,7 +1872,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)* as not suitable for copying when cloning. */ if (sk_user_data_is_nocopy (newsk)) -RCU_INIT_POINTER (newsk->sk_user_data,NULL ); + newsk->sk_user_data =NULL ; newsk->sk_err =0 ; newsk->sk_err_soft =0 ;
Signature · 1 line
2.25.1
Daniel Borkmann
maintainerQuoted 11 lines · Jakub Sitnicki
sparse reports an error due to use of
RCU_INIT_POINTERhelper to assign tosk_user_datapointer, which is not tagged with__rcu:
net/core/sock.c:1875:25: error: incompatible types in comparison expression (different address spaces):net/core/sock.c:1875:25: void [noderef] <asn:4> *net/core/sock.c:1875:25: void *... and rightfully so.
sk_user_datais not always treated as a pointer to an RCU-protected data. When it is used to point at an RCU-protected object, we access it with__sk_user_datato inform sparse about it.
Quoted 8 lines
In this case, when the child socket does not inherit
sk_user_datafrom the parent, there is no reason to treat it as an RCU-protected pointer.Use a regular assignment to clear the pointer value.
Fixes f1ff5ce2cd5e ("net, sk_msg: Clear sk_user_data pointer on clone if tagged")Reported-by kbuild test robot <[email protected]>Signed-off-by Jakub Sitnicki <[email protected]>
LGTM, applied, thanks!