From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 137AFC282CB for ; Wed, 6 Feb 2019 00:12:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D370B21852 for ; Wed, 6 Feb 2019 00:11:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="nyDpSfKM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729763AbfBFAL6 (ORCPT ); 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-Google-Smtp-Source: AHgI3IaQLZU/ityy40418rEonwOBkSpXjf/PCswBQ9QvGsWbCm+Dg84sVWsmvjASDwFFucVw62OpuA== 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