100 Commits
Author SHA1 Message Date
Al Viro 3304f18bfc Adding VFS co-maintainer
Acked-by: Christian Brauner <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2023-03-05 10:31:17 -05:00
Al Viro caa82ae7ef openrisc: fix livelock in uaccess
openrisc equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:32:44 -05:00
Al Viro e902e508c5 nios2: fix livelock in uaccess
nios2 equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:32:35 -05:00
Al Viro a1179ac743 microblaze: fix livelock in uaccess
microblaze equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:32:31 -05:00
Al Viro d088af1e22 ia64: fix livelock in uaccess
ia64 equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:32:27 -05:00
Al Viro 79c54c97c7 sparc: fix livelock in uaccess
sparc equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:32:19 -05:00
Al Viro dce45493af alpha: fix livelock in uaccess
alpha equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:32:15 -05:00
Al Viro 15261678a8 parisc: fix livelock in uaccess
parisc equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Tested-by: Helge Deller <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:31:40 -05:00
Al Viro 0b92ed09cb hexagon: fix livelock in uaccess
hexagon equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Acked-by: Brian Cain <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:30:21 -05:00
Al Viro d835eb3a57 riscv: fix livelock in uaccess
riscv equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Tested-by: Björn Töpel <[email protected]>
Tested-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:30:15 -05:00
Al Viro bd75497a77 m68k: fix livelock in uaccess
m68k equivalent of 26178ec11e "x86: mm: consolidate VM_FAULT_RETRY handling"
If e.g. get_user() triggers a page fault and a fatal signal is caught, we might
end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything
to page tables.  In such case we must *not* return to the faulting insn -
that would repeat the entire thing without making any progress; what we need
instead is to treat that as failed (user) memory access.

Tested-by: Finn Thain <[email protected]>
Tested-by: Geert Uytterhoeven <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2023-03-02 12:30:08 -05:00
Al Viro 0509666660 alpha: lazy FPU switching
On each context switch we save the FPU registers on stack
of old process and restore FPU registers from the stack of new one.
That allows us to avoid doing that each time we enter/leave the
kernel mode; however, that can get suboptimal in some cases.

	For one thing, we don't need to bother saving anything
for kernel threads.  For another, if between entering and leaving
the kernel a thread gives CPU up more than once, it will do
useless work, saving the same values every time, only to discard
the saved copy as soon as it returns from switch_to().

	Alternative solution:

* move the array we save into from switch_stack to thread_info
* have a (thread-synchronous) flag set when we save them
* have another flag set when they should be restored on return to userland.
* do *NOT* save/restore them in do_switch_stack()/undo_switch_stack().
* restore on the exit to user mode if the restore flag had
been set.  Clear both flags.
* on context switch, entry to fork/clone/vfork, before entry into do_signal()
and on entry into straced syscall save the registers and set the 'saved' flag
unless it had been already set.
* on context switch set the 'restore' flag as well.
* have copy_thread() set both flags for child, so the registers would be
restored once the child returns to userland.
* use the saved data in setup_sigcontext(); have restore_sigcontext() set both flags
and copy from sigframe to save area.
* teach ptrace to look for FPU registers in thread_info instead of
switch_stack.
* teach isolated accesses to FPU registers (rdfpcr, wrfpcr, etc.)
to check the 'saved' flag (under preempt_disable()) and work with the save area
if it's been set; if 'saved' flag is found upon write access, set 'restore' flag
as well.

Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Matt Turner <[email protected]>
2023-02-24 23:14:22 -05:00
Al Viro a7acb188e8 alpha/boot/misc: trim unused declarations
gzip_mark() and gzip_release() are gone; there used to be two
forward declarations of each and the patch removing those suckers
had left one of each behind...

Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Matt Turner <[email protected]>
2023-02-24 23:14:22 -05:00
Al Viro a4c082f267 alpha/boot/tools/objstrip: fix the check for ELF header
Just memcmp() with ELFMAG - that's the normal way to do it in userland
code, which that thing is.  Besides, that has the benefit of actually
building - str_has_prefix() is *NOT* present in <string.h>.

