<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-stable.git/fs, branch v5.4.8</title>
<subtitle>Linux kernel stable tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/'/>
<entry>
<title>mm/hugetlbfs: fix for_each_hstate() loop in init_hugetlbfs_fs()</title>
<updated>2020-01-04T18:19:19+00:00</updated>
<author>
<name>Jan Stancek</name>
<email>jstancek@redhat.com</email>
</author>
<published>2020-01-03T17:37:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=1cab43eb6137928106364340a5287b29ce3552f1'/>
<id>1cab43eb6137928106364340a5287b29ce3552f1</id>
<content type='text'>
commit 15f0ec941f4f908fefa23a30ded8358977cc1cc0 upstream.

LTP memfd_create04 started failing for some huge page sizes
after v5.4-10135-gc3bfc5dd73c6.

The problem is the check introduced to for_each_hstate() loop that
should skip default_hstate_idx.  Since it doesn't update 'i' counter,
all subsequent huge page sizes are skipped as well.

Fixes: 8fc312b32b25 ("mm/hugetlbfs: fix error handling when setting up mounts")
Signed-off-by: Jan Stancek &lt;jstancek@redhat.com&gt;
Reviewed-by: Mike Kravetz &lt;mike.kravetz@oracle.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 15f0ec941f4f908fefa23a30ded8358977cc1cc0 upstream.

LTP memfd_create04 started failing for some huge page sizes
after v5.4-10135-gc3bfc5dd73c6.

The problem is the check introduced to for_each_hstate() loop that
should skip default_hstate_idx.  Since it doesn't update 'i' counter,
all subsequent huge page sizes are skipped as well.

Fixes: 8fc312b32b25 ("mm/hugetlbfs: fix error handling when setting up mounts")
Signed-off-by: Jan Stancek &lt;jstancek@redhat.com&gt;
Reviewed-by: Mike Kravetz &lt;mike.kravetz@oracle.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>xfs: fix mount failure crash on invalid iclog memory access</title>
<updated>2020-01-04T18:18:43+00:00</updated>
<author>
<name>Brian Foster</name>
<email>bfoster@redhat.com</email>
</author>
<published>2019-12-03T15:53:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=03c074b26ff95d715c2f48798ac2c03d9d9b80c8'/>
<id>03c074b26ff95d715c2f48798ac2c03d9d9b80c8</id>
<content type='text'>
commit 798a9cada4694ca8d970259f216cec47e675bfd5 upstream.

syzbot (via KASAN) reports a use-after-free in the error path of
xlog_alloc_log(). Specifically, the iclog freeing loop doesn't
handle the case of a fully initialized -&gt;l_iclog linked list.
Instead, it assumes that the list is partially constructed and NULL
terminated.

This bug manifested because there was no possible error scenario
after iclog list setup when the original code was added.  Subsequent
code and associated error conditions were added some time later,
while the original error handling code was never updated. Fix up the
error loop to terminate either on a NULL iclog or reaching the end
of the list.

Reported-by: syzbot+c732f8644185de340492@syzkaller.appspotmail.com
Signed-off-by: Brian Foster &lt;bfoster@redhat.com&gt;
Reviewed-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 798a9cada4694ca8d970259f216cec47e675bfd5 upstream.

syzbot (via KASAN) reports a use-after-free in the error path of
xlog_alloc_log(). Specifically, the iclog freeing loop doesn't
handle the case of a fully initialized -&gt;l_iclog linked list.
Instead, it assumes that the list is partially constructed and NULL
terminated.

This bug manifested because there was no possible error scenario
after iclog list setup when the original code was added.  Subsequent
code and associated error conditions were added some time later,
while the original error handling code was never updated. Fix up the
error loop to terminate either on a NULL iclog or reaching the end
of the list.

Reported-by: syzbot+c732f8644185de340492@syzkaller.appspotmail.com
Signed-off-by: Brian Foster &lt;bfoster@redhat.com&gt;
Reviewed-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK</title>
<updated>2020-01-04T18:18:32+00:00</updated>
<author>
<name>Mike Rapoport</name>
<email>rppt@linux.ibm.com</email>
</author>
<published>2019-12-01T01:58:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=2176441fdd00bdeba970ec5c382723d9d1448b3d'/>
<id>2176441fdd00bdeba970ec5c382723d9d1448b3d</id>
<content type='text'>
[ Upstream commit 3c1c24d91ffd536de0a64688a9df7f49e58fadbc ]

