[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230724151507.6b725396@kernel.org>
Date: Mon, 24 Jul 2023 15:15:07 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Lin Ma <linma@....edu.cn>
Cc: davem@...emloft.net, edumazet@...gle.com, pabeni@...hat.com,
ast@...nel.org, martin.lau@...nel.org, yhs@...com,
andrii@...nel.org, void@...ifault.com, houtao1@...wei.com,
laoar.shao@...il.com, inwardvessel@...il.com, kuniyu@...zon.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH v1] bpf: Add length check for
SK_DIAG_BPF_STORAGE_REQ_MAP_FD parsing
On Sun, 23 Jul 2023 15:54:52 +0800 Lin Ma wrote:
> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> index d4172534dfa8..6f1afbb394a6 100644
> --- a/net/core/bpf_sk_storage.c
> +++ b/net/core/bpf_sk_storage.c
> @@ -511,6 +511,11 @@ bpf_sk_storage_diag_alloc(const struct nlattr *nla_stgs)
> if (nla_type(nla) != SK_DIAG_BPF_STORAGE_REQ_MAP_FD)
> continue;
>
> + if (nla_len(nla) < sizeof(map_fd)) {
> + err = -EINVAL;
> + goto err_free;
> + }
You can move this check earlier, when the attributes are getting
counted. That way we can avoid the alloc/free on error.
Powered by blists - more mailing lists