Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5605847ybe; Tue, 10 Sep 2019 06:21:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvcoUbd10LXqT2bCO2Qc9+liiw/TCfei6ZWp1NKVXVCGQWQ+gdh0CUZyVG70xDjEWnLGYP X-Received: by 2002:a50:e691:: with SMTP id z17mr30707123edm.84.1568121699646; Tue, 10 Sep 2019 06:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568121699; cv=none; d=google.com; s=arc-20160816; b=YKtCAsByeqTQy5ZTpynzlkjOQd0EBlWmFgkwmINM78AmHkwjBILb3NZvZvXbOid0M7 LHmB3imvfMy8u6BHV32ICFrnquxM7VC8ZyVT7F9lkq8J2kORfIu1nvyPS1awktYRVNIb TTdwWgR7x6hdeULzm+sW9YUsXMbyLTr29Zv+0zmMW00NqQ64h6zr97cO5EZyUpqbW3Su Vnew8b0THv0Fcv6YCf1XOU6CQCZkUkkOAiKcb32ynMWa2bmflDvmYq4M/pFmjs3mSTqv ReCtNF7HKiwQvQn8jWvNDr2KqtKctyHd3oBSAcsBw1eAAd2l518c1HSBDawzAqNy0knb osXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t15c8HaxO7PieQmaQJo6m5Fa3LC9U0plzJQkm4Wyt4U=; b=oYyCBR+nwbkupvDqyrrYt19lvfnqe3BH5zxyTVD90rfK11v40+kxUqbRnCTUpSSpid CCl4vac89q/RlpFSzaLn7x1UQU89tLiuI5GuSP6WJrWLp/iF6RbtPrRCDoOoCdHio/Bp XR6bpoBAeqdC1JZy6LWsMRx3SnjWV6CkzCUnnsnfIYjwXZ5FhfVhz/oIdIsXWYzVrYaa KSXKfIMcXBVhFZ2xUrnqJy2gNk5kXUC/DDbN42dURY/0OBh2mWD4OSnshj0zjwiXxUG/ Fp91szvBBeoFVJyLb9foFWwJE3cLJXQG9LRAnpZwQzs8E22iXl14vPsxrnRZ8tC9rd0t gWkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fN37gePq; 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 f47si10843120ede.263.2019.09.10.06.21.11; Tue, 10 Sep 2019 06:21:39 -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=fN37gePq; 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 S2388159AbfIJL4m (ORCPT + 99 others); Tue, 10 Sep 2019 07:56:42 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36866 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733144AbfIJL4k (ORCPT ); Tue, 10 Sep 2019 07:56:40 -0400 Received: by mail-wr1-f68.google.com with SMTP id i1so19028452wro.4 for ; Tue, 10 Sep 2019 04:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t15c8HaxO7PieQmaQJo6m5Fa3LC9U0plzJQkm4Wyt4U=; b=fN37gePq6j/onKdsWODRjgRB0RSIEAzJkFNsmZsO7Rj/2Ydz5NSbjvpWNzIbAy9pA/ 9oxN0X6e2Zy8DSUr+5l7voWWPCZHxmcHB9aPMViYyGqKV2xJO+fJXtKd2cTvIS+oWUAb U/eQ9hzmSg0IgzNvMa+MSbiuuwdf05LgDQSFQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t15c8HaxO7PieQmaQJo6m5Fa3LC9U0plzJQkm4Wyt4U=; b=Qqya+uJOLFYkT4Mv3NBEjyP9kZGYa1dLcvLMNf1yuMlpQuA7P9yEeYsUfOO1eTtL5L MMhcq06Y8SQclsw6Gx4RE3fkKK/d4stbJ0VY9E6U5Yu295woYxNiMCW7viVmE4JQxGbr EQh9GyGck6Xe+8AYhYOdFIFPmbAZ8qHTiOKhTdjKbsfaTyOF7ZXqmZ4STH+YFI6XD4S5 2LmmwycMa8rp3p+O5NgJTwaanFAX7rUB4BJXMmGGeAaNgAmGMt6ZJ33xCeEEb0mMd25C tZu6sNmYgVdrQedgB+HWXof1e50bbvcgnz7M0ONJBjK/uZLrnT7injBIMnNXGKQTavel EPjg== X-Gm-Message-State: APjAAAVfHz46YgVra6Y8UI5uCP3rrL9X40vVNq7eUcjfupKw5Jzz0U4o wNrFmaOIwhEkQc8WuzT/5kD7wlZEkDc= X-Received: by 2002:adf:dd04:: with SMTP id a4mr26091671wrm.340.1568116598261; Tue, 10 Sep 2019 04:56:38 -0700 (PDT) Received: from kpsingh-kernel.c.hoisthospitality.com (110.8.30.213.rev.vodafone.pt. [213.30.8.110]) by smtp.gmail.com with ESMTPSA id q19sm23732935wra.89.2019.09.10.04.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 04:56:37 -0700 (PDT) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Jann Horn , Matthew Garrett , Christian Brauner , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Florent Revest , Martin KaFai Lau , Song Liu , Yonghong Song , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Nicolas Ferre , Stanislav Fomichev , Quentin Monnet , Andrey Ignatov , Joe Stringer Subject: [RFC v1 09/14] krsi: Add a helper function for bpf_perf_event_output Date: Tue, 10 Sep 2019 13:55:22 +0200 Message-Id: <20190910115527.5235-10-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910115527.5235-1-kpsingh@chromium.org> References: <20190910115527.5235-1-kpsingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: KP Singh This helper is mapped to the existing operation BPF_FUNC_perf_event_output. An example usage of this function would be: #define BUF_SIZE 64; struct bpf_map_def SEC("maps") perf_map = { .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, .key_size = sizeof(int), .value_size = sizeof(u32), .max_entries = MAX_CPUS, }; SEC("krsi") int bpf_prog1(void *ctx) { char buf[BUF_SIZE]; int len; u64 flags = BPF_F_CURRENT_CPU; /* some logic that fills up buf with len data*/ len = fill_up_buf(buf); if (len < 0) return len; if (len > BU) return 0; bpf_perf_event_output(ctx, &perf_map, flags, buf len); return 0; } A sample program that showcases the use of bpf_perf_event_output is added later. Signed-off-by: KP Singh --- security/krsi/ops.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/security/krsi/ops.c b/security/krsi/ops.c index a61508b7018f..57bd304a03f4 100644 --- a/security/krsi/ops.c +++ b/security/krsi/ops.c @@ -111,6 +111,26 @@ static bool krsi_prog_is_valid_access(int off, int size, return false; } +BPF_CALL_5(krsi_event_output, void *, log, + struct bpf_map *, map, u64, flags, void *, data, u64, size) +{ + if (unlikely(flags & ~(BPF_F_INDEX_MASK))) + return -EINVAL; + + return bpf_event_output(map, flags, data, size, NULL, 0, NULL); +} + +static const struct bpf_func_proto krsi_event_output_proto = { + .func = krsi_event_output, + .gpl_only = true, + .ret_type = RET_INTEGER, + .arg1_type = ARG_PTR_TO_CTX, + .arg2_type = ARG_CONST_MAP_PTR, + .arg3_type = ARG_ANYTHING, + .arg4_type = ARG_PTR_TO_MEM, + .arg5_type = ARG_CONST_SIZE_OR_ZERO, +}; + static const struct bpf_func_proto *krsi_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog @@ -121,6 +141,8 @@ static const struct bpf_func_proto *krsi_prog_func_proto(enum bpf_func_id return &bpf_map_lookup_elem_proto; case BPF_FUNC_get_current_pid_tgid: return &bpf_get_current_pid_tgid_proto; + case BPF_FUNC_perf_event_output: + return &krsi_event_output_proto; default: return NULL; } -- 2.20.1