Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5663487ima; Tue, 5 Feb 2019 16:12:38 -0800 (PST) X-Google-Smtp-Source: AHgI3IaGTHASz0g44mUmK145zFTDaDNpgsVvOYCTtnYkZj/tttQhmye1tOfDzmzXA5bsWfOIZcXu X-Received: by 2002:a62:43c5:: with SMTP id l66mr7694207pfi.207.1549411958762; Tue, 05 Feb 2019 16:12:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549411958; cv=none; d=google.com; s=arc-20160816; b=Xd7piSulwPZnxeEDpMrHYcMAi9pnYoa3QxQlE/9Xw1YKoucQdcfhDO5H8wlhzyoFkA 1RfHsNCotNbJ6x07g1AVT6Ve/zCbqWRWjviXgi6BLxCvK98sOn7V1cpxCzd44Yel7bJw iSpmz2GBH82Pur7WqBaSPY3UMu9k4BmqgHf51yHS3eJ5YLi0HVH7kFY2YqDkiaoebTD4 khl8MGGs9Nr3QVgSq7hVDhxC3cJ+E3NZPU2FvPp+UOB4Rd4JrPEcYTKpHSpRoNGJ+Ai4 2xjNu+vEiNLv/bJBpYlTDNvJN484nSnF4CYab+efVHU8188Xd6g+3lHf4ABbfadytcaH J8DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p6BmnRMTaCdrw1Lw8yJ4Z4epizq8SWVZSx6J4ZEuxXU=; b=Kyg+xjh6hMDtOBnJcIHN2Zq9RQFZXLt5C4Q3k+ZIIlaOe8JXEndnJpuZ9SkMdmTKbq jQc64rEJbZmC+v3MhzZ5iF9PEwvQ/Sjm6dpfSt4CtrqLn3lUJ8mEEP8ElUz4P/A3mlHz Ox8YEUdHS/KdNrAK2PS4p5i4aFzTz9toMLSFr2FkyRGU4nLtwSJd7+mwyiTSFOoz6EFL 0wI/Q8sTDsCSgedcCTIb3TgD8lMMmD13gCh9pVZ6mgtHcgl8Xo63zSosAvnmye0co8+3 HD67v6/NIbwralOCnWYaqT3l1GD5CzN6mgjKMlDXWRCK/QRPpeC/rhq2B9Yzh1CbhqaH RCzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=nyDpSfKM; 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=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si1281317pff.161.2019.02.05.16.12.23; Tue, 05 Feb 2019 16:12:38 -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=@arista.com header.s=googlenew header.b=nyDpSfKM; 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=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729746AbfBFAL6 (ORCPT + 99 others); Tue, 5 Feb 2019 19:11:58 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:40249 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729545AbfBFALw (ORCPT ); Tue, 5 Feb 2019 19:11:52 -0500 Received: by mail-ed1-f67.google.com with SMTP id g22so4471274edr.7 for ; Tue, 05 Feb 2019 16:11:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p6BmnRMTaCdrw1Lw8yJ4Z4epizq8SWVZSx6J4ZEuxXU=; b=nyDpSfKMe8wYcWDH4nEIBXQ3k2ViHmeA7v8Bpet3m0rZZ4UUgZdZjp2O2w9Pxrkwd0 isB0PAfHioeaw3hsFQKcbu/NGJWpil8CO/dqvoLuhxL9CU5R8ZDx4ZA30HQi9VGOK8dZ HsAUuxoudk6B+XjeZgGSkwUaL6LhSp+8ZpBp091EQDM6CoQk9mc2mukILOLShbIBNkev dMWsyFYjRlO+oU9WVyZl/qbZ9mNrBT10l+jCmcw3D+CZHYC72/mIHBySW7MkkOmu/bmm HytgTKuJhhFPxkZN4BiG8fYVFXU2NgrGnp1ZHM4GOQwoFhMHXMBi9AnBq7mRNkn1zoUC rwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p6BmnRMTaCdrw1Lw8yJ4Z4epizq8SWVZSx6J4ZEuxXU=; b=lCRIEoqy/HWsw1d+tTmVd1RKHJp9lXmQnneoQokr7liIDFqMRRV1A/SJKOra5g63sP vFmOlCa6Teh/HVh460o6IBc8y4/XBPYsF4n6q5z2jsfTJkTvLlu+AqmhboRC54AVezdl ZGmig/aohJLF+4z65sT1mJ0rwP72LgS+ezkLMNXx4Ndy7XDVwbn8uP0xBe6tTcWGtFzr ZIk1hzBB9/XNM8DM33HldUjlMdbgiYnc3dIjQR+twOiR6kr/rIMK+PGgX3IT1FSDiZSx 1+oKVlfqdtlPi8rMaSws4zCyAVhlQutKkNS19Cmwrk5adOIFvBy/cHFRBwkpu5R7WFe4 rt1Q== X-Gm-Message-State: AHQUAuY9BDste2UY5LBXbJUrUoaGe/6X1h8AWIp7W6Xoso8VJ2DoD9fU 4PvrDJI/x2SoKdJUIO3o+qXxLkSmoAY= X-Received: by 2002:a50:a741:: with SMTP id h59mr5706133edc.106.1549411909674; Tue, 05 Feb 2019 16:11:49 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id p30sm5489594eda.68.2019.02.05.16.11.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 05 Feb 2019 16:11:49 -0800 (PST) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Andrei Vagin , Dmitry Safonov , Adrian Reber , Andrei Vagin , Andy Lutomirski , Andy Tucker , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , Dmitry Safonov <0x7f454c46@gmail.com>, "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , Thomas Gleixner , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: [PATCH 30/32] selftest/timens: Check that a right vdso is mapped after fork and exec Date: Wed, 6 Feb 2019 00:11:04 +0000 Message-Id: <20190206001107.16488-31-dima@arista.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206001107.16488-1-dima@arista.com> References: <20190206001107.16488-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Vagin Signed-off-by: Andrei Vagin Signed-off-by: Dmitry Safonov --- tools/testing/selftests/timens/.gitignore | 1 + tools/testing/selftests/timens/Makefile | 2 +- tools/testing/selftests/timens/exec.c | 91 +++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timens/exec.c diff --git a/tools/testing/selftests/timens/.gitignore b/tools/testing/selftests/timens/.gitignore index 6bb90fdb4519..b08b4066f5ca 100644 --- a/tools/testing/selftests/timens/.gitignore +++ b/tools/testing/selftests/timens/.gitignore @@ -1,4 +1,5 @@ clock_nanosleep +exec gettime_perf procfs timens diff --git a/tools/testing/selftests/timens/Makefile b/tools/testing/selftests/timens/Makefile index ef65bf96b55c..9e0edf354906 100644 --- a/tools/testing/selftests/timens/Makefile +++ b/tools/testing/selftests/timens/Makefile @@ -1,4 +1,4 @@ -TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs gettime_perf +TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs gettime_perf exec uname_M := $(shell uname -m 2>/dev/null || echo not) ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) diff --git a/tools/testing/selftests/timens/exec.c b/tools/testing/selftests/timens/exec.c new file mode 100644 index 000000000000..b3a05c41e202 --- /dev/null +++ b/tools/testing/selftests/timens/exec.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "log.h" +#include "timens.h" + +#define OFFSET (36000) + +int main(int argc, char *argv[]) +{ + struct timespec now, tst; + int status, i; + pid_t pid; + + if (argc > 1) { + if (sscanf(argv[1], "%ld", &now.tv_sec) != 1) + return pr_perror("sscanf"); + + for (i = 0; i < 2; i++) { + _gettime(CLOCK_MONOTONIC, &tst, i); + if (abs(tst.tv_sec - now.tv_sec) > 5) + return pr_fail("%ld %ld\n", now.tv_sec, tst.tv_sec); + } + } + + nscheck(); + + clock_gettime(CLOCK_MONOTONIC, &now); + + if (unshare(CLONE_NEWTIME)) + return pr_perror("Can't unshare() timens"); + + if (_settime(CLOCK_MONOTONIC, OFFSET)) + return 1; + + for (i = 0; i < 2; i++) { + _gettime(CLOCK_MONOTONIC, &tst, i); + if (abs(tst.tv_sec - now.tv_sec) > 5) + return pr_fail("%ld %ld\n", + now.tv_sec, tst.tv_sec); + } + + if (argc > 1) + return 0; + + pid = fork(); + if (pid < 0) + return pr_perror("fork"); + + if (pid == 0) { + char now_str[64]; + char *cargv[] = {"exec", now_str, NULL}; + char *cenv[] = {NULL}; + + /* Check that a child process is in the new timens. */ + for (i = 0; i < 2; i++) { + _gettime(CLOCK_MONOTONIC, &tst, i); + if (abs(tst.tv_sec - now.tv_sec - OFFSET) > 5) + return pr_fail("%ld %ld\n", + now.tv_sec + OFFSET, tst.tv_sec); + } + + /* Check that a proper vdso will be mapped after execve. */ + snprintf(now_str, sizeof(now_str), "%ld", now.tv_sec + OFFSET); + execve("/proc/self/exe", cargv, cenv); + return pr_perror("execve"); + } + + if (waitpid(pid, &status, 0) != pid) + return pr_perror("waitpid"); + + if (status) + ksft_exit_fail(); + + ksft_test_result_pass("exec\n"); + ksft_exit_pass(); + return 0; +} -- 2.20.1