auth_gss.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. /*
  2. * linux/net/sunrpc/auth_gss/auth_gss.c
  3. *
  4. * RPCSEC_GSS client authentication.
  5. *
  6. * Copyright (c) 2000 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Dug Song <dugsong@monkey.org>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/module.h>
  38. #include <linux/init.h>
  39. #include <linux/types.h>
  40. #include <linux/slab.h>
  41. #include <linux/sched.h>
  42. #include <linux/pagemap.h>
  43. #include <linux/sunrpc/clnt.h>
  44. #include <linux/sunrpc/auth.h>
  45. #include <linux/sunrpc/auth_gss.h>
  46. #include <linux/sunrpc/svcauth_gss.h>
  47. #include <linux/sunrpc/gss_err.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/sunrpc/rpc_pipe_fs.h>
  50. #include <linux/sunrpc/gss_api.h>
  51. #include <asm/uaccess.h>
  52. static const struct rpc_authops authgss_ops;
  53. static const struct rpc_credops gss_credops;
  54. static const struct rpc_credops gss_nullops;
  55. #define GSS_RETRY_EXPIRED 5
  56. static unsigned int gss_expired_cred_retry_delay = GSS_RETRY_EXPIRED;
  57. #ifdef RPC_DEBUG
  58. # define RPCDBG_FACILITY RPCDBG_AUTH
  59. #endif
  60. #define GSS_CRED_SLACK (RPC_MAX_AUTH_SIZE * 2)
  61. /* length of a krb5 verifier (48), plus data added before arguments when
  62. * using integrity (two 4-byte integers): */
  63. #define GSS_VERF_SLACK 100
  64. struct gss_auth {
  65. struct kref kref;
  66. struct rpc_auth rpc_auth;
  67. struct gss_api_mech *mech;
  68. enum rpc_gss_svc service;
  69. struct rpc_clnt *client;
  70. /*
  71. * There are two upcall pipes; dentry[1], named "gssd", is used
  72. * for the new text-based upcall; dentry[0] is named after the
  73. * mechanism (for example, "krb5") and exists for
  74. * backwards-compatibility with older gssd's.
  75. */
  76. struct rpc_pipe *pipe[2];
  77. };
  78. /* pipe_version >= 0 if and only if someone has a pipe open. */
  79. static int pipe_version = -1;
  80. static atomic_t pipe_users = ATOMIC_INIT(0);
  81. static DEFINE_SPINLOCK(pipe_version_lock);
  82. static struct rpc_wait_queue pipe_version_rpc_waitqueue;
  83. static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue);
  84. static void gss_free_ctx(struct gss_cl_ctx *);
  85. static const struct rpc_pipe_ops gss_upcall_ops_v0;
  86. static const struct rpc_pipe_ops gss_upcall_ops_v1;
  87. static inline struct gss_cl_ctx *
  88. gss_get_ctx(struct gss_cl_ctx *ctx)
  89. {
  90. atomic_inc(&ctx->count);
  91. return ctx;
  92. }
  93. static inline void
  94. gss_put_ctx(struct gss_cl_ctx *ctx)
  95. {
  96. if (atomic_dec_and_test(&ctx->count))
  97. gss_free_ctx(ctx);
  98. }
  99. /* gss_cred_set_ctx:
  100. * called by gss_upcall_callback and gss_create_upcall in order
  101. * to set the gss context. The actual exchange of an old context
  102. * and a new one is protected by the pipe->lock.
  103. */
  104. static void
  105. gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
  106. {
  107. struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
  108. if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags))
  109. return;
  110. gss_get_ctx(ctx);
  111. rcu_assign_pointer(gss_cred->gc_ctx, ctx);
  112. set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  113. smp_mb__before_clear_bit();
  114. clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags);
  115. }
  116. static const void *
  117. simple_get_bytes(const void *p, const void *end, void *res, size_t len)
  118. {
  119. const void *q = (const void *)((const char *)p + len);
  120. if (unlikely(q > end || q < p))
  121. return ERR_PTR(-EFAULT);
  122. memcpy(res, p, len);
  123. return q;
  124. }
  125. static inline const void *
  126. simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest)
  127. {
  128. const void *q;
  129. unsigned int len;
  130. p = simple_get_bytes(p, end, &len, sizeof(len));
  131. if (IS_ERR(p))
  132. return p;
  133. q = (const void *)((const char *)p + len);
  134. if (unlikely(q > end || q < p))
  135. return ERR_PTR(-EFAULT);
  136. dest->data = kmemdup(p, len, GFP_NOFS);
  137. if (unlikely(dest->data == NULL))
  138. return ERR_PTR(-ENOMEM);
  139. dest->len = len;
  140. return q;
  141. }
  142. static struct gss_cl_ctx *
  143. gss_cred_get_ctx(struct rpc_cred *cred)
  144. {
  145. struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
  146. struct gss_cl_ctx *ctx = NULL;
  147. rcu_read_lock();
  148. if (gss_cred->gc_ctx)
  149. ctx = gss_get_ctx(gss_cred->gc_ctx);
  150. rcu_read_unlock();
  151. return ctx;
  152. }
  153. static struct gss_cl_ctx *
  154. gss_alloc_context(void)
  155. {
  156. struct gss_cl_ctx *ctx;
  157. ctx = kzalloc(sizeof(*ctx), GFP_NOFS);
  158. if (ctx != NULL) {
  159. ctx->gc_proc = RPC_GSS_PROC_DATA;
  160. ctx->gc_seq = 1; /* NetApp 6.4R1 doesn't accept seq. no. 0 */
  161. spin_lock_init(&ctx->gc_seq_lock);
  162. atomic_set(&ctx->count,1);
  163. }
  164. return ctx;
  165. }
  166. #define GSSD_MIN_TIMEOUT (60 * 60)
  167. static const void *
  168. gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct gss_api_mech *gm)
  169. {
  170. const void *q;
  171. unsigned int seclen;
  172. unsigned int timeout;
  173. unsigned long now = jiffies;
  174. u32 window_size;
  175. int ret;
  176. /* First unsigned int gives the remaining lifetime in seconds of the
  177. * credential - e.g. the remaining TGT lifetime for Kerberos or
  178. * the -t value passed to GSSD.
  179. */
  180. p = simple_get_bytes(p, end, &timeout, sizeof(timeout));
  181. if (IS_ERR(p))
  182. goto err;
  183. if (timeout == 0)
  184. timeout = GSSD_MIN_TIMEOUT;
  185. ctx->gc_expiry = now + ((unsigned long)timeout * HZ);
  186. /* Sequence number window. Determines the maximum number of
  187. * simultaneous requests
  188. */
  189. p = simple_get_bytes(p, end, &window_size, sizeof(window_size));
  190. if (IS_ERR(p))
  191. goto err;
  192. ctx->gc_win = window_size;
  193. /* gssd signals an error by passing ctx->gc_win = 0: */
  194. if (ctx->gc_win == 0) {
  195. /*
  196. * in which case, p points to an error code. Anything other
  197. * than -EKEYEXPIRED gets converted to -EACCES.
  198. */
  199. p = simple_get_bytes(p, end, &ret, sizeof(ret));
  200. if (!IS_ERR(p))
  201. p = (ret == -EKEYEXPIRED) ? ERR_PTR(-EKEYEXPIRED) :
  202. ERR_PTR(-EACCES);
  203. goto err;
  204. }
  205. /* copy the opaque wire context */
  206. p = simple_get_netobj(p, end, &ctx->gc_wire_ctx);
  207. if (IS_ERR(p))
  208. goto err;
  209. /* import the opaque security context */
  210. p = simple_get_bytes(p, end, &seclen, sizeof(seclen));
  211. if (IS_ERR(p))
  212. goto err;
  213. q = (const void *)((const char *)p + seclen);
  214. if (unlikely(q > end || q < p)) {
  215. p = ERR_PTR(-EFAULT);
  216. goto err;
  217. }
  218. ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx, GFP_NOFS);
  219. if (ret < 0) {
  220. p = ERR_PTR(ret);
  221. goto err;
  222. }
  223. dprintk("RPC: %s Success. gc_expiry %lu now %lu timeout %u\n",
  224. __func__, ctx->gc_expiry, now, timeout);
  225. return q;
  226. err:
  227. dprintk("RPC: %s returns %ld gc_expiry %lu now %lu timeout %u\n",
  228. __func__, -PTR_ERR(p), ctx->gc_expiry, now, timeout);
  229. return p;
  230. }
  231. #define UPCALL_BUF_LEN 128
  232. struct gss_upcall_msg {
  233. atomic_t count;
  234. uid_t uid;
  235. struct rpc_pipe_msg msg;
  236. struct list_head list;
  237. struct gss_auth *auth;
  238. struct rpc_pipe *pipe;
  239. struct rpc_wait_queue rpc_waitqueue;
  240. wait_queue_head_t waitqueue;
  241. struct gss_cl_ctx *ctx;
  242. char databuf[UPCALL_BUF_LEN];
  243. };
  244. static int get_pipe_version(void)
  245. {
  246. int ret;
  247. spin_lock(&pipe_version_lock);
  248. if (pipe_version >= 0) {
  249. atomic_inc(&pipe_users);
  250. ret = pipe_version;
  251. } else
  252. ret = -EAGAIN;
  253. spin_unlock(&pipe_version_lock);
  254. return ret;
  255. }
  256. static void put_pipe_version(void)
  257. {
  258. if (atomic_dec_and_lock(&pipe_users, &pipe_version_lock)) {
  259. pipe_version = -1;
  260. spin_unlock(&pipe_version_lock);
  261. }
  262. }
  263. static void
  264. gss_release_msg(struct gss_upcall_msg *gss_msg)
  265. {
  266. if (!atomic_dec_and_test(&gss_msg->count))
  267. return;
  268. put_pipe_version();
  269. BUG_ON(!list_empty(&gss_msg->list));
  270. if (gss_msg->ctx != NULL)
  271. gss_put_ctx(gss_msg->ctx);
  272. rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue);
  273. kfree(gss_msg);
  274. }
  275. static struct gss_upcall_msg *
  276. __gss_find_upcall(struct rpc_pipe *pipe, uid_t uid)
  277. {
  278. struct gss_upcall_msg *pos;
  279. list_for_each_entry(pos, &pipe->in_downcall, list) {
  280. if (pos->uid != uid)
  281. continue;
  282. atomic_inc(&pos->count);
  283. dprintk("RPC: %s found msg %p\n", __func__, pos);
  284. return pos;
  285. }
  286. dprintk("RPC: %s found nothing\n", __func__);
  287. return NULL;
  288. }
  289. /* Try to add an upcall to the pipefs queue.
  290. * If an upcall owned by our uid already exists, then we return a reference
  291. * to that upcall instead of adding the new upcall.
  292. */
  293. static inline struct gss_upcall_msg *
  294. gss_add_msg(struct gss_upcall_msg *gss_msg)
  295. {
  296. struct rpc_pipe *pipe = gss_msg->pipe;
  297. struct gss_upcall_msg *old;
  298. spin_lock(&pipe->lock);
  299. old = __gss_find_upcall(pipe, gss_msg->uid);
  300. if (old == NULL) {
  301. atomic_inc(&gss_msg->count);
  302. list_add(&gss_msg->list, &pipe->in_downcall);
  303. } else
  304. gss_msg = old;
  305. spin_unlock(&pipe->lock);
  306. return gss_msg;
  307. }
  308. static void
  309. __gss_unhash_msg(struct gss_upcall_msg *gss_msg)
  310. {
  311. list_del_init(&gss_msg->list);
  312. rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno);
  313. wake_up_all(&gss_msg->waitqueue);
  314. atomic_dec(&gss_msg->count);
  315. }
  316. static void
  317. gss_unhash_msg(struct gss_upcall_msg *gss_msg)
  318. {
  319. struct rpc_pipe *pipe = gss_msg->pipe;
  320. if (list_empty(&gss_msg->list))
  321. return;
  322. spin_lock(&pipe->lock);
  323. if (!list_empty(&gss_msg->list))
  324. __gss_unhash_msg(gss_msg);
  325. spin_unlock(&pipe->lock);
  326. }
  327. static void
  328. gss_handle_downcall_result(struct gss_cred *gss_cred, struct gss_upcall_msg *gss_msg)
  329. {
  330. switch (gss_msg->msg.errno) {
  331. case 0:
  332. if (gss_msg->ctx == NULL)
  333. break;
  334. clear_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags);
  335. gss_cred_set_ctx(&gss_cred->gc_base, gss_msg->ctx);
  336. break;
  337. case -EKEYEXPIRED:
  338. set_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags);
  339. }
  340. gss_cred->gc_upcall_timestamp = jiffies;
  341. gss_cred->gc_upcall = NULL;
  342. rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno);
  343. }
  344. static void
  345. gss_upcall_callback(struct rpc_task *task)
  346. {
  347. struct gss_cred *gss_cred = container_of(task->tk_rqstp->rq_cred,
  348. struct gss_cred, gc_base);
  349. struct gss_upcall_msg *gss_msg = gss_cred->gc_upcall;
  350. struct rpc_pipe *pipe = gss_msg->pipe;
  351. spin_lock(&pipe->lock);
  352. gss_handle_downcall_result(gss_cred, gss_msg);
  353. spin_unlock(&pipe->lock);
  354. task->tk_status = gss_msg->msg.errno;
  355. gss_release_msg(gss_msg);
  356. }
  357. static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg)
  358. {
  359. gss_msg->msg.data = &gss_msg->uid;
  360. gss_msg->msg.len = sizeof(gss_msg->uid);
  361. }
  362. static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
  363. struct rpc_clnt *clnt,
  364. const char *service_name)
  365. {
  366. struct gss_api_mech *mech = gss_msg->auth->mech;
  367. char *p = gss_msg->databuf;
  368. int len = 0;
  369. gss_msg->msg.len = sprintf(gss_msg->databuf, "mech=%s uid=%d ",
  370. mech->gm_name,
  371. gss_msg->uid);
  372. p += gss_msg->msg.len;
  373. if (clnt->cl_principal) {
  374. len = sprintf(p, "target=%s ", clnt->cl_principal);
  375. p += len;
  376. gss_msg->msg.len += len;
  377. }
  378. if (service_name != NULL) {
  379. len = sprintf(p, "service=%s ", service_name);
  380. p += len;
  381. gss_msg->msg.len += len;
  382. }
  383. if (mech->gm_upcall_enctypes) {
  384. len = sprintf(p, "enctypes=%s ", mech->gm_upcall_enctypes);
  385. p += len;
  386. gss_msg->msg.len += len;
  387. }
  388. len = sprintf(p, "\n");
  389. gss_msg->msg.len += len;
  390. gss_msg->msg.data = gss_msg->databuf;
  391. BUG_ON(gss_msg->msg.len > UPCALL_BUF_LEN);
  392. }
  393. static void gss_encode_msg(struct gss_upcall_msg *gss_msg,
  394. struct rpc_clnt *clnt,
  395. const char *service_name)
  396. {
  397. if (pipe_version == 0)
  398. gss_encode_v0_msg(gss_msg);
  399. else /* pipe_version == 1 */
  400. gss_encode_v1_msg(gss_msg, clnt, service_name);
  401. }
  402. static struct gss_upcall_msg *
  403. gss_alloc_msg(struct gss_auth *gss_auth, struct rpc_clnt *clnt,
  404. uid_t uid, const char *service_name)
  405. {
  406. struct gss_upcall_msg *gss_msg;
  407. int vers;
  408. gss_msg = kzalloc(sizeof(*gss_msg), GFP_NOFS);
  409. if (gss_msg == NULL)
  410. return ERR_PTR(-ENOMEM);
  411. vers = get_pipe_version();
  412. if (vers < 0) {
  413. kfree(gss_msg);
  414. return ERR_PTR(vers);
  415. }
  416. gss_msg->pipe = gss_auth->pipe[vers];
  417. INIT_LIST_HEAD(&gss_msg->list);
  418. rpc_init_wait_queue(&gss_msg->rpc_waitqueue, "RPCSEC_GSS upcall waitq");
  419. init_waitqueue_head(&gss_msg->waitqueue);
  420. atomic_set(&gss_msg->count, 1);
  421. gss_msg->uid = uid;
  422. gss_msg->auth = gss_auth;
  423. gss_encode_msg(gss_msg, clnt, service_name);
  424. return gss_msg;
  425. }
  426. static struct gss_upcall_msg *
  427. gss_setup_upcall(struct rpc_clnt *clnt, struct gss_auth *gss_auth, struct rpc_cred *cred)
  428. {
  429. struct gss_cred *gss_cred = container_of(cred,
  430. struct gss_cred, gc_base);
  431. struct gss_upcall_msg *gss_new, *gss_msg;
  432. uid_t uid = cred->cr_uid;
  433. gss_new = gss_alloc_msg(gss_auth, clnt, uid, gss_cred->gc_principal);
  434. if (IS_ERR(gss_new))
  435. return gss_new;
  436. gss_msg = gss_add_msg(gss_new);
  437. if (gss_msg == gss_new) {
  438. int res = rpc_queue_upcall(gss_new->pipe, &gss_new->msg);
  439. if (res) {
  440. gss_unhash_msg(gss_new);
  441. gss_msg = ERR_PTR(res);
  442. }
  443. } else
  444. gss_release_msg(gss_new);
  445. return gss_msg;
  446. }
  447. static void warn_gssd(void)
  448. {
  449. static unsigned long ratelimit;
  450. unsigned long now = jiffies;
  451. if (time_after(now, ratelimit)) {
  452. printk(KERN_WARNING "RPC: AUTH_GSS upcall timed out.\n"
  453. "Please check user daemon is running.\n");
  454. ratelimit = now + 15*HZ;
  455. }
  456. }
  457. static inline int
  458. gss_refresh_upcall(struct rpc_task *task)
  459. {
  460. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  461. struct gss_auth *gss_auth = container_of(cred->cr_auth,
  462. struct gss_auth, rpc_auth);
  463. struct gss_cred *gss_cred = container_of(cred,
  464. struct gss_cred, gc_base);
  465. struct gss_upcall_msg *gss_msg;
  466. struct rpc_pipe *pipe;
  467. int err = 0;
  468. dprintk("RPC: %5u %s for uid %u\n",
  469. task->tk_pid, __func__, cred->cr_uid);
  470. gss_msg = gss_setup_upcall(task->tk_client, gss_auth, cred);
  471. if (PTR_ERR(gss_msg) == -EAGAIN) {
  472. /* XXX: warning on the first, under the assumption we
  473. * shouldn't normally hit this case on a refresh. */
  474. warn_gssd();
  475. task->tk_timeout = 15*HZ;
  476. rpc_sleep_on(&pipe_version_rpc_waitqueue, task, NULL);
  477. return -EAGAIN;
  478. }
  479. if (IS_ERR(gss_msg)) {
  480. err = PTR_ERR(gss_msg);
  481. goto out;
  482. }
  483. pipe = gss_msg->pipe;
  484. spin_lock(&pipe->lock);
  485. if (gss_cred->gc_upcall != NULL)
  486. rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL);
  487. else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) {
  488. task->tk_timeout = 0;
  489. gss_cred->gc_upcall = gss_msg;
  490. /* gss_upcall_callback will release the reference to gss_upcall_msg */
  491. atomic_inc(&gss_msg->count);
  492. rpc_sleep_on(&gss_msg->rpc_waitqueue, task, gss_upcall_callback);
  493. } else {
  494. gss_handle_downcall_result(gss_cred, gss_msg);
  495. err = gss_msg->msg.errno;
  496. }
  497. spin_unlock(&pipe->lock);
  498. gss_release_msg(gss_msg);
  499. out:
  500. dprintk("RPC: %5u %s for uid %u result %d\n",
  501. task->tk_pid, __func__, cred->cr_uid, err);
  502. return err;
  503. }
  504. static inline int
  505. gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred)
  506. {
  507. struct rpc_pipe *pipe;
  508. struct rpc_cred *cred = &gss_cred->gc_base;
  509. struct gss_upcall_msg *gss_msg;
  510. DEFINE_WAIT(wait);
  511. int err = 0;
  512. dprintk("RPC: %s for uid %u\n", __func__, cred->cr_uid);
  513. retry:
  514. gss_msg = gss_setup_upcall(gss_auth->client, gss_auth, cred);
  515. if (PTR_ERR(gss_msg) == -EAGAIN) {
  516. err = wait_event_interruptible_timeout(pipe_version_waitqueue,
  517. pipe_version >= 0, 15*HZ);
  518. if (pipe_version < 0) {
  519. warn_gssd();
  520. err = -EACCES;
  521. }
  522. if (err)
  523. goto out;
  524. goto retry;
  525. }
  526. if (IS_ERR(gss_msg)) {
  527. err = PTR_ERR(gss_msg);
  528. goto out;
  529. }
  530. pipe = gss_msg->pipe;
  531. for (;;) {
  532. prepare_to_wait(&gss_msg->waitqueue, &wait, TASK_KILLABLE);
  533. spin_lock(&pipe->lock);
  534. if (gss_msg->ctx != NULL || gss_msg->msg.errno < 0) {
  535. break;
  536. }
  537. spin_unlock(&pipe->lock);
  538. if (fatal_signal_pending(current)) {
  539. err = -ERESTARTSYS;
  540. goto out_intr;
  541. }
  542. schedule();
  543. }
  544. if (gss_msg->ctx)
  545. gss_cred_set_ctx(cred, gss_msg->ctx);
  546. else
  547. err = gss_msg->msg.errno;
  548. spin_unlock(&pipe->lock);
  549. out_intr:
  550. finish_wait(&gss_msg->waitqueue, &wait);
  551. gss_release_msg(gss_msg);
  552. out:
  553. dprintk("RPC: %s for uid %u result %d\n",
  554. __func__, cred->cr_uid, err);
  555. return err;
  556. }
  557. #define MSG_BUF_MAXSIZE 1024
  558. static ssize_t
  559. gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
  560. {
  561. const void *p, *end;
  562. void *buf;
  563. struct gss_upcall_msg *gss_msg;
  564. struct rpc_pipe *pipe = RPC_I(filp->f_dentry->d_inode)->pipe;
  565. struct gss_cl_ctx *ctx;
  566. uid_t uid;
  567. ssize_t err = -EFBIG;
  568. if (mlen > MSG_BUF_MAXSIZE)
  569. goto out;
  570. err = -ENOMEM;
  571. buf = kmalloc(mlen, GFP_NOFS);
  572. if (!buf)
  573. goto out;
  574. err = -EFAULT;
  575. if (copy_from_user(buf, src, mlen))
  576. goto err;
  577. end = (const void *)((char *)buf + mlen);
  578. p = simple_get_bytes(buf, end, &uid, sizeof(uid));
  579. if (IS_ERR(p)) {
  580. err = PTR_ERR(p);
  581. goto err;
  582. }
  583. err = -ENOMEM;
  584. ctx = gss_alloc_context();
  585. if (ctx == NULL)
  586. goto err;
  587. err = -ENOENT;
  588. /* Find a matching upcall */
  589. spin_lock(&pipe->lock);
  590. gss_msg = __gss_find_upcall(pipe, uid);
  591. if (gss_msg == NULL) {
  592. spin_unlock(&pipe->lock);
  593. goto err_put_ctx;
  594. }
  595. list_del_init(&gss_msg->list);
  596. spin_unlock(&pipe->lock);
  597. p = gss_fill_context(p, end, ctx, gss_msg->auth->mech);
  598. if (IS_ERR(p)) {
  599. err = PTR_ERR(p);
  600. switch (err) {
  601. case -EACCES:
  602. case -EKEYEXPIRED:
  603. gss_msg->msg.errno = err;
  604. err = mlen;
  605. break;
  606. case -EFAULT:
  607. case -ENOMEM:
  608. case -EINVAL:
  609. case -ENOSYS:
  610. gss_msg->msg.errno = -EAGAIN;
  611. break;
  612. default:
  613. printk(KERN_CRIT "%s: bad return from "
  614. "gss_fill_context: %zd\n", __func__, err);
  615. BUG();
  616. }
  617. goto err_release_msg;
  618. }
  619. gss_msg->ctx = gss_get_ctx(ctx);
  620. err = mlen;
  621. err_release_msg:
  622. spin_lock(&pipe->lock);
  623. __gss_unhash_msg(gss_msg);
  624. spin_unlock(&pipe->lock);
  625. gss_release_msg(gss_msg);
  626. err_put_ctx:
  627. gss_put_ctx(ctx);
  628. err:
  629. kfree(buf);
  630. out:
  631. dprintk("RPC: %s returning %Zd\n", __func__, err);
  632. return err;
  633. }
  634. static int gss_pipe_open(struct inode *inode, int new_version)
  635. {
  636. int ret = 0;
  637. spin_lock(&pipe_version_lock);
  638. if (pipe_version < 0) {
  639. /* First open of any gss pipe determines the version: */
  640. pipe_version = new_version;
  641. rpc_wake_up(&pipe_version_rpc_waitqueue);
  642. wake_up(&pipe_version_waitqueue);
  643. } else if (pipe_version != new_version) {
  644. /* Trying to open a pipe of a different version */
  645. ret = -EBUSY;
  646. goto out;
  647. }
  648. atomic_inc(&pipe_users);
  649. out:
  650. spin_unlock(&pipe_version_lock);
  651. return ret;
  652. }
  653. static int gss_pipe_open_v0(struct inode *inode)
  654. {
  655. return gss_pipe_open(inode, 0);
  656. }
  657. static int gss_pipe_open_v1(struct inode *inode)
  658. {
  659. return gss_pipe_open(inode, 1);
  660. }
  661. static void
  662. gss_pipe_release(struct inode *inode)
  663. {
  664. struct rpc_pipe *pipe = RPC_I(inode)->pipe;
  665. struct gss_upcall_msg *gss_msg;
  666. restart:
  667. spin_lock(&pipe->lock);
  668. list_for_each_entry(gss_msg, &pipe->in_downcall, list) {
  669. if (!list_empty(&gss_msg->msg.list))
  670. continue;
  671. gss_msg->msg.errno = -EPIPE;
  672. atomic_inc(&gss_msg->count);
  673. __gss_unhash_msg(gss_msg);
  674. spin_unlock(&pipe->lock);
  675. gss_release_msg(gss_msg);
  676. goto restart;
  677. }
  678. spin_unlock(&pipe->lock);
  679. put_pipe_version();
  680. }
  681. static void
  682. gss_pipe_destroy_msg(struct rpc_pipe_msg *msg)
  683. {
  684. struct gss_upcall_msg *gss_msg = container_of(msg, struct gss_upcall_msg, msg);
  685. if (msg->errno < 0) {
  686. dprintk("RPC: %s releasing msg %p\n",
  687. __func__, gss_msg);
  688. atomic_inc(&gss_msg->count);
  689. gss_unhash_msg(gss_msg);
  690. if (msg->errno == -ETIMEDOUT)
  691. warn_gssd();
  692. gss_release_msg(gss_msg);
  693. }
  694. }
  695. static void gss_pipes_dentries_destroy(struct rpc_auth *auth)
  696. {
  697. struct gss_auth *gss_auth;
  698. gss_auth = container_of(auth, struct gss_auth, rpc_auth);
  699. if (gss_auth->pipe[0]->dentry)
  700. rpc_unlink(gss_auth->pipe[0]->dentry);
  701. if (gss_auth->pipe[1]->dentry)
  702. rpc_unlink(gss_auth->pipe[1]->dentry);
  703. }
  704. static int gss_pipes_dentries_create(struct rpc_auth *auth)
  705. {
  706. int err;
  707. struct gss_auth *gss_auth;
  708. struct rpc_clnt *clnt;
  709. gss_auth = container_of(auth, struct gss_auth, rpc_auth);
  710. clnt = gss_auth->client;
  711. gss_auth->pipe[1]->dentry = rpc_mkpipe_dentry(clnt->cl_dentry,
  712. "gssd",
  713. clnt, gss_auth->pipe[1]);
  714. if (IS_ERR(gss_auth->pipe[1]->dentry))
  715. return PTR_ERR(gss_auth->pipe[1]->dentry);
  716. gss_auth->pipe[0]->dentry = rpc_mkpipe_dentry(clnt->cl_dentry,
  717. gss_auth->mech->gm_name,
  718. clnt, gss_auth->pipe[0]);
  719. if (IS_ERR(gss_auth->pipe[0]->dentry)) {
  720. err = PTR_ERR(gss_auth->pipe[0]->dentry);
  721. goto err_unlink_pipe_1;
  722. }
  723. return 0;
  724. err_unlink_pipe_1:
  725. rpc_unlink(gss_auth->pipe[1]->dentry);
  726. return err;
  727. }
  728. static void gss_pipes_dentries_destroy_net(struct rpc_clnt *clnt,
  729. struct rpc_auth *auth)
  730. {
  731. struct net *net = rpc_net_ns(clnt);
  732. struct super_block *sb;
  733. sb = rpc_get_sb_net(net);
  734. if (sb) {
  735. if (clnt->cl_dentry)
  736. gss_pipes_dentries_destroy(auth);
  737. rpc_put_sb_net(net);
  738. }
  739. }
  740. static int gss_pipes_dentries_create_net(struct rpc_clnt *clnt,
  741. struct rpc_auth *auth)
  742. {
  743. struct net *net = rpc_net_ns(clnt);
  744. struct super_block *sb;
  745. int err = 0;
  746. sb = rpc_get_sb_net(net);
  747. if (sb) {
  748. if (clnt->cl_dentry)
  749. err = gss_pipes_dentries_create(auth);
  750. rpc_put_sb_net(net);
  751. }
  752. return err;
  753. }
  754. /*
  755. * NOTE: we have the opportunity to use different
  756. * parameters based on the input flavor (which must be a pseudoflavor)
  757. */
  758. static struct rpc_auth *
  759. gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
  760. {
  761. struct gss_auth *gss_auth;
  762. struct rpc_auth * auth;
  763. int err = -ENOMEM; /* XXX? */
  764. dprintk("RPC: creating GSS authenticator for client %p\n", clnt);
  765. if (!try_module_get(THIS_MODULE))
  766. return ERR_PTR(err);
  767. if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL)))
  768. goto out_dec;
  769. gss_auth->client = clnt;
  770. err = -EINVAL;
  771. gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor);
  772. if (!gss_auth->mech) {
  773. printk(KERN_WARNING "%s: Pseudoflavor %d not found!\n",
  774. __func__, flavor);
  775. goto err_free;
  776. }
  777. gss_auth->service = gss_pseudoflavor_to_service(gss_auth->mech, flavor);
  778. if (gss_auth->service == 0)
  779. goto err_put_mech;
  780. auth = &gss_auth->rpc_auth;
  781. auth->au_cslack = GSS_CRED_SLACK >> 2;
  782. auth->au_rslack = GSS_VERF_SLACK >> 2;
  783. auth->au_ops = &authgss_ops;
  784. auth->au_flavor = flavor;
  785. atomic_set(&auth->au_count, 1);
  786. kref_init(&gss_auth->kref);
  787. /*
  788. * Note: if we created the old pipe first, then someone who
  789. * examined the directory at the right moment might conclude
  790. * that we supported only the old pipe. So we instead create
  791. * the new pipe first.
  792. */
  793. gss_auth->pipe[1] = rpc_mkpipe_data(&gss_upcall_ops_v1,
  794. RPC_PIPE_WAIT_FOR_OPEN);
  795. if (IS_ERR(gss_auth->pipe[1])) {
  796. err = PTR_ERR(gss_auth->pipe[1]);
  797. goto err_put_mech;
  798. }
  799. gss_auth->pipe[0] = rpc_mkpipe_data(&gss_upcall_ops_v0,
  800. RPC_PIPE_WAIT_FOR_OPEN);
  801. if (IS_ERR(gss_auth->pipe[0])) {
  802. err = PTR_ERR(gss_auth->pipe[0]);
  803. goto err_destroy_pipe_1;
  804. }
  805. err = gss_pipes_dentries_create_net(clnt, auth);
  806. if (err)
  807. goto err_destroy_pipe_0;
  808. err = rpcauth_init_credcache(auth);
  809. if (err)
  810. goto err_unlink_pipes;
  811. return auth;
  812. err_unlink_pipes:
  813. gss_pipes_dentries_destroy_net(clnt, auth);
  814. err_destroy_pipe_0:
  815. rpc_destroy_pipe_data(gss_auth->pipe[0]);
  816. err_destroy_pipe_1:
  817. rpc_destroy_pipe_data(gss_auth->pipe[1]);
  818. err_put_mech:
  819. gss_mech_put(gss_auth->mech);
  820. err_free:
  821. kfree(gss_auth);
  822. out_dec:
  823. module_put(THIS_MODULE);
  824. return ERR_PTR(err);
  825. }
  826. static void
  827. gss_free(struct gss_auth *gss_auth)
  828. {
  829. gss_pipes_dentries_destroy_net(gss_auth->client, &gss_auth->rpc_auth);
  830. rpc_destroy_pipe_data(gss_auth->pipe[0]);
  831. rpc_destroy_pipe_data(gss_auth->pipe[1]);
  832. gss_mech_put(gss_auth->mech);
  833. kfree(gss_auth);
  834. module_put(THIS_MODULE);
  835. }
  836. static void
  837. gss_free_callback(struct kref *kref)
  838. {
  839. struct gss_auth *gss_auth = container_of(kref, struct gss_auth, kref);
  840. gss_free(gss_auth);
  841. }
  842. static void
  843. gss_destroy(struct rpc_auth *auth)
  844. {
  845. struct gss_auth *gss_auth;
  846. dprintk("RPC: destroying GSS authenticator %p flavor %d\n",
  847. auth, auth->au_flavor);
  848. rpcauth_destroy_credcache(auth);
  849. gss_auth = container_of(auth, struct gss_auth, rpc_auth);
  850. kref_put(&gss_auth->kref, gss_free_callback);
  851. }
  852. /*
  853. * gss_destroying_context will cause the RPCSEC_GSS to send a NULL RPC call
  854. * to the server with the GSS control procedure field set to
  855. * RPC_GSS_PROC_DESTROY. This should normally cause the server to release
  856. * all RPCSEC_GSS state associated with that context.
  857. */
  858. static int
  859. gss_destroying_context(struct rpc_cred *cred)
  860. {
  861. struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
  862. struct gss_auth *gss_auth = container_of(cred->cr_auth, struct gss_auth, rpc_auth);
  863. struct rpc_task *task;
  864. if (gss_cred->gc_ctx == NULL ||
  865. test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) == 0)
  866. return 0;
  867. gss_cred->gc_ctx->gc_proc = RPC_GSS_PROC_DESTROY;
  868. cred->cr_ops = &gss_nullops;
  869. /* Take a reference to ensure the cred will be destroyed either
  870. * by the RPC call or by the put_rpccred() below */
  871. get_rpccred(cred);
  872. task = rpc_call_null(gss_auth->client, cred, RPC_TASK_ASYNC|RPC_TASK_SOFT);
  873. if (!IS_ERR(task))
  874. rpc_put_task(task);
  875. put_rpccred(cred);
  876. return 1;
  877. }
  878. /* gss_destroy_cred (and gss_free_ctx) are used to clean up after failure
  879. * to create a new cred or context, so they check that things have been
  880. * allocated before freeing them. */
  881. static void
  882. gss_do_free_ctx(struct gss_cl_ctx *ctx)
  883. {
  884. dprintk("RPC: %s\n", __func__);
  885. gss_delete_sec_context(&ctx->gc_gss_ctx);
  886. kfree(ctx->gc_wire_ctx.data);
  887. kfree(ctx);
  888. }
  889. static void
  890. gss_free_ctx_callback(struct rcu_head *head)
  891. {
  892. struct gss_cl_ctx *ctx = container_of(head, struct gss_cl_ctx, gc_rcu);
  893. gss_do_free_ctx(ctx);
  894. }
  895. static void
  896. gss_free_ctx(struct gss_cl_ctx *ctx)
  897. {
  898. call_rcu(&ctx->gc_rcu, gss_free_ctx_callback);
  899. }
  900. static void
  901. gss_free_cred(struct gss_cred *gss_cred)
  902. {
  903. dprintk("RPC: %s cred=%p\n", __func__, gss_cred);
  904. kfree(gss_cred);
  905. }
  906. static void
  907. gss_free_cred_callback(struct rcu_head *head)
  908. {
  909. struct gss_cred *gss_cred = container_of(head, struct gss_cred, gc_base.cr_rcu);
  910. gss_free_cred(gss_cred);
  911. }
  912. static void
  913. gss_destroy_nullcred(struct rpc_cred *cred)
  914. {
  915. struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
  916. struct gss_auth *gss_auth = container_of(cred->cr_auth, struct gss_auth, rpc_auth);
  917. struct gss_cl_ctx *ctx = gss_cred->gc_ctx;
  918. RCU_INIT_POINTER(gss_cred->gc_ctx, NULL);
  919. call_rcu(&cred->cr_rcu, gss_free_cred_callback);
  920. if (ctx)
  921. gss_put_ctx(ctx);
  922. kref_put(&gss_auth->kref, gss_free_callback);
  923. }
  924. static void
  925. gss_destroy_cred(struct rpc_cred *cred)
  926. {
  927. if (gss_destroying_context(cred))
  928. return;
  929. gss_destroy_nullcred(cred);
  930. }
  931. /*
  932. * Lookup RPCSEC_GSS cred for the current process
  933. */
  934. static struct rpc_cred *
  935. gss_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
  936. {
  937. return rpcauth_lookup_credcache(auth, acred, flags);
  938. }
  939. static struct rpc_cred *
  940. gss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
  941. {
  942. struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth);
  943. struct gss_cred *cred = NULL;
  944. int err = -ENOMEM;
  945. dprintk("RPC: %s for uid %d, flavor %d\n",
  946. __func__, acred->uid, auth->au_flavor);
  947. if (!(cred = kzalloc(sizeof(*cred), GFP_NOFS)))
  948. goto out_err;
  949. rpcauth_init_cred(&cred->gc_base, acred, auth, &gss_credops);
  950. /*
  951. * Note: in order to force a call to call_refresh(), we deliberately
  952. * fail to flag the credential as RPCAUTH_CRED_UPTODATE.
  953. */
  954. cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW;
  955. cred->gc_service = gss_auth->service;
  956. cred->gc_principal = NULL;
  957. if (acred->machine_cred)
  958. cred->gc_principal = acred->principal;
  959. kref_get(&gss_auth->kref);
  960. return &cred->gc_base;
  961. out_err:
  962. dprintk("RPC: %s failed with error %d\n", __func__, err);
  963. return ERR_PTR(err);
  964. }
  965. static int
  966. gss_cred_init(struct rpc_auth *auth, struct rpc_cred *cred)
  967. {
  968. struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth);
  969. struct gss_cred *gss_cred = container_of(cred,struct gss_cred, gc_base);
  970. int err;
  971. do {
  972. err = gss_create_upcall(gss_auth, gss_cred);
  973. } while (err == -EAGAIN);
  974. return err;
  975. }
  976. static int
  977. gss_match(struct auth_cred *acred, struct rpc_cred *rc, int flags)
  978. {
  979. struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
  980. if (test_bit(RPCAUTH_CRED_NEW, &rc->cr_flags))
  981. goto out;
  982. /* Don't match with creds that have expired. */
  983. if (time_after(jiffies, gss_cred->gc_ctx->gc_expiry))
  984. return 0;
  985. if (!test_bit(RPCAUTH_CRED_UPTODATE, &rc->cr_flags))
  986. return 0;
  987. out:
  988. if (acred->principal != NULL) {
  989. if (gss_cred->gc_principal == NULL)
  990. return 0;
  991. return strcmp(acred->principal, gss_cred->gc_principal) == 0;
  992. }
  993. if (gss_cred->gc_principal != NULL)
  994. return 0;
  995. return rc->cr_uid == acred->uid;
  996. }
  997. /*
  998. * Marshal credentials.
  999. * Maybe we should keep a cached credential for performance reasons.
  1000. */
  1001. static __be32 *
  1002. gss_marshal(struct rpc_task *task, __be32 *p)
  1003. {
  1004. struct rpc_rqst *req = task->tk_rqstp;
  1005. struct rpc_cred *cred = req->rq_cred;
  1006. struct gss_cred *gss_cred = container_of(cred, struct gss_cred,
  1007. gc_base);
  1008. struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred);
  1009. __be32 *cred_len;
  1010. u32 maj_stat = 0;
  1011. struct xdr_netobj mic;
  1012. struct kvec iov;
  1013. struct xdr_buf verf_buf;
  1014. dprintk("RPC: %5u %s\n", task->tk_pid, __func__);
  1015. *p++ = htonl(RPC_AUTH_GSS);
  1016. cred_len = p++;
  1017. spin_lock(&ctx->gc_seq_lock);
  1018. req->rq_seqno = ctx->gc_seq++;
  1019. spin_unlock(&ctx->gc_seq_lock);
  1020. *p++ = htonl((u32) RPC_GSS_VERSION);
  1021. *p++ = htonl((u32) ctx->gc_proc);
  1022. *p++ = htonl((u32) req->rq_seqno);
  1023. *p++ = htonl((u32) gss_cred->gc_service);
  1024. p = xdr_encode_netobj(p, &ctx->gc_wire_ctx);
  1025. *cred_len = htonl((p - (cred_len + 1)) << 2);
  1026. /* We compute the checksum for the verifier over the xdr-encoded bytes
  1027. * starting with the xid and ending at the end of the credential: */
  1028. iov.iov_base = xprt_skip_transport_header(task->tk_xprt,
  1029. req->rq_snd_buf.head[0].iov_base);
  1030. iov.iov_len = (u8 *)p - (u8 *)iov.iov_base;
  1031. xdr_buf_from_iov(&iov, &verf_buf);
  1032. /* set verifier flavor*/
  1033. *p++ = htonl(RPC_AUTH_GSS);
  1034. mic.data = (u8 *)(p + 1);
  1035. maj_stat = gss_get_mic(ctx->gc_gss_ctx, &verf_buf, &mic);
  1036. if (maj_stat == GSS_S_CONTEXT_EXPIRED) {
  1037. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  1038. } else if (maj_stat != 0) {
  1039. printk("gss_marshal: gss_get_mic FAILED (%d)\n", maj_stat);
  1040. goto out_put_ctx;
  1041. }
  1042. p = xdr_encode_opaque(p, NULL, mic.len);
  1043. gss_put_ctx(ctx);
  1044. return p;
  1045. out_put_ctx:
  1046. gss_put_ctx(ctx);
  1047. return NULL;
  1048. }
  1049. static int gss_renew_cred(struct rpc_task *task)
  1050. {
  1051. struct rpc_cred *oldcred = task->tk_rqstp->rq_cred;
  1052. struct gss_cred *gss_cred = container_of(oldcred,
  1053. struct gss_cred,
  1054. gc_base);
  1055. struct rpc_auth *auth = oldcred->cr_auth;
  1056. struct auth_cred acred = {
  1057. .uid = oldcred->cr_uid,
  1058. .principal = gss_cred->gc_principal,
  1059. .machine_cred = (gss_cred->gc_principal != NULL ? 1 : 0),
  1060. };
  1061. struct rpc_cred *new;
  1062. new = gss_lookup_cred(auth, &acred, RPCAUTH_LOOKUP_NEW);
  1063. if (IS_ERR(new))
  1064. return PTR_ERR(new);
  1065. task->tk_rqstp->rq_cred = new;
  1066. put_rpccred(oldcred);
  1067. return 0;
  1068. }
  1069. static int gss_cred_is_negative_entry(struct rpc_cred *cred)
  1070. {
  1071. if (test_bit(RPCAUTH_CRED_NEGATIVE, &cred->cr_flags)) {
  1072. unsigned long now = jiffies;
  1073. unsigned long begin, expire;
  1074. struct gss_cred *gss_cred;
  1075. gss_cred = container_of(cred, struct gss_cred, gc_base);
  1076. begin = gss_cred->gc_upcall_timestamp;
  1077. expire = begin + gss_expired_cred_retry_delay * HZ;
  1078. if (time_in_range_open(now, begin, expire))
  1079. return 1;
  1080. }
  1081. return 0;
  1082. }
  1083. /*
  1084. * Refresh credentials. XXX - finish
  1085. */
  1086. static int
  1087. gss_refresh(struct rpc_task *task)
  1088. {
  1089. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  1090. int ret = 0;
  1091. if (gss_cred_is_negative_entry(cred))
  1092. return -EKEYEXPIRED;
  1093. if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) &&
  1094. !test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags)) {
  1095. ret = gss_renew_cred(task);
  1096. if (ret < 0)
  1097. goto out;
  1098. cred = task->tk_rqstp->rq_cred;
  1099. }
  1100. if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags))
  1101. ret = gss_refresh_upcall(task);
  1102. out:
  1103. return ret;
  1104. }
  1105. /* Dummy refresh routine: used only when destroying the context */
  1106. static int
  1107. gss_refresh_null(struct rpc_task *task)
  1108. {
  1109. return -EACCES;
  1110. }
  1111. static __be32 *
  1112. gss_validate(struct rpc_task *task, __be32 *p)
  1113. {
  1114. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  1115. struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred);
  1116. __be32 seq;
  1117. struct kvec iov;
  1118. struct xdr_buf verf_buf;
  1119. struct xdr_netobj mic;
  1120. u32 flav,len;
  1121. u32 maj_stat;
  1122. dprintk("RPC: %5u %s\n", task->tk_pid, __func__);
  1123. flav = ntohl(*p++);
  1124. if ((len = ntohl(*p++)) > RPC_MAX_AUTH_SIZE)
  1125. goto out_bad;
  1126. if (flav != RPC_AUTH_GSS)
  1127. goto out_bad;
  1128. seq = htonl(task->tk_rqstp->rq_seqno);
  1129. iov.iov_base = &seq;
  1130. iov.iov_len = sizeof(seq);
  1131. xdr_buf_from_iov(&iov, &verf_buf);
  1132. mic.data = (u8 *)p;
  1133. mic.len = len;
  1134. maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &verf_buf, &mic);
  1135. if (maj_stat == GSS_S_CONTEXT_EXPIRED)
  1136. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  1137. if (maj_stat) {
  1138. dprintk("RPC: %5u %s: gss_verify_mic returned error 0x%08x\n",
  1139. task->tk_pid, __func__, maj_stat);
  1140. goto out_bad;
  1141. }
  1142. /* We leave it to unwrap to calculate au_rslack. For now we just
  1143. * calculate the length of the verifier: */
  1144. cred->cr_auth->au_verfsize = XDR_QUADLEN(len) + 2;
  1145. gss_put_ctx(ctx);
  1146. dprintk("RPC: %5u %s: gss_verify_mic succeeded.\n",
  1147. task->tk_pid, __func__);
  1148. return p + XDR_QUADLEN(len);
  1149. out_bad:
  1150. gss_put_ctx(ctx);
  1151. dprintk("RPC: %5u %s failed.\n", task->tk_pid, __func__);
  1152. return NULL;
  1153. }
  1154. static void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
  1155. __be32 *p, void *obj)
  1156. {
  1157. struct xdr_stream xdr;
  1158. xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p);
  1159. encode(rqstp, &xdr, obj);
  1160. }
  1161. static inline int
  1162. gss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
  1163. kxdreproc_t encode, struct rpc_rqst *rqstp,
  1164. __be32 *p, void *obj)
  1165. {
  1166. struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
  1167. struct xdr_buf integ_buf;
  1168. __be32 *integ_len = NULL;
  1169. struct xdr_netobj mic;
  1170. u32 offset;
  1171. __be32 *q;
  1172. struct kvec *iov;
  1173. u32 maj_stat = 0;
  1174. int status = -EIO;
  1175. integ_len = p++;
  1176. offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
  1177. *p++ = htonl(rqstp->rq_seqno);
  1178. gss_wrap_req_encode(encode, rqstp, p, obj);
  1179. if (xdr_buf_subsegment(snd_buf, &integ_buf,
  1180. offset, snd_buf->len - offset))
  1181. return status;
  1182. *integ_len = htonl(integ_buf.len);
  1183. /* guess whether we're in the head or the tail: */
  1184. if (snd_buf->page_len || snd_buf->tail[0].iov_len)
  1185. iov = snd_buf->tail;
  1186. else
  1187. iov = snd_buf->head;
  1188. p = iov->iov_base + iov->iov_len;
  1189. mic.data = (u8 *)(p + 1);
  1190. maj_stat = gss_get_mic(ctx->gc_gss_ctx, &integ_buf, &mic);
  1191. status = -EIO; /* XXX? */
  1192. if (maj_stat == GSS_S_CONTEXT_EXPIRED)
  1193. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  1194. else if (maj_stat)
  1195. return status;
  1196. q = xdr_encode_opaque(p, NULL, mic.len);
  1197. offset = (u8 *)q - (u8 *)p;
  1198. iov->iov_len += offset;
  1199. snd_buf->len += offset;
  1200. return 0;
  1201. }
  1202. static void
  1203. priv_release_snd_buf(struct rpc_rqst *rqstp)
  1204. {
  1205. int i;
  1206. for (i=0; i < rqstp->rq_enc_pages_num; i++)
  1207. __free_page(rqstp->rq_enc_pages[i]);
  1208. kfree(rqstp->rq_enc_pages);
  1209. }
  1210. static int
  1211. alloc_enc_pages(struct rpc_rqst *rqstp)
  1212. {
  1213. struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
  1214. int first, last, i;
  1215. if (snd_buf->page_len == 0) {
  1216. rqstp->rq_enc_pages_num = 0;
  1217. return 0;
  1218. }
  1219. first = snd_buf->page_base >> PAGE_CACHE_SHIFT;
  1220. last = (snd_buf->page_base + snd_buf->page_len - 1) >> PAGE_CACHE_SHIFT;
  1221. rqstp->rq_enc_pages_num = last - first + 1 + 1;
  1222. rqstp->rq_enc_pages
  1223. = kmalloc(rqstp->rq_enc_pages_num * sizeof(struct page *),
  1224. GFP_NOFS);
  1225. if (!rqstp->rq_enc_pages)
  1226. goto out;
  1227. for (i=0; i < rqstp->rq_enc_pages_num; i++) {
  1228. rqstp->rq_enc_pages[i] = alloc_page(GFP_NOFS);
  1229. if (rqstp->rq_enc_pages[i] == NULL)
  1230. goto out_free;
  1231. }
  1232. rqstp->rq_release_snd_buf = priv_release_snd_buf;
  1233. return 0;
  1234. out_free:
  1235. rqstp->rq_enc_pages_num = i;
  1236. priv_release_snd_buf(rqstp);
  1237. out:
  1238. return -EAGAIN;
  1239. }
  1240. static inline int
  1241. gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
  1242. kxdreproc_t encode, struct rpc_rqst *rqstp,
  1243. __be32 *p, void *obj)
  1244. {
  1245. struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
  1246. u32 offset;
  1247. u32 maj_stat;
  1248. int status;
  1249. __be32 *opaque_len;
  1250. struct page **inpages;
  1251. int first;
  1252. int pad;
  1253. struct kvec *iov;
  1254. char *tmp;
  1255. opaque_len = p++;
  1256. offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
  1257. *p++ = htonl(rqstp->rq_seqno);
  1258. gss_wrap_req_encode(encode, rqstp, p, obj);
  1259. status = alloc_enc_pages(rqstp);
  1260. if (status)
  1261. return status;
  1262. first = snd_buf->page_base >> PAGE_CACHE_SHIFT;
  1263. inpages = snd_buf->pages + first;
  1264. snd_buf->pages = rqstp->rq_enc_pages;
  1265. snd_buf->page_base -= first << PAGE_CACHE_SHIFT;
  1266. /*
  1267. * Give the tail its own page, in case we need extra space in the
  1268. * head when wrapping:
  1269. *
  1270. * call_allocate() allocates twice the slack space required
  1271. * by the authentication flavor to rq_callsize.
  1272. * For GSS, slack is GSS_CRED_SLACK.
  1273. */
  1274. if (snd_buf->page_len || snd_buf->tail[0].iov_len) {
  1275. tmp = page_address(rqstp->rq_enc_pages[rqstp->rq_enc_pages_num - 1]);
  1276. memcpy(tmp, snd_buf->tail[0].iov_base, snd_buf->tail[0].iov_len);
  1277. snd_buf->tail[0].iov_base = tmp;
  1278. }
  1279. maj_stat = gss_wrap(ctx->gc_gss_ctx, offset, snd_buf, inpages);
  1280. /* slack space should prevent this ever happening: */
  1281. BUG_ON(snd_buf->len > snd_buf->buflen);
  1282. status = -EIO;
  1283. /* We're assuming that when GSS_S_CONTEXT_EXPIRED, the encryption was
  1284. * done anyway, so it's safe to put the request on the wire: */
  1285. if (maj_stat == GSS_S_CONTEXT_EXPIRED)
  1286. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  1287. else if (maj_stat)
  1288. return status;
  1289. *opaque_len = htonl(snd_buf->len - offset);
  1290. /* guess whether we're in the head or the tail: */
  1291. if (snd_buf->page_len || snd_buf->tail[0].iov_len)
  1292. iov = snd_buf->tail;
  1293. else
  1294. iov = snd_buf->head;
  1295. p = iov->iov_base + iov->iov_len;
  1296. pad = 3 - ((snd_buf->len - offset - 1) & 3);
  1297. memset(p, 0, pad);
  1298. iov->iov_len += pad;
  1299. snd_buf->len += pad;
  1300. return 0;
  1301. }
  1302. static int
  1303. gss_wrap_req(struct rpc_task *task,
  1304. kxdreproc_t encode, void *rqstp, __be32 *p, void *obj)
  1305. {
  1306. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  1307. struct gss_cred *gss_cred = container_of(cred, struct gss_cred,
  1308. gc_base);
  1309. struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred);
  1310. int status = -EIO;
  1311. dprintk("RPC: %5u %s\n", task->tk_pid, __func__);
  1312. if (ctx->gc_proc != RPC_GSS_PROC_DATA) {
  1313. /* The spec seems a little ambiguous here, but I think that not
  1314. * wrapping context destruction requests makes the most sense.
  1315. */
  1316. gss_wrap_req_encode(encode, rqstp, p, obj);
  1317. status = 0;
  1318. goto out;
  1319. }
  1320. switch (gss_cred->gc_service) {
  1321. case RPC_GSS_SVC_NONE:
  1322. gss_wrap_req_encode(encode, rqstp, p, obj);
  1323. status = 0;
  1324. break;
  1325. case RPC_GSS_SVC_INTEGRITY:
  1326. status = gss_wrap_req_integ(cred, ctx, encode, rqstp, p, obj);
  1327. break;
  1328. case RPC_GSS_SVC_PRIVACY:
  1329. status = gss_wrap_req_priv(cred, ctx, encode, rqstp, p, obj);
  1330. break;
  1331. }
  1332. out:
  1333. gss_put_ctx(ctx);
  1334. dprintk("RPC: %5u %s returning %d\n", task->tk_pid, __func__, status);
  1335. return status;
  1336. }
  1337. static inline int
  1338. gss_unwrap_resp_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
  1339. struct rpc_rqst *rqstp, __be32 **p)
  1340. {
  1341. struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf;
  1342. struct xdr_buf integ_buf;
  1343. struct xdr_netobj mic;
  1344. u32 data_offset, mic_offset;
  1345. u32 integ_len;
  1346. u32 maj_stat;
  1347. int status = -EIO;
  1348. integ_len = ntohl(*(*p)++);
  1349. if (integ_len & 3)
  1350. return status;
  1351. data_offset = (u8 *)(*p) - (u8 *)rcv_buf->head[0].iov_base;
  1352. mic_offset = integ_len + data_offset;
  1353. if (mic_offset > rcv_buf->len)
  1354. return status;
  1355. if (ntohl(*(*p)++) != rqstp->rq_seqno)
  1356. return status;
  1357. if (xdr_buf_subsegment(rcv_buf, &integ_buf, data_offset,
  1358. mic_offset - data_offset))
  1359. return status;
  1360. if (xdr_buf_read_netobj(rcv_buf, &mic, mic_offset))
  1361. return status;
  1362. maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &integ_buf, &mic);
  1363. if (maj_stat == GSS_S_CONTEXT_EXPIRED)
  1364. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  1365. if (maj_stat != GSS_S_COMPLETE)
  1366. return status;
  1367. return 0;
  1368. }
  1369. static inline int
  1370. gss_unwrap_resp_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
  1371. struct rpc_rqst *rqstp, __be32 **p)
  1372. {
  1373. struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf;
  1374. u32 offset;
  1375. u32 opaque_len;
  1376. u32 maj_stat;
  1377. int status = -EIO;
  1378. opaque_len = ntohl(*(*p)++);
  1379. offset = (u8 *)(*p) - (u8 *)rcv_buf->head[0].iov_base;
  1380. if (offset + opaque_len > rcv_buf->len)
  1381. return status;
  1382. /* remove padding: */
  1383. rcv_buf->len = offset + opaque_len;
  1384. maj_stat = gss_unwrap(ctx->gc_gss_ctx, offset, rcv_buf);
  1385. if (maj_stat == GSS_S_CONTEXT_EXPIRED)
  1386. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  1387. if (maj_stat != GSS_S_COMPLETE)
  1388. return status;
  1389. if (ntohl(*(*p)++) != rqstp->rq_seqno)
  1390. return status;
  1391. return 0;
  1392. }
  1393. static int
  1394. gss_unwrap_req_decode(kxdrdproc_t decode, struct rpc_rqst *rqstp,
  1395. __be32 *p, void *obj)
  1396. {
  1397. struct xdr_stream xdr;
  1398. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  1399. return decode(rqstp, &xdr, obj);
  1400. }
  1401. static int
  1402. gss_unwrap_resp(struct rpc_task *task,
  1403. kxdrdproc_t decode, void *rqstp, __be32 *p, void *obj)
  1404. {
  1405. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  1406. struct gss_cred *gss_cred = container_of(cred, struct gss_cred,
  1407. gc_base);
  1408. struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred);
  1409. __be32 *savedp = p;
  1410. struct kvec *head = ((struct rpc_rqst *)rqstp)->rq_rcv_buf.head;
  1411. int savedlen = head->iov_len;
  1412. int status = -EIO;
  1413. if (ctx->gc_proc != RPC_GSS_PROC_DATA)
  1414. goto out_decode;
  1415. switch (gss_cred->gc_service) {
  1416. case RPC_GSS_SVC_NONE:
  1417. break;
  1418. case RPC_GSS_SVC_INTEGRITY:
  1419. status = gss_unwrap_resp_integ(cred, ctx, rqstp, &p);
  1420. if (status)
  1421. goto out;
  1422. break;
  1423. case RPC_GSS_SVC_PRIVACY:
  1424. status = gss_unwrap_resp_priv(cred, ctx, rqstp, &p);
  1425. if (status)
  1426. goto out;
  1427. break;
  1428. }
  1429. /* take into account extra slack for integrity and privacy cases: */
  1430. cred->cr_auth->au_rslack = cred->cr_auth->au_verfsize + (p - savedp)
  1431. + (savedlen - head->iov_len);
  1432. out_decode:
  1433. status = gss_unwrap_req_decode(decode, rqstp, p, obj);
  1434. out:
  1435. gss_put_ctx(ctx);
  1436. dprintk("RPC: %5u %s returning %d\n",
  1437. task->tk_pid, __func__, status);
  1438. return status;
  1439. }
  1440. static const struct rpc_authops authgss_ops = {
  1441. .owner = THIS_MODULE,
  1442. .au_flavor = RPC_AUTH_GSS,
  1443. .au_name = "RPCSEC_GSS",
  1444. .create = gss_create,
  1445. .destroy = gss_destroy,
  1446. .lookup_cred = gss_lookup_cred,
  1447. .crcreate = gss_create_cred,
  1448. .pipes_create = gss_pipes_dentries_create,
  1449. .pipes_destroy = gss_pipes_dentries_destroy,
  1450. .list_pseudoflavors = gss_mech_list_pseudoflavors,
  1451. };
  1452. static const struct rpc_credops gss_credops = {
  1453. .cr_name = "AUTH_GSS",
  1454. .crdestroy = gss_destroy_cred,
  1455. .cr_init = gss_cred_init,
  1456. .crbind = rpcauth_generic_bind_cred,
  1457. .crmatch = gss_match,
  1458. .crmarshal = gss_marshal,
  1459. .crrefresh = gss_refresh,
  1460. .crvalidate = gss_validate,
  1461. .crwrap_req = gss_wrap_req,
  1462. .crunwrap_resp = gss_unwrap_resp,
  1463. };
  1464. static const struct rpc_credops gss_nullops = {
  1465. .cr_name = "AUTH_GSS",
  1466. .crdestroy = gss_destroy_nullcred,
  1467. .crbind = rpcauth_generic_bind_cred,
  1468. .crmatch = gss_match,
  1469. .crmarshal = gss_marshal,
  1470. .crrefresh = gss_refresh_null,
  1471. .crvalidate = gss_validate,
  1472. .crwrap_req = gss_wrap_req,
  1473. .crunwrap_resp = gss_unwrap_resp,
  1474. };
  1475. static const struct rpc_pipe_ops gss_upcall_ops_v0 = {
  1476. .upcall = rpc_pipe_generic_upcall,
  1477. .downcall = gss_pipe_downcall,
  1478. .destroy_msg = gss_pipe_destroy_msg,
  1479. .open_pipe = gss_pipe_open_v0,
  1480. .release_pipe = gss_pipe_release,
  1481. };
  1482. static const struct rpc_pipe_ops gss_upcall_ops_v1 = {
  1483. .upcall = rpc_pipe_generic_upcall,
  1484. .downcall = gss_pipe_downcall,
  1485. .destroy_msg = gss_pipe_destroy_msg,
  1486. .open_pipe = gss_pipe_open_v1,
  1487. .release_pipe = gss_pipe_release,
  1488. };
  1489. static __net_init int rpcsec_gss_init_net(struct net *net)
  1490. {
  1491. return gss_svc_init_net(net);
  1492. }
  1493. static __net_exit void rpcsec_gss_exit_net(struct net *net)
  1494. {
  1495. gss_svc_shutdown_net(net);
  1496. }
  1497. static struct pernet_operations rpcsec_gss_net_ops = {
  1498. .init = rpcsec_gss_init_net,
  1499. .exit = rpcsec_gss_exit_net,
  1500. };
  1501. /*
  1502. * Initialize RPCSEC_GSS module
  1503. */
  1504. static int __init init_rpcsec_gss(void)
  1505. {
  1506. int err = 0;
  1507. err = rpcauth_register(&authgss_ops);
  1508. if (err)
  1509. goto out;
  1510. err = gss_svc_init();
  1511. if (err)
  1512. goto out_unregister;
  1513. err = register_pernet_subsys(&rpcsec_gss_net_ops);
  1514. if (err)
  1515. goto out_svc_exit;
  1516. rpc_init_wait_queue(&pipe_version_rpc_waitqueue, "gss pipe version");
  1517. return 0;
  1518. out_svc_exit:
  1519. gss_svc_shutdown();
  1520. out_unregister:
  1521. rpcauth_unregister(&authgss_ops);
  1522. out:
  1523. return err;
  1524. }
  1525. static void __exit exit_rpcsec_gss(void)
  1526. {
  1527. unregister_pernet_subsys(&rpcsec_gss_net_ops);
  1528. gss_svc_shutdown();
  1529. rpcauth_unregister(&authgss_ops);
  1530. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  1531. }
  1532. MODULE_LICENSE("GPL");
  1533. module_param_named(expired_cred_retry_delay,
  1534. gss_expired_cred_retry_delay,
  1535. uint, 0644);
  1536. MODULE_PARM_DESC(expired_cred_retry_delay, "Timeout (in seconds) until "
  1537. "the RPC engine retries an expired credential");
  1538. module_init(init_rpcsec_gss)
  1539. module_exit(exit_rpcsec_gss)