08 Apr, 2022

1 commit

  • [ Upstream commit 39844b7e3084baecef52d1498b5fa81afa2cefa9 ]

    __setup() handlers should return 1 if the parameter is handled.
    Returning 0 causes the entire string to be added to init's
    environment strings (limited to 32 strings), unnecessarily polluting it.

    Using the documented strings "TOMOYO_loader=string1" and
    "TOMOYO_trigger=string2" causes an Unknown parameter message:
    Unknown kernel command line parameters
    "BOOT_IMAGE=/boot/bzImage-517rc5 TOMOYO_loader=string1 \
    TOMOYO_trigger=string2", will be passed to user space.

    and these strings are added to init's environment string space:
    Run /sbin/init as init process
    with arguments:
    /sbin/init
    with environment:
    HOME=/
    TERM=linux
    BOOT_IMAGE=/boot/bzImage-517rc5
    TOMOYO_loader=string1
    TOMOYO_trigger=string2

    With this change, these __setup handlers act as expected,
    and init's environment is not polluted with these strings.

    Fixes: 0e4ae0e0dec63 ("TOMOYO: Make several options configurable.")
    Signed-off-by: Randy Dunlap
    Reported-by: Igor Zhbanov
    Link: https://lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
    Cc: James Morris
    Cc: Kentaro Takeda
    Cc: tomoyo-dev-en@lists.osdn.me
    Cc: "Serge E. Hallyn"
    Signed-off-by: Tetsuo Handa
    Signed-off-by: Sasha Levin

    Randy Dunlap
     

05 Jan, 2022

2 commits

  • [ Upstream commit f702e1107601230eec707739038a89018ea3468d ]

    hwight16() is much faster. While we are at it, no need to include
    "perm =" part into data_race() macro, for perm is a local variable
    that cannot be accessed by other threads.

    Signed-off-by: Tetsuo Handa
    Signed-off-by: Sasha Levin

    Tetsuo Handa
     
  • [ Upstream commit 04e57a2d952bbd34bc45744e72be3eecdc344294 ]

    If tomoyo is used in a testing/fuzzing environment in learning mode,
    for lots of domains the quota will be exceeded and stay exceeded
    for prolonged periods of time. In such cases it's pointless (and slow)
    to walk the whole acl list again and again just to rediscover that
    the quota is exceeded. We already have the TOMOYO_DIF_QUOTA_WARNED flag
    that notes the overflow condition. Check it early to avoid the slowdown.

    [penguin-kernel]
    This patch causes a user visible change that the learning mode will not be
    automatically resumed after the quota is increased. To resume the learning
    mode, administrator will need to explicitly clear TOMOYO_DIF_QUOTA_WARNED
    flag after increasing the quota. But I think that this change is generally
    preferable, for administrator likely wants to optimize the acl list for
    that domain before increasing the quota, or that domain likely hits the
    quota again. Therefore, don't try to care to clear TOMOYO_DIF_QUOTA_WARNED
    flag automatically when the quota for that domain changed.

    Signed-off-by: Dmitry Vyukov
    Signed-off-by: Tetsuo Handa
    Signed-off-by: Sasha Levin

    Dmitry Vyukov
     

04 Sep, 2021

1 commit

  • find_vma() and variants need protection when used. This patch adds
    mmap_assert_lock() calls in the functions.

    To make sure the invariant is satisfied, we also need to add a
    mmap_read_lock() around the get_user_pages_remote() call in
    get_arg_page(). The lock is not strictly necessary because the mm has
    been newly created, but the extra cost is limited because the same mutex
    was also acquired shortly before in __bprm_mm_init(), so it is hot and
    uncontended.

    [penguin-kernel@i-love.sakura.ne.jp: TOMOYO needs the same protection which get_arg_page() needs]
    Link: https://lkml.kernel.org/r/58bb6bf7-a57e-8a40-e74b-39584b415152@i-love.sakura.ne.jp

    Link: https://lkml.kernel.org/r/20210731175341.3458608-1-lrizzo@google.com
    Signed-off-by: Luigi Rizzo
    Cc: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Luigi Rizzo
     

