<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/sound/core/seq/seq_clientmgr.c, branch linux-4.1.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.1.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.1.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2018-05-23T01:33:47Z</updated>
<entry>
<title>ALSA: seq: Clear client entry before deleting else at closing</title>
<updated>2018-05-23T01:33:47Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2018-03-09T21:23:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7071325e0483aa3909e1218823300355e3b704eb'/>
<id>urn:sha1:7071325e0483aa3909e1218823300355e3b704eb</id>
<content type='text'>
[ Upstream commit a2ff19f7b70118ced291a28d5313469914de451b ]

When releasing a client, we need to clear the clienttab[] entry at
first, then call snd_seq_queue_client_leave().  Otherwise, the
in-flight cell in the queue might be picked up by the timer interrupt
via snd_seq_check_queue() before calling snd_seq_queue_client_leave(),
and it's delivered to another queue while the client is clearing
queues.  This may eventually result in an uncleared cell remaining in
a queue, and the later snd_seq_pool_delete() may need to wait for a
long time until the event gets really processed.

By moving the clienttab[] clearance at the beginning of release, any
event delivery of a cell belonging to this client will fail at a later
point, since snd_seq_client_ptr() returns NULL.  Thus the cell that
was picked up by the timer interrupt will be returned immediately
without further delivery, and the long stall of snd_seq_delete_pool()
can be avoided, too.

Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: More protection for concurrent write and ioctl races</title>
<updated>2018-03-21T03:49:50Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2018-03-05T21:06:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0bbe623302abae2bf88baac4fd1888d87bbb6ef7'/>
<id>urn:sha1:0bbe623302abae2bf88baac4fd1888d87bbb6ef7</id>
<content type='text'>
[ Upstream commit 7bd80091567789f1c0cb70eb4737aac8bcd2b6b9 ]

This patch is an attempt for further hardening against races between
the concurrent write and ioctls.  The previous fix d15d662e89fc
("ALSA: seq: Fix racy pool initializations") covered the race of the
pool initialization at writer and the pool resize ioctl by the
client-&gt;ioctl_mutex (CVE-2018-1000004).  However, basically this mutex
should be applied more widely to the whole write operation for
avoiding the unexpected pool operations by another thread.

The only change outside snd_seq_write() is the additional mutex
argument to helper functions, so that we can unlock / relock the given
mutex temporarily during schedule() call for blocking write.

Fixes: d15d662e89fc ("ALSA: seq: Fix racy pool initializations")
Reported-by: 范龙飞 &lt;long7573@126.com&gt;
Reported-by: Nicolai Stange &lt;nstange@suse.de&gt;
Reviewed-and-tested-by: Nicolai Stange &lt;nstange@suse.de&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Don't allow resizing pool in use</title>
<updated>2018-03-21T03:49:50Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2018-03-05T21:00:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=282e27a729a6f766354e39a35f4e77f615a8e2ac'/>
<id>urn:sha1:282e27a729a6f766354e39a35f4e77f615a8e2ac</id>
<content type='text'>
[ Upstream commit d85739367c6d56e475c281945c68fdb05ca74b4c ]

This is a fix for a (sort of) fallout in the recent commit
d15d662e89fc ("ALSA: seq: Fix racy pool initializations") for
CVE-2018-1000004.
As the pool resize deletes the existing cells, it may lead to a race
when another thread is writing concurrently, eventually resulting a
UAF.

A simple workaround is not to allow the pool resizing when the pool is
in use.  It's an invalid behavior in anyway.

Fixes: d15d662e89fc ("ALSA: seq: Fix racy pool initializations")
Reported-by: 范龙飞 &lt;long7573@126.com&gt;
Reported-by: Nicolai Stange &lt;nstange@suse.de&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Fix racy pool initializations</title>
<updated>2018-03-04T15:28:23Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2018-02-12T14:20:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e78748b40e887c6e544dab71653858c370e283ea'/>
<id>urn:sha1:e78748b40e887c6e544dab71653858c370e283ea</id>
<content type='text'>
[ Upstream commit d15d662e89fc667b90cd294b0eb45694e33144da ]

