From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 4F944C43218 for ; Fri, 26 Apr 2019 15:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EF55206E0 for ; Fri, 26 Apr 2019 15:41:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HMM5WLh2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbfDZPlS (ORCPT ); Fri, 26 Apr 2019 11:41:18 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:53790 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbfDZPlR (ORCPT ); Fri, 26 Apr 2019 11:41:17 -0400 Received: by mail-qk1-f201.google.com with SMTP id k8so3040055qkj.20 for ; Fri, 26 Apr 2019 08:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rEbSdTKKeAFt5WvgLdodgWB9c/0wbhWtboJF4nL298A=; b=HMM5WLh2ryEB9DItJfad/v0bsiG+JIg9wYXhXlSoKsFtwS77Mc6qcZ8ynHo0sTLwHp Ig0wPOIac4kCFpZYrVWCneTN4GcgLsKD9pjKTDIe/ajkrSRNOeGXAsvPLpkQM2HgDhlg vIuGftU9QX/cKuS85+P9bI7lsJXdh9ByUNOoD6rnRsr2C2HWa+KBMWqptrlpXFcP0GB7 wXD8elRHkR03HPJvb5qN4jlZDSRzUJ0OYujQP8qZlPDF3K1+CXsliolzBl41/jUA0aYC bwXzH0lCDwCaHQ1EujugAxiKRoUtMvEeZGFHGCmyAeRiKDsdkYHah7Y1KcCKJg83g44k eRhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rEbSdTKKeAFt5WvgLdodgWB9c/0wbhWtboJF4nL298A=; b=N+vXBlxitMF7am65GV3U8aeKHbkj7JsxtxTSh8E+/zbRmcgF2+CdLiw8sr5lS8VSCk LkfTWb15ohjZoMLelu5+NaBfEQZAcZq27LEyg7HPGOSgFN2yoKsqfzb/DSkZwYHc3RkU 3gMxMMkIeGGOxT5QNxJj+04HimhauYrRCbdrXVHcRfuJ0/yb7dZpPrRRx0vJjKdLYHpO Ac9DeXjemfkI9WHa1/uCT7saVAOXxD3ktO6B3r61wCVh2xvNbeFGVvu17WFNpigKc1g4 rDDv5wlijaj2pR+fdckSJDIcrr+ZlAqTXNiZTkwQ/rDOx28Mr6yEHzjN8DfZWG1obJZU WIeA== X-Gm-Message-State: APjAAAWm/glJ4ysmKUzVRITOw6QURKb+/pL12s1U9P2jNh+aILz+uLxI ItiedsatWYk9k/LBXlaZ515KG37A X-Google-Smtp-Source: APXvYqzkHeBydHQ7kM4Pw6SXpeagss5f2YuVmIJz/NsKTRDoFEtIVQWgcaGB5Wk1mJcG5pa+zSt07uwA X-Received: by 2002:ac8:1914:: with SMTP id t20mr12160841qtj.197.1556293275952; Fri, 26 Apr 2019 08:41:15 -0700 (PDT) Date: Fri, 26 Apr 2019 08:41:04 -0700 In-Reply-To: <20190426154108.52277-1-posk@google.com> Message-Id: <20190426154108.52277-2-posk@google.com> Mime-Version: 1.0 References: <20190426154108.52277-1-posk@google.com> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH 4.9 stable 1/5] ipv6: frags: fix a lockdep false positive From: Peter Oskolkov To: Greg Kroah-Hartman , stable@vger.kernel.org, netdev@vger.kernel.org Cc: Peter Oskolkov , David Miller , Eric Dumazet , Sasha Levin , Captain Wiggum , Lars Persson Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet [ Upstream commit 415787d7799f4fccbe8d49cb0b8e5811be6b0389 ] lockdep does not know that the locks used by IPv4 defrag and IPv6 reassembly units are of different classes. It complains because of following chains : 1) sch_direct_xmit() (lock txq->_xmit_lock) dev_hard_start_xmit() xmit_one() dev_queue_xmit_nit() packet_rcv_fanout() ip_check_defrag() ip_defrag() spin_lock() (lock frag queue spinlock) 2) ip6_input_finish() ipv6_frag_rcv() (lock frag queue spinlock) ip6_frag_queue() icmpv6_param_prob() (lock txq->_xmit_lock at some point) We could add lockdep annotations, but we also can make sure IPv6 calls icmpv6_param_prob() only after the release of the frag queue spinlock, since this naturally makes frag queue spinlock a leaf in lock hierarchy. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller --- net/ipv6/reassembly.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 74ffbcb306a6..64c8f20d3c41 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c @@ -169,7 +169,8 @@ fq_find(struct net *net, __be32 id, const struct ipv6hdr *hdr, int iif) } static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, - struct frag_hdr *fhdr, int nhoff) + struct frag_hdr *fhdr, int nhoff, + u32 *prob_offset) { struct sk_buff *prev, *next; struct net_device *dev; @@ -185,11 +186,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1))); if ((unsigned int)end > IPV6_MAXPLEN) { - __IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), - IPSTATS_MIB_INHDRERRORS); - icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, - ((u8 *)&fhdr->frag_off - - skb_network_header(skb))); + *prob_offset = (u8 *)&fhdr->frag_off - skb_network_header(skb); return -1; } @@ -220,10 +217,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, /* RFC2460 says always send parameter problem in * this case. -DaveM */ - __IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), - IPSTATS_MIB_INHDRERRORS); - icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, - offsetof(struct ipv6hdr, payload_len)); + *prob_offset = offsetof(struct ipv6hdr, payload_len); return -1; } if (end > fq->q.len) { @@ -524,15 +518,22 @@ static int ipv6_frag_rcv(struct sk_buff *skb) iif = skb->dev ? skb->dev->ifindex : 0; fq = fq_find(net, fhdr->identification, hdr, iif); if (fq) { + u32 prob_offset = 0; int ret; spin_lock(&fq->q.lock); fq->iif = iif; - ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff); + ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff, + &prob_offset); spin_unlock(&fq->q.lock); inet_frag_put(&fq->q); + if (prob_offset) { + __IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), + IPSTATS_MIB_INHDRERRORS); + icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, prob_offset); + } return ret; } -- 2.21.0.593.g511ec345e18-goog