Re: [Potential Spoof] [PATCH v2 bpf] bpf: Sanitize the bpf_struct_ops tcp-cc name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 13, 2020 at 05:51:40PM -0700, Martin KaFai Lau wrote:
> The bpf_struct_ops tcp-cc name should be sanitized in order to
> avoid problematic chars (e.g. whitespaces).
> 
> This patch reuses the bpf_obj_name_cpy() for accepting the same set
> of characters in order to keep a consistent bpf programming experience.
> A "size" param is added.  Also, the strlen is returned on success so
> that the caller (like the bpf_tcp_ca here) can error out on empty name.
> The existing callers of the bpf_obj_name_cpy() only need to change the
> testing statement to "if (err < 0)".  For all these existing callers,
> the err will be overwritten later, so no extra change is needed
> for the new strlen return value.
> 
> v2:
> - Save the orig_src to avoid "end - size" (Andrii)
> 
> Fixes: 0baf26b0fcd7 ("bpf: tcp: Support tcp_congestion_ops in bpf")
> Acked-by: Andrii Nakryiko <andriin@xxxxxx>
> Signed-off-by: Martin KaFai Lau <kafai@xxxxxx>
> ---
>  include/linux/bpf.h   |  1 +
>  kernel/bpf/syscall.c  | 25 ++++++++++++++-----------
>  net/ipv4/bpf_tcp_ca.c |  7 ++-----
>  3 files changed, 17 insertions(+), 16 deletions(-)
> 
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 49b1a70e12c8..212991f6f2a5 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -160,6 +160,7 @@ static inline void copy_map_value(struct bpf_map *map, void *dst, void *src)
>  }
>  void copy_map_value_locked(struct bpf_map *map, void *dst, void *src,
>  			   bool lock_src);
> +int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size);
>  
>  struct bpf_offload_dev;
>  struct bpf_offloaded_map;
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 0c7fb0d4836d..11d96a2625f2 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -696,14 +696,15 @@ int bpf_get_file_flag(int flags)
>  		   offsetof(union bpf_attr, CMD##_LAST_FIELD) - \
>  		   sizeof(attr->CMD##_LAST_FIELD)) != NULL
>  
> -/* dst and src must have at least BPF_OBJ_NAME_LEN number of bytes.
> - * Return 0 on success and < 0 on error.
> +/* dst and src must have at least "size" number of bytes.
> + * Return strlen on success and < 0 on error.
>   */
> -static int bpf_obj_name_cpy(char *dst, const char *src)
> +int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size)
>  {
> -	const char *end = src + BPF_OBJ_NAME_LEN;
> +	const char *orig_src = src;
> +	const char *end = src + size;
messed up the xmas style.  fixing in v3.

>  
> -	memset(dst, 0, BPF_OBJ_NAME_LEN);
> +	memset(dst, 0, size);
>  	/* Copy all isalnum(), '_' and '.' chars. */
>  	while (src < end && *src) {
>  		if (!isalnum(*src) &&



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux