Commit Graph

102 Commits

Author SHA1 Message Date
Ian Kent b994812892 autofs: fix thinko in validate_dev_ioctl()
JIRA: https://issues.redhat.com/browse/RHEL-67294
Upstream status: Linus

commit f19910006effbd08398de79ca0233ea7e480616a
Author: Ian Kent <raven@themaw.net>
Date:   Mon Oct 28 06:47:17 2024 +0800

    autofs: fix thinko in validate_dev_ioctl()

    I was so sure the per-dentry expire timeout patch worked ok but my
    testing was flawed.

    In validate_dev_ioctl() the check for ioctl AUTOFS_DEV_IOCTL_TIMEOUT_CMD
    should use the ioctl number not the passed in ioctl command.

    Fixes: 433f9d76a010 ("autofs: add per dentry expire timeout")
    Cc: <stable@vger.kernel.org> # mainline only
    Signed-off-by: Ian Kent <raven@themaw.net>
    Link: https://lore.kernel.org/r/20241027224732.5507-1-raven@themaw.net
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-11-29 14:56:09 +08:00
Ian Kent 0def070f24 autofs: add per dentry expire timeout
JIRA: https://issues.redhat.com/browse/RHEL-67294
Upstream status: Linus

commit 433f9d76a01056dfeaefc15167b11e514e56f956
Author: Ian Kent <raven@themaw.net>
Date:   Wed Aug 14 17:02:31 2024 +0800

    autofs: add per dentry expire timeout

    Add ability to set per-dentry mount expire timeout to autofs.

    There are two fairly well known automounter map formats, the autofs
    format and the amd format (more or less System V and Berkley).

    Some time ago Linux autofs added an amd map format parser that
    implemented a fair amount of the amd functionality. This was done
    within the autofs infrastructure and some functionality wasn't
    implemented because it either didn't make sense or required extra
    kernel changes. The idea was to restrict changes to be within the
    existing autofs functionality as much as possible and leave changes
    with a wider scope to be considered later.

    One of these changes is implementing the amd options:
    1) "unmount", expire this mount according to a timeout (same as the
       current autofs default).
    2) "nounmount", don't expire this mount (same as setting the autofs
       timeout to 0 except only for this specific mount) .
    3) "utimeout=<seconds>", expire this mount using the specified
       timeout (again same as setting the autofs timeout but only for
       this mount).

    To implement these options per-dentry expire timeouts need to be
    implemented for autofs indirect mounts. This is because all map keys
    (mounts) for autofs indirect mounts use an expire timeout stored in
    the autofs mount super block info. structure and all indirect mounts
    use the same expire timeout.

    Now I have a request to add the "nounmount" option so I need to add
    the per-dentry expire handling to the kernel implementation to do this.

    The implementation uses the trailing path component to identify the
    mount (and is also used as the autofs map key) which is passed in the
    autofs_dev_ioctl structure path field. The expire timeout is passed
    in autofs_dev_ioctl timeout field (well, of the timeout union).

    If the passed in timeout is equal to -1 the per-dentry timeout and
    flag are cleared providing for the "unmount" option. If the timeout
    is greater than or equal to 0 the timeout is set to the value and the
    flag is also set. If the dentry timeout is 0 the dentry will not expire
    by timeout which enables the implementation of the "nounmount" option
    for the specific mount. When the dentry timeout is greater than zero it
    allows for the implementation of the "utimeout=<seconds>" option.

    Signed-off-by: Ian Kent <raven@themaw.net>
    Link: https://lore.kernel.org/r/20240814090231.963520-1-raven@themaw.net
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-11-29 14:53:51 +08:00
Ian Kent 304ec491ee fs: port ->permission() to pass mnt_idmap
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