Fixes: 5f14596e55 "alpha: Replace strncmp with str_has_prefix"
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Matt Turner <[email protected]>
2023-02-24 23:14:22 -05:00
Al Viro 56efd34f82 alpha/boot: fix the breakage from -isystem series...
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Matt Turner <[email protected]>
2023-02-24 23:14:22 -05:00
Al Viro d3c51b701b alpha: fix FEN fault handling
Type 3 instruction fault (FPU insn with FPU disabled) is handled
by quietly enabling FPU and returning.  Which is fine, except that
we need to do that both for fault in userland and in the kernel;
the latter *can* legitimately happen - all it takes is this:

.global _start
_start:
	call_pal 0xae
	lda $0, 0
	ldq $0, 0($0)

- call_pal CLRFEN to clear "FPU enabled" flag and arrange for
a signal delivery (SIGSEGV in this case).

Fixed by moving the handling of type 3 into the common part of
do_entIF(), before we check for kernel vs. user mode.

Incidentally, check for kernel mode is unidiomatic; the normal
way to do that is !user_mode(regs).  The difference is that
the open-coded variant treats any of bits 63..3 of regs->ps being
set as "it's user mode" while the normal approach is to check just
the bit 3.  PS is a 4-bit register and regs->ps always will have
bits 63..4 clear, so the open-code variant here is actually equivalent
to !user_mode(regs).  Harder to follow, though...

Reproducer above will crash any box where CLRFEN is not ignored by
PAL (== any actual hardware, AFAICS; PAL used in qemu doesn't
bother implementing that crap).

Cc: [email protected] # all way back...
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Matt Turner <[email protected]>
2023-02-24 23:14:22 -05:00
Al Viro abb7c74239 sysv: fix handling of delete_entry and set_link failures
similar to minixfs series - make sysv_set_link() report failures,
lift dir_put_page() into the callers of sysv_set_link() and
sysv_delete_entry(), make sysv_rename() handle failures in both.

Signed-off-by: Al Viro <[email protected]>
2023-01-19 23:24:42 -05:00
Al Viro 2cb6a44220 minix_rename(): minix_delete_entry() might fail
Signed-off-by: Al Viro <[email protected]>
2023-01-19 19:29:26 -05:00
Al Viro beb9797ee8 alpha/boot/misc: trim unused declarations
gzip_mark() and gzip_release() are gone; there used to be two
forward declarations of each and the patch removing those suckers
had left one of each behind...

Signed-off-by: Al Viro <[email protected]>
2023-01-11 15:36:52 -05:00
Al Viro 1878787797 alpha/boot/tools/objstrip: fix the check for ELF header
Just memcmp() with ELFMAG - that's the normal way to do it in userland
code, which that thing is.  Besides, that has the benefit of actually
building - str_has_prefix() is *NOT* present in <string.h>.

Fixes: 5f14596e55 "alpha: Replace strncmp with str_has_prefix"
Signed-off-by: Al Viro <[email protected]>
2023-01-11 15:36:46 -05:00
Al Viro e07f68d5e4 alpha/boot: fix the breakage from -isystem series...
Signed-off-by: Al Viro <[email protected]>
2023-01-11 15:36:16 -05:00
Al Viro 977a300954 alpha: fix FEN fault handling
Type 3 instruction fault (FPU insn with FPU disabled) is handled
by quietly enabling FPU and returning.  Which is fine, except that
we need to do that both for fault in userland and in the kernel;
the latter *can* legitimately happen - all it takes is this:

.global _start
_start:
        call_pal 0xae
	lda $0, 0
	ldq $0, 0($0)

- call_pal CLRFEN to clear "FPU enabled" flag and arrange for
a signal delivery (SIGSEGV in this case).

Fixed by moving the handling of type 3 into the common part of
do_entIF(), before we check for kernel vs. user mode.

Incidentally, the check for kernel mode is unidiomatic; the normal
way to do that is !user_mode(regs).  The difference is that
the open-coded variant treats any of bits 63..3 of regs->ps being
set as "it's user mode" while the normal approach is to check just
the bit 3.  PS is a 4-bit register and regs->ps always will have
bits 63..4 clear, so the open-coded variant here is actually equivalent
to !user_mode(regs).  Harder to follow, though...

Cc: [email protected]
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2023-01-11 15:34:43 -05:00
Al Viro 4a29a1262a minix: make minix_new_inode() return error as ERR_PTR(-E...)
adjust the callers

