Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4864892imm; Fri, 18 May 2018 12:01:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpiUM5x3WyTzf5+5c2aRUon78ENRgMQKSwzb4Vr2ulfPtoAYFR0VJdUrSA3S+dTb73rVFM0 X-Received: by 2002:a17:902:581:: with SMTP id f1-v6mr10810971plf.48.1526670064795; Fri, 18 May 2018 12:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526670064; cv=none; d=google.com; s=arc-20160816; b=vhdJvalwOmioM+0CHfICcYGWhzknIzfEnpyK6qIMbdND4p4Dnv18uoTn/e5akuqKmG u3OzDDgWC8vjVVxECgbLiGXSNWVsKuheQtrcVW7Q7ZqGwKGcEYejpDZ0DyymgzpmBpfd dQZtj3BAPufSQPRwORFFlz95hq6qeEbn/oB5a1DEYgqTfrCVRKwGfLzmyrdEEnhAuCsl Tt1JXTxL9gYayCYke+3aXdQTS8IJ4nsNHGxnQuHJAfxVRF+BMm8BHjzGroaQVWim5QYg Br+K1w2M67D/PCvsVIcf3Yzh7IBK5VGOzfm4yTOc2jTrcgbHuFetoSnLE325/YGxEmRQ IX3Q== 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=tAhnVCdZqZ/0LrUJ4nMKXI+IUvcEd4HRez6/WjCgYFM=; b=eq3IEI8HgPgPnLnaWcHMjdcNBtMO6KKAFsbJyjBGtnIKLW6CIh83kCB71PO8LPoFoA GCepM2UPlscZzuoYlvG0tRcL8AfGpXZrc+BJESO/3WwetExHoWY42LqeK7G/k862CT8X MEQekzsYJkDA6NH+3H3NH1z7eRg44f9sgWW3GKjEVtVfNFg53qhL4FgKlETzt+zyYNZ+ JZ6HE7ro6ZoYlFOKpmdiELu9ZH1z5TnZ3tFZ+OvnC79q81B7zNWrCy5NiYwg7OLA5spz WZx/pfa2ZuFPtgmbFKqC1IfwxjK5VJYtG7J+OeeWLctzpdmSFzFgjJlD4qNjy1j4WIj+ SmaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L1iaNYur; 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 m79-v6si7965614pfi.236.2018.05.18.12.00.50; Fri, 18 May 2018 12:01:04 -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=L1iaNYur; 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 S1752026AbeERTAB (ORCPT + 99 others); Fri, 18 May 2018 15:00:01 -0400 Received: from mail-vk0-f65.google.com ([209.85.213.65]:39009 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751940AbeERTAA (ORCPT ); Fri, 18 May 2018 15:00:00 -0400 Received: by mail-vk0-f65.google.com with SMTP id g83-v6so5453028vkc.6; Fri, 18 May 2018 11:59:59 -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=tAhnVCdZqZ/0LrUJ4nMKXI+IUvcEd4HRez6/WjCgYFM=; b=L1iaNYurdBwvCYVdsigvZ6mUcvdcviHzsCVW7nWMJ7yJBy1BtCGnf4BXZjDsMMT6oH 1GyGIt8xImz0TCmNdRSzBjM+F5CyT9Rs3XNrwjaRyg0D+ZioMWbI0rtJp7ZSboN/wkqh Kxq7RCAmAECIL721AO6+CcUUZPHtQFaIttfGAVOH71eTiCM8Rj08fypwm9dG9GZVoSGA XwAQ/VbbKuZTZgZXgpFIhddS0qj4QpOSDdyWf2HBfVgC+6ny5xW6/gEDeDoXm20pr1Tf +X6ozT090qycJDjbSWICzEj8ZzvIjQbDYMGxmJIahvxXCTm7gl7WKEUpgC+xUr05JLBx CdWQ== 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=tAhnVCdZqZ/0LrUJ4nMKXI+IUvcEd4HRez6/WjCgYFM=; b=F6STHUIJC68c6qBtHy3A9KU4jx7BAX+zaOZoscaCM/98Rs9T0GJsL4pyyUvjVEyZZ+ Xaw0CYZmBe5fqd1sblxQqtLlaa2dXCP80ak69hte/aZ9fp46F2fX8h0+NtbYDjvFzPEf w6dspoYKLRuD8oVlRg+RnFsYZmTz9w4O7iPUGXKlf9cLYfwSpxAZ6liR+SS+Ag3sjcSu qvSjMLHFv0ZbXY8fUCwDkvdzU1M0mtaKHHNg5Fl8SD0RXHZjVk5y8ArZoxaLuB93v3Fp QOVdogmHD2JshBb5PCF4zKHbH2eqHPtoPQBV47HcBSwQVYviH/6D7XVnuBO9nka57PSa Q0rg== X-Gm-Message-State: ALKqPwfC9ilh+kTFnAxejwadIKdCVmgekc+rVEKpMiF7ONgLGm5d1G2y O6XDP730BuUNaNN1kyn3aPK0G0cKGPCdJaw2zsY= X-Received: by 2002:a1f:1dcf:: with SMTP id d198-v6mr8040607vkd.113.1526669999096; Fri, 18 May 2018 11:59:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.151.90 with HTTP; Fri, 18 May 2018 11:59:18 -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: Fri, 18 May 2018 14:59:18 -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: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.