From: Takashi Iwai <tiwai@suse.de>
To: "Evan Green" <evgreen@chromium.org>
Cc: <alsa-devel@alsa-project.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Amadeusz S*awi*ski" <amadeuszx.slawinski@linux.intel.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jaroslav Kysela" <perex@perex.cz>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] ALSA: hda: Fix widget_mutex incomplete protection
Date: Mon, 01 Jul 2019 16:08:54 +0200 [thread overview]
Message-ID: <s5hlfxh6e4p.wl-tiwai@suse.de> (raw)
In-Reply-To: <20190626212220.239897-2-evgreen@chromium.org>
On Wed, 26 Jun 2019 23:22:19 +0200,
Evan Green wrote:
>
> The widget_mutex was introduced to serialize callers to
> hda_widget_sysfs_{re}init. However, its protection of the sysfs widget array
> is incomplete. For example, it is acquired around the call to
> hda_widget_sysfs_reinit(), which actually creates the new array, but isn't
> still acquired when codec->num_nodes and codec->start_nid is updated. So
> the lock ensures one thread sets up the new array at a time, but doesn't
> ensure which thread's value will end up in codec->num_nodes. If a larger
> num_nodes wins but a smaller array was set up, the next call to
> refresh_widgets() will touch free memory as it iterates over codec->num_nodes
> that aren't there.
>
> The widget_lock really protects both the tree as well as codec->num_nodes,
> start_nid, and end_nid, so make sure it's held across that update. It should
> also be held during snd_hdac_get_sub_nodes(), so that a very old read from that
> function doesn't end up clobbering a later update.
OK, right, this fix is needed no matter whether to take my other
change to skip hda_widget_sysfs_init() call in
hda_widget_sysfs_reinit().
However...
> While in there, move the exit mutex call inside the function. This moves the
> mutex closer to the data structure it protects and removes a requirement of
> acquiring the somewhat internal widget_lock before calling sysfs_exit.
... this doesn't look better from consistency POV. The whole code in
hdac_sysfs.c doesn't take any lock in itself. The protection is
supposed to be done in the caller side. So, let's keep as is now.
Also...
> codec->num_nodes = nums;
> codec->start_nid = start_nid;
> codec->end_nid = start_nid + nums;
> + mutex_unlock(&codec->widget_lock);
> return 0;
> +
> +unlock:
> + mutex_unlock(&codec->widget_lock);
> + return err;
There is no need of two mutex_unlock() here. They can be unified,
codec->num_nodes = nums;
codec->start_nid = start_nid;
codec->end_nid = start_nid + nums;
unlock:
mutex_unlock(&codec->widget_lock);
return err;
Could you refresh this and resubmit?
thanks,
Takashi
next prev parent reply other threads:[~2019-07-01 14:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-26 21:22 [PATCH v2 0/2] ALSA: hda: Widget memory fixes Evan Green
2019-06-26 21:22 ` [PATCH v2 1/2] ALSA: hda: Fix widget_mutex incomplete protection Evan Green
2019-07-01 14:08 ` Takashi Iwai [this message]
2019-07-01 15:57 ` Evan Green
2019-06-26 21:22 ` [PATCH v2 2/2] ALSA: hda: Use correct start/count for sysfs init Evan Green
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=s5hlfxh6e4p.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=evgreen@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tglx@linutronix.de \
/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®