From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from delorie.com (wally.delorie.com [65.175.133.2]) by sourceware.org (Postfix) with ESMTPS id 70F863858005 for ; Thu, 12 Nov 2020 22:28:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 70F863858005 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=delorie.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=dj@delorie.com Received: from envy.delorie.com (envy [172.31.3.1]) by delorie.com (8.15.2/8.15.2) with ESMTPS id 0ACMRxK0009062 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Thu, 12 Nov 2020 17:28:08 -0500 Received: from envy.delorie.com (localhost [127.0.0.1]) by envy.delorie.com (8.15.2/8.15.2) with ESMTP id 0ACMRxvT009655 for ; Thu, 12 Nov 2020 17:27:59 -0500 Received: (from dj@localhost) by envy.delorie.com (8.15.2/8.15.2/Submit) id 0ACMRxhG009652; Thu, 12 Nov 2020 17:27:59 -0500 Date: Thu, 12 Nov 2020 17:27:59 -0500 Message-Id: <202011122227.0ACMRxhG009652@envy.delorie.com> From: DJ Delorie To: libffi-discuss@sourceware.org Subject: [PATCH] Use memfd_create if available. X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libffi-discuss@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libffi-discuss mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2020 22:28:23 -0000 For cases where selinux et al disallow suitable closures, before we try a disk-backed closure, try a memory-backed closure. diff --git a/configure.ac b/configure.ac index 790274e..093b87d 100644 --- a/configure.ac +++ b/configure.ac @@ -63,6 +63,9 @@ EOF AM_MAINTAINER_MODE +AC_CHECK_HEADERS(sys/memfd.h) +AC_CHECK_FUNCS([memfd_create]) + AC_CHECK_HEADERS(sys/mman.h) AC_CHECK_FUNCS([mmap mkostemp]) AC_FUNC_MMAP_BLACKLIST diff --git a/src/closures.c b/src/closures.c index 4fe6158..dfc2f68 100644 --- a/src/closures.c +++ b/src/closures.c @@ -45,6 +45,9 @@ #include #include +#ifdef HAVE_SYS_MEMFD_H +#include +#endif static const size_t overhead = (sizeof(max_align_t) > sizeof(void *) + sizeof(size_t)) ? @@ -544,6 +547,17 @@ static int execfd = -1; /* The amount of space already allocated from the temporary file. */ static size_t execsize = 0; +#ifdef HAVE_MEMFD_CREATE +/* Open a temporary file name, and immediately unlink it. */ +static int +open_temp_exec_file_memfd (const char *name) +{ + int fd; + fd = memfd_create (name, MFD_CLOEXEC); + return fd; +} +#endif + /* Open a temporary file name, and immediately unlink it. */ static int open_temp_exec_file_name (char *name, int flags) @@ -671,6 +685,9 @@ static struct const char *arg; int repeat; } open_temp_exec_file_opts[] = { +#ifdef HAVE_MEMFD_CREATE + { open_temp_exec_file_memfd, "libffi", 0 }, +#endif { open_temp_exec_file_env, "TMPDIR", 0 }, { open_temp_exec_file_dir, "/tmp", 0 }, { open_temp_exec_file_dir, "/var/tmp", 0 },