1. 16 6月, 2016 3 次提交
    • S
      [media] media: fix media devnode ioctl/syscall and unregister race · 6f0dd24a
      Shuah Khan 提交于
      Media devnode open/ioctl could be in progress when media device unregister
      is initiated. System calls and ioctls check media device registered status
      at the beginning, however, there is a window where unregister could be in
      progress without changing the media devnode status to unregistered.
      
      process 1				process 2
      fd = open(/dev/media0)
      media_devnode_is_registered()
      	(returns true here)
      
      					media_device_unregister()
      						(unregister is in progress
      						and devnode isn't
      						unregistered yet)
      					...
      ioctl(fd, ...)
      __media_ioctl()
      media_devnode_is_registered()
      	(returns true here)
      					...
      					media_devnode_unregister()
      					...
      					(driver releases the media device
      					memory)
      
      media_device_ioctl()
      	(By this point
      	devnode->media_dev does not
      	point to allocated memory.
      	use-after free in in mutex_lock_nested)
      
      BUG: KASAN: use-after-free in mutex_lock_nested+0x79c/0x800 at addr
      ffff8801ebe914f0
      
      Fix it by clearing register bit when unregister starts to avoid the race.
      
      process 1                               process 2
      fd = open(/dev/media0)
      media_devnode_is_registered()
              (could return true here)
      
                                              media_device_unregister()
                                                      (clear the register bit,
      						 then start unregister.)
                                              ...
      ioctl(fd, ...)
      __media_ioctl()
      media_devnode_is_registered()
              (return false here, ioctl
      	 returns I/O error, and
      	 will not access media
      	 device memory)
                                              ...
                                              media_devnode_unregister()
                                              ...
                                              (driver releases the media device
      					 memory)
      Signed-off-by: NShuah Khan <shuahkh@osg.samsung.com>
      Suggested-by: NSakari Ailus <sakari.ailus@linux.intel.com>
      Reported-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Tested-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Signed-off-by: NMauro Carvalho Chehab <mchehab@s-opensource.com>
      6f0dd24a
    • S
      [media] media: fix use-after-free in cdev_put() when app exits after driver unbind · 5b28dde5
      Shuah Khan 提交于
      When driver unbinds while media_ioctl is in progress, cdev_put() fails with
      when app exits after driver unbinds.
      
      Add devnode struct device kobj as the cdev parent kobject. cdev_add() gets
      a reference to it and releases it in cdev_del() ensuring that the devnode
      is not deallocated as long as the application has the device file open.
      
      media_devnode_register() initializes the struct device kobj before calling
      cdev_add(). media_devnode_unregister() does cdev_del() and then deletes the
      device. devnode is released when the last reference to the struct device is
      gone.
      
      This problem is found on uvcvideo, em28xx, and au0828 drivers and fix has
      been tested on all three.
      
      kernel: [  193.599736] BUG: KASAN: use-after-free in cdev_put+0x4e/0x50
      kernel: [  193.599745] Read of size 8 by task media_device_te/1851
      kernel: [  193.599792] INFO: Allocated in __media_device_register+0x54
      kernel: [  193.599951] INFO: Freed in media_devnode_release+0xa4/0xc0
      
      kernel: [  193.601083] Call Trace:
      kernel: [  193.601093]  [<ffffffff81aecac3>] dump_stack+0x67/0x94
      kernel: [  193.601102]  [<ffffffff815359b2>] print_trailer+0x112/0x1a0
      kernel: [  193.601111]  [<ffffffff8153b5e4>] object_err+0x34/0x40
      kernel: [  193.601119]  [<ffffffff8153d9d4>] kasan_report_error+0x224/0x530
      kernel: [  193.601128]  [<ffffffff814a2c3d>] ? kzfree+0x2d/0x40
      kernel: [  193.601137]  [<ffffffff81539d72>] ? kfree+0x1d2/0x1f0
      kernel: [  193.601154]  [<ffffffff8157ca7e>] ? cdev_put+0x4e/0x50
      kernel: [  193.601162]  [<ffffffff8157ca7e>] cdev_put+0x4e/0x50
      kernel: [  193.601170]  [<ffffffff815767eb>] __fput+0x52b/0x6c0
      kernel: [  193.601179]  [<ffffffff8117743a>] ? switch_task_namespaces+0x2a
      kernel: [  193.601188]  [<ffffffff815769ee>] ____fput+0xe/0x10
      kernel: [  193.601196]  [<ffffffff81170023>] task_work_run+0x133/0x1f0
      kernel: [  193.601204]  [<ffffffff8117746e>] ? switch_task_namespaces+0x5e
      kernel: [  193.601213]  [<ffffffff8111b50c>] do_exit+0x72c/0x2c20
      kernel: [  193.601224]  [<ffffffff8111ade0>] ? release_task+0x1250/0x1250
      -
      -
      -
      kernel: [  193.601360]  [<ffffffff81003587>] ? exit_to_usermode_loop+0xe7
      kernel: [  193.601368]  [<ffffffff810035c0>] exit_to_usermode_loop+0x120
      kernel: [  193.601376]  [<ffffffff810061da>] syscall_return_slowpath+0x16a
      kernel: [  193.601386]  [<ffffffff82848b33>] entry_SYSCALL_64_fastpath+0xa6
      Signed-off-by: NShuah Khan <shuahkh@osg.samsung.com>
      Tested-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Signed-off-by: NMauro Carvalho Chehab <mchehab@s-opensource.com>
      5b28dde5
    • M
      [media] media-device: dynamically allocate struct media_devnode · a087ce70
      Mauro Carvalho Chehab 提交于
      struct media_devnode is currently embedded at struct media_device.
      
      While this works fine during normal usage, it leads to a race
      condition during devnode unregister. the problem is that drivers
      assume that, after calling media_device_unregister(), the struct
      that contains media_device can be freed. This is not true, as it
      can't be freed until userspace closes all opened /dev/media devnodes.
      
      In other words, if the media devnode is still open, and media_device
      gets freed, any call to an ioctl will make the core to try to access
      struct media_device, with will cause an use-after-free and even GPF.
      
      Fix this by dynamically allocating the struct media_devnode and only
      freeing it when it is safe.
      Signed-off-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      Signed-off-by: NMauro Carvalho Chehab <mchehab@s-opensource.com>
      a087ce70
  2. 07 5月, 2016 2 次提交
  3. 05 5月, 2016 1 次提交
    • M
      [media] media-device: fix builds when USB or PCI is compiled as module · b34ecd5a
      Mauro Carvalho Chehab 提交于
      Just checking ifdef CONFIG_USB is not enough, if the USB is compiled
      as module. The same applies to PCI.
      
      Tested with the following .config alternatives:
      
      CONFIG_USB=m
      CONFIG_MEDIA_CONTROLLER=y
      CONFIG_MEDIA_SUPPORT=m
      CONFIG_VIDEO_AU0828=m
      
      CONFIG_USB=m
      CONFIG_MEDIA_CONTROLLER=y
      CONFIG_MEDIA_SUPPORT=y
      CONFIG_VIDEO_AU0828=m
      
      CONFIG_USB=y
      CONFIG_MEDIA_CONTROLLER=y
      CONFIG_MEDIA_SUPPORT=y
      CONFIG_VIDEO_AU0828=m
      
      CONFIG_USB=y
      CONFIG_MEDIA_CONTROLLER=y
      CONFIG_MEDIA_SUPPORT=y
      CONFIG_VIDEO_AU0828=y
      Signed-off-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      b34ecd5a
  4. 21 4月, 2016 1 次提交
    • M
      [media] media-device: get rid of the spinlock · e2c91d4d
      Mauro Carvalho Chehab 提交于
      Right now, the lock schema for media_device struct is messy,
      since sometimes, it is protected via a spin lock, while, for
      media graph traversal, it is protected by a mutex.
      
      Solve this conflict by always using a mutex.
      
      As a side effect, this prevents a bug when the media notifiers
      is called at atomic context, while running the notifier callback:
      
       BUG: sleeping function called from invalid context at mm/slub.c:1289
       in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
       4 locks held by modprobe/3479:
       #0:  (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
       #1:  (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
       #2:  (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
       #3:  (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
       CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
       Hardware name:                  /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
       0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
       ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
       ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
       Call Trace:
       [<ffffffff81933901>] dump_stack+0x85/0xc4
       [<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
       [<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
       [<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
       [<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
       [<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
       [<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
       [<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
       [<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
       [<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
      Reviewed-by: NJavier Martinez Canillas <javier@osg.samsung.com>
      Acked-by: NSakari Ailus <sakari.ailus@linux.intel.com>
      Acked-by: NHans Verkuil <hans.verkuil@cisco.com>
      Signed-off-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      e2c91d4d
  5. 11 3月, 2016 1 次提交
    • M
      [media] media-device: map new functions into old types for legacy API · b2cd2744
      Mauro Carvalho Chehab 提交于
      The legacy media controller userspace API exposes entity types that
      carry both type and function information. The new API replaces the type
      with a function. It preserves backward compatibility by defining legacy
      functions for the existing types and using them in drivers.
      
      This works fine, as long as newer entity functions won't be added.
      
      Unfortunately, some tools, like media-ctl with --print-dot argument
      rely on the now legacy MEDIA_ENT_T_V4L2_SUBDEV and MEDIA_ENT_T_DEVNODE
      numeric ranges to identify what entities will be shown.
      
      Also, if the entity doesn't match those ranges, it will ignore the
      major/minor information on devnodes, and won't be getting the devnode
      name via udev or sysfs.
      
      As we're now adding devices outside the old range, the legacy ioctl
      needs to map the new entity functions into a type at the old range,
      or otherwise we'll have a regression.
      
      Detected on all released media-ctl versions (e. g. versions <= 1.10).
      
      Fix this by deriving the type from the function to emulate the legacy
      API if the function isn't in the legacy functions range.
      Reported-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: NMauro Carvalho Chehab <mchehab@osg.samsung.com>
      b2cd2744
  6. 04 3月, 2016 2 次提交
  7. 03 3月, 2016 1 次提交
  8. 27 2月, 2016 1 次提交
  9. 23 2月, 2016 2 次提交
  10. 16 2月, 2016 1 次提交
  11. 25 1月, 2016 1 次提交
  12. 11 1月, 2016 24 次提交