17 Aug, 2022

1 commit

  • [ Upstream commit 6e195b0f7c8e50927fa31946369c22a0534ec7e2 ]

    Sohaib Mohamed started a serie of tiny and incomplete checkpatch fixes but
    seemingly stopped halfway -- take over and do most of it.
    This is still missing net/9p/trans* and net/9p/protocol.c for a later
    time...

    Link: http://lkml.kernel.org/r/20211102134608.1588018-3-dominique.martinet@atmark-techno.com
    Signed-off-by: Dominique Martinet
    Signed-off-by: Sasha Levin

    Dominique Martinet
     

29 Jun, 2022

3 commits

  • commit e5690f263208c5abce7451370b7786eb25b405eb upstream.

    we check for protocol version later than required, after a fid has
    been obtained. Just move the version check earlier.

    Link: https://lkml.kernel.org/r/20220612085330.1451496-3-asmadeus@codewreck.org
    Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct")
    Cc: stable@vger.kernel.org
    Reviewed-by: Tyler Hicks
    Reviewed-by: Christian Schoenebeck
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Dominique Martinet
     
  • commit beca774fc51a9ba8abbc869cf0c3d965ff17cd24 upstream.

    We need to release directory fid if we fail halfway through open

    This fixes fid leaking with xfstests generic 531

    Link: https://lkml.kernel.org/r/20220612085330.1451496-2-asmadeus@codewreck.org
    Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct")
    Cc: stable@vger.kernel.org
    Reported-by: Tyler Hicks
    Reviewed-by: Tyler Hicks
    Reviewed-by: Christian Schoenebeck
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Dominique Martinet
     
  • commit 2a3dcbccd64ba35c045fac92272ff981c4cbef44 upstream.

    Decrement the refcount of the parent dentry's fid after walking
    each path component during a full path walk for a lookup. Failure to do
    so can lead to fids that are not clunked until the filesystem is
    unmounted, as indicated by this warning:

    9pnet: found fid 3 not clunked

    The improper refcounting after walking resulted in open(2) returning
    -EIO on any directories underneath the mount point when using the virtio
    transport. When using the fd transport, there's no apparent issue until
    the filesytem is unmounted and the warning above is emitted to the logs.

    In some cases, the user may not yet be attached to the filesystem and a
    new root fid, associated with the user, is created and attached to the
    root dentry before the full path walk is performed. Increment the new
    root fid's refcount to two in that situation so that it can be safely
    decremented to one after it is used for the walk operation. The new fid
    will still be attached to the root dentry when
    v9fs_fid_lookup_with_uid() returns so a final refcount of one is
    correct/expected.

    Link: https://lkml.kernel.org/r/20220527000003.355812-2-tyhicks@linux.microsoft.com
    Link: https://lkml.kernel.org/r/20220612085330.1451496-4-asmadeus@codewreck.org
    Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct")
    Cc: stable@vger.kernel.org
    Signed-off-by: Tyler Hicks
    Reviewed-by: Christian Schoenebeck
    [Dominique: fix clunking fid multiple times discussed in second link]
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Tyler Hicks
     

09 Feb, 2022

