mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: John Garry <john.g.garry@oracle.com>,
	Bryam Vargas <hexlabsecurity@proton.me>,
	"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Mike Christie <michael.christie@oracle.com>,
	Maurizio Lombardi <mlombard@redhat.com>,
	David Disseldorp <ddiss@suse.de>,
	 linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] scsi: target: copy iSCSI ISID before unmapping the PR OUT buffer
Date: Tue, 09 Jun 2026 08:27:38 -0400	[thread overview]
Message-ID: <6282620112fd9db8224dbf04046dbf24267d0433.camel@HansenPartnership.com> (raw)
In-Reply-To: <6b6ebec8-0e92-41bd-8001-0608ee6e804b@oracle.com>

On Tue, 2026-06-09 at 13:14 +0100, John Garry wrote:
> On 09/06/2026 12:36, James Bottomley wrote:
> > On Tue, 2026-06-09 at 09:50 +0100, John Garry wrote:
> > > > @@ -1808,9 +1809,11 @@ core_scsi3_decode_spec_i_port(
> > > >     		core_scsi3_tpg_undepend_item(dest_tpg);
> > > >     	}
> > > > 
> > > > +	kfree(iport_ptr);
> > > >     	return 0;
> > > >     out_unmap:
> > > >     	transport_kunmap_data_sg(cmd);
> > > > +	kfree(iport_ptr);
> > > 
> > > sorry for suggesting this change, but this is worse than what you
> > > had
> > > originally, as we have so many paths to call kfree() [which means
> > > more bugs possible]
> > > 
> > > it's hard to make good suggestions for this target code as the
> > > functions are so large and complex.
> > 
> > Given that it's allocated in a function called by the routine but
> > never
> > actually retained by anything what about defining it as
> > 
> > chat *iport_ptr __free(kfree) = NULL;
> > 
> > ?  That way we don't need to care about freeing it in the error
> > legs.
> 
> It's not just freed in the error legs, as 
> core_scsi3_decode_spec_i_port() calls target_parse_pr_out() in a loop
> 
> while (tpdl > 0) {
> 
> ...
> 
> 	spin_lock(&dev->se_port_lock);
> 	list_for_each_entry(tmp_lun, &dev->dev_sep_list,
> lun_dev_link) {
> 		...
> 
> 		kfree(iport_ptr);
> 		iport_ptr = NULL;
> 		tid_found =
> target_parse_pr_out_transport_id(tmp_tpg,
> 				ptr, &tid_len, &iport_ptr, i_str);
> 		if (!tid_found)
> 			continue;
> 
> ....
> 
> 	kfree(iport_ptr);
> out_unmap:
> 	kfree(iport_ptr);
> out:
> 	...

You'd simply remove those since the pointer would be kfree'd on any
function return.

> If __free(kfree) attr can still handle this sort of flow, then ok.

It can, but there's nuance.  If you do an early free (or a transfer of
ownership) you have to set the original pointer to NULL to avoid kfree
being called on it on return.

> I still think that it would be simpler to keep the mapping in place
> for longer (to avoid all of this), if possible.

I was just looking at the multiple error legs in the patched code and
thinking it's an ideal candidate for a __free() attribute.  If there's
a way of rearranging the code to keep it longer that you think is more
readable, by all means do that instead.

Regards,

James


  reply	other threads:[~2026-06-09 12:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09  0:59 Bryam Vargas
2026-06-09  8:50 ` John Garry
2026-06-09 11:36   ` James Bottomley
2026-06-09 12:14     ` John Garry
2026-06-09 12:27       ` James Bottomley [this message]
2026-06-10  4:22         ` Bryam Vargas

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=6282620112fd9db8224dbf04046dbf24267d0433.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=ddiss@suse.de \
    --cc=hexlabsecurity@proton.me \
    --cc=john.g.garry@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=mlombard@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®