From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sonic315-26.consmr.mail.ne1.yahoo.com (sonic315-26.consmr.mail.ne1.yahoo.com [66.163.190.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 783791A8F8E for ; Tue, 31 Dec 2024 17:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.163.190.152 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735664611; cv=none; b=aIOZBMwttToLKyWaI+gABvdyCUkWTLjG+jKA7aFRWDfPNNhF/k503HWG58ww03ydIGmEB2iYKlBWPoGwKQXAJ2UZUcBsKUgFMrWPYbIxaotxNOk6LROz4wXgD+XRO2GRwU1yYnWUfIgCEf7p8Yk14sRJe5fvvtNgf2vr49fWAT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735664611; c=relaxed/simple; bh=Pugcqp5K5OArUrlpoMeQcrZUwKSYDkMqRXJ10uUfwJM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ychyr82lIQ5K6S4rgZspLPidJMtrTsLeQUZx5wVRoM2F6XM6YUaPOTCQ65HtxRZRkNZCXbfio6Cx6WAMLx2fvGWNBReWb7fFpTIB6WEXNHsNGHdxyPnb/Vx4coIXjAZ/YyTaqPLnPNvFOyRgXROR2wKoZ4kZiSQPS2T0K0Lx3/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com; spf=none smtp.mailfrom=schaufler-ca.com; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b=eNrMhV9A; arc=none smtp.client-ip=66.163.190.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="eNrMhV9A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1735664608; bh=TkpSdyKsGexIiV51RXZS9TY5keUBaNd0m9AcvfOr4wU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=eNrMhV9Aaj/3siQ29raQ0KCARH8FLs14NBf9/CB5fZUuXZrmKlI0fFjxgJtISvZBD4zreGQsbTmSrIeKNtwH6bCLTOBDRTnUlhJ1evUNJB5YJK3ogeBxP4gYZvBOnflMeTDPhkOYc10QKGDOfxKxOtMNgqoRXPEAfJO547GZDEo/yhRk7YateqqqczzEFU9Y27YLT0/nwEpVeMuQx5Al/tGvGEnDBwYFq6gJ5E3vVZtLBulce3IPENNASrOf5rWYY0EGdOZDDg0zEhW5T7Fekku5/eI4sF7GGYDQSgMCvZ9qdOAc2wnG+vHvJn9mnTnFbMBXznSk8CD3Bt8+2EAtsQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1735664608; bh=+/3aDx7v0iNfAHcxL74ebvQ59NDPBy0Y41JVgey88H8=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=Rq+9BqeP+kj/x4yCP04UtISoIujgyUfvLHBuAy3Y5pUHzU4eM91aY8qnNkVzN5ZjSFVmy2EQVW8U0e8TBmtcLw6mvGn1hiJhXn95eqo9ctws6ysz/7QVlQY9VM/n2y08PLUfBdiqMvYWEGhEe+1/45WN7WOO3hlHvR4FN+KOUtuyjzaIVpzrv0BlsOmamZRwtuCO1gRNPmMmiYagJ35tdjiW6P4VYh+dpcG3WLJ90tUCyt/CAmIbcfuOIb/KgbXEJivSwr6BEHs7mrpSyz6yPG20knSf3ltUyY/qnhROVfmDnCnn1I6AGGOpq+MGra05Jf0V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kz.9bcYbAS7cDrkn 4aM3oQ7swKEu7slvkb6nlhsyLil1jvYNMSnf9IRS6NSEUvCy5J.dvwCU6QwrBtL_7lu_Pa0btOcp 9vPdPvjpmKjuGfyeHKb4lHnP9H7hI3rEf2HJukbLwRWsYD5jxDCkjTGVdUJNfbv72tXjra.kd4D4 4rvVmoRpXO3IqTv51ArIzy3cLopOzwLC1Ugg07_oHpr2PnOFM.KLpA.SOGmqglUtHg7BjMA1QWeY PUqHQjyNsPute_RpaOVzufA-- X-Sonic-MF: X-Sonic-ID: 6bfc5ee9-478d-4524-8da5-a254e066c6d2 Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Tue, 31 Dec 2024 17:03:28 +0000 Received: by hermes--production-gq1-5dd4b47f46-mb2l9 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 20e8b2953a42cd7a3c2c540ac5b1a4f0; Tue, 31 Dec 2024 16:43:11 +0000 (UTC) Message-ID: <5d7466ad-7790-4a08-86ba-82b0059562c1@schaufler-ca.com> Date: Tue, 31 Dec 2024 08:43:09 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] fs: add loopback/bind mount specific security hook To: Shervin Oloumi , mic@digikod.net, viro@zeniv.linux.org.uk Cc: brauner@kernel.org, jack@suse.cz, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, gnoack@google.com, shuah@kernel.org, jorgelo@chromium.org, allenwebb@chromium.org, Casey Schaufler References: <20241231014632.589049-1-enlightened@chromium.org> Content-Language: en-US From: Casey Schaufler In-Reply-To: <20241231014632.589049-1-enlightened@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.23040 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo On 12/30/2024 5:46 PM, Shervin Oloumi wrote: > The main mount security hook (security_sb_mount) is called early in the > process before the mount type is determined and the arguments are > validated and converted to the appropriate format. Specifically, the > source path is surfaced as a string, which is not appropriate for > checking bind mount requests. For bind mounts the source should be > validated and passed as a path struct (same as destination), after the > mount type is determined. This allows the hook users to evaluate the > mount attributes without the need to perform any validations or > conversions out of band, which can introduce a TOCTOU race condition. > > The newly introduced hook is invoked only if the security_sb_mount hook > passes, and only if the MS_BIND flag is detected. At this point the > source of the mount has been successfully converted to a path struct > using the kernel's kern_path API. This allows LSMs to target bind mount > requests at the right stage, and evaluate the attributes in the right > format, based on the type of mount. I am not very happy about an LSM hook that is this specific. Why restrict it to bind mounts? It seems that there might be other valuable restrictions on mounts that are based on the path. > > This does not affect the functionality of the existing mount security > hooks, including security_sb_mount. The new hook, can be utilized as a > supplement to the main hook for further analyzing bind mount requests. > This means that there is still the option of only using the main hook > function, if all one wants to do is indiscriminately reject all bind > mount requests, regardless of the source and destination arguments. > However, if one needs to evaluate the source and destination of a bind > mount request before making a decision, this hook function should be > preferred. Of course, if a bind mount request does not make it past the > security_sb_mount check, the bind mount hook function is never invoked. > > Signed-off-by: Shervin Oloumi > --- > fs/namespace.c | 4 ++++ > include/linux/lsm_hook_defs.h | 1 + > include/linux/security.h | 1 + > security/security.c | 16 ++++++++++++++++ > 4 files changed, 22 insertions(+) > > diff --git a/fs/namespace.c b/fs/namespace.c > index 23e81c2a1e3f..c902608c9759 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -2765,6 +2765,10 @@ static int do_loopback(struct path *path, const char *old_name, > if (err) > return err; > > + err = security_sb_bindmount(&old_path, path); I can easily envision uses for this other than bind mounts. Perhaps security_sb_mount_path()? > + if (err) > + goto out; > + > err = -EINVAL; > if (mnt_ns_loop(old_path.dentry)) > goto out; > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index eb2937599cb0..3d1940239556 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -71,6 +71,7 @@ LSM_HOOK(int, 0, sb_show_options, struct seq_file *m, struct super_block *sb) > LSM_HOOK(int, 0, sb_statfs, struct dentry *dentry) > LSM_HOOK(int, 0, sb_mount, const char *dev_name, const struct path *path, > const char *type, unsigned long flags, void *data) > +LSM_HOOK(int, 0, sb_bindmount, const struct path *old_path, const struct path *path) > LSM_HOOK(int, 0, sb_umount, struct vfsmount *mnt, int flags) > LSM_HOOK(int, 0, sb_pivotroot, const struct path *old_path, > const struct path *new_path) > diff --git a/include/linux/security.h b/include/linux/security.h > index cbdba435b798..512ac656500e 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -365,6 +365,7 @@ int security_sb_show_options(struct seq_file *m, struct super_block *sb); > int security_sb_statfs(struct dentry *dentry); > int security_sb_mount(const char *dev_name, const struct path *path, > const char *type, unsigned long flags, void *data); > +int security_sb_bindmount(const struct path *old_path, const struct path *path); > int security_sb_umount(struct vfsmount *mnt, int flags); > int security_sb_pivotroot(const struct path *old_path, const struct path *new_path); > int security_sb_set_mnt_opts(struct super_block *sb, > diff --git a/security/security.c b/security/security.c > index 09664e09fec9..bd7cb3df16f4 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1564,6 +1564,22 @@ int security_sb_mount(const char *dev_name, const struct path *path, > return call_int_hook(sb_mount, dev_name, path, type, flags, data); > } > > +/** > + * security_sb_bindmount() - Loopback/bind mount specific permission check > + * @old_path: source of loopback/bind mount > + * @path: mount point > + * > + * This check is performed in addition to security_sb_mount and only if the > + * mount type is determined to be loopback/bind mount (flags & MS_BIND). It > + * surfaces the mount source as a path struct. > + * > + * Return: Returns 0 if permission is granted. > + */ > +int security_sb_bindmount(const struct path *old_path, const struct path *path) > +{ > + return call_int_hook(sb_bindmount, old_path, path); > +} > + > /** > * security_sb_umount() - Check permission for unmounting a filesystem > * @mnt: mounted filesystem > > base-commit: fc033cf25e612e840e545f8d5ad2edd6ba613ed5