Patch Detail
Show a patch.
GET /api/patches/15296/?format=api
{ "id": 15296, "url": "https://patchwork.libcamera.org/api/patches/15296/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15296/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220128220031.3467-1-laurent.pinchart@ideasonboard.com>", "date": "2022-01-28T22:00:31", "name": "[libcamera-devel] v4l2: Accept read-only buffers mappings and require MAP_SHARED", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "6ac9cfaab3c352fdaf1d40c6775d86667604cbb6", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15296/mbox/", "series": [ { "id": 2903, "url": "https://patchwork.libcamera.org/api/series/2903/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2903", "date": "2022-01-28T22:00:31", "name": "[libcamera-devel] v4l2: Accept read-only buffers mappings and require MAP_SHARED", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2903/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15296/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15296/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B757EBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Jan 2022 22:01:02 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A9595609B3;\n\tFri, 28 Jan 2022 23:01:01 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2298C604F1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jan 2022 23:00:59 +0100 (CET)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 88B25471;\n\tFri, 28 Jan 2022 23:00:58 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"E/dvGavB\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1643407258;\n\tbh=kE9PBAmfrvLwraMeUl/Oc2OrHhEN7TL6leLSpJF71cY=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=E/dvGavBkR6SkhNVZEwOTrWiONQyVzJvNItZ5N6L/Pg75nw7V/fpZ4SG/AmRZJ+J9\n\traQ0jCJuXDoTbHUBN6mE3BZgxWnyrNW/8vGGaO/zasHWLLRKZ+2UmnIXIkwGLwgd8u\n\tzQtemw57QQQHu3IGkzC56/Gm9DmvgJHnFw/6xqjk=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 29 Jan 2022 00:00:31 +0200", "Message-Id": "<20220128220031.3467-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.34.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] v4l2: Accept read-only buffers mappings\n\tand require MAP_SHARED", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Cc": "Nejc Galof <galof.nejc@gmail.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "V4L2 is happy to map buffers read-only for capture devices (but rejects\nwrite-only mappings). We can support this as the dmabuf mmap()\nimplementation supports it. This change fixes usage of the V4L2\ncompatibility layer with OpenCV.\n\nWhile at it, attempt to validate the other flags. videobuf2 requires\nMAP_SHARED and doesn't check other flags, so mimic the same behaviour.\nWhile unlikly, other flags could get rejected by other kernel layers for\nV4L2 buffers but not for dmabuf. This can be handled later if the need\narises.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/v4l2/v4l2_camera_proxy.cpp | 13 +++++++++++--\n 1 file changed, 11 insertions(+), 2 deletions(-)\n\nNejc, could you please test this patch ? It's slightly different than\nthe one I've shared on the IRC channel. If you don't mind appearing in\nthe git development history, you can reply with\n\nTested-by: Name <email@address>\n\nand I'll add that (as well as a corresponding Reported-by tag) to the\ncommit before pushing it.\n\n\nbase-commit: 7ea52d2b586144fdc033a3ffc1c4a4bbb99b5440", "diff": "diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex f3470a6d312a..ebe7601a4ba6 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -104,8 +104,17 @@ void *V4L2CameraProxy::mmap(V4L2CameraFile *file, void *addr, size_t length,\n \n \tMutexLocker locker(proxyMutex_);\n \n-\t/* \\todo Validate prot and flags properly. */\n-\tif (prot != (PROT_READ | PROT_WRITE)) {\n+\t/*\n+\t * Mimic the videobuf2 behaviour, which requires PROT_READ. Reject\n+\t * PROT_EXEC as it makes no sense.\n+\t */\n+\tif (!(prot & PROT_READ) || prot & PROT_EXEC) {\n+\t\terrno = EINVAL;\n+\t\treturn MAP_FAILED;\n+\t}\n+\n+\t/* videobuf2 also requires MAP_SHARED. */\n+\tif (!(flags & MAP_SHARED)) {\n \t\terrno = EINVAL;\n \t\treturn MAP_FAILED;\n \t}\n", "prefixes": [ "libcamera-devel" ] }