From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mauricio Vasquez B Subject: [RFC PATCH bpf-next v2 2/4] bpf: restrict use of peek/push/pop Date: Fri, 31 Aug 2018 23:26:00 +0200 Message-ID: <153575075998.30050.14181063558477405003.stgit@kernel> References: <153575074884.30050.17670029209466860207.stgit@kernel> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org Return-path: Received: from fm2nodo5.polito.it ([130.192.180.19]:60817 "EHLO fm2nodo5.polito.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727234AbeIABfc (ORCPT ); Fri, 31 Aug 2018 21:35:32 -0400 In-Reply-To: <153575074884.30050.17670029209466860207.stgit@kernel> Sender: netdev-owner@vger.kernel.org List-ID: Restrict the use of peek, push and pop helpers only to queue and stack maps. Signed-off-by: Mauricio Vasquez B --- kernel/bpf/verifier.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 5bd67feb2f07..9e177ff4a3b9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2172,6 +2172,13 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env, if (func_id != BPF_FUNC_sk_select_reuseport) goto error; break; + case BPF_MAP_TYPE_QUEUE: + case BPF_MAP_TYPE_STACK: + if (func_id != BPF_FUNC_map_peek_elem && + func_id != BPF_FUNC_map_pop_elem && + func_id != BPF_FUNC_map_push_elem) + goto error; + break; default: break; } @@ -2227,6 +2234,13 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env, if (map->map_type != BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) goto error; break; + case BPF_FUNC_map_peek_elem: + case BPF_FUNC_map_pop_elem: + case BPF_FUNC_map_push_elem: + if (map->map_type != BPF_MAP_TYPE_QUEUE && + map->map_type != BPF_MAP_TYPE_STACK) + goto error; + break; default: break; }