bpf: Add kfuncs for read-only string operations
Subsystems (3)
v7 cover bpf: Add kfuncs for read-only string operations
String operations are commonly used in programming and BPF programs are no exception. Since it is cumbersome to reimplement them over and over, this series introduce kfuncs which provide the most common operations. For now, we only limit ourselves to functions which do not copy memory since these usually introduce undefined behaviour in case the source/destination buffers overlap which would have to be prevented by the verifier.
The kernel already contains implementations for all of these, however, it is not possible to use them from BPF context. The main reason is that the verifier is not able to check that it is safe to access the entire string and that the string is null-terminated and the function won't loop forever. Therefore, the operations are open-coded using __get_kernel_nofault instead of plain dereference and bounded to at most XATTR_SIZE_MAX characters to make them safe. That allows to skip all the verfier checks for the passed-in strings as safety is ensured dynamically.
All of the proposed functions return integers, even those that normally (in the kernel or libc) return pointers into the strings. The reason is that since the strings are generally treated as unsafe, the pointers couldn't be dereferenced anyways. So, instead, we return an index to the string and let user decide what to do with it. The integer APIs also allow to return various error codes when unexpected situations happen while processing the strings.
The series include both positive and negative tests using the kfuncs.
Changelog
---------
Changes in v7:
- Disable negative tests passing NULL and 0x1 to kfuncs on s390 as they aren't relevant (see comment in string_kfuncs_failure1.c for details).
Changes in v6:
- Improve the third patch which allows to use macros in __retval in selftests. The previous solution broke several tests.
Changes in v5:
- Make all kfuncs return integers (Andrii).
- Return -ERANGE when passing non-kernel pointers on arches with non-overlapping address spaces (Alexei).
- Implement "unbounded" variants using the bounded ones (Andrii).
- Add more negative test cases.
Changes in v4 (all suggested by Andrii):
- Open-code all the kfuncs, not just the unbounded variants.
- Introduce pagefault lock guard to simplify the implementation
- Return appropriate error codes (-E2BIG and -EFAULT) on failures
- Const-ify all arguments and return values
- Add negative test-cases
Changes in v3:
- Open-code unbounded variants with __get_kernel_nofault instead of dereference (suggested by Alexei).
- Use the __sz suffix for size parameters in bounded variants (suggested by Eduard and Alexei).
- Make tests more compact (suggested by Eduard).
- Add benchmark.
Viktor Malik (4):
uaccess: Define pagefault lock guard
bpf: Add kfuncs for read-only string operations
selftests/bpf: Allow macros in __retval
selftests/bpf: Add tests for string kfuncs
include/linux/uaccess.h | 2 + kernel/bpf/helpers.c | 389 ++++++++++++++++++ .../selftests/bpf/prog_tests/string_kfuncs.c | 63 +++ tools/testing/selftests/bpf/progs/bpf_misc.h | 14 +- .../bpf/progs/string_kfuncs_failure1.c | 85 ++++ .../bpf/progs/string_kfuncs_failure2.c | 21 + .../bpf/progs/string_kfuncs_success.c | 35 ++ .../bpf/progs/verifier_div_overflow.c | 4 +- tools/testing/selftests/bpf/test_loader.c | 23 +- 9 files changed, 613 insertions(+), 23 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/string_kfuncs.c create mode 100644 tools/testing/selftests/bpf/progs/string_kfuncs_failure1.c create mode 100644 tools/testing/selftests/bpf/progs/string_kfuncs_failure2.c create mode 100644 tools/testing/selftests/bpf/progs/string_kfuncs_success.c
Signature · 1 line
2.49.0
PATCH v7 1/4 uaccess: Define pagefault lock guard
Define a pagefault lock guard which allows to simplify functions that need to disable page faults.
--- include/linux/uaccess.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/uaccess.h +2 -0
@@ -296,6 +296,8 @@ static inline bool pagefault_disabled(void)*/ #define faulthandler_disabled () (pagefault_disabled() || in_atomic()) +DEFINE_LOCK_GUARD_0(pagefault, pagefault_disable(), pagefault_enable()) +#ifndef CONFIG_ARCH_HAS_SUBPAGE_FAULTS /**
Signature · 1 line
2.49.0
PATCH v7 2/4 bpf: Add kfuncs for read-only string operations
In reply to Viktor MalikString operations are commonly used so this exposes the most common ones to BPF programs. For now, we limit ourselves to operations which do not copy memory around.
Unfortunately, most in-kernel implementations assume that strings are %NUL-terminated, which is not necessarily true, and therefore we cannot use them directly in the BPF context. Instead, we open-code them using __get_kernel_nofault instead of plain dereference to make them safe and limit the strings length to XATTR_SIZE_MAX to make sure the functions terminate. When __get_kernel_nofault fails, functions return -EFAULT. Similarly, when the size bound is reached, the functions return -E2BIG. In addition, we return -ERANGE when the passed strings are outside of the kernel address space.
Note that thanks to these dynamic safety checks, no other constraints are put on the kfunc args (they are marked with the "__ign" suffix to skip any verifier checks for them).
All of the functions return integers, including functions which normally (in kernel or libc) return pointers to the strings. The reason is that since the strings are generally treated as unsafe, the pointers couldn't be dereferenced anyways. So, instead, we return an index to the string and let user decide what to do with it. This also nicely fits with returning various error codes when necessary (see above).
--- kernel/bpf/helpers.c | 389 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+)
kernel/bpf/helpers.c +389 -0
@@ -24,6 +24,7 @@#include <linux/bpf_mem_alloc.h> #include <linux/kasan.h> #include <linux/bpf_verifier.h> +#include <linux/uaccess.h> #include "../../lib/kstrtox.h"
@@ -3278,6 +3279,383 @@ __bpf_kfunc void __bpf_trap(void) { } +/* Kfuncs for string operations. +* +* Since strings are not necessarily %NUL-terminated, we cannot directly call +* in-kernel implementations. Instead, we open-code the implementations using +* __get_kernel_nofault instead of plain dereference to make them safe. +*/ + +/** +* bpf_strcmp - Compare two strings +* @s1__ign: One string +* @s2__ign: Another string +* +* Return: +* * %0 - Strings are equal +* * %-1 - @s1__ign is smaller +* * %1 - @s2__ign is smaller +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of strings is too large +* * %-ERANGE - One of strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strcmp(const char *s1__ign, const char *s2__ign) +{ +char c1, c2; +int i; + +if (!copy_from_kernel_nofault_allowed (s1__ign,1 ) || + !copy_from_kernel_nofault_allowed (s2__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&c1, s1__ign, char, err_out); +__get_kernel_nofault (&c2, s2__ign, char, err_out); +if (c1 != c2) +return c1 < c2 ?-1 :1 ; +if (c1 =='\0' ) +return 0 ; + s1__ign++; + s2__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} + +/** +* bpf_strnchr - Find a character in a length limited string +* @s__ign: The string to be searched +* @count: The number of characters to be searched +* @c: The character to search for +* +* Note that the %NUL-terminator is considered part of the string, and can +* be searched for. +* +* Return: +* * >=0 - Index of the first occurrence of @c within @s__ign +* * %-1 - @c not found in the first @count characters of @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strnchr(const char *s__ign, size_t count, char c) +{ +char sc; +int i; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 )) +return -ERANGE ; + +guard (pagefault)(); +for (i =0 ; i < count && i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&sc, s__ign, char, err_out); +if (sc == c) +return i; +if (sc =='\0' ) +return -1 ; + s__ign++; + } +return i ==XATTR_SIZE_MAX ? -E2BIG :-1 ; +err_out: +return -EFAULT ; +} + +/** +* bpf_strchr - Find the first occurrence of a character in a string +* @s__ign: The string to be searched +* @c: The character to search for +* +* Note that the %NUL-terminator is considered part of the string, and can +* be searched for. +* +* Return: +* * >=0 - The index of the first occurrence of @c within @s__ign +* * -1 - @c not found in @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strchr(const char *s__ign, char c) +{ +return bpf_strnchr (s__ign,XATTR_SIZE_MAX , c); +} + +/** +* bpf_strchrnul - Find and return a character in a string, or end of string +* @s__ign: The string to be searched +* @c: The character to search for +* +* Return: +* * >=0 - Index of the first occurrence of @c within @s__ign or index of +* the null byte at the end of @s__ign when @c is not found +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strchrnul(const char *s__ign, char c) +{ +char sc; +int i; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 )) +return -ERANGE ; + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&sc, s__ign, char, err_out); +if (sc =='\0' || sc == c) +return i; + s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} + +/** +* bpf_strrchr - Find the last occurrence of a character in a string +* @s__ign: The string to be searched +* @c: The character to search for +* +* Return: +* * >=0 - Index of the last occurrence of @c within @s__ign +* * %-1 - @c not found in @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strrchr(const char *s__ign, int c) +{ +char sc; +int i, last =-1 ; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 )) +return -ERANGE ; + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&sc, s__ign, char, err_out); +if (sc =='\0' ) +return last; +if (sc == c) + last = i; + s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} + +/** +* bpf_strlen - Calculate the length of a length-limited string +* @s__ign: The string +* @count: The maximum number of characters to count +* +* Return: +* * >=0 - The length of @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strnlen(const char *s__ign, size_t count) +{ +char c; +int i; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 )) +return -ERANGE ; + +guard (pagefault)(); +for (i =0 ; i < count && i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&c, s__ign, char, err_out); +if (c =='\0' ) +return i; + s__ign++; + } +return i ==XATTR_SIZE_MAX ? -E2BIG : i; +err_out: +return -EFAULT ; +} + +/** +* bpf_strlen - Calculate the length of a string +* @s__ign: The string +* +* Return: +* * >=0 - The length of @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strlen(const char *s__ign) +{ +return bpf_strnlen (s__ign,XATTR_SIZE_MAX ); +} + +/** +* bpf_strspn - Calculate the length of the initial substring of @s__ign which +* only contains letters in @accept__ign +* @s__ign: The string to be searched +* @accept__ign: The string to search for +* +* Return: +* * >=0 - The length of the initial substring of @s__ign which only +* contains letters from @accept__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strspn(const char *s__ign, const char *accept__ign) +{ +char cs, ca; +bool found; +int i, j; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 ) || + !copy_from_kernel_nofault_allowed (accept__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&cs, s__ign, char, err_out); +if (cs =='\0' ) +return i; + found = false; +for (j =0 ; j <XATTR_SIZE_MAX ; j++) { +__get_kernel_nofault (&ca, accept__ign + j, char, err_out); +if (cs == ca) { + found = true; +break ; + } +if (ca =='\0' ) +break ; + } +if (!found) +return i; + s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} + +/** +* strcspn - Calculate the length of the initial substring of @s__ign which +* does not contain letters in @reject__ign +* @s__ign: The string to be searched +* @reject__ign: The string to search for +* +* Return: +* * >=0 - The length of the initial substring of @s__ign which does not +* contain letters from @reject__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strcspn(const char *s__ign, const char *reject__ign) +{ +char cs, cr; +bool found; +int i, j; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 ) || + !copy_from_kernel_nofault_allowed (reject__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&cs, s__ign, char, err_out); +if (cs =='\0' ) +return i; + found = false; +for (j =0 ; j <XATTR_SIZE_MAX ; j++) { +__get_kernel_nofault (&cr, reject__ign + j, char, err_out); +if (cs == cr) { + found = true; +break ; + } +if (cr =='\0' ) +break ; + } +if (found) +return i; + s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} + +/** +* bpf_strnstr - Find the first substring in a length-limited string +* @s1__ign: The string to be searched +* @s2__ign: The string to search for +* @len: the maximum number of characters to search +* +* Return: +* * >=0 - Index of the first character of the first occurrence of @s2__ign +* within the first @len characters of @s1__ign +* * %-1 - @s2__ign not found in the first @len characters of @s1__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strnstr(const char *s1__ign, const char *s2__ign, size_t len) +{ +char c1, c2; +int i, j; + +if (!copy_from_kernel_nofault_allowed (s1__ign,1 ) || + !copy_from_kernel_nofault_allowed (s2__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +for (j =0 ; i + j < len && j <XATTR_SIZE_MAX ; j++) { +__get_kernel_nofault (&c1, s1__ign + j, char, err_out); +__get_kernel_nofault (&c2, s2__ign + j, char, err_out); +if (c2 =='\0' ) +return i; +if (c1 =='\0' ) +return -1 ; +if (c1 != c2) +break ; + } +if (j ==XATTR_SIZE_MAX ) +return -E2BIG ; +if (i + j == len) +return -1 ; + s1__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} + +/** +* bpf_strstr - Find the first substring in a string +* @s1__ign: The string to be searched +* @s2__ign: The string to search for +* +* Return: +* * >=0 - Index of the first character of the first occurrence of @s2__ign +* within @s1__ign +* * %-1 - @s2__ign is not a substring of @s1__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strstr(const char *s1__ign, const char *s2__ign) +{ +return bpf_strnstr (s1__ign, s2__ign,XATTR_SIZE_MAX ); +} +__bpf_kfunc_end_defs ();BTF_KFUNCS_START (generic_btf_ids)
@@ -3397,6 +3775,17 @@ BTF_ID_FLAGS(func, bpf_iter_dmabuf_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLEEPAB BTF_ID_FLAGS(func, bpf_iter_dmabuf_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)#endif BTF_ID_FLAGS(func, __bpf_trap) +BTF_ID_FLAGS (func, bpf_strcmp); +BTF_ID_FLAGS (func, bpf_strchr); +BTF_ID_FLAGS (func, bpf_strchrnul); +BTF_ID_FLAGS (func, bpf_strnchr); +BTF_ID_FLAGS (func, bpf_strrchr); +BTF_ID_FLAGS (func, bpf_strlen); +BTF_ID_FLAGS (func, bpf_strnlen); +BTF_ID_FLAGS (func, bpf_strspn); +BTF_ID_FLAGS (func, bpf_strcspn); +BTF_ID_FLAGS (func, bpf_strstr); +BTF_ID_FLAGS (func, bpf_strnstr);BTF_KFUNCS_END (common_btf_ids) static const struct btf_kfunc_id_set common_kfunc_set = {
Signature · 1 line
2.49.0
PATCH v7 3/4 selftests/bpf: Allow macros in __retval
In reply to Viktor MalikAllow macro expansion for values passed to the __retval and __retval_unpriv attributes. This is especially useful for testing programs which return various error codes.
With this change, the code for parsing special literals can be made simpler, as the literals are defined via macros. The only exception is INT_MIN which expands to (-INT_MAX -1), which is not single number and cannot be parsed by strtol. So, we instead use a prefixed literal _INT_MIN in __retval and handle it separately (assign the expected return to INT_MIN). Also, strtol cannot handle the "ll" suffix so change the value of POINTER_VALUE from 0xcafe4all to 0xbadcafe.
--- tools/testing/selftests/bpf/progs/bpf_misc.h | 14 ++++++----- .../bpf/progs/verifier_div_overflow.c | 4 ++-- tools/testing/selftests/bpf/test_loader.c | 23 +++++++------------ 3 files changed, 18 insertions(+), 23 deletions(-)
tools/testing/selftests/bpf/progs/bpf_misc.h +8 -6
@@ -83,9 +83,11 @@* expect return value to match passed parameter: * - a decimal number * - a hexadecimal number, when starts from 0x -* - literal INT_MIN -* - literal POINTER_VALUE (see definition below) -* - literal TEST_DATA_LEN (see definition below) +* - a macro which expands to one of the above +* - literal _INT_MIN (expands to INT_MIN) +* In addition, two special macros are defined below: +* - POINTER_VALUE +* - TEST_DATA_LEN * __retval_unpriv Same, but load program in unprivileged mode. * * __description Text to be used instead of a program name for display
@@ -125,8 +127,8 @@#define __success_unpriv __attribute__((btf_decl_tag("comment:test_expect_success_unpriv")))#define __log_level (lvl) __attribute__((btf_decl_tag("comment:test_log_level="#lvl)))#define __flag (flag) __attribute__((btf_decl_tag("comment:test_prog_flags="#flag))) -#define __retval (val) __attribute__((btf_decl_tag("comment:test_retval="#val))) -#define __retval_unpriv (val) __attribute__((btf_decl_tag("comment:test_retval_unpriv="#val))) +#define __retval (val) __attribute__((btf_decl_tag("comment:test_retval="XSTR(val)))) +#define __retval_unpriv (val) __attribute__((btf_decl_tag("comment:test_retval_unpriv="XSTR(val))))#define __auxiliary __attribute__((btf_decl_tag("comment:test_auxiliary")))#define __auxiliary_unpriv __attribute__((btf_decl_tag("comment:test_auxiliary_unpriv")))#define __btf_path (path) __attribute__((btf_decl_tag("comment:test_btf_path=" path)))
@@ -155,7 +157,7 @@#define __imm_insn (name, expr) [name]"i"(*(long *)&(expr))/* Magic constants used with __retval() */ -#define POINTER_VALUE 0xcafe4all +#define POINTER_VALUE 0xbadcafe#define TEST_DATA_LEN 64#ifndef __used
tools/testing/selftests/bpf/progs/verifier_div_overflow.c +2 -2
@@ -77,7 +77,7 @@ l0_%=: exit; \ SEC("tc") __description("MOD32 overflow, check 1") -__success __retval (INT_MIN ) +__success __retval (_INT_MIN )__naked voidmod32_overflow_check_1 (void) { asm volatile (" \
@@ -92,7 +92,7 @@ __naked void mod32_overflow_check_1(void) SEC("tc") __description("MOD32 overflow, check 2") -__success __retval (INT_MIN ) +__success __retval (_INT_MIN )__naked voidmod32_overflow_check_2 (void) { asm volatile (" \
tools/testing/selftests/bpf/test_loader.c +8 -15
@@ -40,7 +40,7 @@#define TEST_TAG_LOAD_MODE_PFX "comment:load_mode="/* Warning: duplicated in bpf_misc.h */ -#define POINTER_VALUE 0xcafe4all +#define POINTER_VALUE 0xbadcafe#define TEST_DATA_LEN 64#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
@@ -318,20 +318,13 @@ static int parse_caps(const char *str, __u64 *val, const char *name)static int parse_retval (const char *str,int *val,const char *name) { -struct { -char *name; -int val; - } named_values[] = { - {"INT_MIN" ,INT_MIN }, - {"POINTER_VALUE" ,POINTER_VALUE }, - {"TEST_DATA_LEN" ,TEST_DATA_LEN }, - }; -int i; - -for (i =0 ; i <ARRAY_SIZE (named_values); ++i) { -if (strcmp (str, named_values[i].name) !=0 ) -continue ; - *val = named_values[i].val; +/* INT_MIN is defined as (-INT_MAX -1), i.e. it doesn't expand to a +* single int and cannot be parsed with strtol, so we handle it +* separately here. In addition, it expands to different expressions in +* different compilers so we use a prefixed _INT_MIN instead. +*/ +if (strcmp (str,"_INT_MIN" ) ==0 ) { + *val =INT_MIN ;return 0 ; }
Signature · 1 line
2.49.0
PATCH v7 4/4 selftests/bpf: Add tests for string kfuncs
In reply to Viktor MalikAdd both positive and negative tests cases using string kfuncs added in the previous patches.
Positive tests check that the functions work as expected.
Negative tests pass various incorrect strings to the kfuncs and check for the expected error codes:
-E2BIG when passing too long strings
-EFAULT when trying to read inaccessible kernel memory -ERANGE when passing userspace pointers on arches with non-overlapping
address spaces
A majority of the tests use the RUN_TESTS helper which executes BPF programs with BPF_PROG_TEST_RUN and check for the expected return value. An exception to this are tests for long strings as we need to memset the long string from userspace (at least I haven't found an ergonomic way to memset it from a BPF program), which cannot be done using the RUN_TESTS infrastructure.
--- .../selftests/bpf/prog_tests/string_kfuncs.c | 63 ++++++++++++++ .../bpf/progs/string_kfuncs_failure1.c | 85 +++++++++++++++++++ .../bpf/progs/string_kfuncs_failure2.c | 21 +++++ .../bpf/progs/string_kfuncs_success.c | 35 ++++++++ 4 files changed, 204 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/string_kfuncs.c create mode 100644 tools/testing/selftests/bpf/progs/string_kfuncs_failure1.c create mode 100644 tools/testing/selftests/bpf/progs/string_kfuncs_failure2.c create mode 100644 tools/testing/selftests/bpf/progs/string_kfuncs_success.c
tools/testing/selftests/bpf/prog_tests/string_kfuncs.c new file +63 -0
@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2025 Red Hat, Inc.*/ +#include <test_progs.h> +#include "string_kfuncs_success.skel.h" +#include "string_kfuncs_failure1.skel.h" +#include "string_kfuncs_failure2.skel.h" +#include <sys/mman.h> + +static const char *const string_kfuncs[] = { +"strcmp" , +"strchr" , +"strchrnul" , +"strnchr" , +"strrchr" , +"strlen" , +"strnlen" , +"strspn" , +"strcspn" , +"strstr" , +"strnstr" , +}; + +void run_too_long_tests (void ) +{ +struct string_kfuncs_failure2 *skel; +struct bpf_program *prog; +char test_name[256 ]; +int err, i; + + skel =string_kfuncs_failure2__open_and_load (); +if (!ASSERT_OK_PTR (skel,"string_kfuncs_failure2__open_and_load" )) +return ; + +memset (skel->bss->long_str,'a' ,sizeof (skel->bss->long_str)); + +for (i =0 ; i <ARRAY_SIZE (string_kfuncs); i++) { +sprintf (test_name,"test_%s_too_long" , string_kfuncs[i]); +if (!test__start_subtest (test_name)) +continue ; + + prog =bpf_object__find_program_by_name (skel->obj, test_name); +if (!ASSERT_OK_PTR (prog,"bpf_object__find_program_by_name" )) + goto cleanup; + +LIBBPF_OPTS (bpf_test_run_opts, topts); + err =bpf_prog_test_run_opts (bpf_program__fd (prog), &topts); +if (!ASSERT_OK (err,"bpf_prog_test_run" )) + goto cleanup; + +ASSERT_EQ (topts.retval, -E2BIG ,"reading too long string fails with -E2BIG" ); + } + +cleanup: +string_kfuncs_failure2__destroy (skel); +} + +void test_string_kfuncs (void ) +{ +RUN_TESTS (string_kfuncs_success); +RUN_TESTS (string_kfuncs_failure1); + +run_too_long_tests (); +}
tools/testing/selftests/bpf/progs/string_kfuncs_failure1.c new file +85 -0
85 lines not on this page · raw message
tools/testing/selftests/bpf/progs/string_kfuncs_failure2.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2025 Red Hat, Inc.*/ +#include "vmlinux.h" +#include <bpf/bpf_helpers.h> +#include <linux/limits.h> + +char long_str[XATTR_SIZE_MAX +1 ]; + +SEC("syscall") int test_strcmp_too_long(void *ctx) { return bpf_strcmp(long_str, long_str); } +SEC("syscall") int test_strchr_too_long(void *ctx) { return bpf_strchr(long_str, 'b'); } +SEC("syscall") int test_strchrnul_too_long(void *ctx) { return bpf_strchrnul(long_str, 'b'); } +SEC("syscall") int test_strnchr_too_long(void *ctx) { return bpf_strnchr(long_str, sizeof(long_str), 'b'); } +SEC("syscall") int test_strrchr_too_long(void *ctx) { return bpf_strrchr(long_str, 'b'); } +SEC("syscall") int test_strlen_too_long(void *ctx) { return bpf_strlen(long_str); } +SEC("syscall") int test_strnlen_too_long(void *ctx) { return bpf_strnlen(long_str, sizeof(long_str)); } +SEC("syscall") int test_strspn_too_long(void *ctx) { return bpf_strspn(long_str, "a"); } +SEC("syscall") int test_strcspn_too_long(void *ctx) { return bpf_strcspn(long_str, "b"); } +SEC("syscall") int test_strstr_too_long(void *ctx) { return bpf_strstr(long_str, "hello"); } +SEC("syscall") int test_strnstr_too_long(void *ctx) { return bpf_strnstr(long_str, "hello", sizeof(long_str)); } + +char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/string_kfuncs_success.c new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2025 Red Hat, Inc.*/ +#include "vmlinux.h" +#include <bpf/bpf_helpers.h> +#include "bpf_misc.h" + +char str[] ="hello world" ; + +#define __test (retval) SEC("syscall") __success __retval(retval) + +/* Functional tests */ +__test(0) int test_strcmp_eq(void *ctx) { return bpf_strcmp(str, "hello world"); } +__test(1) int test_strcmp_neq(void *ctx) { return bpf_strcmp(str, "hello"); } +__test(1) int test_strchr_found(void *ctx) { return bpf_strchr(str, 'e'); } +__test(11) int test_strchr_null(void *ctx) { return bpf_strchr(str, '\0'); } +__test(-1) int test_strchr_notfound(void *ctx) { return bpf_strchr(str, 'x'); } +__test(1) int test_strchrnul_found(void *ctx) { return bpf_strchrnul(str, 'e'); } +__test(11) int test_strchrnul_notfound(void *ctx) { return bpf_strchrnul(str, 'x'); } +__test(1) int test_strnchr_found(void *ctx) { return bpf_strnchr(str, 5, 'e'); } +__test(11) int test_strnchr_null(void *ctx) { return bpf_strnchr(str, 12, '\0'); } +__test(-1) int test_strnchr_notfound(void *ctx) { return bpf_strnchr(str, 5, 'w'); } +__test(9) int test_strrchr_found(void *ctx) { return bpf_strrchr(str, 'l'); } +__test(-1) int test_strrchr_notfound(void *ctx) { return bpf_strrchr(str, 'x'); } +__test(11) int test_strlen(void *ctx) { return bpf_strlen(str); } +__test(11) int test_strnlen(void *ctx) { return bpf_strnlen(str, 12); } +__test(5) int test_strspn(void *ctx) { return bpf_strspn(str, "ehlo"); } +__test(2) int test_strcspn(void *ctx) { return bpf_strcspn(str, "lo"); } +__test(6) int test_strstr_found(void *ctx) { return bpf_strstr(str, "world"); } +__test(-1) int test_strstr_notfound(void *ctx) { return bpf_strstr(str, "hi"); } +__test(0) int test_strstr_empty(void *ctx) { return bpf_strstr(str, ""); } +__test(0) int test_strnstr_found(void *ctx) { return bpf_strnstr(str, "hello", 6); } +__test(-1) int test_strnstr_notfound(void *ctx) { return bpf_strnstr(str, "hi", 10); } +__test(0) int test_strnstr_empty(void *ctx) { return bpf_strnstr(str, "", 1); } + +char _license[] SEC("license") = "GPL";
Signature · 1 line
2.49.0
Quoted 2 lines · Viktor Malik
+/* Kfuncs for string operations.
Pls use normal kernel style comments instead of old networking. That's what we prefer for all new code.
Quoted 5 lines
+ *
+ * Since strings are not necessarily %NUL-terminated, we cannot directly call
+ * in-kernel implementations. Instead, we open-code the implementations using
+ *__get_kernel_nofaultinstead of plain dereference to make them safe.
+ */
kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3297
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+ +/** +* bpf_strcmp - Compare two strings +* @s1__ign: One string +* @s2__ign: Another string +* +* Return: +* * %0 - Strings are equal +* * %-1 - @s1__ign is smaller +* * %1 - @s2__ign is smaller
Here -1 and 1 return values are probably ok, since they match traditional strcmp.
Quoted 4 lines
+ * * %-EFAULT - Cannot read one of the strings
+ * * %-E2BIG - One of strings is too large
+ * * %-ERANGE - One of strings is outside of kernel address space
+ */
...
Quoted 8 lines
+/**
+ *bpf_strnchr- Find a character in a length limited string
+ * @s__ign: The string to be searched
+ * @count: The number of characters to be searched
+ * @c: The character to search for
+ *
+ * Note that the %NUL-terminator is considered part of the string, and can
+ * be searched for.
Quoted 8 lines
+ *
+ * Return:
+ * * >=0 - Index of the first occurrence of @c within @s__ign
+ * * %-1 - @c not found in the first @count characters of @s__ign
+ * * %-EFAULT - Cannot read @s__ign
+ * * %-E2BIG - @s__ign is too large
+ * * %-ERANGE - @s__ign is outside of kernel address space
+ */
but here and in a few other places returning -1 is effectively returning -EPERM for "not found".
Which is odd.
Maybe let's return -ENOENT instead ?
Quoted 26 lines · Viktor Malik
String operations are commonly used so this exposes the most common ones to BPF programs. For now, we limit ourselves to operations which do not copy memory around.
Unfortunately, most in-kernel implementations assume that strings are %NUL-terminated, which is not necessarily true, and therefore we cannot use them directly in the BPF context. Instead, we open-code them using
__get_kernel_nofaultinstead of plain dereference to make them safe and limit the strings length toXATTR_SIZE_MAXto make sure the functions terminate. When__get_kernel_nofaultfails, functions return-EFAULT. Similarly, when the size bound is reached, the functions return-E2BIG. In addition, we return-ERANGEwhen the passed strings are outside of the kernel address space.Note that thanks to these dynamic safety checks, no other constraints are put on the kfunc args (they are marked with the "
__ign" suffix to skip any verifier checks for them).All of the functions return integers, including functions which normally (in kernel or libc) return pointers to the strings. The reason is that since the strings are generally treated as unsafe, the pointers couldn't be dereferenced anyways. So, instead, we return an index to the string and let user decide what to do with it. This also nicely fits with returning various error codes when necessary (see above).
Quoted 6 lines
Suggested-by Alexei Starovoitov <[email protected]>Signed-off-by Viktor Malik <[email protected]>--- kernel/bpf/helpers.c | 389 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+)
few more comments below, beside the -ENOENT issue Alexei mentioned earlier
[...]
Quoted 17 lines
kernel/bpf/helpers.c +17
-0+/** +* bpf_strrchr - Find the last occurrence of a character in a string +* @s__ign: The string to be searched +* @c: The character to search for +* +* Return: +* * >=0 - Index of the last occurrence of @c within @s__ign +* * %-1 - @c not found in @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strrchr(const char *s__ign, int c) +{ +char sc; +int i, last =-1 ; +
kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3444
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+if (!copy_from_kernel_nofault_allowed (s__ign,1 )) +return -ERANGE ; + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&sc, s__ign, char, err_out); +if (sc =='\0' ) +return last; +if (sc == c) + last = i;
swap these two ifs, so that bpf_strrchr("blah", 0) will still return a meaningful result (effectively become bpf_strlen(), of course)? That should match strrchr's behavior in libc, if I'm reading this correctly:
"The terminating NUL character is considered to be part of the string."
Quoted 7 lines
kernel/bpf/helpers.c +7
-0+ s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} +
[...]
Quoted 31 lines
kernel/bpf/helpers.c +31
-0+/** +* bpf_strspn - Calculate the length of the initial substring of @s__ign which +* only contains letters in @accept__ign +* @s__ign: The string to be searched +* @accept__ign: The string to search for +* +* Return: +* * >=0 - The length of the initial substring of @s__ign which only +* contains letters from @accept__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strspn(const char *s__ign, const char *accept__ign) +{ +char cs, ca; +bool found; +int i, j; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 ) || + !copy_from_kernel_nofault_allowed (accept__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&cs, s__ign, char, err_out); +if (cs =='\0' ) +return i; + found = false; +for (j =0 ; j <XATTR_SIZE_MAX ; j++) {
kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3538
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+__get_kernel_nofault (&ca, accept__ign + j, char, err_out); +if (cs == ca) { + found = true; +break ; + } +if (ca =='\0' ) +break ; + } +if (!found) +return i;
nit: you shouldn't need "found", just ca == '\0' would mean "not found", I think?
so you'd have a succinct if (cs == ca || ca == '\0') break; in the innermost loop
Quoted 7 lines
kernel/bpf/helpers.c +7
-0+ s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} +
[...]
Quoted 18 lines
kernel/bpf/helpers.c +18
-0+/** +* bpf_strnstr - Find the first substring in a length-limited string +* @s1__ign: The string to be searched +* @s2__ign: The string to search for +* @len: the maximum number of characters to search +* +* Return: +* * >=0 - Index of the first character of the first occurrence of @s2__ign +* within the first @len characters of @s1__ign +* * %-1 - @s2__ign not found in the first @len characters of @s1__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strnstr(const char *s1__ign, const char *s2__ign, size_t len) +{ +char c1, c2; +int i, j;
kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3621
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+ +if (!copy_from_kernel_nofault_allowed (s1__ign,1 ) || + !copy_from_kernel_nofault_allowed (s2__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +for (j =0 ; i + j < len && j <XATTR_SIZE_MAX ; j++) { +__get_kernel_nofault (&c1, s1__ign + j, char, err_out);
move this after you check c2 == 0 below? why reading this character if we are not going to compare it?
Quoted 19 lines
kernel/bpf/helpers.c +19
-0+__get_kernel_nofault (&c2, s2__ign + j, char, err_out); +if (c2 =='\0' ) +return i; +if (c1 =='\0' ) +return -1 ; +if (c1 != c2) +break ; + } +if (j ==XATTR_SIZE_MAX ) +return -E2BIG ; +if (i + j == len) +return -1 ; + s1__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} +
[...]
Quoted 50 lines · Alexei Starovoitov
Quoted 2 lines · Viktor Malik
+/* Kfuncs for string operations.
Pls use normal kernel style comments instead of old networking. That's what we prefer for all new code.
Quoted 5 lines
+ *
+ * Since strings are not necessarily %NUL-terminated, we cannot directly call
+ * in-kernel implementations. Instead, we open-code the implementations using
+ *__get_kernel_nofaultinstead of plain dereference to make them safe.
+ */kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3297
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+ +/** +* bpf_strcmp - Compare two strings +* @s1__ign: One string +* @s2__ign: Another string +* +* Return: +* * %0 - Strings are equal +* * %-1 - @s1__ign is smaller +* * %1 - @s2__ign is smaller Here -1 and 1 return values are probably ok, since they match traditional strcmp.
Quoted 4 lines
+ * * %-EFAULT - Cannot read one of the strings
+ * * %-E2BIG - One of strings is too large
+ * * %-ERANGE - One of strings is outside of kernel address space
+ */...
Quoted 8 lines
+/**
+ *bpf_strnchr- Find a character in a length limited string
+ * @s__ign: The string to be searched
+ * @count: The number of characters to be searched
+ * @c: The character to search for
+ *
+ * Note that the %NUL-terminator is considered part of the string, and can
+ * be searched for.Quoted 8 lines
+ *
+ * Return:
+ * * >=0 - Index of the first occurrence of @c within @s__ign
+ * * %-1 - @c not found in the first @count characters of @s__ign
+ * * %-EFAULT - Cannot read @s__ign
+ * * %-E2BIG - @s__ign is too large
+ * * %-ERANGE - @s__ign is outside of kernel address space
+ */
Quoted 4 lines
but here and in a few other places returning -1 is effectively returning
-EPERMfor "not found".
Which is odd.
Maybe let's return-ENOENTinstead ?
Yes, that was my other alternative, I'll change it.
Thanks.
Quoted 71 lines · Andrii Nakryiko
Quoted 26 lines · Viktor Malik
String operations are commonly used so this exposes the most common ones to BPF programs. For now, we limit ourselves to operations which do not copy memory around.
Unfortunately, most in-kernel implementations assume that strings are %NUL-terminated, which is not necessarily true, and therefore we cannot use them directly in the BPF context. Instead, we open-code them using
__get_kernel_nofaultinstead of plain dereference to make them safe and limit the strings length toXATTR_SIZE_MAXto make sure the functions terminate. When__get_kernel_nofaultfails, functions return-EFAULT. Similarly, when the size bound is reached, the functions return-E2BIG. In addition, we return-ERANGEwhen the passed strings are outside of the kernel address space.Note that thanks to these dynamic safety checks, no other constraints are put on the kfunc args (they are marked with the "
__ign" suffix to skip any verifier checks for them).All of the functions return integers, including functions which normally (in kernel or libc) return pointers to the strings. The reason is that since the strings are generally treated as unsafe, the pointers couldn't be dereferenced anyways. So, instead, we return an index to the string and let user decide what to do with it. This also nicely fits with returning various error codes when necessary (see above).
Quoted 6 lines
Suggested-by Alexei Starovoitov <[email protected]>Signed-off-by Viktor Malik <[email protected]>--- kernel/bpf/helpers.c | 389 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+)few more comments below, beside the
-ENOENTissue Alexei mentioned earlier[...]
Quoted 17 lines
kernel/bpf/helpers.c +17
-0+/** +* bpf_strrchr - Find the last occurrence of a character in a string +* @s__ign: The string to be searched +* @c: The character to search for +* +* Return: +* * >=0 - Index of the last occurrence of @c within @s__ign +* * %-1 - @c not found in @s__ign +* * %-EFAULT - Cannot read @s__ign +* * %-E2BIG - @s__ign is too large +* * %-ERANGE - @s__ign is outside of kernel address space +*/ +__bpf_kfunc int bpf_strrchr(const char *s__ign, int c) +{ +char sc; +int i, last =-1 ; +kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3444
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+if (!copy_from_kernel_nofault_allowed (s__ign,1 )) +return -ERANGE ; + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&sc, s__ign, char, err_out); +if (sc =='\0' ) +return last; +if (sc == c) + last = i;swap these two ifs, so that
bpf_strrchr("blah", 0)will still return a meaningful result (effectively becomebpf_strlen(), of course)? That should match strrchr's behavior in libc, if I'm reading this correctly:
Quoted 1 line
"The terminating NUL character is considered to be part of the string."
Yeah, that's correct, nice catch! I'll add a test for the above case.
Quoted 57 lines
Quoted 9 lines
kernel/bpf/helpers.c +7
-0+ s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} +[...]
Quoted 31 lines
kernel/bpf/helpers.c +31
-0+/** +* bpf_strspn - Calculate the length of the initial substring of @s__ign which +* only contains letters in @accept__ign +* @s__ign: The string to be searched +* @accept__ign: The string to search for +* +* Return: +* * >=0 - The length of the initial substring of @s__ign which only +* contains letters from @accept__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strspn(const char *s__ign, const char *accept__ign) +{ +char cs, ca; +bool found; +int i, j; + +if (!copy_from_kernel_nofault_allowed (s__ign,1 ) || + !copy_from_kernel_nofault_allowed (accept__ign,1 )) { +return -ERANGE ; + } + +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +__get_kernel_nofault (&cs, s__ign, char, err_out); +if (cs =='\0' ) +return i; + found = false; +for (j =0 ; j <XATTR_SIZE_MAX ; j++) {kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3538
Quoted 10 lines
kernel/bpf/helpers.c +10
-0+__get_kernel_nofault (&ca, accept__ign + j, char, err_out); +if (cs == ca) { + found = true; +break ; + } +if (ca =='\0' ) +break ; + } +if (!found) +return i;nit: you shouldn't need "found", just
ca == '\0'would mean "not found", I think?
Quoted 2 lines
so you'd have a succinct
if (cs == ca || ca == '\0') break;in the innermost loop
That sounds about right. We'll just need to cover the case when j == XATTR_SIZE_MAX and return -E2BIG in such a case (which should have been done anyways here and currently is not).
Also, an analogical thing can be done in bpf_strcspn.
Quoted 35 lines
Quoted 9 lines
kernel/bpf/helpers.c +7
-0+ s__ign++; + } +return -E2BIG ; +err_out: +return -EFAULT ; +} +[...]
Quoted 23 lines
kernel/bpf/helpers.c +23
-0+/** +* bpf_strnstr - Find the first substring in a length-limited string +* @s1__ign: The string to be searched +* @s2__ign: The string to search for +* @len: the maximum number of characters to search +* +* Return: +* * >=0 - Index of the first character of the first occurrence of @s2__ign +* within the first @len characters of @s1__ign +* * %-1 - @s2__ign not found in the first @len characters of @s1__ign +* * %-EFAULT - Cannot read one of the strings +* * %-E2BIG - One of the strings is too large +* * %-ERANGE - One of the strings is outside of kernel address space +*/ +__bpf_kfunc int bpf_strnstr(const char *s1__ign, const char *s2__ign, size_t len) +{ +char c1, c2; +int i, j; + +if (!copy_from_kernel_nofault_allowed (s1__ign,1 ) || + !copy_from_kernel_nofault_allowed (s2__ign,1 )) { +return -ERANGE ; + }
Quoted 8 lines
kernel/bpf/helpers.c __bpf_kfunc void __bpf_trap(void) · line 3621
Quoted 5 lines
kernel/bpf/helpers.c +5
-0+ +guard (pagefault)(); +for (i =0 ; i <XATTR_SIZE_MAX ; i++) { +for (j =0 ; i + j < len && j <XATTR_SIZE_MAX ; j++) { +__get_kernel_nofault (&c1, s1__ign + j, char, err_out);move this after you check
c2 == 0below? why reading this character if we are not going to compare it?
Good point, will move it.
Quoted 14 lines
Quoted 14 lines
kernel/bpf/helpers.c +13
-0+__get_kernel_nofault (&c2, s2__ign + j, char, err_out); +if (c2 =='\0' ) +return i; +if (c1 =='\0' ) +return -1 ; +if (c1 != c2) +break ; + } +if (j ==XATTR_SIZE_MAX ) +return -E2BIG ; +if (i + j == len) +return -1 ; + s1__ign++;
Quoted 8 lines
Quoted 6 lines
kernel/bpf/helpers.c +6
-0+ } +return -E2BIG ; +err_out: +return -EFAULT ; +} +[...]
Thanks for the reviews!
I'll wait a couple more days for potential reviews for the other patches before sending the next revision.
Viktor