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,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 916FEC282E1 for ; Mon, 22 Apr 2019 22:29:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60078204EC for ; Mon, 22 Apr 2019 22:29:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Elw1oydx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730245AbfDVW3j (ORCPT ); Mon, 22 Apr 2019 18:29:39 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:49306 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727407AbfDVW3i (ORCPT ); Mon, 22 Apr 2019 18:29:38 -0400 Received: by mail-qk1-f201.google.com with SMTP id 23so11594911qkl.16 for ; Mon, 22 Apr 2019 15:29:37 -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=Elw1oydxMKFfTFBuM8+CZK0xN0cwRAQ7Z3MnyhzVgcxJTXF7EE871nte1m2aOYm3an NBY6cmbI8F22Iic2KfZiWM+bwcMN70mm4MEW+4xEBTZG/UCSXD5ltsVd+2fGdwFG8Vfd l4SN9we7OLvAAX58OlKZMKbalsd7sq5hzH4zUWEyhP60rQDmRhFjvgYunE9prCw92zih qpFw+l66irExG5AfLbl+q+uvkrQCs4nfydno81gXW1SnnH4acvd0FJ5ccSbuHL1k2Xd4 27Yvb6xRph48MIPilCTBbj+mVa8D35VIv1KsQhNZ656YXWHKJ8+QcjVu7inpaMVHIBEj eCrQ== 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=g2VRydRa/tJ0hshpDE5/tav6Th+tqSVUOyF40fLCqDsFkOkQrHJ4OPUhdo+docBe1Y 08/Znwudm57tnh1TMwWCMoIV+4ufSUMP+niFXVWUqpTvxfni5Jdz47y7VAo/jFF0NVy8 NIu5JvYP1JqpQ9P9PiLSlrKfLurr1MGEkeEqmK5p9kFu4vimtHQ3SrzbjHyYM7lZfJhr Ygn2JBRx+Tj61I+VZasyNpMHijYdnLuX0DrDDlKosyxN2jN+I0PhY6vZeeVzIiUr7c1P AJzVjJqbsvYQADUNA9cPxGM5Hykcw5eO56oL4p1jWp+sXEVS9DBj9L1/camPo7ie/7LL obZw== X-Gm-Message-State: APjAAAXXOlzgpRHB/2qAuH9cze5b5UNCsM/qNPygydF4Ldn8sNorR3Pg OyJDlJdUDt61+MrqayvV3H+c8hGX X-Google-Smtp-Source: APXvYqz24m7tE/kfT5DbA1f5CmsPOWlliFEb2Mc4gO1IoCLpo7h4sUJGHxV9JjtK065PWBDv6XZorN+L X-Received: by 2002:ae9:f403:: with SMTP id y3mr17443670qkl.301.1555972177253; Mon, 22 Apr 2019 15:29:37 -0700 (PDT) Date: Mon, 22 Apr 2019 15:29:26 -0700 In-Reply-To: <20190422222930.195053-1-posk@google.com> Message-Id: <20190422222930.195053-2-posk@google.com> Mime-Version: 1.0 References: <20190422222930.195053-1-posk@google.com> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH 4.14 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 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