afs: Fix missing cursor clearance
authorDavid Howells <dhowells@redhat.com>
Tue, 6 Feb 2018 06:26:30 +0000 (06:26 +0000)
committerDavid Howells <dhowells@redhat.com>
Tue, 6 Feb 2018 14:36:54 +0000 (14:36 +0000)
commitfe4d774c847398c2a45c10a780ccfde069840793
tree80e685497ff9e9a7b703e8f9f6cef8c5b80e8946
parente44150157f42219fa5c074588efdb31ccfb197fc
afs: Fix missing cursor clearance

afs_select_fileserver() ends the address cursor it is using in the case in
which we get some sort of network error and run out of addresses to iterate
through, before it jumps to try the next server.  This also needs to be
done when the server aborts with some sort of error that means we should
try the next server.

Fix this by:

 (1) Move the iterate_address afs_end_cursor() call to the next_server
     case.

 (2) End the cursor in the failed case.

 (3) Make afs_end_cursor() clear the ->begun flag and ->addr pointer in the
     address cursor.

 (4) Make afs_end_cursor() able to be called on an already cleared cursor.

Without this, something like the following oops may occur:

AFS: Assertion failed
18446612134397189888 == 0 is false
0xffff88007c279f00 == 0x0 is false
------------[ cut here ]------------
kernel BUG at fs/afs/rotate.c:360!
RIP: 0010:afs_select_fileserver+0x79b/0xa30 [kafs]
Call Trace:
 afs_statfs+0xcc/0x180 [kafs]
 ? p9_client_statfs+0x9e/0x110 [9pnet]
 ? _cond_resched+0x19/0x40
 statfs_by_dentry+0x6d/0x90
 vfs_statfs+0x1b/0xc0
 user_statfs+0x4b/0x80
 SYSC_statfs+0x15/0x30
 SyS_statfs+0xe/0x10
 entry_SYSCALL_64_fastpath+0x20/0x83

Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation")
Reported-by: Marc Dionne <marc.dionne@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: stable@vger.kernel.org
fs/afs/addr_list.c
fs/afs/rotate.c