<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/drivers/i2c/i2c-dev.c, branch v4.9.296</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.9.296</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.9.296'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2021-08-26T12:37:22Z</updated>
<entry>
<title>i2c: dev: zero out array used for i2c reads from userspace</title>
<updated>2021-08-26T12:37:22Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2021-07-29T14:35:32Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=bc42bd9090ecbacb8ea325e25e02afdf37fc811e'/>
<id>urn:sha1:bc42bd9090ecbacb8ea325e25e02afdf37fc811e</id>
<content type='text'>
commit 86ff25ed6cd8240d18df58930bd8848b19fce308 upstream.

If an i2c driver happens to not provide the full amount of data that a
user asks for, it is possible that some uninitialized data could be sent
to userspace.  While all in-kernel drivers look to be safe, just be sure
by initializing the buffer to zero before it is passed to the i2c driver
so that any future drivers will not have this issue.

Also properly copy the amount of data recvieved to the userspace buffer,
as pointed out by Dan Carpenter.

Reported-by: Eric Dumazet &lt;edumazet@google.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Wolfram Sang &lt;wsa@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>i2c: dev: Fix the race between the release of i2c_dev and cdev</title>
<updated>2020-05-27T14:41:51Z</updated>
<author>
<name>Kevin Hao</name>
<email>haokexin@gmail.com</email>
</author>
<published>2019-10-11T15:00:14Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=c0d34399045609eda76882fa6d01fdfaf5b20d38'/>
<id>urn:sha1:c0d34399045609eda76882fa6d01fdfaf5b20d38</id>
<content type='text'>
[ Upstream commit 1413ef638abae4ab5621901cf4d8ef08a4a48ba6 ]

The struct cdev is embedded in the struct i2c_dev. In the current code,
we would free the i2c_dev struct directly in put_i2c_dev(), but the
cdev is manged by a kobject, and the release of it is not predictable.
So it is very possible that the i2c_dev is freed before the cdev is
entirely released. We can easily get the following call trace with
CONFIG_DEBUG_KOBJECT_RELEASE and CONFIG_DEBUG_OBJECTS_TIMERS enabled.
  ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x38
  WARNING: CPU: 19 PID: 1 at lib/debugobjects.c:325 debug_print_object+0xb0/0xf0
  Modules linked in:
  CPU: 19 PID: 1 Comm: swapper/0 Tainted: G        W         5.2.20-yocto-standard+ #120
  Hardware name: Marvell OcteonTX CN96XX board (DT)
  pstate: 80c00089 (Nzcv daIf +PAN +UAO)
  pc : debug_print_object+0xb0/0xf0
  lr : debug_print_object+0xb0/0xf0
  sp : ffff00001292f7d0
  x29: ffff00001292f7d0 x28: ffff800b82151788
  x27: 0000000000000001 x26: ffff800b892c0000
  x25: ffff0000124a2558 x24: 0000000000000000
  x23: ffff00001107a1d8 x22: ffff0000116b5088
  x21: ffff800bdc6afca8 x20: ffff000012471ae8
  x19: ffff00001168f2c8 x18: 0000000000000010
  x17: 00000000fd6f304b x16: 00000000ee79de43
  x15: ffff800bc0e80568 x14: 79616c6564203a74
  x13: 6e6968207473696c x12: 5f72656d6974203a
  x11: ffff0000113f0018 x10: 0000000000000000
  x9 : 000000000000001f x8 : 0000000000000000
  x7 : ffff0000101294cc x6 : 0000000000000000
  x5 : 0000000000000000 x4 : 0000000000000001
  x3 : 00000000ffffffff x2 : 0000000000000000
  x1 : 387fc15c8ec0f200 x0 : 0000000000000000
  Call trace:
   debug_print_object+0xb0/0xf0
   __debug_check_no_obj_freed+0x19c/0x228
   debug_check_no_obj_freed+0x1c/0x28
   kfree+0x250/0x440
   put_i2c_dev+0x68/0x78
   i2cdev_detach_adapter+0x60/0xc8
   i2cdev_notifier_call+0x3c/0x70
   notifier_call_chain+0x8c/0xe8
   blocking_notifier_call_chain+0x64/0x88
   device_del+0x74/0x380
   device_unregister+0x54/0x78
   i2c_del_adapter+0x278/0x2d0
   unittest_i2c_bus_remove+0x3c/0x80
   platform_drv_remove+0x30/0x50
   device_release_driver_internal+0xf4/0x1c0
   driver_detach+0x58/0xa0
   bus_remove_driver+0x84/0xd8
   driver_unregister+0x34/0x60
   platform_driver_unregister+0x20/0x30
   of_unittest_overlay+0x8d4/0xbe0
   of_unittest+0xae8/0xb3c
   do_one_initcall+0xac/0x450
   do_initcall_level+0x208/0x224
   kernel_init_freeable+0x2d8/0x36c
   kernel_init+0x18/0x108
   ret_from_fork+0x10/0x1c
  irq event stamp: 3934661
  hardirqs last  enabled at (3934661): [&lt;ffff00001009fa04&gt;] debug_exception_exit+0x4c/0x58
  hardirqs last disabled at (3934660): [&lt;ffff00001009fb14&gt;] debug_exception_enter+0xa4/0xe0
  softirqs last  enabled at (3934654): [&lt;ffff000010081d94&gt;] __do_softirq+0x46c/0x628
  softirqs last disabled at (3934649): [&lt;ffff0000100b4a1c&gt;] irq_exit+0x104/0x118

