Secure user authentication for NFS using RPCSEC_GSS [4/6]
Subsystems (4)
PATCH 1/1 Secure user authentication for NFS using RPCSEC_GSS [4/6]
This patch provides the basic framework for RPCSEC_GSS authentication in the RPC client. The protocol is fully described in RFC-2203. Sun has supported it in their commercial NFSv3 and v2 implementations for quite some time, and it has been specified in RFC3010 as being mandatory for NFSv4.
- Update the mount_data struct for NFSv2 and v3 in order to allow them to pass an RPCSEC_GSS security flavour. Compatibility with existing versions of the 'mount' program is ensured by requiring that RPCSEC support be enabled using the new flag NFS_MOUNT_SECFLAVOUR.
- Provide secure authentication, and later data encryption on a per-user basis. A later patch will an provide an implementation of the Kerberos 5 security mechanism. SPKM and LIPKEY are still being planned.
- Security context negotiation and initialization are all assumed to be done in userland. A later patch will provide the actual upcall mechanisms to allow for this.
fs/Kconfig +11 -0
@@ -1339,6 +1339,17 @@ default m if NFS_FS!=y && NFSD!=y && (NFS_FS=m || NFSD=m) default y if NFS_FS=y || NFSD=y +config SUNRPC_GSS + tristate "Provide RPCSEC_GSS authentication (EXPERIMENTAL)" + depends on SUNRPC && EXPERIMENTAL + default SUNRPC if NFS_V4=y + help + Provides cryptographic authentication for NFS rpc requests. To + make this useful, you also need support for a gss-api mechanism + (such as Kerberos). + Note: You should always select this option if you wish to use + NFSv4. + config LOCKD tristate default m if NFS_FS!=y && NFSD!=y && (NFS_FS=m || NFSD=m)
fs/nfs/inode.c +8 -1
@@ -346,6 +346,7 @@struct rpc_clnt *clnt =NULL ;struct rpc_timeout timeparms;int tcp, err = -EIO ; +u32 authflavor; server =NFS_SB (sb); sb->s_blocksize_bits =0 ;
@@ -408,8 +409,14 @@printk (KERN_WARNING "NFS: cannot create RPC transport.\n" ); goto out_fail; } + +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + authflavor = data->pseudoflavor; +else + authflavor =RPC_AUTH_UNIX ; + clnt =rpc_create_client (xprt, server->hostname, &nfs_program, - server->rpc_ops->version,RPC_AUTH_UNIX ); + server->rpc_ops->version, authflavor);if (clnt ==NULL ) {printk (KERN_WARNING "NFS: cannot create RPC client.\n" );xprt_destroy (xprt);
include/linux/nfs_mount.h +1 -2
@@ -40,6 +40,7 @@int namlen;/* 2 */ unsigned int bsize;/* 3 */ struct nfs3_fh root;/* 4 */ +int pseudoflavor;/* 4 */ };/* bits in the flags field */
@@ -55,10 +56,8 @@#define NFS_MOUNT_KERBEROS 0x0100/* 3 */ #define NFS_MOUNT_NONLM 0x0200/* 3 */ #define NFS_MOUNT_BROKEN_SUID 0x0400/* 4 */ -#if 0 #define NFS_MOUNT_STRICTLOCK 0x1000/* reserved for NFSv4 */ #define NFS_MOUNT_SECFLAVOUR 0x2000/* reserved */ -#endif #define NFS_MOUNT_FLAGMASK 0xFFFF#endif
include/linux/sunrpc/auth_gss.h +97 -0
97 lines not on this page · raw message
include/linux/sunrpc/auth.h +13 -2
@@ -13,12 +13,17 @@#include <linux/config.h> #include <linux/sunrpc/sched.h> +#include <linux/sunrpc/msg_prot.h> +#include <linux/sunrpc/xdr.h> #include <asm/atomic.h> /* size of the nodename buffer */ #define UNX_MAXNODENAME 32 +/* Maximum size (in bytes) of an rpc credential or verifier */ +#define RPC_MAX_AUTH_SIZE (400) +/* Work around the lack of a VFS credential */ struct auth_cred {uid_t uid;
@@ -64,6 +69,10 @@unsigned int au_rslack;/* reply verf size guess */ unsigned int au_flags;/* various flags */ struct rpc_authops * au_ops;/* operations */ +rpc_authflavor_t au_flavor;/* pseudoflavor (note may +* differ from the flavor in +* au_ops->au_flavor in gss +* case) */ /* per-flavor data */ };
@@ -79,10 +88,10 @@#ifdef RPC_DEBUG char * au_name;#endif -struct rpc_auth * (*create)(struct rpc_clnt *); +struct rpc_auth * (*create)(struct rpc_clnt *,rpc_authflavor_t );void (*destroy)(struct rpc_auth *); -struct rpc_cred * (*crcreate)(struct auth_cred *,int ); +struct rpc_cred * (*crcreate)(struct rpc_auth *,struct auth_cred *,int ); };struct rpc_credops {
@@ -100,6 +109,8 @@extern struct rpc_authops authdes_ops;#endif +u32 pseudoflavor_to_flavor (rpc_authflavor_t ); +int rpcauth_register (struct rpc_authops *);int rpcauth_unregister (struct rpc_authops *);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);
include/linux/sunrpc/gss_api.h +132 -0
132 lines not on this page · raw message
include/linux/sunrpc/gss_asn1.h +85 -0
85 lines not on this page · raw message
include/linux/sunrpc/gss_err.h +177 -0
177 lines not on this page · raw message
include/linux/sunrpc/msg_prot.h +15 -1
@@ -20,7 +20,18 @@RPC_AUTH_SHORT =2 ,RPC_AUTH_DES =3 ,RPC_AUTH_KRB =4 , +RPC_AUTH_GSS =6 ,RPC_AUTH_MAXFLAVOR =8 , +/* pseudoflavors: */ +RPC_AUTH_GSS_KRB5 =390003 , +RPC_AUTH_GSS_KRB5I =390004 , +RPC_AUTH_GSS_KRB5P =390005 , +RPC_AUTH_GSS_LKEY =390006 , +RPC_AUTH_GSS_LKEYI =390007 , +RPC_AUTH_GSS_LKEYP =390008 , +RPC_AUTH_GSS_SPKM =390009 , +RPC_AUTH_GSS_SPKMI =390010 , + RPC_AUTH_GSS_SPKMP = 390011, }; enum rpc_msg_type {
@@ -53,7 +64,10 @@RPC_AUTH_REJECTEDCRED =2 ,RPC_AUTH_BADVERF =3 ,RPC_AUTH_REJECTEDVERF =4 , - RPC_AUTH_TOOWEAK = 5 +RPC_AUTH_TOOWEAK =5 , +/* RPCSEC_GSS errors */ +RPCSEC_GSS_CREDPROBLEM =13 , + RPCSEC_GSS_CTXPROBLEM = 14 };#define RPC_PMAP_PROGRAM 100000
include/linux/sunrpc/sched.h +3 -0
@@ -12,6 +12,7 @@#include <linux/timer.h> #include <linux/sunrpc/types.h> #include <linux/wait.h> +#include <linux/sunrpc/xdr.h> /* * This is the actual RPC procedure call info.
@@ -47,6 +48,8 @@__u8 tk_garb_retry, tk_cred_retry, tk_suid_retry; +u32 tk_gss_seqno;/* rpcsec_gss sequence number +used on this request */ /* * timeout_fn to be executed by timer bottom half
include/linux/sunrpc/xdr.h +3 -1
@@ -80,7 +80,9 @@#define rpc_autherr_badverf __constant_htonl(RPC_AUTH_BADVERF)#define rpc_autherr_rejectedverf __constant_htonl(RPC_AUTH_REJECTEDVERF)#define rpc_autherr_tooweak __constant_htonl(RPC_AUTH_TOOWEAK) - +#define rpcsec_gsserr_credproblem __constant_htonl(RPCSEC_GSS_CREDPROBLEM) +#define rpcsec_gsserr_ctxproblem __constant_htonl(RPCSEC_GSS_CTXPROBLEM) +#define rpc_autherr_oldseqnum __constant_htonl(101)/* * Miscellaneous XDR helper functions
net/sunrpc/auth.c +11 -3
@@ -24,6 +24,13 @@ NULL, /* others can be loadable modules */ }; +u32 +pseudoflavor_to_flavor (u32 flavor) { +if (flavor >=RPC_AUTH_MAXFLAVOR ) +return RPC_AUTH_GSS ; +return flavor; +} +int rpcauth_register (struct rpc_authops *ops) {
@@ -51,13 +58,14 @@ }struct rpc_auth * -rpcauth_create (rpc_authflavor_t flavor,struct rpc_clnt *clnt) +rpcauth_create (rpc_authflavor_t pseudoflavor,struct rpc_clnt *clnt) {struct rpc_authops *ops; +u32 flavor =pseudoflavor_to_flavor (pseudoflavor);if (flavor >=RPC_AUTH_MAXFLAVOR || !(ops = auth_flavors[flavor]))return NULL ; - clnt->cl_auth = ops->create (clnt); + clnt->cl_auth = ops->create (clnt, pseudoflavor);return clnt->cl_auth; }
@@ -218,7 +226,7 @@rpcauth_destroy_credlist (&free);if (!cred) { - new = auth->au_ops->crcreate (acred, taskflags); + new = auth->au_ops->crcreate (auth, acred, taskflags);if (new) {#ifdef RPC_DEBUG new->cr_magic =RPCAUTH_CRED_MAGIC ;
net/sunrpc/auth_gss/auth_gss.c +378 -0
378 lines not on this page · raw message
net/sunrpc/auth_gss/gss_generic_token.c +269 -0
269 lines not on this page · raw message
net/sunrpc/auth_gss/gss_mech_switch.c +243 -0
243 lines not on this page · raw message
net/sunrpc/auth_gss/gss_pseudoflavors.c +235 -0
235 lines not on this page · raw message
net/sunrpc/auth_gss/Makefile +11 -0
@@ -0,0 +1,11 @@ +# +# Makefile for Linux kernel rpcsec_gss implementation +# + +obj-$(CONFIG_SUNRPC_GSS) += auth_rpcgss.o + +export-objs := sunrpcgss_syms.o + +auth_rpcgss-objs := auth_gss.o gss_pseudoflavors.o gss_generic_token.o \ + sunrpcgss_syms.o gss_mech_switch.o +
net/sunrpc/auth_gss/sunrpcgss_syms.c +34 -0
@@ -0,0 +1,34 @@ +#define __NO_VERSION__ +#include <linux/config.h> +#include <linux/module.h> + +#include <linux/types.h> +#include <linux/socket.h> +#include <linux/sched.h> +#include <linux/uio.h> +#include <linux/unistd.h> + +#include <linux/sunrpc/auth_gss.h> +#include <linux/sunrpc/gss_asn1.h> + +/* sec_triples: */ +EXPORT_SYMBOL (gss_register_triple); +EXPORT_SYMBOL (gss_unregister_triple); +EXPORT_SYMBOL (gss_cmp_triples); +EXPORT_SYMBOL (gss_pseudoflavor_to_mechOID); +EXPORT_SYMBOL (gss_pseudoflavor_supported); +EXPORT_SYMBOL (gss_pseudoflavor_to_service); + +/* registering gss mechanisms to the mech switching code: */ +EXPORT_SYMBOL (gss_mech_register); +EXPORT_SYMBOL (gss_mech_get); +EXPORT_SYMBOL (gss_mech_get_by_OID); +EXPORT_SYMBOL (gss_mech_put); + +/* generic functionality in gss code: */ +EXPORT_SYMBOL (g_make_token_header); +EXPORT_SYMBOL (g_verify_token_header); +EXPORT_SYMBOL (g_token_size); + +/* debug */ +EXPORT_SYMBOL (print_hexl);
net/sunrpc/auth_null.c +2 -2
@@ -20,7 +20,7 @@static struct rpc_credops null_credops;static struct rpc_auth * -nul_create (struct rpc_clnt *clnt) +nul_create (struct rpc_clnt *clnt,rpc_authflavor_t flavor) {struct rpc_auth *auth;
@@ -48,7 +48,7 @@* Create NULL creds for current process */ static struct rpc_cred * -nul_create_cred (struct auth_cred *acred,int flags) +nul_create_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) {struct rpc_cred *cred;
net/sunrpc/auth_unix.c +3 -3
@@ -38,7 +38,7 @@static struct rpc_credops unix_credops;static struct rpc_auth * -unx_create (struct rpc_clnt *clnt) +unx_create (struct rpc_clnt *clnt,rpc_authflavor_t flavor) {struct rpc_auth *auth;
@@ -64,7 +64,7 @@ }static struct rpc_cred * -unx_create_cred (struct auth_cred *acred,int flags) +unx_create_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) {struct unx_cred *cred;int i;
@@ -208,7 +208,7 @@ } size =ntohl (*p++); -if (size >400 ) { +if (size >RPC_MAX_AUTH_SIZE ) {printk ("RPC: giant verf size: %u\n" , size);return NULL ; }
net/sunrpc/clnt.c +1 -1
@@ -35,7 +35,7 @@#include <linux/nfs.h> -#define RPC_SLACK_SPACE 512/* total overkill */ +#define RPC_SLACK_SPACE (1024)/* total overkill */ #ifdef RPC_DEBUG # define RPCDBG_FACILITY RPCDBG_CALL
net/sunrpc/Makefile +2 -0
@@ -2,6 +2,8 @@ # Makefile for Linux kernel SUN RPC # +obj-$(CONFIG_SUNRPC_GSS) += auth_gss/ + obj-$(CONFIG_SUNRPC) += sunrpc.o export-objs := sunrpc_syms.o
net/sunrpc/sunrpc_syms.c +2 -0
@@ -68,6 +68,8 @@EXPORT_SYMBOL (rpcauth_register);EXPORT_SYMBOL (rpcauth_unregister);EXPORT_SYMBOL (rpcauth_lookupcred); +EXPORT_SYMBOL (rpcauth_free_credcache); +EXPORT_SYMBOL (rpcauth_init_credcache);EXPORT_SYMBOL (put_rpccred);/* RPC server stuff */