A while ago Andy noticed
(http://lkml.kernel.org/r/CALCETrWY+5ynDct7eU_nDUqx=okQvjm=Y5wJvA4ahBja=CQXGw@mail.gmail.com)
that UFFD_FEATURE_EVENT_FORK used by an unprivileged user may have
security implications.

As the first step of the solution the following patch limits the availably
of UFFD_FEATURE_EVENT_FORK only for those having CAP_SYS_PTRACE.

The usage of CAP_SYS_PTRACE ensures compatibility with CRIU.

Yet, if there are other users of non-cooperative userfaultfd that run
without CAP_SYS_PTRACE, they would be broken :(

Current implementation of UFFD_FEATURE_EVENT_FORK modifies the file
descriptor table from the read() implementation of uffd, which may have
security implications for unprivileged use of the userfaultfd.

Limit availability of UFFD_FEATURE_EVENT_FORK only for callers that have
CAP_SYS_PTRACE.

Link: http://lkml.kernel.org/r/1572967777-8812-2-git-send-email-rppt@linux.ibm.com
Signed-off-by: Mike Rapoport &lt;rppt@linux.ibm.com&gt;
Reviewed-by: Andrea Arcangeli &lt;aarcange@redhat.com&gt;
Cc: Daniel Colascione &lt;dancol@google.com&gt;
Cc: Jann Horn &lt;jannh@google.com&gt;
Cc: Lokesh Gidra &lt;lokeshgidra@google.com&gt;
Cc: Nick Kralevich &lt;nnk@google.com&gt;
Cc: Nosh Minwalla &lt;nosh@google.com&gt;
Cc: Pavel Emelyanov &lt;ovzxemul@gmail.com&gt;
Cc: Tim Murray &lt;timmurray@google.com&gt;
Cc: Aleksa Sarai &lt;cyphar@cyphar.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 3c1c24d91ffd536de0a64688a9df7f49e58fadbc ]

A while ago Andy noticed
(http://lkml.kernel.org/r/CALCETrWY+5ynDct7eU_nDUqx=okQvjm=Y5wJvA4ahBja=CQXGw@mail.gmail.com)
that UFFD_FEATURE_EVENT_FORK used by an unprivileged user may have
security implications.

As the first step of the solution the following patch limits the availably
of UFFD_FEATURE_EVENT_FORK only for those having CAP_SYS_PTRACE.

The usage of CAP_SYS_PTRACE ensures compatibility with CRIU.

Yet, if there are other users of non-cooperative userfaultfd that run
without CAP_SYS_PTRACE, they would be broken :(

Current implementation of UFFD_FEATURE_EVENT_FORK modifies the file
descriptor table from the read() implementation of uffd, which may have
security implications for unprivileged use of the userfaultfd.

Limit availability of UFFD_FEATURE_EVENT_FORK only for callers that have
CAP_SYS_PTRACE.

Link: http://lkml.kernel.org/r/1572967777-8812-2-git-send-email-rppt@linux.ibm.com
Signed-off-by: Mike Rapoport &lt;rppt@linux.ibm.com&gt;
Reviewed-by: Andrea Arcangeli &lt;aarcange@redhat.com&gt;
Cc: Daniel Colascione &lt;dancol@google.com&gt;
Cc: Jann Horn &lt;jannh@google.com&gt;
Cc: Lokesh Gidra &lt;lokeshgidra@google.com&gt;
Cc: Nick Kralevich &lt;nnk@google.com&gt;
Cc: Nosh Minwalla &lt;nosh@google.com&gt;
Cc: Pavel Emelyanov &lt;ovzxemul@gmail.com&gt;
Cc: Tim Murray &lt;timmurray@google.com&gt;
Cc: Aleksa Sarai &lt;cyphar@cyphar.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/hugetlbfs: fix error handling when setting up mounts</title>
<updated>2020-01-04T18:18:31+00:00</updated>
<author>
<name>Mike Kravetz</name>
<email>mike.kravetz@oracle.com</email>
</author>
<published>2019-12-01T01:56:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=865e3fd60eaa6bc3f5271708b520bd55e98f1a48'/>
<id>865e3fd60eaa6bc3f5271708b520bd55e98f1a48</id>
<content type='text'>
[ Upstream commit 8fc312b32b25c6b0a8b46fab4df8c68df5af1223 ]

It is assumed that the hugetlbfs_vfsmount[] array will contain either a
valid vfsmount pointer or NULL for each hstate after initialization.
Changes made while converting to use fs_context broke this assumption.

While fixing the hugetlbfs_vfsmount issue, it was discovered that
init_hugetlbfs_fs never did correctly clean up when encountering a vfs
mount error.

It was found during code inspection.  A small memory allocation failure
would be the most likely cause of taking a error path with the bug.
This is unlikely to happen as this is early init code.

Link: http://lkml.kernel.org/r/94b6244d-2c24-e269-b12c-e3ba694b242d@oracle.com
Reported-by: Chengguang Xu &lt;cgxu519@mykernel.net&gt;
Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context")
Signed-off-by: Mike Kravetz &lt;mike.kravetz@oracle.com&gt;
Cc: David Howells &lt;dhowells@redhat.com&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 8fc312b32b25c6b0a8b46fab4df8c68df5af1223 ]

It is assumed that the hugetlbfs_vfsmount[] array will contain either a
valid vfsmount pointer or NULL for each hstate after initialization.
Changes made while converting to use fs_context broke this assumption.

While fixing the hugetlbfs_vfsmount issue, it was discovered that
init_hugetlbfs_fs never did correctly clean up when encountering a vfs
mount error.

It was found during code inspection.  A small memory allocation failure
would be the most likely cause of taking a error path with the bug.
This is unlikely to happen as this is early init code.

Link: http://lkml.kernel.org/r/94b6244d-2c24-e269-b12c-e3ba694b242d@oracle.com
Reported-by: Chengguang Xu &lt;cgxu519@mykernel.net&gt;
Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context")
Signed-off-by: Mike Kravetz &lt;mike.kravetz@oracle.com&gt;
Cc: David Howells &lt;dhowells@redhat.com&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ocfs2: fix passing zero to 'PTR_ERR' warning</title>
<updated>2020-01-04T18:18:30+00:00</updated>
<author>
<name>Ding Xiang</name>
<email>dingxiang@cmss.chinamobile.com</email>
</author>
<published>2019-12-01T01:49:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=496cec79449b6beee9d67f227c8d4de02be76ccc'/>
<id>496cec79449b6beee9d67f227c8d4de02be76ccc</id>
<content type='text'>
[ Upstream commit 188c523e1c271d537f3c9f55b6b65bf4476de32f ]

Fix a static code checker warning:
fs/ocfs2/acl.c:331
	ocfs2_acl_chmod() warn: passing zero to 'PTR_ERR'

Link: http://lkml.kernel.org/r/1dee278b-6c96-eec2-ce76-fe6e07c6e20f@linux.alibaba.com
Fixes: 5ee0fbd50fd ("ocfs2: revert using ocfs2_acl_chmod to avoid inode cluster lock hang")
Signed-off-by: Ding Xiang &lt;dingxiang@cmss.chinamobile.com&gt;
Reviewed-by: Joseph Qi &lt;joseph.qi@linux.alibaba.com&gt;
Cc: Mark Fasheh &lt;mark@fasheh.com&gt;
Cc: Joel Becker &lt;jlbec@evilplan.org&gt;
Cc: Junxiao Bi &lt;junxiao.bi@oracle.com&gt;
Cc: Changwei Ge &lt;gechangwei@live.cn&gt;
Cc: Gang He &lt;ghe@suse.com&gt;
Cc: Jun Piao &lt;piaojun@huawei.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 188c523e1c271d537f3c9f55b6b65bf4476de32f ]

Fix a static code checker warning:
fs/ocfs2/acl.c:331
	ocfs2_acl_chmod() warn: passing zero to 'PTR_ERR'

Link: http://lkml.kernel.org/r/1dee278b-6c96-eec2-ce76-fe6e07c6e20f@linux.alibaba.com
Fixes: 5ee0fbd50fd ("ocfs2: revert using ocfs2_acl_chmod to avoid inode cluster lock hang")
Signed-off-by: Ding Xiang &lt;dingxiang@cmss.chinamobile.com&gt;
Reviewed-by: Joseph Qi &lt;joseph.qi@linux.alibaba.com&gt;
Cc: Mark Fasheh &lt;mark@fasheh.com&gt;
Cc: Joel Becker &lt;jlbec@evilplan.org&gt;
Cc: Junxiao Bi &lt;junxiao.bi@oracle.com&gt;
Cc: Changwei Ge &lt;gechangwei@live.cn&gt;
Cc: Gang He &lt;ghe@suse.com&gt;
Cc: Jun Piao &lt;piaojun@huawei.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cifs: move cifsFileInfo_put logic into a work-queue</title>
<updated>2020-01-04T18:18:26+00:00</updated>
<author>
<name>Ronnie Sahlberg</name>
<email>lsahlber@redhat.com</email>
</author>
<published>2019-11-03T03:06:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=2685410d1e3c7b184d09b07f5473e7d5b33c4d34'/>
<id>2685410d1e3c7b184d09b07f5473e7d5b33c4d34</id>
<content type='text'>
[ Upstream commit 32546a9586aa4565035bb557e191648e022b29e8 ]

This patch moves the final part of the cifsFileInfo_put() logic where we
need a write lock on lock_sem to be processed in a separate thread that
holds no other locks.
This is to prevent deadlocks like the one below:

&gt; there are 6 processes looping to while trying to down_write
&gt; cinode-&gt;lock_sem, 5 of them from _cifsFileInfo_put, and one from
&gt; cifs_new_fileinfo
&gt;
&gt; and there are 5 other processes which are blocked, several of them
&gt; waiting on either PG_writeback or PG_locked (which are both set), all
&gt; for the same page of the file
&gt;
&gt; 2 inode_lock() (inode-&gt;i_rwsem) for the file
&gt; 1 wait_on_page_writeback() for the page
&gt; 1 down_read(inode-&gt;i_rwsem) for the inode of the directory
&gt; 1 inode_lock()(inode-&gt;i_rwsem) for the inode of the directory
&gt; 1 __lock_page
&gt;
&gt;
&gt; so processes are blocked waiting on:
&gt;   page flags PG_locked and PG_writeback for one specific page
&gt;   inode-&gt;i_rwsem for the directory
&gt;   inode-&gt;i_rwsem for the file
&gt;   cifsInodeInflock_sem
&gt;
&gt;
&gt;
&gt; here are the more gory details (let me know if I need to provide
&gt; anything more/better):
&gt;
&gt; [0 00:48:22.765] [UN]  PID: 8863   TASK: ffff8c691547c5c0  CPU: 3
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965007e3ba8] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965007e3c38] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965007e3c48] rwsem_down_write_slowpath at ffffffff9af283d7
&gt;  #3 [ffff9965007e3cb8] legitimize_path at ffffffff9b0f975d
&gt;  #4 [ffff9965007e3d08] path_openat at ffffffff9b0fe55d
&gt;  #5 [ffff9965007e3dd8] do_filp_open at ffffffff9b100a33
&gt;  #6 [ffff9965007e3ee0] do_sys_open at ffffffff9b0eb2d6
&gt;  #7 [ffff9965007e3f38] do_syscall_64 at ffffffff9ae04315
&gt; * (I think legitimize_path is bogus)
&gt;
&gt; in path_openat
&gt;         } else {
&gt;                 const char *s = path_init(nd, flags);
&gt;                 while (!(error = link_path_walk(s, nd)) &amp;&amp;
&gt;                         (error = do_last(nd, file, op)) &gt; 0) {  &lt;&lt;&lt;&lt;
&gt;
&gt; do_last:
&gt;         if (open_flag &amp; O_CREAT)
&gt;                 inode_lock(dir-&gt;d_inode);  &lt;&lt;&lt;&lt;
&gt;         else
&gt; so it's trying to take inode-&gt;i_rwsem for the directory
&gt;
&gt;      DENTRY           INODE           SUPERBLK     TYPE PATH
&gt; ffff8c68bb8e79c0 ffff8c691158ef20 ffff8c6915bf9000 DIR  /mnt/vm1_smb/
&gt; inode.i_rwsem is ffff8c691158efc0
&gt;
&gt; &lt;struct rw_semaphore 0xffff8c691158efc0&gt;:
&gt;         owner: &lt;struct task_struct 0xffff8c6914275d00&gt; (UN -   8856 -
&gt; reopen_file), counter: 0x0000000000000003
&gt;         waitlist: 2
&gt;         0xffff9965007e3c90     8863   reopen_file      UN 0  1:29:22.926
&gt;   RWSEM_WAITING_FOR_WRITE
&gt;         0xffff996500393e00     9802   ls               UN 0  1:17:26.700
&gt;   RWSEM_WAITING_FOR_READ
&gt;
&gt;
&gt; the owner of the inode.i_rwsem of the directory is:
&gt;
&gt; [0 00:00:00.109] [UN]  PID: 8856   TASK: ffff8c6914275d00  CPU: 3
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff99650065b828] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff99650065b8b8] schedule at ffffffff9b6e64df
&gt;  #2 [ffff99650065b8c8] schedule_timeout at ffffffff9b6e9f89
&gt;  #3 [ffff99650065b940] msleep at ffffffff9af573a9
&gt;  #4 [ffff99650065b948] _cifsFileInfo_put.cold.63 at ffffffffc0a42dd6 [cifs]
&gt;  #5 [ffff99650065ba38] cifs_writepage_locked at ffffffffc0a0b8f3 [cifs]
&gt;  #6 [ffff99650065bab0] cifs_launder_page at ffffffffc0a0bb72 [cifs]
&gt;  #7 [ffff99650065bb30] invalidate_inode_pages2_range at ffffffff9b04d4bd
&gt;  #8 [ffff99650065bcb8] cifs_invalidate_mapping at ffffffffc0a11339 [cifs]
&gt;  #9 [ffff99650065bcd0] cifs_revalidate_mapping at ffffffffc0a1139a [cifs]
&gt; #10 [ffff99650065bcf0] cifs_d_revalidate at ffffffffc0a014f6 [cifs]
&gt; #11 [ffff99650065bd08] path_openat at ffffffff9b0fe7f7
&gt; #12 [ffff99650065bdd8] do_filp_open at ffffffff9b100a33
&gt; #13 [ffff99650065bee0] do_sys_open at ffffffff9b0eb2d6
&gt; #14 [ffff99650065bf38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; cifs_launder_page is for page 0xffffd1e2c07d2480
&gt;
&gt; crash&gt; page.index,mapping,flags 0xffffd1e2c07d2480
&gt;       index = 0x8
&gt;       mapping = 0xffff8c68f3cd0db0
&gt;   flags = 0xfffffc0008095
&gt;
&gt;   PAGE-FLAG       BIT  VALUE
&gt;   PG_locked         0  0000001
&gt;   PG_uptodate       2  0000004
&gt;   PG_lru            4  0000010
&gt;   PG_waiters        7  0000080
&gt;   PG_writeback     15  0008000
&gt;
&gt;
&gt; inode is ffff8c68f3cd0c40
&gt; inode.i_rwsem is ffff8c68f3cd0ce0
&gt;      DENTRY           INODE           SUPERBLK     TYPE PATH
&gt; ffff8c68a1f1b480 ffff8c68f3cd0c40 ffff8c6915bf9000 REG
&gt; /mnt/vm1_smb/testfile.8853
&gt;
&gt;
&gt; this process holds the inode-&gt;i_rwsem for the parent directory, is
&gt; laundering a page attached to the inode of the file it's opening, and in
&gt; _cifsFileInfo_put is trying to down_write the cifsInodeInflock_sem
&gt; for the file itself.
&gt;
&gt;
&gt; &lt;struct rw_semaphore 0xffff8c68f3cd0ce0&gt;:
&gt;         owner: &lt;struct task_struct 0xffff8c6914272e80&gt; (UN -   8854 -
&gt; reopen_file), counter: 0x0000000000000003
&gt;         waitlist: 1
&gt;         0xffff9965005dfd80     8855   reopen_file      UN 0  1:29:22.912
&gt;   RWSEM_WAITING_FOR_WRITE
&gt;
&gt; this is the inode.i_rwsem for the file
&gt;
&gt; the owner:
&gt;
&gt; [0 00:48:22.739] [UN]  PID: 8854   TASK: ffff8c6914272e80  CPU: 2
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff99650054fb38] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff99650054fbc8] schedule at ffffffff9b6e64df
&gt;  #2 [ffff99650054fbd8] io_schedule at ffffffff9b6e68e2
&gt;  #3 [ffff99650054fbe8] __lock_page at ffffffff9b03c56f
&gt;  #4 [ffff99650054fc80] pagecache_get_page at ffffffff9b03dcdf
&gt;  #5 [ffff99650054fcc0] grab_cache_page_write_begin at ffffffff9b03ef4c
&gt;  #6 [ffff99650054fcd0] cifs_write_begin at ffffffffc0a064ec [cifs]
&gt;  #7 [ffff99650054fd30] generic_perform_write at ffffffff9b03bba4
&gt;  #8 [ffff99650054fda8] __generic_file_write_iter at ffffffff9b04060a
&gt;  #9 [ffff99650054fdf0] cifs_strict_writev.cold.70 at ffffffffc0a4469b [cifs]
&gt; #10 [ffff99650054fe48] new_sync_write at ffffffff9b0ec1dd
&gt; #11 [ffff99650054fed0] vfs_write at ffffffff9b0eed35
&gt; #12 [ffff99650054ff00] ksys_write at ffffffff9b0eefd9
&gt; #13 [ffff99650054ff38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; the process holds the inode-&gt;i_rwsem for the file to which it's writing,
&gt; and is trying to __lock_page for the same page as in the other processes
&gt;
&gt;
&gt; the other tasks:
&gt; [0 00:00:00.028] [UN]  PID: 8859   TASK: ffff8c6915479740  CPU: 2
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965007b39d8] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965007b3a68] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965007b3a78] schedule_timeout at ffffffff9b6e9f89
&gt;  #3 [ffff9965007b3af0] msleep at ffffffff9af573a9
&gt;  #4 [ffff9965007b3af8] cifs_new_fileinfo.cold.61 at ffffffffc0a42a07 [cifs]
&gt;  #5 [ffff9965007b3b78] cifs_open at ffffffffc0a0709d [cifs]
&gt;  #6 [ffff9965007b3cd8] do_dentry_open at ffffffff9b0e9b7a
&gt;  #7 [ffff9965007b3d08] path_openat at ffffffff9b0fe34f
&gt;  #8 [ffff9965007b3dd8] do_filp_open at ffffffff9b100a33
&gt;  #9 [ffff9965007b3ee0] do_sys_open at ffffffff9b0eb2d6
&gt; #10 [ffff9965007b3f38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; this is opening the file, and is trying to down_write cinode-&gt;lock_sem
&gt;
&gt;
&gt; [0 00:00:00.041] [UN]  PID: 8860   TASK: ffff8c691547ae80  CPU: 2
&gt; COMMAND: "reopen_file"
&gt; [0 00:00:00.057] [UN]  PID: 8861   TASK: ffff8c6915478000  CPU: 3
&gt; COMMAND: "reopen_file"
&gt; [0 00:00:00.059] [UN]  PID: 8858   TASK: ffff8c6914271740  CPU: 2
&gt; COMMAND: "reopen_file"
&gt; [0 00:00:00.109] [UN]  PID: 8862   TASK: ffff8c691547dd00  CPU: 6
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965007c3c78] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965007c3d08] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965007c3d18] schedule_timeout at ffffffff9b6e9f89
&gt;  #3 [ffff9965007c3d90] msleep at ffffffff9af573a9
&gt;  #4 [ffff9965007c3d98] _cifsFileInfo_put.cold.63 at ffffffffc0a42dd6 [cifs]
&gt;  #5 [ffff9965007c3e88] cifs_close at ffffffffc0a07aaf [cifs]
&gt;  #6 [ffff9965007c3ea0] __fput at ffffffff9b0efa6e
&gt;  #7 [ffff9965007c3ee8] task_work_run at ffffffff9aef1614
&gt;  #8 [ffff9965007c3f20] exit_to_usermode_loop at ffffffff9ae03d6f
&gt;  #9 [ffff9965007c3f38] do_syscall_64 at ffffffff9ae0444c
&gt;
&gt; closing the file, and trying to down_write cifsi-&gt;lock_sem
&gt;
&gt;
&gt; [0 00:48:22.839] [UN]  PID: 8857   TASK: ffff8c6914270000  CPU: 7
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965006a7cc8] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965006a7d58] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965006a7d68] io_schedule at ffffffff9b6e68e2
&gt;  #3 [ffff9965006a7d78] wait_on_page_bit at ffffffff9b03cac6
&gt;  #4 [ffff9965006a7e10] __filemap_fdatawait_range at ffffffff9b03b028
&gt;  #5 [ffff9965006a7ed8] filemap_write_and_wait at ffffffff9b040165
&gt;  #6 [ffff9965006a7ef0] cifs_flush at ffffffffc0a0c2fa [cifs]
&gt;  #7 [ffff9965006a7f10] filp_close at ffffffff9b0e93f1
&gt;  #8 [ffff9965006a7f30] __x64_sys_close at ffffffff9b0e9a0e
&gt;  #9 [ffff9965006a7f38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; in __filemap_fdatawait_range
&gt;                         wait_on_page_writeback(page);
&gt; for the same page of the file
&gt;
&gt;
&gt;
&gt; [0 00:48:22.718] [UN]  PID: 8855   TASK: ffff8c69142745c0  CPU: 7
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965005dfc98] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965005dfd28] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965005dfd38] rwsem_down_write_slowpath at ffffffff9af283d7
&gt;  #3 [ffff9965005dfdf0] cifs_strict_writev at ffffffffc0a0c40a [cifs]
&gt;  #4 [ffff9965005dfe48] new_sync_write at ffffffff9b0ec1dd
&gt;  #5 [ffff9965005dfed0] vfs_write at ffffffff9b0eed35
&gt;  #6 [ffff9965005dff00] ksys_write at ffffffff9b0eefd9
&gt;  #7 [ffff9965005dff38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt;         inode_lock(inode);
&gt;
&gt;
&gt; and one 'ls' later on, to see whether the rest of the mount is available
&gt; (the test file is in the root, so we get blocked up on the directory
&gt; -&gt;i_rwsem), so the entire mount is unavailable
&gt;
&gt; [0 00:36:26.473] [UN]  PID: 9802   TASK: ffff8c691436ae80  CPU: 4
&gt; COMMAND: "ls"
&gt;  #0 [ffff996500393d28] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff996500393db8] schedule at ffffffff9b6e64df
&gt;  #2 [ffff996500393dc8] rwsem_down_read_slowpath at ffffffff9b6e9421
&gt;  #3 [ffff996500393e78] down_read_killable at ffffffff9b6e95e2
&gt;  #4 [ffff996500393e88] iterate_dir at ffffffff9b103c56
&gt;  #5 [ffff996500393ec8] ksys_getdents64 at ffffffff9b104b0c
&gt;  #6 [ffff996500393f30] __x64_sys_getdents64 at ffffffff9b104bb6
&gt;  #7 [ffff996500393f38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; in iterate_dir:
&gt;         if (shared)
&gt;                 res = down_read_killable(&amp;inode-&gt;i_rwsem);  &lt;&lt;&lt;&lt;
&gt;         else
&gt;                 res = down_write_killable(&amp;inode-&gt;i_rwsem);
&gt;

