1. 17 Aug, 2018 8 commits
    • Eric Biggers's avatar
      crypto: blkcipher - fix crash flushing dcache in error path · 2cde72d9
      Eric Biggers authored
      commit 0868def3 upstream.
      
      Like the skcipher_walk case:
      
      scatterwalk_done() is only meant to be called after a nonzero number of
      bytes have been processed, since scatterwalk_pagedone() will flush the
      dcache of the *previous* page.  But in the error case of
      blkcipher_walk_done(), e.g. if the input wasn't an integer number of
      blocks, scatterwalk_done() was actually called after advancing 0 bytes.
      This caused a crash ("BUG: unable to handle kernel paging request")
      during '!PageSlab(page)' on architectures like arm and arm64 that define
      ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE, provided that the input was
      page-aligned as in that case walk->offset == 0.
      
      Fix it by reorganizing blkcipher_walk_done() to skip the
      scatterwalk_advance() and scatterwalk_done() if an error has occurred.
      
      This bug was found by syzkaller fuzzing.
      
      Reproducer, assuming ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE:
      
      	#include <linux/if_alg.h>
      	#include <sys/socket.h>
      	#include <unistd.h>
      
      	int main()
      	{
      		struct sockaddr_alg addr = {
      			.salg_type = "skcipher",
      			.salg_name = "ecb(aes-generic)",
      		};
      		char buffer[4096] __attribute__((aligned(4096))) = { 0 };
      		int fd;
      
      		fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
      		bind(fd, (void *)&addr, sizeof(addr));
      		setsockopt(fd, SOL_ALG, ALG_SET_KEY, buffer, 16);
      		fd = accept(fd, NULL, NULL);
      		write(fd, buffer, 15);
      		read(fd, buffer, 15);
      	}
      Reported-by: default avatarLiu Chao <liuchao741@huawei.com>
      Fixes: 5cde0af2 ("[CRYPTO] cipher: Added block cipher type")
      Cc: <stable@vger.kernel.org> # v2.6.19+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2cde72d9
    • Eric Biggers's avatar
      crypto: vmac - separate tfm and request context · e7aefb13
      Eric Biggers authored
      commit bb296481 upstream.
      
      syzbot reported a crash in vmac_final() when multiple threads
      concurrently use the same "vmac(aes)" transform through AF_ALG.  The bug
      is pretty fundamental: the VMAC template doesn't separate per-request
      state from per-tfm (per-key) state like the other hash algorithms do,
      but rather stores it all in the tfm context.  That's wrong.
      
      Also, vmac_final() incorrectly zeroes most of the state including the
      derived keys and cached pseudorandom pad.  Therefore, only the first
      VMAC invocation with a given key calculates the correct digest.
      
      Fix these bugs by splitting the per-tfm state from the per-request state
      and using the proper init/update/final sequencing for requests.
      
      Reproducer for the crash:
      
          #include <linux/if_alg.h>
          #include <sys/socket.h>
          #include <unistd.h>
      
          int main()
          {
                  int fd;
                  struct sockaddr_alg addr = {
                          .salg_type = "hash",
                          .salg_name = "vmac(aes)",
                  };
                  char buf[256] = { 0 };
      
                  fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
                  bind(fd, (void *)&addr, sizeof(addr));
                  setsockopt(fd, SOL_ALG, ALG_SET_KEY, buf, 16);
                  fork();
                  fd = accept(fd, NULL, NULL);
                  for (;;)
                          write(fd, buf, 256);
          }
      
      The immediate cause of the crash is that vmac_ctx_t.partial_size exceeds
      VMAC_NHBYTES, causing vmac_final() to memset() a negative length.
      
      Reported-by: syzbot+264bca3a6e8d645550d3@syzkaller.appspotmail.com
      Fixes: f1939f7c ("crypto: vmac - New hash algorithm for intel_txt support")
      Cc: <stable@vger.kernel.org> # v2.6.32+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e7aefb13
    • Eric Biggers's avatar
      crypto: vmac - require a block cipher with 128-bit block size · ef70d145
      Eric Biggers authored
      commit 73bf20ef upstream.
      
      The VMAC template assumes the block cipher has a 128-bit block size, but
      it failed to check for that.  Thus it was possible to instantiate it
      using a 64-bit block size cipher, e.g. "vmac(cast5)", causing
      uninitialized memory to be used.
      
      Add the needed check when instantiating the template.
      
      Fixes: f1939f7c ("crypto: vmac - New hash algorithm for intel_txt support")
      Cc: <stable@vger.kernel.org> # v2.6.32+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ef70d145
    • Eric Biggers's avatar
      crypto: x86/sha256-mb - fix digest copy in sha256_mb_mgr_get_comp_job_avx2() · e7382838
      Eric Biggers authored
      commit af839b4e upstream.
      
      There is a copy-paste error where sha256_mb_mgr_get_comp_job_avx2()
      copies the SHA-256 digest state from sha256_mb_mgr::args::digest to
      job_sha256::result_digest.  Consequently, the sha256_mb algorithm
      sometimes calculates the wrong digest.  Fix it.
      
      Reproducer using AF_ALG:
      
          #include <assert.h>
          #include <linux/if_alg.h>
          #include <stdio.h>
          #include <string.h>
          #include <sys/socket.h>
          #include <unistd.h>
      
          static const __u8 expected[32] =
              "\xad\x7f\xac\xb2\x58\x6f\xc6\xe9\x66\xc0\x04\xd7\xd1\xd1\x6b\x02"
              "\x4f\x58\x05\xff\x7c\xb4\x7c\x7a\x85\xda\xbd\x8b\x48\x89\x2c\xa7";
      
          int main()
          {
              int fd;
              struct sockaddr_alg addr = {
                  .salg_type = "hash",
                  .salg_name = "sha256_mb",
              };
              __u8 data[4096] = { 0 };
              __u8 digest[32];
              int ret;
              int i;
      
              fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
              bind(fd, (void *)&addr, sizeof(addr));
              fork();
              fd = accept(fd, 0, 0);
              do {
                  ret = write(fd, data, 4096);
                  assert(ret == 4096);
                  ret = read(fd, digest, 32);
                  assert(ret == 32);
              } while (memcmp(digest, expected, 32) == 0);
      
              printf("wrong digest: ");
              for (i = 0; i < 32; i++)
                  printf("%02x", digest[i]);
              printf("\n");
          }
      
      Output was:
      
          wrong digest: ad7facb2000000000000000000000000ffffffef7cb47c7a85dabd8b48892ca7
      
      Fixes: 172b1d6b ("crypto: sha256-mb - fix ctx pointer and digest copy")
      Cc: <stable@vger.kernel.org> # v4.8+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e7382838
    • Randy Dunlap's avatar
      kbuild: verify that $DEPMOD is installed · 50123ab8
      Randy Dunlap authored
      commit 934193a6 upstream.
      
      Verify that 'depmod' ($DEPMOD) is installed.
      This is a partial revert of commit 620c231c
      ("kbuild: do not check for ancient modutils tools").
      
      Also update Documentation/process/changes.rst to refer to
      kmod instead of module-init-tools.
      
      Fixes kernel bugzilla #198965:
      https://bugzilla.kernel.org/show_bug.cgi?id=198965Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Lucas De Marchi <lucas.demarchi@profusion.mobi>
      Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
      Cc: Michal Marek <michal.lkml@markovi.net>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Chih-Wei Huang <cwhuang@linux.org.tw>
      Cc: stable@vger.kernel.org # any kernel since 2012
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      50123ab8
    • Toshi Kani's avatar
      x86/mm: Disable ioremap free page handling on x86-PAE · 3d0170b8
      Toshi Kani authored
      commit f967db0b upstream.
      
      ioremap() supports pmd mappings on x86-PAE.  However, kernel's pmd
      tables are not shared among processes on x86-PAE.  Therefore, any
      update to sync'd pmd entries need re-syncing.  Freeing a pte page
      also leads to a vmalloc fault and hits the BUG_ON in vmalloc_sync_one().
      
      Disable free page handling on x86-PAE.  pud_free_pmd_page() and
      pmd_free_pte_page() simply return 0 if a given pud/pmd entry is present.
      This assures that ioremap() does not update sync'd pmd entries at the
      cost of falling back to pte mappings.
      
      Fixes: 28ee90fe ("x86/mm: implement free pmd/pte page interfaces")
      Reported-by: default avatarJoerg Roedel <joro@8bytes.org>
      Signed-off-by: default avatarToshi Kani <toshi.kani@hpe.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: mhocko@suse.com
      Cc: akpm@linux-foundation.org
      Cc: hpa@zytor.com
      Cc: cpandya@codeaurora.org
      Cc: linux-mm@kvack.org
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: stable@vger.kernel.org
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lkml.kernel.org/r/20180627141348.21777-2-toshi.kani@hpe.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3d0170b8
    • Guenter Roeck's avatar
      x86: i8259: Add missing include file · 7985292f
      Guenter Roeck authored
      commit 0a957467 upstream.
      
      i8259.h uses inb/outb and thus needs to include asm/io.h to avoid the
      following build error, as seen with x86_64:defconfig and CONFIG_SMP=n.
      
        In file included from drivers/rtc/rtc-cmos.c:45:0:
        arch/x86/include/asm/i8259.h: In function 'inb_pic':
        arch/x86/include/asm/i8259.h:32:24: error:
      	implicit declaration of function 'inb'
      
        arch/x86/include/asm/i8259.h: In function 'outb_pic':
        arch/x86/include/asm/i8259.h:45:2: error:
      	implicit declaration of function 'outb'
      Reported-by: default avatarSebastian Gottschall <s.gottschall@dd-wrt.com>
      Suggested-by: default avatarSebastian Gottschall <s.gottschall@dd-wrt.com>
      Fixes: 447ae316 ("x86: Don't include linux/irq.h from asm/hardirq.h")
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7985292f
    • Guenter Roeck's avatar
      x86/l1tf: Fix build error seen if CONFIG_KVM_INTEL is disabled · 5f7a6454
      Guenter Roeck authored
      commit 1eb46908 upstream.
      
      allmodconfig+CONFIG_INTEL_KVM=n results in the following build error.
      
        ERROR: "l1tf_vmx_mitigation" [arch/x86/kvm/kvm.ko] undefined!
      
      Fixes: 5b76a3cf ("KVM: VMX: Tell the nested hypervisor to skip L1D flush on vmentry")
      Reported-by: default avatarMeelis Roos <mroos@linux.ee>
      Cc: Meelis Roos <mroos@linux.ee>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5f7a6454
  2. 15 Aug, 2018 32 commits