Skip to content

Commit 18ac618

Browse files
committed
afs: Fix callback handling
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: 68251f0 ("afs: Fix whole-volume callback handling") Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 2feeaf8 commit 18ac618

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎fs/afs/fsclient.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static void xdr_decode_AFSCallBack(struct afs_call *call,
269269

270270
write_seqlock(&vnode->cb_lock);
271271

272-
if (call->cb_break == afs_cb_break_sum(vnode, cbi)) {
272+
if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
273273
vnode->cb_version = ntohl(*bp++);
274274
cb_expiry = ntohl(*bp++);
275275
vnode->cb_type = ntohl(*bp++);

‎fs/afs/internal.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,13 @@ static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
776776
return vnode->cb_break + vnode->cb_s_break + vnode->cb_v_break;
777777
}
778778

779-
static inline unsigned int afs_cb_break_sum(struct afs_vnode *vnode,
780-
struct afs_cb_interest *cbi)
779+
static inline bool afs_cb_is_broken(unsigned int cb_break,
780+
const struct afs_vnode *vnode,
781+
const struct afs_cb_interest *cbi)
781782
{
782-
return vnode->cb_break + cbi->server->cb_s_break + vnode->volume->cb_v_break;
783+
return !cbi || cb_break != (vnode->cb_break +
784+
cbi->server->cb_s_break +
785+
vnode->volume->cb_v_break);
783786
}
784787

785788
/*

‎fs/afs/security.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
147147
break;
148148
}
149149

150-
if (cb_break != afs_cb_break_sum(vnode, vnode->cb_interest)) {
150+
if (afs_cb_is_broken(cb_break, vnode,
151+
vnode->cb_interest)) {
151152
changed = true;
152153
break;
153154
}
@@ -177,7 +178,7 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
177178
}
178179
}
179180

180-
if (cb_break != afs_cb_break_sum(vnode, vnode->cb_interest))
181+
if (afs_cb_is_broken(cb_break, vnode, vnode->cb_interest))
181182
goto someone_else_changed_it;
182183

183184
/* 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,
256257

257258
spin_lock(&vnode->lock);
258259
zap = rcu_access_pointer(vnode->permit_cache);
259-
if (cb_break == afs_cb_break_sum(vnode, vnode->cb_interest) &&
260+
if (!afs_cb_is_broken(cb_break, vnode, vnode->cb_interest) &&
260261
zap == permits)
261262
rcu_assign_pointer(vnode->permit_cache, replacement);
262263
else

‎fs/afs/yfsclient.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static void xdr_decode_YFSCallBack(struct afs_call *call,
324324

325325
write_seqlock(&vnode->cb_lock);
326326

327-
if (call->cb_break == afs_cb_break_sum(vnode, cbi)) {
327+
if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
328328
cb_expiry = xdr_to_u64(xdr->expiration_time);
329329
do_div(cb_expiry, 10 * 1000 * 1000);
330330
vnode->cb_version = ntohl(xdr->version);

0 commit comments

Comments
 (0)