<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/fs/fscache, branch linux-6.0.y</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=linux-6.0.y</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=linux-6.0.y'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2022-12-14T10:40:51+00:00</updated>
<entry>
<title>fscache: Fix oops due to race with cookie_lru and use_cookie</title>
<updated>2022-12-14T10:40:51+00:00</updated>
<author>
<name>Dave Wysochanski</name>
<email>dwysocha@redhat.com</email>
</author>
<published>2022-12-07T13:49:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=37f0b459c9b67e14fe4dcc3a15d286c4436ed01d'/>
<id>urn:sha1:37f0b459c9b67e14fe4dcc3a15d286c4436ed01d</id>
<content type='text'>
[ Upstream commit b5b52de3214a29911f949459a79f6640969b5487 ]

If a cookie expires from the LRU and the LRU_DISCARD flag is set, but
the state machine has not run yet, it's possible another thread can call
fscache_use_cookie and begin to use it.

When the cookie_worker finally runs, it will see the LRU_DISCARD flag
set, transition the cookie-&gt;state to LRU_DISCARDING, which will then
withdraw the cookie.  Once the cookie is withdrawn the object is removed
the below oops will occur because the object associated with the cookie
is now NULL.

Fix the oops by clearing the LRU_DISCARD bit if another thread uses the
cookie before the cookie_worker runs.

  BUG: kernel NULL pointer dereference, address: 0000000000000008
  ...
  CPU: 31 PID: 44773 Comm: kworker/u130:1 Tainted: G     E    6.0.0-5.dneg.x86_64 #1
  Hardware name: Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2022
  Workqueue: events_unbound netfs_rreq_write_to_cache_work [netfs]
  RIP: 0010:cachefiles_prepare_write+0x28/0x90 [cachefiles]
  ...
  Call Trace:
    netfs_rreq_write_to_cache_work+0x11c/0x320 [netfs]
    process_one_work+0x217/0x3e0
    worker_thread+0x4a/0x3b0
    kthread+0xd6/0x100

Fixes: 12bb21a29c19 ("fscache: Implement cookie user counting and resource pinning")
Reported-by: Daire Byrne &lt;daire.byrne@gmail.com&gt;
Signed-off-by: Dave Wysochanski &lt;dwysocha@redhat.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Tested-by: Daire Byrne &lt;daire@dneg.com&gt;
Link: https://lore.kernel.org/r/20221117115023.1350181-1-dwysocha@redhat.com/ # v1
Link: https://lore.kernel.org/r/20221117142915.1366990-1-dwysocha@redhat.com/ # v2
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>fscache: fix OOB Read in __fscache_acquire_volume</title>
<updated>2022-12-02T16:43:08+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2022-11-21T16:31:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a751898a460ebaeb531b7dbebfb98c49a6c330e4'/>
<id>urn:sha1:a751898a460ebaeb531b7dbebfb98c49a6c330e4</id>
<content type='text'>
[ Upstream commit 9f0933ac026f7e54fe096797af9de20724e79097 ]

The type of a-&gt;key[0] is char in fscache_volume_same().  If the length
of cache volume key is greater than 127, the value of a-&gt;key[0] is less
than 0.  In this case, klen becomes much larger than 255 after type
conversion, because the type of klen is size_t.  As a result, memcmp()
is read out of bounds.

This causes a slab-out-of-bounds Read in __fscache_acquire_volume(), as
reported by Syzbot.

