<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/bpf/syscall.c, branch v5.7</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v5.7</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v5.7'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2020-05-21T03:21:53Z</updated>
<entry>
<title>bpf: Prevent mmap()'ing read-only maps as writable</title>
<updated>2020-05-21T03:21:53Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andriin@fb.com</email>
</author>
<published>2020-05-19T05:38:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=dfeb376dd4cb2c5004aeb625e2475f58a5ff2ea7'/>
<id>urn:sha1:dfeb376dd4cb2c5004aeb625e2475f58a5ff2ea7</id>
<content type='text'>
As discussed in [0], it's dangerous to allow mapping BPF map, that's meant to
be frozen and is read-only on BPF program side, because that allows user-space
to actually store a writable view to the page even after it is frozen. This is
exacerbated by BPF verifier making a strong assumption that contents of such
frozen map will remain unchanged. To prevent this, disallow mapping
BPF_F_RDONLY_PROG mmap()'able BPF maps as writable, ever.

  [0] https://lore.kernel.org/bpf/CAEf4BzYGWYhXdp6BJ7_=9OQPJxQpgug080MMjdSB72i9R+5c6g@mail.gmail.com/

Fixes: fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
Suggested-by: Jann Horn &lt;jannh@google.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Reviewed-by: Jann Horn &lt;jannh@google.com&gt;
Link: https://lore.kernel.org/bpf/20200519053824.1089415-1-andriin@fb.com
</content>
</entry>
<entry>
<title>bpf: Fix error return code in map_lookup_and_delete_elem()</title>
<updated>2020-04-30T14:19:08Z</updated>
<author>
<name>Wei Yongjun</name>
<email>weiyongjun1@huawei.com</email>
</author>
<published>2020-04-30T08:18:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7f645462ca01d01abb94d75e6768c8b3ed3a188b'/>
<id>urn:sha1:7f645462ca01d01abb94d75e6768c8b3ed3a188b</id>
<content type='text'>
Fix to return negative error code -EFAULT from the copy_to_user() error
handling case instead of 0, as done elsewhere in this function.

Fixes: bd513cd08f10 ("bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall")
Signed-off-by: Wei Yongjun &lt;weiyongjun1@huawei.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20200430081851.166996-1-weiyongjun1@huawei.com
</content>
</entry>
<entry>
<title>bpf: Make bpf_link_fops static</title>
<updated>2020-04-25T00:42:44Z</updated>
<author>
<name>Zou Wei</name>
<email>zou_wei@huawei.com</email>
</author>
<published>2020-04-23T02:32:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=6f302bfb221470e712ce3e5911fb83cdca174387'/>
<id>urn:sha1:6f302bfb221470e712ce3e5911fb83cdca174387</id>
<content type='text'>
Fix the following sparse warning:

kernel/bpf/syscall.c:2289:30: warning: symbol 'bpf_link_fops' was not declared. Should it be static?

Reported-by: Hulk Robot &lt;hulkci@huawei.com&gt;
Signed-off-by: Zou Wei &lt;zou_wei@huawei.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Link: https://lore.kernel.org/bpf/1587609160-117806-1-git-send-email-zou_wei@huawei.com
</content>
</entry>
<entry>
<title>bpf: Fix leak in LINK_UPDATE and enforce empty old_prog_fd</title>
<updated>2020-04-25T00:27:02Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andriin@fb.com</email>
</author>
<published>2020-04-24T05:20:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4adb7a4a151c65ac7e9c3a1aa462c84190d48385'/>
<id>urn:sha1:4adb7a4a151c65ac7e9c3a1aa462c84190d48385</id>
<content type='text'>
Fix bug of not putting bpf_link in LINK_UPDATE command.
Also enforce zeroed old_prog_fd if no BPF_F_REPLACE flag is specified.

Signed-off-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20200424052045.4002963-1-andriin@fb.com
</content>
</entry>
<entry>
<title>bpf: Prevent re-mmap()'ing BPF map as writable for initially r/o mapping</title>
<updated>2020-04-14T19:28:57Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andriin@fb.com</email>
</author>
<published>2020-04-10T20:26:12Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1f6cb19be2e231fe092f40decb71f066eba090d7'/>
<id>urn:sha1:1f6cb19be2e231fe092f40decb71f066eba090d7</id>
<content type='text'>
VM_MAYWRITE flag during initial memory mapping determines if already mmap()'ed
pages can be later remapped as writable ones through mprotect() call. To
prevent user application to rewrite contents of memory-mapped as read-only and
subsequently frozen BPF map, remove VM_MAYWRITE flag completely on initially
read-only mapping.

Alternatively, we could treat any memory-mapping on unfrozen map as writable
and bump writecnt instead. But there is little legitimate reason to map
BPF map as read-only and then re-mmap() it as writable through mprotect(),
instead of just mmap()'ing it as read/write from the very beginning.

Also, at the suggestion of Jann Horn, drop unnecessary refcounting in mmap
operations. We can just rely on VMA holding reference to BPF map's file
properly.

