From: David Ahern Subject: Re: [PATCH net] net: diag: Don't double-free TCP_NEW_SYN_RECV sockets in tcp_abort Date: Mon, 9 Jul 2018 10:14:23 -0600 Message-ID: References: <20180707073140.202004-1-lorenzo@google.com> <20180707.221146.161981342461262899.davem@davemloft.net> <1acf7d5a-4465-120e-70bf-4fe24b1f7e3e@cumulusnetworks.com> <593e8213-16ea-0a9c-2a23-63450c770455@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: David Miller , netdev@vger.kernel.org, Alistair Strachan , Subash Abhinov Kasiviswanathan To: Eric Dumazet , Lorenzo Colitti Return-path: Received: from mail-pf0-f196.google.com ([209.85.192.196]:33479 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933188AbeGIQO0 (ORCPT ); Mon, 9 Jul 2018 12:14:26 -0400 Received: by mail-pf0-f196.google.com with SMTP id b17-v6so14014480pfi.0 for ; Mon, 09 Jul 2018 09:14:25 -0700 (PDT) In-Reply-To: <593e8213-16ea-0a9c-2a23-63450c770455@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 7/9/18 9:17 AM, Eric Dumazet wrote: > > > On 07/09/2018 07:59 AM, David Ahern wrote: >> On 7/8/18 10:53 PM, Lorenzo Colitti wrote: >>> On Sat, Jul 7, 2018 at 10:29 PM Eric Dumazet wrote: >>>>>> Tested: passes Android sock_diag_test.py, which exercises this codepath >>>>> >>>>> If this Android test case exercises this path, why didn't it trigger >>>>> the double free and thus cause this bug to be found much sooner? >>>>> >>>>> Just curious. >>>> >>>> Presumably android has not backported yet the refcount_t stuff in their kernels. >>> >>> That's correct. We only started seeing this on 4.14, which is not yet >>> in the field. >> >> Prior to 4.12 syn-recv sockets did not show up in the list, so it could >> not be closed through the diag API. I did not chase it to a specific >> commit between 4.11 (no syn-recv in 'ss -ta') and 4.12 (syn-recv shows >> up in 'ss -ta'). >> > > I suggest you look more closely to tcp_abort(), the function you changed > in commit d7226c7a4dd1 (linux-4.8) > > Then you will see it had support for syn-recv since linux-4.5 > > So I do not understand your 4.11/4.12 mentions at all. > > "ss -ta" always had dumped syn-recv request sockets. > > Perhaps it is something with my config, settings, ss version or test program, but I do not see it on 4.11: # ip addr sh dev eth1 3: eth1: mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 02:e0:f9:1c:00:37 brd ff:ff:ff:ff:ff:ff inet 10.100.1.4/24 scope global eth1 valid_lft forever preferred_lft forever ... # uname -r 4.11.0 # iptables -A OUTPUT -p tcp --sport 12345 --tcp-flags SYN,ACK SYN,ACK -j DROP # vrf-test -s & [1] 823 --> connection attempt into this node from 10.100.1.254 # ss -ta | grep 1234 LISTEN 0 5 *:12345 *:* No, SYN-RECV in output. A local connection does show up (but I was not looking at that earlier): # vrf-test -r 10.100.1.4 & [2] 827 # ss -ta | grep 1234 LISTEN 0 5 *:12345 *:* SYN-RECV 0 0 10.100.1.4:12345 10.100.1.254:54276 SYN-RECV 0 0 10.100.1.4:12345 10.100.1.4:52316 SYN-SENT 0 1 10.100.1.4:52316 10.100.1.4:12345 Same commands on 4.12: # uname -r 4.12.0 # iptables -A OUTPUT -p tcp --sport 12345 --tcp-flags SYN,ACK SYN,ACK -j DROP # vrf-test -s & [1] 815 --> connection attempt into this node from 10.100.1.254 # ss -ta | grep 1234 LISTEN 0 5 *:12345 *:* SYN-RECV 0 0 10.100.1.4:12345 10.100.1.254:54272 So, SYN-RECV is there. However, in writing this response and repeating the steps over and over I have noticed inconsistencies even with 4.12. For example, I reboot 4.12 and try the steps again: # uname -r 4.12.0 # iptables -A OUTPUT -p tcp --sport 12345 --tcp-flags SYN,ACK SYN,ACK -j DROP # vrf-test -s & [1] 821 --> connection attempt into this node from 10.100.1.254 # ss -ta | grep 1234 LISTEN 0 5 *:12345 *:* no SYN-RECV. Local test: # vrf-test -r 10.100.1.4 & [2] 824 # ss -ta | grep 1234 LISTEN 0 5 *:12345 *:* SYN-SENT 0 1 10.100.1.4:59922 10.100.1.4:12345 No SYN-RECV. # ss --version ss utility, iproute2-ss150831