Patch Detail
Show a patch.
GET /api/1.1/patches/12961/?format=api
{ "id": 12961, "url": "https://patchwork.libcamera.org/api/1.1/patches/12961/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12961/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20210715142130.139675-1-kieran.bingham@ideasonboard.com>", "date": "2021-07-15T14:21:30", "name": "[libcamera-devel] libcamera: v4l2_videodevice: Handle unexpected buffers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7cb9fa63f51c614eaba16dd64e7df5ae3d516cc2", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/1.1/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": { "id": 11, "url": "https://patchwork.libcamera.org/api/1.1/users/11/?format=api", "username": "kbingham", "first_name": "Kieran", "last_name": "Bingham", "email": "kieran.bingham@ideasonboard.com" }, "mbox": "https://patchwork.libcamera.org/patch/12961/mbox/", "series": [ { "id": 2237, "url": "https://patchwork.libcamera.org/api/1.1/series/2237/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2237", "date": "2021-07-15T14:21:30", "name": "[libcamera-devel] libcamera: v4l2_videodevice: Handle unexpected buffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2237/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/12961/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12961/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 D5F7EC3225\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Jul 2021 14:21:36 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4466068525;\n\tThu, 15 Jul 2021 16:21:36 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7615C60282\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Jul 2021 16:21:34 +0200 (CEST)", "from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 807AC340;\n\tThu, 15 Jul 2021 16:21:33 +0200 (CEST)" ], "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=\"K5d9k7fl\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626358893;\n\tbh=Da//xXzy1ueDALPCCoaZjAs2XqjirqYHUcL5luTBAk8=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=K5d9k7fl/UiyeR85HXwZyPuTqERVEz044ynlL1+OinGKJrLJdFuE458b8cNumhios\n\tWGAtcRzanktfUH7XX3ppAA91e1cs0lJDyuokkDeJrWA+iz89YOtuGov1QpFax0HO/Y\n\tNtc/9azYYqFXahMnwK47Z5PTgIiLhK3N6ccHnbAA=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Date": "Thu, 15 Jul 2021 15:21:30 +0100", "Message-Id": "<20210715142130.139675-1-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.30.2", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Handle\n\tunexpected buffers", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "A kernel bug can lead to unexpected buffers being dequeued where we\nhaven't entered the buffer in our queuedBuffers_ list.\n\nThis causes invalid accesses if not handled correctly within libcamera,\nand while it is a kernel issue, we must protect against unpatched\nkernels.\n\nHandle unexpected buffers by returning a nullptr, and move cache\nmanagement after the validation of the buffer.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/v4l2_videodevice.cpp | 21 ++++++++++++++++++++-\n 1 file changed, 20 insertions(+), 1 deletion(-)", "diff": "diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 3d2d99b46e4e..6c7f9daf24db 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1519,9 +1519,28 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \n \tLOG(V4L2, Debug) << \"Dequeuing buffer \" << buf.index;\n \n+\tauto it = queuedBuffers_.find(buf.index);\n+\t/*\n+\t * If the video node fails to stream-on successfully (which can occur\n+\t * when queing a buffer), a vb2 kernel bug can lead to the buffer which\n+\t * returns a failure upon queing, being mistakenely kept in the kernel.\n+\t * This leads to the kernel notifying us that a buffer is available to\n+\t * dequeue, which we have no awareness of being queued, and thus we will\n+\t * not find it in the queuedBuffers_ list.\n+\t *\n+\t * Whilst this is a kernel bug and should be fixed there, ensure that we\n+\t * safely ignore buffers which are unexpected to prevent crashes on\n+\t * unpatched kernels.\n+\t */\n+\tif (it == queuedBuffers_.end()) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Dequeued an unexpected buffer:\" << buf.index;\n+\n+\t\treturn nullptr;\n+\t}\n+\n \tcache_->put(buf.index);\n \n-\tauto it = queuedBuffers_.find(buf.index);\n \tFrameBuffer *buffer = it->second;\n \tqueuedBuffers_.erase(it);\n \n", "prefixes": [ "libcamera-devel" ] }