Change behavior when "sec=" is not specified by user
Subsystems (3)
cover Change behavior when "sec=" is not specified by user
Trond, Bruce-
Second pass at providing the correct default security flavor for NFSv3 mounts when the user does not specify "sec=".
I posted these late last week, but somehow they never appeared on the mailing list. There has been one bug fix since then.
Bruce, I'm especially interested in your review. I think I've addressed all of your requests.
---
Chuck Lever (2):
NFS: Change default behavior when "sec=" is not specified by user
SUNRPC: Provide an API to determine what auth flavors are supported
fs/nfs/super.c | 99 ++++++++++++++++++++++++++++----------- include/linux/sunrpc/auth.h | 2 + include/linux/sunrpc/msg_prot.h | 2 + net/sunrpc/auth.c | 33 +++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 18 +++++++ 5 files changed, 125 insertions(+), 29 deletions(-)
Signature · 1 line
Chuck Lever <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20090908223433.23375.40342.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org
PATCH 1/2 SUNRPC: Provide an API to determine what auth flavors are supported
Introduce an external function call that can report whether sunrpc.ko can support an authentication flavor or not.
A new optional rpc_authops hook is added. If the hook is not present, then the flavor is assumed to be supported. If the hook is present, it is passed the pseudoflavor to check, and returns an indication of whether the pseudoflavor is supported or not.
---
include/linux/sunrpc/auth.h | 2 ++ net/sunrpc/auth.c | 33 +++++++++++++++++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 18 +++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletions(-)
include/linux/sunrpc/auth.h +2 -0
@@ -103,6 +103,7 @@ struct rpc_authops {struct rpc_cred * (*lookup_cred)(struct rpc_auth *,struct auth_cred *,int );struct rpc_cred * (*crcreate)(struct rpc_auth *,struct auth_cred *,int ); +int (*is_supported)(const rpc_authflavor_t ); };struct rpc_credops {
@@ -134,6 +135,7 @@ struct rpc_cred * rpc_lookup_cred(void);struct rpc_cred *rpc_lookup_machine_cred (void );int rpcauth_register (const struct rpc_authops *);int rpcauth_unregister (const struct rpc_authops *); +int rpcauth_is_supported (rpc_authflavor_t pseudoflavor);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);void rpcauth_release (struct rpc_auth *);struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct auth_cred *,int );
net/sunrpc/auth.c +33 -0
@@ -72,6 +72,39 @@ rpcauth_unregister(const struct rpc_authops *ops) }EXPORT_SYMBOL_GPL (rpcauth_unregister); +/** +* rpcauth_is_supported - report whether a particular flavor is supported +* @pseudoflavor: RPC authentication flavor to check +* +* Returns 1 if there is built-in support, or a loaded module, which can +* handle @pseudoflavor. Otherwise, zero is returned. +*/ +int +rpcauth_is_supported (rpc_authflavor_t pseudoflavor) +{ +const rpc_authflavor_t flavor =pseudoflavor_to_flavor (pseudoflavor); +const struct rpc_authops *ops; +int ret =0 ; + +spin_lock (&rpc_authflavor_lock); + ops = auth_flavors[flavor]; +if (ops ==NULL || !try_module_get (ops->owner)) { +spin_unlock (&rpc_authflavor_lock); + goto out; + } +spin_unlock (&rpc_authflavor_lock); + + ret =1 ; +if (ops->is_supported) + ret = ops->is_supported (pseudoflavor); + +module_put (ops->owner); + +out: +return ret; +} +EXPORT_SYMBOL_GPL (rpcauth_is_supported); +struct rpc_auth *rpcauth_create (rpc_authflavor_t pseudoflavor,struct rpc_clnt *clnt) {
net/sunrpc/auth_gss/auth_gss.c +17 -1
@@ -735,6 +735,21 @@ gss_pipe_destroy_msg(struct rpc_pipe_msg *msg) } } +static int +gss_is_supported (const rpc_authflavor_t pseudoflavor) +{ +struct gss_api_mech *mech; +int ret =0 ; + + mech =gss_mech_get_by_pseudoflavor (pseudoflavor); +if (mech) { + ret =1 ; +gss_mech_put (mech); + } + +return ret; +} +/* * NOTE: we have the opportunity to use different * parameters based on the input flavor (which must be a pseudoflavor)
@@ -1479,7 +1494,8 @@ static const struct rpc_authops authgss_ops = { .create = gss_create, .destroy = gss_destroy, .lookup_cred = gss_lookup_cred, - .crcreate = gss_create_cred + .crcreate = gss_create_cred, + .is_supported = gss_is_supported, };static const struct rpc_credops gss_credops = {
A message that is not in the archive (sent off-list or not yet received): 20090908223624.23375.28359.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org
Re: [PATCH 1/2] SUNRPC: Provide an API to determine what auth flavors are supported
Quoted 67 lines · Chuck Lever
Introduce an external function call that can report whether sunrpc.ko can support an authentication flavor or not.
A new optional
rpc_authopshook is added. If the hook is not present, then the flavor is assumed to be supported. If the hook is present, it is passed the pseudoflavor to check, and returns an indication of whether the pseudoflavor is supported or not.Signed-off-by Chuck Lever <[email protected]>---
include/linux/sunrpc/auth.h | 2 ++ net/sunrpc/auth.c | 33 +++++++++++++++++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 18 +++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletions(-)include/linux/sunrpc/auth.h +2
-0@@ -103,6 +103,7 @@ struct rpc_authops {struct rpc_cred * (*lookup_cred)(struct rpc_auth *,struct auth_cred *,int );struct rpc_cred * (*crcreate)(struct rpc_auth *,struct auth_cred *,int ); +int (*is_supported)(const rpc_authflavor_t ); };struct rpc_credops {@@ -134,6 +135,7 @@ struct rpc_cred * rpc_lookup_cred(void);struct rpc_cred *rpc_lookup_machine_cred (void );int rpcauth_register (const struct rpc_authops *);int rpcauth_unregister (const struct rpc_authops *); +int rpcauth_is_supported (rpc_authflavor_t pseudoflavor);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);void rpcauth_release (struct rpc_auth *);struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct auth_cred *,int );net/sunrpc/auth.c +23
-0@@ -72,6 +72,39 @@ rpcauth_unregister(const struct rpc_authops *ops) }EXPORT_SYMBOL_GPL (rpcauth_unregister); +/** +* rpcauth_is_supported - report whether a particular flavor is supported +* @pseudoflavor: RPC authentication flavor to check +* +* Returns 1 if there is built-in support, or a loaded module, which can +* handle @pseudoflavor. Otherwise, zero is returned. +*/ +int +rpcauth_is_supported (rpc_authflavor_t pseudoflavor) +{ +const rpc_authflavor_t flavor =pseudoflavor_to_flavor (pseudoflavor); +const struct rpc_authops *ops; +int ret =0 ; + +spin_lock (&rpc_authflavor_lock); + ops = auth_flavors[flavor]; +if (ops ==NULL || !try_module_get (ops->owner)) { +spin_unlock (&rpc_authflavor_lock); + goto out; + } +spin_unlock (&rpc_authflavor_lock); + + ret =1 ;
net/sunrpc/auth.c rpcauth_unregister(const struct rpc_authops *ops) · line 107
Quoted 10 lines
net/sunrpc/auth.c +10
-0+if (ops->is_supported) + ret = ops->is_supported (pseudoflavor); + +module_put (ops->owner); + +out: +return ret; +} +EXPORT_SYMBOL_GPL (rpcauth_is_supported); +
This doesn't look like the right interface to me. NFSv3's mount code, and the legacy binary mount interface may indeed use pseudoflavours, but the text based mount code uses pseudoflavour name strings, whereas NFSv4 SECINFO uses the ordinary flavour together with the RPCSEC_GSS <oid,qop,service> triplet.
I think we'd be better off with an interface that could handle all three types of request...
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
A message that is not in the archive (sent off-list or not yet received): 1252451892.8099.93.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Re: [PATCH 1/2] SUNRPC: Provide an API to determine what auth flavors are supported
Quoted 80 lines · Trond Myklebust
Quoted 79 lines · Chuck Lever
Introduce an external function call that can report whether sunrpc.ko can support an authentication flavor or not.
A new optional
rpc_authopshook is added. If the hook is not present, then the flavor is assumed to be supported. If the hook is present, it is passed the pseudoflavor to check, and returns an indication of whether the pseudoflavor is supported or not.Signed-off-by Chuck Lever <[email protected]>---
include/linux/sunrpc/auth.h| 2 ++net/sunrpc/auth.c| 33 ++++++++++++++++++++++++++++++
+++net/sunrpc/auth_gss/auth_gss.c| 18 +++++++++++++++++-3 files changed, 52 insertions(+), 1 deletions(-)include/linux/sunrpc/auth.h +1
-0@@ -103,6 +103,7 @@ struct rpc_authops {struct rpc_cred * (*lookup_cred)(struct rpc_auth *,struct auth_cred *,int );struct rpc_cred * (*crcreate)(struct rpc_auth *,struct auth_cred *,int ); +int (*is_supported)(const rpc_authflavor_t ); };struct
rpc_credops{include/linux/sunrpc/auth.h +1
-0@@ -134,6 +135,7 @@ struct rpc_cred * rpc_lookup_cred(void);struct rpc_cred *rpc_lookup_machine_cred (void );int rpcauth_register (const struct rpc_authops *);int rpcauth_unregister (const struct rpc_authops *); +int rpcauth_is_supported (rpc_authflavor_t pseudoflavor);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);void rpcauth_release (struct rpc_auth *);struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct auth_cred *,int );net/sunrpc/auth.c +2
-0@@ -72,6 +72,39 @@ rpcauth_unregister(const struct rpc_authops *ops) }EXPORT_SYMBOL_GPL (rpcauth_unregister); +/** +* rpcauth_is_supported - report whether a particular flavor is supported
+ * @pseudoflavor: RPC authentication flavor to check
+ *
+ * Returns 1 if there is built-in support, or a loaded module, which can
+ * handle @pseudoflavor. Otherwise, zero is returned.
+ */net/sunrpc/auth.c +4
-0+int +rpcauth_is_supported (rpc_authflavor_t pseudoflavor) +{ + const rpc_authflavor_t flavor =
pseudoflavor_to_flavor(pseudoflavor);net/sunrpc/auth.c +18
-0+const struct rpc_authops *ops; +int ret =0 ; + +spin_lock (&rpc_authflavor_lock); + ops = auth_flavors[flavor]; +if (ops ==NULL || !try_module_get (ops->owner)) { +spin_unlock (&rpc_authflavor_lock); + goto out; + } +spin_unlock (&rpc_authflavor_lock); + + ret =1 ; +if (ops->is_supported) + ret = ops->is_supported (pseudoflavor); + +module_put (ops->owner); + +out:
Quoted 8 lines
net/sunrpc/auth.c rpcauth_unregister(const struct rpc_authops *ops) · line 107
Quoted 4 lines
net/sunrpc/auth.c +4
-0+return ret; +} +EXPORT_SYMBOL_GPL (rpcauth_is_supported); +This doesn't look like the right interface to me. NFSv3's mount code, and the legacy binary mount interface may indeed use pseudoflavours, but the text based mount code uses pseudoflavour name strings,
Code in fs/nfs/super.c maps those strings to pseudoflavors. I used a text-based mount to test this new API, so I know it works.
Are you proposing to sink that super.c string mapping logic into the RPC client? It seems to me that mount options (ie the mapping of flavor names to pseudo flavors using the mount option interface) are wholly a problem of the client's upper layer.
Quoted 3 lines
whereas NFSv4
SECINFO uses the ordinary flavour together with theRPCSEC_GSS<oid,qop,service> triplet.
In which case we can provide another API (or a function in the NFS client) to map that tuple to a pseudoflavor.
Quoted 2 lines
I think we'd be better off with an interface that could handle all three types of request...
Perhaps, but I don't think we have a complete taxonomy of uses for this yet. I'm more in favor of coding these up separately, then seeing what commonalities emerge, rather than trying to overdesign a single API from the start.
But if you have a less rough idea of what you're looking for (or could point at some existing code samples), I'm still open.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 2/2 NFS: Change default behavior when "sec=" is not specified by user
In reply to a message not in the archiveCurrently the kernel's MNT client always uses AUTH_UNIX if no "sec=" mount option was specified. In the interest of conforming more closely to RFC 2623, use the first flavor on the server's returned authflavor list instead of AUTH_UNIX, if "sec=" was not specified.
When the user does _not_ specify "sec=" :
o For NFSv2 and NFSv4: the default is always AUTH_UNIX (unchanged).
o For NFSv3: if the server does not return an auth flavor list, use AUTH_UNIX by default; if the server does return a list, use the first entry on the list supported by the client.
See http://marc.info/?t=125075305400001&r=1&w=2
and
http://marc.info/?l=linux-nfs&m=125089022306281&w=2 .
---
fs/nfs/super.c | 100 ++++++++++++++++++++++++++++----------- include/linux/sunrpc/msg_prot.h | 2 + 2 files changed, 74 insertions(+), 28 deletions(-)
fs/nfs/super.c +72 -28
@@ -1363,48 +1363,72 @@ out_security_failure: }/* -* Match the requested auth flavors with the list returned by -* the server. Returns zero and sets the mount's authentication -* flavor on success; returns -EACCES if server does not support -* the requested flavor. +* User did not request a security flavor: pick one we support */ -static int nfs_walk_authlist (struct nfs_parsed_mount_data *args, -struct nfs_mount_request *request) +static int nfs_walk_authlist_unspec (struct nfs_parsed_mount_data *args, +struct nfs_mount_request *request) { -unsigned int i, j, server_authlist_len = *(request->auth_flav_len); +unsigned int i, server_authlist_len = *(request->auth_flav_len);/* * Certain releases of Linux's mountd return an empty * flavor list. To prevent behavioral regression with * these servers (ie. rejecting mounts that used to -* succeed), revert to pre-2.6.32 behavior (no checking) -* if the returned flavor list is empty. +* succeed), revert to pre-2.6.32 behavior (select +* AUTH_UNIX). */ -if (server_authlist_len ==0 ) +if (server_authlist_len ==0 ) { + args->auth_flavors[0 ] =RPC_AUTH_UNIX ;return 0 ; + }/* -* We avoid sophisticated negotiating here, as there are -* plenty of cases where we can get it wrong, providing -* either too little or too much security. +* See RFC 2623, section 2.7. * -* RFC 2623, section 2.7 suggests we SHOULD prefer the -* flavor listed first. However, some servers list -* AUTH_NULL first. Our caller plants AUTH_SYS, the -* preferred default, in args->auth_flavors[0] if user -* didn't specify sec= mount option. +* Exception: some older servers don't properly sort their +* flavor list, and return AUTH_NULL first. To prevent a +* client upgrade suddenly causing unexpected permission +* and file ownership problems with these servers, avoid +* selecting AUTH_NULL by default. */ +for (i =0 ; i < server_authlist_len; i++) { +if (args->auth_flavors[i] ==RPC_AUTH_NULL && + server_authlist_len >1 ) +continue ; +if (rpcauth_is_supported (args->auth_flavors[i])) { + args->auth_flavors[0 ] = request->auth_flavs[i]; +return 0 ; + } + } + +return -EACCES ; +} + +/* +* User requested a specific security flavor: check it against the +* returned list. +*/ +static int nfs_walk_authlist_spec (struct nfs_parsed_mount_data *args, +struct nfs_mount_request *request) +{ +unsigned int i, j, server_authlist_len = *(request->auth_flav_len); + +/* +* Certain releases of Linux's mountd return an empty +* flavor list. To prevent behavioral regression with +* these servers (ie. rejecting mounts that used to +* succeed), revert to pre-2.6.32 behavior (no checking). +*/ +if (server_authlist_len ==0 ) +return 0 ; +for (i =0 ; i < args->auth_flavor_len; i++)for (j =0 ; j < server_authlist_len; j++)if (args->auth_flavors[i] == request->auth_flavs[j]) { -dfprintk (MOUNT ,"NFS: using auth flavor %d\n" , - request->auth_flavs[j]); args->auth_flavors[0 ] = request->auth_flavs[j];return 0 ; } -dfprintk (MOUNT ,"NFS: server does not support requested auth flavor\n" ); -nfs_umount (request);return -EACCES ; }
@@ -1465,11 +1489,27 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args, }/* -* MNTv1 (NFSv2) does not support auth flavor negotiation. +* Verify the authentication flavor for this mount. */ -if (args->mount_server.version !=NFS_MNT3_VERSION ) -return 0 ; -return nfs_walk_authlist (args, &request); +if (args->mount_server.version ==NFS_MNT_VERSION ) { + status =0 ; +if (args->auth_flavors[0 ] ==RPC_AUTH_UNSPEC ) + args->auth_flavors[0 ] =RPC_AUTH_UNIX ; + }else { +if (args->auth_flavors[0 ] ==RPC_AUTH_UNSPEC ) + status =nfs_walk_authlist_unspec (args, &request); +else + status =nfs_walk_authlist_spec (args, &request); + } + +if (status) { +dfprintk (MOUNT , +"NFS: server does not support requested auth flavor\n" ); +nfs_umount (&request); + }else +dfprintk (MOUNT ,"NFS: MNT succeeded, using flavor %u\n" , + args->auth_flavors[0 ]); +return status; } static int nfs_parse_simple_hostname(const char *dev_name,
@@ -1644,7 +1684,7 @@ static int nfs_validate_mount_data(void *options, args->mount_server.port =NFS_UNSPEC_PORT ; args->nfs_server.port =NFS_UNSPEC_PORT ; args->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - args->auth_flavors[0 ] =RPC_AUTH_UNIX ; + args->auth_flavors[0 ] =RPC_AUTH_UNSPEC ; args->auth_flavor_len =1 ; args->minorversion =0 ;
@@ -1703,6 +1743,7 @@ static int nfs_validate_mount_data(void *options, args->namlen = data->namlen; args->bsize = data->bsize; + args->auth_flavors[0 ] =RPC_AUTH_UNIX ;if (data->flags &NFS_MOUNT_SECFLAVOUR ) args->auth_flavors[0 ] = data->pseudoflavor;if (!args->nfs_server.hostname)
@@ -2323,6 +2364,8 @@ static int nfs4_validate_text_mount_data(void *options, "NFS4: Too many RPC auth flavours specified\n");return -EINVAL ; } +if (args->auth_flavors[0 ] ==RPC_AUTH_UNSPEC ) + args->auth_flavors[0 ] =RPC_AUTH_UNIX ;if (args->client_address ==NULL ) { dfprintk(MOUNT,
@@ -2358,7 +2401,7 @@ static int nfs4_validate_mount_data(void *options, args->acdirmin =NFS_DEF_ACDIRMIN ; args->acdirmax =NFS_DEF_ACDIRMAX ; args->nfs_server.port =NFS_UNSPEC_PORT ; - args->auth_flavors[0 ] =RPC_AUTH_UNIX ; + args->auth_flavors[0 ] =RPC_AUTH_UNSPEC ; args->auth_flavor_len =1 ; args->minorversion =0 ;
@@ -2374,6 +2417,7 @@ static int nfs4_validate_mount_data(void *options,if (!nfs_verify_server_address (sap)) goto out_no_address; + args->auth_flavors[0 ] =RPC_AUTH_UNIX ;if (data->auth_flavourlen) {if (data->auth_flavourlen >1 ) goto out_inval_auth;
include/linux/sunrpc/msg_prot.h +2 -0
@@ -35,6 +35,8 @@ enum rpc_auth_flavors {RPC_AUTH_GSS_SPKM =390009 ,RPC_AUTH_GSS_SPKMI =390010 ,RPC_AUTH_GSS_SPKMP =390011 , +/* flavor was unspecified: */ + RPC_AUTH_UNSPEC = 0xffffffff, };/* Maximum size (in bytes) of an rpc credential or verifier */