1. 22 Mar, 2018 7 commits
  2. 18 Mar, 2018 33 commits
    • Greg Kroah-Hartman's avatar
      Linux 4.4.122 · b8ea1f9b
      Greg Kroah-Hartman authored
      b8ea1f9b
    • Greg Kroah-Hartman's avatar
      fixup: sctp: verify size of a new chunk in _sctp_make_chunk() · 7b822932
      Greg Kroah-Hartman authored
      Ben writes:
      > > +	int chunklen;
      > > +
      > > +	chunklen = sizeof(*chunk_hdr) + paylen;
      > 
      > I think this length still needs to be rounded up (with WORD_ROUND here,
      > instead of SCTP_PAD4 upstream).
      
      So here's a fix for this problem.
      Reported-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7b822932
    • Nikola Ciprich's avatar
      serial: 8250_pci: Add Brainboxes UC-260 4 port serial device · 7954c6dc
      Nikola Ciprich authored
      commit 9f2068f3 upstream.
      
      Add PCI ids for two variants of Brainboxes UC-260 quad port
      PCI serial cards.
      Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarNikola Ciprich <nikola.ciprich@linuxbox.cz>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7954c6dc
    • Xinyong's avatar
      usb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb() · 551ea590
      Xinyong authored
      commit 1a087f03 upstream.
      
      When I debug a kernel crash issue in funcitonfs, found ffs_data.ref
      overflowed, While functionfs is unmounting, ffs_data is put twice.
      
      Commit 43938613 ("drivers, usb: convert ffs_data.ref from atomic_t to
      refcount_t") can avoid refcount overflow, but that is risk some situations.
      So no need put ffs data in ffs_fs_kill_sb, already put in ffs_data_closed.
      
      The issue can be reproduced in Mediatek mt6763 SoC, ffs for ADB device.
      KASAN enabled configuration reports use-after-free errro.
      
      BUG: KASAN: use-after-free in refcount_dec_and_test+0x14/0xe0 at addr ffffffc0579386a0
      Read of size 4 by task umount/4650
      ====================================================
      BUG kmalloc-512 (Tainted: P        W  O   ): kasan: bad access detected
      -----------------------------------------------------------------------------
      
      INFO: Allocated in ffs_fs_mount+0x194/0x844 age=22856 cpu=2 pid=566
          alloc_debug_processing+0x1ac/0x1e8
          ___slab_alloc.constprop.63+0x640/0x648
          __slab_alloc.isra.57.constprop.62+0x24/0x34
          kmem_cache_alloc_trace+0x1a8/0x2bc
          ffs_fs_mount+0x194/0x844
          mount_fs+0x6c/0x1d0
          vfs_kern_mount+0x50/0x1b4
          do_mount+0x258/0x1034
      INFO: Freed in ffs_data_put+0x25c/0x320 age=0 cpu=3 pid=4650
          free_debug_processing+0x22c/0x434
          __slab_free+0x2d8/0x3a0
          kfree+0x254/0x264
          ffs_data_put+0x25c/0x320
          ffs_data_closed+0x124/0x15c
          ffs_fs_kill_sb+0xb8/0x110
          deactivate_locked_super+0x6c/0x98
          deactivate_super+0xb0/0xbc
      INFO: Object 0xffffffc057938600 @offset=1536 fp=0x          (null)
      ......
      Call trace:
      [<ffffff900808cf5c>] dump_backtrace+0x0/0x250
      [<ffffff900808d3a0>] show_stack+0x14/0x1c
      [<ffffff90084a8c04>] dump_stack+0xa0/0xc8
      [<ffffff900826c2b4>] print_trailer+0x158/0x260
      [<ffffff900826d9d8>] object_err+0x3c/0x40
      [<ffffff90082745f0>] kasan_report_error+0x2a8/0x754
      [<ffffff9008274f84>] kasan_report+0x5c/0x60
      [<ffffff9008273208>] __asan_load4+0x70/0x88
      [<ffffff90084cd81c>] refcount_dec_and_test+0x14/0xe0
      [<ffffff9008d98f9c>] ffs_data_put+0x80/0x320
      [<ffffff9008d9d904>] ffs_fs_kill_sb+0xc8/0x110
      [<ffffff90082852a0>] deactivate_locked_super+0x6c/0x98
      [<ffffff900828537c>] deactivate_super+0xb0/0xbc
      [<ffffff90082af0c0>] cleanup_mnt+0x64/0xec
      [<ffffff90082af1b0>] __cleanup_mnt+0x10/0x18
      [<ffffff90080d9e68>] task_work_run+0xcc/0x124
      [<ffffff900808c8c0>] do_notify_resume+0x60/0x70
      [<ffffff90080866e4>] work_pending+0x10/0x14
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarXinyong <xinyong.fang@linux.alibaba.com>
      Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      551ea590
    • Pete Zaitcev's avatar
      usb: usbmon: Read text within supplied buffer size · abe0ecd5
      Pete Zaitcev authored
      commit a5f59683 upstream.
      
      This change fixes buffer overflows and silent data corruption with the
      usbmon device driver text file read operations.
      Signed-off-by: default avatarFredrik Noring <noring@nocrew.org>
      Signed-off-by: default avatarPete Zaitcev <zaitcev@redhat.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      abe0ecd5
    • Julia Lawall's avatar
      USB: usbmon: remove assignment from IS_ERR argument · 2feea85f
      Julia Lawall authored
      commit 46c236dc upstream.
      
      The semantic patch that makes this change is as follows:
      (http://coccinelle.lip6.fr/)
      
      // <smpl>
      @@
      expression e1,e2;
      statement S1,S2;
      @@
      
      +e1 = e2;
      if (IS_ERR(
          e1
      -   = e2
         )) S1 else S2
      // </smpl>
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2feea85f
    • Danilo Krummrich's avatar
      usb: quirks: add control message delay for 1b1c:1b20 · 38f54194
      Danilo Krummrich authored
      commit cb88a058 upstream.
      
      Corsair Strafe RGB keyboard does not respond to usb control messages
      sometimes and hence generates timeouts.
      
      Commit de3af5bf ("usb: quirks: add delay init quirk for Corsair
      Strafe RGB keyboard") tried to fix those timeouts by adding
      USB_QUIRK_DELAY_INIT.
      
      Unfortunately, even with this quirk timeouts of usb_control_msg()
      can still be seen, but with a lower frequency (approx. 1 out of 15):
      
      [   29.103520] usb 1-8: string descriptor 0 read error: -110
      [   34.363097] usb 1-8: can't set config #1, error -110
      
      Adding further delays to different locations where usb control
      messages are issued just moves the timeouts to other locations,
      e.g.:
      
      [   35.400533] usbhid 1-8:1.0: can't add hid device: -110
      [   35.401014] usbhid: probe of 1-8:1.0 failed with error -110
      
      The only way to reliably avoid those issues is having a pause after
      each usb control message. In approx. 200 boot cycles no more timeouts
      were seen.
      
      Addionaly, keep USB_QUIRK_DELAY_INIT as it turned out to be necessary
      to have the delay in hub_port_connect() after hub_port_init().
      
      The overall boot time seems not to be influenced by these additional
      delays, even on fast machines and lightweight distributions.
      
      Fixes: de3af5bf ("usb: quirks: add delay init quirk for Corsair Strafe RGB keyboard")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarDanilo Krummrich <danilokrummrich@dk-develop.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      38f54194
    • Teijo Kinnunen's avatar
      USB: storage: Add JMicron bridge 152d:2567 to unusual_devs.h · 5bf1d744
      Teijo Kinnunen authored
      commit 5126a504 upstream.
      
      This USB-SATA controller seems to be similar with JMicron bridge
      152d:2566 already on the list. Adding it here fixes "Invalid
      field in cdb" errors.
      Signed-off-by: default avatarTeijo Kinnunen <teijo.kinnunen@code-q.fi>
      Cc: stable@vger.kernel.org
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5bf1d744
    • Joel Fernandes's avatar
      staging: android: ashmem: Fix lockdep issue during llseek · e29c324d
      Joel Fernandes authored
      commit cb57469c upstream.
      
      ashmem_mutex create a chain of dependencies like so:
      
      (1)
      mmap syscall ->
        mmap_sem ->  (acquired)
        ashmem_mmap
        ashmem_mutex (try to acquire)
        (block)
      
      (2)
      llseek syscall ->
        ashmem_llseek ->
        ashmem_mutex ->  (acquired)
        inode_lock ->
        inode->i_rwsem (try to acquire)
        (block)
      
      (3)
      getdents ->
        iterate_dir ->
        inode_lock ->
        inode->i_rwsem   (acquired)
        copy_to_user ->
        mmap_sem         (try to acquire)
      
      There is a lock ordering created between mmap_sem and inode->i_rwsem
      causing a lockdep splat [2] during a syzcaller test, this patch fixes
      the issue by unlocking the mutex earlier. Functionally that's Ok since
      we don't need to protect vfs_llseek.
      
      [1] https://patchwork.kernel.org/patch/10185031/
      [2] https://lkml.org/lkml/2018/1/10/48Acked-by: default avatarTodd Kjos <tkjos@google.com>
      Cc: Arve Hjonnevag <arve@android.com>
      Cc: stable@vger.kernel.org
      Reported-by: syzbot+8ec30bb7bf1a981a2012@syzkaller.appspotmail.com
      Signed-off-by: default avatarJoel Fernandes <joelaf@google.com>
      Acked-by: default avatarGreg Hackmann <ghackmann@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e29c324d
    • Frank Mori Hess's avatar
      staging: comedi: fix comedi_nsamples_left. · 76e267cd
      Frank Mori Hess authored
      commit a42ae590 upstream.
      
      A rounding error was causing comedi_nsamples_left to
      return the wrong value when nsamples was not a multiple
      of the scan length.
      
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by: default avatarFrank Mori Hess <fmh6jj@gmail.com>
      Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      76e267cd
    • Oliver Neukum's avatar
      uas: fix comparison for error code · 131967e8
      Oliver Neukum authored
      commit 9a513c90 upstream.
      
      A typo broke the comparison.
      
      Fixes: cbeef22f ("usb: uas: unconditionally bring back host after reset")
      Signed-off-by: default avatarOliver Neukum <oneukum@suse.com>
      CC: stable@kernel.org
      Acked-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      131967e8
    • Jonas Danielsson's avatar
      tty/serial: atmel: add new version check for usart · b583e6eb
      Jonas Danielsson authored
      commit fd63a890 upstream.
      
      On our at91sam9260 based board the usart0 and usart1 ports report
      their versions (ATMEL_US_VERSION) as 0x10302. This version is not
      included in the current checks in the driver.
      Signed-off-by: default avatarJonas Danielsson <jonas@orbital-systems.com>
      Acked-by: default avatarRichard Genoud <richard.genoud@gmail.com>
      Acked-by: default avatarNicolas Ferre <nicolas.ferre@microchip.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b583e6eb
    • Ulrich Hecht's avatar
      serial: sh-sci: prevent lockup on full TTY buffers · e79e49e7
      Ulrich Hecht authored
      commit 7842055b upstream.
      
      When the TTY buffers fill up to the configured maximum, a system lockup
      occurs:
      
      [  598.820128] INFO: rcu_preempt detected stalls on CPUs/tasks:
      [  598.825796]  0-...!: (1 GPs behind) idle=5a6/2/0 softirq=1974/1974 fqs=1
      [  598.832577]  (detected by 3, t=62517 jiffies, g=296, c=295, q=126)
      [  598.838755] Task dump for CPU 0:
      [  598.841977] swapper/0       R  running task        0     0      0 0x00000022
      [  598.849023] Call trace:
      [  598.851476]  __switch_to+0x98/0xb0
      [  598.854870]            (null)
      
      This can be prevented by doing a dummy read of the RX data register.
      
      This issue affects both HSCIF and SCIF ports. Reported for R-Car H3 ES2.0;
      reproduced and fixed on H3 ES1.1. Probably affects other R-Car platforms
      as well.
      Reported-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Signed-off-by: default avatarUlrich Hecht <ulrich.hecht+renesas@gmail.com>
      Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Cc: stable <stable@vger.kernel.org>
      Tested-by: default avatarNguyen Viet Dung <dung.nguyen.aj@renesas.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e79e49e7
    • H.J. Lu's avatar
      x86: Treat R_X86_64_PLT32 as R_X86_64_PC32 · 6b0ce59b
      H.J. Lu authored
      commit b21ebf2f upstream.
      
      On i386, there are 2 types of PLTs, PIC and non-PIC.  PIE and shared
      objects must use PIC PLT.  To use PIC PLT, you need to load
      _GLOBAL_OFFSET_TABLE_ into EBX first.  There is no need for that on
      x86-64 since x86-64 uses PC-relative PLT.
      
      On x86-64, for 32-bit PC-relative branches, we can generate PLT32
      relocation, instead of PC32 relocation, which can also be used as
      a marker for 32-bit PC-relative branches.  Linker can always reduce
      PLT32 relocation to PC32 if function is defined locally.   Local
      functions should use PC32 relocation.  As far as Linux kernel is
      concerned, R_X86_64_PLT32 can be treated the same as R_X86_64_PC32
      since Linux kernel doesn't use PLT.
      
      R_X86_64_PLT32 for 32-bit PC-relative branches has been enabled in
      binutils master branch which will become binutils 2.31.
      
      [ hjl is working on having better documentation on this all, but a few
        more notes from him:
      
         "PLT32 relocation is used as marker for PC-relative branches. Because
          of EBX, it looks odd to generate PLT32 relocation on i386 when EBX
          doesn't have GOT.
      
          As for symbol resolution, PLT32 and PC32 relocations are almost
          interchangeable. But when linker sees PLT32 relocation against a
          protected symbol, it can resolved locally at link-time since it is
          used on a branch instruction. Linker can't do that for PC32
          relocation"
      
        but for the kernel use, the two are basically the same, and this
        commit gets things building and working with the current binutils
        master   - Linus ]
      Signed-off-by: default avatarH.J. Lu <hjl.tools@gmail.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6b0ce59b
    • Josh Poimboeuf's avatar
      x86/module: Detect and skip invalid relocations · 138d1901
      Josh Poimboeuf authored
      commit eda9cec4 upstream.
      
      There have been some cases where external tooling (e.g., kpatch-build)
      creates a corrupt relocation which targets the wrong address.  This is a
      silent failure which can corrupt memory in unexpected places.
      
      On x86, the bytes of data being overwritten by relocations are always
      initialized to zero beforehand.  Use that knowledge to add sanity checks
      to detect such cases before they corrupt memory.
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: jeyu@kernel.org
      Cc: live-patching@vger.kernel.org
      Link: http://lkml.kernel.org/r/37450d6c6225e54db107fba447ce9e56e5f758e9.1509713553.git.jpoimboe@redhat.com
      [ Restructured the messages, as it's unclear whether the relocation or the target is corrupted. ]
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      138d1901
    • Greg Kroah-Hartman's avatar
      Revert "ARM: dts: LogicPD Torpedo: Fix I2C1 pinmux" · 8d02a551
      Greg Kroah-Hartman authored
      This reverts commit c86bfc7b which was
      commit 74402055 upstream.
      
      The backport merged incorrectly, so I'm dropping it.
      Reported-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
      Cc: Adam Ford <aford173@gmail.com>
      Cc: Tony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      8d02a551
    • Trond Myklebust's avatar
      NFS: Fix an incorrect type in struct nfs_direct_req · 099bccc1
      Trond Myklebust authored
      commit d9ee6553 upstream.
      
      The start offset needs to be of type loff_t.
      
      Fixed: 5fadeb47 ("nfs: count DIO good bytes correctly with mirroring")
      Cc: stable@vger.kernel.org # v4.0+
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      099bccc1
    • Quinn Tran's avatar
      scsi: qla2xxx: Replace fcport alloc with qla2x00_alloc_fcport · 7f566971
      Quinn Tran authored
      commit 063b36d6 upstream.
      
      Current code manually allocate an fcport structure that is not properly
      initialize. Replace kzalloc with qla2x00_alloc_fcport, so that all
      fields are initialized.  Also set set scan flag to port found
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarQuinn Tran <quinn.tran@cavium.com>
      Signed-off-by: default avatarHimanshu Madhani <himanshu.madhani@cavium.com>
      Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7f566971
    • Clay McClure's avatar
      ubi: Fix race condition between ubi volume creation and udev · 35482f62
      Clay McClure authored
      commit a51a0c8d upstream.
      
      Similar to commit 714fb87e ("ubi: Fix race condition between ubi
      device creation and udev"), we should make the volume active before
      registering it.
      Signed-off-by: default avatarClay McClure <clay@daemons.net>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      35482f62
    • Tahsin Erdogan's avatar
      ext4: inplace xattr block update fails to deduplicate blocks · 0683564e
      Tahsin Erdogan authored
      commit ec000220 upstream.
      
      When an xattr block has a single reference, block is updated inplace
      and it is reinserted to the cache. Later, a cache lookup is performed
      to see whether an existing block has the same contents. This cache
      lookup will most of the time return the just inserted entry so
      deduplication is not achieved.
      
      Running the following test script will produce two xattr blocks which
      can be observed in "File ACL: " line of debugfs output:
      
        mke2fs -b 1024 -I 128 -F -O extent /dev/sdb 1G
        mount /dev/sdb /mnt/sdb
      
        touch /mnt/sdb/{x,y}
      
        setfattr -n user.1 -v aaa /mnt/sdb/x
        setfattr -n user.2 -v bbb /mnt/sdb/x
      
        setfattr -n user.1 -v aaa /mnt/sdb/y
        setfattr -n user.2 -v bbb /mnt/sdb/y
      
        debugfs -R 'stat x' /dev/sdb | cat
        debugfs -R 'stat y' /dev/sdb | cat
      
      This patch defers the reinsertion to the cache so that we can locate
      other blocks with the same contents.
      Signed-off-by: default avatarTahsin Erdogan <tahsin@google.com>
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
      Signed-off-by: default avatarTommi Rantala <tommi.t.rantala@nokia.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0683564e
    • Florian Westphal's avatar
      netfilter: x_tables: pack percpu counter allocations · 43f9d23f
      Florian Westphal authored
      commit ae0ac0ed upstream.
      
      instead of allocating each xt_counter individually, allocate 4k chunks
      and then use these for counter allocation requests.
      
      This should speed up rule evaluation by increasing data locality,
      also speeds up ruleset loading because we reduce calls to the percpu
      allocator.
      
      As Eric points out we can't use PAGE_SIZE, page_allocator would fail on
      arches with 64k page size.
      Suggested-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Acked-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      43f9d23f
    • Florian Westphal's avatar
      netfilter: x_tables: pass xt_counters struct to counter allocator · 54e6e845
      Florian Westphal authored
      commit f28e15ba upstream.
      
      Keeps some noise away from a followup patch.
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Acked-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      54e6e845
    • Florian Westphal's avatar
      netfilter: x_tables: pass xt_counters struct instead of packet counter · de53c52f
      Florian Westphal authored
      commit 4d31eef5 upstream.
      
      On SMP we overload the packet counter (unsigned long) to contain
      percpu offset.  Hide this from callers and pass xt_counters address
      instead.
      
      Preparation patch to allocate the percpu counters in page-sized batch
      chunks.
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Acked-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de53c52f
    • Florian Westphal's avatar
      netfilter: use skb_to_full_sk in ip_route_me_harder · 04b8427b
      Florian Westphal authored
      commit 29e09229 upstream.
      
      inet_sk(skb->sk) is illegal in case skb is attached to request socket.
      
      Fixes: ca6fb065 ("tcp: attach SYNACK messages to request sockets instead of listener")
      Reported by: Daniel J Blueman <daniel@quora.org>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Tested-by: default avatarDaniel J Blueman <daniel@quora.org>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      04b8427b
    • Florian Westphal's avatar
      netfilter: ipv6: fix use-after-free Write in nf_nat_ipv6_manip_pkt · a6b73606
      Florian Westphal authored
      commit b078556a upstream.
      
      l4proto->manip_pkt() can cause reallocation of skb head so pointer
      to the ipv6 header must be reloaded.
      
      Reported-and-tested-by: <syzbot+10005f4292fc9cc89de7@syzkaller.appspotmail.com>
      Fixes: 58a317f1 ("netfilter: ipv6: add IPv6 NAT support")
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a6b73606
    • Florian Westphal's avatar
      netfilter: bridge: ebt_among: add missing match size checks · f8d11851
      Florian Westphal authored
      commit c4585a28 upstream.
      
      ebt_among is special, it has a dynamic match size and is exempt
      from the central size checks.
      
      Therefore it must check that the size of the match structure
      provided from userspace is sane by making sure em->match_size
      is at least the minimum size of the expected structure.
      
      The module has such a check, but its only done after accessing
      a structure that might be out of bounds.
      
      tested with: ebtables -A INPUT ... \
      --among-dst fe:fe:fe:fe:fe:fe
      --among-dst fe:fe:fe:fe:fe:fe --among-src fe:fe:fe:fe:ff:f,fe:fe:fe:fe:fe:fb,fe:fe:fe:fe:fc:fd,fe:fe:fe:fe:fe:fd,fe:fe:fe:fe:fe:fe
      --among-src fe:fe:fe:fe:ff:f,fe:fe:fe:fe:fe:fa,fe:fe:fe:fe:fe:fd,fe:fe:fe:fe:fe:fe,fe:fe:fe:fe:fe:fe
      
      Reported-by: <syzbot+fe0b19af568972814355@syzkaller.appspotmail.com>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f8d11851
    • Florian Westphal's avatar
      netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets · 6d31b2ef
      Florian Westphal authored
      commit b7181216 upstream.
      
      We need to make sure the offsets are not out of range of the
      total size.
      Also check that they are in ascending order.
      
      The WARN_ON triggered by syzkaller (it sets panic_on_warn) is
      changed to also bail out, no point in continuing parsing.
      
      Briefly tested with simple ruleset of
      -A INPUT --limit 1/s' --log
      plus jump to custom chains using 32bit ebtables binary.
      
      Reported-by: <syzbot+845a53d13171abf8bf29@syzkaller.appspotmail.com>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6d31b2ef
    • Eric Dumazet's avatar
      netfilter: IDLETIMER: be syzkaller friendly · 55230ae8
      Eric Dumazet authored
      commit cfc2c740 upstream.
      
      We had one report from syzkaller [1]
      
      First issue is that INIT_WORK() should be done before mod_timer()
      or we risk timer being fired too soon, even with a 1 second timer.
      
      Second issue is that we need to reject too big info->timeout
      to avoid overflows in msecs_to_jiffies(info->timeout * 1000), or
      risk looping, if result after overflow is 0.
      
      [1]
      WARNING: CPU: 1 PID: 5129 at kernel/workqueue.c:1444 __queue_work+0xdf4/0x1230 kernel/workqueue.c:1444
      Kernel panic - not syncing: panic_on_warn set ...
      
      CPU: 1 PID: 5129 Comm: syzkaller159866 Not tainted 4.16.0-rc1+ #230
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       <IRQ>
       __dump_stack lib/dump_stack.c:17 [inline]
       dump_stack+0x194/0x257 lib/dump_stack.c:53
       panic+0x1e4/0x41c kernel/panic.c:183
       __warn+0x1dc/0x200 kernel/panic.c:547
       report_bug+0x211/0x2d0 lib/bug.c:184
       fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178
       fixup_bug arch/x86/kernel/traps.c:247 [inline]
       do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
       do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
       invalid_op+0x22/0x40 arch/x86/entry/entry_64.S:988
      RIP: 0010:__queue_work+0xdf4/0x1230 kernel/workqueue.c:1444
      RSP: 0018:ffff8801db507538 EFLAGS: 00010006
      RAX: ffff8801aeb46080 RBX: ffff8801db530200 RCX: ffffffff81481404
      RDX: 0000000000000100 RSI: ffffffff86b42640 RDI: 0000000000000082
      RBP: ffff8801db507758 R08: 1ffff1003b6a0de5 R09: 000000000000000c
      R10: ffff8801db5073f0 R11: 0000000000000020 R12: 1ffff1003b6a0eb6
      R13: ffff8801b1067ae0 R14: 00000000000001f8 R15: dffffc0000000000
       queue_work_on+0x16a/0x1c0 kernel/workqueue.c:1488
       queue_work include/linux/workqueue.h:488 [inline]
       schedule_work include/linux/workqueue.h:546 [inline]
       idletimer_tg_expired+0x44/0x60 net/netfilter/xt_IDLETIMER.c:116
       call_timer_fn+0x228/0x820 kernel/time/timer.c:1326
       expire_timers kernel/time/timer.c:1363 [inline]
       __run_timers+0x7ee/0xb70 kernel/time/timer.c:1666
       run_timer_softirq+0x4c/0x70 kernel/time/timer.c:1692
       __do_softirq+0x2d7/0xb85 kernel/softirq.c:285
       invoke_softirq kernel/softirq.c:365 [inline]
       irq_exit+0x1cc/0x200 kernel/softirq.c:405
       exiting_irq arch/x86/include/asm/apic.h:541 [inline]
       smp_apic_timer_interrupt+0x16b/0x700 arch/x86/kernel/apic/apic.c:1052
       apic_timer_interrupt+0xa9/0xb0 arch/x86/entry/entry_64.S:829
       </IRQ>
      RIP: 0010:arch_local_irq_restore arch/x86/include/asm/paravirt.h:777 [inline]
      RIP: 0010:__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:160 [inline]
      RIP: 0010:_raw_spin_unlock_irqrestore+0x5e/0xba kernel/locking/spinlock.c:184
      RSP: 0018:ffff8801c20173c8 EFLAGS: 00000282 ORIG_RAX: ffffffffffffff12
      RAX: dffffc0000000000 RBX: 0000000000000282 RCX: 0000000000000006
      RDX: 1ffffffff0d592cd RSI: 1ffff10035d68d23 RDI: 0000000000000282
      RBP: ffff8801c20173d8 R08: 1ffff10038402e47 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff8820e5c8
      R13: ffff8801b1067ad8 R14: ffff8801aea7c268 R15: ffff8801aea7c278
       __debug_object_init+0x235/0x1040 lib/debugobjects.c:378
       debug_object_init+0x17/0x20 lib/debugobjects.c:391
       __init_work+0x2b/0x60 kernel/workqueue.c:506
       idletimer_tg_create net/netfilter/xt_IDLETIMER.c:152 [inline]
       idletimer_tg_checkentry+0x691/0xb00 net/netfilter/xt_IDLETIMER.c:213
       xt_check_target+0x22c/0x7d0 net/netfilter/x_tables.c:850
       check_target net/ipv6/netfilter/ip6_tables.c:533 [inline]
       find_check_entry.isra.7+0x935/0xcf0 net/ipv6/netfilter/ip6_tables.c:575
       translate_table+0xf52/0x1690 net/ipv6/netfilter/ip6_tables.c:744
       do_replace net/ipv6/netfilter/ip6_tables.c:1160 [inline]
       do_ip6t_set_ctl+0x370/0x5f0 net/ipv6/netfilter/ip6_tables.c:1686
       nf_sockopt net/netfilter/nf_sockopt.c:106 [inline]
       nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:115
       ipv6_setsockopt+0x10b/0x130 net/ipv6/ipv6_sockglue.c:927
       udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422
       sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2976
       SYSC_setsockopt net/socket.c:1850 [inline]
       SyS_setsockopt+0x189/0x360 net/socket.c:1829
       do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
      
      Fixes: 0902b469 ("netfilter: xtables: idletimer target implementation")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzkaller <syzkaller@googlegroups.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      55230ae8
    • Paolo Abeni's avatar
      netfilter: nat: cope with negative port range · 5a91fa63
      Paolo Abeni authored
      commit db57ccf0 upstream.
      
      syzbot reported a division by 0 bug in the netfilter nat code:
      
      divide error: 0000 [#1] SMP KASAN
      Dumping ftrace buffer:
          (ftrace buffer empty)
      Modules linked in:
      CPU: 1 PID: 4168 Comm: syzkaller034710 Not tainted 4.16.0-rc1+ #309
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      RIP: 0010:nf_nat_l4proto_unique_tuple+0x291/0x530
      net/netfilter/nf_nat_proto_common.c:88
      RSP: 0018:ffff8801b2466778 EFLAGS: 00010246
      RAX: 000000000000f153 RBX: ffff8801b2466dd8 RCX: ffff8801b2466c7c
      RDX: 0000000000000000 RSI: ffff8801b2466c58 RDI: ffff8801db5293ac
      RBP: ffff8801b24667d8 R08: ffff8801b8ba6dc0 R09: ffffffff88af5900
      R10: ffff8801b24666f0 R11: 0000000000000000 R12: 000000002990f153
      R13: 0000000000000001 R14: 0000000000000000 R15: ffff8801b2466c7c
      FS:  00000000017e3880(0000) GS:ffff8801db500000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00000000208fdfe4 CR3: 00000001b5340002 CR4: 00000000001606e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
        dccp_unique_tuple+0x40/0x50 net/netfilter/nf_nat_proto_dccp.c:30
        get_unique_tuple+0xc28/0x1c10 net/netfilter/nf_nat_core.c:362
        nf_nat_setup_info+0x1c2/0xe00 net/netfilter/nf_nat_core.c:406
        nf_nat_redirect_ipv6+0x306/0x730 net/netfilter/nf_nat_redirect.c:124
        redirect_tg6+0x7f/0xb0 net/netfilter/xt_REDIRECT.c:34
        ip6t_do_table+0xc2a/0x1a30 net/ipv6/netfilter/ip6_tables.c:365
        ip6table_nat_do_chain+0x65/0x80 net/ipv6/netfilter/ip6table_nat.c:41
        nf_nat_ipv6_fn+0x594/0xa80 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c:302
        nf_nat_ipv6_local_fn+0x33/0x5d0
      net/ipv6/netfilter/nf_nat_l3proto_ipv6.c:407
        ip6table_nat_local_fn+0x2c/0x40 net/ipv6/netfilter/ip6table_nat.c:69
        nf_hook_entry_hookfn include/linux/netfilter.h:120 [inline]
        nf_hook_slow+0xba/0x1a0 net/netfilter/core.c:483
        nf_hook include/linux/netfilter.h:243 [inline]
        NF_HOOK include/linux/netfilter.h:286 [inline]
        ip6_xmit+0x10ec/0x2260 net/ipv6/ip6_output.c:277
        inet6_csk_xmit+0x2fc/0x580 net/ipv6/inet6_connection_sock.c:139
        dccp_transmit_skb+0x9ac/0x10f0 net/dccp/output.c:142
        dccp_connect+0x369/0x670 net/dccp/output.c:564
        dccp_v6_connect+0xe17/0x1bf0 net/dccp/ipv6.c:946
        __inet_stream_connect+0x2d4/0xf00 net/ipv4/af_inet.c:620
        inet_stream_connect+0x58/0xa0 net/ipv4/af_inet.c:684
        SYSC_connect+0x213/0x4a0 net/socket.c:1639
        SyS_connect+0x24/0x30 net/socket.c:1620
        do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
        entry_SYSCALL_64_after_hwframe+0x26/0x9b
      RIP: 0033:0x441c69
      RSP: 002b:00007ffe50cc0be8 EFLAGS: 00000217 ORIG_RAX: 000000000000002a
      RAX: ffffffffffffffda RBX: ffffffffffffffff RCX: 0000000000441c69
      RDX: 000000000000001c RSI: 00000000208fdfe4 RDI: 0000000000000003
      RBP: 00000000006cc018 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000538 R11: 0000000000000217 R12: 0000000000403590
      R13: 0000000000403620 R14: 0000000000000000 R15: 0000000000000000
      Code: 48 89 f0 83 e0 07 83 c0 01 38 d0 7c 08 84 d2 0f 85 46 02 00 00 48 8b
      45 c8 44 0f b7 20 e8 88 97 04 fd 31 d2 41 0f b7 c4 4c 89 f9 <41> f7 f6 48
      c1 e9 03 48 b8 00 00 00 00 00 fc ff df 0f b6 0c 01
      RIP: nf_nat_l4proto_unique_tuple+0x291/0x530
      net/netfilter/nf_nat_proto_common.c:88 RSP: ffff8801b2466778
      
      The problem is that currently we don't have any check on the
      configured port range. A port range == -1 triggers the bug, while
      other negative values may require a very long time to complete the
      following loop.
      
      This commit addresses the issue swapping the two ends on negative
      ranges. The check is performed in nf_nat_l4proto_unique_tuple() since
      the nft nat loads the port values from nft registers at runtime.
      
      v1 -> v2: use the correct 'Fixes' tag
      v2 -> v3: update commit message, drop unneeded READ_ONCE()
      
      Fixes: 5b1158e9 ("[NETFILTER]: Add NAT support for nf_conntrack")
      Reported-by: syzbot+8012e198bd037f4871e5@syzkaller.appspotmail.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5a91fa63
    • Paolo Abeni's avatar
      netfilter: x_tables: fix missing timer initialization in xt_LED · d44c2eeb
      Paolo Abeni authored
      commit 10414014 upstream.
      
      syzbot reported that xt_LED may try to use the ledinternal->timer
      without previously initializing it:
      
      ------------[ cut here ]------------
      kernel BUG at kernel/time/timer.c:958!
      invalid opcode: 0000 [#1] SMP KASAN
      Dumping ftrace buffer:
          (ftrace buffer empty)
      Modules linked in:
      CPU: 1 PID: 1826 Comm: kworker/1:2 Not tainted 4.15.0+ #306
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      Workqueue: ipv6_addrconf addrconf_dad_work
      RIP: 0010:__mod_timer kernel/time/timer.c:958 [inline]
      RIP: 0010:mod_timer+0x7d6/0x13c0 kernel/time/timer.c:1102
      RSP: 0018:ffff8801d24fe9f8 EFLAGS: 00010293
      RAX: ffff8801d25246c0 RBX: ffff8801aec6cb50 RCX: ffffffff816052c6
      RDX: 0000000000000000 RSI: 00000000fffbd14b RDI: ffff8801aec6cb68
      RBP: ffff8801d24fec98 R08: 0000000000000000 R09: 1ffff1003a49fd6c
      R10: ffff8801d24feb28 R11: 0000000000000005 R12: dffffc0000000000
      R13: ffff8801d24fec70 R14: 00000000fffbd14b R15: ffff8801af608f90
      FS:  0000000000000000(0000) GS:ffff8801db500000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00000000206d6fd0 CR3: 0000000006a22001 CR4: 00000000001606e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
        led_tg+0x1db/0x2e0 net/netfilter/xt_LED.c:75
        ip6t_do_table+0xc2a/0x1a30 net/ipv6/netfilter/ip6_tables.c:365
        ip6table_raw_hook+0x65/0x80 net/ipv6/netfilter/ip6table_raw.c:42
        nf_hook_entry_hookfn include/linux/netfilter.h:120 [inline]
        nf_hook_slow+0xba/0x1a0 net/netfilter/core.c:483
        nf_hook.constprop.27+0x3f6/0x830 include/linux/netfilter.h:243
        NF_HOOK include/linux/netfilter.h:286 [inline]
        ndisc_send_skb+0xa51/0x1370 net/ipv6/ndisc.c:491
        ndisc_send_ns+0x38a/0x870 net/ipv6/ndisc.c:633
        addrconf_dad_work+0xb9e/0x1320 net/ipv6/addrconf.c:4008
        process_one_work+0xbbf/0x1af0 kernel/workqueue.c:2113
        worker_thread+0x223/0x1990 kernel/workqueue.c:2247
        kthread+0x33c/0x400 kernel/kthread.c:238
        ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:429
      Code: 85 2a 0b 00 00 4d 8b 3c 24 4d 85 ff 75 9f 4c 8b bd 60 fd ff ff e8 bb
      57 10 00 65 ff 0d 94 9a a1 7e e9 d9 fc ff ff e8 aa 57 10 00 <0f> 0b e8 a3
      57 10 00 e9 14 fb ff ff e8 99 57 10 00 4c 89 bd 70
      RIP: __mod_timer kernel/time/timer.c:958 [inline] RSP: ffff8801d24fe9f8
      RIP: mod_timer+0x7d6/0x13c0 kernel/time/timer.c:1102 RSP: ffff8801d24fe9f8
      ---[ end trace f661ab06f5dd8b3d ]---
      
      The ledinternal struct can be shared between several different
      xt_LED targets, but the related timer is currently initialized only
      if the first target requires it. Fix it by unconditionally
      initializing the timer struct.
      
      v1 -> v2: call del_timer_sync() unconditionally, too.
      
      Fixes: 268cb38e ("netfilter: x_tables: add LED trigger target")
      Reported-by: syzbot+10c98dc5725c6c8fc7fb@syzkaller.appspotmail.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d44c2eeb
    • Florian Westphal's avatar
      netfilter: add back stackpointer size checks · 48db3004
      Florian Westphal authored
      commit 57ebd808 upstream.
      
      The rationale for removing the check is only correct for rulesets
      generated by ip(6)tables.
      
      In iptables, a jump can only occur to a user-defined chain, i.e.
      because we size the stack based on number of user-defined chains we
      cannot exceed stack size.
      
      However, the underlying binary format has no such restriction,
      and the validation step only ensures that the jump target is a
      valid rule start point.
      
      IOW, its possible to build a rule blob that has no user-defined
      chains but does contain a jump.
      
      If this happens, no jump stack gets allocated and crash occurs
      because no jumpstack was allocated.
      
      Fixes: 7814b6ec ("netfilter: xtables: don't save/restore jumpstack offset")
      Reported-by: syzbot+e783f671527912cd9403@syzkaller.appspotmail.com
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      48db3004
    • Philipp Zabel's avatar
      tc358743: fix register i2c_rd/wr function fix · 44f3c2b6
      Philipp Zabel authored
      commit f2c61f98 upstream.
      
      The below mentioned fix contains a small but severe bug,
      fix it to make the driver work again.
      
      Fixes: 3538aa6e ("[media] tc358743: fix register i2c_rd/wr functions")
      
      Cc: Hans Verkuil <hans.verkuil@cisco.com>
      Cc: Mauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
      Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarHans Verkuil <hansverk@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      44f3c2b6
    • Dmitry Torokhov's avatar
      Input: tca8418_keypad - remove double read of key event register · 81e510a3
      Dmitry Torokhov authored
      commit 9dd46c02 upstream.
      
      There is no need to tread the same register twice in a row.
      
      Fixes: ea4348c8 ("Input: tca8418_keypad - hide gcc-4.9 -Wmaybe-un ...")
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      81e510a3