lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 22 May 2024 19:32:07 +0100
From: Simon Horman <horms@...nel.org>
To: Vadim Fedorenko <vadfed@...a.com>
Cc: Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
	Martin KaFai Lau <martin.lau@...ux.dev>,
	Andrii Nakryiko <andrii@...nel.org>,
	Alexei Starovoitov <ast@...nel.org>,
	Mykola Lysenko <mykolal@...com>, Jakub Kicinski <kuba@...nel.org>,
	bpf@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpf: add CHECKSUM_COMPLETE to bpf test progs

On Wed, May 22, 2024 at 07:57:10AM -0700, Vadim Fedorenko wrote:
> Add special flag to validate that TC BPF program properly updates
> checksum information in skb.
> 
> Signed-off-by: Vadim Fedorenko <vadfed@...a.com>

...

> diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
> index f6aad4ed2ab2..841552785c65 100644
> --- a/net/bpf/test_run.c
> +++ b/net/bpf/test_run.c
> @@ -974,10 +974,13 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
>  	int hh_len = ETH_HLEN;
>  	struct sk_buff *skb;
>  	struct sock *sk;
> +	__wsum csum;
> +	__sum16 sum;

Hi Vadim,

sum seems to be is unused in this function.
And, fwiiw, the scope of csum looks like it could be reduced.

>  	void *data;
>  	int ret;
>  
> -	if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size)
> +	if ((kattr->test.flags & ~BPF_F_TEST_SKB_CHECKSUM_COMPLETE) ||
> +	    kattr->test.cpu || kattr->test.batch_size)
>  		return -EINVAL;
>  
>  	data = bpf_test_init(kattr, kattr->test.data_size_in,
> @@ -1025,6 +1028,12 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
>  
>  	skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
>  	__skb_put(skb, size);
> +
> +	if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) {
> +		skb->csum = skb_checksum(skb, 0, skb->len, 0);
> +		skb->ip_summed = CHECKSUM_COMPLETE;
> +	}
> +
>  	if (ctx && ctx->ifindex > 1) {
>  		dev = dev_get_by_index(net, ctx->ifindex);
>  		if (!dev) {
> @@ -1079,6 +1088,14 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
>  	}
>  	convert_skb_to___skb(skb, ctx);
>  
> +	if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) {
> +		csum = skb_checksum(skb, 0, skb->len, 0);
> +		if (skb->csum != csum) {
> +			ret = -EINVAL;
> +			goto out;
> +		}
> +	}
> +
>  	size = skb->len;
>  	/* bpf program can never convert linear skb to non-linear */
>  	if (WARN_ON_ONCE(skb_is_nonlinear(skb)))

...

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