public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: sdf@google.com
To: Xu Kuohai <xukuohai@huaweicloud.com>
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>
Subject: Re: [PATCH bpf] bpf: Fix offset calculation error in __copy_map_value and zero_map_value
Date: Fri, 11 Nov 2022 11:17:52 -0800	[thread overview]
Message-ID: <Y26f4H7buQXKqQFd@google.com> (raw)
In-Reply-To: <20221111125620.754855-1-xukuohai@huaweicloud.com>

On 11/11, Xu Kuohai wrote:
> From: Xu Kuohai <xukuohai@huawei.com>

> Function __copy_map_value and zero_map_value miscalculated copy offset,
> resulting in possible copy of unwanted data to user or kernel.

> Fix it.

> Fixes: cc48755808c6 ("bpf: Add zero_map_value to zero map value with  
> special fields")
> Fixes: 4d7d7f69f4b1 ("bpf: Adapt copy_map_value for multiple offset case")
> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
> ---
>   include/linux/bpf.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 74c6f449d81e..c1bd1bd10506 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -315,7 +315,7 @@ static inline void __copy_map_value(struct bpf_map  
> *map, void *dst, void *src, b
>   		u32 next_off = map->off_arr->field_off[i];

>   		memcpy(dst + curr_off, src + curr_off, next_off - curr_off);
> -		curr_off += map->off_arr->field_sz[i];
> +		curr_off = next_off + map->off_arr->field_sz[i];
>   	}
>   	memcpy(dst + curr_off, src + curr_off, map->value_size - curr_off);
>   }
> @@ -344,7 +344,7 @@ static inline void zero_map_value(struct bpf_map  
> *map, void *dst)
>   		u32 next_off = map->off_arr->field_off[i];

>   		memset(dst + curr_off, 0, next_off - curr_off);
> -		curr_off += map->off_arr->field_sz[i];
> +		curr_off = next_off + map->off_arr->field_sz[i];
>   	}
>   	memset(dst + curr_off, 0, map->value_size - curr_off);
>   }

Hmm, does it mean that it currently works only for the cases where
these special fields are first/last?

Also, what about bpf-next? The same problem seem to exist there?

Might be a good idea to have some selftest to exercise this?

> --
> 2.30.2


  reply	other threads:[~2022-11-11 19:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 12:56 [PATCH bpf] bpf: Fix offset calculation error in __copy_map_value and zero_map_value Xu Kuohai
2022-11-11 19:17 ` sdf [this message]
2022-11-11 20:45   ` Kumar Kartikeya Dwivedi
2022-11-12 10:25     ` Xu Kuohai
2022-11-11 19:35 ` Kumar Kartikeya Dwivedi
2022-11-11 20:50 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y26f4H7buQXKqQFd@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=xukuohai@huaweicloud.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox