1. 19 Apr, 2021 3 commits
    • Florent Revest's avatar
      bpf: Add a bpf_snprintf helper · 7b15523a
      Florent Revest authored
      The implementation takes inspiration from the existing bpf_trace_printk
      helper but there are a few differences:
      
      To allow for a large number of format-specifiers, parameters are
      provided in an array, like in bpf_seq_printf.
      
      Because the output string takes two arguments and the array of
      parameters also takes two arguments, the format string needs to fit in
      one argument. Thankfully, ARG_PTR_TO_CONST_STR is guaranteed to point to
      a zero-terminated read-only map so we don't need a format string length
      arg.
      
      Because the format-string is known at verification time, we also do
      a first pass of format string validation in the verifier logic. This
      makes debugging easier.
      Signed-off-by: default avatarFlorent Revest <revest@chromium.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210419155243.1632274-4-revest@chromium.org
      7b15523a
    • Florent Revest's avatar
      bpf: Add a ARG_PTR_TO_CONST_STR argument type · fff13c4b
      Florent Revest authored
      This type provides the guarantee that an argument is going to be a const
      pointer to somewhere in a read-only map value. It also checks that this
      pointer is followed by a zero character before the end of the map value.
      Signed-off-by: default avatarFlorent Revest <revest@chromium.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210419155243.1632274-3-revest@chromium.org
      fff13c4b
    • Florent Revest's avatar
      bpf: Factorize bpf_trace_printk and bpf_seq_printf · d9c9e4db
      Florent Revest authored
      Two helpers (trace_printk and seq_printf) have very similar
      implementations of format string parsing and a third one is coming
      (snprintf). To avoid code duplication and make the code easier to
      maintain, this moves the operations associated with format string
      parsing (validation and argument sanitization) into one generic
      function.
      
      The implementation of the two existing helpers already drifted quite a
      bit so unifying them entailed a lot of changes:
      
      - bpf_trace_printk always expected fmt[fmt_size] to be the terminating
        NULL character, this is no longer true, the first 0 is terminating.
      - bpf_trace_printk now supports %% (which produces the percentage char).
      - bpf_trace_printk now skips width formating fields.
      - bpf_trace_printk now supports the X modifier (capital hexadecimal).
      - bpf_trace_printk now supports %pK, %px, %pB, %pi4, %pI4, %pi6 and %pI6
      - argument casting on 32 bit has been simplified into one macro and
        using an enum instead of obscure int increments.
      
      - bpf_seq_printf now uses bpf_trace_copy_string instead of
        strncpy_from_kernel_nofault and handles the %pks %pus specifiers.
      - bpf_seq_printf now prints longs correctly on 32 bit architectures.
      
      - both were changed to use a global per-cpu tmp buffer instead of one
        stack buffer for trace_printk and 6 small buffers for seq_printf.
      - to avoid per-cpu buffer usage conflict, these helpers disable
        preemption while the per-cpu buffer is in use.
      - both helpers now support the %ps and %pS specifiers to print symbols.
      
      The implementation is also moved from bpf_trace.c to helpers.c because
      the upcoming bpf_snprintf helper will be made available to all BPF
      programs and will need it.
      Signed-off-by: default avatarFlorent Revest <revest@chromium.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210419155243.1632274-2-revest@chromium.org
      d9c9e4db
  2. 15 Apr, 2021 9 commits
  3. 14 Apr, 2021 2 commits
  4. 13 Apr, 2021 2 commits
  5. 12 Apr, 2021 4 commits
  6. 09 Apr, 2021 10 commits
  7. 06 Apr, 2021 2 commits
  8. 05 Apr, 2021 1 commit
  9. 03 Apr, 2021 1 commit
  10. 02 Apr, 2021 6 commits