linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: viro@zeniv.linux.org.uk
Cc: dhowells@redhat.com, linux-afs@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 24/25] afs: Fix callback handling [ver #2]
Date: Wed, 24 Oct 2018 01:00:40 +0100	[thread overview]
Message-ID: <154033924063.12041.12132959166024617.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <154033906284.12041.12908874734066278152.stgit@warthog.procyon.org.uk>

In some circumstances, the callback interest pointer is NULL, so in such a
case we can't dereference it when checking to see if the callback is
broken.  This causes an oops in some circumstances.

Fix this by replacing the function that worked out the aggregate break
counter with one that actually does the comparison, and then make that
return true (ie. broken) if there is no callback interest as yet (ie. the
pointer is NULL).

Fixes: 68251f0a6818 ("afs: Fix whole-volume callback handling")
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/afs/fsclient.c  |    2 +-
 fs/afs/internal.h  |    9 ++++++---
 fs/afs/security.c  |    7 ++++---
 fs/afs/yfsclient.c |    2 +-
 4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index 3975969719de..7c75a1813321 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -269,7 +269,7 @@ static void xdr_decode_AFSCallBack(struct afs_call *call,
 
 	write_seqlock(&vnode->cb_lock);
 
-	if (call->cb_break == afs_cb_break_sum(vnode, cbi)) {
+	if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
 		vnode->cb_version	= ntohl(*bp++);
 		cb_expiry		= ntohl(*bp++);
 		vnode->cb_type		= ntohl(*bp++);
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index e5b596bd8acf..b60d15212975 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -776,10 +776,13 @@ static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
 	return vnode->cb_break + vnode->cb_s_break + vnode->cb_v_break;
 }
 
-static inline unsigned int afs_cb_break_sum(struct afs_vnode *vnode,
-					    struct afs_cb_interest *cbi)
+static inline bool afs_cb_is_broken(unsigned int cb_break,
+				    const struct afs_vnode *vnode,
+				    const struct afs_cb_interest *cbi)
 {
-	return vnode->cb_break + cbi->server->cb_s_break + vnode->volume->cb_v_break;
+	return !cbi || cb_break != (vnode->cb_break +
+				    cbi->server->cb_s_break +
+				    vnode->volume->cb_v_break);
 }
 
 /*
diff --git a/fs/afs/security.c b/fs/afs/security.c
index d1ae53fd3739..5f58a9a17e69 100644
--- a/fs/afs/security.c
+++ b/fs/afs/security.c
@@ -147,7 +147,8 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
 					break;
 				}
 
-				if (cb_break != afs_cb_break_sum(vnode, vnode->cb_interest)) {
+				if (afs_cb_is_broken(cb_break, vnode,
+						     vnode->cb_interest)) {
 					changed = true;
 					break;
 				}
@@ -177,7 +178,7 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
 		}
 	}
 
-	if (cb_break != afs_cb_break_sum(vnode, vnode->cb_interest))
+	if (afs_cb_is_broken(cb_break, vnode, vnode->cb_interest))
 		goto someone_else_changed_it;
 
 	/* We need a ref on any permits list we want to copy as we'll have to
@@ -256,7 +257,7 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
 
 	spin_lock(&vnode->lock);
 	zap = rcu_access_pointer(vnode->permit_cache);
-	if (cb_break == afs_cb_break_sum(vnode, vnode->cb_interest) &&
+	if (!afs_cb_is_broken(cb_break, vnode, vnode->cb_interest) &&
 	    zap == permits)
 		rcu_assign_pointer(vnode->permit_cache, replacement);
 	else
diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c
index d5e3f0095040..12658c1363ae 100644
--- a/fs/afs/yfsclient.c
+++ b/fs/afs/yfsclient.c
@@ -324,7 +324,7 @@ static void xdr_decode_YFSCallBack(struct afs_call *call,
 
 	write_seqlock(&vnode->cb_lock);
 
-	if (call->cb_break == afs_cb_break_sum(vnode, cbi)) {
+	if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
 		cb_expiry = xdr_to_u64(xdr->expiration_time);
 		do_div(cb_expiry, 10 * 1000 * 1000);
 		vnode->cb_version	= ntohl(xdr->version);


  parent reply	other threads:[~2018-10-24  3:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23 23:57 [PATCH 00/25] AFS development [ver #2] David Howells
2018-10-23 23:57 ` [PATCH 01/25] amd-gpu: Don't undefine READ and WRITE " David Howells
2018-11-01 22:06   ` Pavel Machek
2018-10-23 23:57 ` [PATCH 02/25] iov_iter: Use accessor function " David Howells
2018-11-28  1:39   ` NeilBrown
2018-10-23 23:58 ` [PATCH 03/25] iov_iter: Separate type from direction and use accessor functions " David Howells
2018-10-23 23:58 ` [PATCH 04/25] iov_iter: Add I/O discard iterator " David Howells
2018-10-23 23:58 ` [PATCH 05/25] afs: Better tracing of protocol errors " David Howells
2018-10-23 23:58 ` [PATCH 06/25] afs: Set up the iov_iter before calling afs_extract_data() " David Howells
2018-10-23 23:58 ` [PATCH 07/25] afs: Improve FS server rotation error handling " David Howells
2018-10-23 23:58 ` [PATCH 08/25] afs: Implement VL server rotation " David Howells
2018-10-23 23:58 ` [PATCH 09/25] afs: Fix TTL on VL server and address lists " David Howells
2018-10-23 23:59 ` [PATCH 10/25] afs: Handle EIO from delivery function " David Howells
2018-10-23 23:59 ` [PATCH 11/25] afs: Add a couple of tracepoints to log I/O errors " David Howells
2018-10-23 23:59 ` [PATCH 12/25] afs: Don't invoke the server to read data beyond EOF " David Howells
2018-10-23 23:59 ` [PATCH 13/25] afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS " David Howells
2018-10-23 23:59 ` [PATCH 14/25] afs: Commit the status on a new file/dir/symlink " David Howells
2018-10-23 23:59 ` [PATCH 15/25] afs: Remove callback details from afs_callback_break struct " David Howells
2018-10-23 23:59 ` [PATCH 16/25] afs: Implement the YFS cache manager service " David Howells
2018-10-23 23:59 ` [PATCH 17/25] afs: Fix FS.FetchStatus delivery from updating wrong vnode " David Howells
2018-10-23 23:59 ` [PATCH 18/25] afs: Calc callback expiry in op reply delivery " David Howells
2018-10-24  0:00 ` [PATCH 19/25] afs: Get the target vnode in afs_rmdir() and get a callback on it " David Howells
2018-10-24  0:00 ` [PATCH 20/25] afs: Expand data structure fields to support YFS " David Howells
2018-10-24  0:00 ` [PATCH 21/25] afs: Implement YFS support in the fs client " David Howells
2018-10-24  0:00 ` [PATCH 22/25] afs: Allow dumping of server cursor on operation failure " David Howells
2018-10-24  0:00 ` [PATCH 23/25] afs: Eliminate the address pointer from the address list cursor " David Howells
2018-10-24  0:00 ` David Howells [this message]
2018-10-24  0:00 ` [PATCH 25/25] afs: Probe multiple fileservers simultaneously " David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=154033924063.12041.12132959166024617.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).