From patchwork Tue Jul 30 23:27:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20722 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 39F2CC323E for ; Tue, 30 Jul 2024 23:27:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BBCAB63377; Wed, 31 Jul 2024 01:27:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DUmlP148"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6D31E61984 for ; Wed, 31 Jul 2024 01:27:32 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 966796EF for ; Wed, 31 Jul 2024 01:26:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1722382004; bh=W51WlWVDdlpUexfgjY7CBoQOL0kaXN0ViCbnD43c4Y0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DUmlP148aknBJs/g7whn0zhQCRdPas63ElRd6VaGnLHZV54wOSWUiVivbqAU3+Wwf MYsEaeo8VVq04/FahmcqVfR2ERkgmQRs/hIOe2DkrLrNM95XWIEhJQwwK6Qx9GG+hD 6PpN38SE39HDVOaINsqNgrYgVR0nxQrtXZ+V9Ego= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from shrinking or growing Date: Wed, 31 Jul 2024 02:27:07 +0300 Message-ID: <20240730232708.17399-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240730232708.17399-1-laurent.pinchart@ideasonboard.com> References: <20240730232708.17399-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The memfd underlying the SharedMem object must not shrink, or memory corruption will happen. Prevent this by setting the shrink seal on the file. As there's no valid use case for growing the memory either, set the grow seal as well. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Kieran Bingham --- src/libcamera/shared_mem_object.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp index 022645e71a35..d4c7991ad16a 100644 --- a/src/libcamera/shared_mem_object.cpp +++ b/src/libcamera/shared_mem_object.cpp @@ -58,7 +58,8 @@ SharedMem::SharedMem() = default; */ SharedMem::SharedMem(const std::string &name, std::size_t size) { - UniqueFD memfd = MemFd::create(name.c_str(), size); + UniqueFD memfd = MemFd::create(name.c_str(), size, MemFd::Seal::Shrink | + MemFd::Seal::Grow); if (!memfd.isValid()) return;