From patchwork Fri May 5 16:13:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias Naur X-Patchwork-Id: 18604 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ADE2CC0DA4 for ; Fri, 5 May 2023 16:14:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E3C4C633AC; Fri, 5 May 2023 18:14:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1683303240; bh=t6loezZenFIPDvk0hRSgEhn0+HGR6QhGcUvVgfi8Uf4=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gWfPkOLNg3fa9OCC/Mvq1QASI1+8LN95nFPb7QzgxXWqAOF5SE8kbmN44CVSlBVjF bkqC8eT10P9nbBjDsr7ch/O1F/hiZc2SUhQThbbFjEhaxlj9BdbQPR97lOkWPqvrbD Ul5qNR/WGKt1gbVMX2yLiPN5hztB5tU1yxSCB9fwJDECrcT+68fMoHc5YiYhHv4Q+i L2qZ2f9d1IhGTlE67AOK2YDoNSN+4YCRhgWEdGXQf8UdELkc+gfyB2XAtNnleUFtDq f4rR2S91gw6CpxovypW837TU7xq1fojua17FhX0+taHclr6sqLVhMIt6xm8UAxQzsD Bef9pM3VkFZ2Q== Received: from mail-vk1-xa30.google.com (mail-vk1-xa30.google.com [IPv6:2607:f8b0:4864:20::a30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C7E7627DE for ; Fri, 5 May 2023 18:13:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=eliasnaur.com header.i=@eliasnaur.com header.b="3e9xcDFO"; dkim-atps=neutral Received: by mail-vk1-xa30.google.com with SMTP id 71dfb90a1353d-44fa585ad7aso1326950e0c.0 for ; Fri, 05 May 2023 09:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eliasnaur.com; s=google; t=1683303238; x=1685895238; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9HwkdLlw9lfRIaJCD+YUSn7bFlXyiKUB17HVmyD4MZ4=; b=3e9xcDFO3OyqpF3RjcRU4KcIePDjEm6AVeJF3dSFO/rqdpjSEZK+VLDcIz1KrlCjyQ Wa9tzJ1MkIEg4CBKwD9iEjSXTGkiYE5GLAy4Z9Bzf9CXjsV03kuMklxP4OcG+/LsfM/f vA5+l+TTi1+eQwdTLMzEtb++QZJvbLs4g/H/ijCS5ZGA5yyZO05eIW6NDL9yZYztGESu r8ABNXsHa+wOjP7Ta6gOxl+hsY8dFIoxRXAwZ4o+jPjx5SAnYizFFT9/SlM2dk9HZi8f doJjBiwk/g6y3maVQXG4vZTWIN5q99gVaVA8fdgVe7m8+ouRdVwhWagBXFZok+vPlb5K Y7dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683303238; x=1685895238; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9HwkdLlw9lfRIaJCD+YUSn7bFlXyiKUB17HVmyD4MZ4=; b=j3Wxt5ig0o33/h/byYmHenVID3gpkP8dvwiYs9OKW5s1OfKY/VnWnXsRLR0NoN7Nl6 cUHo3Fw+VOvylgoNyszmaqUSWLwbuLCyEmLkZVU4bbo7sgXyaeFtp4fgwKkwWkgXGohn GMacpKMlWAE5fC7bMOQvFqmnJL10JClDmV+/xuaSNOjU7IUOtgnufTT1f8OQRX7aSuzt TN9LONzHKGAUI8NDgf1KbPhtPoO0V/sssgI+B1DkPtn2VATvHWkuxALjbnezfshxPGAV JNlNrCdLDwPyP3tdMrIE80DKnomiFqLBTx3PvjCzioTfBDHO8pdzLEzua9r6nSGu92UR osyQ== X-Gm-Message-State: AC+VfDyevUWxnUflPMK59sAS4Fhf641o9l/CG+1Sig8/eRXeq6XWpRL+ MpYJA0vP0r5N5qkDzRx6dHLOiitufj8ZyWCpBns= X-Google-Smtp-Source: ACHHUZ6AJs8kZFHnxiGd7enR6j1bbS6pidi819ChHiTjj9G/aKcJj+FRHTO9rUiu8kAZNCKCbaiyyQ== X-Received: by 2002:a1f:4b04:0:b0:440:d7:da79 with SMTP id y4-20020a1f4b04000000b0044000d7da79mr686143vka.2.1683303237901; Fri, 05 May 2023 09:13:57 -0700 (PDT) Received: from localhost.localdomain ([190.53.13.8]) by smtp.gmail.com with ESMTPSA id p68-20020a1f2947000000b00440186078d6sm28599vkp.50.2023.05.05.09.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 09:13:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 5 May 2023 10:13:46 -0600 Message-Id: <20230505161346.25489-1-mail@eliasnaur.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: v4l2_videodevice: Use O_CLOEXEC when exporting DMA buffers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Elias Naur via libcamera-devel From: Elias Naur Reply-To: Elias Naur Cc: Elias Naur Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Files opened internally in libcamera without the O_CLOEXEC file will remain open upon a call to one of the exec(3) functions. As exec() doesn't destroy local or global objects, this can lead to various side effects. Avoid this by opening file descriptors with O_CLOEXEC for all internal files. The O_CLOEXEC flag should also be set when obtaining file handles from the V4L2 VIDIOC_EXPBUF operation, but was missed during the updates to both d942bdc913c5 ("libcamera: v4l2_device: openat(2) with O_CLOEXEC to cleanup after exec(3)") and 436b38fd89fe ("libcamera: Open files with O_CLOEXEC"). Set the O_CLOEXEC flag on calls to ioctl(VIDIOC_EXPBUF). Fixes: 436b38fd89fe ("libcamera: Open files with O_CLOEXEC") Signed-off-by: Elias Naur Reviewed-by: Kieran Bingham --- Updated commit message as suggested by Kieran (thanks!). src/libcamera/v4l2_videodevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 1051997e..a72ef64d 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1471,7 +1471,7 @@ UniqueFD V4L2VideoDevice::exportDmabufFd(unsigned int index, expbuf.type = bufferType_; expbuf.index = index; expbuf.plane = plane; - expbuf.flags = O_RDWR; + expbuf.flags = O_CLOEXEC | O_RDWR; ret = ioctl(VIDIOC_EXPBUF, &expbuf); if (ret < 0) {