Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp869729ybl; Wed, 11 Dec 2019 08:45:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwtSVNm03AHAzp+dr8TkXx41QBojLgJCgXIMhNuITpsC/8viLdUaVLyhsofYmMiJ8d3AbVi X-Received: by 2002:a9d:7094:: with SMTP id l20mr3035238otj.190.1576082720419; Wed, 11 Dec 2019 08:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576082720; cv=none; d=google.com; s=arc-20160816; b=qZWygzw8a4BfBI+DtMxpZzyEgAuEHIs7sFSR1onkLwkwAJnpZ3G8RfQ0wImZuQBilP 1pKQ/uSQRyUGLSM5rNvb250HtgZ0Pk2Pf/iVoFTrkPdEVgWMLkOqjxWI3XzgUGRVGZhR 3PcThTMU6jOVcFwYh5wAWLBlg3Pqu+VaXZ0nczzNYGwzxWn2vwhedQgqthbNpEmduWtv H18MVXBAFAtFJ0cH7zce1G91yvttIYDQpPnvhphGjBWeF/jXTbP4ekAKtulvsPtLayac inbYju42oMDmfAjlw0hxD0GSl76atlcNKntvlbzLaRFkFQ6fhaYaBSr8KKkviys4T83m PM4g== 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:dkim-signature; bh=10lzTmOPQ6zS85mddCCF/QGaIZzbNtgyZVeftGBpNEQ=; b=yQcCXjjm2u5geCMRv21XFA7ghbYACRJEzYUkY925/1iipr0QlB18cIsOsYzqefgXf8 QkdWjRyLQ8BIdSltHLL9MH+oJHLqYr4od0wFpQ5fX4CSU/QZifqDMuleZUlxEnkRni26 7glu4hqxD+s5j4tggPuH/NwKyzdFDDatGOfoUp3ExIf8JQXBfGGloMaFYDdNSGp44J/X HQ2FS3RxgBb1qRhWAneB/Cmf+R6+Z8BiDrS3j26ZIuIkSGXqQthnus+lGchKbl/hTPUN f3jqqZYk0fgU/8+g+RbqVDjWd5onWBOtVe8SFx+aHhHK9W9UJIcpel/B/1VWJErRjx7s guLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pQtnC6gW; 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 h9si1515040otb.49.2019.12.11.08.45.04; Wed, 11 Dec 2019 08:45:20 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=pQtnC6gW; 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 S1731674AbfLKPQW (ORCPT + 99 others); Wed, 11 Dec 2019 10:16:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:43314 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731878AbfLKPQT (ORCPT ); Wed, 11 Dec 2019 10:16:19 -0500 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 3961E24658; Wed, 11 Dec 2019 15:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077378; bh=xcdkye4lRun+480vOvUlfnWMlKXPKn42zOyCFXCoA4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQtnC6gWT34Z2kO21vINO/K507BiYVkv0Lg2q2AtRcK0odSlRbicQ02v+akRssdi0 AN12tBfoDrgFTFDZ9W+1sqt6ZZPSwECLCrMYjxEKhXg7f/1VYDAsWk8FGU6msVuaBm Gem4iS0B/0fKaIwQM5xUSr1NJ76o0loTU7rzpx7w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaodong Xu , Bo Chen , Steffen Klassert , Sasha Levin Subject: [PATCH 4.19 017/243] xfrm: release device reference for invalid state Date: Wed, 11 Dec 2019 16:02:59 +0100 Message-Id: <20191211150340.183928044@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@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: Xiaodong Xu [ Upstream commit 4944a4b1077f74d89073624bd286219d2fcbfce3 ] An ESP packet could be decrypted in async mode if the input handler for this packet returns -EINPROGRESS in xfrm_input(). At this moment the device reference in skb is held. Later xfrm_input() will be invoked again to resume the processing. If the transform state is still valid it would continue to release the device reference and there won't be a problem; however if the transform state is not valid when async resumption happens, the packet will be dropped while the device reference is still being held. When the device is deleted for some reason and the reference to this device is not properly released, the kernel will keep logging like: unregister_netdevice: waiting for ppp2 to become free. Usage count = 1 The issue is observed when running IPsec traffic over a PPPoE device based on a bridge interface. By terminating the PPPoE connection on the server end for multiple times, the PPPoE device on the client side will eventually get stuck on the above warning message. This patch will check the async mode first and continue to release device reference in async resumption, before it is dropped due to invalid state. v2: Do not assign address family from outer_mode in the transform if the state is invalid v3: Release device reference in the error path instead of jumping to resume Fixes: 4ce3dbe397d7b ("xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0)") Signed-off-by: Xiaodong Xu Reported-by: Bo Chen Tested-by: Bo Chen Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_input.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c index d5635908587f4..82b0a99ee1f43 100644 --- a/net/xfrm/xfrm_input.c +++ b/net/xfrm/xfrm_input.c @@ -246,6 +246,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) else XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEINVALID); + + if (encap_type == -1) + dev_put(skb->dev); goto drop; } -- 2.20.1