ALSA sequencer core initializes the event pool on demand by invoking
snd_seq_pool_init() when the first write happens and the pool is
empty.  Meanwhile user can reset the pool size manually via ioctl
concurrently, and this may lead to UAF or out-of-bound accesses since
the function tries to vmalloc / vfree the buffer.

A simple fix is to just wrap the snd_seq_pool_init() call with the
recently introduced client-&gt;ioctl_mutex; as the calls for
snd_seq_pool_init() from other side are always protected with this
mutex, we can avoid the race.

Reported-by: 范龙飞 &lt;long7573@126.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Make ioctls race-free</title>
<updated>2018-03-01T03:09:45Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2018-01-09T22:11:03Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f8a38ab4cd9624fc5ac8a7f965c7b20f5b62c03c'/>
<id>urn:sha1:f8a38ab4cd9624fc5ac8a7f965c7b20f5b62c03c</id>
<content type='text'>
[ Upstream commit b3defb791b26ea0683a93a4f49c77ec45ec96f10 ]

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 &lt;a4651386@163.com&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Fix nested rwsem annotation for lockdep splat</title>
<updated>2017-12-07T02:19:53Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2017-10-29T10:10:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6abd54bb4b96875884a36241d6fd57dbd8992889'/>
<id>urn:sha1:6abd54bb4b96875884a36241d6fd57dbd8992889</id>
<content type='text'>
[ Upstream commit 1f20f9ff57ca23b9f5502fca85ce3977e8496cb1 ]

syzkaller reported the lockdep splat due to the possible deadlock of
grp-&gt;list_mutex of each sequencer client object.  Actually this is
rather a false-positive report due to the missing nested lock
annotations.  The sequencer client may deliver the event directly to
another client which takes another own lock.

For addressing this issue, this patch replaces the simple down_read()
with down_read_nested().  As a lock subclass, the already existing
"hop" can be re-used, which indicates the depth of the call.

Reference: http://lkml.kernel.org/r/089e082686ac9b482e055c832617@google.com
Reported-by: syzbot &lt;bot+7feb8de6b4d6bf810cf098bef942cc387e79d0ad@syzkaller.appspotmail.com&gt;
Reported-by: Dmitry Vyukov &lt;dvyukov@google.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Fix use-after-free at creating a port</title>
<updated>2017-11-06T04:54:24Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2017-10-09T09:09:20Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=507bb1c783c2edc4ea481a6eab7a6d2d88627624'/>
<id>urn:sha1:507bb1c783c2edc4ea481a6eab7a6d2d88627624</id>
<content type='text'>
[ Upstream commit 71105998845fb012937332fe2e806d443c09e026 ]

