[{"id":15416,"web_url":"https://patchwork.libcamera.org/comment/15416/","msgid":"<YD4vdb+RYMFPCUjG@pendragon.ideasonboard.com>","date":"2021-03-02T12:28:37","subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: Request: validate\n\tstate on complete","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Mar 02, 2021 at 12:23:40PM +0000, Kieran Bingham wrote:\n> Requests should only be completed from the RequestPending state.\n> \n> Requests which are completed from the RequestCancelled, or RequestComplete\n> state, will indicate that a double-complete has been called on the Request,\n> or that it has been used internally after it has been given back to the\n> application.\n> \n> Ensure that this can be caught early if it occurs by enforcing the state\n> required with an assert.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> This issue has been seen while developing the IPA for the IPU3.\n> \n> Requests are completed, and then completed again while closing.\n> It is likely that this occured, where a request was completed, and was\n> then re-used.\n> \n> A use case where the Request was deleted instead of re-used was also\n> seen which caused a segmentation fault instead, due to the use of the\n> memory after free().\n> \n>  src/libcamera/request.cpp | 2 ++\n>  1 file changed, 2 insertions(+)\n> \n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index e561ce1d5d0e..24c3694de5fc 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -262,7 +262,9 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const\n>   */\n>  void Request::complete()\n>  {\n> +\tASSERT(status_ == RequestPending);\n>  \tASSERT(!hasPendingBuffers());\n> +\n>  \tstatus_ = cancelled_ ? RequestCancelled : RequestComplete;\n>  \n>  \tLOG(Request, Debug)","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 C4DD0BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 12:29:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 51DBB68A93;\n\tTue,  2 Mar 2021 13:29:08 +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 858ED68A91\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 13:29:06 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E8A1E45D;\n\tTue,  2 Mar 2021 13:29:05 +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=\"smUsGIha\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1614688146;\n\tbh=Et+ms9h0gZJgi/PiUibZC7RMLn/Oq3ciG/LWX4uk/R4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=smUsGIhabDIx+F45w678fJlOm21mNTt5iMZY0cJxLJfisEaxwLwSF8RFf0zRVhqO/\n\tfSrpFyBRHJ9X2kEcn8BkQJbNjGrHWTlMglzfu2VjZyxjKrTOJx+7sNxpr54p7sdjIz\n\tY/HFUXDCNw9VSaEqnDbm5QbDSL8V4YLYgT20paaw=","Date":"Tue, 2 Mar 2021 14:28:37 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YD4vdb+RYMFPCUjG@pendragon.ideasonboard.com>","References":"<20210302122341.83985-1-kieran.bingham@ideasonboard.com>\n\t<20210302122341.83985-2-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210302122341.83985-2-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: Request: validate\n\tstate on complete","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":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15419,"web_url":"https://patchwork.libcamera.org/comment/15419/","msgid":"<3ad69c20-d63d-44bb-2676-928dc1ce642c@uajain.com>","date":"2021-03-02T12:44:12","subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: Request: validate\n\tstate on complete","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/","name":"Umang Jain","email":"email@uajain.com"},"content":"Hi Kieran\n\nOn 3/2/21 5:53 PM, Kieran Bingham wrote:\n> Requests should only be completed from the RequestPending state.\n>\n> Requests which are completed from the RequestCancelled, or RequestComplete\n> state, will indicate that a double-complete has been called on the Request,\n> or that it has been used internally after it has been given back to the\n> application.\n>\n> Ensure that this can be caught early if it occurs by enforcing the state\n> required with an assert.\n>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Umang Jain <email@uajain.com>\n>\n> ---\n> This issue has been seen while developing the IPA for the IPU3.\n>\n> Requests are completed, and then completed again while closing.\n> It is likely that this occured, where a request was completed, and was\n> then re-used.\n>\n> A use case where the Request was deleted instead of re-used was also\n> seen which caused a segmentation fault instead, due to the use of the\n> memory after free().\n>\n>   src/libcamera/request.cpp | 2 ++\n>   1 file changed, 2 insertions(+)\n>\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index e561ce1d5d0e..24c3694de5fc 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -262,7 +262,9 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const\n>    */\n>   void Request::complete()\n>   {\n> +\tASSERT(status_ == RequestPending);\n>   \tASSERT(!hasPendingBuffers());\n> +\n>   \tstatus_ = cancelled_ ? RequestCancelled : RequestComplete;\n>   \n>   \tLOG(Request, Debug)","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 181C5BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 12:44:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 94CC468A93;\n\tTue,  2 Mar 2021 13:44:19 +0100 (CET)","from mail.uajain.com (static.126.159.217.95.clients.your-server.de\n\t[95.217.159.126])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7CEA168A91\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 13:44:17 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"reiaCe9O\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail;\n\tt=1614689056; bh=danktRGRYx3YLsi/6y1EpuHloCkz3fJfNxtNbcOTMrI=;\n\th=Subject:To:References:From:In-Reply-To;\n\tb=reiaCe9OtKxnHeOaayHYHZzwwfnrUDNvUTcwFNzjye/NGFNKzt+UPSl17kigTdyBV\n\t7bApWyBH2pTRHirTbA7U8Uz2sw0sRoW7qjXNFqBTUrDMP+Z0BH+tEn9JRwNb1oJMxn\n\t2ID1DNm2t9lowu5HV/RGW5Du+A8VhabLmFDKx7qHM8ss2Tycr2EwUJS7MECl6VVKOc\n\tQaiLvlCmsj6C/2hfVpTijlWEevkVGhWDJmIR0Eb8AMPhapP/31dASEJ3JaE17AzGrB\n\tXjYOPvt9NQArAc56EohB0fcXmgG6xUVS+U70PLlKVd3O+byxuqalvKMChnahIaKYmL\n\tPyhspd0BECI6g==","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","References":"<20210302122341.83985-1-kieran.bingham@ideasonboard.com>\n\t<20210302122341.83985-2-kieran.bingham@ideasonboard.com>","From":"Umang Jain <email@uajain.com>","Message-ID":"<3ad69c20-d63d-44bb-2676-928dc1ce642c@uajain.com>","Date":"Tue, 2 Mar 2021 18:14:12 +0530","Mime-Version":"1.0","In-Reply-To":"<20210302122341.83985-2-kieran.bingham@ideasonboard.com>","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: Request: validate\n\tstate on complete","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>","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=\"us-ascii\"; Format=\"flowed\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15497,"web_url":"https://patchwork.libcamera.org/comment/15497/","msgid":"<YEQJvEdVkv20fGrY@oden.dyn.berto.se>","date":"2021-03-06T23:01:16","subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: Request: validate\n\tstate on complete","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Kieran,\n\nThanks for your work.\n\nOn 2021-03-02 12:23:40 +0000, Kieran Bingham wrote:\n> Requests should only be completed from the RequestPending state.\n> \n> Requests which are completed from the RequestCancelled, or RequestComplete\n> state, will indicate that a double-complete has been called on the Request,\n> or that it has been used internally after it has been given back to the\n> application.\n> \n> Ensure that this can be caught early if it occurs by enforcing the state\n> required with an assert.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> \n> ---\n> This issue has been seen while developing the IPA for the IPU3.\n> \n> Requests are completed, and then completed again while closing.\n> It is likely that this occured, where a request was completed, and was\n> then re-used.\n> \n> A use case where the Request was deleted instead of re-used was also\n> seen which caused a segmentation fault instead, due to the use of the\n> memory after free().\n> \n>  src/libcamera/request.cpp | 2 ++\n>  1 file changed, 2 insertions(+)\n> \n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index e561ce1d5d0e..24c3694de5fc 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -262,7 +262,9 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const\n>   */\n>  void Request::complete()\n>  {\n> +\tASSERT(status_ == RequestPending);\n>  \tASSERT(!hasPendingBuffers());\n> +\n>  \tstatus_ = cancelled_ ? RequestCancelled : RequestComplete;\n>  \n>  \tLOG(Request, Debug)\n> -- \n> 2.25.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 2EE4CBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  6 Mar 2021 23:01:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D3B668A92;\n\tSun,  7 Mar 2021 00:01:20 +0100 (CET)","from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com\n\t[IPv6:2a00:1450:4864:20::22a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B2D9B602E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  7 Mar 2021 00:01:18 +0100 (CET)","by mail-lj1-x22a.google.com with SMTP id r25so9792720ljk.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 06 Mar 2021 15:01:18 -0800 (PST)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tx25sm794650lfn.307.2021.03.06.15.01.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 06 Mar 2021 15:01:17 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"f7syKc1T\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=GlPqkIks1eDJyUr2QPSLvyyFX6e8YpqfLyvssv7g3U0=;\n\tb=f7syKc1TvOVgyMXkIXdnKVlFmiHxfiIttjf9cQP+R7PrRqZbhbTK8IPKF7EXGSzhfw\n\tptaPiOMKBtkRDLrEva61lW5pnZww/ro7HXtbdi80CkvC+bwZ98aSZm634Zf6vAl7Xyza\n\tjVQIOZlZ/V54KNumQ2QvS9h9yX2hhlBBrdKgUi4Tl3oBjmZSK4fEqMcmJbC48YC+kAyP\n\tPD+gw0bC8J8yatw0Epo9Fyu+G1GcjInByNuyisRwOnbdooq1YkdYcXJ394OpjRcxC5y9\n\tYXT+7GG26MQoKHaf7TY8Q16wFpnoSWm/o5BD6Lau7C1zdY7bdPeBDkbD8Gfg6kcbTTMd\n\tN81Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=GlPqkIks1eDJyUr2QPSLvyyFX6e8YpqfLyvssv7g3U0=;\n\tb=cm9b9NzrRHrgmQvRaVilNV86O5Ujwy5fwOvqxdVXKHMaDJbmmk8u8MM2WGV4sxjW5b\n\tYxbd2Drh4ygVPp0r/nv/0QI2P9YoivwqOSX6mqFyw1yf86jTPccpnU18oFzyEYAKeKe5\n\t0NEtUWjIH4WXG5kmeZ8tzWuFBOgzwPu7vUVyffpeDcR3QnEp5TwEqbKRa5qbAZJtgWdW\n\tYR6mpQtjBwqN+jYrwmZSpM+GwifeYeDCuu7jvf6vTpWrn1/4qaSuZAlTFInnj/u/hPwB\n\tYpIzbSzZ90XZz1YrxqS1mheIHPpivlj0aYTQJr7fXlk7dwiydXQaiz5qQQ4MydXlC37D\n\taIGg==","X-Gm-Message-State":"AOAM531mJJltz+Mf42DHMEunrE4mx8tfmrWJ444fqgCXa1Ep5yHV0mCR\n\tmxeQw+CEAaq0JfFw7XI6X+3gRg==","X-Google-Smtp-Source":"ABdhPJyIytkes9nFkitnEoNky/xSJn9J7BntErcG09jRL++Vt+VJueXydmWZp/oVHTq5rkh4vqThKQ==","X-Received":"by 2002:a05:651c:54a:: with SMTP id\n\tq10mr9432548ljp.454.1615071677826; \n\tSat, 06 Mar 2021 15:01:17 -0800 (PST)","Date":"Sun, 7 Mar 2021 00:01:16 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YEQJvEdVkv20fGrY@oden.dyn.berto.se>","References":"<20210302122341.83985-1-kieran.bingham@ideasonboard.com>\n\t<20210302122341.83985-2-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210302122341.83985-2-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: Request: validate\n\tstate on complete","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":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]