Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1696834lqm; Fri, 3 May 2024 04:01:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVCJzfach3h2WLKVOZ2Xs7ACcMP1c9Lj9kjbjyXvLEJ7+vWHZnV6arONVVrKzfgwxpzaEBggd3C2cqWcuqUi6vgRkSbT4xSuM75w08OVQ== X-Google-Smtp-Source: AGHT+IEzrqCWPCl2QqfQysloBmzrXxPhgZKT9hwcO/h5fmjZkX8PIBWRQcbFZql6ZLDoY10GZWAT X-Received: by 2002:a05:6a21:3a4b:b0:1af:36df:5159 with SMTP id zu11-20020a056a213a4b00b001af36df5159mr2389842pzb.59.1714734118501; Fri, 03 May 2024 04:01:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714734118; cv=pass; d=google.com; s=arc-20160816; b=RXmCfmFZw9NR8kWbgAXX2iCH1CrEIi7kV8GHGzx+WQrDfHrWn1W0Sc4alZ+wNgbVUO BoBf6iRySJY7sHd27ZSQQ/r5UbkBxdMS3o+qv3Wfm2/Kvoxj34SHeEsNvqtAQ1P8YGmg YyUMlcXpSRLe+/x3bc4AH653oFNbISqAsvFT0orLhSuQ2PbbrSUqgLoUQHXJvYBRA3qb B9TXpP+NdEOTSs9ig92/klkTQnC6ObB9cjqtwZHizouFm4y4dr2s/Fajm5yn/gc7e5n6 pIG2/6rRPmmaPXdNlMK4I0whLUOrxR0rRX2DwiR9vTPjkV9bDa01Q1Ik1kFm07eoGlyK FC4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uq2gq9sb+f37oshOAwR0UBxaPxe2WMkAuES11PyajaY=; fh=siSkyeuTkzLUvvmYOCEsHOQyZbylO5CVG0oIjh590fE=; b=teFJU2NokhTE3X0NUuCfv0fwmbhIJz3y6jr98XXsGKPoOAUEZ47nqQ0Adn+B+n/ZKA AwjCYfxj+6DTbzbvE150b5Py0sdQqOZAaovbopJ+oI4c9Rhyx2DZ1JHHoCXuxhBJbjVV egIw3w84cEoldB69GE6jdW9hRidkg5iJpW0TQta79msNhaZFFeCfjslQggrOF6iMXx37 MbqBljKjVB/c5jJz4KVsyjZHhQS+EATpZpWW3MTbXIjZ1B6C2VA2dMeAzQXFiE/2F0hV mgm/BKL6WJjEmRn3JCxlBPpVL6ozJGA6t8FG4IIiGsnewM5UaDumD3sE/PHRuO8paj6A dE2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=qkc6ln92; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-167556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167556-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id cp17-20020a17090afb9100b002b2880464efsi5158431pjb.107.2024.05.03.04.01.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 04:01:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=qkc6ln92; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-167556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167556-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 873C0B21753 for ; Fri, 3 May 2024 11:01:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A80515539B; Fri, 3 May 2024 10:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="qkc6ln92" Received: from smtp-1909.mail.infomaniak.ch (smtp-1909.mail.infomaniak.ch [185.125.25.9]) (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 95865153BEC for ; Fri, 3 May 2024 10:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.25.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714733925; cv=none; b=blS4xT9lE6gnzBqGEIkZ+ABFex9HVoo1s+zcB/fK+Cibrv41ZiJT3GzvyyWOHtbqBaWZA2LFU3Fqfjm3PhYpJfr/gJydMl0qGd5Mlg6FZLD1MEcGbGKWB+fVhv9KYAxjZKB0vrpXNCIBWwZn87OCiZ2GNSPpBozXHJOTeRhJE0U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714733925; c=relaxed/simple; bh=BIt36l2FjR1gUySHM36X1f9Iu+hPWXA/lkNOx4MEpHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GFwUED9VMKdUFKFVTw8mInXYn/kJMT+fEZcVlqmo1vwdK8dPHeeez3RzxWTYz7MnjZdOmEbVQbRkLqleEDtc8A/9VL/S7VFhdmrZy2hdqKF/ZMwb1YlQbIbl4n/dMG05Fdz+j02BDIn6KlXtL8ij7YpTAzghVFLFas5waaFTApE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=qkc6ln92; arc=none smtp.client-ip=185.125.25.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VW78C2WfFz9wx; Fri, 3 May 2024 12:58:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1714733915; bh=BIt36l2FjR1gUySHM36X1f9Iu+hPWXA/lkNOx4MEpHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qkc6ln92mSHUeuzi8Fimn+OGoLCxBllwH6wC6oX+yyWhITCxj44XyJ8it83Cc/NJl II4R6ohGeN89pUtBv8KQooopouhQEAS90q+mZy5oWHx1qOrlG5kUYHlqe3+40CrWch KZIvEQPL9r4jIs3eCx3i8E4TR6uwp5uVX9JddsaE= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4VW78B5mtdzjfK; Fri, 3 May 2024 12:58:34 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Christian Brauner , Jakub Kicinski , Kees Cook , Mark Brown , Sean Christopherson , Shengyu Li , Shuah Khan Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , "David S . Miller" , =?UTF-8?q?G=C3=BCnther=20Noack?= , Will Drewry , kernel test robot , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v5 04/10] selftests/harness: Fix interleaved scheduling leading to race conditions Date: Fri, 3 May 2024 12:58:14 +0200 Message-ID: <20240503105820.300927-5-mic@digikod.net> In-Reply-To: <20240503105820.300927-1-mic@digikod.net> References: <20240503105820.300927-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha Fix a race condition when running several FIXTURE_TEARDOWN() managing the same resource. This fixes a race condition in the Landlock file system tests when creating or unmounting the same directory. Using clone3() with CLONE_VFORK guarantees that the child and grandchild test processes are sequentially scheduled. This is implemented with a new clone3_vfork() helper replacing the fork() call. This avoids triggering this error in __wait_for_test(): Test ended in some other way [127] Cc: Christian Brauner Cc: David S. Miller Cc: Günther Noack Cc: Jakub Kicinski Cc: Mark Brown Cc: Shuah Khan Cc: Will Drewry Fixes: 41cca0542d7c ("selftests/harness: Fix TEST_F()'s vfork handling") Reviewed-by: Kees Cook Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240503105820.300927-5-mic@digikod.net --- Changes since v2: * Replace __attribute__((__unused__)) with inline for clone3_vfork() (suggested by Kees and Jakub) --- tools/testing/selftests/kselftest_harness.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 55699a762c45..9d7178a71c2c 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include "kselftest.h" @@ -80,6 +82,17 @@ # define TH_LOG_ENABLED 1 #endif +/* Wait for the child process to end but without sharing memory mapping. */ +static inline pid_t clone3_vfork(void) +{ + struct clone_args args = { + .flags = CLONE_VFORK, + .exit_signal = SIGCHLD, + }; + + return syscall(__NR_clone3, &args, sizeof(args)); +} + /** * TH_LOG() * @@ -1183,7 +1196,7 @@ void __run_test(struct __fixture_metadata *f, fflush(stdout); fflush(stderr); - t->pid = fork(); + t->pid = clone3_vfork(); if (t->pid < 0) { ksft_print_msg("ERROR SPAWNING TEST CHILD\n"); t->exit_code = KSFT_FAIL; -- 2.45.0