There is a potential race window opened at creating and deleting a
port via ioctl, as spotted by fuzzing.  snd_seq_create_port() creates
a port object and returns its pointer, but it doesn't take the
refcount, thus it can be deleted immediately by another thread.
Meanwhile, snd_seq_ioctl_create_port() still calls the function
snd_seq_system_client_ev_port_start() with the created port object
that is being deleted, and this triggers use-after-free like:

 BUG: KASAN: use-after-free in snd_seq_ioctl_create_port+0x504/0x630 [snd_seq] at addr ffff8801f2241cb1
 =============================================================================
 BUG kmalloc-512 (Tainted: G    B          ): kasan: bad access detected
 -----------------------------------------------------------------------------
 INFO: Allocated in snd_seq_create_port+0x94/0x9b0 [snd_seq] age=1 cpu=3 pid=4511
 	___slab_alloc+0x425/0x460
 	__slab_alloc+0x20/0x40
  	kmem_cache_alloc_trace+0x150/0x190
	snd_seq_create_port+0x94/0x9b0 [snd_seq]
	snd_seq_ioctl_create_port+0xd1/0x630 [snd_seq]
 	snd_seq_do_ioctl+0x11c/0x190 [snd_seq]
 	snd_seq_ioctl+0x40/0x80 [snd_seq]
 	do_vfs_ioctl+0x54b/0xda0
 	SyS_ioctl+0x79/0x90
 	entry_SYSCALL_64_fastpath+0x16/0x75
 INFO: Freed in port_delete+0x136/0x1a0 [snd_seq] age=1 cpu=2 pid=4717
 	__slab_free+0x204/0x310
 	kfree+0x15f/0x180
 	port_delete+0x136/0x1a0 [snd_seq]
 	snd_seq_delete_port+0x235/0x350 [snd_seq]
 	snd_seq_ioctl_delete_port+0xc8/0x180 [snd_seq]
 	snd_seq_do_ioctl+0x11c/0x190 [snd_seq]
 	snd_seq_ioctl+0x40/0x80 [snd_seq]
 	do_vfs_ioctl+0x54b/0xda0
 	SyS_ioctl+0x79/0x90
 	entry_SYSCALL_64_fastpath+0x16/0x75
 Call Trace:
  [&lt;ffffffff81b03781&gt;] dump_stack+0x63/0x82
  [&lt;ffffffff81531b3b&gt;] print_trailer+0xfb/0x160
  [&lt;ffffffff81536db4&gt;] object_err+0x34/0x40
  [&lt;ffffffff815392d3&gt;] kasan_report.part.2+0x223/0x520
  [&lt;ffffffffa07aadf4&gt;] ? snd_seq_ioctl_create_port+0x504/0x630 [snd_seq]
  [&lt;ffffffff815395fe&gt;] __asan_report_load1_noabort+0x2e/0x30
  [&lt;ffffffffa07aadf4&gt;] snd_seq_ioctl_create_port+0x504/0x630 [snd_seq]
  [&lt;ffffffffa07aa8f0&gt;] ? snd_seq_ioctl_delete_port+0x180/0x180 [snd_seq]
  [&lt;ffffffff8136be50&gt;] ? taskstats_exit+0xbc0/0xbc0
  [&lt;ffffffffa07abc5c&gt;] snd_seq_do_ioctl+0x11c/0x190 [snd_seq]
  [&lt;ffffffffa07abd10&gt;] snd_seq_ioctl+0x40/0x80 [snd_seq]
  [&lt;ffffffff8136d433&gt;] ? acct_account_cputime+0x63/0x80
  [&lt;ffffffff815b515b&gt;] do_vfs_ioctl+0x54b/0xda0
  .....

We may fix this in a few different ways, and in this patch, it's fixed
simply by taking the refcount properly at snd_seq_create_port() and
letting the caller unref the object after use.  Also, there is another
potential use-after-free by sprintf() call in snd_seq_create_port(),
and this is moved inside the lock.

This fix covers CVE-2017-15265.

Reported-and-tested-by: Michael23 Yu &lt;ycqzsy@gmail.com&gt;
Suggested-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: 2nd attempt at fixing race creating a queue</title>
<updated>2017-10-04T01:36:29Z</updated>
<author>
<name>Daniel Mentz</name>
</author>
<published>2017-08-14T21:46:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=624e20caa0777050a0057b2dea49711220b3371f'/>
<id>urn:sha1:624e20caa0777050a0057b2dea49711220b3371f</id>
<content type='text'>
[ Upstream commit 7e1d90f60a0d501c8503e636942ca704a454d910 ]

