Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FFD2C43381 for ; Sat, 16 Mar 2019 20:02:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E9C821019 for ; Sat, 16 Mar 2019 20:02:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sAwsIehn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbfCPUCy (ORCPT ); Sat, 16 Mar 2019 16:02:54 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35200 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726376AbfCPUCy (ORCPT ); Sat, 16 Mar 2019 16:02:54 -0400 Received: by mail-pg1-f196.google.com with SMTP id e17so8710019pgd.2 for ; Sat, 16 Mar 2019 13:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sdHWDNpllgQHyJOFXxgjdD9IbKvTMedHjVyAlppPTYY=; b=sAwsIehnRatAB/wpttDFQYRCv9RofJCamCetJfK0pKaB+kQwLVXHRXjZ2vIkD6YLOB bbSTZMlUDPDxAnMMHm5N/8zAK+XX5lzetZRIRSAGdPeZKJLybxehExnGJqbKsJ76NEtB 0DwpEr3Pjzn18DmLQJWX0NDQChMjNgufCNRdkPtc9b2HzMB1NtyhRfDZiZeH5QVWZzeb 3wsKHy6wf0mM7nQ75hB9uF2/48dalBbMTH5cMIIEeyzoFhhYnINXdlIaXYbVyTxxvIwF 0bRKppBKO7YszEzHPk9ZM5YRif/vBerTRg+GORvNyDQtb3DnU/j2nIl4bvf45pIIIGhw U3fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sdHWDNpllgQHyJOFXxgjdD9IbKvTMedHjVyAlppPTYY=; b=D1fRFmhIdmIImgxg2VRb+H7/pv2KjhE5J6Ri5acP4SSdEuSAQ1MrpIS3rDFYD84TYt FBur2Lk4gPAfk6rQXsDEPw82lsDgHEstCy9X7MiRLNWeYGe9cUFT+4GfS4rtYm4aWh82 URr5wibOQpERVaes5gG1hdjs4LU/YobvnQtTgfzJs0zpIub1kgwz40gPm6kH53wwxMn8 Q0VRrCntmIQWgivoLF6JRoxysKGiLiVqomlyg+X269O+1T0Tt76xLokKxJ8ZzmP4H+Yv 0Ij7OS9vaf2UmouT2Gj7iYVaBq0Rwt8BdzlpIyOS6upcwYkFb1hrq+cPpb5oEol//5Kh R4+Q== X-Gm-Message-State: APjAAAX29D0x3iFvjNgqgppHRb1BEuuLhtlp8sz4niZsX/PxErDUCwn3 bvg+7QR/1zHxWKUnaZkZLWE= X-Google-Smtp-Source: APXvYqxlLZnMwC1tLS0K6FEPNVKgxJ2h2d2aQL/ThXrlisRlXfaCSGuCeixokiHfJVtkfV27mccxKA== X-Received: by 2002:a62:29c6:: with SMTP id p189mr11148860pfp.194.1552766573747; Sat, 16 Mar 2019 13:02:53 -0700 (PDT) Received: from [192.168.86.235] (c-73-241-150-70.hsd1.ca.comcast.net. [73.241.150.70]) by smtp.gmail.com with ESMTPSA id u10sm6609537pgr.2.2019.03.16.13.02.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Mar 2019 13:02:52 -0700 (PDT) Subject: Re: [PATCH net] tun: properly test for IFF_UP To: Eric Dumazet , "David S . Miller" Cc: netdev , Eric Dumazet , syzbot References: <20190315031947.63245-1-edumazet@google.com> From: Eric Dumazet Message-ID: <8bf60184-c950-0d47-7bc9-adc68e7ae1b1@gmail.com> Date: Sat, 16 Mar 2019 13:02:51 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190315031947.63245-1-edumazet@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 03/14/2019 08:19 PM, Eric Dumazet wrote: > Same reasons than the ones explained in commit 4179cb5a4c92 > ("vxlan: test dev->flags & IFF_UP before calling netif_rx()") > > netif_rx_ni() or napi_gro_frags() must be called under a strict contract. > > At device dismantle phase, core networking clears IFF_UP > and flush_all_backlogs() is called after rcu grace period > to make sure no incoming packet might be in a cpu backlog > and still referencing the device. > > A similar protocol is used for gro layer. > > Most drivers call netif_rx() from their interrupt handler, > and since the interrupts are disabled at device dismantle, > netif_rx() does not have to check dev->flags & IFF_UP > > Virtual drivers do not have this guarantee, and must > therefore make the check themselves. > > Fixes: 1bd4978a88ac ("tun: honor IFF_UP in tun_get_user()") > Signed-off-by: Eric Dumazet > Reported-by: syzbot > --- > drivers/net/tun.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 1d68921723dc08532b3f5321a52865076ad66336..0d343359f647ff58fee35462358827e61857c837 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -1763,9 +1763,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > int skb_xdp = 1; > bool frags = tun_napi_frags_enabled(tfile); > > - if (!(tun->dev->flags & IFF_UP)) > - return -EIO; > - > if (!(tun->flags & IFF_NO_PI)) { > if (len < sizeof(pi)) > return -EINVAL; > @@ -1867,6 +1864,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > err = skb_copy_datagram_from_iter(skb, 0, from, len); > > if (err) { > + err = -EFAULT; > +drop: > this_cpu_inc(tun->pcpu_stats->rx_dropped); > kfree_skb(skb); > if (frags) { > @@ -1874,7 +1873,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > mutex_unlock(&tfile->napi_mutex); > } > > - return -EFAULT; > + return err; > } > } > > @@ -1958,6 +1957,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > !tfile->detached) > rxhash = __skb_get_hash_symmetric(skb); > > + rcu_read_lock(); > + if (unlikely(!(tun->dev->flags & IFF_UP))) { > + err = -EIO; Hmm, it looks like I forgot a rcu_read_unlock() here. > + goto drop; > + } > + > if (frags) { > /* Exercise flow dissector code path. */ > u32 headlen = eth_get_headlen(skb->data, skb_headlen(skb)); > @@ -1965,6 +1970,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > if (unlikely(headlen > skb_headlen(skb))) { > this_cpu_inc(tun->pcpu_stats->rx_dropped); > napi_free_frags(&tfile->napi); > + rcu_read_unlock(); > mutex_unlock(&tfile->napi_mutex); > WARN_ON(1); > return -ENOMEM; > @@ -1992,6 +1998,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > } else { > netif_rx_ni(skb); > } > + rcu_read_unlock(); > > stats = get_cpu_ptr(tun->pcpu_stats); > u64_stats_update_begin(&stats->syncp); >