Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4063690ybb; Mon, 23 Mar 2020 12:46:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtVnImtv6BSsDcZV6/y0FRA45QUZbHt1+w4eQg0CLG3bbyujNvhrvhlmBaGrn8JLEoAiYfI X-Received: by 2002:a05:6830:1358:: with SMTP id r24mr18689094otq.337.1584992800100; Mon, 23 Mar 2020 12:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584992800; cv=none; d=google.com; s=arc-20160816; b=JOc2nUHZT5qWRxq0uW1Syay+EgsHmuc9gIHoA0tE/nwM9fEvz/tLKrwKE7tXh2v2z8 F6V2oJUPXgCKfkSk3pn/CEQxtC7CVom8vl4kJrX/IYzyKCdxjP3XmXHw1tknXWBwhIfb o1BV0noTC0C/0FExOd79YumOh69Dl8B9YLQTtXCtd9N+RVxLsRxkYf5N7D10DO3+d1NM wyIoLmoV6eVqqPuyswtQ42ft+vQ1bPQSlixBqVpx9516EcyZ89Ez02tLYVGDDoT7DagY /Kkj3FfFL2yuL5SoU53LrlKIJruC91g2iiN+o0DXuCrsmlTce8e/A/OlZ4krVDEEppp4 Xc1w== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=VPTbVbHjbimek43chtj4q4jGy4zz4Aerrx5erMEH+Rc=; b=ep0ErBBNrbGMX5aa8dmoEItkOMCY1GTnviRFa8Dl1wEaVnecmH6W5XmwzUKdOiMZh5 YThClGiMzuucOh16iyzi9gilQmB2yb2pOKW8D8LuSzrNgK8TPZtHZPNj8XdYGzJgBYVK UnSBfL89tennSnMGVatauINsFS3iNTUgC/dg/YFHfcSWS3oPDk+pySRBvhfHsULY1V8o t0pqwdW+acDsPupc78TF8AkWlxUnBfQb+40tmhLJ6DXA1Q87AD6IW9V05o8nPL2ynkXv yq2Y0xs6Z914fnfXryYRSihdmOjx9PG+/qTkLZbSkePvyx1QbBTBhht/Iph96Yxel1S5 cC9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NIcVqOL8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h23si9141135otk.294.2020.03.23.12.46.27; Mon, 23 Mar 2020 12:46:40 -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=@chromium.org header.s=google header.b=NIcVqOL8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726204AbgCWTog (ORCPT + 99 others); Mon, 23 Mar 2020 15:44:36 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36907 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbgCWTof (ORCPT ); Mon, 23 Mar 2020 15:44:35 -0400 Received: by mail-wm1-f67.google.com with SMTP id d1so914089wmb.2 for ; Mon, 23 Mar 2020 12:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=VPTbVbHjbimek43chtj4q4jGy4zz4Aerrx5erMEH+Rc=; b=NIcVqOL8Hcu2/424YGZ28OCTXzD6TkjF7KtL6DTv9OThUdUUPcvGtXPZx0xQXrJTko DfhPLmC9cc39I2qXIOUrPhKv/OZqHmTgXzCGJpYpkZMIB/5ui0f21hAhliaxKRjZSMyD lYZxc8FEriRy0PRfvXgwgMiiYg0lamphqkKI0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=VPTbVbHjbimek43chtj4q4jGy4zz4Aerrx5erMEH+Rc=; b=PB2nFjxA9prg9SXhE+4X3dZ8y8fD1hZwSjlaoyfHqzQuT6klV+4hlxiN/4y1raxlW/ PtmZ9EoYYm7870K+03rWDnar+c87i9i+kjoKgvtk7fSpnaMmLVE6k2RQKKIsorgovVwT 7X1U+c/yUMRjECKPabrKIRRBCPvlo3oAAAxQHztYwjrhCbfEq4nlSjtD2zHdZ/BTKEWv H7kNYJNKEuYk7PymUXj4duWjOv0IOXxBiwWqJDnYzTvWjknn5bMUAgJNOuU/ZNFIto6s B6ItPb+EW9LYxw/q/o6T4Jdf/VUOHFV2K9limJ28z+cVLG8Vt+l5cjf9VaXYZSqIzOGD /ZWA== X-Gm-Message-State: ANhLgQ2Ti6WpP/9bHSYqhnWLLh3vCGb3zyXBZ2zDAA8tgIF530vBPf+Y oPxy9T5kOt/437OH0AD7rh7+xw== X-Received: by 2002:a05:600c:2146:: with SMTP id v6mr1092762wml.155.1584992672996; Mon, 23 Mar 2020 12:44:32 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id w204sm910043wma.1.2020.03.23.12.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 12:44:32 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Mon, 23 Mar 2020 20:44:30 +0100 To: Yonghong Song Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman Subject: Re: [PATCH bpf-next v5 4/7] bpf: lsm: Implement attach, detach and execution Message-ID: <20200323194430.GA18787@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-5-kpsingh@chromium.org> <3455719d-1359-cdba-431e-e7d06e5b398b@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3455719d-1359-cdba-431e-e7d06e5b398b@fb.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23-M?r 12:16, Yonghong Song wrote: > > > On 3/23/20 9:44 AM, KP Singh wrote: > > From: KP Singh > > > > JITed BPF programs are dynamically attached to the LSM hooks > > using BPF trampolines. The trampoline prologue generates code to handle > > conversion of the signature of the hook to the appropriate BPF context. > > > > The allocated trampoline programs are attached to the nop functions > > initialized as LSM hooks. > > > > BPF_PROG_TYPE_LSM programs must have a GPL compatible license and > > and need CAP_SYS_ADMIN (required for loading eBPF programs). > > > > Upon attachment: > > > > * A BPF fexit trampoline is used for LSM hooks with a void return type. > > * A BPF fmod_ret trampoline is used for LSM hooks which return an > > int. The attached programs can override the return value of the > > bpf LSM hook to indicate a MAC Policy decision. > > > > Signed-off-by: KP Singh > > Reviewed-by: Brendan Jackman > > Reviewed-by: Florent Revest > > --- > > include/linux/bpf.h | 4 ++++ > > include/linux/bpf_lsm.h | 11 +++++++++++ > > kernel/bpf/bpf_lsm.c | 29 +++++++++++++++++++++++++++++ > > kernel/bpf/btf.c | 9 ++++++++- > > kernel/bpf/syscall.c | 26 ++++++++++++++++++++++---- > > kernel/bpf/trampoline.c | 17 +++++++++++++---- > > kernel/bpf/verifier.c | 19 +++++++++++++++---- > > 7 files changed, 102 insertions(+), 13 deletions(-) > > > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index af81ec7b783c..adf2e5a6de4b 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -433,6 +433,10 @@ struct btf_func_model { > > * programs only. Should not be used with normal calls and indirect calls. > > */ > > #define BPF_TRAMP_F_SKIP_FRAME BIT(2) > > +/* Override the return value of the original function. This flag only makes > > + * sense for fexit trampolines. > > + */ > > +#define BPF_TRAMP_F_OVERRIDE_RETURN BIT(3) > > Whether the return value is overridable is determined by hook return type as > below. Do we still need this flag? Apologies, this is a relic and should not have been there, will send a new revision with this removed. - KP > > > /* Each call __bpf_prog_enter + call bpf_func + call __bpf_prog_exit is ~50 > > * bytes on x86. Pick a number to fit into BPF_IMAGE_SIZE / 2 > [...]