49
49
#include <linux/sunrpc/svcauth.h>
50
50
#include <linux/sunrpc/svcauth_gss.h>
51
51
#include <linux/sunrpc/cache.h>
52
+ #include <linux/sunrpc/gss_krb5.h>
52
53
53
54
#include <trace/events/rpcgss.h>
54
55
55
56
#include "gss_rpc_upcall.h"
56
57
58
+ /*
59
+ * Unfortunately there isn't a maximum checksum size exported via the
60
+ * GSS API. Manufacture one based on GSS mechanisms supported by this
61
+ * implementation.
62
+ */
63
+ #define GSS_MAX_CKSUMSIZE (GSS_KRB5_TOK_HDR_LEN + GSS_KRB5_MAX_CKSUM_LEN)
64
+
65
+ /*
66
+ * This value may be increased in the future to accommodate other
67
+ * usage of the scratch buffer.
68
+ */
69
+ #define GSS_SCRATCH_SIZE GSS_MAX_CKSUMSIZE
70
+
71
+ struct gss_svc_data {
72
+ /* decoded gss client cred: */
73
+ struct rpc_gss_wire_cred clcred ;
74
+ /* save a pointer to the beginning of the encoded verifier,
75
+ * for use in encryption/checksumming in svcauth_gss_release: */
76
+ __be32 * verf_start ;
77
+ struct rsc * rsci ;
78
+
79
+ /* for temporary results */
80
+ u8 gsd_scratch [GSS_SCRATCH_SIZE ];
81
+ };
57
82
58
83
/* The rpcsec_init cache is used for mapping RPCSEC_GSS_{,CONT_}INIT requests
59
84
* into replies.
@@ -887,13 +912,11 @@ read_u32_from_xdr_buf(struct xdr_buf *buf, int base, u32 *obj)
887
912
static int
888
913
unwrap_integ_data (struct svc_rqst * rqstp , struct xdr_buf * buf , u32 seq , struct gss_ctx * ctx )
889
914
{
915
+ struct gss_svc_data * gsd = rqstp -> rq_auth_data ;
890
916
u32 integ_len , rseqno , maj_stat ;
891
- int stat = - EINVAL ;
892
917
struct xdr_netobj mic ;
893
918
struct xdr_buf integ_buf ;
894
919
895
- mic .data = NULL ;
896
-
897
920
/* NFS READ normally uses splice to send data in-place. However
898
921
* the data in cache can change after the reply's MIC is computed
899
922
* but before the RPC reply is sent. To prevent the client from
@@ -917,11 +940,9 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g
917
940
/* copy out mic... */
918
941
if (read_u32_from_xdr_buf (buf , integ_len , & mic .len ))
919
942
goto unwrap_failed ;
920
- if (mic .len > RPC_MAX_AUTH_SIZE )
921
- goto unwrap_failed ;
922
- mic .data = kmalloc (mic .len , GFP_KERNEL );
923
- if (!mic .data )
943
+ if (mic .len > sizeof (gsd -> gsd_scratch ))
924
944
goto unwrap_failed ;
945
+ mic .data = gsd -> gsd_scratch ;
925
946
if (read_bytes_from_xdr_buf (buf , integ_len + 4 , mic .data , mic .len ))
926
947
goto unwrap_failed ;
927
948
maj_stat = gss_verify_mic (ctx , & integ_buf , & mic );
@@ -932,20 +953,17 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g
932
953
goto bad_seqno ;
933
954
/* trim off the mic and padding at the end before returning */
934
955
xdr_buf_trim (buf , round_up_to_quad (mic .len ) + 4 );
935
- stat = 0 ;
936
- out :
937
- kfree (mic .data );
938
- return stat ;
956
+ return 0 ;
939
957
940
958
unwrap_failed :
941
959
trace_rpcgss_svc_unwrap_failed (rqstp );
942
- goto out ;
960
+ return - EINVAL ;
943
961
bad_seqno :
944
962
trace_rpcgss_svc_seqno_bad (rqstp , seq , rseqno );
945
- goto out ;
963
+ return - EINVAL ;
946
964
bad_mic :
947
965
trace_rpcgss_svc_mic (rqstp , maj_stat );
948
- goto out ;
966
+ return - EINVAL ;
949
967
}
950
968
951
969
static inline int
@@ -1023,15 +1041,6 @@ unwrap_priv_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct gs
1023
1041
return - EINVAL ;
1024
1042
}
1025
1043
1026
- struct gss_svc_data {
1027
- /* decoded gss client cred: */
1028
- struct rpc_gss_wire_cred clcred ;
1029
- /* save a pointer to the beginning of the encoded verifier,
1030
- * for use in encryption/checksumming in svcauth_gss_release: */
1031
- __be32 * verf_start ;
1032
- struct rsc * rsci ;
1033
- };
1034
-
1035
1044
static int
1036
1045
svcauth_gss_set_client (struct svc_rqst * rqstp )
1037
1046
{
0 commit comments