Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35714434rwd; Mon, 10 Jul 2023 11:22:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHt+2vioBSebXjq6YC6BIqrmTjCZaSMGipOBnewfm1pB+SGfxzJ+7p3cvFEjLAyKfBHh3MP X-Received: by 2002:a17:907:2943:b0:979:dad9:4e9 with SMTP id et3-20020a170907294300b00979dad904e9mr12446375ejc.50.1689013345868; Mon, 10 Jul 2023 11:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689013345; cv=none; d=google.com; s=arc-20160816; b=ljkbEbn/apooWEkV8vc3wB9UQ+fIE22ldi7kjwzDg5E2zgX1FZSxL7SBDwBEZV29Fq 5UpaOin006NmHLZCeJbvy51GjABNg4vrglcZtn62shRRvwvaqIlyQmy7qHrPWuWSALQ+ sjRtW360BoSrB53QGpUVo4TZ/EGLObcKnurgtsb/b/V0+CeUVD1koDRrlsrqGxo5gihA LC/+kJ33V8SL8HMAzgHJWC2ANAQS5af26XshEllZm1SHJEyPxsr8QIOtFtHv1IfkgTjc dXbHuqhZF3QCr+NAvu9KrALlsq7zXguLACWNk0RbZMcLJfRCPcbw4FpyGPs4OGuckTET Gw7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EB5CFdTYWApS8YMHOsiv0TiQQf51kpScKMC8hHDqG8g=; fh=U0D7cxqupt2uSuLTPCUHKYbLyLXt1MHgpYtxWTjdZxM=; b=UJG2j2U/Vmcndbo5XPVwIwoh/VaswhOHDaHMi3Xd71tbDGSufLuVLpvlWGyLGG29pK 40Pr0xTxKVoWKPtedKds7Swc0UvgpctM4g/p56/ZmnP2b1tF8umlfnG2oNwidQl/Hiry YJ8FhsKHuKM8k+fcNUo8vLjOwyVwHc9dHwKTq9so0TtuzAOC7f/0riSW142kHuIAbta9 vsesPWptehVlGVryZpK2nwH5F1kNn4ytZn4NBQ2ATGFyzkoYwzQNI/4TgB/iPtfnnzNj Zy6BQ0EoBraQ/P0gRLoUgVwA4MUSy4z0sHld5u1den1c0sXVs8zVJZifxJG7RoRsBj1o Z1Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=PRUSckhb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170906118600b009659573b4e3si183579eja.51.2023.07.10.11.21.55; Mon, 10 Jul 2023 11:22:25 -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=@paul-moore.com header.s=google header.b=PRUSckhb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232077AbjGJSFN (ORCPT + 99 others); Mon, 10 Jul 2023 14:05:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbjGJSFL (ORCPT ); Mon, 10 Jul 2023 14:05:11 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B8711B for ; Mon, 10 Jul 2023 11:05:09 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-57764a6bf8cso60310377b3.3 for ; Mon, 10 Jul 2023 11:05:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1689012309; x=1691604309; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EB5CFdTYWApS8YMHOsiv0TiQQf51kpScKMC8hHDqG8g=; b=PRUSckhb2w2tvQVVqKRnAyFmh/xH4DVarLn2tfQUHuZsRmlUdlaoZS4tZ/DtqvuCcC vw7wH9gSaid4XnJN8d0feAmFI+jdpMwX19vdHLHSWTT/aaIB+ces3ILY4kHUkuLjXoHQ CmEpOHNRRSFnNjUm0goZkW6P579aehUi1pSQtU87E+sxiJeekPKGmihjBe2w1IN/vS5h SSeoBmil9Z+t5D3S1+K20tHmPDDQdCz0gPzjlQBkR3Kw6vrkkebxGQd93XdCw+eVSM5A bv/ahQVscDhIR+kBLYh6Q/z5/MEcwbba/IK44dTuptfxx2eLDdO7uulqpaNx7DtWj5qb B3ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689012309; x=1691604309; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EB5CFdTYWApS8YMHOsiv0TiQQf51kpScKMC8hHDqG8g=; b=SnEx3DDrS1X5EjRD+XFjzIwLwSJAHQ8lJwK9Lv2k25whoGTzsz9OaMzQ8MUtXc877+ DCO7n1CENcRky3CcLM9xHJyrhXpLUfH6Z9Dxiy5s5vceo+eGwHvMzWVMiJVW0gn/qdif jzTDLP2nlbm5XwPMJN/2a41k1sFLzanc/4PZ2fp7SRSw0CvOeluUHvROukj9p7skPEQK sBb7rqmSX/SpFN3SgTNIb9v22eNI3E0VfvqJ4HrjTCPDyLUTD3upNCFnlpGE/F7iO+p3 5N5SIfXzIP4z4yvsyMA9u4Llq/UYU/ovT6hZ78GO3RL/HXsH2HA6Q6dtjU08duqPPqHQ eS5w== X-Gm-Message-State: ABy/qLaJNQBNFo0LMR45LebaY1kb4xVNUjRA/vcOoomElQ30XIC7iUaG wFp0jyOGYTJS3BIOAPNV5v8+eC9fhJoBkfA+Acaj X-Received: by 2002:a0d:cc47:0:b0:577:a46:26e5 with SMTP id o68-20020a0dcc47000000b005770a4626e5mr12504009ywd.31.1689012309085; Mon, 10 Jul 2023 11:05:09 -0700 (PDT) MIME-Version: 1.0 References: <20230610075738.3273764-2-roberto.sassu@huaweicloud.com> <1c8c612d99e202a61e6a6ecf50d4cace.paul@paul-moore.com> In-Reply-To: From: Paul Moore Date: Mon, 10 Jul 2023 14:04:58 -0400 Message-ID: Subject: Re: [PATCH v12 1/4] security: Allow all LSMs to provide xattrs for inode_init_security hook To: Roberto Sassu Cc: Casey Schaufler , zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Fri, Jul 7, 2023 at 5:44=E2=80=AFPM Paul Moore wro= te: > On Fri, Jul 7, 2023 at 12:54=E2=80=AFPM Casey Schaufler wrote: > > On 7/6/2023 6:43 PM, Paul Moore wrote: > > > On Jun 10, 2023 Roberto Sassu wrote: > > >> Currently, the LSM infrastructure supports only one LSM providing an= xattr > > >> and EVM calculating the HMAC on that xattr, plus other inode metadat= a. > > >> > > >> Allow all LSMs to provide one or multiple xattrs, by extending the s= ecurity > > >> blob reservation mechanism. Introduce the new lbs_xattr_count field = of the > > >> lsm_blob_sizes structure, so that each LSM can specify how many xatt= rs it > > >> needs, and the LSM infrastructure knows how many xattr slots it shou= ld > > >> allocate. > > >> > > >> Modify the inode_init_security hook definition, by passing the full > > >> xattr array allocated in security_inode_init_security(), and the cur= rent > > >> number of xattr slots in that array filled by LSMs. The first parame= ter > > >> would allow EVM to access and calculate the HMAC on xattrs supplied = by > > >> other LSMs, the second to not leave gaps in the xattr array, when an= LSM > > >> requested but did not provide xattrs (e.g. if it is not initialized)= . > > >> > > >> Introduce lsm_get_xattr_slot(), which LSMs can call as many times as= the > > >> number specified in the lbs_xattr_count field of the lsm_blob_sizes > > >> structure. During each call, lsm_get_xattr_slot() increments the num= ber of > > >> filled xattrs, so that at the next invocation it returns the next xa= ttr > > >> slot to fill. > > >> > > >> Cleanup security_inode_init_security(). Unify the !initxattrs and > > >> initxattrs case by simply not allocating the new_xattrs array in the > > >> former. Update the documentation to reflect the changes, and fix the > > >> description of the xattr name, as it is not allocated anymore. > > >> > > >> Adapt both SELinux and Smack to use the new definition of the > > >> inode_init_security hook, and to call lsm_get_xattr_slot() to obtain= and > > >> fill the reserved slots in the xattr array. > > >> > > >> Move the xattr->name assignment after the xattr->value one, so that = it is > > >> done only in case of successful memory allocation. > > >> > > >> Finally, change the default return value of the inode_init_security = hook > > >> from zero to -EOPNOTSUPP, so that BPF LSM correctly follows the hook > > >> conventions. > > >> > > >> Reported-by: Nicolas Bouchinet > > >> Link: https://lore.kernel.org/linux-integrity/Y1FTSIo+1x+4X0LS@archl= inux/ > > >> Signed-off-by: Roberto Sassu > > >> --- > > >> include/linux/lsm_hook_defs.h | 6 +-- > > >> include/linux/lsm_hooks.h | 20 ++++++++++ > > >> security/security.c | 71 +++++++++++++++++++++++---------= --- > > >> security/selinux/hooks.c | 17 +++++---- > > >> security/smack/smack_lsm.c | 25 ++++++------ > > >> 5 files changed, 92 insertions(+), 47 deletions(-) > > > Two *very* small suggestions below, but I can make those during the > > > merge if you are okay with that Roberto? > > > > > > I'm also going to assume that Casey is okay with the Smack portion of > > > this patchset? It looks fine to me, and considering his ACK on the > > > other Smack patch in this patchset I'm assuming he is okay with this > > > one as well ... ? > > > > Yes, please feel free to add my Acked-by as needed. > > Done. Thanks Casey. I'm merging the full patchset into lsm/next right now. Thanks for all your work on this Roberto, and a thank you for everyone else who helped with reviews, testing, etc. --=20 paul-moore.com