linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Tadeusz Struk <tadeusz.struk@intel.com>
Cc: Will Deacon <will@kernel.org>,
	Jeffrin Jose <jeffrin@rajagiritech.edu.in>,
	peterz@infradead.org, mingo@redhat.com,
	linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org,
	peterhuewe@gmx.de, jgg@ziepe.ca
Subject: Re: [PROBLEM]: WARNING: lock held when returning to user space! (5.4.1 #16 Tainted: G )
Date: Wed, 11 Dec 2019 19:45:36 +0200	[thread overview]
Message-ID: <20191211174536.GG4516@linux.intel.com> (raw)
In-Reply-To: <34e5340f-de75-f20e-7898-6142eac45c13@intel.com>

On Mon, Dec 09, 2019 at 01:34:29PM -0800, Tadeusz Struk wrote:
> I think that's expected for a non-blocking operation.

What do you mean by "expected"?

It is a locking bug. When you implemented the feature you failed
to free locks before going back to the user space and I failed to
notice this when I reviewed the code.

> To get rid of the warning it should be changed to something like this:
> 
> diff --git a/drivers/char/tpm/tpm-dev-common.c
> b/drivers/char/tpm/tpm-dev-common.c
> index 2ec47a69a2a6..47f1c0c5c8de 100644
> --- a/drivers/char/tpm/tpm-dev-common.c
> +++ b/drivers/char/tpm/tpm-dev-common.c
> @@ -61,6 +61,12 @@ static void tpm_dev_async_work(struct work_struct *work)
> 
>  	mutex_lock(&priv->buffer_mutex);
>  	priv->command_enqueued = false;
> +	ret = tpm_try_get_ops(priv->chip);
> +	if (ret) {
> +		priv->response_length = ret;
> +		goto out;
> +	}
> +
>  	ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer,
>  			       sizeof(priv->data_buffer));
>  	tpm_put_ops(priv->chip);
> @@ -68,6 +74,7 @@ static void tpm_dev_async_work(struct work_struct *work)
>  		priv->response_length = ret;
>  		mod_timer(&priv->user_read_timer, jiffies + (120 * HZ));
>  	}
> +out:
>  	mutex_unlock(&priv->buffer_mutex);
>  	wake_up_interruptible(&priv->async_wait);
>  }
> @@ -205,6 +212,7 @@ ssize_t tpm_common_write(struct file *file, const
> char __user *buf,
>  		priv->command_enqueued = true;
>  		queue_work(tpm_dev_wq, &priv->async_work);
>  		mutex_unlock(&priv->buffer_mutex);
> +		tpm_put_ops(priv->chip);
>  		return size;
>  	}
> 
> 
> 
> -- 
> Tadeusz

The fix looks appropriate but needs to be formalized as a patch.

/Jarkko

  parent reply	other threads:[~2019-12-11 17:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191207173420.GA5280@debian>
2019-12-09 10:34 ` [PROBLEM]: WARNING: lock held when returning to user space! (5.4.1 #16 Tainted: G ) Will Deacon
2019-12-09 20:25   ` Jarkko Sakkinen
2019-12-09 21:34     ` Tadeusz Struk
2019-12-10 19:04       ` [PATCH] tpm: selftest: add test covering async mode Tadeusz Struk
2019-12-11 17:42         ` Jarkko Sakkinen
2019-12-10 21:17       ` [PATCH] tpm: fix WARNING: lock held when returning to user space Tadeusz Struk
2019-12-11 17:47         ` Jarkko Sakkinen
2019-12-11 17:52         ` Jarkko Sakkinen
2019-12-11 18:00           ` Jarkko Sakkinen
2019-12-11 15:17       ` [PROBLEM]: WARNING: lock held when returning to user space! (5.4.1 #16 Tainted: G ) Jeffrin Jose
2019-12-11 18:36         ` Tadeusz Struk
2019-12-12  8:12           ` Jeffrin Jose
2019-12-11 17:45       ` Jarkko Sakkinen [this message]
2019-12-11 18:18   ` Jeffrin Jose
2019-12-11 18:22   ` Jeffrin Jose

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=20191211174536.GG4516@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=jeffrin@rajagiritech.edu.in \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterhuewe@gmx.de \
    --cc=peterz@infradead.org \
    --cc=tadeusz.struk@intel.com \
    --cc=will@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;
as well as URLs for NNTP newsgroup(s).