Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3547574pxb; Mon, 16 Nov 2020 18:43:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6lYmRrwmvXhLmzU66/0SpF0ZeZzAukUmxILH252qsmWBCSLPWbE6awHptfUZKdC4qSrix X-Received: by 2002:a17:906:1317:: with SMTP id w23mr16913230ejb.120.1605580989110; Mon, 16 Nov 2020 18:43:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605580989; cv=none; d=google.com; s=arc-20160816; b=bX2sttl1rFfGVmuGX0z9N0GXGZDGYjuqKJp2a71nOD4V9o0GWcTPPXGGae5JYAifdq tWhr3BmJtJek9vGZn6w9u9LzCRFKU8ativcvgCefKbK3AS/rro/Fijd07yXjMRVEAZ7q rw4qqcB31Beoo631aKToKwTUBD1kjIFfephNsU7VZCS7mlqp/vmO3DW3bd26wQC5bfXg parudWjQghYI82BsNDkQCNi80IICrVKFVXedM8YmssfuoP0EsMoqeR0Oyg1XZ8Y4zhat eM5LC/Hdrpk/DSYnkOWtyD3jVa1gUge1Py+NmQesuQyYm591pvkkG98PbzBb9uOgHKKR dWVA== 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=yqbgq64ReeSsWVRfJZSYCmJDwtd55XetjTjMDOlnW+w=; b=mvtKvN/Fqh3u93l5gTHKUFEL1pDJUDnKEMI2ZAILwS5Mhj0Tqjekih3cvdmVhM1zrs up5dnRTrhqe3N0Epbj2ea0wrCPMFKnLdjNb63NFbplf7DMPao73BM8UWOw4pJ2o/LD8u Sj6tUIlvydtpHW9E6N4Mrag3AV/iKEYi3Vf3ika1F0bP6/qCVrc1jdiigjD1AMdmOxRo Lma+Yxh6GyQqPh1CKiNMdt7PY4kNTH7FJjS5atf2kqfJbPh+L4ki9XKeVC+0awjTXVSL vpgGk012yA0S6GSNs9hIrI1T2o2V+zKpi7AXb4I1J2TulWLLICUxUlzVFzGaOSiAM7AO mXlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HZRO+6VF; 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 pv12si12294427ejb.613.2020.11.16.18.42.46; Mon, 16 Nov 2020 18:43:09 -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=HZRO+6VF; 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 S1726211AbgKQCEM (ORCPT + 99 others); Mon, 16 Nov 2020 21:04:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgKQCEM (ORCPT ); Mon, 16 Nov 2020 21:04:12 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00A2CC0613CF for ; Mon, 16 Nov 2020 18:04:11 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id j205so27990963lfj.6 for ; Mon, 16 Nov 2020 18:04:11 -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=yqbgq64ReeSsWVRfJZSYCmJDwtd55XetjTjMDOlnW+w=; b=HZRO+6VFpomk3p/phkHzWTic70PPvGOgnTXVJZgstfa5SI7EFt4np4dBT9UeaBUIwc LhggC9VlRcHUsgmvTADl29p3Q0pvCXdJm9zs5Pws0DqGB5eYFjo26CldUtEv3j02ESS8 1Fb4L2QkC6qGQvFu70FptgZAUwMmA+DRK4NR0= 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=yqbgq64ReeSsWVRfJZSYCmJDwtd55XetjTjMDOlnW+w=; b=AFwdDGrZAy5M8KggGwkAM83XuokjYfRPjv9iAqtDpu1r0zr4SEPZj25HvBQpMTVpTH mC5wz08MMlPuuAGzE7YpdstH8MtJvIzyTkCuBNRFUK2PAnpzNpkYljwEFjZ1Q33iP0n1 9Y+0QNQkbn20UY2FdkA2rR/U7NhHA6U2O9HtAEhJfMCVg3c/NWS6y4PWl5aSz+OfOfNu cYybjS6+6B12mXfOYn++vEfJ6I803q2+uoQqZfA4m0QRrQsKjrpxS4pouxvgrdEv7Z2v P05XdEWSJ4eiMYg2C4CMaaq49hOhFbzW7bzxl9DJFOarPaqLqoO37Ao5kvKwLya6GESI IPGg== X-Gm-Message-State: AOAM532MBdhv6RbF54F8Ff94YnrOwPIpEgO4PTVyX9DdQBVWLLAPi0pr laox3NObP8c/7hDP7SatubLMdp2BsEGrhaRzVun2sQ== X-Received: by 2002:ac2:5591:: with SMTP id v17mr763576lfg.562.1605578650470; Mon, 16 Nov 2020 18:04:10 -0800 (PST) MIME-Version: 1.0 References: <20201116232536.1752908-1-kpsingh@chromium.org> <20201117001128.7bepy37cxuymfwr3@kafai-mbp.dhcp.thefacebook.com> In-Reply-To: <20201117001128.7bepy37cxuymfwr3@kafai-mbp.dhcp.thefacebook.com> From: KP Singh Date: Tue, 17 Nov 2020 03:03:59 +0100 Message-ID: Subject: Re: [PATCH bpf-next v2 1/2] bpf: Add bpf_lsm_set_bprm_opts helper 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:11 AM Martin KaFai Lau wrote: > > On Mon, Nov 16, 2020 at 11:25:35PM +0000, KP Singh wrote: > > From: KP Singh > > > > The helper allows modification of certain bits on the linux_binprm > > struct starting with the secureexec bit which can be updated using the > > BPF_LSM_F_BPRM_SECUREEXEC flag. > > > > secureexec can be set by the LSM for privilege gaining executions to set > > the AT_SECURE auxv for glibc. When set, the dynamic linker disables the > > use of certain environment variables (like LD_PRELOAD). > > > > Signed-off-by: KP Singh > > --- > > include/uapi/linux/bpf.h | 14 ++++++++++++++ > > kernel/bpf/bpf_lsm.c | 27 +++++++++++++++++++++++++++ > > scripts/bpf_helpers_doc.py | 2 ++ > > tools/include/uapi/linux/bpf.h | 14 ++++++++++++++ > > 4 files changed, 57 insertions(+) > > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > index 162999b12790..7f1b6ba8246c 100644 > > --- a/include/uapi/linux/bpf.h > > +++ b/include/uapi/linux/bpf.h > > @@ -3787,6 +3787,14 @@ union bpf_attr { > > * *ARG_PTR_TO_BTF_ID* of type *task_struct*. > > * Return > > * Pointer to the current task. > > + * > > + * long bpf_lsm_set_bprm_opts(struct linux_binprm *bprm, u64 flags) > > + * > > + * Description > > + * Sets certain options on the *bprm*: > > + * > > + * **BPF_LSM_F_BPRM_SECUREEXEC** Set the secureexec bit > > + * which sets the **AT_SECURE** auxv for glibc. > The return value needs to be documented also. Done. > > > */ > > #define __BPF_FUNC_MAPPER(FN) \ > > FN(unspec), \ > > @@ -3948,6 +3956,7 @@ union bpf_attr { > > FN(task_storage_get), \ > > FN(task_storage_delete), \ > > FN(get_current_task_btf), \ > > + FN(lsm_set_bprm_opts), \ > > /* */ > > > > /* integer value in 'imm' field of BPF_CALL instruction selects which helper > > @@ -4119,6 +4128,11 @@ enum bpf_lwt_encap_mode { > > BPF_LWT_ENCAP_IP, > > }; > > > > +/* Flags for LSM helpers */ > > +enum { > > + BPF_LSM_F_BPRM_SECUREEXEC = (1ULL << 0), > > +}; > > + > > #define __bpf_md_ptr(type, name) \ > > union { \ > > type name; \ > > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > > index 553107f4706a..31f85474a0ef 100644 > > --- a/kernel/bpf/bpf_lsm.c > > +++ b/kernel/bpf/bpf_lsm.c > > @@ -7,6 +7,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -51,6 +52,30 @@ int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, > > return 0; > > } > > > > +/* Mask for all the currently supported BPRM option flags */ > > +#define BPF_LSM_F_BRPM_OPTS_MASK 0x1ULL > If there is a need to have v3, it will be better to use > BPF_LSM_F_BPRM_SECUREEXEC instead of 0x1ULL. Done. > > > + > > +BPF_CALL_2(bpf_lsm_set_bprm_opts, struct linux_binprm *, bprm, u64, flags) > > +{ > > + > > + if (flags & ~BPF_LSM_F_BRPM_OPTS_MASK) > > + return -EINVAL; > > + > > + bprm->secureexec = (flags & BPF_LSM_F_BPRM_SECUREEXEC); > The intention of this helper is to set "or clear" a bit? > It may be useful to clarify the "clear" part in the doc also. Updated the docs: * long bpf_lsm_set_bprm_opts(struct linux_binprm *bprm, u64 flags) * * Description * Set or clear certain options on *bprm*: * * **BPF_LSM_F_BPRM_SECUREEXEC** Set the secureexec bit * which sets the **AT_SECURE** auxv for glibc. The bit is * is cleared if the flag is not specified. * Return * **-EINVAL** if invalid *flags* are passed. > > > + return 0; > > +} > > +