From patchwork Thu Aug 15 21:32:30 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: 13765196 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 417411547CA; Thu, 15 Aug 2024 21:32:49 +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=1723757570; cv=none; b=kk7Dl0LPMU1PPKrQxunyuE4uRjMPLZiYR2V675+CAmhGFxiS3QVmD/43x1A3e4k5yI//oaw0ruVJZuFNGHb9unPIYvDm9pXqrWV2Nb5OaFpj3q5reojWOWnyjAhnGc0y7xMDKGE9ttBNgMpVQzJxl12CPCg0369aDgmm+WFpeHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723757570; 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=po6h1R3UXw8VYRBCxeqaP8mT7imnP9iE5nXTe3zxs8Xi3ocFEObVcIhgyhz/wePi3ktqjxVuYdFWGf9001KLj8wR1yUGivlheT3srFA7+C4gtZZsCxcYv+/EWXwhG8gzcTGrXhNdKwTvcHgjdM3md385rj23dg6bBMQqAPwlVmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OjEAzRMw; 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="OjEAzRMw" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9CB55C4AF18; Thu, 15 Aug 2024 21:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723757569; bh=FlRDgQfR+nrQBOMJFqD/5DmN2P7fAM5/J4RlKSRP3VQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OjEAzRMwn6gWAXNOSco5mqoqlLJ80+qh5DdvkI8VKXaSqJ4n2VZR9nW7ZzVhamiQC 20NrkqJCE+q10W5toB9os/tX9CFVYmyYFeIjXZn7bLjgAelqHjI226sfDrj8AKQ6vu 9qUpuBgSBE/m0mBbAkrrS+hpXvCqqO5xfshTYEBAUlN386Or0IGkEoCzUjja8MzT8b amCp0bkWckF9GVSv9+x8MH0adsKIlCwk5xtT3a15pXJuqh6qwMnfxLephwERBkuKPu 0Ns2pYjzM+jBfLIshPPGkok7BfWmIf9/G7mIHnCgftC/o/wuRrN7Ig2QvzbehgD6uE wPJ//FZzM9bEQ== 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 9370AC52D7F; Thu, 15 Aug 2024 21:32:49 +0000 (UTC) From: Dmitry Safonov via B4 Relay Date: Thu, 15 Aug 2024 22:32:30 +0100 Subject: [PATCH net-next v3 5/8] selftests/net: Don't forget to close nsfd after switch_save_ns() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240815-tcp-ao-selftests-upd-6-12-v3-5-7bd2e22bb81c@gmail.com> References: <20240815-tcp-ao-selftests-upd-6-12-v3-0-7bd2e22bb81c@gmail.com> In-Reply-To: <20240815-tcp-ao-selftests-upd-6-12-v3-0-7bd2e22bb81c@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=1723757567; l=1650; i=0x7f454c46@gmail.com; s=20240410; h=from:subject:message-id; bh=RZZIhByrLVMtPYu4stmuI1j7mLzypnmNTN4/LUHGhUo=; b=JQVXu0rFLKFN9wQiSOLG1y2WKWLqEEuUfoSIYnWaOAIMdP/n1P8sSdbTOctbwfyDbD+MF22wW 0heHQbaUdgUAPx8apCRX6zH8JTOZnSnDM6zMiYjDVQJYE9iOhpjda+s 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 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)