Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1745894ybb; Thu, 26 Mar 2020 06:37:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvu/ckS17L27GxY5Hi5aaYs5HcqNOAXnR3CZ3oj6b3QGlihANLBd3m/qbrlqfOqNNGWYlDA X-Received: by 2002:aca:c552:: with SMTP id v79mr34530oif.156.1585229828042; Thu, 26 Mar 2020 06:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585229828; cv=none; d=google.com; s=arc-20160816; b=nyxs5ccOHcgFVo26K4rCbBYaIDLc4Y4mvDTpJHuB5a7Tx8FwY2jP6v+WLRB/8qPvzZ vCUsG5JdSj6wZ+gTnCmMIeVX5tnubnwe/q+U0+TsWE7dkxdwJuF4zj399QUD/qKKzIMT He1mEcFepcB1qkJfhe5KBx1Q6qMJHL2dW/LXIv1dqc+X3Z4AW8ptKgPxWsnSZPtTdQbg OYXqrKYJOoIa44DkzFn3oVEsvZW/WmE3IRZQgD6sYHfb+mtowH4m07HrhPxKCgc9PVv1 9i3O7q7LpdU5tAFBbs1NzQT7HudSBOVD2cvwPt+JEQMHJX97buUnDaIJpLHpq3cnVvzu wKCQ== 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=ovCKN6r26UhRylA1vm+kwz+TJf7uPDzl6lowndnjD70=; b=t0LIzMZZdly3B7t34BpviM6lCdu3eFQQlDC1x7+ThQZGhC3SUo9iBVu9RfRxss1tX4 mNOfBcyP0ObrTV6ytY8doAgUn9iVrtwaPq1+DQuWABGEiK5NtWhS5ojeWthXYX8txRM3 Qg2qXmwLLwYqYowEwTXEDUqe3CwyTWo+65qHZC1xoGG9fQHKaTM1mdqCnc+6jvmktu74 me3/fb412FDeT5OwDXUjZAM7NciKQisYBVtJjrD5Dtb3z291kvIVtZI19FsaeKzY3vhy 5SVi3XdxlgGHoGl06xbUxooY2zVtgwy1WvhnrpwOpo66OE1nMJDeXaFABmHk8cqY0ydS W7kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="aX7Amg/4"; 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 r6si1061232oti.159.2020.03.26.06.36.54; Thu, 26 Mar 2020 06:37:08 -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="aX7Amg/4"; 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 S1727695AbgCZNg1 (ORCPT + 99 others); Thu, 26 Mar 2020 09:36:27 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45270 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgCZNg0 (ORCPT ); Thu, 26 Mar 2020 09:36:26 -0400 Received: by mail-wr1-f68.google.com with SMTP id t7so7758274wrw.12 for ; Thu, 26 Mar 2020 06:36:25 -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=ovCKN6r26UhRylA1vm+kwz+TJf7uPDzl6lowndnjD70=; b=aX7Amg/46758K2hIawHd5YOPoDrIwsKkKCmkQGPWJLgpI5bZnube9C0/LCQnSGvwUP iV0QhWaOjaN7p9ZMwc8S8wSy9SSSu7TLsY4Zvtr09q7OeW0wtfFfAw0U+ZvFSyVA8SP0 da49F5jmKwK9hxv9Vjyrxo69UW1Zb58H1Roiw= 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=ovCKN6r26UhRylA1vm+kwz+TJf7uPDzl6lowndnjD70=; b=KMGTYYlZg4qrFnYR6XY/j57ZbQ+zt/KpFngmJCRwfia9kEqlbGOM9mYekN3rMDga9b psvP8EHXcfLB/tncQ4VIO4NjBDoKwlWwmnQAmIl/NOB0bRgedts9cMmMDMl3vsRGNwNA 1NZAycMM+gzZ4nn/jPtLKLRzBP+SFGQIBSID3eXiARsSPt12lAwPtnOvaeJ6vr00muXI ukt6CnB9MyR2bBfTyJs4xy3l+ZuqY30CuMxEsf/6Pb0z2K1OfYGwrybPjbsdvRBtMJnR 2lsacCxHx+2tq++MEgdDe8d15VmjVVURV16NOyYxiRMot67hA4aivzTyY/v6dgZojbwN WZdg== X-Gm-Message-State: ANhLgQ1fFVj9eSwgm/wMmv9RK7UH5NwrUp2ozRqXCqNbpunhzZkThld5 sg2IxYIcs60wex5r53VPiiJ8zg== X-Received: by 2002:adf:f0c5:: with SMTP id x5mr9499607wro.415.1585229784324; Thu, 26 Mar 2020 06:36:24 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id a186sm3499256wmh.33.2020.03.26.06.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 06:36:23 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Thu, 26 Mar 2020 14:36:17 +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 v6 7/8] bpf: lsm: Add selftests for BPF_PROG_TYPE_LSM Message-ID: <20200326133617.GC8575@chromium.org> References: <20200325152629.6904-1-kpsingh@chromium.org> <20200325152629.6904-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 25-M?r 19:01, Andrii Nakryiko wrote: > On Wed, Mar 25, 2020 at 8:27 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 > > --- > > tools/testing/selftests/bpf/config | 2 + > > .../selftests/bpf/prog_tests/test_lsm.c | 84 +++++++++++++++++++ > > tools/testing/selftests/bpf/progs/lsm.c | 48 +++++++++++ > > 3 files changed, 134 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/test_lsm.c > > create mode 100644 tools/testing/selftests/bpf/progs/lsm.c > > > > [...] > > > + > > +int exec_cmd(int *monitored_pid) > > +{ > > + int child_pid; > > + > > + child_pid = fork(); > > + if (child_pid == 0) { > > + *monitored_pid = getpid(); > > + execvp(CMD_ARGS[0], CMD_ARGS); > > + return -EINVAL; > > + } else if (child_pid > 0) > > This test is part of test_progs, so let's be a good citizen and wait > for your specific child. I'd rather not hunt for elusive bugs later, > so please use waitpid() instead. Good idea. Done. - KP > > Otherwise looks good and clean, thanks! > > > + return wait(NULL); > > + > > + return -EINVAL; > > +} > > + > > [...]