Skip to content

Commit 184233a

Browse files
Dan Carpenterjoergroedel
authored andcommitted
iommu/omap: Fix buffer overflow in debugfs
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: bd4396f ("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>
1 parent 7e18e42 commit 184233a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/iommu/omap-iommu-debug.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ static inline bool is_omap_iommu_detached(struct omap_iommu *obj)
3232
ssize_t bytes; \
3333
const char *str = "%20s: %08x\n"; \
3434
const int maxcol = 32; \
35-
bytes = snprintf(p, maxcol, str, __stringify(name), \
35+
if (len < maxcol) \
36+
goto out; \
37+
bytes = scnprintf(p, maxcol, str, __stringify(name), \
3638
iommu_read_reg(obj, MMU_##name)); \
3739
p += bytes; \
3840
len -= bytes; \
39-
if (len < maxcol) \
40-
goto out; \
4141
} while (0)
4242

4343
static ssize_t

0 commit comments

Comments
 (0)