<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/jffs2/file.c, branch linux-6.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2023-02-02T20:13:32Z</updated>
<entry>
<title>jffs2: correct logic when creating a hole in jffs2_write_begin</title>
<updated>2023-02-02T20:13:32Z</updated>
<author>
<name>Yifei Liu</name>
</author>
<published>2022-08-03T15:53:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=23892d383bee15b64f5463bd7195615734bb2415'/>
<id>urn:sha1:23892d383bee15b64f5463bd7195615734bb2415</id>
<content type='text'>
Bug description and fix:

1. Write data to a file, say all 1s from offset 0 to 16.

2. Truncate the file to a smaller size, say 8 bytes.

3. Write new bytes (say 2s) from an offset past the original size of the
file, say at offset 20, for 4 bytes.  This is supposed to create a "hole"
in the file, meaning that the bytes from offset 8 (where it was truncated
above) up to the new write at offset 20, should all be 0s (zeros).

4. Flush all caches using "echo 3 &gt; /proc/sys/vm/drop_caches" (or unmount
and remount) the f/s.

5. Check the content of the file.  It is wrong.  The 1s that used to be
between bytes 9 and 16, before the truncation, have REAPPEARED (they should
be 0s).

We wrote a script and helper C program to reproduce the bug
(reproduce_jffs2_write_begin_issue.sh, write_file.c, and Makefile).  We can
make them available to anyone.

The above example is shown when writing a small file within the same first
page.  But the bug happens for larger files, as long as steps 1, 2, and 3
above all happen within the same page.

The problem was traced to the jffs2_write_begin code, where it goes into an
'if' statement intended to handle writes past the current EOF (i.e., writes
that may create a hole).  The code computes a 'pageofs' that is the floor
of the write position (pos), aligned to the page size boundary.  In other
words, 'pageofs' will never be larger than 'pos'.  The code then sets the
internal jffs2_raw_inode-&gt;isize to the size of max(current inode size,
pageofs) but that is wrong: the new file size should be the 'pos', which is
larger than both the current inode size and pageofs.

Similarly, the code incorrectly sets the internal jffs2_raw_inode-&gt;dsize to
the difference between the pageofs minus current inode size; instead it
should be the current pos minus the current inode size.  Finally,
inode-&gt;i_size was also set incorrectly.

The patch below fixes this bug.  The bug was discovered using a new tool
for finding f/s bugs using model checking, called MCFS (Model Checking File
Systems).

Signed-off-by: Yifei Liu &lt;yifeliu@cs.stonybrook.edu&gt;
Signed-off-by: Erez Zadok &lt;ezk@cs.stonybrook.edu&gt;
Signed-off-by: Manish Adkar &lt;madkar@cs.stonybrook.edu&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
</content>
</entry>
<entry>
<title>fs: rename current get acl method</title>
<updated>2022-10-20T08:13:27Z</updated>
<author>
<name>Christian Brauner</name>
</author>
<published>2022-09-22T15:17:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cac2f8b8d8b50ef32b3e34f6dcbbf08937e4f616'/>
<id>urn:sha1:cac2f8b8d8b50ef32b3e34f6dcbbf08937e4f616</id>
<content type='text'>
The current way of setting and getting posix acls through the generic
xattr interface is error prone and type unsafe. The vfs needs to
interpret and fixup posix acls before storing or reporting it to
userspace. Various hacks exist to make this work. The code is hard to
understand and difficult to maintain in it's current form. Instead of
making this work by hacking posix acls through xattr handlers we are
building a dedicated posix acl api around the get and set inode
operations. This removes a lot of hackiness and makes the codepaths
easier to maintain. A lot of background can be found in [1].

The current inode operation for getting posix acls takes an inode
argument but various filesystems (e.g., 9p, cifs, overlayfs) need access
to the dentry. In contrast to the -&gt;set_acl() inode operation we cannot
simply extend -&gt;get_acl() to take a dentry argument. The -&gt;get_acl()
inode operation is called from:

