Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Dan Carpenter <error27@gmail.com>
Cc: kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org,
	Clemens Ladisch <clemens@ladisch.de>,
	Takashi Iwai <tiwai@suse.com>
Subject: Re: [PATCH] ALSA: fireface: fix locking bug in ff400_copy_msg_to_user()
Date: Wed, 18 Jan 2023 09:08:45 +0900	[thread overview]
Message-ID: <Y8c4jcr/Uo0wiCnq@workstation> (raw)
In-Reply-To: <Y8at+W/7OGvEBY8O@kili>

Hi,

On Tue, Jan 17, 2023 at 05:17:29PM +0300, Dan Carpenter wrote:
> The ff400_copy_msg_to_user() function drops the spin lock to call
> copy_to_user().  However, if the copy_to_user() fails, then it must
> take the lock again before returning.  Failure to take the lock leads
> to a double unlock in the caller, hwdep_read().
> 
> Fixes: acdebd8b4c0c ("ALSA: fireface: implement message parser for Fireface 400")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
>  sound/firewire/fireface/ff-protocol-former.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)

Indeed. Thanks for your care.

Acked-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

> diff --git a/sound/firewire/fireface/ff-protocol-former.c b/sound/firewire/fireface/ff-protocol-former.c
> index f58008762fe6..fa41de978756 100644
> --- a/sound/firewire/fireface/ff-protocol-former.c
> +++ b/sound/firewire/fireface/ff-protocol-former.c
> @@ -680,28 +680,30 @@ static long ff400_copy_msg_to_user(struct snd_ff *ff, char __user *buf, long cou
>  	struct ff400_msg_parser *parser = ff->msg_parser;
>  	u32 type = SNDRV_FIREWIRE_EVENT_FF400_MESSAGE;
>  	long consumed = 0;
> +	int ret = 0;
>  
>  	if (count < 8)
>  		return 0;
>  
>  	spin_unlock_irq(&ff->lock);
> -
>  	if (copy_to_user(buf, &type, sizeof(type)))
> -		return -EFAULT;
> -
> +		ret = -EFAULT;
>  	spin_lock_irq(&ff->lock);
> +	if (ret)
> +		return ret;
>  
>  	count -= sizeof(type);
>  	consumed += sizeof(type);
>  
>  	while (count >= sizeof(*parser->msgs) && parser->pull_pos != parser->push_pos) {
>  		spin_unlock_irq(&ff->lock);
> -
>  		if (copy_to_user(buf + consumed, parser->msgs + parser->pull_pos,
>  				 sizeof(*parser->msgs)))
> -			return -EFAULT;
> -
> +			ret = -EFAULT;
>  		spin_lock_irq(&ff->lock);
> +		if (ret)
> +			return ret;
> +
>  		++parser->pull_pos;
>  		if (parser->pull_pos >= FF400_QUEUE_SIZE)
>  			parser->pull_pos = 0;
> -- 
> 2.35.1
 

Regards

Takashi Sakamoto

  reply	other threads:[~2023-01-18  0:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 14:17 [PATCH] ALSA: fireface: fix locking bug in ff400_copy_msg_to_user() Dan Carpenter
2023-01-18  0:08 ` Takashi Sakamoto [this message]
2023-01-18 16:50 ` Takashi Iwai

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=Y8c4jcr/Uo0wiCnq@workstation \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=error27@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=tiwai@suse.com \
    /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