i2c: dev: zero out array used for i2c reads from userspace
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Jul 2021 14:35:32 +0000 (16:35 +0200)
committerSasha Levin <sashal@kernel.org>
Thu, 26 Aug 2021 12:37:22 +0000 (08:37 -0400)
commitbc42bd9090ecbacb8ea325e25e02afdf37fc811e
tree6780b79dbeed65f9fec993b15ac1b2270adfff0b
parent642b0c747a03c03cadc1b4a614fb44ff1c1ec4c3
i2c: dev: zero out array used for i2c reads from userspace

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 <edumazet@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/i2c/i2c-dev.c