Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1952028pxb; Mon, 8 Mar 2021 10:08:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeatyfYjip9Qo6JpM9TIiUoSGjCVQtaFYJDqS6DWk8P5vs1YTJXuLY9w/T0aY8CKMKY+Zf X-Received: by 2002:a17:906:d94:: with SMTP id m20mr15927939eji.511.1615226928097; Mon, 08 Mar 2021 10:08:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615226928; cv=none; d=google.com; s=arc-20160816; b=DAfkYE6XKgevOHsKsUWqj0jxNucfiptn/ed1V26x8sM6zoMsm3oLi+ysvWyVNeOvJY z/ztlhFol8mob3vu4cdLvu2v+8QdabsnUbuBCKkCX9xdqetKIk8p9muxvc/l2K838rQi +XYxkEcFTB9UMP+wkDffj3HfNjWKJ2Af11bdWETT9RBrveNkhiPXjO/QsUTzcFVJ2SVB VStHUlpM7ISaxo+ZPyhOtXW+NVWOVanrN/c5Yqk8hFDxNzp9Qy9m//j1OyKsPY/hlKHP z+QWTbLWITqDY2UVdx2JqhpMEZ90ClGPudUx8MaoUtVhSC14GLe+kwvU6+YK5KXgC8X+ SKjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=FCoQQe6qSwrfqgd3qEOzXrTKGrS+9FdkbkwaZQjnWyA=; b=Mkt62ub8rLKtgnUgOtjFLw6vp1hQLYxCqfjPRdFGVIig44f+v8zTJ9NUyMXwFDQo7Y a7zE+dzZ8+DJF1fCakIiVvB+OL4FQcRA645P3nh6kjBjQT/vqUEGyR+qzvvxHfYTLCyG J8vGuvZpeMZ8+DdgwD1g8qS3k4Xft4/RfrvGhgmQsimI9UHznZ3F9SMjvjbw0i1D7lfY eyOynaTAHE8hH2ObU9wTmNNZkjkIQcjprPcywBvNl3I5+kLlAaUphAZDO/m4yRF5lr5B 5l9pSq/QiOFfs0CBnyh5+v7NuDY8A4eldn2oVeocRyUXDA4Lu8IBdZ1+I3MSzG1IFOvj t7nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EImqdiUB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co24si7344893edb.599.2021.03.08.10.08.18; Mon, 08 Mar 2021 10:08:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EImqdiUB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230286AbhCHSHS (ORCPT + 99 others); Mon, 8 Mar 2021 13:07:18 -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-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. >