Skip to contentSkip to conversation

RFC: Linux IMA on NFS prototype

PATCH In review Chuck Lever 3 participants 17 messages Mar 7, 2019 – Mar 25, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover RFC: Linux IMA on NFS prototype

This series implements support for accessing and updating the security.ima xattr on files that reside on an NFS export. Since the NFS protocol does not have capabilities like CAP_SYS_ADMIN, on NFS clients, only root is allowed to set this xattr.

I'm interested in comments on the implementation, test results, or a discussion of whether this proposal creates undesirable security exposures.

Git repo: git://git.linux-nfs.org/projects/cel/cel-2.6.git

in the nfs-ima-prototype topic branch.

Implementation Notes

Please see the individual patch descriptions: standards action is still required to define the official FATTR4 flag that all NFSv4.2 implementations recognize as meaning "the security.ima xattr". This prototype is not guaranteed to interoperate with future prototypes or standards-compliant implementations of this feature. It is for experimental purposes only.

EVM is not supported in this prototype. The NFS protocol does not support several of the xattrs that are protected by EVM: SMACK64, Posix ACLs, and Linux file capabilities are not supported. When these are present in an EVM hash, NFS clients can't retrieve them to verify the hash.

This prototype does not match what is described in draft-ietf-nfsv4- integrity-measurement. Since that draft was submitted, there has been vigorous discussion on [email protected] about how the NFS protocol should support Linux IMA. The prototype attempts a narrow interpretation of what the comments have requested. The draft will be updated to reflect the prototype implementation.

Changes since v1:
- Rebased on kernel v5.0
- Moved NFSD support out from behind CONFIG_NFSD_V4_SECURITY_LABELS
- Added a patch to remove ima_file_check call in NFSD

---

Chuck Lever (5):
NFS: Define common IMA-related protocol elements
NFSD: Prototype support for IMA on NFS (server)
NFSD: Remove ima_file_check call
NFS: Rename security xattr handler
NFS: Prototype support for IMA on NFS (client)

 fs/nfs/nfs4_fs.h          |    1 
 fs/nfs/nfs4proc.c         |  134 +++++++++++++++++++++++++++++---
 fs/nfs/nfs4xdr.c          |  186 +++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/nfs4proc.c        |    9 ++
 fs/nfsd/nfs4xdr.c         |   49 ++++++++++--
 fs/nfsd/nfsd.h            |    3 -
 fs/nfsd/vfs.c             |   25 +++++-
 fs/nfsd/vfs.h             |    3 +
 fs/nfsd/xdr4.h            |    3 +
 fs/xattr.c                |   25 +++---
 include/linux/nfs4.h      |    5 +
 include/linux/nfs_fs_sb.h |    1 
 include/linux/nfs_xdr.h   |   21 +++++
 13 files changed, 426 insertions(+), 39 deletions(-)

--
Chuck Lever

#1 lore raw

PATCH v2 1/5 NFS: Define common IMA-related protocol elements

Common protocol definitions used by the server and client implementations. A separate patch also makes it easier to identify the code that needs to change when the flag name and value is eventually standardized.

---
 include/linux/nfs4.h |    2 ++
 1 file changed, 2 insertions(+)
include/linux/nfs4.h +2 -0
index 1b06f0b..ca3adb1 100644
@@ -41,6 +41,7 @@ struct nfs4_acl {
 };
 
 #define NFS4_MAXLABELLEN	2048
+#define NFS4_MAXIMALEN		(4096)
 
 struct nfs4_label {
 	uint32_t	lfs;
@@ -451,6 +452,7 @@ enum change_attr_type4 {
 #define FATTR4_WORD2_CHANGE_ATTR_TYPE	(1UL << 15)
 #define FATTR4_WORD2_SECURITY_LABEL     (1UL << 16)
 #define FATTR4_WORD2_MODE_UMASK		(1UL << 17)
+#define FATTR4_WORD2_LINUX_IMA		(1UL << 18)
 
 /* MDS threshold bitmap bits */
 #define THRESHOLD_RD                    (1UL << 0)
#2 lore raw

PATCH v2 2/5 NFSD: Prototype support for IMA on NFS (server)

In reply to Chuck Lever

Provide code to handle the "security.ima" xattr. The NFS server converts incoming GETATTR and SETATTR calls to acesses and updates of the xattr. Even if CONFIG_IMA is disabled, the NFS server can access and update that extended attribute.

The new FATTR4 bit is made up; meaning we still have to go through a standards process to allocate a bit that all NFS vendors agree on. Thus there is no guarantee this prototype will interoperate with others or with a future standards-based implementation.

---
 fs/nfsd/nfs4proc.c |    9 +++++++++
 fs/nfsd/nfs4xdr.c  |   49 +++++++++++++++++++++++++++++++++++++++++++------
 fs/nfsd/nfsd.h     |    3 ++-
 fs/nfsd/vfs.c      |   19 +++++++++++++++++++
 fs/nfsd/vfs.h      |    3 +++
 fs/nfsd/xdr4.h     |    3 +++
 fs/xattr.c         |   25 +++++++++++++------------
 7 files changed, 92 insertions(+), 19 deletions(-)
fs/nfsd/nfs4proc.c +9 -0
index 0cfd257..8851bce 100644
@@ -979,6 +979,11 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
 				&setattr->sa_label);
 	if (status)
 		goto out;
+	if (setattr->sa_ima.len)
+		status = nfsd4_set_ima_metadata(rqstp, &cstate->current_fh,
+						&setattr->sa_ima);
+	if (status)
+		goto out;
 	status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
 				0, (time_t)0);
 out:
@@ -2135,6 +2140,10 @@ static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
 		ret += NFS4_MAXLABELLEN + 12;
 		bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
 	}
+	if (bmap2 & FATTR4_WORD2_LINUX_IMA) {
+		ret += NFS4_MAXIMALEN + 4;
+		bmap2 &= ~FATTR4_WORD2_LINUX_IMA;
+	}
 	/*
 	 * Largest of remaining attributes are 16 bytes (e.g.,
 	 * supported_attributes)
fs/nfsd/nfs4xdr.c +43 -6

121 lines not on this page · raw message

fs/nfsd/nfsd.h +2 -1
index 0668999..c87ff8e 100644
@@ -362,6 +362,7 @@ static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
 	(NFSD4_1_SUPPORTED_ATTRS_WORD2 | \
 	FATTR4_WORD2_CHANGE_ATTR_TYPE | \
 	FATTR4_WORD2_MODE_UMASK | \
+	FATTR4_WORD2_LINUX_IMA | \
 	NFSD4_2_SECURITY_ATTRS)
 
 extern const u32 nfsd_suppattrs[3][3];
@@ -399,7 +400,7 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
 #define MAYBE_FATTR4_WORD2_SECURITY_LABEL 0
 #endif
 #define NFSD_WRITEABLE_ATTRS_WORD2 \
-	(FATTR4_WORD2_MODE_UMASK \
+	(FATTR4_WORD2_MODE_UMASK | FATTR4_WORD2_LINUX_IMA \
 	| MAYBE_FATTR4_WORD2_SECURITY_LABEL)
 
 #define NFSD_SUPPATTR_EXCLCREAT_WORD0 \
fs/nfsd/vfs.c +19 -0
index 7dc98e1..3c00072 100644
@@ -551,6 +551,25 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,
 }
 #endif
 
+__be32 nfsd4_set_ima_metadata(struct svc_rqst *rqstp, struct svc_fh *fhp,
+			      struct xdr_netobj *ima)
+{
+	struct dentry *dentry;
+	int host_error;
+	__be32 error;
+
+	error = fh_verify(rqstp, fhp, 0 /* S_IFREG */, NFSD_MAY_SATTR);
+	if (error)
+		return error;
+	dentry = fhp->fh_dentry;
+
+	inode_lock(d_inode(dentry));
+	host_error = __vfs_setxattr_noperm(dentry, XATTR_NAME_IMA, ima->data,
+					   ima->len, 0);
+	inode_unlock(d_inode(dentry));
+	return nfserrno(host_error);
+}
+
 __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst,
 		u64 dst_pos, u64 count)
 {
fs/nfsd/vfs.h +3 -0
index a7e1073..acfc2b0 100644
@@ -55,6 +55,9 @@ __be32		nfsd_setattr(struct svc_rqst *, struct svc_fh *,
 #ifdef CONFIG_NFSD_V4
 __be32          nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *,
 		    struct xdr_netobj *);
+__be32		nfsd4_set_ima_metadata(struct svc_rqst *rqstp,
+				       struct svc_fh *fhp,
+				       struct xdr_netobj *ima);
 __be32		nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
 				    struct file *, loff_t, loff_t, int);
 __be32		nfsd4_clone_file_range(struct file *, u64, struct file *,
fs/nfsd/xdr4.h +3 -0
index feeb6d4..2f3307f 100644
@@ -123,6 +123,7 @@ struct nfsd4_create {
 	struct nfsd4_change_info  cr_cinfo; /* response */
 	struct nfs4_acl *cr_acl;
 	struct xdr_netobj cr_label;
+	struct xdr_netobj cr_ima;
 };
 #define cr_datalen	u.link.datalen
 #define cr_data		u.link.data
@@ -255,6 +256,7 @@ struct nfsd4_open {
 	struct nfs4_clnt_odstate *op_odstate; /* used during processing */
 	struct nfs4_acl *op_acl;
 	struct xdr_netobj op_label;
+	struct xdr_netobj op_ima;
 };
 
 struct nfsd4_open_confirm {
@@ -339,6 +341,7 @@ struct nfsd4_setattr {
 	struct iattr	sa_iattr;           /* request */
 	struct nfs4_acl *sa_acl;
 	struct xdr_netobj sa_label;
+	struct xdr_netobj sa_ima;
 };
 
 struct nfsd4_setclientid {
fs/xattr.c +13 -12
index 0d6a6a4..5674be1 100644
@@ -151,20 +151,20 @@
 EXPORT_SYMBOL(__vfs_setxattr);
 
 /**
- *  __vfs_setxattr_noperm - perform setxattr operation without performing
- *  permission checks.
+ * __vfs_setxattr_noperm - perform setxattr operation without performing
+ * permission checks.
  *
- *  @dentry - object to perform setxattr on
- *  @name - xattr name to set
- *  @value - value to set @name to
- *  @size - size of @value
- *  @flags - flags to pass into filesystem operations
+ * @dentry: object to perform setxattr on
+ * @name: xattr name to set
+ * @value: value to set @name to
+ * @size: size of @value
+ * @flags: flags to pass into filesystem operations
  *
- *  returns the result of the internal setxattr or setsecurity operations.
+ * Returns the result of the internal setxattr or setsecurity operations.
  *
- *  This function requires the caller to lock the inode's i_mutex before it
- *  is executed. It also assumes that the caller will make the appropriate
- *  permission checks.
+ * This function requires the caller to lock the inode's i_mutex before it
+ * is executed. It also assumes that the caller will make the appropriate
+ * permission checks.
  */
 int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
 		const void *value, size_t size, int flags)
@@ -202,7 +202,7 @@ int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
 
 	return error;
 }
-
+EXPORT_SYMBOL_GPL(__vfs_setxattr_noperm);
 
 int
 vfs_setxattr(struct dentry *dentry, const char *name, const void *value,
@@ -295,6 +295,7 @@ int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
 	*xattr_value = value;
 	return error;
 }
+EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
 
 ssize_t
 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
#3 lore raw

PATCH v2 3/5 NFSD: Remove ima_file_check call

In reply to Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

---
 fs/nfsd/vfs.c |    6 ------
 1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -6
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else
#4 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Can we really remove this call?

--b.

Quoted 23 lines
---
 fs/nfsd/vfs.c |    6 ------
 1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -6
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else
#5 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 9 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Can we really remove this call?

Why wouldn't we be able to?

Quoted 16 lines

--b.

Quoted 14 lines

---
fs/nfsd/vfs.c | 6 ------

1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -0
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
Quoted 9 lines

fs/nfsd/vfs.c static int nfsd_open_break_lease(struct inode *inode, int access) · line 807

Quoted 9 lines
fs/nfsd/vfs.c +0 -6
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else

--
Chuck Lever

#6 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 11 lines · Chuck Lever
Quoted 9 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Can we really remove this call?

Why wouldn't we be able to?

I don't know the first thing about IMA, but surely it's there for some reason--is it really OK just to skip this on opens by nfsd?

--b.

Quoted 27 lines
Quoted 13 lines
Quoted 13 lines

---
fs/nfsd/vfs.c | 6 ------

1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -0
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
Quoted 9 lines

fs/nfsd/vfs.c static int nfsd_open_break_lease(struct inode *inode, int access) · line 807

Quoted 9 lines
fs/nfsd/vfs.c +0 -6
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else

--
Chuck Lever

#7 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 13 lines · Bruce Fields
Quoted 8 lines · Chuck Lever
Quoted 8 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Can we really remove this call?

Why wouldn't we be able to?

I don't know the first thing about IMA, but surely it's there for some reason--

It was originally added because the number of opens and closes of @file were counted, and not having that call was triggering a warning. Since commit 8eb988c70e770 ("fix ima breakage") the counters are maintained separately.

Quoted 1 line

is it really OK just to skip this on opens by nfsd?

That's why I split this out into a separate patch. I'm hoping to get some commentary from the linux-integrity community.

Quoted 29 lines

--b.

Quoted 27 lines
Quoted 13 lines
Quoted 13 lines

---
fs/nfsd/vfs.c | 6 ------

1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -0
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
Quoted 9 lines

fs/nfsd/vfs.c static int nfsd_open_break_lease(struct inode *inode, int access) · line 807

Quoted 9 lines
fs/nfsd/vfs.c +0 -6
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else

--
Chuck Lever

--
Chuck Lever

maintainer
#8 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

On Fri, 2019-03-08 at 16:29 -0500, Chuck Lever wrote:

Thanks Serge for bringing this thread to my attention.  Sorry for the delay in responding ...

Quoted 10 lines
Quoted 10 lines · Bruce Fields
Quoted 7 lines · Chuck Lever
Quoted 7 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Measurement and attestation is only one aspect.  The other aspect is verifying the integrity of files.  Shouldn't the NFS server verify the integrity of a file before allowing it to be served (eg. malware)?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Can we really remove this call?

Why wouldn't we be able to?

Quoted 7 lines
Quoted 2 lines

I don't know the first thing about IMA, but surely it's there for some reason--

It was originally added because the number of opens and closes of @file were counted, and not having that call was triggering a warning. Since commit 8eb988c70e770 ("fix ima breakage") the counters are maintained separately.

If that was the only reason, then the call itself would have been removed with the counter code.

Mimi

Quoted 43 lines
Quoted 3 lines

is it really OK just to skip this on opens by nfsd?

That's why I split this out into a separate patch. I'm hoping to get some commentary from the linux-integrity community.

Quoted 29 lines

--b.

Quoted 27 lines
Quoted 13 lines
Quoted 13 lines

---
fs/nfsd/vfs.c | 6 ------

1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -0
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
Quoted 9 lines

fs/nfsd/vfs.c static int nfsd_open_break_lease(struct inode *inode, int access) · line 807

Quoted 9 lines
fs/nfsd/vfs.c +0 -6
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else

--
Chuck Lever

--
Chuck Lever

#9 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 16 lines · Mimi Zohar

On Fri, 2019-03-08 at 16:29 -0500, Chuck Lever wrote:

Thanks Serge for bringing this thread to my attention. Sorry for the delay in responding ...

Quoted 7 lines
Quoted 7 lines · Bruce Fields
Quoted 4 lines · Chuck Lever
Quoted 4 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Chuck Lever
Quoted 2 lines

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Measurement and attestation is only one aspect. The other aspect is verifying the integrity of files. Shouldn't the NFS server verify the integrity of a file before allowing it to be served (eg. malware)?

Hi Mimi, thanks for the review.

Architecturally, the server is not using the file's data, it is merely part of the filesystem that stores it. But that said, there are several concrete reasons why I feel an NFS server should not be involved in measurement/attestation, but only with storing file content and IMA metadata.

1. The broadest attack surface for a remote filesystem is modification of data in flight. Attestation of the file on the server is not going to defend against that attack, only attestation on the client will do that. Is there a good reason to pay the cost of double attestation?

2. It is possible (perhaps even likely) that the NFS server and a client of that server will have different IMA policies and even different file signing authorities.

A third, perhaps related, reason is that NFS can run on non-Linux NFS servers which would not have any attestation at all. An NFS client should not have to rely on the server for attestation, but should trust only its own measurement of each file, which would be done as late as possible before use.

Lastly, the NFS protocol does not enable an NFS client to tell a server how the file is to be used. For example, the server's policy might block execution of an unverifiable file, but the server won't have any way of knowing how the client is going to use that file. The client might be opening the file to copy it or update its IMA metadata.

Speaking of protocol, there's no special error code that reports an integrity verification failure. The client just sees that the UID does not have access to the file. There's no way the user or client can do anything to clear this condition via NFS without IMA support.

If these reasons make sense, should I add them to the patch description?

Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Can we really remove this call?

Why wouldn't we be able to?

I don't know the first thing about IMA, but surely it's there for some reason--

It was originally added because the number of opens and closes of @file were counted, and not having that call was triggering a warning. Since commit 8eb988c70e770 ("fix ima breakage") the counters are maintained separately.

Quoted 49 lines

If that was the only reason, then the call itself would have been removed with the counter code.

Mimi

Quoted 43 lines
Quoted 3 lines

is it really OK just to skip this on opens by nfsd?

That's why I split this out into a separate patch. I'm hoping to get some commentary from the linux-integrity community.

Quoted 29 lines

--b.

Quoted 27 lines
Quoted 13 lines
Quoted 13 lines

---
fs/nfsd/vfs.c | 6 ------

1 file changed, 6 deletions(-)
fs/nfsd/vfs.c +0 -0
index 3c00072..524c6e5 100644
@@ -802,12 +802,6 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
 		goto out_nfserr;
 	}
 
