1. 03 Mar, 2018 40 commits
    • Daniel Mentz's avatar
      media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic · a0b6b578
      Daniel Mentz authored
      commit a1dfb4c4 upstream.
      
      The 32-bit compat v4l2 ioctl handling is implemented based on its 64-bit
      equivalent. It converts 32-bit data structures into its 64-bit
      equivalents and needs to provide the data to the 64-bit ioctl in user
      space memory which is commonly allocated using
      compat_alloc_user_space().
      
      However, due to how that function is implemented, it can only be called
      a single time for every syscall invocation.
      
      Supposedly to avoid this limitation, the existing code uses a mix of
      memory from the kernel stack and memory allocated through
      compat_alloc_user_space().
      
      Under normal circumstances, this would not work, because the 64-bit
      ioctl expects all pointers to point to user space memory. As a
      workaround, set_fs(KERNEL_DS) is called to temporarily disable this
      extra safety check and allow kernel pointers. However, this might
      introduce a security vulnerability: The result of the 32-bit to 64-bit
      conversion is writeable by user space because the output buffer has been
      allocated via compat_alloc_user_space(). A malicious user space process
      could then manipulate pointers inside this output buffer, and due to the
      previous set_fs(KERNEL_DS) call, functions like get_user() or put_user()
      no longer prevent kernel memory access.
      
      The new approach is to pre-calculate the total amount of user space
      memory that is needed, allocate it using compat_alloc_user_space() and
      then divide up the allocated memory to accommodate all data structures
      that need to be converted.
      
      An alternative approach would have been to retain the union type karg
      that they allocated on the kernel stack in do_video_ioctl(), copy all
      data from user space into karg and then back to user space. However, we
      decided against this approach because it does not align with other
      compat syscall implementations. Instead, we tried to replicate the
      get_user/put_user pairs as found in other places in the kernel:
      
          if (get_user(clipcount, &up->clipcount) ||
              put_user(clipcount, &kp->clipcount)) return -EFAULT;
      
      Notes from hans.verkuil@cisco.com:
      
      This patch was taken from:
          https://github.com/LineageOS/android_kernel_samsung_apq8084/commit/97b733953c06e4f0398ade18850f0817778255f7
      
      Clearly nobody could be bothered to upstream this patch or at minimum
      tell us :-( We only heard about this a week ago.
      
      This patch was rebased and cleaned up. Compared to the original I
      also swapped the order of the convert_in_user arguments so that they
      matched copy_in_user. It was hard to review otherwise. I also replaced
      the ALLOC_USER_SPACE/ALLOC_AND_GET by a normal function.
      
      Fixes: 6b5a9492
      
       ("v4l: introduce string control support.")
      Signed-off-by: default avatarDaniel Mentz <danielmentz@google.com>
      Co-developed-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      [bwh: Rebased on top of some earlier fixes]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      a0b6b578
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors · 8c04a4f0
      Hans Verkuil authored
      commit d83a8243
      
       upstream.
      
      Some ioctls need to copy back the result even if the ioctl returned
      an error. However, don't do this for the error code -ENOTTY.
      It makes no sense in that cases.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      8c04a4f0
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type · 3b764d65
      Hans Verkuil authored
      commit 169f24ca
      
       upstream.
      
      There is nothing wrong with using an unknown buffer type. So
      stop spamming the kernel log whenever this happens. The kernel
      will just return -EINVAL to signal this.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      3b764d65
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32 · e05a2d30
      Hans Verkuil authored
      commit a751be5b
      
       upstream.
      
      put_v4l2_window32() didn't copy back the clip list to userspace.
      Drivers can update the clip rectangles, so this should be done.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      e05a2d30
    • Daniel Mentz's avatar
      media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha · 79bd1439
      Daniel Mentz authored
      commit 025a26fa upstream.
      
      Commit b2787845
      
       ("V4L/DVB (5289): Add support for video output
      overlays.") added the field global_alpha to struct v4l2_window but did
      not update the compat layer accordingly. This change adds global_alpha
      to struct v4l2_window32 and copies the value for global_alpha back and
      forth.
      Signed-off-by: default avatarDaniel Mentz <danielmentz@google.com>
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      79bd1439
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer · 606ae3b1
      Hans Verkuil authored
      commit b8c601e8
      
       upstream.
      
      ctrl_is_pointer just hardcoded two known string controls, but that
      caused problems when using e.g. custom controls that use a pointer
      for the payload.
      
      Reimplement this function: it now finds the v4l2_ctrl (if the driver
      uses the control framework) or it calls vidioc_query_ext_ctrl (if the
      driver implements that directly).
      
      In both cases it can now check if the control is a pointer control
      or not.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      [bwh: Rebased on top of some earlier fixes]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      606ae3b1
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32 · e8b35041
      Hans Verkuil authored
      commit 8ed5a59d
      
       upstream.
      
      The struct v4l2_plane32 should set m.userptr as well. The same
      happens in v4l2_buffer32 and v4l2-compliance tests for this.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      e8b35041
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: avoid sizeof(type) · e601a9a8
      Hans Verkuil authored
      commit 333b1e9f
      
       upstream.
      
      Instead of doing sizeof(struct foo) use sizeof(*up). There even were
      cases where 4 * sizeof(__u32) was used instead of sizeof(kp->reserved),
      which is very dangerous when the size of the reserved array changes.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      [bwh: Rebased on top of some earlier fixes]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      e601a9a8
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32 · f64f7bd5
      Hans Verkuil authored
      commit 486c5215
      
       upstream.
      
      These helper functions do not really help. Move the code to the
      __get/put_v4l2_format32 functions.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      [bwh: Rebased on top of some earlier fixes]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      f64f7bd5
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: fix the indentation · 846e2145
      Hans Verkuil authored
      commit b7b957d4
      
       upstream.
      
      The indentation of this source is all over the place. Fix this.
      This patch only changes whitespace.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      [bwh: Rebased on top of some earlier fixes]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      846e2145
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF · 182f3143
      Hans Verkuil authored
      commit 3ee6d040
      
       upstream.
      
      The result of the VIDIOC_PREPARE_BUF ioctl was never copied back
      to userspace since it was missing in the switch.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      182f3143
    • Ricardo Ribalda's avatar
      vb2: V4L2_BUF_FLAG_DONE is set after DQBUF · a1cdbb82
      Ricardo Ribalda authored
      commit 3171cc2b
      
       upstream.
      
      According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:
      
      V4L2_BUF_FLAG_DONE 0x00000004  ... After calling the VIDIOC_QBUF or
      VIDIOC_DQBUF it is always cleared ...
      
      Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
      can be tested with vivid and dev_debug:
      
      [257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
      type=vid-cap, flags=0x00002004, field=none, sequence=163,
      memory=userptr, bytesused=460800, offset/userptr=0x344b000,
      length=460800
      
      This patch forces FLAG_DONE to 0 after calling DQBUF.
      Reported-by: default avatarDimitrios Katsaros <patcherwork@gmail.com>
      Signed-off-by: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      a1cdbb82
    • Hans Verkuil's avatar
      media: v4l2-ioctl.c: don't copy back the result for -ENOTTY · 5e574764
      Hans Verkuil authored
      commit 181a4a2d
      
       upstream.
      
      If the ioctl returned -ENOTTY, then don't bother copying
      back the result as there is no point.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      5e574764
    • Hans Verkuil's avatar
      adv7604: use correct drive strength defines · 98dc7e90
      Hans Verkuil authored
      The prefix is ADV7604_, not ADV76XX.
      
      Fixes: f31b62e1
      
       ("adv7604: add hdmi driver strength adjustment")
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      98dc7e90
    • Hans Verkuil's avatar
      media: v4l2-compat-ioctl32.c: add capabilities field to, v4l2_input32 · f9b33d1f
      Hans Verkuil authored
      commit 037e0865
      
       upstream.
      
      The v4l2_input32 struct wasn't updated when this field was added.
      It didn't cause a failure in the compat code, but it is better to
      keep it in sync with v4l2_input to avoid confusion.
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      f9b33d1f
    • Tiffany Lin's avatar
      media: v4l2-compat-ioctl32: fix missing reserved field copy in put_v4l2_create32 · bd4e8dc0
      Tiffany Lin authored
      commit baf43c6e
      
       upstream.
      
      In v4l2-compliance utility, test VIDIOC_CREATE_BUFS will check whether reserved
      filed of v4l2_create_buffers filled with zero
      Reserved field is filled with zero in v4l_create_bufs.
      This patch copy reserved field of v4l2_create_buffer from kernel space to user
      space
      Signed-off-by: default avatarTiffany Lin <tiffany.lin@mediatek.com>
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      bd4e8dc0
    • Guennadi Liakhovetski's avatar
      V4L2: fix VIDIOC_CREATE_BUFS 32-bit compatibility mode data copy-back · 99d5e1c4
      Guennadi Liakhovetski authored
      commit 6ed9b285
      
       upstream.
      
      Similar to an earlier patch, fixing reading user-space data for the
      VIDIOC_CREATE_BUFS ioctl() in 32-bit compatibility mode, this patch fixes
      writing back of the possibly modified struct to the user. However, unlike
      the former bug, this one is much less harmful, because it only results in
      the kernel failing to write the .type field back to the user, but in fact
      this is likely unneeded, because the kernel will hardly want to change
      that field. Therefore this bug is more of a theoretical nature.
      Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
      Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      99d5e1c4
    • Hans Verkuil's avatar
      v4l2-compat-ioctl32: fix sparse warnings · 64a2bd74
      Hans Verkuil authored
      commit 8ae632b1
      
       upstream.
      
      A lot of these warnings are caused by the fact that we don't generally use
      __user in videodev2.h. Normally the video_usercopy function will copy anything
      pointed to by pointers into kernel space, so having __user in the struct will only
      cause lots of warnings in the drivers. But the flip side of that is that you
      need to add __force casts here.
      
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:337:26: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:337:30: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:338:31: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:338:49: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:343:21: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:346:21: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:349:35: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:349:46: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:352:35: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:352:54: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:363:26: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:363:32: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:364:31: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:364:51: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:371:35: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:371:56: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:376:35: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:376:48: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:430:30: warning: incorrect type in assignment (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:433:48: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:433:56: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:501:24: warning: incorrect type in assignment (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:507:48: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:507:56: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:565:18: warning: incorrect type in assignment (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:670:22: warning: incorrect type in assignment (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:680:29: warning: incorrect type in assignment (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:692:55: warning: incorrect type in initializer (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:773:18: warning: incorrect type in assignment (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:786:30: warning: incorrect type in argument 1 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:786:44: warning: incorrect type in argument 2 (different address spaces)
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:674:37: warning: dereference of noderef expression
      drivers/media/v4l2-core/v4l2-compat-ioctl32.c:718:37: warning: dereference of noderef expression
      Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
      [bwh: Backported to 3.16: adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      64a2bd74
    • Ming Lei's avatar
      blk-mq: fix race between timeout and freeing request · 7acba7c0
      Ming Lei authored
      commit 0048b483
      
       upstream.
      
      Inside timeout handler, blk_mq_tag_to_rq() is called
      to retrieve the request from one tag. This way is obviously
      wrong because the request can be freed any time and some
      fiedds of the request can't be trusted, then kernel oops
      might be triggered[1].
      
      Currently wrt. blk_mq_tag_to_rq(), the only special case is
      that the flush request can share same tag with the request
      cloned from, and the two requests can't be active at the same
      time, so this patch fixes the above issue by updating tags->rqs[tag]
      with the active request(either flush rq or the request cloned
      from) of the tag.
      
      Also blk_mq_tag_to_rq() gets much simplified with this patch.
      
      Given blk_mq_tag_to_rq() is mainly for drivers and the caller must
      make sure the request can't be freed, so in bt_for_each() this
      helper is replaced with tags->rqs[tag].
      
      [1] kernel oops log
      [  439.696220] BUG: unable to handle kernel NULL pointer dereference at 0000000000000158^M
      [  439.697162] IP: [<ffffffff812d89ba>] blk_mq_tag_to_rq+0x21/0x6e^M
      [  439.700653] PGD 7ef765067 PUD 7ef764067 PMD 0 ^M
      [  439.700653] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC ^M
      [  439.700653] Dumping ftrace buffer:^M
      [  439.700653]    (ftrace buffer empty)^M
      [  439.700653] Modules linked in: nbd ipv6 kvm_intel kvm serio_raw^M
      [  439.700653] CPU: 6 PID: 2779 Comm: stress-ng-sigfd Not tainted 4.2.0-rc5-next-20150805+ #265^M
      [  439.730500] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011^M
      [  439.730500] task: ffff880605308000 ti: ffff88060530c000 task.ti: ffff88060530c000^M
      [  439.730500] RIP: 0010:[<ffffffff812d89ba>]  [<ffffffff812d89ba>] blk_mq_tag_to_rq+0x21/0x6e^M
      [  439.730500] RSP: 0018:ffff880819203da0  EFLAGS: 00010283^M
      [  439.730500] RAX: ffff880811b0e000 RBX: ffff8800bb465f00 RCX: 0000000000000002^M
      [  439.730500] RDX: 0000000000000000 RSI: 0000000000000202 RDI: 0000000000000000^M
      [  439.730500] RBP: ffff880819203db0 R08: 0000000000000002 R09: 0000000000000000^M
      [  439.730500] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000202^M
      [  439.730500] R13: ffff880814104800 R14: 0000000000000002 R15: ffff880811a2ea00^M
      [  439.730500] FS:  00007f165b3f5740(0000) GS:ffff880819200000(0000) knlGS:0000000000000000^M
      [  439.730500] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b^M
      [  439.730500] CR2: 0000000000000158 CR3: 00000007ef766000 CR4: 00000000000006e0^M
      [  439.730500] Stack:^M
      [  439.730500]  0000000000000008 ffff8808114eed90 ffff880819203e00 ffffffff812dc104^M
      [  439.755663]  ffff880819203e40 ffffffff812d9f5e 0000020000000000 ffff8808114eed80^M
      [  439.755663] Call Trace:^M
      [  439.755663]  <IRQ> ^M
      [  439.755663]  [<ffffffff812dc104>] bt_for_each+0x6e/0xc8^M
      [  439.755663]  [<ffffffff812d9f5e>] ? blk_mq_rq_timed_out+0x6a/0x6a^M
      [  439.755663]  [<ffffffff812d9f5e>] ? blk_mq_rq_timed_out+0x6a/0x6a^M
      [  439.755663]  [<ffffffff812dc1b3>] blk_mq_tag_busy_iter+0x55/0x5e^M
      [  439.755663]  [<ffffffff812d88b4>] ? blk_mq_bio_to_request+0x38/0x38^M
      [  439.755663]  [<ffffffff812d8911>] blk_mq_rq_timer+0x5d/0xd4^M
      [  439.755663]  [<ffffffff810a3e10>] call_timer_fn+0xf7/0x284^M
      [  439.755663]  [<ffffffff810a3d1e>] ? call_timer_fn+0x5/0x284^M
      [  439.755663]  [<ffffffff812d88b4>] ? blk_mq_bio_to_request+0x38/0x38^M
      [  439.755663]  [<ffffffff810a46d6>] run_timer_softirq+0x1ce/0x1f8^M
      [  439.755663]  [<ffffffff8104c367>] __do_softirq+0x181/0x3a4^M
      [  439.755663]  [<ffffffff8104c76e>] irq_exit+0x40/0x94^M
      [  439.755663]  [<ffffffff81031482>] smp_apic_timer_interrupt+0x33/0x3e^M
      [  439.755663]  [<ffffffff815559a4>] apic_timer_interrupt+0x84/0x90^M
      [  439.755663]  <EOI> ^M
      [  439.755663]  [<ffffffff81554350>] ? _raw_spin_unlock_irq+0x32/0x4a^M
      [  439.755663]  [<ffffffff8106a98b>] finish_task_switch+0xe0/0x163^M
      [  439.755663]  [<ffffffff8106a94d>] ? finish_task_switch+0xa2/0x163^M
      [  439.755663]  [<ffffffff81550066>] __schedule+0x469/0x6cd^M
      [  439.755663]  [<ffffffff8155039b>] schedule+0x82/0x9a^M
      [  439.789267]  [<ffffffff8119b28b>] signalfd_read+0x186/0x49a^M
      [  439.790911]  [<ffffffff8106d86a>] ? wake_up_q+0x47/0x47^M
      [  439.790911]  [<ffffffff811618c2>] __vfs_read+0x28/0x9f^M
      [  439.790911]  [<ffffffff8117a289>] ? __fget_light+0x4d/0x74^M
      [  439.790911]  [<ffffffff811620a7>] vfs_read+0x7a/0xc6^M
      [  439.790911]  [<ffffffff8116292b>] SyS_read+0x49/0x7f^M
      [  439.790911]  [<ffffffff81554c17>] entry_SYSCALL_64_fastpath+0x12/0x6f^M
      [  439.790911] Code: 48 89 e5 e8 a9 b8 e7 ff 5d c3 0f 1f 44 00 00 55 89
      f2 48 89 e5 41 54 41 89 f4 53 48 8b 47 60 48 8b 1c d0 48 8b 7b 30 48 8b
      53 38 <48> 8b 87 58 01 00 00 48 85 c0 75 09 48 8b 97 88 0c 00 00 eb 10
      ^M
      [  439.790911] RIP  [<ffffffff812d89ba>] blk_mq_tag_to_rq+0x21/0x6e^M
      [  439.790911]  RSP <ffff880819203da0>^M
      [  439.790911] CR2: 0000000000000158^M
      [  439.790911] ---[ end trace d40af58949325661 ]---^M
      Signed-off-by: default avatarMing Lei <ming.lei@canonical.com>
      Signed-off-by: default avatarJens Axboe <axboe@fb.com>
      [bwh: Backported to 3.16:
       - Flush state is in struct request_queue, not struct blk_flush_queue
       - Flush request cloning is done in blk_mq_clone_flush_request() rather
         than blk_kick_flush()
       - Drop changes in bt{,_tags}_for_each()
       - Adjust filename, context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      7acba7c0
    • Andrew Bresticker's avatar
      mac80211_hwsim: fix compiler warning on MIPS · 79e66041
      Andrew Bresticker authored
      commit 5d26b508
      
       upstream.
      
      The dividend in do_div() is expected to be an unsigned 64-bit integer,
      which leads to the following warning when building for 32-bit MIPS:
      
        drivers/net/wireless/mac80211_hwsim.c: In function 'mac80211_hwsim_set_tsf':
        drivers/net/wireless/mac80211_hwsim.c:664:98: warning: comparison of distinct pointer types lacks a cast [enabled by default]
          data->bcn_delta = do_div(delta, bcn_int);
      
      Since we care about the signedness of delta when adjusting tsf_offset
      and bcm_delta, use the absolute value for the division and compare
      the two timestamps to determine the sign.
      Signed-off-by: default avatarAndrew Bresticker <abrestic@chromium.org>
      Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      79e66041
    • Petri Gynther's avatar
      net: bcmgenet: fix bcmgenet_open() · 95b5d4fc
      Petri Gynther authored
      commit fac25940
      
       upstream.
      
      If bcmgenet_init_dma() fails, it cleans up after itself. Rx and Tx
      DMAs are off, and NAPI instances haven't been netif_napi_add()'ed.
      Therefore, we need to skip calling bcmgenet_fini_dma() on the error
      handling path. bcmgenet_resume() already does this correctly.
      Signed-off-by: default avatarPetri Gynther <pgynther@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      95b5d4fc
    • Ben Hutchings's avatar
      of: fdt: Fix return with value in void function · 52f0b4f1
      Ben Hutchings authored
      Commit 49e67dd1
      
       "of: fdt: add missing allocation-failure check"
      added a "return NULL" statement in __unflatten_device_tree().  When
      applied to the 3.16-stable branch, this introduced a compiler warning
      (not an error!) because the function returns void here.
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      52f0b4f1
    • Thomas Gleixner's avatar
      hrtimer: Reset hrtimer cpu base proper on CPU hotplug · 491b0fc4
      Thomas Gleixner authored
      commit d5421ea4 upstream.
      
      The hrtimer interrupt code contains a hang detection and mitigation
      mechanism, which prevents that a long delayed hrtimer interrupt causes a
      continous retriggering of interrupts which prevent the system from making
      progress. If a hang is detected then the timer hardware is programmed with
      a certain delay into the future and a flag is set in the hrtimer cpu base
      which prevents newly enqueued timers from reprogramming the timer hardware
      prior to the chosen delay. The subsequent hrtimer interrupt after the delay
      clears the flag and resumes normal operation.
      
      If such a hang happens in the last hrtimer interrupt before a CPU is
      unplugged then the hang_detected flag is set and stays that way when the
      CPU is plugged in again. At that point the timer hardware is not armed and
      it cannot be armed because the hang_detected flag is still active, so
      nothing clears that flag. As a consequence the CPU does not receive hrtimer
      interrupts and no timers expire on that CPU which results in RCU stalls and
      other malfunctions.
      
      Clear the flag along with some other less critical members of the hrtimer
      cpu base to ensure starting from a clean state when a CPU is plugged in.
      
      Thanks to Paul, Sebastian and Anna-Maria for their help to get down to the
      root cause of that hard to reproduce heisenbug. Once understood it's
      trivial and certainly justifies a brown paperbag.
      
      Fixes: 41d2e494
      
       ("hrtimer: Tune hrtimer_interrupt hang logic")
      Reported-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sebastian Sewior <bigeasy@linutronix.de>
      Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
      Link: https://lkml.kernel.org/r/alpine.DEB.2.20.1801261447590.2067@nanos
      
      
      [bwh: Backported to 3.16:
       - There's no next_timer field to reset
       - Adjust filename, context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      491b0fc4
    • Alexey Kodanev's avatar
      dccp: don't restart ccid2_hc_tx_rto_expire() if sk in closed state · e67eb710
      Alexey Kodanev authored
      commit dd5684ec upstream.
      
      ccid2_hc_tx_rto_expire() timer callback always restarts the timer
      again and can run indefinitely (unless it is stopped outside), and after
      commit 120e9dab ("dccp: defer ccid_hc_tx_delete() at dismantle time"),
      which moved ccid_hc_tx_delete() (also includes sk_stop_timer()) from
      dccp_destroy_sock() to sk_destruct(), this started to happen quite often.
      The timer prevents releasing the socket, as a result, sk_destruct() won't
      be called.
      
      Found with LTP/dccp_ipsec tests running on the bonding device,
      which later couldn't be unloaded after the tests were completed:
      
        unregister_netdevice: waiting for bond0 to become free. Usage count = 148
      
      Fixes: 2a91aa39
      
       ("[DCCP] CCID2: Initial CCID2 (TCP-Like) implementation")
      Signed-off-by: default avatarAlexey Kodanev <alexey.kodanev@oracle.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      e67eb710
    • Jia Zhang's avatar
      x86/microcode/intel: Extend BDW late-loading further with LLC size check · 3ff8643e
      Jia Zhang authored
      commit 7e702d17 upstream.
      
      Commit b94b7373 ("x86/microcode/intel: Extend BDW late-loading with a
      revision check") reduced the impact of erratum BDF90 for Broadwell model
      79.
      
      The impact can be reduced further by checking the size of the last level
      cache portion per core.
      
      Tony: "The erratum says the problem only occurs on the large-cache SKUs.
      So we only need to avoid the update if we are on a big cache SKU that is
      also running old microcode."
      
      For more details, see erratum BDF90 in document #334165 (Intel Xeon
      Processor E7-8800/4800 v4 Product Family Specification Update) from
      September 2017.
      
      Fixes: b94b7373
      
       ("x86/microcode/intel: Extend BDW late-loading with a revision check")
      Signed-off-by: default avatarJia Zhang <zhang.jia@linux.alibaba.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarTony Luck <tony.luck@intel.com>
      Link: https://lkml.kernel.org/r/1516321542-31161-1-git-send-email-zhang.jia@linux.alibaba.com
      
      
      [bwh: Backported to 3.16: adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      3ff8643e
    • Guillaume Nault's avatar
      pppoe: take ->needed_headroom of lower device into account on xmit · 7b400f4d
      Guillaume Nault authored
      commit 02612bb0 upstream.
      
      In pppoe_sendmsg(), reserving dev->hard_header_len bytes of headroom
      was probably fine before the introduction of ->needed_headroom in
      commit f5184d26 ("net: Allow netdevices to specify needed head/tailroom").
      
      But now, virtual devices typically advertise the size of their overhead
      in dev->needed_headroom, so we must also take it into account in
      skb_reserve().
      Allocation size of skb is also updated to take dev->needed_tailroom
      into account and replace the arbitrary 32 bytes with the real size of
      a PPPoE header.
      
      This issue was discovered by syzbot, who connected a pppoe socket to a
      gre device which had dev->header_ops->create == ipgre_header and
      dev->hard_header_len == 0. Therefore, PPPoE didn't reserve any
      headroom, and dev_hard_header() crashed when ipgre_header() tried to
      prepend its header to skb->data.
      
      skbuff: skb_under_panic: text:000000001d390b3a len:31 put:24
      head:00000000d8ed776f data:000000008150e823 tail:0x7 end:0xc0 dev:gre0
      ------------[ cut here ]------------
      kernel BUG at net/core/skbuff.c:104!
      invalid opcode: 0000 [#1] SMP KASAN
      Dumping ftrace buffer:
          (ftrace buffer empty)
      Modules linked in:
      CPU: 1 PID: 3670 Comm: syzkaller801466 Not tainted
      4.15.0-rc7-next-20180115+ #97
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      RIP: 0010:skb_panic+0x162/0x1f0 net/core/skbuff.c:100
      RSP: 0018:ffff8801d9bd7840 EFLAGS: 00010282
      RAX: 0000000000000083 RBX: ffff8801d4f083c0 RCX: 0000000000000000
      RDX: 0000000000000083 RSI: 1ffff1003b37ae92 RDI: ffffed003b37aefc
      RBP: ffff8801d9bd78a8 R08: 1ffff1003b37ae8a R09: 0000000000000000
      R10: 0000000000000001 R11: 0000000000000000 R12: ffffffff86200de0
      R13: ffffffff84a981ad R14: 0000000000000018 R15: ffff8801d2d34180
      FS:  00000000019c4880(0000) GS:ffff8801db300000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00000000208bc000 CR3: 00000001d9111001 CR4: 00000000001606e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
        skb_under_panic net/core/skbuff.c:114 [inline]
        skb_push+0xce/0xf0 net/core/skbuff.c:1714
        ipgre_header+0x6d/0x4e0 net/ipv4/ip_gre.c:879
        dev_hard_header include/linux/netdevice.h:2723 [inline]
        pppoe_sendmsg+0x58e/0x8b0 drivers/net/ppp/pppoe.c:890
        sock_sendmsg_nosec net/socket.c:630 [inline]
        sock_sendmsg+0xca/0x110 net/socket.c:640
        sock_write_iter+0x31a/0x5d0 net/socket.c:909
        call_write_iter include/linux/fs.h:1775 [inline]
        do_iter_readv_writev+0x525/0x7f0 fs/read_write.c:653
        do_iter_write+0x154/0x540 fs/read_write.c:932
        vfs_writev+0x18a/0x340 fs/read_write.c:977
        do_writev+0xfc/0x2a0 fs/read_write.c:1012
        SYSC_writev fs/read_write.c:1085 [inline]
        SyS_writev+0x27/0x30 fs/read_write.c:1082
        entry_SYSCALL_64_fastpath+0x29/0xa0
      
      Admittedly PPPoE shouldn't be allowed to run on non Ethernet-like
      interfaces, but reserving space for ->needed_headroom is a more
      fundamental issue that needs to be addressed first.
      
      Same problem exists for __pppoe_xmit(), which also needs to take
      dev->needed_headroom into account in skb_cow_head().
      
      Fixes: f5184d26
      
       ("net: Allow netdevices to specify needed head/tailroom")
      Reported-by: syzbot+ed0838d0fa4c4f2b528e20286e6dc63effc7c14d@syzkaller.appspotmail.com
      Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
      Reviewed-by: default avatarXin Long <lucien.xin@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      7b400f4d
    • Aaron Ma's avatar
      Input: trackpoint - force 3 buttons if 0 button is reported · 4a6e9e32
      Aaron Ma authored
      commit f5d07b9e
      
       upstream.
      
      Lenovo introduced trackpoint compatible sticks with minimum PS/2 commands.
      They supposed to reply with 0x02, 0x03, or 0x04 in response to the
      "Read Extended ID" command, so we would know not to try certain extended
      commands. Unfortunately even some trackpoints reporting the original IBM
      version (0x01 firmware 0x0e) now respond with incorrect data to the "Get
      Extended Buttons" command:
      
       thinkpad_acpi: ThinkPad BIOS R0DET87W (1.87 ), EC unknown
       thinkpad_acpi: Lenovo ThinkPad E470, model 20H1004SGE
      
       psmouse serio2: trackpoint: IBM TrackPoint firmware: 0x0e, buttons: 0/0
      
      Since there are no trackpoints without buttons, let's assume the trackpoint
      has 3 buttons when we get 0 response to the extended buttons query.
      Signed-off-by: default avatarAaron Ma <aaron.ma@canonical.com>
      Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196253
      
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      4a6e9e32
    • Oscar Campos's avatar
      Input: trackpoint - assume 3 buttons when buttons detection fails · dd7ae1d0
      Oscar Campos authored
      commit 293b915f
      
       upstream.
      
      Trackpoint buttons detection fails on ThinkPad 570 and 470 series,
      this makes the middle button of the trackpoint to not being recogized.
      As I don't believe there is any trackpoint with less than 3 buttons this
      patch just assumes three buttons when the extended button information
      read fails.
      Signed-off-by: default avatarOscar Campos <oscar.campos@member.fsf.org>
      Acked-by: default avatarPeter Hutterer <peter.hutterer@who-t.net>
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      [bwh: Backported to 3.16: adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      dd7ae1d0
    • Felix Fietkau's avatar
      net: igmp: fix source address check for IGMPv3 reports · d01262f5
      Felix Fietkau authored
      commit ad23b750 upstream.
      
      Commit "net: igmp: Use correct source address on IGMPv3 reports"
      introduced a check to validate the source address of locally generated
      IGMPv3 packets.
      Instead of checking the local interface address directly, it uses
      inet_ifa_match(fl4->saddr, ifa), which checks if the address is on the
      local subnet (or equal to the point-to-point address if used).
      
      This breaks for point-to-point interfaces, so check against
      ifa->ifa_local directly.
      
      Cc: Kevin Cernekee <cernekee@chromium.org>
      Fixes: a46182b0
      
       ("net: igmp: Use correct source address on IGMPv3 reports")
      Reported-by: default avatarSebastian Gottschall <s.gottschall@dd-wrt.com>
      Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      d01262f5
    • Kevin Cernekee's avatar
      net: igmp: Use correct source address on IGMPv3 reports · d3c38df3
      Kevin Cernekee authored
      commit a46182b0
      
       upstream.
      
      Closing a multicast socket after the final IPv4 address is deleted
      from an interface can generate a membership report that uses the
      source IP from a different interface.  The following test script, run
      from an isolated netns, reproduces the issue:
      
          #!/bin/bash
      
          ip link add dummy0 type dummy
          ip link add dummy1 type dummy
          ip link set dummy0 up
          ip link set dummy1 up
          ip addr add 10.1.1.1/24 dev dummy0
          ip addr add 192.168.99.99/24 dev dummy1
      
          tcpdump -U -i dummy0 &
          socat EXEC:"sleep 2" \
              UDP4-DATAGRAM:239.101.1.68:8889,ip-add-membership=239.0.1.68:10.1.1.1 &
      
          sleep 1
          ip addr del 10.1.1.1/24 dev dummy0
          sleep 5
          kill %tcpdump
      
      RFC 3376 specifies that the report must be sent with a valid IP source
      address from the destination subnet, or from address 0.0.0.0.  Add an
      extra check to make sure this is the case.
      Signed-off-by: default avatarKevin Cernekee <cernekee@chromium.org>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      d3c38df3
    • Thomas Gleixner's avatar
      x86/mce: Make machine check speculation protected · 81619a39
      Thomas Gleixner authored
      commit 6f41c34d
      
       upstream.
      
      The machine check idtentry uses an indirect branch directly from the low
      level code. This evades the speculation protection.
      
      Replace it by a direct call into C code and issue the indirect call there
      so the compiler can apply the proper speculation protection.
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarBorislav Petkov <bp@alien8.de>
      Reviewed-by: default avatarDavid Woodhouse <dwmw@amazon.co.uk>
      Niced-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/alpine.DEB.2.20.1801181626290.1847@nanos
      
      
      [bwh: Backported to 3.16
       - #include <asm/traps.h> in mce.c
       - Adjust filename, context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      81619a39
    • Johannes Berg's avatar
      cfg80211: fix station info handling bugs · 993d55fc
      Johannes Berg authored
      commit 5762d7d3 upstream.
      
      Fix two places where the structure isn't initialized to zero,
      and thus can't be filled properly by the driver.
      
      Fixes: 4a4b8169 ("cfg80211: Accept multiple RSSI thresholds for CQM")
      Fixes: 9930380f
      
       ("cfg80211: implement IWRATE")
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [bwh: Backported to 3.16: drop change in cfg80211_cqm_rssi_update()]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      993d55fc
    • Marc Kleine-Budde's avatar
      can: af_can: canfd_rcv(): replace WARN_ONCE by pr_warn_once · 75b43780
      Marc Kleine-Budde authored
      commit d4689846
      
       upstream.
      
      If an invalid CANFD frame is received, from a driver or from a tun
      interface, a Kernel warning is generated.
      
      This patch replaces the WARN_ONCE by a simple pr_warn_once, so that a
      kernel, bootet with panic_on_warn, does not panic. A printk seems to be
      more appropriate here.
      
      Reported-by: syzbot+e3b775f40babeff6e68b@syzkaller.appspotmail.com
      Suggested-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Acked-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      [bwh: Backported to 3.16:
       - Keep using the 'drop' label, as it has another user
       - Adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      75b43780
    • Marc Kleine-Budde's avatar
      can: af_can: can_rcv(): replace WARN_ONCE by pr_warn_once · 0d8fccb2
      Marc Kleine-Budde authored
      commit 8cb68751
      
       upstream.
      
      If an invalid CAN frame is received, from a driver or from a tun
      interface, a Kernel warning is generated.
      
      This patch replaces the WARN_ONCE by a simple pr_warn_once, so that a
      kernel, bootet with panic_on_warn, does not panic. A printk seems to be
      more appropriate here.
      
      Reported-by: syzbot+4386709c0c1284dca827@syzkaller.appspotmail.com
      Suggested-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Acked-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      [bwh: Backported to 3.16:
       - Keep using the 'drop' label, as it has another user
       - Adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      0d8fccb2
    • Christophe Leroy's avatar
      net: fs_enet: do not call phy_stop() in interrupts · 13b9af48
      Christophe Leroy authored
      commit f8b39039 upstream.
      
      In case of TX timeout, fs_timeout() calls phy_stop(), which
      triggers the following BUG_ON() as we are in interrupt.
      
      [92708.199889] kernel BUG at drivers/net/phy/mdio_bus.c:482!
      [92708.204985] Oops: Exception in kernel mode, sig: 5 [#1]
      [92708.210119] PREEMPT
      [92708.212107] CMPC885
      [92708.214216] CPU: 0 PID: 3 Comm: ksoftirqd/0 Tainted: G        W       4.9.61 #39
      [92708.223227] task: c60f0a40 task.stack: c6104000
      [92708.227697] NIP: c02a84bc LR: c02a947c CTR: c02a93d8
      [92708.232614] REGS: c6105c70 TRAP: 0700   Tainted: G        W        (4.9.61)
      [92708.241193] MSR: 00021032 <ME,IR,DR,RI>[92708.244818]   CR: 24000822  XER: 20000000
      [92708.248767]
      GPR00: c02a947c c6105d20 c60f0a40 c62b4c00 00000005 0000001f c069aad8 0001a688
      GPR08: 00000007 00000100 c02a93d8 00000000 000005fc 00000000 c6213240 c06338e4
      GPR16: 00000001 c06330d4 c0633094 00000000 c0680000 c6104000 c6104000 00000000
      GPR24: 00000200 00000000 ffffffff 00000004 00000078 00009032 00000000 c62b4c00
      NIP [c02a84bc] mdiobus_read+0x20/0x74
      [92708.281517] LR [c02a947c] kszphy_config_intr+0xa4/0xc4
      [92708.286547] Call Trace:
      [92708.288980] [c6105d20] [c6104000] 0xc6104000 (unreliable)
      [92708.294339] [c6105d40] [c02a947c] kszphy_config_intr+0xa4/0xc4
      [92708.300098] [c6105d50] [c02a5330] phy_stop+0x60/0x9c
      [92708.305007] [c6105d60] [c02c84d0] fs_timeout+0xdc/0x110
      [92708.310197] [c6105d80] [c035cd48] dev_watchdog+0x268/0x2a0
      [92708.315593] [c6105db0] [c0060288] call_timer_fn+0x34/0x17c
      [92708.321014] [c6105dd0] [c00605f0] run_timer_softirq+0x21c/0x2e4
      [92708.326887] [c6105e50] [c001e19c] __do_softirq+0xf4/0x2f4
      [92708.332207] [c6105eb0] [c001e3c8] run_ksoftirqd+0x2c/0x40
      [92708.337560] [c6105ec0] [c003b420] smpboot_thread_fn+0x1f0/0x258
      [92708.343405] [c6105ef0] [c003745c] kthread+0xbc/0xd0
      [92708.348217] [c6105f40] [c000c400] ret_from_kernel_thread+0x5c/0x64
      [92708.354275] Instruction dump:
      [92708.357207] 7c0803a6 bbc10018 38210020 4e800020 7c0802a6 9421ffe0 54290024 bfc10018
      [92708.364865] 90010024 7c7f1b78 81290008 552902ee <0f090000> 3bc3002c 7fc3f378 90810008
      [92708.372711] ---[ end trace 42b05441616fafd7 ]---
      
      This patch moves fs_timeout() actions into an async worker.
      
      Fixes: commit 48257c4f
      
       ("Add fs_enet ethernet network driver, for several embedded platforms")
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      [bwh: Backported to 3.16: adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      13b9af48
    • Jeremy Compostella's avatar
      i2c: core-smbus: prevent stack corruption on read I2C_BLOCK_DATA · 4a6efb01
      Jeremy Compostella authored
      commit 89c6efa6
      
       upstream.
      
      On a I2C_SMBUS_I2C_BLOCK_DATA read request, if data->block[0] is
      greater than I2C_SMBUS_BLOCK_MAX + 1, the underlying I2C driver writes
      data out of the msgbuf1 array boundary.
      
      It is possible from a user application to run into that issue by
      calling the I2C_SMBUS ioctl with data.block[0] greater than
      I2C_SMBUS_BLOCK_MAX + 1.
      
      This patch makes the code compliant with
      Documentation/i2c/dev-interface by raising an error when the requested
      size is larger than 32 bytes.
      
      Call Trace:
       [<ffffffff8139f695>] dump_stack+0x67/0x92
       [<ffffffff811802a4>] panic+0xc5/0x1eb
       [<ffffffff810ecb5f>] ? vprintk_default+0x1f/0x30
       [<ffffffff817456d3>] ? i2cdev_ioctl_smbus+0x303/0x320
       [<ffffffff8109a68b>] __stack_chk_fail+0x1b/0x20
       [<ffffffff817456d3>] i2cdev_ioctl_smbus+0x303/0x320
       [<ffffffff81745aed>] i2cdev_ioctl+0x4d/0x1e0
       [<ffffffff811f761a>] do_vfs_ioctl+0x2ba/0x490
       [<ffffffff81336e43>] ? security_file_ioctl+0x43/0x60
       [<ffffffff811f7869>] SyS_ioctl+0x79/0x90
       [<ffffffff81a22e97>] entry_SYSCALL_64_fastpath+0x12/0x6a
      Signed-off-by: default avatarJeremy Compostella <jeremy.compostella@intel.com>
      Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
      [bwh: Backported to 3.16: adjust filename]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      4a6efb01
    • Lixin Wang's avatar
      i2c: core: decrease reference count of device node in i2c_unregister_device · 3f8470bb
      Lixin Wang authored
      commit e0638fa4
      
       upstream.
      
      Reference count of device node was increased in of_i2c_register_device,
      but without decreasing it in i2c_unregister_device. Then the added
      device node will never be released. Fix this by adding the of_node_put.
      Signed-off-by: default avatarLixin Wang <alan.1.wang@nokia-sbell.com>
      Tested-by: default avatarWolfram Sang <wsa@the-dreams.de>
      Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
      [bwh: Backported to 3.16: adjust context]
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      3f8470bb
    • Joe Thornber's avatar
      dm btree: fix serious bug in btree_split_beneath() · 8cbb486d
      Joe Thornber authored
      commit bc68d0a4 upstream.
      
      When inserting a new key/value pair into a btree we walk down the spine of
      btree nodes performing the following 2 operations:
      
        i) space for a new entry
        ii) adjusting the first key entry if the new key is lower than any in the node.
      
      If the _root_ node is full, the function btree_split_beneath() allocates 2 new
      nodes, and redistibutes the root nodes entries between them.  The root node is
      left with 2 entries corresponding to the 2 new nodes.
      
      btree_split_beneath() then adjusts the spine to point to one of the two new
      children.  This means the first key is never adjusted if the new key was lower,
      ie. operation (ii) gets missed out.  This can result in the new key being
      'lost' for a period; until another low valued key is inserted that will uncover
      it.
      
      This is a serious bug, and quite hard to make trigger in normal use.  A
      reproducing test case ("thin create devices-in-reverse-order") is
      available as part of the thin-provision-tools project:
        https://github.com/jthornber/thin-provisioning-tools/blob/master/functional-tests/device-mapper/dm-tests.scm#L593
      
      
      
      Fix the issue by changing btree_split_beneath() so it no longer adjusts
      the spine.  Instead it unlocks both the new nodes, and lets the main
      loop in btree_insert_raw() relock the appropriate one and make any
      neccessary adjustments.
      Reported-by: default avatarMonty Pavel <monty_pavel@sina.com>
      Signed-off-by: default avatarJoe Thornber <thornber@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      8cbb486d
    • Dennis Yang's avatar
      dm thin metadata: THIN_MAX_CONCURRENT_LOCKS should be 6 · 86aeb765
      Dennis Yang authored
      commit 490ae017
      
       upstream.
      
      For btree removal, there is a corner case that a single thread
      could takes 6 locks which is more than THIN_MAX_CONCURRENT_LOCKS(5)
      and leads to deadlock.
      
      A btree removal might eventually call
      rebalance_children()->rebalance3() to rebalance entries of three
      neighbor child nodes when shadow_spine has already acquired two
      write locks. In rebalance3(), it tries to shadow and acquire the
      write locks of all three child nodes. However, shadowing a child
      node requires acquiring a read lock of the original child node and
      a write lock of the new block. Although the read lock will be
      released after block shadowing, shadowing the third child node
      in rebalance3() could still take the sixth lock.
      (2 write locks for shadow_spine +
       2 write locks for the first two child nodes's shadow +
       1 write lock for the last child node's shadow +
       1 read lock for the last child node)
      Signed-off-by: default avatarDennis Yang <dennisyang@qnap.com>
      Acked-by: default avatarJoe Thornber <thornber@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      86aeb765
    • Tianyu Lan's avatar
      KVM/x86: Fix wrong macro references of X86_CR0_PG_BIT and X86_CR4_PAE_BIT in kvm_valid_sregs() · 8b5184f9
      Tianyu Lan authored
      commit 37b95951 upstream.
      
      kvm_valid_sregs() should use X86_CR0_PG and X86_CR4_PAE to check bit
      status rather than X86_CR0_PG_BIT and X86_CR4_PAE_BIT. This patch is
      to fix it.
      
      Fixes: f2981033
      
      (KVM/x86: Check input paging mode when cs.l is set)
      Reported-by: default avatarJeremi Piotrowski <jeremi.piotrowski@gmail.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Radim Krčmář <rkrcmar@redhat.com>
      Signed-off-by: default avatarTianyu Lan <Tianyu.Lan@microsoft.com>
      Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      8b5184f9