Signed-off-by: Al Viro <[email protected]>
2023-01-11 15:30:08 -05:00
Al Viro 456b59e757 ovl: update ->f_iocb_flags when ovl_change_flags() modifies ->f_flags
ovl_change_flags() is an open-coded variant of fs/fcntl.c:setfl() and it
got missed by commit 164f4064ca ("keep iocb_flags() result cached in
struct file"); the same change applies there.

Reported-by: Pierre Labastie <[email protected]>
Fixes: 164f4064ca ("keep iocb_flags() result cached in struct file")
Cc: <[email protected]> # v6.0
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216738
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
2022-11-28 11:53:28 +01:00
Al Viro 27e714c007 ext2: unbugger ext2_empty_dir()
In 27cfa25895 "ext2: fix fs corruption when trying to remove
a non-empty directory with IO error" a funny thing has happened:

-               page = ext2_get_page(inode, i, dir_has_error, &page_addr);
+               page = ext2_get_page(inode, i, 0, &page_addr);

 -               if (IS_ERR(page)) {
 -                       dir_has_error = 1;
 -                       continue;
 -               }
 +               if (IS_ERR(page))
 +                       goto not_empty;

And at not_empty: we hit ext2_put_page(page, page_addr), which does
put_page(page).  Which, unless I'm very mistaken, should oops
immediately when given ERR_PTR(-E...) as page.

OK, shit happens, insufficiently tested patches included.  But when
commit in question describes the fault-injection test that exercised
that particular failure exit...

Ow.

CC: [email protected]
Fixes: 27cfa25895 ("ext2: fix fs corruption when trying to remove a non-empty directory with IO error")
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
2022-11-28 11:41:43 +01:00
Al Viro de4eda9de2 use less confusing names for iov_iter direction initializers
READ/WRITE proved to be actively confusing - the meanings are
"data destination, as used with read(2)" and "data source, as
used with write(2)", but people keep interpreting those as
"we read data from it" and "we write data to it", i.e. exactly
the wrong way.

Call them ITER_DEST and ITER_SOURCE - at least that is harder
to misinterpret...

Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:55 -05:00
Al Viro a41dad905e iov_iter: saner checks for attempt to copy to/from iterator
instead of "don't do it to ITER_PIPE" check for ->data_source being
false on copying from iterator.  Check for !->data_source for
copying to iterator, while we are at it.

Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:21 -05:00
Al Viro fc02f33787 [xen] fix "direction" argument of iov_iter_kvec()
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:21 -05:00
Al Viro e3bf3df824 [vhost] fix 'direction' argument of iov_iter_{init,bvec}()
READ means "data destination", WRITE - "data source".

Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:21 -05:00
Al Viro b676668d99 [target] fix iov_iter_bvec() "direction" argument
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:21 -05:00
Al Viro 77729412ac [s390] memcpy_real(): WRITE is "data source", not destination...
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:21 -05:00
Al Viro 4ba48e1bae [s390] zcore: WRITE is "data source", not destination...
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:21 -05:00
Al Viro 355d2c2798 [infiniband] READ is "data destination", not source...
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:20 -05:00
Al Viro 974c36fb82 [fsi] WRITE is "data source", not destination...
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:20 -05:00
Al Viro 0e1e4a2238 [s390] copy_oldmem_kernel() - WRITE is "data source", not destination
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:20 -05:00
Al Viro c67f1fd2b2 csum_and_copy_to_iter(): handle ITER_DISCARD
Not hard to implement - we are not copying anything here, so
csum_and_memcpy() is not usable, but calculating a checksum
of source directly is trivial...

Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:20 -05:00
Al Viro 40a86061a5 get rid of unlikely() on page_copy_sane() calls
Signed-off-by: Al Viro <[email protected]>
2022-11-25 13:01:20 -05:00
Al Viro 38ba2f11d9 [elf] get rid of get_note_info_size()
it's trivial now...

Signed-off-by: Al Viro <[email protected]>
2022-11-24 23:26:04 -05:00
Al Viro e92edb85d8 [elf] unify regset and non-regset cases
The only real difference is in filling per-thread notes - getting
the values of registers.   And this is the only part that is worth
an ifdef - we don't need to duplicate the logics regarding gathering
threads, filling other notes, etc.

It would've been hard to do back when regset-based variant had been
introduced, mostly due to sharing bits and pieces of helpers with
aout coredumps.  As the result, too much had been duplicated and
the copies had drifted away since then.  Now it can be done cleanly...

Signed-off-by: Al Viro <[email protected]>
2022-11-24 23:26:04 -05:00
Al Viro e961d370fc [elf][non-regset] use elf_core_copy_task_regs() for dumper as well
elf_core_copy_regs() is equivalent to elf_core_copy_task_regs() of
current on all architectures.

Signed-off-by: Al Viro <[email protected]>
2022-11-24 23:26:04 -05:00
Al Viro bdbadfcc37 [elf][non-regset] uninline elf_core_copy_task_fpregs() (and lose pt_regs argument)
Don't bother with pointless macros - we are not sharing it with aout coredumps
anymore.  Just convert the underlying functions to the same arguments (nobody
uses regs, actually) and call them elf_core_copy_task_fpregs().  And unexport
the entire bunch, while we are at it.

[added missing includes in arch/{csky,m68k,um}/kernel/process.c to avoid extra
warnings about the lack of externs getting added to huge piles for those
files.  Pointless, but...]

Signed-off-by: Al Viro <[email protected]>
2022-11-24 23:24:23 -05:00
Al Viro 61d8e42667 copy_mnt_ns(): handle a corner case (overmounted mntns bindings) saner
copy_mnt_ns() has the old tree copied, with mntns binding *and* anything
bound on top of them skipped.  Then it proceeds to walk both trees in
parallel.  Unfortunately, it doesn't get the "skip the stuff we'd skipped
when copying" quite right.  Consequences are minor (the ->mnt_root
comparison will return the situation to sanity pretty soon and the worst
we get is the unexpected subset of opened non-directories being switched
to new namespace), but it's confusing enough and it's not hard to get
the expected behaviour...

Signed-off-by: Al Viro <[email protected]>
2022-11-24 22:55:57 -05:00
Al Viro 878eb6e48f block: blk_add_rq_to_plug(): clear stale 'last' after flush
blk_mq_flush_plug_list() empties ->mq_list and request we'd peeked there
before that call is gone; in any case, we are not dealing with a mix
of requests for different queues now - there's no requests left in the
plug.

Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
2022-10-31 20:21:38 -06:00
Al Viro fa6a3bf7ff alpha: ret_from_fork can go straight to ret_to_user
We only hit ret_from_fork when the child is meant to return to
userland (since 2012 or so).

Signed-off-by: Al Viro <[email protected]>
2022-10-29 23:31:16 -04:00
Al Viro e778eaeced alpha: syscall exit cleanup
$ret_success consists of two insn + branch to ret_from_syscall.
The thing is, those insns are identical to the ones immediately
preceding ret_from_syscall...

Signed-off-by: Al Viro <[email protected]>
2022-10-29 23:31:15 -04:00
Al Viro 19a09e4268 alpha: fix handling of a3 on straced syscalls
For successful syscall that happens to return a negative, we want
a3 set to 0, no matter whether it's straced or not.  As it is,
for straced case we leave the value it used to have on syscall
entry.  Easily fixed, fortunately...

Signed-off-by: Al Viro <[email protected]>
2022-10-29 23:31:15 -04:00
Al Viro f7b2431a6d alpha: fix syscall entry in !AUDUT_SYSCALL case
We only want to take the slow path if SYSCALL_TRACE or SYSCALL_AUDIT is
set; on !AUDIT_SYSCALL configs the current tree hits it whenever _any_
thread flag (including NEED_RESCHED, NOTIFY_SIGNAL, etc.) happens to
be set.

Fixes: a9302e8439 "alpha: Enable system-call auditing support"
Signed-off-by: Al Viro <[email protected]>
2022-10-29 23:31:15 -04:00
Al Viro 71ac548bfd alpha: _TIF_ALLWORK_MASK is unused
... and never had been used, actually

Signed-off-by: Al Viro <[email protected]>
2022-10-29 23:31:14 -04:00
Al Viro e2c7554cc6 alpha: fix TIF_NOTIFY_SIGNAL handling
it needs to be added to _TIF_WORK_MASK, or we might not reach
do_work_pending() in the first place...

