From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
bpf@vger.kernel.org, linux-mm@kvack.org,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Lorenzo Stoakes <ljs@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Federico Di Pierro <nierro92@gmail.com>
Subject: Re: [PATCHv3 bpf-next 2/8] bpf: Add user memory kfuncs
Date: Fri, 6 Nov 2026 14:52:18 +0100 [thread overview]
Message-ID: <au3bkmPTBnpVU-9m@krava> (raw)
In-Reply-To: <CAEf4BzY+1a8v8AHcr1AfUBR24uMitU7gEe2_1Npwp-8_kagU3w@mail.gmail.com>
On Thu, Nov 05, 2026 at 04:34:40PM -0800, Andrii Nakryiko wrote:
SNIP
> > +/**
> > + * bpf_copy_to_user() - Copy data to the current task's address space
> > + * @unsafe_ptr__ign: Destination address in the current task's address space
> > + * @src: Source address, in kernel space
> > + * @src__sz: Number of bytes to copy
> > + * @flags: Reserved for future use; must be zero
> > + *
> > + * Faults in the destination and writes the way ptrace(PTRACE_POKETEXT) does:
> > + * a private mapping doesn't have to be writable. A partial copy is not undone,
> > + * the bytes before the fault stay written.
> > + *
> > + * The caller must coordinate with other threads so they do not execute the
> > + * destination range while it is being modified, and ensure execution begins
> > + * only after the copy completes.
> > + *
> > + * Return: 0 on success, -EINVAL if @flags is non-zero, or -EFAULT if the copy
> > + * fails or is partial.
> > + */
> > +__bpf_kfunc int bpf_copy_to_user(void __user *unsafe_ptr__ign, const void *src,
> > + u32 src__sz, u64 flags)
>
> you'll eventually want bpf_copy_to_user_dynptr (we already have
> bpf_copy_from_user_dynptr), so might as well add it from the get go?
ok, might be useful will check.. will send as follow up
thanks,
jirka
>
> > +{
> > + int ret;
> > +
> > + if (unlikely(flags))
> > + return -EINVAL;
> > + if (unlikely(src__sz > S32_MAX))
> > + return -EINVAL;
> > + if (unlikely(!src__sz))
> > + return 0;
> > + ret = access_process_vm(current, (unsigned long)unsafe_ptr__ign, (void *)src,
> > + src__sz, FOLL_FORCE | FOLL_WRITE);
> > + return ret == src__sz ? 0 : -EFAULT;
> > +}
> > +
>
> [...]
next prev parent reply other threads:[~2026-11-06 13:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 10:23 [PATCHv3 bpf-next 0/8] bpf: Add user memory kfuncs Jiri Olsa
2026-11-05 10:23 ` [PATCHv3 bpf-next 1/8] bpf: Honor const on generic kfunc memory arguments Jiri Olsa
2026-11-05 10:59 ` bot+bpf-ci
2026-11-06 0:34 ` Andrii Nakryiko
2026-11-06 13:52 ` Jiri Olsa
2026-11-06 19:51 ` Andrii Nakryiko
2026-11-05 10:23 ` [PATCHv3 bpf-next 2/8] bpf: Add user memory kfuncs Jiri Olsa
2026-11-05 10:44 ` sashiko-bot
2026-11-06 0:34 ` Andrii Nakryiko
2026-11-06 13:52 ` Jiri Olsa [this message]
2026-11-05 10:23 ` [PATCHv3 bpf-next 3/8] selftests/bpf: Add get_procmap_info helper Jiri Olsa
2026-11-05 10:23 ` [PATCHv3 bpf-next 4/8] selftests/bpf: Test const kfunc memory arguments Jiri Olsa
2026-11-05 10:32 ` sashiko-bot
2026-11-05 10:23 ` [PATCHv3 bpf-next 5/8] selftests/bpf: Test user memory mmap kfuncs Jiri Olsa
2026-11-05 10:33 ` sashiko-bot
2026-11-05 10:23 ` [PATCHv3 bpf-next 6/8] selftests/bpf: Test user memory page exec Jiri Olsa
2026-11-05 10:23 ` [PATCHv3 bpf-next 7/8] selftests/bpf: Test bpf_copy_to_user kfunc Jiri Olsa
2026-11-05 10:23 ` [PATCHv3 bpf-next 8/8] selftests/bpf: Test user memory kfunc errors Jiri Olsa
2026-11-06 2:50 ` [PATCHv3 bpf-next 0/8] bpf: Add user memory kfuncs patchwork-bot+netdevbpf
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=au3bkmPTBnpVU-9m@krava \
--to=olsajiri@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=memxor@gmail.com \
--cc=nierro92@gmail.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