Re: Linux 3.16.54: suspend stops working.

From: Takashi Iwai
Date: Mon Feb 19 2018 - 10:19:00 EST


On Mon, 19 Feb 2018 16:06:55 +0100,
Andres Bertens wrote:
>
> Hi there!
>
> If of any interest to you, upgrading to linux 3.16.54 from 3.16.53,
> suspend stops working. The same is for upgrading from linux 4.4.114 to
> 4.4.115.
>
> Checking pm-utils log:
>
> /usr/lib/pm-utils/pm-functions: line 259: echo: write error: Resource
> temporarily unavailable
>
> And line 259 is:
> do_suspend() { echo -n "mem" >/sys/power/state; }
>
>
>
> Reverting patch:
> commit 02cbce8576a31df8fca54aaec91ee081076bd79d
> Author: Takashi Iwai <tiwai@xxxxxxx>
> Date: Tue Jan 9 23:11:03 2018 +0100
>
> ALSA: seq: Make ioctls race-free
>
> commit b3defb791b26ea0683a93a4f49c77ec45ec96f10 upstream.
>
> makes it work again!

Just a blind shot: could you try the patch below instead?

And, are you using some sequencer audio stuff?


thanks,

Takashi

-- 8< --
From: Takashi Iwai <tiwai@xxxxxxx>
Subject: [PATCH] ALSA: seq: Make ioctls race-free (revised)

The ALSA sequencer ioctls have no protection against racy calls while
the concurrent operations may lead to interfere with each other. As
reported recently, for example, the concurrent calls of setting client
pool with a combination of write calls may lead to either the
unkillable dead-lock or UAF.

As a slightly big hammer solution, this patch introduces the mutex to
make each ioctl exclusive. Although this may reduce performance via
parallel ioctl calls, usually it's not demanded for sequencer usages,
hence it should be negligible.

Reported-by: Luo Quan <a4651386@xxxxxxx>
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
Reviewed-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>

---
sound/core/seq/seq_clientmgr.c | 7 ++++++-
sound/core/seq/seq_clientmgr.h | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)

--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -236,6 +236,7 @@ static struct snd_seq_client *seq_create
rwlock_init(&client->ports_lock);
mutex_init(&client->ports_mutex);
INIT_LIST_HEAD(&client->ports_list_head);
+ mutex_init(&client->ioctl_mutex);

/* find free slot in the client table */
spin_lock_irqsave(&clients_lock, flags);
@@ -2220,11 +2221,15 @@ static int snd_seq_do_ioctl(struct snd_s
static long snd_seq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct snd_seq_client *client = file->private_data;
+ long ret;

if (snd_BUG_ON(!client))
return -ENXIO;

- return snd_seq_do_ioctl(client, cmd, (void __user *) arg);
+ mutex_lock(&client->ioctl_mutex);
+ ret = snd_seq_do_ioctl(client, cmd, (void __user *) arg);
+ mutex_unlock(&client->ioctl_mutex);
+ return ret;
}

#ifdef CONFIG_COMPAT
--- a/sound/core/seq/seq_clientmgr.h
+++ b/sound/core/seq/seq_clientmgr.h
@@ -59,6 +59,7 @@ struct snd_seq_client {
struct list_head ports_list_head;
rwlock_t ports_lock;
struct mutex ports_mutex;
+ struct mutex ioctl_mutex;
int convert32; /* convert 32->64bit */

/* output pool */