Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp703243ybh; Tue, 10 Mar 2020 06:46:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvQ+L3PwOFhXjIYsH7RqILXTcZiO3md/nJ7h05pscGap3xe7NQmRMqt9VdN6MCludc0Zh8c X-Received: by 2002:a9d:2c44:: with SMTP id f62mr17914454otb.7.1583847977253; Tue, 10 Mar 2020 06:46:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1583847977; cv=pass; d=google.com; s=arc-20160816; b=JgSjOIE6tJqF5fcz1Lwl2oFBUtTjnmntbylfAOa+9dm9YzjuL28FxUbTJcNXos+BnQ vFt8fiHDYeClskHCVH4oaHkG5P+lRU+LP6Scpg1YUg8C+U2lSGh8xbxH9EbczbiTHdoB vu27VEOw3Uyr+NI4wgoE9bib3wsWODJF/yHXhQanr21jZc9oyhjKoF6jIzwV6CDi7kgU OoPCDoPQOAhMKpiqPxcXBcQFlC40TTOjsJFTTFT6hI9HFdrXv7DUWUhWCI5o0N6l0SWb LdbhDgXGCVxvmOoeppqHlfOpiXRqokVTA0lovZs6MZyrPliTTmphbrhMZodBkdwYwZOr z2PA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:references :cc:to:subject:from; bh=qOZY463IAaXjiQVx7MRIl6eponpktQjQKIZPtfN8f0A=; b=GkfJS9VYngJ4EW6lnBVCQLzZ/4bVwTBkIFCtdvG1f7VL+uWqoKqYjX+KHBpUqP7/pK 7R1S95iBRGH03DnFbQtFEL3SnYUcDGSIuz1ZR2iVrPnJgnbK9LFAxvsLwDmLLiyr6Qd9 fclC0xJqh4LdlnMfRdZV3fT/5Zv+aMrgKAKki2uI9Yy3seecONORRj19BSdsWq4OOPk/ WFcVMja9PSsgUrka8UtHsWjuITXgenDaWdcrp2FLjhr2IjFv6hawO/z8ZMN+4e7B+fBR QF0vxjKea3B1jBnnczxXGd+Bwt2Xc8YhUGdIR0AYkeHVZmmuiWgrgrJ8zidrnE3/drZn yIPQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hotmail.de dkim=pass dkdomain=hotmail.de dmarc=pass fromdomain=hotmail.de); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p21si5118918oic.178.2020.03.10.06.46.05; Tue, 10 Mar 2020 06:46:17 -0700 (PDT) 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; arc=pass (i=1 spf=pass spfdomain=hotmail.de dkim=pass dkdomain=hotmail.de dmarc=pass fromdomain=hotmail.de); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728023AbgCJNoV (ORCPT + 99 others); Tue, 10 Mar 2020 09:44:21 -0400 Received: from mail-oln040092064070.outbound.protection.outlook.com ([40.92.64.70]:44472 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726353AbgCJNoM (ORCPT ); Tue, 10 Mar 2020 09:44:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DFhvp+Oo45MXHFV30ls6zqT7/546uqQptqKa+nZwGSFJbMbVs39WFCMR3R4+ZWtEAPmWz9sSFvBXcMZn0AT/yyLwW7fPZQV+dlBtynTVIP92g9Hxt3mC4Y7u2NXWrtqaQir7P0PO6wu+IfzH74keqMDowVxzqJzGSOSOpRA4Y/yvMjGVDbcIe0c/AV7POZGdy2re8ydZbI3rSxPq3OGoFEZpY8V32jOHuEcebdKL9+fn6muJ4RtebV5KSddLfS3ZYy7sGlR5cf/TgMsECc/ZUOX/9DVPFWSgsNP4byzCIhuIDwYFNrCk1fJ5RpqAF1VSV3aclDIfckMkv36j+4KKmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qOZY463IAaXjiQVx7MRIl6eponpktQjQKIZPtfN8f0A=; b=cXWMpRR2CIXaZtvc0JBPdHMXIE7pdrMYY7W6C6JhFuzZdWpCjYoZepNahB2O+2VlSpx7pZ8TpRWAX05N85gT+L3sGVRt84yudbYdNT19apQzmZQHE+m2+vU1c4h71IFqhLRfscPzzvMwXdo3uXFUzNJ9HKE3rlGSHTYKnNs2zepozadCv+p3vXZ2r6CNhjqmwqgL5W2V/jrQyZmIUUfDqGyzUf6hePedfauhxZm6L9VUO569ZrrcRTc86IQnCh6na7FRhuWCEXoqN7FDcU5tXdGO0pb82xbZNwolU6vIRRo/4SBWAo5T+HgEzLtKz2Pw4pQKGZSZiQb11/Ybt1F1fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hotmail.de; dmarc=pass action=none header.from=hotmail.de; dkim=pass header.d=hotmail.de; arc=none Received: from HE1EUR01FT023.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e18::37) by HE1EUR01HT005.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e18::492) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11; Tue, 10 Mar 2020 13:44:03 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.0.52) by HE1EUR01FT023.mail.protection.outlook.com (10.152.0.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Tue, 10 Mar 2020 13:44:03 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:2534592BB12048E38E56F803EF8B67E0599C52D4D49AF5C559ECF8080DBF5FF9;UpperCasedChecksum:01EBD96ECEB138968F5094E9AB20D61588959F6B6FFED1F4D775C0A1AC968775;SizeAsReceived:10294;Count:50 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2793.013; Tue, 10 Mar 2020 13:44:03 +0000 From: Bernd Edlinger Subject: [PATCH 2/4] selftests/ptrace: add test cases for dead-locks To: "Eric W. Biederman" Cc: Christian Brauner , Kees Cook , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" References: <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> <878sk94eay.fsf@x220.int.ebiederm.org> <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> Message-ID: Date: Tue, 10 Mar 2020 14:44:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <877dzt1fnf.fsf@x220.int.ebiederm.org> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM0PR06CA0084.eurprd06.prod.outlook.com (2603:10a6:208:fa::25) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by AM0PR06CA0084.eurprd06.prod.outlook.com (2603:10a6:208:fa::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.16 via Frontend Transport; Tue, 10 Mar 2020 13:44:01 +0000 X-Microsoft-Original-Message-ID: X-TMN: [mbH5VsuP3pnDx5S83zh5PLwQRoDsVQ4R] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: f77651f4-c28d-44e1-771b-08d7c4f91823 X-MS-TrafficTypeDiagnostic: HE1EUR01HT005: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e3lk3mxrLBIqFPpGQyawO5+/E2DepRJw7nqU8+HOzUUV1tJZ5vXQ4OQxytSOH1PYS4u0VTkVrm3Ma/vPULqTzVD0oeY1W0nn/ROspV4OKXXw5aQI5BMO+LwqI3IQK7rlJjz9hgWJC0ShTt8eB+l4D4m3YnjZoNchxqx6NCl9ExDqRv035keCQeu5ZtRBYiEI X-MS-Exchange-AntiSpam-MessageData: UD3Fct7HirAC7qOQjBjLnzGmOlwPO0C65kL3A1S8q+1f/GsK7MYg9HzUCHCkqI7sA+dMLnxcfKeES/ctFXneRsd1eCglzjw2FOhCdSEakOwSEYWbIuQP8ojNt0stkZgqAozUAM0tip7VaTqslbmwYw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f77651f4-c28d-44e1-771b-08d7c4f91823 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2020 13:44:03.1660 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR01HT005 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds test cases for ptrace deadlocks. Additionally fixes a compile problem in get_syscall_info.c, observed with gcc-4.8.4: get_syscall_info.c: In function 'get_syscall_info': get_syscall_info.c:93:3: error: 'for' loop initial declarations are only allowed in C99 mode for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) { ^ get_syscall_info.c:93:3: note: use option -std=c99 or -std=gnu99 to compile your code Signed-off-by: Bernd Edlinger --- tools/testing/selftests/ptrace/Makefile | 4 +- tools/testing/selftests/ptrace/vmaccess.c | 86 +++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/ptrace/vmaccess.c diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index c0b7f89..2f1f532 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -CFLAGS += -iquote../../../../include/uapi -Wall +CFLAGS += -std=c99 -pthread -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := get_syscall_info peeksiginfo +TEST_GEN_PROGS := get_syscall_info peeksiginfo vmaccess include ../lib.mk diff --git a/tools/testing/selftests/ptrace/vmaccess.c b/tools/testing/selftests/ptrace/vmaccess.c new file mode 100644 index 0000000..4db327b --- /dev/null +++ b/tools/testing/selftests/ptrace/vmaccess.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Bernd Edlinger + * All rights reserved. + * + * Check whether /proc/$pid/mem can be accessed without causing deadlocks + * when de_thread is blocked with ->cred_guard_mutex held. + */ + +#include "../kselftest_harness.h" +#include +#include +#include +#include +#include +#include + +static void *thread(void *arg) +{ + ptrace(PTRACE_TRACEME, 0, 0L, 0L); + return NULL; +} + +TEST(vmaccess) +{ + int f, pid = fork(); + char mm[64]; + + if (!pid) { + pthread_t pt; + + pthread_create(&pt, NULL, thread, NULL); + pthread_join(pt, NULL); + execlp("true", "true", NULL); + } + + sleep(1); + sprintf(mm, "/proc/%d/mem", pid); + f = open(mm, O_RDONLY); + ASSERT_GE(f, 0); + close(f); + f = kill(pid, SIGCONT); + ASSERT_EQ(f, 0); +} + +TEST(attach) +{ + int s, k, pid = fork(); + + if (!pid) { + pthread_t pt; + + pthread_create(&pt, NULL, thread, NULL); + pthread_join(pt, NULL); + execlp("sleep", "sleep", "2", NULL); + } + + sleep(1); + k = ptrace(PTRACE_ATTACH, pid, 0L, 0L); + ASSERT_EQ(errno, EAGAIN); + ASSERT_EQ(k, -1); + k = waitpid(-1, &s, WNOHANG); + ASSERT_NE(k, -1); + ASSERT_NE(k, 0); + ASSERT_NE(k, pid); + ASSERT_EQ(WIFEXITED(s), 1); + ASSERT_EQ(WEXITSTATUS(s), 0); + sleep(1); + k = ptrace(PTRACE_ATTACH, pid, 0L, 0L); + ASSERT_EQ(k, 0); + k = waitpid(-1, &s, 0); + ASSERT_EQ(k, pid); + ASSERT_EQ(WIFSTOPPED(s), 1); + ASSERT_EQ(WSTOPSIG(s), SIGSTOP); + k = ptrace(PTRACE_DETACH, pid, 0L, 0L); + ASSERT_EQ(k, 0); + k = waitpid(-1, &s, 0); + ASSERT_EQ(k, pid); + ASSERT_EQ(WIFEXITED(s), 1); + ASSERT_EQ(WEXITSTATUS(s), 0); + k = waitpid(-1, NULL, 0); + ASSERT_EQ(k, -1); + ASSERT_EQ(errno, ECHILD); +} + +TEST_HARNESS_MAIN -- 1.9.1