Quoted 9 lines

fs/nfsd/vfs.c static int nfsd_open_break_lease(struct inode *inode, int access) · line 807

Quoted 9 lines
fs/nfsd/vfs.c +0 -6
-	host_err = ima_file_check(file, may_flags);
-	if (host_err) {
-		fput(file);
-		goto out_nfserr;
-	}
-
 	if (may_flags & NFSD_MAY_64BIT_COOKIE)
 		file->f_mode |= FMODE_64BITHASH;
 	else

--
Chuck Lever

--
Chuck Lever

--
Chuck Lever

maintainer
#10 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 23 lines · Chuck Lever
Quoted 15 lines · Mimi Zohar

On Fri, 2019-03-08 at 16:29 -0500, Chuck Lever wrote:

Thanks Serge for bringing this thread to my attention. Sorry for the delay in responding ...

Quoted 7 lines
Quoted 7 lines · Bruce Fields
Quoted 4 lines · Chuck Lever
Quoted 4 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Chuck Lever
Quoted 2 lines

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Measurement and attestation is only one aspect. The other aspect is verifying the integrity of files. Shouldn't the NFS server verify the integrity of a file before allowing it to be served (eg. malware)?

Quoted 7 lines

Hi Mimi, thanks for the review.

Architecturally, the server is not using the file's data, it is merely part of the filesystem that stores it. But that said, there are several concrete reasons why I feel an NFS server should not be involved in measurement/attestation, but only with storing file content and IMA metadata.

