1. 30 Nov, 2017 24 commits
    • Arnd Bergmann's avatar
      isofs: fix timestamps beyond 2027 · 4e23be61
      Arnd Bergmann authored
      commit 34be4dbf upstream.
      
      isofs uses a 'char' variable to load the number of years since
      1900 for an inode timestamp. On architectures that use a signed
      char type by default, this results in an invalid date for
      anything beyond 2027.
      
      This changes the function argument to a 'u8' array, which
      is defined the same way on all architectures, and unambiguously
      lets us use years until 2155.
      
      This should be backported to all kernels that might still be
      in use by that date.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e23be61
    • Coly Li's avatar
      bcache: check ca->alloc_thread initialized before wake up it · 85c79043
      Coly Li authored
      commit 91af8300 upstream.
      
      In bcache code, sysfs entries are created before all resources get
      allocated, e.g. allocation thread of a cache set.
      
      There is posibility for NULL pointer deference if a resource is accessed
      but which is not initialized yet. Indeed Jorg Bornschein catches one on
      cache set allocation thread and gets a kernel oops.
      
      The reason for this bug is, when bch_bucket_alloc() is called during
      cache set registration and attaching, ca->alloc_thread is not properly
      allocated and initialized yet, call wake_up_process() on ca->alloc_thread
      triggers NULL pointer deference failure. A simple and fast fix is, before
      waking up ca->alloc_thread, checking whether it is allocated, and only
      wake up ca->alloc_thread when it is not NULL.
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Reported-by: default avatarJorg Bornschein <jb@capsec.org>
      Cc: Kent Overstreet <kent.overstreet@gmail.com>
      Reviewed-by: default avatarMichael Lyle <mlyle@lyle.org>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      85c79043
    • Dan Carpenter's avatar
      eCryptfs: use after free in ecryptfs_release_messaging() · 9c093a25
      Dan Carpenter authored
      commit db86be3a upstream.
      
      We're freeing the list iterator so we should be using the _safe()
      version of hlist_for_each_entry().
      
      Fixes: 88b4a07e ("[PATCH] eCryptfs: Public key transport mechanism")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarTyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9c093a25
    • Andreas Rohner's avatar
      nilfs2: fix race condition that causes file system corruption · 7d7b05e4
      Andreas Rohner authored
      commit 31ccb1f7 upstream.
      
      There is a race condition between nilfs_dirty_inode() and
      nilfs_set_file_dirty().
      
      When a file is opened, nilfs_dirty_inode() is called to update the
      access timestamp in the inode.  It calls __nilfs_mark_inode_dirty() in a
      separate transaction.  __nilfs_mark_inode_dirty() caches the ifile
      buffer_head in the i_bh field of the inode info structure and marks it
      as dirty.
      
      After some data was written to the file in another transaction, the
      function nilfs_set_file_dirty() is called, which adds the inode to the
      ns_dirty_files list.
      
      Then the segment construction calls nilfs_segctor_collect_dirty_files(),
      which goes through the ns_dirty_files list and checks the i_bh field.
      If there is a cached buffer_head in i_bh it is not marked as dirty
      again.
      
      Since nilfs_dirty_inode() and nilfs_set_file_dirty() use separate
      transactions, it is possible that a segment construction that writes out
      the ifile occurs in-between the two.  If this happens the inode is not
      on the ns_dirty_files list, but its ifile block is still marked as dirty
      and written out.
      
      In the next segment construction, the data for the file is written out
      and nilfs_bmap_propagate() updates the b-tree.  Eventually the bmap root
      is written into the i_bh block, which is not dirty, because it was
      written out in another segment construction.
      
      As a result the bmap update can be lost, which leads to file system
      corruption.  Either the virtual block address points to an unallocated
      DAT block, or the DAT entry will be reused for something different.
      
      The error can remain undetected for a long time.  A typical error
      message would be one of the "bad btree" errors or a warning that a DAT
      entry could not be found.
      
      This bug can be reproduced reliably by a simple benchmark that creates
      and overwrites millions of 4k files.
      
      Link: http://lkml.kernel.org/r/1509367935-3086-2-git-send-email-konishi.ryusuke@lab.ntt.co.jpSigned-off-by: default avatarAndreas Rohner <andreas.rohner@gmx.net>
      Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
      Tested-by: default avatarAndreas Rohner <andreas.rohner@gmx.net>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7d7b05e4
    • NeilBrown's avatar
      autofs: don't fail mount for transient error · 9a4e08c6
      NeilBrown authored
      commit ecc0c469 upstream.
      
      Currently if the autofs kernel module gets an error when writing to the
      pipe which links to the daemon, then it marks the whole moutpoint as
      catatonic, and it will stop working.
      
      It is possible that the error is transient.  This can happen if the
      daemon is slow and more than 16 requests queue up.  If a subsequent
      process tries to queue a request, and is then signalled, the write to
      the pipe will return -ERESTARTSYS and autofs will take that as total
      failure.
      
      So change the code to assess -ERESTARTSYS and -ENOMEM as transient
      failures which only abort the current request, not the whole mountpoint.
      
      It isn't a crash or a data corruption, but having autofs mountpoints
      suddenly stop working is rather inconvenient.
      
      Ian said:
      
      : And given the problems with a half dozen (or so) user space applications
      : consuming large amounts of CPU under heavy mount and umount activity this
      : could happen more easily than we expect.
      
      Link: http://lkml.kernel.org/r/87y3norvgp.fsf@notabene.neil.brown.nameSigned-off-by: default avatarNeilBrown <neilb@suse.com>
      Acked-by: default avatarIan Kent <raven@themaw.net>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9a4e08c6
    • Mirko Parthey's avatar
      MIPS: BCM47XX: Fix LED inversion for WRT54GSv1 · 15314296
      Mirko Parthey authored
      commit 56a46acf upstream.
      
      The WLAN LED on the Linksys WRT54GSv1 is active low, but the software
      treats it as active high. Fix the inverted logic.
      
      Fixes: 7bb26b16 ("MIPS: BCM47xx: Fix LEDs on WRT54GS V1.0")
      Signed-off-by: default avatarMirko Parthey <mirko.parthey@web.de>
      Looks-ok-by: default avatarRafał Miłecki <zajec5@gmail.com>
      Cc: Hauke Mehrtens <hauke@hauke-m.de>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16071/Signed-off-by: default avatarJames Hogan <jhogan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      15314296
    • Maciej W. Rozycki's avatar
      MIPS: Fix an n32 core file generation regset support regression · 00fd53bc
      Maciej W. Rozycki authored
      commit 547da673 upstream.
      
      Fix a commit 7aeb753b ("MIPS: Implement task_user_regset_view.")
      regression, then activated by commit 6a9c001b ("MIPS: Switch ELF
      core dumper to use regsets.)", that caused n32 processes to dump o32
      core files by failing to set the EF_MIPS_ABI2 flag in the ELF core file
      header's `e_flags' member:
      
      $ file tls-core
      tls-core: ELF 32-bit MSB executable, MIPS, N32 MIPS64 rel2 version 1 (SYSV), [...]
      $ ./tls-core
      Aborted (core dumped)
      $ file core
      core: ELF 32-bit MSB core file MIPS, MIPS-I version 1 (SYSV), SVR4-style
      $
      
      Previously the flag was set as the result of a:
      
      statement placed in arch/mips/kernel/binfmt_elfn32.c, however in the
      regset case, i.e. when CORE_DUMP_USE_REGSET is set, ELF_CORE_EFLAGS is
      no longer used by `fill_note_info' in fs/binfmt_elf.c, and instead the
      `->e_flags' member of the regset view chosen is.  We have the views
      defined in arch/mips/kernel/ptrace.c, however only an o32 and an n64
      one, and the latter is used for n32 as well.  Consequently an o32 core
      file is incorrectly dumped from n32 processes (the ELF32 vs ELF64 class
      is chosen elsewhere, and the 32-bit one is correctly selected for n32).
      
      Correct the issue then by defining an n32 regset view and using it as
      appropriate.  Issue discovered in GDB testing.
      
      Fixes: 7aeb753b ("MIPS: Implement task_user_regset_view.")
      Signed-off-by: default avatarMaciej W. Rozycki <macro@mips.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Djordje Todorovic <djordje.todorovic@rt-rk.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/17617/Signed-off-by: default avatarJames Hogan <jhogan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00fd53bc
    • Hou Tao's avatar
      dm: fix race between dm_get_from_kobject() and __dm_destroy() · 4e82464a
      Hou Tao authored
      commit b9a41d21 upstream.
      
      The following BUG_ON was hit when testing repeat creation and removal of
      DM devices:
      
          kernel BUG at drivers/md/dm.c:2919!
          CPU: 7 PID: 750 Comm: systemd-udevd Not tainted 4.1.44
          Call Trace:
           [<ffffffff81649e8b>] dm_get_from_kobject+0x34/0x3a
           [<ffffffff81650ef1>] dm_attr_show+0x2b/0x5e
           [<ffffffff817b46d1>] ? mutex_lock+0x26/0x44
           [<ffffffff811df7f5>] sysfs_kf_seq_show+0x83/0xcf
           [<ffffffff811de257>] kernfs_seq_show+0x23/0x25
           [<ffffffff81199118>] seq_read+0x16f/0x325
           [<ffffffff811de994>] kernfs_fop_read+0x3a/0x13f
           [<ffffffff8117b625>] __vfs_read+0x26/0x9d
           [<ffffffff8130eb59>] ? security_file_permission+0x3c/0x44
           [<ffffffff8117bdb8>] ? rw_verify_area+0x83/0xd9
           [<ffffffff8117be9d>] vfs_read+0x8f/0xcf
           [<ffffffff81193e34>] ? __fdget_pos+0x12/0x41
           [<ffffffff8117c686>] SyS_read+0x4b/0x76
           [<ffffffff817b606e>] system_call_fastpath+0x12/0x71
      
      The bug can be easily triggered, if an extra delay (e.g. 10ms) is added
      between the test of DMF_FREEING & DMF_DELETING and dm_get() in
      dm_get_from_kobject().
      
      To fix it, we need to ensure the test of DMF_FREEING & DMF_DELETING and
      dm_get() are done in an atomic way, so _minor_lock is used.
      
      The other callers of dm_get() have also been checked to be OK: some
      callers invoke dm_get() under _minor_lock, some callers invoke it under
      _hash_lock, and dm_start_request() invoke it after increasing
      md->open_count.
      Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e82464a
    • Eric Biggers's avatar
      dm bufio: fix integer overflow when limiting maximum cache size · 36c4819a
      Eric Biggers authored
      commit 74d4108d upstream.
      
      The default max_cache_size_bytes for dm-bufio is meant to be the lesser
      of 25% of the size of the vmalloc area and 2% of the size of lowmem.
      However, on 32-bit systems the intermediate result in the expression
      
          (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100
      
      overflows, causing the wrong result to be computed.  For example, on a
      32-bit system where the vmalloc area is 520093696 bytes, the result is
      1174405 rather than the expected 130023424, which makes the maximum
      cache size much too small (far less than 2% of lowmem).  This causes
      severe performance problems for dm-verity users on affected systems.
      
      Fix this by using mult_frac() to correctly multiply by a percentage.  Do
      this for all places in dm-bufio that multiply by a percentage.  Also
      replace (VMALLOC_END - VMALLOC_START) with VMALLOC_TOTAL, which contrary
      to the comment is now defined in include/linux/vmalloc.h.
      
      Depends-on: 9993bc63 ("sched/x86: Fix overflow in cyc2ns_offset")
      Fixes: 95d402f0 ("dm: add bufio")
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      36c4819a
    • Vijendar Mukunda's avatar
      ALSA: hda: Add Raven PCI ID · a9f06640
      Vijendar Mukunda authored
      commit 9ceace3c upstream.
      
      This commit adds PCI ID for Raven platform
      Signed-off-by: default avatarVijendar Mukunda <Vijendar.Mukunda@amd.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a9f06640
    • Mathias Kresin's avatar
      MIPS: ralink: Fix typo in mt7628 pinmux function · 0c1faf9d
      Mathias Kresin authored
      commit 05a67cc2 upstream.
      
      There is a typo inside the pinmux setup code. The function is called
      refclk and not reclk.
      
      Fixes: 53263a1c ("MIPS: ralink: add mt7628an support")
      Signed-off-by: default avatarMathias Kresin <dev@kresin.me>
      Acked-by: default avatarJohn Crispin <john@phrozen.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16047/Signed-off-by: default avatarJames Hogan <jhogan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c1faf9d
    • Mathias Kresin's avatar
      MIPS: ralink: Fix MT7628 pinmux · 84c785ed
      Mathias Kresin authored
      commit 8ef4b43c upstream.
      
      According to the datasheet the REFCLK pin is shared with GPIO#37 and
      the PERST pin is shared with GPIO#36.
      
      Fixes: 53263a1c ("MIPS: ralink: add mt7628an support")
      Signed-off-by: default avatarMathias Kresin <dev@kresin.me>
      Acked-by: default avatarJohn Crispin <john@phrozen.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16046/Signed-off-by: default avatarJames Hogan <jhogan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      84c785ed
    • Philip Derrin's avatar
      ARM: 8721/1: mm: dump: check hardware RO bit for LPAE · 36a082ce
      Philip Derrin authored
      commit 3b0c0c92 upstream.
      
      When CONFIG_ARM_LPAE is set, the PMD dump relies on the software
      read-only bit to determine whether a page is writable. This
      concealed a bug which left the kernel text section writable
      (AP2=0) while marked read-only in the software bit.
      
      In a kernel with the AP2 bug, the dump looks like this:
      
          ---[ Kernel Mapping ]---
          0xc0000000-0xc0200000           2M RW NX SHD
          0xc0200000-0xc0600000           4M ro x  SHD
          0xc0600000-0xc0800000           2M ro NX SHD
          0xc0800000-0xc4800000          64M RW NX SHD
      
      The fix is to check that the software and hardware bits are both
      set before displaying "ro". The dump then shows the true perms:
      
          ---[ Kernel Mapping ]---
          0xc0000000-0xc0200000           2M RW NX SHD
          0xc0200000-0xc0600000           4M RW x  SHD
          0xc0600000-0xc0800000           2M RW NX SHD
          0xc0800000-0xc4800000          64M RW NX SHD
      
      Fixes: ded94779 ("ARM: 8109/1: mm: Modify pte_write and pmd_write logic for LPAE")
      Signed-off-by: default avatarPhilip Derrin <philip@cog.systems>
      Tested-by: default avatarNeil Dick <neil@cog.systems>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      36a082ce
    • Philip Derrin's avatar
      ARM: 8722/1: mm: make STRICT_KERNEL_RWX effective for LPAE · 5f8046f7
      Philip Derrin authored
      commit 400eeffa upstream.
      
      Currently, for ARM kernels with CONFIG_ARM_LPAE and
      CONFIG_STRICT_KERNEL_RWX enabled, the 2MiB pages mapping the
      kernel code and rodata are writable. They are marked read-only in
      a software bit (L_PMD_SECT_RDONLY) but the hardware read-only bit
      is not set (PMD_SECT_AP2).
      
      For user mappings, the logic that propagates the software bit
      to the hardware bit is in set_pmd_at(); but for the kernel,
      section_update() writes the PMDs directly, skipping this logic.
      
      The fix is to set PMD_SECT_AP2 for read-only sections in
      section_update(), at the same time as L_PMD_SECT_RDONLY.
      
      Fixes: 1e347922 ("ARM: 8275/1: mm: fix PMD_SECT_RDONLY undeclared compile error")
      Signed-off-by: default avatarPhilip Derrin <philip@cog.systems>
      Reported-by: default avatarNeil Dick <neil@cog.systems>
      Tested-by: default avatarNeil Dick <neil@cog.systems>
      Tested-by: default avatarLaura Abbott <labbott@redhat.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5f8046f7
    • Masami Hiramatsu's avatar
      x86/decoder: Add new TEST instruction pattern · 29c4b6b4
      Masami Hiramatsu authored
      commit 12a78d43 upstream.
      
      The kbuild test robot reported this build warning:
      
        Warning: arch/x86/tools/test_get_len found difference at <jump_table>:ffffffff8103dd2c
      
        Warning: ffffffff8103dd82: f6 09 d8 testb $0xd8,(%rcx)
        Warning: objdump says 3 bytes, but insn_get_length() says 2
        Warning: decoded and checked 1569014 instructions with 1 warnings
      
      This sequence seems to be a new instruction not in the opcode map in the Intel SDM.
      
      The instruction sequence is "F6 09 d8", means Group3(F6), MOD(00)REG(001)RM(001), and 0xd8.
      Intel SDM vol2 A.4 Table A-6 said the table index in the group is "Encoding of Bits 5,4,3 of
      the ModR/M Byte (bits 2,1,0 in parenthesis)"
      
      In that table, opcodes listed by the index REG bits as:
      
        000         001       010 011  100        101        110         111
       TEST Ib/Iz,(undefined),NOT,NEG,MUL AL/rAX,IMUL AL/rAX,DIV AL/rAX,IDIV AL/rAX
      
      So, it seems TEST Ib is assigned to 001.
      
      Add the new pattern.
      Reported-by: default avatarkbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29c4b6b4
    • Eric Biggers's avatar
      lib/mpi: call cond_resched() from mpi_powm() loop · 4fdb1637
      Eric Biggers authored
      commit 1d9ddde1 upstream.
      
      On a non-preemptible kernel, if KEYCTL_DH_COMPUTE is called with the
      largest permitted inputs (16384 bits), the kernel spends 10+ seconds
      doing modular exponentiation in mpi_powm() without rescheduling.  If all
      threads do it, it locks up the system.  Moreover, it can cause
      rcu_sched-stall warnings.
      
      Notwithstanding the insanity of doing this calculation in kernel mode
      rather than in userspace, fix it by calling cond_resched() as each bit
      from the exponent is processed.  It's still noninterruptible, but at
      least it's preemptible now.
      
      Do the cond_resched() once per bit rather than once per MPI limb because
      each limb might still easily take 100+ milliseconds on slow CPUs.
      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>
      4fdb1637
    • Paul E. McKenney's avatar
      sched: Make resched_cpu() unconditional · 8ff34718
      Paul E. McKenney authored
      commit 7c2102e5 upstream.
      
      The current implementation of synchronize_sched_expedited() incorrectly
      assumes that resched_cpu() is unconditional, which it is not.  This means
      that synchronize_sched_expedited() can hang when resched_cpu()'s trylock
      fails as follows (analysis by Neeraj Upadhyay):
      
      o	CPU1 is waiting for expedited wait to complete:
      
      	sync_rcu_exp_select_cpus
      	     rdp->exp_dynticks_snap & 0x1   // returns 1 for CPU5
      	     IPI sent to CPU5
      
      	synchronize_sched_expedited_wait
      		 ret = swait_event_timeout(rsp->expedited_wq,
      					   sync_rcu_preempt_exp_done(rnp_root),
      					   jiffies_stall);
      
      	expmask = 0x20, CPU 5 in idle path (in cpuidle_enter())
      
      o	CPU5 handles IPI and fails to acquire rq lock.
      
      	Handles IPI
      	     sync_sched_exp_handler
      		 resched_cpu
      		     returns while failing to try lock acquire rq->lock
      		 need_resched is not set
      
      o	CPU5 calls  rcu_idle_enter() and as need_resched is not set, goes to
      	idle (schedule() is not called).
      
      o	CPU 1 reports RCU stall.
      
      Given that resched_cpu() is now used only by RCU, this commit fixes the
      assumption by making resched_cpu() unconditional.
      Reported-by: default avatarNeeraj Upadhyay <neeraju@codeaurora.org>
      Suggested-by: default avatarNeeraj Upadhyay <neeraju@codeaurora.org>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Acked-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ff34718
    • WANG Cong's avatar
      vsock: use new wait API for vsock_stream_sendmsg() · 3223ea12
      WANG Cong authored
      commit 499fde66 upstream.
      
      As reported by Michal, vsock_stream_sendmsg() could still
      sleep at vsock_stream_has_space() after prepare_to_wait():
      
        vsock_stream_has_space
          vmci_transport_stream_has_space
            vmci_qpair_produce_free_space
              qp_lock
                qp_acquire_queue_mutex
                  mutex_lock
      
      Just switch to the new wait API like we did for commit
      d9dc8b0f ("net: fix sleeping for sk_wait_event()").
      Reported-by: default avatarMichal Kubecek <mkubecek@suse.cz>
      Cc: Stefan Hajnoczi <stefanha@redhat.com>
      Cc: Jorgen Hansen <jhansen@vmware.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Cc: "Jorgen S. Hansen" <jhansen@vmware.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3223ea12
    • Claudio Imbrenda's avatar
      AF_VSOCK: Shrink the area influenced by prepare_to_wait · df24d6c2
      Claudio Imbrenda authored
      commit f7f9b5e7 upstream.
      
      When a thread is prepared for waiting by calling prepare_to_wait, sleeping
      is not allowed until either the wait has taken place or finish_wait has
      been called.  The existing code in af_vsock imposed unnecessary no-sleep
      assumptions to a broad list of backend functions.
      This patch shrinks the influence of prepare_to_wait to the area where it
      is strictly needed, therefore relaxing the no-sleep restriction there.
      Signed-off-by: default avatarClaudio Imbrenda <imbrenda@linux.vnet.ibm.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Cc: "Jorgen S. Hansen" <jhansen@vmware.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df24d6c2
    • WANG Cong's avatar
      ipv6: only call ip6_route_dev_notify() once for NETDEV_UNREGISTER · 2417da3f
      WANG Cong authored
      commit 76da0704 upstream.
      
      In commit 242d3a49 ("ipv6: reorder ip6_route_dev_notifier after ipv6_dev_notf")
      I assumed NETDEV_REGISTER and NETDEV_UNREGISTER are paired,
      unfortunately, as reported by jeffy, netdev_wait_allrefs()
      could rebroadcast NETDEV_UNREGISTER event until all refs are
      gone.
      
      We have to add an additional check to avoid this corner case.
      For netdev_wait_allrefs() dev->reg_state is NETREG_UNREGISTERED,
      for dev_change_net_namespace(), dev->reg_state is
      NETREG_REGISTERED. So check for dev->reg_state != NETREG_UNREGISTERED.
      
      Fixes: 242d3a49 ("ipv6: reorder ip6_route_dev_notifier after ipv6_dev_notf")
      Reported-by: default avatarjeffy <jeffy.chen@rock-chips.com>
      Cc: David Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Acked-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2417da3f
    • Vasily Gorbik's avatar
      s390/disassembler: increase show_code buffer size · 5c2607d3
      Vasily Gorbik authored
      commit b192571d upstream.
      
      Current buffer size of 64 is too small. objdump shows that there are
      instructions which would require up to 75 bytes buffer (with current
      formating). 128 bytes "ought to be enough for anybody".
      
      Also replaces 8 spaces with a single tab to reduce the memory footprint.
      
      Fixes the following KASAN finding:
      
      BUG: KASAN: stack-out-of-bounds in number+0x3fe/0x538
      Write of size 1 at addr 000000005a4a75a0 by task bash/1282
      
      CPU: 1 PID: 1282 Comm: bash Not tainted 4.14.0+ #215
      Hardware name: IBM 2964 N96 702 (z/VM 6.4.0)
      Call Trace:
      ([<000000000011eeb6>] show_stack+0x56/0x88)
       [<0000000000e1ce1a>] dump_stack+0x15a/0x1b0
       [<00000000004e2994>] print_address_description+0xf4/0x288
       [<00000000004e2cf2>] kasan_report+0x13a/0x230
       [<0000000000e38ae6>] number+0x3fe/0x538
       [<0000000000e3dfe4>] vsnprintf+0x194/0x948
       [<0000000000e3ea42>] sprintf+0xa2/0xb8
       [<00000000001198dc>] print_insn+0x374/0x500
       [<0000000000119346>] show_code+0x4ee/0x538
       [<000000000011f234>] show_registers+0x34c/0x388
       [<000000000011f2ae>] show_regs+0x3e/0xa8
       [<000000000011f502>] die+0x1ea/0x2e8
       [<0000000000138f0e>] do_no_context+0x106/0x168
       [<0000000000139a1a>] do_protection_exception+0x4da/0x7d0
       [<0000000000e55914>] pgm_check_handler+0x16c/0x1c0
       [<000000000090639e>] sysrq_handle_crash+0x46/0x58
      ([<0000000000000007>] 0x7)
       [<00000000009073fa>] __handle_sysrq+0x102/0x218
       [<0000000000907c06>] write_sysrq_trigger+0xd6/0x100
       [<000000000061d67a>] proc_reg_write+0xb2/0x128
       [<0000000000520be6>] __vfs_write+0xee/0x368
       [<0000000000521222>] vfs_write+0x21a/0x278
       [<000000000052156a>] SyS_write+0xda/0x178
       [<0000000000e555cc>] system_call+0xc4/0x270
      
      The buggy address belongs to the page:
      page:000003d1016929c0 count:0 mapcount:0 mapping:          (null) index:0x0
      flags: 0x0()
      raw: 0000000000000000 0000000000000000 0000000000000000 ffffffff00000000
      raw: 0000000000000100 0000000000000200 0000000000000000 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       000000005a4a7480: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
       000000005a4a7500: 00 00 00 00 00 00 00 00 f2 f2 f2 f2 00 00 00 00
      >000000005a4a7580: 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00 00 00 00
                                     ^
       000000005a4a7600: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8
       000000005a4a7680: f2 f2 f2 f2 f2 f2 f8 f8 f2 f2 f3 f3 f3 f3 00 00
      ==================================================================
      Signed-off-by: default avatarVasily Gorbik <gor@linux.vnet.ibm.com>
      Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5c2607d3
    • Heiko Carstens's avatar
      s390/disassembler: add missing end marker for e7 table · 4337fa24
      Heiko Carstens authored
      commit 5c505387 upstream.
      
      The e7 opcode table does not have an end marker. Hence when trying to
      find an unknown e7 instruction the code will access memory behind the
      table until it finds something that matches the opcode, or the kernel
      crashes, whatever comes first.
      
      This affects not only the in-kernel disassembler but also uprobes and
      kprobes which refuse to set a probe on unknown instructions, and
      therefore search the opcode tables to figure out if instructions are
      known or not.
      
      Fixes: 3585cb02 ("s390/disassembler: add vector instructions")
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4337fa24
    • Heiko Carstens's avatar
      s390/runtime instrumention: fix possible memory corruption · 04bc7a27
      Heiko Carstens authored
      commit d6e646ad upstream.
      
      For PREEMPT enabled kernels the runtime instrumentation (RI) code
      contains a possible use-after-free bug. If a task that makes use of RI
      exits, it will execute do_exit() while still enabled for preemption.
      
      That function will call exit_thread_runtime_instr() via
      exit_thread(). If exit_thread_runtime_instr() gets preempted after the
      RI control block of the task has been freed but before the pointer to
      it is set to NULL, then save_ri_cb(), called from switch_to(), will
      write to already freed memory.
      
      Avoid this and simply disable preemption while freeing the control
      block and setting the pointer to NULL.
      
      Fixes: e4b8b3f3 ("s390: add support for runtime instrumentation")
      Reviewed-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      04bc7a27
    • Heiko Carstens's avatar
      s390: fix transactional execution control register handling · 7ddbe701
      Heiko Carstens authored
      commit a1c5befc upstream.
      
      Dan Horák reported the following crash related to transactional execution:
      
      User process fault: interruption code 0013 ilc:3 in libpthread-2.26.so[3ff93c00000+1b000]
      CPU: 2 PID: 1 Comm: /init Not tainted 4.13.4-300.fc27.s390x #1
      Hardware name: IBM 2827 H43 400 (z/VM 6.4.0)
      task: 00000000fafc8000 task.stack: 00000000fafc4000
      User PSW : 0705200180000000 000003ff93c14e70
                 R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:2 PM:0 RI:0 EA:3
      User GPRS: 0000000000000077 000003ff00000000 000003ff93144d48 000003ff93144d5e
                 0000000000000000 0000000000000002 0000000000000000 000003ff00000000
                 0000000000000000 0000000000000418 0000000000000000 000003ffcc9fe770
                 000003ff93d28f50 000003ff9310acf0 000003ff92b0319a 000003ffcc9fe6d0
      User Code: 000003ff93c14e62: 60e0b030            std     %f14,48(%r11)
                 000003ff93c14e66: 60f0b038            std     %f15,56(%r11)
                #000003ff93c14e6a: e5600000ff0e        tbegin  0,65294
                >000003ff93c14e70: a7740006            brc     7,3ff93c14e7c
                 000003ff93c14e74: a7080000            lhi     %r0,0
                 000003ff93c14e78: a7f40023            brc     15,3ff93c14ebe
                 000003ff93c14e7c: b2220000            ipm     %r0
                 000003ff93c14e80: 8800001c            srl     %r0,28
      
      There are several bugs with control register handling with respect to
      transactional execution:
      
      - on task switch update_per_regs() is only called if the next task has
        an mm (is not a kernel thread). This however is incorrect. This
        breaks e.g. for user mode helper handling, where the kernel creates
        a kernel thread and then execve's a user space program. Control
        register contents related to transactional execution won't be
        updated on execve. If the previous task ran with transactional
        execution disabled then the new task will also run with
        transactional execution disabled, which is incorrect. Therefore call
        update_per_regs() unconditionally within switch_to().
      
      - on startup the transactional execution facility is not enabled for
        the idle thread. This is not really a bug, but an inconsistency to
        other facilities. Therefore enable the facility if it is available.
      
      - on fork the new thread's per_flags field is not cleared. This means
        that a child process inherits the PER_FLAG_NO_TE flag. This flag can
        be set with a ptrace request to disable transactional execution for
        the current process. It should not be inherited by new child
        processes in order to be consistent with the handling of all other
        PER related debugging options. Therefore clear the per_flags field in
        copy_thread_tls().
      Reported-and-tested-by: default avatarDan Horák <dan@danny.cz>
      Fixes: d35339a4 ("s390: add support for transactional memory")
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Reviewed-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
      Reviewed-by: default avatarHendrik Brueckner <brueckner@linux.vnet.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7ddbe701
  2. 24 Nov, 2017 16 commits