Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4414590pxa; Mon, 10 Aug 2020 08:32:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeW/E2oM+L0KOa3zVwspT2ZcxhpHOAt/WTah0kSfaW/rTfjk+Iq/Y+t8PLTAp9lRE/n9K5 X-Received: by 2002:a17:906:7fc9:: with SMTP id r9mr21447781ejs.407.1597073568535; Mon, 10 Aug 2020 08:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073568; cv=none; d=google.com; s=arc-20160816; b=KJAlvNkG1OtwbEh9mSF9wXnbCh3p93v+CKe3DFLn0ptbG+XpjLIEzxbsvMbFvW1kwP 1QDgjvxaaLv90XYw7XYCBKCOSQA+wxkbEt4BZSbQMVEMAyDUbCsbU/1Rl1E/0afGpCUQ fe7exJtpFCJMb/L5F20sJQorSHMr9uoUxYH7HhXDJgwUYWwOXnz3eIFfcS1ofMcz0Ifw WlY5WT5rs9+gUjMQNPzMw5lTd/MDk/oqE2RtMUOvXDL27xzxo645r/Pqou0L0QCFx84T qX3k9rxdHCCaMikiNneZcivO6jr3hrfKcMgApYEoBRoz3YrmkkY1502ifBCqY7cwqKOX HaMQ== 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=h6hdaAh88oPOWW0cbGvS7rOI7+Y5DOdeygCP1UB2EGo=; b=nDh+H29omcMJVM6DVw/4PJktwyIgfqedkWfMTwSeVpO71FO4Vz9SBt+oSFXMe7+t8M sLmkA/Ak9YcMc3y282xojeW8AfVzP3Xs18s2V/xdjg5cPXLO+MjgJ3y3mSJ980S0G0SX 53EBBYMAAlX62JaY31H3CbEnXeaTy8E4BfytW2YKCQb0O+FGNI7MIsDCjVVMGH5tJiJN Ky69w29NbF0w5lIyE0H+38SoJidGouA1jHLjTMLu6E9Y4tFP06+DPg09cRR3z4pGstgu v0QI2X41flkcwtsAYjG/q9IPMFaLaQAI7ggvmNb6mEwt8PRv9Y+2fTaasXRym0vgd87L jwQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=etnyEP1V; 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 md1si10818006ejb.344.2020.08.10.08.32.25; Mon, 10 Aug 2020 08:32:48 -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=etnyEP1V; 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 S1728994AbgHJPby (ORCPT + 99 others); Mon, 10 Aug 2020 11:31:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:38650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729190AbgHJPbR (ORCPT ); Mon, 10 Aug 2020 11:31:17 -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 8C685207FF; Mon, 10 Aug 2020 15:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073477; bh=vXeEIzsqQBvfgLUHF5Suok51uUamakv2YzQy1CuxnzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=etnyEP1VukVgZLVNdlu8Vpgk5QAbASJzky2oBSwj0xm2WCdJklYc7ClhciFPF/ejP gmb1H2N0Bhrfa1UbfuJU0Tlv04B6WyZ6AqbcQbgH6befxo7ESJJXhJom/xFz6ms87e r+ZAMA5bnYeBGugM+kovtk2Wiua5PkaWwWoQ8VVU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Xiong , Xiyu Yang , Xin Tan , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 28/48] atm: fix atm_dev refcnt leaks in atmtcp_remove_persistent Date: Mon, 10 Aug 2020 17:21:50 +0200 Message-Id: <20200810151805.596847709@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151804.199494191@linuxfoundation.org> References: <20200810151804.199494191@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 Xiong [ Upstream commit 51875dad43b44241b46a569493f1e4bfa0386d86 ] atmtcp_remove_persistent() invokes atm_dev_lookup(), which returns a reference of atm_dev with increased refcount or NULL if fails. The refcount leaks issues occur in two error handling paths. If dev_data->persist is zero or PRIV(dev)->vcc isn't NULL, the function returns 0 without decreasing the refcount kept by a local variable, resulting in refcount leaks. Fix the issue by adding atm_dev_put() before returning 0 both when dev_data->persist is zero or PRIV(dev)->vcc isn't NULL. Signed-off-by: Xin Xiong Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/atm/atmtcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c index afebeb1c3e1e9..723bad1201cc5 100644 --- a/drivers/atm/atmtcp.c +++ b/drivers/atm/atmtcp.c @@ -432,9 +432,15 @@ static int atmtcp_remove_persistent(int itf) return -EMEDIUMTYPE; } dev_data = PRIV(dev); - if (!dev_data->persist) return 0; + if (!dev_data->persist) { + atm_dev_put(dev); + return 0; + } dev_data->persist = 0; - if (PRIV(dev)->vcc) return 0; + if (PRIV(dev)->vcc) { + atm_dev_put(dev); + return 0; + } kfree(dev_data); atm_dev_put(dev); atm_dev_deregister(dev); -- 2.25.1