"Remote attestation" is the process of verifying the measurement list against the TPM PCRs, based on a TPM quote.  I think you meant "measurement/appraisal".

Quoted 5 lines

1. The broadest attack surface for a remote filesystem is modification of data in flight. Attestation of the file on the server is not going to defend against that attack, only attestation on the client will do that. Is there a good reason to pay the cost of double attestation?

Doesn't the server have a responsibility to provide files that have not been unintentionally or maliciously altered?

Quoted 3 lines

2. It is possible (perhaps even likely) that the NFS server and a client of that server will have different IMA policies and even different file signing authorities.

That doesn't negate the due diligence on the server's part of preventing the spread of malware.

Quoted 6 lines

A third, perhaps related, reason is that NFS can run on non-Linux NFS servers which would not have any attestation at all. An NFS client should not have to rely on the server for attestation, but should trust only its own measurement of each file, which would be done as late as possible before use.

The ima_file_check() hook can also audit the file, providing additional forensic information (eg. the file hash).

Mimi

Quoted 15 lines

Lastly, the NFS protocol does not enable an NFS client to tell a server how the file is to be used. For example, the server's policy might block execution of an unverifiable file, but the server won't have any way of knowing how the client is going to use that file. The client might be opening the file to copy it or update its IMA metadata.

Speaking of protocol, there's no special error code that reports an integrity verification failure. The client just sees that the UID does not have access to the file. There's no way the user or client can do anything to clear this condition via NFS without IMA support.

