Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1468859lqa; Mon, 29 Apr 2024 09:15:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFu7+zW1aTYgPUx51FiX4yx2s4TpfGu0VV9Gt4biWgTed4V6R/vBz32hkG492APj/kz6VQd7vgvEeORJD0VAQk/jSlZrJhRmy7qq7Vgg== X-Google-Smtp-Source: AGHT+IGpRpJQtlU0J6Gl6RKAQ7dI99IbNxJyORvsIZetC89HRVli4aB0tQQ4h859eLdea0e8u/bH X-Received: by 2002:a05:6a20:f392:b0:1ad:6874:497d with SMTP id qr18-20020a056a20f39200b001ad6874497dmr152111pzb.17.1714407322551; Mon, 29 Apr 2024 09:15:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714407322; cv=pass; d=google.com; s=arc-20160816; b=WTu0/Zhl1qlAGrkukmWXsxogyH7KGLKW/zxMl44R9CZQVkyV+dLWRdSJ4NrUZZYIu6 Vm+TkXuR4hp+cfGuk8E3ndaSyN2uP/iod7sYiAt6bkFlaBFYLnl/oWMidKZ9zsKS6sdx l41d8MUseevZgd47PH4J37E+8xPG8GixMPx9yeM/V1+iVTq1y4sETCkV3KryBqkTZQwn xCc55zeMbU1HbyPA0Ix22Y+9diriJSpTDO1t4a4q0vxPmS46O9X98osvK5IH9s9fC57v jQCdQrWink5EhzNDOBCXSDEij6U8mIP4yJZNWcnCkn4lnR7emMSBEDwFXJ8UnwUGhjGW FtPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gima1jfCICeyQJgLxFU9qZsAD6bEvLHMP34ZgzB6Ps0=; fh=h3DlY72cttnrRo05+Wg/iCIJrd7u2UIxXh/XMCt1T2A=; b=xE40RpYtA0AvpBPQ57aPsqZGR5dM/qVSEWY+uz/ys1ojCo8Eapr4c+g60Ow+su/MJw iBCuJ0Fwgjx+XMmjjnuUg9Ulten/eMfMUl0lleFvDgARmArWmmM7k2bVdhyKr/HC3NLZ I7HcIt9uoT2z1B47okRg26DFrE1YDJm0LcVsPRSewwujgFYV8JuO7gVsWehy7SScoyz0 lFefGzdtKcwLwBYCZeO7BhSxhfEGKRSWRr7UHNpHu+Su/1Jfss0gcHFqzOE9M9uHT4M7 LqwvvPY2EODkxZAIcIo0cKXLUW5392xymJRXGvuu+vutyPEb5RchK0ZzcTQBRMwTIXkc yPNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V6RmxZrh; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-162620-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 bv67-20020a632e46000000b005e438e94d35si19689536pgb.2.2024.04.29.09.15.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 09:15:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162620-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=@chromium.org header.s=google header.b=V6RmxZrh; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-162620-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 E70E8B22F8F for ; Mon, 29 Apr 2024 15:52:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72B1782D69; Mon, 29 Apr 2024 15:52:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V6RmxZrh" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 526BD82883 for ; Mon, 29 Apr 2024 15:52:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714405959; cv=none; b=C7lqYQcG4az8LmA4oeBsd1dkW20aSqRIm4blTHipmOP73rOXgtzYueKO6wEzxiJoCVGwS4tWMfzBotWOLQ3oC0bFJLhCVYem4C9QYSM3pnbdm57MmHWPKHeJCP3t18LOKb9BCpyTJ13UbAaiHQdbPKkcvj37rGkEIIxgRldvn2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714405959; c=relaxed/simple; bh=ZGroGLVCIbK/w2kt3vda3NvOtFQm8DNYiuqe1a85j7c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RLSZ8hVr2MZUEkuICPgyrRY/dLFz4Z51BMvUsE1EMA0BaH+rdd0HYRy5V2h4y3/a1CUMEezGgsA4pbEqhS3lTksEevmNiDLxf2kUCm0xQJEq2cj22M/G7/Wg/7apc8+nu+LnpkefIHiUaEjZ3lMBjTASnpWKmlrnHvnChPz56BY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=V6RmxZrh; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6ee12766586so3474481b3a.0 for ; Mon, 29 Apr 2024 08:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714405957; x=1715010757; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=gima1jfCICeyQJgLxFU9qZsAD6bEvLHMP34ZgzB6Ps0=; b=V6RmxZrhZWKzVig5HYsP2yF9HZMG45HYF7j3aS1InQHCmcJUL34YQcHolJIS/ddpmn FUMOlIRq81A8Pi4fnjNglddQRmZi0GdYVLQ6QQqis3bOGEyBQvGc8hzDEsQu+qkuVHjn 3n0AEFHhLLzMkQT3kzRQHa9qx08kD3VFy5Svk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714405957; x=1715010757; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gima1jfCICeyQJgLxFU9qZsAD6bEvLHMP34ZgzB6Ps0=; b=oR3Wz0GJGmsY5JiS+7eRDmiT3RdKrI2l7iMRK424BG3zA4fu3GrhbkZ1BUOIq4J1cX 6HhjtOVuki8qPUlZecgbP1jpbl7QhJUVwbBrGoAreAPGxquuIvR1FhJNvAzb2oVyPq7C +Jo5xS6qP5dJt9W8yspJt1lX+QHi2IUkoTNEJDNJY2kjeAnLdxT8c4kbdXczUsVRqKEH RWebp4JyBZyJXN3gk1bqzz1wuCplyoV7Kytj7I4vJZihUkv6Vk+2QGyt7nVh/dwFijQi 6OvDUuqt25Br2vMUoMRVUTdYRyAY3ZhMA3XQrTxgwvTL4y26cP+jOx5l5r0clkhYgxKz NyOw== X-Forwarded-Encrypted: i=1; AJvYcCUu+NYXuVrT/KyTvHLvdH2wo2RWcGSNLtTQAtEV00Gh8AWineWOFNAZPjMb1LiwZ2MalVfEDa0NP+r5ti6tmcXUZQ8u0U0MaQou+G+I X-Gm-Message-State: AOJu0YzFh6bbQkQ/HfDDYcZ46dpra4WtZhn+Qfz9yfBa6YBcJTKMiCyA rYqxf3WNtVsVEka9Xyb5Wm75jYgKIlyIOghMTMVsB4xWGB6pIcoP1dAuJ0Higg== X-Received: by 2002:a05:6a00:4b10:b0:6ed:21d5:fbdb with SMTP id kq16-20020a056a004b1000b006ed21d5fbdbmr63495pfb.8.1714405957544; Mon, 29 Apr 2024 08:52:37 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id fb22-20020a056a002d9600b006eceaccaec9sm19364854pfb.131.2024.04.29.08.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 08:52:36 -0700 (PDT) Date: Mon, 29 Apr 2024 08:52:36 -0700 From: Kees Cook To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: Christian Brauner , Jakub Kicinski , Mark Brown , Shengyu Li , Shuah Khan , "David S . Miller" , =?iso-8859-1?Q?G=FCnther?= Noack , Will Drewry , kernel test robot , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 4/9] selftests/harness: Fix interleaved scheduling leading to race conditions Message-ID: <202404290852.C327596A@keescook> References: <20240429130931.2394118-1-mic@digikod.net> <20240429130931.2394118-5-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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240429130931.2394118-5-mic@digikod.net> On Mon, Apr 29, 2024 at 03:09:26PM +0200, Micka?l Sala?n wrote: > 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: Kees Cook > Cc: Mark Brown > Cc: Shuah Khan > Cc: Will Drewry > Fixes: 41cca0542d7c ("selftests/harness: Fix TEST_F()'s vfork handling") > Signed-off-by: Micka?l Sala?n > Link: https://lore.kernel.org/r/20240429130931.2394118-5-mic@digikod.net > --- > 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..9f04638707ae 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 pid_t __attribute__((__unused__)) clone3_vfork(void) Why "unused"? > +{ > + 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; Regardless, yup, looks good. Reviewed-by: Kees Cook -- Kees Cook