Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1333005imm; Sun, 27 May 2018 04:25:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqVBGuX+2Tc6weuJEbJbNZlWVOzkzTbMmm0u+p8XxUaMMpDuaWzSzA2IzHNlGLuGl+o7+sA X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr9702422plb.26.1527420318148; Sun, 27 May 2018 04:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527420318; cv=none; d=google.com; s=arc-20160816; b=QYAGwlx/srk9RojQqlLCEJ6b3FqhpCi0sdCgJa16jCR8YAQJUCvZKOUlvYjmX/hpRv JoNYiS74UybtLlcCW6Wq4WniNm2Dcqspp2Q1Uv4g60ec813Rl9VJkZRfYibYsIPEqwOn QG9fI0+ti14TUbN//9A+WoUG99ZNZp2cPSlpBDjo/c6NuF1BVJCHVs/UeuCSwAVqsbNW zpORXK91ARlaz+v281z/QL6lAtMhwcNKZYHkNealiiJMsDZRKC1QxU+RegLZuQY4+zOz zBkz5VhqcS9WGc5WhGjthL5TtCcGiEhT3DM2xJNECgeQmRJpXRb5gN6b/V/eA8gYU3ya GEcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from :arc-authentication-results; bh=kKwQ/UaHPB6r79W8J7qTXTaGwxu2ZoT8PHYGQNTsJr0=; b=lA5hm8V1FdB8XiyzW29EEmQV7WG+UA1c9gT6lyUr84UXlCmwcR8I3heGLjJ+FGzvvV +FmwqqMAFlUKq690PzoNpyiSgoQHPHHKkwsBw6ZahwFAIWavifpLwvx1wzpGcD6hD6wE 35SPh2O/UVh0JnHh67N3Z4utzq/jOrVc9TUCf8nAmpqXwbPpZOYANtemE6HCt9GIILyb 71TY2YVnVi/j65WD5cf577kjAmZ9oBYl9lntTDu4Lng/uaxBtGHJG6s+/pj5mOI2PFFw f6Nbpi4nfEaAGJNOPouhpNcA23elRfzhW6+ESKezUQEC+w2KH95oI/KIDnDc/hjbjlko bRIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11-v6si16797449pgt.356.2018.05.27.04.25.03; Sun, 27 May 2018 04:25:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755254AbeE0LYQ (ORCPT + 99 others); Sun, 27 May 2018 07:24:16 -0400 Received: from gofer.mess.org ([88.97.38.141]:49335 "EHLO gofer.mess.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755127AbeE0LYO (ORCPT ); Sun, 27 May 2018 07:24:14 -0400 Received: by gofer.mess.org (Postfix, from userid 1000) id C529060C5D; Sun, 27 May 2018 12:24:10 +0100 (BST) From: Sean Young To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Mauro Carvalho Chehab , Daniel Borkmann , netdev@vger.kernel.org, Matthias Reichl , Devin Heitmueller , Y Song , Quentin Monnet Subject: [PATCH v5 1/3] bpf: bpf_prog_array_copy() should return -ENOENT if exclude_prog not found Date: Sun, 27 May 2018 12:24:08 +0100 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This makes is it possible for bpf prog detach to return -ENOENT. Acked-by: Yonghong Song Signed-off-by: Sean Young --- kernel/bpf/core.c | 11 +++++++++-- kernel/trace/bpf_trace.c | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index b574dddc05b8..527587de8a67 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1616,6 +1616,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, int new_prog_cnt, carry_prog_cnt = 0; struct bpf_prog **existing_prog; struct bpf_prog_array *array; + bool found_exclude = false; int new_prog_idx = 0; /* Figure out how many existing progs we need to carry over to @@ -1624,14 +1625,20 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, if (old_array) { existing_prog = old_array->progs; for (; *existing_prog; existing_prog++) { - if (*existing_prog != exclude_prog && - *existing_prog != &dummy_bpf_prog.prog) + if (*existing_prog == exclude_prog) { + found_exclude = true; + continue; + } + if (*existing_prog != &dummy_bpf_prog.prog) carry_prog_cnt++; if (*existing_prog == include_prog) return -EEXIST; } } + if (exclude_prog && !found_exclude) + return -ENOENT; + /* How many progs (not NULL) will be in the new array? */ new_prog_cnt = carry_prog_cnt; if (include_prog) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 81fdf2fc94ac..af1486d9a0ed 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1006,6 +1006,8 @@ void perf_event_detach_bpf_prog(struct perf_event *event) old_array = event->tp_event->prog_array; ret = bpf_prog_array_copy(old_array, event->prog, NULL, &new_array); + if (ret == -ENOENT) + goto unlock; if (ret < 0) { bpf_prog_array_delete_safe(old_array, event->prog); } else { -- 2.17.0