1 commit

  • commit 22e424feb6658c5d6789e45121830357809c59cb upstream.

    This reverts commit 478ba09edc1f2f2ee27180a06150cb2d1a686f9c.

    That commit was meant as a fix for setattrs with by fd (e.g. ftruncate)
    to use an open fid instead of the first fid it found on lookup.
    The proper fix for that is to use the fid associated with the open file
    struct, available in iattr->ia_file for such operations, and was
    actually done just before in 66246641609b ("9p: retrieve fid from file
    when file instance exist.")
    As such, this commit is no longer required.

    Furthermore, changing lookup to return open fids first had unwanted side
    effects, as it turns out the protocol forbids the use of open fids for
    further walks (e.g. clone_fid) and we broke mounts for some servers
    enforcing this rule.

    Note this only reverts to the old working behaviour, but it's still
    possible for lookup to return open fids if dentry->d_fsdata is not set,
    so more work is needed to make sure we respect this rule in the future,
    for example by adding a flag to the lookup functions to only match
    certain fid open modes depending on caller requirements.

    Link: https://lkml.kernel.org/r/20220130130651.712293-1-asmadeus@codewreck.org
    Fixes: 478ba09edc1f ("fs/9p: search open fids first")
    Cc: stable@vger.kernel.org # v5.11+
    Reported-by: ron minnich
    Reported-by: ng@0x80.stream
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Dominique Martinet
     

20 Jan, 2022

1 commit

  • commit 3cb6ee991496b67ee284c6895a0ba007e2d7bac3 upstream.

    The 9P2000.L setattr method v9fs_vfs_setattr_dotl() copies struct iattr
    values without checking whether they are valid causing unitialized
    values to be copied. The 9P2000 setattr method v9fs_vfs_setattr() method
    gets this right. Check whether struct iattr fields are valid first
    before copying in v9fs_vfs_setattr_dotl() too and make sure that all
    other fields are set to 0 apart from {g,u}id which should be set to
    INVALID_{G,U}ID. This ensure that they can be safely sent over the wire
    or printed for debugging later on.

    Link: https://lkml.kernel.org/r/20211129114434.3637938-1-brauner@kernel.org
    Link: https://lkml.kernel.org/r/000000000000a0d53f05d1c72a4c%40google.com
    Cc: Eric Van Hensbergen
    Cc: Latchesar Ionkov
    Cc: Dominique Martinet
    Cc: stable@kernel.org
    Cc: v9fs-developer@lists.sourceforge.net
    Reported-by: syzbot+dfac92a50024b54acaa4@syzkaller.appspotmail.com
    Signed-off-by: Christian Brauner
    [Dominique: do not set a/mtime with just ATTR_A/MTIME as discussed]
    Signed-off-by: Dominique Martinet
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     

05 Oct, 2021

1 commit

  • Fix a bunch of kerneldoc warnings shown up by W=1 in the 9p filesystem:

    (1) Add/remove/fix kerneldoc parameters descriptions.

    (2) Move __add_fid() from between v9fs_fid_add() and its comment.

    (3) 9p's caches_show() doesn't really make sense as an API function, so
    remove the kerneldoc annotation. It's also not prefixed with 'v9fs_'.
    Also remove the kerneldoc markers from the 9p fscache wrappers.

    Signed-off-by: David Howells
    Reviewed-by: Dominique Martinet
    Reviewed-by: Jeff Layton
    cc: Mauro Carvalho Chehab
    cc: v9fs-developer@lists.sourceforge.net
    cc: linux-fsdevel@vger.kernel.org
    cc: linux-doc@vger.kernel.org
    Link: https://lore.kernel.org/r/163214005516.2945267.7000234432243167892.stgit@warthog.procyon.org.uk/ # rfc v1
    Link: https://lore.kernel.org/r/163281899704.2790286.9177774252843775348.stgit@warthog.procyon.org.uk/ # rfc v2

    David Howells
     

03 Sep, 2021

1 commit

  • Pull overlayfs update from Miklos Szeredi:

    - Copy up immutable/append/sync/noatime attributes (Amir Goldstein)

    - Improve performance by enabling RCU lookup.

    - Misc fixes and improvements

    The reason this touches so many files is that the ->get_acl() method now
    gets a "bool rcu" argument. The ->get_acl() API was updated based on
    comments from Al and Linus:

    Link: https://lore.kernel.org/linux-fsdevel/CAJfpeguQxpd6Wgc0Jd3ks77zcsAv_bn0q17L3VNnnmPKu11t8A@mail.gmail.com/

    * tag 'ovl-update-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs:
    ovl: enable RCU'd ->get_acl()
    vfs: add rcu argument to ->get_acl() callback
    ovl: fix BUG_ON() in may_delete() when called from ovl_cleanup()
    ovl: use kvalloc in xattr copy-up
    ovl: update ctime when changing fileattr
    ovl: skip checking lower file's i_writecount on truncate
    ovl: relax lookup error on mismatch origin ftype
    ovl: do not set overlay.opaque for new directories
    ovl: add ovl_allow_offline_changes() helper
    ovl: disable decoding null uuid with redirect_dir
    ovl: consistent behavior for immutable/append-only inodes
    ovl: copy up sync/noatime fileattr flags
    ovl: pass ovl_fs to ovl_check_setxattr()
    fs: add generic helper for filling statx attribute flags

    Linus Torvalds
     

01 Sep, 2021

1 commit

  • Pull btrfs updates from David Sterba:
    "The highlights of this round are integrations with fs-verity and
    idmapped mounts, the rest is usual mix of minor improvements, speedups
    and cleanups.

    There are some patches outside of btrfs, namely updating some VFS
    interfaces, all straightforward and acked.

    Features:

    - fs-verity support, using standard ioctls, backward compatible with
    read-only limitation on inodes with previously enabled fs-verity

    - idmapped mount support

    - make mount with rescue=ibadroots more tolerant to partially damaged
    trees

    - allow raid0 on a single device and raid10 on two devices,
    degenerate cases but might be useful as an intermediate step during
    conversion to other profiles

    - zoned mode block group auto reclaim can be disabled via sysfs knob

    Performance improvements:

    - continue readahead of node siblings even if target node is in
    memory, could speed up full send (on sample test +11%)

    - batching of delayed items can speed up creating many files

    - fsync/tree-log speedups
    - avoid unnecessary work (gains +2% throughput, -2% run time on
    sample load)
    - reduced lock contention on renames (on dbench +4% throughput,
    up to -30% latency)

    Fixes:

    - various zoned mode fixes

    - preemptive flushing threshold tuning, avoid excessive work on
    almost full filesystems

    Core:

    - continued subpage support, preparation for implementing remaining
    features like compression and defragmentation; with some
    limitations, write is now enabled on 64K page systems with 4K
    sectors, still considered experimental
    - no readahead on compressed reads
    - inline extents disabled
    - disabled raid56 profile conversion and mount

    - improved flushing logic, fixing early ENOSPC on some workloads

    - inode flags have been internally split to read-only and read-write
    incompat bit parts, used by fs-verity

    - new tree items for fs-verity
    - descriptor item
    - Merkle tree item

    - inode operations extended to be namespace-aware

    - cleanups and refactoring

    Generic code changes:

    - fs: new export filemap_fdatawrite_wbc

    - fs: removed sync_inode

    - block: bio_trim argument type fixups

    - vfs: add namespace-aware lookup"

    * tag 'for-5.15-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (114 commits)
    btrfs: reset replace target device to allocation state on close
    btrfs: zoned: fix ordered extent boundary calculation
    btrfs: do not do preemptive flushing if the majority is global rsv
    btrfs: reduce the preemptive flushing threshold to 90%
    btrfs: tree-log: check btrfs_lookup_data_extent return value
    btrfs: avoid unnecessarily logging directories that had no changes
    btrfs: allow idmapped mount
    btrfs: handle ACLs on idmapped mounts
    btrfs: allow idmapped INO_LOOKUP_USER ioctl
    btrfs: allow idmapped SUBVOL_SETFLAGS ioctl
    btrfs: allow idmapped SET_RECEIVED_SUBVOL ioctls
    btrfs: relax restrictions for SNAP_DESTROY_V2 with subvolids
    btrfs: allow idmapped SNAP_DESTROY ioctls
    btrfs: allow idmapped SNAP_CREATE/SUBVOL_CREATE ioctls
    btrfs: check whether fsgid/fsuid are mapped during subvolume creation
    btrfs: allow idmapped permission inode op
    btrfs: allow idmapped setattr inode op
    btrfs: allow idmapped tmpfile inode op
    btrfs: allow idmapped symlink inode op
    btrfs: allow idmapped mkdir inode op
    ...

    Linus Torvalds
     

23 Aug, 2021

2 commits

  • We're going to remove sync_inode, so migrate to filemap_fdatawrite_wbc
    instead.

    Reviewed-by: Christoph Hellwig
    Reviewed-by: Nikolay Borisov
    Signed-off-by: Josef Bacik
    Reviewed-by: David Sterba
    Signed-off-by: David Sterba

    Josef Bacik
     
  • We added CONFIG_MANDATORY_FILE_LOCKING in 2015, and soon after turned it
    off in Fedora and RHEL8. Several other distros have followed suit.

    I've heard of one problem in all that time: Someone migrated from an
    older distro that supported "-o mand" to one that didn't, and the host
    had a fstab entry with "mand" in it which broke on reboot. They didn't
    actually _use_ mandatory locking so they just removed the mount option
    and moved on.

    This patch rips out mandatory locking support wholesale from the kernel,
    along with the Kconfig option and the Documentation file. It also
    changes the mount code to ignore the "mand" mount option instead of
    erroring out, and to throw a big, ugly warning.

    Signed-off-by: Jeff Layton

    Jeff Layton
     

19 Aug, 2021

1 commit


08 May, 2021

1 commit


31 Mar, 2021

2 commits

  • IS_ERR() and PTR_ERR() use wrong pointer, it should be
    writeback_fid, fix it.

    Link: http://lkml.kernel.org/r/20210330130632.1054357-1-yangyingliang@huawei.com
    Fixes: 5bfe97d7382b ("9p: Fix writeback fid incorrectly being attached to dentry")
    Reported-by: Hulk Robot
    Signed-off-by: Yang Yingliang
    [Dominique: adjusted commit summary]
    Signed-off-by: Dominique Martinet

    Yang Yingliang
     
  • The only usage of v9fs_attr_group is to pass its address to
    sysfs_create_group() and sysfs_create_group(), both which takes pointers
    to const struct attribute_group. Make it const to allow the compiler to
    put it in read-only memory.

    Link: http://lkml.kernel.org/r/20210108224650.25872-1-rikard.falkeborn@gmail.com
    Signed-off-by: Rikard Falkeborn
    Signed-off-by: Dominique Martinet

    Rikard Falkeborn
     

13 Mar, 2021

1 commit


08 Mar, 2021

1 commit

  • inode_wrong_type(inode, mode) returns true if setting inode->i_mode
    to given value would've changed the inode type. We have enough of
    those checks open-coded to make a helper worthwhile.

    Signed-off-by: Al Viro

    Al Viro
     

28 Feb, 2021

1 commit


23 Feb, 2021

1 commit

  • 1) sscanf() return value needs to be checked, damnit
    2) sscanf() is perfectly capable of checking for fixed prefix,
    no need for that %13s + strncmp with constant string.
    3) st->extension is a valid string; no need for voodoo with
    str*cpy() there.

    Signed-off-by: Al Viro

    Al Viro
     

