Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2024728pxa; Mon, 3 Aug 2020 05:41:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpF/Ra4DvY/oIKmM9bDeT/N6S9b4cNM2xd08kJ4MM76HeWjO8tN84kUEhjwYvCeGr14L/8 X-Received: by 2002:a05:6402:1a26:: with SMTP id be6mr15331731edb.162.1596458483881; Mon, 03 Aug 2020 05:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458483; cv=none; d=google.com; s=arc-20160816; b=KZHD82EDSgjaPRysPbyRQE6n49HBIUBdQW13kuCtk8Uf+K9r0KJgnfFl35GBUxNVu6 tOL0k4NJ6nUvxEI8MYM6llYtfKP92drmHmz5hlGOm0DYwzbphwNjEDfTzfel63ZORjh8 Rdr7ul7E2rnpIq0kw0betAf3dUebLPQUYSb2LogXe3HY6oC2/0C40gw/oNaq+HpesoVJ uPZkkl6s1d8heyVnWwH47olswtB7n9s0Rs1Wm4OHf5MneQ/2gkbbARwX8VpXOItT6C83 PQoyqynhs2EG8GsMAucmxiUEBi8t2B7YOUUmAnDFAbRt2qmVigrZ93b7fNZmq2/7Hf2c iIzw== 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=vAnzC6h91ZsVhYCr3KWcAQ6ej+bC6zX8nhY+lpnoGb8=; b=bYAba+4rtTi3+Ijo2pCMbZsRK8ZDGs5BNvLjdu2gSFtoqBSNSnQpOK/EYFBoS03GOu N13FJnMtZ8B/ihoH5sV0Y7mUT06xPN31G2ZNqbJHZej1GPrxjVGsagmKwcBOVwtA2bfl 4tsGG2SasHPyly226Me5AeiPfb5HU/tmUGqPyOBYzD+bw/L5zd2JKr8cJSCoXg4aT12w UkoB9zMZdZOygN7FTKZywAFyDNkNQRy1qgYwoIeYdxkiHyg1qiPyM/D6Fj14Z0UdkL4N AsEg8PpoFha8MCTH8upLnMNFE/z7zrfsKvbnFVX9CkcK7lUDFWtrEuYxItz0SdHLT/dJ JKGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aHouRpdt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk14si10368862edb.61.2020.08.03.05.41.01; Mon, 03 Aug 2020 05:41:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aHouRpdt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729395AbgHCMdM (ORCPT + 99 others); Mon, 3 Aug 2020 08:33:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:32846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729386AbgHCMdC (ORCPT ); Mon, 3 Aug 2020 08:33:02 -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 27DE3204EC; Mon, 3 Aug 2020 12:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457981; bh=0Aup74NOSS42XQ7aEIwZYIA0RB6k4tahoOrwdO6yJoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHouRpdtEiNUA954OAhLcSwwkYxP/f+Sb9wVQ7934gsCuYSPj7aSdd3ZIsIDc2rEz 4VJQKnozglM3YuF/k5VqB+TRfSHtz2U8FfjsjSEZL5EZGW3prnrK1PXJ1FLPaJczFq xgzu44Oskavjgr2F0x7rZ4rRRuUiQMWSWevjFhFQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Tan , "David S. Miller" Subject: [PATCH 4.19 25/56] net/x25: Fix x25_neigh refcnt leak when x25 disconnect Date: Mon, 3 Aug 2020 14:19:40 +0200 Message-Id: <20200803121851.567113942@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@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: Xiyu Yang commit 4becb7ee5b3d2829ed7b9261a245a77d5b7de902 upstream. x25_connect() invokes x25_get_neigh(), which returns a reference of the specified x25_neigh object to "x25->neighbour" with increased refcnt. When x25 connect success and returns, the reference still be hold by "x25->neighbour", so the refcount should be decreased in x25_disconnect() to keep refcount balanced. The reference counting issue happens in x25_disconnect(), which forgets to decrease the refcnt increased by x25_get_neigh() in x25_connect(), causing a refcnt leak. Fix this issue by calling x25_neigh_put() before x25_disconnect() returns. Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/x25/x25_subr.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/net/x25/x25_subr.c +++ b/net/x25/x25_subr.c @@ -362,6 +362,10 @@ void x25_disconnect(struct sock *sk, int sk->sk_state_change(sk); sock_set_flag(sk, SOCK_DEAD); } + read_lock_bh(&x25_list_lock); + x25_neigh_put(x25->neighbour); + x25->neighbour = NULL; + read_unlock_bh(&x25_list_lock); } /*