Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4560074imm; Fri, 18 May 2018 07:08:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoCQH5WXc7kX8SSN/RxxKUpQovNPerAgcTvGfomlxuv8fxA3xzQdFMknxtTdgD2yj8JbeO6 X-Received: by 2002:a62:ed12:: with SMTP id u18-v6mr9669746pfh.127.1526652501780; Fri, 18 May 2018 07:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526652501; cv=none; d=google.com; s=arc-20160816; b=A0OWhsYSsNnby1f1lp/t7nBCTUJedynLhKMthCbC+ol4QNAqus9FUSf9Zr05jmphjg chZ6H4K9lwWUIlH5cOYWN7hhdq4eAxA0HPwGJX2SAtE5KAJnZ243L753xiDmgnMIcLek 1/Zcj+hJGUY9kcBxe1w8wEm1PeY040xRBpLeSCboD0ZSPwg+i2V0IxU7k2BAfJLRb+29 TPPK4/iBTaghxXB3fo3dLEn4dxJBnhCC/Z3dog9iS7BaYWNZgQ2PwsP106lpHHWKZOFo YjIT8Xu7JoyhyXyG/PXdjbI+uwlWzwJraYcS6lywK8UJgGJgIDclSG/9Xh+UkkDutdUY 0FNQ== 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=jlxdgyYjKLIoR37viILj9Jj2Lxy3nj5FB37wb7q/fFI=; b=GMI4kkA7sGt5u15E0Te3Aq3hI72iFIgXmgbPyUixax82MrI3MjqjxXkhU5qws/GZvF WWGpSZjcXI+RLqqIVeU20E7STLoXLkQWCmC+lPoWL+TgR4XHlhU1sTiAVEioYTF7NdDQ O/xCom4MAfWlWwuU2dUQbeUfnV4EabaxTj6pUbDGF1mdb/tZQhka2jLx0iP+pWmgkrB3 8VZIrfqYFoBPknWL2LcXgJEM4H4Fn9xMc78CLspIg27R//9YSs3AC/0lIMf1q9GcKk7J cQX11DSvSCvxlaD0NQ7rwgCXUvpfNduM7FU2Qydu2Jdv6bo0TrvjqcF3AlFW0qQyedhO Xjbw== 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 d9-v6si7649856plj.573.2018.05.18.07.08.07; Fri, 18 May 2018 07:08:21 -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 S1752663AbeEROHk (ORCPT + 99 others); Fri, 18 May 2018 10:07:40 -0400 Received: from gofer.mess.org ([88.97.38.141]:54477 "EHLO gofer.mess.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752059AbeEROHd (ORCPT ); Fri, 18 May 2018 10:07:33 -0400 Received: by gofer.mess.org (Postfix, from userid 1000) id E1F116078C; Fri, 18 May 2018 15:07:30 +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 v4 1/3] bpf: bpf_prog_array_copy() should return -ENOENT if exclude_prog not found Date: Fri, 18 May 2018 15:07:28 +0100 Message-Id: <36f48c3a4a563bd8cdac18bcf8d48c0d06365863.1526651592.git.sean@mess.org> 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. 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 2194c6a9df42..198848837783 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1566,6 +1566,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 @@ -1574,14 +1575,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 ce2cbbff27e4..daf36acb2a17 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1005,6 +1005,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