1. 08 Nov, 2017 1 commit
  2. 02 Nov, 2017 21 commits
  3. 27 Oct, 2017 18 commits
    • Greg Kroah-Hartman's avatar
      Linux 4.4.95 · 9b366996
      Greg Kroah-Hartman authored
      9b366996
    • Eric Biggers's avatar
      FS-Cache: fix dereference of NULL user_key_payload · aa3a0a70
      Eric Biggers authored
      commit d124b2c5 upstream.
      
      When the file /proc/fs/fscache/objects (available with
      CONFIG_FSCACHE_OBJECT_LIST=y) is opened, we request a user key with
      description "fscache:objlist", then access its payload.  However, a
      revoked key has a NULL payload, and we failed to check for this.
      request_key() *does* skip revoked keys, but there is still a window
      where the key can be revoked before we access its payload.
      
      Fix it by checking for a NULL payload, treating it like a key which was
      already revoked at the time it was requested.
      
      Fixes: 4fbf4291 ("FS-Cache: Allow the current state of all objects to be dumped")
      Reviewed-by: default avatarJames Morris <james.l.morris@oracle.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa3a0a70
    • Eric Biggers's avatar
      fscrypto: require write access to mount to set encryption policy · 1bb1d425
      Eric Biggers authored
      commit ba63f23d upstream.
      
      [Please apply to 4.4-stable.  Note: this was already backported, but
      only to ext4; it was missed that it should go to f2fs as well.  This is
      needed to make xfstest generic/395 pass on f2fs.]
      
      Since setting an encryption policy requires writing metadata to the
      filesystem, it should be guarded by mnt_want_write/mnt_drop_write.
      Otherwise, a user could cause a write to a frozen or readonly
      filesystem.  This was handled correctly by f2fs but not by ext4.  Make
      fscrypt_process_policy() handle it rather than relying on the filesystem
      to get it right.
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Acked-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1bb1d425
    • David Howells's avatar
      KEYS: Fix race between updating and finding a negative key · 8a004cae
      David Howells authored
      commit 363b02da upstream.
      
      Consolidate KEY_FLAG_INSTANTIATED, KEY_FLAG_NEGATIVE and the rejection
      error into one field such that:
      
       (1) The instantiation state can be modified/read atomically.
      
       (2) The error can be accessed atomically with the state.
      
       (3) The error isn't stored unioned with the payload pointers.
      
      This deals with the problem that the state is spread over three different
      objects (two bits and a separate variable) and reading or updating them
      atomically isn't practical, given that not only can uninstantiated keys
      change into instantiated or rejected keys, but rejected keys can also turn
      into instantiated keys - and someone accessing the key might not be using
      any locking.
      
      The main side effect of this problem is that what was held in the payload
      may change, depending on the state.  For instance, you might observe the
      key to be in the rejected state.  You then read the cached error, but if
      the key semaphore wasn't locked, the key might've become instantiated
      between the two reads - and you might now have something in hand that isn't
      actually an error code.
      
      The state is now KEY_IS_UNINSTANTIATED, KEY_IS_POSITIVE or a negative error
      code if the key is negatively instantiated.  The key_is_instantiated()
      function is replaced with key_is_positive() to avoid confusion as negative
      keys are also 'instantiated'.
      
      Additionally, barriering is included:
      
       (1) Order payload-set before state-set during instantiation.
      
       (2) Order state-read before payload-read when using the key.
      
      Further separate barriering is necessary if RCU is being used to access the
      payload content after reading the payload pointers.
      
      Fixes: 146aa8b1 ("KEYS: Merge the type-specific data with the payload data")
      Reported-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8a004cae
    • Eric Biggers's avatar
      fscrypt: fix dereference of NULL user_key_payload · 1dda04c7
      Eric Biggers authored
      commit d60b5b78 upstream.
      
      When an fscrypt-encrypted file is opened, we request the file's master
      key from the keyrings service as a logon key, then access its payload.
      However, a revoked key has a NULL payload, and we failed to check for
      this.  request_key() *does* skip revoked keys, but there is still a
      window where the key can be revoked before we acquire its semaphore.
      
      Fix it by checking for a NULL payload, treating it like a key which was
      already revoked at the time it was requested.
      
      Fixes: 88bd6ccd ("ext4 crypto: add encryption key management facilities")
      Reviewed-by: default avatarJames Morris <james.l.morris@oracle.com>
      Cc: <stable@vger.kernel.org>    [v4.1+]
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1dda04c7
    • Jaegeuk Kim's avatar
      f2fs crypto: add missing locking for keyring_key access · 7d9e13d9
      Jaegeuk Kim authored
      commit 745e8490 upstream.
      
      This patch adopts:
      	ext4 crypto: add missing locking for keyring_key access
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7d9e13d9
    • Jaegeuk Kim's avatar
      f2fs crypto: replace some BUG_ON()'s with error checks · 4db9f111
      Jaegeuk Kim authored
      commit 66aa3e12 upstream.
      
      This patch adopts:
      	ext4 crypto: replace some BUG_ON()'s with error checks
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4db9f111
    • Oleg Nesterov's avatar
      sched/autogroup: Fix autogroup_move_group() to never skip sched_move_task() · 0f85c095
      Oleg Nesterov authored
      commit 18f649ef upstream.
      
      The PF_EXITING check in task_wants_autogroup() is no longer needed. Remove
      it, but see the next patch.
      
      However the comment is correct in that autogroup_move_group() must always
      change task_group() for every thread so the sysctl_ check is very wrong;
      we can race with cgroups and even sys_setsid() is not safe because a task
      running with task_group() == ag->tg must participate in refcounting:
      
      	int main(void)
      	{
      		int sctl = open("/proc/sys/kernel/sched_autogroup_enabled", O_WRONLY);
      
      		assert(sctl > 0);
      		if (fork()) {
      			wait(NULL); // destroy the child's ag/tg
      			pause();
      		}
      
      		assert(pwrite(sctl, "1\n", 2, 0) == 2);
      		assert(setsid() > 0);
      		if (fork())
      			pause();
      
      		kill(getppid(), SIGKILL);
      		sleep(1);
      
      		// The child has gone, the grandchild runs with kref == 1
      		assert(pwrite(sctl, "0\n", 2, 0) == 2);
      		assert(setsid() > 0);
      
      		// runs with the freed ag/tg
      		for (;;)
      			sleep(1);
      
      		return 0;
      	}
      
      crashes the kernel. It doesn't really need sleep(1), it doesn't matter if
      autogroup_move_group() actually frees the task_group or this happens later.
      Reported-by: default avatarVern Lovejoy <vlovejoy@redhat.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: hartsjc@redhat.com
      Cc: vbendel@redhat.com
      Link: http://lkml.kernel.org/r/20161114184609.GA15965@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSumit Semwal <sumit.semwal@linaro.org>
       [sumits: submit to 4.4 LTS, post testing on Hikey]
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0f85c095
    • John David Anglin's avatar
      parisc: Fix double-word compare and exchange in LWS code on 32-bit kernels · fcc65ab1
      John David Anglin authored
      commit 374b3bf8 upstream.
      
      As discussed on the debian-hppa list, double-wordcompare and exchange
      operations fail on 32-bit kernels.  Looking at the code, I realized that
      the ",ma" completer does the wrong thing in the  "ldw,ma  4(%r26), %r29"
      instruction.  This increments %r26 and causes the following store to
      write to the wrong location.
      
      Note by Helge Deller:
      The patch applies cleanly to stable kernel series if this upstream
      commit is merged in advance:
      f4125cfd ("parisc: Avoid trashing sr2 and sr3 in LWS code").
      Signed-off-by: default avatarJohn David Anglin <dave.anglin@bell.net>
      Tested-by: default avatarChristoph Biedl <debian.axhn@manchmal.in-ulm.de>
      Fixes: 89206491 ("parisc: Implement new LWS CAS supporting 64 bit operations.")
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fcc65ab1
    • John David Anglin's avatar
      parisc: Avoid trashing sr2 and sr3 in LWS code · 558ca24d
      John David Anglin authored
      commit f4125cfd upstream.
      
      There is no need to trash sr2 and sr3 in the Light-weight syscall (LWS).  sr2
      already points to kernel space (it's zero in userspace, otherwise syscalls
      wouldn't work), and since the LWS code is executed in userspace, we can simply
      ignore to preload sr3.
      Signed-off-by: default avatarJohn David Anglin <dave.anglin@bell.net>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      558ca24d
    • Eric Sesterhenn's avatar
      pkcs7: Prevent NULL pointer dereference, since sinfo is not always set. · 6f0dee7d
      Eric Sesterhenn authored
      commit 68a1fdbb upstream.
      
      The ASN.1 parser does not necessarily set the sinfo field,
      this patch prevents a NULL pointer dereference on broken
      input.
      
      Fixes: 99db4435 ("PKCS#7: Appropriately restrict authenticated attributes and content type")
      Signed-off-by: default avatarEric Sesterhenn <eric.sesterhenn@x41-dsec.de>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f0dee7d
    • David Howells's avatar
      KEYS: don't let add_key() update an uninstantiated key · 33dea302
      David Howells authored
      commit 60ff5b2f upstream.
      
      Currently, when passed a key that already exists, add_key() will call the
      key's ->update() method if such exists.  But this is heavily broken in the
      case where the key is uninstantiated because it doesn't call
      __key_instantiate_and_link().  Consequently, it doesn't do most of the
      things that are supposed to happen when the key is instantiated, such as
      setting the instantiation state, clearing KEY_FLAG_USER_CONSTRUCT and
      awakening tasks waiting on it, and incrementing key->user->nikeys.
      
      It also never takes key_construction_mutex, which means that
      ->instantiate() can run concurrently with ->update() on the same key.  In
      the case of the "user" and "logon" key types this causes a memory leak, at
      best.  Maybe even worse, the ->update() methods of the "encrypted" and
      "trusted" key types actually just dereference a NULL pointer when passed an
      uninstantiated key.
      
      Change key_create_or_update() to wait interruptibly for the key to finish
      construction before continuing.
      
      This patch only affects *uninstantiated* keys.  For now we still allow a
      negatively instantiated key to be updated (thereby positively
      instantiating it), although that's broken too (the next patch fixes it)
      and I'm not sure that anyone actually uses that functionality either.
      
      Here is a simple reproducer for the bug using the "encrypted" key type
      (requires CONFIG_ENCRYPTED_KEYS=y), though as noted above the bug
      pertained to more than just the "encrypted" key type:
      
          #include <stdlib.h>
          #include <unistd.h>
          #include <keyutils.h>
      
          int main(void)
          {
              int ringid = keyctl_join_session_keyring(NULL);
      
              if (fork()) {
                  for (;;) {
                      const char payload[] = "update user:foo 32";
      
                      usleep(rand() % 10000);
                      add_key("encrypted", "desc", payload, sizeof(payload), ringid);
                      keyctl_clear(ringid);
                  }
              } else {
                  for (;;)
                      request_key("encrypted", "desc", "callout_info", ringid);
              }
          }
      
      It causes:
      
          BUG: unable to handle kernel NULL pointer dereference at 0000000000000018
          IP: encrypted_update+0xb0/0x170
          PGD 7a178067 P4D 7a178067 PUD 77269067 PMD 0
          PREEMPT SMP
          CPU: 0 PID: 340 Comm: reproduce Tainted: G      D         4.14.0-rc1-00025-g428490e3 #796
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
          task: ffff8a467a39a340 task.stack: ffffb15c40770000
          RIP: 0010:encrypted_update+0xb0/0x170
          RSP: 0018:ffffb15c40773de8 EFLAGS: 00010246
          RAX: 0000000000000000 RBX: ffff8a467a275b00 RCX: 0000000000000000
          RDX: 0000000000000005 RSI: ffff8a467a275b14 RDI: ffffffffb742f303
          RBP: ffffb15c40773e20 R08: 0000000000000000 R09: ffff8a467a275b17
          R10: 0000000000000020 R11: 0000000000000000 R12: 0000000000000000
          R13: 0000000000000000 R14: ffff8a4677057180 R15: ffff8a467a275b0f
          FS:  00007f5d7fb08700(0000) GS:ffff8a467f200000(0000) knlGS:0000000000000000
          CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
          CR2: 0000000000000018 CR3: 0000000077262005 CR4: 00000000001606f0
          Call Trace:
           key_create_or_update+0x2bc/0x460
           SyS_add_key+0x10c/0x1d0
           entry_SYSCALL_64_fastpath+0x1f/0xbe
          RIP: 0033:0x7f5d7f211259
          RSP: 002b:00007ffed03904c8 EFLAGS: 00000246 ORIG_RAX: 00000000000000f8
          RAX: ffffffffffffffda RBX: 000000003b2a7955 RCX: 00007f5d7f211259
          RDX: 00000000004009e4 RSI: 00000000004009ff RDI: 0000000000400a04
          RBP: 0000000068db8bad R08: 000000003b2a7955 R09: 0000000000000004
          R10: 000000000000001a R11: 0000000000000246 R12: 0000000000400868
          R13: 00007ffed03905d0 R14: 0000000000000000 R15: 0000000000000000
          Code: 77 28 e8 64 34 1f 00 45 31 c0 31 c9 48 8d 55 c8 48 89 df 48 8d 75 d0 e8 ff f9 ff ff 85 c0 41 89 c4 0f 88 84 00 00 00 4c 8b 7d c8 <49> 8b 75 18 4c 89 ff e8 24 f8 ff ff 85 c0 41 89 c4 78 6d 49 8b
          RIP: encrypted_update+0xb0/0x170 RSP: ffffb15c40773de8
          CR2: 0000000000000018
      Reported-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Eric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      33dea302
    • Eric Biggers's avatar
      lib/digsig: fix dereference of NULL user_key_payload · 503ef5c0
      Eric Biggers authored
      commit 192cabd6 upstream.
      
      digsig_verify() requests a user key, then accesses its payload.
      However, a revoked key has a NULL payload, and we failed to check for
      this.  request_key() *does* skip revoked keys, but there is still a
      window where the key can be revoked before we acquire its semaphore.
      
      Fix it by checking for a NULL payload, treating it like a key which was
      already revoked at the time it was requested.
      
      Fixes: 051dbb91 ("crypto: digital signature verification support")
      Reviewed-by: default avatarJames Morris <james.l.morris@oracle.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      503ef5c0
    • Eric Biggers's avatar
      KEYS: encrypted: fix dereference of NULL user_key_payload · 2b7e0226
      Eric Biggers authored
      commit 13923d08 upstream.
      
      A key of type "encrypted" references a "master key" which is used to
      encrypt and decrypt the encrypted key's payload.  However, when we
      accessed the master key's payload, we failed to handle the case where
      the master key has been revoked, which sets the payload pointer to NULL.
      Note that request_key() *does* skip revoked keys, but there is still a
      window where the key can be revoked before we acquire its semaphore.
      
      Fix it by checking for a NULL payload, treating it like a key which was
      already revoked at the time it was requested.
      
      This was an issue for master keys of type "user" only.  Master keys can
      also be of type "trusted", but those cannot be revoked.
      
      Fixes: 7e70cb49 ("keys: add new key-type encrypted")
      Reviewed-by: default avatarJames Morris <james.l.morris@oracle.com>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: David Safford <safford@us.ibm.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      2b7e0226
    • Larry Finger's avatar
      rtlwifi: rtl8821ae: Fix connection lost problem · 51ba40fc
      Larry Finger authored
      commit b8b8b163 upstream.
      
      In commit 40b368af ("rtlwifi: Fix alignment issues"), the read
      of REG_DBI_READ was changed from 16 to 8 bits. For unknown reasonsi
      this change results in reduced stability for the wireless connection.
      This regression was located using bisection.
      
      Fixes: 40b368af ("rtlwifi: Fix alignment issues")
      Reported-and-tested-by: default avatarJames Cameron <quozl@laptop.org>
      Signed-off-by: default avatarLarry Finger <Larry.Finger@lwfinger.net>
      Cc: Ping-Ke Shih <pkshih@realtek.com>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      51ba40fc
    • David Kozub's avatar
      clockevents/drivers/cs5535: Improve resilience to spurious interrupts · cffdaa65
      David Kozub authored
      commit eb39a7c0 upstream.
      
      The interrupt handler mfgpt_tick() is not robust versus spurious interrupts
      which happen before the clock event device is registered and fully
      initialized.
      
      The reason is that the safe guard against spurious interrupts solely checks
      for the clockevents shutdown state, but lacks a check for detached
      state. If the interrupt hits while the device is in detached state it
      passes the safe guard and dereferences the event handler call back which is
      NULL.
      
      Add the missing state check.
      
      Fixes: 8f9327cb ("clockevents/drivers/cs5535: Migrate to new 'set-state' interface")
      Suggested-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarDavid Kozub <zub@linux.fjfi.cvut.cz>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
      Link: https://lkml.kernel.org/r/20171020093103.3317F6004D@linux.fjfi.cvut.czSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cffdaa65
    • Jan Luebbe's avatar
      bus: mbus: fix window size calculation for 4GB windows · b178c94e
      Jan Luebbe authored
      commit 2bbbd963 upstream.
      
      At least the Armada XP SoC supports 4GB on a single DRAM window. Because
      the size register values contain the actual size - 1, the MSB is set in
      that case. For example, the SDRAM window's control register's value is
      0xffffffe1 for 4GB (bits 31 to 24 contain the size).
      
      The MBUS driver reads back each window's size from registers and
      calculates the actual size as (control_reg | ~DDR_SIZE_MASK) + 1, which
      overflows for 32 bit values, resulting in other miscalculations further
      on (a bad RAM window for the CESA crypto engine calculated by
      mvebu_mbus_setup_cpu_target_nooverlap() in my case).
      
      This patch changes the type in 'struct mbus_dram_window' from u32 to
      u64, which allows us to keep using the same register calculation code in
      most MBUS-using drivers (which calculate ->size - 1 again).
      
      Fixes: fddddb52 ("bus: introduce an Marvell EBU MBus driver")
      Signed-off-by: default avatarJan Luebbe <jlu@pengutronix.de>
      Signed-off-by: default avatarGregory CLEMENT <gregory.clement@free-electrons.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b178c94e
    • Arnd Bergmann's avatar
      brcmsmac: make some local variables 'static const' to reduce stack size · 260b6739
      Arnd Bergmann authored
      commit c503dd38 upstream.
      
      With KASAN and a couple of other patches applied, this driver is one
      of the few remaining ones that actually use more than 2048 bytes of
      kernel stack:
      
      broadcom/brcm80211/brcmsmac/phy/phy_n.c: In function 'wlc_phy_workarounds_nphy_gainctrl':
      broadcom/brcm80211/brcmsmac/phy/phy_n.c:16065:1: warning: the frame size of 3264 bytes is larger than 2048 bytes [-Wframe-larger-than=]
      broadcom/brcm80211/brcmsmac/phy/phy_n.c: In function 'wlc_phy_workarounds_nphy':
      broadcom/brcm80211/brcmsmac/phy/phy_n.c:17138:1: warning: the frame size of 2864 bytes is larger than 2048 bytes [-Wframe-larger-than=]
      
      Here, I'm reducing the stack size by marking as many local variables as
      'static const' as I can without changing the actual code.
      
      This is the first of three patches to improve the stack usage in this
      driver. It would be good to have this backported to stabl kernels
      to get all drivers in 'allmodconfig' below the 2048 byte limit so
      we can turn on the frame warning again globally, but I realize that
      the patch is larger than the normal limit for stable backports.
      
      The other two patches do not need to be backported.
      Acked-by: default avatarArend van Spriel <arend.vanspriel@broadcom.com>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      260b6739