Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp158906imu; Wed, 2 Jan 2019 16:37:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN6jHagJt1Z/DurobQiZ6Ss65T0QGOjJUGzOtapcFem4aU0GSHSKNaPITCuw5bbtOdEM+KGd X-Received: by 2002:a63:ac46:: with SMTP id z6mr15279816pgn.162.1546475863876; Wed, 02 Jan 2019 16:37:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546475863; cv=none; d=google.com; s=arc-20160816; b=YDoK6zEpaXK2++yS9hhKwa9gascLh165E/wSvaSy7pJ3AVqSo+2puVM+FjoTbMYst9 vKMt2q4UrKFscmMYZ2jsrI9TUZ+hfkfNe4w2XfuUvvn94RTbeTK1c8twFkFbpwJeUyxR 8V2pNpreXMcZsYdf3e9dYB/6HfdItKLbcUwWllL3KF7ZZ6vMRGQFiCZhXOcxb/sIGOBK yz8AyNrYwnzudeL5XQGNPJVfKnwxxhXHsI2GWO5b/kDHbpFimQZuPjjpViZlkeOqHz19 QBrAlHlAlOZyAJ5hKCAhEX05GA8NWNEchtY5TIwfHoE4hx5dCDjPbRpFzs2OxFYdwL62 oIzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=slOs5HVUDIi/Tpmu6RLaJrzMYZWLNYUNQu8MlH9pJVg=; b=cC4sVvdXlAvLVXiUF2A8PyISXlo4UuygMzgH+ISc3RDaIMiovowmV5GTkN8HVBRwhf /LRbbCThFMx9A4AZurBsj6mDpqXjhYUHY8VPT3vyxMbpjBjp/CbglFU8rIeD/Hc9Liq+ C7qart5g6QMu86Tbvwg2JnxTXMkEoacOIY8+w+TmWGCTXlt5by606oQzlmB8aQbuyeHo 5BJnZbvMoKpf7zLFhCjQesegDbVhq22XZ1AXYfvjR8d/HNulnJg3rxX4tPjQb2nr5T+O RvE3sLnmb6ahNxkhykmnOC/m+Ve78w+jG+hdyK1Qd8jzF1ZLJt16KbN5RJDZeZwpnU7m bsbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kf7OU3nI; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si50786019pgl.153.2019.01.02.16.37.29; Wed, 02 Jan 2019 16:37:43 -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=@gmail.com header.s=20161025 header.b=kf7OU3nI; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728274AbfABU7n (ORCPT + 99 others); Wed, 2 Jan 2019 15:59:43 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36299 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726941AbfABU7n (ORCPT ); Wed, 2 Jan 2019 15:59:43 -0500 Received: by mail-pg1-f196.google.com with SMTP id n2so15066181pgm.3 for ; Wed, 02 Jan 2019 12:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=slOs5HVUDIi/Tpmu6RLaJrzMYZWLNYUNQu8MlH9pJVg=; b=kf7OU3nI0S2hH7AACI8TgRbihF5wMq4j1iybBNcdzj8Ii/cRpXvYcM8afgiYGDtzog JVPpGA6m1iHi4ki+AoGqnd7Fn6JPv21nmOoF3GB8oQ1Q11TUt4y1CXcZcBRYMPkCgbBR G3NDYvWerD+tMhtZX1Z7SKtBxYWNvgReBn+s+Lhd2Znzo40DeAielNeHERmkecPvDOHc MBppGX3/cXrnjkfiMDsS+se2Xdr+Xlrp/o1Z5wsgeeXgcYXeYqo55I03FkeOSbDIueaw bHYgoP7/t+fveVxzFvBuOtzpJufkvMqLUMXNBM7P0RqurmG9Lgwej8+133rVxjVQt12N kDAA== 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; bh=slOs5HVUDIi/Tpmu6RLaJrzMYZWLNYUNQu8MlH9pJVg=; b=fmS/X1w0wiOy02XQCoh3ZCnZAFdVyeNgGhtNriyyLe78GBf6PQWiEGX/59zgIlE3zv BMfJ9olO5zE1xYvmAT05CffdfDXxaY0lmQFMGbjEGBMcY6w6+6EfF9XSeEViSrDdWlU9 jhscUBGQWA5EVaEsOZDwh6swTjz1711Eo3T/gLmswJq+dexRLwI17VmnBEPcKnmCWMxg qZkMhM8iGSPOfNkhYNTRwiXPrF/yepxRCsGe4IC9E9SLiaBW8xcFFRKwhbLhgaF7Ph9r ca1+LhpBZdfNdmSPpZJ5YqhHdhgy/g+YLKecrJPyRJUAiQeymEgLg+yxi54vaC3UfIzh fWzQ== X-Gm-Message-State: AA+aEWYRYzReW2W+/J8usLPGdXmnN3fB488eTHcGmDUrt8xVlpX9ZdLv kbyLxfui0fmxANAaCgdIUyo= X-Received: by 2002:a62:4c5:: with SMTP id 188mr46395749pfe.130.1546462781908; Wed, 02 Jan 2019 12:59:41 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:78b4:3a07:980a:287b]) by smtp.gmail.com with ESMTPSA id k24sm79185108pfj.13.2019.01.02.12.59.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Jan 2019 12:59:41 -0800 (PST) From: Andrei Vagin To: Alexander Viro , Andrew Morton , Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Andrei Vagin , "Eric W. Biederman" Subject: [PATCH] kernel: release ptraced tasks before zap_pid_ns_processes Date: Wed, 2 Jan 2019 12:59:39 -0800 Message-Id: <20190102205939.26231-1-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, exit_ptrace() adds all ptraced tasks in a dead list, than zap_pid_ns_processes() waits all tasks in a current pid ns, and only then tasks from the dead list are released. zap_pid_ns_processes() can stuck on waiting tasks from the dead list. In this case, we will have one unkillable process with one or more dead children. Cc: Oleg Nesterov Cc: "Eric W. Biederman" Cc: Andrew Morton Signed-off-by: Andrei Vagin --- kernel/exit.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 0e21e6d21f35..ccaa6f6549ba 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -664,9 +664,6 @@ static void forget_original_parent(struct task_struct *father, { struct task_struct *p, *t, *reaper; - if (unlikely(!list_empty(&father->ptraced))) - exit_ptrace(father, dead); - /* Can drop and reacquire tasklist_lock */ reaper = find_child_reaper(father); if (list_empty(&father->children)) @@ -705,8 +702,18 @@ static void exit_notify(struct task_struct *tsk, int group_dead) LIST_HEAD(dead); write_lock_irq(&tasklist_lock); - forget_original_parent(tsk, &dead); + if (unlikely(!list_empty(&tsk->ptraced))) + exit_ptrace(tsk, &dead); + write_unlock_irq(&tasklist_lock); + + /* Ptraced tasks have to be released before zap_pid_ns_processes(). */ + list_for_each_entry_safe(p, n, &dead, ptrace_entry) { + list_del_init(&p->ptrace_entry); + release_task(p); + } + write_lock_irq(&tasklist_lock); + forget_original_parent(tsk, &dead); if (group_dead) kill_orphaned_pgrp(tsk->group_leader, NULL); -- 2.17.2