Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1746364ybb; Thu, 26 Mar 2020 06:37:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vutUC5x295M5B8LBGCu4Pcyey0VZK107F2DvxvHcOi1sq8b16RAy99NO4+VO8Urmvj9KXjz X-Received: by 2002:a9d:62c6:: with SMTP id z6mr6208311otk.328.1585229864080; Thu, 26 Mar 2020 06:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585229864; cv=none; d=google.com; s=arc-20160816; b=Ky/k24kXkGXY34lLVJuAIOgh9zHydy9CyzQwtNi48d6ol917jqDdy3m+GD+FLj8zDy kiPiWBPodJBkZONQxcVZtzxlRm4oFAfNoKk/0tmk24+XW6vllUvQUJktBj1A5tjC4p9j WS9H2EQObq7LgfaYGropyV6VYsr8qpsn92wE86C3Zm6K0nq35zfhhXcoFSt3O+QXeBnl vuZ0jR0RD8YFgDLBNB/GsmZvWM7QRdR2JRpk337cZHdfNSwqC+kFjuoaJ4glmrcmOvPP B8Iqnp5nieYQBGchwpNBzZUItQn/7e+DzS3XIt9CyibHgzduB7wbnDtE78CKI1jV0FPi 0ATQ== 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=V3FPFqQqihDv51B2EC+6j3PXfsDAs8xWIOORX4GI6BE=; b=h4LP+1u6h2x+hfhLBIij6TDIK1tZOYK5GxC6mgExa45++eEuvYMpJ15XyBGapWazok NOIywRXQYzf0FK8brWCDmte7TklwU1PrnltQOmH0CoXXXZsKDFtvaqWhVCTHNvHEiMo/ ysUerg0GMo3U7qvfsJn9SIH4XfDbANYa65EAxJbBgkJpnEIfACX7DsAxqn+sI0oKgvhO AtAGdxVLl/QiWLMddUeAwnmsNXN4b8kRtxXO8u8hZiv5/H67KeNDoWaIb5PI63IA8cWo HDhaVPcawkQtM5pzwQ/3ggF+GfuDGKeVb3HAVyB5e4TYYpdhc7RDsQCyIOxA3HA258zD NrSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OU2CdvNf; 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 y3si1087223otq.204.2020.03.26.06.37.30; Thu, 26 Mar 2020 06:37:44 -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=OU2CdvNf; 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 S1727647AbgCZNfx (ORCPT + 99 others); Thu, 26 Mar 2020 09:35:53 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43384 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727541AbgCZNfx (ORCPT ); Thu, 26 Mar 2020 09:35:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id m11so1915886wrx.10 for ; Thu, 26 Mar 2020 06:35:52 -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=V3FPFqQqihDv51B2EC+6j3PXfsDAs8xWIOORX4GI6BE=; b=OU2CdvNfnHQaPtqcTFjw0kBWW1Zulr0Dh2t5tSDDdbEQSnD+WiGxBdCRQaJw0EWvuq AwqWxe+eanybPcnewJ7F/Ue57ukfTcoex0adU6mKHeWbco4+p4uSSq7T1+tlXANOtTt5 v24dc7WmHf+rjs04tY5UYE0vPE5YUPItM3+yM= 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=V3FPFqQqihDv51B2EC+6j3PXfsDAs8xWIOORX4GI6BE=; b=lWmxtuoRjLfDomMl1kskuYeAqc0vOmxnO9o4JAde7Nsxjhtqjh3uzyMwkc1B8s7Rnk KxHoSqAHnKvPBl3fBbFNihwUIT+IdiRPOG8TN3hMawM9O3SVeHkixQhp6rz2EsvANIBV MKQkQDYQY8Glq0hCCbACXadwJsEEUohHlkpRdAexuMUicqnW1D721LUTJAS169WGpPQP EQtK3kNvRraT8FS6SHbXBpMedRV4eWPctRSyk2VNVR4SNdJ0P389buBndlDgbedV+z3U /LSCh4Zvyrb1RpRh/g3CEiA2UZyq38Q0uTHxMG48Cc5TEGgaenXsorf7CMSmhtM/ziIi 3jlw== X-Gm-Message-State: ANhLgQ0GxpoSbKjj2H53O2xepfT5rH0gouwERFbIjy6jaiAfvWH8aple ELWjry6oIimofQbsxIwFdsid/A== X-Received: by 2002:adf:916f:: with SMTP id j102mr9015893wrj.335.1585229751684; Thu, 26 Mar 2020 06:35:51 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id q185sm3713058wme.10.2020.03.26.06.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 06:35:51 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Thu, 26 Mar 2020 14:35:47 +0100 To: Andrii Nakryiko Cc: open list , bpf , 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 v6 4/8] bpf: lsm: Implement attach, detach and execution Message-ID: <20200326133547.GB8575@chromium.org> References: <20200325152629.6904-1-kpsingh@chromium.org> <20200325152629.6904-5-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 25-M?r 18:49, Andrii Nakryiko wrote: > On Wed, Mar 25, 2020 at 8:27 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_lsm.h | 11 ++++++++ > > kernel/bpf/bpf_lsm.c | 28 +++++++++++++++++++++ > > kernel/bpf/btf.c | 9 ++++++- > > kernel/bpf/syscall.c | 56 ++++++++++++++++++++++++++++------------- > > kernel/bpf/trampoline.c | 17 ++++++++++--- > > kernel/bpf/verifier.c | 19 +++++++++++--- > > 6 files changed, 113 insertions(+), 27 deletions(-) > > > > [...] > > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > > index 85567a6ea5f9..3ba30fd6101e 100644 > > --- a/kernel/bpf/syscall.c > > +++ b/kernel/bpf/syscall.c > > @@ -25,6 +25,7 @@ > > #include > > #include > > #include > > +#include [...] > > - if (prog->expected_attach_type == BPF_TRACE_RAW_TP) > > + if (prog->expected_attach_type == BPF_TRACE_RAW_TP) { > > this should probably also ensure prog->type == BPF_PROG_TYPE_TRACING ? > Otherwise you can trick kernel with BPF_PROG_TYPE_LSM and > expected_attach_type == BPF_TRACE_RAW_TP, no? Indeed, fixed. Thanks! - KP > > > tp_name = prog->aux->attach_func_name; > > - else > > - return bpf_tracing_prog_attach(prog); > > - } else { > > + break; > > + } > > + return bpf_tracing_prog_attach(prog); > > + case BPF_PROG_TYPE_RAW_TRACEPOINT: > > + case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE: > > if (strncpy_from_user(buf, > > u64_to_user_ptr(attr->raw_tracepoint.name), > > sizeof(buf) - 1) < 0) { > > @@ -2479,6 +2495,10 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) > > } > > [...]