If these reasons make sense, should I add them to the patch description?

#11 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 41 lines · Mimi Zohar
Quoted 23 lines · Chuck Lever
Quoted 15 lines · Mimi Zohar

On Fri, 2019-03-08 at 16:29 -0500, Chuck Lever wrote:

Thanks Serge for bringing this thread to my attention. Sorry for the delay in responding ...

Quoted 7 lines
Quoted 7 lines · Bruce Fields
Quoted 4 lines · Chuck Lever
Quoted 4 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Chuck Lever
Quoted 2 lines

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Measurement and attestation is only one aspect. The other aspect is verifying the integrity of files. Shouldn't the NFS server verify the integrity of a file before allowing it to be served (eg. malware)?

Quoted 7 lines

Hi Mimi, thanks for the review.

Architecturally, the server is not using the file's data, it is merely part of the filesystem that stores it. But that said, there are several concrete reasons why I feel an NFS server should not be involved in measurement/attestation, but only with storing file content and IMA metadata.

"Remote attestation" is the process of verifying the measurement list against the TPM PCRs, based on a TPM quote. I think you meant "measurement/appraisal".

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

1. The broadest attack surface for a remote filesystem is modification of data in flight. Attestation of the file on the server is not going to defend against that attack, only attestation on the client will do that. Is there a good reason to pay the cost of double attestation?

Doesn't the server have a responsibility to provide files that have not been unintentionally or maliciously altered?

It's a design goal of any filesystem to present unaltered file data to applications. But the responsibility is end-to-end. Adding extra checks in the middle introduce a cost. Measuring on the client is sufficient, and it is equivalent to what local filesystems do (and, it allows each client to apply its own security policy).

I'm going to claim here without proof that there is little value in using IMA on an NFS server that serves NFS clients that are not IMA-aware. :-)

Quoted 6 lines
Quoted 3 lines

2. It is possible (perhaps even likely) that the NFS server and a client of that server will have different IMA policies and even different file signing authorities.

That doesn't negate the due diligence on the server's part of preventing the spread of malware.

Commercial NFS servers (like NetApp filers) perform malware and integrity checking via a scrubbing agent rather than checking in a hot path. Filesystems are not only responsible for leaving data unchanged, they also have performance requirements.

Quoted 8 lines
Quoted 5 lines

A third, perhaps related, reason is that NFS can run on non-Linux NFS servers which would not have any attestation at all. An NFS client should not have to rely on the server for attestation, but should trust only its own measurement of each file, which would be done as late as possible before use.

The ima_file_check() hook can also audit the file, providing additional forensic information (eg. the file hash).

IIUC, you are talking about troubleshooting, which should be rare. That can be done with tools on the server if needed, but IMO can be avoided in performance-sensitive paths.

Quoted 16 lines

Mimi

Quoted 14 lines

Lastly, the NFS protocol does not enable an NFS client to tell a server how the file is to be used. For example, the server's policy might block execution of an unverifiable file, but the server won't have any way of knowing how the client is going to use that file. The client might be opening the file to copy it or update its IMA metadata.

Speaking of protocol, there's no special error code that reports an integrity verification failure. The client just sees that the UID does not have access to the file. There's no way the user or client can do anything to clear this condition via NFS without IMA support.

If these reasons make sense, should I add them to the patch description?

--
Chuck Lever

maintainer
#12 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 35 lines · Chuck Lever
Quoted 35 lines · Mimi Zohar
Quoted 14 lines · Chuck Lever
Quoted 5 lines · Mimi Zohar

On Fri, 2019-03-08 at 16:29 -0500, Chuck Lever wrote:
Thanks Serge for bringing this thread to my attention. Sorry for the

Quoted 2 lines
Quoted 2 lines · Bruce Fields

On Fri, Mar 08, 2019 at 04:11:06PM -0500, Chuck Lever wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Measurement and attestation is only one aspect. The other aspect is verifying the integrity of files. Shouldn't the NFS server verify the integrity of a file before allowing it to be served (eg. malware)?

Quoted 7 lines

Hi Mimi, thanks for the review.