Reported-by: Frank Sorenson &lt;sorenson@redhat.com&gt;
Reviewed-by: Pavel Shilovsky &lt;pshilov@microsoft.com&gt;
Signed-off-by: Ronnie Sahlberg &lt;lsahlber@redhat.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 32546a9586aa4565035bb557e191648e022b29e8 ]

This patch moves the final part of the cifsFileInfo_put() logic where we
need a write lock on lock_sem to be processed in a separate thread that
holds no other locks.
This is to prevent deadlocks like the one below:

&gt; there are 6 processes looping to while trying to down_write
&gt; cinode-&gt;lock_sem, 5 of them from _cifsFileInfo_put, and one from
&gt; cifs_new_fileinfo
&gt;
&gt; and there are 5 other processes which are blocked, several of them
&gt; waiting on either PG_writeback or PG_locked (which are both set), all
&gt; for the same page of the file
&gt;
&gt; 2 inode_lock() (inode-&gt;i_rwsem) for the file
&gt; 1 wait_on_page_writeback() for the page
&gt; 1 down_read(inode-&gt;i_rwsem) for the inode of the directory
&gt; 1 inode_lock()(inode-&gt;i_rwsem) for the inode of the directory
&gt; 1 __lock_page
&gt;
&gt;
&gt; so processes are blocked waiting on:
&gt;   page flags PG_locked and PG_writeback for one specific page
&gt;   inode-&gt;i_rwsem for the directory
&gt;   inode-&gt;i_rwsem for the file
&gt;   cifsInodeInflock_sem
&gt;
&gt;
&gt;
&gt; here are the more gory details (let me know if I need to provide
&gt; anything more/better):
&gt;
&gt; [0 00:48:22.765] [UN]  PID: 8863   TASK: ffff8c691547c5c0  CPU: 3
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965007e3ba8] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965007e3c38] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965007e3c48] rwsem_down_write_slowpath at ffffffff9af283d7
&gt;  #3 [ffff9965007e3cb8] legitimize_path at ffffffff9b0f975d
&gt;  #4 [ffff9965007e3d08] path_openat at ffffffff9b0fe55d
&gt;  #5 [ffff9965007e3dd8] do_filp_open at ffffffff9b100a33
&gt;  #6 [ffff9965007e3ee0] do_sys_open at ffffffff9b0eb2d6
&gt;  #7 [ffff9965007e3f38] do_syscall_64 at ffffffff9ae04315
&gt; * (I think legitimize_path is bogus)
&gt;
&gt; in path_openat
&gt;         } else {
&gt;                 const char *s = path_init(nd, flags);
&gt;                 while (!(error = link_path_walk(s, nd)) &amp;&amp;
&gt;                         (error = do_last(nd, file, op)) &gt; 0) {  &lt;&lt;&lt;&lt;
&gt;
&gt; do_last:
&gt;         if (open_flag &amp; O_CREAT)
&gt;                 inode_lock(dir-&gt;d_inode);  &lt;&lt;&lt;&lt;
&gt;         else
&gt; so it's trying to take inode-&gt;i_rwsem for the directory
&gt;
&gt;      DENTRY           INODE           SUPERBLK     TYPE PATH
&gt; ffff8c68bb8e79c0 ffff8c691158ef20 ffff8c6915bf9000 DIR  /mnt/vm1_smb/
&gt; inode.i_rwsem is ffff8c691158efc0
&gt;
&gt; &lt;struct rw_semaphore 0xffff8c691158efc0&gt;:
&gt;         owner: &lt;struct task_struct 0xffff8c6914275d00&gt; (UN -   8856 -
&gt; reopen_file), counter: 0x0000000000000003
&gt;         waitlist: 2
&gt;         0xffff9965007e3c90     8863   reopen_file      UN 0  1:29:22.926
&gt;   RWSEM_WAITING_FOR_WRITE
&gt;         0xffff996500393e00     9802   ls               UN 0  1:17:26.700
&gt;   RWSEM_WAITING_FOR_READ
&gt;
&gt;
&gt; the owner of the inode.i_rwsem of the directory is:
&gt;
&gt; [0 00:00:00.109] [UN]  PID: 8856   TASK: ffff8c6914275d00  CPU: 3
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff99650065b828] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff99650065b8b8] schedule at ffffffff9b6e64df
&gt;  #2 [ffff99650065b8c8] schedule_timeout at ffffffff9b6e9f89
&gt;  #3 [ffff99650065b940] msleep at ffffffff9af573a9
&gt;  #4 [ffff99650065b948] _cifsFileInfo_put.cold.63 at ffffffffc0a42dd6 [cifs]
&gt;  #5 [ffff99650065ba38] cifs_writepage_locked at ffffffffc0a0b8f3 [cifs]
&gt;  #6 [ffff99650065bab0] cifs_launder_page at ffffffffc0a0bb72 [cifs]
&gt;  #7 [ffff99650065bb30] invalidate_inode_pages2_range at ffffffff9b04d4bd
&gt;  #8 [ffff99650065bcb8] cifs_invalidate_mapping at ffffffffc0a11339 [cifs]
&gt;  #9 [ffff99650065bcd0] cifs_revalidate_mapping at ffffffffc0a1139a [cifs]
&gt; #10 [ffff99650065bcf0] cifs_d_revalidate at ffffffffc0a014f6 [cifs]
&gt; #11 [ffff99650065bd08] path_openat at ffffffff9b0fe7f7
&gt; #12 [ffff99650065bdd8] do_filp_open at ffffffff9b100a33
&gt; #13 [ffff99650065bee0] do_sys_open at ffffffff9b0eb2d6
&gt; #14 [ffff99650065bf38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; cifs_launder_page is for page 0xffffd1e2c07d2480
&gt;
&gt; crash&gt; page.index,mapping,flags 0xffffd1e2c07d2480
&gt;       index = 0x8
&gt;       mapping = 0xffff8c68f3cd0db0
&gt;   flags = 0xfffffc0008095
&gt;
&gt;   PAGE-FLAG       BIT  VALUE
&gt;   PG_locked         0  0000001
&gt;   PG_uptodate       2  0000004
&gt;   PG_lru            4  0000010
&gt;   PG_waiters        7  0000080
&gt;   PG_writeback     15  0008000
&gt;
&gt;
&gt; inode is ffff8c68f3cd0c40
&gt; inode.i_rwsem is ffff8c68f3cd0ce0
&gt;      DENTRY           INODE           SUPERBLK     TYPE PATH
&gt; ffff8c68a1f1b480 ffff8c68f3cd0c40 ffff8c6915bf9000 REG
&gt; /mnt/vm1_smb/testfile.8853
&gt;
&gt;
&gt; this process holds the inode-&gt;i_rwsem for the parent directory, is
&gt; laundering a page attached to the inode of the file it's opening, and in
&gt; _cifsFileInfo_put is trying to down_write the cifsInodeInflock_sem
&gt; for the file itself.
&gt;
&gt;
&gt; &lt;struct rw_semaphore 0xffff8c68f3cd0ce0&gt;:
&gt;         owner: &lt;struct task_struct 0xffff8c6914272e80&gt; (UN -   8854 -
&gt; reopen_file), counter: 0x0000000000000003
&gt;         waitlist: 1
&gt;         0xffff9965005dfd80     8855   reopen_file      UN 0  1:29:22.912
&gt;   RWSEM_WAITING_FOR_WRITE
&gt;
&gt; this is the inode.i_rwsem for the file
&gt;
&gt; the owner:
&gt;
&gt; [0 00:48:22.739] [UN]  PID: 8854   TASK: ffff8c6914272e80  CPU: 2
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff99650054fb38] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff99650054fbc8] schedule at ffffffff9b6e64df
&gt;  #2 [ffff99650054fbd8] io_schedule at ffffffff9b6e68e2
&gt;  #3 [ffff99650054fbe8] __lock_page at ffffffff9b03c56f
&gt;  #4 [ffff99650054fc80] pagecache_get_page at ffffffff9b03dcdf
&gt;  #5 [ffff99650054fcc0] grab_cache_page_write_begin at ffffffff9b03ef4c
&gt;  #6 [ffff99650054fcd0] cifs_write_begin at ffffffffc0a064ec [cifs]
&gt;  #7 [ffff99650054fd30] generic_perform_write at ffffffff9b03bba4
&gt;  #8 [ffff99650054fda8] __generic_file_write_iter at ffffffff9b04060a
&gt;  #9 [ffff99650054fdf0] cifs_strict_writev.cold.70 at ffffffffc0a4469b [cifs]
&gt; #10 [ffff99650054fe48] new_sync_write at ffffffff9b0ec1dd
&gt; #11 [ffff99650054fed0] vfs_write at ffffffff9b0eed35
&gt; #12 [ffff99650054ff00] ksys_write at ffffffff9b0eefd9
&gt; #13 [ffff99650054ff38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; the process holds the inode-&gt;i_rwsem for the file to which it's writing,
&gt; and is trying to __lock_page for the same page as in the other processes
&gt;
&gt;
&gt; the other tasks:
&gt; [0 00:00:00.028] [UN]  PID: 8859   TASK: ffff8c6915479740  CPU: 2
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965007b39d8] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965007b3a68] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965007b3a78] schedule_timeout at ffffffff9b6e9f89
&gt;  #3 [ffff9965007b3af0] msleep at ffffffff9af573a9
&gt;  #4 [ffff9965007b3af8] cifs_new_fileinfo.cold.61 at ffffffffc0a42a07 [cifs]
&gt;  #5 [ffff9965007b3b78] cifs_open at ffffffffc0a0709d [cifs]
&gt;  #6 [ffff9965007b3cd8] do_dentry_open at ffffffff9b0e9b7a
&gt;  #7 [ffff9965007b3d08] path_openat at ffffffff9b0fe34f
&gt;  #8 [ffff9965007b3dd8] do_filp_open at ffffffff9b100a33
&gt;  #9 [ffff9965007b3ee0] do_sys_open at ffffffff9b0eb2d6
&gt; #10 [ffff9965007b3f38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; this is opening the file, and is trying to down_write cinode-&gt;lock_sem
&gt;
&gt;
&gt; [0 00:00:00.041] [UN]  PID: 8860   TASK: ffff8c691547ae80  CPU: 2
&gt; COMMAND: "reopen_file"
&gt; [0 00:00:00.057] [UN]  PID: 8861   TASK: ffff8c6915478000  CPU: 3
&gt; COMMAND: "reopen_file"
&gt; [0 00:00:00.059] [UN]  PID: 8858   TASK: ffff8c6914271740  CPU: 2
&gt; COMMAND: "reopen_file"
&gt; [0 00:00:00.109] [UN]  PID: 8862   TASK: ffff8c691547dd00  CPU: 6
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965007c3c78] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965007c3d08] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965007c3d18] schedule_timeout at ffffffff9b6e9f89
&gt;  #3 [ffff9965007c3d90] msleep at ffffffff9af573a9
&gt;  #4 [ffff9965007c3d98] _cifsFileInfo_put.cold.63 at ffffffffc0a42dd6 [cifs]
&gt;  #5 [ffff9965007c3e88] cifs_close at ffffffffc0a07aaf [cifs]
&gt;  #6 [ffff9965007c3ea0] __fput at ffffffff9b0efa6e
&gt;  #7 [ffff9965007c3ee8] task_work_run at ffffffff9aef1614
&gt;  #8 [ffff9965007c3f20] exit_to_usermode_loop at ffffffff9ae03d6f
&gt;  #9 [ffff9965007c3f38] do_syscall_64 at ffffffff9ae0444c
&gt;
&gt; closing the file, and trying to down_write cifsi-&gt;lock_sem
&gt;
&gt;
&gt; [0 00:48:22.839] [UN]  PID: 8857   TASK: ffff8c6914270000  CPU: 7
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965006a7cc8] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965006a7d58] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965006a7d68] io_schedule at ffffffff9b6e68e2
&gt;  #3 [ffff9965006a7d78] wait_on_page_bit at ffffffff9b03cac6
&gt;  #4 [ffff9965006a7e10] __filemap_fdatawait_range at ffffffff9b03b028
&gt;  #5 [ffff9965006a7ed8] filemap_write_and_wait at ffffffff9b040165
&gt;  #6 [ffff9965006a7ef0] cifs_flush at ffffffffc0a0c2fa [cifs]
&gt;  #7 [ffff9965006a7f10] filp_close at ffffffff9b0e93f1
&gt;  #8 [ffff9965006a7f30] __x64_sys_close at ffffffff9b0e9a0e
&gt;  #9 [ffff9965006a7f38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; in __filemap_fdatawait_range
&gt;                         wait_on_page_writeback(page);
&gt; for the same page of the file
&gt;
&gt;
&gt;
&gt; [0 00:48:22.718] [UN]  PID: 8855   TASK: ffff8c69142745c0  CPU: 7
&gt; COMMAND: "reopen_file"
&gt;  #0 [ffff9965005dfc98] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff9965005dfd28] schedule at ffffffff9b6e64df
&gt;  #2 [ffff9965005dfd38] rwsem_down_write_slowpath at ffffffff9af283d7
&gt;  #3 [ffff9965005dfdf0] cifs_strict_writev at ffffffffc0a0c40a [cifs]
&gt;  #4 [ffff9965005dfe48] new_sync_write at ffffffff9b0ec1dd
&gt;  #5 [ffff9965005dfed0] vfs_write at ffffffff9b0eed35
&gt;  #6 [ffff9965005dff00] ksys_write at ffffffff9b0eefd9
&gt;  #7 [ffff9965005dff38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt;         inode_lock(inode);
&gt;
&gt;
&gt; and one 'ls' later on, to see whether the rest of the mount is available
&gt; (the test file is in the root, so we get blocked up on the directory
&gt; -&gt;i_rwsem), so the entire mount is unavailable
&gt;
&gt; [0 00:36:26.473] [UN]  PID: 9802   TASK: ffff8c691436ae80  CPU: 4
&gt; COMMAND: "ls"
&gt;  #0 [ffff996500393d28] __schedule at ffffffff9b6e6095
&gt;  #1 [ffff996500393db8] schedule at ffffffff9b6e64df
&gt;  #2 [ffff996500393dc8] rwsem_down_read_slowpath at ffffffff9b6e9421
&gt;  #3 [ffff996500393e78] down_read_killable at ffffffff9b6e95e2
&gt;  #4 [ffff996500393e88] iterate_dir at ffffffff9b103c56
&gt;  #5 [ffff996500393ec8] ksys_getdents64 at ffffffff9b104b0c
&gt;  #6 [ffff996500393f30] __x64_sys_getdents64 at ffffffff9b104bb6
&gt;  #7 [ffff996500393f38] do_syscall_64 at ffffffff9ae04315
&gt;
&gt; in iterate_dir:
&gt;         if (shared)
&gt;                 res = down_read_killable(&amp;inode-&gt;i_rwsem);  &lt;&lt;&lt;&lt;
&gt;         else
&gt;                 res = down_write_killable(&amp;inode-&gt;i_rwsem);
&gt;

