LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ding Hui <dinghui@sangfor.com.cn>
To: Mike Christie <michael.christie@oracle.com>,
	lduncan@suse.com, cleech@redhat.com, jejb@linux.ibm.com,
	martin.petersen@oracle.com, open-iscsi@googlegroups.com,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] scsi: libiscsi: fix invalid pointer dereference in iscsi_eh_session_reset
Date: Sat, 11 Sep 2021 17:52:01 +0800	[thread overview]
Message-ID: <2863c857-7121-1e96-0c28-d7f697b99ef7@sangfor.com.cn> (raw)
In-Reply-To: <302af74d-5b72-5b2f-050a-33f0978e321f@oracle.com>

On 2021/9/11 12:38 上午, Mike Christie wrote:
> On 9/9/21 8:02 PM, Ding Hui wrote:
>> like commit 5db6dd14b313 ("scsi: libiscsi: Fix NULL pointer dereference in
>> iscsi_eh_session_reset"), access conn->persistent_address here is not safe
>> too.
>>
>> The persistent_address is independent of conn refcount, so maybe
>> already freed by iscsi_conn_teardown(), also we put the refcount of conn
>> above, the conn pointer may be invalid.
> 
> This shouldn't happen like you describe above, because when we wake up
> we will see the session->state is ISCSI_STATE_TERMINATE. We will then
> not reference the conn in that code below.
> 
> However, it looks like we could hit an issue where if a user was resetting
> the persistent_address or targetname via iscsi_set_param -> iscsi_switch_str_param
> then we could be accessing freed memory. I think we need the frwd_lock when swapping
> the strings in iscsi_switch_str_param.
> 

Thanks for your detailed explanation, I'll drop 2/3 and 3/3 in v2 patch.
I expect that the persistent_address issue be fixed in your future patchset.

Sorry for my ignorance.

> 
>>
>> Signed-off-by: Ding Hui <dinghui@sangfor.com.cn>
>> ---
>>   drivers/scsi/libiscsi.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
>> index 712a45368385..69b3b2148328 100644
>> --- a/drivers/scsi/libiscsi.c
>> +++ b/drivers/scsi/libiscsi.c
>> @@ -2531,8 +2531,8 @@ int iscsi_eh_session_reset(struct scsi_cmnd *sc)
>>   	spin_lock_bh(&session->frwd_lock);
>>   	if (session->state == ISCSI_STATE_LOGGED_IN) {
>>   		ISCSI_DBG_EH(session,
>> -			     "session reset succeeded for %s,%s\n",
>> -			     session->targetname, conn->persistent_address);
>> +			     "session reset succeeded for %s\n",
>> +			     session->targetname);
>>   	} else
>>   		goto failed;
>>   	spin_unlock_bh(&session->frwd_lock);
>>
> 


-- 
Thanks,
-dinghui

  reply	other threads:[~2021-09-11  9:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10  1:02 [RESEND] [PATCH 0/3] fix several bugs about libiscsi Ding Hui
2021-09-10  1:02 ` [PATCH 1/3] scsi: libiscsi: move init ehwait to iscsi_session_setup() Ding Hui
2021-09-10 16:25   ` Mike Christie
2021-09-11  9:37     ` Ding Hui
2021-09-10  1:02 ` [PATCH 2/3] scsi: libiscsi: fix invalid pointer dereference in iscsi_eh_session_reset Ding Hui
2021-09-10 16:38   ` Mike Christie
2021-09-11  9:52     ` Ding Hui [this message]
2021-09-10  1:02 ` [PATCH 3/3] scsi: libiscsi: get ref to conn in iscsi_eh_device/target_reset() Ding Hui
2021-09-10 16:46   ` Mike Christie
  -- strict thread matches above, loose matches on Subject: below --
2021-09-09 15:47 [PATCH 1/3] scsi: libiscsi: move init ehwait to iscsi_session_setup() Ding Hui
2021-09-09 15:47 ` [PATCH 2/3] scsi: libiscsi: fix invalid pointer dereference in iscsi_eh_session_reset Ding Hui

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=2863c857-7121-1e96-0c28-d7f697b99ef7@sangfor.com.cn \
    --to=dinghui@sangfor.com.cn \
    --cc=cleech@redhat.com \
    --cc=jejb@linux.ibm.com \
    --cc=lduncan@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=open-iscsi@googlegroups.com \
    --subject='Re: [PATCH 2/3] scsi: libiscsi: fix invalid pointer dereference in iscsi_eh_session_reset' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).