Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3756502pxk; Tue, 29 Sep 2020 05:38:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBNni4tY6k8Vie5hrtkslfbrTRq+mYNo7qJ3wd7LwD5ZJ2lRYBuIbrcPPUnKt5dxv8tuns X-Received: by 2002:a17:906:c957:: with SMTP id fw23mr2821851ejb.510.1601383084583; Tue, 29 Sep 2020 05:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383084; cv=none; d=google.com; s=arc-20160816; b=zUQnMtH1s5Pajy1vM0DkCL9TZ2zhhBJ6bGmjJ7GNo6yzdGfLUZuFi5GPQoDJz6AAyK KJtuZGR4Q2C0saQKuxKqslaWqp6ZaVhwL4B3QVHra0RJ0ZNKq1Hb2WOtXdF0GOPzpIjW nVFAKczD39vQpFe3twAf0URumtcok0zoTSxb1p2V6XhWT15bkl3GJUo8C/Gkr9GsMguH Hp2j5yt0GsLziLzmS4QvbflCX/FQTWZLjqcvWavgF3sDwWBEdDO/NC6BFLsRRaDSCv89 yO2rdsPHVX9yTObxto+BfbRlqzIH8CI4hLZqe/A5/9Ic7D7lLtH2A0Pw1ZJe6cnuktUN 1zyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mABPdcK86omcPgkF1AhrS8Zo9HxKYWAxe7c4kBWCI00=; b=1EhwAo+Idr7zG0hYzXK8oIkEvocbk39d/K9FahiGlURZN0wIEK//VV4SqjXS1K0HtC xmSRVvKwMKYoBV3no6P+pEaHJhTuIEpspnEpvEeSONB8pXyS6bhjFXbBnfACdZaFQlYh 7uz8/rRY0k7yCvI5EC3iZo1te6e2UR7kaksG0XlnebKUmIO5xbQnqyqq5NLeqy/UDLcC JX1YRAwGbjKe17NtvpsqtlUqJzBTZUDmeAhl4ShAvvURp2U0snkTrt932QtJtuKdJrxB zfXwjZ9uMQlNntoTn2LROvcSs5V7yRP79breWnOYROkdTRUXDaLcQXJeMwgreCl5kQ8w xmoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uTUC6jSN; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo13si2459306ejb.200.2020.09.29.05.37.41; Tue, 29 Sep 2020 05:38:04 -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=uTUC6jSN; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729764AbgI2Mgo (ORCPT + 99 others); Tue, 29 Sep 2020 08:36:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:36424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729419AbgI2LU6 (ORCPT ); Tue, 29 Sep 2020 07:20:58 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 6251B2388B; Tue, 29 Sep 2020 11:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378318; bh=q4MqQEMeVjXUteqrkCzOYQn50fCqKwcytNOP0ZMrXrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTUC6jSNj4ocQaVpVYEaHjpXDZPYlZ75K8WbqSdeKpswpm0+nARztkNiv18Qw6Tj+ G/9h+ldL2ESrzO0tTnM9uM02gat6XNEEn7C36P47ZkPEoSauYYclwBJ+1rJODTmg2M 4lZ9b7vGnZxEz9/UEjNwxx3jaP0ap9h4iYf4G9DI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Girish Basrur , Saurav Kashyap , Shyam Sundar , Javed Hasan , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 138/166] scsi: libfc: Handling of extra kref Date: Tue, 29 Sep 2020 13:00:50 +0200 Message-Id: <20200929105942.084507245@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105935.184737111@linuxfoundation.org> References: <20200929105935.184737111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Javed Hasan [ Upstream commit 71f2bf85e90d938d4a9ef9dd9bfa8d9b0b6a03f7 ] Handling of extra kref which is done by lookup table in case rdata is already present in list. This issue was leading to memory leak. Trace from KMEMLEAK tool: unreferenced object 0xffff8888259e8780 (size 512): comm "kworker/2:1", pid 182614, jiffies 4433237386 (age 113021.971s) hex dump (first 32 bytes): 58 0a ec cf 83 88 ff ff 00 00 00 00 00 00 00 00 01 00 00 00 08 00 00 00 13 7d f0 1e 0e 00 00 10 backtrace: [<000000006b25760f>] fc_rport_recv_req+0x3c6/0x18f0 [libfc] [<00000000f208d994>] fc_lport_recv_els_req+0x120/0x8a0 [libfc] [<00000000a9c437b8>] fc_lport_recv+0xb9/0x130 [libfc] [<00000000ad5be37b>] qedf_ll2_process_skb+0x73d/0xad0 [qedf] [<00000000e0eb6893>] process_one_work+0x382/0x6c0 [<000000002dfd9e21>] worker_thread+0x57/0x5c0 [<00000000b648204f>] kthread+0x1a0/0x1c0 [<0000000072f5ab20>] ret_from_fork+0x35/0x40 [<000000001d5c05d8>] 0xffffffffffffffff Below is the log sequence which leads to memory leak. Here we get the nested "Received PLOGI request" for same port and this request leads to call the fc_rport_create() twice for the same rport. kernel: host1: rport fffce5: Received PLOGI request kernel: host1: rport fffce5: Received PLOGI in INIT state kernel: host1: rport fffce5: Port is Ready kernel: host1: rport fffce5: Received PRLI request while in state Ready kernel: host1: rport fffce5: PRLI rspp type 8 active 1 passive 0 kernel: host1: rport fffce5: Received LOGO request while in state Ready kernel: host1: rport fffce5: Delete port kernel: host1: rport fffce5: Received PLOGI request kernel: host1: rport fffce5: Received PLOGI in state Delete - send busy Link: https://lore.kernel.org/r/20200622101212.3922-2-jhasan@marvell.com Reviewed-by: Girish Basrur Reviewed-by: Saurav Kashyap Reviewed-by: Shyam Sundar Signed-off-by: Javed Hasan Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/libfc/fc_rport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c index 0e964ce75406b..a9137f64befa0 100644 --- a/drivers/scsi/libfc/fc_rport.c +++ b/drivers/scsi/libfc/fc_rport.c @@ -145,8 +145,10 @@ struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id) size_t rport_priv_size = sizeof(*rdata); rdata = fc_rport_lookup(lport, port_id); - if (rdata) + if (rdata) { + kref_put(&rdata->kref, fc_rport_destroy); return rdata; + } if (lport->rport_priv_size > 0) rport_priv_size = lport->rport_priv_size; -- 2.25.1