Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5072393ybc; Fri, 15 Nov 2019 14:21:42 -0800 (PST) X-Google-Smtp-Source: APXvYqzplfM/fJhXi95MBHVk4X3qqEOBCn7/ctE1Whuis8u/lrGsio5C6ZiOVqd/Bf/QgIrhCEtW X-Received: by 2002:a17:906:6a8e:: with SMTP id p14mr4346984ejr.137.1573856502605; Fri, 15 Nov 2019 14:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573856502; cv=none; d=google.com; s=arc-20160816; b=IizXqQOsZSkb21kTfsJVUqj0708UTXJZeiKHeyu5ce+OxRosZbTmfEFH3F4YACAH5g WhOipGiNRQ/lOGDq/9oiZSTVTxlIlTw6fkYQfYtEzm2gFctMU8rZZO2F5/kgFTSP/Y0w joFWFJAeBRnGD/y03lQc4K+vQ0Nmrqxy/VsYGDuq54F4CB+237Ha5kWn5cBS6Cmj3Zfd sjgRC98ajJEqtnM/8BnmC0jBvuM9j0uQd3U00bLOB1nT1jmNyusABEnZjQDluWvoV01A ed3IzIyBqX3TiK9QerTGmwnpfXCxh06hFx8pmJtbOwpaLOrzPka3Es/bSGMIdM0+jFq6 VtTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=oVyJpir/VLUEMttgrpMJ1qWScwdPhvyUGo9A2jE2/Wc=; b=Zmbe5Wm/2T5mmUm5DWFfrt1dutKsJJu18Rx0SChPEEFSCWQ7COw9/Vs6fwfY5R4oFA VnnvVHN+BRUsiV1PfnN+6E8CUEPRpU+ypfr9GiE+rZxX8YgiOiRgCWu2HiaXXOntL0SL kdbyn9P7acmkk0RWnZF5tUhUxYxXT5rYFjbWPNiPvUaqg1GB0bUNaoRhNngxfXK2b9dL GzmmNgxC+KFYDsX55R61TLVbOG8gd8ENWDFZmQMFpPevG7+MtN9lRZHxK11UIPOU6hlO HloKCYK231vzK6l+H/Z4GsJfbwHEXkPVQ4rH6S9A0jCVp2khz6WrJlEECOugTlJFwEde zRnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TnklFHyJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2si7435610eda.339.2019.11.15.14.21.17; Fri, 15 Nov 2019 14:21:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TnklFHyJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbfKOWUW (ORCPT + 99 others); Fri, 15 Nov 2019 17:20:22 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40441 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbfKOWUW (ORCPT ); Fri, 15 Nov 2019 17:20:22 -0500 Received: by mail-pg1-f195.google.com with SMTP id 15so6611651pgt.7 for ; Fri, 15 Nov 2019 14:20:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=oVyJpir/VLUEMttgrpMJ1qWScwdPhvyUGo9A2jE2/Wc=; b=TnklFHyJy57V8i737k8NzApU3WrqLAzuuyE/BBO1+iLl6KxeQJxRlh8bdXfZOAuFWj DoFbUH5nqWpRYj2/qbxGZH6gEd0SSaANDwjGcTDdhHs2OuZH4pTDVjT5cFtYVIWecA36 A05bGbZEE1cS9CVojaweW0HVIO3T5RmzdaKk82fhB94NV0rHI8DzBfXfgJcxWUyeUFaZ aMSBCqyMcb+wcIzgYRHgN+7Upsd9XdKs7CaY2lKttrgsAQJ2C2Nx+i8sfdpoAc3AScgw ERZQo41dg3HFXbDlGTfdW3WSGIUQ2Y9HVEIiVouBAzOWvE4fvhkSPVinARcuYkRCrNEm +LyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=oVyJpir/VLUEMttgrpMJ1qWScwdPhvyUGo9A2jE2/Wc=; b=lMS3NcLkBFg+qT2wpE6zsTCsKnzXSQWqdOlyWq4VJrjeIUpLw60ZDqpRLLBw0iiniQ x0StG9YoCFzFxZwA+oT++xhRmojO7z3uKwbAFBk2Ai3bzSuhLJfi1BafqZFAjOKsdTiG vY8L9CJHR7ts2I62WBXdu2CoWEBm/3t9U/CxY0XpnwLHI5gw1v7reSegu03Owmi1oUNC S3p2djfn5kEWkFBc5dFciex7tEKjq2pe0P7jDBpLj5mDHo7tiksiy3aK670oND/I2si+ h1f9eYIrF5GkGCCg3vxBjdgZTfpIMl3ITK1yL955SglrOu2XXxsv22ANhpeojs7nTTCh YKmw== X-Gm-Message-State: APjAAAV/ipCX+zHnLbKzS7rzxxvuhdYI4DEMC8TeAHwMW/oRP5pbhHdT Coo4mMJtpdvm3M3kKJCZoY4= X-Received: by 2002:a63:535c:: with SMTP id t28mr6117263pgl.173.1573856421040; Fri, 15 Nov 2019 14:20:21 -0800 (PST) Received: from gmail.com ([2620:0:1009:fd00:e14f:8808:551a:63ec]) by smtp.gmail.com with ESMTPSA id r203sm9582595pfr.184.2019.11.15.14.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 14:20:20 -0800 (PST) Date: Fri, 15 Nov 2019 14:20:18 -0800 From: Andrei Vagin To: Adrian Reber Cc: Christian Brauner , Eric Biederman , Pavel Emelyanov , Jann Horn , Oleg Nesterov , Dmitry Safonov <0x7f454c46@gmail.com>, Rasmus Villemoes , linux-kernel@vger.kernel.org, Mike Rapoport , Radostin Stoyanov Subject: Re: [PATCH v11 2/2] selftests: add tests for clone3() with *set_tid Message-ID: <20191115222018.GB353836@gmail.com> References: <20191115123621.142252-1-areber@redhat.com> <20191115123621.142252-2-areber@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <20191115123621.142252-2-areber@redhat.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --17pEHd4RhPHOinZp Content-Type: text/plain; charset=koi8-r Content-Disposition: inline On Fri, Nov 15, 2019 at 01:36:21PM +0100, Adrian Reber wrote: > This tests clone3() with *set_tid to see if all desired PIDs are working > as expected. The tests are trying multiple invalid input parameters as > well as creating processes while specifying a certain PID in multiple > PID namespaces at the same time. > > Additionally this moves common clone3() test code into clone3_selftests.h. > > Signed-off-by: Adrian Reber > --- > v9: > - applied all changes from Christian's review (except using the > NSpid: parsing code from selftests/pidfd/pidfd_fdinfo_test.c) > > v10: > - added even more '\n' and include file fixes (Christian) > > v11: > - added more return code checking at multiple places (Andrei) > - also add set_tid/set_tid_size to internal struct (Andrei) I think we can add a test case to trigger the issue what I found in the previous version of the kernel patch. You can find my version of this test case in the attached patch. nit: we need to flush stdout and stderr buffers before calling the raw clone3 syscall and _exit(). Otherwise, some log messages can be lost and some of them can be printed twice. To trigger this issue, you can run the test and redirect its output to file or pipe: $ ./clone3_set_tid | cat I have attached the patch to address both these problems. It is a draft version and may require some work. Adrian and Christian, it is up to you to decide whether we want to update the current patch or to fix this on top by a separate patch. Thanks, Andrei --17pEHd4RhPHOinZp Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename=patch diff --git a/tools/testing/selftests/clone3/Makefile b/tools/testing/selftests/clone3/Makefile index cf976c732906..a7c7d8d15e1c 100644 --- a/tools/testing/selftests/clone3/Makefile +++ b/tools/testing/selftests/clone3/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS += -g -I../../../../usr/include/ +CFLAGS += -Wall -g -I../../../../usr/include/ TEST_GEN_PROGS := clone3 clone3_clear_sighand clone3_set_tid diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c index 3480e1c46983..ab1df5ce201f 100644 --- a/tools/testing/selftests/clone3/clone3_set_tid.c +++ b/tools/testing/selftests/clone3/clone3_set_tid.c @@ -30,6 +30,12 @@ static int pipe_1[2]; static int pipe_2[2]; +static void flush() +{ + fflush(stdout); + fflush(stderr); +} + static int call_clone3_set_tid(pid_t *set_tid, size_t set_tid_size, int flags, @@ -46,6 +52,7 @@ static int call_clone3_set_tid(pid_t *set_tid, .set_tid_size = set_tid_size, }; + flush(); pid = sys_clone3(&args, sizeof(struct clone_args)); if (pid < 0) { ksft_print_msg("%s - Failed to create new process\n", @@ -83,6 +90,7 @@ static int call_clone3_set_tid(pid_t *set_tid, close(pipe_2[0]); } + flush(); if (set_tid[0] != getpid()) _exit(EXIT_FAILURE); _exit(exit_code); @@ -153,7 +161,7 @@ int main(int argc, char *argv[]) ksft_exit_fail_msg("pipe() failed\n"); ksft_print_header(); - ksft_set_plan(27); + ksft_set_plan(29); f = fopen("/proc/sys/kernel/pid_max", "r"); if (f == NULL) @@ -249,6 +257,7 @@ int main(int argc, char *argv[]) pid = fork(); if (pid == 0) { ksft_print_msg("Child has PID %d\n", getpid()); + flush(); _exit(EXIT_SUCCESS); } if (waitpid(pid, &status, 0) < 0) @@ -283,6 +292,19 @@ int main(int argc, char *argv[]) /* Let's create a PID 1 */ ns_pid = fork(); if (ns_pid == 0) { + set_tid[0] = 43; + set_tid[1] = -1; + /* + * This should fail as there are not enough active PID + * namespaces. Again assuming this is running in the host's + * PID namespace. Not yet nested. + */ + test_clone3_set_tid(set_tid, 2, 0, -EINVAL, 0, 0); + + set_tid[0] = 43; + set_tid[1] = pid; + test_clone3_set_tid(set_tid, 2, 0, 0, 43, 0); + ksft_print_msg("Child in PID namespace has PID %d\n", getpid()); set_tid[0] = 2; test_clone3_set_tid(set_tid, 1, 0, 0, 2, 0); @@ -309,6 +331,8 @@ int main(int argc, char *argv[]) */ test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true); + + flush(); _exit(ksft_cnt.ksft_pass); } --17pEHd4RhPHOinZp--