From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B7DFC49ED6 for ; Tue, 10 Sep 2019 11:57:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D17FF21019 for ; Tue, 10 Sep 2019 11:57:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fN37gePq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388030AbfIJL4l (ORCPT ); Tue, 10 Sep 2019 07:56:41 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42749 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387824AbfIJL4k (ORCPT ); Tue, 10 Sep 2019 07:56:40 -0400 Received: by mail-wr1-f66.google.com with SMTP id q14so19603050wrm.9 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=pfF/uzUObmtIXi94uB5Gnthoa5lMmjOqujvEPWgthRM+TSp/SaYXTj2ZYcCot9GaoB wlW8hQ9FUT3I4/AOiUeFsfbDlDFxzIjMzNHnd+H7wBrI/ykeyNOUinGOpAmtlJDrqKpi gUwxiN2NSKCfxpoS3IyjSagISCRILXR671WlyJGGikdUPMdG+wZuYh96Hc6Wjx57cPlS K4XFWITwjsK5Mp61fmJBwdGQN5qVCoLAOpMdSchOC58upDbsg3ootpnXISNjk75WDVjc y/W/00OXNNyxzv1YPCoab/Lps7PpCrWf9d1ONW0twgykYYJbvUZPmKdMqcTMnJxsZPQQ o98g== X-Gm-Message-State: APjAAAWN/QS0m/7XqV2c/+9hLxXjHCbYwVYyijwISS4NBCkMFSkfBRo/ c/esSy6mHoU0nepHFdu+Bt5aoA== X-Google-Smtp-Source: APXvYqx5bCZdZM8ig5BWorMuJCs6R0fLGHDD6n+wdFQaD3/uF7xN9UX6qDjEC4Ak4zVX4HLaU+dLvQ== 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: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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