15 Jun, 2021

1 commit

  • Fix gcc W=1 warnings:

    security/tomoyo/audit.c:331: warning: Function parameter or member 'matched_acl' not described in 'tomoyo_get_audit'
    security/tomoyo/securityfs_if.c:146: warning: Function parameter or member 'inode' not described in 'tomoyo_release'
    security/tomoyo/tomoyo.c:122: warning: Function parameter or member 'path' not described in 'tomoyo_inode_getattr'
    security/tomoyo/tomoyo.c:497: warning: Function parameter or member 'clone_flags' not described in 'tomoyo_task_alloc'
    security/tomoyo/util.c:92: warning: Function parameter or member 'time64' not described in 'tomoyo_convert_time'

    Signed-off-by: ChenXiaoSong
    [ penguin-kernel: Also adjust spaces and similar warnings ]
    Signed-off-by: Tetsuo Handa

    ChenXiaoSong
     

28 Mar, 2021

1 commit

  • Since commit 3bfe6106693b6b4b ("io-wq: fork worker threads from original
    task") stopped using PF_KTHREAD flag for the io_uring PF_IO_WORKER threads,
    tomoyo_kernel_service() no longer needs to check PF_IO_WORKER flag.

    (This is a 5.12+ patch. Please don't send to stable kernels.)

    Signed-off-by: Jens Axboe
    Signed-off-by: Tetsuo Handa

    Jens Axboe
     

01 Feb, 2021

2 commits

  • Commit db68ce10c4f0a27c ("new helper: uaccess_kernel()") replaced
    segment_eq(get_fs(), KERNEL_DS) with uaccess_kernel(). But the correct
    method for tomoyo to check whether current is a kernel thread in order
    to assume that kernel threads are privileged for socket operations was
    (current->flags & PF_KTHREAD). Now that uaccess_kernel() became 0 on x86,
    tomoyo has to fix this problem. Do like commit 942cb357ae7d9249 ("Smack:
    Handle io_uring kernel thread privileges") does.

    Signed-off-by: Tetsuo Handa

    Tetsuo Handa
     
  • syzbot is reporting that tomoyo's quota check is racy [1]. But this check
    is tolerant of some degree of inaccuracy. Thus, teach KCSAN to ignore
    this data race.

    [1] https://syzkaller.appspot.com/bug?id=999533deec7ba6337f8aa25d8bd1a4d5f7e50476

    Reported-by: syzbot
    Signed-off-by: Tetsuo Handa

    Tetsuo Handa
     

06 Dec, 2020

1 commit


27 Nov, 2020

1 commit

  • Since tomoyo_memory_ok() will check for null pointer returned by
    kzalloc() in tomoyo_assign_profile(), tomoyo_assign_namespace(),
    tomoyo_get_name() and tomoyo_commit_ok(), then emit OOM warnings
    if needed. And this is the expected behavior as informed by
    Tetsuo Handa.

    Let's add __GFP_NOWARN to kzalloc() in those related functions.
    Besides, to achieve this goal, remove the null check for entry
    right after kzalloc() in tomoyo_assign_namespace().

    Reported-by: Hulk Robot
    Suggested-by: Tetsuo Handa
    Signed-off-by: Zheng Zengkai
    Signed-off-by: Tetsuo Handa

    Zheng Zengkai
     

03 Nov, 2020

1 commit

  • Since wildcards that need recursion consume kernel stack memory (or might
    cause CPU stall warning problem), we cannot allow infinite recursion.

    Since TOMOYO 1.8 survived with 20 recursions limit for 5 years, nobody
    would complain if applying this limit to TOMOYO 2.6.

    Signed-off-by: Tetsuo Handa

    Tetsuo Handa
     

28 Oct, 2020

1 commit

  • clang warns about additions on NULL pointers being undefined in C:

    security/tomoyo/securityfs_if.c:226:59: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
    securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,

    Change the code to instead use a cast through uintptr_t to avoid
    the warning.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Tetsuo Handa

    Arnd Bergmann
     

12 Oct, 2020

1 commit

  • Since commit e2dc9bf3f5275ca3 ("umd: Transform fork_usermode_blob into
    fork_usermode_driver") started calling execve() on a program written in
    a local mount which is not connected to mount tree,
    tomoyo_realpath_from_path() started returning a pathname in
    "$fsname:/$pathname" format which violates TOMOYO's domainname rule that
    it must start with "" followed by zero or more repetitions of
    pathnames which start with '/'.

    Since $fsname must not contain '.' since commit 79c0b2df79eb56fc ("add
    filesystem subtype support"), tomoyo_correct_path() can recognize a token
    which appears '/' before '.' appears (e.g. proc:/self/exe ) as a pathname
    while rejecting a token which appears '.' before '/' appears (e.g.
    exec.realpath="/bin/bash" ) as a condition parameter.

    Therefore, accept domainnames which contain pathnames which do not start
    with '/' but contain '/' before '.' (e.g. tmpfs:/bpfilter_umh ).

    Signed-off-by: Tetsuo Handa

    Tetsuo Handa
     

24 Aug, 2020

1 commit

  • Replace the existing /* fall through */ comments and its variants with
    the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
    fall-through markings when it is the case.

    [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

13 Aug, 2020

1 commit

  • After the cleanup of page fault accounting, gup does not need to pass
    task_struct around any more. Remove that parameter in the whole gup
    stack.

    Signed-off-by: Peter Xu
    Signed-off-by: Andrew Morton
    Reviewed-by: John Hubbard
    Link: http://lkml.kernel.org/r/20200707225021.200906-26-peterx@redhat.com
    Signed-off-by: Linus Torvalds

    Peter Xu
     

21 Jul, 2020

1 commit

  • To allow the kernel not to play games with set_fs to call exec
    implement kernel_execve. The function kernel_execve takes pointers
    into kernel memory and copies the values pointed to onto the new
    userspace stack.

    The calls with arguments from kernel space of do_execve are replaced
    with calls to kernel_execve.

    The calls do_execve and do_execveat are made static as there are now
    no callers outside of exec.

    The comments that mention do_execve are updated to refer to
    kernel_execve or execve depending on the circumstances. In addition
    to correcting the comments, this makes it easy to grep for do_execve
    and verify it is not used.

    Inspired-by: https://lkml.kernel.org/r/20200627072704.2447163-1-hch@lst.de
    Reviewed-by: Kees Cook
    Link: https://lkml.kernel.org/r/87wo365ikj.fsf@x220.int.ebiederm.org
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

14 Jun, 2020

1 commit

  • Since commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
    '---help---'"), the number of '---help---' has been gradually
    decreasing, but there are still more than 2400 instances.

    This commit finishes the conversion. While I touched the lines,
    I also fixed the indentation.

    There are a variety of indentation styles found.

    a) 4 spaces + '---help---'
    b) 7 spaces + '---help---'
    c) 8 spaces + '---help---'
    d) 1 space + 1 tab + '---help---'
    e) 1 tab + '---help---' (correct indentation)
    f) 1 tab + 1 space + '---help---'
    g) 1 tab + 2 spaces + '---help---'

    In order to convert all of them to 1 tab + 'help', I ran the
    following commend:

    $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

