<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/kernel/bpf/helpers.c, branch linux-5.18.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.18.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.18.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2022-08-17T12:41:08Z</updated>
<entry>
<title>bpf: Allow storing referenced kptr in map</title>
<updated>2022-08-17T12:41:08Z</updated>
<author>
<name>Kumar Kartikeya Dwivedi</name>
</author>
<published>2022-04-24T21:48:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9c3710ac21adb6131f60602003c4c8574e7e59d5'/>
<id>urn:sha1:9c3710ac21adb6131f60602003c4c8574e7e59d5</id>
<content type='text'>
[ Upstream commit c0a5a21c25f37c9fd7b36072f9968cdff1e4aa13 ]

Extending the code in previous commits, introduce referenced kptr
support, which needs to be tagged using 'kptr_ref' tag instead. Unlike
unreferenced kptr, referenced kptr have a lot more restrictions. In
addition to the type matching, only a newly introduced bpf_kptr_xchg
helper is allowed to modify the map value at that offset. This transfers
the referenced pointer being stored into the map, releasing the
references state for the program, and returning the old value and
creating new reference state for the returned pointer.

Similar to unreferenced pointer case, return value for this case will
also be PTR_TO_BTF_ID_OR_NULL. The reference for the returned pointer
must either be eventually released by calling the corresponding release
function, otherwise it must be transferred into another map.

It is also allowed to call bpf_kptr_xchg with a NULL pointer, to clear
the value, and obtain the old value if any.

BPF_LDX, BPF_STX, and BPF_ST cannot access referenced kptr. A future
commit will permit using BPF_LDX for such pointers, but attempt at
making it safe, since the lifetime of object won't be guaranteed.

There are valid reasons to enforce the restriction of permitting only
bpf_kptr_xchg to operate on referenced kptr. The pointer value must be
consistent in face of concurrent modification, and any prior values
contained in the map must also be released before a new one is moved
into the map. To ensure proper transfer of this ownership, bpf_kptr_xchg
returns the old value, which the verifier would require the user to
either free or move into another map, and releases the reference held
for the pointer being moved in.

In the future, direct BPF_XCHG instruction may also be permitted to work
like bpf_kptr_xchg helper.

Note that process_kptr_func doesn't have to call
check_helper_mem_access, since we already disallow rdonly/wronly flags
for map, which is what check_map_access_type checks, and we already
ensure the PTR_TO_MAP_VALUE refers to kptr by obtaining its off_desc,
so check_map_access is also not required.

Signed-off-by: Kumar Kartikeya Dwivedi &lt;memxor@gmail.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220424214901.2743946-4-memxor@gmail.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Replace strncpy() with strscpy()</title>
<updated>2022-03-08T06:04:33Z</updated>
<author>
<name>Yuntao Wang</name>
</author>
<published>2022-03-04T07:04:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=03b9c7fa3f15f51bcd07f3828c2a01311e7746c4'/>
<id>urn:sha1:03b9c7fa3f15f51bcd07f3828c2a01311e7746c4</id>
<content type='text'>
Using strncpy() on NUL-terminated strings is considered deprecated[1].
Moreover, if the length of 'task-&gt;comm' is less than the destination buffer
size, strncpy() will NUL-pad the destination buffer, which is a needless
performance penalty.

Replacing strncpy() with strscpy() fixes all these issues.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Signed-off-by: Yuntao Wang &lt;ytcoode@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Acked-by: Yonghong Song &lt;yhs@fb.com&gt;
Link: https://lore.kernel.org/bpf/20220304070408.233658-1-ytcoode@gmail.com
</content>
</entry>
<entry>
<title>bpf: Cleanup comments</title>
<updated>2022-02-23T23:17:51Z</updated>
<author>
<name>Tom Rix</name>
</author>
<published>2022-02-20T18:40:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c561d11063009323a0e57c528cb1d77b7d2c41e0'/>
<id>urn:sha1:c561d11063009323a0e57c528cb1d77b7d2c41e0</id>
<content type='text'>
Add leading space to spdx tag
Use // for spdx c file comment

Replacements
resereved to reserved
inbetween to in between
everytime to every time
intutivie to intuitive
currenct to current
encontered to encountered
referenceing to referencing
upto to up to
exectuted to executed

Signed-off-by: Tom Rix &lt;trix@redhat.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Acked-by: Song Liu &lt;songliubraving@fb.com&gt;
Link: https://lore.kernel.org/bpf/20220220184055.3608317-1-trix@redhat.com
</content>
</entry>
<entry>
<title>Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net</title>
<updated>2022-02-17T20:22:28Z</updated>
<author>
<name>Jakub Kicinski</name>
</author>
<published>2022-02-17T20:22:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=93d11e0d76e3c5a8350c77d1463d9f845bdc9307'/>
<id>urn:sha1:93d11e0d76e3c5a8350c77d1463d9f845bdc9307</id>
<content type='text'>
Fast path bpf marge for some -next work.

Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Emit bpf_timer in vmlinux BTF</title>
<updated>2022-02-11T21:21:47Z</updated>
<author>
<name>Yonghong Song</name>
</author>
<published>2022-02-11T19:49:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3bd916ee0ecbbdd902fc24845f2fef332b2a310c'/>
<id>urn:sha1:3bd916ee0ecbbdd902fc24845f2fef332b2a310c</id>
<content type='text'>
Currently the following code in check_and_init_map_value()
  *(struct bpf_timer *)(dst + map-&gt;timer_off) =
      (struct bpf_timer){};
can help generate bpf_timer definition in vmlinuxBTF.
But the code above may not zero the whole structure
due to anonymour members and that code will be replaced
by memset in the subsequent patch and
bpf_timer definition will disappear from vmlinuxBTF.
Let us emit the type explicitly so bpf program can continue
to use it from vmlinux.h.

Signed-off-by: Yonghong Song &lt;yhs@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220211194948.3141529-1-yhs@fb.com
</content>
</entry>
<entry>
<title>bpf: make bpf_copy_from_user_task() gpl only</title>
<updated>2022-01-31T20:44:37Z</updated>
<author>
<name>Kenta Tada</name>
</author>
<published>2022-01-28T17:09:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0407a65f356e6d9340ad673907c17e52fade43e3'/>
<id>urn:sha1:0407a65f356e6d9340ad673907c17e52fade43e3</id>
<content type='text'>
access_process_vm() is exported by EXPORT_SYMBOL_GPL().

Signed-off-by: Kenta Tada &lt;Kenta.Tada@sony.com&gt;
Link: https://lore.kernel.org/r/20220128170906.21154-1-Kenta.Tada@sony.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Add bpf_copy_from_user_task() helper</title>
<updated>2022-01-25T03:59:27Z</updated>
<author>
<name>Kenny Yu</name>
</author>
<published>2022-01-24T18:54:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=376040e47334c6dc6a939a32197acceb00fe4acf'/>
<id>urn:sha1:376040e47334c6dc6a939a32197acceb00fe4acf</id>
<content type='text'>
This adds a helper for bpf programs to read the memory of other
tasks.

As an example use case at Meta, we are using a bpf task iterator program
and this new helper to print C++ async stack traces for all threads of
a given process.

Signed-off-by: Kenny Yu &lt;kennyyu@fb.com&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/r/20220124185403.468466-3-kennyyu@fb.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Add MEM_RDONLY for helper args that are pointers to rdonly mem.</title>
<updated>2021-12-18T21:27:41Z</updated>
<author>
<name>Hao Luo</name>
</author>
<published>2021-12-17T00:31:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=216e3cd2f28dbbf1fe86848e0e29e6693b9f0a20'/>
<id>urn:sha1:216e3cd2f28dbbf1fe86848e0e29e6693b9f0a20</id>
<content type='text'>
Some helper functions may modify its arguments, for example,
bpf_d_path, bpf_get_stack etc. Previously, their argument types
were marked as ARG_PTR_TO_MEM, which is compatible with read-only
mem types, such as PTR_TO_RDONLY_BUF. Therefore it's legitimate,
but technically incorrect, to modify a read-only memory by passing
it into one of such helper functions.

This patch tags the bpf_args compatible with immutable memory with
MEM_RDONLY flag. The arguments that don't have this flag will be
only compatible with mutable memory types, preventing the helper
from modifying a read-only memory. The bpf_args that have
MEM_RDONLY are compatible with both mutable memory and immutable
memory.

Signed-off-by: Hao Luo &lt;haoluo@google.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211217003152.48334-9-haoluo@google.com
</content>
</entry>
<entry>
<title>bpf: Make per_cpu_ptr return rdonly PTR_TO_MEM.</title>
<updated>2021-12-18T21:27:41Z</updated>
<author>
<name>Hao Luo</name>
</author>
<published>2021-12-17T00:31:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=34d3a78c681e8e7844b43d1a2f4671a04249c821'/>
<id>urn:sha1:34d3a78c681e8e7844b43d1a2f4671a04249c821</id>
<content type='text'>
Tag the return type of {per, this}_cpu_ptr with RDONLY_MEM. The
returned value of this pair of helpers is kernel object, which
can not be updated by bpf programs. Previously these two helpers
return PTR_OT_MEM for kernel objects of scalar type, which allows
one to directly modify the memory. Now with RDONLY_MEM tagging,
the verifier will reject programs that write into RDONLY_MEM.

Fixes: 63d9b80dcf2c ("bpf: Introducte bpf_this_cpu_ptr()")
Fixes: eaa6bcb71ef6 ("bpf: Introduce bpf_per_cpu_ptr()")
Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id")
Signed-off-by: Hao Luo &lt;haoluo@google.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211217003152.48334-8-haoluo@google.com
</content>
</entry>
<entry>
<title>bpf: Replace RET_XXX_OR_NULL with RET_XXX | PTR_MAYBE_NULL</title>
<updated>2021-12-18T20:48:08Z</updated>
<author>
<name>Hao Luo</name>
</author>
<published>2021-12-17T00:31:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3c4807322660d4290ac9062c034aed6b87243861'/>
<id>urn:sha1:3c4807322660d4290ac9062c034aed6b87243861</id>
<content type='text'>
We have introduced a new type to make bpf_ret composable, by
reserving high bits to represent flags.

One of the flag is PTR_MAYBE_NULL, which indicates a pointer
may be NULL. When applying this flag to ret_types, it means
the returned value could be a NULL pointer. This patch
switches the qualified arg_types to use this flag.
The ret_types changed in this patch include:

1. RET_PTR_TO_MAP_VALUE_OR_NULL
2. RET_PTR_TO_SOCKET_OR_NULL
3. RET_PTR_TO_TCP_SOCK_OR_NULL
4. RET_PTR_TO_SOCK_COMMON_OR_NULL
5. RET_PTR_TO_ALLOC_MEM_OR_NULL
6. RET_PTR_TO_MEM_OR_BTF_ID_OR_NULL
7. RET_PTR_TO_BTF_ID_OR_NULL

This patch doesn't eliminate the use of these names, instead
it makes them aliases to 'RET_PTR_TO_XXX | PTR_MAYBE_NULL'.

Signed-off-by: Hao Luo &lt;haoluo@google.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20211217003152.48334-4-haoluo@google.com
</content>
</entry>
</feed>
