1. 21 Aug, 2020 1 commit
  2. 19 Aug, 2020 8 commits
  3. 11 Aug, 2020 2 commits
    • Bruno Meneguele's avatar
      ima: move APPRAISE_BOOTPARAM dependency on ARCH_POLICY to runtime · 37b9e578
      Bruno Meneguele authored
      commit 311aa6aa upstream.
      
      The IMA_APPRAISE_BOOTPARAM config allows enabling different "ima_appraise="
      modes - log, fix, enforce - at run time, but not when IMA architecture
      specific policies are enabled.  This prevents properly labeling the
      filesystem on systems where secure boot is supported, but not enabled on the
      platform.  Only when secure boot is actually enabled should these IMA
      appraise modes be disabled.
      
      This patch removes the compile time dependency and makes it a runtime
      decision, based on the secure boot state of that platform.
      
      Test results as follows:
      
      -> x86-64 with secure boot enabled
      
      [    0.015637] Kernel command line: <...> ima_policy=appraise_tcb ima_appraise=fix
      [    0.015668] ima: Secure boot enabled: ignoring ima_appraise=fix boot parameter option
      
      -> powerpc with secure boot disabled
      
      [    0.000000] Kernel command line: <...> ima_policy=appraise_tcb ima_appraise=fix
      [    0.000000] Secure boot mode disabled
      
      -> Running the system without secure boot and with both options set:
      
      CONFIG_IMA_APPRAISE_BOOTPARAM=y
      CONFIG_IMA_ARCH_POLICY=y
      
      Audit prompts "missing-hash" but still allow execution and, consequently,
      filesystem labeling:
      
      type=INTEGRITY_DATA msg=audit(07/09/2020 12:30:27.778:1691) : pid=4976
      uid=root auid=root ses=2
      subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 op=appraise_data
      cause=missing-hash comm=bash name=/usr/bin/evmctl dev="dm-0" ino=493150
      res=no
      
      Cc: stable@vger.kernel.org
      Fixes: d958083a
      
       ("x86/ima: define arch_get_ima_policy() for x86")
      Signed-off-by: default avatarBruno Meneguele <bmeneg@redhat.com>
      Cc: stable@vger.kernel.org # 5.0
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      37b9e578
    • Eric Biggers's avatar
      Smack: fix use-after-free in smk_write_relabel_self() · 5ec142a2
      Eric Biggers authored
      commit beb4ee67 upstream.
      
      smk_write_relabel_self() frees memory from the task's credentials with
      no locking, which can easily cause a use-after-free because multiple
      tasks can share the same credentials structure.
      
      Fix this by using prepare_creds() and commit_creds() to correctly modify
      the task's credentials.
      
      Reproducer for "BUG: KASAN: use-after-free in smk_write_relabel_self":
      
      	#include <fcntl.h>
      	#include <pthread.h>
      	#include <unistd.h>
      
      	static void *thrproc(void *arg)
      	{
      		int fd = open("/sys/fs/smackfs/relabel-self", O_WRONLY);
      		for (;;) write(fd, "foo", 3);
      	}
      
      	int main()
      	{
      		pthread_t t;
      		pthread_create(&t, NULL, thrproc, NULL);
      		thrproc(NULL);
      	}
      
      Reported-by: syzbot+e6416dabb497a650da40@syzkaller.appspotmail.com
      Fixes: 38416e53
      
       ("Smack: limited capability for changing process label")
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5ec142a2
  4. 08 Jul, 2020 1 commit
  5. 25 Jun, 2020 1 commit
  6. 23 Jun, 2020 1 commit
    • KP Singh's avatar
      security: Fix hook iteration and default value for inode_copy_up_xattr · 23e390cd
      KP Singh authored
      inode_copy_up_xattr returns 0 to indicate the acceptance of the xattr
      and 1 to reject it. If the LSM does not know about the xattr, it's
      expected to return -EOPNOTSUPP, which is the correct default value for
      this hook. BPF LSM, currently, uses 0 as the default value and thereby
      falsely allows all overlay fs xattributes to be copied up.
      
      The iteration logic is also updated from the "bail-on-fail"
      call_int_hook to continue on the non-decisive -EOPNOTSUPP and bail out
      on other values.
      
      Fixes: 98e828a0
      
       ("security: Refactor declaration of LSM hooks")
      Signed-off-by: default avatarKP Singh <kpsingh@google.com>
      Signed-off-by: default avatarJames Morris <jmorris@namei.org>
      23e390cd
  7. 17 Jun, 2020 2 commits
    • Tom Rix's avatar
      selinux: fix undefined return of cond_evaluate_expr · 8231b0b9
      Tom Rix authored
      
      clang static analysis reports an undefined return
      
      security/selinux/ss/conditional.c:79:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]
              return s[0];
              ^~~~~~~~~~~
      
      static int cond_evaluate_expr( ...
      {
      	u32 i;
      	int s[COND_EXPR_MAXDEPTH];
      
      	for (i = 0; i < expr->len; i++)
      	  ...
      
      	return s[0];
      
      When expr->len is 0, the loop which sets s[0] never runs.
      
      So return -1 if the loop never runs.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Acked-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      8231b0b9
    • Tom Rix's avatar
      selinux: fix a double free in cond_read_node()/cond_read_list() · aa449a79
      Tom Rix authored
      Clang static analysis reports this double free error
      
      security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc]
              kfree(node->expr.nodes);
              ^~~~~~~~~~~~~~~~~~~~~~~
      
      When cond_read_node fails, it calls cond_node_destroy which frees the
      node but does not poison the entry in the node list.  So when it
      returns to its caller cond_read_list, cond_read_list deletes the
      partial list.  The latest entry in the list will be deleted twice.
      
      So instead of freeing the node in cond_read_node, let list freeing in
      code_read_list handle the freeing the problem node along with all of the
      earlier nodes.
      
      Because cond_read_node no longer does any error handling, the goto's
      the error case are redundant.  Instead just return the error code.
      
      Cc: stable@vger.kernel.org
      Fixes: 60abd318
      
       ("selinux: convert cond_list to array")
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Reviewed-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      [PM: subject line tweaks]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      aa449a79
  8. 16 Jun, 2020 1 commit
  9. 14 Jun, 2020 1 commit
  10. 13 Jun, 2020 1 commit
    • Masahiro Yamada's avatar
      treewide: replace '---help---' in Kconfig files with 'help' · a7f7f624
      Masahiro Yamada authored
      Since commit 84af7a61
      
       ("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: default avatarMasahiro Yamada <masahiroy@kernel.org>
      a7f7f624
  11. 12 Jun, 2020 1 commit
  12. 11 Jun, 2020 1 commit
    • Tom Rix's avatar
      selinux: fix double free · 65de5096
      Tom Rix authored
      
      Clang's static analysis tool reports these double free memory errors.
      
      security/selinux/ss/services.c:2987:4: warning: Attempt to free released memory [unix.Malloc]
                              kfree(bnames[i]);
                              ^~~~~~~~~~~~~~~~
      security/selinux/ss/services.c:2990:2: warning: Attempt to free released memory [unix.Malloc]
              kfree(bvalues);
              ^~~~~~~~~~~~~~
      
      So improve the security_get_bools error handling by freeing these variables
      and setting their return pointers to NULL and the return len to 0
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Acked-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      65de5096
  13. 09 Jun, 2020 1 commit
  14. 07 Jun, 2020 4 commits
    • Roberto Sassu's avatar
      ima: Remove __init annotation from ima_pcrread() · 8b8c704d
      Roberto Sassu authored
      Commit 6cc7c266 ("ima: Call ima_calc_boot_aggregate() in
      ima_eventdigest_init()") added a call to ima_calc_boot_aggregate() so that
      the digest can be recalculated for the boot_aggregate measurement entry if
      the 'd' template field has been requested. For the 'd' field, only SHA1 and
      MD5 digests are accepted.
      
      Given that ima_eventdigest_init() does not have the __init annotation, all
      functions called should not have it. This patch removes __init from
      ima_pcrread().
      
      Cc: stable@vger.kernel.org
      Fixes:  6cc7c266
      
       ("ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init()")
      Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      8b8c704d
    • John Johansen's avatar
      apparmor: Fix memory leak of profile proxy · 3622ad25
      John Johansen authored
      When the proxy isn't replaced and the profile is removed, the proxy
      is being leaked resulting in a kmemleak check message of
      
      unreferenced object 0xffff888077a3a490 (size 16):
        comm "apparmor_parser", pid 128041, jiffies 4322684109 (age 1097.028s)
        hex dump (first 16 bytes):
          03 00 00 00 00 00 00 00 b0 92 fd 4b 81 88 ff ff  ...........K....
        backtrace:
          [<0000000084d5daf2>] aa_alloc_proxy+0x58/0xe0
          [<00000000ecc0e21a>] aa_alloc_profile+0x159/0x1a0
          [<000000004cc9ce15>] unpack_profile+0x275/0x1c40
          [<000000007332b3ca>] aa_unpack+0x1e7/0x7e0
          [<00000000e25e31bd>] aa_replace_profiles+0x18a/0x1d10
          [<00000000350d9415>] policy_update+0x237/0x650
          [<000000003fbf934e>] profile_load+0x122/0x160
          [<0000000047f7b781>] vfs_write+0x139/0x290
          [<000000008ad12358>] ksys_write+0xcd/0x170
          [<000000001a9daa7b>] do_syscall_64+0x70/0x310
          [<00000000b9efb0cf>] entry_SYSCALL_64_after_hwframe+0x49/0xb3
      
      Make sure to cleanup the profile's embedde...
      3622ad25
    • John Johansen's avatar
      apparmor: fix introspection of of task mode for unconfined tasks · dd2569fb
      John Johansen authored
      Fix two issues with introspecting the task mode.
      
      1. If a task is attached to a unconfined profile that is not the
         ns->unconfined profile then. Mode the mode is always reported
         as -
      
            $ ps -Z
            LABEL                               PID TTY          TIME CMD
            unconfined                         1287 pts/0    00:00:01 bash
            test (-)                           1892 pts/0    00:00:00 ps
      
         instead of the correct value of (unconfined) as shown below
      
            $ ps -Z
            LABEL                               PID TTY          TIME CMD
            unconfined                         2483 pts/0    00:00:01 bash
            test (unconfined)                  3591 pts/0    00:00:00 ps
      
      2. if a task is confined by a stack of profiles that are unconfined
         the output of label mode is again the incorrect value of (-) like
         above, instead of (unconfined). This is because the visibile
         profile count increment is skipped by the special casing of
         unconfined.
      
      Fixes: f1bd9041
      
       ("apparmor: add the base fns() for domain labels")
      Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
      dd2569fb
    • Mauricio Faria de Oliveira's avatar
      apparmor: check/put label on apparmor_sk_clone_security() · 3b646abc
      Mauricio Faria de Oliveira authored
      Currently apparmor_sk_clone_security() does not check for existing
      label/peer in the 'new' struct sock; it just overwrites it, if any
      (with another reference to the label of the source sock.)
      
          static void apparmor_sk_clone_security(const struct sock *sk,
                                                 struct sock *newsk)
          {
                  struct aa_sk_ctx *ctx = SK_CTX(sk);
                  struct aa_sk_ctx *new = SK_CTX(newsk);
      
                  new->label = aa_get_label(ctx->label);
                  new->peer = aa_get_label(ctx->peer);
          }
      
      This might leak label references, which might overflow under load.
      Thus, check for and put labels, to prevent such errors.
      
      Note this is similarly done on:
      
          static int apparmor_socket_post_create(struct socket *sock, ...)
          ...
                  if (sock->sk) {
                          struct aa_sk_ctx *ctx = SK_CTX(sock->sk);
      
                          aa_put_label(ctx->label);
                          ctx->label = aa_get_label(label);
                  }
          ...
      
      Context:
      -------
      
      The label reference count leak is observed if apparmor_sock_graft()
      is called previously: this sets the 'ctx->label' field by getting
      a reference to the current label (later overwritten, without put.)
      
          static void apparmor_sock_graft(struct sock *sk, ...)
          {
                  struct aa_sk_ctx *ctx = SK_CTX(sk);
      
                  if (!ctx->label)
                          ctx->label = aa_get_current_label();
          }
      
      And that is the case on crypto/af_alg.c:af_alg_accept():
      
          int af_alg_accept(struct sock *sk, struct socket *newsock, ...)
          ...
                  struct sock *sk2;
                  ...
                  sk2 = sk_alloc(...);
                  ...
                  security_sock_graft(sk2, newsock);
                  security_sk_clone(sk, sk2);
          ...
      
      Apparently both calls are done on their own right, especially for
      other LSMs, being introduced in 2010/2014, before apparmor socket
      mediation in 2017 (see commits [1,2,3,4]).
      
      So, it looks OK there! Let's fix the reference leak in apparmor.
      
      Test-case:
      ---------
      
      Exercise that code path enough to overflow label reference count.
      
          $ cat aa-refcnt-af_alg.c
          #include <stdio.h>
          #include <string.h>
          #include <unistd.h>
          #include <sys/socket.h>
          #include <linux/if_alg.h>
      
          int main() {
                  int sockfd;
                  struct sockaddr_alg sa;
      
                  /* Setup the crypto API socket */
                  sockfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
                  if (sockfd < 0) {
                          perror("socket");
                          return 1;
                  }
      
                  memset(&sa, 0, sizeof(sa));
                  sa.salg_family = AF_ALG;
                  strcpy((char *) sa.salg_type, "rng");
                  strcpy((char *) sa.salg_name, "stdrng");
      
                  if (bind(sockfd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
                          perror("bind");
                          return 1;
                  }
      
                  /* Accept a "connection" and close it; repeat. */
                  while (!close(accept(sockfd, NULL, 0)));
      
                  return 0;
          }
      
          $ gcc -o aa-refcnt-af_alg aa-refcnt-af_alg.c
      
          $ ./aa-refcnt-af_alg
          <a few hours later>
      
          [ 9928.475953] refcount_t overflow at apparmor_sk_clone_security+0x37/0x70 in aa-refcnt-af_alg[1322], uid/euid: 1000/1000
          ...
          [ 9928.507443] RIP: 0010:apparmor_sk_clone_security+0x37/0x70
          ...
          [ 9928.514286]  security_sk_clone+0x33/0x50
          [ 9928.514807]  af_alg_accept+0x81/0x1c0 [af_alg]
          [ 9928.516091]  alg_accept+0x15/0x20 [af_alg]
          [ 9928.516682]  SYSC_accept4+0xff/0x210
          [ 9928.519609]  SyS_accept+0x10/0x20
          [ 9928.520190]  do_syscall_64+0x73/0x130
          [ 9928.520808]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
      
      Note that other messages may be seen, not just overflow, depending on
      the value being incremented by kref_get(); on another run:
      
          [ 7273.182666] refcount_t: saturated; leaking memory.
          ...
          [ 7273.185789] refcount_t: underflow; use-after-free.
      
      Kprobes:
      -------
      
      Using kprobe events to monitor sk -> sk_security -> label -> count (kref):
      
      Original v5.7 (one reference leak every iteration)
      
       ... (af_alg_accept+0x0/0x1c0) label=0xffff8a0f36c25eb0 label_refcnt=0x11fd2
       ... (af_alg_release_parent+0x0/0xd0) label=0xffff8a0f36c25eb0 label_refcnt=0x11fd4
       ... (af_alg_accept+0x0/0x1c0) label=0xffff8a0f36c25eb0 label_refcnt=0x11fd3
       ... (af_alg_release_parent+0x0/0xd0) label=0xffff8a0f36c25eb0 label_refcnt=0x11fd5
       ... (af_alg_accept+0x0/0x1c0) label=0xffff8a0f36c25eb0 label_refcnt=0x11fd4
       ... (af_alg_release_parent+0x0/0xd0) label=0xffff8a0f36c25eb0 label_refcnt=0x11fd6
      
      Patched v5.7 (zero reference leak per iteration)
      
       ... (af_alg_accept+0x0/0x1c0) label=0xffff9ff376c25eb0 label_refcnt=0x593
       ... (af_alg_release_parent+0x0/0xd0) label=0xffff9ff376c25eb0 label_refcnt=0x594
       ... (af_alg_accept+0x0/0x1c0) label=0xffff9ff376c25eb0 label_refcnt=0x593
       ... (af_alg_release_parent+0x0/0xd0) label=0xffff9ff376c25eb0 label_refcnt=0x594
       ... (af_alg_accept+0x0/0x1c0) label=0xffff9ff376c25eb0 label_refcnt=0x593
       ... (af_alg_release_parent+0x0/0xd0) label=0xffff9ff376c25eb0 label_refcnt=0x594
      
      Commits:
      -------
      
      [1] commit 507cad35 ("crypto: af_alg - Make sure sk_security is initialized on accept()ed sockets")
      [2] commit 4c63f83c ("crypto: af_alg - properly label AF_ALG socket")
      [3] commit 2acce6aa ("Networking") a.k.a ("crypto: af_alg - Avoid sock_graft call warning)
      [4] commit 56974a6f ("apparmor: add base infastructure for socket mediation")
      
      Fixes: 56974a6f
      
       ("apparmor: add base infastructure for socket mediation")
      Reported-by: default avatarBrian Moyles <bmoyles@netflix.com>
      Signed-off-by: default avatarMauricio Faria de Oliveira <mfo@canonical.com>
      Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
      3b646abc
  15. 05 Jun, 2020 2 commits
  16. 03 Jun, 2020 3 commits
    • Roberto Sassu's avatar
      ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init() · 6cc7c266
      Roberto Sassu authored
      If the template field 'd' is chosen and the digest to be added to the
      measurement entry was not calculated with SHA1 or MD5, it is
      recalculated with SHA1, by using the passed file descriptor. However, this
      cannot be done for boot_aggregate, because there is no file descriptor.
      
      This patch adds a call to ima_calc_boot_aggregate() in
      ima_eventdigest_init(), so that the digest can be recalculated also for the
      boot_aggregate entry.
      
      Cc: stable@vger.kernel.org # 3.13.x
      Fixes: 3ce1217d
      
       ("ima: define template fields library and new helpers")
      Reported-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      6cc7c266
    • Roberto Sassu's avatar
      ima: Directly assign the ima_default_policy pointer to ima_rules · 067a436b
      Roberto Sassu authored
      This patch prevents the following oops:
      
      [   10.771813] BUG: kernel NULL pointer dereference, address: 0000000000000
      [...]
      [   10.779790] RIP: 0010:ima_match_policy+0xf7/0xb80
      [...]
      [   10.798576] Call Trace:
      [   10.798993]  ? ima_lsm_policy_change+0x2b0/0x2b0
      [   10.799753]  ? inode_init_owner+0x1a0/0x1a0
      [   10.800484]  ? _raw_spin_lock+0x7a/0xd0
      [   10.801592]  ima_must_appraise.part.0+0xb6/0xf0
      [   10.802313]  ? ima_fix_xattr.isra.0+0xd0/0xd0
      [   10.803167]  ima_must_appraise+0x4f/0x70
      [   10.804004]  ima_post_path_mknod+0x2e/0x80
      [   10.804800]  do_mknodat+0x396/0x3c0
      
      It occurs when there is a failure during IMA initialization, and
      ima_init_policy() is not called. IMA hooks still call ima_match_policy()
      but ima_rules is NULL. This patch prevents the crash by directly assigning
      the ima_default_policy pointer to ima_rules when ima_rules is defined. This
      wouldn't alter the existing behavior, as ima_rules is always set at the end
      of ima_init_policy().
      
      Cc: stable@vger.kernel.org # 3.7.x
      Fixes: 07f6a794
      
       ("ima: add appraise action keywords and default rules")
      Reported-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      067a436b
    • Miklos Szeredi's avatar
      ovl: call secutiry hook in ovl_real_ioctl() · 292f902a
      Miklos Szeredi authored
      
      Verify LSM permissions for underlying file, since vfs_ioctl() doesn't do
      it.
      
      [Stephen Rothwell] export security_file_ioctl
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
      292f902a
  17. 02 Jun, 2020 2 commits
    • David Howells's avatar
      keys: Implement update for the big_key type · b6f61c31
      David Howells authored
      
      Implement the ->update op for the big_key type.
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Acked-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      b6f61c31
    • Jason A. Donenfeld's avatar
      security/keys: rewrite big_key crypto to use library interface · 521fd61c
      Jason A. Donenfeld authored
      
      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: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      521fd61c
  18. 01 Jun, 2020 1 commit
  19. 30 May, 2020 2 commits
    • Eric W. Biederman's avatar
      exec: Compute file based creds only once · 56305aa9
      Eric W. Biederman authored
      
      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: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      56305aa9
    • Eric W. Biederman's avatar
      exec: Add a per bprm->file version of per_clear · a7868323
      Eric W. Biederman authored
      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: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      a7868323
  20. 29 May, 2020 1 commit
  21. 26 May, 2020 1 commit
    • Eric W. Biederman's avatar
      exec: Always set cap_ambient in cap_bprm_set_creds · a4ae32c7
      Eric W. Biederman authored
      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: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      a4ae32c7
  22. 22 May, 2020 1 commit
  23. 21 May, 2020 1 commit