From patchwork Fri Mar 20 20:26:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 11450285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 591C81668 for ; Fri, 20 Mar 2020 20:26:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2329E2072C for ; Fri, 20 Mar 2020 20:26:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2329E2072C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 542EC6B0036; Fri, 20 Mar 2020 16:26:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F35E6B0037; Fri, 20 Mar 2020 16:26:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3937F6B006C; Fri, 20 Mar 2020 16:26:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 2231D6B0036 for ; Fri, 20 Mar 2020 16:26:26 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D41F88131 for ; Fri, 20 Mar 2020 20:26:25 +0000 (UTC) X-FDA: 76616873130.03.kick64_8f58cd7bec12a X-Spam-Summary: 2,0,0,523b9630d51e532a,d41d8cd98f00b204,bernd.edlinger@hotmail.de,,RULES_HIT:1:41:355:379:800:854:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1543:1593:1594:1683:1711:1730:1747:1777:1792:1801:2393:2538:2539:2559:2562:2918:3138:3139:3140:3141:3142:3354:3867:3870:3871:4321:4605:5007:6609:6737:6738:7652:9121:10004:10400:11026:11473:11657:11658:11914:12043:12048:12160:12291:12294:12296:12297:12519:12555:12683:12760:12895:12986:14096:14097:14181:14394:14721:21080:21324:21444:21451:21627:21789:21983:21990:30012:30054:30055:30056:30067:30070,0,RBL:40.92.73.53:@hotmail.de:.lbl8.mailshell.net-62.18.84.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: kick64_8f58cd7bec12a X-Filterd-Recvd-Size: 10066 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073053.outbound.protection.outlook.com [40.92.73.53]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Mar 2020 20:26:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GPlfI1VtCNTt7Ny+lfFPzpdqjSkJutIxzw98zi2c6iJAez9LprhTqoTiT0xcMtMPVtqRNBj5ldi5PJgNxIAeCdI1iNTXwi7ldtN/ymD2z2aaqtMxa8WT+k+U3IMQ/hv8im1Em40xIN6is443kfOrClgnjrVCz1bV6jx1l3vC++/9SiR3dMpQlQ7ht0Ochhc5j/3ZKTGrwLeQYkdxiZQ8/wUB3kw9yDHJU1eF3nNzbHuc++Nlg8zEs+dDmg/aSmbbzrc2q4gFyp7lJILhaZ6xyzmp7U5/7XNVYoPvqHz5W5srkKs3Kgt4xsPl8hCWHabx3GPl1/dHiJI++d+4EU1Uuw== 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=pd5tqvTa6xvEYJ44Dt5463qSdZ9On+0UnUjylKhegr8=; b=FNhJqb3WwBlB2kxhSAbX/BennsJ1dqlhotB/3ZHZxuSki1BnqmiyP2mLha2ic/7JdygmwnQBiB/Ol50W8DBy24Xy2CycpAwl47lAbQcHjdjvgjVIamvAb+hWSUrDwCRG9gxLXkgkNcAlMNMq+JEekVM+0gir73p4bNZgbe/MRKT0UuOZM+JTV9uGiX6fsMviXPMb2WY8tKAnk2UiduqbLVqvIQSkHfgB7GEixkxKOOvs4Fpnr3lUWABGkIXt2Sg5+uP5k91ZILo9+8igLv0pZVtAE4a9yGDkW6i0gLmGIa5Yfw7BTofF3vzRaQycdug1ohhCVW3fjuQnfj84ulMmSw== 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 DB3EUR04FT027.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::39) by DB3EUR04HT098.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13; Fri, 20 Mar 2020 20:26:22 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.24.52) by DB3EUR04FT027.mail.protection.outlook.com (10.152.24.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13 via Frontend Transport; Fri, 20 Mar 2020 20:26:22 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:37CE4F438BC61B38067051E65AF3E2968517349F957219336FCCDA618C080E2F;UpperCasedChecksum:DBA3AA576F2428A0568806CE8995B99A0AA642CB8F5443D70BBEABA9F842296F;SizeAsReceived:9412;Count:49 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.2835.017; Fri, 20 Mar 2020 20:26:22 +0000 From: Bernd Edlinger Subject: [PATCH v6 07/16] selftests/ptrace: add test cases for dead-locks To: Greg Kroah-Hartman , Kirill Tkhai , "Eric W. Biederman" , 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 , 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: <077b63b7-6f5e-aa8e-bf96-a586b481cc46@hotmail.de> Message-ID: Date: Fri, 20 Mar 2020 21:26:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <077b63b7-6f5e-aa8e-bf96-a586b481cc46@hotmail.de> Content-Language: en-US X-ClientProxiedBy: AM0PR01CA0068.eurprd01.prod.exchangelabs.com (2603:10a6:208:e6::45) 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 AM0PR01CA0068.eurprd01.prod.exchangelabs.com (2603:10a6:208:e6::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20 via Frontend Transport; Fri, 20 Mar 2020 20:26:21 +0000 X-Microsoft-Original-Message-ID: X-TMN: [FczRzGiRDb3oaKdVwSJahXA7QSJR1crD] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 49 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: cd599a82-2d7d-4448-bf05-08d7cd0cf47d X-MS-TrafficTypeDiagnostic: DB3EUR04HT098: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TjgjVV4YphAWfzM0xWYSz3GiS8CR2rQMIeDoSmT+afGjuP5wd9knGa93x5wyI5SWHfgjjX5YdqOYkuMwmIYnWeDHAl1/SukK9V+P+hU3wGBNVB1cl3656CSyi+vQVpRicY//1sTcQ5MaNX63OA0BKI9MLOIPdKyVkmx5ze4WWmY8gTdjq9dUVZtZr81d9bO8 X-MS-Exchange-AntiSpam-MessageData: aefkdQqnH8qqunrS9TsJiQLQVGvQorkqRk+FG2k2yzILNvP/AZR5/rAIWHvGP5H8F6pCBd9cgW82Z2UviAEu8BHl1Y9hkguLsdV2CiP/FC5KHMx4uBYgDvRGU8ZsQ0tlDR1ywr3eKp0bkMsWFOAelQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd599a82-2d7d-4448-bf05-08d7cd0cf47d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2020 20:26:22.4246 (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: DB3EUR04HT098 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Kees Cook --- 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