linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH] NFS: Filter auth flavors returned by MNT3
Date: Thu, 30 Aug 2012 13:53:58 -0700	[thread overview]
Message-ID: <20120830204930.3101.99200.stgit@seurat.1015granger.net> (raw)

Use the new rpcauth_list_flavors() API introduced in commit 6a1a1e34
to prevent legacy NFS mounts from attempting to use security flavors
that the local RPC client does not support.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

I don't remember exactly what we wanted to do here.  Trond, do you
recall?

 fs/nfs/mount_clnt.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)

diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c
index 8e65c7f..3e39678 100644
--- a/fs/nfs/mount_clnt.c
+++ b/fs/nfs/mount_clnt.c
@@ -135,6 +135,88 @@ struct mnt_fhstatus {
 	struct nfs_fh *fh;
 };
 
+/*
+ * Predicate: return true if info->auth_flavs[] contains "flavor"
+ */
+static bool flavor_found(struct nfs_mount_request *info,
+			 rpc_authflavor_t flavor)
+{
+	unsigned int i, max = *info->auth_flav_len;
+
+	for (i = 0; i < max; i++) {
+		if (info->auth_flavs[i] == flavor) {
+			return true;
+		}
+	}
+	return false;
+}
+
+static int do_filter_flavors(rpc_authflavor_t *supported,
+			     unsigned int sup_size,
+			     struct nfs_mount_request *info)
+{
+	unsigned int i, j, max = *info->auth_flav_len;
+	rpc_authflavor_t *good;
+	int status;
+
+	good = kcalloc(max, sizeof(*good), GFP_KERNEL);
+	if (good == NULL) {
+		status = -ENOMEM;
+		goto out;
+	}
+
+	j = 0;
+	for (i = 0; i < sup_size; i++) {
+		if (flavor_found(info, supported[i])) {
+			good[j++] = supported[i];
+		}
+	}
+
+	if (j == 0) {
+		/* no supported flavors found */
+		status = -EACCES;
+		goto out;
+	}
+
+	for (i = 0; i < j; i++) {
+		info->auth_flavs[i] = good[i];
+	}
+	*info->auth_flav_len = j;
+	status = 0;
+
+out:
+	kfree(good);
+	return status;
+}
+
+/*
+ * Flavors not supported locally are removed from the flavor list
+ * returned from the server.  On success, update the server's
+ * flavor list and return zero.  Otherwise a negative errno
+ * is returned.
+ */
+static int nfs_filter_auth_flavors(struct nfs_mount_request *info)
+{
+	int status, sup_size = NFS_MAX_SECFLAVORS;
+	rpc_authflavor_t *supported;
+
+	supported = kcalloc(sup_size, sizeof(*supported), GFP_KERNEL);
+	if (supported == NULL) {
+		status = -ENOMEM;
+		goto out;
+	}
+
+	status = rpcauth_list_flavors(supported, sup_size);
+	if (status < 0)
+		goto out;
+
+	status = do_filter_flavors(supported, status, info);
+
+out:
+	kfree(supported);
+	return status;
+}
+
 /**
  * nfs_mount - Obtain an NFS file handle for the given host and path
  * @info: pointer to mount request arguments
@@ -189,6 +271,12 @@ int nfs_mount(struct nfs_mount_request *info)
 	if (result.errno != 0)
 		goto out_mnt_err;
 
+	if (info->version == NFS_MNT3_VERSION) {
+		status = nfs_filter_auth_flavors(info);
+		if (status < 0)
+			goto out_filter_err;
+	}
+
 	dprintk("NFS: MNT request succeeded\n");
 	status = 0;
 
@@ -208,6 +296,9 @@ out_mnt_err:
 	dprintk("NFS: MNT server returned result %d\n", result.errno);
 	status = result.errno;
 	goto out;
+out_filter_err:
+	dprintk("NFS: error %d filtering flavors\n", status);
+	goto out;
 }
 
 /**


                 reply	other threads:[~2012-08-30 20:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120830204930.3101.99200.stgit@seurat.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).