Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3516023rdb; Sun, 10 Dec 2023 08:42:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgfIPrP3kQTKaxpCfw41vlZUUV31yNT4ownrt680VIduwslXnrJn5JjOQZk6BRGUWFJalU X-Received: by 2002:a17:903:2301:b0:1d0:bba7:4f8f with SMTP id d1-20020a170903230100b001d0bba74f8fmr1514779plh.0.1702226543634; Sun, 10 Dec 2023 08:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702226543; cv=none; d=google.com; s=arc-20160816; b=OS4K6TtlbO34PYz2lQPQc+/xSSxq2ngDLs07fUAQC3+SSukwHmeSr8/Wkfeetxca6u 4FJ4Z6TAgkWFDFwtlmC6ejk4omdzEz0d9XPgrsDRV4OB7/ZKTgzJuFfN31eGeG1tHP/p WU2xgVLTKxhER3zX4tqmtbmDS8wGJghviWIujdEZ28IZF9Z6O9DOQWqqhfn/f+ZHKJYS v2iowK3bkFKNAbPHFB1tr8yIEQO3bxA5+f/IttgXxErooLhtPcScVqrqWSCNACOV6wQ5 tFy2X3S7HY71cWkIHI/ikuKvWGkOf/X7MSAVU4VDxsDpFWTsmTpqYoSSfgxL0S3AgDUo ROQQ== 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=i0lrZcnXtGyQm/QMIPVbNtLua11zuI47QiJurNMFZ1o=; fh=zjzXdevm5Kyk2+P5uY1B90RH8NWT/SyFJT417XI3PU4=; b=e4rMLiy/fjAiXmQKeE+5TFksZMCm0MysQq+uMpnfF+Q4ZMd06CisFXTVKzsiGzRkCg JpMRFaoQTC5Dr2fHq0cNURUGvzz0YFU6vyIXzTeCIiQUTqbmRZM2u2SQtTR+G+jz6+kP BhNrBYiE2JbsXGugqQc6xM2QmD/pDHEFGOpymHQKdI5SgHTPV9UCyfRwXdAsyIRP2dBW QOS2Z4DFnPZIp8oaseE1LDG2szg0hzZ8wrnXn59WEmsw/+YqHWDV6P/vvcIMmY59RKNB tNE/w6RgwhARvx2egy/LtCqLWBv9xrzdzZa5i1IJ9DZghwIS0Kxrs1ReQKNJUr+zX04g yOcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jVL4YL0q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id q14-20020a170902eb8e00b001cfb3d25f2asi4692569plg.652.2023.12.10.08.42.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 08:42:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jVL4YL0q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1771780859A0; Sun, 10 Dec 2023 08:42:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231916AbjLJQl7 (ORCPT + 99 others); Sun, 10 Dec 2023 11:41:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjLJQl6 (ORCPT ); Sun, 10 Dec 2023 11:41:58 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26CD4F5; Sun, 10 Dec 2023 08:42:04 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-67a948922aaso25526186d6.3; Sun, 10 Dec 2023 08:42:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702226523; x=1702831323; darn=vger.kernel.org; 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=i0lrZcnXtGyQm/QMIPVbNtLua11zuI47QiJurNMFZ1o=; b=jVL4YL0qmHRswmEa+HuW3r3TTfypYAf1tKa4jUS6xxD2BFE03NuG3JFj8VLJ+56jWo 5DV6H1zMsWFfuGITdWK56eTneH1zvXBzzlUSgjgiMKu1V/kc4MhpPyeyhxw5+5risPO/ IrtK7vzUzS7OHGsHf7H1pj6DvyxopeTxLNmPRuxnTj1llD3pyGZ38hd5/SvDgApRLGhk 2gksLZVi4A+W1M0dTy1FwTUiO/wXRk4J+yHaszbXq4ZHR3xbcDsqOU+avPcYvG+ge7Ta A1bc68it6gM4Ynq7PqMW+Ypiq8a1C0nQBTOdh59jjsR7EtYQwf1tQLhC1jsV86TGeh8z s+iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702226523; x=1702831323; 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=i0lrZcnXtGyQm/QMIPVbNtLua11zuI47QiJurNMFZ1o=; b=GDdeU8cJHIIutAY/bkt3H5c2ETZSHNHyCCyxIx2vL64DowKM8/ZWkCxT0L1vEzp7t0 qhQcR5iIz0fpfOS15zfyK923mRTdwOw5XSiVqtDLWX3N1G8edxDEtt9HcmBP9kRwugCl s0ij+bnvtkjrEINAXYdVxfXvfbnBVJsMFC1GRBNcCjIneM3jcqrUqMPShjTDjNzaZMmE /mVxTt58mnmuCrHh3an7ZF2zR7Br46cG9rIIvB+HkFRvtGeV6O+v3unsnFhpZhCA8cc2 nlxeggn3ze8wBbp+pEbUHaslcxosDBsixleK1WZoK40xxYcZSp4Ugd/pu/vxVhOVM5cs wXow== X-Gm-Message-State: AOJu0YzUnZl1DYISCBtWF2+Lvl0rX4kWzJmQHYC+kuarqUSG4LWbnW7Z kqhUECLd0vlc3JSyhL+GT3SyTZR5bQMa/aAC5bhkDKD/60A= X-Received: by 2002:a05:6214:17c9:b0:67a:a721:e12d with SMTP id cu9-20020a05621417c900b0067aa721e12dmr3567441qvb.90.1702226523168; Sun, 10 Dec 2023 08:42:03 -0800 (PST) MIME-Version: 1.0 References: <20231129-idmap-fscap-refactor-v1-0-da5a26058a5b@kernel.org> <20231129-idmap-fscap-refactor-v1-9-da5a26058a5b@kernel.org> <20231201-reintreten-gehalt-435a960f80ed@brauner> In-Reply-To: From: Amir Goldstein Date: Sun, 10 Dec 2023 18:41:52 +0200 Message-ID: Subject: Re: [PATCH 09/16] fs: add vfs_set_fscaps() To: "Seth Forshee (DigitalOcean)" Cc: Christian Brauner , Serge Hallyn , Paul Moore , Eric Paris , James Morris , Alexander Viro , Miklos Szeredi , Mimi Zohar , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, audit@vger.kernel.org, linux-unionfs@vger.kernel.org, Roberto Sassu , Stefan Berger , Vivek Goyal Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 10 Dec 2023 08:42:21 -0800 (PST) On Thu, Dec 7, 2023 at 4:43=E2=80=AFPM Seth Forshee (DigitalOcean) wrote: > > [Adding Mimi for insights on EVM questions] > > On Fri, Dec 01, 2023 at 12:18:00PM -0600, Seth Forshee (DigitalOcean) wro= te: > > On Fri, Dec 01, 2023 at 06:39:18PM +0100, Christian Brauner wrote: > > > > +/** > > > > + * vfs_set_fscaps - set filesystem capabilities > > > > + * @idmap: idmap of the mount the inode was found from > > > > + * @dentry: the dentry on which to set filesystem capabilities > > > > + * @caps: the filesystem capabilities to be written > > > > + * @flags: setxattr flags to use when writing the capabilities xat= tr > > > > + * > > > > + * This function writes the supplied filesystem capabilities to th= e dentry. > > > > + * > > > > + * Return: 0 on success, a negative errno on error. > > > > + */ > > > > +int vfs_set_fscaps(struct mnt_idmap *idmap, struct dentry *dentry, > > > > + const struct vfs_caps *caps, int flags) > > > > +{ > > > > + struct inode *inode =3D d_inode(dentry); > > > > + struct inode *delegated_inode =3D NULL; > > > > + struct vfs_ns_cap_data nscaps; > > > > + int size, error; > > > > + > > > > + /* > > > > + * Unfortunately EVM wants to have the raw xattr value to compare= to > > > > + * the on-disk version, so we need to pass the raw xattr to the > > > > + * security hooks. But we also want to do security checks before > > > > + * breaking leases, so that means a conversion to the raw xattr h= ere > > > > + * which will usually be reduntant with the conversion we do for > > > > + * writing the xattr to disk. > > > > + */ > > > > + size =3D vfs_caps_to_xattr(idmap, i_user_ns(inode), caps, &nscaps= , > > > > + sizeof(nscaps)); > > > > + if (size < 0) > > > > + return size; > > > > > > Oh right, I remember that. Slight eyeroll. See below though... > > > > > > > + > > > > +retry_deleg: > > > > + inode_lock(inode); > > > > + > > > > + error =3D xattr_permission(idmap, inode, XATTR_NAME_CAPS, MAY_WRI= TE); > > > > + if (error) > > > > + goto out_inode_unlock; > > > > + error =3D security_inode_setxattr(idmap, dentry, XATTR_NAME_CAPS,= &nscaps, > > > > + size, flags); > > > > + if (error) > > > > + goto out_inode_unlock; > > > > > > For posix acls I added dedicated security hooks that take the struct > > > posix_acl stuff and then plumb that down into the security modules. Y= ou > > > could do the same thing here and then just force EVM and others to do > > > their own conversion from in-kernel to xattr format, instead of forci= ng > > > the VFS to do this. > > > > > > Because right now we make everyone pay the price all the time when > > > really EVM should pay that price and this whole unpleasantness. > > > > Good point, I'll do that. > > I've been reconsidering various approaches here. One thing I noticed is > that for the non-generic case (iow overlayfs) I missed calling > security_inode_post_setxattr(), where EVM also wants the raw xattr, so > that would require another conversion. That got me wondering whether the > setxattr security hooks really matter when writing fscaps to overlayfs. > And it seems like they might not: the LSMs only look for their own > xattrs, and IMA doesn't do anything with fscaps xattrs. EVM does, but > what it does for a xattr write to an overlayfs indoe seems at least > partially if not completely redundant with what it will do when the > xattr is written to the upper filesystem. > > So could we push these security calls down to the generic fscaps > implementations just before/after writing the raw xattr data and just > skip them for overlayfs? If so we can get away with doing the vfs_caps > to xattr conversion only once. > > The trade offs are that filesystems which implement fscaps inode > operations become responsible for calling the security hooks if needed, > and if something changes such that we need to call those security hooks > for fscaps on overlayfs this solution would no longer work. Hi Seth, I was trying to understand the alternative proposals, but TBH, I cannot wrap my head about overlayfs+IMA/EVM and I do not fully understand the use case. Specifically, I do not understand why the IMA/EVM attestation on the upper and lower fs isn't enough to make overlayfs tamper proof. I never got an explanation of the threat model for overlayfs+IMA/EVM. I know that for SELinux and overlayfs a lot of work was done by Vivek. I was not involved in this work, but AKAIF, it did not involve any conversi= on of selinux xattrs. Thanks, Amir.