From patchwork Fri May 5 16:18:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias Naur X-Patchwork-Id: 18605 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 56AB9BD16B for ; Fri, 5 May 2023 16:18:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD0AA633B5; Fri, 5 May 2023 18:18:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1683303533; bh=L8hY8KfX/qMibdOoUxWMbJ6nUM/V73unTyh0WiCXZuE=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BxT+Z0ecow3GIhBHzDwbseM4Fh2XAV8JaW0G6Lu50K7BC3dRvQt+z19nTWoghg+48 JHbcmS8+85r6iGZEIrDLfeK1Ipn6VJycgqsJ8MIvhMZ6UElIPNK2LjGHUm6zVyjPx8 px3GWDge1lGTDxUXPSr0x9anQuLuAeIxYouduWSmTWihdBTxUxnCZRTqemtYXakgqY dkIVw6Tj4rkD5qP+EIvmQcft9t+psWzf5wJK4lfqc/YlxpjT2uvzdOT4j3aDuInxqq otA4SdKgAEg+cydFSl3bYWQHViUlFelhrXExfiYnWGQXcS5Cy0MHRwHkkhjVDrK0WY +x6CqS+qWvA4Q== Received: from mail-vs1-xe31.google.com (mail-vs1-xe31.google.com [IPv6:2607:f8b0:4864:20::e31]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91851627DE for ; Fri, 5 May 2023 18:18:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=eliasnaur.com header.i=@eliasnaur.com header.b="F+vyfO0n"; dkim-atps=neutral Received: by mail-vs1-xe31.google.com with SMTP id ada2fe7eead31-43483520faaso247773137.0 for ; Fri, 05 May 2023 09:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eliasnaur.com; s=google; t=1683303531; x=1685895531; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Xp2rABvHpmpB1uL0IV5ZRuGGNGvedXtVvn03fu959CE=; b=F+vyfO0nzxgqKZnoj8ap45EZbdgQ4XAb7KMEuRRvoYnMdWUbWy7oy2S4Nez3fVITO+ JFKcqipda37ph5k6Ak/tdoP+DvK/Ca6j5p9pJoBV4YBYBBxTaawDsxSc+9BdZB/k7S1d rVO+ON/obMANAAMbtmMFHMLGvDg+d8cKYRGqA5ItP/JMLKCBtlb0ausOYUQh9GfAWjFy VZ2dRYqm0QYFYLW8Zq85rf9BUMD+1Y+UCk/MSlQ0RZdEcC/fQSrXhzQHj8yP6ZtmCIOx ueJbv5o34iSjGCo5jXeD+Jp9CK8VV4JZnuCVOXiGNVAAIYWTBnnz5GLVTZ+ZpuRGmtaD tHGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683303531; x=1685895531; 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=Xp2rABvHpmpB1uL0IV5ZRuGGNGvedXtVvn03fu959CE=; b=grORbF6pUyi7emKk8NBPSGt8qfAewxeahzIwlqtDshNfgfl496h1FR1vXfP9mpjx36 qOfWQtggmhcGUAbLwIGqjTZYKdqLCtPrdyJGWYkNJA3/iU9xL4jCDTtFks37pm1q9xuZ o6S3vuMQkHctrWI8V0tHCi2B7ARCSbVbNDyOxKdTOmQMHBQ3UqfWORoena2n7rSKrn1c +AyfVVRoE1w1Z36qg7+zul+Ptg7ydJrwwVdFQZFsPJym6WzBfJt6DZMk385DZYqI3qU5 NU1V8papm5rAqFJOutSxSnj0KOAQtbM7m9yGVvZ4cYDNIwaMhjhJUAunegxFxlvYJdK4 R1UQ== X-Gm-Message-State: AC+VfDyK4mBi7RCzOTkEMdDUEZsp0qW5fA6QLGx8Y4hLEalqIjekuT1i GWRMfaAE7TvkDP6LNJMnFsQA62wSAUwGRH+BBtI= X-Google-Smtp-Source: ACHHUZ474XVYpv6OKxCU1uJLSUAtZ1TDWZCcT2vWbyNTT4WbjsB61rlWCckcTbxLhCzevx/1LhGdag== X-Received: by 2002:a05:6102:199:b0:42c:624c:147c with SMTP id r25-20020a056102019900b0042c624c147cmr812321vsq.7.1683303531245; Fri, 05 May 2023 09:18:51 -0700 (PDT) Received: from localhost.localdomain ([190.53.13.8]) by smtp.gmail.com with ESMTPSA id e2-20020ab01102000000b0076ea015dd34sm323303uab.13.2023.05.05.09.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 09:18:50 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 5 May 2023 10:18:43 -0600 Message-Id: <20230505161843.25545-1-mail@eliasnaur.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] 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 Reviewed-by: Laurent Pinchart --- Added Laurent's Reviewed-by that I missed. 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) {