24 Jan, 2021

5 commits

  • Extend some inode methods with an additional user namespace argument. A
    filesystem that is aware of idmapped mounts will receive the user
    namespace the mount has been marked with. This can be used for
    additional permission checking and also to enable filesystems to
    translate between uids and gids if they need to. We have implemented all
    relevant helpers in earlier patches.

    As requested we simply extend the exisiting inode method instead of
    introducing new ones. This is a little more code churn but it's mostly
    mechanical and doesnt't leave us with additional inode methods.

    Link: https://lore.kernel.org/r/20210121131959.646623-25-christian.brauner@ubuntu.com
    Cc: Christoph Hellwig
    Cc: David Howells
    Cc: Al Viro
    Cc: linux-fsdevel@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Christian Brauner

    Christian Brauner
     
  • The generic_fillattr() helper fills in the basic attributes associated
    with an inode. Enable it to handle idmapped mounts. If the inode is
    accessed through an idmapped mount map it into the mount's user
    namespace before we store the uid and gid. If the initial user namespace
    is passed nothing changes so non-idmapped mounts will see identical
    behavior as before.

    Link: https://lore.kernel.org/r/20210121131959.646623-12-christian.brauner@ubuntu.com
    Cc: Christoph Hellwig
    Cc: David Howells
    Cc: Al Viro
    Cc: linux-fsdevel@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Reviewed-by: James Morris
    Signed-off-by: Christian Brauner

    Christian Brauner
     
  • The posix acl permission checking helpers determine whether a caller is
    privileged over an inode according to the acls associated with the
    inode. Add helpers that make it possible to handle acls on idmapped
    mounts.

    The vfs and the filesystems targeted by this first iteration make use of
    posix_acl_fix_xattr_from_user() and posix_acl_fix_xattr_to_user() to
    translate basic posix access and default permissions such as the
    ACL_USER and ACL_GROUP type according to the initial user namespace (or
    the superblock's user namespace) to and from the caller's current user
    namespace. Adapt these two helpers to handle idmapped mounts whereby we
    either map from or into the mount's user namespace depending on in which
    direction we're translating.
    Similarly, cap_convert_nscap() is used by the vfs to translate user
    namespace and non-user namespace aware filesystem capabilities from the
    superblock's user namespace to the caller's user namespace. Enable it to
    handle idmapped mounts by accounting for the mount's user namespace.

    In addition the fileystems targeted in the first iteration of this patch
    series make use of the posix_acl_chmod() and, posix_acl_update_mode()
    helpers. Both helpers perform permission checks on the target inode. Let
    them handle idmapped mounts. These two helpers are called when posix
    acls are set by the respective filesystems to handle this case we extend
    the ->set() method to take an additional user namespace argument to pass
    the mount's user namespace down.

    Link: https://lore.kernel.org/r/20210121131959.646623-9-christian.brauner@ubuntu.com
    Cc: Christoph Hellwig
    Cc: David Howells
    Cc: Al Viro
    Cc: linux-fsdevel@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Christian Brauner

    Christian Brauner
     
  • When file attributes are changed most filesystems rely on the
    setattr_prepare(), setattr_copy(), and notify_change() helpers for
    initialization and permission checking. Let them handle idmapped mounts.
    If the inode is accessed through an idmapped mount map it into the
    mount's user namespace. Afterwards the checks are identical to
    non-idmapped mounts. If the initial user namespace is passed nothing
    changes so non-idmapped mounts will see identical behavior as before.

    Helpers that perform checks on the ia_uid and ia_gid fields in struct
    iattr assume that ia_uid and ia_gid are intended values and have already
    been mapped correctly at the userspace-kernelspace boundary as we
    already do today. If the initial user namespace is passed nothing
    changes so non-idmapped mounts will see identical behavior as before.

    Link: https://lore.kernel.org/r/20210121131959.646623-8-christian.brauner@ubuntu.com
    Cc: Christoph Hellwig
    Cc: David Howells
    Cc: Al Viro
    Cc: linux-fsdevel@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Christian Brauner

    Christian Brauner
     
  • The inode_owner_or_capable() helper determines whether the caller is the
    owner of the inode or is capable with respect to that inode. Allow it to
    handle idmapped mounts. If the inode is accessed through an idmapped
    mount it according to the mount's user namespace. Afterwards the checks
    are identical to non-idmapped mounts. If the initial user namespace is
    passed nothing changes so non-idmapped mounts will see identical
    behavior as before.

    Similarly, allow the inode_init_owner() helper to handle idmapped
    mounts. It initializes a new inode on idmapped mounts by mapping the
    fsuid and fsgid of the caller from the mount's user namespace. If the
    initial user namespace is passed nothing changes so non-idmapped mounts
    will see identical behavior as before.

    Link: https://lore.kernel.org/r/20210121131959.646623-7-christian.brauner@ubuntu.com
    Cc: Christoph Hellwig
    Cc: David Howells
    Cc: Al Viro
    Cc: linux-fsdevel@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Reviewed-by: James Morris
    Signed-off-by: Christian Brauner

    Christian Brauner
     

22 Dec, 2020

1 commit

  • Pull 9p update from Dominique Martinet:

    - fix long-standing limitation on open-unlink-fop pattern

    - add refcount to p9_fid (fixes the above and will allow for more
    cleanups and simplifications in the future)

    * tag '9p-for-5.11-rc1' of git://github.com/martinetd/linux:
    9p: Remove unnecessary IS_ERR() check
    9p: Uninitialized variable in v9fs_writeback_fid()
    9p: Fix writeback fid incorrectly being attached to dentry
    9p: apply review requests for fid refcounting
    9p: add refcount to p9_fid struct
    fs/9p: search open fids first
    fs/9p: track open fids
    fs/9p: fix create-unlink-getattr idiom

    Linus Torvalds
     

02 Dec, 2020

2 commits

  • The default splice operations got removed recently, add it back to 9p
    with iter_file_splice_write like many other filesystems do.

    Link: http://lkml.kernel.org/r/1606837496-21717-1-git-send-email-asmadeus@codewreck.org
    Fixes: 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")
    Signed-off-by: Dominique Martinet
    Acked-by: Toke Høiland-Jørgensen
    Reviewed-by: Christoph Hellwig

    Dominique Martinet
     
  • The v9fs file operations were missing the splice_read operations, which
    breaks sendfile() of files on such a filesystem. I discovered this while
    trying to load an eBPF program using iproute2 inside a 'virtme' environment
    which uses 9pfs for the virtual file system. iproute2 relies on sendfile()
    with an AF_ALG socket to hash files, which was erroring out in the virtual
    environment.

    Since generic_file_splice_read() seems to just implement splice_read in
    terms of the read_iter operation, I simply added the generic implementation
    to the file operations, which fixed the error I was seeing. A quick grep
    indicates that this is what most other file systems do as well.

    Link: http://lkml.kernel.org/r/20201201135409.55510-1-toke@redhat.com
    Fixes: 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")
    Signed-off-by: Toke Høiland-Jørgensen
    Signed-off-by: Dominique Martinet

    Toke Høiland-Jørgensen
     

01 Dec, 2020

2 commits

  • The "fid" variable can't be an error pointer so there is no need to
    check. The code is slightly cleaner if we move the increment before
    the break and remove the NULL check as well.

    Signed-off-by: Dan Carpenter
    Signed-off-by: Dominique Martinet

    Dan Carpenter
     
  • If v9fs_fid_lookup_with_uid() fails then "fid" is not initialized.

    The v9fs_fid_lookup_with_uid() can't return NULL. If it returns an
    error pointer then we can still pass that to clone_fid() and it will
    return the error pointer back again.

    Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct")
    Signed-off-by: Dan Carpenter
    Signed-off-by: Dominique Martinet

    Dan Carpenter
     

20 Nov, 2020

3 commits

  • v9fs_dir_release needs fid->ilist to have been initialized for filp's
    fid, not the inode's writeback fid's.

    With refcounting this can be improved on later but this appears to fix
    null deref issues.

    Link: http://lkml.kernel.org/r/1605802012-31133-3-git-send-email-asmadeus@codewreck.org
    Fixes: 6636b6dcc3db ("fs/9p: track open fids")
    Signed-off-by: Dominique Martinet

    Dominique Martinet
     
  • Fix style issues in parent commit ("apply review requests for fid
    refcounting"), no functional change.

    Link: http://lkml.kernel.org/r/1605802012-31133-2-git-send-email-asmadeus@codewreck.org
    Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct")
    Signed-off-by: Dominique Martinet

    Dominique Martinet
     
  • Fix race issue in fid contention.

    Eric's and Greg's patch offer a mechanism to fix open-unlink-f*syscall
    bug in 9p. But there is race issue in fid parallel accesses.
    As Greg's patch stores all of fids from opened files into according inode,
    so all the lookup fid ops can retrieve fid from inode preferentially. But
    there is no mechanism to handle the fid contention issue. For example,
    there are two threads get the same fid in the same time and one of them
    clunk the fid before the other thread ready to discard the fid. In this
    scenario, it will lead to some fatal problems, even kernel core dump.

    I introduce a mechanism to fix this race issue. A counter field introduced
    into p9_fid struct to store the reference counter to the fid. When a fid
    is allocated from the inode or dentry, the counter will increase, and
    will decrease at the end of its occupation. It is guaranteed that the
    fid won't be clunked before the reference counter go down to 0, then
    we can avoid the clunked fid to be used.

    tests:
    race issue test from the old test case:
    for file in {01..50}; do touch f.${file}; done
    seq 1 1000 | xargs -n 1 -P 50 -I{} cat f.* > /dev/null

    open-unlink-f*syscall test:
    I have tested for f*syscall include: ftruncate fstat fchown fchmod faccessat.

    Link: http://lkml.kernel.org/r/20200923141146.90046-5-jianyong.wu@arm.com
    Fixes: 478ba09edc1f ("fs/9p: search open fids first")
    Signed-off-by: Jianyong Wu
    Signed-off-by: Dominique Martinet

    Jianyong Wu
     

03 Nov, 2020

3 commits

  • A previous patch fixed the "create-unlink-getattr" idiom: if getattr is
    called on an unlinked file, we try to find an open fid attached to the
    corresponding inode.

    We have a similar issue with file permissions and setattr:

    open("./test.txt", O_RDWR|O_CREAT, 0666) = 4
    chmod("./test.txt", 0) = 0
    truncate("./test.txt", 0) = -1 EACCES (Permission denied)
    ftruncate(4, 0) = -1 EACCES (Permission denied)

    The failure is expected with truncate() but not with ftruncate().

    This happens because the lookup code does find a matching fid in the
    dentry list. Unfortunately, this is not an open fid and the server
    will be forced to rely on the path name, rather than on an open file
    descriptor. This is the case in QEMU: the setattr operation will use
    truncate() and fail because of bad write permissions.

    This patch changes the logic in the lookup code, so that we consider
    open fids first. It gives a chance to the server to match this open
    fid to an open file descriptor and use ftruncate() instead of truncate().
    This does not change the current behaviour for truncate() and other
    path name based syscalls, since file permissions are checked earlier
    in the VFS layer.

    With this patch, we get:

    open("./test.txt", O_RDWR|O_CREAT, 0666) = 4
    chmod("./test.txt", 0) = 0
    truncate("./test.txt", 0) = -1 EACCES (Permission denied)
    ftruncate(4, 0) = 0

    Link: http://lkml.kernel.org/r/20200923141146.90046-4-jianyong.wu@arm.com
    Signed-off-by: Greg Kurz
    Signed-off-by: Jianyong Wu
    Signed-off-by: Dominique Martinet

    Greg Kurz
     
  • This patch adds accounting of open fids in a list hanging off the i_private
    field of the corresponding inode. This allows faster lookups compared to
    searching the full 9p client list.

    The lookup code is modified accordingly.

    Link: http://lkml.kernel.org/r/20200923141146.90046-3-jianyong.wu@arm.com
    Signed-off-by: Greg Kurz
    Signed-off-by: Jianyong Wu
    Signed-off-by: Dominique Martinet

    Greg Kurz
     
  • Fixes several outstanding bug reports of not being able to getattr from an
    open file after an unlink. This patch cleans up transient fids on an unlink
    and will search open fids on a client if it detects a dentry that appears to
    have been unlinked. This search is necessary because fstat does not pass fd
    information through the VFS API to the filesystem, only the dentry which for
    9p has an imperfect match to fids.

    Inherent in this patch is also a fix for the qid handling on create/open
    which apparently wasn't being set correctly and was necessary for the search
    to succeed.

    A possible optimization over this fix is to include accounting of open fids
    with the inode in the private data (in a similar fashion to the way we track
    transient fids with dentries). This would allow a much quicker search for
    a matching open fid.

    (changed v9fs_fid_find_global to v9fs_fid_find_inode in comment)

    Link: http://lkml.kernel.org/r/20200923141146.90046-2-jianyong.wu@arm.com
    Signed-off-by: Eric Van Hensbergen
    Signed-off-by: Greg Kurz
    Signed-off-by: Jianyong Wu
    Signed-off-by: Dominique Martinet

    Eric Van Hensbergen
     

25 Oct, 2020

1 commit

  • Pull misc vfs updates from Al Viro:
    "Assorted stuff all over the place (the largest group here is
    Christoph's stat cleanups)"

    * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    fs: remove KSTAT_QUERY_FLAGS
    fs: remove vfs_stat_set_lookup_flags
    fs: move vfs_fstatat out of line
    fs: implement vfs_stat and vfs_lstat in terms of vfs_fstatat
    fs: remove vfs_statx_fd
    fs: omfs: use kmemdup() rather than kmalloc+memcpy
    [PATCH] reduce boilerplate in fsid handling
    fs: Remove duplicated flag O_NDELAY occurring twice in VALID_OPEN_FLAGS
    selftests: mount: add nosymfollow tests
    Add a "nosymfollow" mount option.

    Linus Torvalds
     

23 Oct, 2020

1 commit

  • Pull 9p updates from Dominique Martinet:
    "A couple of small fixes (loff_t overflow on 32bit, syzbot
    uninitialized variable warning) and code cleanup (xen)"

    * tag '9p-for-5.10-rc1' of git://github.com/martinetd/linux:
    net: 9p: initialize sun_server.sun_path to have addr's value only when addr is valid
    9p/xen: Fix format argument warning
    9P: Cast to loff_t before multiplying

    Linus Torvalds
     

08 Oct, 2020

1 commit

  • On 32-bit systems, this multiplication will overflow for files larger
    than 4GB.

    Link: http://lkml.kernel.org/r/20201004180428.14494-2-willy@infradead.org
    Cc: stable@vger.kernel.org
    Fixes: fb89b45cdfdc ("9P: introduction of a new cache=mmap model.")
    Signed-off-by: Matthew Wilcox (Oracle)
    Signed-off-by: Dominique Martinet

    Matthew Wilcox (Oracle)
     

25 Sep, 2020

2 commits

  • Replace the two negative flags that are always used together with a
    single positive flag that indicates the writeback capability instead
    of two related non-capabilities. Also remove the pointless wrappers
    to just check the flag.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Jan Kara
    Reviewed-by: Johannes Thumshirn
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     
  • Set up a readahead size by default, as very few users have a good
    reason to change it. This means code, ecryptfs, and orangefs now
    set up the values while they were previously missing it, while ubifs,
    mtd and vboxsf manually set it to 0 to avoid readahead.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Jan Kara
    Acked-by: David Sterba [btrfs]
    Acked-by: Richard Weinberger [ubifs, mtd]
    Signed-off-by: Jens Axboe

    Christoph Hellwig