Fix this by changing the type of the stored key to "u8 *" rather than
"char *" (it isn't a simple string anyway).  Also put in a check that
the volume name doesn't exceed NAME_MAX.

  BUG: KASAN: slab-out-of-bounds in memcmp+0x16f/0x1c0 lib/string.c:757
  Read of size 8 at addr ffff888016f3aa90 by task syz-executor344/3613
  Call Trace:
   memcmp+0x16f/0x1c0 lib/string.c:757
   memcmp include/linux/fortify-string.h:420 [inline]
   fscache_volume_same fs/fscache/volume.c:133 [inline]
   fscache_hash_volume fs/fscache/volume.c:171 [inline]
   __fscache_acquire_volume+0x76c/0x1080 fs/fscache/volume.c:328
   fscache_acquire_volume include/linux/fscache.h:204 [inline]
   v9fs_cache_session_get_cookie+0x143/0x240 fs/9p/cache.c:34
   v9fs_session_init+0x1166/0x1810 fs/9p/v9fs.c:473
   v9fs_mount+0xba/0xc90 fs/9p/vfs_super.c:126
   legacy_get_tree+0x105/0x220 fs/fs_context.c:610
   vfs_get_tree+0x89/0x2f0 fs/super.c:1530
   do_new_mount fs/namespace.c:3040 [inline]
   path_mount+0x1326/0x1e20 fs/namespace.c:3370
   do_mount fs/namespace.c:3383 [inline]
   __do_sys_mount fs/namespace.c:3591 [inline]
   __se_sys_mount fs/namespace.c:3568 [inline]
   __x64_sys_mount+0x27f/0x300 fs/namespace.c:3568

Fixes: 62ab63352350 ("fscache: Implement volume registration")
Reported-by: syzbot+a76f6a6e524cf2080aa3@syzkaller.appspotmail.com
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Zhang Peng &lt;zhangpeng362@huawei.com&gt;
Reviewed-by: Jingbo Xu &lt;jefflexu@linux.alibaba.com&gt;
cc: Dominique Martinet &lt;asmadeus@codewreck.org&gt;
cc: Jeff Layton &lt;jlayton@kernel.org&gt;
cc: v9fs-developer@lists.sourceforge.net
cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/r/Y3OH+Dmi0QIOK18n@codewreck.org/ # Zhang Peng's v1 fix
Link: https://lore.kernel.org/r/20221115140447.2971680-1-zhangpeng362@huawei.com/ # Zhang Peng's v2 fix
Link: https://lore.kernel.org/r/166869954095.3793579.8500020902371015443.stgit@warthog.procyon.org.uk/ # v1
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>fscache: add tracepoint when failing cookie</title>
<updated>2022-08-09T13:13:59+00:00</updated>
<author>
<name>Jeff Layton</name>
<email>jlayton@kernel.org</email>
</author>
<published>2022-08-05T10:43:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1a1e3aca9d4957e282945cdc2b58e7c560b8e0d2'/>
<id>urn:sha1:1a1e3aca9d4957e282945cdc2b58e7c560b8e0d2</id>
<content type='text'>
Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
</content>
</entry>
<entry>
<title>fscache: don't leak cookie access refs if invalidation is in progress or failed</title>
<updated>2022-08-09T13:13:55+00:00</updated>
<author>
<name>Jeff Layton</name>
<email>jlayton@kernel.org</email>
</author>
<published>2022-08-05T10:42:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=fb24771faf72a2fd62b3b6287af3c610c3ec9cf1'/>
<id>urn:sha1:fb24771faf72a2fd62b3b6287af3c610c3ec9cf1</id>
<content type='text'>
It's possible for a request to invalidate a fscache_cookie will come in
while we're already processing an invalidation. If that happens we
currently take an extra access reference that will leak. Only call
__fscache_begin_cookie_access if the FSCACHE_COOKIE_DO_INVALIDATE bit
was previously clear.

Also, ensure that we attempt to clear the bit when the cookie is
"FAILED" and put the reference to avoid an access leak.

Fixes: 85e4ea1049c7 ("fscache: Fix invalidation/lookup race")
Suggested-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
</content>
</entry>
<entry>
<title>fscache: Fix invalidation/lookup race</title>
<updated>2022-07-05T15:12:55+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2022-04-20T13:27:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=85e4ea1049c70fb99de5c6057e835d151fb647da'/>
<id>urn:sha1:85e4ea1049c70fb99de5c6057e835d151fb647da</id>
<content type='text'>
If an NFS file is opened for writing and closed, fscache_invalidate() will
be asked to invalidate the file - however, if the cookie is in the
LOOKING_UP state (or the CREATING state), then request to invalidate
doesn't get recorded for fscache_cookie_state_machine() to do something
with.

Fix this by making __fscache_invalidate() set a flag if it sees the cookie
is in the LOOKING_UP state to indicate that we need to go to invalidation.
Note that this requires a count on the n_accesses counter for the state
machine, which that will release when it's done.

fscache_cookie_state_machine() then shifts to the INVALIDATING state if it
sees the flag.

Without this, an nfs file can get corrupted if it gets modified locally and
then read locally as the cache contents may not get updated.

Fixes: d24af13e2e23 ("fscache: Implement cookie invalidation")
Reported-by: Max Kellermann &lt;mk@cm4all.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Tested-by: Max Kellermann &lt;mk@cm4all.com&gt;
Link: https://lore.kernel.org/r/YlWWbpW5Foynjllo@rabbit.intern.cm-ag [1]
</content>
</entry>
<entry>
<title>fscache: Introduce fscache_cookie_is_dropped()</title>
<updated>2022-07-05T15:12:20+00:00</updated>
<author>
<name>Yue Hu</name>
<email>zbestahu@gmail.com</email>
</author>
<published>2022-05-25T02:51:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5c4588aea6675b69e328d468c5b6be5127e19a79'/>
<id>urn:sha1:5c4588aea6675b69e328d468c5b6be5127e19a79</id>
<content type='text'>
FSCACHE_COOKIE_STATE_DROPPED will be read more than once, so let's add a
helper to avoid code duplication.

Signed-off-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Link: https://listman.redhat.com/archives/linux-cachefs/2022-May/006919.html
</content>
</entry>
<entry>
<title>fscache: Fix if condition in fscache_wait_on_volume_collision()</title>
<updated>2022-07-05T15:12:20+00:00</updated>
<author>
<name>Yue Hu</name>
<email>huyue2@coolpad.com</email>
</author>
<published>2022-05-25T02:32:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=bf17455b9cbd4b10bf30d39c047307e1d774fb1a'/>
<id>urn:sha1:bf17455b9cbd4b10bf30d39c047307e1d774fb1a</id>
<content type='text'>
After waiting for the volume to complete the acquisition with timeout,
the if condition under which potential volume collision occurs should be
acquire the volume is still pending rather than not pending so that we
will continue to wait until the pending flag is cleared. Also, use the
existing test pending wrapper directly instead of test_bit().

Fixes: 62ab63352350 ("fscache: Implement volume registration")
Signed-off-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Jeffle Xu &lt;jefflexu@linux.alibaba.com&gt;
Reviewed-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Link: https://listman.redhat.com/archives/linux-cachefs/2022-May/006918.html
</content>
</entry>
<entry>
<title>fscache: remove FSCACHE_OLD_API Kconfig option</title>
<updated>2022-04-08T22:54:37+00:00</updated>
<author>
<name>Yue Hu</name>
<email>huyue2@coolpad.com</email>
</author>
<published>2022-03-31T11:57:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=61132ceeda723d2c48cbc2610ca3213a7fcb083b'/>
<id>urn:sha1:61132ceeda723d2c48cbc2610ca3213a7fcb083b</id>
<content type='text'>
Commit 01491a756578 ("fscache, cachefiles: Disable configuration") added
the FSCACHE_OLD_API configuration when rewritten. Now, it's not used any
more. Remove it.

Signed-off-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
cc: linux-cachefs@redhat.com
Link: https://listman.redhat.com/archives/linux-cachefs/2022-March/006647.html # v1
</content>
</entry>
<entry>
<title>fscache: Use wrapper fscache_set_cache_state() directly when relinquishing</title>
<updated>2022-04-08T22:54:37+00:00</updated>
<author>
<name>Yue Hu</name>
<email>huyue2@coolpad.com</email>
</author>
<published>2022-04-01T06:37:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b3c958c20a61fb8514fa16e3edcb421703600ee0'/>
<id>urn:sha1:b3c958c20a61fb8514fa16e3edcb421703600ee0</id>
<content type='text'>
We already have the wrapper function to set cache state.

Signed-off-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Jeffle Xu &lt;jefflexu@linux.alibaba.com&gt;
cc: linux-cachefs@redhat.com
Link: https://listman.redhat.com/archives/linux-cachefs/2022-April/006648.html # v1
</content>
</entry>
<entry>
<title>fscache: Move fscache_cookies_seq_ops specific code under CONFIG_PROC_FS</title>
<updated>2022-04-08T22:54:37+00:00</updated>
<author>
<name>Yue Hu</name>
<email>huyue2@coolpad.com</email>
</author>
<published>2022-04-02T04:47:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=19517e53740ec671c335f05089abe1f0720103c7'/>
<id>urn:sha1:19517e53740ec671c335f05089abe1f0720103c7</id>
<content type='text'>
fscache_cookies_seq_ops is only used in proc.c that is compiled under
enabled CONFIG_PROC_FS, so move related code under this config. The
same case exsits in internal.h.

Also, make fscache_lru_cookie_timeout static due to no user outside
of cookie.c.

Signed-off-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
cc: linux-cachefs@redhat.com
Link: https://listman.redhat.com/archives/linux-cachefs/2022-April/006649.html # v1
</content>
</entry>
</feed>