Conflicts: For consistency drop btrfs hunks because it isn't supported in
	CentOS Stream and other backports also drop such hunks.
	CentOS Stream commit 48fa94aacd ("ceph: fscrypt_auth handling
	for ceph") is presnt which causes fuzz 2 in hunk #1 in
	fs/ceph/super.h.
	Upstream commit 427505ffeaa46 ("exportfs: use pr_debug for
	unreachable debug statements") is not present causing fuzz 2
	in hunk #1 against fs/exportfs/expfs.c.
	Dropped hunks for ksmbd because the source is not present in the
	CentOS Stream source tree.
	Upstream commit 03fa86e9f79d8 ("namei: stash the sampled ->d_seq
	into nameidata") is not present causing a fuzz 1 for hunk #14
	against fs/namei.c.
	CentOS Stream c4f3dd0731 ("nfsd: handle failure to collect
	pre/post-op attrs more sanely") is present and causes a rejects
	for hunks #4 and #5 against fs/nfsd/vfs.c, apply manually.
	Dropped hunks for ntfs3 because the source is not present in the
	CentOS Stream source tree.
	CentOS Stream commit 98ba731fc7 ("ovl: Move xattr support to
	new xattrs.c file") moves ovl_xattr_set() and ovl_xattr_get()
	from fs/overlayfs/inode.c to fs/overlayfs/xattrs.c which causes
	hunks #4 and #5 to fail, manually apply to fs/overlayfs/xattrs.c.
	CentOS Stream commit 55177e4b83 ("ovl: mark xwhiteouts directory
	with overlay.opaque='x'") and commit d17b324bb6 ("ovl: use
	ovl_numlower() and ovl_lowerstack() accessors") change the first
	and third hunks of fs/overlayfs/namei.c causing them to fail,
	manually apply.
	CentOS Stream commit 98ba731fc7 ("ovl: Move xattr support to
	new xattrs.c file") causes fuzz 2 in hunk #5 of
	fs/overlayfs/overlayfs.h
	CentOS Stream commit 355a9c490a ("ovl: Add an alternative
	type of whiteout") changes ovl_cache_update_ino() to
	ovl_cache_update() in fs/overlayfs/readdir.c, make the change
	manually.
	Upstream commit 217af7e2f4deb ("apparmor: refactor profile
	rules and attachments") is not in CentOS Stream causing hunk #1
	to fail to apply so manually apply the change.

commit 4609e1f18e19c3b302e1eb4858334bca1532f780
Author: Christian Brauner <brauner@kernel.org>
Date:   Fri Jan 13 12:49:22 2023 +0100

    fs: port ->permission() to pass mnt_idmap

    Convert to struct mnt_idmap.

    Last cycle we merged the necessary infrastructure in
    256c8aed2b42 ("fs: introduce dedicated idmap type for mounts").
    This is just the conversion to struct mnt_idmap.

    Currently we still pass around the plain namespace that was attached to a
    mount. This is in general pretty convenient but it makes it easy to
    conflate namespaces that are relevant on the filesystem with namespaces
    that are relevent on the mount level. Especially for non-vfs developers
    without detailed knowledge in this area this can be a potential source for
    bugs.

    Once the conversion to struct mnt_idmap is done all helpers down to the
    really low-level helpers will take a struct mnt_idmap argument instead of
    two namespace arguments. This way it becomes impossible to conflate the two
    eliminating the possibility of any bugs. All of the vfs and all filesystems
    only operate on struct mnt_idmap.

    Acked-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:45:20 +08:00
Ian Kent a7750be4f4 fs: port ->mkdir() to pass mnt_idmap
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

Conflicts: For consistency drop btrfs hunks because it isn't supported in
	CentOS Stream and other backports also drop such hunks.
	The cifs source has been moved in CentOS Stream so manually
	apply rejected hunks to fs/smb/client/cifsfs.h and
	fs/smb/client/inode.c.
	Dropped hunks for ntfs3 because the source is not present in the
	CentOS Stream source tree.

commit c54bd91e9eaba43f09aadc25b52ea869ff3b5587
Author: Christian Brauner <brauner@kernel.org>
Date:   Fri Jan 13 12:49:15 2023 +0100

    fs: port ->mkdir() to pass mnt_idmap

    Convert to struct mnt_idmap.

    Last cycle we merged the necessary infrastructure in
    256c8aed2b42 ("fs: introduce dedicated idmap type for mounts").
    This is just the conversion to struct mnt_idmap.

    Currently we still pass around the plain namespace that was attached to a
    mount. This is in general pretty convenient but it makes it easy to
    conflate namespaces that are relevant on the filesystem with namespaces
    that are relevent on the mount level. Especially for non-vfs developers
    without detailed knowledge in this area this can be a potential source for
    bugs.

    Once the conversion to struct mnt_idmap is done all helpers down to the
    really low-level helpers will take a struct mnt_idmap argument instead of
    two namespace arguments. This way it becomes impossible to conflate the two
    eliminating the possibility of any bugs. All of the vfs and all filesystems
    only operate on struct mnt_idmap.

    Acked-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:45:00 +08:00
Ian Kent 5744ba0ee3 fs: port ->symlink() to pass mnt_idmap
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

Conflicts: The cifs source has been moved in CentOS Stream so manually
	apply rejected hunks to fs/smb/client/cifsfs.h and
	fs/smb/client/link.c.
	Dropped hunks for ntfs3 because the source is not present in the
	CentOS Stream source tree.
	CentOS Stream commit f0f830cd7e ("ceph: create symlinks with
	encrypted and base64-encoded targets") is present and resulted
	in fuzz against fs/ceph/dir.c.

commit 7a77db95511c39be4b2db2ceca152ef589adc2dc
Author: Christian Brauner <brauner@kernel.org>
Date:   Fri Jan 13 12:49:14 2023 +0100

    fs: port ->symlink() to pass mnt_idmap

    Convert to struct mnt_idmap.

    Last cycle we merged the necessary infrastructure in
    256c8aed2b42 ("fs: introduce dedicated idmap type for mounts").
    This is just the conversion to struct mnt_idmap.

    Currently we still pass around the plain namespace that was attached to a
    mount. This is in general pretty convenient but it makes it easy to
    conflate namespaces that are relevant on the filesystem with namespaces
    that are relevent on the mount level. Especially for non-vfs developers
    without detailed knowledge in this area this can be a potential source for
    bugs.

    Once the conversion to struct mnt_idmap is done all helpers down to the
    really low-level helpers will take a struct mnt_idmap argument instead of
    two namespace arguments. This way it becomes impossible to conflate the two
    eliminating the possibility of any bugs. All of the vfs and all filesystems
    only operate on struct mnt_idmap.

    Acked-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:45:00 +08:00
Ian Kent 292b1b165f autofs: remove unused ino field inode
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

commit 7ffe4e90a061a2f612b3b8c29b583ec3b707781f
Author: Ian Kent <raven@themaw.net>
Date:   Fri Jul 8 09:43:23 2022 +0800

    autofs: remove unused ino field inode

    Remove the unused inode field of the autofs dentry info structure.

    Link: https://lkml.kernel.org/r/165724460393.30914.6511330213821246793.stgit@donald.themaw.net
    Signed-off-by: Ian Kent <raven@themaw.net>
    Cc: Al Viro <viro@ZenIV.linux.org.uk>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Miklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:44:59 +08:00
Ian Kent f99c69f3df autofs: add comment about autofs_mountpoint_changed()
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

commit ba97a0a3a31a2451607ebf601c0b7c4b1322ce9a
Author: Ian Kent <raven@themaw.net>
Date:   Fri Jul 8 09:43:18 2022 +0800

    autofs: add comment about autofs_mountpoint_changed()

    The function autofs_mountpoint_changed() is unusual, add a comment about
    two cases for which it is needed.

    Link: https://lkml.kernel.org/r/165724459804.30914.10974834416046555127.stgit@donald.themaw.net
    Signed-off-by: Ian Kent <raven@themaw.net>
    Cc: Al Viro <viro@ZenIV.linux.org.uk>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Miklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:44:57 +08:00
Ian Kent 166165f823 autofs: use dentry info count instead of simple_empty()
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

Conflicts: CentOS Stream commit 7f1fb7b62c ("dentry: switch the lists
	of children to hlist") results in hunk #6 in fs/autofs/root.c,
	manually apply hunk.

commit a4a87303874c1a7d49cc18a8fe33676b0002ffbf
Author: Ian Kent <raven@themaw.net>
Date:   Fri Jul 8 09:43:12 2022 +0800

    autofs: use dentry info count instead of simple_empty()

    The dentry info.  field count is used to check if a dentry is in use
    during expire.  But, to be used for this the count field must account for
    the presence of child dentries in a directory dentry.

    Therefore it can also be used to check for an empty directory dentry which
    can be done without having to to take an additional lock or account for
    the presence of a readdir cursor dentry as is done by simple_empty().

    Link: https://lkml.kernel.org/r/165724459238.30914.1504611159945950108.stgit@donald.themaw.net
    Signed-off-by: Ian Kent <raven@themaw.net>
    Cc: Al Viro <viro@ZenIV.linux.org.uk>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Miklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:44:56 +08:00
Ian Kent 9958c76bbe autofs: make dentry info count consistent
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

commit 9ccbac76e71de411b9c4beea9d91ba98f3fad690
Author: Ian Kent <raven@themaw.net>
Date:   Fri Jul 8 09:43:06 2022 +0800

    autofs: make dentry info count consistent

    If an autofs dentry is a mount root directory there's no ->mkdir() call to
    set its count to one.

    To make the dentry info count consistent for all autofs dentries set count
    to one when the dentry info struct is allocated.

    Link: https://lkml.kernel.org/r/165724458671.30914.2902424437132835325.stgit@donald.themaw.net
    Signed-off-by: Ian Kent <raven@themaw.net>
    Cc: Al Viro <viro@ZenIV.linux.org.uk>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Miklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:44:55 +08:00
Ian Kent 5bee4d17af autofs: use inode permission method for write access
JIRA: https://issues.redhat.com/browse/RHEL-33888
Status: Linus

commit f71381fcdc3ab615f55278d435a9f35542dc9e63
Author: Ian Kent <raven@themaw.net>
Date:   Fri Jul 8 09:43:01 2022 +0800

    autofs: use inode permission method for write access

    Patch series "autofs: misc patches".

    This series contains several patches that resulted mostly from comments
    made by Al Viro (quite a long time ago now).

    This patch (of 5):

    Eliminate some code duplication from mkdir/rmdir/symlink/unlink methods by
    using the inode operation .permission().

    Link: https://lkml.kernel.org/r/165724445154.30914.10970894936827635879.stgit@donald.themaw.net
    Link: https://lkml.kernel.org/r/165724458096.30914.13499431569758625806.stgit@donald.themaw.net
    Signed-off-by: Ian Kent <raven@themaw.net>
    Cc: Al Viro <viro@ZenIV.linux.org.uk>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Miklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Ian Kent <ikent@redhat.com>
2024-10-16 10:44:54 +08:00
Ming Lei 7f1fb7b62c dentry: switch the lists of children to hlist
JIRA: https://issues.redhat.com/browse/RHEL-29564
Conflicts: drop change in tracefs because rhel9 tracefs doesn't
	use d->subdirs; add one extra conversion in fs/autofs.c;
	cover conversion in remove_event_file_dir()

commit da549bdd15c295c24b2ee7ffe7ad0f3877fa8a87
Author: Al Viro <viro@zeniv.linux.org.uk>
Date:   Tue Nov 7 02:00:39 2023 -0500

    dentry: switch the lists of children to hlist

    Saves a pointer per struct dentry and actually makes the things less
    clumsy.  Cleaned the d_walk() and dcache_readdir() a bit by use
    of hlist_for_... iterators.

    A couple of new helpers - d_first_child() and d_next_sibling(),
    to make the expressions less awful.

    Reviewed-by: Christian Brauner <brauner@kernel.org>
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Ming Lei <ming.lei@redhat.com>
2024-04-17 09:46:42 +08:00
Prarit Bhargava 509ec2d51f arch/*/configs/*defconfig: Replace AUTOFS4_FS by AUTOFS_FS
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.  Note this change also includes
redhat/config renames.

commit 1f2190d6b7112d22d3f8dfeca16a2f6a2f51444e
Author: Sven Joachim <svenjoac@gmx.de>
Date:   Thu Jul 27 22:00:41 2023 +0200

    arch/*/configs/*defconfig: Replace AUTOFS4_FS by AUTOFS_FS

    Commit a2225d931f ("autofs: remove left-over autofs4 stubs")
    promised the removal of the fs/autofs/Kconfig fragment for AUTOFS4_FS
    within a couple of releases, but five years later this still has not
    happened yet, and AUTOFS4_FS is still enabled in 63 defconfigs.

    Get rid of it mechanically:

       git grep -l CONFIG_AUTOFS4_FS -- '*defconfig' |
           xargs sed -i 's/AUTOFS4_FS/AUTOFS_FS/'

    Also just remove the AUTOFS4_FS config option stub.  Anybody who hasn't
    regenerated their config file in the last five years will need to just
    get the new name right when they do.

    Signed-off-by: Sven Joachim <svenjoac@gmx.de>
    Acked-by: Ian Kent <raven@themaw.net>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:14 -04:00
Ian Kent 69eb1b1584 autofs: fix wait name hash calculation in autofs_wait()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2185245
Status: Linus

commit 25f54d08f12feb593e62cc2193fedefaf7825301
Author: Ian Kent <raven@themaw.net>
Date:   Thu Sep 23 15:13:39 2021 +0800

	autofs: fix wait name hash calculation in autofs_wait()

	There's a mistake in commit 2be7828c9f ("get rid of autofs_getpath()")
	that affects kernels from v5.13.0, basically missed because of me not
	fully testing the change for Al.

	The problem is that the hash calculation for the wait name qstr hasn't
	been updated to account for the change to use dentry_path_raw(). This
	prevents the correct matching an existing wait resulting in multiple
	notifications being sent to the daemon for the same mount which must
	not occur.

	The problem wasn't discovered earlier because it only occurs when
	multiple processes trigger a request for the same mount concurrently
	so it only shows up in more aggressive testing.

	Fixes: 2be7828c9f ("get rid of autofs_getpath()")
	Cc: stable@vger.kernel.org
	Signed-off-by: Ian Kent <raven@themaw.net>
	Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Ian Kent <ikent@redhat.com>
2023-04-17 09:57:07 +08:00
Al Viro eecf77e097 autofs: should_expire() argument is guaranteed to be positive
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2021-03-24 14:14:27 -04:00
Al Viro 2be7828c9f get rid of autofs_getpath()
allow wq->name.name to point not at the beginning of the object containing
the string, with wq->offset telling how far into it we are.  Then we can
bloody well just use dentry_path_raw() instead of autofs_getpath() -
the only real difference is that dentry_path_raw() puts the result into
the end of buffer and returns where it starts.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2021-03-21 11:44:02 -04:00
Christian Brauner 549c729771
fs: make helpers idmap mount aware
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 <hch@lst.de>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-01-24 14:27:20 +01:00
Eric W. Biederman 1572bfdf21 file: Replace ksys_close with close_fd
Now that ksys_close is exactly identical to close_fd replace
the one caller of ksys_close with close_fd.

[1] https://lkml.kernel.org/r/20200818112020.GA17080@infradead.org
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lkml.kernel.org/r/20201120231441.29911-22-ebiederm@xmission.com
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
2020-12-10 12:42:59 -06:00
Matthew Wilcox 589f6b5268 autofs: harden ioctl table
The table of ioctl functions should be marked const in order to put them
in read-only memory, and we should use array_index_nospec() to avoid
speculation disclosing the contents of kernel memory to userspace.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Ian Kent <raven@themaw.net>
Link: https://lkml.kernel.org/r/20200818122203.GO17456@casper.infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-16 11:11:22 -07:00
Linus Torvalds 90fb702791 autofs: use __kernel_write() for the autofs pipe writing
autofs got broken in some configurations by commit 13c164b1a1
("autofs: switch to kernel_write") because there is now an extra LSM
permission check done by security_file_permission() in rw_verify_area().

autofs is one if the few places that really does want the much more
limited __kernel_write(), because the write is an internal kernel one
that shouldn't do any user permission checks (it also doesn't need the
file_start_write/file_end_write logic, since it's just a pipe).

There are a couple of other cases like that - accounting, core dumping,
and splice - but autofs stands out because it can be built as a module.

As a result, we need to export this internal __kernel_write() function
again.

We really don't want any other module to use this, but we don't have a
"EXPORT_SYMBOL_FOR_AUTOFS_ONLY()".  But we can mark it GPL-only to at
least approximate that "internal use only" for licensing.

While in this area, make autofs pass in NULL for the file position
pointer, since it's always a pipe, and we now use a NULL file pointer
for streaming file descriptors (see file_ppos() and commit 438ab720c675:
"vfs: pass ppos=NULL to .read()/.write() of FMODE_STREAM files")

This effectively reverts commits 9db9775224 ("fs: unexport
__kernel_write") and 13c164b1a1 ("autofs: switch to kernel_write").

Fixes: 13c164b1a1 ("autofs: switch to kernel_write")
Reported-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Acked-by: Acked-by: Ian Kent <raven@themaw.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-29 17:18:34 -07:00
Randy Dunlap c734124c5c fs: autofs: delete repeated words in comments
Drop duplicated words {the, at} in comments.

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Ian Kent <raven@themaw.net>
Link: http://lkml.kernel.org/r/20200811021817.24982-1-rdunlap@infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-14 19:56:56 -07:00
Christoph Hellwig 13c164b1a1 autofs: switch to kernel_write
While pipes don't really need sb_writers projection, __kernel_write is an
interface better kept private, and the additional rw_verify_area does not
hurt here.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Ian Kent <raven@themaw.net>
2020-07-08 08:27:56 +02:00
Al Viro 161aff1d93 LOOKUP_MOUNTPOINT: fold path_mountpointat() into path_lookupat()
New LOOKUP flag, telling path_lookupat() to act as path_mountpointat().
IOW, traverse mounts at the final point and skip revalidation of the
location where it ends up.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-03-13 21:08:17 -04:00
Linus Torvalds b0d4beaa5a Merge branch 'next.autofs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull autofs updates from Al Viro:
 "autofs misuses checks for ->d_subdirs emptiness; the cursors are in
  the same lists, resulting in false negatives. It's not needed anyway,
  since autofs maintains counter in struct autofs_info, containing 0 for
  removed ones, 1 for live symlinks and 1 + number of children for live
  directories, which is precisely what we need for those checks.

  This series switches to use of that counter and untangles the crap
  around its uses (it needs not be atomic and there's a bunch of
  completely pointless "defensive" checks).

  This fell out of dcache_readdir work; the main point is to get rid of
  ->d_subdirs abuses in there. I've more followup cleanups, but I hadn't
  run those by Ian yet, so they can go next cycle"

* 'next.autofs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  autofs: don't bother with atomics for ino->count
  autofs_dir_rmdir(): check ino->count for deciding whether it's empty...
  autofs: get rid of pointless checks around ->count handling
  autofs_clear_leaf_automount_flags(): use ino->count instead of ->d_subdirs
2019-12-05 17:11:48 -08:00
Al Viro 03ad0d703d autofs: fix a leak in autofs_expire_indirect()
if the second call of should_expire() in there ends up
grabbing and returning a new reference to dentry, we need
to drop it before continuing.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-10-25 00:03:11 -04:00
Al Viro 850d71acd5 autofs: don't bother with atomics for ino->count
All writers are serialized on inode->i_rwsem.  So are the readers
outside of expire.c.  And the readers in expire.c are in the
code that really doesn't care about narrow races - it's looking
for expiry candidates and its callers have to cope with the
possibility of a good candidate becoming busy right under them.

No point bothering with atomic operations - just use int and
mark the non-serialized readers with READ_ONCE().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-09-17 23:31:27 -04:00
Al Viro c3aed16680 autofs_dir_rmdir(): check ino->count for deciding whether it's empty...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-09-17 23:28:08 -04:00
Al Viro 41ca19740a autofs: get rid of pointless checks around ->count handling
* IS_ROOT can't be true for unlink or rmdir victim
* any positive autofs dentry has non-NULL autofs_dentry_ino()
* autofs symlink can't have ->count other than 1
* autofs empty directory can't have ->count other than 1

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-09-17 23:23:08 -04:00
Al Viro e509d6e9c1 autofs_clear_leaf_automount_flags(): use ino->count instead of ->d_subdirs
We want to find out if the parent will become empty after we remove
the victim of rmdir().  Checking if the victim is the only element
of parent's ->d_subdirs is completely wrong - e.g. opening the parent
will end up with a cursor added to its ->d_parent and fooling the
check.

We do maintain ino->count - 0 for anything removed, 1 + number of
children for anything live.  Which gives us precisely what we need
for that check...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-09-17 22:16:58 -04:00
Al Viro 5f68056ca5 autofs_lookup(): hold ->d_lock over playing with ->d_flags
... as well as setting ->d_fsdata, etc.  Make all of that
atomic.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-07-27 10:03:14 -04:00
Al Viro c4931db9b0 get rid of autofs_info->active_count
autofs_add_active() is always called only once (and on a dentry
with freshly allocated ino, at that).  autofs_del_active() is
never called more than once.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-07-27 10:00:33 -04:00
Al Viro ff09297ec9 autofs: simplify get_next_positive_...(), get rid of trylocks
* new helper: positive_after(parent, child); parent->d_lock is
held by caller, grabs and returns the first thing after child
in the list of children that has simple_positive() true.  NULL
if nothing's found; NULL child == search the entire list.

* get_next_positive_subdir() loses the redundant check for
d_count and switches to use of that helper.  BTW, dput(NULL) is
a no-op for a good reason...

* get_next_positive_dentry() switched to the same helper.  Logics:
look for positive child in prev; if not found, look for the
positive child of prev's parent following prev, etc.  That way
we are guaranteed that we are only moving rootwards through the
ancestors of prev, which is pinned and thus not going anywhere.
Since ->d_parent on autofs never changes, the same goes for
the entire chain of ancestors and we don't need overlapping
->d_lock on them.  Which avoids the trylock loops, in addition
to simplifying the logics in there...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-07-24 23:02:21 -04:00
Thomas Gleixner d691005856 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 83
Based on 1 normalized pattern(s):

  this file is part of the linux kernel and is made available under
  the terms of the gnu general public license version 2 or at your
  option any later version incorporated herein by reference

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 18 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Richard Fontana <rfontana@redhat.com>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Armijn Hemel <armijn@tjaldur.nl>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190520075211.321157221@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-24 17:37:52 +02:00
Thomas Gleixner ec8f24b7fa treewide: Add SPDX license identifier - Makefile/Kconfig
Add SPDX license identifiers to all Make/Kconfig files which:

 - Have no license information of any form

These files fall under the project license, GPL v2 only. The resulting SPDX
license identifier is:

  GPL-2.0-only

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-21 10:50:46 +02:00
Al Viro ce285c267a autofs: fix use-after-free in lockless ->d_manage()
autofs_d_release() can overlap with lockless ->d_manage(),
ending up with autofs_dentry_ino() freed under the latter.
Make freeing autofs_info instances RCU-delayed...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-04-09 19:18:19 -04:00
NeilBrown 660c9fc72e autofs: clear O_NONBLOCK on the pipe
autofs does not expect the pipe it is given to have O_NONBLOCK set -
specifically if __kernel_write() in autofs_write() returns -EAGAIN, this
is treated as a fatal error and the pipe is closed.

For safety autofs should, therefore, clear the O_NONBLOCK flag.

Releases of systemd prior to 8th February 2019 used
  pipe2(p, O_NONBLOCK|O_CLOEXEC)
and thus (inadvertently) set this flag.

Link: http://lkml.kernel.org/r/154993550902.3321.1183632970046073478.stgit@pluto-themaw-net
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-03-07 18:32:01 -08:00
Ian Kent 874d22d62b fs/autofs/inode.c: use seq_puts() for simple strings in autofs_show_options()
Fix checkpatch.sh WARNING about the use of seq_printf() to print simple
strings in autofs_show_options(), use seq_puts() in this case.

Link: http://lkml.kernel.org/r/154889012613.4863.12231175554744203482.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-03-07 18:32:01 -08:00
Ian Kent 60d6d04ca3 autofs: add ignore mount option
Add an autofs file system mount option that can be used to provide a
generic indicator to applications that the mount entry should be ignored
when displaying mount information.

In other OSes that provide autofs and that provide a mount list to user
space based on the kernel mount list a no-op mount option ("ignore" is
the one use on the most common OS) is allowed so that autofs file system
users can optionally use it.

The idea is that it be used by user space programs to exclude autofs
mounts from consideration when reading the mounts list.

Prior to the change to link /etc/mtab to /proc/self/mounts all I needed
to do to achieve this was to use mount(2) and not update the mtab but
now that no longer works.

I know the symlinking happened a long time ago and I considered doing
this then but, at the time I couldn't remember the commonly used option
name and thought persuading the various utility maintainers would be too
hard.

But now I have a RHEL request to do this for compatibility for a widely
used product so I want to go ahead with it and try and enlist the help
of some utility package maintainers.

Clearly, without the option nothing can be done so it's at least a
start.

Link: http://lkml.kernel.org/r/154725123970.11260.6113771566924907275.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-03-07 18:32:01 -08:00
Ian Kent f585b283e3 autofs: fix error return in autofs_fill_super()
In autofs_fill_super() on error of get inode/make root dentry the return
should be ENOMEM as this is the only failure case of the called
functions.

Link: http://lkml.kernel.org/r/154725123240.11260.796773942606871359.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-02-01 15:46:24 -08:00
Pan Bian 63ce5f552b autofs: drop dentry reference only when it is never used
autofs_expire_run() calls dput(dentry) to drop the reference count of
dentry.  However, dentry is read via autofs_dentry_ino(dentry) after
that.  This may result in a use-free-bug.  The patch drops the reference
count of dentry only when it is never used.

Link: http://lkml.kernel.org/r/154725122396.11260.16053424107144453867.stgit@pluto-themaw-net
Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-02-01 15:46:24 -08:00
Ian Kent f5162216b7 autofs: add strictexpire mount option
Commit 092a53452b ("autofs: take more care to not update last_used on
path walk") helped to (partially) resolve a problem where automounts
were not expiring due to aggressive accesses from user space.

This patch was later reverted because, for very large environments, it
meant more mount requests from clients and when there are a lot of
clients this caused a fairly significant increase in server load.

But there is a need for both types of expire check, depending on use
case, so add a mount option to allow for strict update of last use of
autofs dentrys (which just means not updating the last use on path walk
access).

Link: http://lkml.kernel.org/r/154296973880.9889.14085372741514507967.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 13:13:47 -08:00
Ian Kent 9d8719a42e autofs: change catatonic setting to a bit flag
Change the superblock info.  catatonic setting to be part of a flags bit
field.

Link: http://lkml.kernel.org/r/154296973142.9889.17275721668508589639.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 13:13:47 -08:00
Ian Kent 9bf964c9ce autofs: simplify parse_options() function call
The parse_options() function uses a long list of parameters, most of
which are present in the super block info structure already.

The mount parameters set in parse_options() options don't require
cleanup so using the super block info struct directly is simpler.

Link: http://lkml.kernel.org/r/154296972423.9889.9368859245676473329.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 13:13:46 -08:00
Ian Kent 55f0d8205d autofs: improve ioctl sbi checks
Al Viro made some suggestions to improve the implementation of commit
0633da48f0 ("fix autofs_sbi() does not check super block type").

The check is unnecessary in all cases except for ioctl usage so placing
the check in the super block accessor function adds a small overhead to
the common case where it isn't needed.

So it's sufficient to do this in the ioctl code only.

Also the check in the ioctl code is needlessly complex.

[akpm@linux-foundation.org: declare autofs_fs_type in .h, not .c]
Link: http://lkml.kernel.org/r/154296970987.9889.1597442413573683096.stgit@pluto-themaw-net
Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 13:13:46 -08:00
Linus Torvalds cd9b44f907 Merge branch 'akpm' (patches from Andrew)
Merge more updates from Andrew Morton:

 - the rest of MM

 - procfs updates

 - various misc things

 - more y2038 fixes

 - get_maintainer updates

 - lib/ updates

 - checkpatch updates

 - various epoll updates

 - autofs updates

 - hfsplus

 - some reiserfs work

 - fatfs updates

 - signal.c cleanups

 - ipc/ updates

* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (166 commits)
  ipc/util.c: update return value of ipc_getref from int to bool
  ipc/util.c: further variable name cleanups
  ipc: simplify ipc initialization
  ipc: get rid of ids->tables_initialized hack
  lib/rhashtable: guarantee initial hashtable allocation
  lib/rhashtable: simplify bucket_table_alloc()
  ipc: drop ipc_lock()
  ipc/util.c: correct comment in ipc_obtain_object_check
  ipc: rename ipcctl_pre_down_nolock()
  ipc/util.c: use ipc_rcu_putref() for failues in ipc_addid()
  ipc: reorganize initialization of kern_ipc_perm.seq
  ipc: compute kern_ipc_perm.id under the ipc lock
  init/Kconfig: remove EXPERT from CHECKPOINT_RESTORE
  fs/sysv/inode.c: use ktime_get_real_seconds() for superblock stamp
  adfs: use timespec64 for time conversion
  kernel/sysctl.c: fix typos in comments
  drivers/rapidio/devices/rio_mport_cdev.c: remove redundant pointer md
  fork: don't copy inconsistent signal handler state to child
  signal: make get_signal() return bool
  signal: make sigkill_pending() return bool
  ...
2018-08-22 12:34:08 -07:00
Ian Kent cbf6898fd6 autofs: add AUTOFS_EXP_FORCED flag
The userspace automount(8) daemon is meant to perform a forced expire when
sent a SIGUSR2.

But since the expiration is routed through the kernel and the kernel
doesn't send an expire request if the mount is busy this hasn't worked at
least since autofs version 5.

Add an AUTOFS_EXP_FORCED flag to allow implemention of the feature and
bump the protocol version so user space can check if it's implemented if
needed.

Link: http://lkml.kernel.org/r/152937734715.21213.6594007182776598970.stgit@pluto.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:49 -07:00
Ian Kent e5c85e1fe1 autofs: make expire flags usage consistent with v5 params
Make the usage of the expire flags consistent by naming the expire flags
the same as it is named in the version 5 miscelaneous ioctl parameters and
only check the bit flags when needed.

Link: http://lkml.kernel.org/r/152937734046.21213.9454131988766280028.stgit@pluto.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:49 -07:00
Ian Kent 571bc35c42 autofs: make autofs_expire_indirect() static
autofs_expire_indirect() isn't used outside of fs/autofs/expire.c so make
it static.

Link: http://lkml.kernel.org/r/152937733512.21213.10509996499623738446.stgit@pluto.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:49 -07:00
Ian Kent 5d30517d67 autofs: make autofs_expire_direct() static
autofs_expire_direct() isn't used outside of fs/autofs/expire.c so make it
static.

Link: http://lkml.kernel.org/r/152937732944.21213.11821977712410930973.stgit@pluto.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:49 -07:00
Ian Kent d1055565bd autofs: fix clearing AUTOFS_EXP_LEAVES in autofs_expire_indirect()
The expire flag AUTOFS_EXP_LEAVES is cleared before the second call to
should_expire() in autofs_expire_indirect() but the parameter passed in
the second call is incorrect.

Fortunately AUTOFS_EXP_LEAVES expire flag has not been used for a long
time but might be needed in the future so fix it rather than remove the
expire leaves functionality.

Link: http://lkml.kernel.org/r/152937732410.21213.7447294898147765076.stgit@pluto.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:49 -07:00
Ian Kent 2fd9944f0f autofs: fix inconsistent use of now variable
The global variable "now" in fs/autofs/expire.c is used in an inconsistent
way, sometimes using jiffies directly, and sometimes using the "now"
variable, and setting it isn't done consistently either.

But the autofs dentry info last_used field is only updated during path
walks or during expire so jiffies can be used directly and the global
variable "now" removed.

Link: http://lkml.kernel.org/r/152937731702.21213.7371321165189170865.stgit@pluto.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:49 -07:00