Architecturally, the server is not using the file's data, it is merely part of the filesystem that stores it. But that said, there are several concrete reasons why I feel an NFS server should not be involved in measurement/attestation, but only with storing file content and IMA metadata.

"Remote attestation" is the process of verifying the measurement list against the TPM PCRs, based on a TPM quote. I think you meant "measurement/appraisal".

Quoted 5 lines

1. The broadest attack surface for a remote filesystem is modification of data in flight. Attestation of the file on the server is not going to defend against that attack, only attestation on the client will do that. Is there a good reason to pay the cost of double attestation?

Quoted 6 lines
Quoted 2 lines

Doesn't the server have a responsibility to provide files that have not been unintentionally or maliciously altered?

It's a design goal of any filesystem to present unaltered file data to applications. But the responsibility is end-to-end. Adding extra checks in the middle introduce a cost.

Files are measured/appraised/audited based on the IMA policy.  Have you measured the performance cost of measuring and appraising the files being served?  Unless a policy has been supplied, the performance impact, if any, would be limited to walking the IMA policy rules.

Quoted 3 lines

Measuring on the client is
sufficient, and it is equivalent to what local filesystems do (and, it allows each client to apply its own security policy).

I'm not arguing with you about an end-to-end file integrity solution. That is the goal, but one that assumes this proposed work, based on fs-verity signatures.

Quoted 3 lines

I'm going to claim here without proof that there is little value in using IMA on an NFS server that serves NFS clients that are not IMA-aware. :-)

For systems that don't or haven't implemented the proposed end-to-end file integrity solution, verifying the file integrity on the server is all the more important.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

2. It is possible (perhaps even likely) that the NFS server and a client of that server will have different IMA policies and even different file signing authorities.

Quoted 7 lines
Quoted 2 lines

That doesn't negate the due diligence on the server's part of preventing the spread of malware.

Commercial NFS servers (like NetApp filers) perform malware and integrity checking via a scrubbing agent rather than checking in a hot path. Filesystems are not only responsible for leaving data unchanged, they also have performance requirements.

Any userspace application leaves a window of opportunity between the time the file has been created/modified and the time that the application verifies it.  This is one of the main reason for IMA being
in the kernel.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

A third, perhaps related, reason is that NFS can run on non-Linux NFS servers which would not have any attestation at all. An NFS client should not have to rely on the server for attestation, but should trust only its own measurement of each file, which would be done as late as possible before use.

Quoted 6 lines
Quoted 2 lines

The ima_file_check() hook can also audit the file, providing additional forensic information (eg. the file hash).

IIUC, you are talking about troubleshooting, which should be rare. That can be done with tools on the server if needed, but IMO can be avoided in performance-sensitive paths.

No, this isn't about "troubleshooting", but about auditing the files served and using the file hashes for forensic investigations.[1][2]

Mimi

[1] Commit e7c568e0fd0c ("ima: audit log hashes")
[2] https://www.fireeye.com/blog/threat-research/2016/11/extending_linux_exec.html

#13 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 47 lines · Mimi Zohar
Quoted 35 lines · Chuck Lever
Quoted 35 lines · Mimi Zohar
Quoted 14 lines · Chuck Lever
Quoted 5 lines · Mimi Zohar

On Fri, 2019-03-08 at 16:29 -0500, Chuck Lever wrote:
Thanks Serge for bringing this thread to my attention. Sorry for the

Quoted 2 lines
Quoted 2 lines · Bruce Fields

On Fri, Mar 08, 2019 at 04:11:06PM -0500, Chuck Lever wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · On Mar 8, 2019, at 4:10 PM, [email protected] wrote:
Quoted 2 lines · Chuck Lever

The NFS server needs to allow NFS clients to perform their own attestation and measurement.

Measurement and attestation is only one aspect. The other aspect is verifying the integrity of files. Shouldn't the NFS server verify the integrity of a file before allowing it to be served (eg. malware)?

Quoted 7 lines

Hi Mimi, thanks for the review.

Architecturally, the server is not using the file's data, it is merely part of the filesystem that stores it. But that said, there are several concrete reasons why I feel an NFS server should not be involved in measurement/attestation, but only with storing file content and IMA metadata.

"Remote attestation" is the process of verifying the measurement list against the TPM PCRs, based on a TPM quote. I think you meant "measurement/appraisal".

Quoted 5 lines

1. The broadest attack surface for a remote filesystem is modification of data in flight. Attestation of the file on the server is not going to defend against that attack, only attestation on the client will do that. Is there a good reason to pay the cost of double attestation?

Quoted 6 lines
Quoted 2 lines

Doesn't the server have a responsibility to provide files that have not been unintentionally or maliciously altered?

It's a design goal of any filesystem to present unaltered file data to applications. But the responsibility is end-to-end. Adding extra checks in the middle introduce a cost.

Quoted 5 lines

Files are measured/appraised/audited based on the IMA policy. Have you measured the performance cost of measuring and appraising the files being served? Unless a policy has been supplied, the performance impact, if any, would be limited to walking the IMA policy rules.

I have not measured the performance cost, but I'm simply observing that it could be substantial in some cases.

