All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Khoroshilov <khoroshilov@ispras.ru>
To: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org,
	Sagi Grimberg <sagig@mellanox.com>
Subject: [BUG] iscsi-target: deadlock because of iscsit_get_tpg()
Date: Tue, 19 May 2015 23:25:30 +0300	[thread overview]
Message-ID: <555B9C3A.40106@ispras.ru> (raw)

Hello,

Our tool reports a potential double lock because of quite strange code
in iscsit_get_tpg().

drivers/target/iscsi/iscsi_target_tpg.c:
int iscsit_get_tpg(
	struct iscsi_portal_group *tpg)
{
	int ret;

	ret = mutex_lock_interruptible(&tpg->tpg_access_lock);
	return ((ret != 0) || signal_pending(current)) ? -1 : 0;
}

If mutex_lock_interruptible() successfully acquires the mutex, but there
is a pending signal, the function returns error, but it leaves the mutex
held. Callers do not expect such behaviour that can lead to a deadlock.

Why the check for pending signal is needed here?

Found by Linux Driver Verification project (linuxtesting.org).


Similar dangerous pattern presents in a couple of other places:

drivers/target/iscsi/iscsi_target.c:
int iscsit_access_np(struct iscsi_np *np, struct iscsi_portal_group *tpg)
{
...
	ret = down_interruptible(&tpg->np_login_sem);
	if ((ret != 0) || signal_pending(current))
		return -1;


drivers/target/target_core_sbc.c:
static sense_reason_t
sbc_compare_and_write(struct se_cmd *cmd)
{
...
	rc = down_interruptible(&dev->caw_sem);
	if ((rc != 0) || signal_pending(current)) {
		cmd->transport_complete_callback = NULL;
		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
	}


--
Alexey Khoroshilov
Linux Verification Center, ISPRAS

             reply	other threads:[~2015-05-19 20:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-19 20:25 Alexey Khoroshilov [this message]
2015-05-19 22:10 ` [BUG] iscsi-target: deadlock because of iscsit_get_tpg() Nicholas A. Bellinger

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=555B9C3A.40106@ispras.ru \
    --to=khoroshilov@ispras.ru \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=sagig@mellanox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.