Fixes: 5a9a8897c2 "alpha: add support for TIF_NOTIFY_SIGNAL"
Signed-off-by: Al Viro <[email protected]>
2022-10-29 23:31:14 -04:00
Al Viro fcf1492d66 elf_core_copy_task_regs(): task_pt_regs is defined everywhere
Had been since 2011 for all live architectures, ever since 2013
for all architectures, period.

Signed-off-by: Al Viro <[email protected]>
2022-10-23 18:06:56 -04:00
Al Viro 4b0e21d642 [elf][regset] simplify thread list handling in fill_note_info()
fill_note_info() iterates through the list of threads collected in
mm->core_state->dumper, allocating a struct elf_thread_core_info
instance for each and linking those into a list.

We need the entry corresponding to current to be first in the
resulting list, so the logics for list insertion is
	if it's for current or list is empty
		insert in the head
	else
		insert after the first element

However, in mm->core_state->dumper the entry for current is guaranteed
to be the first one.  Which means that both parts of condition will
be true on the first iteration and neither will be true on all subsequent
ones.

Taking the first iteration out of the loop simplifies things nicely...

Signed-off-by: Al Viro <[email protected]>
2022-10-23 18:06:56 -04:00
Al Viro 922ef161b2 [elf][regset] clean fill_note_info() a bit
*info is already initialized...

Signed-off-by: Al Viro <[email protected]>
2022-10-23 18:06:56 -04:00
Al Viro 87562ed953 kill extern of vsyscall32_sysctl
it's been dead for years.

Signed-off-by: Al Viro <[email protected]>
2022-10-23 18:06:55 -04:00
Al Viro 9a938eba8d kill coredump_params->regs
it's always task_pt_regs(current)

Signed-off-by: Al Viro <[email protected]>
2022-10-23 18:06:55 -04:00
Al Viro 6a542d1d5f kill signal_pt_regs()
Once upon at it was used on hot paths, but that had not been
true since 2013.  IOW, there's no point for arch-optimized
equivalent of task_pt_regs(current) - remaining two users are
not worth bothering with.

Signed-off-by: Al Viro <[email protected]>
2022-10-23 18:06:54 -04:00
Al Viro c22180a5e2 ksmbd: constify struct path
... in particular, there should never be a non-const pointers to
any file->f_path.

Acked-by: Namjae Jeon <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Steve French <[email protected]>
2022-10-05 01:15:37 -05:00
Al Viro 369c1634cc ksmbd: don't open-code %pD
a bunch of places used %pd with file->f_path.dentry; shorter (and saner)
way to spell that is %pD with file...

Acked-by: Namjae Jeon <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Steve French <[email protected]>
2022-10-05 01:15:37 -05:00
Al Viro 2f5930c1d7 ksmbd: don't open-code file_path()
Acked-by: Namjae Jeon <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Steve French <[email protected]>
2022-10-05 01:15:37 -05:00
Al Viro 4f526fef91 [brown paperbag] fix coredump breakage
Let me count the ways in which I'd screwed up:

* when emitting a page, handling of gaps in coredump should happen
before fetching the current file position.
* fix for a problem that occurs on rather uncommon setups (and hadn't
been observed in the wild) had been sent very late in the cycle.
* ... with badly insufficient testing, introducing an easily
reproducible breakage.  Without giving it time to soak in -next.

Fucked-up-by: Al Viro <[email protected]>
Reported-by: "J. R. Okajima" <[email protected]>
Tested-by: "J. R. Okajima" <[email protected]>
Fixes: 06bbaa6dc5 "[coredump] don't use __kernel_write() on kmap_local_page()"
Cc: [email protected]	# v6.0-only
Signed-off-by: Al Viro <[email protected]>
2022-10-03 20:28:38 -04:00
Al Viro 06bbaa6dc5 [coredump] don't use __kernel_write() on kmap_local_page()
passing kmap_local_page() result to __kernel_write() is unsafe -
random ->write_iter() might (and 9p one does) get unhappy when
passed ITER_KVEC with pointer that came from kmap_local_page().

Fix by providing a variant of __kernel_write() that takes an iov_iter
from caller (__kernel_write() becomes a trivial wrapper) and adding
dump_emit_page() that parallels dump_emit(), except that instead of
__kernel_write() it uses __kernel_write_iter() with ITER_BVEC source.

