Merge tag 'vfs-7.4-rc3.fixes.2' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull more vfs fixes from Christian Brauner:

 - inode: Let the shrinker reclaim inodes with I_METADATA_WRITEBACK like
   any other clean inode and have evict() write out what the bit tracks
   unless the inode is being deleted.

   Since v7.3 ext2, ext4 without a journal, fat, udf and minix set
   I_METADATA_WRITEBACK when they copy an inode into its buffer and only
   fsync() and friends clear it again. inode_lru_isolate() took such
   inodes off the LRU expecting something to put them back once the bit
   was gone but nothing ever did. So they couldn't be reclaimed until
   something fsynced them or the filesystem was unmounted.

   On ext4 without a journal an atime update was enough to pin an inode,
   and creating 60000 small files in a memory cgroup limited to 96M got
   the task OOM killed after about 43000 of them. Now all 60000 get
   created.

 - dcache:

     - Give d_set_mounted() a seqlock of its own that d_invalidate()
       waits on after unhashing the dentry.

       Since v6.17 d_set_mounted() doesn't bump the seqcount of
       rename_lock anymore, so a mount racing d_invalidate() could end
       up below the unhashed directory. Nobody can reach it there and it
       pins the subtree until the mount namespace goes away. With a FUSE
       directory 3000 levels deep 151 of 200 bind mounts racing
       FUSE_NOTIFY_INVAL_ENTRY ended up there.

     - Only take busy secondary roots off ->s_roots in do_one_tree() so
       that umount waits for a racing eviction of an idle one. Since
       v7.3 it didn't, which ended in busy inodes after unmount and an
       iput() on a dead superblock.

     - Make a disconnected dentry a secondary root when the mount on it
       goes away so that umount finds it and waits for its eviction.
       With CAP_DAC_READ_SEARCH such a dentry can be mounted on via
       open_by_handle_at() and move_mount() and umount racing its
       eviction ended the same way.

 - splice:

     - Remove pipe buffer stealing as you and David suggested.

       fuse and virtio_console were the only users of ->try_steal() and
       now always copy, as they already did when a steal failed.
       Stealing took page cache folios out of their files and turned
       pages into page cache folios and back. SPLICE_F_GIFT and
       SPLICE_F_MOVE are still accepted and fuse still advertises
       FUSE_SPLICE_MOVE so servers that ask for it mount as before.

     - Clamp a ->write_iter() result that is larger than the iterator in
       iter_file_splice_write() instead of only warning about it.
       Otherwise the pipe releases buffers past its head.

 - ns:

     -Allocate the namespace id before calling the namespace_init LSM
      hook that was added this merge window. Landlock now logs the
      allocated id instead of zero when it denies the creation of a
      namespace.

     -Don't mark the arguments of the namespace_init and namespace_free
      hooks as trusted for bpf LSM programs. Both see namespaces that
      are only partially set up or on their way out.

 - proc: Don't let proc_sys_call_handler() report more bytes written
   than it was passed when a cgroup/sysctl bpf program replaced the
   value with a longer one. A splice() into the sysctl file then walked
   past the pipe head.

 - coda: Pass the append state of each write on to the container file
   with RWF_APPEND or RWF_NOAPPEND. coda_open() sets O_APPEND on the
   container file after its iocb flags were cached, so an O_APPEND write
   overwrote existing data instead of appending.

 - adfs: Reject big directory entries in adfs_fplus_getnext() whose name
   doesn't fit into the name buffer. A crafted image overflowed it on
   the stack.

* tag 'vfs-7.4-rc3.fixes.2' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (28 commits)
  nstree: drop ns_tree_add_raw()
  ns: allocate the namespace id before the namespace_init hook
  bpf: don't mark namespace_init and namespace_free arguments as trusted
  splice: replace nosteal_pipe_buf_ops with default_pipe_buf_ops
  splice: remove pipe buffer stealing
  fuse: don't move pipe buffers into the page cache
  virtio_console: copy pipe buffers in splice_write()
  fs/adfs: bound directory entry name length in adfs_fplus_getnext()
  dcache: let umount find a disconnected ex-mountpoint
  dcache: wait for a racing eviction of a secondary root
  dcache: let d_invalidate() wait for a d_set_mounted() in flight
  fat: drop mmb_sync() from fat_evict_inode()
  udf: drop mmb_sync() from udf_evict_inode()
  minix: drop mmb_sync() from minix_evict_inode()
  ext4: drop mmb_sync() from ext4_evict_inode()
  ext2: drop mmb_sync() from ext2_evict_inode()
  fs: don't strand I_METADATA_WRITEBACK inodes outside the LRU
  fs: set I_METADATA_WRITEBACK in mmb_mark_buffer_dirty()
  udf: don't allocate the inode block in udf_sync_inode_metadata()
  minix: don't read the inode block in minix_sync_inode_metadata()
  ...