nfsd_open is called in the NFSv3 READ and WRITE paths, in addition to whenever a file is locked (NFSv3) or opened (NFSv4). The impact is small when there is no IMA policy, but could be substantial when there is an IMA policy in effect.

Note that NFSv3 does not have an OPEN operation. I'm not sure what would be an adequate substitute location for an IMA hash audit for NFSv3 file accesses.

Measuring on the client gives us the most effective integrity coverage and an implementation that is closest in behavior to local filesystem semantics. I'm just saying I'd rather not measure twice, because it doesn't provide a great benefit (more below) and can be costly. I agree that we should figure out a way to assess its performance impact.

Quoted 8 lines
Quoted 3 lines

Measuring on the client is
sufficient, and it is equivalent to what local filesystems do (and, it allows each client to apply its own security policy).

I'm not arguing with you about an end-to-end file integrity solution.
That is the goal, but one that assumes this proposed work, based on
fs-verity signatures.

Quoted 7 lines
Quoted 3 lines

I'm going to claim here without proof that there is little value in using IMA on an NFS server that serves NFS clients that are not IMA-aware. :-)

For systems that don't or haven't implemented the proposed end-to-end file integrity solution, verifying the file integrity on the server is all the more important.

As I said before, the largest integrity exposure is modification of file data as it is transported between server and client -- _after_ the server has measured it. IMHO that makes measuring on the server a bit of security theatre.

In addition to that, ima_file_check returns -EACCES if it fails (and the IMA policy is in enforcing mode). That is a confusing situation for NFS, since that looks like the user does not have permission to access the file (ie, that it can be corrected by the user by changing an ACL or mode bits).

Maybe NFS should have new error codes that can convey "blocked by administrative policy" or "failed integrity check". In the meantime, though, existing NFS systems without any IMA support do not have these codes.

Quoted 31 lines
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

2. It is possible (perhaps even likely) that the NFS server and a client of that server will have different IMA policies and even different file signing authorities.

That doesn't negate the due diligence on the server's part of preventing the spread of malware.

Commercial NFS servers (like NetApp filers) perform malware and integrity checking via a scrubbing agent rather than checking in a hot path. Filesystems are not only responsible for leaving data unchanged, they also have performance requirements.

Any userspace application leaves a window of opportunity between the time the file has been created/modified and the time that the application verifies it. This is one of the main reason for IMA being in the kernel.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

A third, perhaps related, reason is that NFS can run on non-Linux NFS servers which would not have any attestation at all. An NFS client should not have to rely on the server for attestation, but should trust only its own measurement of each file, which would be done as late as possible before use.

Quoted 6 lines
Quoted 2 lines

The ima_file_check() hook can also audit the file, providing additional forensic information (eg. the file hash).

IIUC, you are talking about troubleshooting, which should be rare. That can be done with tools on the server if needed, but IMO can be avoided in performance-sensitive paths.

Quoted 7 lines

No, this isn't about "troubleshooting", but about auditing the files served and using the file hashes for forensic investigations.[1][2]

Mimi

[1] Commit e7c568e0fd0c ("ima: audit log hashes")
[2] https://www.fireeye.com/blog/threat-research/2016/11/extending_linux_exec.html

Auditing can be done by keeping the ima_file_check call site but ignoring its return code, for example.

In any event, removing the ima_file_check call is not required for the prototype to be functional. I can drop this patch for now, but I encourage examination of how the NFS server measures and audits files when an actual IMA policy is in effect.

--
Chuck Lever

maintainer
#14 lore raw

Re: [PATCH v2 3/5] NFSD: Remove ima_file_check call

Quoted 2 lines · Chuck Lever

Auditing can be done by keeping the ima_file_check call site but ignoring its return code, for example.

Neither the "measure" or "audit" rules control the return code.  Only an IMA "appraise" rule verifies a file's integrity, which could fail, resulting in an error return code.

Different systems might have different requirements.  Having the IMA hook here, allows IMA custom policies to be defined, based on the specific system requirements.

In terms of performance, IMA calculates the file hash once, which can then be used for measuring, appraising, and auditing.  Unless the file changes, calculating the file hash is only done once.

Quoted 4 lines

In any event, removing the ima_file_check call is not required for the prototype to be functional. I can drop this patch for now, but I encourage examination of how the NFS server measures and audits files when an actual IMA policy is in effect.

Thank you!

Mimi

#15 lore raw

PATCH v2 4/5 NFS: Rename security xattr handler

In reply to Chuck Lever

Refactor: In a moment, the handler will no longer deal with only NFSv4 security labels. Give it a more generic name.

---
 fs/nfs/nfs4proc.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
fs/nfs/nfs4proc.c +11 -12
index 557a5d6..df0ee42 100644
@@ -7128,20 +7128,19 @@ static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry)
 
 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
 
-static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler,
-				     struct dentry *unused, struct inode *inode,
-				     const char *key, const void *buf,
-				     size_t buflen, int flags)
+static int nfs4_xattr_set_security(const struct xattr_handler *handler,
+				   struct dentry *unused, struct inode *inode,
+				   const char *key, const void *buf,
+				   size_t buflen, int flags)
 {
 	if (security_ismaclabel(key))
 		return nfs4_set_security_label(inode, buf, buflen);
-
 	return -EOPNOTSUPP;
 }
 
