Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4634271yba; Sun, 12 May 2019 18:22:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0pO7bcAIFV0RyyakmT9vtCqYMBtTz2nwnguC1NPXIcnL1sXe7lCX/1jFezlvGn+sIzu5X X-Received: by 2002:a65:4006:: with SMTP id f6mr27918734pgp.47.1557710524781; Sun, 12 May 2019 18:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557710524; cv=none; d=google.com; s=arc-20160816; b=03DamdjpHmZmSXKjAi/+2xwBRx0bWSPr29iJ+fkmyBtcC76XqFJvytWsO1SP6nro0w QQwEb7vuVz2Z9XQuQDacfqcZTvaMMDbajwNh3yfUJ+W6OV3KwQ4PfxYNbBRi4ekEHCR0 InPB/p8UjVdx4KZYgQm/22xnZ7qvWGlcTNgduRZH8dlCc6UxThKFxptmU4EHwJKzd0oa HS0A11oFT6Zi/EzezjwH/VFYdOhOPoi9dd6uw9roV8Cu1+6Bg2LET+ufsjGBSvaY1Vox E3L0o7QhyxBXujIePalC6WT1tJzZfi1ozZHURsiEDlRte7d5/epeBtgLwTtRNPkRmtnW sQig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id :user-agent:mime-version:cc:to:subject:from:date:dkim-signature; bh=kmhcbfiUAPDcBNaPIgo8gEuwKeqhFA+LCiP83+sxgTg=; b=K/FugyoxmQPXNDtkjuv4X/uawP5MDvZufvUAU8Am65GR5jo14ylcyRAwbZpv37MPb2 vHR3G26zLPB2wLY/UI4BVcjREdmFx9jXVtcJBTu6BmjyUxxwwhasLIDIxRANt7iqL4h2 d1JEQg7oKToGCFIeX4PoyybjaKgsFIYiVVpkU3cStphP3POO9ESaMcSmECR9tW6OvG8r HM/0a16VUoU7B2pF9EzAwBlbFMEpC1I+twj5U2apSMi8NB/L4MdZC6JLoVbxV7ewdfIg uBMKQrGUq4cQNSewGtxZfYQtyVA+/NJHZlaV3vyAOOHmHWj3rxGGepIgIB9KvtiuOEi9 Laqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.ca header.s=s2048 header.b=HfaBWEDV; 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=REJECT sp=REJECT dis=NONE) header.from=yahoo.ca Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z123si17137585pfz.168.2019.05.12.18.21.48; Sun, 12 May 2019 18:22:04 -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; dkim=pass header.i=@yahoo.ca header.s=s2048 header.b=HfaBWEDV; 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=REJECT sp=REJECT dis=NONE) header.from=yahoo.ca Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727266AbfEMBUY (ORCPT + 99 others); Sun, 12 May 2019 21:20:24 -0400 Received: from sonic305-3.consmr.mail.bf2.yahoo.com ([74.6.133.42]:46720 "EHLO sonic305-3.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727131AbfEMBUY (ORCPT ); Sun, 12 May 2019 21:20:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.ca; s=s2048; t=1557710422; bh=kmhcbfiUAPDcBNaPIgo8gEuwKeqhFA+LCiP83+sxgTg=; h=Date:From:Subject:To:Cc:From:Subject; b=HfaBWEDVcqfHssIjbJOfGi8sQT+nkHvPiT9GZAShc8nYefRyh9Hev0derFXlMhrR2QktghAxTgQ1hD5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o74mhqjLYFCk3Tfg Sa2RKbbUTqhMoNLNl4D3dq0HoDLujoAPGAYuC5UvT0O5QBJR_Y9sHCL4PTCbvnJUs0EwD0W5dTuf TAEfz76QJesi9X0DzHdlGeJEQRkKEHEWMEIlnkErj871CdjZrzsk1D30TV9Er0240HHYcge0CCPv QijG8z.yZpX6fxjkUKbF8Ytu.A2vK4kue_CyhtScQtEbkF5y6j4u8MiXlKknXede3bbyA2Ho6Ufg iwfQdC2jj9jk98I65y4NfwLHVOdjrGKVggv0x8581W4QqK_SVfww63lBs.r10tX1IC3v3rIK2.21 4v4Ba7i2.iZWFDBH9xRzmOtAlk1.HNpRkpHhy.VF4RGPDQBEBbMMtLY3zCg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Mon, 13 May 2019 01:20:22 +0000 Received: from CPE00fc8de26033-CM00fc8de26030.cpe.net.cable.rogers.com (EHLO localhost) ([99.228.156.240]) by smtp406.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 10b57405150ea85529f4fce74da5bb61; Mon, 13 May 2019 01:20:18 +0000 (UTC) Date: Sun, 12 May 2019 21:20:12 -0400 From: "Alex Xu (Hello71)" Subject: [REGRESSION] ptrace broken from "cgroup: cgroup v2 freezer" (76f969e) To: linux-kernel@vger.kernel.org, tj@kernel.org, guro@fb.com Cc: oleg@redhat.com, kernel-team@fb.com MIME-Version: 1.0 User-Agent: astroid/0.14.0 (https://github.com/astroidmail/astroid) Message-Id: <1557709124.798rxdb4l3.astroid@alex-desktop.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I was trying to use strace recently and found that it exhibited some=20 strange behavior. I produced this minimal test case: #include int main() { write(1, "a", 1); return 0; } which, when run using "gcc test.c && strace ./a.out" produces this=20 strace output: [ pre-main omitted ] write(1, "a", 1) =3D ? ERESTARTSYS (To be restarted = if SA_RESTART is set) write(1, "a", 1) =3D ? ERESTARTSYS (To be restarted = if SA_RESTART is set) write(1, "a", 1) =3D ? ERESTARTSYS (To be restarted = if SA_RESTART is set) write(1, "a", 1) =3D ? ERESTARTSYS (To be restarted = if SA_RESTART is set) write(1, "a", 1) =3D ? ERESTARTSYS (To be restarted = if SA_RESTART is set) write(1, "a", 1) =3D ? ERESTARTSYS (To be restarted = if SA_RESTART is set) [ repeats forever ] The correct result is of course: [ pre-main omitted ] write(1, "a", 1) =3D 1 exit_group(0) =3D ? +++ exited with 0 +++ Strangely, this only occurs when outputting to a tty-like output.=20 Running "strace ./a.out" from a native Linux x86 console or a terminal=20 emulator causes the abnormal behavior. However, the following commands=20 work correctly: - strace ./a.out >/dev/null - strace ./a.out >/tmp/a # /tmp is a standard tmpfs - strace ./a.out >&- # causes -1 EBADF (Bad file descriptor) "strace -o /tmp/a ./a.out" hangs and produces the above (infinite)=20 output to /tmp/a. I bisected this to 76f969e, "cgroup: cgroup v2 freezer". I reverted the=20 entire patchset (reverting only that one caused a conflict), which=20 resolved the issue. I skimmed the patch and came up with this=20 workaround, which also resolves the issue. I am not at all clear on the=20 technical workings of the patchset, but it seems to me like a process's=20 frozen status is supposed to be "suspended" when a frozen process is=20 ptraced, and "unsuspended" when ptracing ends. Therefore, it seems=20 suspicious to always "enter frozen" whether or not the cgroup is=20 actually frozen. It seems like the code should instead check if the=20 cgroup is actually frozen, and if so, restore the frozen status. I am using systemd but not any other cgroup features. I tried in an=20 initramfs environment (no systemd, /init -> shell script) and reproduced=20 the failing test case. Please CC me on replies. Thanks, Alex. --- kernel/signal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index 62f9aea4a15a..47145d9d89ca 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2110,7 +2110,7 @@ static void ptrace_stop(int exit_code, int why, int c= lear_code, kernel_siginfo_t preempt_disable(); read_unlock(&tasklist_lock); preempt_enable_no_resched(); - cgroup_enter_frozen(); + //cgroup_enter_frozen(); freezable_schedule(); } else { /* @@ -2289,7 +2289,7 @@ static bool do_signal_stop(int signr) } =20 /* Now we don't run again until woken by SIGCONT or SIGKILL= */ - cgroup_enter_frozen(); + //cgroup_enter_frozen(); freezable_schedule(); return true; } else { --=20 2.21.0