]> git.baikalelectronics.ru Git - kernel.git/commit
iommu/omap: Fix buffer overflow in debugfs
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 4 Aug 2022 14:32:39 +0000 (17:32 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:22:45 +0000 (13:22 +0200)
commitdf6f148856d842f348de20662084f2ddb3c2d61b
treeb289c8b5b191c3b59fd26e9753c1bff51d5d75d2
parent9ca7785ecf6a0685863a97c8eb0b2849bb13724c
iommu/omap: Fix buffer overflow in debugfs

[ Upstream commit a6660e9b7b5fa4e15e09cd4ee7d7801bae70968a ]

There are two issues here:

1) The "len" variable needs to be checked before the very first write.
   Otherwise if omap2_iommu_dump_ctx() with "bytes" less than 32 it is a
   buffer overflow.
2) The snprintf() function returns the number of bytes that *would* have
   been copied if there were enough space.  But we want to know the
   number of bytes which were *actually* copied so use scnprintf()
   instead.

Fixes: b8bdc993e891 ("iommu/omap: Consolidate OMAP IOMMU modules")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://lore.kernel.org/r/YuvYh1JbE3v+abd5@kili
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/omap-iommu-debug.c