-static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
-				     struct dentry *unused, struct inode *inode,
-				     const char *key, void *buf, size_t buflen)
+static int nfs4_xattr_get_security(const struct xattr_handler *handler,
+				   struct dentry *unused, struct inode *inode,
+				   const char *key, void *buf, size_t buflen)
 {
 	if (security_ismaclabel(key))
 		return nfs4_get_security_label(inode, buf, buflen);
@@ -7161,10 +7160,10 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 	return len;
 }
 
-static const struct xattr_handler nfs4_xattr_nfs4_label_handler = {
+static const struct xattr_handler nfs4_xattr_security_handler = {
 	.prefix = XATTR_SECURITY_PREFIX,
-	.get	= nfs4_xattr_get_nfs4_label,
-	.set	= nfs4_xattr_set_nfs4_label,
+	.get	= nfs4_xattr_get_security,
+	.set	= nfs4_xattr_set_security,
 };
 
 #else
@@ -9824,7 +9823,7 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 const struct xattr_handler *nfs4_xattr_handlers[] = {
 	&nfs4_xattr_nfs4_acl_handler,
 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
-	&nfs4_xattr_nfs4_label_handler,
+	&nfs4_xattr_security_handler,
 #endif
 	NULL
 };
#16 lore raw

PATCH v2 5/5 NFS: Prototype support for IMA on NFS (client)

In reply to Chuck Lever

When NFSv4 Security Label support is enabled and kernel Integrity and IMA support is enabled (via CONFIG), then build in code to handle the "security.ima" xattr. The NFS client converts this to a particular FATTR4 bit which can be handled on the wire via a standard NFSv4 GETATTR or SETATTR operation.

The new FATTR4 bit is made up; meaning we still have to go through a standards process to allocate a bit that all NFS vendors agree on. Thus there is no guarantee this prototype will interoperate with others or with a future standards-based implementation.

---
 fs/nfs/nfs4_fs.h          |    1 
 fs/nfs/nfs4proc.c         |  111 ++++++++++++++++++++++++++-
 fs/nfs/nfs4xdr.c          |  186 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/nfs4.h      |    3 +
 include/linux/nfs_fs_sb.h |    1 
 include/linux/nfs_xdr.h   |   21 +++++
 6 files changed, 321 insertions(+), 2 deletions(-)
fs/nfs/nfs4_fs.h +1 -0
index 06ac3d9a..795f2f5 100644
@@ -424,6 +424,7 @@ extern int nfs4_detect_session_trunking(struct nfs_client *clp,
 extern const u32 nfs4_pathconf_bitmap[3];
 extern const u32 nfs4_fsinfo_bitmap[3];
 extern const u32 nfs4_fs_locations_bitmap[3];
+extern const u32 nfs4_ima_bitmap[3];
 
 void nfs40_shutdown_client(struct nfs_client *);
 void nfs41_shutdown_client(struct nfs_client *);
fs/nfs/nfs4proc.c +109 -2

164 lines not on this page · raw message

fs/nfs/nfs4xdr.c +186 -0

234 lines not on this page · raw message

include/linux/nfs4.h +3 -0
index ca3adb1..4d5c771 100644
@@ -540,6 +540,9 @@ enum {
 	NFSPROC4_CLNT_OFFLOAD_CANCEL,
 
 	NFSPROC4_CLNT_LOOKUPP,
+
+	NFSPROC4_CLNT_GETIMA,
+	NFSPROC4_CLNT_SETIMA,
 };
 
 /* nfs41 types */
include/linux/nfs_fs_sb.h +1 -0
index 6aa8cc8..b92f954 100644
@@ -261,5 +261,6 @@ struct nfs_server {
 #define NFS_CAP_CLONE		(1U << 23)
 #define NFS_CAP_COPY		(1U << 24)
 #define NFS_CAP_OFFLOAD_CANCEL	(1U << 25)
+#define NFS_CAP_IMA		(1U << 26)
 
 #endif
include/linux/nfs_xdr.h +21 -0
index 441a93e..4ee30f0 100644
@@ -1010,6 +1010,27 @@ struct nfs4_getattr_res {
 	struct nfs4_label		*label;
 };
 
+struct nfs4_getima_arg {
+	struct nfs4_sequence_args	seq_args;
+	const struct nfs_fh		*fh;
+	const u32			*bitmask;
+};
+
+struct nfs4_getima_res {
+	struct nfs4_sequence_res	seq_res;
+	const struct nfs_server		*server;
+	void				*data;
+	u32				len;
+};
+
+struct nfs4_setima_arg {
+	struct nfs4_sequence_args	seq_args;
+	struct nfs_fh			*fh;
+	nfs4_stateid                    stateid;
+	const void			*data;
+	u32				len;
+};
+
 struct nfs4_link_arg {
 	struct nfs4_sequence_args 	seq_args;
 	const struct nfs_fh *		fh;