05 Jun, 2020

2 commits

  • Pull execve updates from Eric Biederman:
    "Last cycle for the Nth time I ran into bugs and quality of
    implementation issues related to exec that could not be easily be
    fixed because of the way exec is implemented. So I have been digging
    into exec and cleanup up what I can.

    I don't think I have exec sorted out enough to fix the issues I
    started with but I have made some headway this cycle with 4 sets of
    changes.

    - promised cleanups after introducing exec_update_mutex

    - trivial cleanups for exec

    - control flow simplifications

    - remove the recomputation of bprm->cred

    The net result is code that is a bit easier to understand and work
    with and a decrease in the number of lines of code (if you don't count
    the added tests)"

    * 'exec-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (24 commits)
    exec: Compute file based creds only once
    exec: Add a per bprm->file version of per_clear
    binfmt_elf_fdpic: fix execfd build regression
    selftests/exec: Add binfmt_script regression test
    exec: Remove recursion from search_binary_handler
    exec: Generic execfd support
    exec/binfmt_script: Don't modify bprm->buf and then return -ENOEXEC
    exec: Move the call of prepare_binprm into search_binary_handler
    exec: Allow load_misc_binary to call prepare_binprm unconditionally
    exec: Convert security_bprm_set_creds into security_bprm_repopulate_creds
    exec: Factor security_bprm_creds_for_exec out of security_bprm_set_creds
    exec: Teach prepare_exec_creds how exec treats uids & gids
    exec: Set the point of no return sooner
    exec: Move handling of the point of no return to the top level
    exec: Run sync_mm_rss before taking exec_update_mutex
    exec: Fix spelling of search_binary_handler in a comment
    exec: Move the comment from above de_thread to above unshare_sighand
    exec: Rename flush_old_exec begin_new_exec
    exec: Move most of setup_new_exec into flush_old_exec
    exec: In setup_new_exec cache current in the local variable me
    ...

    Linus Torvalds
     
  • Pull proc updates from Eric Biederman:
    "This has four sets of changes:

    - modernize proc to support multiple private instances

    - ensure we see the exit of each process tid exactly

    - remove has_group_leader_pid

    - use pids not tasks in posix-cpu-timers lookup

    Alexey updated proc so each mount of proc uses a new superblock. This
    allows people to actually use mount options with proc with no fear of
    messing up another mount of proc. Given the kernel's internal mounts
    of proc for things like uml this was a real problem, and resulted in
    Android's hidepid mount options being ignored and introducing security
    issues.

    The rest of the changes are small cleanups and fixes that came out of
    my work to allow this change to proc. In essence it is swapping the
    pids in de_thread during exec which removes a special case the code
    had to handle. Then updating the code to stop handling that special
    case"

    * 'proc-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace:
    proc: proc_pid_ns takes super_block as an argument
    remove the no longer needed pid_alive() check in __task_pid_nr_ns()
    posix-cpu-timers: Replace __get_task_for_clock with pid_for_clock
    posix-cpu-timers: Replace cpu_timer_pid_type with clock_pid_type
    posix-cpu-timers: Extend rcu_read_lock removing task_struct references
    signal: Remove has_group_leader_pid
    exec: Remove BUG_ON(has_group_leader_pid)
    posix-cpu-timer: Unify the now redundant code in lookup_task
    posix-cpu-timer: Tidy up group_leader logic in lookup_task
    proc: Ensure we see the exit of each process tid exactly once
    rculist: Add hlists_swap_heads_rcu
    proc: Use PIDTYPE_TGID in next_tgid
    Use proc_pid_ns() to get pid_namespace from the proc superblock
    proc: use named enums for better readability
    proc: use human-readable values for hidepid
    docs: proc: add documentation for "hidepid=4" and "subset=pid" options and new mount behavior
    proc: add option to mount only a pids subset
    proc: instantiate only pids that we can ptrace on 'hidepid=4' mount option
    proc: allow to mount many instances of proc in one pid namespace
    proc: rename struct proc_fs_info to proc_fs_opts

    Linus Torvalds
     