Fixes: 3159ed5779 "fs/coredump: use kmap_local_page()"
Signed-off-by: Al Viro <[email protected]>
2022-09-28 14:28:40 -04:00
Al Viro 19ee5345f2 hugetlbfs: cleanup mknod and tmpfile
Duplicate the few lines that are shared between hugetlbfs_mknod() and
hugetlbfs_tmpfile().

This is a prerequisite for sanely changing the signature of ->tmpfile().

Signed-off-by: Al Viro <[email protected]>
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
2022-09-24 06:59:59 +02:00
Al Viro 762df359aa riscv: fix a nasty sigreturn bug...
riscv has an equivalent of arm bug fixed by 653d48b221 ("arm: fix
really nasty sigreturn bug"); if signal gets caught by an interrupt that
hits when we have the right value in a0 (-513), *and* another signal
gets delivered upon sigreturn() (e.g. included into the blocked mask for
the first signal and posted while the handler had been running), the
syscall restart logics will see regs->cause equal to EXC_SYSCALL (we are
in a syscall, after all) and a0 already restored to its original value
(-513, which happens to be -ERESTARTNOINTR) and assume that we need to
apply the usual syscall restart logics.

Signed-off-by: Al Viro <[email protected]>
Fixes: e2c0cdfba7 ("RISC-V: User-facing API")
Cc: [email protected]
Link: https://lore.kernel.org/r/YxJEiSq%2FCGaL6Gm9@ZenIV/
Signed-off-by: Palmer Dabbelt <[email protected]>
2022-09-17 01:48:23 -07:00
Al Viro bfbfb6182a nfsd_splice_actor(): handle compound pages
pipe_buffer might refer to a compound page (and contain more than a PAGE_SIZE
worth of data).  Theoretically it had been possible since way back, but
nfsd_splice_actor() hadn't run into that until copy_page_to_iter() change.
Fortunately, the only thing that changes for compound pages is that we
need to stuff each relevant subpage in and convert the offset into offset
in the first subpage.

Acked-by: Chuck Lever <[email protected]>
Tested-by: Benjamin Coddington <[email protected]>
Fixes: f0f6b614f8 "copy_page_to_iter(): don't split high-order page in case of ITER_PIPE"
Signed-off-by: Al Viro <[email protected]>
2022-09-12 22:38:36 -04:00
Al Viro ccf3a57041 termios: kill uapi termios.h that are identical to generic one
mandatory-y will have the generic picked for architectures that
don't have uapi/asm/termios.h of their own.  ia64, parisc and
s390 ones are identical to generic, so...

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxGVXpS2dWoTwoa0@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:35 +02:00
Al Viro 89bbeb7e31 termios: get rid of non-UAPI asm/termios.h
All non-UAPI asm/termios.h consist of include of UAPI counterpart
and, possibly, include of linux/uaccess.h

	The latter can't be simply removed, even though nothing in
linux/termios.h doesn't depend upon it anymore - there are several
places that rely upon that indirect chain of includes to pull
linux/uaccess.h.  So the include needs to be lifted out of there -
we lift into tty_driver.h, serdev.h and places that pull asm/termios.h,
but none of
	* linux/uaccess.h (obvious)
	* net/sock.h (pulls uaccess.h)
	* linux/{tty,tty_driver,serdev}.h (tty.h pulls tty_driver.h)

That leaves us just with the include of UAPI asm/termios.h, which is
what <asm/termios.h> will resolve to if we simply remove non-UAPI header.

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxDnKvYCHn/ogBUv@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:35 +02:00
Al Viro e7b4c812b9 termios: convert the last (sparc) INIT_C_CC to array
Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxDnDCR2VRTA3Etp@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:35 +02:00
Al Viro d04f9915fa make generic INIT_C_CC a bit more generic
turn it into an array initializer; then alpha, mips and powerpc
variants fold into it.

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxDm7M6M91gC2RPL@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:35 +02:00
Al Viro 38fc315a73 termios: consolidate values for VDISCARD in INIT_C_CC
On old systems it used to be ^O.  Linux had never actually used
the value, but INIT_C_CC (on i386) did initialize it to ^O;
unfortunately, it had a typo in the comment claiming that to be
^U.  Most of the architectures copied the (correct) definition
along with mistaken comment.  alpha, powerpc and sparc tried
to make the definition match comment.

However, util-linux still resets it to ^O on any architecture,
^O is the historical value, kernel ignores it anyway and finally,
Linus said "Just change everybody to do the same, nobody cares
about VDISCARD".

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxDmy//MKzs3ye7l@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:34 +02:00
Al Viro c9874d3ffe termios: start unifying non-UAPI parts of asm/termios.h
* new header (linut/termios_internal.h), pulled by the users of those
suckers
* defaults for INIT_C_CC and externs for conversion helpers moved over
there
* remove termios-base.h (empty now)

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxDmptU7dNGZ+/Hn@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:34 +02:00
Al Viro 1d5d668256 termios: uninline conversion helpers
default go into drivers/tty/tty_ioctl.c, unusual - into
arch/*/kernel/termios.c (only alpha and sparc have those).

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/YxDmeUBHo0s/Ew8b@ZenIV
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-09 10:44:34 +02:00
Al Viro 4094d98e33 orangefs: use ->f_mapping
... and don't check for impossible conditions - file_inode() is
never NULL in anything seen by ->release() and neither is its
->i_mapping.

Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:46:06 -04:00
Al Viro 265a04b076 _nfs42_proc_copy(): use ->f_mapping instead of file_inode()->i_mapping
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:45:36 -04:00
Al Viro ff58105a47 dma_buf: no need to bother with file_inode()->i_mapping
->f_mapping will do just fine

Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:45:20 -04:00
Al Viro 1f24cd31c2 nfs_finish_open(): don't open-code file_inode()
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:44:57 -04:00
Al Viro e6ae438124 bprm_fill_uid(): don't open-code file_inode()
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:44:38 -04:00
Al Viro 235185b8ed sgx: use ->f_mapping...
Reviewed-by: Jarkko Sakkinen <[email protected]>
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:43:29 -04:00
Al Viro 703e3e9a9c exfat_iterate(): don't open-code file_inode(file)
and it's file, not filp...

Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:42:52 -04:00
Al Viro 8789c172e5 ibmvmc: don't open-code file_inode()
badly, at that...

Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:42:27 -04:00
Al Viro 88569546e8 ecryptfs: constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:40:38 -04:00
Al Viro 20f45ad50d spufs: constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:40:14 -04:00
Al Viro ea4af4aa03 nd_jump_link(): constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:39:49 -04:00
Al Viro bf2e1ae417 audit_init_parent(): constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:39:30 -04:00
Al Viro e81f574da0 __io_setxattr(): constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:39:05 -04:00
Al Viro 5b09c9fec0 do_proc_readlink(): constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:38:37 -04:00
Al Viro 2d3430875a overlayfs: constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:38:07 -04:00
Al Viro d5bf88895f fs/notify: constify path
Reviewed-by: Matthew Bobrowski <[email protected]>
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:37:29 -04:00
Al Viro 8996682b10 may_linkat(): constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:36:52 -04:00
Al Viro 6ccaaf59c3 do_sys_name_to_handle(): constify path
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:36:39 -04:00
Al Viro c8e477c649 ->getprocattr(): attribute name is const char *, TYVM...
cast of ->d_name.name to char * is completely wrong - nothing is
allowed to modify its contents.

Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Acked-by: Paul Moore <[email protected]>
Acked-by: Casey Schaufler <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-09-01 17:34:39 -04:00
Al Viro 9d64d2405f binderfs: rework superblock destruction
So far we relied on
.put_super = binderfs_put_super()
to destroy info we stashed in sb->s_fs_info. This gave us the required ordering
between ->evict_inode() and sb->s_fs_info destruction.

But the current implementation of binderfs_fill_super() has a memory leak in
the rare circumstance that d_make_root() fails because ->put_super() is only
called when sb->s_root is initialized. Fix this by removing ->put_super() and
simply do all that work in binderfs_kill_super().

Reported-by: Dongliang Mu <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Christian Brauner (Microsoft) <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-09-01 16:18:49 +02:00
Al Viro 0c7833b9e8 termios: get rid of stray asm/termios.h include in n_hdlc.c
that's the only one outside of include/uapi/linux/termios.h and it's
not even needed there - we have linux/tty.h already pulled and that
pulls linux/termios.h

Normally I would not consider that a sufficient reason, but there's a
plenty of linux/tty.h users, and this is the only one that follows that
with asm/termios.h.  The situation with termios.h is genuinely convoluted,
and this complicates it for no good reason.

Signed-off-by: Al Viro <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-08-30 14:25:02 +02:00
Al Viro 6f418aeaad loongarch: remove generic-y += termios.h
not really needed - UAPI mandatory-y += termios.h is sufficient...

Signed-off-by: Al Viro <[email protected]>
Acked-by: Huacai Chen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2022-08-30 14:24:32 +02:00
Al Viro 467cf8ef88 tomoyo: struct path it might get from LSM callers won't have NULL dentry or mnt
Acked-by: Tetsuo Handa <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-08-21 11:50:42 -04:00
Al Viro 89868773fe tomoyo: use vsnprintf() properly
Idiomatic way to find how much space sprintf output would take is
	len = snprintf(NULL, 0, ...) + 1;
Once upon a time there'd been libc implementations that blew chunks
on that and somebody had come up with the following "cute" trick:
	len = snprintf((char *) &len, 1, ...) + 1;
for doing the same.  However, that's unidiomatic, harder to follow
*and* any such libc implementation would violate both C99 and POSIX
(since 2001).
	IOW, this kludge is best buried along with such libc implementations,
nevermind getting cargo-culted into newer code.  Our vsnprintf() does not
suffer that braindamage, TYVM.

Acked-by: Tetsuo Handa <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-08-21 11:50:42 -04:00
Al Viro c4c8451147 d_path.c: typo fix...
Signed-off-by: Al Viro <[email protected]>
2022-08-20 11:34:33 -04:00
Al Viro 0f60d28828 dynamic_dname(): drop unused dentry argument
Signed-off-by: Al Viro <[email protected]>
2022-08-20 11:34:04 -04:00
Al Viro 47091e4ed9 dma_buf_getfile(): don't bother with ->f_flags reassignments
just pass the already sanitized value to alloc_file_pseudo().

Signed-off-by: Al Viro <[email protected]>
2022-08-17 17:25:54 -04:00
Al Viro 25885a35a7 Change calling conventions for filldir_t
filldir_t instances (directory iterators callbacks) used to return 0 for
"OK, keep going" or -E... for "stop".  Note that it's *NOT* how the
error values are reported - the rules for those are callback-dependent
and ->iterate{,_shared}() instances only care about zero vs. non-zero
(look at emit_dir() and friends).

So let's just return bool ("should we keep going?") - it's less confusing
that way.  The choice between "true means keep going" and "true means
stop" is bikesheddable; we have two groups of callbacks -
	do something for everything in directory, until we run into problem
and
	find an entry in directory and do something to it.

The former tended to use 0/-E... conventions - -E<something> on failure.
The latter tended to use 0/1, 1 being "stop, we are done".
The callers treated anything non-zero as "stop", ignoring which
non-zero value did they get.

"true means stop" would be more natural for the second group; "true
means keep going" - for the first one.  I tried both variants and
the things like
	if allocation failed
		something = -ENOMEM;
		return true;
just looked unnatural and asking for trouble.

[folded suggestion from Matthew Wilcox <[email protected]>]
Acked-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
2022-08-17 17:25:04 -04:00
Al Viro fd0c153daa nios2: add force_successful_syscall_return()
If we use the ancient SysV syscall ABI, we'd better have tell the
kernel how to claim that a negative return value is a success.
Use ->orig_r2 for that - it's inaccessible via ptrace, so it's
a fair game for changes and it's normally[*] non-negative on return
from syscall.  Set to -1; syscall is not going to be restart-worthy
by definition, so we won't interfere with that use either.

[*] the only exception is rt_sigreturn(), where we skip the entire
messing with r1/r2 anyway.

Fixes: 82ed08dd1b ("nios2: Exception handling")
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Dinh Nguyen <[email protected]>
2022-08-15 11:25:32 -05:00
Al Viro 411a76b721 nios2: restarts apply only to the first sigframe we build...
Fixes: b53e906d25 ("nios2: Signal handling support")
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Dinh Nguyen <[email protected]>
2022-08-15 11:25:32 -05:00