Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp731726imm; Thu, 13 Sep 2018 06:59:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaybAC1tIB9obZXE1+v7wNvH92drNUjxXWlEQdx6ZQHAGlTHy4nxrWQtE5qXXoEoqHJpj2C X-Received: by 2002:a63:6881:: with SMTP id d123-v6mr7253040pgc.298.1536847159550; Thu, 13 Sep 2018 06:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847159; cv=none; d=google.com; s=arc-20160816; b=e+bKKey6uksG85CwNs4nozJUgR4IgMYWsRuU+TwGQe48REP7CXUxZ+nBLPmoXm1oOx 37THic/yeSU4rTFmJNoLvxQLZnBIle5/J/pIkkGJ1aeHJn1KFS/nyBLgk4NKUuZaAtvY ksW3V/3SBf4/jVrOTsB3MImAx7vwpzZX2p+TOIuZNP3BRhQ7DnQVTWd3Baa7cpsX5HNe 4StQvQ7acs6cslVCIkyZ9OfH7uHIfYAbQJp6/gqNwM4mNHaLVYR2gRfjzftrAyG6GtDj 4X9foHYhvvRbX85syBGkyMOUCRsVxDUILNP8eynjQKWb0VsJYs+2WD2VvIyO+dHp8oan kHZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=DXOop7PONXGvMpqln3glLr8X71ycuKyp6FYDFeKVicw=; b=MzvP9CLc1BpXwplkVTu0U03wX2acUGYey55H6CBWZ7rLrYdNFSZXbPBOyo1TRuNkSJ /EAnYqxHGbATdvfCNS314DvNRMFkpLlOJfJondnw+b523MNTiUtaVyleidQw7ouWQf8e Qf3pMH8PqJky+gBoXZcTASpEmMaIjpPf6citSIUCmUMexnjr7CNTdka8jKwg+xm6FMyn u6HRcguLHSrjMyB2ZlmlC53iMxGGNDk9hX1fpVfmPINhF06rNIxCNJb332VUiqEDK36N +QupDGxPP9WoLga7hpaC0X8T/oZimbc5h+GIMDMZydVGUr9igUdYs3zSZbYCYrCEu+fS g/Ng== 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 d17-v6si3863661pgp.549.2018.09.13.06.59.04; Thu, 13 Sep 2018 06:59:19 -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 S1731653AbeIMTIg (ORCPT + 99 others); Thu, 13 Sep 2018 15:08:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34752 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731373AbeIMTIf (ORCPT ); Thu, 13 Sep 2018 15:08:35 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CB4C8D19; Thu, 13 Sep 2018 13:58:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tan Hu , Jiang Biao , Julian Anastasov , Simon Horman , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.18 071/197] ipvs: fix race between ip_vs_conn_new() and ip_vs_del_dest() Date: Thu, 13 Sep 2018 15:30:20 +0200 Message-Id: <20180913131844.364786660@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tan Hu [ Upstream commit a53b42c11815d2357e31a9403ae3950517525894 ] 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 Acked-by: Julian Anastasov Acked-by: Simon Horman Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/netfilter/ipvs/ip_vs_core.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -1972,13 +1972,20 @@ ip_vs_in(struct netns_ipvs *ipvs, unsign if (cp->dest && !(cp->dest->flags & IP_VS_DEST_F_AVAILABLE)) { /* the destination server is not available */ - if (sysctl_expire_nodest_conn(ipvs)) { + __u32 flags = cp->flags; + + /* 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) && + !(flags & IP_VS_CONN_F_ONE_PACKET)) { /* 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; }