<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/md/dm-ioctl.c, branch linux-6.3.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.3.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.3.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2023-07-05T17:29:23Z</updated>
<entry>
<title>dm ioctl: Avoid double-fetch of version</title>
<updated>2023-07-05T17:29:23Z</updated>
<author>
<name>Demi Marie Obenour</name>
</author>
<published>2023-06-03T14:52:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5a904225c16d93c49500384455daf1481d6abf1e'/>
<id>urn:sha1:5a904225c16d93c49500384455daf1481d6abf1e</id>
<content type='text'>
commit 249bed821b4db6d95a99160f7d6d236ea5fe6362 upstream.

The version is fetched once in check_version(), which then does some
validation and then overwrites the version in userspace with the API
version supported by the kernel.  copy_params() then fetches the version
from userspace *again*, and this time no validation is done.  The result
is that the kernel's version number is completely controllable by
userspace, provided that userspace can win a race condition.

Fix this flaw by not copying the version back to the kernel the second
time.  This is not exploitable as the version is not further used in the
kernel.  However, it could become a problem if future patches start
relying on the version field.

Cc: stable@vger.kernel.org
Signed-off-by: Demi Marie Obenour &lt;demi@invisiblethingslab.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>dm: don't lock fs when the map is NULL during suspend or resume</title>
<updated>2023-06-21T14:02:18Z</updated>
<author>
<name>Li Lingfeng</name>
</author>
<published>2023-06-01T06:14:23Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=051f16acfeba7eab58a2a84dbeaf978b8ee76bd8'/>
<id>urn:sha1:051f16acfeba7eab58a2a84dbeaf978b8ee76bd8</id>
<content type='text'>
[ Upstream commit 2760904d895279f87196f0fa9ec570c79fe6a2e4 ]

As described in commit 38d11da522aa ("dm: don't lock fs when the map is
NULL in process of resume"), a deadlock may be triggered between
do_resume() and do_mount().

This commit preserves the fix from commit 38d11da522aa but moves it to
where it also serves to fix a similar deadlock between do_suspend()
and do_mount().  It does so, if the active map is NULL, by clearing
DM_SUSPEND_LOCKFS_FLAG in dm_suspend() which is called by both
do_suspend() and do_resume().

Fixes: 38d11da522aa ("dm: don't lock fs when the map is NULL in process of resume")
Signed-off-by: Li Lingfeng &lt;lilingfeng3@huawei.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>dm: don't lock fs when the map is NULL in process of resume</title>
<updated>2023-05-11T14:17:38Z</updated>
<author>
<name>Li Lingfeng</name>
</author>
<published>2023-04-18T08:38:04Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d958b0ddbb57e5d31ab36db8b78277bd0ec4bc9f'/>
<id>urn:sha1:d958b0ddbb57e5d31ab36db8b78277bd0ec4bc9f</id>
<content type='text'>
commit 38d11da522aacaa05898c734a1cec86f1e611129 upstream.

Commit fa247089de99 ("dm: requeue IO if mapping table not yet available")
added a detection of whether the mapping table is available in the IO
submission process. If the mapping table is unavailable, it returns
BLK_STS_RESOURCE and requeues the IO.
This can lead to the following deadlock problem:

dm create                                      mount
ioctl(DM_DEV_CREATE_CMD)
ioctl(DM_TABLE_LOAD_CMD)
                               do_mount
                                vfs_get_tree
                                 ext4_get_tree
                                  get_tree_bdev
                                   sget_fc
                                    alloc_super
                                     // got &amp;s-&gt;s_umount
                                     down_write_nested(&amp;s-&gt;s_umount, ...);
                                   ext4_fill_super
                                    ext4_load_super
                                     ext4_read_bh
                                      submit_bio
                                      // submit and wait io end
ioctl(DM_DEV_SUSPEND_CMD)
dev_suspend
 do_resume
  dm_suspend
   __dm_suspend
    lock_fs
     freeze_bdev
      get_active_super
       grab_super
        // wait for &amp;s-&gt;s_umount
        down_write(&amp;s-&gt;s_umount);
  dm_swap_table
   __bind
    // set md-&gt;map(can't get here)

IO will be continuously requeued while holding the lock since mapping
table is NULL. At the same time, mapping table won't be set since the
lock is not available.
Like request-based DM, bio-based DM also has the same problem.

It's not proper to just abort IO if the mapping table not available.
So clear DM_SKIP_LOCKFS_FLAG when the mapping table is NULL, this
allows the DM table to be loaded and the IO submitted upon resume.

Fixes: fa247089de99 ("dm: requeue IO if mapping table not yet available")
Cc: stable@vger.kernel.org
Signed-off-by: Li Lingfeng &lt;lilingfeng3@huawei.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>dm ioctl: fix nested locking in table_clear() to remove deadlock concern</title>
<updated>2023-05-11T14:17:38Z</updated>
<author>
<name>Mike Snitzer</name>
</author>
<published>2023-04-17T15:59:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a554e6ec3626d4c11f55d7eef8d6aa93fb211c24'/>
<id>urn:sha1:a554e6ec3626d4c11f55d7eef8d6aa93fb211c24</id>
<content type='text'>
commit 3d32aaa7e66d5c1479a3c31d6c2c5d45dd0d3b89 upstream.

syzkaller found the following problematic rwsem locking (with write
lock already held):

 down_read+0x9d/0x450 kernel/locking/rwsem.c:1509
 dm_get_inactive_table+0x2b/0xc0 drivers/md/dm-ioctl.c:773
 __dev_status+0x4fd/0x7c0 drivers/md/dm-ioctl.c:844
 table_clear+0x197/0x280 drivers/md/dm-ioctl.c:1537

In table_clear, it first acquires a write lock
https://elixir.bootlin.com/linux/v6.2/source/drivers/md/dm-ioctl.c#L1520
down_write(&amp;_hash_lock);

Then before the lock is released at L1539, there is a path shown above:
table_clear -&gt; __dev_status -&gt; dm_get_inactive_table -&gt;  down_read
https://elixir.bootlin.com/linux/v6.2/source/drivers/md/dm-ioctl.c#L773
down_read(&amp;_hash_lock);

It tries to acquire the same read lock again, resulting in the deadlock
problem.

Fix this by moving table_clear()'s __dev_status() call to after its
up_write(&amp;_hash_lock);

Cc: stable@vger.kernel.org
Reported-by: Zheng Zhang &lt;zheng.zhang@email.ucr.edu&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>dm ioctl: remove unnecessary check when using dm_get_mdptr()</title>
<updated>2023-02-17T19:49:21Z</updated>
<author>
<name>Hou Tao</name>
</author>
<published>2022-12-16T04:23:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a2f998a78a425edde5a1a1973c1d4854fe9d019f'/>
<id>urn:sha1:a2f998a78a425edde5a1a1973c1d4854fe9d019f</id>
<content type='text'>
__hash_remove() removes hash_cell with _hash_lock locked, so acquiring
_hash_lock can guarantee no-NULL hc returned from dm_get_mdptr() must
have not been removed and hc-&gt;md must still be md.

__hash_remove() also acquires dm_hash_cells_mutex before setting mdptr
as NULL. So in dm_copy_name_and_uuid(), after acquiring
dm_hash_cells_mutex and ensuring returned hc is not NULL, the returned
hc must still be alive and hc-&gt;md must still be md.

Remove the unnecessary hc-&gt;md != md checks when using dm_get_mdptr()
with _hash_lock or dm_hash_cells_mutex acquired.

Signed-off-by: Hou Tao &lt;houtao1@huawei.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
</content>
</entry>
<entry>
<title>dm ioctl: assert _hash_lock is held in __hash_remove</title>
<updated>2023-02-17T19:49:21Z</updated>
<author>
<name>Mike Snitzer</name>
</author>
<published>2023-02-17T18:08:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=69868bebfe8e9a47b0d8a12f7473b8a3b7239ef3'/>
<id>urn:sha1:69868bebfe8e9a47b0d8a12f7473b8a3b7239ef3</id>
<content type='text'>
Also update dm_early_create() to take _hash_lock when calling both
__get_name_cell and __hash_remove -- given dm_early_create()'s early
boot usecase this locking isn't about correctness but it allows
lockdep_assert_held() to be added to __hash_remove.

Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
</content>
</entry>
<entry>
<title>dm ioctl: prefer strscpy() instead of strlcpy()</title>
<updated>2023-02-14T19:23:07Z</updated>
<author>
<name>Heinz Mauelshagen</name>
</author>
<published>2023-02-07T22:04:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=22a8b84945e9a5027174e06ec5c8ce3d978844d6'/>
<id>urn:sha1:22a8b84945e9a5027174e06ec5c8ce3d978844d6</id>
<content type='text'>
Signed-off-by: Heinz Mauelshagen &lt;heinzm@redhat.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
</content>
</entry>
<entry>
<title>dm ioctl: have constant on the right side of the test</title>
<updated>2023-02-14T19:23:07Z</updated>
<author>
<name>Heinz Mauelshagen</name>
</author>
<published>2023-02-07T20:47:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5cae0aa77397015f530aeb34f3ced32db6ac2875'/>
<id>urn:sha1:5cae0aa77397015f530aeb34f3ced32db6ac2875</id>
<content type='text'>
Signed-off-by: Heinz Mauelshagen &lt;heinzm@redhat.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
</content>
</entry>
<entry>
<title>dm: prefer '"%s...", __func__'</title>
<updated>2023-02-14T19:23:07Z</updated>
<author>
<name>Heinz Mauelshagen</name>
</author>
<published>2023-02-06T22:42:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1c13188669282dac48f1e67d77f07a746a4899d7'/>
<id>urn:sha1:1c13188669282dac48f1e67d77f07a746a4899d7</id>
<content type='text'>
Signed-off-by: Heinz Mauelshagen &lt;heinzm@redhat.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
</content>
</entry>
<entry>
<title>dm: avoid split of quoted strings where possible</title>
<updated>2023-02-14T19:23:07Z</updated>
<author>
<name>Heinz Mauelshagen</name>
</author>
<published>2023-02-03T17:55:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2e84fecf19e1694338deec8bf6c90ff84f8f31fb'/>
<id>urn:sha1:2e84fecf19e1694338deec8bf6c90ff84f8f31fb</id>
<content type='text'>
Signed-off-by: Heinz Mauelshagen &lt;heinzm@redhat.com&gt;
Signed-off-by: Mike Snitzer &lt;snitzer@kernel.org&gt;
</content>
</entry>
</feed>
