Dynamically load GSS pseudoflavors by OID
Subsystems (3)
v3 cover Dynamically load GSS pseudoflavors by OID
Currently the RPC client is able to dynamically load GSS security flavor support by name or pseudoflavor number, but not by [OID, qop, service] tuple. Such a tuple can be provided by an NFSv4 server in a SECINFO reply, for example.
This means that if an NFSv4 server lists a tuple for, say, krb5p, in a SECINFO reply, our client will pretend it doesn't support krb5p if the rpc-auth-gss-krb5 module is available on the system but does not happen to be loaded at that moment.
This series implements support for loading the correct GSS pseudoflavor module before searching by GSS tuple.
This version of the series seems ready for linux-next or 3.9.
Changes since v2:
1. Some polish
2. Server-side [9/9] rewritten based on testing results
Changes since v1:
1. Simplify function and method names
2. Add an equivalent server-side interface
3. Improve automatic loading of the auth_rpcgss module
4. nfs_find_best_sec() also verifies non-GSS flavors against
RPC client's list of registered flavors
5. Search for (qop, svc) pair without adding a new function
6. Clean up GSS mech switch
7. Remove dprintk() calls
8. Improve patch descriptions
9. Numerous small improvements and fixes---
Chuck Lever (9):
SUNRPC: Remove EXPORT_SYMBOL_GPL() from GSS mech switch
SUNRPC: Make gss_mech_get() static
SUNRPC: Refactor nfsd4_do_encode_secinfo()
SUNRPC: Consider qop when looking up pseudoflavors
SUNRPC: Load GSS kernel module by OID
SUNRPC: Introduce rpcauth_get_pseudoflavor()
SUNRPC: Define rpcsec_gss_info structure
NFS: Remove unneeded forward declaration
SUNRPC: Missing module alias for auth_rpcgss.ko
fs/nfs/nfs4namespace.c | 43 +++++++----- fs/nfs/nfs4xdr.c | 20 +++--- fs/nfsd/nfs4xdr.c | 24 +++---- include/linux/nfs_xdr.h | 24 +------ include/linux/sunrpc/auth.h | 6 ++ include/linux/sunrpc/gss_api.h | 29 ++++++-- net/sunrpc/Kconfig | 1 net/sunrpc/auth.c | 68 +++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 3 + net/sunrpc/auth_gss/gss_krb5_mech.c | 6 +- net/sunrpc/auth_gss/gss_mech_switch.c | 117 +++++++++++++++++++++++++-------- net/sunrpc/auth_gss/svcauth_gss.c | 4 + 12 files changed, 245 insertions(+), 100 deletions(-)
Signature · 1 line
Chuck Lever
PATCH v3 1/9 SUNRPC: Missing module alias for auth_rpcgss.ko
Commit f344f6df "SUNRPC: Auto-load RPC authentication kernel modules", Mon Mar 20 13:44:08 2006, adds a request_module() call in rpcauth_create() to auto-load RPC security modules when a ULP tries to create a credential of that flavor.
In rpcauth_create(), the name of the module to load is built like this:
request_module("rpc-auth-%u", flavor);This means that for, say, RPC_AUTH_GSS, request_module() is looking for a module or alias called "rpc-auth-6".
The GSS module is named "auth_rpcgss", and commit f344f6df does not add any new module aliases. There is also no such alias provided in /etc/modprobe.d on my system (Fedora 16). Without this alias, the GSS module is not loaded on demand.
---
net/sunrpc/auth_gss/auth_gss.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +1 -0
@@ -1721,6 +1721,7 @@ static void __exit exit_rpcsec_gss(void)rcu_barrier ();/* Wait for completion of call_rcu()'s */ } +MODULE_ALIAS ("rpc-auth-6" );MODULE_LICENSE ("GPL" ); module_param_named(expired_cred_retry_delay, gss_expired_cred_retry_delay,
Re: [PATCH v3 1/9] SUNRPC: Missing module alias for auth_rpcgss.ko
Quoted 10 lines · Chuck Lever
Commit
f344f6df"SUNRPC: Auto-load RPC authentication kernel modules", Mon Mar 20 13:44:08 2006, adds arequest_module()call inrpcauth_create()to auto-load RPC security modules when a ULP tries to create a credential of that flavor.In
rpcauth_create(), the name of the module to load is built like this:request_module("rpc-auth-%u", flavor);
Quoted 7 lines
This means that for, say,
RPC_AUTH_GSS,request_module()is looking for a module or alias called "rpc-auth-6".The GSS module is named "
auth_rpcgss", and commitf344f6dfdoes not add any new module aliases. There is also no such alias provided in/etc/modprobe.don my system (Fedora 16). Without this alias, the GSS module is not loaded on demand.
Wait... Why do we want to load the auth_rpcgss module on its own? It doesn't provide any authentication or security mechanisms of its own. All it does is to provide support for the other security mechanisms.
As far as I can see, calling rpcauth_create() with a pseudoflavour value of '6' is a bug...
Quoted 19 lines
Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/auth_gss/auth_gss.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)net/sunrpc/auth_gss/auth_gss.c +1
-0@@ -1721,6 +1721,7 @@ static void __exit exit_rpcsec_gss(void)rcu_barrier ();/* Wait for completion of call_rcu()'s */ } +MODULE_ALIAS ("rpc-auth-6" );MODULE_LICENSE ("GPL" ); module_param_named(expired_cred_retry_delay, gss_expired_cred_retry_delay,
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Re: [PATCH v3 1/9] SUNRPC: Missing module alias for auth_rpcgss.ko
Quoted 14 lines · Trond
Quoted 13 lines · Chuck Lever
Commit
f344f6df"SUNRPC: Auto-load RPC authentication kernel modules", Mon Mar 20 13:44:08 2006, adds arequest_module()call inrpcauth_create()to auto-load RPC security modules when a ULP tries to create a credential of that flavor.In
rpcauth_create(), the name of the module to load is built like this:request_module("rpc-auth-%u", flavor);This means that for, say,
RPC_AUTH_GSS,request_module()is looking for a module or alias called "rpc-auth-6".
Quoted 8 lines
Quoted 4 lines
The GSS module is named "
auth_rpcgss", and commitf344f6dfdoes not add any new module aliases. There is also no such alias provided in/etc/modprobe.don my system (Fedora 16). Without this alias, the GSS module is not loaded on demand.Wait... Why do we want to load the
auth_rpcgssmodule on its own? It doesn't provide any authentication or security mechanisms of its own. All it does is to provide support for the other security mechanisms.
This is a bootstrap. Have a look at the logic in rpcauth_create().
Suppose auth_rpcgss.ko has not been loaded, and some caller wants to create an rpc_auth with pseudoflavor RPC_AUTH_GSS_KRB5.
pseudoflavor_to_flavor() converts RPC_AUTH_GSS_KRB5 to RPC_AUTH_GSS. RPC_AUTH_GSS is used to index the auth_flavors[] array, where the ops pointer is found to be NULL. In that case request_module() is invoked with the argument "rpc-auth-6".
Without the module alias, nothing happens: at line 194, the ops pointer at index "flavor" is still NULL, and rpcauth_create() exits with -EINVAL.
With the module alias, authrpc_gss.ko is loaded. This makes ops->create() for GSS available, which is then invoked with the argument RPC_AUTH_GSS_KRB5. authrpc_gss.ko in turn loads rpcsec_gss_krb5.ko, and the bootstrap is complete.
All of this logic has been in here since Olaf added it, but has lain fallow without the "rpc-auth-6" module alias. We've not hit a problem before, I believe, because distributions have worked around the missing modules by loading them via init scripts.
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
PATCH v3 2/9 NFS: Remove unneeded forward declaration
In reply to Chuck LeverI've built with NFSv4 enabled and disabled. This forward declaration does not seem to be required.
---
include/linux/nfs_xdr.h | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
include/linux/nfs_xdr.h +0 -3
@@ -14,9 +14,6 @@#define NFS_DEF_FILE_IO_SIZE (4096U)#define NFS_MIN_FILE_IO_SIZE (1024U) -/* Forward declaration for NFS v3 */ -struct nfs4_secinfo_flavors ; -struct nfs4_string {unsigned int len;char *data;
PATCH v3 3/9 SUNRPC: Define rpcsec_gss_info structure
In reply to Chuck LeverThe NFSv4 SECINFO procedure returns a list of security flavors. Any GSS flavor also has a GSS tuple containing an OID, a quality-of- protection value, and a service value, which specifies a particular GSS pseudoflavor.
For simplicity and efficiency, I'd like to return each GSS tuple from the NFSv4 SECINFO XDR decoder and pass it straight into the RPC client.
Define a data structure that is visible to both the NFS client and the RPC client.
---
fs/nfs/nfs4namespace.c | 12 ++++++------ fs/nfs/nfs4xdr.c | 20 +++++++++++--------- include/linux/nfs_xdr.h | 21 +++++---------------- include/linux/sunrpc/gss_api.h | 14 ++++++++++++-- net/sunrpc/auth_gss/gss_krb5_mech.c | 2 +- 5 files changed, 35 insertions(+), 34 deletions(-)
fs/nfs/nfs4namespace.c +6 -6
@@ -137,23 +137,23 @@ rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *flavors) {struct gss_api_mech *mech;struct xdr_netobj oid; -int i; +unsigned int i;rpc_authflavor_t pseudoflavor =RPC_AUTH_UNIX ;for (i =0 ; i < flavors->num_flavors; i++) { -struct nfs4_secinfo_flavor *flavor; - flavor = &flavors->flavors[i]; +struct nfs4_secinfo4 *flavor = &flavors->flavors[i];if (flavor->flavor ==RPC_AUTH_NULL || flavor->flavor ==RPC_AUTH_UNIX ) { pseudoflavor = flavor->flavor;break ; }else if (flavor->flavor ==RPC_AUTH_GSS ) { - oid.len = flavor->gss.sec_oid4.len; - oid.data = flavor->gss.sec_oid4.data; + oid.len = flavor->flavor_info.oid.len; + oid.data = flavor->flavor_info.oid.data; mech =gss_mech_get_by_OID (&oid);if (!mech)continue ; - pseudoflavor =gss_svc_to_pseudoflavor (mech, flavor->gss.service); + pseudoflavor =gss_svc_to_pseudoflavor (mech, + flavor->flavor_info.service);gss_mech_put (mech);break ; }
fs/nfs/nfs4xdr.c +11 -9
@@ -5209,27 +5209,29 @@ static int decode_delegreturn(struct xdr_stream *xdr)return decode_op_hdr (xdr,OP_DELEGRETURN ); } -static int decode_secinfo_gss (struct xdr_stream *xdr,struct nfs4_secinfo_flavor *flavor) +static int decode_secinfo_gss (struct xdr_stream *xdr,struct nfs4_secinfo4 *flavor) { +u32 oid_len;__be32 *p; p =xdr_inline_decode (xdr,4 );if (unlikely (!p)) goto out_overflow; - flavor->gss.sec_oid4.len =be32_to_cpup (p); -if (flavor->gss.sec_oid4.len >GSS_OID_MAX_LEN ) + oid_len =be32_to_cpup (p); +if (oid_len >GSS_OID_MAX_LEN ) goto out_err; - p =xdr_inline_decode (xdr, flavor->gss.sec_oid4.len); + p =xdr_inline_decode (xdr, oid_len);if (unlikely (!p)) goto out_overflow; -memcpy (flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); +memcpy (flavor->flavor_info.oid.data, p, oid_len); + flavor->flavor_info.oid.len = oid_len; p =xdr_inline_decode (xdr,8 );if (unlikely (!p)) goto out_overflow; - flavor->gss.qop4 =be32_to_cpup (p++); - flavor->gss.service =be32_to_cpup (p); + flavor->flavor_info.qop =be32_to_cpup (p++); + flavor->flavor_info.service =be32_to_cpup (p);return 0 ;
@@ -5242,10 +5244,10 @@ out_err:static int decode_secinfo_common (struct xdr_stream *xdr,struct nfs4_secinfo_res *res) { -struct nfs4_secinfo_flavor *sec_flavor; +struct nfs4_secinfo4 *sec_flavor; +unsigned int i, num_flavors;int status;__be32 *p; -int i, num_flavors; p =xdr_inline_decode (xdr,4 );if (unlikely (!p))
include/linux/nfs_xdr.h +5 -16
@@ -1046,25 +1046,14 @@ struct nfs4_fs_locations_res {struct nfs4_fs_locations *fs_locations; }; -struct nfs4_secinfo_oid { -unsigned int len; -char data[GSS_OID_MAX_LEN ]; -}; - -struct nfs4_secinfo_gss { -struct nfs4_secinfo_oid sec_oid4; -unsigned int qop4; -unsigned int service; -}; - -struct nfs4_secinfo_flavor { -unsigned int flavor; -struct nfs4_secinfo_gss gss; +struct nfs4_secinfo4 { +u32 flavor; +struct rpcsec_gss_info flavor_info; };struct nfs4_secinfo_flavors { -unsigned int num_flavors; -struct nfs4_secinfo_flavor flavors[0 ]; +unsigned int num_flavors; +struct nfs4_secinfo4 flavors[0 ]; };struct nfs4_secinfo_arg {
include/linux/sunrpc/gss_api.h +12 -2
@@ -25,10 +25,20 @@ struct gss_ctx {#define GSS_C_NO_BUFFER ((struct xdr_netobj) 0)#define GSS_C_NO_CONTEXT ((struct gss_ctx *) 0) -#define GSS_C_NULL_OID ((struct xdr_netobj) 0)/*XXX arbitrary length - is this set somewhere? */ #define GSS_OID_MAX_LEN 32 +struct rpcsec_gss_oid { +unsigned int len; +u8 data[GSS_OID_MAX_LEN ]; +}; + +/* From RFC 3530 */ +struct rpcsec_gss_info { +struct rpcsec_gss_oid oid; +u32 qop; +u32 service; +};/* gss-api prototypes; note that these are somewhat simplified versions of * the prototypes specified in RFC 2744. */
@@ -76,7 +86,7 @@ struct pf_desc {struct gss_api_mech {struct list_head gm_list;struct module *gm_owner; -struct xdr_netobj gm_oid; +struct rpcsec_gss_oid gm_oid;char *gm_name;const struct gss_api_ops *gm_ops;/* pseudoflavors supported by this mechanism: */
net/sunrpc/auth_gss/gss_krb5_mech.c +1 -1
@@ -754,7 +754,7 @@ MODULE_ALIAS("rpc-auth-gss-390005");static struct gss_api_mech gss_kerberos_mech = { .gm_name ="krb5" , .gm_owner =THIS_MODULE , - .gm_oid = {9 , (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" }, + .gm_oid = {9 ,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" }, .gm_ops = &gss_kerberos_ops, .gm_pf_num =ARRAY_SIZE (gss_kerberos_pfs), .gm_pfs = gss_kerberos_pfs,
PATCH v3 4/9 SUNRPC: Introduce rpcauth_get_pseudoflavor()
In reply to Chuck Levernfs_find_best_sec() now verifies all flavors requested in a SECINFO reply against those that have been explicitly registered via rpcauth_register(). For GSS pseudoflavors, these are verified against the list of GSS pseudoflavors registered via gss_mech_register().
Note that the current version of nfs_find_best_sec() can return RPC_AUTH_MAXFLAVOR if the server returns a recognized OID but an unsupported "service" value. The new code returns RPC_AUTH_UNIX in this case.
---
fs/nfs/nfs4namespace.c | 41 +++++++++++++++++++-------------- include/linux/sunrpc/auth.h | 4 +++ include/linux/sunrpc/gss_api.h | 5 ++-- net/sunrpc/auth.c | 34 +++++++++++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 1 + net/sunrpc/auth_gss/gss_mech_switch.c | 28 +++++++++++++++++++---- 6 files changed, 87 insertions(+), 26 deletions(-)
fs/nfs/nfs4namespace.c +23 -18
@@ -133,33 +133,38 @@ static size_t nfs_parse_server_name(char *string, size_t len,return ret; } +/** +* nfs_find_best_sec - Find a security mechanism supported locally +* @flavors: List of security tuples returned by SECINFO procedure +* +* Return the pseudoflavor of the first security mechanism in +* "flavors" that is locally supported. Return RPC_AUTH_UNIX if +* no matching flavor is found in the array. The "flavors" array +* is searched in the order returned from the server, per RFC 3530 +* recommendation. +*/ rpc_authflavor_t nfs_find_best_sec (struct nfs4_secinfo_flavors *flavors) { -struct gss_api_mech *mech; -struct xdr_netobj oid; +rpc_authflavor_t pseudoflavor; +struct nfs4_secinfo4 *secinfo;unsigned int i; -rpc_authflavor_t pseudoflavor =RPC_AUTH_UNIX ;for (i =0 ; i < flavors->num_flavors; i++) { -struct nfs4_secinfo4 *flavor = &flavors->flavors[i]; - -if (flavor->flavor ==RPC_AUTH_NULL || flavor->flavor ==RPC_AUTH_UNIX ) { - pseudoflavor = flavor->flavor; -break ; - }else if (flavor->flavor ==RPC_AUTH_GSS ) { - oid.len = flavor->flavor_info.oid.len; - oid.data = flavor->flavor_info.oid.data; - mech =gss_mech_get_by_OID (&oid); -if (!mech) -continue ; - pseudoflavor =gss_svc_to_pseudoflavor (mech, - flavor->flavor_info.service); -gss_mech_put (mech); + secinfo = &flavors->flavors[i]; + +switch (secinfo->flavor) { +case RPC_AUTH_NULL : +case RPC_AUTH_UNIX : +case RPC_AUTH_GSS : + pseudoflavor =rpcauth_get_pseudoflavor (secinfo->flavor, + &secinfo->flavor_info); +if (pseudoflavor !=RPC_AUTH_MAXFLAVOR ) +return pseudoflavor;break ; } } -return pseudoflavor; +return RPC_AUTH_UNIX ; }static rpc_authflavor_t nfs4_negotiate_security (struct inode *inode,struct qstr *name)
include/linux/sunrpc/auth.h +4 -0
@@ -21,6 +21,8 @@/* size of the nodename buffer */ #define UNX_MAXNODENAME 32 +struct rpcsec_gss_info ; +/* Work around the lack of a VFS credential */ struct auth_cred {uid_t uid;
@@ -102,6 +104,7 @@ struct rpc_authops {int (*pipes_create)(struct rpc_auth *);void (*pipes_destroy)(struct rpc_auth *);int (*list_pseudoflavors)(rpc_authflavor_t *,int ); +rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *); };struct rpc_credops {
@@ -136,6 +139,7 @@ int rpcauth_register(const struct rpc_authops *);int rpcauth_unregister (const struct rpc_authops *);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);void rpcauth_release (struct rpc_auth *); +rpc_authflavor_t rpcauth_get_pseudoflavor (rpc_authflavor_t ,struct rpcsec_gss_info *);int rpcauth_list_flavors (rpc_authflavor_t *,int );struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct auth_cred *,int );void rpcauth_init_cred (struct rpc_cred *,const struct auth_cred *,struct rpc_auth *,const struct rpc_credops *);
include/linux/sunrpc/gss_api.h +2 -3
@@ -127,9 +127,8 @@ struct gss_api_ops {int gss_mech_register (struct gss_api_mech *);void gss_mech_unregister (struct gss_api_mech *); -/* returns a mechanism descriptor given an OID, and increments the mechanism's -* reference count. */ -struct gss_api_mech *gss_mech_get_by_OID (struct xdr_netobj *); +/* Given a GSS security tuple, look up a pseudoflavor */ +rpc_authflavor_t gss_mech_info2flavor (struct rpcsec_gss_info *);/* Returns a reference to a mechanism, given a name like "krb5" etc. */ struct gss_api_mech *gss_mech_get_by_name (const char *);
net/sunrpc/auth.c +34 -0
@@ -124,6 +124,40 @@ rpcauth_unregister(const struct rpc_authops *ops)EXPORT_SYMBOL_GPL (rpcauth_unregister);/** +* rpcauth_get_pseudoflavor - check if security flavor is supported +* @flavor: a security flavor +* @info: a GSS mech OID, quality of protection, and service value +* +* Verifies that an appropriate kernel module is available or already loaded. +* Returns an equivalent pseudoflavor, or RPC_AUTH_MAXFLAVOR if "flavor" is +* not supported locally. +*/ +rpc_authflavor_t +rpcauth_get_pseudoflavor (rpc_authflavor_t flavor,struct rpcsec_gss_info *info) +{ +const struct rpc_authops *ops; +rpc_authflavor_t pseudoflavor; + +if ((ops = auth_flavors[flavor]) ==NULL ) +request_module ("rpc-auth-%u" , flavor); +spin_lock (&rpc_authflavor_lock); + ops = auth_flavors[flavor]; +if (ops ==NULL || !try_module_get (ops->owner)) { +spin_unlock (&rpc_authflavor_lock); +return RPC_AUTH_MAXFLAVOR ; + } +spin_unlock (&rpc_authflavor_lock); + + pseudoflavor = flavor; +if (ops->info2flavor !=NULL ) + pseudoflavor = ops->info2flavor (info); + +module_put (ops->owner); +return pseudoflavor; +} +EXPORT_SYMBOL_GPL (rpcauth_get_pseudoflavor); + +/** * rpcauth_list_flavors - discover registered flavors and pseudoflavors * @array: array to fill in * @size: size of "array"
net/sunrpc/auth_gss/auth_gss.c +1 -0
@@ -1629,6 +1629,7 @@ static const struct rpc_authops authgss_ops = { .pipes_create = gss_pipes_dentries_create, .pipes_destroy = gss_pipes_dentries_destroy, .list_pseudoflavors = gss_mech_list_pseudoflavors, + .info2flavor = gss_mech_info2flavor, };static const struct rpc_credops gss_credops = {
net/sunrpc/auth_gss/gss_mech_switch.c +23 -5
@@ -171,8 +171,7 @@ struct gss_api_mech * gss_mech_get_by_name(const char *name) }EXPORT_SYMBOL_GPL (gss_mech_get_by_name); -struct gss_api_mech * -gss_mech_get_by_OID (struct xdr_netobj *obj) +static struct gss_api_mech *gss_mech_get_by_OID (struct rpcsec_gss_oid *obj) {struct gss_api_mech *pos, *gm =NULL ;
@@ -188,11 +187,8 @@ gss_mech_get_by_OID(struct xdr_netobj *obj) }spin_unlock (®istered_mechs_lock);return gm; - } -EXPORT_SYMBOL_GPL (gss_mech_get_by_OID); -static inline int mech_supports_pseudoflavor (struct gss_api_mech *gm,u32 pseudoflavor) {
@@ -282,6 +278,28 @@ gss_svc_to_pseudoflavor(struct gss_api_mech *gm, u32 service) }EXPORT_SYMBOL_GPL (gss_svc_to_pseudoflavor); +/** +* gss_mech_info2flavor - look up a pseudoflavor given a GSS tuple +* @info: a GSS mech OID, quality of protection, and service value +* +* Returns a matching pseudoflavor, or RPC_AUTH_MAXFLAVOR if the tuple is +* not supported. +*/ +rpc_authflavor_t gss_mech_info2flavor (struct rpcsec_gss_info *info) +{ +rpc_authflavor_t pseudoflavor; +struct gss_api_mech *gm; + + gm =gss_mech_get_by_OID (&info->oid); +if (gm ==NULL ) +return RPC_AUTH_MAXFLAVOR ; + + pseudoflavor =gss_svc_to_pseudoflavor (gm, info->service); + +gss_mech_put (gm); +return pseudoflavor; +} +u32 gss_pseudoflavor_to_service (struct gss_api_mech *gm,u32 pseudoflavor) {
PATCH v3 5/9 SUNRPC: Load GSS kernel module by OID
In reply to Chuck LeverThe current GSS mech switch can find and load GSS pseudoflavor modules by name ("krb5") or pseudoflavor number ("390003"), but cannot find GSS modules by GSS tuple:
[ "1.2.840.113554.1.2.2", GSS_C_QOP_DEFAULT, RPC_GSS_SVC_NONE ]
This is important when dealing with a SECINFO request. A SECINFO reply contains a list of flavors the server supports for the requested export, but GSS flavors also have a GSS tuple that maps to a pseudoflavor (like 390003 for krb5).
If the GSS module that supports the OID in the tuple is not loaded, our client is not able to load that module dynamically to support that pseudoflavor.
Add a way for the GSS mech switch to load GSS pseudoflavor support by OID before searching for the pseudoflavor that matches the OID and service.
---
net/sunrpc/Kconfig | 1 + net/sunrpc/auth_gss/gss_krb5_mech.c | 1 + net/sunrpc/auth_gss/gss_mech_switch.c | 7 +++++++ 3 files changed, 9 insertions(+), 0 deletions(-)
net/sunrpc/Kconfig +1 -0
@@ -3,6 +3,7 @@ config SUNRPC config SUNRPC_GSS tristate + select OID_REGISTRY config SUNRPC_BACKCHANNEL bool
net/sunrpc/auth_gss/gss_krb5_mech.c +1 -0
@@ -750,6 +750,7 @@ MODULE_ALIAS("rpc-auth-gss-krb5p");MODULE_ALIAS ("rpc-auth-gss-390003" );MODULE_ALIAS ("rpc-auth-gss-390004" );MODULE_ALIAS ("rpc-auth-gss-390005" ); +MODULE_ALIAS ("rpc-auth-gss-1.2.840.113554.1.2.2" );static struct gss_api_mech gss_kerberos_mech = { .gm_name ="krb5" ,
net/sunrpc/auth_gss/gss_mech_switch.c +7 -0
@@ -36,6 +36,7 @@#include <linux/types.h> #include <linux/slab.h> #include <linux/module.h> +#include <linux/oid_registry.h> #include <linux/sunrpc/msg_prot.h> #include <linux/sunrpc/gss_asn1.h> #include <linux/sunrpc/auth_gss.h>
@@ -174,6 +175,12 @@ EXPORT_SYMBOL_GPL(gss_mech_get_by_name);static struct gss_api_mech *gss_mech_get_by_OID (struct rpcsec_gss_oid *obj) {struct gss_api_mech *pos, *gm =NULL ; +char buf[32 ]; + +if (sprint_oid (obj->data, obj->len, buf,sizeof (buf)) <0 ) +return NULL ; +dprintk ("RPC: %s(%s)\n" , __func__, buf); +request_module ("rpc-auth-gss-%s" , buf);spin_lock (®istered_mechs_lock);list_for_each_entry (pos, ®istered_mechs, gm_list) {
PATCH v3 6/9 SUNRPC: Consider qop when looking up pseudoflavors
In reply to Chuck LeverThe NFSv4 SECINFO operation returns a list of security flavors that the server supports for a particular share. An NFSv4 client is supposed to pick a pseudoflavor it supports that corresponds to one of the flavors returned by the server.
GSS flavors in this list have a GSS tuple that identify a specific GSS pseudoflavor.
Currently our client ignores the GSS tuple's "qop" value. A matching pseudoflavor is chosen based only on the OID and service value.
So far this omission has not had much effect on Linux. The NFSv4 protocol currently supports only one qop value: zero, or GSS_C_QOP_DEFAULT.
However, if an NFSv4 server happens to return something other than zero in the qop field, our client won't notice. This could cause the client to behave in incorrect ways that could have security implications.
---
include/linux/sunrpc/gss_api.h | 4 +++- net/sunrpc/auth_gss/gss_krb5_mech.c | 3 +++ net/sunrpc/auth_gss/gss_mech_switch.c | 19 +++++++++++++------ net/sunrpc/auth_gss/svcauth_gss.c | 4 +++- 4 files changed, 22 insertions(+), 8 deletions(-)
include/linux/sunrpc/gss_api.h +3 -1
@@ -25,6 +25,7 @@ struct gss_ctx {#define GSS_C_NO_BUFFER ((struct xdr_netobj) 0)#define GSS_C_NO_CONTEXT ((struct gss_ctx *) 0) +#define GSS_C_QOP_DEFAULT (0)/*XXX arbitrary length - is this set somewhere? */ #define GSS_OID_MAX_LEN 32
@@ -68,12 +69,13 @@ u32 gss_unwrap(u32 gss_delete_sec_context (struct gss_ctx **ctx_id); -u32 gss_svc_to_pseudoflavor (struct gss_api_mech *,u32 service); +rpc_authflavor_t gss_svc_to_pseudoflavor (struct gss_api_mech *,u32 qop,u32 service);u32 gss_pseudoflavor_to_service (struct gss_api_mech *,u32 pseudoflavor);char *gss_service_to_auth_domain_name (struct gss_api_mech *,u32 service);struct pf_desc {u32 pseudoflavor; +u32 qop;u32 service;char *name;char *auth_domain_name;
net/sunrpc/auth_gss/gss_krb5_mech.c +3 -0
@@ -729,16 +729,19 @@ static const struct gss_api_ops gss_kerberos_ops = {static struct pf_desc gss_kerberos_pfs[] = { [0 ] = { .pseudoflavor =RPC_AUTH_GSS_KRB5 , + .qop =GSS_C_QOP_DEFAULT , .service =RPC_GSS_SVC_NONE , .name ="krb5" , }, [1 ] = { .pseudoflavor =RPC_AUTH_GSS_KRB5I , + .qop =GSS_C_QOP_DEFAULT , .service =RPC_GSS_SVC_INTEGRITY , .name ="krb5i" , }, [2 ] = { .pseudoflavor =RPC_AUTH_GSS_KRB5P , + .qop =GSS_C_QOP_DEFAULT , .service =RPC_GSS_SVC_PRIVACY , .name ="krb5p" , },
net/sunrpc/auth_gss/gss_mech_switch.c +13 -6
@@ -271,19 +271,26 @@ int gss_mech_list_pseudoflavors(rpc_authflavor_t *array_ptr, int size)return i; } -u32 -gss_svc_to_pseudoflavor (struct gss_api_mech *gm,u32 service) +/** +* gss_svc_to_pseudoflavor - map a GSS service number to a pseudoflavor +* @gm: GSS mechanism handle +* @qop: GSS quality-of-protection value +* @service: GSS service value +* +* Returns a matching security flavor, or RPC_AUTH_MAXFLAVOR if none is found. +*/ +rpc_authflavor_t gss_svc_to_pseudoflavor (struct gss_api_mech *gm,u32 qop,u32 service) {int i;for (i =0 ; i < gm->gm_pf_num; i++) { -if (gm->gm_pfs[i].service == service) { +if (gm->gm_pfs[i].qop == qop && + gm->gm_pfs[i].service == service) {return gm->gm_pfs[i].pseudoflavor; } } -return RPC_AUTH_MAXFLAVOR ;/* illegal value */ +return RPC_AUTH_MAXFLAVOR ; } -EXPORT_SYMBOL_GPL (gss_svc_to_pseudoflavor);/** * gss_mech_info2flavor - look up a pseudoflavor given a GSS tuple
@@ -301,7 +308,7 @@ rpc_authflavor_t gss_mech_info2flavor(struct rpcsec_gss_info *info)if (gm ==NULL )return RPC_AUTH_MAXFLAVOR ; - pseudoflavor =gss_svc_to_pseudoflavor (gm, info->service); + pseudoflavor =gss_svc_to_pseudoflavor (gm, info->qop, info->service);gss_mech_put (gm);return pseudoflavor;
net/sunrpc/auth_gss/svcauth_gss.c +3 -1
@@ -1208,7 +1208,9 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp) svcdata->rsci = rsci;cache_get (&rsci->h); rqstp->rq_cred.cr_flavor =gss_svc_to_pseudoflavor ( - rsci->mechctx->mech_type, gc->gc_svc); + rsci->mechctx->mech_type, +GSS_C_QOP_DEFAULT , + gc->gc_svc); ret =SVC_OK ; goto out; }
PATCH v3 7/9 SUNRPC: Refactor nfsd4_do_encode_secinfo()
In reply to Chuck LeverClean up. This matches a similar API for the client side, and keeps ULP fingers out the of the GSS mech switch.
---
fs/nfsd/nfs4xdr.c | 24 +++++++++++------------ include/linux/sunrpc/auth.h | 2 ++ include/linux/sunrpc/gss_api.h | 3 +++ net/sunrpc/auth.c | 34 +++++++++++++++++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 1 + net/sunrpc/auth_gss/gss_mech_switch.c | 34 +++++++++++++++++++++++++++++++-- 6 files changed, 83 insertions(+), 15 deletions(-)
fs/nfsd/nfs4xdr.c +11 -13
@@ -3127,10 +3127,9 @@ nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_static __be32 nfsd4_do_encode_secinfo (struct nfsd4_compoundres *resp, -__be32 nfserr,struct svc_export *exp) +__be32 nfserr,struct svc_export *exp) { -int i =0 ; -u32 nflavs; +u32 i, nflavs;struct exp_flavor_info *flavs;struct exp_flavor_info def_flavs[2 ];__be32 *p;
@@ -3161,30 +3160,29 @@ nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp,WRITE32 (nflavs);ADJUST_ARGS ();for (i =0 ; i < nflavs; i++) { -u32 flav = flavs[i].pseudoflavor; -struct gss_api_mech *gm =gss_mech_get_by_pseudoflavor (flav); +struct rpcsec_gss_info info; -if (gm) { +if (rpcauth_get_gssinfo (flavs[i].pseudoflavor, &info) ==0 ) {RESERVE_SPACE (4 );WRITE32 (RPC_AUTH_GSS );ADJUST_ARGS (); -RESERVE_SPACE (4 + gm->gm_oid.len); -WRITE32 (gm->gm_oid.len); -WRITEMEM (gm->gm_oid.data, gm->gm_oid.len); +RESERVE_SPACE (4 + info.oid.len); +WRITE32 (info.oid.len); +WRITEMEM (info.oid.data, info.oid.len);ADJUST_ARGS ();RESERVE_SPACE (4 ); -WRITE32 (0 );/* qop */ +WRITE32 (info.qop);ADJUST_ARGS ();RESERVE_SPACE (4 ); -WRITE32 (gss_pseudoflavor_to_service (gm, flav)); +WRITE32 (info.service);ADJUST_ARGS (); -gss_mech_put (gm); }else {RESERVE_SPACE (4 ); -WRITE32 (flav); +WRITE32 (flavs[i].pseudoflavor);ADJUST_ARGS (); } } + out:if (exp)exp_put (exp);
include/linux/sunrpc/auth.h +2 -0
@@ -105,6 +105,7 @@ struct rpc_authops {void (*pipes_destroy)(struct rpc_auth *);int (*list_pseudoflavors)(rpc_authflavor_t *,int );rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *); +int (*flavor2info)(rpc_authflavor_t ,struct rpcsec_gss_info *); };struct rpc_credops {
@@ -140,6 +141,7 @@ int rpcauth_unregister(const struct rpc_authops *);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);void rpcauth_release (struct rpc_auth *);rpc_authflavor_t rpcauth_get_pseudoflavor (rpc_authflavor_t ,struct rpcsec_gss_info *); +int rpcauth_get_gssinfo (rpc_authflavor_t ,struct rpcsec_gss_info *);int rpcauth_list_flavors (rpc_authflavor_t *,int );struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct auth_cred *,int );void rpcauth_init_cred (struct rpc_cred *,const struct auth_cred *,struct rpc_auth *,const struct rpc_credops *);
include/linux/sunrpc/gss_api.h +3 -0
@@ -132,6 +132,9 @@ void gss_mech_unregister(struct gss_api_mech *);/* Given a GSS security tuple, look up a pseudoflavor */ rpc_authflavor_t gss_mech_info2flavor (struct rpcsec_gss_info *); +/* Given a pseudoflavor, look up a GSS security tuple */ +int gss_mech_flavor2info (rpc_authflavor_t ,struct rpcsec_gss_info *); +/* Returns a reference to a mechanism, given a name like "krb5" etc. */ struct gss_api_mech *gss_mech_get_by_name (const char *);
net/sunrpc/auth.c +34 -0
@@ -158,6 +158,40 @@ rpcauth_get_pseudoflavor(rpc_authflavor_t flavor, struct rpcsec_gss_info *info)EXPORT_SYMBOL_GPL (rpcauth_get_pseudoflavor);/** +* rpcauth_get_gssinfo - find GSS tuple matching a GSS pseudoflavor +* @pseudoflavor: GSS pseudoflavor to match +* @info: rpcsec_gss_info structure to fill in +* +* Returns zero and fills in "info" if pseudoflavor matches a +* supported mechanism. +*/ +int +rpcauth_get_gssinfo (rpc_authflavor_t pseudoflavor,struct rpcsec_gss_info *info) +{ +rpc_authflavor_t flavor =pseudoflavor_to_flavor (pseudoflavor); +const struct rpc_authops *ops; +int result; + +if ((ops = auth_flavors[flavor]) ==NULL ) +request_module ("rpc-auth-%u" , flavor); +spin_lock (&rpc_authflavor_lock); + ops = auth_flavors[flavor]; +if (ops ==NULL || !try_module_get (ops->owner)) { +spin_unlock (&rpc_authflavor_lock); +return -ENOENT ; + } +spin_unlock (&rpc_authflavor_lock); + + result = -ENOENT ; +if (ops->flavor2info !=NULL ) + result = ops->flavor2info (pseudoflavor, info); + +module_put (ops->owner); +return result; +} +EXPORT_SYMBOL_GPL (rpcauth_get_gssinfo); + +/** * rpcauth_list_flavors - discover registered flavors and pseudoflavors * @array: array to fill in * @size: size of "array"
net/sunrpc/auth_gss/auth_gss.c +1 -0
@@ -1630,6 +1630,7 @@ static const struct rpc_authops authgss_ops = { .pipes_destroy = gss_pipes_dentries_destroy, .list_pseudoflavors = gss_mech_list_pseudoflavors, .info2flavor = gss_mech_info2flavor, + .flavor2info = gss_mech_flavor2info, };static const struct rpc_credops gss_credops = {
net/sunrpc/auth_gss/gss_mech_switch.c +32 -2
@@ -240,8 +240,6 @@ gss_mech_get_by_pseudoflavor(u32 pseudoflavor)return gm; } -EXPORT_SYMBOL_GPL (gss_mech_get_by_pseudoflavor); -/** * gss_mech_list_pseudoflavors - Discover registered GSS pseudoflavors * @array: array to fill in
@@ -314,6 +312,38 @@ rpc_authflavor_t gss_mech_info2flavor(struct rpcsec_gss_info *info)return pseudoflavor; } +/** +* gss_mech_flavor2info - look up a GSS tuple for a given pseudoflavor +* @pseudoflavor: GSS pseudoflavor to match +* @info: rpcsec_gss_info structure to fill in +* +* Returns zero and fills in "info" if pseudoflavor matches a +* supported mechanism. Otherwise a negative errno is returned. +*/ +int gss_mech_flavor2info (rpc_authflavor_t pseudoflavor,struct rpcsec_gss_info *info) +{ +struct gss_api_mech *gm; +int i; + + gm =gss_mech_get_by_pseudoflavor (pseudoflavor); +if (gm ==NULL ) +return -ENOENT ; + +for (i =0 ; i < gm->gm_pf_num; i++) { +if (gm->gm_pfs[i].pseudoflavor == pseudoflavor) { +memcpy (info->oid.data, gm->gm_oid.data, gm->gm_oid.len); + info->oid.len = gm->gm_oid.len; + info->qop = gm->gm_pfs[i].qop; + info->service = gm->gm_pfs[i].service; +gss_mech_put (gm); +return 0 ; + } + } + +gss_mech_put (gm); +return -ENOENT ; +} +u32 gss_pseudoflavor_to_service (struct gss_api_mech *gm,u32 pseudoflavor) {
PATCH v3 8/9 SUNRPC: Make gss_mech_get() static
In reply to Chuck Levergss_mech_get() is no longer used outside of gss_mech_switch.c.
---
include/linux/sunrpc/gss_api.h | 3 --- net/sunrpc/auth_gss/gss_mech_switch.c | 5 +---- 2 files changed, 1 insertions(+), 7 deletions(-)
include/linux/sunrpc/gss_api.h +0 -3
@@ -144,9 +144,6 @@ struct gss_api_mech *gss_mech_get_by_pseudoflavor(u32);/* Fill in an array with a list of supported pseudoflavors */ int gss_mech_list_pseudoflavors (rpc_authflavor_t *,int ); -/* Just increments the mechanism's reference count and returns its input: */ -struct gss_api_mech *gss_mech_get (struct gss_api_mech *); -/* For every successful gss_mech_get or gss_mech_get_by_* call there must be a * corresponding call to gss_mech_put. */ void gss_mech_put (struct gss_api_mech *);
net/sunrpc/auth_gss/gss_mech_switch.c +1 -4
@@ -132,15 +132,12 @@ gss_mech_unregister(struct gss_api_mech *gm)EXPORT_SYMBOL_GPL (gss_mech_unregister); -struct gss_api_mech * -gss_mech_get (struct gss_api_mech *gm) +static struct gss_api_mech *gss_mech_get (struct gss_api_mech *gm) {__module_get (gm->gm_owner);return gm; } -EXPORT_SYMBOL_GPL (gss_mech_get); -struct gss_api_mech *_gss_mech_get_by_name (const char *name) {
PATCH v3 9/9 SUNRPC: Remove EXPORT_SYMBOL_GPL() from GSS mech switch
In reply to Chuck LeverClean up: Reduce the symbol table footprint for auth_rpcgss.ko by removing exported symbols for functions that are not used outside of auth_rpcgss.
The remaining two EXPORTs in gss_mech_switch.c get documenting comments.
---
net/sunrpc/auth_gss/gss_mech_switch.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
net/sunrpc/auth_gss/gss_mech_switch.c +13 -13
@@ -103,8 +103,13 @@ out:return status; } -int -gss_mech_register (struct gss_api_mech *gm) +/** +* gss_mech_register - register a GSS mechanism +* @gm: GSS mechanism handle +* +* Returns zero if successful, or a negative errno. +*/ +int gss_mech_register (struct gss_api_mech *gm) {int status;
@@ -117,11 +122,14 @@ gss_mech_register(struct gss_api_mech *gm)dprintk ("RPC: registered gss mechanism %s\n" , gm->gm_name);return 0 ; } -EXPORT_SYMBOL_GPL (gss_mech_register); -void -gss_mech_unregister (struct gss_api_mech *gm) +/** +* gss_mech_unregister - release a GSS mechanism +* @gm: GSS mechanism handle +* +*/ +void gss_mech_unregister (struct gss_api_mech *gm) {spin_lock (®istered_mechs_lock);list_del (&gm->gm_list);
@@ -129,7 +137,6 @@ gss_mech_unregister(struct gss_api_mech *gm)dprintk ("RPC: unregistered gss mechanism %s\n" , gm->gm_name);gss_mech_free (gm); } -EXPORT_SYMBOL_GPL (gss_mech_unregister);static struct gss_api_mech *gss_mech_get (struct gss_api_mech *gm)
@@ -167,7 +174,6 @@ struct gss_api_mech * gss_mech_get_by_name(const char *name) }return gm; } -EXPORT_SYMBOL_GPL (gss_mech_get_by_name);static struct gss_api_mech *gss_mech_get_by_OID (struct rpcsec_gss_oid *obj) {
@@ -353,8 +359,6 @@ gss_pseudoflavor_to_service(struct gss_api_mech *gm, u32 pseudoflavor)return 0 ; } -EXPORT_SYMBOL_GPL (gss_pseudoflavor_to_service); -char *gss_service_to_auth_domain_name (struct gss_api_mech *gm,u32 service) {
@@ -367,8 +371,6 @@ gss_service_to_auth_domain_name(struct gss_api_mech *gm, u32 service)return NULL ; } -EXPORT_SYMBOL_GPL (gss_service_to_auth_domain_name); -void gss_mech_put (struct gss_api_mech * gm) {
@@ -376,8 +378,6 @@ gss_mech_put(struct gss_api_mech * gm)module_put (gm->gm_owner); } -EXPORT_SYMBOL_GPL (gss_mech_put); -/* The mech could probably be determined from the token instead, but it's just * as easy for now to pass it in. */ int