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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 058A6EE14C3 for ; Wed, 6 Sep 2023 23:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233003AbjIFX6r (ORCPT ); Wed, 6 Sep 2023 19:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231187AbjIFX6p (ORCPT ); Wed, 6 Sep 2023 19:58:45 -0400 Received: from sonic309-27.consmr.mail.ne1.yahoo.com (sonic309-27.consmr.mail.ne1.yahoo.com [66.163.184.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89BE910F7 for ; Wed, 6 Sep 2023 16:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1694044720; bh=tRjWz5xTmyODV3eJ2DcADpEY+4F+IbUA23RJut/dyxQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=BsoBap4exTpmD0r0/roS3aSJdT4imQBkyc8oQYQzEOjCW/6BxlWAZ77I8N6rTivghAEBT66yf9hKHkb+SIzJX5wgSOnLBImf9eIOY7IL4/aXlsP1nb8JsdtYZAjN7sSBsfr/1vnoh+5hOfT3o58BtP52TBuf+khL4D75vlT897g+/Pw3yqnImFEhdOKNA61zFrPHwujLyD5vQ9lT9neodz9u3X6rMOwoO1ZkoqrZjgMK4lH2687Ly3ncbccay57zTWYpTG2qOGNwO4CKoIr25xEEUgh9o4u0ddPpXbGWpFifdzUa/uKZOu1Ejz1nHbd/btK5MpT2lYvADP+iSYL8oA== X-SONIC-DKIM-SIGN: v=1; a=rsa-s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fJVUQ1zwC93g_clm9PWKpQIg7lWy9QcSwnIEjHTwxlcNJCY7eP.hkPM3TqBjpTOoIgIbxEp6P9gE soLAJPKJKUg9rzOGhVCAS8.AIiACsXbqN6dWX7amz4hQ5k2.sFj8_CnwEOWmm4bSOb69uvZHCGDS 9LIX6NpZUihmCYXkxDCefx3malHkXQJE1XKwxfHhiIACKVGEm6BO_m3.qO.TZG8yaMI86PjyOcmC yw1v0LYgJs4qZ6SD7oTvXUkVoIPITTGEtHHhDdVRrv2m52KC7ZteVwpQRCnEG5O.dWNM4lZ_nO6D B_rhr.1KSELkI.pzpWksyAd9m47l9Dm4idJ_8tGbv72cA9AVG29KwXbfdIJUz8KfPhHBlTrccuhn 3apGAS_UDYH8pmcWW8pDZWNTeOm0LV3f9ChxWWklBAgXy61KDLrbeEZEE89MNvFhAUxyFWm2clQo ZmOZeOe1b1jCG2uGZIPDwwa0xN9OOvS8Bv.0cPcGrXHzSmSSvahlDaY1ddFCjYeJVFB9XLbBo3qz iWJUUt4XElxbG.BWG7aX9kmF.4F.tL1wlwCw4BZAxQEKjwBU5leZvy95.EkkMGujgVVwt2EtkI9D pGF1W5RYyemrzZicbDC3xlKnCZBRqV0eMVU1eLMvBixVRrjmeYbadMOZ1nQ.6o5iy6pb358UQOmE xE_Im1wHRi2x1G.c- X-Sonic-MF: X-Sonic-ID: 9a27b2be-e813-4ee3-ad8c-a0d353044ee7 Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Wed, 6 Sep 2023 23:58:40 +0000 Received: by hermes--production-bf1-865889d799-5m62n (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0ff25f29cdc434fda842453459ee2cee; Wed, 06 Sep 2023 23:48:08 +0000 (UTC) Message-ID: Date: Wed, 6 Sep 2023 16:48:04 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH v14 4/11] LSM: syscalls for current process attributes Content-Language: en-US To: Paul Moore , linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mic@digikod.net, Casey Schaufler References: <20230828195802.135055-5-casey@schaufler-ca.com> <6bdfc1b73926b16fc4eea848f25275ed.paul@paul-moore.com> From: Casey Schaufler In-Reply-To: <6bdfc1b73926b16fc4eea848f25275ed.paul@paul-moore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.21763 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Precedence: bulk List-ID: On 9/6/2023 4:22 PM, Paul Moore wrote: > On Aug 28, 2023 Casey Schaufler wrote: >> Create a system call lsm_get_self_attr() to provide the security >> module maintained attributes of the current process. >> Create a system call lsm_set_self_attr() to set a security >> module maintained attribute of the current process. >> Historically these attributes have been exposed to user space via >> entries in procfs under /proc/self/attr. >> >> The attribute value is provided in a lsm_ctx structure. The structure >> identifies the size of the attribute, and the attribute value. The format >> of the attribute value is defined by the security module. A flags field >> is included for LSM specific information. It is currently unused and must >> be 0. The total size of the data, including the lsm_ctx structure and any >> padding, is maintained as well. >> >> struct lsm_ctx { >> __u64 id; >> __u64 flags; >> __u64 len; >> __u64 ctx_len; >> __u8 ctx[]; >> }; >> >> Two new LSM hooks are used to interface with the LSMs. >> security_getselfattr() collects the lsm_ctx values from the >> LSMs that support the hook, accounting for space requirements. >> security_setselfattr() identifies which LSM the attribute is >> intended for and passes it along. >> >> Signed-off-by: Casey Schaufler >> Reviewed-by: Kees Cook >> Reviewed-by: Serge Hallyn >> Reviewed-by: John Johansen >> --- >> Documentation/userspace-api/lsm.rst | 70 +++++++++++++ >> include/linux/lsm_hook_defs.h | 4 + >> include/linux/lsm_hooks.h | 1 + >> include/linux/security.h | 19 ++++ >> include/linux/syscalls.h | 5 + >> include/uapi/linux/lsm.h | 36 +++++++ >> kernel/sys_ni.c | 2 + >> security/Makefile | 1 + >> security/lsm_syscalls.c | 57 +++++++++++ >> security/security.c | 146 ++++++++++++++++++++++++++++ >> 10 files changed, 341 insertions(+) >> create mode 100644 Documentation/userspace-api/lsm.rst >> create mode 100644 security/lsm_syscalls.c > .. > >> diff --git a/security/security.c b/security/security.c >> index 82253294069c..aa4ade1f71b9 100644 >> --- a/security/security.c >> +++ b/security/security.c >> @@ -3798,6 +3798,152 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) >> } >> EXPORT_SYMBOL(security_d_instantiate); >> >> +/** >> + * security_getselfattr - Read an LSM attribute of the current process. >> + * @attr: which attribute to return >> + * @uctx: the user-space destination for the information, or NULL >> + * @size: pointer to the size of space available to receive the data >> + * @flags: special handling options. LSM_FLAG_SINGLE indicates that only >> + * attributes associated with the LSM identified in the passed @ctx be >> + * reported. >> + * >> + * A NULL value for @uctx can be used to get both the number of attributes >> + * and the size of the data. >> + * >> + * Returns the number of attributes found on success, negative value >> + * on error. @size is reset to the total size of the data. >> + * If @size is insufficient to contain the data -E2BIG is returned. >> + */ >> +int security_getselfattr(unsigned int attr, struct lsm_ctx __user *uctx, >> + size_t __user *size, u32 flags) >> +{ >> + struct security_hook_list *hp; >> + struct lsm_ctx lctx = { .id = LSM_ID_UNDEF, }; >> + u8 __user *base = (u8 __user *)uctx; >> + size_t total = 0; >> + size_t entrysize; >> + size_t left; >> + bool toobig = false; >> + bool single = false; >> + int count = 0; >> + int rc; >> + >> + if (attr == LSM_ATTR_UNDEF) >> + return -EINVAL; >> + if (size == NULL) >> + return -EINVAL; >> + if (get_user(left, size)) >> + return -EFAULT; >> + >> + if (flags) { >> + /* >> + * Only flag supported is LSM_FLAG_SINGLE >> + */ >> + if (flags & LSM_FLAG_SINGLE) >> + return -EINVAL; > Should this be something like the following? > > if (flags & ~LSM_FLAG_SINGLE) > return -EINVAL; Yes. I have a fix ready. There are a couple other touch-ups, too. > >> + if (uctx && >> + copy_struct_from_user(&lctx, sizeof(lctx), uctx, left)) >> + return -EFAULT; >> + /* >> + * If the LSM ID isn't specified it is an error. >> + */ >> + if (lctx.id == LSM_ID_UNDEF) >> + return -EINVAL; >> + single = true; >> + } >> + >> + /* >> + * In the usual case gather all the data from the LSMs. >> + * In the single case only get the data from the LSM specified. >> + */ >> + hlist_for_each_entry(hp, &security_hook_heads.getselfattr, list) { >> + if (single) { >> + if (count > 0) >> + break; >> + if (lctx.id != hp->lsmid->id) >> + continue; >> + } >> + entrysize = left; >> + if (base) >> + uctx = (struct lsm_ctx __user *)(base + total); >> + rc = hp->hook.getselfattr(attr, uctx, &entrysize, flags); >> + if (rc == -EOPNOTSUPP) { >> + rc = 0; >> + continue; >> + } >> + if (rc == -E2BIG) { >> + toobig = true; >> + left = 0; >> + total += entrysize; >> + continue; >> + } >> + if (rc < 0) >> + return rc; >> + >> + left -= entrysize; >> + total += entrysize; >> + count += rc; >> + } >> + if (put_user(total, size)) >> + return -EFAULT; >> + if (toobig) >> + return -E2BIG; >> + if (count == 0) >> + return LSM_RET_DEFAULT(getselfattr); >> + return count; >> +} > > -- > paul-moore.com