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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 45281C433E9 for ; Mon, 8 Mar 2021 18:07:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F263652B3 for ; Mon, 8 Mar 2021 18:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbhCHSHT (ORCPT ); Mon, 8 Mar 2021 13:07:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbhCHSG6 (ORCPT ); Mon, 8 Mar 2021 13:06:58 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61AA5C06174A for ; Mon, 8 Mar 2021 10:06:58 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id x7-20020a17090a2b07b02900c0ea793940so3441111pjc.2 for ; Mon, 08 Mar 2021 10:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=FCoQQe6qSwrfqgd3qEOzXrTKGrS+9FdkbkwaZQjnWyA=; b=EImqdiUBJ+tprda7YfqaWhFRqDVz9ryw95HyqpXC0QRJ4ftaPtJxP8os21xT2W2TQZ V2j8GSarAekfSwUNCFK789tuU7oip9UPXlsiNTQ4xvMy/qIYJhDBTY7sRsIt2753feRw L8vVCms/mHMOg0yZQ9FDiarWQJcqPNQD7jOE/CiVvxOXtmc2M770kj3WIy8IQlWjbPmM Wkhb9Nvf5idJEVxtm4JLgxyDdtRuTwvPF7XjXr4jxkIN7w6ANq4YXouEQy8Azb+tHorr buNi3nasxHrRRyQzrDf4maTsMx4EHSvtFfmPsO3j8b3wRiK+4EMkw/cRN3G4e8SD9Hid znZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=FCoQQe6qSwrfqgd3qEOzXrTKGrS+9FdkbkwaZQjnWyA=; b=jYRVzVdqvlE2lQgHnS7TFMXYtqvm8y6BO8hdi+Cuty4Z6qpt7yWgLeC4SSRH5/0uV7 k0MItEc3HQmjpCXsxgW++rCkncrvMBzS8PW/TQlYXbaECXMyQKAz+N8SCKctBeZW7W2z F+VgVSjj51d7uE8lSSWDyLhzO5ST2s+UCFu5siynGgRbVC6RT7rfzjF8/apfoyeFovE8 YFPYOkq2MXRg/H3RnPas0HWUv+px4mCGaCz3jSauaHfguHPhOSf40zDtTgC4UTMWBINr TEM3JJZswbHHPKuZrKIGyAKNfnk1YCPUoBDa9K3kGHeewZ0vWrxzRNYCvR+XvhKr9SPo 8W/Q== X-Gm-Message-State: AOAM531mTSgQQ56vBsU5z9HcTGzDyzzPWG3llvqHYQrL6/LpkGIgK+dF /a+kurTeTzU15ZGH8E1wESTjwlUoV1dmxqmtUbaZyQ== X-Google-Smtp-Source: ABdhPJwe1qAb01loXOzfjJCGx8c9J7P5S+jvM49t5+56HOWkG3JPGL9lKnVzP5Un8wfNpsZg0qMqUcFs4j5Vsyjgdk8= X-Received: by 2002:a17:90a:c918:: with SMTP id v24mr82113pjt.182.1615226817785; Mon, 08 Mar 2021 10:06:57 -0800 (PST) MIME-Version: 1.0 References: <20210308170651.919148-1-kaleshsingh@google.com> In-Reply-To: From: Kalesh Singh Date: Mon, 8 Mar 2021 13:06:46 -0500 Message-ID: Subject: Re: [RESEND PATCH v6 1/2] procfs: Allow reading fdinfo with PTRACE_MODE_READ To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Jann Horn , Jeffrey Vander Stoep , Kees Cook , Suren Baghdasaryan , Minchan Kim , Hridya Valsaraju , Randy Dunlap , Matthew Wilcox , Alexander Viro , "Cc: Android Kernel" , Alexey Dobriyan , Jonathan Corbet , Andrew Morton , Mauro Carvalho Chehab , Michal Hocko , Alexey Gladkov , Szabolcs Nagy , "Eric W. Biederman" , Christian Brauner , Michel Lespinasse , Bernd Edlinger , Andrei Vagin , Helge Deller , James Morris , LKML , linux-fsdevel , "open list:DOCUMENTATION" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 8, 2021 at 12:54 PM Christian K=C3=B6nig wrote: > > Am 08.03.21 um 18:06 schrieb Kalesh Singh: > > Android captures per-process system memory state when certain low memor= y > > events (e.g a foreground app kill) occur, to identify potential memory > > hoggers. In order to measure how much memory a process actually consume= s, > > it is necessary to include the DMA buffer sizes for that process in the > > memory accounting. Since the handle to DMA buffers are raw FDs, it is > > important to be able to identify which processes have FD references to > > a DMA buffer. > > > > Currently, DMA buffer FDs can be accounted using /proc//fd/* and > > /proc//fdinfo -- both are only readable by the process owner, > > as follows: > > 1. Do a readlink on each FD. > > 2. If the target path begins with "/dmabuf", then the FD is a dmabuf= FD. > > 3. stat the file to get the dmabuf inode number. > > 4. Read/ proc//fdinfo/, to get the DMA buffer size. > > > > Accessing other processes' fdinfo requires root privileges. This limits > > the use of the interface to debugging environments and is not suitable > > for production builds. Granting root privileges even to a system proce= ss > > increases the attack surface and is highly undesirable. > > > > Since fdinfo doesn't permit reading process memory and manipulating > > process state, allow accessing fdinfo under PTRACE_MODE_READ_FSCRED. > > > > Suggested-by: Jann Horn > > Signed-off-by: Kalesh Singh > > Both patches are Acked-by: Christian K=C3=B6nig Thanks Christian. > > > --- > > Hi everyone, > > > > The initial posting of this patch can be found at [1]. > > I didn't receive any feedback last time, so resending here. > > Would really appreciate any constructive comments/suggestions. > > > > Thanks, > > Kalesh > > > > [1] https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2= Flore.kernel.org%2Fr%2F20210208155315.1367371-1-kaleshsingh%40google.com%2F= &data=3D04%7C01%7Cchristian.koenig%40amd.com%7C38c98420f0564e15117f08d8= e2549ff5%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637508200431130855%7C= Unknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiL= CJXVCI6Mn0%3D%7C1000&sdata=3DdeJBlAk6%2BEQkfAC8iRK95xhV1%2FiO9Si%2Bylc5= Z0QzzrM%3D&reserved=3D0 > > > > Changes in v2: > > - Update patch description > > fs/proc/base.c | 4 ++-- > > fs/proc/fd.c | 15 ++++++++++++++- > > 2 files changed, 16 insertions(+), 3 deletions(-) > > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > > index 3851bfcdba56..fd46d8dd0cf4 100644 > > --- a/fs/proc/base.c > > +++ b/fs/proc/base.c > > @@ -3159,7 +3159,7 @@ static const struct pid_entry tgid_base_stuff[] = =3D { > > DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, pr= oc_task_operations), > > DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc= _fd_operations), > > DIR("map_files", S_IRUSR|S_IXUSR, proc_map_files_inode_operation= s, proc_map_files_operations), > > - DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, = proc_fdinfo_operations), > > + DIR("fdinfo", S_IRUGO|S_IXUGO, proc_fdinfo_inode_operations, = proc_fdinfo_operations), > > DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, = proc_ns_dir_operations), > > #ifdef CONFIG_NET > > DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, pro= c_net_operations), > > @@ -3504,7 +3504,7 @@ static const struct inode_operations proc_tid_com= m_inode_operations =3D { > > */ > > static const struct pid_entry tid_base_stuff[] =3D { > > DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_= fd_operations), > > - DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, p= roc_fdinfo_operations), > > + DIR("fdinfo", S_IRUGO|S_IXUGO, proc_fdinfo_inode_operations, p= roc_fdinfo_operations), > > DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, p= roc_ns_dir_operations), > > #ifdef CONFIG_NET > > DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, pro= c_net_operations), > > diff --git a/fs/proc/fd.c b/fs/proc/fd.c > > index 07fc4fad2602..6a80b40fd2fe 100644 > > --- a/fs/proc/fd.c > > +++ b/fs/proc/fd.c > > @@ -6,6 +6,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -72,6 +73,18 @@ static int seq_show(struct seq_file *m, void *v) > > > > static int seq_fdinfo_open(struct inode *inode, struct file *file) > > { > > + bool allowed =3D false; > > + struct task_struct *task =3D get_proc_task(inode); > > + > > + if (!task) > > + return -ESRCH; > > + > > + allowed =3D ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS); > > + put_task_struct(task); > > + > > + if (!allowed) > > + return -EACCES; > > + > > return single_open(file, seq_show, inode); > > } > > > > @@ -308,7 +321,7 @@ static struct dentry *proc_fdinfo_instantiate(struc= t dentry *dentry, > > struct proc_inode *ei; > > struct inode *inode; > > > > - inode =3D proc_pid_make_inode(dentry->d_sb, task, S_IFREG | S_IRU= SR); > > + inode =3D proc_pid_make_inode(dentry->d_sb, task, S_IFREG | S_IRU= GO); > > if (!inode) > > return ERR_PTR(-ENOENT); > > > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >