From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752683AbbJXVyh (ORCPT ); Sat, 24 Oct 2015 17:54:37 -0400 Received: from mail-vk0-f50.google.com ([209.85.213.50]:36335 "EHLO mail-vk0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752357AbbJXVyg (ORCPT ); Sat, 24 Oct 2015 17:54:36 -0400 MIME-Version: 1.0 X-Originating-IP: [75.157.4.179] Date: Sat, 24 Oct 2015 14:54:35 -0700 Message-ID: Subject: piping core dump to a program escapes container From: Shayan Pooya To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I noticed the following core_pattern behavior in my linux box while running docker containers. I am not sure if it is bug, but it is inconsistent and not documented. If the core_pattern is set on the host, the containers will observe and use the pattern for dumping cores (there is no per cgroup core_pattern). According to core(5) for setting core_pattern one can: 1. echo "/tmp/cores/core.%e.%p" > /proc/sys/kernel/core_pattern 2. echo "|/bin/custom_core /tmp/cores/ %e %p " > /proc/sys/kernel/core_pattern The former pattern evaluates the /tmp/cores path in the container's filesystem namespace. Which means, the host does not see a core file in /tmp/cores. However, the latter evaluates the /bin/custom_core path in the global filesystem namespace. Moreover, if /bin/core decides to write the core to a path (/tmp/cores in this case as shown by the arg to custom_core), the path will be evaluated in the global filesystem namespace as well. The latter behaviour is counter-intuitive and error-prone as the container can fill up the core-file directory which it does not have direct access to (which means the core is also not accessible for debugging if someone only has access to the container). Currently, I work around this issue by detecting that the process is crashing from a container (by comparing the namespace pid to the global pid) and refuse to dump the core if it is from a container. Tested on Ubuntu (kernel 3.16) and Fedora (kernel 4.1).