<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/notify/mark.c, branch linux-4.19.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.19.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.19.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2022-06-14T14:59:20Z</updated>
<entry>
<title>fsnotify: fix wrong lockdep annotations</title>
<updated>2022-06-14T14:59:20Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2022-04-22T12:03:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=72632015277b56d5f8fd666ccd24cb0ed7ef1d72'/>
<id>urn:sha1:72632015277b56d5f8fd666ccd24cb0ed7ef1d72</id>
<content type='text'>
[ Upstream commit 623af4f538b5df9b416e1b82f720af7371b4c771 ]

Commit 6960b0d909cd ("fsnotify: change locking order") changed some
of the mark_mutex locks in direct reclaim path to use:
  mutex_lock_nested(&amp;group-&gt;mark_mutex, SINGLE_DEPTH_NESTING);

This change is explained:
 "...It uses nested locking to avoid deadlock in case we do the final
  iput() on an inode which still holds marks and thus would take the
  mutex again when calling fsnotify_inode_delete() in destroy_inode()."

The problem is that the mutex_lock_nested() is not a nested lock at
all. In fact, it has the opposite effect of preventing lockdep from
warning about a very possible deadlock.

Due to these wrong annotations, a deadlock that was introduced with
nfsd filecache in kernel v5.4 went unnoticed in v5.4.y for over two
years until it was reported recently by Khazhismel Kumykov, only to
find out that the deadlock was already fixed in kernel v5.5.

Fix the wrong lockdep annotations.

Cc: Khazhismel Kumykov &lt;khazhy@google.com&gt;
Fixes: 6960b0d909cd ("fsnotify: change locking order")
Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/
Link: https://lore.kernel.org/r/20220422120327.3459282-4-amir73il@gmail.com
Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>fsnotify: Fix busy inodes during unmount</title>
<updated>2018-11-13T19:08:50Z</updated>
<author>
<name>Jan Kara</name>
</author>
<published>2018-10-17T11:07:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=778af261c53b0852ba5d9e2f45d4c03f46eddee6'/>
<id>urn:sha1:778af261c53b0852ba5d9e2f45d4c03f46eddee6</id>
<content type='text'>
commit 721fb6fbfd2132164c2e8777cc837f9b2c1794dc upstream.

Detaching of mark connector from fsnotify_put_mark() can race with
unmounting of the filesystem like:

  CPU1				CPU2
fsnotify_put_mark()
  spin_lock(&amp;conn-&gt;lock);
  ...
  inode = fsnotify_detach_connector_from_object(conn)
  spin_unlock(&amp;conn-&gt;lock);
				generic_shutdown_super()
				  fsnotify_unmount_inodes()
				    sees connector detached for inode
				      -&gt; nothing to do
				  evict_inode()
				    barfs on pending inode reference
  iput(inode);

Resulting in "Busy inodes after unmount" message and possible kernel
oops. Make fsnotify_unmount_inodes() properly wait for outstanding inode
references from detached connectors.

Note that the accounting of outstanding inode references in the
superblock can cause some cacheline contention on the counter. OTOH it
happens only during deletion of the last notification mark from an inode
(or during unlinking of watched inode) and that is not too bad. I have
measured time to create &amp; delete inotify watch 100000 times from 64
processes in parallel (each process having its own inotify group and its
own file on a shared superblock) on a 64 CPU machine. Average and
standard deviation of 15 runs look like:

	Avg		Stddev
Vanilla	9.817400	0.276165
Fixed	9.710467	0.228294

So there's no statistically significant difference.

Fixes: 6b3f05d24d35 ("fsnotify: Detach mark from object list when last reference is dropped")
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>fsnotify: fix false positive warning on inode delete</title>
<updated>2018-08-20T11:55:45Z</updated>
<author>
<name>Jan Kara</name>
</author>
<published>2018-08-20T11:55:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d3bc0fa8411c35194f99046157e2e26fe60e1d91'/>
<id>urn:sha1:d3bc0fa8411c35194f99046157e2e26fe60e1d91</id>
<content type='text'>
When inode is getting deleted and someone else holds reference to a mark
attached to the inode, we just detach the connector from the inode. In
that case fsnotify_put_mark() called from fsnotify_destroy_marks() will
decide to recalculate mask for the inode and __fsnotify_recalc_mask()
will WARN about invalid connector type:

WARNING: CPU: 1 PID: 12015 at fs/notify/mark.c:139
__fsnotify_recalc_mask+0x2d7/0x350 fs/notify/mark.c:139

Actually there's no reason to warn about detached connector in
__fsnotify_recalc_mask() so just silently skip updating the mask in such
case.

