Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3548035pxb; Mon, 16 Nov 2020 18:44:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxEAHWTfyKvLjhAc+vUQ+8Qvmo+toKRZQNQJ9CELJtBlyMuZpwXOdhFJ6MT8kj7O54XyKbQ X-Received: by 2002:a50:cc48:: with SMTP id n8mr19366020edi.137.1605581065262; Mon, 16 Nov 2020 18:44:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605581065; cv=none; d=google.com; s=arc-20160816; b=uHOV+GA11igwnMt0uZSiAYOxezLC2gyyA0eSELwkHarPJba2Gdb6DvpoT//5FiUlv6 OwJfxlQ7/kOh/SazxxZ9xRxkl/Mfl49A5mXlOTW8KKNoM66dGq5r9EYCXUQpx6VF0p0w +1tuH8DCzpb3VN+qNn63JjAKGOioR3X2CoBaxDXQXXt1ql1gi8SygeeszDZ9NvHiBZ8r Jy9GJxDUqEHjoS2lvGz7wCLYifwy/rlFXqQ5NpWoabuEewzA11fLO3trtfW7vCmJ36ZT PFq7TIu/khHj8M4t+v8UQ7CMgk2c0XHlGErfrVEqyv1+WQNa2QW0p6CEgJZA/13nRQFd koaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YfmeEzTzooKWiWXCjbwP20V8N58LWWLSI+WemXBqoSo=; b=wSa14ytblhaTuvzF7FgPzZ4Xjz5KuLHWpF/7MviF+yhqFaPwU35kkq3gqoHRjI7e6+ TFIAMunvdf2soRFp8SSCD0p+XJsDqmJSSmL91vYZCdlC0b9A6ee78l7PA/bg9eWOhoBE 6qrwQitBgQLuQ0oDF7HDZ3mV2Via0yL1ikJRZne2Vcpn3xY5xIBFI56WP6o9Jc15ELJU VgZ/5Pi3vWucIb4teughi3M0vtAIiADFIQUzlTF7gf4LWAGnCyxpobt+nOqkAMIHjLnp Ul2a0AaMpHxx5Qc25qzRPDwqGOyo+GH570ekIVI+hzae79nh9KUA0c0MEO3EFFavBx3R lG5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TupcO9kk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id x16si13100090ejy.343.2020.11.16.18.43.58; Mon, 16 Nov 2020 18:44:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TupcO9kk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727041AbgKQBzS (ORCPT + 99 others); Mon, 16 Nov 2020 20:55:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgKQBzR (ORCPT ); Mon, 16 Nov 2020 20:55:17 -0500 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ADF8C0613CF for ; Mon, 16 Nov 2020 17:55:16 -0800 (PST) Received: by mail-lj1-x244.google.com with SMTP id h23so22446641ljg.13 for ; Mon, 16 Nov 2020 17:55:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YfmeEzTzooKWiWXCjbwP20V8N58LWWLSI+WemXBqoSo=; b=TupcO9kkun3hFmFaHl+Hd59DU33+9i2l1KglJF0L5RdSg05j11UByYlDKCEr906/SB 06DminEu3QjwEzyvvFnwk5AzhzWZVlLL3sleE4dH+4wlNwJ9YMZL6PCAyIhx7/LGUV8p pydxIu3TUTFSQf4Mdti2YUr3a+qqqtQZxjcGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YfmeEzTzooKWiWXCjbwP20V8N58LWWLSI+WemXBqoSo=; b=gqlgZbJpyy1QnS+BNa4yo0m1XimfY5Rt2RKOk+UlUlYRVh91+V1Sj/aHGLB39JXTns Ejyf31oJOPK5KJhNDNod0l8MuzXY8qG5NYn3UEXE6dPu7rtChMu3eJmXOv3Rt44D9EJO LFYlSPB9zdDj8KqsRFamlqbWtGjQ7lG5N7CgEOhNl01Bu8JhYtoexgfN6bDoPq0ZsTmp AjfqKOEyoo/3uaC5SwyWFJ/5aJ8WEU4vhKephUQbTjK9H5FGCF9IAwEXvZ1eZw8+qd19 N6b11/RZog6G0Xf3iKy7xRuRJVwlBsNU5kQ7SgY7Ccz/jLizneuq26AwP2qPvS++1RnO cLDQ== X-Gm-Message-State: AOAM532mvFnPKEktRM6eM0lnanYoaDblO6qIWm7BzkhN328oQNX6i46S l9lm6pRRHDFFLIfOrri8zWwFXG+Teor5qkvyUOwemg== X-Received: by 2002:a2e:b16f:: with SMTP id a15mr896846ljm.430.1605578114448; Mon, 16 Nov 2020 17:55:14 -0800 (PST) MIME-Version: 1.0 References: <20201116232536.1752908-1-kpsingh@chromium.org> <20201116232536.1752908-2-kpsingh@chromium.org> <20201117004303.zpzoqluhslwbp7ce@kafai-mbp.dhcp.thefacebook.com> In-Reply-To: <20201117004303.zpzoqluhslwbp7ce@kafai-mbp.dhcp.thefacebook.com> From: KP Singh Date: Tue, 17 Nov 2020 02:55:03 +0100 Message-ID: Subject: Re: [PATCH bpf-next v2 2/2] bpf: Add tests for bpf_lsm_set_bprm_opts To: Martin KaFai Lau Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Florent Revest , Brendan Jackman , Pauline Middelink Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 17, 2020 at 1:43 AM Martin KaFai Lau wrote: > > On Mon, Nov 16, 2020 at 11:25:36PM +0000, KP Singh wrote: > > From: KP Singh > > > > The test forks a child process, updates the local storage to set/unset > > the securexec bit. > > > > The BPF program in the test attaches to bprm_creds_for_exec which checks > > the local storage of the current task to set the secureexec bit on the > > binary parameters (bprm). > > > > The child then execs a bash command with the environment variable > > TMPDIR set in the envp. The bash command returns a different exit code > > based on its observed value of the TMPDIR variable. > > > > Since TMPDIR is one of the variables that is ignored by the dynamic > > loader when the secureexec bit is set, one should expect the > > child execution to not see this value when the secureexec bit is set. > > > > Signed-off-by: KP Singh > > --- > > .../selftests/bpf/prog_tests/test_bprm_opts.c | 124 ++++++++++++++++++ > > tools/testing/selftests/bpf/progs/bprm_opts.c | 34 +++++ > > 2 files changed, 158 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bprm_opts.c > > create mode 100644 tools/testing/selftests/bpf/progs/bprm_opts.c > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/test_bprm_opts.c b/tools/testing/selftests/bpf/prog_tests/test_bprm_opts.c > > new file mode 100644 > > index 000000000000..cba1ef3dc8b4 > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/prog_tests/test_bprm_opts.c > > @@ -0,0 +1,124 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +/* > > + * Copyright (C) 2020 Google LLC. > > + */ > > + > > +#include > > +#include > Is it needed? No, Good catch, removed. > > > +#include [...] > > + * If the value of TMPDIR is set, the bash command returns 10 > > + * and if the value is unset, it returns 20. > > + */ > > + ret = execle("/bin/bash", "bash", "-c", > > + "[[ -z \"${TMPDIR}\" ]] || exit 10 && exit 20", > > + NULL, bash_envp); > > + if (ret) > It should never reach here? May be just exit() unconditionally > instead of having a chance to fall-through and then return -EINVAL. Agreed. changed it to exit(errno); here. > > > + exit(errno); > > + } else if (child_pid > 0) { > > + waitpid(child_pid, &child_status, 0); > > + ret = WEXITSTATUS(child_status); > > + > > + /* If a secureexec occured, the exit status should be 20. > > + */ > > + if (secureexec && ret == 20) > > + return 0; > > + > > + /* If normal execution happened the exit code should be 10. > > + */ > > + if (!secureexec && ret == 10) > > + return 0; > > + > > + return ret; > Any chance that ret may be 0? I think it's safer to just let it fall through and return -EINVAL, so I removed the return ret here. > > > + } [...] > > + 0 /* secureexec */); > > + if (CHECK(err, "run_set_secureexec:0", "err = %d", err)) > nit. err = %d"\n" Fixed. > > > + goto close_prog; > > + > > + /* Run the test with the secureexec bit set */ > > + err = run_set_secureexec(bpf_map__fd(skel->maps.secure_exec_task_map), > > + 1 /* secureexec */); > > + if (CHECK(err, "run_set_secureexec:1", "err = %d", err)) > Same here. Fixed. - KP > > Others LGTM.