This is a common issue when using cdev embedded in a struct.
Fortunately, we already have a mechanism to solve this kind of issue.
Please see commit 233ed09d7fda ("chardev: add helper function to
register char devs with a struct device") for more detail.

In this patch, we choose to embed the struct device into the i2c_dev,
and use the API provided by the commit 233ed09d7fda to make sure that
the release of i2c_dev and cdev are in sequence.

Signed-off-by: Kevin Hao &lt;haokexin@gmail.com&gt;
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr</title>
<updated>2019-06-22T06:17:23Z</updated>
<author>
<name>Yingjoe Chen</name>
<email>yingjoe.chen@mediatek.com</email>
</author>
<published>2019-05-07T14:20:32Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8557793a2fea4f2b7006ea7b97d3f67532b2503d'/>
<id>urn:sha1:8557793a2fea4f2b7006ea7b97d3f67532b2503d</id>
<content type='text'>
[ Upstream commit a0692f0eef91354b62c2b4c94954536536be5425 ]

If I2C_M_RECV_LEN check failed, msgs[i].buf allocated by memdup_user
will not be freed. Pump index up so it will be freed.

Fixes: 838bfa6049fb ("i2c-dev: Add support for I2C_M_RECV_LEN")
Signed-off-by: Yingjoe Chen &lt;yingjoe.chen@mediatek.com&gt;
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>i2c: dev: prevent adapter retries and timeout being set as minus value</title>
<updated>2019-01-16T21:12:32Z</updated>
<author>
<name>Yi Zeng</name>
<email>yizeng@asrmicro.com</email>
</author>
<published>2019-01-09T07:33:07Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=57cd3fad7644a22f7b0fab8e3e5670c3424852fb'/>
<id>urn:sha1:57cd3fad7644a22f7b0fab8e3e5670c3424852fb</id>
<content type='text'>
commit 6ebec961d59bccf65d08b13fc1ad4e6272a89338 upstream.

If adapter-&gt;retries is set to a minus value from user space via ioctl,
it will make __i2c_transfer and __i2c_smbus_xfer skip the calling to
adapter-&gt;algo-&gt;master_xfer and adapter-&gt;algo-&gt;smbus_xfer that is
registered by the underlying bus drivers, and return value 0 to all the
callers. The bus driver will never be accessed anymore by all users,
besides, the users may still get successful return value without any
error or information log print out.

If adapter-&gt;timeout is set to minus value from user space via ioctl,
it will make the retrying loop in __i2c_transfer and __i2c_smbus_xfer
always break after the the first try, due to the time_after always
returns true.

Signed-off-by: Yi Zeng &lt;yizeng@asrmicro.com&gt;
[wsa: minor grammar updates to commit message]
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
Cc: stable@kernel.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>i2c: fix kernel memory disclosure in dev interface</title>
<updated>2017-01-19T19:18:02Z</updated>
<author>
<name>Vlad Tsyrklevich</name>
<email>vlad@tsyrklevich.net</email>
</author>
<published>2017-01-09T15:53:36Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=ab8957396a692d46a357aec8ff57abc9bd5a878a'/>
<id>urn:sha1:ab8957396a692d46a357aec8ff57abc9bd5a878a</id>
<content type='text'>
commit 30f939feaeee23e21391cfc7b484f012eb189c3c upstream.

i2c_smbus_xfer() does not always fill an entire block, allowing
kernel stack memory disclosure through the temp variable. Clear
it before it's read to.

Signed-off-by: Vlad Tsyrklevich &lt;vlad@tsyrklevich.net&gt;
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>i2c-dev: don't get i2c adapter via i2c_dev</title>
<updated>2016-07-08T01:29:31Z</updated>
<author>
<name>viresh kumar</name>
<email>viresh.kumar@linaro.org</email>
</author>
<published>2016-07-06T02:57:06Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=5136ed4fcb05cd4981cc6034a11e66370ed84789'/>
<id>urn:sha1:5136ed4fcb05cd4981cc6034a11e66370ed84789</id>
<content type='text'>
There is no code protecting i2c_dev to be freed after it is returned
from i2c_dev_get_by_minor() and using it to access the value which we
already have (minor) isn't safe really.

Avoid using it and get the adapter directly from 'minor'.

Signed-off-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Reviewed-by: Jean Delvare &lt;jdelvare@suse.de&gt;
Tested-by: Jean Delvare &lt;jdelvare@suse.de&gt;
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
</content>
</entry>
<entry>
<title>i2c: dev: use after free in detach</title>
<updated>2016-05-28T15:37:42Z</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2016-05-28T05:01:46Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=e6be18f6d62c1d3b331ae020b76a29c2ccf6b0bf'/>
<id>urn:sha1:e6be18f6d62c1d3b331ae020b76a29c2ccf6b0bf</id>
<content type='text'>
The call to put_i2c_dev() frees "i2c_dev" so there is a use after
free when we call cdev_del(&amp;i2c_dev-&gt;cdev).

Fixes: d6760b14d4a1 ('i2c: dev: switch from register_chrdev to cdev API')
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
</content>
</entry>
<entry>
<title>i2c: dev: don't start function name with 'return'</title>
<updated>2016-05-27T11:13:01Z</updated>
<author>
<name>Wolfram Sang</name>
<email>wsa@the-dreams.de</email>
</author>
<published>2016-05-27T11:13:01Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=72a71f869c95dc11b73f09fe18c593d4a0618c3f'/>
<id>urn:sha1:72a71f869c95dc11b73f09fe18c593d4a0618c3f</id>
<content type='text'>
I stumbled multiple times over 'return_i2c_dev', especially before the
actual 'return res'. It makes the code hard to read, so reanme the
function to 'put_i2c_dev' which also better matches 'get_free_i2c_dev'.

Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
</content>
</entry>
<entry>
<title>i2c: dev: switch from register_chrdev to cdev API</title>
<updated>2016-05-26T19:18:57Z</updated>
<author>
<name>Erico Nunes</name>
<email>erico.nunes@datacom.ind.br</email>
</author>
<published>2016-05-03T18:45:43Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=d6760b14d4a1243f918d983bba1e35c5a5cd5a6d'/>
<id>urn:sha1:d6760b14d4a1243f918d983bba1e35c5a5cd5a6d</id>
<content type='text'>
i2c-dev had never moved away from the older register_chrdev interface to
implement its char device registration. The register_chrdev API has the
limitation of enabling only up to 256 i2c-dev busses to exist.

Large platforms with lots of i2c devices (i.e. pluggable transceivers)
with dedicated busses may have to exceed that limit.
In particular, there are also platforms making use of the i2c bus
multiplexing API, which instantiates a virtual bus for each possible
multiplexed selection.

This patch removes the register_chrdev usage and replaces it with the
less old cdev API, which takes away the 256 i2c-dev bus limitation.
It should not have any other impact for i2c bus drivers or user space.

This patch has been tested on qemu x86 and qemu powerpc platforms with
the aid of a module which adds and removes 5000 virtual i2c busses, as
well as validated on an existing powerpc hardware platform which makes
use of the i2c bus multiplexing API.
i2c-dev busses with device minor numbers larger than 256 have also been
validated to work with the existing i2c-tools.

Signed-off-by: Erico Nunes &lt;erico.nunes@datacom.ind.br&gt;
[wsa: kept includes sorted]
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
</content>
</entry>
<entry>
<title>i2c: i2c-dev: sort includes</title>
<updated>2016-02-20T22:33:38Z</updated>
<author>
<name>Wolfram Sang</name>
<email>wsa@the-dreams.de</email>
</author>
<published>2016-02-20T22:33:38Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=a87660737f66123acf2f0dd2e5994e91b95a2351'/>
<id>urn:sha1:a87660737f66123acf2f0dd2e5994e91b95a2351</id>
<content type='text'>
I request this for drivers, so the core should adhere to sorted includes as
well.

Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
</content>
</entry>
</feed>
