Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6261737iog; Thu, 23 Jun 2022 15:09:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tme8Y2XIPMFw/vHhHTM0Q8oFtjdcH9sW2fs1nXp7C7Yk6Tqt9YMU7daY/MDNaMhs8bFjTZ X-Received: by 2002:a17:907:6d23:b0:707:90a0:afb3 with SMTP id sa35-20020a1709076d2300b0070790a0afb3mr10173177ejc.685.1656022163474; Thu, 23 Jun 2022 15:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656022163; cv=none; d=google.com; s=arc-20160816; b=Oeip48BBLIvXTKuxdJC7NUibAHAVD85TmnQL0y/hsE3KqB+0mAipAoDtD6BwtUx9XK LaaJDwORzsnmCAF9c82HOcw0pOGoE02hDFQiKvAEVkCvR9fPB7op3Sgwe8esoB2A+WYU W1tnC279uoZuihTdGlffXHl1roqZeKyNTsfsy4kaBouLnVDqLVARVshe0l/1xUIoB54X gbDWTaJc83l+TG8uHg9HTv544dfd1C7w4BZ4EePZlZf6K/eLsqHm3Cs7v17eNySBit91 3k/nmreeSEHjN+0Q2o0bAdfP/+JNx0UdhSMKOgOlu617iaJKkqU7U6N4CO5Cgc8YJKWX hLKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=KwqDl7Ku0++kd3bGbvwgzs1gT1laIcj9GIfwKObRL9E=; b=t3jH2NXpm0djrndAJmZ6BiGyxe3PXJxL1IJmnftAa8g5q09r2meJY7fZOFHZhy+1sr e/NsDtgC3Q0WZbAB+H7wZgoCCiWnkErHGLQ3MUcnHvqa8KrlPMZMJr8EYHeWEZ7v1YJT AlV480SdNXIjV0O7IF7STvdGW6bbPyv/Tp9c5JOJ8o44yKKK8jmy7bH9JMId2vjHHe/9 h7tKdgjKMVMV1FWPP8RCBIgHwShJkHgcKpLMRXuJ5QxZoXumKkYLq77FZUsGevABMI0a SUR1wZ1+zYqQMunMdRUS7EkLFfLXbw8gDd961xv/+xR/GWJYIDTx2nPYSe8nnY6HyIBt nU8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="f8U/4xKG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z21-20020a05640240d500b00435bcb8758dsi1145788edb.12.2022.06.23.15.08.35; Thu, 23 Jun 2022 15:09:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="f8U/4xKG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbiFWWGa (ORCPT + 99 others); Thu, 23 Jun 2022 18:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbiFWWG2 (ORCPT ); Thu, 23 Jun 2022 18:06:28 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C00F563A6 for ; Thu, 23 Jun 2022 15:06:24 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id by4-20020a056a00400400b005251029fd97so362135pfb.9 for ; Thu, 23 Jun 2022 15:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=KwqDl7Ku0++kd3bGbvwgzs1gT1laIcj9GIfwKObRL9E=; b=f8U/4xKGanNwrOdn737tuWhSmnZoG61m1qxfjiv5VkQ8UPtSqaWeibB404rrX79rJX Sr8EwtDegZkmDOiQT1PYLi73vlNuyK3MEO3CteMf7qrTyzJdkDqEDsqiRCNCHSPQ5OpW eesWhWqiGdmVom/8h4KWFRd14AnohMl03xMmbV6Ab1oeKOXQCzTP9OQoqz1l8U2F6/ec VlqIw1iK8+IqtbCAOHrXtiW4tOefdgMl+CoajfkyUTpBuZ8kM+4EuI/xDArQ35ySZCKy wRv8WwozJNFIjWw3i7yzruaQIY9s/ub55YNu2bl9iMISFr3cyMkNMY6hYWwYFcZJ8fYO pNYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=KwqDl7Ku0++kd3bGbvwgzs1gT1laIcj9GIfwKObRL9E=; b=DlQAta/H4ao1L1VkzZ5vVO2aPfVt8Kze9Ro9DhA/5zr9SQgpIBwxo65XxxMfMwUX0G 8Bke+pR/VqS9KH/LWEWG1qVXwcEXyfYxqZsldk7K/rh6EyIXucl0+3/p6AIumW5o2tYr WbXA/HwUpbZEpZP5USB3zawvpi+GJSRbRKv/Ozn/JFlWSJq1WGXBgqBM8X4dv7apmTaG iORQhqY219rtc8BPwqFRyztlBkYoAltehPYv1udhrj9ywhMLkV5iEGXiZBvxoeYOyqTQ WOZw/Hv5zGCF1/gctsQcfr1lfXjQkedZU7RJS1PnkUeJgeLOh7xY53aUnZfffbW1jiGS cpJA== X-Gm-Message-State: AJIora+LvgemoOsX4GVDEINlPeVBQ1+IavX+kQfA5ZQVe90/+RPMqVSK N/eSFfiXyi9It8AVVmodUOeyv9gxac8fhgO4Tw== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:ac62:20a7:e3c5:c221]) (user=kaleshsingh job=sendgmr) by 2002:a05:6a00:885:b0:510:950f:f787 with SMTP id q5-20020a056a00088500b00510950ff787mr42464806pfj.83.1656021983532; Thu, 23 Jun 2022 15:06:23 -0700 (PDT) Date: Thu, 23 Jun 2022 15:06:05 -0700 Message-Id: <20220623220613.3014268-1-kaleshsingh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v2 0/2] procfs: Add file path and size to /proc//fdinfo From: Kalesh Singh To: ckoenig.leichtzumerken@gmail.com, christian.koenig@amd.com, viro@zeniv.linux.org.uk, hch@infradead.org, stephen.s.brennan@oracle.com, David.Laight@ACULAB.COM Cc: ilkos@google.com, tjmercier@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , Jonathan Corbet , Sumit Semwal , Andrew Morton , Christoph Anton Mitterer , Johannes Weiner , Mike Rapoport , Colin Cross , Paul Gortmaker , Randy Dunlap , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, This is v2 of the fdinfo patches. The main update is adding path field only for files with anon inodes. Rebased on 5.19-rc3. The previous cover letter is copied below for convenience. Thanks, Kalesh ----------- Processes can pin shared memory by keeping a handle to it through a file descriptor; for instance dmabufs, memfd, and ashmem (in Android). In the case of a memory leak, to identify the process pinning the memory, userspace needs to: - Iterate the /proc//fd/* for each process - Do a readlink on each entry to identify the type of memory from the file path. - stat() each entry to get the size of the memory. The file permissions on /proc//fd/* only allows for the owner or root to perform the operations above; and so is not suitable for capturing the system-wide state in a production environment. This issue was addressed for dmabufs by making /proc/*/fdinfo/* accessible to a process with PTRACE_MODE_READ_FSCREDS credentials[1] To allow the same kind of tracking for other types of shared memory, add the following fields to /proc//fdinfo/: path - This allows identifying the type of memory based on common prefixes: e.g. "/memfd...", "/dmabuf...", "/dev/ashmem..." This was not an issued when dmabuf tracking was introduced because the exp_name field of dmabuf fdinfo could be used to distinguish dmabuf fds from other types. size - To track the amount of memory that is being pinned. dmabufs expose size as an additional field in fdinfo. Remove this and make it a common field for all fds. Access to /proc//fdinfo is governed by PTRACE_MODE_READ_FSCREDS -- the same as for /proc//maps which also exposes the path and size for mapped memory regions. This allows for a system process with PTRACE_MODE_READ_FSCREDS to account the pinned per-process memory via fdinfo. Kalesh Singh (2): procfs: Add 'size' to /proc//fdinfo/ procfs: Add 'path' to /proc//fdinfo/ Documentation/filesystems/proc.rst | 22 ++++++++++++++++++++-- drivers/dma-buf/dma-buf.c | 1 - fs/libfs.c | 9 +++++++++ fs/proc/fd.c | 18 ++++++++++++++---- include/linux/fs.h | 1 + 5 files changed, 44 insertions(+), 7 deletions(-) base-commit: a111daf0c53ae91e71fd2bfe7497862d14132e3e -- 2.37.0.rc0.161.g10f37bed90-goog