Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp846983ybp; Fri, 11 Oct 2019 05:24:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh+C7b7lPAQJILurxEywnt6ZaqJWQ7OoVMq8zg1c993njf/Ib4RngPGpH6JL74h+RCd+ot X-Received: by 2002:aa7:d584:: with SMTP id r4mr12987550edq.92.1570796665319; Fri, 11 Oct 2019 05:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570796665; cv=none; d=google.com; s=arc-20160816; b=zPWzowY4ZM2F5so+LDEzFdfjVBrOCl/QNsMO+oKDZzEUzd2VAp5ClCx6X14CkHoHKD d6sVL2+4vCFesg0t7rb3udw8WhIlMKXigTo8ofOPDDzYp/j+k05XsdCSbtlkaieVK2P+ NXeyF+Ggeb/9yogh6q9WnhQmV2saz39GgBoSsSfuz7mI29H32abhUyiu2sJQogWIScoa 0I1bVDI71JynxrolOynziViwNBXKfwWGOjlc9DmP90KmOTwETMHlRbv+rbGIG7tQGg3g jYgYXgwE3ptJSBMlYMqDV3CVGAGPGvqIc1FG0nH9cZFzLDFkzQdULNt+1ApTZdERzUHt wnZg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=H2MBbbJ40+7c+zCxtdMVPxmyJTAgLs4tX+z2yWBAoJY=; b=CigT1XHfRiGG3HjEQSjbTx3l6xi9fSVK+m977Q/idmXiPFgGlr9ydL9bqZQBHgIJft WxHllcdp/4C7KkQV747W/ZRsRi+qVIusLquekP14Kn83pjqZSR6FR/5O6zcXbijPT5GG gSQ6D+3XnfeUHeHKKefVPaTOFPe36zlJgc1ayP7VIlB4sv3Eo0vo+x6xv9Ecg/GhLiZG Re0dikCF0zcse4z7flIMnqSrlfdO+tyvWB+vkRfIu/bUvYfl4PqRdosML0EYFNItkqR2 5AsF8SUquRuQ1wHwA/tV0EeEwccwpXDwkqb92ijKXbELWbdRSuqtutMMFA/Po/DPC0cf vRoA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17si6166423edb.89.2019.10.11.05.24.01; Fri, 11 Oct 2019 05:24:25 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728056AbfJKMXn (ORCPT + 99 others); Fri, 11 Oct 2019 08:23:43 -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-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