]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: sockmap update rollback on error can incorrectly dec prog refcnt
authorJohn Fastabend <john.fastabend@gmail.com>
Thu, 17 May 2018 21:06:35 +0000 (14:06 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 17 May 2018 22:27:37 +0000 (00:27 +0200)
commita359370379dacf09df76e0cd18e3fab9d9a0f731
tree1e5780ac1e66e6cb26d999fe70a9e0980e793d66
parent26397a1c28cb7eb5562aaa039052ceb90ffc2359
bpf: sockmap update rollback on error can incorrectly dec prog refcnt

If the user were to only attach one of the parse or verdict programs
then it is possible a subsequent sockmap update could incorrectly
decrement the refcnt on the program. This happens because in the
rollback logic, after an error, we have to decrement the program
reference count when its been incremented. However, we only increment
the program reference count if the user has both a verdict and a
parse program. The reason for this is because, at least at the
moment, both are required for any one to be meaningful. The problem
fixed here is in the rollback path we decrement the program refcnt
even if only one existing. But we never incremented the refcnt in
the first place creating an imbalance.

This patch fixes the error path to handle this case.

Fixes: ceebdc27c8d6 ("bpf: sockmap, remove STRPARSER map_flags and add multi-map support")
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/sockmap.c