net: use the %px format to display sock
Subsystems (3)
PATCH 1/1 net: use the %px format to display sock
From: Jason Xing <[email protected]>
I found that the current socket address, say 000000009842d952, cannot be searched in messages because %p format function hashes and converts it into an unique identifier which is currently useless for debugging.
--- net/ipv4/af_inet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/af_inet.c +2 -2
@@ -139,12 +139,12 @@ void inet_sock_destruct(struct sock *sk)sk_mem_reclaim_final (sk);if (sk->sk_type ==SOCK_STREAM && sk->sk_state !=TCP_CLOSE ) { -pr_err ("Attempt to release TCP socket in state %d %p\n" , +pr_err ("Attempt to release TCP socket in state %d %px\n" , sk->sk_state, sk);return ; }if (!sock_flag (sk,SOCK_DEAD )) { -pr_err ("Attempt to release alive inet socket %p\n" , sk); +pr_err ("Attempt to release alive inet socket %px\n" , sk);return ; }
Signature · 1 line
1.8.3.1
Hi Jason,
net/ipv4/af_inet.c void inet_sock_destruct(struct sock *sk) · line 142
Quoted 2 lines · On Thu, May 05, 2022 at 09:08:26PM +0800, [email protected] wrote:
net/ipv4/af_inet.c +1
-1- pr_err("Attempt to release TCP socket in state %d %p\n", + pr_err("Attempt to release TCP socket in state %d %px\n",
I think we cannot use %px here for security reasons? checkpatch is also warning about it:
WARNING: Using vsprintf specifier '%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '%p'. #21: FILE: net/ipv4/af_inet.c:142:
+ pr_err("Attempt to release TCP socket in state %d %px\n",
sk->sk_state, sk);
Thanks,
Peilin Ye
Quoted 10 lines · Peilin Ye
Hi Jason,
net/ipv4/af_inet.c void inet_sock_destruct(struct sock *sk) · line 142
Quoted 2 lines · On Thu, May 05, 2022 at 09:08:26PM +0800, [email protected] wrote:
net/ipv4/af_inet.c +1
-1- pr_err("Attempt to release TCP socket in state %d %p\n", + pr_err("Attempt to release TCP socket in state %d %px\n",I think we cannot use %px here for security reasons? checkpatch is also warning about it:
I noticed this warning before submitting. Since the %p format doesn't print the real address, printing the address here will be helpless and we cannot trace what exactly the bad socket is.
What do you suggest?
Thanks,
Jason
Quoted 8 lines
WARNING: Using vsprintf specifier '%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '%p'. #21: FILE:
net/ipv4/af_inet.c:142:
+ pr_err("Attempt to release TCP socket in state %d %px\n",sk->sk_state, sk);Thanks,
Peilin Ye
Quoted 12 lines · Jason Xing
Quoted 10 lines · Peilin Ye
Hi Jason,
net/ipv4/af_inet.c void inet_sock_destruct(struct sock *sk) · line 142
Quoted 2 lines · On Thu, May 05, 2022 at 09:08:26PM +0800, [email protected] wrote:
net/ipv4/af_inet.c +1
-1- pr_err("Attempt to release TCP socket in state %d %p\n", + pr_err("Attempt to release TCP socket in state %d %px\n",I think we cannot use %px here for security reasons? checkpatch is also warning about it:
Quoted 5 lines
I noticed this warning before submitting. Since the %p format doesn't print the real address, printing the address here will be helpless and we cannot trace what exactly the bad socket is.
What do you suggest?
How is a socket identified in places like /proc/<PID>/net/tcp ? Could you print the local and remote port to identify the socket?
How does the address of the structure actually help you? Do you see this address somewhere else?
Andrew