This commit is contained in:
Linus Torvalds
2026-11-11 16:48:56 -08:00
38 changed files with 239 additions and 508 deletions
+3 -2
View File
@@ -73,8 +73,9 @@ AUDIT_LANDLOCK_ACCESS
:manpage:`open_tree(2)`, or :manpage:`fsmount(2)`, or joining via
:manpage:`setns(2)`);
``namespace_type`` indicates the type (hex ``CLONE_NEW*`` bitmask),
and ``namespace_id`` identifies the target namespace for
:manpage:`setns(2)` operations (zero for creation)
and ``namespace_id`` identifies the target namespace (for a denied
creation, the namespace never becomes reachable so its ID is not
directly visible from user space)
**capability.*** - Capability restrictions (ABI 12+):
- capability.use - Capability use was denied;
+3 -2
View File
@@ -187,8 +187,9 @@ therefore appears as zero while still advancing the ruleset version, and adding
a member already present still emits an event.
``landlock_deny_permission_namespace`` reports the denied raw
``CLONE_NEW*`` value. ``namespace_id`` is zero for namespace creation and is
the exact target namespace ID for :manpage:`setns(2)`.
``CLONE_NEW*`` value. ``namespace_id`` is the exact target namespace ID. For
a denied namespace creation, the namespace never becomes reachable so its ID
is not directly visible from user space.
``landlock_deny_permission_capability`` reports the denied ``CAP_*`` number.
Like every denial event, both include the denying domain, ``same_exec``, and
``logged``.
+14 -25
View File
@@ -891,45 +891,34 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
{
struct sg_list *sgl = sd->u.data;
unsigned int offset, len;
struct page *page;
char *src;
if (sgl->n == sgl->size)
return 0;
/* Try lock this page */
if (pipe_buf_try_steal(pipe, buf)) {
/* Get reference and unlock page for moving */
get_page(buf->page);
unlock_page(buf->page);
page = alloc_page(GFP_KERNEL);
if (!page)
return -ENOMEM;
len = min(buf->len, sd->len);
sg_set_page(&(sgl->sg[sgl->n]), buf->page, len, buf->offset);
} else {
/* Failback to copying a page */
struct page *page = alloc_page(GFP_KERNEL);
char *src;
offset = sd->pos & ~PAGE_MASK;
if (!page)
return -ENOMEM;
len = sd->len;
if (len + offset > PAGE_SIZE)
len = PAGE_SIZE - offset;
offset = sd->pos & ~PAGE_MASK;
src = kmap_local_page(buf->page);
memcpy(page_address(page) + offset, src + buf->offset, len);
kunmap_local(src);
len = sd->len;
if (len + offset > PAGE_SIZE)
len = PAGE_SIZE - offset;
src = kmap_local_page(buf->page);
memcpy(page_address(page) + offset, src + buf->offset, len);
kunmap_local(src);
sg_set_page(&(sgl->sg[sgl->n]), page, len, offset);
}
sg_set_page(&sgl->sg[sgl->n], page, len, offset);
sgl->n++;
sgl->len += len;
return len;
}
/* Faster zero-copy write by splicing */
/* Write by splicing, copying the data from the pipe */
static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,
struct file *filp, loff_t *ppos,
size_t len, unsigned int flags)
+2
View File
@@ -192,6 +192,8 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
obj->indaddr = le32_to_cpu(bde.bigdirindaddr);
obj->attr = le32_to_cpu(bde.bigdirattr);
obj->name_len = le32_to_cpu(bde.bigdirobnamelen);
if (obj->name_len > ADFS_MAX_NAME_LEN - 4) /* leave room for ,xyz suffix */
return -EIO;
offset = adfs_fplus_offset(h, le32_to_cpu(h->bigdirentries));
offset += le32_to_cpu(bde.bigdirobnameptr);
+14 -2
View File
@@ -621,12 +621,15 @@ void write_boundary_block(struct block_device *bdev,
* @bh: The buffer to mark dirty.
* @mmb: The list of buffers to add the buffer to.
*
* Mark the buffer dirty and add it to the list if it is not already on
* a list.
* Mark the buffer dirty, add it to the list if it is not already on a list
* and set I_METADATA_WRITEBACK on the inode so that fsync() and eviction
* write it out.
*/
void mmb_mark_buffer_dirty(struct buffer_head *bh,
struct mapping_metadata_bhs *mmb)
{
struct inode *inode = mmb->mapping->host;
mark_buffer_dirty(bh);
if (!bh->b_mmb) {
spin_lock(&mmb->lock);
@@ -641,6 +644,15 @@ void mmb_mark_buffer_dirty(struct buffer_head *bh,
list_move_tail(&bh->b_assoc_buffers, &mmb->list);
spin_unlock(&mmb->lock);
}
/*
* The inode itself may never have been dirtied, so attach it to a wb
* before setting the bit or writeback_single_inode() has nothing to
* lock when evict() syncs it.
*/
spin_lock(&inode->i_lock);
inode_attach_wb(inode, NULL);
inode_state_set(inode, I_METADATA_WRITEBACK);
spin_unlock(&inode->i_lock);
}
EXPORT_SYMBOL(mmb_mark_buffer_dirty);
+2 -1
View File
@@ -71,6 +71,7 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
struct file *host_file = cfi->cfi_container;
loff_t ki_pos = iocb->ki_pos;
size_t count = iov_iter_count(to);
rwf_t flags = (iocb->ki_flags & IOCB_APPEND) ? RWF_APPEND : RWF_NOAPPEND;
ssize_t ret;
ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
@@ -80,7 +81,7 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
goto finish_write;
inode_lock(coda_inode);
ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0);
ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, flags);
coda_inode->i_size = file_inode(host_file)->i_size;
coda_inode->i_blocks = (coda_inode->i_size + 511) >> 9;
inode_set_mtime_to_ts(coda_inode, inode_set_ctime_current(coda_inode));
+36 -8
View File
@@ -46,7 +46,8 @@
* dcache_hash_bucket lock protects:
* - the dcache hash table
* s_roots_lock protects:
* - the s_roots list (see __d_move()/dentry_unlist()/d_obtain_root())
* - the s_roots list (see __d_move()/dentry_unlist()/d_obtain_root()/
* dput_to_list())
* dentry->d_sb->s_dentry_lru_lock protects:
* - the dcache lru lists and counters
* d_lock protects:
@@ -1118,7 +1119,18 @@ void dput_to_list(struct dentry *dentry, struct list_head *list)
{
if (likely(fast_dput(dentry)))
return;
__move_to_shrink_list(dentry, list);
/*
* The list owner need not pin the superblock, so make a disconnected
* root a secondary one for shrink_dcache_for_umount() to find.
*/
if (__move_to_shrink_list(dentry, list) &&
unlikely(IS_ROOT(dentry) && hlist_unhashed(&dentry->d_sib))) {
struct super_block *sb = dentry->d_sb;
spin_lock(&sb->s_roots_lock);
hlist_add_head(&dentry->d_sib, &sb->s_roots);
spin_unlock(&sb->s_roots_lock);
}
spin_unlock(&dentry->d_lock);
}
@@ -1606,21 +1618,25 @@ int path_has_submounts(const struct path *parent)
}
EXPORT_SYMBOL(path_has_submounts);
/* odd while d_set_mounted() runs, d_invalidate() waits on it */
static __cacheline_aligned_in_smp DEFINE_SEQLOCK(d_set_mounted_lock);
/*
* Called by mount code to set a mountpoint and check if the mountpoint is
* reachable (e.g. NFS can unhash a directory dentry and then the complete
* subtree can become unreachable).
*
* Only one of d_invalidate() and d_set_mounted() must succeed. For
* this reason take rename_lock and d_lock on dentry and ancestors.
* Likewise for dont_mount() which marks a dentry that is being removed
* under d_lock.
* this reason take rename_lock, d_set_mounted_lock and d_lock on dentry
* and ancestors. Likewise for dont_mount() which marks a dentry that
* is being removed under d_lock.
*/
int d_set_mounted(struct dentry *dentry)
{
struct dentry *p;
int ret = -ENOENT;
read_seqlock_excl(&rename_lock);
write_seqlock(&d_set_mounted_lock);
for (p = dentry->d_parent; !IS_ROOT(p); p = p->d_parent) {
/* Need exclusion wrt. d_invalidate() */
spin_lock(&p->d_lock);
@@ -1638,8 +1654,9 @@ int d_set_mounted(struct dentry *dentry)
ret = 0;
}
}
spin_unlock(&dentry->d_lock);
spin_unlock(&dentry->d_lock);
out:
write_sequnlock(&d_set_mounted_lock);
read_sequnlock_excl(&rename_lock);
return ret;
}
@@ -1828,8 +1845,13 @@ static void do_one_tree(struct dentry *dentry)
d_walk(dentry, dentry, umount_check);
spin_lock(&dentry->d_lock);
__d_drop(dentry);
/* A busy root survives the dput() below so don't leave it on ->s_roots. */
if (unlikely(!hlist_unhashed(&dentry->d_sib)))
/*
* A busy root survives the dput() below so don't leave it on ->s_roots.
* An idle one stays until dentry_unlist() so that umount can wait for
* a racing eviction, see lock_for_kill().
*/
if (unlikely(dentry->d_lockref.count > 1 &&
!hlist_unhashed(&dentry->d_sib)))
unlink_secondary_root(dentry);
spin_unlock(&dentry->d_lock);
dput(dentry);
@@ -1892,6 +1914,7 @@ static enum d_walk_ret find_submount(void *_data, struct dentry *dentry)
void d_invalidate(struct dentry *dentry)
{
bool had_submounts = false;
unsigned seq;
spin_lock(&dentry->d_lock);
if (d_unhashed(dentry)) {
spin_unlock(&dentry->d_lock);
@@ -1904,6 +1927,11 @@ void d_invalidate(struct dentry *dentry)
if (!dentry->d_inode)
return;
/* wait for a d_set_mounted() that saw us hashed to set its flag */
do {
seq = read_seqbegin(&d_set_mounted_lock);
} while (read_seqretry(&d_set_mounted_lock, seq));
shrink_dcache_parent(dentry);
for (;;) {
struct dentry *victim = NULL;
+38 -25
View File
@@ -93,8 +93,6 @@ void ext2_evict_inode(struct inode * inode)
if (inode->i_blocks)
ext2_truncate_blocks(inode, 0);
ext2_xattr_delete_inode(inode);
} else {
mmb_sync(&EXT2_I(inode)->i_metadata_bhs);
}
mmb_invalidate(&EXT2_I(inode)->i_metadata_bhs);
clear_inode(inode);
@@ -1266,46 +1264,59 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)
return 0;
}
static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino,
struct buffer_head **p)
/*
* Find the inode table block that holds inode @ino and the offset of the
* inode in that block.
*/
static int ext2_inode_block(struct super_block *sb, ino_t ino,
unsigned long *block, unsigned long *offset)
{
struct buffer_head * bh;
unsigned long block_group;
unsigned long block;
unsigned long offset;
struct ext2_group_desc * gdp;
*p = NULL;
if ((ino != EXT2_ROOT_INO && ino < EXT2_FIRST_INO(sb)) ||
ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count))
goto Einval;
ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count)) {
ext2_error(sb, __func__, "bad inode number: %lu",
(unsigned long) ino);
return -EINVAL;
}
block_group = (ino - 1) / EXT2_INODES_PER_GROUP(sb);
gdp = ext2_get_group_desc(sb, block_group, NULL);
if (!gdp)
goto Egdp;
return -EIO;
/*
* Figure out the offset within the block group inode table
*/
offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb);
block = le32_to_cpu(gdp->bg_inode_table) +
(offset >> EXT2_BLOCK_SIZE_BITS(sb));
*offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb);
*block = le32_to_cpu(gdp->bg_inode_table) +
(*offset >> EXT2_BLOCK_SIZE_BITS(sb));
*offset &= (EXT2_BLOCK_SIZE(sb) - 1);
return 0;
}
static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino,
struct buffer_head **p)
{
struct buffer_head *bh;
unsigned long block;
unsigned long offset;
int err;
*p = NULL;
err = ext2_inode_block(sb, ino, &block, &offset);
if (err)
return ERR_PTR(err);
if (!(bh = sb_bread(sb, block)))
goto Eio;
*p = bh;
offset &= (EXT2_BLOCK_SIZE(sb) - 1);
return (struct ext2_inode *) (bh->b_data + offset);
Einval:
ext2_error(sb, "ext2_get_inode", "bad inode number: %lu",
(unsigned long) ino);
return ERR_PTR(-EINVAL);
Eio:
ext2_error(sb, "ext2_get_inode",
"unable to read inode block - inode=%lu, block=%lu",
(unsigned long) ino, block);
Egdp:
return ERR_PTR(-EIO);
}
@@ -1567,19 +1578,22 @@ int ext2_write_inode(struct inode *inode, struct writeback_control *wbc)
int ext2_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc)
{
struct buffer_head *bh;
struct ext2_inode *raw_inode = ext2_get_inode(inode->i_sb, inode->i_ino,
&bh);
unsigned long block, offset;
int err = 0;
if (IS_ERR(raw_inode))
if (ext2_inode_block(inode->i_sb, inode->i_ino, &block, &offset))
return -EIO;
err = mmb_sync(&EXT2_I(inode)->i_metadata_bhs);
if (err) {
ext2_error(inode->i_sb, __func__,
"Error syncing inode metadata ino=%lu\n",
(unsigned long)inode->i_ino);
goto out;
return err;
}
/* A block that isn't cached is neither dirty nor under writeback. */
bh = sb_find_get_block_nonatomic(inode->i_sb, block);
if (!bh)
return 0;
sync_dirty_buffer(bh);
if (buffer_write_io_error(bh)) {
ext2_error(inode->i_sb, __func__,
@@ -1587,7 +1601,6 @@ int ext2_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc)
(unsigned long)inode->i_ino);
err = -EIO;
}
out:
brelse(bh);
return err;
}
+10 -12
View File
@@ -250,8 +250,6 @@ void ext4_evict_inode(struct inode *inode)
if (EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)
ext4_evict_ea_inode(inode);
if (inode->i_nlink) {
struct mapping_metadata_bhs *mmb;
/*
* If there's dirty page will lead to data loss, user
* could see stale data.
@@ -261,9 +259,6 @@ void ext4_evict_inode(struct inode *inode)
ext4_warning_inode(inode, "data will be lost");
truncate_inode_pages_final(&inode->i_data);
mmb = ext4_i_metadata_bhs(inode);
if (mmb)
mmb_sync(mmb);
goto no_delete;
}
@@ -5852,7 +5847,8 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
/*
* ext4_get_inode_loc_noio() is a best-effort variant of ext4_get_inode_loc().
* It looks up the inode table block in the buffer cache and returns -EAGAIN if
* the block is not present or not uptodate, without starting any I/O.
* the block is not present or not uptodate, without starting any I/O. It may
* sleep on the folio lock of the block.
*/
int ext4_get_inode_loc_noio(struct inode *inode, struct ext4_iloc *iloc)
{
@@ -5888,7 +5884,7 @@ int ext4_get_inode_loc_noio(struct inode *inode, struct ext4_iloc *iloc)
}
block += inode_offset / inodes_per_block;
bh = sb_find_get_block(sb, block);
bh = sb_find_get_block_nonatomic(sb, block);
if (!bh)
return -EAGAIN;
if (!ext4_buffer_uptodate(bh)) {
@@ -6796,22 +6792,24 @@ int ext4_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc)
if (WARN_ON_ONCE(EXT4_SB(inode->i_sb)->s_journal))
return -EFSCORRUPTED;
err = __ext4_get_inode_loc_noinmem(inode, &iloc);
if (err)
return err;
mmb = READ_ONCE(EXT4_I(inode)->i_metadata_bhs);
if (mmb) {
err = mmb_sync(mmb);
if (err)
goto out;
return err;
}
/* A block that isn't cached is neither dirty nor under writeback. */
err = ext4_get_inode_loc_noio(inode, &iloc);
if (err == -EAGAIN)
return 0;
if (err)
return err;
sync_dirty_buffer(iloc.bh);
if (buffer_write_io_error(iloc.bh)) {
ext4_error_inode_block(inode, iloc.bh->b_blocknr, EIO,
"IO error syncing inode");
err = -EIO;
}
out:
brelse(iloc.bh);
return err;
}
-1
View File
@@ -695,7 +695,6 @@ static void fat_evict_inode(struct inode *inode)
inode->i_size = 0;
fat_truncate_blocks(inode, 0);
} else {
mmb_sync(&MSDOS_I(inode)->i_metadata_bhs);
fat_free_eofblocks(inode);
}
-1
View File
@@ -36,7 +36,6 @@ struct fuse_args {
bool user_pages:1;
bool out_argvar:1;
bool page_zeroing:1;
bool page_replace:1;
bool may_block:1;
bool is_ext:1;
bool is_pinned:1;
+4 -142
View File
@@ -1099,128 +1099,6 @@ static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size)
return ncpy;
}
static int fuse_check_folio(struct folio *folio)
{
if (folio_mapped(folio) ||
folio->mapping != NULL ||
(folio->flags.f & PAGE_FLAGS_CHECK_AT_PREP &
~(1 << PG_locked |
1 << PG_referenced |
1 << PG_lru |
1 << PG_active |
1 << PG_workingset |
1 << PG_reclaim |
1 << PG_waiters |
LRU_GEN_MASK | LRU_REFS_MASK))) {
dump_page(&folio->page, "fuse: trying to steal weird page");
return 1;
}
return 0;
}
/*
* Attempt to steal a page from the splice() pipe and move it into the
* pagecache. If successful, the pointer in @pagep will be updated. The
* folio that was originally in @pagep will lose a reference and the new
* folio returned in @pagep will carry a reference.
*/
static int fuse_try_move_folio(struct fuse_copy_state *cs, struct folio **foliop)
{
int err;
struct folio *oldfolio = *foliop;
struct folio *newfolio;
struct pipe_buffer *buf = cs->pipebufs;
folio_get(oldfolio);
err = unlock_request(cs->req);
if (err)
goto out_put_old;
fuse_copy_finish(cs);
err = pipe_buf_confirm(cs->pipe, buf);
if (err)
goto out_put_old;
BUG_ON(!cs->nr_segs);
cs->currbuf = buf;
cs->len = buf->len;
cs->pipebufs++;
cs->nr_segs--;
if (cs->len != folio_size(oldfolio))
goto out_fallback;
newfolio = page_folio(buf->page);
if (folio_test_large(newfolio))
goto out_fallback;
/*
* This is a new and locked page, it shouldn't be mapped or
* have any special flags on it
*/
if (WARN_ON(folio_mapped(oldfolio)))
goto out_fallback;
if (WARN_ON(folio_has_private(oldfolio)))
goto out_fallback;
if (WARN_ON(folio_test_dirty(oldfolio) ||
folio_test_writeback(oldfolio)))
goto out_fallback;
if (WARN_ON(folio_test_mlocked(oldfolio)))
goto out_fallback;
if (!pipe_buf_try_steal(cs->pipe, buf))
goto out_fallback;
folio_clear_uptodate(newfolio);
folio_clear_mappedtodisk(newfolio);
if (fuse_check_folio(newfolio) != 0)
goto out_fallback_unlock;
err = lock_request(cs->req);
if (err)
goto out_fallback_unlock;
replace_page_cache_folio(oldfolio, newfolio);
folio_get(newfolio);
if (!(buf->flags & PIPE_BUF_FLAG_LRU))
folio_add_lru(newfolio);
/*
* Release while we have extra ref on stolen page. Otherwise
* anon_pipe_buf_release() might think the page can be reused.
*/
pipe_buf_release(cs->pipe, buf);
*foliop = newfolio;
folio_unlock(oldfolio);
/* Drop ref for ap->pages[] array */
folio_put(oldfolio);
cs->len = 0;
err = 0;
out_put_old:
/* Drop ref obtained in this function */
folio_put(oldfolio);
return err;
out_fallback_unlock:
folio_unlock(newfolio);
out_fallback:
cs->pg = buf->page;
cs->offset = buf->offset;
err = lock_request(cs->req);
if (!err)
err = 1;
goto out_put_old;
}
static int fuse_ref_folio(struct fuse_copy_state *cs, struct folio *folio,
unsigned offset, unsigned count)
{
@@ -1275,16 +1153,9 @@ int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
return fuse_ref_folio(cs, folio, offset, count);
}
} else if (!cs->len) {
if (cs->move_folios && folio &&
offset == 0 && count == folio_size(folio)) {
err = fuse_try_move_folio(cs, foliop);
if (err <= 0)
return err;
} else {
err = fuse_copy_fill(cs);
if (err)
return err;
}
err = fuse_copy_fill(cs);
if (err)
return err;
}
if (folio) {
void *mapaddr = kmap_local_folio(folio, offset);
@@ -1756,7 +1627,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
* Need to be careful about this. Having buf->ops in module
* code can Oops if the buffer persists after module unload.
*/
bufs[page_nr].ops = &nosteal_pipe_buf_ops;
bufs[page_nr].ops = &default_pipe_buf_ops;
bufs[page_nr].flags = 0;
ret = add_to_pipe(pipe, &bufs[page_nr++]);
if (unlikely(ret < 0))
@@ -1920,9 +1791,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
if (!smp_load_acquire(&fch->initialized) || !fch->connected)
goto copy_finish;
/* Don't try to move folios (yet) */
cs->move_folios = false;
err = fuse_notify(fch->conn, oh.error, nbytes - sizeof(oh), cs);
goto copy_finish;
}
@@ -1966,8 +1834,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
set_bit(FR_LOCKED, &req->flags);
spin_unlock(&fpq->lock);
cs->req = req;
if (!req->args->page_replace)
cs->move_folios = false;
if (oh.error)
err = nbytes != sizeof(oh) ? -EINVAL : 0;
@@ -2068,7 +1934,6 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
goto out_free;
*obuf = *ibuf;
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
obuf->len = rem;
ibuf->offset += obuf->len;
ibuf->len -= obuf->len;
@@ -2083,9 +1948,6 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
cs.nr_segs = nbuf;
cs.pipe = pipe;
if (flags & SPLICE_F_MOVE)
cs.move_folios = true;
ret = fuse_dev_do_write(fud, &cs, len);
pipe_lock(pipe);
-1
View File
@@ -1092,7 +1092,6 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file,
ap->args.out_pages = true;
ap->args.page_zeroing = true;
ap->args.page_replace = true;
/*
* Don't overflow end offset.
-1
View File
@@ -326,7 +326,6 @@ struct fuse_copy_state {
unsigned int len;
unsigned int offset;
bool write:1;
bool move_folios:1;
bool is_uring:1;
/* set when the payload is zero-copied. folios are filled in place */
bool skip_folio_copy:1;
+12 -1
View File
@@ -817,6 +817,14 @@ static void evict(struct inode *inode)
inode_wait_for_writeback(inode);
spin_unlock(&inode->i_lock);
/*
* fsync() can't find what I_METADATA_WRITEBACK tracks anymore once the
* inode is gone, so write it out unless the inode is being deleted.
*/
if (inode->i_nlink &&
(inode_state_read_once(inode) & I_METADATA_WRITEBACK))
sync_inode_metadata(inode, 1);
if (op->evict_inode) {
op->evict_inode(inode);
} else {
@@ -952,9 +960,12 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
* they're already on the LRU, and this can make them
* unreclaimable for a while. Remove them lazily here; iput,
* sync, or the last page cache deletion will requeue them.
* Nothing requeues them for I_METADATA_WRITEBACK, evict() writes
* that out instead.
*/
if (icount_read(inode) ||
(inode_state_read(inode) & ~I_REFERENCED) ||
(inode_state_read(inode) &
~(I_REFERENCED | I_METADATA_WRITEBACK)) ||
!mapping_shrinkable(&inode->i_data)) {
list_lru_isolate(lru, &inode->i_lru);
spin_unlock(&inode->i_lock);
+23 -14
View File
@@ -121,21 +121,35 @@ unsigned long minix_count_free_blocks(struct super_block *sb)
<< sbi->s_log_zone_size);
}
struct minix_inode *
minix_V1_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
/* Return the block that holds inode @ino or 0 if @ino is out of range. */
int minix_inode_block(struct super_block *sb, ino_t ino)
{
int block;
struct minix_sb_info *sbi = minix_sb(sb);
struct minix_inode *p;
int inodes_per_block;
if (!ino || ino > sbi->s_ninodes) {
printk("Bad inode number on dev %s: %ld is out of range\n",
sb->s_id, (long)ino);
return NULL;
return 0;
}
if (sbi->s_version == MINIX_V1)
inodes_per_block = MINIX_INODES_PER_BLOCK;
else
inodes_per_block = sb->s_blocksize / sizeof(struct minix2_inode);
return 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks +
(ino - 1) / inodes_per_block;
}
struct minix_inode *
minix_V1_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
{
int block;
struct minix_inode *p;
block = minix_inode_block(sb, ino);
if (!block)
return NULL;
ino--;
block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks +
ino / MINIX_INODES_PER_BLOCK;
*bh = sb_bread(sb, block);
if (!*bh) {
printk("Unable to read inode block\n");
@@ -149,19 +163,14 @@ struct minix2_inode *
minix_V2_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
{
int block;
struct minix_sb_info *sbi = minix_sb(sb);
struct minix2_inode *p;
int minix2_inodes_per_block = sb->s_blocksize / sizeof(struct minix2_inode);
*bh = NULL;
if (!ino || ino > sbi->s_ninodes) {
printk("Bad inode number on dev %s: %ld is out of range\n",
sb->s_id, (long)ino);
block = minix_inode_block(sb, ino);
if (!block)
return NULL;
}
ino--;
block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks +
ino / minix2_inodes_per_block;
*bh = sb_bread(sb, block);
if (!*bh) {
printk("Unable to read inode block\n");
+8 -10
View File
@@ -50,8 +50,6 @@ static void minix_evict_inode(struct inode *inode)
if (!inode->i_nlink) {
inode->i_size = 0;
minix_truncate(inode);
} else {
mmb_sync(&minix_i(inode)->i_metadata_bhs);
}
mmb_invalidate(&minix_i(inode)->i_metadata_bhs);
clear_inode(inode);
@@ -702,24 +700,24 @@ static int minix_sync_inode_metadata(struct inode *inode,
{
int err = 0;
struct buffer_head *bh;
void *raw_inode;
int block;
if (INODE_VERSION(inode) == MINIX_V1)
raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
else
raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
if (!raw_inode)
block = minix_inode_block(inode->i_sb, inode->i_ino);
if (!block)
return -EIO;
err = mmb_sync(&minix_i(inode)->i_metadata_bhs);
if (err)
goto out;
return err;
/* A block that isn't cached is neither dirty nor under writeback. */
bh = sb_find_get_block_nonatomic(inode->i_sb, block);
if (!bh)
return 0;
sync_dirty_buffer(bh);
if (buffer_write_io_error(bh)) {
printk("IO error syncing minix inode [%s:%08llx]\n",
inode->i_sb->s_id, inode->i_ino);
err = -EIO;
}
out:
brelse(bh);
return err;
}
+1
View File
@@ -47,6 +47,7 @@ void __minix_error_inode(struct inode *inode, const char *function,
unsigned int line, const char *fmt, ...);
struct inode *minix_iget(struct super_block *, unsigned long);
int minix_inode_block(struct super_block *sb, ino_t ino);
struct minix_inode *minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
struct minix2_inode *minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
struct inode *minix_new_inode(const struct inode *, umode_t);
+2 -4
View File
@@ -3296,7 +3296,7 @@ static struct mnt_namespace *create_new_namespace(struct path *path,
}
new_ns->root = new_ns_root;
ns_tree_add_raw(new_ns);
ns_tree_add(new_ns);
return new_ns;
}
@@ -4394,8 +4394,6 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
dec_mnt_namespaces(ucounts);
return ERR_PTR(ret);
}
ns_tree_gen_id(new_ns);
new_ns->is_anon = anon;
refcount_set(&new_ns->passive, 1);
new_ns->mounts = RB_ROOT;
@@ -4499,7 +4497,7 @@ struct mnt_namespace *copy_mnt_ns(u64 flags, struct mnt_namespace *ns,
p = next_mnt(skip_mnt_tree(p), old);
}
}
ns_tree_add_raw(new_ns);
ns_tree_add(new_ns);
return new_ns;
}
-43
View File
@@ -222,48 +222,6 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe,
anon_pipe_put_page(pipe, page);
}
static bool anon_pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
struct page *page = buf->page;
if (page_count(page) != 1)
return false;
memcg_kmem_uncharge_page(page, 0);
__SetPageLocked(page);
return true;
}
/**
* generic_pipe_buf_try_steal - attempt to take ownership of a &pipe_buffer
* @pipe: the pipe that the buffer belongs to
* @buf: the buffer to attempt to steal
*
* Description:
* This function attempts to steal the &struct page attached to
* @buf. If successful, this function returns 0 and returns with
* the page locked. The caller may then reuse the page for whatever
* he wishes; the typical use is insertion into a different file
* page cache.
*/
bool generic_pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
struct page *page = buf->page;
/*
* A reference of one is golden, that means that the owner of this
* page is the only one holding a reference to it. lock the page
* and return OK.
*/
if (page_count(page) == 1) {
lock_page(page);
return true;
}
return false;
}
EXPORT_SYMBOL(generic_pipe_buf_try_steal);
/**
* generic_pipe_buf_get - get a reference to a &struct pipe_buffer
* @pipe: the pipe that the buffer belongs to
@@ -297,7 +255,6 @@ EXPORT_SYMBOL(generic_pipe_buf_release);
static const struct pipe_buf_operations anon_pipe_buf_ops = {
.release = anon_pipe_buf_release,
.try_steal = anon_pipe_buf_try_steal,
.get = generic_pipe_buf_get,
};
+4 -1
View File
@@ -557,6 +557,8 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter,
struct ctl_table_header *head = grab_header(inode);
const struct ctl_table *table = PROC_I(inode)->sysctl_entry;
size_t count = iov_iter_count(iter);
/* ->write_iter() must never report more than the iterator held */
size_t orig_count = count;
char *kbuf;
ssize_t error;
@@ -607,7 +609,8 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter,
goto out_free_buf;
}
error = count;
/* the write path consumed at most the original iterator length */
error = write ? min(count, orig_count) : count;
out_free_buf:
kvfree(kbuf);
out:
+13 -100
View File
@@ -55,63 +55,6 @@ static noinline void pipe_clear_nowait(struct file *file)
} while (!try_cmpxchg(&file->f_mode, &fmode, fmode & ~FMODE_NOWAIT));
}
/*
* Attempt to steal a page from a pipe buffer. This should perhaps go into
* a vm helper function, it's already simplified quite a bit by the
* addition of remove_mapping(). If success is returned, the caller may
* attempt to reuse this page for another destination.
*/
static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
struct folio *folio = page_folio(buf->page);
struct address_space *mapping;
folio_lock(folio);
mapping = folio_mapping(folio);
if (mapping) {
WARN_ON(!folio_test_uptodate(folio));
/*
* At least for ext2 with nobh option, we need to wait on
* writeback completing on this folio, since we'll remove it
* from the pagecache. Otherwise truncate wont wait on the
* folio, allowing the disk blocks to be reused by someone else
* before we actually wrote our data to them. fs corruption
* ensues.
*/
folio_wait_writeback(folio);
if (!filemap_release_folio(folio, GFP_KERNEL))
goto out_unlock;
/*
* If we succeeded in removing the mapping, set LRU flag
* and return good.
*/
if (remove_mapping(mapping, folio)) {
buf->flags |= PIPE_BUF_FLAG_LRU;
return true;
}
}
/*
* Raced with truncate or failed to remove folio from current
* address space, unlock and return failure.
*/
out_unlock:
folio_unlock(folio);
return false;
}
static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
put_page(buf->page);
buf->flags &= ~PIPE_BUF_FLAG_LRU;
}
/*
* Check whether the contents of buf is OK to access. Since the content
* is a page cache page, IO may be in flight.
@@ -154,24 +97,12 @@ error:
const struct pipe_buf_operations page_cache_pipe_buf_ops = {
.confirm = page_cache_pipe_buf_confirm,
.release = page_cache_pipe_buf_release,
.try_steal = page_cache_pipe_buf_try_steal,
.release = generic_pipe_buf_release,
.get = generic_pipe_buf_get,
};
static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
if (!(buf->flags & PIPE_BUF_FLAG_GIFT))
return false;
buf->flags |= PIPE_BUF_FLAG_LRU;
return generic_pipe_buf_try_steal(pipe, buf);
}
static const struct pipe_buf_operations user_page_pipe_buf_ops = {
.release = page_cache_pipe_buf_release,
.try_steal = user_page_pipe_buf_try_steal,
.release = generic_pipe_buf_release,
.get = generic_pipe_buf_get,
};
@@ -400,16 +331,9 @@ EXPORT_SYMBOL(copy_splice_read);
const struct pipe_buf_operations default_pipe_buf_ops = {
.release = generic_pipe_buf_release,
.try_steal = generic_pipe_buf_try_steal,
.get = generic_pipe_buf_get,
};
/* Pipe buffer operations for a socket and similar. */
const struct pipe_buf_operations nosteal_pipe_buf_ops = {
.release = generic_pipe_buf_release,
.get = generic_pipe_buf_get,
};
EXPORT_SYMBOL(nosteal_pipe_buf_ops);
EXPORT_SYMBOL(default_pipe_buf_ops);
static void wakeup_pipe_writers(struct pipe_inode_info *pipe)
{
@@ -737,9 +661,12 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
sd.pos = kiocb.ki_pos;
if (ret <= 0)
break;
WARN_ONCE(ret > sd.total_len - left,
"Splice Exceeded! ret=%zd tot=%zu left=%zu\n",
ret, sd.total_len, left);
if (unlikely(ret > sd.total_len - left)) {
WARN_ONCE(1,
"Splice Exceeded! ret=%zd tot=%zu left=%zu\n",
ret, sd.total_len, left);
ret = sd.total_len - left;
}
sd.num_spliced += ret;
sd.total_len -= ret;
@@ -1469,12 +1396,10 @@ static ssize_t __do_splice(struct file *in, loff_t __user *off_in,
}
static ssize_t iter_to_pipe(struct iov_iter *from,
struct pipe_inode_info *pipe,
unsigned int flags)
struct pipe_inode_info *pipe)
{
struct pipe_buffer buf = {
.ops = &user_page_pipe_buf_ops,
.flags = flags
};
size_t total = 0;
ssize_t ret = 0;
@@ -1564,10 +1489,6 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
{
struct pipe_inode_info *pipe;
ssize_t ret = 0;
unsigned buf_flag = 0;
if (flags & SPLICE_F_GIFT)
buf_flag = PIPE_BUF_FLAG_GIFT;
pipe = get_pipe_info(file, true);
if (!pipe)
@@ -1578,7 +1499,7 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
pipe_lock(pipe);
ret = wait_for_space(pipe, flags);
if (!ret)
ret = iter_to_pipe(iter, pipe, buf_flag);
ret = iter_to_pipe(iter, pipe);
pipe_unlock(pipe);
if (ret > 0) {
wakeup_pipe_readers(pipe);
@@ -1839,11 +1760,7 @@ retry:
}
*obuf = *ibuf;
/*
* Don't inherit the gift and merge flags, we need to
* prevent multiple steals of this page.
*/
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
/* The page is shared with ipipe: don't append to it */
obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE;
obuf->len = len;
@@ -1956,11 +1873,7 @@ retry:
*obuf = *ibuf;
/*
* Don't inherit the gift and merge flag, we need to prevent
* multiple steals of this page.
*/
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
/* The page is shared with ipipe: don't append to it */
obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE;
if (obuf->len > len)
+15 -18
View File
@@ -152,8 +152,6 @@ void udf_evict_inode(struct inode *inode)
}
}
truncate_inode_pages_final(&inode->i_data);
if (!want_delete)
mmb_sync(&iinfo->i_metadata_bhs);
mmb_invalidate(&iinfo->i_metadata_bhs);
clear_inode(inode);
kfree(iinfo->i_data);
@@ -1747,25 +1745,24 @@ void udf_update_extra_perms(struct inode *inode, umode_t mode)
int udf_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc)
{
struct buffer_head *bh;
unsigned long block;
int err = 0;
bh = sb_getblk(inode->i_sb,
udf_get_lb_pblock(inode->i_sb,
&UDF_I(inode)->i_location, 0));
if (!bh)
return -EIO;
sync_dirty_buffer(bh);
if (buffer_write_io_error(bh)) {
udf_warn(inode->i_sb, "IO error syncing udf inode [%08llx]\n",
inode->i_ino);
err = -EIO;
goto out;
block = udf_get_lb_pblock(inode->i_sb, &UDF_I(inode)->i_location, 0);
/* A block that isn't cached is neither dirty nor under writeback. */
bh = sb_find_get_block_nonatomic(inode->i_sb, block);
if (bh) {
sync_dirty_buffer(bh);
if (buffer_write_io_error(bh)) {
udf_warn(inode->i_sb, "IO error syncing udf inode [%08llx]\n",
inode->i_ino);
err = -EIO;
}
brelse(bh);
if (err)
return err;
}
err = mmb_sync(&UDF_I(inode)->i_metadata_bhs);
out:
brelse(bh);
return err;
return mmb_sync(&UDF_I(inode)->i_metadata_bhs);
}
static void udf_adjust_time(struct udf_inode_info *iinfo, struct timespec64 time)
+1 -1
View File
@@ -173,7 +173,7 @@ struct super_block {
struct unicode_map *s_encoding;
__u16 s_encoding_flags;
#endif
struct hlist_head s_roots; /* alternate root dentries for NFS */
struct hlist_head s_roots; /* alternate root dentries for NFS and ex-mountpoints */
spinlock_t s_roots_lock;
struct mount *s_mounts; /* list of mounts; _not_ for fs use */
struct block_device *s_bdev; /* can go away once we use an accessor for @s_bdev_file */
+9 -7
View File
@@ -9,7 +9,8 @@
#include <uapi/linux/nsfs.h>
bool is_current_namespace(struct ns_common *ns);
int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, int inum);
int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops,
int inum, u64 ns_id);
void __ns_common_free(struct ns_common *ns);
struct ns_common *__must_check ns_owner(struct ns_common *ns);
@@ -41,17 +42,18 @@ static __always_inline bool is_ns_init_id(const struct ns_common *ns)
.ns_owner_root.ns_list_head = LIST_HEAD_INIT(nsname.ns.ns_owner_root.ns_list_head), \
}
#define ns_common_init(__ns) \
__ns_common_init(to_ns_common(__ns), \
ns_common_type(__ns), \
to_ns_operations(__ns), \
(((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
#define ns_common_init(__ns) \
__ns_common_init(to_ns_common(__ns), \
ns_common_type(__ns), \
to_ns_operations(__ns), \
(((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0), \
(((__ns) == ns_init_ns(__ns)) ? ns_init_id(__ns) : 0))
#define ns_common_init_inum(__ns, __inum) \
__ns_common_init(to_ns_common(__ns), \
ns_common_type(__ns), \
to_ns_operations(__ns), \
__inum)
__inum, 0)
#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
+4 -25
View File
@@ -41,43 +41,22 @@ void ns_tree_node_del(struct ns_tree_node *node, struct ns_tree_root *root);
struct user_namespace *: &(user_ns_tree), \
struct uts_namespace *: &(uts_ns_tree))
#define ns_tree_gen_id(__ns) \
__ns_tree_gen_id(to_ns_common(__ns), \
(((__ns) == ns_init_ns(__ns)) ? ns_init_id(__ns) : 0))
u64 __ns_tree_gen_id(struct ns_common *ns, u64 id);
void __ns_tree_add_raw(struct ns_common *ns, struct ns_tree_root *ns_tree);
void __ns_tree_add(struct ns_common *ns, struct ns_tree_root *ns_tree);
void __ns_tree_remove(struct ns_common *ns, struct ns_tree_root *ns_tree);
struct ns_common *ns_tree_lookup_rcu(u64 ns_id, int ns_type);
struct ns_common *__ns_tree_adjoined_rcu(struct ns_common *ns,
struct ns_tree_root *ns_tree,
bool previous);
static inline void __ns_tree_add(struct ns_common *ns, struct ns_tree_root *ns_tree, u64 id)
{
__ns_tree_gen_id(ns, id);
__ns_tree_add_raw(ns, ns_tree);
}
/**
* ns_tree_add_raw - Add a namespace to a namespace
* @__ns: Namespace to add
*
* This function adds a namespace to the appropriate namespace tree
* without assigning a id.
*/
#define ns_tree_add_raw(__ns) __ns_tree_add_raw(to_ns_common(__ns), to_ns_tree(__ns))
/**
* ns_tree_add - Add a namespace to a namespace tree
* @__ns: Namespace to add
*
* This function assigns a new id to the namespace and adds it to the
* appropriate namespace tree and list.
* This function adds a namespace to the appropriate namespace tree and
* list. The namespace must already have been assigned an id.
*/
#define ns_tree_add(__ns) \
__ns_tree_add(to_ns_common(__ns), to_ns_tree(__ns), \
(((__ns) == ns_init_ns(__ns)) ? ns_init_id(__ns) : 0))
#define ns_tree_add(__ns) __ns_tree_add(to_ns_common(__ns), to_ns_tree(__ns))
/**
* ns_tree_remove - Remove a namespace from a namespace tree
-38
View File
@@ -4,9 +4,7 @@
#define PIPE_DEF_BUFFERS 16
#define PIPE_BUF_FLAG_LRU 0x01 /* page is on the LRU */
#define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */
#define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */
#define PIPE_BUF_FLAG_PACKET 0x08 /* read() as a packet */
#define PIPE_BUF_FLAG_CAN_MERGE 0x10 /* can merge buffers */
#define PIPE_BUF_FLAG_WHOLE 0x20 /* read() must return entire buffer or error */
@@ -127,16 +125,6 @@ struct pipe_inode_info {
#endif
};
/*
* Note on the nesting of these functions:
*
* ->confirm()
* ->try_steal()
*
* That is, ->try_steal() must be called on a confirmed buffer. See below for
* the meaning of each operation. Also see the kerneldoc in fs/pipe.c for the
* pipe and generic variants of these hooks.
*/
struct pipe_buf_operations {
/*
* ->confirm() verifies that the data in the pipe buffer is there
@@ -153,16 +141,6 @@ struct pipe_buf_operations {
*/
void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
/*
* Attempt to take ownership of the pipe buffer and its contents.
* ->try_steal() returns %true for success, in which case the contents
* of the pipe (the buf->page) is locked and now completely owned by the
* caller. The page may then be transferred to a different mapping, the
* most often used case is insertion into different file address space
* cache.
*/
bool (*try_steal)(struct pipe_inode_info *, struct pipe_buffer *);
/*
* Get a reference to the pipe buffer.
*/
@@ -304,19 +282,6 @@ static inline int pipe_buf_confirm(struct pipe_inode_info *pipe,
return buf->ops->confirm(pipe, buf);
}
/**
* pipe_buf_try_steal - attempt to take ownership of a pipe_buffer
* @pipe: the pipe that the buffer belongs to
* @buf: the buffer to attempt to steal
*/
static inline bool pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
if (!buf->ops->try_steal)
return false;
return buf->ops->try_steal(pipe, buf);
}
/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
#define PIPE_SIZE PAGE_SIZE
@@ -335,11 +300,8 @@ void free_pipe_info(struct pipe_inode_info *);
/* Generic pipe buffer ops functions */
bool generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
bool generic_pipe_buf_try_steal(struct pipe_inode_info *, struct pipe_buffer *);
void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
extern const struct pipe_buf_operations nosteal_pipe_buf_ops;
unsigned long account_pipe_buffers(struct user_struct *user,
unsigned long old, unsigned long new);
bool too_many_pipe_buffers_soft(unsigned long user_bufs);
+2 -1
View File
@@ -987,7 +987,8 @@ TRACE_EVENT(landlock_deny_access_net,
* @logged: Whether this denial was selected for audit logging.
* @blockers: Request type and final missing permission subset (never NULL).
* @namespace_type: CLONE_NEW* namespace type that was denied.
* @namespace_id: Namespace ID, or 0 when creation was denied.
* @namespace_id: Namespace ID, not directly visible from user space when
* creation was denied.
*
* Emitted when a Landlock domain denies namespace use.
*/
+1 -2
View File
@@ -66,7 +66,6 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
if (err)
goto fail_free;
ns_tree_gen_id(ns);
ns->user_ns = get_user_ns(user_ns);
ns->ucounts = ucounts;
@@ -87,7 +86,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
sem_init_ns(ns);
shm_init_ns(ns);
ns_tree_add_raw(ns);
ns_tree_add(ns);
return ns;
+2
View File
@@ -411,6 +411,8 @@ BTF_ID(func, bpf_lsm_bpf_map_free)
BTF_ID(func, bpf_lsm_bpf_prog_free)
BTF_ID(func, bpf_lsm_file_alloc_security)
BTF_ID(func, bpf_lsm_file_free_security)
BTF_ID(func, bpf_lsm_namespace_init)
BTF_ID(func, bpf_lsm_namespace_free)
#ifdef CONFIG_SECURITY_NETWORK
BTF_ID(func, bpf_lsm_sk_alloc_security)
BTF_ID(func, bpf_lsm_sk_free_security)
+5 -2
View File
@@ -54,7 +54,8 @@ static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops)
}
#endif
int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, int inum)
int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops,
int inum, u64 ns_id)
{
int ret = 0;
@@ -64,7 +65,6 @@ int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_ope
ns->ns_security = NULL;
#endif
ns->ops = ops;
ns->ns_id = 0;
ns->ns_type = ns_type;
ns_tree_node_init(&ns->ns_tree_node);
ns_tree_node_init(&ns->ns_unified_node);
@@ -82,6 +82,9 @@ int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_ope
if (ret)
return ret;
/* Allocate the id before the LSM hook so it can track the namespace by it. */
__ns_tree_gen_id(ns, ns_id);
ret = security_namespace_init(ns);
if (ret) {
if (!inum)
+1 -1
View File
@@ -194,7 +194,7 @@ static int ns_cmp_owner(struct rb_node *a, const struct rb_node *b)
return ns_id_cmp(node_to_ns_owner(a)->ns_id, node_to_ns_owner(b)->ns_id);
}
void __ns_tree_add_raw(struct ns_common *ns, struct ns_tree_root *ns_tree)
void __ns_tree_add(struct ns_common *ns, struct ns_tree_root *ns_tree)
{
struct rb_node *node;
const struct proc_ns_operations *ops = ns->ops;
-4
View File
@@ -77,13 +77,9 @@ static void watch_queue_pipe_buf_release(struct pipe_inode_info *pipe,
generic_pipe_buf_release(pipe, buf);
}
// No try_steal function => no stealing
#define watch_queue_pipe_buf_try_steal NULL
/* New data written to a pipe may be appended to a buffer with this type. */
static const struct pipe_buf_operations watch_queue_pipe_buf_ops = {
.release = watch_queue_pipe_buf_release,
.try_steal = watch_queue_pipe_buf_try_steal,
.get = generic_pipe_buf_get,
};
-7
View File
@@ -3703,15 +3703,8 @@ static void zero_pipe_buf_release(struct pipe_inode_info *pipe,
{
}
static bool zero_pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
return false;
}
static const struct pipe_buf_operations zero_pipe_buf_ops = {
.release = zero_pipe_buf_release,
.try_steal = zero_pipe_buf_try_steal,
.get = zero_pipe_buf_get,
};
+2 -2
View File
@@ -437,7 +437,7 @@ static __net_init int setup_net(struct net *net)
LIST_HEAD(net_exit_list);
int error = 0;
net->net_cookie = ns_tree_gen_id(net);
net->net_cookie = to_ns_common(net)->ns_id;
list_for_each_entry(ops, &pernet_list, list) {
error = ops_init(ops, net);
@@ -449,7 +449,7 @@ static __net_init int setup_net(struct net *net)
up_write(&net_rwsem);
/* Without CONFIG_NET_NS init_net isn't exposed as a namespace. */
if (IS_ENABLED(CONFIG_NET_NS))
ns_tree_add_raw(net);
ns_tree_add(net);
out:
return error;
+1 -1
View File
@@ -3281,7 +3281,7 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
.pages = pages,
.partial = partial,
.nr_pages_max = MAX_SKB_FRAGS,
.ops = &nosteal_pipe_buf_ops,
.ops = &default_pipe_buf_ops,
.spd_release = sock_spd_release,
};
int ret = 0;
+2 -1
View File
@@ -94,7 +94,8 @@ static const struct access_masks ns_permission = {
* Shared check for namespace_init (creation via clone(2), unshare(2),
* open_tree(2), or fsmount(2)) and namespace_install (use via setns(2)): denies
* when the namespace type is not in the domain's allowed set. At allocation
* time @ns->ns_id is still zero and is logged as such.
* time @ns->ns_id is already set even though the namespace is not reachable
* from user space yet.
*
* Return: 0 if allowed, -EPERM if denied.
*/
+5 -2
View File
@@ -1899,8 +1899,9 @@ TEST(setns_inherited_fd)
static int matches_log_ns_create(int audit_fd, __u64 ns_type)
{
/* A denied creation logs the ID allocated for the new namespace. */
static const char log_template[] = REGEX_LANDLOCK_PREFIX
" blockers=namespace\\.use namespace_type=0x%x namespace_id=0$";
" blockers=namespace\\.use namespace_type=0x%x namespace_id=[1-9][0-9]*$";
char log_match[sizeof(log_template) + 10];
int log_match_len;
@@ -2538,7 +2539,9 @@ static void test_ns_trace_denial(struct __test_metadata *const _metadata,
ASSERT_EQ(0, tracefs_extract_field(
buf, REGEX_DENY_PERMISSION_NAMESPACE(TRACE_TASK),
"namespace_id", field, sizeof(field)));
EXPECT_EQ(use_setns ? expected_ns_id : 0, strtoull(field, NULL, 10));
EXPECT_STRNE("0", field);
if (use_setns)
EXPECT_EQ(expected_ns_id, strtoull(field, NULL, 10));
free(buf);
}