Received: by 10.223.164.221 with SMTP id h29csp185011wrb; Fri, 3 Nov 2017 07:32:28 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QWPVDoL0sT4mwX22AAdNoRC5z8V1PtrZA7AFkDQQrtieF44j84kt3iWmWJe7v1xZxE5amd X-Received: by 10.159.218.1 with SMTP id v1mr6770189plp.288.1509719548238; Fri, 03 Nov 2017 07:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509719548; cv=none; d=google.com; s=arc-20160816; b=PYqcxc6VaJ/LtrWYHMh9Jki673YlDUIqOywuKNwnKeVdzR3QKCl8jMUk143gMqH2G9 ieTzVDKQfzZOmhh76XLohpC1OiQuR3laXmfNyN2fXlqKw0yWFTnmkFx3TTJ2zedoMq5P D88zW24jGN5XKdDlHM/XeCGrYEcCM6JjJZ3b4bgF3hAX9ApJ52sFnV66PyBpgRR9vH8+ 0rJrbbcF6QiskrqL48cLGHncDXrMUBDqz2MYrdv/LAHzUHHi1179MpV6r3u5v62ZmQ/I OU8vXYT5dH23O8AHGJ0VPdcu0jbVVHp1vKCwEnYnZQENHAXM0mRajbanwtziNuGTuNMm QwQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=wvuKcyP0zFgWOrGXHo8z3t3R6d5oiaoCdLm/+NdPG5Q=; b=Oy2Suv70sWYDKusJTzHs5E93bUXxDgAFYcZOI4PURKINpIHKWUHkqkDttTGDrSpjq2 QvAL9K9AHD5CLyEwKq4HNcKkXL2NnxB3pqd+7qWkX0kSo90xOkKBbStY4z5edqCZV90F klch4bcMA6LT9p/4VeD6OU92yeWivnt9wruw++pkup2zdSpxhIs4UaGdCp9WbsApZLaU NkoC0akMP17o1cXcVLX8sytQefU2As8xgq1WAK0YPWbRJPqECwSRLaQCe5yJ9rXhZLkO MrZZrZCUgXKfjqAzVxNI/E4pDHtz38IZsZdeESm8p4la5TZ8ae0sbUfdt57JRCXoVy6Q NYvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=ZhKtd29i; 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 k67si6231470pga.110.2017.11.03.07.32.15; Fri, 03 Nov 2017 07:32:28 -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; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=ZhKtd29i; 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 S1755829AbdKCObl (ORCPT + 95 others); Fri, 3 Nov 2017 10:31:41 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:57295 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750971AbdKCObj (ORCPT ); Fri, 3 Nov 2017 10:31:39 -0400 Received: by mail-qt0-f193.google.com with SMTP id z28so3410567qtz.13 for ; Fri, 03 Nov 2017 07:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wvuKcyP0zFgWOrGXHo8z3t3R6d5oiaoCdLm/+NdPG5Q=; b=ZhKtd29iUK0YWY3oOCw2icDJb49iiJySE6i4soU9cQmdbitMlzn40C8C0TulCa8vcr /wYnI2T2OEwyTVX45Gk+dnlxTyn3SdKv/fWv3rt+nEtJJH6nNsaGfP2B1dcgLR4G2m4U VUoh9Tgp+wYhNS/+N8tSgSC2xJWbxu4/aTsNmQ9wy4WAZIuCxl/Ati3I2E5FCrYXIT20 Nd0WwuizoVlkXBTRQ4P1UpMuJGvhab0Hqxu6N75lSWTFoYGMUYm5onjSR+JJkIP0Usyz J2I7rJxAVtf+WEzVXlxHhYXYr0yn3uTdDD33xGF1m6qHxfh4a/TfvJgkg9sK5QYmkAhq uz3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wvuKcyP0zFgWOrGXHo8z3t3R6d5oiaoCdLm/+NdPG5Q=; b=rmIdQvIctFXuxVRXg7KJ1ng0kZ/CbWf6MmTHmQMGMGKdTH76dibIOrUAb+u7SYpURu 0AISYfwblS8YEkwy7YX3817P8jGQS3RD5qusBMhvHOCqrmWxbIhIxZuXulfIH7W0k+nR HLSWLnKAKUomFIyPeKzGH8vgQNEmNlHHFs6cC1NutSXa2dWjb8iM2u9ViyC9UitOvdvf ctomXTlBZ4cPJruMEulylb/tk1kKYsm2AUshx0pK/0P2mgnFVhx5G1g8TXkYw3Kd1+r1 tNqmVYFd8oFxzDaeIq+LN7X50qNdZJIDLsb4xvklFDqrOLEdwQkvcf6pYc7hhBvZII/a pr8w== X-Gm-Message-State: AMCzsaWM8LCTC58HX4YTdPmYqb7nDE0kY/KFlfV1ZwWeK+AtnLjyECDZ hfY4NrgsbY+bZAytzgL/uEbd/Q== X-Received: by 10.200.25.112 with SMTP id g45mr10546456qtk.40.1509719498553; Fri, 03 Nov 2017 07:31:38 -0700 (PDT) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id y7sm3811330qke.58.2017.11.03.07.31.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 07:31:37 -0700 (PDT) Date: Fri, 3 Nov 2017 10:31:36 -0400 From: Josef Bacik To: Daniel Borkmann Cc: Josef Bacik , rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ast@kernel.org, kernel-team@fb.com, Josef Bacik Subject: Re: [PATCH 1/2] bpf: add a bpf_override_function helper Message-ID: <20171103143135.bnlwu7hmtgmgjdri@destiny> References: <1509633431-2184-1-git-send-email-josef@toxicpanda.com> <1509633431-2184-2-git-send-email-josef@toxicpanda.com> <59FBA64D.1050400@iogearbox.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <59FBA64D.1050400@iogearbox.net> User-Agent: NeoMutt/20170714 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 03, 2017 at 12:12:13AM +0100, Daniel Borkmann wrote: > Hi Josef, > > one more issue I just noticed, see comment below: > > On 11/02/2017 03:37 PM, Josef Bacik wrote: > [...] > > diff --git a/include/linux/filter.h b/include/linux/filter.h > > index cdd78a7beaae..dfa44fd74bae 100644 > > --- a/include/linux/filter.h > > +++ b/include/linux/filter.h > > @@ -458,7 +458,8 @@ struct bpf_prog { > > locked:1, /* Program image locked? */ > > gpl_compatible:1, /* Is filter GPL compatible? */ > > cb_access:1, /* Is control block accessed? */ > > - dst_needed:1; /* Do we need dst entry? */ > > + dst_needed:1, /* Do we need dst entry? */ > > + kprobe_override:1; /* Do we override a kprobe? */ > > kmemcheck_bitfield_end(meta); > > enum bpf_prog_type type; /* Type of BPF program */ > > u32 len; /* Number of filter blocks */ > [...] > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index d906775e12c1..f8f7927a9152 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -4189,6 +4189,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) > > prog->dst_needed = 1; > > if (insn->imm == BPF_FUNC_get_prandom_u32) > > bpf_user_rnd_init_once(); > > + if (insn->imm == BPF_FUNC_override_return) > > + prog->kprobe_override = 1; > > if (insn->imm == BPF_FUNC_tail_call) { > > /* If we tail call into other programs, we > > * cannot make any assumptions since they can > > diff --git a/kernel/events/core.c b/kernel/events/core.c > > index 9660ee65fbef..0d7fce52391d 100644 > > --- a/kernel/events/core.c > > +++ b/kernel/events/core.c > > @@ -8169,6 +8169,13 @@ static int perf_event_set_bpf_prog(struct perf_event *event, u32 prog_fd) > > return -EINVAL; > > } > > > > + /* Kprobe override only works for kprobes, not uprobes. */ > > + if (prog->kprobe_override && > > + !(event->tp_event->flags & TRACE_EVENT_FL_KPROBE)) { > > + bpf_prog_put(prog); > > + return -EINVAL; > > + } > > Can we somehow avoid the prog->kprobe_override flag here completely > and also same in the perf_event_attach_bpf_prog() handler? > > Reason is that it's not reliable for bailing out this way: Think of > the main program you're attaching doesn't use bpf_override_return() > helper, but it tail-calls into other BPF progs that make use of it > instead. So above check would be useless and will fail and we continue > to attach the prog for probes where it's not intended to be used. > > We've had similar issues in the past e.g. c2002f983767 ("bpf: fix > checking xdp_adjust_head on tail calls") is just one of those. Thus, > can we avoid the flag altogether and handle such error case differently? > So if I'm reading this right there's no way to know what we'll tail call at any given point, so I need to go back to my previous iteration of this patch and always save the state of the kprobe in the per-cpu variable to make sure we don't use bpf_override_return in the wrong case? The tail call functions won't be in the BPF_PROG_ARRAY right? It'll be just some other arbitrary function? If that's the case then we really need something like this https://patchwork.kernel.org/patch/10034815/ and I need to bring that back right? Thanks, Josef From 1582997858782919160@xxx Thu Nov 02 23:13:20 +0000 2017 X-GM-THRID: 1582965462915356698 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread