Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5844006rwl; Tue, 11 Apr 2023 10:42:50 -0700 (PDT) X-Google-Smtp-Source: AKy350bbstJRu95OBUK/084MATBOsSu6fA0R54210pRFY3kT4hqkmRDcrOEVESfsF/sRyC2v8jJJ X-Received: by 2002:a62:5209:0:b0:636:e0fb:8c45 with SMTP id g9-20020a625209000000b00636e0fb8c45mr9532356pfb.16.1681234970573; Tue, 11 Apr 2023 10:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681234970; cv=none; d=google.com; s=arc-20160816; b=fiH/tZXdsmDCstGI12ieF3e82LnfNfOYLyLL2yGC1OeDRtafGio+IdPpJLiydh/Zcb iVTCuoq4N294rp+1xKkDFs9LoiKV7/NwJkYYd7Ok5MR3D3v8kHJSA4m4h/MPqfHrY/eF c6BV75A2HVEsKpMdD+txuCuzKpj+1+MXXt2+7TALq8Ly6SQ/R71cr802O3lkKTxmxtkr ACYtehGHyWl5mEWKP8PG345Kmim9VlOZ822XUrT8LjATNMTfJrhexhhldk5CwXxROCs7 J/wvMGfF5/yI3OjCxHU/sJqS7edwR0Yyx7rC/Swkr1024feze68WK5J88iuo0YKPTPPQ trgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=CoX/1kMuppKD03pjH1ilRnYMKCAkeOsMHAIAIKVvjIQ=; b=BMUkTUTzGfSKebeW72mB8Ypn6oIMA/lcXcCYjkUOW5+00zM4T/XdxcgC/gMzNNgbmm dn5kijROtvsbyjMHx4e/x5r66ICRGTh8NJtoPoEknYu7/u55/4W0N5fuqdMXXncYkge/ 9YTZHIDnhzxIajT4z3zV+qeAMdA5+8lvuZScahkypeOguFecdnPrUqLXvTJkfBccbSU4 oFIBmQ9PCjAvC/NwSnHzAJS1KeYKuqM+2E/kz122klGFH8lBPhj3cU6cr8Ld9f/1CAvX aCSgwWvbQQdPq5y9r1qoYi+Dz5iNgR9bhr61IHcW8Fl8uXbHGePVmdO6CzEn9TTZNz/n BapA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=m85RXdsl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a632d02000000b00513b0d416e4si13270179pgt.599.2023.04.11.10.42.39; Tue, 11 Apr 2023 10:42:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=m85RXdsl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjDKRlR (ORCPT + 99 others); Tue, 11 Apr 2023 13:41:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjDKRlN (ORCPT ); Tue, 11 Apr 2023 13:41:13 -0400 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F07446EB8 for ; Tue, 11 Apr 2023 10:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681234833; bh=CoX/1kMuppKD03pjH1ilRnYMKCAkeOsMHAIAIKVvjIQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=m85RXdslqAXGZiL2M+YsxJUG5nrrYFRYvrcCYdpesf/hDsiG0ZW/FAS7RYzFCstFzRSmNiLxnWu2dr3N0JN35ZuFjt/TGyxWmk0xgC9k1+0rG/w9PXXLFpbw8fDcs7VeJwgeTd/9ZsAkQ8D7kMagHCLwgqwW9hj2yTDvegGogd1WRpF8d0zg9NYHmhQnSpeGYPCMpcZ9/f45PVtiAQv8r3cIuLs4qnUDQ4K5/yeL2Dhm+PMBac74itOomZ2T5K4dWGbFJj+VZPtd6QQxd3/fxoNZBnKkHcxhsO25xr69nUt5UBla7RgkxjUArJFjBUy7vEYWUvy4iEQZq8BZSXqK0g== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681234833; bh=HUGy1sLYedvXwmVTmDWHp8NmtgMIN57UYhNvHWx4z7C=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=Qmb9FJSB/KErmPlewtCtOEU+JwiMc+VK5I3Ys34A25wTBmhIX4UTR106v0CSLFPVy2Onp7lYLAVKw/CumVD+4GVBb3kqYjPFcRqy5yy6WqRs5lZ1DAObXKs6olXlREkF/ykGDpk5900EuqE9nd+CPjB2Ho3TlZlWAhHeOfNyrHtz/c+vTZNh8vAFGCKgacdhXhNKyYWJcA57QxunDrQxLrmpc/txhRMlDJJzY7IJYgcPMyUEg20278ZCxWjW1gvpWWIhnFfuIe34HISA3Vy/93N3J5Jh/DKpHaj0VofsbTG/DK2c2PdC9P0wHamftpGwZLAi/jWr3W6FrEkltR6fsw== X-YMail-OSG: _xtNrbIVM1knc08DZaIJ1wawTHdIu4A9JWkXIpZhmZ29ODtpg5vL7E6t6BeKSux ZT7GS2rWPN_fIAZpo74xt5SlfJCs2vWQo3JUqqMrqNa0zgDIG71Cy7VXz0XVee.CEoBXaUkLeEEm svW3iFqnEjQNn65MDjmyo1MKwPkPQ8jq.T8zwCAnzKc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HzsdJZLV9K kCoNHkN.5_fRNDyvu_b7T847kWDCZT8sd X-Sonic-MF: X-Sonic-ID: 77ecec08-8f74-4683-906c-9a3d97c588ac Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Tue, 11 Apr 2023 17:40:33 +0000 Received: by hermes--production-ne1-7dbd98dd99-znv4z (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 250d474f6a917934edff60a5d255f833; Tue, 11 Apr 2023 17:40:30 +0000 (UTC) Message-ID: Date: Tue, 11 Apr 2023 10:40:27 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v10 2/4] security: Allow all LSMs to provide xattrs for inode_init_security hook Content-Language: en-US To: Roberto Sassu , Mimi Zohar , dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org Cc: reiserfs-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, bpf@vger.kernel.org, kpsingh@kernel.org, keescook@chromium.org, nicolas.bouchinet@clip-os.org, Roberto Sassu , Casey Schaufler References: <20230331123221.3273328-1-roberto.sassu@huaweicloud.com> <20230331123221.3273328-3-roberto.sassu@huaweicloud.com> <64d8dcae509beca4cd763acb148d2665b805ee6e.camel@huaweicloud.com> <6c48e6df58e9762607cf7f8287cc95f6a161c064.camel@huaweicloud.com> From: Casey Schaufler In-Reply-To: <6c48e6df58e9762607cf7f8287cc95f6a161c064.camel@huaweicloud.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.21365 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/11/2023 10:25 AM, Roberto Sassu wrote: > On Tue, 2023-04-11 at 09:42 -0700, Casey Schaufler wrote: >> On 4/11/2023 12:53 AM, Roberto Sassu wrote: >>> On Tue, 2023-04-11 at 03:22 -0400, Mimi Zohar wrote: >>>> Hi Roberto, >>>> >>>> Sorry for the delay in responding... >>> Hi Mimi >>> >>> no worries! >>> >>>> The patch description reads as though support for per LSM multiple >>>> xattrs is being added in this patch, though lsm_get_xattr_slot() only >>>> ever is incremented once for each LSM. To simplify review, it would be >>>> nice to mention that lsm_get_xattr_slot() would be called multiple >>>> times per LSM xattr. >>> Ok, I will mention it. >>> >>>> On Fri, 2023-03-31 at 14:32 +0200, Roberto Sassu wrote: >>>>> From: Roberto Sassu >>>>> >>>>> Currently, security_inode_init_security() supports only one LSM providing >>>>> an xattr and EVM calculating the HMAC on that xattr, plus other inode >>>>> metadata. >>>>> >>>>> Allow all LSMs to provide one or multiple xattrs, by extending the security >>>>> blob reservation mechanism. Introduce the new lbs_xattr_count field of the >>>>> lsm_blob_sizes structure, so that each LSM can specify how many xattrs it >>>>> needs, and the LSM infrastructure knows how many xattr slots it should >>>>> allocate. >>>>> >>>>> Dynamically allocate the new_xattrs array to be populated by LSMs with the >>>>> inode_init_security hook, and pass it to the latter instead of the >>>>> name/value/len triple. Unify the !initxattrs and initxattrs case, simply >>>>> don't allocate the new_xattrs array in the former. >>>>> >>>>> Also, pass to the hook the number of xattrs filled by each LSM, so that >>>>> there are no gaps when the next LSM fills the array. Gaps might occur >>>>> because an LSM can legitimately request xattrs to the LSM infrastructure, >>>>> but not fill the reserved slots, if it was not initialized. >>>> The number of security xattrs permitted per LSM was discussed in the >>>> second paragraph. The first line of this paragraph needs to be updated >>>> to reflect the current number of security xattrs used, though that is >>>> more related to the new lsm_get_xattr_slot(). Or perhaps the entire >>>> paragraph is unnecessary, a remnant from >>>> security_check_compact_filled_xattrs(), and should be removed. >>> I would probably say in that paragraph that the number specified for >>> the lbs_xattr_count field determines how many times an LSM can call >>> lsm_get_xattr_slot(). >>> >>>>> Update the documentation of security_inode_init_security() to reflect the >>>>> changes, and fix the description of the xattr name, as it is not allocated >>>>> anymore. >>>>> >>>>> Finally, adapt both SELinux and Smack to use the new definition of the >>>>> inode_init_security hook, and to fill the reserved slots in the xattr >>>>> array. Introduce the lsm_get_xattr_slot() helper to retrieve an available >>>>> slot to fill, and to increment the number of filled slots. >>>>> >>>>> Move the xattr->name assignment after the xattr->value one, so that it is >>>>> done only in case of successful memory allocation. For Smack, also reserve >>>>> space for the other defined xattrs although they are not set yet in >>>>> smack_inode_init_security(). >>>> This Smack comment should be moved to the previous paragraph and even >>>> expanded explaining that lsm_get_xattr_slot() will be called for each >>>> additional security xattr. >>>> From previous Paul's and Casey's comments, Smack will have just two >>> xattrs, assuming that security.SMACK_TRASMUTE64 can be set in >>> smack_inode_init_security(). I will change this part accordingly once >>> Casey can have a look at the function. >> To be clear, Smack may use two xattrs from smack_inode_init_security(), >> SMACK64 and SMACK64_TRANSMUTE. SMACK64_TRANSMUTE is only set on directories. >> SMACK64_MMAP and SMACK64_EXEC can be set on files, but they have to be >> set explicitly. A file may have three xattrs, but only one from >> smack_inode_init_security(). >> >> I'm looking at the existing Smack function, and it includes checking for >> the transmute attribute. Your patch seems to have dropped this important >> behavior. That needs to be restored in any case. You can tell that you need >> to include the SMACK64_TRANSMUTE xattr if setting it is detected. > Uhm, I think it is simply omitted in the patch, not deleted. Oops. Right you are. > > I just sent a draft of the modifications required to set > SMACK64_TRANSMUTE in smack_inode_init_security(). Yup. I'll comment on that. > > Roberto > >>>>> Reported-by: Nicolas Bouchinet (EVM crash) >>>>> Link: https://lore.kernel.org/linux-integrity/Y1FTSIo+1x+4X0LS@archlinux/ >>>>> Signed-off-by: Roberto Sassu >>>>> --- >>>>> diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h >>>>> index c2be66c669a..9eb9b686493 100644 >>>>> --- a/include/linux/lsm_hooks.h >>>>> +++ b/include/linux/lsm_hooks.h >>>>> @@ -28,6 +28,7 @@ >>>>> #include >>>>> #include >>>>> #include >>>>> +#include >>>>> >>>>> union security_list_options { >>>>> #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__); >>>>> @@ -63,8 +64,27 @@ struct lsm_blob_sizes { >>>>> int lbs_ipc; >>>>> int lbs_msg_msg; >>>>> int lbs_task; >>>>> + int lbs_xattr_count; /* number of xattr slots in new_xattrs array */ >>>>> }; >>>>> >>>>> +/** >>>>> + * lsm_get_xattr_slot - Return the next available slot and increment the index >>>>> + * @xattrs: array storing LSM-provided xattrs >>>>> + * @xattr_count: number of already stored xattrs (updated) >>>>> + * >>>>> + * Retrieve the first available slot in the @xattrs array to fill with an xattr, >>>>> + * and increment @xattr_count. >>>>> + * >>>>> + * Return: The slot to fill in @xattrs if non-NULL, NULL otherwise. >>>>> + */ >>>>> +static inline struct xattr *lsm_get_xattr_slot(struct xattr *xattrs, >>>>> + int *xattr_count) >>>>> +{ >>>>> + if (unlikely(!xattrs)) >>>>> + return NULL; >>>>> + return xattrs + (*xattr_count)++; >>>> At some point, since lsm_get_xattr_slot() could be called multiple >>>> times from the same LSM, shouldn't there be some sort of bounds >>>> checking? >>>> From previous Paul's comments, I understood that he prefers to avoid >>> extra checks. It will be up to LSM developers to ensure that the API is >>> used correctly. >>> >>> Thanks >>> >>> Roberto >>>