Commit graph

12 commits

Author SHA1 Message Date
Arnd Bergmann
0cd1151886 csky: use generic strncpy/strnlen from_user
Remove the csky implemenation of strncpy/strnlen and instead use the
generic versions.  The csky version is fairly slow because it always does
byte accesses even for aligned data, and it lacks a checks for
user_addr_max().

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2021-07-23 14:40:01 +02:00
Arnd Bergmann
f27180dd63 asm-generic/uaccess.h: remove __strncpy_from_user/__strnlen_user
This is a preparation for changing over architectures to the
generic implementation one at a time. As there are no callers
of either __strncpy_from_user() or __strnlen_user(), fold these
into the strncpy_from_user() and strnlen_user() functions to make
each implementation independent of the others.

Many of these implementations have known bugs, but the intention
here is to not change behavior at all and stay compatible with
those bugs for the moment.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2021-07-23 14:39:56 +02:00
Linus Torvalds
cda689f870 arch/csky patches for 5.13-rc1
Just 1 feature and 3 fixups.
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCgAwFiEE2KAv+isbWR/viAKHAXH1GYaIxXsFAmCQHXUSHGd1b3JlbkBr
 ZXJuZWwub3JnAAoJEAFx9RmGiMV7QbEP/A5noQq5vO5DcIywFpyjw1Ca+kS8WVKq
 67cQMn+vlaD4RAllWkjPnatg0OkLqvpsp8pJytM4RmmCOuoaMtKQGXiCU01u1t3V
 3CZifEBTg0ZzlliSjsEzaA8RvleLURlkHEcswVILklMESajvqkpHsnTSbkoctrrr
 cD1A1Dwyas5oSrj5Qfdsz52u0jmeY+gmtK8NMQr3rbKBAHdu+D1NpeADnrD1uWs6
 Fcw7qZZ5AmOffQ73JgqPiJ0YWpiP6GBn7pTst8PHrBrG8CR3XYUV+OdbPkiTvznb
 GNYUJ7tum9b7JNEHW7w2EQO0Pz96bbSczddZPrNV06HtC67hKqjsPS2WTDCGF/f7
 wzSgaUyKoHA/F1FVbPJbP7NeGDsqAfwHdnkgR86MKYfP4jE6+zECFvbfxKrmw8Ob
 5Owp9TF3vS7hO5wJA550e79xKdw2fVuvJ5k+ZoKpgQYifRexxIRfXNLANxfCv1sx
 6hYt/NZWsRJSGcZ4cr1BQvp+pQq/zjsP9Z4x+2aKORG9tz2uSaf2T7XkQDkoJxln
 SxvDDYWDRi2khzZ4IGTiavTNC4C3WsBKvfKBYCGYKG1AH8uQQt+cK1+wBQaERmgG
 9AK4mkOWtlw6GPl+rKzum/15toCFZywU0idx19t/2pxWxTTmzAly/Z4xCQant6YY
 PZGmQYwAKKVV
 =jXN4
 -----END PGP SIGNATURE-----

Merge tag 'csky-for-linus-5.13-rc1' of git://github.com/c-sky/csky-linux

Pull arch/csky updates from Guo Ren:
 "Just cleanups"

* tag 'csky-for-linus-5.13-rc1' of git://github.com/c-sky/csky-linux:
  csky: uaccess.h: Coding convention with asm generic
  csky: fix syscache.c fallthrough warning
  csky: Fixup typos
  csky: Remove duplicate include in arch/csky/kernel/entry.S
2021-05-03 12:58:31 -07:00
Guo Ren
e58a41c222 csky: uaccess.h: Coding convention with asm generic
Using asm-generic/uaccess.h to prevent duplicated code:
 - Add user_addr_max which mentioned in generic uaccess.h
 - Remove custom definitions of KERNEL/USER_DS, get/set_fs,
   uaccess_kerenl
 - Using generic extable.h instead of custom definitions in
   uaccess.h

Change v2:
 - Fixup tinyconfig compile error, "__put_user_bad"
 - Add __get_user_asm_64

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Link: https://lore.kernel.org/linux-csky/CAK8P3a1DvsXSEDoovLk11hzNHyJi7vqNoToU+n5aFi2viZO_Uw@mail.gmail.com/T/#mbcd58a0e3450e5598974116b607589afa16a3ab7
Cc: Arnd Bergmann <arnd@arndb.de>
2021-04-28 23:02:23 +08:00
Al Viro
a0d8d55278 whack-a-mole: kill strlen_user() (again)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2021-03-27 19:36:31 -04:00
Guo Ren
71e193d7cb csky: Add support for function error injection
Inspired by the commit 42d038c4fb ("arm64: Add support for function
error injection"), this patch supports function error injection for
csky.

This patch mainly support two functions: one is regs_set_return_value()
which is used to overwrite the return value; the another function is
override_function_with_return() which is to override the probed
function returning and jump to its caller.

Test log:

 cd /sys/kernel/debug/fail_function/
 echo sys_clone > inject
 echo 100 > probability
 echo 1 > interval
 ls /
[  108.644163] FAULT_INJECTION: forcing a failure.
[  108.644163] name fail_function, interval 1, probability 100, space 0, times 1
[  108.647799] CPU: 0 PID: 104 Comm: sh Not tainted 5.8.0-rc5+ #46
[  108.648384] Call Trace:
[  108.649339] [<8005eed4>] walk_stackframe+0x0/0xf0
[  108.649679] [<8005f16a>] show_stack+0x32/0x5c
[  108.649927] [<8040f9d2>] dump_stack+0x6e/0x9c
[  108.650271] [<80406f7e>] should_fail+0x15e/0x1ac
[  108.650720] [<80118ba8>] fei_kprobe_handler+0x28/0x5c
[  108.651519] [<80754110>] kprobe_breakpoint_handler+0x144/0x1cc
[  108.652289] [<8005d6da>] trap_c+0x8e/0x110
[  108.652816] [<8005ce8c>] csky_trap+0x5c/0x70
-sh: can't fork: Invalid argument

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Cc: Arnd Bergmann <arnd@arndb.de>
2020-07-31 01:52:07 +00:00
Al Viro
51bb38cb78 csky: Fixup raw_copy_from_user()
If raw_copy_from_user(to, from, N) returns K, callers expect
the first N - K bytes starting at to to have been replaced with
the contents of corresponding area starting at from and the last
K bytes of destination *left* *unmodified*.

What arch/sky/lib/usercopy.c is doing is broken - it can lead to e.g.
data corruption on write(2).

raw_copy_to_user() is inaccurate about return value, which is a bug,
but consequences are less drastic than for raw_copy_from_user().
And just what are those access_ok() doing in there?  I mean, look into
linux/uaccess.h; that's where we do that check (as well as zero tail
on failure in the callers that need zeroing).

AFAICS, all of that shouldn't be hard to fix; something like a patch
below might make a useful starting point.

I would suggest moving these macros into usercopy.c (they are never
used anywhere else) and possibly expanding them there; if you leave
them alive, please at least rename __copy_user_zeroing(). Again,
it must not zero anything on failed read.

Said that, I'm not sure we won't be better off simply turning
usercopy.c into usercopy.S - all that is left there is a couple of
functions, each consisting only of inline asm.

Guo Ren reply:

Yes, raw_copy_from_user is wrong, it's no need zeroing code.

unsigned long _copy_from_user(void *to, const void __user *from,
unsigned long n)
{
        unsigned long res = n;
        might_fault();
        if (likely(access_ok(from, n))) {
                kasan_check_write(to, n);
                res = raw_copy_from_user(to, from, n);
        }
        if (unlikely(res))
                memset(to + (n - res), 0, res);
        return res;
}
EXPORT_SYMBOL(_copy_from_user);

You are right and access_ok() should be removed.

but, how about:
do {
...
        "2:     stw     %3, (%1, 0)     \n"             \
+       "       subi    %0, 4          \n"               \
        "9:     stw     %4, (%1, 4)     \n"             \
+       "       subi    %0, 4          \n"               \
        "10:    stw     %5, (%1, 8)     \n"             \
+       "       subi    %0, 4          \n"               \
        "11:    stw     %6, (%1, 12)    \n"             \
+       "       subi    %0, 4          \n"               \
        "       addi    %2, 16          \n"             \
        "       addi    %1, 16          \n"             \

Don't expand __ex_table

AI Viro reply:

Hey, I've no idea about the instruction scheduling on csky -
if that doesn't slow the things down, all the better.  It's just
that copy_to_user() and friends are on fairly hot codepaths,
and in quite a few situations they will dominate the speed of
e.g. read(2).  So I tried to keep the fast path unchanged.
Up to the architecture maintainers, obviously.  Which would be
you...

As for the fixups size increase (__ex_table size is unchanged)...
You have each of those macros expanded exactly once.
So the size is not a serious argument, IMO - useless complexity
would be, if it is, in fact, useless; the size... not really,
especially since those extra subi will at least offset it.

Again, up to you - asm optimizations of (essentially)
memcpy()-style loops are tricky and can depend upon the
fairly subtle details of architecture.  So even on something
I know reasonably well I would resort to direct experiments
if I can't pass the buck to architecture maintainers.

It *is* worth optimizing - this is where read() from a file
that is already in page cache spends most of the time, etc.

Guo Ren reply:

Thx, after fixup some typo “sub %0, 4”, apply the patch.

TODO:
 - user copy/from codes are still need optimizing.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
2020-05-15 00:16:30 +08: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
Linus Torvalds
96d4f267e4 Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.

It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access.  But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.

A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model.  And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.

This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.

There were a couple of notable cases:

 - csky still had the old "verify_area()" name as an alias.

 - the iter_iov code had magical hardcoded knowledge of the actual
   values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
   really used it)

 - microblaze used the type argument for a debug printout

but other than those oddities this should be a total no-op patch.

I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something.  Any missed conversion should be trivially fixable, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-03 18:57:57 -08:00
Guo Ren
da55128194 csky: User access
The patch adds "user access from kernel" codes.

Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
2018-10-26 00:54:25 +08:00
Guo Ren
c5af58b769 csky: Library functions
This patch adds string optimize codes and some auxiliary codes.

Signed-off-by: Chen Linfei <linfei_chen@c-sky.com>
Signed-off-by: Mao Han <han_mao@c-sky.com>
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
2018-10-26 00:54:24 +08:00
Guo Ren
c32e64e852 csky: Build infrastructure
This patch adds Makefile, Kconfig for build infrastructure.

Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2018-10-25 23:36:19 +08:00