Avoid expired credential keys for buffered writes
Subsystems (3)
cover Avoid expired credential keys for buffered writes
From: Andy Adamson <[email protected]>
-----------
Version 3, responded to comments:
1) Changed "SUNRPC Fix rpc_verify_header error returns" into "SUNRPC refactor rpcauth_checkverf error returns" which only returns -EACCES on rpcauth_checkverf error in gss_validate if -EKEYEXPIRED is returned.
Rebased on 3.7-rc7 Trond's testing branch.
-------------
Version 2, responded to comments:
1) Just use high water mark
2) Move expiration testing into nfs_file_write
3) Added a patch to clean up rpc_verify_header error processing
NOTE: Often "Input/output error" is returned instead of "Permission Denied". This is because of nfs_wb_all(). The NFS layer returns -EACCES, but it gets mapped to -EIO (I believe via AG_EIO).
I would like to have Permision Denied always be returned...
NOTE: I will add a patch for directIO and look into mmaped I/O as well after this patch set is done.
-------------
We must avoid buffering a WRITE that is using a credential key (e.g. a GSS context key) that is about to expire or has expired. We currently will paint ourselves into a corner by returning success to the applciation for such a buffered WRITE, only to discover that we do not have permission when we attempt to flush the WRITE (and potentially associated COMMIT) to disk. This results in data corruption.
First, a couple of "setup" patches:
1) Patch SUNRPC handle EKEYEXPIRED in call_refreshresult returns EACCES to the application on an expired or non-existent gss context when the users (Kerberos) credentials have also expired or are non-existent. Current behavior is to retry upcalls to GSSD forever. Please see patch comment for detail.
2) Patch SUNRPC set gss gc_expiry to full lifetime works in conjunction with the gssd patch "0001-GSSD-Pass-GSS_context-lifetime-to-the-kernel". The gssd patch passes the actual remaining TGT lifetime in the downcall, and this kernel patch sets the gss context gc_expiry to this lifetime.
Then the two patches that avoid using an expired credential key:
3) Patch SUNRPC new rpc_credops to test credential expiry is the heart of this work. It provides the RPC layer helper functions to allow NFS to manage data in the face of expired credentials
4) Patch NFS avoid expired credential keys for buffered writes calls the RPC helper functions.
5) Patch SUNRPC Fix rpc_verify_header error returns changes a -EIO return to a -EACCES return when there is an auth error.
Pages for buffered WRITEs are allocated in nfs_write_begin where we have an nfs_open_context and associated rpc_cred. This is a generic rpc_cred, NOT the gss_cred used in the actual WRITE RPC. Each WRITE RPC call takes the generic rpc_cred (or uses the 'current_cred') uid and uses it to lookup the associated gss_cred and gss_context in the call_refresh RPC state. So, there is a one-to-one association between the nfs_open_context generic_cred and a gss_cred with a matching uid and a valid non expired gss context.
We need to check the nfs_open_context generic cred 'underlying' gss_cred gss_context gc_expiry prior to nfs_write_begin in nfs_file_write to determine if there is enough time left in the gss_context lifetime to complete the buffered WRITEs.
I started by adding a "key_timeout" rpc_authops routine only set by the generic auth to do this work, called by rpcauth_key_timeout_notify, called from nfs_write_begin. It does the lookup of the gss_cred (see the patch for fast-tracking of non-gss underlying creds) and then tests the gss_context gc_expiry against timeouts by calling a new crkey_timeout rpc_credops set only for the gss_cred.
I coded a water mark, RPC_KEY_EXPIRE_TIMEO set to 90 seconds.
NOTE: this timeout is a guess that works in a VM environment. We may want to make it adjustable via a module parameter.
If key_timeout is called on a credential with an underlying credential key that will expire within watermark seconds, we set the RPC_CRED_KEY_EXPIRE_SOON flag in the generic_cred acred so that the NFS layer can clean up prior to key expiration It does this by calling a new crkey_to_expire rpc_credop set only for generic creds that tests for the RPC_CRED_KEY_EXPIRE_SOON flag.
If the RPC_CRED_KEY_EXPIRE_SOON flag is set in the nfs_open_context generic cred (the acred portion), then nfs_file_write will call vfs_fsync on EVERY WRITE CALL it sees, and will send NFS_FILE_SYNC WRITEs. The idea of the watermark is to give time to flush all buffered WRITEs and COMMITs, as well as to continue to WRITE, but only with NFS_FILE_SYNC, allowing the application to try to finish writing before the gss context expires. NOTE that this means EACH WRITE within the watermark
timeout is a singe PAGE of NFS_FILE_SYNC. I think this is fine, because we are in a failure mode - the most important thing is to NOT fail a buffered WRITE..
Checking a generic credential's underlying credential involves a cred lookup. To avoid this lookup in the normal case when the underlying credential has a key that is valid (before the watermark), a notify flag is set in the generic credential the first time the key_timeout is called. The generic credential then stops checking the underlying credential key expiry, and the underlying credential (gss_cred) match routine then checks the key expiration upon each normal use and sets a flag in the associated generic credential only when the key expiration is within the watermark. This in turn signals the generic credential key_timeout to perform the extra credetial lookup thereafter.
TESTING:
I have tested these patches with a TGT of 2 minutes, and the Connectathon special test: bigfile.c with a 60MB bigfile size.
I kinit, and run 5 instances of buffered write with the first and maybe second test completing prior to TGT expiration, and the third/fourth tests spanning the water mark. The fifth test starts within the water mark.
I have seen the expected behavior: test 1,2 succeed. Tests 3-5 fail with Permission Denied. Tests 3 and 4 start with normal buffered UNSTABLE writes then switch to single page NFS_FILE_SYNC writes with a COMMIT for the normal buffered writes. Test 5 has only single page NFS_FILE_SYNC writes.
None of the WRITEs fail on the wire, no failed WRITEs are returned as successful to the application.
ISSUES:
The only issue is once in a while I see "Input/Output Error" instead of "Permission denied". I believe the -EACCES error is translated into an -EIO error in the VFS.
-->Andy
Andy Adamson (5):
SUNRPC handle EKEYEXPIRED in call_refreshresult SUNRPC set gss gc_expiry to full lifetime SUNRPC new rpc_credops to test credential expiry NFS avoid expired credential keys for buffered writes SUNRPC refactor rpcauth_checkverf error returns
fs/nfs/file.c | 15 +++++++- fs/nfs/internal.h | 2 + fs/nfs/nfs3proc.c | 6 +- fs/nfs/nfs4filelayout.c | 1 - fs/nfs/nfs4proc.c | 18 -------- fs/nfs/nfs4state.c | 23 ----------- fs/nfs/proc.c | 43 -------------------- fs/nfs/write.c | 27 +++++++++++++ include/linux/sunrpc/auth.h | 21 ++++++++++ net/sunrpc/auth.c | 21 +++++++++- net/sunrpc/auth_generic.c | 84 ++++++++++++++++++++++++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 68 ++++++++++++++++++++++++++++---- net/sunrpc/auth_null.c | 5 +- net/sunrpc/auth_unix.c | 5 +- net/sunrpc/clnt.c | 18 +++++--- 15 files changed, 248 insertions(+), 109 deletions(-)
Signature · 1 line
1.7.7.6
PATCH 1/5 SUNRPC handle EKEYEXPIRED in call_refreshresult
From: Andy Adamson <[email protected]>
Currently, when an RPCSEC_GSS context has expired or is non-existent and the users (Kerberos) credentials have also expired or are non-existent, the client receives the -EKEYEXPIRED error and tries to refresh the context forever. If an application is performing I/O, or other work against the share, the application hangs, and the user is not prompted to refresh/establish their credentials. This can result in a denial of service for other users.
Users are expected to manage their Kerberos credential lifetimes to mitigate this issue.
Move the -EKEYEXPIRED handling into the RPC layer. Try tk_cred_retry number of times to refresh the gss_context, and then return -EACCES to the application.
--- fs/nfs/nfs3proc.c | 6 +++--- fs/nfs/nfs4filelayout.c | 1 - fs/nfs/nfs4proc.c | 18 ------------------ fs/nfs/nfs4state.c | 23 ----------------------- fs/nfs/proc.c | 43 ------------------------------------------- net/sunrpc/clnt.c | 1 + 6 files changed, 4 insertions(+), 88 deletions(-)
fs/nfs/nfs3proc.c +3 -3
@@ -24,14 +24,14 @@#define NFSDBG_FACILITY NFSDBG_PROC -/* A wrapper to handle the EJUKEBOX and EKEYEXPIRED error messages */ +/* A wrapper to handle the EJUKEBOX error messages */ static int nfs3_rpc_wrapper (struct rpc_clnt *clnt,struct rpc_message *msg,int flags) {int res; do { res = rpc_call_sync(clnt, msg, flags); - if (res != -EJUKEBOX && res != -EKEYEXPIRED) + if (res != -EJUKEBOX) break; freezable_schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME); res = -ERESTARTSYS;
@@ -44,7 +44,7 @@ nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)static int nfs3_async_handle_jukebox (struct rpc_task *task,struct inode *inode) { -if (task->tk_status != -EJUKEBOX && task->tk_status != -EKEYEXPIRED ) +if (task->tk_status != -EJUKEBOX )return 0 ;if (task->tk_status == -EJUKEBOX )nfs_inc_stats (inode,NFSIOS_DELAY );
fs/nfs/nfs4filelayout.c +0 -1
@@ -179,7 +179,6 @@ static int filelayout_async_handle_error(struct rpc_task *task,break ;case -NFS4ERR_DELAY :case -NFS4ERR_GRACE : -case -EKEYEXPIRED :rpc_delay (task,FILELAYOUT_POLL_RETRY_MAX );break ;case -NFS4ERR_RETRY_UNCACHED_REP :
fs/nfs/nfs4proc.c +0 -18
@@ -333,7 +333,6 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc }case -NFS4ERR_GRACE :case -NFS4ERR_DELAY : -case -EKEYEXPIRED : ret =nfs4_delay (server->client, &exception->timeout);if (ret !=0 )break ;
@@ -1331,13 +1330,6 @@ int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_statenfs_inode_find_state_and_recover (state->inode, stateid);nfs4_schedule_stateid_recovery (server, state); -case -EKEYEXPIRED : -/* -* User RPCSEC_GSS context has expired. -* We cannot recover this stateid now, so -* skip it and allow recovery thread to -* proceed. -*/ case -ENOMEM : err =0 ; goto out;
@@ -3927,7 +3919,6 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,case -NFS4ERR_DELAY :nfs_inc_server_stats (server,NFSIOS_DELAY );case -NFS4ERR_GRACE : -case -EKEYEXPIRED :rpc_delay (task,NFS4_POLL_RETRY_MAX ); task->tk_status =0 ;return -EAGAIN ;
@@ -4926,15 +4917,6 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)nfs4_schedule_stateid_recovery (server, state); err =0 ; goto out; -case -EKEYEXPIRED : -/* -* User RPCSEC_GSS context has expired. -* We cannot recover this stateid now, so -* skip it and allow recovery thread to -* proceed. -*/ - err =0 ; - goto out;case -ENOMEM :case -NFS4ERR_DENIED :/* kill_proc(fl->fl_pid, SIGLOST, 1); */
fs/nfs/nfs4state.c +0 -23
@@ -1441,14 +1441,6 @@ restart:/* Mark the file as being 'closed' */ state->state =0 ;break ; -case -EKEYEXPIRED : -/* -* User RPCSEC_GSS context has expired. -* We cannot recover this stateid now, so -* skip it and allow recovery thread to -* proceed. -*/ -break ;case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_STALE_STATEID :case -NFS4ERR_BAD_STATEID :
@@ -1601,14 +1593,6 @@ static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)nfs4_state_mark_reclaim_helper (clp, nfs4_state_mark_reclaim_nograce); } -static void nfs4_warn_keyexpired (const char *s) -{ -printk_ratelimited (KERN_WARNING "Error: state manager" -" encountered RPCSEC_GSS session" -" expired against NFSv4 server %s.\n" , - s); -} -static int nfs4_recovery_handle_error (struct nfs_client *clp,int error) {switch (error) {
@@ -1642,10 +1626,6 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION :set_bit (NFS4CLNT_BIND_CONN_TO_SESSION , &clp->cl_state);break ; -case -EKEYEXPIRED : -/* Nothing we can do */ -nfs4_warn_keyexpired (clp->cl_hostname); -break ;default :dprintk ("%s: failed to handle error %d for server %s\n" , __func__, error, clp->cl_hostname);
@@ -1762,8 +1742,6 @@ static int nfs4_handle_reclaim_lease_error(struct nfs_client *clp, int status)dprintk ("%s: exit with error %d for server %s\n" , __func__, -EPROTONOSUPPORT , clp->cl_hostname);return -EPROTONOSUPPORT ; -case -EKEYEXPIRED : -nfs4_warn_keyexpired (clp->cl_hostname);case -NFS4ERR_NOT_SAME :/* FixMe: implement recovery * in nfs4_exchange_id */ default :
@@ -1916,7 +1894,6 @@ again:break ;case -EKEYEXPIRED : -nfs4_warn_keyexpired (clp->cl_hostname);case -NFS4ERR_NOT_SAME :/* FixMe: implement recovery * in nfs4_exchange_id */ status = -EKEYEXPIRED ;
fs/nfs/proc.c +0 -43
73 lines not on this page · raw message
net/sunrpc/clnt.c +1 -0
@@ -1381,6 +1381,7 @@ call_refreshresult(struct rpc_task *task)return ;case -ETIMEDOUT :rpc_delay (task,3 *HZ ); +case -EKEYEXPIRED :case -EAGAIN : status = -EACCES ;if (!task->tk_cred_retry)
Signature · 1 line
1.7.7.6
PATCH 2/5 SUNRPC set gss gc_expiry to full lifetime
In reply to [email protected]From: Andy Adamson <[email protected]>
Only use the default GSSD_MIN_TIMEOUT if the gss downcall timeout is zero. Store the full lifetime in gc_expiry (not 3/4 of the lifetime) as subsequent patches will use the gc_expiry to determine buffered WRITE behavior in the face of expired or soon to be expired gss credentials.
--- net/sunrpc/auth_gss/auth_gss.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +13 -4
@@ -192,17 +192,23 @@ gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, structconst void *q;unsigned int seclen;unsigned int timeout; +unsigned long now = jiffies;u32 window_size;int ret; -/* First unsigned int gives the lifetime (in seconds) of the cred */ +/* First unsigned int gives the remaining lifetime in seconds of the +* credential - e.g. the remaining TGT lifetime for Kerberos or +* the -t value passed to GSSD. +*/ p =simple_get_bytes (p, end, &timeout,sizeof (timeout));if (IS_ERR (p)) goto err;if (timeout ==0 ) timeout =GSSD_MIN_TIMEOUT ; - ctx->gc_expiry = jiffies + (unsigned long )timeout *HZ *3 /4 ; -/* Sequence number window. Determines the maximum number of simultaneous requests */ + ctx->gc_expiry = now + ((unsigned long )timeout *HZ ); +/* Sequence number window. Determines the maximum number of +* simultaneous requests +*/ p =simple_get_bytes (p, end, &window_size,sizeof (window_size));if (IS_ERR (p)) goto err;
@@ -237,9 +243,12 @@ gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct p =ERR_PTR (ret); goto err; } +dprintk ("RPC: %s Success. gc_expiry %lu now %lu timeout %u\n" , + __func__, ctx->gc_expiry, now, timeout);return q; err: -dprintk ("RPC: %s returning %ld\n" , __func__, -PTR_ERR (p)); +dprintk ("RPC: %s returns %ld gc_expiry %lu now %lu timeout %u\n" , + __func__, -PTR_ERR (p), ctx->gc_expiry, now, timeout);return p; }
Signature · 1 line
1.7.7.6
PATCH 3/5 SUNRPC new rpc_credops to test credential expiry
In reply to [email protected]From: Andy Adamson <[email protected]>
This patch provides the RPC layer helper functions to allow NFS to manage data in the face of expired credentials - such as avoiding buffered WRITEs and COMMITs when the gss context will expire before the WRITEs are flushed and COMMITs are sent.
These helper functions enable checking the expiration of an underlying credential key for a generic rpc credential, e.g. the gss_cred gss context gc_expiry which for Kerberos is set to the remaining TGT lifetime.
A new rpc_authops key_timeout is only defined for the generic auth. A new rpc_credops crkey_to_expire is only defined for the generic cred. A new rpc_credops crkey_timeout is only defined for the gss cred.
Set a credential key expiry watermark, RPC_KEY_EXPIRE_TIMEO set to 60 seconds.
NOTE: this timeout is a guess that works in a VM environment. We may want to make it adjustable via a module parameter.
If key_timeout is called on a credential with an underlying credential key that will expire within watermark seconds, we set the RPC_CRED_KEY_EXPIRE_SOON flag in the generic_cred acred so that the NFS layer can clean up prior to key expiration.
Checking a generic credential's underlying credential involves a cred lookup. To avoid this lookup in the normal case when the underlying credential has a key that is valid (before the watermark), a notify flag is set in the generic credential the first time the key_timeout is called. The generic credential then stops checking the underlying credential key expiry, and the underlying credential (gss_cred) match routine then checks the key expiration upon each normal use and sets a flag in the associated generic credential only when the key expiration is within the watermark. This in turn signals the generic credential key_timeout to perform the extra credetial lookup thereafter.
--- include/linux/sunrpc/auth.h | 21 ++++++++++ net/sunrpc/auth.c | 21 +++++++++- net/sunrpc/auth_generic.c | 84 ++++++++++++++++++++++++++++++++++++++++ net/sunrpc/auth_gss/auth_gss.c | 44 ++++++++++++++++++++- 4 files changed, 167 insertions(+), 3 deletions(-)
include/linux/sunrpc/auth.h +21 -0
@@ -21,12 +21,25 @@/* size of the nodename buffer */ #define UNX_MAXNODENAME 32 +/* Set RPC_CRED_KEY_EXPIRE_SOON auth_cred flag if called RPC_CRED_EXPIRE_TIMEO +* seconds before the credential key will expire */ +#define RPC_KEY_EXPIRE_TIMEO (60 * HZ) + +/* auth_cred ac_flags bits */ +enum { +RPC_CRED_NO_CRKEY_TIMEOUT =0 ,/* underlying cred has no key timeout */ +RPC_CRED_KEY_EXPIRE_SOON =1 ,/* underlying cred key will expire soon */ +RPC_CRED_NOTIFY_TIMEOUT =2 ,/* nofity generic cred when underlying +key will expire soon */ +}; +/* Work around the lack of a VFS credential */ struct auth_cred {uid_t uid;gid_t gid;struct group_info *group_info;const char *principal; +unsigned long ac_flags;unsigned char machine_cred :1 ; };
@@ -102,6 +115,8 @@ struct rpc_authops {int (*pipes_create)(struct rpc_auth *);void (*pipes_destroy)(struct rpc_auth *);int (*list_pseudoflavors)(rpc_authflavor_t *,int ); +int (*key_timeout)(struct rpc_auth *, +struct rpc_cred *); };struct rpc_credops {
@@ -118,6 +133,9 @@ struct rpc_credops { void *, __be32 *, void *);int (*crunwrap_resp)(struct rpc_task *,kxdrdproc_t ,void *,__be32 *,void *); +int (*crkey_timeout)(struct rpc_cred *, +unsigned long ); +bool (*crkey_to_expire)(struct rpc_cred *); };extern const struct rpc_authops authunix_ops;
@@ -152,6 +170,9 @@ int rpcauth_uptodatecred(struct rpc_task *);int rpcauth_init_credcache (struct rpc_auth *);void rpcauth_destroy_credcache (struct rpc_auth *);void rpcauth_clear_credcache (struct rpc_cred_cache *); +int rpcauth_key_timeout_notify (struct rpc_auth *, +struct rpc_cred *); +bool rpcauth_cred_key_to_expire (struct rpc_cred *);static inline struct rpc_cred *get_rpccred (struct rpc_cred *cred)
net/sunrpc/auth.c +20 -1
@@ -270,8 +270,27 @@ out_nocache:EXPORT_SYMBOL_GPL (rpcauth_init_credcache);/* -* Destroy a list of credentials +* Setup a credential key lifetime timeout notification */ +int +rpcauth_key_timeout_notify (struct rpc_auth *auth,struct rpc_cred *cred) +{ +if (!cred->cr_auth->au_ops->key_timeout) +return 0 ; +return cred->cr_auth->au_ops->key_timeout (auth, cred); +} +EXPORT_SYMBOL_GPL (rpcauth_key_timeout_notify); + +bool +rpcauth_cred_key_to_expire (struct rpc_cred *cred) +{ +if (!cred->cr_ops->crkey_to_expire) +return false; +return cred->cr_ops->crkey_to_expire (cred); +} +EXPORT_SYMBOL_GPL (rpcauth_cred_key_to_expire); + +/* Destroy a list of credentials */ static inline void rpcauth_destroy_credlist (struct list_head *head) {
net/sunrpc/auth_generic.c +84 -0
110 lines not on this page · raw message
net/sunrpc/auth_gss/auth_gss.c +42 -2
69 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH 4/5 NFS avoid expired credential keys for buffered writes
In reply to [email protected]From: Andy Adamson <[email protected]>
We must avoid buffering a WRITE that is using a credential key (e.g. a GSS context key) that is about to expire or has expired. We currently will paint ourselves into a corner by returning success to the applciation for such a buffered WRITE, only to discover that we do not have permission when we attempt to flush the WRITE (and potentially associated COMMIT) to disk.
Use the RPC layer credential key timeout and expire routines which use a a watermark, RPC_KEY_EXPIRE_TIMEO. We test the key in nfs_file_write.
If a WRITE is using a credential with a key that will expire within watermark seconds, flush the inode in nfs_write_end and send only NFS_FILE_SYNC WRITEs by adding nfs_ctx_key_to_expire to nfs_need_sync_write. Note that this results in single page NFS_FILE_SYNC WRITEs.
--- fs/nfs/file.c | 15 ++++++++++++++- fs/nfs/internal.h | 2 ++ fs/nfs/write.c | 27 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletions(-)
fs/nfs/file.c +14 -1
@@ -406,6 +406,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping, struct page *page, void *fsdata) { unsigned offset = pos & (PAGE_CACHE_SIZE - 1); +struct nfs_open_context *ctx =nfs_file_open_context (file);int status; dfprintk(PAGECACHE, "NFS: write_end(%s/%s(%ld), %u@%lld)\n",
@@ -441,6 +442,13 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,if (status <0 )return status;NFS_I (mapping->host)->write_io += copied; + +if (nfs_ctx_key_to_expire (ctx)) { + status =nfs_wb_all (mapping->host); +if (status <0 ) +return status; + } +return copied; }
@@ -605,7 +613,8 @@ static int nfs_need_sync_write(struct file *filp, struct inode *inode)if (IS_SYNC (inode) || (filp->f_flags &O_DSYNC ))return 1 ; ctx =nfs_file_open_context (filp); -if (test_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags)) +if (test_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags) || +nfs_ctx_key_to_expire (ctx))return 1 ;return 0 ; }
@@ -619,6 +628,10 @@ ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,ssize_t result;size_t count =iov_length (iov, nr_segs); + result =nfs_key_timeout_notify (iocb->ki_filp); +if (result) +return result; +if (iocb->ki_filp->f_flags &O_DIRECT )return nfs_file_direct_write (iocb, iov, nr_segs, pos, true);
fs/nfs/internal.h +2 -0
@@ -428,6 +428,8 @@ void nfs_request_remove_commit_list(struct nfs_page *req,void nfs_init_cinfo (struct nfs_commit_info *cinfo,struct inode *inode,struct nfs_direct_req *dreq); +int nfs_key_timeout_notify (struct file *filp); +bool nfs_ctx_key_to_expire (struct nfs_open_context *ctx);#ifdef CONFIG_MIGRATION extern int nfs_migrate_page(struct address_space *,
fs/nfs/write.c +27 -0
@@ -871,6 +871,33 @@ int nfs_flush_incompatible(struct file *file, struct page *page) }/* +* Avoid buffered writes when a open context credential's key would +* expire soon. +* +* Returns -EACCES if the key will expire within RPC_KEY_EXPIRE_FAIL. +* +* Return 0 and set a credential flag which triggers the inode to flush +* and performs NFS_FILE_SYNC writes if the key will expired within +* RPC_KEY_EXPIRE_TIMEO. +*/ +int +nfs_key_timeout_notify (struct file *filp) +{ +struct nfs_open_context *ctx =nfs_file_open_context (filp); +struct rpc_auth *auth =NFS_SERVER (ctx->state->inode)->client->cl_auth; + +return rpcauth_key_timeout_notify (auth, ctx->cred); +} + +/* +* Test if the open context credential key is marked to expire soon. +*/ +bool nfs_ctx_key_to_expire (struct nfs_open_context *ctx) +{ +return rpcauth_cred_key_to_expire (ctx->cred); +} + +/* * If the page cache is marked as unsafe or invalid, then we can't rely on * the PageUptodate() flag. In this case, we will need to turn off * write optimisations that depend on the page contents being correct.
Signature · 1 line
1.7.7.6
PATCH 5/5 SUNRPC refactor rpcauth_checkverf error returns
In reply to [email protected]From: Andy Adamson <[email protected]>
Most of the time an error from the credops crvalidate function means the server has sent us a garbage verifier. The gss_validate function is the exception where there is an -EACCES case if the user GSS_context on the client has expired.
--- net/sunrpc/auth_gss/auth_gss.c | 7 +++++-- net/sunrpc/auth_null.c | 5 +++-- net/sunrpc/auth_unix.c | 5 +++-- net/sunrpc/clnt.c | 17 ++++++++++------- 4 files changed, 21 insertions(+), 13 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +5 -2
@@ -1300,6 +1300,7 @@ gss_validate(struct rpc_task *task, __be32 *p)struct xdr_netobj mic;u32 flav,len;u32 maj_stat; +__be32 *ret =ERR_PTR (-EIO );dprintk ("RPC: %5u %s\n" , task->tk_pid, __func__);
@@ -1315,6 +1316,7 @@ gss_validate(struct rpc_task *task, __be32 *p) mic.data = (u8 *)p; mic.len = len; + ret =ERR_PTR (-EACCES ); maj_stat =gss_verify_mic (ctx->gc_gss_ctx, &verf_buf, &mic);if (maj_stat ==GSS_S_CONTEXT_EXPIRED )clear_bit (RPCAUTH_CRED_UPTODATE , &cred->cr_flags);
@@ -1332,8 +1334,9 @@ gss_validate(struct rpc_task *task, __be32 *p)return p +XDR_QUADLEN (len); out_bad:gss_put_ctx (ctx); -dprintk ("RPC: %5u %s failed.\n" , task->tk_pid, __func__); -return NULL ; +dprintk ("RPC: %5u %s failed ret %ld.\n" , task->tk_pid, __func__, +PTR_ERR (ret)); +return ret; } static void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
net/sunrpc/auth_null.c +3 -2
@@ -84,17 +84,18 @@ nul_validate(struct rpc_task *task, __be32 *p) {rpc_authflavor_t flavor;u32 size; +__be32 *ret =ERR_PTR (-EIO ); flavor =ntohl (*p++);if (flavor !=RPC_AUTH_NULL ) {printk ("RPC: bad verf flavor: %u\n" , flavor); -return NULL ; +return ret; } size =ntohl (*p++);if (size !=0 ) {printk ("RPC: bad verf size: %u\n" , size); -return NULL ; +return ret; }return p;
net/sunrpc/auth_unix.c +3 -2
@@ -192,19 +192,20 @@ unx_validate(struct rpc_task *task, __be32 *p) {rpc_authflavor_t flavor;u32 size; +__be32 *ret =ERR_PTR (-EIO ); flavor =ntohl (*p++);if (flavor !=RPC_AUTH_NULL && flavor !=RPC_AUTH_UNIX && flavor !=RPC_AUTH_SHORT ) {printk ("RPC: bad verf flavor: %u\n" , flavor); -return NULL ; +return ret; } size =ntohl (*p++);if (size >RPC_MAX_AUTH_SIZE ) {printk ("RPC: giant verf size: %u\n" , size); -return NULL ; +return ret; } task->tk_rqstp->rq_cred->cr_auth->au_rslack = (size >>2 ) +2 ; p += (size >>2 );
net/sunrpc/clnt.c +10 -7
@@ -2041,7 +2041,8 @@ rpc_verify_header(struct rpc_task *task)dprintk ("RPC: %5u %s: XDR representation not a multiple of" " 4 bytes: 0x%x\n" , task->tk_pid, __func__, task->tk_rqstp->rq_rcv_buf.len); - goto out_eio; + error = -EIO ; + goto out_err; }if ((len -=3 ) <0 ) goto out_overflow;
@@ -2050,6 +2051,7 @@ rpc_verify_header(struct rpc_task *task)if ((n =ntohl (*p++)) !=RPC_REPLY ) {dprintk ("RPC: %5u %s: not an RPC reply: %x\n" , task->tk_pid, __func__, n); + error = -EIO ; goto out_garbage; }
@@ -2068,7 +2070,8 @@ rpc_verify_header(struct rpc_task *task)dprintk ("RPC: %5u %s: RPC call rejected, " "unknown error: %x\n" , task->tk_pid, __func__, n); - goto out_eio; + error = -EIO ; + goto out_err; }if (--len <0 ) goto out_overflow;
@@ -2113,9 +2116,11 @@ rpc_verify_header(struct rpc_task *task) task->tk_pid, __func__, n); goto out_err; } -if (!(p =rpcauth_checkverf (task, p))) { -dprintk ("RPC: %5u %s: auth check failed\n" , - task->tk_pid, __func__); + p =rpcauth_checkverf (task, p); +if (IS_ERR (p)) { + error =PTR_ERR (p); +dprintk ("RPC: %5u %s: auth check failed with %d\n" , + task->tk_pid, __func__, error); goto out_garbage;/* bad verifier, retry */ } len = p - (__be32 *)iov->iov_base -1 ;
@@ -2168,8 +2173,6 @@ out_garbage: out_retry:return ERR_PTR (-EAGAIN ); } -out_eio: - error = -EIO ; out_err:rpc_exit (task, error); dprintk("RPC: %5u %s: call failed with error %d\n", task->tk_pid,
Signature · 1 line
1.7.7.6