auth_gss.c revision bf2695516db982e90a22fc94f93491b481796bb1
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2f30c2269544bffc7bf1b0d7c0abe5be1be83b8cbUwe Zeisberger * linux/net/sunrpc/auth_gss/auth_gss.c 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * RPCSEC_GSS client authentication. 5cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki * 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (c) 2000 The Regents of the University of Michigan. 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * All rights reserved. 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Dug Song <dugsong@monkey.org> 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Andy Adamson <andros@umich.edu> 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redistribution and use in source and binary forms, with or without 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * modification, are permitted provided that the following conditions 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are met: 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1. Redistributions of source code must retain the above copyright 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * notice, this list of conditions and the following disclaimer. 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * notice, this list of conditions and the following disclaimer in the 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * documentation and/or other materials provided with the distribution. 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3. Neither the name of the University nor the names of its 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * contributors may be used to endorse or promote products derived 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * from this software without specific prior written permission. 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/types.h> 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/slab.h> 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sched.h> 442d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields#include <linux/pagemap.h> 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/clnt.h> 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/auth.h> 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/auth_gss.h> 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/svcauth_gss.h> 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/gss_err.h> 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/workqueue.h> 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/rpc_pipe_fs.h> 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/sunrpc/gss_api.h> 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/uaccess.h> 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 55f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_authops authgss_ops; 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 57f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_credops gss_credops; 580df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic const struct rpc_credops gss_nullops; 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 60126e216a8730532dfb685205309275f87e3d133eTrond Myklebust#define GSS_RETRY_EXPIRED 5 61126e216a8730532dfb685205309275f87e3d133eTrond Myklebuststatic unsigned int gss_expired_cred_retry_delay = GSS_RETRY_EXPIRED; 62126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef RPC_DEBUG 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds# define RPCDBG_FACILITY RPCDBG_AUTH 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 67725f2865d4df31ac0768b13ae763beadc4bb8ce9Kevin Coffman#define GSS_CRED_SLACK (RPC_MAX_AUTH_SIZE * 2) 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* length of a krb5 verifier (48), plus data added before arguments when 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * using integrity (two 4-byte integers): */ 70adeb8133dd57f380e70a389a89a2ea3ae227f9e2Olga Kornievskaia#define GSS_VERF_SLACK 100 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct gss_auth { 730285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust struct kref kref; 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_auth rpc_auth; 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_api_mech *mech; 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum rpc_gss_svc service; 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_clnt *client; 7834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* 7934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * There are two upcall pipes; dentry[1], named "gssd", is used 8034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * for the new text-based upcall; dentry[0] is named after the 8134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * mechanism (for example, "krb5") and exists for 8234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * backwards-compatibility with older gssd's. 8334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ */ 8434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ struct dentry *dentry[2]; 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\/* pipe_version >= 0 if and only if someone has a pipe open. */ 8879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static int pipe_version = -1; 89cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\static atomic_t pipe_users = ATOMIC_INIT(0); 9079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static DEFINE_SPINLOCK(pipe_version_lock); 9179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static struct rpc_wait_queue pipe_version_rpc_waitqueue; 9279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue); 93cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ 945d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebuststatic void gss_free_ctx(struct gss_cl_ctx *); 95b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v0; 96b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v1; 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct gss_cl_ctx * 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_get_ctx(struct gss_cl_ctx *ctx) 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&ctx->count); 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ctx; 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_put_ctx(struct gss_cl_ctx *ctx) 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (atomic_dec_and_test(&ctx->count)) 1095d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust gss_free_ctx(ctx); 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1125d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust/* gss_cred_set_ctx: 1135d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust * called by gss_upcall_callback and gss_create_upcall in order 1145d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust * to set the gss context. The actual exchange of an old context 1155d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust * and a new one is protected by the inode->i_lock. 1165d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust */ 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx) 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 1215d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 122cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags)) 123cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return; 1247b6962b0a6000df48c8a5fd967d262f77704101bTrond Myklebust gss_get_ctx(ctx); 1255d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust rcu_assign_pointer(gss_cred->gc_ctx, ctx); 126fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 127cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust smp_mb__before_clear_bit(); 128fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags); 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic const void * 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssimple_get_bytes(const void *p, const void *end, void *res, size_t len) 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *q = (const void *)((const char *)p + len); 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(q > end || q < p)) 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(-EFAULT); 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(res, p, len); 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return q; 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline const void * 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssimple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *q; 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int len; 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &len, sizeof(len)); 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p; 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q = (const void *)((const char *)p + len); 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(q > end || q < p)) 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(-EFAULT); 1530f38b873aeaae698c3693748438547c8493165fbTrond Myklebust dest->data = kmemdup(p, len, GFP_NOFS); 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(dest->data == NULL)) 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(-ENOMEM); 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dest->len = len; 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return q; 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_cl_ctx * 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_cred_get_ctx(struct rpc_cred *cred) 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = NULL; 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1665d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust rcu_read_lock(); 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_cred->gc_ctx) 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx = gss_get_ctx(gss_cred->gc_ctx); 1695d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust rcu_read_unlock(); 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ctx; 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_cl_ctx * 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_alloc_context(void) 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx; 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1780f38b873aeaae698c3693748438547c8493165fbTrond Myklebust ctx = kzalloc(sizeof(*ctx), GFP_NOFS); 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx != NULL) { 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_proc = RPC_GSS_PROC_DATA; 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_seq = 1; /* NetApp 6.4R1 doesn't accept seq. no. 0 */ 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_init(&ctx->gc_seq_lock); 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_set(&ctx->count,1); 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ctx; 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define GSSD_MIN_TIMEOUT (60 * 60) 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic const void * 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct gss_api_mech *gm) 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *q; 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int seclen; 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int timeout; 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 window_size; 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int ret; 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* First unsigned int gives the lifetime (in seconds) of the cred */ 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &timeout, sizeof(timeout)); 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (timeout == 0) 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds timeout = GSSD_MIN_TIMEOUT; 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_expiry = jiffies + (unsigned long)timeout * HZ * 3 / 4; 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Sequence number window. Determines the maximum number of simultaneous requests */ 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &window_size, sizeof(window_size)); 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_win = window_size; 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* gssd signals an error by passing ctx->gc_win = 0: */ 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx->gc_win == 0) { 212dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton /* 213dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton * in which case, p points to an error code. Anything other 214dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton * than -EKEYEXPIRED gets converted to -EACCES. 215dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton */ 216dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton p = simple_get_bytes(p, end, &ret, sizeof(ret)); 217dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton if (!IS_ERR(p)) 218dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton p = (ret == -EKEYEXPIRED) ? ERR_PTR(-EKEYEXPIRED) : 219dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton ERR_PTR(-EACCES); 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* copy the opaque wire context */ 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_netobj(p, end, &ctx->gc_wire_ctx); 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* import the opaque security context */ 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &seclen, sizeof(seclen)); 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q = (const void *)((const char *)p + seclen); 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(q > end || q < p)) { 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = ERR_PTR(-EFAULT); 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2351f4c86c0be9064ab4eebd9e67c84606c1cfeec4bTrond Myklebust ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx, GFP_NOFS); 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ret < 0) { 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = ERR_PTR(ret); 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return q; 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr: 2428885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_fill_context returning %ld\n", -PTR_ERR(p)); 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p; 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\#define UPCALL_BUF_LEN 128 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct gss_upcall_msg { 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_t count; 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds uid_t uid; 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_pipe_msg msg; 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct list_head list; 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *auth; 2545b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct rpc_inode *inode; 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_wait_queue rpc_waitqueue; 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_head_t waitqueue; 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx; 25834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ char databuf[UPCALL_BUF_LEN]; 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static int get_pipe_version(void) 26279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\{ 26379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ int ret; 26479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ 26579a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_lock(&pipe_version_lock); 26679a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (pipe_version >= 0) { 26779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ atomic_inc(&pipe_users); 26834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ ret = pipe_version; 26979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } else 27079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ ret = -EAGAIN; 27179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_unlock(&pipe_version_lock); 27279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ return ret; 27379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\} 27479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ 27579a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static void put_pipe_version(void) 27679a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\{ 27779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (atomic_dec_and_lock(&pipe_users, &pipe_version_lock)) { 27879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ pipe_version = -1; 27979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_unlock(&pipe_version_lock); 28079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 28179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\} 28279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_release_msg(struct gss_upcall_msg *gss_msg) 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!atomic_dec_and_test(&gss_msg->count)) 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 28879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ put_pipe_version(); 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(!list_empty(&gss_msg->list)); 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg->ctx != NULL) 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(gss_msg->ctx); 292f6a1cc89309f0ae847a9b6fe418d1c4215e5bc55Trond Myklebust rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue); 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(gss_msg); 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_upcall_msg * 2976e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust__gss_find_upcall(struct rpc_inode *rpci, uid_t uid) 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *pos; 3006e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust list_for_each_entry(pos, &rpci->in_downcall, list) { 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (pos->uid != uid) 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&pos->count); 3048885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_find_upcall found msg %p\n", pos); 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return pos; 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3078885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_find_upcall found nothing\n"); 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 311720b8f2d6f7de9e16f1217448cc7396e1604e175\\\"J. Bruce Fields\\\/* Try to add an upcall to the pipefs queue. 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If an upcall owned by our uid already exists, then we return a reference 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to that upcall instead of adding the new upcall. 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct gss_upcall_msg * 316053e324f67b9921fe7de0c4cbc720d29cb4bf207Suresh Jayaramangss_add_msg(struct gss_upcall_msg *gss_msg) 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3185b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct rpc_inode *rpci = gss_msg->inode; 3195b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct inode *inode = &rpci->vfs_inode; 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *old; 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 322b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_lock(&inode->i_lock); 3236e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust old = __gss_find_upcall(rpci, gss_msg->uid); 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (old == NULL) { 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 3266e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust list_add(&gss_msg->list, &rpci->in_downcall); 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg = old; 329b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return gss_msg; 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds__gss_unhash_msg(struct gss_upcall_msg *gss_msg) 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_del_init(&gss_msg->list); 3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno); 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wake_up_all(&gss_msg->waitqueue); 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_dec(&gss_msg->count); 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_unhash_msg(struct gss_upcall_msg *gss_msg) 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3455b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct inode *inode = &gss_msg->inode->vfs_inode; 3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3473b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust if (list_empty(&gss_msg->list)) 3483b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust return; 349b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_lock(&inode->i_lock); 3503b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust if (!list_empty(&gss_msg->list)) 3513b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust __gss_unhash_msg(gss_msg); 352b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 356126e216a8730532dfb685205309275f87e3d133eTrond Myklebustgss_handle_downcall_result(struct gss_cred *gss_cred, struct gss_upcall_msg *gss_msg) 357126e216a8730532dfb685205309275f87e3d133eTrond Myklebust{ 358126e216a8730532dfb685205309275f87e3d133eTrond Myklebust switch (gss_msg->msg.errno) { 359126e216a8730532dfb685205309275f87e3d133eTrond Myklebust case 0: 360126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (gss_msg->ctx == NULL) 361126e216a8730532dfb685205309275f87e3d133eTrond Myklebust break; 362126e216a8730532dfb685205309275f87e3d133eTrond Myklebust clear_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags); 363126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred_set_ctx(&gss_cred->gc_base, gss_msg->ctx); 364126e216a8730532dfb685205309275f87e3d133eTrond Myklebust break; 365126e216a8730532dfb685205309275f87e3d133eTrond Myklebust case -EKEYEXPIRED: 366126e216a8730532dfb685205309275f87e3d133eTrond Myklebust set_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags); 367126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } 368126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred->gc_upcall_timestamp = jiffies; 369126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred->gc_upcall = NULL; 370126e216a8730532dfb685205309275f87e3d133eTrond Myklebust rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno); 371126e216a8730532dfb685205309275f87e3d133eTrond Myklebust} 372126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 373126e216a8730532dfb685205309275f87e3d133eTrond Myklebuststatic void 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_upcall_callback(struct rpc_task *task) 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 376a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct gss_cred *gss_cred = container_of(task->tk_rqstp->rq_cred, 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred, gc_base); 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg = gss_cred->gc_upcall; 3795b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct inode *inode = &gss_msg->inode->vfs_inode; 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3815d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust spin_lock(&inode->i_lock); 382126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_handle_downcall_result(gss_cred, gss_msg); 383b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 384126e216a8730532dfb685205309275f87e3d133eTrond Myklebust task->tk_status = gss_msg->msg.errno; 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 38834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg) 38934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 39034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_msg->msg.data = &gss_msg->uid; 39134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_msg->msg.len = sizeof(gss_msg->uid); 39234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 39334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 3948b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaiastatic void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg, 3952efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia struct rpc_clnt *clnt, int machine_cred) 39634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 397683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust struct gss_api_mech *mech = gss_msg->auth->mech; 3988b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia char *p = gss_msg->databuf; 3998b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia int len = 0; 4008b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia 4018b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia gss_msg->msg.len = sprintf(gss_msg->databuf, "mech=%s uid=%d ", 402683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust mech->gm_name, 40334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_msg->uid); 4048b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia p += gss_msg->msg.len; 4058b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia if (clnt->cl_principal) { 4068b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia len = sprintf(p, "target=%s ", clnt->cl_principal); 4078b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia p += len; 4088b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia gss_msg->msg.len += len; 4098b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia } 4102efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia if (machine_cred) { 4112efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia len = sprintf(p, "service=* "); 4122efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia p += len; 4132efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia gss_msg->msg.len += len; 4142efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia } else if (!strcmp(clnt->cl_program->name, "nfs4_cb")) { 4152efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia len = sprintf(p, "service=nfs "); 4162efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia p += len; 4172efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia gss_msg->msg.len += len; 4182efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia } 419683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust if (mech->gm_upcall_enctypes) { 420683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust len = sprintf(p, mech->gm_upcall_enctypes); 421683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust p += len; 422683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust gss_msg->msg.len += len; 423683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust } 4248b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia len = sprintf(p, "\n"); 4258b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia gss_msg->msg.len += len; 4268b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia 42734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_msg->msg.data = gss_msg->databuf; 42834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ BUG_ON(gss_msg->msg.len > UPCALL_BUF_LEN); 42934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 43034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 4318b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaiastatic void gss_encode_msg(struct gss_upcall_msg *gss_msg, 4322efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia struct rpc_clnt *clnt, int machine_cred) 43334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 43434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ if (pipe_version == 0) 43534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_encode_v0_msg(gss_msg); 43634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ else /* pipe_version == 1 */ 4372efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia gss_encode_v1_msg(gss_msg, clnt, machine_cred); 43834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 43934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct gss_upcall_msg * 4412efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaiagss_alloc_msg(struct gss_auth *gss_auth, uid_t uid, struct rpc_clnt *clnt, 4422efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia int machine_cred) 4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 44579a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ int vers; 4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4470f38b873aeaae698c3693748438547c8493165fbTrond Myklebust gss_msg = kzalloc(sizeof(*gss_msg), GFP_NOFS); 448db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ if (gss_msg == NULL) 449db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ return ERR_PTR(-ENOMEM); 45079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ vers = get_pipe_version(); 45179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (vers < 0) { 45279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ kfree(gss_msg); 45379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ return ERR_PTR(vers); 45479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 45534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_msg->inode = RPC_I(gss_auth->dentry[vers]->d_inode); 456db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ INIT_LIST_HEAD(&gss_msg->list); 457db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ rpc_init_wait_queue(&gss_msg->rpc_waitqueue, "RPCSEC_GSS upcall waitq"); 458db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ init_waitqueue_head(&gss_msg->waitqueue); 459db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ atomic_set(&gss_msg->count, 1); 460db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ gss_msg->uid = uid; 461db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ gss_msg->auth = gss_auth; 4622efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia gss_encode_msg(gss_msg, clnt, machine_cred); 4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return gss_msg; 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_upcall_msg * 4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_setup_upcall(struct rpc_clnt *clnt, struct gss_auth *gss_auth, struct rpc_cred *cred) 4681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4697c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust struct gss_cred *gss_cred = container_of(cred, 4707c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust struct gss_cred, gc_base); 4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_new, *gss_msg; 4727c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust uid_t uid = cred->cr_uid; 4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4742efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia gss_new = gss_alloc_msg(gss_auth, uid, clnt, gss_cred->gc_machine_cred); 475db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ if (IS_ERR(gss_new)) 476db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ return gss_new; 477053e324f67b9921fe7de0c4cbc720d29cb4bf207Suresh Jayaraman gss_msg = gss_add_msg(gss_new); 4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg == gss_new) { 4795b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct inode *inode = &gss_new->inode->vfs_inode; 4805b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ int res = rpc_queue_upcall(inode, &gss_new->msg); 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (res) { 4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_unhash_msg(gss_new); 4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg = ERR_PTR(res); 4841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_new); 4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return gss_msg; 4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 490b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\static void warn_gssd(void) 491b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\{ 492b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ static unsigned long ratelimit; 493b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ unsigned long now = jiffies; 494b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ 495b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ if (time_after(now, ratelimit)) { 496b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ printk(KERN_WARNING "RPC: AUTH_GSS upcall timed out.\n" 497b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ "Please check user daemon is running.\n"); 498b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ ratelimit = now + 15*HZ; 499b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ } 500b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\} 501b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ 5021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 5031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_refresh_upcall(struct rpc_task *task) 5041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 505a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 5064a8c1344dccb848dbcf0edabc8b5c51a8ecf2808Trond Myklebust struct gss_auth *gss_auth = container_of(cred->cr_auth, 5071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth, rpc_auth); 5081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, 5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred, gc_base); 5101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 5115b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct inode *inode; 5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5148885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_refresh_upcall for uid %u\n", task->tk_pid, 5158885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever cred->cr_uid); 5161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg = gss_setup_upcall(task->tk_client, gss_auth, cred); 517480e3243df156e39eea6c91057e2ae612a6bbe19Roel Kluin if (PTR_ERR(gss_msg) == -EAGAIN) { 51879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ /* XXX: warning on the first, under the assumption we 51979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ * shouldn't normally hit this case on a refresh. */ 52079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ warn_gssd(); 52179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ task->tk_timeout = 15*HZ; 52279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ rpc_sleep_on(&pipe_version_rpc_waitqueue, task, NULL); 52379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ return 0; 52479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(gss_msg)) { 5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(gss_msg); 5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5295b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ inode = &gss_msg->inode->vfs_inode; 530b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_lock(&inode->i_lock); 5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_cred->gc_upcall != NULL) 5325d00837b90340af9106dcd93af75fd664c8eb87fTrond Myklebust rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL); 533126e216a8730532dfb685205309275f87e3d133eTrond Myklebust else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) { 5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds task->tk_timeout = 0; 5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_cred->gc_upcall = gss_msg; 5361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* gss_upcall_callback will release the reference to gss_upcall_msg */ 5371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 5385d00837b90340af9106dcd93af75fd664c8eb87fTrond Myklebust rpc_sleep_on(&gss_msg->rpc_waitqueue, task, gss_upcall_callback); 539126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } else { 540126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_handle_downcall_result(gss_cred, gss_msg); 5411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = gss_msg->msg.errno; 542126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } 543b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 5441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 5451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 5468885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_refresh_upcall for uid %u result %d\n", 5478885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever task->tk_pid, cred->cr_uid, err); 5481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 5491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 5521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred) 5531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5545b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ struct inode *inode; 5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_cred *cred = &gss_cred->gc_base; 5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 5571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(wait); 5581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 5591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5608885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_upcall for uid %u\n", cred->cr_uid); 56179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\retry: 5621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg = gss_setup_upcall(gss_auth->client, gss_auth, cred); 56379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (PTR_ERR(gss_msg) == -EAGAIN) { 56479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ err = wait_event_interruptible_timeout(pipe_version_waitqueue, 56579a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ pipe_version >= 0, 15*HZ); 56679a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (err) 56779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ goto out; 56879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (pipe_version < 0) 56979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ warn_gssd(); 57079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ goto retry; 57179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(gss_msg)) { 5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(gss_msg); 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5765b7ddd4a7b19f913901140ef7807dbf5e2b301cd\"J. Bruce Fields\ inode = &gss_msg->inode->vfs_inode; 5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { 5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prepare_to_wait(&gss_msg->waitqueue, &wait, TASK_INTERRUPTIBLE); 579b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_lock(&inode->i_lock); 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg->ctx != NULL || gss_msg->msg.errno < 0) { 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 583b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (signalled()) { 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ERESTARTSYS; 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_intr; 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule(); 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg->ctx) 5917b6962b0a6000df48c8a5fd967d262f77704101bTrond Myklebust gss_cred_set_ctx(cred, gss_msg->ctx); 5921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = gss_msg->msg.errno; 5945d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust spin_unlock(&inode->i_lock); 5951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_intr: 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds finish_wait(&gss_msg->waitqueue, &wait); 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 5998885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_create_upcall for uid %u result %d\n", 6008885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever cred->cr_uid, err); 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 6021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg, 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char __user *dst, size_t buflen) 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *data = (char *)msg->data + msg->copied; 6097df089952fca41cb336733e1167c0a25e5a025d8Chuck Lever size_t mlen = min(msg->len, buflen); 6107df089952fca41cb336733e1167c0a25e5a025d8Chuck Lever unsigned long left; 6111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds left = copy_to_user(dst, data, mlen); 6137df089952fca41cb336733e1167c0a25e5a025d8Chuck Lever if (left == mlen) { 6147df089952fca41cb336733e1167c0a25e5a025d8Chuck Lever msg->errno = -EFAULT; 6157df089952fca41cb336733e1167c0a25e5a025d8Chuck Lever return -EFAULT; 6161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6177df089952fca41cb336733e1167c0a25e5a025d8Chuck Lever 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mlen -= left; 6191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds msg->copied += mlen; 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds msg->errno = 0; 6211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return mlen; 6221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define MSG_BUF_MAXSIZE 1024 6251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 6271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) 6281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *p, *end; 6301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void *buf; 6311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 632b185f835e243e654047ae85f42346827d3894171Trond Myklebust struct inode *inode = filp->f_path.dentry->d_inode; 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx; 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds uid_t uid; 6353b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust ssize_t err = -EFBIG; 6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mlen > MSG_BUF_MAXSIZE) 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ENOMEM; 6400f38b873aeaae698c3693748438547c8493165fbTrond Myklebust buf = kmalloc(mlen, GFP_NOFS); 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!buf) 6421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -EFAULT; 6451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (copy_from_user(buf, src, mlen)) 6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds end = (const void *)((char *)buf + mlen); 6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(buf, end, &uid, sizeof(uid)); 6501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) { 6511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(p); 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ENOMEM; 6561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx = gss_alloc_context(); 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx == NULL) 6581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 6593b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust 6603b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust err = -ENOENT; 6613b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust /* Find a matching upcall */ 6623b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust spin_lock(&inode->i_lock); 6636e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust gss_msg = __gss_find_upcall(RPC_I(inode), uid); 6643b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust if (gss_msg == NULL) { 6653b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust spin_unlock(&inode->i_lock); 6663b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust goto err_put_ctx; 6673b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust } 6683b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust list_del_init(&gss_msg->list); 6693b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust spin_unlock(&inode->i_lock); 6703b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust 6716e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust p = gss_fill_context(p, end, ctx, gss_msg->auth->mech); 6721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) { 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(p); 674486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton switch (err) { 675486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -EACCES: 676dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton case -EKEYEXPIRED: 677486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton gss_msg->msg.errno = err; 678486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton err = mlen; 679486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton break; 680486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -EFAULT: 681486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -ENOMEM: 682486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -EINVAL: 683486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -ENOSYS: 684486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton gss_msg->msg.errno = -EAGAIN; 685486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton break; 686486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton default: 687486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton printk(KERN_CRIT "%s: bad return from " 6886c8530993e1fdf1d6af0403e796fe14d80b4b097Randy Dunlap "gss_fill_context: %zd\n", __func__, err); 689486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton BUG(); 690486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton } 6913b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust goto err_release_msg; 6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6933b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust gss_msg->ctx = gss_get_ctx(ctx); 6943b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust err = mlen; 6953b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust 6963b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebusterr_release_msg: 697b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_lock(&inode->i_lock); 6983b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust __gss_unhash_msg(gss_msg); 6993b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust spin_unlock(&inode->i_lock); 7003b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust gss_release_msg(gss_msg); 7011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr_put_ctx: 7021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 7031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr: 7041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(buf); 7051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 7063b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust dprintk("RPC: gss_pipe_downcall returning %Zd\n", err); 7071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 7081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 71034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static int gss_pipe_open(struct inode *inode, int new_version) 711cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\{ 71234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ int ret = 0; 71334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 71479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_lock(&pipe_version_lock); 71579a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (pipe_version < 0) { 71634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* First open of any gss pipe determines the version: */ 71734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ pipe_version = new_version; 71879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ rpc_wake_up(&pipe_version_rpc_waitqueue); 71979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ wake_up(&pipe_version_waitqueue); 72034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ } else if (pipe_version != new_version) { 72134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* Trying to open a pipe of a different version */ 72234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ ret = -EBUSY; 72334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ goto out; 72479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 725cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ atomic_inc(&pipe_users); 72634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\out: 72779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_unlock(&pipe_version_lock); 72834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ return ret; 72934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 73034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 73134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 73234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static int gss_pipe_open_v0(struct inode *inode) 73334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 73434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ return gss_pipe_open(inode, 0); 73534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 73634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 73734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static int gss_pipe_open_v1(struct inode *inode) 73834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 73934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ return gss_pipe_open(inode, 1); 740cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\} 741cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ 7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 7431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_release(struct inode *inode) 7441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_inode *rpci = RPC_I(inode); 7466e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust struct gss_upcall_msg *gss_msg; 7471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7485a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebustrestart: 749b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_lock(&inode->i_lock); 7505a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust list_for_each_entry(gss_msg, &rpci->in_downcall, list) { 7511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7525a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust if (!list_empty(&gss_msg->msg.list)) 7535a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust continue; 7541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg->msg.errno = -EPIPE; 7551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 7561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __gss_unhash_msg(gss_msg); 757b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 7581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 7595a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust goto restart; 7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 761b185f835e243e654047ae85f42346827d3894171Trond Myklebust spin_unlock(&inode->i_lock); 762cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ 76379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ put_pipe_version(); 7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 7671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_destroy_msg(struct rpc_pipe_msg *msg) 7681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg = container_of(msg, struct gss_upcall_msg, msg); 7701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (msg->errno < 0) { 7728885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_pipe_destroy_msg releasing msg %p\n", 7731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg); 7741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 7751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_unhash_msg(gss_msg); 776b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ if (msg->errno == -ETIMEDOUT) 777b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ warn_gssd(); 7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 7791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 782cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki/* 783cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki * NOTE: we have the opportunity to use different 7841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * parameters based on the input flavor (which must be a pseudoflavor) 7851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 7861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct rpc_auth * 7871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) 7881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *gss_auth; 7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_auth * auth; 7916a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields int err = -ENOMEM; /* XXX? */ 7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7938885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: creating GSS authenticator for client %p\n", clnt); 7941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!try_module_get(THIS_MODULE)) 7966a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields return ERR_PTR(err); 7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL))) 7981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_dec; 7991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth->client = clnt; 8006a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields err = -EINVAL; 8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor); 8021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!gss_auth->mech) { 8033392c34922130d1dca9ad436c358330daa85e94eJames Morris printk(KERN_WARNING "%s: Pseudoflavor %d not found!\n", 8040dc47877a3de00ceadea0005189656ae8dc52669Harvey Harrison __func__, flavor); 8051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err_free; 8061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth->service = gss_pseudoflavor_to_service(gss_auth->mech, flavor); 808438b6fdebf2a2e8573e7290bc176feb4d4475f43J. Bruce Fields if (gss_auth->service == 0) 809438b6fdebf2a2e8573e7290bc176feb4d4475f43J. Bruce Fields goto err_put_mech; 8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth = &gss_auth->rpc_auth; 8111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_cslack = GSS_CRED_SLACK >> 2; 8121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_rslack = GSS_VERF_SLACK >> 2; 8131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_ops = &authgss_ops; 8141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_flavor = flavor; 8151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_set(&auth->au_count, 1); 8160285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kref_init(&gss_auth->kref); 8171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 81834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* 81934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * Note: if we created the old pipe first, then someone who 82034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * examined the directory at the right moment might conclude 82134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * that we supported only the old pipe. So we instead create 82234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * the new pipe first. 82334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ */ 8247d217caca5d704e48aa5e59aba0b3ad4c7af4fd2Trond Myklebust gss_auth->dentry[1] = rpc_mkpipe(clnt->cl_path.dentry, 82534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ "gssd", 82634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ clnt, &gss_upcall_ops_v1, 82734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ RPC_PIPE_WAIT_FOR_OPEN); 82834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ if (IS_ERR(gss_auth->dentry[1])) { 82934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ err = PTR_ERR(gss_auth->dentry[1]); 8301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err_put_mech; 8316a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields } 8321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8337d217caca5d704e48aa5e59aba0b3ad4c7af4fd2Trond Myklebust gss_auth->dentry[0] = rpc_mkpipe(clnt->cl_path.dentry, 83434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_auth->mech->gm_name, 83534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ clnt, &gss_upcall_ops_v0, 83634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ RPC_PIPE_WAIT_FOR_OPEN); 83734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ if (IS_ERR(gss_auth->dentry[0])) { 83834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ err = PTR_ERR(gss_auth->dentry[0]); 83934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ goto err_unlink_pipe_1; 84034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ } 841f5c2187cfef628784d8a09b6d0f77888246d0c0fTrond Myklebust err = rpcauth_init_credcache(auth); 84207a2bf1da4765d987ffd1d8045e92ba032e0ad78Trond Myklebust if (err) 84334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ goto err_unlink_pipe_0; 84407a2bf1da4765d987ffd1d8045e92ba032e0ad78Trond Myklebust 8451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return auth; 84634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\err_unlink_pipe_0: 84734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ rpc_unlink(gss_auth->dentry[0]); 84834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\err_unlink_pipe_1: 84934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ rpc_unlink(gss_auth->dentry[1]); 8501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr_put_mech: 8511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_mech_put(gss_auth->mech); 8521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr_free: 8531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(gss_auth); 8541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_dec: 8551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds module_put(THIS_MODULE); 8566a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields return ERR_PTR(err); 8571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 8600285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebustgss_free(struct gss_auth *gss_auth) 8610285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust{ 86234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ rpc_unlink(gss_auth->dentry[1]); 86334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ rpc_unlink(gss_auth->dentry[0]); 8640285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust gss_mech_put(gss_auth->mech); 8650285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 8660285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kfree(gss_auth); 8670285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust module_put(THIS_MODULE); 8680285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust} 8690285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 8700285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebuststatic void 8710285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebustgss_free_callback(struct kref *kref) 8720285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust{ 8730285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust struct gss_auth *gss_auth = container_of(kref, struct gss_auth, kref); 8740285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 8750285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust gss_free(gss_auth); 8760285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust} 8770285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 8780285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebuststatic void 8791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_destroy(struct rpc_auth *auth) 8801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 8811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *gss_auth; 8821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8838885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: destroying GSS authenticator %p flavor %d\n", 8848885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever auth, auth->au_flavor); 8851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8863ab9bb7243489f9db3abf3d05521ddfc6b184c0aTrond Myklebust rpcauth_destroy_credcache(auth); 8873ab9bb7243489f9db3abf3d05521ddfc6b184c0aTrond Myklebust 8881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth = container_of(auth, struct gss_auth, rpc_auth); 8890285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kref_put(&gss_auth->kref, gss_free_callback); 8901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8920df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust/* 8930df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * gss_destroying_context will cause the RPCSEC_GSS to send a NULL RPC call 8940df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * to the server with the GSS control procedure field set to 8950df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * RPC_GSS_PROC_DESTROY. This should normally cause the server to release 8960df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * all RPCSEC_GSS state associated with that context. 8970df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust */ 8980df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic int 8990df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebustgss_destroying_context(struct rpc_cred *cred) 9000df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust{ 9010df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 9020df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust struct gss_auth *gss_auth = container_of(cred->cr_auth, struct gss_auth, rpc_auth); 9030df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust struct rpc_task *task; 9040df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 9050df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust if (gss_cred->gc_ctx == NULL || 9066dcd3926b214a1fb081df18305921dedae269977Jeff Layton test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) == 0) 9070df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust return 0; 9080df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 9090df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust gss_cred->gc_ctx->gc_proc = RPC_GSS_PROC_DESTROY; 9100df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust cred->cr_ops = &gss_nullops; 9110df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 9120df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust /* Take a reference to ensure the cred will be destroyed either 9130df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * by the RPC call or by the put_rpccred() below */ 9140df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust get_rpccred(cred); 9150df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 916080a1f148df0615f7a610e4776dd8f3fb706f54fTrond Myklebust task = rpc_call_null(gss_auth->client, cred, RPC_TASK_ASYNC|RPC_TASK_SOFT); 9170df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust if (!IS_ERR(task)) 9180df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust rpc_put_task(task); 9190df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 9200df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust put_rpccred(cred); 9210df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust return 1; 9220df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust} 9230df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 9240df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust/* gss_destroy_cred (and gss_free_ctx) are used to clean up after failure 9251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to create a new cred or context, so they check that things have been 9261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * allocated before freeing them. */ 9271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 9285d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebustgss_do_free_ctx(struct gss_cl_ctx *ctx) 9291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9305d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust dprintk("RPC: gss_free_ctx\n"); 9311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9320d8a374673c9bc62bc78a2d8fe64553a51542cb4Trond Myklebust gss_delete_sec_context(&ctx->gc_gss_ctx); 9331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(ctx->gc_wire_ctx.data); 9341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(ctx); 9351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 9385d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebustgss_free_ctx_callback(struct rcu_head *head) 9395d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust{ 9405d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust struct gss_cl_ctx *ctx = container_of(head, struct gss_cl_ctx, gc_rcu); 9415d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust gss_do_free_ctx(ctx); 9425d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust} 9435d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 9445d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebuststatic void 9455d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebustgss_free_ctx(struct gss_cl_ctx *ctx) 9465d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust{ 9475d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust call_rcu(&ctx->gc_rcu, gss_free_ctx_callback); 9485d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust} 9495d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 9505d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebuststatic void 95131be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebustgss_free_cred(struct gss_cred *gss_cred) 9521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 95331be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust dprintk("RPC: gss_free_cred %p\n", gss_cred); 95431be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust kfree(gss_cred); 95531be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust} 9561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 95731be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebuststatic void 95831be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebustgss_free_cred_callback(struct rcu_head *head) 95931be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust{ 96031be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust struct gss_cred *gss_cred = container_of(head, struct gss_cred, gc_base.cr_rcu); 96131be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust gss_free_cred(gss_cred); 96231be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust} 9631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 96431be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebuststatic void 9656dcd3926b214a1fb081df18305921dedae269977Jeff Laytongss_destroy_nullcred(struct rpc_cred *cred) 96631be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust{ 9675d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 9680285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust struct gss_auth *gss_auth = container_of(cred->cr_auth, struct gss_auth, rpc_auth); 9695d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust struct gss_cl_ctx *ctx = gss_cred->gc_ctx; 9705d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 9715d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust rcu_assign_pointer(gss_cred->gc_ctx, NULL); 97231be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust call_rcu(&cred->cr_rcu, gss_free_cred_callback); 9735d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust if (ctx) 9745d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust gss_put_ctx(ctx); 9750285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kref_put(&gss_auth->kref, gss_free_callback); 9761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9786dcd3926b214a1fb081df18305921dedae269977Jeff Laytonstatic void 9796dcd3926b214a1fb081df18305921dedae269977Jeff Laytongss_destroy_cred(struct rpc_cred *cred) 9806dcd3926b214a1fb081df18305921dedae269977Jeff Layton{ 9816dcd3926b214a1fb081df18305921dedae269977Jeff Layton 9826dcd3926b214a1fb081df18305921dedae269977Jeff Layton if (gss_destroying_context(cred)) 9836dcd3926b214a1fb081df18305921dedae269977Jeff Layton return; 9846dcd3926b214a1fb081df18305921dedae269977Jeff Layton gss_destroy_nullcred(cred); 9856dcd3926b214a1fb081df18305921dedae269977Jeff Layton} 9866dcd3926b214a1fb081df18305921dedae269977Jeff Layton 9871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 9881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Lookup RPCSEC_GSS cred for the current process 9891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 9901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct rpc_cred * 9918a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustgss_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) 9921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9938a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebust return rpcauth_lookup_credcache(auth, acred, flags); 9941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct rpc_cred * 9978a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustgss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) 9981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth); 10001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *cred = NULL; 10011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = -ENOMEM; 10021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10038885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_create_cred for uid %d, flavor %d\n", 10041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds acred->uid, auth->au_flavor); 10051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10060f38b873aeaae698c3693748438547c8493165fbTrond Myklebust if (!(cred = kzalloc(sizeof(*cred), GFP_NOFS))) 10071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_err; 10081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10095fe4755e2526a2aa82b7ed8daeb3aed74a236925Trond Myklebust rpcauth_init_cred(&cred->gc_base, acred, auth, &gss_credops); 10101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 10111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note: in order to force a call to call_refresh(), we deliberately 10121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fail to flag the credential as RPCAUTH_CRED_UPTODATE. 10131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1014fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW; 10151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cred->gc_service = gss_auth->service; 10167c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust cred->gc_machine_cred = acred->machine_cred; 10170285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kref_get(&gss_auth->kref); 10181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &cred->gc_base; 10191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_err: 10218885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: gss_create_cred failed with error %d\n", err); 10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(err); 10231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 1026fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebustgss_cred_init(struct rpc_auth *auth, struct rpc_cred *cred) 1027fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust{ 1028fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth); 1029fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust struct gss_cred *gss_cred = container_of(cred,struct gss_cred, gc_base); 1030fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust int err; 1031fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust 1032fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust do { 1033fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust err = gss_create_upcall(gss_auth, gss_cred); 1034fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust } while (err == -EAGAIN); 1035fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust return err; 1036fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust} 1037fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust 1038fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebuststatic int 10398a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustgss_match(struct auth_cred *acred, struct rpc_cred *rc, int flags) 10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base); 10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1043cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (test_bit(RPCAUTH_CRED_NEW, &rc->cr_flags)) 10448a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebust goto out; 10451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Don't match with creds that have expired. */ 1046cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (time_after(jiffies, gss_cred->gc_ctx->gc_expiry)) 1047cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return 0; 1048cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (!test_bit(RPCAUTH_CRED_UPTODATE, &rc->cr_flags)) 10491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 10508a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustout: 10517c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust if (acred->machine_cred != gss_cred->gc_machine_cred) 10527c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust return 0; 1053a02cec2155fbea457eca8881870fd2de1a4c4c76Eric Dumazet return rc->cr_uid == acred->uid; 10541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 10571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds* Marshal credentials. 10581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds* Maybe we should keep a cached credential for performance reasons. 10591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/ 1060d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic __be32 * 1061d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyangss_marshal(struct rpc_task *task, __be32 *p) 10621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1063a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_rqst *req = task->tk_rqstp; 1064a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = req->rq_cred; 10651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 10661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gc_base); 10671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 1068d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *cred_len; 10691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat = 0; 10701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 10711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct kvec iov; 10721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf verf_buf; 10731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10748885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_marshal\n", task->tk_pid); 10751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl(RPC_AUTH_GSS); 10771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cred_len = p++; 10781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock(&ctx->gc_seq_lock); 10801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds req->rq_seqno = ctx->gc_seq++; 10811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock(&ctx->gc_seq_lock); 10821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) RPC_GSS_VERSION); 10841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) ctx->gc_proc); 10851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) req->rq_seqno); 10861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) gss_cred->gc_service); 10871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = xdr_encode_netobj(p, &ctx->gc_wire_ctx); 10881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *cred_len = htonl((p - (cred_len + 1)) << 2); 10891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We compute the checksum for the verifier over the xdr-encoded bytes 10911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * starting with the xid and ending at the end of the credential: */ 1092808012fbb23a52ec59352445d2076d175ad4ab26Chuck Lever iov.iov_base = xprt_skip_transport_header(task->tk_xprt, 1093808012fbb23a52ec59352445d2076d175ad4ab26Chuck Lever req->rq_snd_buf.head[0].iov_base); 10941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov.iov_len = (u8 *)p - (u8 *)iov.iov_base; 10951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds xdr_buf_from_iov(&iov, &verf_buf); 10961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* set verifier flavor*/ 10981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl(RPC_AUTH_GSS); 10991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.data = (u8 *)(p + 1); 110100fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_get_mic(ctx->gc_gss_ctx, &verf_buf, &mic); 11021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) { 1103fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 11041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (maj_stat != 0) { 11051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk("gss_marshal: gss_get_mic FAILED (%d)\n", maj_stat); 11061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_put_ctx; 11071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = xdr_encode_opaque(p, NULL, mic.len); 11091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 11101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p; 11111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_put_ctx: 11121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 11131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 11141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1116cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebuststatic int gss_renew_cred(struct rpc_task *task) 1117cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust{ 1118a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *oldcred = task->tk_rqstp->rq_cred; 1119cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct gss_cred *gss_cred = container_of(oldcred, 1120cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct gss_cred, 1121cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust gc_base); 1122cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct rpc_auth *auth = oldcred->cr_auth; 1123cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct auth_cred acred = { 1124cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust .uid = oldcred->cr_uid, 1125cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust .machine_cred = gss_cred->gc_machine_cred, 1126cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust }; 1127cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct rpc_cred *new; 1128cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust 1129cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust new = gss_lookup_cred(auth, &acred, RPCAUTH_LOOKUP_NEW); 1130cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (IS_ERR(new)) 1131cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return PTR_ERR(new); 1132a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust task->tk_rqstp->rq_cred = new; 1133cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust put_rpccred(oldcred); 1134cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return 0; 1135cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust} 1136cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust 1137126e216a8730532dfb685205309275f87e3d133eTrond Myklebuststatic int gss_cred_is_negative_entry(struct rpc_cred *cred) 1138126e216a8730532dfb685205309275f87e3d133eTrond Myklebust{ 1139126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (test_bit(RPCAUTH_CRED_NEGATIVE, &cred->cr_flags)) { 1140126e216a8730532dfb685205309275f87e3d133eTrond Myklebust unsigned long now = jiffies; 1141126e216a8730532dfb685205309275f87e3d133eTrond Myklebust unsigned long begin, expire; 1142126e216a8730532dfb685205309275f87e3d133eTrond Myklebust struct gss_cred *gss_cred; 1143126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 1144126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred = container_of(cred, struct gss_cred, gc_base); 1145126e216a8730532dfb685205309275f87e3d133eTrond Myklebust begin = gss_cred->gc_upcall_timestamp; 1146126e216a8730532dfb685205309275f87e3d133eTrond Myklebust expire = begin + gss_expired_cred_retry_delay * HZ; 1147126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 1148126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (time_in_range_open(now, begin, expire)) 1149126e216a8730532dfb685205309275f87e3d133eTrond Myklebust return 1; 1150126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } 1151126e216a8730532dfb685205309275f87e3d133eTrond Myklebust return 0; 1152126e216a8730532dfb685205309275f87e3d133eTrond Myklebust} 1153126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 11541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 11551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds* Refresh credentials. XXX - finish 11561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/ 11571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 11581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_refresh(struct rpc_task *task) 11591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1160a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 1161cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust int ret = 0; 1162cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust 1163126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (gss_cred_is_negative_entry(cred)) 1164126e216a8730532dfb685205309275f87e3d133eTrond Myklebust return -EKEYEXPIRED; 1165126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 1166cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) && 1167cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust !test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags)) { 1168cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust ret = gss_renew_cred(task); 1169cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (ret < 0) 1170cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust goto out; 1171a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust cred = task->tk_rqstp->rq_cred; 1172cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust } 11731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1174cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags)) 1175cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust ret = gss_refresh_upcall(task); 1176cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebustout: 1177cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return ret; 11781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11800df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust/* Dummy refresh routine: used only when destroying the context */ 11810df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic int 11820df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebustgss_refresh_null(struct rpc_task *task) 11830df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust{ 11840df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust return -EACCES; 11850df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust} 11860df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 1187d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic __be32 * 1188d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyangss_validate(struct rpc_task *task, __be32 *p) 11891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1190a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 11911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 1192d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 seq; 11931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct kvec iov; 11941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf verf_buf; 11951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 11961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 flav,len; 11971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat; 11981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11998885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_validate\n", task->tk_pid); 12001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds flav = ntohl(*p++); 12021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((len = ntohl(*p++)) > RPC_MAX_AUTH_SIZE) 1203cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki goto out_bad; 12041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (flav != RPC_AUTH_GSS) 12051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_bad; 12061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds seq = htonl(task->tk_rqstp->rq_seqno); 12071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov.iov_base = &seq; 12081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov.iov_len = sizeof(seq); 12091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds xdr_buf_from_iov(&iov, &verf_buf); 12101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.data = (u8 *)p; 12111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.len = len; 12121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 121300fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &verf_buf, &mic); 12141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1215fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 12160df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust if (maj_stat) { 1217014313a9d66272ed37b9ebd64c3f30b596a4c8e1Joe Perches dprintk("RPC: %5u gss_validate: gss_verify_mic returned " 12180df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust "error 0x%08x\n", task->tk_pid, maj_stat); 12191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_bad; 12200df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust } 122124b2605becc10ca63c4c30808fa59a8abbf68727J. Bruce Fields /* We leave it to unwrap to calculate au_rslack. For now we just 122224b2605becc10ca63c4c30808fa59a8abbf68727J. Bruce Fields * calculate the length of the verifier: */ 12231be27f36601973815171db684c711d30557cf50cTrond Myklebust cred->cr_auth->au_verfsize = XDR_QUADLEN(len) + 2; 12241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 12258885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_validate: gss_verify_mic succeeded.\n", 12261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds task->tk_pid); 12271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p + XDR_QUADLEN(len); 12281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_bad: 12291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 12308885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_validate failed.\n", task->tk_pid); 12311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 12321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12349f06c719f474be7003763284a990bed6377bb0d4Chuck Leverstatic void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp, 12359f06c719f474be7003763284a990bed6377bb0d4Chuck Lever __be32 *p, void *obj) 12369f06c719f474be7003763284a990bed6377bb0d4Chuck Lever{ 12379f06c719f474be7003763284a990bed6377bb0d4Chuck Lever struct xdr_stream xdr; 12389f06c719f474be7003763284a990bed6377bb0d4Chuck Lever 12399f06c719f474be7003763284a990bed6377bb0d4Chuck Lever xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p); 12409f06c719f474be7003763284a990bed6377bb0d4Chuck Lever encode(rqstp, &xdr, obj); 12419f06c719f474be7003763284a990bed6377bb0d4Chuck Lever} 12429f06c719f474be7003763284a990bed6377bb0d4Chuck Lever 12431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 12441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 12459f06c719f474be7003763284a990bed6377bb0d4Chuck Lever kxdreproc_t encode, struct rpc_rqst *rqstp, 12469f06c719f474be7003763284a990bed6377bb0d4Chuck Lever __be32 *p, void *obj) 12471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 12481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 12491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf integ_buf; 1250d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *integ_len = NULL; 12511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 1252d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan u32 offset; 1253d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *q; 12541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct kvec *iov; 12551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat = 0; 12561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 12571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds integ_len = p++; 12591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base; 12601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl(rqstp->rq_seqno); 12611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12629f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 12631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (xdr_buf_subsegment(snd_buf, &integ_buf, 12651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset, snd_buf->len - offset)) 12661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 12671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *integ_len = htonl(integ_buf.len); 12681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* guess whether we're in the head or the tail: */ 1270cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki if (snd_buf->page_len || snd_buf->tail[0].iov_len) 12711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov = snd_buf->tail; 12721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 12731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov = snd_buf->head; 12741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = iov->iov_base + iov->iov_len; 12751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.data = (u8 *)(p + 1); 12761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 127700fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_get_mic(ctx->gc_gss_ctx, &integ_buf, &mic); 12781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = -EIO; /* XXX? */ 12791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1280fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 12811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else if (maj_stat) 12821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 12831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q = xdr_encode_opaque(p, NULL, mic.len); 12841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset = (u8 *)q - (u8 *)p; 12861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov->iov_len += offset; 12871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds snd_buf->len += offset; 12881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 12891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12912d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic void 12922d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldspriv_release_snd_buf(struct rpc_rqst *rqstp) 12932d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 12942d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int i; 12952d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 12962d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields for (i=0; i < rqstp->rq_enc_pages_num; i++) 12972d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields __free_page(rqstp->rq_enc_pages[i]); 12982d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields kfree(rqstp->rq_enc_pages); 12992d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 13002d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13012d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic int 13022d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsalloc_enc_pages(struct rpc_rqst *rqstp) 13032d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 13042d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 13052d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int first, last, i; 13062d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13072d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (snd_buf->page_len == 0) { 13082d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages_num = 0; 13092d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 13102d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields } 13112d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13122d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields first = snd_buf->page_base >> PAGE_CACHE_SHIFT; 13132d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields last = (snd_buf->page_base + snd_buf->page_len - 1) >> PAGE_CACHE_SHIFT; 13142d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages_num = last - first + 1 + 1; 13152d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages 13162d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields = kmalloc(rqstp->rq_enc_pages_num * sizeof(struct page *), 13172d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields GFP_NOFS); 13182d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (!rqstp->rq_enc_pages) 13192d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields goto out; 13202d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields for (i=0; i < rqstp->rq_enc_pages_num; i++) { 13212d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages[i] = alloc_page(GFP_NOFS); 13222d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (rqstp->rq_enc_pages[i] == NULL) 13232d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields goto out_free; 13242d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields } 13252d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_release_snd_buf = priv_release_snd_buf; 13262d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 13272d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsout_free: 1328cdead7cf12896c0e50a8be2e52de52c364603095Trond Myklebust rqstp->rq_enc_pages_num = i; 1329cdead7cf12896c0e50a8be2e52de52c364603095Trond Myklebust priv_release_snd_buf(rqstp); 13302d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsout: 13312d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return -EAGAIN; 13322d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 13332d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13342d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic inline int 13352d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsgss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 13369f06c719f474be7003763284a990bed6377bb0d4Chuck Lever kxdreproc_t encode, struct rpc_rqst *rqstp, 13379f06c719f474be7003763284a990bed6377bb0d4Chuck Lever __be32 *p, void *obj) 13382d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 13392d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 13402d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 offset; 13412d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 maj_stat; 13422d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int status; 1343d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *opaque_len; 13442d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct page **inpages; 13452d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int first; 13462d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int pad; 13472d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct kvec *iov; 13482d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields char *tmp; 13492d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13502d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields opaque_len = p++; 13512d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base; 13522d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields *p++ = htonl(rqstp->rq_seqno); 13532d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13549f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 13552d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13562d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields status = alloc_enc_pages(rqstp); 13572d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (status) 13582d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 13592d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields first = snd_buf->page_base >> PAGE_CACHE_SHIFT; 13602d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields inpages = snd_buf->pages + first; 13612d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->pages = rqstp->rq_enc_pages; 13622d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->page_base -= first << PAGE_CACHE_SHIFT; 13637561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman /* 13647561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * Give the tail its own page, in case we need extra space in the 13657561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * head when wrapping: 13667561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * 13677561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * call_allocate() allocates twice the slack space required 13687561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * by the authentication flavor to rq_callsize. 13697561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * For GSS, slack is GSS_CRED_SLACK. 13707561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman */ 13712d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (snd_buf->page_len || snd_buf->tail[0].iov_len) { 13722d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields tmp = page_address(rqstp->rq_enc_pages[rqstp->rq_enc_pages_num - 1]); 13732d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields memcpy(tmp, snd_buf->tail[0].iov_base, snd_buf->tail[0].iov_len); 13742d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->tail[0].iov_base = tmp; 13752d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields } 137600fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_wrap(ctx->gc_gss_ctx, offset, snd_buf, inpages); 13777561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman /* slack space should prevent this ever happening: */ 13782d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields BUG_ON(snd_buf->len > snd_buf->buflen); 1379cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki status = -EIO; 13802d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields /* We're assuming that when GSS_S_CONTEXT_EXPIRED, the encryption was 13812d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields * done anyway, so it's safe to put the request on the wire: */ 13822d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1383fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 13842d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields else if (maj_stat) 13852d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 13862d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13872d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields *opaque_len = htonl(snd_buf->len - offset); 13882d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields /* guess whether we're in the head or the tail: */ 13892d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (snd_buf->page_len || snd_buf->tail[0].iov_len) 13902d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields iov = snd_buf->tail; 13912d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields else 13922d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields iov = snd_buf->head; 13932d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields p = iov->iov_base + iov->iov_len; 13942d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields pad = 3 - ((snd_buf->len - offset - 1) & 3); 13952d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields memset(p, 0, pad); 13962d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields iov->iov_len += pad; 13972d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->len += pad; 13982d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 13992d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 14002d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 14012d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 14021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 14031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_wrap_req(struct rpc_task *task, 14049f06c719f474be7003763284a990bed6377bb0d4Chuck Lever kxdreproc_t encode, void *rqstp, __be32 *p, void *obj) 14051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1406a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 14071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 14081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gc_base); 14091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 14101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 14111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14128885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_wrap_req\n", task->tk_pid); 14131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx->gc_proc != RPC_GSS_PROC_DATA) { 14141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* The spec seems a little ambiguous here, but I think that not 14151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wrapping context destruction requests makes the most sense. 14161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 14179f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 14189f06c719f474be7003763284a990bed6377bb0d4Chuck Lever status = 0; 14191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 14201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (gss_cred->gc_service) { 14221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case RPC_GSS_SVC_NONE: 14239f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 14249f06c719f474be7003763284a990bed6377bb0d4Chuck Lever status = 0; 14251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 14261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case RPC_GSS_SVC_INTEGRITY: 14271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = gss_wrap_req_integ(cred, ctx, encode, 14281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rqstp, p, obj); 14291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 1430cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki case RPC_GSS_SVC_PRIVACY: 14312d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields status = gss_wrap_req_priv(cred, ctx, encode, 14322d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp, p, obj); 14331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 14341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 14361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 14378885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_wrap_req returning %d\n", task->tk_pid, status); 14381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 14401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 14421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_unwrap_resp_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 1443d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan struct rpc_rqst *rqstp, __be32 **p) 14441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 14451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf; 14461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf integ_buf; 14471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 14481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 data_offset, mic_offset; 14491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 integ_len; 14501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat; 14511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 14521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds integ_len = ntohl(*(*p)++); 14541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (integ_len & 3) 14551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data_offset = (u8 *)(*p) - (u8 *)rcv_buf->head[0].iov_base; 14571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic_offset = integ_len + data_offset; 14581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mic_offset > rcv_buf->len) 14591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ntohl(*(*p)++) != rqstp->rq_seqno) 14611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (xdr_buf_subsegment(rcv_buf, &integ_buf, data_offset, 14641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic_offset - data_offset)) 14651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (xdr_buf_read_netobj(rcv_buf, &mic, mic_offset)) 14681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 147000fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &integ_buf, &mic); 14711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1472fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 14731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat != GSS_S_COMPLETE) 14741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 14751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 14761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 14771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14782d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic inline int 14792d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsgss_unwrap_resp_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 1480d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan struct rpc_rqst *rqstp, __be32 **p) 14812d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 14822d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf; 14832d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 offset; 14842d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 opaque_len; 14852d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 maj_stat; 14862d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int status = -EIO; 14872d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 14882d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields opaque_len = ntohl(*(*p)++); 14892d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields offset = (u8 *)(*p) - (u8 *)rcv_buf->head[0].iov_base; 14902d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (offset + opaque_len > rcv_buf->len) 14912d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 14922d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields /* remove padding: */ 14932d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rcv_buf->len = offset + opaque_len; 14942d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 149500fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_unwrap(ctx->gc_gss_ctx, offset, rcv_buf); 14962d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1497fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 14982d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (maj_stat != GSS_S_COMPLETE) 14992d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 15002d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (ntohl(*(*p)++) != rqstp->rq_seqno) 15012d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 15022d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 15032d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 15042d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 15052d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 1506bf2695516db982e90a22fc94f93491b481796bb1Chuck Leverstatic int 1507bf2695516db982e90a22fc94f93491b481796bb1Chuck Levergss_unwrap_req_decode(kxdrdproc_t decode, struct rpc_rqst *rqstp, 1508bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever __be32 *p, void *obj) 1509bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever{ 1510bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever struct xdr_stream xdr; 1511bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever 1512bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 1513bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever return decode(rqstp, &xdr, obj); 1514bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever} 15152d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 15161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 15171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_unwrap_resp(struct rpc_task *task, 1518bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever kxdrdproc_t decode, void *rqstp, __be32 *p, void *obj) 15191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1520a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 15211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 15221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gc_base); 15231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 1524d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *savedp = p; 15252d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct kvec *head = ((struct rpc_rqst *)rqstp)->rq_rcv_buf.head; 15262d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int savedlen = head->iov_len; 15271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 15281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx->gc_proc != RPC_GSS_PROC_DATA) 15301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_decode; 15311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (gss_cred->gc_service) { 15321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case RPC_GSS_SVC_NONE: 15331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 15341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case RPC_GSS_SVC_INTEGRITY: 15351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = gss_unwrap_resp_integ(cred, ctx, rqstp, &p); 15361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (status) 15371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 15381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 1539cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki case RPC_GSS_SVC_PRIVACY: 15402d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields status = gss_unwrap_resp_priv(cred, ctx, rqstp, &p); 15412d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (status) 15422d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields goto out; 15431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 15441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 154524b2605becc10ca63c4c30808fa59a8abbf68727J. Bruce Fields /* take into account extra slack for integrity and privacy cases: */ 15461be27f36601973815171db684c711d30557cf50cTrond Myklebust cred->cr_auth->au_rslack = cred->cr_auth->au_verfsize + (p - savedp) 15472d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields + (savedlen - head->iov_len); 15481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_decode: 1549bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever status = gss_unwrap_req_decode(decode, rqstp, p, obj); 15501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 15511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 15528885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: %5u gss_unwrap_resp returning %d\n", task->tk_pid, 15531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status); 15541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 15551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1556cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki 1557f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_authops authgss_ops = { 15581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .owner = THIS_MODULE, 15591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .au_flavor = RPC_AUTH_GSS, 15601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .au_name = "RPCSEC_GSS", 15611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .create = gss_create, 15621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .destroy = gss_destroy, 15631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .lookup_cred = gss_lookup_cred, 15641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crcreate = gss_create_cred 15651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 15661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1567f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_credops gss_credops = { 15681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .cr_name = "AUTH_GSS", 15691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crdestroy = gss_destroy_cred, 1570fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust .cr_init = gss_cred_init, 15715c691044ecbca04dd558fca4c754121689fe1b34Trond Myklebust .crbind = rpcauth_generic_bind_cred, 15721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crmatch = gss_match, 15731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crmarshal = gss_marshal, 15741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crrefresh = gss_refresh, 15751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crvalidate = gss_validate, 15761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crwrap_req = gss_wrap_req, 15771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crunwrap_resp = gss_unwrap_resp, 15781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 15791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15800df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic const struct rpc_credops gss_nullops = { 15810df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .cr_name = "AUTH_GSS", 15826dcd3926b214a1fb081df18305921dedae269977Jeff Layton .crdestroy = gss_destroy_nullcred, 15835c691044ecbca04dd558fca4c754121689fe1b34Trond Myklebust .crbind = rpcauth_generic_bind_cred, 15840df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crmatch = gss_match, 15850df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crmarshal = gss_marshal, 15860df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crrefresh = gss_refresh_null, 15870df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crvalidate = gss_validate, 15880df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crwrap_req = gss_wrap_req, 15890df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crunwrap_resp = gss_unwrap_resp, 15900df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust}; 15910df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 1592b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v0 = { 159334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .upcall = gss_pipe_upcall, 159434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .downcall = gss_pipe_downcall, 159534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .destroy_msg = gss_pipe_destroy_msg, 159634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .open_pipe = gss_pipe_open_v0, 159734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .release_pipe = gss_pipe_release, 159834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\}; 159934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 1600b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v1 = { 16011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .upcall = gss_pipe_upcall, 16021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .downcall = gss_pipe_downcall, 16031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .destroy_msg = gss_pipe_destroy_msg, 160434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .open_pipe = gss_pipe_open_v1, 16051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .release_pipe = gss_pipe_release, 16061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 16071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 16091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Initialize RPCSEC_GSS module 16101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 16111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init init_rpcsec_gss(void) 16121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 16131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 16141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = rpcauth_register(&authgss_ops); 16161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) 16171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 16181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = gss_svc_init(); 16191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) 16201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_unregister; 162179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ rpc_init_wait_queue(&pipe_version_rpc_waitqueue, "gss pipe version"); 16221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 16231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_unregister: 16241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rpcauth_unregister(&authgss_ops); 16251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 16261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 16271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit exit_rpcsec_gss(void) 16301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 16311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_svc_shutdown(); 16321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rpcauth_unregister(&authgss_ops); 1633bf12691d846b48fa6e3289810a822687457036cfJesper Dangaard Brouer rcu_barrier(); /* Wait for completion of call_rcu()'s */ 16341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 1637126e216a8730532dfb685205309275f87e3d133eTrond Myklebustmodule_param_named(expired_cred_retry_delay, 1638126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_expired_cred_retry_delay, 1639126e216a8730532dfb685205309275f87e3d133eTrond Myklebust uint, 0644); 1640126e216a8730532dfb685205309275f87e3d133eTrond MyklebustMODULE_PARM_DESC(expired_cred_retry_delay, "Timeout (in seconds) until " 1641126e216a8730532dfb685205309275f87e3d133eTrond Myklebust "the RPC engine retries an expired credential"); 1642126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 16431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(init_rpcsec_gss) 16441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(exit_rpcsec_gss) 1645