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 D6A41E7AD57 for ; Tue, 3 Oct 2023 14:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240047AbjJCO2Y (ORCPT ); Tue, 3 Oct 2023 10:28:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232420AbjJCO2X (ORCPT ); Tue, 3 Oct 2023 10:28:23 -0400 Received: from smtp-42ab.mail.infomaniak.ch (smtp-42ab.mail.infomaniak.ch [IPv6:2001:1600:3:17::42ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D66AB for ; Tue, 3 Oct 2023 07:28:20 -0700 (PDT) Received: from smtp-3-0001.mail.infomaniak.ch (unknown [10.4.36.108]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4S0KtW2q00zMqQ4j; Tue, 3 Oct 2023 14:28:19 +0000 (UTC) Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4S0KtV662VzMpnPj; Tue, 3 Oct 2023 16:28:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1696343299; bh=bxaiRwZbRP+DCPlU5RWsMgsAK1wN3CIFf3Qiv5AVhuU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vqLFDImQ8xlJXyunnrGj/aBs+Um6iRfp/wEYXbhsbuo8uZ38WevLSkTHttQHw0TNW KUZWXP5okxlZd64fnzah1YJYlJjj61RZ/umSOImtjLQeXwXjiaqJNKmCqdiThgRQ4j rho/pZXMQaW/mD3BMVOQh/RdNhDLQ6BXPB0j0kNg= Date: Tue, 3 Oct 2023 16:28:19 +0200 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: Casey Schaufler Cc: paul@paul-moore.com, linux-security-module@vger.kernel.org, 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 Subject: Re: [PATCH v15 08/11] Smack: implement setselfattr and getselfattr hooks Message-ID: <20231003.uva7zohqueNu@digikod.net> References: <20230912205658.3432-1-casey@schaufler-ca.com> <20230912205658.3432-9-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230912205658.3432-9-casey@schaufler-ca.com> X-Infomaniak-Routing: alpha Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Tue, Sep 12, 2023 at 01:56:53PM -0700, Casey Schaufler wrote: > Implement Smack support for security_[gs]etselfattr. > Refactor the setprocattr hook to avoid code duplication. > > Signed-off-by: Casey Schaufler > Reviewed-by: John Johansen > --- > security/smack/smack_lsm.c | 95 ++++++++++++++++++++++++++++++++++++-- > 1 file changed, 90 insertions(+), 5 deletions(-) > > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c > index f73f9a2834eb..12160d060cc1 100644 > --- a/security/smack/smack_lsm.c > +++ b/security/smack/smack_lsm.c > @@ -3626,6 +3626,46 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) > return; > } > > +/** > + * smack_getselfattr - Smack current process attribute > + * @attr: which attribute to fetch > + * @ctx: buffer to receive the result > + * @size: available size in, actual size out > + * @flags: unused > + * > + * Fill the passed user space @ctx with the details of the requested > + * attribute. > + * > + * Returns the number of attributes on success, an error code otherwise. > + * There will only ever be one attribute. > + */ > +static int smack_getselfattr(unsigned int attr, struct lsm_ctx __user *ctx, > + size_t *size, u32 flags) > +{ > + struct smack_known *skp = smk_of_current(); > + int total; > + int slen; > + int rc; > + > + if (attr != LSM_ATTR_CURRENT) > + return -EOPNOTSUPP; > + > + slen = strlen(skp->smk_known) + 1; > + total = ALIGN(slen + sizeof(*ctx), 8); > + if (total > *size) > + rc = -E2BIG; > + else if (ctx) > + rc = lsm_fill_user_ctx(ctx, skp->smk_known, slen, LSM_ID_SMACK, > + 0); > + else > + rc = 1; Can we move these checks into lsm_fill_user_ctx()? They are similar for AppArmor and SELinux. > + > + *size = total; > + if (rc >= 0) > + return 1; > + return rc; > +}