Fixes: fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
Reported-by: Jann Horn &lt;jannh@google.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Reviewed-by: Jann Horn &lt;jannh@google.com&gt;
Link: https://lore.kernel.org/bpf/20200410202613.3679837-1-andriin@fb.com
</content>
</entry>
<entry>
<title>Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next</title>
<updated>2020-03-31T02:52:37Z</updated>
<author>
<name>David S. Miller</name>
<email>davem@davemloft.net</email>
</author>
<published>2020-03-31T02:52:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ed52f2c608c9451fa2bad298b2ab927416105d65'/>
<id>urn:sha1:ed52f2c608c9451fa2bad298b2ab927416105d65</id>
<content type='text'>
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>bpf: Implement bpf_prog replacement for an active bpf_cgroup_link</title>
<updated>2020-03-31T00:36:33Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andriin@fb.com</email>
</author>
<published>2020-03-30T02:59:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0c991ebc8c69d29b7fc44db17075c5aa5253e2ab'/>
<id>urn:sha1:0c991ebc8c69d29b7fc44db17075c5aa5253e2ab</id>
<content type='text'>
Add new operation (LINK_UPDATE), which allows to replace active bpf_prog from
under given bpf_link. Currently this is only supported for bpf_cgroup_link,
but will be extended to other kinds of bpf_links in follow-up patches.

For bpf_cgroup_link, implemented functionality matches existing semantics for
direct bpf_prog attachment (including BPF_F_REPLACE flag). User can either
unconditionally set new bpf_prog regardless of which bpf_prog is currently
active under given bpf_link, or, optionally, can specify expected active
bpf_prog. If active bpf_prog doesn't match expected one, no changes are
performed, old bpf_link stays intact and attached, operation returns
a failure.

cgroup_bpf_replace() operation is resolving race between auto-detachment and
bpf_prog update in the same fashion as it's done for bpf_link detachment,
except in this case update has no way of succeeding because of target cgroup
marked as dying. So in this case error is returned.

Signed-off-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20200330030001.2312810-3-andriin@fb.com
</content>
</entry>
<entry>
<title>bpf: Implement bpf_link-based cgroup BPF program attachment</title>
<updated>2020-03-31T00:35:59Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andriin@fb.com</email>
</author>
<published>2020-03-30T02:59:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=af6eea57437a830293eab56246b6025cc7d46ee7'/>
<id>urn:sha1:af6eea57437a830293eab56246b6025cc7d46ee7</id>
<content type='text'>
Implement new sub-command to attach cgroup BPF programs and return FD-based
bpf_link back on success. bpf_link, once attached to cgroup, cannot be
replaced, except by owner having its FD. Cgroup bpf_link supports only
BPF_F_ALLOW_MULTI semantics. Both link-based and prog-based BPF_F_ALLOW_MULTI
attachments can be freely intermixed.

To prevent bpf_cgroup_link from keeping cgroup alive past the point when no
BPF program can be executed, implement auto-detachment of link. When
cgroup_bpf_release() is called, all attached bpf_links are forced to release
cgroup refcounts, but they leave bpf_link otherwise active and allocated, as
well as still owning underlying bpf_prog. This is because user-space might
still have FDs open and active, so bpf_link as a user-referenced object can't
be freed yet. Once last active FD is closed, bpf_link will be freed and
underlying bpf_prog refcount will be dropped. But cgroup refcount won't be
touched, because cgroup is released already.

The inherent race between bpf_cgroup_link release (from closing last FD) and
cgroup_bpf_release() is resolved by both operations taking cgroup_mutex. So
the only additional check required is when bpf_cgroup_link attempts to detach
itself from cgroup. At that time we need to check whether there is still
cgroup associated with that link. And if not, exit with success, because
bpf_cgroup_link was already successfully detached.

Signed-off-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Roman Gushchin &lt;guro@fb.com&gt;
Link: https://lore.kernel.org/bpf/20200330030001.2312810-2-andriin@fb.com
</content>
</entry>
<entry>
<title>Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net</title>
<updated>2020-03-30T04:25:29Z</updated>
<author>
<name>David S. Miller</name>
<email>davem@davemloft.net</email>
</author>
<published>2020-03-30T04:25:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f0b5989745c3e0e92424d36869a97e4e8df7ab13'/>
<id>urn:sha1:f0b5989745c3e0e92424d36869a97e4e8df7ab13</id>
<content type='text'>
Minor comment conflict in mac80211.

Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>bpf: lsm: Implement attach, detach and execution</title>
<updated>2020-03-29T23:34:00Z</updated>
<author>
<name>KP Singh</name>
<email>kpsingh@google.com</email>
</author>
<published>2020-03-29T00:43:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9e4e01dfd3254c7f04f24b7c6b29596bc12332f3'/>
<id>urn:sha1:9e4e01dfd3254c7f04f24b7c6b29596bc12332f3</id>
<content type='text'>
JITed BPF programs are dynamically attached to the LSM hooks
using BPF trampolines. The trampoline prologue generates code to handle
conversion of the signature of the hook to the appropriate BPF context.

The allocated trampoline programs are attached to the nop functions
initialized as LSM hooks.

BPF_PROG_TYPE_LSM programs must have a GPL compatible license and
and need CAP_SYS_ADMIN (required for loading eBPF programs).

Upon attachment:

* A BPF fexit trampoline is used for LSM hooks with a void return type.
* A BPF fmod_ret trampoline is used for LSM hooks which return an
  int. The attached programs can override the return value of the
  bpf LSM hook to indicate a MAC Policy decision.

Signed-off-by: KP Singh &lt;kpsingh@google.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Reviewed-by: Brendan Jackman &lt;jackmanb@google.com&gt;
Reviewed-by: Florent Revest &lt;revest@google.com&gt;
Acked-by: Andrii Nakryiko &lt;andriin@fb.com&gt;
Acked-by: James Morris &lt;jamorris@linux.microsoft.com&gt;
Link: https://lore.kernel.org/bpf/20200329004356.27286-5-kpsingh@chromium.org
</content>
</entry>
</feed>
