Kees Cook and Linus Torvalds
189f164e57
Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
...
Conversion performed via this Coccinelle script:
// SPDX-License-Identifier: GPL-2.0-only
// Options: --include-headers-for-types --all-includes --include-headers --keep-comments
virtual patch
@gfp depends on patch && !(file in "tools") && !(file in "samples")@
identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex,
kzalloc_obj,kzalloc_objs,kzalloc_flex,
kvmalloc_obj,kvmalloc_objs,kvmalloc_flex,
kvzalloc_obj,kvzalloc_objs,kvzalloc_flex};
@@
ALLOC(...
- , GFP_KERNEL
)
$ make coccicheck MODE=patch COCCI=gfp.cocci
Build and boot tested x86_64 with Fedora 42's GCC and Clang:
Linux version 6.19.0+ (user@host) (gcc (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7), GNU ld version 2.44-12.fc42) #1 SMP PREEMPT_DYNAMIC 1970-01-01
Linux version 6.19.0+ (user@host) (clang version 20.1.8 (Fedora 20.1.8-4.fc42), LLD 20.1.8) #1 SMP PREEMPT_DYNAMIC 1970-01-01
Signed-off-by: Kees Cook <kees@kernel.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2026-02-22 08:26:33 -08:00
Kees Cook
69050f8d6d
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
...
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org >
2026-02-21 01:02:28 -08:00
Jeff Layton and Christian Brauner
dfd8676efe
squashfs: add setlease file operation
...
Add the setlease file_operation pointing to generic_setlease to the
squashfs file_operations structures. A future patch will change the
default behavior to reject lease attempts with -EINVAL when there is no
setlease file operation defined. Add generic_setlease to retain the
ability to set leases on this filesystem.
Signed-off-by: Jeff Layton <jlayton@kernel.org >
Link: https://patch.msgid.link/20260108-setlease-6-20-v1-18-ea4dec9b67fa@kernel.org
Acked-by: Al Viro <viro@zeniv.linux.org.uk >
Acked-by: Christoph Hellwig <hch@lst.de >
Signed-off-by: Christian Brauner <brauner@kernel.org >
2026-01-12 10:55:47 +01:00
Phillip Lougher and Andrew Morton
dec91e7ab1
Squashfs: add SEEK_DATA/SEEK_HOLE support
...
Add support for SEEK_DATA and SEEK_HOLE lseek() whence values.
These allow much faster searches for holes and data in sparse files, which
can significantly speed up file copying, e.g.
before (GNU coreutils, Debian 13):
cp --sparse=always big-file /
took real 11m58s, user 0m5.764s, sys 11m48s
after:
real 0.047s, user 0.000s, sys 0.027s
Where big-file has a 256 GB hole followed by 47 KB of data.
Link: https://lkml.kernel.org/r/20250923220652.568416-3-phillip@squashfs.org.uk
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-09-28 11:36:14 -07:00
Matthew Wilcox (Oracle) and Andrew Morton
ca742a822a
squashfs: pass the inode to squashfs_readahead_fragment()
...
Patch series "squashfs: Remove page->mapping references".
We're close to being able to kill page->mapping. These two patches get us
a little bit closer.
This patch (of 2):
Eliminate a reference to page->mapping by passing the inode from the
caller.
Link: https://lkml.kernel.org/r/20250612143903.2849289-1-willy@infradead.org
Link: https://lkml.kernel.org/r/20250612143903.2849289-2-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Cc: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-07-09 22:57:50 -07:00
Matthew Wilcox (Oracle) and Andrew Morton
5748be3e9e
squashfs: convert squashfs_fill_page() to take a folio
...
squashfs_fill_page is only used in this file, so make it static.
Use kmap_local instead of kmap_atomic, and return a bool so that
the caller can use folio_end_read() which saves an atomic operation
over calling folio_mark_uptodate() followed by folio_unlock().
[willy@infradead.org: fix polarity of "uptodate" Thanks to Ryan for testing]
Link: https://lkml.kernel.org/r/20250110163300.3346321-2-willy@infradead.org
Link: https://lkml.kernel.org/r/20241220224634.723899-5-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Tested-by: Ryan Roberts <ryan.roberts@arm.com >
Cc: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-01-24 22:47:22 -08:00
Matthew Wilcox (Oracle) and Andrew Morton
5641371fd0
squashfs; convert squashfs_copy_cache() to take a folio
...
Remove accesses to page->index and page->mapping. Also use folio
APIs where available. This code still assumes order 0 folios.
[dan.carpenter@linaro.org: fix a NULL vs IS_ERR() bug]
Link: https://lkml.kernel.org/r/7b7f44d6-9153-4d7c-b65b-2d78febe6c7a@stanley.mountain
Link: https://lkml.kernel.org/r/20241220224634.723899-4-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org >
Cc: Phillip Lougher <phillip@squashfs.org.uk >
Cc: Dan Carpenter <dan.carpenter@linaro.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-01-24 22:47:22 -08:00
Matthew Wilcox (Oracle) and Andrew Morton
2a7aea59cf
squashfs: convert squashfs_readpage_block() to take a folio
...
Remove a few accesses to page->mapping.
Link: https://lkml.kernel.org/r/20241220224634.723899-3-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Cc: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-01-24 22:47:22 -08:00
Matthew Wilcox (Oracle) and Andrew Morton
8c1565fcf6
squashfs: pass a folio to squashfs_readpage_fragment()
...
Remove an access to page->mapping.
Link: https://lkml.kernel.org/r/20241220224634.723899-2-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Cc: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-01-24 22:47:22 -08:00
Matthew Wilcox (Oracle) and Andrew Morton
608c250167
squashfs: use a folio throughout squashfs_read_folio()
...
Use modern folio APIs where they exist and convert back to struct
page for the internal functions.
Link: https://lkml.kernel.org/r/20241220224634.723899-1-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Cc: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2025-01-24 22:47:22 -08:00
Phillip Lougher and Christian Brauner
84e0e03b30
Squashfs: Ensure all readahead pages have been used
...
In the recent work to remove page->index, a sanity check
that ensured all the readhead pages were covered by the
Squashfs data block was removed [1].
To avoid any regression, this commit adds the sanity check
back in an equivalent way. Namely the page actor will now
return error if any pages are unused after completion.
[1] https://lore.kernel.org/all/20240818235847.170468-3-phillip@squashfs.org.uk/
--
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Link: https://lore.kernel.org/r/20240822233106.121522-1-phillip@squashfs.org.uk
V3: last_page should be actor->last_page
Signed-off-by: Christian Brauner <brauner@kernel.org >
2024-08-23 13:11:36 +02:00
Phillip Lougher and Christian Brauner
fd54fa6efe
Squashfs: Rewrite and update squashfs_readahead_fragment() to not use page->index
...
The previous implementation lacked error checking (e.g. the bytes
returned by squashfs_fill_page() is not checked), and the use of
page->index could not be removed without substantially rewriting
the routine to use the page actor abstraction used elsewhere.
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Link: https://lore.kernel.org/r/20240818235847.170468-5-phillip@squashfs.org.uk
Signed-off-by: Christian Brauner <brauner@kernel.org >
2024-08-19 14:08:21 +02:00
Phillip Lougher and Christian Brauner
6f09ffb1f4
Squashfs: Update squashfs_readahead() to not use page->index
...
This commit removes references to page->index in the pages returned
from __readahead_batch(), and instead uses the 'start' variable.
This does reveal a bug in the previous code in that 'start' was
not updated every time around the loop. This is fixed in this
commit.
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Link: https://lore.kernel.org/r/20240818235847.170468-3-phillip@squashfs.org.uk
Signed-off-by: Christian Brauner <brauner@kernel.org >
2024-08-19 14:08:20 +02:00
Phillip Lougher and Christian Brauner
2258e22f05
Squashfs: Update page_actor to not use page->index
...
This commit removes an unnecessary use of page->index,
and moves the other use over to folio->index.
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Link: https://lore.kernel.org/r/20240818235847.170468-2-phillip@squashfs.org.uk
Signed-off-by: Christian Brauner <brauner@kernel.org >
2024-08-19 14:08:20 +02:00
Matthew Wilcox (Oracle) and Andrew Morton
bbf45b7e68
squashfs: remove calls to set the folio error flag
...
Nobody checks the error flag on squashfs folios, so stop setting it.
Link: https://lkml.kernel.org/r/20240420025029.2166544-24-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Tested-by: Phillip Lougher <phillip@squashfs.org.uk >
Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2024-05-08 08:41:28 -07:00
Phillip Lougher and Andrew Morton
12427de943
Squashfs: fix variable overflow triggered by sysbot
...
Sysbot reports a slab out of bounds write in squashfs_readahead().
This is ultimately caused by a file reporting an (infeasibly) large file
size (1407374883553280 bytes) with the minimum block size of 4K.
This causes variable overflow.
Link: https://lkml.kernel.org/r/20231113160901.6444-1-phillip@squashfs.org.uk
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Reported-by: syzbot+604424eb051c2f696163@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000b1fda20609ede0d1@google.com/
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2023-12-10 17:21:26 -08:00
Phillip Lougher and Andrew Morton
e11c4e088b
squashfs: fix buffer release race condition in readahead code
...
Fix a buffer release race condition, where the error value was used after
release.
Link: https://lkml.kernel.org/r/20221020223616.7571-4-phillip@squashfs.org.uk
Fixes: b09a7a036d ("squashfs: support reading fragments in readahead call")
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com >
Reported-by: Marc Miltenberger <marcmiltenberger@gmail.com >
Cc: Dimitri John Ledkov <dimitri.ledkov@canonical.com >
Cc: Hsin-Yi Wang <hsinyi@chromium.org >
Cc: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr >
Cc: Slade Watkins <srw@sladewatkins.net >
Cc: Thorsten Leemhuis <regressions@leemhuis.info >
Cc: <stable@vger.kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2022-10-28 13:37:21 -07:00
Phillip Lougher and Andrew Morton
c9199de82b
squashfs: fix extending readahead beyond end of file
...
The readahead code will try to extend readahead to the entire size of the
Squashfs data block.
But, it didn't take into account that the last block at the end of the
file may not be a whole block. In this case, the code would extend
readahead to beyond the end of the file, leaving trailing pages.
Fix this by only requesting the expected number of pages.
Link: https://lkml.kernel.org/r/20221020223616.7571-3-phillip@squashfs.org.uk
Fixes: 8fc78b6fe2 ("squashfs: implement readahead")
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com >
Reported-by: Marc Miltenberger <marcmiltenberger@gmail.com >
Cc: Dimitri John Ledkov <dimitri.ledkov@canonical.com >
Cc: Hsin-Yi Wang <hsinyi@chromium.org >
Cc: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr >
Cc: Slade Watkins <srw@sladewatkins.net >
Cc: Thorsten Leemhuis <regressions@leemhuis.info >
Cc: <stable@vger.kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2022-10-28 13:37:21 -07:00
Phillip Lougher and Andrew Morton
9ef8eb6104
squashfs: fix read regression introduced in readahead code
...
Patch series "squashfs: fix some regressions introduced in the readahead
code".
This patchset fixes 3 regressions introduced by the recent readahead code
changes. The first regression is causing "snaps" to randomly fail after a
couple of hours or days, which how the regression came to light.
This patch (of 3):
If a file isn't a whole multiple of the page size, the last page will have
trailing bytes unfilled.
There was a mistake in the readahead code which did this. In particular
it incorrectly assumed that the last page in the readahead page array
(page[nr_pages - 1]) will always contain the last page in the block, which
if we're at file end, will be the page that needs to be zero filled.
But the readahead code may not return the last page in the block, which
means it is unmapped and will be skipped by the decompressors (a temporary
buffer used).
In this case the zero filling code will zero out the wrong page, leading
to data corruption.
Fix this by by extending the "page actor" to return the last page if
present, or NULL if a temporary buffer was used.
Link: https://lkml.kernel.org/r/20221020223616.7571-1-phillip@squashfs.org.uk
Link: https://lkml.kernel.org/r/20221020223616.7571-2-phillip@squashfs.org.uk
Fixes: 8fc78b6fe2 ("squashfs: implement readahead")
Link: https://lore.kernel.org/lkml/b0c258c3-6dcf-aade-efc4-d62a8b3a1ce2@alu.unizg.hr/
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr >
Tested-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr >
Tested-by: Slade Watkins <srw@sladewatkins.net >
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com >
Reported-by: Marc Miltenberger <marcmiltenberger@gmail.com >
Cc: Dimitri John Ledkov <dimitri.ledkov@canonical.com >
Cc: Hsin-Yi Wang <hsinyi@chromium.org >
Cc: Thorsten Leemhuis <regressions@leemhuis.info >
Cc: <stable@vger.kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2022-10-28 13:37:21 -07:00
Phillip Lougher and Andrew Morton
1f13dff09f
squashfs: don't call kmalloc in decompressors
...
The decompressors may be called while in an atomic section. So move the
kmalloc() out of this path, and into the "page actor" init function.
This fixes a regression introduced by commit
f268eedddf ("squashfs: extend "page actor" to handle missing pages")
Link: https://lkml.kernel.org/r/20220822215430.15933-1-phillip@squashfs.org.uk
Fixes: f268eedddf ("squashfs: extend "page actor" to handle missing pages")
Reported-by: Chris Murphy <lists@colorremedies.com >
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Cc: <stable@vger.kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2022-08-28 14:02:45 -07:00
Linus Torvalds
eb5699ba31
Merge tag 'mm-nonmm-stable-2022-08-06-2' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
...
Pull misc updates from Andrew Morton:
"Updates to various subsystems which I help look after. lib, ocfs2,
fatfs, autofs, squashfs, procfs, etc. A relatively small amount of
material this time"
* tag 'mm-nonmm-stable-2022-08-06-2' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (72 commits)
scripts/gdb: ensure the absolute path is generated on initial source
MAINTAINERS: kunit: add David Gow as a maintainer of KUnit
mailmap: add linux.dev alias for Brendan Higgins
mailmap: update Kirill's email
profile: setup_profiling_timer() is moslty not implemented
ocfs2: fix a typo in a comment
ocfs2: use the bitmap API to simplify code
ocfs2: remove some useless functions
lib/mpi: fix typo 'the the' in comment
proc: add some (hopefully) insightful comments
bdi: remove enum wb_congested_state
kernel/hung_task: fix address space of proc_dohung_task_timeout_secs
lib/lzo/lzo1x_compress.c: replace ternary operator with min() and min_t()
squashfs: support reading fragments in readahead call
squashfs: implement readahead
squashfs: always build "file direct" version of page actor
Revert "squashfs: provide backing_dev_info in order to disable read-ahead"
fs/ocfs2: Fix spelling typo in comment
ia64: old_rr4 added under CONFIG_HUGETLB_PAGE
proc: fix test for "vsyscall=xonly" boot option
...
2022-08-07 10:03:24 -07:00
Matthew Wilcox (Oracle)
31e748e4b1
squashfs: Return the actual error from squashfs_read_folio()
...
Since we actually know what error happened, we can report it instead
of having the generic code return -EIO for pages that were unlocked
without being marked uptodate. Also remove a test of PageError since
we have the return value at this point.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org >
2022-08-02 12:34:02 -04:00
Phillip Lougher and akpm
b09a7a036d
squashfs: support reading fragments in readahead call
...
Add a function which can be used to read fragments in the readahead call.
This function is necessary because filesystems built with the -tailends
(or -always-use-fragments) option may have fragments present which cannot
be currently handled.
Link: https://lkml.kernel.org/r/20220617083810.337573-5-hsinyi@chromium.org
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk >
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org >
Cc: Hou Tao <houtao1@huawei.com >
Cc: kernel test robot <lkp@intel.com >
Cc: Marek Szyprowski <m.szyprowski@samsung.com >
Cc: Matthew Wilcox <willy@infradead.org >
Cc: Miao Xie <miaoxie@huawei.com >
Cc: Xiongwei Song <Xiongwei.Song@windriver.com >
Cc: Zhang Yi <yi.zhang@huawei.com >
Cc: Zheng Liang <zhengliang6@huawei.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2022-07-29 18:12:34 -07:00
Hsin-Yi Wang and akpm
8fc78b6fe2
squashfs: implement readahead
...
Implement readahead callback for squashfs. It will read datablocks which
cover pages in readahead request. For a few cases it will not mark page
as uptodate, including:
- file end is 0.
- zero filled blocks.
- current batch of pages isn't in the same datablock.
- decompressor error.
Otherwise pages will be marked as uptodate. The unhandled pages will be
updated by readpage later.
Link: https://lkml.kernel.org/r/20220617083810.337573-4-hsinyi@chromium.org
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org >
Suggested-by: Matthew Wilcox <willy@infradead.org >
Reported-by: Matthew Wilcox <willy@infradead.org >
Reported-by: Phillip Lougher <phillip@squashfs.org.uk >
Reported-by: Xiongwei Song <Xiongwei.Song@windriver.com >
Reported-by: Andrew Morton <akpm@linux-foundation.org >
Cc: Hou Tao <houtao1@huawei.com >
Cc: kernel test robot <lkp@intel.com >
Cc: Marek Szyprowski <m.szyprowski@samsung.com >
Cc: Miao Xie <miaoxie@huawei.com >
Cc: Zhang Yi <yi.zhang@huawei.com >
Cc: Zheng Liang <zhengliang6@huawei.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
2022-07-29 18:12:34 -07:00
Matthew Wilcox (Oracle)
124cfc154f
squashfs: Convert squashfs to read_folio
...
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) <willy@infradead.org >
2022-05-09 16:21:46 -04:00