提交 7b64dbf8 编写于 作者: D Dan Carpenter 提交者: Greg Kroah-Hartman

misc: mic/scif: fix wrap around tests

Signed integer overflow is undefined.  Also I added a check for
"(offset < 0)" in scif_unregister() because that makes it match the
other conditions and because I didn't want to subtract a negative.

Fixes: ba612aa8 ('misc: mic: SCIF memory registration and unregistration')
Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 269ad6e0
...@@ -1511,7 +1511,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd, ...@@ -1511,7 +1511,7 @@ off_t scif_register_pinned_pages(scif_epd_t epd,
if ((map_flags & SCIF_MAP_FIXED) && if ((map_flags & SCIF_MAP_FIXED) &&
((ALIGN(offset, PAGE_SIZE) != offset) || ((ALIGN(offset, PAGE_SIZE) != offset) ||
(offset < 0) || (offset < 0) ||
(offset + (off_t)len < offset))) (len > LONG_MAX - offset)))
return -EINVAL; return -EINVAL;
might_sleep(); might_sleep();
...@@ -1614,7 +1614,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset, ...@@ -1614,7 +1614,7 @@ off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset,
if ((map_flags & SCIF_MAP_FIXED) && if ((map_flags & SCIF_MAP_FIXED) &&
((ALIGN(offset, PAGE_SIZE) != offset) || ((ALIGN(offset, PAGE_SIZE) != offset) ||
(offset < 0) || (offset < 0) ||
(offset + (off_t)len < offset))) (len > LONG_MAX - offset)))
return -EINVAL; return -EINVAL;
/* Unsupported protection requested */ /* Unsupported protection requested */
...@@ -1732,7 +1732,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t len) ...@@ -1732,7 +1732,8 @@ scif_unregister(scif_epd_t epd, off_t offset, size_t len)
/* Offset is not page aligned or offset+len wraps around */ /* Offset is not page aligned or offset+len wraps around */
if ((ALIGN(offset, PAGE_SIZE) != offset) || if ((ALIGN(offset, PAGE_SIZE) != offset) ||
(offset + (off_t)len < offset)) (offset < 0) ||
(len > LONG_MAX - offset))
return -EINVAL; return -EINVAL;
err = scif_verify_epd(ep); err = scif_verify_epd(ep);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册