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 85650C282E1 for ; Tue, 23 Apr 2019 17:48:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57EBF218B0 for ; Tue, 23 Apr 2019 17:48:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cYUecuRN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729455AbfDWRse (ORCPT ); Tue, 23 Apr 2019 13:48:34 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:33741 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729321AbfDWRsd (ORCPT ); Tue, 23 Apr 2019 13:48:33 -0400 Received: by mail-qk1-f202.google.com with SMTP id a188so13804796qkf.0 for ; Tue, 23 Apr 2019 10:48:32 -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=PO88u2Np2dPldt+tXJAk3eA690OhrDTUYq6Xk2cxDHE=; b=cYUecuRNNntu9qTX9MgFJsgkxlo3KtYk9yze+Zvq+0RjTMrTM7vq+AP2WqJLQNA/D9 3faVNIMpH9S+/i2m3I2O0Gce2+3ISm99Xawe0E6CfgAcJWu6dXFuqFgFt/MdRhPf89tD JdZWYia+bpAspjcKIBVFovGQrUWQLbWe9o6JH1JGxab4Cy7OhLJtofpPB5PT9ChhycfN ljgE42F+MS3Ct/ix2h7WR2lL4pdw//q7dAfidObbassgpK8datsE9oqIYQbJeD8LeLes LhLUbXM0DHNfuKkdFgI52C/CcGavt5IRnPuZhmiWyjDjicfW66CMu+kcHhjGXuy7NNBA /7Sg== 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=PO88u2Np2dPldt+tXJAk3eA690OhrDTUYq6Xk2cxDHE=; b=QALFr/YNyzIwa2IAYd14xqRlLPDMko0n+caFDfh1/1SB1oY/DDm9BLYIc1WgxBed7u vxraZvQA/OsDynGwhGI0joO7VbiNI4boRpVqKRzouGi/btGjlYH5bMHBUqGUIp+vzy0a zCTGje+idQMvWXT8+vuQW238KTT/MUGrPwSX7a155qebueWH9UfoVl34hMUrckbY+PNI pwTPyzjdBjkXOCVQORZJShuutaCgAFqX9XlRdxn7qvwaO5ygPmobIP7Mi9eAtxnU0nKo imLtOYpw+fZSBgRNiJjwJEXcvBBE/g17qVX9E5XnAefmx0rTEc5q8NrC1LphcGS83w6l F8zg== X-Gm-Message-State: APjAAAUmxRB10fC47SHJCfC4C6S47vMORy84qLNuFgsOgNGV4wt56d8j mT/bRlUoqt2vpQuufXz/3+iwZh0R X-Google-Smtp-Source: APXvYqyTNd5V+ZQRhF9HslvmQeSeGyWxDA7Y2P+t2S5p7t/Yt99+zjd/Lzid1+mRkCgh0lxrLc6EuEpx X-Received: by 2002:ac8:6d1:: with SMTP id j17mr14665447qth.134.1556041712076; Tue, 23 Apr 2019 10:48:32 -0700 (PDT) Date: Tue, 23 Apr 2019 10:48:21 -0700 In-Reply-To: <20190423174825.24810-1-posk@google.com> Message-Id: <20190423174825.24810-2-posk@google.com> Mime-Version: 1.0 References: <20190423174825.24810-1-posk@google.com> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH 4.14 stable v2 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 2a8c680b67cd..f75e9e711c31 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c @@ -170,7 +170,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; @@ -186,11 +187,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; } @@ -221,10 +218,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) { @@ -536,15 +530,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