03 Jun, 2020

1 commit


29 May, 2020

1 commit


21 May, 2020

1 commit

  • Today security_bprm_set_creds has several implementations:
    apparmor_bprm_set_creds, cap_bprm_set_creds, selinux_bprm_set_creds,
    smack_bprm_set_creds, and tomoyo_bprm_set_creds.

    Except for cap_bprm_set_creds they all test bprm->called_set_creds and
    return immediately if it is true. The function cap_bprm_set_creds
    ignores bprm->calld_sed_creds entirely.

    Create a new LSM hook security_bprm_creds_for_exec that is called just
    before prepare_binprm in __do_execve_file, resulting in a LSM hook
    that is called exactly once for the entire of exec. Modify the bits
    of security_bprm_set_creds that only want to be called once per exec
    into security_bprm_creds_for_exec, leaving only cap_bprm_set_creds
    behind.

    Remove bprm->called_set_creds all of it's former users have been moved
    to security_bprm_creds_for_exec.

    Add or upate comments a appropriate to bring them up to date and
    to reflect this change.

    Link: https://lkml.kernel.org/r/87v9kszrzh.fsf_-_@x220.int.ebiederm.org
    Acked-by: Linus Torvalds
    Acked-by: Casey Schaufler # For the LSM and Smack bits
    Reviewed-by: Kees Cook
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

19 May, 2020

1 commit

  • syzbot found that

    touch /proc/testfile

    causes NULL pointer dereference at tomoyo_get_local_path()
    because inode of the dentry is NULL.

    Before c59f415a7cb6, Tomoyo received pid_ns from proc's s_fs_info
    directly. Since proc_pid_ns() can only work with inode, using it in
    the tomoyo_get_local_path() was wrong.

    To avoid creating more functions for getting proc_ns, change the
    argument type of the proc_pid_ns() function. Then, Tomoyo can use
    the existing super_block to get pid_ns.

    Link: https://lkml.kernel.org/r/0000000000002f0c7505a5b0e04c@google.com
    Link: https://lkml.kernel.org/r/20200518180738.2939611-1-gladkov.alexey@gmail.com
    Reported-by: syzbot+c1af344512918c61362c@syzkaller.appspotmail.com
    Fixes: c59f415a7cb6 ("Use proc_pid_ns() to get pid_namespace from the proc superblock")
    Signed-off-by: Alexey Gladkov
    Signed-off-by: Eric W. Biederman

    Alexey Gladkov
     

12 May, 2020

1 commit


25 Apr, 2020

1 commit

  • To get pid_namespace from the procfs superblock should be used a special
    helper. This will avoid errors when s_fs_info will change the type.

    Link: https://lore.kernel.org/lkml/20200423200316.164518-3-gladkov.alexey@gmail.com/
    Link: https://lore.kernel.org/lkml/20200423112858.95820-1-gladkov.alexey@gmail.com/
    Link: https://lore.kernel.org/lkml/06B50A1C-406F-4057-BFA8-3A7729EA7469@lca.pw/
    Signed-off-by: Alexey Gladkov
    Signed-off-by: Eric W. Biederman

    Alexey Gladkov
     

25 Mar, 2020

1 commit


02 Jan, 2020

1 commit

  • syzbot is reporting that there is a race at tomoyo_stat_update() [1].
    Although it is acceptable to fail to track exact number of times policy
    was updated, convert to atomic_t because this is not a hot path.

    [1] https://syzkaller.appspot.com/bug?id=a4d7b973972eeed410596e6604580e0133b0fc04

    Reported-by: syzbot
    Signed-off-by: Tetsuo Handa

    Tetsuo Handa
     

16 Dec, 2019

1 commit

  • John Garry has reported that allmodconfig kernel on arm64 causes flood of
    "RCU-list traversed in non-reader section!!" warning. I don't know what
    change caused this warning, but this warning is safe because TOMOYO uses
    SRCU lock instead. Let's suppress this warning by explicitly telling that
    the caller is holding SRCU lock.

    Reported-and-tested-by: John Garry
    Signed-off-by: Tetsuo Handa

    Tetsuo Handa
     

11 Dec, 2019

