net: add sanity check in proto_register()

prot->memory_allocated should only be set if prot->sysctl_mem
is also set.

This is a followup of commit 2520611151 ("crypto: af_alg - get
rid of alg_memory_allocated").

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20220216171801.3604366-1-eric.dumazet@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Dumazet 2022-02-16 09:18:01 -08:00 committed by Jakub Kicinski
parent 60f8ad2392
commit f20cfd662a
1 changed files with 4 additions and 0 deletions

View File

@ -3718,6 +3718,10 @@ int proto_register(struct proto *prot, int alloc_slab)
{
int ret = -ENOBUFS;
if (prot->memory_allocated && !prot->sysctl_mem) {
pr_err("%s: missing sysctl_mem\n", prot->name);
return -EINVAL;
}
if (alloc_slab) {
prot->slab = kmem_cache_create_usercopy(prot->name,
prot->obj_size, 0,