Reported-by: syzbot+c34692a51b9a6ca93540@syzkaller.appspotmail.com
Fixes: 3ac70bfcde81 ("fsnotify: add helper to get mask from connector")
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: add helper to get mask from connector</title>
<updated>2018-06-27T11:45:07Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2018-06-23T14:54:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3ac70bfcde812b1b97d8a88a832df59941fa293f'/>
<id>urn:sha1:3ac70bfcde812b1b97d8a88a832df59941fa293f</id>
<content type='text'>
Use a helper to get the mask from the object (i.e. i_fsnotify_mask)
to generalize code of add/remove inode/vfsmount mark.

Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: let connector point to an abstract object</title>
<updated>2018-06-27T11:45:05Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2018-06-23T14:54:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=36f10f55ff1d2867bfc48ed898a9cc0dc6b49dd2'/>
<id>urn:sha1:36f10f55ff1d2867bfc48ed898a9cc0dc6b49dd2</id>
<content type='text'>
Make the code to attach/detach a connector to object more generic
by letting the fsnotify connector point to an abstract fsnotify_connp_t.
Code that needs to dereference an inode or mount object now uses the
helpers fsnotify_conn_{inode,mount}.

Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: pass connp and object type to fsnotify_add_mark()</title>
<updated>2018-06-27T11:45:03Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2018-06-23T14:54:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b812a9f5896379b6cff2ac168ddb5b89037d8e78'/>
<id>urn:sha1:b812a9f5896379b6cff2ac168ddb5b89037d8e78</id>
<content type='text'>
Instead of passing inode and vfsmount arguments to fsnotify_add_mark()
and its _locked variant, pass an abstract object pointer and the object
type.

The helpers fsnotify_obj_{inode,mount} are added to get the concrete
object pointer from abstract object pointer.

Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: use typedef fsnotify_connp_t for brevity</title>
<updated>2018-06-27T11:44:59Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2018-06-23T14:54:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9b6e543450dc03635899ba56b1c39cc593694560'/>
<id>urn:sha1:9b6e543450dc03635899ba56b1c39cc593694560</id>
<content type='text'>
The object marks manipulation functions fsnotify_destroy_marks()
fsnotify_find_mark() and their helpers take an argument of type
struct fsnotify_mark_connector __rcu ** to dereference the connector
pointer. use a typedef to describe this type for brevity.

Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: generalize iteration of marks by object type</title>
<updated>2018-05-18T12:58:22Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2018-04-20T23:10:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=47d9c7cc457adc5d6d8ca966482a51459f81e852'/>
<id>urn:sha1:47d9c7cc457adc5d6d8ca966482a51459f81e852</id>
<content type='text'>
Make some code that handles marks of object types inode and vfsmount
generic, so it can handle other object types.

Introduce fsnotify_foreach_obj_type macro to iterate marks by object type
and fsnotify_iter_{should|set}_report_type macros to set/test report_mask.

This is going to be used for adding mark of another object type
(super block mark).

Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: use type id to identify connector object type</title>
<updated>2018-05-18T12:58:22Z</updated>
<author>
<name>Amir Goldstein</name>
</author>
<published>2018-04-20T23:10:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d6f7b98bc8147abd290ead82922f8d83c525fb42'/>
<id>urn:sha1:d6f7b98bc8147abd290ead82922f8d83c525fb42</id>
<content type='text'>
An fsnotify_mark_connector is referencing a single type of object
(either inode or vfsmount). Instead of storing a type mask in
connector-&gt;flags, store a single type id in connector-&gt;type to
identify the type of object.

When a connector object is detached from the object, its type is set
to FSNOTIFY_OBJ_TYPE_DETACHED and this object is not going to be
reused.

The function fsnotify_clear_marks_by_group() is the only place where
type mask was used, so use type flags instead of type id to this
function.

This change is going to be more convenient when adding a new object
type (super block).

Signed-off-by: Amir Goldstein &lt;amir73il@gmail.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
<entry>
<title>fsnotify: convert fsnotify_mark.refcnt from atomic_t to refcount_t</title>
<updated>2017-10-31T16:54:56Z</updated>
<author>
<name>Elena Reshetova</name>
</author>
<published>2017-10-20T10:26:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ab97f87325e28b7ef7717e6cb62e8da14a7176e1'/>
<id>urn:sha1:ab97f87325e28b7ef7717e6cb62e8da14a7176e1</id>
<content type='text'>
atomic_t variables are currently used to implement reference
counters with the following properties:
 - counter is initialized to 1 using atomic_set()
 - a resource is freed upon counter reaching zero
 - once counter reaches zero, its further
   increments aren't allowed
 - counter schema uses basic atomic operations
   (set, inc, inc_not_zero, dec_and_test, etc.)

Such atomic variables should be converted to a newly provided
refcount_t type and API that prevents accidental counter overflows
and underflows. This is important since overflows and underflows
can lead to use-after-free situation and be exploitable.

The variable fsnotify_mark.refcnt is used as pure reference counter.
Convert it to refcount_t and fix up the operations.

Suggested-by: Kees Cook &lt;keescook@chromium.org&gt;
Reviewed-by: David Windsor &lt;dwindsor@gmail.com&gt;
Reviewed-by: Hans Liljestrand &lt;ishkamiel@gmail.com&gt;
Signed-off-by: Elena Reshetova &lt;elena.reshetova@intel.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
</content>
</entry>
</feed>
