lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 09 Nov 2017 06:52:41 -0800
From:   Eric Dumazet <eric.dumazet@...il.com>
To:     Yafang Shao <laoar.shao@...il.com>
Cc:     davem@...emloft.net, kuznet@....inr.ac.ru, yoshfuji@...ux-ipv6.org,
        rostedt@...dmis.org, mingo@...hat.com, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next 2/2] tcp: handle TCP_TIME_WAIT/TCP_NEW_SYN_RECV
 in tcp_set_state tracepoint

On Thu, 2017-11-09 at 14:26 +0000, Yafang Shao wrote:
> When TCP connetion in TCP_TIME_WAIT or TCP_NEW_SYN_RECV state, it can't
> get the sport/dport/saddr/daddr from inet_sock.
> 
> trace_tcp_set_state may be called when the oldstate in these two states.
> 
> Signed-off-by: Yafang Shao <laoar.shao@...il.com>
> ---
>  include/trace/events/tcp.h | 33 ++++++++++++++++++++++++++-------
>  1 file changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> index 07cccca..1982a71 100644
> --- a/include/trace/events/tcp.h
> +++ b/include/trace/events/tcp.h
> @@ -196,7 +196,6 @@
>  	),
>  
>  	TP_fast_assign(
> -		struct inet_sock *inet = inet_sk(sk);
>  		struct in6_addr *pin6;
>  		__be32 *p32;
>  
> @@ -204,14 +203,34 @@
>  		__entry->oldstate = oldstate;
>  		__entry->newstate = newstate;
>  
> -		__entry->sport = ntohs(inet->inet_sport);
> -		__entry->dport = ntohs(inet->inet_dport);
> +		if (oldstate == TCP_TIME_WAIT) {
> +			__entry->sport = ntohs(inet_twsk(sk)->tw_sport);
> +			__entry->dport = ntohs(inet_twsk(sk)->tw_dport);
>  
> -		p32 = (__be32 *) __entry->saddr;
> -		*p32 = inet->inet_saddr;
> +			p32 = (__be32 *) __entry->saddr;
> +			*p32 = inet_twsk(sk)->tw_rcv_saddr;
>  
> -		p32 = (__be32 *) __entry->daddr;
> -		*p32 =  inet->inet_daddr;
> +			p32 = (__be32 *) __entry->daddr;
> +			*p32 = inet_twsk(sk)->tw_daddr;
> +		} else if (oldstate == TCP_NEW_SYN_RECV) {
> +			__entry->sport = inet_rsk(inet_reqsk(sk))->ir_num;
> +			__entry->dport = ntohs(inet_rsk(inet_reqsk(sk))->ir_rmt_port);
> +
> +			p32 = (__be32 *) __entry->saddr;
> +			*p32 = inet_rsk(inet_reqsk(sk))->ir_loc_addr;
> +
> +			p32 = (__be32 *) __entry->daddr;
> +			*p32 = inet_rsk(inet_reqsk(sk))->ir_rmt_addr;
> +		} else {
> +			__entry->sport = ntohs(inet_sk(sk)->inet_sport);
> +			__entry->dport = ntohs(inet_sk(sk)->inet_dport);
> +
> +			p32 = (__be32 *) __entry->saddr;
> +			*p32 = inet_sk(sk)->inet_saddr;
> +
> +			p32 = (__be32 *) __entry->daddr;
> +			*p32 =  inet_sk(sk)->inet_daddr;
> +		}


Wow.


Since all three variants of sockets (full sockets, request sockets,
timewait sockets) are all hashed into ehash table these days, they all
have the fields at the same offset

For IPv4, that would be :

__sk_common.skc_daddr    (or inet_daddr)
__sk_common.skc_rcv_saddr (or inet_rcv_saddr )
__sk_common.skc_dport     (or inet_dport)
__sk_common.skc_num       (or inet_num)

Look at __inet_lookup_established() and INET_MATCH() : They deal with
the three variants, without having to look at sk_state.

If you were using the fields that are common to all sockets, no need to
add all this unnecessary complexity.


Powered by blists - more mailing lists