Thread (12 messages) 12 messages, 3 authors, 2021-08-12

Re: [PATCH v4 bpf-next 2/3] bpf: Support "%c" in bpf_bprintf_prepare().

flat view

From: Andrii Nakryiko <hidden>
Date: 2021-08-11 21:16:03
Also in: bpf

On Tue, Aug 10, 2021 at 2:29 AM Kuniyuki Iwashima [off-list ref] wrote:
quoted hunk ↗ jump to hunk
/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in
the name of the abstract UNIX domain socket.  The following selftest uses
it, so this patch adds support for "%c".  Note that it does not support
wide character ("%lc" and "%llc") for simplicity.

Signed-off-by: Kuniyuki Iwashima <redacted>
---
 kernel/bpf/helpers.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 15746f779fe1..6d3aaf94e9ac 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
                        tmp_buf += err;
                        num_spec++;

+                       continue;
+               } else if (fmt[i] == 'c') {
you are adding new features to printk-like helpers, please add
corresponding tests as well. I'm particularly curious how something
like "% 9c" (which is now allowed, along with a few other unusual
combinations) will work.
+                       if (!tmp_buf)
+                               goto nocopy_fmt;
+
+                       if (tmp_buf_end == tmp_buf) {
+                               err = -ENOSPC;
+                               goto out;
+                       }
+
+                       *tmp_buf = raw_args[num_spec];
+                       tmp_buf++;
+                       num_spec++;
+
                        continue;
                }

--
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help