1. 03 6月, 2020 2 次提交
    • D
      keys: Implement update for the big_key type · b6f61c31
      David Howells 提交于
      Implement the ->update op for the big_key type.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NJason A. Donenfeld <Jason@zx2c4.com>
      b6f61c31
    • J
      security/keys: rewrite big_key crypto to use library interface · 521fd61c
      Jason A. Donenfeld 提交于
      A while back, I noticed that the crypto and crypto API usage in big_keys
      were entirely broken in multiple ways, so I rewrote it. Now, I'm
      rewriting it again, but this time using the simpler ChaCha20Poly1305
      library function. This makes the file considerably more simple; the
      diffstat alone should justify this commit. It also should be faster,
      since it no longer requires a mutex around the "aead api object" (nor
      allocations), allowing us to encrypt multiple items in parallel. We also
      benefit from being able to pass any type of pointer, so we can get rid
      of the ridiculously complex custom page allocator that big_key really
      doesn't need.
      
      [DH: Change the select CRYPTO_LIB_CHACHA20POLY1305 to a depends on as
       select doesn't propagate and the build can end up with an =y dependending
       on some =m pieces.
      
       The depends on CRYPTO also had to be removed otherwise the configurator
       complains about a recursive dependency.]
      
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Greg KH <gregkh@linuxfoundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: kernel-hardening@lists.openwall.com
      Reviewed-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      521fd61c
  2. 30 5月, 2020 2 次提交
    • E
      exec: Compute file based creds only once · 56305aa9
      Eric W. Biederman 提交于
      Move the computation of creds from prepare_binfmt into begin_new_exec
      so that the creds need only be computed once.  This is just code
      reorganization no semantic changes of any kind are made.
      
      Moving the computation is safe.  I have looked through the kernel and
      verified none of the binfmts look at bprm->cred directly, and that
      there are no helpers that look at bprm->cred indirectly.  Which means
      that it is not a problem to compute the bprm->cred later in the
      execution flow as it is not used until it becomes current->cred.
      
      A new function bprm_creds_from_file is added to contain the work that
      needs to be done.  bprm_creds_from_file first computes which file
      bprm->executable or most likely bprm->file that the bprm->creds
      will be computed from.
      
      The funciton bprm_fill_uid is updated to receive the file instead of
      accessing bprm->file.  The now unnecessary work needed to reset the
      bprm->cred->euid, and bprm->cred->egid is removed from brpm_fill_uid.
      A small comment to document that bprm_fill_uid now only deals with the
      work to handle suid and sgid files.  The default case is already
      heandled by prepare_exec_creds.
      
      The function security_bprm_repopulate_creds is renamed
      security_bprm_creds_from_file and now is explicitly passed the file
      from which to compute the creds.  The documentation of the
      bprm_creds_from_file security hook is updated to explain when the hook
      is called and what it needs to do.  The file is passed from
      cap_bprm_creds_from_file into get_file_caps so that the caps are
      computed for the appropriate file.  The now unnecessary work in
      cap_bprm_creds_from_file to reset the ambient capabilites has been
      removed.  A small comment to document that the work of
      cap_bprm_creds_from_file is to read capabilities from the files
      secureity attribute and derive capabilities from the fact the
      user had uid 0 has been added.
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      56305aa9
    • E
      exec: Add a per bprm->file version of per_clear · a7868323
      Eric W. Biederman 提交于
      There is a small bug in the code that recomputes parts of bprm->cred
      for every bprm->file.  The code never recomputes the part of
      clear_dangerous_personality_flags it is responsible for.
      
      Which means that in practice if someone creates a sgid script
      the interpreter will not be able to use any of:
      	READ_IMPLIES_EXEC
      	ADDR_NO_RANDOMIZE
      	ADDR_COMPAT_LAYOUT
      	MMAP_PAGE_ZERO.
      
      This accentially clearing of personality flags probably does
      not matter in practice because no one has complained
      but it does make the code more difficult to understand.
      
      Further remaining bug compatible prevents the recomputation from being
      removed and replaced by simply computing bprm->cred once from the
      final bprm->file.
      
      Making this change removes the last behavior difference between
      computing bprm->creds from the final file and recomputing
      bprm->cred several times.  Which allows this behavior change
      to be justified for it's own reasons, and for any but hunts
      looking into why the behavior changed to wind up here instead
      of in the code that will follow that computes bprm->cred
      from the final bprm->file.
      
      This small logic bug appears to have existed since the code
      started clearing dangerous personality bits.
      
      History Tree: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
      Fixes: 1bb0fa189c6a ("[PATCH] NX: clean up legacy binary support")
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      a7868323
  3. 29 5月, 2020 1 次提交
  4. 27 5月, 2020 1 次提交
    • E
      exec: Always set cap_ambient in cap_bprm_set_creds · a4ae32c7
      Eric W. Biederman 提交于
      An invariant of cap_bprm_set_creds is that every field in the new cred
      structure that cap_bprm_set_creds might set, needs to be set every
      time to ensure the fields does not get a stale value.
      
      The field cap_ambient is not set every time cap_bprm_set_creds is
      called, which means that if there is a suid or sgid script with an
      interpreter that has neither the suid nor the sgid bits set the
      interpreter should be able to accept ambient credentials.
      Unfortuantely because cap_ambient is not reset to it's original value
      the interpreter can not accept ambient credentials.
      
      Given that the ambient capability set is expected to be controlled by
      the caller, I don't think this is particularly serious.  But it is
      definitely worth fixing so the code works correctly.
      
      I have tested to verify my reading of the code is correct and the
      interpreter of a sgid can receive ambient capabilities with this
      change and cannot receive ambient capabilities without this change.
      
      Cc: stable@vger.kernel.org
      Cc: Andy Lutomirski <luto@kernel.org>
      Fixes: 58319057 ("capabilities: ambient capabilities")
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      a4ae32c7
  5. 22 5月, 2020 3 次提交
    • N
      apparmor: Fix use-after-free in aa_audit_rule_init · c54d481d
      Navid Emamdoost 提交于
      In the implementation of aa_audit_rule_init(), when aa_label_parse()
      fails the allocated memory for rule is released using
      aa_audit_rule_free(). But after this release, the return statement
      tries to access the label field of the rule which results in
      use-after-free. Before releasing the rule, copy errNo and return it
      after release.
      
      Fixes: 52e8c380 ("apparmor: Fix memory leak of rule on error exit path")
      Signed-off-by: NNavid Emamdoost <navid.emamdoost@gmail.com>
      Signed-off-by: NJohn Johansen <john.johansen@canonical.com>
      c54d481d
    • X
      apparmor: Fix aa_label refcnt leak in policy_update · c6b39f07
      Xiyu Yang 提交于
      policy_update() invokes begin_current_label_crit_section(), which
      returns a reference of the updated aa_label object to "label" with
      increased refcount.
      
      When policy_update() returns, "label" becomes invalid, so the refcount
      should be decreased to keep refcount balanced.
      
      The reference counting issue happens in one exception handling path of
      policy_update(). When aa_may_manage_policy() returns not NULL, the
      refcnt increased by begin_current_label_crit_section() is not decreased,
      causing a refcnt leak.
      
      Fix this issue by jumping to "end_section" label when
      aa_may_manage_policy() returns not NULL.
      
      Fixes: 5ac8c355 ("apparmor: allow introspecting the loaded policy pre internal transform")
      Signed-off-by: NXiyu Yang <xiyuyang19@fudan.edu.cn>
      Signed-off-by: NXin Tan <tanxin.ctf@gmail.com>
      Signed-off-by: NJohn Johansen <john.johansen@canonical.com>
      c6b39f07
    • X
      apparmor: fix potential label refcnt leak in aa_change_profile · a0b845ff
      Xiyu Yang 提交于
      aa_change_profile() invokes aa_get_current_label(), which returns
      a reference of the current task's label.
      
      According to the comment of aa_get_current_label(), the returned
      reference must be put with aa_put_label().
      However, when the original object pointed by "label" becomes
      unreachable because aa_change_profile() returns or a new object
      is assigned to "label", reference count increased by
      aa_get_current_label() is not decreased, causing a refcnt leak.
      
      Fix this by calling aa_put_label() before aa_change_profile() return
      and dropping unnecessary aa_get_current_label().
      
      Fixes: 9fcf78cc ("apparmor: update domain transitions that are subsets of confinement at nnp")
      Signed-off-by: NXiyu Yang <xiyuyang19@fudan.edu.cn>
      Signed-off-by: NXin Tan <tanxin.ctf@gmail.com>
      Signed-off-by: NJohn Johansen <john.johansen@canonical.com>
      a0b845ff
  6. 21 5月, 2020 3 次提交
  7. 19 5月, 2020 1 次提交
  8. 15 5月, 2020 3 次提交
    • A
      bpf, capability: Introduce CAP_BPF · a17b53c4
      Alexei Starovoitov 提交于
      Split BPF operations that are allowed under CAP_SYS_ADMIN into
      combination of CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN.
      For backward compatibility include them in CAP_SYS_ADMIN as well.
      
      The end result provides simple safety model for applications that use BPF:
      - to load tracing program types
        BPF_PROG_TYPE_{KPROBE, TRACEPOINT, PERF_EVENT, RAW_TRACEPOINT, etc}
        use CAP_BPF and CAP_PERFMON
      - to load networking program types
        BPF_PROG_TYPE_{SCHED_CLS, XDP, SK_SKB, etc}
        use CAP_BPF and CAP_NET_ADMIN
      
      There are few exceptions from this rule:
      - bpf_trace_printk() is allowed in networking programs, but it's using
        tracing mechanism, hence this helper needs additional CAP_PERFMON
        if networking program is using this helper.
      - BPF_F_ZERO_SEED flag for hash/lru map is allowed under CAP_SYS_ADMIN only
        to discourage production use.
      - BPF HW offload is allowed under CAP_SYS_ADMIN.
      - bpf_probe_write_user() is allowed under CAP_SYS_ADMIN only.
      
      CAPs are not checked at attach/detach time with two exceptions:
      - loading BPF_PROG_TYPE_CGROUP_SKB is allowed for unprivileged users,
        hence CAP_NET_ADMIN is required at attach time.
      - flow_dissector detach doesn't check prog FD at detach,
        hence CAP_NET_ADMIN is required at detach time.
      
      CAP_SYS_ADMIN is required to iterate BPF objects (progs, maps, links) via get_next_id
      command and convert them to file descriptor via GET_FD_BY_ID command.
      This restriction guarantees that mutliple tasks with CAP_BPF are not able to
      affect each other. That leads to clean isolation of tasks. For example:
      task A with CAP_BPF and CAP_NET_ADMIN loads and attaches a firewall via bpf_link.
      task B with the same capabilities cannot detach that firewall unless
      task A explicitly passed link FD to task B via scm_rights or bpffs.
      CAP_SYS_ADMIN can still detach/unload everything.
      
      Two networking user apps with CAP_SYS_ADMIN and CAP_NET_ADMIN can
      accidentely mess with each other programs and maps.
      Two networking user apps with CAP_NET_ADMIN and CAP_BPF cannot affect each other.
      
      CAP_NET_ADMIN + CAP_BPF allows networking programs access only packet data.
      Such networking progs cannot access arbitrary kernel memory or leak pointers.
      
      bpftool, bpftrace, bcc tools binaries should NOT be installed with
      CAP_BPF and CAP_PERFMON, since unpriv users will be able to read kernel secrets.
      But users with these two permissions will be able to use these tracing tools.
      
      CAP_PERFMON is least secure, since it allows kprobes and kernel memory access.
      CAP_NET_ADMIN can stop network traffic via iproute2.
      CAP_BPF is the safest from security point of view and harmless on its own.
      
      Having CAP_BPF and/or CAP_NET_ADMIN is not enough to write into arbitrary map
      and if that map is used by firewall-like bpf prog.
      CAP_BPF allows many bpf prog_load commands in parallel. The verifier
      may consume large amount of memory and significantly slow down the system.
      
      Existing unprivileged BPF operations are not affected.
      In particular unprivileged users are allowed to load socket_filter and cg_skb
      program types and to create array, hash, prog_array, map-in-map map types.
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20200513230355.7858-2-alexei.starovoitov@gmail.com
      a17b53c4
    • D
      evm: Fix a small race in init_desc() · 84338569
      Dan Carpenter 提交于
      The IS_ERR_OR_NULL() function has two conditions and if we got really
      unlucky we could hit a race where "ptr" started as an error pointer and
      then was set to NULL.  Both conditions would be false even though the
      pointer at the end was NULL.
      
      This patch fixes the problem by ensuring that "*tfm" can only be NULL
      or valid.  I have introduced a "tmp_tfm" variable to make that work.  I
      also reversed a condition and pulled the code in one tab.
      Reported-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Fixes: 53de3b08 ("evm: Check also if *tfm is an error pointer in init_desc()")
      Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
      Acked-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Acked-by: NKrzysztof Struczynski <krzysztof.struczynski@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      84338569
    • J
      lockdown: Allow unprivileged users to see lockdown status · 60cf7c5e
      Jeremy Cline 提交于
      A number of userspace tools, such as systemtap, need a way to see the
      current lockdown state so they can gracefully deal with the kernel being
      locked down. The state is already exposed in
      /sys/kernel/security/lockdown, but is only readable by root. Adjust the
      permissions so unprivileged users can read the state.
      
      Fixes: 000d388e ("security: Add a static lockdown policy LSM")
      Cc: Frank Ch. Eigler <fche@redhat.com>
      Signed-off-by: NJeremy Cline <jcline@redhat.com>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      60cf7c5e
  9. 13 5月, 2020 1 次提交
  10. 12 5月, 2020 2 次提交
  11. 08 5月, 2020 5 次提交
  12. 07 5月, 2020 5 次提交
  13. 02 5月, 2020 4 次提交
  14. 01 5月, 2020 1 次提交
  15. 28 4月, 2020 1 次提交
  16. 27 4月, 2020 1 次提交
  17. 25 4月, 2020 1 次提交
  18. 23 4月, 2020 1 次提交
    • O
      selinux: don't produce incorrect filename_trans_count · 9521eb3e
      Ondrej Mosnacek 提交于
      I thought I fixed the counting in filename_trans_read_helper() to count
      the compat rule count correctly in the final version, but it's still
      wrong. To really count the same thing as in the compat path, we'd need
      to add up the cardinalities of stype bitmaps of all datums.
      
      Since the kernel currently doesn't implement an ebitmap_cardinality()
      function (and computing the proper count would just waste CPU cycles
      anyway), just document that we use the field only in case of the old
      format and stop updating it in filename_trans_read_helper().
      
      Fixes: 43005902 ("selinux: implement new format of filename transitions")
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      9521eb3e
  19. 18 4月, 2020 2 次提交
    • O
      selinux: implement new format of filename transitions · 43005902
      Ondrej Mosnacek 提交于
      Implement a new, more space-efficient way of storing filename
      transitions in the binary policy. The internal structures have already
      been converted to this new representation; this patch just implements
      reading/writing an equivalent represntation from/to the binary policy.
      
      This new format reduces the size of Fedora policy from 7.6 MB to only
      3.3 MB (with policy optimization enabled in both cases). With the
      unconfined module disabled, the size is reduced from 3.3 MB to 2.4 MB.
      
      The time to load policy into kernel is also shorter with the new format.
      On Fedora Rawhide x86_64 it dropped from 157 ms to 106 ms; without the
      unconfined module from 115 ms to 105 ms.
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      43005902
    • O
      selinux: move context hashing under sidtab · 225621c9
      Ondrej Mosnacek 提交于
      Now that context hash computation no longer depends on policydb, we can
      simplify things by moving the context hashing completely under sidtab.
      The hash is still cached in sidtab entries, but not for the in-flight
      context structures.
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      225621c9