From patchwork Fri Aug 23 22:04:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov via B4 Relay X-Patchwork-Id: 13776071 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49A341C871E; Fri, 23 Aug 2024 22:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724450719; cv=none; b=gOaMzfguEHb8/eOnGYmcq5OF/slfR7ck3S6EqbSAa7kImDt4TXaLAF6QZHoNoJux+blRx8PmvMsV9FnrtF06tMy41wZjCgISRx+DPAuxi+UItPYMeJ2wL/fF6qMU+6AGAkPk0qwEJ++82hpuR5cYAamkl2xlNRD7eXGkk+c428s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724450719; c=relaxed/simple; bh=FlRDgQfR+nrQBOMJFqD/5DmN2P7fAM5/J4RlKSRP3VQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hjfTKi/jF5+EkV9dblFEvX6V20hDd9rmVLg49dqR7qsg5FPIlfPTP+hgTvkzHxDB4h4VFyHUNnfPeQyoHG2tWH7ph/1ObJ0eLQf1NoXZA9yq29ZbhvrdYqZJ4D1FoLofZ7mqpbBCvCuL7pFt2GAHqCNrryTbdSQIYGkPwZqlnVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e3AeK415; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e3AeK415" Received: by smtp.kernel.org (Postfix) with ESMTPS id BA4A9C4AF16; Fri, 23 Aug 2024 22:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724450718; bh=FlRDgQfR+nrQBOMJFqD/5DmN2P7fAM5/J4RlKSRP3VQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=e3AeK41584fI6+xQ7Y9eRW4q7eNJc6nylYsIyHgbwQbdG326mag6wFI94n85TnE6O ep4Yavh8tb2FdUnFl/zyw6umVC5OyEztbVmiW3PafivcqISJz9GwqU9ia1mccsKH9Y CkLp17bHqO+e2C/kkYijbsGNO+sB8+xckwB500t0reGQBgf9MbeUZe+Fg/b9gE4GDB jSSgFE3i7Y8zKjLg2DawP+vEu/rGUbeM6OiNpI8UA5HSKRtZgo9NwWkoQA3lthdbJ+ /HYPtgyizJOmHeO1Lr0PQkGl6bGkmVz0Rrjbq7fTctd2j4jJGMOnquYwFO5cfIApHD gJy2RdOdIvJzQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1256C5321D; Fri, 23 Aug 2024 22:05:18 +0000 (UTC) From: Dmitry Safonov via B4 Relay Date: Fri, 23 Aug 2024 23:04:55 +0100 Subject: [PATCH net-next v4 5/8] selftests/net: Don't forget to close nsfd after switch_save_ns() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-tcp-ao-selftests-upd-6-12-v4-5-05623636fe8c@gmail.com> References: <20240823-tcp-ao-selftests-upd-6-12-v4-0-05623636fe8c@gmail.com> In-Reply-To: <20240823-tcp-ao-selftests-upd-6-12-v4-0-05623636fe8c@gmail.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Mohammad Nassiri , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com> X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1724450716; l=1650; i=0x7f454c46@gmail.com; s=20240410; h=from:subject:message-id; bh=RZZIhByrLVMtPYu4stmuI1j7mLzypnmNTN4/LUHGhUo=; b=U+/ETigXsEiFz8RzDyvc84aF6CU8gl01I8dOANx1OCpIcqj5PdHtpKlXzRtzCcn8bxskrGBJ/ y824EmiKG2VBUtm4o6WjLmLOZdYBF/CSbDbMBHFalxjnPP3yxHSeK8F X-Developer-Key: i=0x7f454c46@gmail.com; a=ed25519; pk=cFSWovqtkx0HrT5O9jFCEC/Cef4DY8a2FPeqP4THeZQ= X-Endpoint-Received: by B4 Relay for 0x7f454c46@gmail.com/20240410 with auth_id=152 X-Original-From: Dmitry Safonov <0x7f454c46@gmail.com> Reply-To: 0x7f454c46@gmail.com X-Patchwork-Delegate: kuba@kernel.org From: Dmitry Safonov <0x7f454c46@gmail.com> The switch_save_ns() helper suppose to help switching to another namespace for some action and to return back to original namespace. The fd should be closed. Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com> --- tools/testing/selftests/net/tcp_ao/lib/setup.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/tcp_ao/lib/setup.c b/tools/testing/selftests/net/tcp_ao/lib/setup.c index d5212ffe9489..86a4f6e20450 100644 --- a/tools/testing/selftests/net/tcp_ao/lib/setup.c +++ b/tools/testing/selftests/net/tcp_ao/lib/setup.c @@ -142,6 +142,13 @@ int switch_save_ns(int new_ns) return ret; } +void switch_close_ns(int fd) +{ + if (setns(fd, CLONE_NEWNET)) + test_error("setns()"); + close(fd); +} + static int nsfd_outside = -1; static int nsfd_parent = -1; static int nsfd_child = -1; @@ -296,7 +303,7 @@ static bool is_optmem_namespaced(void) int old_ns = switch_save_ns(nsfd_child); optmem_ns = !access(optmem_file, F_OK); - switch_ns(old_ns); + switch_close_ns(old_ns); } return !!optmem_ns; } @@ -317,7 +324,7 @@ size_t test_get_optmem(void) test_error("can't read from %s", optmem_file); fclose(foptmem); if (!is_optmem_namespaced()) - switch_ns(old_ns); + switch_close_ns(old_ns); return ret; } @@ -339,7 +346,7 @@ static void __test_set_optmem(size_t new, size_t *old) test_error("can't write %zu to %s", new, optmem_file); fclose(foptmem); if (!is_optmem_namespaced()) - switch_ns(old_ns); + switch_close_ns(old_ns); } static void test_revert_optmem(void)