acl_permission_check()
-&gt; check_acl()
   -&gt; get_acl()

which is part of generic_permission() which in turn is part of
inode_permission(). Both generic_permission() and inode_permission() are
called in the -&gt;permission() handler of various filesystems (e.g.,
overlayfs). So simply passing a dentry argument to -&gt;get_acl() would
amount to also having to pass a dentry argument to -&gt;permission(). We
should avoid this unnecessary change.

So instead of extending the existing inode operation rename it from
-&gt;get_acl() to -&gt;get_inode_acl() and add a -&gt;get_acl() method later that
passes a dentry argument and which filesystems that need access to the
dentry can implement instead of -&gt;get_inode_acl(). Filesystems like cifs
which allow setting and getting posix acls but not using them for
permission checking during lookup can simply not implement
-&gt;get_inode_acl().

This is intended to be a non-functional change.

Link: https://lore.kernel.org/all/20220801145520.1532837-1-brauner@kernel.org [1]
Suggested-by/Inspired-by: Christoph Hellwig &lt;hch@lst.de&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Christian Brauner (Microsoft) &lt;brauner@kernel.org&gt;
</content>
</entry>
<entry>
<title>fs: Change the type of filler_t</title>
<updated>2022-05-09T20:36:48Z</updated>
<author>
<name>Matthew Wilcox (Oracle)</name>
</author>
<published>2022-05-02T01:39:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e9b5b23e957ef9260fec811d8d8081125889308a'/>
<id>urn:sha1:e9b5b23e957ef9260fec811d8d8081125889308a</id>
<content type='text'>
By making filler_t the same as read_folio, we can use the same function
for both in gfs2.  We can push the use of folios down one more level
in jffs2 and nfs.  We also increase type safety for future users of the
various read_cache_page() family of functions by forcing the parameter
to be a pointer to struct file (or NULL).

Signed-off-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Reviewed-by: Andreas Gruenbacher &lt;agruenba@redhat.com&gt;
</content>
</entry>
<entry>
<title>jffs2: Pass the file pointer to jffs2_do_readpage_unlock()</title>
<updated>2022-05-09T20:28:41Z</updated>
<author>
<name>Matthew Wilcox (Oracle)</name>
</author>
<published>2022-05-01T23:39:03Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2294f9b8793d02b265423207e55ce5b26d8960cd'/>
<id>urn:sha1:2294f9b8793d02b265423207e55ce5b26d8960cd</id>
<content type='text'>
In preparation for unifying the read_cache_page() and read_folio()
implementations, make jffs2_do_readpage_unlock() get the inode
from the page instead of passing it in from read_cache_page().

Signed-off-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
</content>
</entry>
<entry>
<title>jffs2: Convert jffs2 to read_folio</title>
<updated>2022-05-09T20:21:45Z</updated>
<author>
<name>Matthew Wilcox (Oracle)</name>
</author>
<published>2022-04-29T15:12:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=75a47803b8e118a2af4f9498acd40d9b4d4b0dff'/>
<id>urn:sha1:75a47803b8e118a2af4f9498acd40d9b4d4b0dff</id>
<content type='text'>
This is a "weak" conversion which converts straight back to using pages.
A full conversion should be performed at some point, hopefully by
someone familiar with the filesystem.

Signed-off-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
</content>
</entry>
<entry>
<title>fs: Remove flags parameter from aops-&gt;write_begin</title>
<updated>2022-05-08T18:28:19Z</updated>
<author>
<name>Matthew Wilcox (Oracle)</name>
</author>
<published>2022-02-22T19:31:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9d6b0cd7579844761ed68926eb3073bab1dca87b'/>
<id>urn:sha1:9d6b0cd7579844761ed68926eb3073bab1dca87b</id>
<content type='text'>
There are no more aop flags left, so remove the parameter.

