From: Jordan Rome <linux@jordanrome.com>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
bpf@vger.kernel.org, linux-mm@kvack.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Kernel Team <kernel-team@fb.com>,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Potapenko <glider@google.com>
Subject: Re: [bpf-next v7 1/3] mm: add copy_remote_vm_str
Date: Wed, 12 Feb 2025 12:33:47 -0500 [thread overview]
Message-ID: <CA+QiOd5xgBkcfwHq_C+fvLvtWbc_SUjOp9GNsZRm=9OPHyto8w@mail.gmail.com> (raw)
In-Reply-To: <mvrphlxx4r5mj7cmzsvmx3v6wcuo3pvjpfb5sva2jcmh34ye2p@dzfxxaymvnk3>
On Tue, Feb 11, 2025 at 9:19 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
>
> On Tue, Feb 11, 2025 at 02:07:31PM -0800, Andrii Nakryiko wrote:
> > On Mon, Feb 10, 2025 at 2:23 PM Jordan Rome <linux@jordanrome.com> wrote:
> > >
> > > Similar to `access_process_vm` but specific to strings.
> > > Also chunks reads by page and utilizes `strscpy`
> > > for handling null termination.
> > >
> > > Signed-off-by: Jordan Rome <linux@jordanrome.com>
> > > ---
> > > include/linux/mm.h | 3 ++
> > > mm/memory.c | 119 +++++++++++++++++++++++++++++++++++++++++++++
> > > mm/nommu.c | 73 +++++++++++++++++++++++++++
> > > 3 files changed, 195 insertions(+)
> > >
> > > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > > index 7b1068ddcbb7..aee23d84ce01 100644
> > > --- a/include/linux/mm.h
> > > +++ b/include/linux/mm.h
> > > @@ -2486,6 +2486,9 @@ extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
> > > extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
> > > void *buf, int len, unsigned int gup_flags);
> > >
> > > +extern int copy_remote_vm_str(struct task_struct *tsk, unsigned long addr,
> > > + void *buf, int len, unsigned int gup_flags);
> > > +
> > > long get_user_pages_remote(struct mm_struct *mm,
> > > unsigned long start, unsigned long nr_pages,
> > > unsigned int gup_flags, struct page **pages,
> > > diff --git a/mm/memory.c b/mm/memory.c
> > > index 539c0f7c6d54..e9d8584a7f56 100644
> > > --- a/mm/memory.c
> > > +++ b/mm/memory.c
> > > @@ -6803,6 +6803,125 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr,
> > > }
> > > EXPORT_SYMBOL_GPL(access_process_vm);
> > >
> > > +/*
> > > + * Copy a string from another process's address space as given in mm.
> > > + * If there is any error return -EFAULT.
> > > + */
> > > +static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr,
> > > + void *buf, int len, unsigned int gup_flags)
> > > +{
> > > + void *old_buf = buf;
> > > + int err = 0;
> > > +
> > > + *(char *)buf = '\0';
> >
> > LGTM overall:
> >
> > Acked-by: Andrii Nakryiko <andrii@kernel.org>
> >
> > But note that all this unconditional buf access will be incorrect if
> > len == 0. So either all of that has to be guarded with `if (len)`,
> > just dropped, or declared unsupported, depending on what mm folks
> > think. BPF helper won't ever call with len == 0, so that's why my ack.
>
> I think early return 0 on len == 0 should be fine.
Ack.
next prev parent reply other threads:[~2025-02-12 17:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 22:16 Jordan Rome
2025-02-10 22:16 ` [bpf-next v7 2/3] bpf: Add bpf_copy_from_user_task_str kfunc Jordan Rome
2025-02-10 22:16 ` [bpf-next v7 3/3] selftests/bpf: Add tests for bpf_copy_from_user_task_str Jordan Rome
2025-02-11 22:07 ` [bpf-next v7 1/3] mm: add copy_remote_vm_str Andrii Nakryiko
2025-02-12 2:19 ` Shakeel Butt
2025-02-12 17:33 ` Jordan Rome [this message]
2025-02-12 22:25 ` Shakeel Butt
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='CA+QiOd5xgBkcfwHq_C+fvLvtWbc_SUjOp9GNsZRm=9OPHyto8w@mail.gmail.com' \
--to=linux@jordanrome.com \
--cc=akpm@linux-foundation.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=glider@google.com \
--cc=kernel-team@fb.com \
--cc=linux-mm@kvack.org \
--cc=shakeel.butt@linux.dev \
/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