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=-5.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 0F4F8C43331 for ; Thu, 26 Mar 2020 19:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8E9B206E6 for ; Thu, 26 Mar 2020 19:44:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mXue/BH8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728596AbgCZToH (ORCPT ); Thu, 26 Mar 2020 15:44:07 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54924 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbgCZToG (ORCPT ); Thu, 26 Mar 2020 15:44:06 -0400 Received: by mail-wm1-f68.google.com with SMTP id c81so8039870wmd.4 for ; Thu, 26 Mar 2020 12:44:03 -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=0Bii1s2deigTxksVQn5D4fa3g6KSqWpYF2vfQCrTCkQ=; b=mXue/BH8dMK46Q+CxoPuOCAXIhsjfNF4BBz9nY0CKpqWmSNg1EdIyHxC/ObRwwi+4Y vrbbv616X1THSsMHpH5lPr0ZnkJbdXDnByiot4haqIrWo6+ag7FMFpksuXbvMVX5B1mz KDJ9sjiU9NcbKj1KvyZfGqfFysuI5OEoyFOoY= 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=0Bii1s2deigTxksVQn5D4fa3g6KSqWpYF2vfQCrTCkQ=; b=X9GNi5qW6Tk+dUwvOCJ80BnBj37cwqB2OhEMUrkQ5Bl/L/Tllds/lVlm7mbjgGWJBV gL+FZeJZILQJrB+UjxXK+n1jw3aRKZDIfU+qZtNERF5VTU0H0ToCdMxeIOMh0KPijqzo /8aTwcIhv8NKHpatsc9cyfgKxo6bRtRyVk8YQlWbWjEEvPhtECGstjicjZGSB6NoZQ8+ eVnS3dZcidbOiuCxIa3nwQ+bHkz59pNtLoU42RhbtQ+V2uUXKPI6qTEUHiCBr4J+YNoU JrdVCgY7wTwOmCOJiFona4rLCjjjpftJZJ88t45C+DOzEvyff8SP1X8D/IPyr2rsYjfR 8WFA== X-Gm-Message-State: ANhLgQ2vFcrK/XjbZKC51Tyr2PjmGwi7pg7dk0RcLBtQRFF4L78yXAmQ gLw+ReFXFzDyMKVeSGS999iA7g== X-Google-Smtp-Source: ADFU+vv6oOna9/uYcBsBB+T/TvHqVZPZsv2Q92xO2Srm3mQHiGr5MgeyNE/xuLzjiHifH8JuX6CviQ== X-Received: by 2002:a05:600c:24c:: with SMTP id 12mr1548359wmj.186.1585251843249; Thu, 26 Mar 2020 12:44:03 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id s127sm4869574wmf.28.2020.03.26.12.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:44:02 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Thu, 26 Mar 2020 20:44:00 +0100 To: Andrii Nakryiko Cc: open list , bpf , linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Thomas Garnier , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman Subject: Re: [PATCH bpf-next v7 7/8] bpf: lsm: Add selftests for BPF_PROG_TYPE_LSM Message-ID: <20200326194400.GB15273@chromium.org> References: <20200326142823.26277-1-kpsingh@chromium.org> <20200326142823.26277-8-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 26-Mär 12:24, Andrii Nakryiko wrote: > On Thu, Mar 26, 2020 at 7:30 AM KP Singh wrote: > > > > From: KP Singh > > > > * Load/attach a BPF program that hooks to file_mprotect (int) > > and bprm_committed_creds (void). > > * Perform an action that triggers the hook. > > * Verify if the audit event was received using the shared global > > variables for the process executed. > > * Verify if the mprotect returns a -EPERM. > > > > Signed-off-by: KP Singh > > Reviewed-by: Brendan Jackman > > Reviewed-by: Florent Revest > > Reviewed-by: Thomas Garnier > > --- > > Please fix endlines below. With that: > > Acked-by: Andrii Nakryiko > > > tools/testing/selftests/bpf/config | 2 + > > .../selftests/bpf/prog_tests/test_lsm.c | 86 +++++++++++++++++++ > > tools/testing/selftests/bpf/progs/lsm.c | 48 +++++++++++ > > 3 files changed, 136 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/test_lsm.c > > create mode 100644 tools/testing/selftests/bpf/progs/lsm.c > > > > [...] > > > +void test_test_lsm(void) > > +{ > > + struct lsm *skel = NULL; > > + int err, duration = 0; > > + > > + skel = lsm__open_and_load(); > > + if (CHECK(!skel, "skel_load", "lsm skeleton failed\n")) > > + goto close_prog; > > + > > + err = lsm__attach(skel); > > + if (CHECK(err, "attach", "lsm attach failed: %d\n", err)) > > + goto close_prog; > > + > > + err = exec_cmd(&skel->bss->monitored_pid); > > + if (CHECK(err < 0, "exec_cmd", "err %d errno %d\n", err, errno)) > > + goto close_prog; > > + > > + CHECK(skel->bss->bprm_count != 1, "bprm_count", "bprm_count = %d", > > \n is missing Done. > > > + skel->bss->bprm_count); > > + > > + skel->bss->monitored_pid = getpid(); > > + > > + err = heap_mprotect(); > > + if (CHECK(errno != EPERM, "heap_mprotect", "want errno=EPERM, got %d\n", > > + errno)) > > + goto close_prog; > > + > > + CHECK(skel->bss->mprotect_count != 1, "mprotect_count", > > + "mprotect_count = %d", skel->bss->mprotect_count); > > \n is missing Done. - KP > > > + > > +close_prog: > > + lsm__destroy(skel); > > +} > > [...]