1. 18 7月, 2023 2 次提交
  2. 16 7月, 2023 1 次提交
    • Z
      bpf, sockops: Enhance the return capability of sockops · 01d81b16
      zhang-mingyi66 提交于
      hulk inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I7LE1H
      
      ----------------------------------------------------
      
      Since commit 2585cd62 ("bpf: Only reply field should be writeable"),
      sockops is not allowd to modify the replylong field except replylong[0].
      The reason is that the replylong[1] to replylong[3] field is not used
      at that time.
      
      But in actual use, we can call `BPF_CGROUP_RUN_PROG_SOCK_OPS` in the
      kernel modules and expect sockops to return some useful data.
      
      The design comment about bpf_sock_ops::replylong in
      include/uapi/linux/bpf.h is described as follows:
      
      ```
        struct bpf_sock_ops {
              __u32 op;
              union {
                      __u32 args[4];          /* Optionally passed to bpf program */
                      __u32 reply;            /* Returned by bpf program          */
                      __u32 replylong[4];     /* Optioznally returned by bpf prog  */
              };
        ...
      ```
      
      It seems to contradict the purpose for which the field was originally
      designed. Let's remove this restriction.
      
      Fixes: 2585cd62 ("bpf: Only reply field should be writeable")
      Signed-off-by: Nzhang-mingyi66 <zhangmingyi5@huawei.com>
      01d81b16
  3. 15 7月, 2023 1 次提交
  4. 22 4月, 2023 1 次提交
  5. 18 4月, 2023 1 次提交
  6. 05 4月, 2023 3 次提交
  7. 22 3月, 2023 1 次提交
  8. 21 3月, 2023 1 次提交
  9. 15 3月, 2023 1 次提交
  10. 04 3月, 2023 1 次提交
  11. 03 3月, 2023 1 次提交
  12. 02 3月, 2023 3 次提交
    • J
      bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr · 66e3a13e
      Joanne Koong 提交于
      Two new kfuncs are added, bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
      The user must pass in a buffer to store the contents of the data slice
      if a direct pointer to the data cannot be obtained.
      
      For skb and xdp type dynptrs, these two APIs are the only way to obtain
      a data slice. However, for other types of dynptrs, there is no
      difference between bpf_dynptr_slice(_rdwr) and bpf_dynptr_data.
      
      For skb type dynptrs, the data is copied into the user provided buffer
      if any of the data is not in the linear portion of the skb. For xdp type
      dynptrs, the data is copied into the user provided buffer if the data is
      between xdp frags.
      
      If the skb is cloned and a call to bpf_dynptr_data_rdwr is made, then
      the skb will be uncloned (see bpf_unclone_prologue()).
      
      Please note that any bpf_dynptr_write() automatically invalidates any prior
      data slices of the skb dynptr. This is because the skb may be cloned or
      may need to pull its paged buffer into the head. As such, any
      bpf_dynptr_write() will automatically have its prior data slices
      invalidated, even if the write is to data in the skb head of an uncloned
      skb. Please note as well that any other helper calls that change the
      underlying packet buffer (eg bpf_skb_pull_data()) invalidates any data
      slices of the skb dynptr as well, for the same reasons.
      Signed-off-by: NJoanne Koong <joannelkoong@gmail.com>
      Link: https://lore.kernel.org/r/20230301154953.641654-10-joannelkoong@gmail.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      66e3a13e
    • J
      bpf: Add xdp dynptrs · 05421aec
      Joanne Koong 提交于
      Add xdp dynptrs, which are dynptrs whose underlying pointer points
      to a xdp_buff. The dynptr acts on xdp data. xdp dynptrs have two main
      benefits. One is that they allow operations on sizes that are not
      statically known at compile-time (eg variable-sized accesses).
      Another is that parsing the packet data through dynptrs (instead of
      through direct access of xdp->data and xdp->data_end) can be more
      ergonomic and less brittle (eg does not need manual if checking for
      being within bounds of data_end).
      
      For reads and writes on the dynptr, this includes reading/writing
      from/to and across fragments. Data slices through the bpf_dynptr_data
      API are not supported; instead bpf_dynptr_slice() and
      bpf_dynptr_slice_rdwr() should be used.
      
      For examples of how xdp dynptrs can be used, please see the attached
      selftests.
      Signed-off-by: NJoanne Koong <joannelkoong@gmail.com>
      Link: https://lore.kernel.org/r/20230301154953.641654-9-joannelkoong@gmail.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      05421aec
    • J
      bpf: Add skb dynptrs · b5964b96
      Joanne Koong 提交于
      Add skb dynptrs, which are dynptrs whose underlying pointer points
      to a skb. The dynptr acts on skb data. skb dynptrs have two main
      benefits. One is that they allow operations on sizes that are not
      statically known at compile-time (eg variable-sized accesses).
      Another is that parsing the packet data through dynptrs (instead of
      through direct access of skb->data and skb->data_end) can be more
      ergonomic and less brittle (eg does not need manual if checking for
      being within bounds of data_end).
      
      For bpf prog types that don't support writes on skb data, the dynptr is
      read-only (bpf_dynptr_write() will return an error)
      
      For reads and writes through the bpf_dynptr_read() and bpf_dynptr_write()
      interfaces, reading and writing from/to data in the head as well as from/to
      non-linear paged buffers is supported. Data slices through the
      bpf_dynptr_data API are not supported; instead bpf_dynptr_slice() and
      bpf_dynptr_slice_rdwr() (added in subsequent commit) should be used.
      
      For examples of how skb dynptrs can be used, please see the attached
      selftests.
      Signed-off-by: NJoanne Koong <joannelkoong@gmail.com>
      Link: https://lore.kernel.org/r/20230301154953.641654-8-joannelkoong@gmail.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      b5964b96
  13. 18 2月, 2023 1 次提交
  14. 17 2月, 2023 1 次提交
  15. 03 2月, 2023 1 次提交
  16. 29 1月, 2023 1 次提交
  17. 26 1月, 2023 1 次提交
  18. 24 1月, 2023 1 次提交
  19. 18 1月, 2023 1 次提交
  20. 16 1月, 2023 1 次提交
  21. 11 1月, 2023 1 次提交
  22. 21 12月, 2022 1 次提交
  23. 20 12月, 2022 1 次提交
  24. 06 12月, 2022 1 次提交
  25. 05 12月, 2022 1 次提交
  26. 22 11月, 2022 1 次提交
  27. 19 11月, 2022 1 次提交
  28. 16 11月, 2022 2 次提交
  29. 15 11月, 2022 1 次提交
  30. 12 11月, 2022 2 次提交
  31. 04 11月, 2022 1 次提交
    • S
      bpf: make sure skb->len != 0 when redirecting to a tunneling device · 07ec7b50
      Stanislav Fomichev 提交于
      syzkaller managed to trigger another case where skb->len == 0
      when we enter __dev_queue_xmit:
      
      WARNING: CPU: 0 PID: 2470 at include/linux/skbuff.h:2576 skb_assert_len include/linux/skbuff.h:2576 [inline]
      WARNING: CPU: 0 PID: 2470 at include/linux/skbuff.h:2576 __dev_queue_xmit+0x2069/0x35e0 net/core/dev.c:4295
      
      Call Trace:
       dev_queue_xmit+0x17/0x20 net/core/dev.c:4406
       __bpf_tx_skb net/core/filter.c:2115 [inline]
       __bpf_redirect_no_mac net/core/filter.c:2140 [inline]
       __bpf_redirect+0x5fb/0xda0 net/core/filter.c:2163
       ____bpf_clone_redirect net/core/filter.c:2447 [inline]
       bpf_clone_redirect+0x247/0x390 net/core/filter.c:2419
       bpf_prog_48159a89cb4a9a16+0x59/0x5e
       bpf_dispatcher_nop_func include/linux/bpf.h:897 [inline]
       __bpf_prog_run include/linux/filter.h:596 [inline]
       bpf_prog_run include/linux/filter.h:603 [inline]
       bpf_test_run+0x46c/0x890 net/bpf/test_run.c:402
       bpf_prog_test_run_skb+0xbdc/0x14c0 net/bpf/test_run.c:1170
       bpf_prog_test_run+0x345/0x3c0 kernel/bpf/syscall.c:3648
       __sys_bpf+0x43a/0x6c0 kernel/bpf/syscall.c:5005
       __do_sys_bpf kernel/bpf/syscall.c:5091 [inline]
       __se_sys_bpf kernel/bpf/syscall.c:5089 [inline]
       __x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5089
       do_syscall_64+0x54/0x70 arch/x86/entry/common.c:48
       entry_SYSCALL_64_after_hwframe+0x61/0xc6
      
      The reproducer doesn't really reproduce outside of syzkaller
      environment, so I'm taking a guess here. It looks like we
      do generate correct ETH_HLEN-sized packet, but we redirect
      the packet to the tunneling device. Before we do so, we
      __skb_pull l2 header and arrive again at skb->len == 0.
      Doesn't seem like we can do anything better than having
      an explicit check after __skb_pull?
      
      Cc: Eric Dumazet <edumazet@google.com>
      Reported-by: syzbot+f635e86ec3fa0a37e019@syzkaller.appspotmail.com
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/r/20221027225537.353077-1-sdf@google.comSigned-off-by: NMartin KaFai Lau <martin.lau@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      07ec7b50
  32. 30 9月, 2022 2 次提交