mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] target: fix memory leak on XCOPY
Date: Sat, 17 May 2014 15:52:03 -0700	[thread overview]
Message-ID: <1400367123.16727.0.camel@haakon3.risingtidesystems.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1405170647430.15837@file01.intranet.prod.int.rdu2.redhat.com>

On Sat, 2014-05-17 at 06:49 -0400, Mikulas Patocka wrote:
> On each processed XCOPY command, two "kmalloc-512" memory objects are
> leaked. These represent two allocations of struct xcopy_pt_cmd in
> target_core_xcopy.c.
> 
> The reason for the memory leak is that the cmd_kref field is not
> initialized (thus, it is zero because the allocations were done with
> kzalloc). When we decrement zero kref in target_put_sess_cmd, the result
> is not zero, thus target_release_cmd_kref is not called.
> 
> This patch fixes the bug by moving kref initialization from
> target_get_sess_cmd to transport_init_se_cmd (this function is called from
> target_core_xcopy.c, so it will correctly initialize cmd_kref). It can be
> easily verified that all code that calls target_get_sess_cmd also calls
> transport_init_se_cmd earlier, thus moving kref_init shouldn't introduce
> any new problems.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org	# 3.12+
> 
> ---
>  drivers/target/target_core_transport.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: linux-3.15-rc5/drivers/target/target_core_transport.c
> ===================================================================
> --- linux-3.15-rc5.orig/drivers/target/target_core_transport.c	2014-04-14 16:08:15.000000000 +0200
> +++ linux-3.15-rc5/drivers/target/target_core_transport.c	2014-05-16 18:24:57.000000000 +0200
> @@ -1113,6 +1113,7 @@ void transport_init_se_cmd(
>  	init_completion(&cmd->cmd_wait_comp);
>  	init_completion(&cmd->task_stop_comp);
>  	spin_lock_init(&cmd->t_state_lock);
> +	kref_init(&cmd->cmd_kref);
>  	cmd->transport_state = CMD_T_DEV_ACTIVE;
>  
>  	cmd->se_tfo = tfo;
> @@ -2357,7 +2358,6 @@ int target_get_sess_cmd(struct se_sessio
>  	unsigned long flags;
>  	int ret = 0;
>  
> -	kref_init(&se_cmd->cmd_kref);
>  	/*
>  	 * Add a second kref if the fabric caller is expecting to handle
>  	 * fabric acknowledgement that requires two target_put_sess_cmd()
> --

Applied.  Thanks alot Mikulas!

--nab


      parent reply	other threads:[~2014-05-17 22:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-17 10:49 Mikulas Patocka
2014-05-17 10:53 ` [PATCH] kref: warn on uninitialized kref Mikulas Patocka
2014-05-17 11:04   ` Mateusz Guzik
2014-05-17 12:36     ` Mikulas Patocka
2014-05-17 12:38     ` [PATCH v2] " Mikulas Patocka
2014-05-17 13:50       ` Bart Van Assche
2014-05-17 21:14         ` Mikulas Patocka
2014-05-18  7:17           ` Bart Van Assche
2014-05-19  8:19           ` Peter Zijlstra
2014-05-17 22:52 ` Nicholas A. Bellinger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400367123.16727.0.camel@haakon3.risingtidesystems.com \
    --to=nab@linux-iscsi.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®