Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1459099
| From | Robert Foss <robert.foss@collabora.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps |
| Date | 2016-08-09 22:20 +0200 |
| Message-ID | <s4lFg-3PL-25@gated-at.bofh.it> (permalink) |
| References | <s4hLk-1pO-27@gated-at.bofh.it> <s4iel-1Aq-27@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 2016-08-09 12:29 PM, Mateusz Guzik wrote:
> On Tue, Aug 09, 2016 at 12:05:43PM -0400, robert.foss@collabora.com wrote:
>> From: Sonny Rao <sonnyrao@chromium.org>
>>
>> This is based on earlier work by Thiago Goncales. It implements a new
>> per process proc file which summarizes the contents of the smaps file
>> but doesn't display any addresses. It gives more detailed information
>> than statm like the PSS (proprotional set size). It differs from the
>> original implementation in that it doesn't use the full blown set of
>> seq operations, uses a different termination condition, and doesn't
>> displayed "Locked" as that was broken on the original implemenation.
>>
>> This new proc file provides information faster than parsing the potentially
>> huge smaps file.
>
> I have no idea about usefulness of this.
>
> The patch is definitely buggy with respect to how it implements actual
> access to mm.
>
>> +static int totmaps_proc_show(struct seq_file *m, void *data)
>> +{
>> + struct proc_maps_private *priv = m->private;
>> + struct mm_struct *mm;
>> + struct vm_area_struct *vma;
>> + struct mem_size_stats *mss_sum = priv->mss;
>> +
>> + /* reference to priv->task already taken */
>> + /* but need to get the mm here because */
>> + /* task could be in the process of exiting */
>> + mm = get_task_mm(priv->task);
>> + if (!mm || IS_ERR(mm))
>> + return -EINVAL;
>> +
>
> That's not how it's done in smaps.
Alright, I'll have to look into the difference between this approach and
the smaps one.
>
>> +static int totmaps_open(struct inode *inode, struct file *file)
>> +{
>> + struct proc_maps_private *priv;
>> + int ret = -ENOMEM;
>> + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>> + if (priv) {
>> + priv->mss = kzalloc(sizeof(*priv->mss), GFP_KERNEL);
>> + if (!priv->mss)
>> + return -ENOMEM;
>
> Cases below explicitly kfree(priv). I can't remember whether the close
> routine gets called if this one fails. Either way, something is wrong
> here.
It looks fishy to me too, I'll have it reworked in v2.
>
>> +
>> + /* we need to grab references to the task_struct */
>> + /* at open time, because there's a potential information */
>> + /* leak where the totmaps file is opened and held open */
>> + /* while the underlying pid to task mapping changes */
>> + /* underneath it */
>> + priv->task = get_pid_task(proc_pid(inode), PIDTYPE_PID);
>
> This performs no permission checks that I would see. If you take a look
> at smaps you will see the user ends up in proc_maps_open which performs
> proc_mem_open(inode, PTRACE_MODE_READ) and gets a mm from there.
The proc_maps_open() function does seem to be doing everything I need
it. I'll have a look at switching to using it.
Thanks for the heads up!
Rob.
>
>
>> + if (!priv->task) {
>> + kfree(priv->mss);
>> + kfree(priv);
>> + return -ESRCH;
>> + }
>> +
>> + ret = single_open(file, totmaps_proc_show, priv);
>> + if (ret) {
>> + put_task_struct(priv->task);
>> + kfree(priv->mss);
>> + kfree(priv);
>> + }
>> + }
>> + return ret;
>> +}
>> +
>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PACTH v1] mm, proc: Implement /proc/<pid>/totmaps robert.foss@collabora.com - 2016-08-09 18:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Mateusz Guzik <mguzik@redhat.com> - 2016-08-09 18:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-09 19:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-09 22:20 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 20:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 20:30 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Mateusz Guzik <mguzik@redhat.com> - 2016-08-10 23:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Alexey Dobriyan <adobriyan@gmail.com> - 2016-08-09 19:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-09 20:30 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Konstantin Khlebnikov <koct9i@gmail.com> - 2016-08-09 21:20 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-10 02:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-09 21:30 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-09 23:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 00:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 20:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 21:50 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 21:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 20:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 20:20 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-10 20:50 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-10 20:30 +0200
csiph-web