<div dir="ltr">Hello.<div>Tomorrow I will test and send you an answer.<br><br>Thank you<br>Nejc Galof</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">V V pet., 28. jan. 2022 ob 23:00 je oseba Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> napisala:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">V4L2 is happy to map buffers read-only for capture devices (but rejects<br>
write-only mappings). We can support this as the dmabuf mmap()<br>
implementation supports it. This change fixes usage of the V4L2<br>
compatibility layer with OpenCV.<br>
<br>
While at it, attempt to validate the other flags. videobuf2 requires<br>
MAP_SHARED and doesn't check other flags, so mimic the same behaviour.<br>
While unlikly, other flags could get rejected by other kernel layers for<br>
V4L2 buffers but not for dmabuf. This can be handled later if the need<br>
arises.<br>
<br>
Signed-off-by: Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank">laurent.pinchart@ideasonboard.com</a>><br>
---<br>
src/v4l2/v4l2_camera_proxy.cpp | 13 +++++++++++--<br>
1 file changed, 11 insertions(+), 2 deletions(-)<br>
<br>
Nejc, could you please test this patch ? It's slightly different than<br>
the one I've shared on the IRC channel. If you don't mind appearing in<br>
the git development history, you can reply with<br>
<br>
Tested-by: Name <email@address><br>
<br>
and I'll add that (as well as a corresponding Reported-by tag) to the<br>
commit before pushing it.<br>
<br>
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp<br>
index f3470a6d312a..ebe7601a4ba6 100644<br>
--- a/src/v4l2/v4l2_camera_proxy.cpp<br>
+++ b/src/v4l2/v4l2_camera_proxy.cpp<br>
@@ -104,8 +104,17 @@ void *V4L2CameraProxy::mmap(V4L2CameraFile *file, void *addr, size_t length,<br>
<br>
MutexLocker locker(proxyMutex_);<br>
<br>
- /* \todo Validate prot and flags properly. */<br>
- if (prot != (PROT_READ | PROT_WRITE)) {<br>
+ /*<br>
+ * Mimic the videobuf2 behaviour, which requires PROT_READ. Reject<br>
+ * PROT_EXEC as it makes no sense.<br>
+ */<br>
+ if (!(prot & PROT_READ) || prot & PROT_EXEC) {<br>
+ errno = EINVAL;<br>
+ return MAP_FAILED;<br>
+ }<br>
+<br>
+ /* videobuf2 also requires MAP_SHARED. */<br>
+ if (!(flags & MAP_SHARED)) {<br>
errno = EINVAL;<br>
return MAP_FAILED;<br>
}<br>
<br>
base-commit: 7ea52d2b586144fdc033a3ffc1c4a4bbb99b5440<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart<br>
<br>
</blockquote></div>