Signed-off-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
</content>
</entry>
<entry>
<title>fs: Remove aop flags parameter from grab_cache_page_write_begin()</title>
<updated>2022-05-08T18:28:19Z</updated>
<author>
<name>Matthew Wilcox (Oracle)</name>
</author>
<published>2022-02-22T16:25:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b7446e7cf15f0926866c8e5de90ab278998bf8c8'/>
<id>urn:sha1:b7446e7cf15f0926866c8e5de90ab278998bf8c8</id>
<content type='text'>
There are no more aop flags left, so remove the parameter.

Signed-off-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
</content>
</entry>
<entry>
<title>jffs2: GC deadlock reading a page that is used in jffs2_write_begin()</title>
<updated>2021-12-23T21:33:41Z</updated>
<author>
<name>Kyeong Yoo</name>
</author>
<published>2017-07-04T04:22:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=aa39cc675799bc92da153af9a13d6f969c348e82'/>
<id>urn:sha1:aa39cc675799bc92da153af9a13d6f969c348e82</id>
<content type='text'>
GC task can deadlock in read_cache_page() because it may attempt
to release a page that is actually allocated by another task in
jffs2_write_begin().
The reason is that in jffs2_write_begin() there is a small window
a cache page is allocated for use but not set Uptodate yet.

This ends up with a deadlock between two tasks:
1) A task (e.g. file copy)
   - jffs2_write_begin() locks a cache page
   - jffs2_write_end() tries to lock "alloc_sem" from
	 jffs2_reserve_space() &lt;-- STUCK
2) GC task (jffs2_gcd_mtd3)
   - jffs2_garbage_collect_pass() locks "alloc_sem"
   - try to lock the same cache page in read_cache_page() &lt;-- STUCK

So to avoid this deadlock, hold "alloc_sem" in jffs2_write_begin()
while reading data in a cache page.

Signed-off-by: Kyeong Yoo &lt;kyeong.yoo@alliedtelesis.co.nz&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
</content>
</entry>
<entry>
<title>jffs2: Hook up splice_write callback</title>
<updated>2021-04-15T20:01:14Z</updated>
<author>
<name>Joel Stanley</name>
</author>
<published>2021-03-30T13:45:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=42984af09afc414d540fcc8247f42894b0378a91'/>
<id>urn:sha1:42984af09afc414d540fcc8247f42894b0378a91</id>
<content type='text'>
overlayfs using jffs2 as the upper filesystem would fail in some cases
since moving to v5.10. The test case used was to run 'touch' on a file
that exists in the lower fs, causing the modification time to be
updated. It returns EINVAL when the bug is triggered.

A bisection showed this was introduced in v5.9-rc1, with commit
36e2c7421f02 ("fs: don't allow splice read/write without explicit ops").
Reverting that commit restores the expected behaviour.

Some digging showed that this was due to jffs2 lacking an implementation
of splice_write. (For unknown reasons the warn_unsupported that should
trigger was not displaying any output).

Adding this patch resolved the issue and the test now passes.

Cc: stable@vger.kernel.org
Fixes: 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")
Signed-off-by: Joel Stanley &lt;joel@jms.id.au&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Tested-by: Lei YU &lt;yulei.sh@bytedance.com&gt;
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
</content>
</entry>
<entry>
<title>jffs2: pass the correct prototype to read_cache_page</title>
<updated>2019-07-12T18:05:43Z</updated>
<author>
<name>Christoph Hellwig</name>
</author>
<published>2019-07-12T03:55:23Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=265de8ce3d5b3c70644a1a45457580bb07548b56'/>
<id>urn:sha1:265de8ce3d5b3c70644a1a45457580bb07548b56</id>
<content type='text'>
Fix the callback jffs2 passes to read_cache_page to actually have the
proper type expected.  Casting around function pointers can easily hide
typing bugs, and defeats control flow protection.

Link: http://lkml.kernel.org/r/20190520055731.24538-4-hch@lst.de
Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Nick Desaulniers &lt;ndesaulniers@google.com&gt;
Cc: Sami Tolvanen &lt;samitolvanen@google.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
