From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9A99ECE58C for ; Fri, 11 Oct 2019 12:23:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AADE52190F for ; Fri, 11 Oct 2019 12:23:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728066AbfJKMXo (ORCPT ); Fri, 11 Oct 2019 08:23:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43700 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727974AbfJKMXn (ORCPT ); Fri, 11 Oct 2019 08:23:43 -0400 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1487C2A09A7 for ; Fri, 11 Oct 2019 12:23:43 +0000 (UTC) Received: by mail-ed1-f69.google.com with SMTP id 34so5661796edf.0 for ; Fri, 11 Oct 2019 05:23:43 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=H2MBbbJ40+7c+zCxtdMVPxmyJTAgLs4tX+z2yWBAoJY=; b=YNPwsuURRfr/wJ7i9F5IbvWxbAoiCp/ypxFHQVxbuoih8cNlAUqh/yiU2182fxnvYm vUcS9uGYj7jxp8xcDq8dE+vxiBRfAu+ATMJ+/muD8ykf47S5Q4KkQjdDn4eNr5x6d5Cu gyh6IobjdpxjRN2wmZasKtkNwKYIb4XLP7w/kg/gQ1goOLUcnSnpY6ovO/0hr89irF27 py3m6mHqpBwkgY9sH6fnhn0Pax6x2XkJpBcQ54ePmK2VHwgSC/sAlBWg6jiy+7ZlTaox UZ7/7f7gBcQXSmRhNlIp9mqcCrWJ4EmraHINVEJlH4uz4xAJODzFNSuGzo0z2yAkwPBS hvUQ== X-Gm-Message-State: APjAAAXebsnsRf9dXpzCuATq8LwSSQtwLpRWoO3DUz0XXZXke2TooXPV l71mq7ovkgmsXTGY4kGW/dUQP+GCpKzasJRBHAqjTwD1X+A6HtpNQYhBQfwqLb69iYfe38UzOBg P9EgO8vkKfvrlK52rSh3JTsYD X-Received: by 2002:a17:906:5407:: with SMTP id q7mr13791852ejo.24.1570796621422; Fri, 11 Oct 2019 05:23:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcuwNfu7eBCa+wJQza/bR/XzgJiVyFoOkqeJ3Q9NTMa95W6G9v3z1bhtpv9pyERQVnbX9Tyg== X-Received: by 2002:a17:906:5407:: with SMTP id q7mr13791826ejo.24.1570796621125; Fri, 11 Oct 2019 05:23:41 -0700 (PDT) Received: from localhost ([2a02:2450:102e:d85:877d:43b4:dd8f:144d]) by smtp.gmail.com with ESMTPSA id lw23sm1095531ejb.68.2019.10.11.05.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 05:23:40 -0700 (PDT) From: Christian Kellner To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, Christian Kellner , Christian Brauner , Andrew Morton , "Peter Zijlstra (Intel)" , Ingo Molnar , Michal Hocko , Thomas Gleixner , Elena Reshetova , Roman Gushchin , Andrea Arcangeli , Al Viro , Aleksa Sarai , "Dmitry V. Levin" Subject: [PATCH v3 1/2] pidfd: show pids for nested pid namespaces in fdinfo Date: Fri, 11 Oct 2019 14:23:20 +0200 Message-Id: <20191011122323.7770-1-ckellner@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191009160532.20674-1-ckellner@redhat.com> References: <20191009160532.20674-1-ckellner@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Kellner The fdinfo file for a process file descriptor already contains the pid of the process in the callers namespaces. Additionally, if pid namespaces are configured, show the process ids of the process in all nested namespaces in the same format as in the procfs status file, i.e. "NSPid:\t%d\%d...". This allows the easy identification of the processes in nested namespaces. Signed-off-by: Christian Kellner --- Changes in v2: - Moved into separate function to avoid multiple ifdefs as suggested by Michal Hocko Changes in v3: - Helper function takes struct pid_namespace *ns param and got a new name kernel/fork.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index bcdf53125210..183950aad82b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1695,12 +1695,27 @@ static int pidfd_release(struct inode *inode, struct file *file) } #ifdef CONFIG_PROC_FS +static inline void print_pidfd_nspid(struct seq_file *m, struct pid *pid, + struct pid_namespace *ns) +{ +#ifdef CONFIG_PID_NS + int i; + + seq_puts(m, "\nNSpid:"); + for (i = ns->level; i <= pid->level; i++) { + ns = pid->numbers[i].ns; + seq_put_decimal_ull(m, "\t", pid_nr_ns(pid, ns)); + } +#endif +} + static void pidfd_show_fdinfo(struct seq_file *m, struct file *f) { struct pid_namespace *ns = proc_pid_ns(file_inode(m->file)); struct pid *pid = f->private_data; seq_put_decimal_ull(m, "Pid:\t", pid_nr_ns(pid, ns)); + print_pidfd_nspid(m, pid, ns); seq_putc(m, '\n'); } #endif -- 2.21.0