From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 91A3E5A026F for ; Wed, 21 Jun 2023 05:06:45 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Qm7h14rssz4x09; Wed, 21 Jun 2023 13:06:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1687316801; bh=pD3eTxeBjYbE4gA4+aii8bbNC7qK6S8CL4MM53J0TfA=; h=From:To:Cc:Subject:Date:From; b=ThEmI9Y5A5b+qK7tYabeWalWnvY3an4LYhnZziV1aJRDSXPCDKxiloFBTzEBNpwVA tCZjxkdzHO8naZ0ZWMtNSteidIK7iRt1sre1CMxkvOpKDzaZn7NbpTRST/QJRx5n6+ LWyigZxy+StbBY+7zeHAQhZXYHl1SKoeuzGEjJ+Y= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH] seccomp: Make seccomp.sh re-entrancy safe Date: Wed, 21 Jun 2023 13:06:37 +1000 Message-ID: <20230621030637.640272-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: OQ32TSUGMCHNBZWKF4ZCGR2TFRHDRATI X-Message-ID-Hash: OQ32TSUGMCHNBZWKF4ZCGR2TFRHDRATI X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: seccomp.sh generates seccomp.h piece by piece using >> directives. This means that if two instances of seccomp.h are run concurrently a corrupted version of seccomp.h will be generated. Amongst other problems this can cause spurious failures on clang-tidy. Alter seccomp.sh to build the output in a temporary file and atomic move it to seccomp.h, so concurrent invocations will still result in valud output. Signed-off-by: David Gibson --- seccomp.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/seccomp.sh b/seccomp.sh index 092c24e0..e1224e0d 100755 --- a/seccomp.sh +++ b/seccomp.sh @@ -15,7 +15,7 @@ TMP="$(mktemp)" IN="$@" -OUT="seccomp.h" +OUT="$(mktemp)" [ -z "${ARCH}" ] && ARCH="$(uname -m)" [ -z "${CC}" ] && CC="cc" @@ -53,7 +53,7 @@ BST=' BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, @NR@, @R@, @L@),' # cleanup() - Remove temporary file if it exists cleanup() { - rm -f "${TMP}" + rm -f "${TMP}" "${OUT}" } trap "cleanup" EXIT @@ -254,3 +254,5 @@ for __p in ${__profiles}; do gen_profile "${__p}" ${__calls} done + +mv "${OUT}" seccomp.h -- 2.41.0