1 commit

  • syzbot is reporting that use of SOCKET_I()->sk from open() can result in
    use after free problem [1], for socket's inode is still reachable via
    /proc/pid/fd/n despite destruction of SOCKET_I()->sk already completed.

    At first I thought that this race condition applies to only open/getattr
    permission checks. But James Morris has pointed out that there are more
    permission checks where this race condition applies to. Thus, get rid of
    tomoyo_get_socket_name() instead of conditionally bypassing permission
    checks on sockets. As a side effect of this patch,
    "socket:[family=\$:type=\$:protocol=\$]" in the policy files has to be
    rewritten to "socket:[\$]".

    [1] https://syzkaller.appspot.com/bug?id=73d590010454403d55164cca23bd0565b1eb3b74

    Signed-off-by: Tetsuo Handa
    Reported-by: syzbot
    Reported-by: James Morris

    Tetsuo Handa
     

21 May, 2019

1 commit


11 May, 2019

4 commits

  • Commit cff0e6c3ec3e6230 ("tomoyo: Add a kernel config option for fuzzing
    testing.") enabled the learning mode, but syzkaller is detecting any
    "WARNING:" string as a crash. Thus, disable TOMOYO's quota warning if
    built for fuzzing testing.

    Signed-off-by: Tetsuo Handa
    Cc: Dmitry Vyukov
    Signed-off-by: James Morris

    Tetsuo Handa
     
  • Commit 5625f2e3266319fd ("TOMOYO: Change pathname for non-rename()able
    filesystems.") intended to be applied to filesystems where the content is
    not controllable from the userspace (e.g. proc, sysfs, securityfs), based
    on an assumption that such filesystems do not support rename() operation.

    But it turned out that read-only filesystems also do not support rename()
    operation despite the content is controllable from the userspace, and that
    commit is annoying TOMOYO users who want to use e.g. squashfs as the root
    filesystem due to use of local name which does not start with '/'.

    Therefore, based on an assumption that filesystems which require the
    device argument upon mount() request is an indication that the content
    is controllable from the userspace, do not use local name if a filesystem
    does not support rename() operation but requires the device argument upon
    mount() request.

    Signed-off-by: Tetsuo Handa
    Signed-off-by: James Morris

    Tetsuo Handa
     
  • KMSAN will complain if valid address length passed to bind()/connect()/
    sendmsg() is shorter than sizeof("struct sockaddr"->sa_family) bytes.

    Signed-off-by: Tetsuo Handa
    Signed-off-by: James Morris

    Tetsuo Handa
     
  • syzbot is reporting kernel panic triggered by memory allocation fault
    injection before loading TOMOYO's policy [1]. To make the fuzzing tests
    useful, we need to assign a profile other than "disabled" (no-op) mode.
    Therefore, let's allow syzbot to load TOMOYO's built-in policy for
    "learning" mode using a kernel config option. This option must not be
    enabled for kernels built for production system, for this option also
    disables domain/program checks when modifying policy configuration via
    /sys/kernel/security/tomoyo/ interface.

    [1] https://syzkaller.appspot.com/bug?extid=29569ed06425fcf67a95

    Reported-by: syzbot
    Reported-by: syzbot
    Reported-by: syzbot
    Signed-off-by: Tetsuo Handa
    Signed-off-by: James Morris

    Tetsuo Handa
     

20 Feb, 2019

1 commit


25 Jan, 2019

2 commits


24 Jan, 2019

1 commit

  • TOMOYO security module is designed to use "struct task_struct"->security
    in order to allow per "struct task_struct" tracking without being disturbed
    by unable to update "struct cred"->security due to override mechanism.

    Now that infrastructure-managed security blob is ready, this patch updates
    TOMOYO to use "struct task_struct"->security.

    Signed-off-by: Tetsuo Handa
    Signed-off-by: James Morris

    Tetsuo Handa
     

19 Jan, 2019

1 commit

  • Since current->cred == current->real_cred when ordered_lsm_init()
    is called, and lsm_early_cred()/lsm_early_task() need to be called
    between the amount of required bytes is determined and module specific
    initialization function is called, we can move these calls from
    individual modules to ordered_lsm_init().

    Signed-off-by: Tetsuo Handa
    Acked-by: Casey Schaufler
    Signed-off-by: James Morris

    Tetsuo Handa
     

09 Jan, 2019

1 commit