Re: [PATCH bpf 1/7] bpf: Add the missing BPF_LINK_TYPE invocation for sockmap

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

 



On Tue, Oct 8, 2024 at 2:05 AM Hou Tao <houtao@xxxxxxxxxxxxxxx> wrote:
>
> From: Hou Tao <houtao1@xxxxxxxxxx>
>
> There is an out-of-bounds read in bpf_link_show_fdinfo() for the sockmap
> link fd. Fix it by adding the missing BPF_LINK_TYPE invocation for
> sockmap link
>
> Also add comments for bpf_link_type to prevent missing updates in the
> future.
>
> Fixes: 699c23f02c65 ("bpf: Add bpf_link support for sk_msg and sk_skb progs")
> Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx>
> ---
>  include/linux/bpf_types.h | 1 +
>  include/uapi/linux/bpf.h  | 3 +++
>  2 files changed, 4 insertions(+)
>
> diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h
> index 9f2a6b83b49e..fa78f49d4a9a 100644
> --- a/include/linux/bpf_types.h
> +++ b/include/linux/bpf_types.h
> @@ -146,6 +146,7 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp)
>  BPF_LINK_TYPE(BPF_LINK_TYPE_NETFILTER, netfilter)
>  BPF_LINK_TYPE(BPF_LINK_TYPE_TCX, tcx)
>  BPF_LINK_TYPE(BPF_LINK_TYPE_NETKIT, netkit)
> +BPF_LINK_TYPE(BPF_LINK_TYPE_SOCKMAP, sockmap)
>  #endif
>  #ifdef CONFIG_PERF_EVENTS
>  BPF_LINK_TYPE(BPF_LINK_TYPE_PERF_EVENT, perf)
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index e8241b320c6d..4a939c90dc2e 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -1121,6 +1121,9 @@ enum bpf_attach_type {
>
>  #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
>
> +/* Add BPF_LINK_TYPE(type, name) in bpf_types.h to keep bpf_link_type_strs[]
> + * in sync with the definitions below.
> + */


Let's also add some static assert making sure that bpf_link_type_strs
(and probably same for other types) size is equal to
__MAX_BPF_LINK_TYPE? Comment is good to remind us, but compilation
error is better.

>  enum bpf_link_type {
>         BPF_LINK_TYPE_UNSPEC = 0,
>         BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
> --
> 2.29.2
>





[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