Reported-by: Frank Sorenson &lt;sorenson@redhat.com&gt;
Reviewed-by: Pavel Shilovsky &lt;pshilov@microsoft.com&gt;
Signed-off-by: Ronnie Sahlberg &lt;lsahlber@redhat.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>io_uring: io_allocate_scq_urings() should return a sane state</title>
<updated>2020-01-04T18:18:24+00:00</updated>
<author>
<name>Jens Axboe</name>
<email>axboe@kernel.dk</email>
</author>
<published>2019-11-20T16:26:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=1768acaa6d8a0a0ef6b6ac3d3c0467e4ab404840'/>
<id>1768acaa6d8a0a0ef6b6ac3d3c0467e4ab404840</id>
<content type='text'>
[ Upstream commit eb065d301e8c83643367bdb0898becc364046bda ]

We currently rely on the ring destroy on cleaning things up in case of
failure, but io_allocate_scq_urings() can leave things half initialized
if only parts of it fails.

Be nice and return with either everything setup in success, or return an
error with things nicely cleaned up.

Reported-by: syzbot+0d818c0d39399188f393@syzkaller.appspotmail.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit eb065d301e8c83643367bdb0898becc364046bda ]

We currently rely on the ring destroy on cleaning things up in case of
failure, but io_allocate_scq_urings() can leave things half initialized
if only parts of it fails.

Be nice and return with either everything setup in success, or return an
error with things nicely cleaned up.

Reported-by: syzbot+0d818c0d39399188f393@syzkaller.appspotmail.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cifs: Fix use-after-free bug in cifs_reconnect()</title>
<updated>2020-01-04T18:18:24+00:00</updated>
<author>
<name>Paulo Alcantara (SUSE)</name>
<email>pc@cjr.nz</email>
</author>
<published>2019-11-22T15:30:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=42e8507bf2dcd39b4eddc318d63a1b494ffd098a'/>
<id>42e8507bf2dcd39b4eddc318d63a1b494ffd098a</id>
<content type='text'>
[ Upstream commit 8354d88efdab72b4da32fc4f032448fcef22dab4 ]

Ensure we grab an active reference in cifs superblock while doing
failover to prevent automounts (DFS links) of expiring and then
destroying the superblock pointer.

This patch fixes the following KASAN report:

[  464.301462] BUG: KASAN: use-after-free in
cifs_reconnect+0x6ab/0x1350
[  464.303052] Read of size 8 at addr ffff888155e580d0 by task
cifsd/1107

[  464.304682] CPU: 3 PID: 1107 Comm: cifsd Not tainted 5.4.0-rc4+ #13
[  464.305552] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009),
BIOS rel-1.12.1-0-ga5cab58-rebuilt.opensuse.org 04/01/2014
[  464.307146] Call Trace:
[  464.307875]  dump_stack+0x5b/0x90
[  464.308631]  print_address_description.constprop.0+0x16/0x200
[  464.309478]  ? cifs_reconnect+0x6ab/0x1350
[  464.310253]  ? cifs_reconnect+0x6ab/0x1350
[  464.311040]  __kasan_report.cold+0x1a/0x41
[  464.311811]  ? cifs_reconnect+0x6ab/0x1350
[  464.312563]  kasan_report+0xe/0x20
[  464.313300]  cifs_reconnect+0x6ab/0x1350
[  464.314062]  ? extract_hostname.part.0+0x90/0x90
[  464.314829]  ? printk+0xad/0xde
[  464.315525]  ? _raw_spin_lock+0x7c/0xd0
[  464.316252]  ? _raw_read_lock_irq+0x40/0x40
[  464.316961]  ? ___ratelimit+0xed/0x182
[  464.317655]  cifs_readv_from_socket+0x289/0x3b0
[  464.318386]  cifs_read_from_socket+0x98/0xd0
[  464.319078]  ? cifs_readv_from_socket+0x3b0/0x3b0
[  464.319782]  ? try_to_wake_up+0x43c/0xa90
[  464.320463]  ? cifs_small_buf_get+0x4b/0x60
[  464.321173]  ? allocate_buffers+0x98/0x1a0
[  464.321856]  cifs_demultiplex_thread+0x218/0x14a0
[  464.322558]  ? cifs_handle_standard+0x270/0x270
[  464.323237]  ? __switch_to_asm+0x40/0x70
[  464.323893]  ? __switch_to_asm+0x34/0x70
[  464.324554]  ? __switch_to_asm+0x40/0x70
[  464.325226]  ? __switch_to_asm+0x40/0x70
[  464.325863]  ? __switch_to_asm+0x34/0x70
[  464.326505]  ? __switch_to_asm+0x40/0x70
[  464.327161]  ? __switch_to_asm+0x34/0x70
[  464.327784]  ? finish_task_switch+0xa1/0x330
[  464.328414]  ? __switch_to+0x363/0x640
[  464.329044]  ? __schedule+0x575/0xaf0
[  464.329655]  ? _raw_spin_lock_irqsave+0x82/0xe0
[  464.330301]  kthread+0x1a3/0x1f0
[  464.330884]  ? cifs_handle_standard+0x270/0x270
[  464.331624]  ? kthread_create_on_node+0xd0/0xd0
[  464.332347]  ret_from_fork+0x35/0x40

[  464.333577] Allocated by task 1110:
[  464.334381]  save_stack+0x1b/0x80
[  464.335123]  __kasan_kmalloc.constprop.0+0xc2/0xd0
[  464.335848]  cifs_smb3_do_mount+0xd4/0xb00
[  464.336619]  legacy_get_tree+0x6b/0xa0
[  464.337235]  vfs_get_tree+0x41/0x110
[  464.337975]  fc_mount+0xa/0x40
[  464.338557]  vfs_kern_mount.part.0+0x6c/0x80
[  464.339227]  cifs_dfs_d_automount+0x336/0xd29
[  464.339846]  follow_managed+0x1b1/0x450
[  464.340449]  lookup_fast+0x231/0x4a0
[  464.341039]  path_openat+0x240/0x1fd0
[  464.341634]  do_filp_open+0x126/0x1c0
[  464.342277]  do_sys_open+0x1eb/0x2c0
[  464.342957]  do_syscall_64+0x5e/0x190
[  464.343555]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

[  464.344772] Freed by task 0:
[  464.345347]  save_stack+0x1b/0x80
[  464.345966]  __kasan_slab_free+0x12c/0x170
[  464.346576]  kfree+0xa6/0x270
[  464.347211]  rcu_core+0x39c/0xc80
[  464.347800]  __do_softirq+0x10d/0x3da

[  464.348919] The buggy address belongs to the object at
ffff888155e58000
                which belongs to the cache kmalloc-256 of size 256
[  464.350222] The buggy address is located 208 bytes inside of
                256-byte region [ffff888155e58000, ffff888155e58100)
[  464.351575] The buggy address belongs to the page:
[  464.352333] page:ffffea0005579600 refcount:1 mapcount:0
mapping:ffff88815a803400 index:0x0 compound_mapcount: 0
[  464.353583] flags: 0x200000000010200(slab|head)
[  464.354209] raw: 0200000000010200 ffffea0005576200 0000000400000004
ffff88815a803400
[  464.355353] raw: 0000000000000000 0000000080100010 00000001ffffffff
0000000000000000
[  464.356458] page dumped because: kasan: bad access detected

[  464.367005] Memory state around the buggy address:
[  464.367787]  ffff888155e57f80: fc fc fc fc fc fc fc fc fc fc fc fc
fc fc fc fc
[  464.368877]  ffff888155e58000: fb fb fb fb fb fb fb fb fb fb fb fb
fb fb fb fb
[  464.369967] &gt;ffff888155e58080: fb fb fb fb fb fb fb fb fb fb fb fb
fb fb fb fb
[  464.371111]                                                  ^
[  464.371775]  ffff888155e58100: fc fc fc fc fc fc fc fc fc fc fc fc
fc fc fc fc
[  464.372893]  ffff888155e58180: fc fc fc fc fc fc fc fc fc fc fc fc
fc fc fc fc
[  464.373983] ==================================================================

Signed-off-by: Paulo Alcantara (SUSE) &lt;pc@cjr.nz&gt;
Reviewed-by: Aurelien Aptel &lt;aaptel@suse.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 8354d88efdab72b4da32fc4f032448fcef22dab4 ]

Ensure we grab an active reference in cifs superblock while doing
failover to prevent automounts (DFS links) of expiring and then
destroying the superblock pointer.

This patch fixes the following KASAN report:

[  464.301462] BUG: KASAN: use-after-free in
cifs_reconnect+0x6ab/0x1350
[  464.303052] Read of size 8 at addr ffff888155e580d0 by task
cifsd/1107

[  464.304682] CPU: 3 PID: 1107 Comm: cifsd Not tainted 5.4.0-rc4+ #13
[  464.305552] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009),
BIOS rel-1.12.1-0-ga5cab58-rebuilt.opensuse.org 04/01/2014
[  464.307146] Call Trace:
[  464.307875]  dump_stack+0x5b/0x90
[  464.308631]  print_address_description.constprop.0+0x16/0x200
[  464.309478]  ? cifs_reconnect+0x6ab/0x1350
[  464.310253]  ? cifs_reconnect+0x6ab/0x1350
[  464.311040]  __kasan_report.cold+0x1a/0x41
[  464.311811]  ? cifs_reconnect+0x6ab/0x1350
[  464.312563]  kasan_report+0xe/0x20
[  464.313300]  cifs_reconnect+0x6ab/0x1350
[  464.314062]  ? extract_hostname.part.0+0x90/0x90
[  464.314829]  ? printk+0xad/0xde
[  464.315525]  ? _raw_spin_lock+0x7c/0xd0
[  464.316252]  ? _raw_read_lock_irq+0x40/0x40
[  464.316961]  ? ___ratelimit+0xed/0x182
[  464.317655]  cifs_readv_from_socket+0x289/0x3b0
[  464.318386]  cifs_read_from_socket+0x98/0xd0
[  464.319078]  ? cifs_readv_from_socket+0x3b0/0x3b0
[  464.319782]  ? try_to_wake_up+0x43c/0xa90
[  464.320463]  ? cifs_small_buf_get+0x4b/0x60
[  464.321173]  ? allocate_buffers+0x98/0x1a0
[  464.321856]  cifs_demultiplex_thread+0x218/0x14a0
[  464.322558]  ? cifs_handle_standard+0x270/0x270
[  464.323237]  ? __switch_to_asm+0x40/0x70
[  464.323893]  ? __switch_to_asm+0x34/0x70
[  464.324554]  ? __switch_to_asm+0x40/0x70
[  464.325226]  ? __switch_to_asm+0x40/0x70
[  464.325863]  ? __switch_to_asm+0x34/0x70
[  464.326505]  ? __switch_to_asm+0x40/0x70
[  464.327161]  ? __switch_to_asm+0x34/0x70
[  464.327784]  ? finish_task_switch+0xa1/0x330
[  464.328414]  ? __switch_to+0x363/0x640
[  464.329044]  ? __schedule+0x575/0xaf0
[  464.329655]  ? _raw_spin_lock_irqsave+0x82/0xe0
[  464.330301]  kthread+0x1a3/0x1f0
[  464.330884]  ? cifs_handle_standard+0x270/0x270
[  464.331624]  ? kthread_create_on_node+0xd0/0xd0
[  464.332347]  ret_from_fork+0x35/0x40

[  464.333577] Allocated by task 1110:
[  464.334381]  save_stack+0x1b/0x80
[  464.335123]  __kasan_kmalloc.constprop.0+0xc2/0xd0
[  464.335848]  cifs_smb3_do_mount+0xd4/0xb00
[  464.336619]  legacy_get_tree+0x6b/0xa0
[  464.337235]  vfs_get_tree+0x41/0x110
[  464.337975]  fc_mount+0xa/0x40
[  464.338557]  vfs_kern_mount.part.0+0x6c/0x80
[  464.339227]  cifs_dfs_d_automount+0x336/0xd29
[  464.339846]  follow_managed+0x1b1/0x450
[  464.340449]  lookup_fast+0x231/0x4a0
[  464.341039]  path_openat+0x240/0x1fd0
[  464.341634]  do_filp_open+0x126/0x1c0
[  464.342277]  do_sys_open+0x1eb/0x2c0
[  464.342957]  do_syscall_64+0x5e/0x190
[  464.343555]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

[  464.344772] Freed by task 0:
[  464.345347]  save_stack+0x1b/0x80
[  464.345966]  __kasan_slab_free+0x12c/0x170
[  464.346576]  kfree+0xa6/0x270
[  464.347211]  rcu_core+0x39c/0xc80
[  464.347800]  __do_softirq+0x10d/0x3da

[  464.348919] The buggy address belongs to the object at
ffff888155e58000
                which belongs to the cache kmalloc-256 of size 256
[  464.350222] The buggy address is located 208 bytes inside of
                256-byte region [ffff888155e58000, ffff888155e58100)
[  464.351575] The buggy address belongs to the page:
[  464.352333] page:ffffea0005579600 refcount:1 mapcount:0
mapping:ffff88815a803400 index:0x0 compound_mapcount: 0
[  464.353583] flags: 0x200000000010200(slab|head)
[  464.354209] raw: 0200000000010200 ffffea0005576200 0000000400000004
ffff88815a803400
[  464.355353] raw: 0000000000000000 0000000080100010 00000001ffffffff
0000000000000000
[  464.356458] page dumped because: kasan: bad access detected

[  464.367005] Memory state around the buggy address:
[  464.367787]  ffff888155e57f80: fc fc fc fc fc fc fc fc fc fc fc fc
fc fc fc fc
[  464.368877]  ffff888155e58000: fb fb fb fb fb fb fb fb fb fb fb fb
fb fb fb fb
[  464.369967] &gt;ffff888155e58080: fb fb fb fb fb fb fb fb fb fb fb fb
fb fb fb fb
[  464.371111]                                                  ^
[  464.371775]  ffff888155e58100: fc fc fc fc fc fc fc fc fc fc fc fc
fc fc fc fc
[  464.372893]  ffff888155e58180: fc fc fc fc fc fc fc fc fc fc fc fc
fc fc fc fc
[  464.373983] ==================================================================

Signed-off-by: Paulo Alcantara (SUSE) &lt;pc@cjr.nz&gt;
Reviewed-by: Aurelien Aptel &lt;aaptel@suse.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>f2fs: Fix deadlock in f2fs_gc() context during atomic files handling</title>
<updated>2020-01-04T18:18:18+00:00</updated>
<author>
<name>Sahitya Tummala</name>
<email>stummala@codeaurora.org</email>
</author>
<published>2019-11-13T10:31:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=ce7269497052f463cb3c74f1388d352c37d24b80'/>
<id>ce7269497052f463cb3c74f1388d352c37d24b80</id>
<content type='text'>
[ Upstream commit 677017d196ba2a4cfff13626b951cc9a206b8c7c ]

The FS got stuck in the below stack when the storage is almost
full/dirty condition (when FG_GC is being done).

schedule_timeout
io_schedule_timeout
congestion_wait
f2fs_drop_inmem_pages_all
f2fs_gc
f2fs_balance_fs
__write_node_page
f2fs_fsync_node_pages
f2fs_do_sync_file
f2fs_ioctl

The root cause for this issue is there is a potential infinite loop
in f2fs_drop_inmem_pages_all() for the case where gc_failure is true
and when there an inode whose i_gc_failures[GC_FAILURE_ATOMIC] is
not set. Fix this by keeping track of the total atomic files
currently opened and using that to exit from this condition.

Fix-suggested-by: Chao Yu &lt;yuchao0@huawei.com&gt;
Signed-off-by: Chao Yu &lt;yuchao0@huawei.com&gt;
Signed-off-by: Sahitya Tummala &lt;stummala@codeaurora.org&gt;
Signed-off-by: Jaegeuk Kim &lt;jaegeuk@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 677017d196ba2a4cfff13626b951cc9a206b8c7c ]

The FS got stuck in the below stack when the storage is almost
full/dirty condition (when FG_GC is being done).

schedule_timeout
io_schedule_timeout
congestion_wait
f2fs_drop_inmem_pages_all
f2fs_gc
f2fs_balance_fs
__write_node_page
f2fs_fsync_node_pages
f2fs_do_sync_file
f2fs_ioctl

The root cause for this issue is there is a potential infinite loop
in f2fs_drop_inmem_pages_all() for the case where gc_failure is true
and when there an inode whose i_gc_failures[GC_FAILURE_ATOMIC] is
not set. Fix this by keeping track of the total atomic files
currently opened and using that to exit from this condition.

Fix-suggested-by: Chao Yu &lt;yuchao0@huawei.com&gt;
Signed-off-by: Chao Yu &lt;yuchao0@huawei.com&gt;
Signed-off-by: Sahitya Tummala &lt;stummala@codeaurora.org&gt;
Signed-off-by: Jaegeuk Kim &lt;jaegeuk@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>iomap: fix return value of iomap_dio_bio_actor on 32bit systems</title>
<updated>2020-01-04T18:17:31+00:00</updated>
<author>
<name>Jan Stancek</name>
<email>jstancek@redhat.com</email>
</author>
<published>2019-11-11T20:58:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=185563ec11956ec1237d62fae80eab593ee63ca9'/>
<id>185563ec11956ec1237d62fae80eab593ee63ca9</id>
<content type='text'>
[ Upstream commit e9f930ac88a8936ccc2d021110c98810cf5aa810 ]

Naresh reported LTP diotest4 failing for 32bit x86 and arm -next
kernels on ext4. Same problem exists in 5.4-rc7 on xfs.

The failure comes down to:
  openat(AT_FDCWD, "testdata-4.5918", O_RDWR|O_DIRECT) = 4
  mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f7b000
  read(4, 0xb7f7b000, 4096)              = 0 // expects -EFAULT

Problem is conversion at iomap_dio_bio_actor() return. Ternary
operator has a return type and an attempt is made to convert each
of operands to the type of the other. In this case "ret" (int)
is converted to type of "copied" (unsigned long). Both have size
of 4 bytes:
    size_t copied = 0;
    int ret = -14;
    long long actor_ret = copied ? copied : ret;

    On x86_64: actor_ret == -14;
    On x86   : actor_ret == 4294967282

Replace ternary operator with 2 return statements to avoid this
unwanted conversion.

Fixes: 4721a6010990 ("iomap: dio data corruption and spurious errors when pipes fill")
Reported-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Jan Stancek &lt;jstancek@redhat.com&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Reviewed-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit e9f930ac88a8936ccc2d021110c98810cf5aa810 ]

Naresh reported LTP diotest4 failing for 32bit x86 and arm -next
kernels on ext4. Same problem exists in 5.4-rc7 on xfs.

The failure comes down to:
  openat(AT_FDCWD, "testdata-4.5918", O_RDWR|O_DIRECT) = 4
  mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f7b000
  read(4, 0xb7f7b000, 4096)              = 0 // expects -EFAULT

Problem is conversion at iomap_dio_bio_actor() return. Ternary
operator has a return type and an attempt is made to convert each
of operands to the type of the other. In this case "ret" (int)
is converted to type of "copied" (unsigned long). Both have size
of 4 bytes:
    size_t copied = 0;
    int ret = -14;
    long long actor_ret = copied ? copied : ret;

    On x86_64: actor_ret == -14;
    On x86   : actor_ret == 4294967282

Replace ternary operator with 2 return statements to avoid this
unwanted conversion.

Fixes: 4721a6010990 ("iomap: dio data corruption and spurious errors when pipes fill")
Reported-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Jan Stancek &lt;jstancek@redhat.com&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Reviewed-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Darrick J. Wong &lt;darrick.wong@oracle.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
