<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/media/media-device.c, branch linux-4.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2020-05-27T14:40:25Z</updated>
<entry>
<title>media: fix media devnode ioctl/syscall and unregister race</title>
<updated>2020-05-27T14:40:25Z</updated>
<author>
<name>Shuah Khan</name>
</author>
<published>2016-06-10T17:37:23Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b882fcc49cb6c95259508766624d08fc516cd672'/>
<id>urn:sha1:b882fcc49cb6c95259508766624d08fc516cd672</id>
<content type='text'>
commit 6f0dd24a084a17f9984dd49dffbf7055bf123993 upstream.

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-&gt;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: Shuah Khan &lt;shuahkh@osg.samsung.com&gt;
Suggested-by: Sakari Ailus &lt;sakari.ailus@linux.intel.com&gt;
Reported-by: Mauro Carvalho Chehab &lt;mchehab@osg.samsung.com&gt;
Tested-by: Mauro Carvalho Chehab &lt;mchehab@osg.samsung.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;mchehab@s-opensource.com&gt;
[bwh: Backported to 4.4: adjut filename, context]
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>media: fix use-after-free in cdev_put() when app exits after driver unbind</title>
<updated>2020-05-27T14:40:25Z</updated>
<author>
<name>Shuah Khan</name>
</author>
<published>2016-05-04T19:48:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bbb3ce60dd698ec19fc7d5ff9fc61e7bedb6b9a4'/>
<id>urn:sha1:bbb3ce60dd698ec19fc7d5ff9fc61e7bedb6b9a4</id>
<content type='text'>
commit 5b28dde51d0ccc54cee70756e1800d70bed7114a upstream.

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]  [&lt;ffffffff81aecac3&gt;] dump_stack+0x67/0x94
kernel: [  193.601102]  [&lt;ffffffff815359b2&gt;] print_trailer+0x112/0x1a0
kernel: [  193.601111]  [&lt;ffffffff8153b5e4&gt;] object_err+0x34/0x40
kernel: [  193.601119]  [&lt;ffffffff8153d9d4&gt;] kasan_report_error+0x224/0x530
kernel: [  193.601128]  [&lt;ffffffff814a2c3d&gt;] ? kzfree+0x2d/0x40
kernel: [  193.601137]  [&lt;ffffffff81539d72&gt;] ? kfree+0x1d2/0x1f0
kernel: [  193.601154]  [&lt;ffffffff8157ca7e&gt;] ? cdev_put+0x4e/0x50
kernel: [  193.601162]  [&lt;ffffffff8157ca7e&gt;] cdev_put+0x4e/0x50
kernel: [  193.601170]  [&lt;ffffffff815767eb&gt;] __fput+0x52b/0x6c0
kernel: [  193.601179]  [&lt;ffffffff8117743a&gt;] ? switch_task_namespaces+0x2a
kernel: [  193.601188]  [&lt;ffffffff815769ee&gt;] ____fput+0xe/0x10
kernel: [  193.601196]  [&lt;ffffffff81170023&gt;] task_work_run+0x133/0x1f0
kernel: [  193.601204]  [&lt;ffffffff8117746e&gt;] ? switch_task_namespaces+0x5e
kernel: [  193.601213]  [&lt;ffffffff8111b50c&gt;] do_exit+0x72c/0x2c20
kernel: [  193.601224]  [&lt;ffffffff8111ade0&gt;] ? release_task+0x1250/0x1250
-
-
-
kernel: [  193.601360]  [&lt;ffffffff81003587&gt;] ? exit_to_usermode_loop+0xe7
kernel: [  193.601368]  [&lt;ffffffff810035c0&gt;] exit_to_usermode_loop+0x120
kernel: [  193.601376]  [&lt;ffffffff810061da&gt;] syscall_return_slowpath+0x16a
kernel: [  193.601386]  [&lt;ffffffff82848b33&gt;] entry_SYSCALL_64_fastpath+0xa6

Signed-off-by: Shuah Khan &lt;shuahkh@osg.samsung.com&gt;
Tested-by: Mauro Carvalho Chehab &lt;mchehab@osg.samsung.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;mchehab@s-opensource.com&gt;
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>media-device: dynamically allocate struct media_devnode</title>
<updated>2020-05-27T14:40:25Z</updated>
<author>
<name>Mauro Carvalho Chehab</name>
</author>
<published>2016-04-27T22:28:26Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bcce79f625b4ad3c9309198f5eb8325483651439'/>
<id>urn:sha1:bcce79f625b4ad3c9309198f5eb8325483651439</id>
<content type='text'>
commit a087ce704b802becbb4b0f2a20f2cb3f6911802e upstream.

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: Mauro Carvalho Chehab &lt;mchehab@osg.samsung.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;mchehab@s-opensource.com&gt;
[bwh: Backported to 4.4:
 - Drop change in au0828
 - Include &lt;linux/slab.h&gt; in media-device.c
 - Adjust context]
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>[media] media: Use strlcpy instead of custom code</title>
<updated>2014-09-21T23:27:08Z</updated>
<author>
<name>Laurent Pinchart</name>
</author>
<published>2014-07-17T11:52:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=de8eae36057b50086278af1ec4d96fc9a2e35f0b'/>
<id>urn:sha1:de8eae36057b50086278af1ec4d96fc9a2e35f0b</id>
<content type='text'>
Replace strncpy + manually setting the terminating '\0' with an strlcpy
call.

