Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6704011imm; Tue, 24 Jul 2018 01:20:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc6+PRFwFUKoIZhdImzLwQUE1keDXEBc7BObdj8LnbljuQ2OGbPqLc8JmtV9PR9P1OScQdp X-Received: by 2002:a62:21c3:: with SMTP id o64-v6mr16686150pfj.21.1532420432877; Tue, 24 Jul 2018 01:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532420432; cv=none; d=google.com; s=arc-20160816; b=nSuq7piCkzlx1/YrMSvUf/dzhgl+58WowJZDBoP/8lmZuB9vD19k5vdMmRAbMrCh31 d/05DVa6+YLIet/Z+VhdL5lGIJ3PK+qCMjbVst1EP0DDDBVJD+ui0KlcmmwmgnoDqoK2 YeGvh9HWVwRLOpbcmjb/WWnampavF7XS6RUz3qRjctndEfW7aLnQl3G65CyNqFPrGDJc xgesJI4p5yDBPaVX82vmYYqc4UaKBEGg/RuW3i082jkjE+inh5ZSFHBxhugsgP9ouE6X B6gJb/4RVy2mz0zQ08+gg6TeUsV3u0vcoDVdtiwPq9B+In2g6aw8p41VIwYihGRXyVgi sKeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yh2UEESqjVMkEpEKyE2mr7mZ5xv1bDN02romlesCSPY=; b=Lp635KNni4ElH7r2Giij/5y7Q1ULukUeaWSnt1IbaTWeIHc2S/lwRy24W2IZ4ZAMLH 8zGoNWBAC1QnxJWcSjYipbInoxHWNjuBU+wNfDRkppjGGwdlxLeMqGEn/E2Fdd8ESs5F yA8JkmlEQeOfRmeywhOevN7tMOsh8ARupVoSA3pRwg+zowiXb61gzI243c5Ymikz+ed7 2ICYBvhL7PxnowT79CiSj5LM/tEgs2uoiKISpQqj02I3Z6HtLNS3myvSZmJMbF7OLb4F oN+n2ZotUHy+bmGiiTSorszDTmF705Qa310Ts6HXEo11n1ACS6EcRHdzwzkzOoqatJxB K6pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k20-v6si10115285pgb.115.2018.07.24.01.20.18; Tue, 24 Jul 2018 01:20:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388768AbeGXJY2 (ORCPT + 99 others); Tue, 24 Jul 2018 05:24:28 -0400 Received: from out1.zte.com.cn ([202.103.147.172]:45054 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388461AbeGXJY1 (ORCPT ); Tue, 24 Jul 2018 05:24:27 -0400 X-Greylist: delayed 952 seconds by postgrey-1.27 at vger.kernel.org; Tue, 24 Jul 2018 05:24:24 EDT Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 65BD4AC1A946A228560F; Tue, 24 Jul 2018 16:03:16 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w6O83BA6059513; Tue, 24 Jul 2018 16:03:11 +0800 (GMT-8) (envelope-from tan.hu@zte.com.cn) Received: from localhost.localdomain ([10.75.9.60]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018072416031519-1499306 ; Tue, 24 Jul 2018 16:03:15 +0800 From: Tan Hu To: wensong@linux-vs.org, horms@verge.net.au, ja@ssi.bg, pablo@netfilter.org, kadlec@blackhole.kfki.hu, fw@strlen.de, davem@davemloft.net Cc: netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, jiang.biao2@zte.com.cn Subject: [PATCH] ipvs: fix race between ip_vs_conn_new() and ip_vs_del_dest() Date: Tue, 24 Jul 2018 16:12:33 +0800 Message-Id: <1532419953-5517-1-git-send-email-tan.hu@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-07-24 16:03:15, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-07-24 16:03:07, Serialize complete at 2018-07-24 16:03:07 X-MAIL: mse01.zte.com.cn w6O83BA6059513 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We came across infinite loop in ipvs when using ipvs in docker env. When ipvs receives new packets and cannot find an ipvs connection, it will create a new connection, then if the dest is unavailable (i.e. IP_VS_DEST_F_AVAILABLE), the packet will be dropped sliently. But if the dropped packet is the first packet of this connection, the connection control timer never has a chance to start and the ipvs connection cannot be released. This will lead to memory leak, or infinite loop in cleanup_net() when net namespace is released like this: ip_vs_conn_net_cleanup at ffffffffa0a9f31a [ip_vs] __ip_vs_cleanup at ffffffffa0a9f60a [ip_vs] ops_exit_list at ffffffff81567a49 cleanup_net at ffffffff81568b40 process_one_work at ffffffff810a851b worker_thread at ffffffff810a9356 kthread at ffffffff810b0b6f ret_from_fork at ffffffff81697a18 race condition: CPU1 CPU2 ip_vs_in() ip_vs_conn_new() ip_vs_del_dest() __ip_vs_unlink_dest() ~IP_VS_DEST_F_AVAILABLE cp->dest && !IP_VS_DEST_F_AVAILABLE __ip_vs_conn_put ... cleanup_net ---> infinite looping Fix this by checking whether the timer already started. Signed-off-by: Tan Hu Reviewed-by: Jiang Biao --- net/netfilter/ipvs/ip_vs_core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index 0679dd1..ca9e7cc 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -1972,13 +1972,17 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb, if (cp->dest && !(cp->dest->flags & IP_VS_DEST_F_AVAILABLE)) { /* the destination server is not available */ + /* when timer already started, silently drop the packet.*/ + if (timer_pending(&cp->timer)) + __ip_vs_conn_put(cp); + else + ip_vs_conn_put(cp); + if (sysctl_expire_nodest_conn(ipvs)) { /* try to expire the connection immediately */ ip_vs_conn_expire_now(cp); } - /* don't restart its timer, and silently - drop the packet. */ - __ip_vs_conn_put(cp); + return NF_DROP; } -- 1.8.3.1