Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp7007648imm; Sun, 20 May 2018 16:14:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp5J5mHyNBOCWvEQzKmL+kg5ZTkHi2uVNCnMbcKQSBLTM/rz2+5H8sTx7lx/aJOp0q7n1Zg X-Received: by 2002:a63:7157:: with SMTP id b23-v6mr7678707pgn.436.1526858086372; Sun, 20 May 2018 16:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526858086; cv=none; d=google.com; s=arc-20160816; b=MFJ3OU6/bWjiaIMh9nfgVUMdSvVBMVQRGsBGJsr3IRXmc50KTcLYru3U0q0aWPWrqv P7/KNMFF0aSaoadvwxeg6jQA7QctqTDtQvOsVAXssycNTmIOb+9RYwct6cz1yn5hzwUK En96YOY0WWgmlR6wLWix5BCaptF4jIPDsneVJJVTE+8oetNuwWDHalFAbKN9NjLfZgJF ZZL3tfTX4GsrH2fXTmHmppxygJ2Boz+pOMrOBBwVcnGj+XsvWEXu9inDw77+JQGtuoTy BGgYn4F/ETV7kyU5i6R6lKEs3af5jK2OsAbk1zcBg7YBCxyUiYeaZiTFC9sTQzXPYqCm RGYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=5wHg7tOBSX5Af2X8rtbNydkTM3jaDXBVdGi75lLyIlY=; b=Xj/tSXDoruC04r7a+GvTWd0+oRMLQqy6NUaJkIMWZ5PFHqMqeeCde6IPDC9JgaCOWh VYgDLIdljMVCza7d/qYB9Cvy3VOEBOpmB86d6TNialr/KgMmFG9vlSAgctNJ3ufyxDIh M/K0XuzMokIa95prIIyfPFKON9g6u1Fsu+urLZ6CmQlpyOzw6T5tzrbRIOKJ6y1LQy3Q ymDPul5iigdX19HfLevLgYmhE6Vz00cHSnY8MQ+Z+zgBNAdxmEqSgZMspMVL0OB2D7kS 1lzHphF5gzFCwP0CtJlquz1D23Kn9EfNnwwHVuOGSpF5V6wYZW2KjcB5kHCbISUictmS xUSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HshQIEbf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89-v6si13120197plb.154.2018.05.20.16.14.31; Sun, 20 May 2018 16:14:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HshQIEbf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752552AbeETXOP (ORCPT + 99 others); Sun, 20 May 2018 19:14:15 -0400 Received: from mail-ua0-f194.google.com ([209.85.217.194]:35219 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751500AbeETXON (ORCPT ); Sun, 20 May 2018 19:14:13 -0400 Received: by mail-ua0-f194.google.com with SMTP id a2-v6so8775902uak.2; Sun, 20 May 2018 16:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5wHg7tOBSX5Af2X8rtbNydkTM3jaDXBVdGi75lLyIlY=; b=HshQIEbfXihvZd9LZZtwxb7YQMnaQZz/t49rFsNrEhmyfJLhc9R7pLbvHmrkM5I++o XrfA7eo7036WQvXzjV2bhQHw2l2oEUp/czKEJtSv2D+c8mX/8iBjjk6MV1OIzAttHwGg /D8HervnDvKwpg2J+Sl3P/jgX1t5fL21nPb9Gq3QU08QlmhuJbKkaTnZ1WQ/MSpSHRdw LOp3pBz//c2Fxpd7pwPAKux4qhKqRjJzF+zA+UpY5TBmdkK28fIgkHq3vOtT+g1JZctH b4N7Ux1TMdNh2U3ZN10uRkTFZrB36Nm0GcvC9UlJYn476e2eQcMjcBCicsK0RXNaTANO aoyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5wHg7tOBSX5Af2X8rtbNydkTM3jaDXBVdGi75lLyIlY=; b=e7jqL9x7KpREaAA7QwLBQp15ZhCLwvRFBuGDhYS7pcQ5Sjpui710xsy9EWsg3QH4To 6SVNbemEzK6gNxwC3fYz158wpQtAd4WFwwqV75S96QjJwJkdbhg99k0OQnwtKBbQdkgH Jaa22IYrkRPrJSNurOs8cBMlxAFS3uHTvYtPsqory5C2ONszpdEUabtkwI3Bb8GnE6TO i9Ycv+Hk5/0i0gClp51ettR7EMKKy+fc6zzC/n1qom+tzb/Rvj2b/TPmmr3XjkMbl73D B3CQlQV8HuMMohXvZcRpXtnO1a98/IOVJrMdonXfjAET+yPrjKw1bcDClRwk+ooNUYKI Jn9w== X-Gm-Message-State: ALKqPwd9+/HPiO2xyZ2EaqirZNA9K9Zjcl8RdGDD9dQ+WDuYBD1AWjWv oRKH8kVPezEIkXsroMFmD9Y0GbERFlrE8uP4j9c= X-Received: by 2002:ab0:2493:: with SMTP id i19-v6mr13432094uan.180.1526858052432; Sun, 20 May 2018 16:14:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.151.90 with HTTP; Sun, 20 May 2018 16:13:31 -0700 (PDT) In-Reply-To: References: <20180518120826.GA19515@dragonet.kaist.ac.kr> <293d029c-b14c-a625-3703-97a5754e99f1@gmail.com> <20180518.114433.390752642781753429.davem@davemloft.net> From: Willem de Bruijn Date: Sun, 20 May 2018 19:13:31 -0400 Message-ID: Subject: Re: WARNING in ip_recv_error To: David Miller Cc: Eric Dumazet , DaeLyong Jeong , Alexey Kuznetsov , Hideaki YOSHIFUJI , Network Development , LKML , Byoungyoung Lee , Kyungtae Kim , bammanag@purdue.edu, Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 2:59 PM, Willem de Bruijn wrote: > On Fri, May 18, 2018 at 2:46 PM, Willem de Bruijn > wrote: >> On Fri, May 18, 2018 at 2:44 PM, Willem de Bruijn >> wrote: >>> On Fri, May 18, 2018 at 1:09 PM, Willem de Bruijn >>> wrote: >>>> On Fri, May 18, 2018 at 11:44 AM, David Miller wrote: >>>>> From: Eric Dumazet >>>>> Date: Fri, 18 May 2018 08:30:43 -0700 >>>>> >>>>>> We probably need to revert Willem patch (7ce875e5ecb8562fd44040f69bda96c999e38bbc) >>>>> >>>>> Is it really valid to reach ip_recv_err with an ipv6 socket? >>>> >>>> I guess the issue is that setsockopt IPV6_ADDRFORM is not an >>>> atomic operation, so that the socket is neither fully ipv4 nor fully >>>> ipv6 by the time it reaches ip_recv_error. >>>> >>>> sk->sk_socket->ops = &inet_dgram_ops; >>>> < HERE > >>>> sk->sk_family = PF_INET; >>>> >>>> Even calling inet_recv_error to demux would not necessarily help. >>>> >>>> Safest would be to look up by skb->protocol, similar to what >>>> ipv6_recv_error does to handle v4-mapped-v6. >>>> >>>> Or to make that function safe with PF_INET and swap the order >>>> of the above two operations. >>>> >>>> All sound needlessly complicated for this rare socket option, but >>>> I don't have a better idea yet. Dropping on the floor is not nice, >>>> either. >>> >>> Ensuring that ip_recv_error correctly handles packets from either >>> socket and removing the warning should indeed be good. >>> >>> It is robust against v4-mapped packets from an AF_INET6 socket, >>> but see caveat on reconnect below. >>> >>> The code between ipv6_recv_error for v4-mapped addresses and >>> ip_recv_error is essentially the same, the main difference being >>> whether to return network headers as sockaddr_in with SOL_IP >>> or sockaddr_in6 with SOL_IPV6. >>> >>> There are very few other locations in the stack that explicitly test >>> sk_family in this way and thus would be vulnerable to races with >>> IPV6_ADDRFORM. >>> >>> I'm not sure whether it is possible for a udpv6 socket to queue a >>> real ipv6 packet on the error queue, disconnect, connect to an >>> ipv4 address, call IPV6_ADDRFORM and then call ip_recv_error >>> on a true ipv6 packet. That would return buggy data, e.g., in >>> msg_name. >> >> In do_ipv6_setsockopt IPV6_ADDRFORM we can test that the >> error queue is empty, and then take its lock for the duration of the >> operation. > > Actually, no reason to hold the lock. This setsockopt holds the socket > lock, which connect would need, too. So testing that the queue > is empty after testing that it is connected to a v4 address is > sufficient to ensure that no ipv6 packets are queued for reception. > > diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c > index 4d780c7f0130..a975d6311341 100644 > --- a/net/ipv6/ipv6_sockglue.c > +++ b/net/ipv6/ipv6_sockglue.c > @@ -199,6 +199,11 @@ static int do_ipv6_setsockopt(struct sock *sk, > int level, int optname, > > if (ipv6_only_sock(sk) || > !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) { > retv = -EADDRNOTAVAIL; > break; > } > > + if (!skb_queue_empty(&sk->sk_error_queue)) { > + retv = -EBUSY; > + break; > + } > + > fl6_free_socklist(sk); > __ipv6_sock_mc_close(sk); > > After this it should be safe to remove the warning in ip_recv_error. Hmm.. nope. This ensures that the socket cannot produce any new true v6 packets. But it does not guarantee that they are not already in the system, e.g. queued in tc, and will find their way to the error queue later. We'll have to just be able to handle ipv6 packets in ip_recv_error. Since IPV6_ADDRFORM is used to pass to legacy v4-only processes and those likely are only confused by SOL_IPV6 error messages, it is probably best to just drop them and perhaps WARN_ONCE.