Reported-by: Joe Perches &lt;joe@perches.com&gt;
Signed-off-by: Laurent Pinchart &lt;laurent.pinchart@ideasonboard.com&gt;
Acked-by: Sakari Ailus &lt;sakari.ailus@linux.intel.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;mchehab@osg.samsung.com&gt;
</content>
</entry>
<entry>
<title>[media] media-device: Remove duplicated memset() in media_enum_entities()</title>
<updated>2014-07-22T04:02:52Z</updated>
<author>
<name>Salva Peiró</name>
</author>
<published>2014-06-07T14:41:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f8ca6ac00d2ba24c5557f08f81439cd3432f0802'/>
<id>urn:sha1:f8ca6ac00d2ba24c5557f08f81439cd3432f0802</id>
<content type='text'>
After the zeroing the whole struct struct media_entity_desc u_ent,
it is no longer necessary to memset(0) its u_ent.name field.

CC: stable@vger.kernel.org
Signed-off-by: Salva Peiró &lt;speiro@ai2.upv.es&gt;
Signed-off-by: Laurent Pinchart &lt;laurent.pinchart@ideasonboard.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;m.chehab@samsung.com&gt;
</content>
</entry>
<entry>
<title>Merge tag 'v3.15-rc6' into patchwork</title>
<updated>2014-05-22T02:03:15Z</updated>
<author>
<name>Mauro Carvalho Chehab</name>
</author>
<published>2014-05-22T02:03:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e899966f626f1f657a4a7bac736c0b9ae5a243ea'/>
<id>urn:sha1:e899966f626f1f657a4a7bac736c0b9ae5a243ea</id>
<content type='text'>
Linux 3.15-rc6

* tag 'v3.15-rc6': (1314 commits)
  Linux 3.15-rc6
  Btrfs: send, fix incorrect ref access when using extrefs
  Btrfs: fix EIO on reading file after ioctl clone works on it
  scripts/checksyscalls.sh: Make renameat optional
  asm-generic: Add renameat2 syscall
  ia64: add renameat2 syscall
  parisc: add renameat2 syscall
  m68k: add renameat2 syscall
  sysfs: make sure read buffer is zeroed
  ahci: imx: PLL clock needs 100us to settle down
  PCI: Wrong register used to check pending traffic
  target: fix memory leak on XCOPY
  random: fix BUG_ON caused by accounting simplification
  clk: tegra: Fix wrong value written to PLLE_AUX
  staging: rtl8723au: Do not reset wdev-&gt;iftype in netdev_close()
  ACPI / video: Revert native brightness quirk for ThinkPad T530
  staging: rtl8723au: Use correct pipe type for USB interrupts
  crush: decode and initialize chooseleaf_vary_r
  libceph: fix corruption when using page_count 0 page in rbd
  arm64: fix pud_huge() for 2-level pagetables
  ...
</content>
</entry>
<entry>
<title>[media] media: Use a better owner for the media device</title>
<updated>2014-05-13T16:39:00Z</updated>
<author>
<name>Sakari Ailus</name>
</author>
<published>2013-12-12T15:38:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=85de721c46ba8ad9b283b2b3e307c9a3e8425042'/>
<id>urn:sha1:85de721c46ba8ad9b283b2b3e307c9a3e8425042</id>
<content type='text'>
mdev-&gt;fops-&gt;owner is actually the owner of the very same module which
implements media_device_register(), so it can't be unloaded anyway. Instead,
use THIS_MODULE through a macro as does video_register_device().

Signed-off-by: Sakari Ailus &lt;sakari.ailus@linux.intel.com&gt;
Acked-by: Laurent Pinchart &lt;laurent.pinchart@ideasonboard.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;m.chehab@samsung.com&gt;
</content>
</entry>
<entry>
<title>[media] media-device: fix infoleak in ioctl media_enum_entities()</title>
<updated>2014-05-01T12:53:28Z</updated>
<author>
<name>Salva Peiró</name>
</author>
<published>2014-04-30T17:48:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e6a623460e5fc960ac3ee9f946d3106233fd28d8'/>
<id>urn:sha1:e6a623460e5fc960ac3ee9f946d3106233fd28d8</id>
<content type='text'>
This fixes CVE-2014-1739.

Signed-off-by: Salva Peiró &lt;speiro@ai2.upv.es&gt;
Acked-by: Laurent Pinchart &lt;laurent.pinchart@ideasonboard.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab &lt;m.chehab@samsung.com&gt;
</content>
</entry>
<entry>
<title>[media] media: info leak in __media_device_enum_links()</title>
<updated>2013-06-12T21:52:45Z</updated>
<author>
<name>Dan Carpenter</name>
</author>
<published>2013-04-13T09:32:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c88e739b1fad662240e99ecbd0bdaac871717987'/>
<id>urn:sha1:c88e739b1fad662240e99ecbd0bdaac871717987</id>
<content type='text'>
These structs have holes and reserved struct members which aren't
cleared.  I've added a memset() so we don't leak stack information.

Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Laurent Pinchart &lt;laurent.pinchart@ideasonboard.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;mchehab@redhat.com&gt;
</content>
</entry>
<entry>
<title>[media] media: info leak in media_device_enum_entities()</title>
<updated>2013-04-23T19:58:52Z</updated>
<author>
<name>Dan Carpenter</name>
</author>
<published>2013-04-21T10:10:03Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c06ca8f92b0b23dfd209fea27d71046c9c776910'/>
<id>urn:sha1:c06ca8f92b0b23dfd209fea27d71046c9c776910</id>
<content type='text'>
The last part of the "u_ent.name" buffer isn't cleared so it still has
uninitialized stack memory.

Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Mauro Carvalho Chehab &lt;mchehab@redhat.com&gt;
</content>
</entry>
</feed>
