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=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 9934DC433F8 for ; Mon, 20 Jul 2020 15:38:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67A6122CB2 for ; Mon, 20 Jul 2020 15:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595259480; bh=yXP0nJ0lUk90ViUe6imEiLf5QQSGcmAp58EZXQIHB78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=B9sNATvGZpKsfUlnJb9XyiaYSSsxpOwD9zjDq2gddl6O4tJNc8XR8Ba2H9pj+kTL+ rZkPiDrev1RecIupdE91fqDeReA49NCEu6a9OSqAR0u/YER7L6/I3k+17j8FMbP5VG q4N8qS+h1uE9Awgjbf1w6JAbfuL0WjtFHRruyvt4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729016AbgGTPh7 (ORCPT ); Mon, 20 Jul 2020 11:37:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:56240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728993AbgGTPhz (ORCPT ); Mon, 20 Jul 2020 11:37:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6EEF422CB2; Mon, 20 Jul 2020 15:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595259475; bh=yXP0nJ0lUk90ViUe6imEiLf5QQSGcmAp58EZXQIHB78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=my2yGPiZ5PvQREjSENR1Y711COv7/hVNQ3tDCRNHoO0CNbizgnx54g0OMMO07c4Bz 9nBXeo2giIiw3vRkD+PhEG0RUIn/Eq7PHWWa479T5qnyugFpVvc3Sj9L9tuMUTIeBe C76VuzRf9s3zbSfiS8cMLcRJ2izHA7OpPp5AmQdk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangbin Liu , Xin Long , James Chapman , "David S. Miller" Subject: [PATCH 4.4 21/58] l2tp: remove skb_dst_set() from l2tp_xmit_skb() Date: Mon, 20 Jul 2020 17:36:37 +0200 Message-Id: <20200720152748.201004849@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152747.127988571@linuxfoundation.org> References: <20200720152747.127988571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit 27d53323664c549b5bb2dfaaf6f7ad6e0376a64e ] In the tx path of l2tp, l2tp_xmit_skb() calls skb_dst_set() to set skb's dst. However, it will eventually call inet6_csk_xmit() or ip_queue_xmit() where skb's dst will be overwritten by: skb_dst_set_noref(skb, dst); without releasing the old dst in skb. Then it causes dst/dev refcnt leak: unregister_netdevice: waiting for eth0 to become free. Usage count = 1 This can be reproduced by simply running: # modprobe l2tp_eth && modprobe l2tp_ip # sh ./tools/testing/selftests/net/l2tp.sh So before going to inet6_csk_xmit() or ip_queue_xmit(), skb's dst should be dropped. This patch is to fix it by removing skb_dst_set() from l2tp_xmit_skb() and moving skb_dst_drop() into l2tp_xmit_core(). Fixes: 3557baabf280 ("[L2TP]: PPP over L2TP driver core") Reported-by: Hangbin Liu Signed-off-by: Xin Long Acked-by: James Chapman Tested-by: James Chapman Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/l2tp/l2tp_core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1139,6 +1139,7 @@ static int l2tp_xmit_core(struct l2tp_se /* Queue the packet to IP for output */ skb->ignore_df = 1; + skb_dst_drop(skb); #if IS_ENABLED(CONFIG_IPV6) if (tunnel->sock->sk_family == PF_INET6 && !tunnel->v4mapped) error = inet6_csk_xmit(tunnel->sock, skb, NULL); @@ -1203,10 +1204,6 @@ int l2tp_xmit_skb(struct l2tp_session *s goto out_unlock; } - /* Get routing info from the tunnel socket */ - skb_dst_drop(skb); - skb_dst_set(skb, sk_dst_check(sk, 0)); - inet = inet_sk(sk); fl = &inet->cork.fl; switch (tunnel->encap) {