Commit graph

1413186 commits

Author SHA1 Message Date
Al Viro
a0c3d1f3de user_statfs(): switch to CLASS(filename)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:04 -05:00
Al Viro
a4503461fb statx: switch to CLASS(filename_maybe_null)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:04 -05:00
Al Viro
ef7282e849 quotactl_block(): switch to CLASS(filename)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:04 -05:00
Al Viro
57483461e1 chroot(2): switch to CLASS(filename)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:04 -05:00
Al Viro
cbe9e300a2 move_mount(2): switch to CLASS(filename_maybe_null)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:04 -05:00
Al Viro
904f58b507 namei.c: switch user pathname imports to CLASS(filename{,_flags})
filename_flags is used by user_path_at().  I suspect that mixing
LOOKUP_EMPTY with real lookup flags had been a mistake all along; the
former belongs to pathname import, the latter - to pathwalk.  Right now
none of the remaining in-tree callers of user_path_at() are getting
LOOKUP_EMPTY in flags, so user_path_at() could probably be switched
to CLASS(filename)...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
e9817d5b8c namei.c: convert getname_kernel() callers to CLASS(filename_kernel)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
33b54bc799 do_f{chmod,chown,access}at(): use CLASS(filename_uflags)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
d4ffeabea7 do_readlinkat(): switch to CLASS(filename_flags)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
97ed55d2f5 do_sys_truncate(): switch to CLASS(filename)
Note that failures from filename_lookup() are final - ESTALE returned
by it means that retry had been done by filename_lookup() and it failed
there.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
7273ed4e78 do_utimes_path(): switch to CLASS(filename_uflags)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
4e9654c2bb chdir(2): unspaghettify a bit...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
f770e4c1a4 do_fchownat(): unspaghettify a bit...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
7f583ad97c fspick(2): use CLASS(filename_flags)
That kills the last place where we mix LOOKUP_EMPTY with lookup
flags proper.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
154ef7dce6 name_to_handle_at(): use CLASS(filename_uflags)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
b79b3c1f66 vfs_open_tree(): use CLASS(filename_uflags)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
819cb2c1dd do_open_execat(): don't care about LOOKUP_EMPTY
do_file_open() doesn't.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
57cd2072bd mount_setattr(2): don't mess with LOOKUP_EMPTY
just use CLASS(filename_uflags) + filename_lookup()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
70772cafff file_[gs]etattr(2): switch to CLASS(filename_maybe_null)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
5b9d406ff7 filename_...xattr(): don't consume filename reference
Callers switched to CLASS(filename_maybe_null) (in fs/xattr.c)
and CLASS(filename_complete_delayed) (in io_uring/xattr.c).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:52:03 -05:00
Al Viro
e50aae1d39 non-consuming variants of do_{unlinkat,rmdir}()
similar to previous commit; replacements are filename_{unlinkat,rmdir}()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:51:50 -05:00
Al Viro
88fdc27617 non-consuming variant of do_mknodat()
similar to previous commit; replacement is filename_mknodat()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:49:26 -05:00
Al Viro
dc912db15a non-consuming variant of do_mkdirat()
similar to previous commit; replacement is filename_mkdirat()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:48:49 -05:00
Al Viro
da72b76aae non-consuming variant of do_symlinkat()
similar to previous commit; replacement is filename_symlinkat()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:48:16 -05:00
Al Viro
037193b0ae non-consuming variant of do_linkat()
similar to previous commit; replacement is filename_linkat()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:47:42 -05:00
Al Viro
e6d50234cc non-consuming variant of do_renameat2()
filename_renameat2() replaces do_renameat2(); unlike the latter,
it does not drop filename references - these days it can be just
as easily arranged in the caller.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-16 12:46:57 -05:00
Al Viro
0697b4f400 switch {alloc,free}_bprm() to CLASS()
All linux_binprm instances come from alloc_bprm() and are unconditionally
destroyed by free_bprm() in the end of the same scope.  IOW, CLASS()
machinery is a decent fit for those.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
194c760b6a do_execveat_common(): don't consume filename reference
... and convert its callers to CLASS(filename...)

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
88b33614f9 execve: fold {compat_,}do_execve{,at}() into their sole callers
All of them are wrappers for do_execveat_common() and each has
exactly one caller.  The only difference is in the way they are
constructing argv/envp arguments for do_execveat_common() and
that's easy to do with less boilerplate.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
bb850584aa simplify the callers of alloc_bprm()
alloc_bprm() starts with do_open_execat() and it will do the right
thing if given ERR_PTR() for name.  Allows to drop such checks in
its callers...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
2c941f26c6 simplify the callers of do_open_execat()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
47b3b9bf93 simplify the callers of file_open_name()
It accepts ERR_PTR() for name and does the right thing in that case.
That allows to simplify the logics in callers, making them trivial
to switch to CLASS(filename).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
151e3257d6 do_sys_openat2(): get rid of useless check, switch to CLASS(filename)
do_file_open() will do the right thing when given ERR_PTR() as name...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:08 -05:00
Al Viro
541003b576 rename do_filp_open() to do_file_open()
"filp" thing never made sense; seeing that there are exactly 4 callers
in the entire tree (and it's neither exported nor even declared in
linux/*/*.h), there's no point keeping that ugliness.

FWIW, the 'filp' thing did originate in OSD&I; for some reason Tanenbaum
decided to call the object representing an opened file 'struct filp',
the last letter standing for 'position'.  In all Unices, Linux included,
the corresponding object had always been 'struct file'...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
2e2d64aea5 do_filp_open(): DTRT when getting ERR_PTR() as pathname
The rest of the set_nameidata() callers treat IS_ERR(pathname) as
"bail out immediately with PTR_ERR(pathname) as error".  Makes
life simpler for callers; do_filp_open() is the only exception
and its callers would also benefit from such calling conventions
change.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
ba33ac100d ksmbd_vfs_rename(): vfs_path_parent_lookup() accepts ERR_PTR() as name
no need to check in the caller

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
edefe6bda7 ksmbd_vfs_path_lookup(): vfs_path_parent_lookup() accepts ERR_PTR() as name
no need to check in the caller

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
1c38f1f9b0 move_mount(): filename_lookup() accepts ERR_PTR() as filename
no need to check it in the caller

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
def2a02a4c file_setattr(): filename_lookup() accepts ERR_PTR() as filename
no need to check it in the caller

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
58a49cc9eb file_getattr(): filename_lookup() accepts ERR_PTR() as filename
no need to check it in the caller

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
741c97fecb struct filename ->refcnt doesn't need to be atomic
... or visible outside of audit, really.  Note that references
held in delayed_filename always have refcount 1, and from the
moment of complete_getname() or equivalent point in getname...()
there won't be any references to struct filename instance left
in places visible to other threads.

Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
9fa3ec8458 allow incomplete imports of filenames
There are two filename-related problems in io_uring and its
interplay with audit.

Filenames are imported when request is submitted and used when
it is processed.  Unfortunately, the latter may very well
happen in a different thread.  In that case the reference to
filename is put into the wrong audit_context - that of submitting
thread, not the processing one.  Audit logics is called by
the latter, and it really wants to be able to find the names
in audit_context current (== processing) thread.

Another related problem is the headache with refcounts -
normally all references to given struct filename are visible
only to one thread (the one that uses that struct filename).
io_uring violates that - an extra reference is stashed in
audit_context of submitter.  It gets dropped when submitter
returns to userland, which can happen simultaneously with
processing thread deciding to drop the reference it got.

We paper over that by making refcount atomic, but that means
pointless headache for everyone.

Solution: the notion of partially imported filenames.  Namely,
already copied from userland, but *not* exposed to audit yet.

io_uring can create that in submitter thread, and complete the
import (obtaining the usual reference to struct filename) in
processing thread.

Object: struct delayed_filename.

Primitives for working with it:

delayed_getname(&delayed_filename, user_string) - copies the name from
userland, returning 0 and stashing the address of (still incomplete)
struct filename in delayed_filename on success and returning -E... on
error.

delayed_getname_uflags(&delayed_filename, user_string, atflags) -
similar, in the same relation to delayed_getname() as getname_uflags()
is to getname()

complete_getname(&delayed_filename) - completes the import of filename
stashed in delayed_filename and returns struct filename to caller,
emptying delayed_filename.

CLASS(filename_complete_delayed, name)(&delayed_filename) - variant of
CLASS(filename) with complete_getname() for constructor.

dismiss_delayed_filename(&delayed_filename) - destructor; drops whatever
might be stashed in delayed_filename, emptying it.

putname_to_delayed(&delayed_filename, name) - if name is shared, stashes
its copy into delayed_filename and drops the reference to name, otherwise
stashes the name itself in there.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Al Viro
a9900a27df switch __getname_maybe_null() to CLASS(filename_flags)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:18:07 -05:00
Mateusz Guzik
7ca83f8ebe fs: hide names_cache behind runtime const machinery
s/names_cachep/names_cache/ for consistency with dentry cache.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:17:26 -05:00
Al Viro
8c888b3190 struct filename: saner handling of long names
Always allocate struct filename from names_cachep, long name or short;
short names would be embedded into struct filename.  Longer ones do
not cannibalize the original struct filename - put them into kmalloc'ed
buffers (PATH_MAX-sized for import from userland, strlen() + 1 - for
ones originating kernel-side, where we know the length beforehand).

Cutoff length for short names is chosen so that struct filename would be
192 bytes long - that's both a multiple of 64 and large enough to cover
the majority of real-world uses.

Simplifies logics in getname()/putname() and friends.

[fixed an embarrassing braino in EMBEDDED_NAME_MAX, first reported by
Dan Carpenter]

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:16:44 -05:00
Al Viro
c3a3577cdb struct filename: use names_cachep only for getname() and friends
Instances of struct filename come from names_cachep (via
__getname()).  That is done by getname_flags() and getname_kernel()
and these two are the main callers of __getname().  However, there are
other callers that simply want to allocate PATH_MAX bytes for uses that
have nothing to do with struct filename.

	We want saner allocation rules for long pathnames, so that struct
filename would *always* come from names_cachep, with the out-of-line
pathname getting kmalloc'ed.  For that we need to be able to change the
size of objects allocated by getname_flags()/getname_kernel().

	That requires the rest of __getname() users to stop using
names_cachep; we could explicitly switch all of those to kmalloc(),
but that would cause quite a bit of noise.  So the plan is to switch
getname_...() to new helpers and turn __getname() into a wrapper for
kmalloc().  Remaining __getname() users could be converted to explicit
kmalloc() at leisure, hopefully along with figuring out what size do
they really want - PATH_MAX is an overkill for some of them, used out
of laziness ("we have a convenient helper that does 4K allocations and
that's large enough, let's use it").

	As a side benefit, names_cachep is no longer used outside
of fs/namei.c, so we can move it there and be done with that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:16:44 -05:00
Al Viro
8f2ac84817 getname_flags() massage, part 2
Take the "long name" case into a helper (getname_long()). In
case of failure have the caller deal with freeing the original
struct filename.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:16:44 -05:00
Al Viro
8ba29c85e2 getname_flags() massage, part 1
In case of long name don't reread what we'd already copied.
memmove() it instead.  That avoids the possibility of ending
up with empty name there and the need to look at the flags
on the slow path.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:16:44 -05:00
Al Viro
ca2a04e84a ntfs: ->d_compare() must not block
... so don't use __getname() there.  Switch it (and ntfs_d_hash(), while
we are at it) to kmalloc(PATH_MAX, GFP_NOWAIT).  Yes, ntfs_d_hash()
almost certainly can do with smaller allocations, but let ntfs folks
deal with that - keep the allocation size as-is for now.

Stop abusing names_cachep in ntfs, period - various uses of that thing
in there have nothing to do with pathnames; just use k[mz]alloc() and
be done with that.  For now let's keep sizes as-in, but AFAICS none of
the users actually want PATH_MAX.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:16:44 -05:00
Al Viro
41670a5900 get rid of audit_reusename()
Originally we tried to avoid multiple insertions into audit names array
during retry loop by a cute hack - memorize the userland pointer and
if there already is a match, just grab an extra reference to it.

Cute as it had been, it had problems - two identical pointers had
audit aux entries merged, two identical strings did not.  Having
different behaviour for syscalls that differ only by addresses of
otherwise identical string arguments is obviously wrong - if nothing
else, compiler can decide to merge identical string literals.

Besides, this hack does nothing for non-audited processes - they get
a fresh copy for retry.  It's not time-critical, but having behaviour
subtly differ that way is bogus.

These days we have very few places that import filename more than once
(9 functions total) and it's easy to massage them so we get rid of all
re-imports.  With that done, we don't need audit_reusename() anymore.
There's no need to memorize userland pointer either.

Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-01-13 15:16:44 -05:00