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.9 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_HELO_NONE,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 96381C3A589 for ; Thu, 15 Aug 2019 16:39:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C32B2089E for ; Thu, 15 Aug 2019 16:39:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="Krs86DRV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732710AbfHOQji (ORCPT ); Thu, 15 Aug 2019 12:39:38 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46619 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732668AbfHOQjd (ORCPT ); Thu, 15 Aug 2019 12:39:33 -0400 Received: by mail-wr1-f68.google.com with SMTP id z1so2731578wru.13 for ; Thu, 15 Aug 2019 09:39:32 -0700 (PDT) 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=QlOwhEOC4bO6ztUPcHZX2D8R8lwFv2ELZ3dmT/1+sz8=; b=Krs86DRVNTVgo/j/k/uiSGf3vcKUhuqPsV/TDx0kVx4p2zPAC1JIhIdF02WAoqEz7o uEeC0dGkeWcO5wZsfdlmWDGV0BNCPlT7myjt5GQX9RRlYiWEmwZhOwRNUCukcg3C3Tar swL2AscP6JlmzUHtpNVFIkPXfDPCyULsGp25K/LGpp1RNKIHZwXZ56EtER1T4UG7SbH8 2tZoc+m4mdFieyFtKdTRzvEuYUsLvbhSWv7lz3G/b4a1Qqeth0bHMoi2ICSzlhqLvHMt XV1Soqs12Y9NE47S51Pm0XTR/Vrlas6M3dZtjEODvBcGmy6uwN+t7+TWmaH2++YFVH73 x24A== 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=QlOwhEOC4bO6ztUPcHZX2D8R8lwFv2ELZ3dmT/1+sz8=; b=AEFWoBATrbM93F8PGs1FZbDqV17Bav5gzmzSaTMbZNgdt+IC3ry3j+kBHwdM9I584b 0Q0hkn3KaNnIkkzg4eFzgG9XuNAPCOPm3xAdxZj5c/eBXDeLEYumNOmEFr2tjQl/KALO ODlr+opeXHmrK+N8JCqdBv4ipDRw3ul4+eD9gGpvTzquvyM9dtQ50shwUv/AiIA6PXqE dJSZM69GBkW0xxW8GWm974UUlnhlHFotChTXx5/s+yErOh8bIA8Evgb2dLV8oCMqOP0i iTVE6xguNC6/DKXxCQIt+K8ifmQSPIgX6EYfr3vMJTnb20d1lVcr9krhogoD9v0irZAH 1BdA== X-Gm-Message-State: APjAAAU1j3PfnfE8G1BtyNUdy6WjmrOAB+D/68rSjTsZ9MFTTpCr8f5e 1DwrDQCemF7LjrAOpMCQNhZZbpQ4ZAM= X-Google-Smtp-Source: APXvYqztK2I0QgbTl4htGjkjFkvwJgmku1QeLCBTziWxHDmG2T54lb6U3mJxBtRv7pWIXzQywQl/4A== X-Received: by 2002:a5d:4950:: with SMTP id r16mr6225691wrs.347.1565887171252; Thu, 15 Aug 2019 09:39:31 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id f7sm5755046wrf.8.2019.08.15.09.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 09:39:30 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin , Dmitry Safonov , Adrian Reber , Andrei Vagin , Andy Lutomirski , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , Thomas Gleixner , Vincenzo Frascino , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: [PATCHv6 36/36] selftest/timens: Check that a right vdso is mapped after fork and exec Date: Thu, 15 Aug 2019 17:38:36 +0100 Message-Id: <20190815163836.2927-37-dima@arista.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815163836.2927-1-dima@arista.com> References: <20190815163836.2927-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 Co-developed-by: Dmitry Safonov Signed-off-by: Dmitry Safonov --- tools/testing/selftests/timens/.gitignore | 1 + tools/testing/selftests/timens/Makefile | 2 +- tools/testing/selftests/timens/exec.c | 93 +++++++++++++++++++++++ 3 files changed, 95 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 16292e4d08a5..789f21e81028 100644 --- a/tools/testing/selftests/timens/.gitignore +++ b/tools/testing/selftests/timens/.gitignore @@ -1,4 +1,5 @@ clock_nanosleep +exec gettime_perf gettime_perf_cold procfs diff --git a/tools/testing/selftests/timens/Makefile b/tools/testing/selftests/timens/Makefile index 97e0460eaf48..b77fe22fa24d 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..de7798832429 --- /dev/null +++ b/tools/testing/selftests/timens/exec.c @@ -0,0 +1,93 @@ +// 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(); + + ksft_set_plan(1); + + 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.22.0