nfs: fix NULL deference in nfs4_get_valid_delegation
authorJ. Bruce Fields <bfields@redhat.com>
Mon, 11 May 2020 14:02:48 +0000 (10:02 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 May 2020 06:20:24 +0000 (08:20 +0200)
commitd1538d8d632542f1db8b5df8deca35e28230ee98
tree25d79f0c042e4e648587c5867ea20206c70b49dc
parentea7c4d9e542fe8e8bf5b6e5e069fb288c97a7e0e
nfs: fix NULL deference in nfs4_get_valid_delegation

[ Upstream commit 29fe839976266bc7c55b927360a1daae57477723 ]

We add the new state to the nfsi->open_states list, making it
potentially visible to other threads, before we've finished initializing
it.

That wasn't a problem when all the readers were also taking the i_lock
(as we do here), but since we switched to RCU, there's now a possibility
that a reader could see the partially initialized state.

Symptoms observed were a crash when another thread called
nfs4_get_valid_delegation() on a NULL inode, resulting in an oops like:

BUG: unable to handle page fault for address: ffffffffffffffb0 ...
RIP: 0010:nfs4_get_valid_delegation+0x6/0x30 [nfsv4] ...
Call Trace:
 nfs4_open_prepare+0x80/0x1c0 [nfsv4]
 __rpc_execute+0x75/0x390 [sunrpc]
 ? finish_task_switch+0x75/0x260
 rpc_async_schedule+0x29/0x40 [sunrpc]
 process_one_work+0x1ad/0x370
 worker_thread+0x30/0x390
 ? create_worker+0x1a0/0x1a0
 kthread+0x10c/0x130
 ? kthread_park+0x80/0x80
 ret_from_fork+0x22/0x30

Fixes: 9ae075fdd190 "NFSv4: Convert open state lookup to use RCU"
Reviewed-by: Seiichi Ikarashi <s.ikarashi@fujitsu.com>
Tested-by: Daisuke Matsuda <matsuda-daisuke@fujitsu.com>
Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Cc: stable@vger.kernel.org # v4.20+
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/nfs4state.c