auth_gss.c revision 9eb2ddb48ce3a7bd745c14a933112994647fa3cd
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> 54eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust#include <linux/hashtable.h> 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 56abfdbd53a4e28844ad953b313f017f55edbb85b7Trond Myklebust#include "../netns.h" 57abfdbd53a4e28844ad953b313f017f55edbb85b7Trond Myklebust 58f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_authops authgss_ops; 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 60f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_credops gss_credops; 610df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic const struct rpc_credops gss_nullops; 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 63126e216a8730532dfb685205309275f87e3d133eTrond Myklebust#define GSS_RETRY_EXPIRED 5 64126e216a8730532dfb685205309275f87e3d133eTrond Myklebuststatic unsigned int gss_expired_cred_retry_delay = GSS_RETRY_EXPIRED; 65126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 664de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson#define GSS_KEY_EXPIRE_TIMEO 240 674de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamsonstatic unsigned int gss_key_expire_timeo = GSS_KEY_EXPIRE_TIMEO; 684de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef RPC_DEBUG 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds# define RPCDBG_FACILITY RPCDBG_AUTH 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 73725f2865d4df31ac0768b13ae763beadc4bb8ce9Kevin Coffman#define GSS_CRED_SLACK (RPC_MAX_AUTH_SIZE * 2) 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* length of a krb5 verifier (48), plus data added before arguments when 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * using integrity (two 4-byte integers): */ 76adeb8133dd57f380e70a389a89a2ea3ae227f9e2Olga Kornievskaia#define GSS_VERF_SLACK 100 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7823c323af0375a7f63732bed0386aba5935b8de69Trond Myklebuststatic DEFINE_HASHTABLE(gss_auth_hash_table, 4); 79eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebuststatic DEFINE_SPINLOCK(gss_auth_hash_lock); 80eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 811917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststruct gss_pipe { 821917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_pipe_dir_object pdo; 831917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_pipe *pipe; 841917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_clnt *clnt; 851917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust const char *name; 86414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct kref kref; 871917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust}; 881917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct gss_auth { 900285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust struct kref kref; 91eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct hlist_node hash; 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_auth rpc_auth; 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_api_mech *mech; 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum rpc_gss_svc service; 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_clnt *client; 96e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust struct net *net; 9734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* 9834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * There are two upcall pipes; dentry[1], named "gssd", is used 9934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * for the new text-based upcall; dentry[0] is named after the 10034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * mechanism (for example, "krb5") and exists for 10134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * backwards-compatibility with older gssd's. 10234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ */ 1031917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_pipe *gss_pipe[2]; 104bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust const char *target_name; 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\/* pipe_version >= 0 if and only if someone has a pipe open. */ 10879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static DEFINE_SPINLOCK(pipe_version_lock); 10979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static struct rpc_wait_queue pipe_version_rpc_waitqueue; 11079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue); 1119eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebuststatic void gss_put_auth(struct gss_auth *gss_auth); 112cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ 1135d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebuststatic void gss_free_ctx(struct gss_cl_ctx *); 114b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v0; 115b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v1; 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct gss_cl_ctx * 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_get_ctx(struct gss_cl_ctx *ctx) 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&ctx->count); 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ctx; 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_put_ctx(struct gss_cl_ctx *ctx) 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (atomic_dec_and_test(&ctx->count)) 1285d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust gss_free_ctx(ctx); 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1315d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust/* gss_cred_set_ctx: 1325d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust * called by gss_upcall_callback and gss_create_upcall in order 1335d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust * to set the gss context. The actual exchange of an old context 1349beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky * and a new one is protected by the pipe->lock. 1355d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust */ 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx) 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 1405d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 141cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags)) 142cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return; 1437b6962b0a6000df48c8a5fd967d262f77704101bTrond Myklebust gss_get_ctx(ctx); 144cf778b00e96df6d64f8e21b8395d1f8a859ecdc7Eric Dumazet rcu_assign_pointer(gss_cred->gc_ctx, ctx); 145fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 146cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust smp_mb__before_clear_bit(); 147fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags); 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic const void * 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssimple_get_bytes(const void *p, const void *end, void *res, size_t len) 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *q = (const void *)((const char *)p + len); 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(q > end || q < p)) 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(-EFAULT); 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(res, p, len); 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return q; 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline const void * 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssimple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *q; 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int len; 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &len, sizeof(len)); 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p; 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q = (const void *)((const char *)p + len); 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(q > end || q < p)) 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(-EFAULT); 1720f38b873aeaae698c3693748438547c8493165fbTrond Myklebust dest->data = kmemdup(p, len, GFP_NOFS); 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(dest->data == NULL)) 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(-ENOMEM); 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dest->len = len; 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return q; 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_cl_ctx * 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_cred_get_ctx(struct rpc_cred *cred) 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = NULL; 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1855d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust rcu_read_lock(); 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_cred->gc_ctx) 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx = gss_get_ctx(gss_cred->gc_ctx); 1885d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust rcu_read_unlock(); 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ctx; 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_cl_ctx * 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_alloc_context(void) 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx; 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1970f38b873aeaae698c3693748438547c8493165fbTrond Myklebust ctx = kzalloc(sizeof(*ctx), GFP_NOFS); 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx != NULL) { 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_proc = RPC_GSS_PROC_DATA; 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_seq = 1; /* NetApp 6.4R1 doesn't accept seq. no. 0 */ 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_init(&ctx->gc_seq_lock); 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_set(&ctx->count,1); 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ctx; 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define GSSD_MIN_TIMEOUT (60 * 60) 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic const void * 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct gss_api_mech *gm) 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *q; 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int seclen; 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int timeout; 214620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson unsigned long now = jiffies; 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 window_size; 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int ret; 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 218620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson /* First unsigned int gives the remaining lifetime in seconds of the 219620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson * credential - e.g. the remaining TGT lifetime for Kerberos or 220620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson * the -t value passed to GSSD. 221620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson */ 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &timeout, sizeof(timeout)); 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (timeout == 0) 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds timeout = GSSD_MIN_TIMEOUT; 227620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson ctx->gc_expiry = now + ((unsigned long)timeout * HZ); 228620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson /* Sequence number window. Determines the maximum number of 229620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson * simultaneous requests 230620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson */ 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &window_size, sizeof(window_size)); 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx->gc_win = window_size; 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* gssd signals an error by passing ctx->gc_win = 0: */ 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx->gc_win == 0) { 237dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton /* 238dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton * in which case, p points to an error code. Anything other 239dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton * than -EKEYEXPIRED gets converted to -EACCES. 240dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton */ 241dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton p = simple_get_bytes(p, end, &ret, sizeof(ret)); 242dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton if (!IS_ERR(p)) 243dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton p = (ret == -EKEYEXPIRED) ? ERR_PTR(-EKEYEXPIRED) : 244dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton ERR_PTR(-EACCES); 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* copy the opaque wire context */ 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_netobj(p, end, &ctx->gc_wire_ctx); 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* import the opaque security context */ 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = simple_get_bytes(p, end, &seclen, sizeof(seclen)); 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q = (const void *)((const char *)p + seclen); 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(q > end || q < p)) { 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = ERR_PTR(-EFAULT); 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 260400f26b542e86995662a0cc5483656b7b1f42af6Simo Sorce ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx, NULL, GFP_NOFS); 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ret < 0) { 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = ERR_PTR(ret); 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 265620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson dprintk("RPC: %s Success. gc_expiry %lu now %lu timeout %u\n", 266620038f6d2304475dce800dc5c75fc335a19613aAndy Adamson __func__, ctx->gc_expiry, now, timeout); 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return q; 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr: 269173db3093474e7691f2c2f3136313565bd366f6cJeff Layton dprintk("RPC: %s returns error %ld\n", __func__, -PTR_ERR(p)); 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p; 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 27334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\#define UPCALL_BUF_LEN 128 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct gss_upcall_msg { 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_t count; 2777eaf040b720bc8c0ce5cd49151ca194ca2d56842Eric W. Biederman kuid_t uid; 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_pipe_msg msg; 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct list_head list; 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *auth; 2819beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe; 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_wait_queue rpc_waitqueue; 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_head_t waitqueue; 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx; 28534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ char databuf[UPCALL_BUF_LEN]; 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2882aed8b476f3478be140df92bbfb182978e835504Trond Myklebuststatic int get_pipe_version(struct net *net) 28979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\{ 2902aed8b476f3478be140df92bbfb182978e835504Trond Myklebust struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 29179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ int ret; 29279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ 29379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_lock(&pipe_version_lock); 2942aed8b476f3478be140df92bbfb182978e835504Trond Myklebust if (sn->pipe_version >= 0) { 2952aed8b476f3478be140df92bbfb182978e835504Trond Myklebust atomic_inc(&sn->pipe_users); 2962aed8b476f3478be140df92bbfb182978e835504Trond Myklebust ret = sn->pipe_version; 29779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } else 29879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ ret = -EAGAIN; 29979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_unlock(&pipe_version_lock); 30079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ return ret; 30179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\} 30279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ 3032aed8b476f3478be140df92bbfb182978e835504Trond Myklebuststatic void put_pipe_version(struct net *net) 30479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\{ 3052aed8b476f3478be140df92bbfb182978e835504Trond Myklebust struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 3062aed8b476f3478be140df92bbfb182978e835504Trond Myklebust 3072aed8b476f3478be140df92bbfb182978e835504Trond Myklebust if (atomic_dec_and_lock(&sn->pipe_users, &pipe_version_lock)) { 3082aed8b476f3478be140df92bbfb182978e835504Trond Myklebust sn->pipe_version = -1; 30979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_unlock(&pipe_version_lock); 31079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 31179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\} 31279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_release_msg(struct gss_upcall_msg *gss_msg) 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 316e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust struct net *net = gss_msg->auth->net; 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!atomic_dec_and_test(&gss_msg->count)) 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 3192aed8b476f3478be140df92bbfb182978e835504Trond Myklebust put_pipe_version(net); 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(!list_empty(&gss_msg->list)); 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg->ctx != NULL) 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(gss_msg->ctx); 323f6a1cc89309f0ae847a9b6fe418d1c4215e5bc55Trond Myklebust rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue); 3249eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust gss_put_auth(gss_msg->auth); 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(gss_msg); 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_upcall_msg * 3297eaf040b720bc8c0ce5cd49151ca194ca2d56842Eric W. Biederman__gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid) 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *pos; 3329beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky list_for_each_entry(pos, &pipe->in_downcall, list) { 3330b4d51b02a2e941beec6f02a6c7a32c5a28c5b43Eric W. Biederman if (!uid_eq(pos->uid, uid)) 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&pos->count); 336632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s found msg %p\n", __func__, pos); 3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return pos; 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 339632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s found nothing\n", __func__); 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 343720b8f2d6f7de9e16f1217448cc7396e1604e175\\\"J. Bruce Fields\\\/* Try to add an upcall to the pipefs queue. 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If an upcall owned by our uid already exists, then we return a reference 3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to that upcall instead of adding the new upcall. 3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct gss_upcall_msg * 348053e324f67b9921fe7de0c4cbc720d29cb4bf207Suresh Jayaramangss_add_msg(struct gss_upcall_msg *gss_msg) 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3509beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe = gss_msg->pipe; 3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *old; 3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3539beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 3549beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky old = __gss_find_upcall(pipe, gss_msg->uid); 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (old == NULL) { 3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 3579beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky list_add(&gss_msg->list, &pipe->in_downcall); 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg = old; 3609beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return gss_msg; 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds__gss_unhash_msg(struct gss_upcall_msg *gss_msg) 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_del_init(&gss_msg->list); 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno); 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wake_up_all(&gss_msg->waitqueue); 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_dec(&gss_msg->count); 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_unhash_msg(struct gss_upcall_msg *gss_msg) 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3769beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe = gss_msg->pipe; 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3783b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust if (list_empty(&gss_msg->list)) 3793b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust return; 3809beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 3813b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust if (!list_empty(&gss_msg->list)) 3823b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust __gss_unhash_msg(gss_msg); 3839beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 387126e216a8730532dfb685205309275f87e3d133eTrond Myklebustgss_handle_downcall_result(struct gss_cred *gss_cred, struct gss_upcall_msg *gss_msg) 388126e216a8730532dfb685205309275f87e3d133eTrond Myklebust{ 389126e216a8730532dfb685205309275f87e3d133eTrond Myklebust switch (gss_msg->msg.errno) { 390126e216a8730532dfb685205309275f87e3d133eTrond Myklebust case 0: 391126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (gss_msg->ctx == NULL) 392126e216a8730532dfb685205309275f87e3d133eTrond Myklebust break; 393126e216a8730532dfb685205309275f87e3d133eTrond Myklebust clear_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags); 394126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred_set_ctx(&gss_cred->gc_base, gss_msg->ctx); 395126e216a8730532dfb685205309275f87e3d133eTrond Myklebust break; 396126e216a8730532dfb685205309275f87e3d133eTrond Myklebust case -EKEYEXPIRED: 397126e216a8730532dfb685205309275f87e3d133eTrond Myklebust set_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags); 398126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } 399126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred->gc_upcall_timestamp = jiffies; 400126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred->gc_upcall = NULL; 401126e216a8730532dfb685205309275f87e3d133eTrond Myklebust rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno); 402126e216a8730532dfb685205309275f87e3d133eTrond Myklebust} 403126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 404126e216a8730532dfb685205309275f87e3d133eTrond Myklebuststatic void 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_upcall_callback(struct rpc_task *task) 4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 407a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct gss_cred *gss_cred = container_of(task->tk_rqstp->rq_cred, 4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred, gc_base); 4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg = gss_cred->gc_upcall; 4109beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe = gss_msg->pipe; 4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4129beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 413126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_handle_downcall_result(gss_cred, gss_msg); 4149beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 415126e216a8730532dfb685205309275f87e3d133eTrond Myklebust task->tk_status = gss_msg->msg.errno; 4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 41934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg) 42034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 42190602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman uid_t uid = from_kuid(&init_user_ns, gss_msg->uid); 42290602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman memcpy(gss_msg->databuf, &uid, sizeof(uid)); 42390602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman gss_msg->msg.data = gss_msg->databuf; 42490602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman gss_msg->msg.len = sizeof(uid); 4259d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust 4269d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust BUILD_BUG_ON(sizeof(uid) > sizeof(gss_msg->databuf)); 42734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 42834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 4299d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebuststatic int gss_encode_v1_msg(struct gss_upcall_msg *gss_msg, 430bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust const char *service_name, 431bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust const char *target_name) 43234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 433683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust struct gss_api_mech *mech = gss_msg->auth->mech; 4348b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia char *p = gss_msg->databuf; 4359d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust size_t buflen = sizeof(gss_msg->databuf); 4369d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust int len; 4379d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust 4389d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust len = scnprintf(p, buflen, "mech=%s uid=%d ", mech->gm_name, 4399d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust from_kuid(&init_user_ns, gss_msg->uid)); 4409d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust buflen -= len; 4419d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust p += len; 4429d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust gss_msg->msg.len = len; 443bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust if (target_name) { 4449d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust len = scnprintf(p, buflen, "target=%s ", target_name); 4459d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust buflen -= len; 4468b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia p += len; 4478b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia gss_msg->msg.len += len; 4488b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia } 44968c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust if (service_name != NULL) { 4509d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust len = scnprintf(p, buflen, "service=%s ", service_name); 4519d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust buflen -= len; 4522efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia p += len; 4532efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia gss_msg->msg.len += len; 4542efef7080f471d312a9c4feb3dc5ee038039c7edOlga Kornievskaia } 455683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust if (mech->gm_upcall_enctypes) { 4569d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust len = scnprintf(p, buflen, "enctypes=%s ", 4579d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust mech->gm_upcall_enctypes); 4589d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust buflen -= len; 459683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust p += len; 460683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust gss_msg->msg.len += len; 461683ac6656cb05b6e83593770ffc049eee4a4d119Trond Myklebust } 4629d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust len = scnprintf(p, buflen, "\n"); 4639d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust if (len == 0) 4649d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust goto out_overflow; 4658b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia gss_msg->msg.len += len; 4668b1c7bf5b624c9bc91b41ae577b9fc5c21641705Olga Kornievskaia 46734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ gss_msg->msg.data = gss_msg->databuf; 4689d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust return 0; 4699d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebustout_overflow: 4709d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust WARN_ON_ONCE(1); 4719d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust return -ENOMEM; 47234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 47334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 47468c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebuststatic struct gss_upcall_msg * 475e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebustgss_alloc_msg(struct gss_auth *gss_auth, 4767eaf040b720bc8c0ce5cd49151ca194ca2d56842Eric W. Biederman kuid_t uid, const char *service_name) 4771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 47979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ int vers; 4809d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust int err = -ENOMEM; 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4820f38b873aeaae698c3693748438547c8493165fbTrond Myklebust gss_msg = kzalloc(sizeof(*gss_msg), GFP_NOFS); 483db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ if (gss_msg == NULL) 4849d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust goto err; 485e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust vers = get_pipe_version(gss_auth->net); 4869d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust err = vers; 4879d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust if (err < 0) 4889d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust goto err_free_msg; 4891917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_msg->pipe = gss_auth->gss_pipe[vers]->pipe; 490db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ INIT_LIST_HEAD(&gss_msg->list); 491db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ rpc_init_wait_queue(&gss_msg->rpc_waitqueue, "RPCSEC_GSS upcall waitq"); 492db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ init_waitqueue_head(&gss_msg->waitqueue); 493db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ atomic_set(&gss_msg->count, 1); 494db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ gss_msg->uid = uid; 495db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ gss_msg->auth = gss_auth; 496bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust switch (vers) { 497bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust case 0: 498bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust gss_encode_v0_msg(gss_msg); 4995fccc5b52ee07d07a74ce53c6f174bff81e26a16Trond Myklebust break; 500bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust default: 5019d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust err = gss_encode_v1_msg(gss_msg, service_name, gss_auth->target_name); 5029d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust if (err) 5039d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust goto err_free_msg; 504bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust }; 5059eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust kref_get(&gss_auth->kref); 5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return gss_msg; 5079d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebusterr_free_msg: 5089d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust kfree(gss_msg); 5099d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebusterr: 5109d3a2260f0f4bd6379b0a0f131c743fff25b0029Trond Myklebust return ERR_PTR(err); 5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct gss_upcall_msg * 514e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebustgss_setup_upcall(struct gss_auth *gss_auth, struct rpc_cred *cred) 5151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5167c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust struct gss_cred *gss_cred = container_of(cred, 5177c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust struct gss_cred, gc_base); 5181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_new, *gss_msg; 5197eaf040b720bc8c0ce5cd49151ca194ca2d56842Eric W. Biederman kuid_t uid = cred->cr_uid; 5201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 521e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust gss_new = gss_alloc_msg(gss_auth, uid, gss_cred->gc_principal); 522db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ if (IS_ERR(gss_new)) 523db75b3d6b5b0dad29860370618ea94d2726641b4\"J. Bruce Fields\ return gss_new; 524053e324f67b9921fe7de0c4cbc720d29cb4bf207Suresh Jayaraman gss_msg = gss_add_msg(gss_new); 5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg == gss_new) { 5269beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky int res = rpc_queue_upcall(gss_new->pipe, &gss_new->msg); 5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (res) { 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_unhash_msg(gss_new); 5291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg = ERR_PTR(res); 5301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_new); 5331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return gss_msg; 5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 536b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\static void warn_gssd(void) 537b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\{ 5380ea9de0ea6a4e4a1d343130b2a159b4f986e288eJeff Layton dprintk("AUTH_GSS upcall failed. Please check user daemon is running.\n"); 539b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\} 540b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ 5411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 5421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_refresh_upcall(struct rpc_task *task) 5431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 544a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 5454a8c1344dccb848dbcf0edabc8b5c51a8ecf2808Trond Myklebust struct gss_auth *gss_auth = container_of(cred->cr_auth, 5461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth, rpc_auth); 5471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, 5481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred, gc_base); 5491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 5509beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe; 5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 5521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 553632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s for uid %u\n", 554cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman task->tk_pid, __func__, from_kuid(&init_user_ns, cred->cr_uid)); 555e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust gss_msg = gss_setup_upcall(gss_auth, cred); 556480e3243df156e39eea6c91057e2ae612a6bbe19Roel Kluin if (PTR_ERR(gss_msg) == -EAGAIN) { 55779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ /* XXX: warning on the first, under the assumption we 55879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ * shouldn't normally hit this case on a refresh. */ 55979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ warn_gssd(); 56079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ task->tk_timeout = 15*HZ; 56179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ rpc_sleep_on(&pipe_version_rpc_waitqueue, task, NULL); 562d1a8016a2d1e75021ecc8715e3c81442d7218eb6Bryan Schumaker return -EAGAIN; 56379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 5641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(gss_msg)) { 5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(gss_msg); 5661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 5671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5689beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky pipe = gss_msg->pipe; 5699beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_cred->gc_upcall != NULL) 5715d00837b90340af9106dcd93af75fd664c8eb87fTrond Myklebust rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL); 572126e216a8730532dfb685205309275f87e3d133eTrond Myklebust else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) { 5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds task->tk_timeout = 0; 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_cred->gc_upcall = gss_msg; 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* gss_upcall_callback will release the reference to gss_upcall_msg */ 5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 5775d00837b90340af9106dcd93af75fd664c8eb87fTrond Myklebust rpc_sleep_on(&gss_msg->rpc_waitqueue, task, gss_upcall_callback); 578126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } else { 579126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_handle_downcall_result(gss_cred, gss_msg); 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = gss_msg->msg.errno; 581126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } 5829beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 585632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s for uid %u result %d\n", 586cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman task->tk_pid, __func__, 587cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman from_kuid(&init_user_ns, cred->cr_uid), err); 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 5921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred) 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 594e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust struct net *net = gss_auth->net; 595abfdbd53a4e28844ad953b313f017f55edbb85b7Trond Myklebust struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 5969beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe; 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_cred *cred = &gss_cred->gc_base; 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 5991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(wait); 600d36ccb9cec22a09a12d9ef8234d634f840d7ae4bTrond Myklebust int err; 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 602cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman dprintk("RPC: %s for uid %u\n", 603cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman __func__, from_kuid(&init_user_ns, cred->cr_uid)); 60479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\retry: 605d36ccb9cec22a09a12d9ef8234d634f840d7ae4bTrond Myklebust err = 0; 60689f842435c630f8426f414e6030bc2ffea0d6f81Jeff Layton /* if gssd is down, just skip upcalling altogether */ 60789f842435c630f8426f414e6030bc2ffea0d6f81Jeff Layton if (!gssd_running(net)) { 60889f842435c630f8426f414e6030bc2ffea0d6f81Jeff Layton warn_gssd(); 60989f842435c630f8426f414e6030bc2ffea0d6f81Jeff Layton return -EACCES; 61089f842435c630f8426f414e6030bc2ffea0d6f81Jeff Layton } 611e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust gss_msg = gss_setup_upcall(gss_auth, cred); 61279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ if (PTR_ERR(gss_msg) == -EAGAIN) { 61379a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ err = wait_event_interruptible_timeout(pipe_version_waitqueue, 61489f842435c630f8426f414e6030bc2ffea0d6f81Jeff Layton sn->pipe_version >= 0, 15 * HZ); 6152aed8b476f3478be140df92bbfb182978e835504Trond Myklebust if (sn->pipe_version < 0) { 616d1a8016a2d1e75021ecc8715e3c81442d7218eb6Bryan Schumaker warn_gssd(); 617d1a8016a2d1e75021ecc8715e3c81442d7218eb6Bryan Schumaker err = -EACCES; 618d1a8016a2d1e75021ecc8715e3c81442d7218eb6Bryan Schumaker } 619d36ccb9cec22a09a12d9ef8234d634f840d7ae4bTrond Myklebust if (err < 0) 62079a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ goto out; 62179a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ goto retry; 62279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 6231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(gss_msg)) { 6241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(gss_msg); 6251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 6261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6279beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky pipe = gss_msg->pipe; 6281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { 6295afa9133cfe67f1bfead6049a9640c9262a7101cTrond Myklebust prepare_to_wait(&gss_msg->waitqueue, &wait, TASK_KILLABLE); 6309beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 6311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg->ctx != NULL || gss_msg->msg.errno < 0) { 6321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6349beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 6355afa9133cfe67f1bfead6049a9640c9262a7101cTrond Myklebust if (fatal_signal_pending(current)) { 6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ERESTARTSYS; 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_intr; 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule(); 6401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (gss_msg->ctx) 6427b6962b0a6000df48c8a5fd967d262f77704101bTrond Myklebust gss_cred_set_ctx(cred, gss_msg->ctx); 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = gss_msg->msg.errno; 6459beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_intr: 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds finish_wait(&gss_msg->waitqueue, &wait); 6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 650632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s for uid %u result %d\n", 651cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman __func__, from_kuid(&init_user_ns, cred->cr_uid), err); 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define MSG_BUF_MAXSIZE 1024 6561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 6581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) 6591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const void *p, *end; 6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void *buf; 6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg; 663496ad9aa8ef448058e36ca7a787c61f2e63f0f54Al Viro struct rpc_pipe *pipe = RPC_I(file_inode(filp))->pipe; 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx; 66590602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman uid_t id; 66690602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman kuid_t uid; 6673b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust ssize_t err = -EFBIG; 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mlen > MSG_BUF_MAXSIZE) 6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ENOMEM; 6720f38b873aeaae698c3693748438547c8493165fbTrond Myklebust buf = kmalloc(mlen, GFP_NOFS); 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!buf) 6741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 6751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -EFAULT; 6771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (copy_from_user(buf, src, mlen)) 6781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 6791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds end = (const void *)((char *)buf + mlen); 68190602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman p = simple_get_bytes(buf, end, &id, sizeof(id)); 6821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) { 6831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(p); 6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 68790602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman uid = make_kuid(&init_user_ns, id); 68890602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman if (!uid_valid(uid)) { 68990602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman err = -EINVAL; 69090602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman goto err; 69190602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman } 69290602c7b192fdd3e6b7c7623479f4bc86ed7ee34Eric W. Biederman 6931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ENOMEM; 6941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ctx = gss_alloc_context(); 6951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx == NULL) 6961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto err; 6973b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust 6983b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust err = -ENOENT; 6993b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust /* Find a matching upcall */ 7009beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 7019beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky gss_msg = __gss_find_upcall(pipe, uid); 7023b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust if (gss_msg == NULL) { 7039beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 7043b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust goto err_put_ctx; 7053b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust } 7063b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust list_del_init(&gss_msg->list); 7079beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 7083b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust 7096e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust p = gss_fill_context(p, end, ctx, gss_msg->auth->mech); 7101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (IS_ERR(p)) { 7111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = PTR_ERR(p); 712486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton switch (err) { 713486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -EACCES: 714dc5ddce956660247e004a4b20a26b7d137ab1644Jeff Layton case -EKEYEXPIRED: 715486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton gss_msg->msg.errno = err; 716486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton err = mlen; 717486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton break; 718486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -EFAULT: 719486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -ENOMEM: 720486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -EINVAL: 721486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton case -ENOSYS: 722486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton gss_msg->msg.errno = -EAGAIN; 723486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton break; 724486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton default: 725486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton printk(KERN_CRIT "%s: bad return from " 7266c8530993e1fdf1d6af0403e796fe14d80b4b097Randy Dunlap "gss_fill_context: %zd\n", __func__, err); 727486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton BUG(); 728486bad2e40e938cd68fd853b7a9fa3115a9d3a4aJeff Layton } 7293b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust goto err_release_msg; 7301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7313b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust gss_msg->ctx = gss_get_ctx(ctx); 7323b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust err = mlen; 7333b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust 7343b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebusterr_release_msg: 7359beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 7363b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust __gss_unhash_msg(gss_msg); 7379beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 7383b68aaeaf54065e5c44583a1d33ffb7793953ba4Trond Myklebust gss_release_msg(gss_msg); 7391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr_put_ctx: 7401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 7411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr: 7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(buf); 7431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 744632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s returning %Zd\n", __func__, err); 7451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 7461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 74834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static int gss_pipe_open(struct inode *inode, int new_version) 749cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\{ 7502aed8b476f3478be140df92bbfb182978e835504Trond Myklebust struct net *net = inode->i_sb->s_fs_info; 7512aed8b476f3478be140df92bbfb182978e835504Trond Myklebust struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 75234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ int ret = 0; 75334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 75479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_lock(&pipe_version_lock); 7552aed8b476f3478be140df92bbfb182978e835504Trond Myklebust if (sn->pipe_version < 0) { 75634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* First open of any gss pipe determines the version: */ 7572aed8b476f3478be140df92bbfb182978e835504Trond Myklebust sn->pipe_version = new_version; 75879a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ rpc_wake_up(&pipe_version_rpc_waitqueue); 75979a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ wake_up(&pipe_version_waitqueue); 7602aed8b476f3478be140df92bbfb182978e835504Trond Myklebust } else if (sn->pipe_version != new_version) { 76134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* Trying to open a pipe of a different version */ 76234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ ret = -EBUSY; 76334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ goto out; 76479a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ } 7652aed8b476f3478be140df92bbfb182978e835504Trond Myklebust atomic_inc(&sn->pipe_users); 76634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\out: 76779a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ spin_unlock(&pipe_version_lock); 76834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ return ret; 76934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 77034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 77134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 77234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static int gss_pipe_open_v0(struct inode *inode) 77334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 77434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ return gss_pipe_open(inode, 0); 77534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\} 77634769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 77734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\static int gss_pipe_open_v1(struct inode *inode) 77834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\{ 77934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ return gss_pipe_open(inode, 1); 780cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\} 781cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ 7821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 7831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_release(struct inode *inode) 7841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7852aed8b476f3478be140df92bbfb182978e835504Trond Myklebust struct net *net = inode->i_sb->s_fs_info; 7869beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky struct rpc_pipe *pipe = RPC_I(inode)->pipe; 7876e84c7b66a0aa0be16a7728d1e687c57978dac2cTrond Myklebust struct gss_upcall_msg *gss_msg; 7881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7895a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebustrestart: 7909beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_lock(&pipe->lock); 7919beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky list_for_each_entry(gss_msg, &pipe->in_downcall, list) { 7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7935a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust if (!list_empty(&gss_msg->msg.list)) 7945a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust continue; 7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_msg->msg.errno = -EPIPE; 7961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __gss_unhash_msg(gss_msg); 7989beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 7991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 8005a67657a2e90c9e4a48518f95d4ba7777aa20fbbTrond Myklebust goto restart; 8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8029beae4677de76cfa4ce8899dc8cd1a1cf8cd8332Stanislav Kinsbursky spin_unlock(&pipe->lock); 803cf81939d6fcdf381fcb069d780c29eceb516bccd\"J. Bruce Fields\ 8042aed8b476f3478be140df92bbfb182978e835504Trond Myklebust put_pipe_version(net); 8051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 8081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_pipe_destroy_msg(struct rpc_pipe_msg *msg) 8091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_upcall_msg *gss_msg = container_of(msg, struct gss_upcall_msg, msg); 8111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (msg->errno < 0) { 813632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s releasing msg %p\n", 814632f0d0503accb8ab749a1165af99d344579c37bChuck Lever __func__, gss_msg); 8151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_inc(&gss_msg->count); 8161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_unhash_msg(gss_msg); 817b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ if (msg->errno == -ETIMEDOUT) 818b03568c32226163cb3588ea8993adb268ed497a5\"J. Bruce Fields\ warn_gssd(); 8191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_release_msg(gss_msg); 8201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8231917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststatic void gss_pipe_dentry_destroy(struct dentry *dir, 8241917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_pipe_dir_object *pdo) 825ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky{ 8261917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_pipe *gss_pipe = pdo->pdo_data; 8271917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_pipe *pipe = gss_pipe->pipe; 828ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 8291917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (pipe->dentry != NULL) { 8301917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust rpc_unlink(pipe->dentry); 8311917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust pipe->dentry = NULL; 8326b2fddd3e7f7cd437fb234407d7504fd22caf064Trond Myklebust } 833ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky} 834ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 8351917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststatic int gss_pipe_dentry_create(struct dentry *dir, 8361917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_pipe_dir_object *pdo) 837ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky{ 8381917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_pipe *p = pdo->pdo_data; 8396b2fddd3e7f7cd437fb234407d7504fd22caf064Trond Myklebust struct dentry *dentry; 840ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 8411917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust dentry = rpc_mkpipe_dentry(dir, p->name, p->clnt, p->pipe); 8421917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (IS_ERR(dentry)) 8431917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust return PTR_ERR(dentry); 8441917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust p->pipe->dentry = dentry; 8451917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust return 0; 8461917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust} 8471917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust 8481917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststatic const struct rpc_pipe_dir_object_ops gss_pipe_dir_object_ops = { 8491917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust .create = gss_pipe_dentry_create, 8501917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust .destroy = gss_pipe_dentry_destroy, 8511917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust}; 8521917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust 8531917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststatic struct gss_pipe *gss_pipe_alloc(struct rpc_clnt *clnt, 8541917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust const char *name, 8551917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust const struct rpc_pipe_ops *upcall_ops) 8561917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust{ 8571917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_pipe *p; 8581917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust int err = -ENOMEM; 859ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 8601917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust p = kmalloc(sizeof(*p), GFP_KERNEL); 8611917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (p == NULL) 8626b2fddd3e7f7cd437fb234407d7504fd22caf064Trond Myklebust goto err; 8631917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust p->pipe = rpc_mkpipe_data(upcall_ops, RPC_PIPE_WAIT_FOR_OPEN); 8641917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (IS_ERR(p->pipe)) { 8651917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust err = PTR_ERR(p->pipe); 8661917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust goto err_free_gss_pipe; 8676b2fddd3e7f7cd437fb234407d7504fd22caf064Trond Myklebust } 8681917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust p->name = name; 8691917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust p->clnt = clnt; 870414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust kref_init(&p->kref); 8711917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust rpc_init_pipe_dir_object(&p->pdo, 8721917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust &gss_pipe_dir_object_ops, 8731917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust p); 874414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return p; 8751917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebusterr_free_gss_pipe: 8761917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust kfree(p); 8776b2fddd3e7f7cd437fb234407d7504fd22caf064Trond Myklebusterr: 8781917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust return ERR_PTR(err); 879ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky} 880ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 881414a629598409497c05f2387c22c77dee143b4ffTrond Myklebuststruct gss_alloc_pdo { 882414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct rpc_clnt *clnt; 883414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust const char *name; 884414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust const struct rpc_pipe_ops *upcall_ops; 885414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust}; 886414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 887414a629598409497c05f2387c22c77dee143b4ffTrond Myklebuststatic int gss_pipe_match_pdo(struct rpc_pipe_dir_object *pdo, void *data) 888414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust{ 889414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct gss_pipe *gss_pipe; 890414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct gss_alloc_pdo *args = data; 891414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 892414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust if (pdo->pdo_ops != &gss_pipe_dir_object_ops) 893414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return 0; 894414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe = container_of(pdo, struct gss_pipe, pdo); 895414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust if (strcmp(gss_pipe->name, args->name) != 0) 896414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return 0; 897414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust if (!kref_get_unless_zero(&gss_pipe->kref)) 898414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return 0; 899414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return 1; 900414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust} 901414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 902414a629598409497c05f2387c22c77dee143b4ffTrond Myklebuststatic struct rpc_pipe_dir_object *gss_pipe_alloc_pdo(void *data) 903414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust{ 904414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct gss_pipe *gss_pipe; 905414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct gss_alloc_pdo *args = data; 906414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 907414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe = gss_pipe_alloc(args->clnt, args->name, args->upcall_ops); 908414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust if (!IS_ERR(gss_pipe)) 909414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return &gss_pipe->pdo; 910414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return NULL; 911414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust} 912414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 913414a629598409497c05f2387c22c77dee143b4ffTrond Myklebuststatic struct gss_pipe *gss_pipe_get(struct rpc_clnt *clnt, 914414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust const char *name, 915414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust const struct rpc_pipe_ops *upcall_ops) 916414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust{ 917414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct net *net = rpc_net_ns(clnt); 918414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct rpc_pipe_dir_object *pdo; 919414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct gss_alloc_pdo args = { 920414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust .clnt = clnt, 921414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust .name = name, 922414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust .upcall_ops = upcall_ops, 923414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust }; 924414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 925414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust pdo = rpc_find_or_alloc_pipe_dir_object(net, 926414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust &clnt->cl_pipedir_objects, 927414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe_match_pdo, 928414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe_alloc_pdo, 929414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust &args); 930414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust if (pdo != NULL) 931414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return container_of(pdo, struct gss_pipe, pdo); 932414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust return ERR_PTR(-ENOMEM); 933414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust} 934414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 9351917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststatic void __gss_pipe_free(struct gss_pipe *p) 936ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky{ 9371917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct rpc_clnt *clnt = p->clnt; 9381917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct net *net = rpc_net_ns(clnt); 939ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 9401917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust rpc_remove_pipe_dir_object(net, 9411917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust &clnt->cl_pipedir_objects, 9421917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust &p->pdo); 9431917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust rpc_destroy_pipe_data(p->pipe); 9441917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust kfree(p); 945ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky} 946ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 947414a629598409497c05f2387c22c77dee143b4ffTrond Myklebuststatic void __gss_pipe_release(struct kref *kref) 948414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust{ 949414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust struct gss_pipe *p = container_of(kref, struct gss_pipe, kref); 950414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 951414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust __gss_pipe_free(p); 952414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust} 953414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust 9541917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebuststatic void gss_pipe_free(struct gss_pipe *p) 955ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky{ 9561917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (p != NULL) 957414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust kref_put(&p->kref, __gss_pipe_release); 958ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky} 959ccdc28f81c91f7ef2dc6c28d27f50264b19e4dd5Stanislav Kinsbursky 960cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki/* 961cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki * NOTE: we have the opportunity to use different 9621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * parameters based on the input flavor (which must be a pseudoflavor) 9631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 964eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebuststatic struct gss_auth * 965eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebustgss_create_new(struct rpc_auth_create_args *args, struct rpc_clnt *clnt) 9661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 967c2190661039b3817b4cc1cbfea620b3f7dbe5cd8Trond Myklebust rpc_authflavor_t flavor = args->pseudoflavor; 9681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *gss_auth; 9691917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_pipe *gss_pipe; 9701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct rpc_auth * auth; 9716a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields int err = -ENOMEM; /* XXX? */ 9721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9738885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: creating GSS authenticator for client %p\n", clnt); 9741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!try_module_get(THIS_MODULE)) 9766a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields return ERR_PTR(err); 9771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL))) 9781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_dec; 979eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust INIT_HLIST_NODE(&gss_auth->hash); 980bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust gss_auth->target_name = NULL; 981c2190661039b3817b4cc1cbfea620b3f7dbe5cd8Trond Myklebust if (args->target_name) { 982c2190661039b3817b4cc1cbfea620b3f7dbe5cd8Trond Myklebust gss_auth->target_name = kstrdup(args->target_name, GFP_KERNEL); 983bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust if (gss_auth->target_name == NULL) 984bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust goto err_free; 985bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust } 9861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth->client = clnt; 987e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust gss_auth->net = get_net(rpc_net_ns(clnt)); 9886a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields err = -EINVAL; 9891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor); 9901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!gss_auth->mech) { 9919b1d75b75505cff4468ceba0da51a1ba47e15ea2Trond Myklebust dprintk("RPC: Pseudoflavor %d not found!\n", flavor); 992e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust goto err_put_net; 9931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_auth->service = gss_pseudoflavor_to_service(gss_auth->mech, flavor); 995438b6fdebf2a2e8573e7290bc176feb4d4475f43J. Bruce Fields if (gss_auth->service == 0) 996438b6fdebf2a2e8573e7290bc176feb4d4475f43J. Bruce Fields goto err_put_mech; 997a699d65ec4ff82245d2c4fdfb8ed1d64776d756eTrond Myklebust if (!gssd_running(gss_auth->net)) 998a699d65ec4ff82245d2c4fdfb8ed1d64776d756eTrond Myklebust goto err_put_mech; 9991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth = &gss_auth->rpc_auth; 10001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_cslack = GSS_CRED_SLACK >> 2; 10011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_rslack = GSS_VERF_SLACK >> 2; 10021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_ops = &authgss_ops; 10031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds auth->au_flavor = flavor; 10041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds atomic_set(&auth->au_count, 1); 10050285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kref_init(&gss_auth->kref); 10061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10071917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust err = rpcauth_init_credcache(auth); 10081917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (err) 10091917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust goto err_put_mech; 101034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ /* 101134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * Note: if we created the old pipe first, then someone who 101234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * examined the directory at the right moment might conclude 101334769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * that we supported only the old pipe. So we instead create 101434769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ * the new pipe first. 101534769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ */ 1016414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe = gss_pipe_get(clnt, "gssd", &gss_upcall_ops_v1); 10171917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (IS_ERR(gss_pipe)) { 10181917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust err = PTR_ERR(gss_pipe); 10191917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust goto err_destroy_credcache; 10206a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields } 10211917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_auth->gss_pipe[1] = gss_pipe; 10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1023414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe = gss_pipe_get(clnt, gss_auth->mech->gm_name, 10241917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust &gss_upcall_ops_v0); 10251917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust if (IS_ERR(gss_pipe)) { 10261917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust err = PTR_ERR(gss_pipe); 1027c239d83b9921b8a8005a3bcd23000cfe18acf5c2Stanislav Kinsbursky goto err_destroy_pipe_1; 1028c239d83b9921b8a8005a3bcd23000cfe18acf5c2Stanislav Kinsbursky } 10291917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_auth->gss_pipe[0] = gss_pipe; 103007a2bf1da4765d987ffd1d8045e92ba032e0ad78Trond Myklebust 1031eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust return gss_auth; 1032c239d83b9921b8a8005a3bcd23000cfe18acf5c2Stanislav Kinsburskyerr_destroy_pipe_1: 1033414a629598409497c05f2387c22c77dee143b4ffTrond Myklebust gss_pipe_free(gss_auth->gss_pipe[1]); 10341917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebusterr_destroy_credcache: 10351917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust rpcauth_destroy_credcache(auth); 10361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr_put_mech: 10371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_mech_put(gss_auth->mech); 1038e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebusterr_put_net: 1039e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust put_net(gss_auth->net); 10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldserr_free: 1041bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust kfree(gss_auth->target_name); 10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(gss_auth); 10431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_dec: 10441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds module_put(THIS_MODULE); 10456a19275ada9137435da58990c8f8d3f58e170bf1J. Bruce Fields return ERR_PTR(err); 10461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 10490285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebustgss_free(struct gss_auth *gss_auth) 10500285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust{ 10511917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_pipe_free(gss_auth->gss_pipe[0]); 10521917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_pipe_free(gss_auth->gss_pipe[1]); 10530285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust gss_mech_put(gss_auth->mech); 1054e726340ac9cf6bb5b3f92a064664e10cd2b748deTrond Myklebust put_net(gss_auth->net); 1055bd4a3eb15bb42296e61d0fd16f2c7f8cc171b681Trond Myklebust kfree(gss_auth->target_name); 10560285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 10570285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kfree(gss_auth); 10580285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust module_put(THIS_MODULE); 10590285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust} 10600285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 10610285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebuststatic void 10620285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebustgss_free_callback(struct kref *kref) 10630285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust{ 10640285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust struct gss_auth *gss_auth = container_of(kref, struct gss_auth, kref); 10650285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 10660285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust gss_free(gss_auth); 10670285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust} 10680285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust 10690285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebuststatic void 10709eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebustgss_put_auth(struct gss_auth *gss_auth) 10719eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust{ 10729eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust kref_put(&gss_auth->kref, gss_free_callback); 10739eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust} 10749eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust 10759eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebuststatic void 10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_destroy(struct rpc_auth *auth) 10771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10781917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_auth *gss_auth = container_of(auth, 10791917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust struct gss_auth, rpc_auth); 10801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10818885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever dprintk("RPC: destroying GSS authenticator %p flavor %d\n", 10828885cb367f86ce02bed3bf18192d74a53ac3b81fChuck Lever auth, auth->au_flavor); 10831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1084eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (hash_hashed(&gss_auth->hash)) { 1085eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust spin_lock(&gss_auth_hash_lock); 1086eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust hash_del(&gss_auth->hash); 1087eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust spin_unlock(&gss_auth_hash_lock); 1088eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust } 1089eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 10901917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_pipe_free(gss_auth->gss_pipe[0]); 10911917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_auth->gss_pipe[0] = NULL; 10921917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_pipe_free(gss_auth->gss_pipe[1]); 10931917228435eebdf4e3267fa95cace694b2fb4efdTrond Myklebust gss_auth->gss_pipe[1] = NULL; 10943ab9bb7243489f9db3abf3d05521ddfc6b184c0aTrond Myklebust rpcauth_destroy_credcache(auth); 10953ab9bb7243489f9db3abf3d05521ddfc6b184c0aTrond Myklebust 10969eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust gss_put_auth(gss_auth); 10971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1099a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields/* 1100a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * Auths may be shared between rpc clients that were cloned from a 1101a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * common client with the same xprt, if they also share the flavor and 1102a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * target_name. 1103a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * 1104a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * The auth is looked up from the oldest parent sharing the same 1105a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * cl_xprt, and the auth itself references only that common parent 1106a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields * (which is guaranteed to last as long as any of its descendants). 1107a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields */ 1108eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebuststatic struct gss_auth * 1109eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebustgss_auth_find_or_add_hashed(struct rpc_auth_create_args *args, 1110eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct rpc_clnt *clnt, 1111eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct gss_auth *new) 1112eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust{ 1113eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct gss_auth *gss_auth; 1114eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust unsigned long hashval = (unsigned long)clnt; 1115eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 1116eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust spin_lock(&gss_auth_hash_lock); 1117eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust hash_for_each_possible(gss_auth_hash_table, 1118eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust gss_auth, 1119eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust hash, 1120eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust hashval) { 1121a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields if (gss_auth->client != clnt) 1122a0f6ed8ebe4f6d494ef70f67d4c0c153cbf59577J. Bruce Fields continue; 1123eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (gss_auth->rpc_auth.au_flavor != args->pseudoflavor) 1124eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust continue; 1125eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (gss_auth->target_name != args->target_name) { 1126eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (gss_auth->target_name == NULL) 1127eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust continue; 1128eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (args->target_name == NULL) 1129eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust continue; 1130eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (strcmp(gss_auth->target_name, args->target_name)) 1131eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust continue; 1132eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust } 1133eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (!atomic_inc_not_zero(&gss_auth->rpc_auth.au_count)) 1134eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust continue; 1135eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust goto out; 1136eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust } 1137eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (new) 1138eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust hash_add(gss_auth_hash_table, &new->hash, hashval); 1139eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust gss_auth = new; 1140eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebustout: 1141eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust spin_unlock(&gss_auth_hash_lock); 1142eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust return gss_auth; 1143eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust} 1144eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 1145eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebuststatic struct gss_auth * 1146eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebustgss_create_hashed(struct rpc_auth_create_args *args, struct rpc_clnt *clnt) 1147eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust{ 1148eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct gss_auth *gss_auth; 1149eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct gss_auth *new; 1150eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 1151eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust gss_auth = gss_auth_find_or_add_hashed(args, clnt, NULL); 1152eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (gss_auth != NULL) 1153eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust goto out; 1154eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust new = gss_create_new(args, clnt); 1155eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (IS_ERR(new)) 1156eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust return new; 1157eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust gss_auth = gss_auth_find_or_add_hashed(args, clnt, new); 1158eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (gss_auth != new) 1159eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust gss_destroy(&new->rpc_auth); 1160eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebustout: 1161eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust return gss_auth; 1162eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust} 1163eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 1164eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebuststatic struct rpc_auth * 1165eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebustgss_create(struct rpc_auth_create_args *args, struct rpc_clnt *clnt) 1166eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust{ 1167eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct gss_auth *gss_auth; 1168eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct rpc_xprt *xprt = rcu_access_pointer(clnt->cl_xprt); 1169eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 1170eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust while (clnt != clnt->cl_parent) { 1171eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust struct rpc_clnt *parent = clnt->cl_parent; 1172eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust /* Find the original parent for this transport */ 1173eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (rcu_access_pointer(parent->cl_xprt) != xprt) 1174eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust break; 1175eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust clnt = parent; 1176eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust } 1177eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 1178eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust gss_auth = gss_create_hashed(args, clnt); 1179eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust if (IS_ERR(gss_auth)) 1180eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust return ERR_CAST(gss_auth); 1181eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust return &gss_auth->rpc_auth; 1182eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust} 1183eb6dc19d8e72ce3a957af5511d20c0db0a8bd007Trond Myklebust 11840df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust/* 11850df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * gss_destroying_context will cause the RPCSEC_GSS to send a NULL RPC call 11860df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * to the server with the GSS control procedure field set to 11870df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * RPC_GSS_PROC_DESTROY. This should normally cause the server to release 11880df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * all RPCSEC_GSS state associated with that context. 11890df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust */ 11900df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic int 11910df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebustgss_destroying_context(struct rpc_cred *cred) 11920df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust{ 11930df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 11940df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust struct gss_auth *gss_auth = container_of(cred->cr_auth, struct gss_auth, rpc_auth); 11950df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust struct rpc_task *task; 11960df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 11970df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust if (gss_cred->gc_ctx == NULL || 11986dcd3926b214a1fb081df18305921dedae269977Jeff Layton test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) == 0) 11990df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust return 0; 12000df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 12010df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust gss_cred->gc_ctx->gc_proc = RPC_GSS_PROC_DESTROY; 12020df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust cred->cr_ops = &gss_nullops; 12030df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 12040df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust /* Take a reference to ensure the cred will be destroyed either 12050df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust * by the RPC call or by the put_rpccred() below */ 12060df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust get_rpccred(cred); 12070df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 1208080a1f148df0615f7a610e4776dd8f3fb706f54fTrond Myklebust task = rpc_call_null(gss_auth->client, cred, RPC_TASK_ASYNC|RPC_TASK_SOFT); 12090df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust if (!IS_ERR(task)) 12100df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust rpc_put_task(task); 12110df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 12120df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust put_rpccred(cred); 12130df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust return 1; 12140df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust} 12150df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 12160df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust/* gss_destroy_cred (and gss_free_ctx) are used to clean up after failure 12171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to create a new cred or context, so they check that things have been 12181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * allocated before freeing them. */ 12191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 12205d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebustgss_do_free_ctx(struct gss_cl_ctx *ctx) 12211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1222632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s\n", __func__); 12231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12240d8a374673c9bc62bc78a2d8fe64553a51542cb4Trond Myklebust gss_delete_sec_context(&ctx->gc_gss_ctx); 12251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(ctx->gc_wire_ctx.data); 12261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(ctx); 12271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 12305d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebustgss_free_ctx_callback(struct rcu_head *head) 12315d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust{ 12325d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust struct gss_cl_ctx *ctx = container_of(head, struct gss_cl_ctx, gc_rcu); 12335d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust gss_do_free_ctx(ctx); 12345d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust} 12355d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 12365d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebuststatic void 12375d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebustgss_free_ctx(struct gss_cl_ctx *ctx) 12385d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust{ 12395d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust call_rcu(&ctx->gc_rcu, gss_free_ctx_callback); 12405d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust} 12415d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 12425d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebuststatic void 124331be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebustgss_free_cred(struct gss_cred *gss_cred) 12441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1245632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s cred=%p\n", __func__, gss_cred); 124631be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust kfree(gss_cred); 124731be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust} 12481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 124931be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebuststatic void 125031be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebustgss_free_cred_callback(struct rcu_head *head) 125131be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust{ 125231be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust struct gss_cred *gss_cred = container_of(head, struct gss_cred, gc_base.cr_rcu); 125331be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust gss_free_cred(gss_cred); 125431be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust} 12551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 125631be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebuststatic void 12576dcd3926b214a1fb081df18305921dedae269977Jeff Laytongss_destroy_nullcred(struct rpc_cred *cred) 125831be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust{ 12595d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 12600285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust struct gss_auth *gss_auth = container_of(cred->cr_auth, struct gss_auth, rpc_auth); 12615d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust struct gss_cl_ctx *ctx = gss_cred->gc_ctx; 12625d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust 1263a9b3cd7f323b2e57593e7215362a7b02fc933e3aStephen Hemminger RCU_INIT_POINTER(gss_cred->gc_ctx, NULL); 126431be5bf15f3dafffce110eb1afadccbf2e3067b4Trond Myklebust call_rcu(&cred->cr_rcu, gss_free_cred_callback); 12655d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust if (ctx) 12665d28dc82074f1e64b22c9424b161abc1f5d6bcdbTrond Myklebust gss_put_ctx(ctx); 12679eb2ddb48ce3a7bd745c14a933112994647fa3cdTrond Myklebust gss_put_auth(gss_auth); 12681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12706dcd3926b214a1fb081df18305921dedae269977Jeff Laytonstatic void 12716dcd3926b214a1fb081df18305921dedae269977Jeff Laytongss_destroy_cred(struct rpc_cred *cred) 12726dcd3926b214a1fb081df18305921dedae269977Jeff Layton{ 12736dcd3926b214a1fb081df18305921dedae269977Jeff Layton 12746dcd3926b214a1fb081df18305921dedae269977Jeff Layton if (gss_destroying_context(cred)) 12756dcd3926b214a1fb081df18305921dedae269977Jeff Layton return; 12766dcd3926b214a1fb081df18305921dedae269977Jeff Layton gss_destroy_nullcred(cred); 12776dcd3926b214a1fb081df18305921dedae269977Jeff Layton} 12786dcd3926b214a1fb081df18305921dedae269977Jeff Layton 12791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 12801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Lookup RPCSEC_GSS cred for the current process 12811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 12821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct rpc_cred * 12838a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustgss_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) 12841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 12858a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebust return rpcauth_lookup_credcache(auth, acred, flags); 12861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct rpc_cred * 12898a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustgss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) 12901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 12911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth); 12921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *cred = NULL; 12931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = -ENOMEM; 12941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1295632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s for uid %d, flavor %d\n", 1296cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman __func__, from_kuid(&init_user_ns, acred->uid), 1297cdba321e291f0fbf5abda4d88340292b858e3d4dEric W. Biederman auth->au_flavor); 12981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12990f38b873aeaae698c3693748438547c8493165fbTrond Myklebust if (!(cred = kzalloc(sizeof(*cred), GFP_NOFS))) 13001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_err; 13011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13025fe4755e2526a2aa82b7ed8daeb3aed74a236925Trond Myklebust rpcauth_init_cred(&cred->gc_base, acred, auth, &gss_credops); 13031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 13041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note: in order to force a call to call_refresh(), we deliberately 13051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fail to flag the credential as RPCAUTH_CRED_UPTODATE. 13061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1307fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW; 13081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cred->gc_service = gss_auth->service; 130968c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust cred->gc_principal = NULL; 131068c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust if (acred->machine_cred) 131168c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust cred->gc_principal = acred->principal; 13120285ed1f12298e5304f0f2642e2cf31a5f302e61Trond Myklebust kref_get(&gss_auth->kref); 13131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &cred->gc_base; 13141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_err: 1316632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %s failed with error %d\n", __func__, err); 13171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ERR_PTR(err); 13181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 1321fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebustgss_cred_init(struct rpc_auth *auth, struct rpc_cred *cred) 1322fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust{ 1323fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth); 1324fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust struct gss_cred *gss_cred = container_of(cred,struct gss_cred, gc_base); 1325fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust int err; 1326fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust 1327fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust do { 1328fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust err = gss_create_upcall(gss_auth, gss_cred); 1329fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust } while (err == -EAGAIN); 1330fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust return err; 1331fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust} 1332fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust 13334de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson/* 13344de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson * Returns -EACCES if GSS context is NULL or will expire within the 13354de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson * timeout (miliseconds) 13364de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson */ 13374de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamsonstatic int 13384de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamsongss_key_timeout(struct rpc_cred *rc) 13394de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson{ 13404de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base); 13414de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson unsigned long now = jiffies; 13424de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson unsigned long expire; 13434de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 13444de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson if (gss_cred->gc_ctx == NULL) 13454de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson return -EACCES; 13464de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 13474de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson expire = gss_cred->gc_ctx->gc_expiry - (gss_key_expire_timeo * HZ); 13484de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 13494de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson if (time_after(now, expire)) 13504de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson return -EACCES; 13514de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson return 0; 13524de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson} 13534de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 1354fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebuststatic int 13558a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustgss_match(struct auth_cred *acred, struct rpc_cred *rc, int flags) 13561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 13571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base); 13584de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson int ret; 13591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1360cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (test_bit(RPCAUTH_CRED_NEW, &rc->cr_flags)) 13618a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebust goto out; 13621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Don't match with creds that have expired. */ 1363cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (time_after(jiffies, gss_cred->gc_ctx->gc_expiry)) 1364cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return 0; 1365cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (!test_bit(RPCAUTH_CRED_UPTODATE, &rc->cr_flags)) 13661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 13678a3177604b729ec3b80e43790ee978863ac7551bTrond Myklebustout: 136868c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust if (acred->principal != NULL) { 136968c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust if (gss_cred->gc_principal == NULL) 137068c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust return 0; 13714de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson ret = strcmp(acred->principal, gss_cred->gc_principal) == 0; 13724de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson goto check_expire; 137368c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust } 137468c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust if (gss_cred->gc_principal != NULL) 13757c67db3a8a98045744f06fcd6d8f476d9df0ba5cTrond Myklebust return 0; 13764de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson ret = uid_eq(rc->cr_uid, acred->uid); 13774de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 13784de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamsoncheck_expire: 13794de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson if (ret == 0) 13804de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson return ret; 13814de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 13824de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson /* Notify acred users of GSS context expiration timeout */ 13834de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson if (test_bit(RPC_CRED_NOTIFY_TIMEOUT, &acred->ac_flags) && 13844de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson (gss_key_timeout(rc) != 0)) { 13854de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson /* test will now be done from generic cred */ 13864de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson test_and_clear_bit(RPC_CRED_NOTIFY_TIMEOUT, &acred->ac_flags); 13874de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson /* tell NFS layer that key will expire soon */ 13884de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson set_bit(RPC_CRED_KEY_EXPIRE_SOON, &acred->ac_flags); 13894de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson } 13904de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson return ret; 13911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 13941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds* Marshal credentials. 13951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds* Maybe we should keep a cached credential for performance reasons. 13961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/ 1397d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic __be32 * 1398d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyangss_marshal(struct rpc_task *task, __be32 *p) 13991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1400a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_rqst *req = task->tk_rqstp; 1401a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = req->rq_cred; 14021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 14031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gc_base); 14041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 1405d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *cred_len; 14061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat = 0; 14071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 14081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct kvec iov; 14091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf verf_buf; 14101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1411632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s\n", task->tk_pid, __func__); 14121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl(RPC_AUTH_GSS); 14141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cred_len = p++; 14151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock(&ctx->gc_seq_lock); 14171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds req->rq_seqno = ctx->gc_seq++; 14181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock(&ctx->gc_seq_lock); 14191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) RPC_GSS_VERSION); 14211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) ctx->gc_proc); 14221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) req->rq_seqno); 14231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl((u32) gss_cred->gc_service); 14241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = xdr_encode_netobj(p, &ctx->gc_wire_ctx); 14251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *cred_len = htonl((p - (cred_len + 1)) << 2); 14261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We compute the checksum for the verifier over the xdr-encoded bytes 14281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * starting with the xid and ending at the end of the credential: */ 1429a4f0835c604f80f945ab3e72ffd00547145c4b2bTrond Myklebust iov.iov_base = xprt_skip_transport_header(req->rq_xprt, 1430808012fbb23a52ec59352445d2076d175ad4ab26Chuck Lever req->rq_snd_buf.head[0].iov_base); 14311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov.iov_len = (u8 *)p - (u8 *)iov.iov_base; 14321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds xdr_buf_from_iov(&iov, &verf_buf); 14331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* set verifier flavor*/ 14351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl(RPC_AUTH_GSS); 14361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.data = (u8 *)(p + 1); 143800fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_get_mic(ctx->gc_gss_ctx, &verf_buf, &mic); 14391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) { 1440fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 14411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (maj_stat != 0) { 14421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk("gss_marshal: gss_get_mic FAILED (%d)\n", maj_stat); 14431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_put_ctx; 14441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = xdr_encode_opaque(p, NULL, mic.len); 14461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 14471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p; 14481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_put_ctx: 14491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 14501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 14511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 14521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1453cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebuststatic int gss_renew_cred(struct rpc_task *task) 1454cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust{ 1455a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *oldcred = task->tk_rqstp->rq_cred; 1456cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct gss_cred *gss_cred = container_of(oldcred, 1457cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct gss_cred, 1458cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust gc_base); 1459cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct rpc_auth *auth = oldcred->cr_auth; 1460cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct auth_cred acred = { 1461cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust .uid = oldcred->cr_uid, 146268c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust .principal = gss_cred->gc_principal, 146368c97153fb7f2877f98aa6c29546381d9cad2fedTrond Myklebust .machine_cred = (gss_cred->gc_principal != NULL ? 1 : 0), 1464cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust }; 1465cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust struct rpc_cred *new; 1466cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust 1467cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust new = gss_lookup_cred(auth, &acred, RPCAUTH_LOOKUP_NEW); 1468cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (IS_ERR(new)) 1469cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return PTR_ERR(new); 1470a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust task->tk_rqstp->rq_cred = new; 1471cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust put_rpccred(oldcred); 1472cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return 0; 1473cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust} 1474cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust 1475126e216a8730532dfb685205309275f87e3d133eTrond Myklebuststatic int gss_cred_is_negative_entry(struct rpc_cred *cred) 1476126e216a8730532dfb685205309275f87e3d133eTrond Myklebust{ 1477126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (test_bit(RPCAUTH_CRED_NEGATIVE, &cred->cr_flags)) { 1478126e216a8730532dfb685205309275f87e3d133eTrond Myklebust unsigned long now = jiffies; 1479126e216a8730532dfb685205309275f87e3d133eTrond Myklebust unsigned long begin, expire; 1480126e216a8730532dfb685205309275f87e3d133eTrond Myklebust struct gss_cred *gss_cred; 1481126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 1482126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_cred = container_of(cred, struct gss_cred, gc_base); 1483126e216a8730532dfb685205309275f87e3d133eTrond Myklebust begin = gss_cred->gc_upcall_timestamp; 1484126e216a8730532dfb685205309275f87e3d133eTrond Myklebust expire = begin + gss_expired_cred_retry_delay * HZ; 1485126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 1486126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (time_in_range_open(now, begin, expire)) 1487126e216a8730532dfb685205309275f87e3d133eTrond Myklebust return 1; 1488126e216a8730532dfb685205309275f87e3d133eTrond Myklebust } 1489126e216a8730532dfb685205309275f87e3d133eTrond Myklebust return 0; 1490126e216a8730532dfb685205309275f87e3d133eTrond Myklebust} 1491126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 14921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 14931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds* Refresh credentials. XXX - finish 14941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/ 14951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 14961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_refresh(struct rpc_task *task) 14971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1498a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 1499cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust int ret = 0; 1500cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust 1501126e216a8730532dfb685205309275f87e3d133eTrond Myklebust if (gss_cred_is_negative_entry(cred)) 1502126e216a8730532dfb685205309275f87e3d133eTrond Myklebust return -EKEYEXPIRED; 1503126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 1504cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) && 1505cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust !test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags)) { 1506cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust ret = gss_renew_cred(task); 1507cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (ret < 0) 1508cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust goto out; 1509a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust cred = task->tk_rqstp->rq_cred; 1510cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust } 15111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1512cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags)) 1513cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust ret = gss_refresh_upcall(task); 1514cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebustout: 1515cd019f7517206a74d8cdb64d5c82b1f76be608ccTrond Myklebust return ret; 15161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 15171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15180df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust/* Dummy refresh routine: used only when destroying the context */ 15190df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic int 15200df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebustgss_refresh_null(struct rpc_task *task) 15210df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust{ 1522c297c8b99b07f496ff69a719cfb8e8fe852832edAndy Adamson return 0; 15230df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust} 15240df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 1525d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyanstatic __be32 * 1526d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyangss_validate(struct rpc_task *task, __be32 *p) 15271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1528a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 15291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 1530d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 seq; 15311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct kvec iov; 15321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf verf_buf; 15331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 15341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 flav,len; 15351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat; 153635fa5f7b35ca2076d594b2670a32d66dd3ae9eecAndy Adamson __be32 *ret = ERR_PTR(-EIO); 15371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1538632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s\n", task->tk_pid, __func__); 15391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds flav = ntohl(*p++); 15411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((len = ntohl(*p++)) > RPC_MAX_AUTH_SIZE) 1542cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki goto out_bad; 15431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (flav != RPC_AUTH_GSS) 15441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_bad; 15451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds seq = htonl(task->tk_rqstp->rq_seqno); 15461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov.iov_base = &seq; 15471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov.iov_len = sizeof(seq); 15481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds xdr_buf_from_iov(&iov, &verf_buf); 15491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.data = (u8 *)p; 15501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.len = len; 15511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 155235fa5f7b35ca2076d594b2670a32d66dd3ae9eecAndy Adamson ret = ERR_PTR(-EACCES); 155300fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &verf_buf, &mic); 15541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1555fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 15560df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust if (maj_stat) { 1557632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s: gss_verify_mic returned error 0x%08x\n", 1558632f0d0503accb8ab749a1165af99d344579c37bChuck Lever task->tk_pid, __func__, maj_stat); 15591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_bad; 15600df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust } 156124b2605becc10ca63c4c30808fa59a8abbf68727J. Bruce Fields /* We leave it to unwrap to calculate au_rslack. For now we just 156224b2605becc10ca63c4c30808fa59a8abbf68727J. Bruce Fields * calculate the length of the verifier: */ 15631be27f36601973815171db684c711d30557cf50cTrond Myklebust cred->cr_auth->au_verfsize = XDR_QUADLEN(len) + 2; 15641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 1565632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s: gss_verify_mic succeeded.\n", 1566632f0d0503accb8ab749a1165af99d344579c37bChuck Lever task->tk_pid, __func__); 15671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return p + XDR_QUADLEN(len); 15681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_bad: 15691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 157035fa5f7b35ca2076d594b2670a32d66dd3ae9eecAndy Adamson dprintk("RPC: %5u %s failed ret %ld.\n", task->tk_pid, __func__, 157135fa5f7b35ca2076d594b2670a32d66dd3ae9eecAndy Adamson PTR_ERR(ret)); 157235fa5f7b35ca2076d594b2670a32d66dd3ae9eecAndy Adamson return ret; 15731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 15741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15759f06c719f474be7003763284a990bed6377bb0d4Chuck Leverstatic void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp, 15769f06c719f474be7003763284a990bed6377bb0d4Chuck Lever __be32 *p, void *obj) 15779f06c719f474be7003763284a990bed6377bb0d4Chuck Lever{ 15789f06c719f474be7003763284a990bed6377bb0d4Chuck Lever struct xdr_stream xdr; 15799f06c719f474be7003763284a990bed6377bb0d4Chuck Lever 15809f06c719f474be7003763284a990bed6377bb0d4Chuck Lever xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p); 15819f06c719f474be7003763284a990bed6377bb0d4Chuck Lever encode(rqstp, &xdr, obj); 15829f06c719f474be7003763284a990bed6377bb0d4Chuck Lever} 15839f06c719f474be7003763284a990bed6377bb0d4Chuck Lever 15841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 15851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 15869f06c719f474be7003763284a990bed6377bb0d4Chuck Lever kxdreproc_t encode, struct rpc_rqst *rqstp, 15879f06c719f474be7003763284a990bed6377bb0d4Chuck Lever __be32 *p, void *obj) 15881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 15891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 15901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf integ_buf; 1591d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *integ_len = NULL; 15921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 1593d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan u32 offset; 1594d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *q; 15951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct kvec *iov; 15961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat = 0; 15971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 15981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds integ_len = p++; 16001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base; 16011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *p++ = htonl(rqstp->rq_seqno); 16021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16039f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 16041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (xdr_buf_subsegment(snd_buf, &integ_buf, 16061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset, snd_buf->len - offset)) 16071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 16081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *integ_len = htonl(integ_buf.len); 16091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* guess whether we're in the head or the tail: */ 1611cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki if (snd_buf->page_len || snd_buf->tail[0].iov_len) 16121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov = snd_buf->tail; 16131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 16141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov = snd_buf->head; 16151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds p = iov->iov_base + iov->iov_len; 16161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic.data = (u8 *)(p + 1); 16171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 161800fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_get_mic(ctx->gc_gss_ctx, &integ_buf, &mic); 16191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = -EIO; /* XXX? */ 16201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1621fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 16221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else if (maj_stat) 16231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 16241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q = xdr_encode_opaque(p, NULL, mic.len); 16251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset = (u8 *)q - (u8 *)p; 16271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iov->iov_len += offset; 16281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds snd_buf->len += offset; 16291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 16301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16322d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic void 16332d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldspriv_release_snd_buf(struct rpc_rqst *rqstp) 16342d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 16352d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int i; 16362d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16372d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields for (i=0; i < rqstp->rq_enc_pages_num; i++) 16382d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields __free_page(rqstp->rq_enc_pages[i]); 16392d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields kfree(rqstp->rq_enc_pages); 16402d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 16412d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16422d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic int 16432d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsalloc_enc_pages(struct rpc_rqst *rqstp) 16442d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 16452d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 16462d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int first, last, i; 16472d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16482d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (snd_buf->page_len == 0) { 16492d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages_num = 0; 16502d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 16512d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields } 16522d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16532d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields first = snd_buf->page_base >> PAGE_CACHE_SHIFT; 16542d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields last = (snd_buf->page_base + snd_buf->page_len - 1) >> PAGE_CACHE_SHIFT; 16552d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages_num = last - first + 1 + 1; 16562d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages 16572d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields = kmalloc(rqstp->rq_enc_pages_num * sizeof(struct page *), 16582d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields GFP_NOFS); 16592d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (!rqstp->rq_enc_pages) 16602d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields goto out; 16612d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields for (i=0; i < rqstp->rq_enc_pages_num; i++) { 16622d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_enc_pages[i] = alloc_page(GFP_NOFS); 16632d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (rqstp->rq_enc_pages[i] == NULL) 16642d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields goto out_free; 16652d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields } 16662d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rqstp->rq_release_snd_buf = priv_release_snd_buf; 16672d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 16682d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsout_free: 1669cdead7cf12896c0e50a8be2e52de52c364603095Trond Myklebust rqstp->rq_enc_pages_num = i; 1670cdead7cf12896c0e50a8be2e52de52c364603095Trond Myklebust priv_release_snd_buf(rqstp); 16712d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsout: 16722d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return -EAGAIN; 16732d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 16742d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16752d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic inline int 16762d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsgss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 16779f06c719f474be7003763284a990bed6377bb0d4Chuck Lever kxdreproc_t encode, struct rpc_rqst *rqstp, 16789f06c719f474be7003763284a990bed6377bb0d4Chuck Lever __be32 *p, void *obj) 16792d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 16802d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 16812d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 offset; 16822d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 maj_stat; 16832d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int status; 1684d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *opaque_len; 16852d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct page **inpages; 16862d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int first; 16872d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int pad; 16882d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct kvec *iov; 16892d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields char *tmp; 16902d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16912d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields opaque_len = p++; 16922d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base; 16932d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields *p++ = htonl(rqstp->rq_seqno); 16942d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16959f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 16962d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 16972d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields status = alloc_enc_pages(rqstp); 16982d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (status) 16992d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 17002d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields first = snd_buf->page_base >> PAGE_CACHE_SHIFT; 17012d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields inpages = snd_buf->pages + first; 17022d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->pages = rqstp->rq_enc_pages; 17032d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->page_base -= first << PAGE_CACHE_SHIFT; 17047561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman /* 17057561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * Give the tail its own page, in case we need extra space in the 17067561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * head when wrapping: 17077561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * 17087561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * call_allocate() allocates twice the slack space required 17097561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * by the authentication flavor to rq_callsize. 17107561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman * For GSS, slack is GSS_CRED_SLACK. 17117561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman */ 17122d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (snd_buf->page_len || snd_buf->tail[0].iov_len) { 17132d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields tmp = page_address(rqstp->rq_enc_pages[rqstp->rq_enc_pages_num - 1]); 17142d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields memcpy(tmp, snd_buf->tail[0].iov_base, snd_buf->tail[0].iov_len); 17152d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->tail[0].iov_base = tmp; 17162d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields } 171700fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_wrap(ctx->gc_gss_ctx, offset, snd_buf, inpages); 17187561042fb7870be0b4ee57efddce68bda8968abfKevin Coffman /* slack space should prevent this ever happening: */ 17192d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields BUG_ON(snd_buf->len > snd_buf->buflen); 1720cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki status = -EIO; 17212d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields /* We're assuming that when GSS_S_CONTEXT_EXPIRED, the encryption was 17222d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields * done anyway, so it's safe to put the request on the wire: */ 17232d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1724fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 17252d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields else if (maj_stat) 17262d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 17272d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 17282d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields *opaque_len = htonl(snd_buf->len - offset); 17292d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields /* guess whether we're in the head or the tail: */ 17302d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (snd_buf->page_len || snd_buf->tail[0].iov_len) 17312d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields iov = snd_buf->tail; 17322d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields else 17332d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields iov = snd_buf->head; 17342d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields p = iov->iov_base + iov->iov_len; 17352d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields pad = 3 - ((snd_buf->len - offset - 1) & 3); 17362d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields memset(p, 0, pad); 17372d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields iov->iov_len += pad; 17382d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields snd_buf->len += pad; 17392d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 17402d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 17412d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 17422d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 17431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 17441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_wrap_req(struct rpc_task *task, 17459f06c719f474be7003763284a990bed6377bb0d4Chuck Lever kxdreproc_t encode, void *rqstp, __be32 *p, void *obj) 17461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1747a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 17481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 17491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gc_base); 17501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 17511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 17521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1753632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s\n", task->tk_pid, __func__); 17541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx->gc_proc != RPC_GSS_PROC_DATA) { 17551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* The spec seems a little ambiguous here, but I think that not 17561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wrapping context destruction requests makes the most sense. 17571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 17589f06c719f474be7003763284a990bed6377bb0d4Chuck Lever gss_wrap_req_encode(encode, rqstp, p, obj); 17599f06c719f474be7003763284a990bed6377bb0d4Chuck Lever status = 0; 17601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 17611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (gss_cred->gc_service) { 176389f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches case RPC_GSS_SVC_NONE: 176489f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches gss_wrap_req_encode(encode, rqstp, p, obj); 176589f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches status = 0; 176689f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches break; 176789f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches case RPC_GSS_SVC_INTEGRITY: 176889f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches status = gss_wrap_req_integ(cred, ctx, encode, rqstp, p, obj); 176989f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches break; 177089f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches case RPC_GSS_SVC_PRIVACY: 177189f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches status = gss_wrap_req_priv(cred, ctx, encode, rqstp, p, obj); 177289f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches break; 17731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 17751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 1776632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s returning %d\n", task->tk_pid, __func__, status); 17771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 17781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 17791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int 17811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_unwrap_resp_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 1782d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan struct rpc_rqst *rqstp, __be32 **p) 17831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 17841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf; 17851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_buf integ_buf; 17861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct xdr_netobj mic; 17871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 data_offset, mic_offset; 17881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 integ_len; 17891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 maj_stat; 17901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 17911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds integ_len = ntohl(*(*p)++); 17931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (integ_len & 3) 17941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 17951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data_offset = (u8 *)(*p) - (u8 *)rcv_buf->head[0].iov_base; 17961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic_offset = integ_len + data_offset; 17971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mic_offset > rcv_buf->len) 17981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 17991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ntohl(*(*p)++) != rqstp->rq_seqno) 18001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 18011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (xdr_buf_subsegment(rcv_buf, &integ_buf, data_offset, 18031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mic_offset - data_offset)) 18041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 18051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (xdr_buf_read_netobj(rcv_buf, &mic, mic_offset)) 18071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 18081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 180900fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &integ_buf, &mic); 18101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1811fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 18121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (maj_stat != GSS_S_COMPLETE) 18131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 18141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 18151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 18161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18172d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsstatic inline int 18182d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fieldsgss_unwrap_resp_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 1819d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan struct rpc_rqst *rqstp, __be32 **p) 18202d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields{ 18212d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct xdr_buf *rcv_buf = &rqstp->rq_rcv_buf; 18222d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 offset; 18232d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 opaque_len; 18242d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields u32 maj_stat; 18252d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int status = -EIO; 18262d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 18272d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields opaque_len = ntohl(*(*p)++); 18282d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields offset = (u8 *)(*p) - (u8 *)rcv_buf->head[0].iov_base; 18292d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (offset + opaque_len > rcv_buf->len) 18302d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 18312d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields /* remove padding: */ 18322d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields rcv_buf->len = offset + opaque_len; 18332d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 183400fd6e14255fe7a249315746386d640bc4e9e758J. Bruce Fields maj_stat = gss_unwrap(ctx->gc_gss_ctx, offset, rcv_buf); 18352d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1836fc432dd90760a629c57026e57f65ff80a1a31d2fTrond Myklebust clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 18372d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (maj_stat != GSS_S_COMPLETE) 18382d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 18392d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields if (ntohl(*(*p)++) != rqstp->rq_seqno) 18402d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return status; 18412d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 18422d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields return 0; 18432d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields} 18442d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 1845bf2695516db982e90a22fc94f93491b481796bb1Chuck Leverstatic int 1846bf2695516db982e90a22fc94f93491b481796bb1Chuck Levergss_unwrap_req_decode(kxdrdproc_t decode, struct rpc_rqst *rqstp, 1847bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever __be32 *p, void *obj) 1848bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever{ 1849bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever struct xdr_stream xdr; 1850bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever 1851bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 1852bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever return decode(rqstp, &xdr, obj); 1853bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever} 18542d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields 18551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 18561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgss_unwrap_resp(struct rpc_task *task, 1857bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever kxdrdproc_t decode, void *rqstp, __be32 *p, void *obj) 18581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1859a17c2153d2e271b0cbacae9bed83b0eaa41db7e1Trond Myklebust struct rpc_cred *cred = task->tk_rqstp->rq_cred; 18601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 18611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gc_base); 18621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred); 1863d8ed029d6000ba2e2908d9286409e4833c091b4cAlexey Dobriyan __be32 *savedp = p; 18642d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields struct kvec *head = ((struct rpc_rqst *)rqstp)->rq_rcv_buf.head; 18652d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields int savedlen = head->iov_len; 18661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int status = -EIO; 18671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ctx->gc_proc != RPC_GSS_PROC_DATA) 18691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_decode; 18701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (gss_cred->gc_service) { 187189f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches case RPC_GSS_SVC_NONE: 187289f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches break; 187389f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches case RPC_GSS_SVC_INTEGRITY: 187489f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches status = gss_unwrap_resp_integ(cred, ctx, rqstp, &p); 187589f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches if (status) 187689f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches goto out; 187789f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches break; 187889f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches case RPC_GSS_SVC_PRIVACY: 187989f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches status = gss_unwrap_resp_priv(cred, ctx, rqstp, &p); 188089f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches if (status) 188189f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches goto out; 188289f0e4feafb64643b0f0aba9d89984362bac9739Joe Perches break; 18831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 188424b2605becc10ca63c4c30808fa59a8abbf68727J. Bruce Fields /* take into account extra slack for integrity and privacy cases: */ 18851be27f36601973815171db684c711d30557cf50cTrond Myklebust cred->cr_auth->au_rslack = cred->cr_auth->au_verfsize + (p - savedp) 18862d2da60c63b67174add32f06e8d54c3a0c5cd9cfJ. Bruce Fields + (savedlen - head->iov_len); 18871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_decode: 1888bf2695516db982e90a22fc94f93491b481796bb1Chuck Lever status = gss_unwrap_req_decode(decode, rqstp, p, obj); 18891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 18901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_put_ctx(ctx); 1891632f0d0503accb8ab749a1165af99d344579c37bChuck Lever dprintk("RPC: %5u %s returning %d\n", 1892632f0d0503accb8ab749a1165af99d344579c37bChuck Lever task->tk_pid, __func__, status); 18931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return status; 18941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1895cca5172a7ec10dfdb0b787cd8e9d5b0b8f179793YOSHIFUJI Hideaki 1896f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_authops authgss_ops = { 18971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .owner = THIS_MODULE, 18981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .au_flavor = RPC_AUTH_GSS, 18991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .au_name = "RPCSEC_GSS", 19001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .create = gss_create, 19011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .destroy = gss_destroy, 19021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .lookup_cred = gss_lookup_cred, 190380df9d202255071c8ec610a6a3fdca5cac69f7bdStanislav Kinsbursky .crcreate = gss_create_cred, 19046a1a1e34dc55f17e7bd260809207442dbb7a0296Chuck Lever .list_pseudoflavors = gss_mech_list_pseudoflavors, 19059568c5e9a61de49f67f524404a27a1014a8d7f1eChuck Lever .info2flavor = gss_mech_info2flavor, 1906a77c806fb9d097bb7733b64207cf52fc2c6438bbChuck Lever .flavor2info = gss_mech_flavor2info, 19071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 19081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1909f1c0a8615090359d57e096157feb9f900cbb233cTrond Myklebuststatic const struct rpc_credops gss_credops = { 19101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .cr_name = "AUTH_GSS", 19111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crdestroy = gss_destroy_cred, 1912fba3bad488a2eec2d76c067edb7a5ff92ef42431Trond Myklebust .cr_init = gss_cred_init, 19135c691044ecbca04dd558fca4c754121689fe1b34Trond Myklebust .crbind = rpcauth_generic_bind_cred, 19141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crmatch = gss_match, 19151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crmarshal = gss_marshal, 19161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crrefresh = gss_refresh, 19171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crvalidate = gss_validate, 19181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crwrap_req = gss_wrap_req, 19191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .crunwrap_resp = gss_unwrap_resp, 19204de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson .crkey_timeout = gss_key_timeout, 19211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 19221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19230df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebuststatic const struct rpc_credops gss_nullops = { 19240df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .cr_name = "AUTH_GSS", 19256dcd3926b214a1fb081df18305921dedae269977Jeff Layton .crdestroy = gss_destroy_nullcred, 19265c691044ecbca04dd558fca4c754121689fe1b34Trond Myklebust .crbind = rpcauth_generic_bind_cred, 19270df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crmatch = gss_match, 19280df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crmarshal = gss_marshal, 19290df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crrefresh = gss_refresh_null, 19300df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crvalidate = gss_validate, 19310df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crwrap_req = gss_wrap_req, 19320df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust .crunwrap_resp = gss_unwrap_resp, 19330df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust}; 19340df7fb74fbb709591301871a38aac7735a1d6583Trond Myklebust 1935b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v0 = { 1936c1225158a8dad9e9d5eee8a17dbbd9c7cda05ab9Peng Tao .upcall = rpc_pipe_generic_upcall, 193734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .downcall = gss_pipe_downcall, 193834769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .destroy_msg = gss_pipe_destroy_msg, 193934769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .open_pipe = gss_pipe_open_v0, 194034769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .release_pipe = gss_pipe_release, 194134769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\}; 194234769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ 1943b693ba4a338da15db1db4b5ebaa36e4ab9781c82Trond Myklebuststatic const struct rpc_pipe_ops gss_upcall_ops_v1 = { 1944c1225158a8dad9e9d5eee8a17dbbd9c7cda05ab9Peng Tao .upcall = rpc_pipe_generic_upcall, 19451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .downcall = gss_pipe_downcall, 19461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .destroy_msg = gss_pipe_destroy_msg, 194734769fc488b463cb753fc632f8f5ba56c918b7cb\"J. Bruce Fields\ .open_pipe = gss_pipe_open_v1, 19481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .release_pipe = gss_pipe_release, 19491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 19501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1951a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsburskystatic __net_init int rpcsec_gss_init_net(struct net *net) 1952a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky{ 1953a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky return gss_svc_init_net(net); 1954a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky} 1955a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky 1956a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsburskystatic __net_exit void rpcsec_gss_exit_net(struct net *net) 1957a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky{ 1958a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky gss_svc_shutdown_net(net); 1959a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky} 1960a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky 1961a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsburskystatic struct pernet_operations rpcsec_gss_net_ops = { 1962a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky .init = rpcsec_gss_init_net, 1963a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky .exit = rpcsec_gss_exit_net, 1964a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky}; 1965a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky 19661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 19671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Initialize RPCSEC_GSS module 19681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 19691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init init_rpcsec_gss(void) 19701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 19711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 19721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = rpcauth_register(&authgss_ops); 19741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) 19751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 19761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = gss_svc_init(); 19771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) 19781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out_unregister; 1979a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky err = register_pernet_subsys(&rpcsec_gss_net_ops); 1980a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky if (err) 1981a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky goto out_svc_exit; 198279a3f20b641f9f93787ada49d1d7cfa98ee5a11e\"J. Bruce Fields\ rpc_init_wait_queue(&pipe_version_rpc_waitqueue, "gss pipe version"); 19831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 1984a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsburskyout_svc_exit: 1985a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky gss_svc_shutdown(); 19861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout_unregister: 19871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rpcauth_unregister(&authgss_ops); 19881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout: 19891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 19901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 19911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit exit_rpcsec_gss(void) 19931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1994a1db410d0bbadc49943f0fcddb21702ceb429396Stanislav Kinsbursky unregister_pernet_subsys(&rpcsec_gss_net_ops); 19951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds gss_svc_shutdown(); 19961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rpcauth_unregister(&authgss_ops); 1997bf12691d846b48fa6e3289810a822687457036cfJesper Dangaard Brouer rcu_barrier(); /* Wait for completion of call_rcu()'s */ 19981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 19991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 200071afa85e798ebc81054164c947b189d163c92b30Chuck LeverMODULE_ALIAS("rpc-auth-6"); 20011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 2002126e216a8730532dfb685205309275f87e3d133eTrond Myklebustmodule_param_named(expired_cred_retry_delay, 2003126e216a8730532dfb685205309275f87e3d133eTrond Myklebust gss_expired_cred_retry_delay, 2004126e216a8730532dfb685205309275f87e3d133eTrond Myklebust uint, 0644); 2005126e216a8730532dfb685205309275f87e3d133eTrond MyklebustMODULE_PARM_DESC(expired_cred_retry_delay, "Timeout (in seconds) until " 2006126e216a8730532dfb685205309275f87e3d133eTrond Myklebust "the RPC engine retries an expired credential"); 2007126e216a8730532dfb685205309275f87e3d133eTrond Myklebust 20084de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamsonmodule_param_named(key_expire_timeo, 20094de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson gss_key_expire_timeo, 20104de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson uint, 0644); 20114de6caa270afaa381dd3373e9e6d148b1090e0ecAndy AdamsonMODULE_PARM_DESC(key_expire_timeo, "Time (in seconds) at the end of a " 20124de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson "credential keys lifetime where the NFS layer cleans up " 20134de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson "prior to key expiration"); 20144de6caa270afaa381dd3373e9e6d148b1090e0ecAndy Adamson 20151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(init_rpcsec_gss) 20161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(exit_rpcsec_gss) 2017