commit 4842e98f26dd80be3623c4714a244ba52ea096a8 ("ALSA: seq: Fix race at
creating a queue") attempted to fix a race reported by syzkaller. That
fix has been described as follows:

"
When a sequencer queue is created in snd_seq_queue_alloc(),it adds the
new queue element to the public list before referencing it.  Thus the
queue might be deleted before the call of snd_seq_queue_use(), and it
results in the use-after-free error, as spotted by syzkaller.

The fix is to reference the queue object at the right time.
"

Even with that fix in place, syzkaller reported a use-after-free error.
It specifically pointed to the last instruction "return q-&gt;queue" in
snd_seq_queue_alloc(). The pointer q is being used after kfree() has
been called on it.

It turned out that there is still a small window where a race can
happen. The window opens at
snd_seq_ioctl_create_queue()-&gt;snd_seq_queue_alloc()-&gt;queue_list_add()
and closes at
snd_seq_ioctl_create_queue()-&gt;queueptr()-&gt;snd_use_lock_use(). Between
these two calls, a different thread could delete the queue and possibly
re-create a different queue in the same location in queue_list.

This change prevents this situation by calling snd_use_lock_use() from
snd_seq_queue_alloc() prior to calling queue_list_add(). It is then the
caller's responsibility to call snd_use_lock_free(&amp;q-&gt;use_lock).

Fixes: 4842e98f26dd ("ALSA: seq: Fix race at creating a queue")
Reported-by: Dmitry Vyukov &lt;dvyukov@google.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Daniel Mentz &lt;danielmentz@google.com&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Fix racy cell insertions during snd_seq_pool_done()</title>
<updated>2017-05-17T19:07:03Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2017-03-21T12:56:04Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f1c9472e3dce9161c316671913c58c1de86fafd9'/>
<id>urn:sha1:f1c9472e3dce9161c316671913c58c1de86fafd9</id>
<content type='text'>
[ Upstream commit c520ff3d03f0b5db7146d9beed6373ad5d2a5e0e ]

When snd_seq_pool_done() is called, it marks the closing flag to
refuse the further cell insertions.  But snd_seq_pool_done() itself
doesn't clear the cells but just waits until all cells are cleared by
the caller side.  That is, it's racy, and this leads to the endless
stall as syzkaller spotted.

This patch addresses the racy by splitting the setup of pool-&gt;closing
flag out of snd_seq_pool_done(), and calling it properly before
snd_seq_pool_done().

BugLink: http://lkml.kernel.org/r/CACT4Y+aqqy8bZA1fFieifNxR2fAfFQQABcBHj801+u5ePV0URw@mail.gmail.com
Reported-and-tested-by: Dmitry Vyukov &lt;dvyukov@google.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
</content>
</entry>
<entry>
<title>ALSA: seq: Fix lockdep warnings due to double mutex locks</title>
<updated>2016-02-15T20:45:32Z</updated>
<author>
<name>Takashi Iwai</name>
</author>
<published>2016-02-03T07:32:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=44660dacb478f79d7fbc7cec0ef342414b563b6a'/>
<id>urn:sha1:44660dacb478f79d7fbc7cec0ef342414b563b6a</id>
<content type='text'>
[ Upstream commit 7f0973e973cd74aa40747c9d38844560cd184ee8 ]

The port subscription code uses double mutex locks for source and
destination ports, and this may become racy once when wrongly set up.
It leads to lockdep warning splat, typically triggered by fuzzer like
syzkaller, although the actual deadlock hasn't been seen, so far.

This patch simplifies the handling by reducing to two single locks, so
that no lockdep warning will be trigger any longer.

By splitting to two actions, a still-in-progress element shall be
added in one list while handling another.  For ignoring this element,
a new check is added in deliver_to_subscribers().

Along with it, the code to add/remove the subscribers list element was
cleaned up and refactored.

BugLink: http://lkml.kernel.org/r/CACT4Y+aKQXV7xkBW9hpQbzaDO7LrUvohxWh-UwMxXjDy-yBD=A@mail.gmail.com
Reported-by: Dmitry Vyukov &lt;dvyukov@google.com&gt;
Tested-by: Dmitry Vyukov &lt;dvyukov@google.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
</entry>
</feed>
