From: Andrei Vagin <avagin@virtuozzo.com>
To: Jann Horn <jannh@google.com>
Cc: Andrei Vagin <avagin@openvz.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org,
kernel list <linux-kernel@vger.kernel.org>,
Linux API <linux-api@vger.kernel.org>,
linux-arch <linux-arch@vger.kernel.org>,
criu@openvz.org, Arnd Bergmann <arnd@arndb.de>,
Pavel Emelyanov <xemul@virtuozzo.com>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] [RFC] vm: add a syscall to map a process memory into a pipe
Date: Fri, 11 Aug 2017 23:10:49 -0700 [thread overview]
Message-ID: <20170812061048.GA31744@outlook.office365.com> (raw)
In-Reply-To: <CAG48ez2Q+rTWUB_VfLhCFvawXLigpJXVxoNgZ28UhS+vHu_vdg@mail.gmail.com>
On Thu, Aug 10, 2017 at 09:42:44PM +0200, Jann Horn wrote:
> On Thu, Aug 10, 2017 at 8:46 PM, Andrei Vagin <avagin@openvz.org> wrote:
> > It is a hybrid of process_vm_readv() and vmsplice().
> >
> > vmsplice can map memory from a current address space into a pipe.
> > process_vm_readv can read memory of another process.
> [...]
> > +/*
> > + * Map pages from a specified task into a pipe
> > + */
> > +static int remote_single_vec_to_pipe(struct task_struct *task,
> > + struct mm_struct *mm,
> > + const struct iovec *rvec,
> > + struct pipe_inode_info *pipe,
> > + unsigned int flags,
> > + size_t *total)
> > +{
> > + struct pipe_buffer buf = {
> > + .ops = &user_page_pipe_buf_ops,
> > + .flags = flags
> > + };
> [...]
> > + while (nr_pages) {
> [...]
> > + /*
> > + * Get the pages we're interested in. We must
> > + * access remotely because task/mm might not
> > + * current/current->mm
> > + */
> > + down_read(&mm->mmap_sem);
> > + pages = get_user_pages_remote(task, mm, pa, pages, flags,
> > + process_pages, NULL, &locked);
>
> This fifth "flags" argument of get_user_pages_remote() should contain
> GUP flags (FOLL_*), but it looks like you're actually passing in 0 or
> PIPE_BUF_FLAG_GIFT, which will be interpreted as FOLL_GET?
> (See the snippets quoted below.) This looks like a bug.
>
> Maybe use a more meaningful variable name than "flags".
Good catch. I will fix and rename the variable. get_user_pages_remote
has to be called with zero flags here. Thank you.
>
> > +static ssize_t remote_iovec_to_pipe(struct task_struct *task,
> > + struct mm_struct *mm,
> > + const struct iovec *rvec,
> > + unsigned long riovcnt,
> > + struct pipe_inode_info *pipe,
> > + unsigned int flags)
> > +{
> [...]
> > + ret = remote_single_vec_to_pipe(
> > + task, mm, &rvec[i], pipe, flags, &total);
> [...]
> > +}
> > +
> > +static long process_vmsplice_to_pipe(struct task_struct *task,
> > + struct mm_struct *mm, struct file *file,
> > + const struct iovec __user *uiov,
> > + unsigned long nr_segs, unsigned int flags)
> > +{
> [...]
> > + unsigned int buf_flag = 0;
> [...]
> > + if (flags & SPLICE_F_GIFT)
> > + buf_flag = PIPE_BUF_FLAG_GIFT;
> [...]
> > + if (!ret)
> > + ret = remote_iovec_to_pipe(task, mm, iov,
> > + nr_segs, pipe, buf_flag);
> [...]
> > +}
next prev parent reply other threads:[~2017-08-12 6:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-10 18:46 [PATCH] [RFC] vm: add a syscall to map a process memory into a pipe Andrei Vagin
2017-08-10 18:46 ` Andrei Vagin
2017-08-10 19:42 ` Jann Horn
2017-08-10 19:42 ` Jann Horn
2017-08-12 6:10 ` Andrei Vagin [this message]
2017-08-12 6:10 ` Andrei Vagin
2017-10-30 12:47 ` Michael Kerrisk (man-pages)
2017-10-30 12:47 ` Michael Kerrisk (man-pages)
2017-11-01 17:47 ` Andrei Vagin
2017-11-01 17:47 ` Andrei Vagin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170812061048.GA31744@outlook.office365.com \
--to=avagin@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=avagin@openvz.org \
--cc=criu@openvz.org \
--cc=jannh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=xemul@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox