Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C88434847A for ; Tue, 21 Oct 2025 17:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761066196; cv=none; b=tMMOUpFCcqHpTC3nK6sYUB9yvt0iw1pGCXI0j5WH4ssDrmP61iLJw3AkDnlWzldBAE4u3Ha+GW2jBL2HBBo2T+W7BgNvmALQQ3+I2DLlAwX93uDFrWUSw/UgZhf8cnW/A2k/2Fpcm63r4tcetOxNLXV2dPhBoru/bIyJykkNldM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761066196; c=relaxed/simple; bh=8N0fnPKehSPZJyBshEHXocnNBSBW/xlBdz5JC0bRk5o=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=tefEcOwcjtsuFpT/jgUyk1x2ZUxscf2kHbSz+nAtmxzzO6Enc5H1DAtLO1KsL/44ra2nvg77Oe2gTXGSDYwtZk0qsF1yppVCQjOmLQaMCvL6P5+XeytaCX0rbhLgdAI4VXPvTl5WyXi84d1ikAXGJjIagdUlHcH+l4DwBEgjFWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LKYb9a1+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LKYb9a1+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D0A7C4CEF5; Tue, 21 Oct 2025 17:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761066195; bh=8N0fnPKehSPZJyBshEHXocnNBSBW/xlBdz5JC0bRk5o=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LKYb9a1+T5of5B4VDWqXOqi4ZdFOjgYH0HVbcduMn+BLw8nskRyJiQekGcIaZmejr DQUNQASLg5XC2jJdAkFn/AjuhnudmDOXb1/CVjVYicHsIc20VCpwD+plLJ2B8PeTLp q/BucUEu+LZMt2mFEjJt4KUmQqkXMfEMPPlmo5fv9BJLDS3W2HHsvj2BuFmXYlLb3r VbY2f4Ro6cSouSRbBsaGnb+fjnIlroznnwEkOp/kNe1lioZk4q2JAdOo8pLzMJPykr OvEQ/OkBvWgNJZWADJ5LpJy+N3rWoErhY6dZOunh+2h8NNYsfjy3Gj1XxJ8eZyPbzw xDE/engn4o54w== Message-ID: Subject: Re: [RFC PATCH 1/1] lockd: prevent UAF in nlm4svc_proc_test in reexport NLM From: Jeff Layton To: Olga Kornievskaia Cc: Olga Kornievskaia , chuck.lever@oracle.com, linux-nfs@vger.kernel.org, neilb@brown.name, Dai.Ngo@oracle.com, tom@talpey.com Date: Tue, 21 Oct 2025 13:03:14 -0400 In-Reply-To: References: <20251021130506.45065-1-okorniev@redhat.com> <33ba39d2ff01eb0e52c80aa7015d27e34dde7fd2.camel@kernel.org> Autocrypt: addr=jlayton@kernel.org; prefer-encrypt=mutual; keydata=mQINBE6V0TwBEADXhJg7s8wFDwBMEvn0qyhAnzFLTOCHooMZyx7XO7dAiIhDSi7G1NPxw n8jdFUQMCR/GlpozMFlSFiZXiObE7sef9rTtM68ukUyZM4pJ9l0KjQNgDJ6Fr342Htkjxu/kFV1Wv egyjnSsFt7EGoDjdKqr1TS9syJYFjagYtvWk/UfHlW09X+jOh4vYtfX7iYSx/NfqV3W1D7EDi0PqV T2h6v8i8YqsATFPwO4nuiTmL6I40ZofxVd+9wdRI4Db8yUNA4ZSP2nqLcLtFjClYRBoJvRWvsv4lm 0OX6MYPtv76hka8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JmC0 BhZ/Ab4sph3EaiZfdXKhiQqSGdK4La3OTJOJYZphPdGgnkvDV9Pl1QZ0ijXQrVIy3zd6VCNaKYq7B AKidn5g/2Q8oio9Tf4XfdZ9dtwcB+bwDJFgvvDYaZ5bI3ln4V3EyW5i2NfXazz/GA/I/ZtbsigCFc 8ftCBKZWZmIExheXRvbiA8amxheXRvbkBrZXJuZWwub3JnPokCOAQTAQIAIgUCWe8u6AIbAwYLCQg HAwIGFQgCCQoLBBYCAwECHgECF4AACgkQAA5oQRlWghUuCg/+Lb/xGxZD2Q1oJVAE37uW308UpVSD 2tAMJUvFTdDbfe3zKlPDTuVsyNsALBGclPLagJ5ZTP+Vp2irAN9uwBuacBOTtmOdz4ZN2tdvNgozz uxp4CHBDVzAslUi2idy+xpsp47DWPxYFIRP3M8QG/aNW052LaPc0cedYxp8+9eiVUNpxF4SiU4i9J DfX/sn9XcfoVZIxMpCRE750zvJvcCUz9HojsrMQ1NFc7MFT1z3MOW2/RlzPcog7xvR5ENPH19ojRD CHqumUHRry+RF0lH00clzX/W8OrQJZtoBPXv9ahka/Vp7kEulcBJr1cH5Wz/WprhsIM7U9pse1f1g Yy9YbXtWctUz8uvDR7shsQxAhX3qO7DilMtuGo1v97I/Kx4gXQ52syh/w6EBny71CZrOgD6kJwPVV AaM1LRC28muq91WCFhs/nzHozpbzcheyGtMUI2Ao4K6mnY+3zIuXPygZMFr9KXE6fF7HzKxKuZMJO aEZCiDOq0anx6FmOzs5E6Jqdpo/mtI8beK+BE7Va6ni7YrQlnT0i3vaTVMTiCThbqsB20VrbMjlhp f8lfK1XVNbRq/R7GZ9zHESlsa35ha60yd/j3pu5hT2xyy8krV8vGhHvnJ1XRMJBAB/UYb6FyC7S+m QZIQXVeAA+smfTT0tDrisj1U5x6ZB9b3nBg65kc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2025-10-21 at 12:17 -0400, Olga Kornievskaia wrote: > On Tue, Oct 21, 2025 at 11:59=E2=80=AFAM Jeff Layton = wrote: > >=20 > > On Tue, 2025-10-21 at 11:23 -0400, Olga Kornievskaia wrote: > > > On Tue, Oct 21, 2025 at 9:40=E2=80=AFAM Jeff Layton wrote: > > > >=20 > > > > On Tue, 2025-10-21 at 09:05 -0400, Olga Kornievskaia wrote: > > > > > When knfsd is a reexport nfs server, it nlm4svc_proc_test() in > > > > > calling nlmsvc_testlock() with a lock conflict lock_release_priva= te() > > > > > call would end up calling nlmsvc_put_lockowner() and then back in > > > > > nlm4svc_proc_test() function there will be another call to > > > > > nlmsvc_put_lockowner() for the same owner leading to use-after-fr= ee > > > > > violation (below). > > > > >=20 > > > > > The problem only arises when the underlying file system has been > > > > > re-exported as different paths are taken in vfs_test_lock(). > > > > > When it's reexport, filp->f_op->lock is set and when vfs_test_loc= k() > > > > > is done fl_lmops pointer is non-null. When it's regular export, > > > > > vfs_test_lock() calls posix_test_lock() which ends up calling > > > > > locks_copy_conflock() and it copies NULL into fl_lmops and then > > > > > calling into lock_release_private() does not call > > > > > nlmsvc_put_lockowner(). > > > > >=20 > > > > > The proposed solution is to intentionally clear fl_lmops pointer = to > > > > > make sure that if there is a conflict (be it a local file system > > > > > or reexport), lock_release_private() would not call > > > > > nlmsvc_put_lockowner(). > > > > >=20 > > > > > kernel: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > > > kernel: BUG: KASAN: slab-use-after-free in nlmsvc_put_lockowner+0= x30/0x250 [lockd] > > > > > kernel: Read of size 4 at addr ffff0000bf3bca10 by task lockd/609= 2 > > > > > kernel: > > > > > kernel: CPU: 0 UID: 0 PID: 6092 Comm: lockd Kdump: loaded Not tai= nted 6.18.0-rc1+ #23 PREEMPT(voluntary) > > > > > kernel: Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.= 00V.24006586.BA64.2406042154 06/04/2024 > > > > > kernel: Call trace: > > > > > kernel: show_stack+0x34/0x98 (C) > > > > > kernel: dump_stack_lvl+0x80/0xa8 > > > > > kernel: print_address_description.constprop.0+0x90/0x310 > > > > > kernel: print_report+0x108/0x1f8 > > > > > kernel: kasan_report+0xc8/0x120 > > > > > kernel: kasan_check_range+0xe8/0x190 > > > > > kernel: __kasan_check_read+0x20/0x30 > > > > > kernel: nlmsvc_put_lockowner+0x30/0x250 [lockd] > > > > > kernel: __nlm4svc_proc_test+0x2a8/0x318 [lockd] > > > > > kernel: nlm4svc_proc_test+0x44/0xb78 [lockd] > > > > > kernel: nlmsvc_dispatch+0xb0/0x200 [lockd] > > > > > kernel: svc_process_common+0xb20/0x17b0 [sunrpc] > > > > > kernel: svc_process+0x414/0x900 [sunrpc] > > > > > kernel: svc_handle_xprt+0x5c8/0xd60 [sunrpc] > > > > > kernel: svc_recv+0x1a4/0x520 [sunrpc] > > > > > kernel: lockd+0x154/0x298 [lockd] > > > > > kernel: kthread+0x2f8/0x398 > > > > > kernel: ret_from_fork+0x10/0x20 > > > > > kernel: > > > > > kernel: Allocated by task 6092: > > > > > kernel: kasan_save_stack+0x3c/0x70 > > > > > kernel: kasan_save_track+0x20/0x40 > > > > > kernel: kasan_save_alloc_info+0x40/0x58 > > > > > kernel: __kasan_kmalloc+0xd4/0xd8 > > > > > kernel: __kmalloc_cache_noprof+0x1a8/0x5c0 > > > > > kernel: nlmsvc_locks_init_private+0xe4/0x520 [lockd] > > > > > kernel: nlm4svc_retrieve_args+0x38c/0x530 [lockd] > > > > > kernel: __nlm4svc_proc_test+0x194/0x318 [lockd] > > > > > kernel: nlm4svc_proc_test+0x44/0xb78 [lockd] > > > > > kernel: nlmsvc_dispatch+0xb0/0x200 [lockd] > > > > > kernel: svc_process_common+0xb20/0x17b0 [sunrpc] > > > > > kernel: svc_process+0x414/0x900 [sunrpc] > > > > > kernel: svc_handle_xprt+0x5c8/0xd60 [sunrpc] > > > > > kernel: svc_recv+0x1a4/0x520 [sunrpc] > > > > > kernel: lockd+0x154/0x298 [lockd] > > > > > kernel: kthread+0x2f8/0x398 > > > > > kernel: ret_from_fork+0x10/0x20 > > > > > kernel: > > > > > kernel: Freed by task 6092: > > > > > kernel: kasan_save_stack+0x3c/0x70 > > > > > kernel: kasan_save_track+0x20/0x40 > > > > > kernel: __kasan_save_free_info+0x4c/0x80 > > > > > kernel: __kasan_slab_free+0x88/0xc0 > > > > > kernel: kfree+0x110/0x480 > > > > > kernel: nlmsvc_put_lockowner+0x1b4/0x250 [lockd] > > > > > kernel: nlmsvc_put_owner+0x18/0x30 [lockd] > > > > > kernel: locks_release_private+0x190/0x2a8 > > > > > kernel: nlmsvc_testlock+0x2e0/0x648 [lockd] > > > > > kernel: __nlm4svc_proc_test+0x244/0x318 [lockd] > > > > > kernel: nlm4svc_proc_test+0x44/0xb78 [lockd] > > > > > kernel: nlmsvc_dispatch+0xb0/0x200 [lockd] > > > > > kernel: svc_process_common+0xb20/0x17b0 [sunrpc] > > > > > kernel: svc_process+0x414/0x900 [sunrpc] > > > > > kernel: svc_handle_xprt+0x5c8/0xd60 [sunrpc] > > > > > kernel: svc_recv+0x1a4/0x520 [sunrpc] > > > > > kernel: lockd+0x154/0x298 [lockd] > > > > > kernel: kthread+0x2f8/0x398 > > > > > kernel: ret_from_fork+0x10/0x20 > > > > > kernel: > > > > > kernel: The buggy address belongs to the object at ffff0000bf3bca= 00 > > > > > which belongs to the cache kmalloc-64 of size 64 > > > > > kernel: The buggy address is located 16 bytes inside of > > > > > freed 64-byte region [ffff0000bf3bca00, ffff0000bf3bca40) > > > > > kernel: > > > > > kernel: The buggy address belongs to the physical page: > > > > > kernel: page: refcount:0 mapcount:0 mapping:0000000000000000 inde= x:0x0 pfn:0x13f3bc > > > > > kernel: flags: 0x2fffff00000000(node=3D0|zone=3D2|lastcpupid=3D0x= fffff) > > > > > kernel: page_type: f5(slab) > > > > > kernel: raw: 002fffff00000000 ffff0000800028c0 dead000000000122 0= 000000000000000 > > > > > kernel: raw: 0000000000000000 0000000080200020 00000000f5000000 0= 000000000000000 > > > > > kernel: page dumped because: kasan: bad access detected > > > > > kernel: > > > > > kernel: Memory state around the buggy address: > > > > > kernel: ffff0000bf3bc900: fa fb fb fb fb fb fb fb fc fc fc fc fc= fc fc fc > > > > > kernel: ffff0000bf3bc980: fa fb fb fb fb fb fb fb fc fc fc fc fc= fc fc fc > > > > > kernel: >ffff0000bf3bca00: fa fb fb fb fb fb fb fb fc fc fc fc fc= fc fc fc > > > > > kernel: ^ > > > > > kernel: ffff0000bf3bca80: fa fb fb fb fb fb fb fb fc fc fc fc fc= fc fc fc > > > > > kernel: ffff0000bf3bcb00: fc fc fc fc fc fc fc fc fc fc fc fc fc= fc fc fc > > > > > kernel: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > > > kernel: Disabling lock debugging due to kernel taint > > > > > kernel: AGLO: nlmsvc_put_lockowner 00000000028055fb count=3D0 > > > > > kernel: CPU: 0 UID: 0 PID: 6092 Comm: lockd Kdump: loaded Tainted= : G B 6.18.0-rc1+ #23 PREEMPT(voluntary) > > > > > kernel: Tainted: [B]=3DBAD_PAGE > > > > > kernel: Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.= 00V.24006586.BA64.2406042154 06/04/2024 > > > > > kernel: Call trace: > > > > > kernel: show_stack+0x34/0x98 (C) > > > > > kernel: dump_stack_lvl+0x80/0xa8 > > > > > kernel: dump_stack+0x1c/0x30 > > > > > kernel: nlmsvc_put_lockowner+0x7c/0x250 [lockd] > > > > > kernel: __nlm4svc_proc_test+0x2a8/0x318 [lockd] > > > > > kernel: nlm4svc_proc_test+0x44/0xb78 [lockd] > > > > > kernel: nlmsvc_dispatch+0xb0/0x200 [lockd] > > > > > kernel: svc_process_common+0xb20/0x17b0 [sunrpc] > > > > > kernel: svc_process+0x414/0x900 [sunrpc] > > > > > kernel: svc_handle_xprt+0x5c8/0xd60 [sunrpc] > > > > > kernel: svc_recv+0x1a4/0x520 [sunrpc] > > > > > kernel: lockd+0x154/0x298 [lockd] > > > > > kernel: kthread+0x2f8/0x398 > > > > > kernel: ret_from_fork+0x10/0x20 > > > > > kernel: ------------[ cut here ]------------ > > > > > kernel: refcount_t: underflow; use-after-free. > > > > > kernel: WARNING: CPU: 0 PID: 6092 at lib/refcount.c:87 refcount_d= ec_not_one+0x198/0x1b0 > > > > > kernel: Modules linked in: rpcrdma rdma_cm iw_cm ib_cm ib_core nf= sd nfsv3 nfs_acl nfs lockd grace nfs_localio netfs ext4 crc16 mbcache jbd2 = overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_= hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc snd_hda_intel vide= obuf2_v4l2 videobuf2_common snd_intel_dspcfg videodev snd_hda_codec snd_hda= _core mc snd_hwdep snd_seq snd_seq_device snd_pcm snd_timer snd soundcore s= g loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vso= ck_vmci_transport vmw_vmci vsock xfs 8021q garp stp llc mrp nvme nvme_core = nvme_keyring nvme_auth ghash_ce hkdf e1000e sr_mod cdrom vmwgfx drm_ttm_hel= per ttm sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libis= csi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink > > > > > kernel: CPU: 0 UID: 0 PID: 6092 Comm: lockd Kdump: loaded Tainted= : G B 6.18.0-rc1+ #23 PREEMPT(voluntary) > > > > > kernel: Tainted: [B]=3DBAD_PAGE > > > > > kernel: Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.= 00V.24006586.BA64.2406042154 06/04/2024 > > > > > kernel: pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTY= PE=3D--) > > > > > kernel: pc : refcount_dec_not_one+0x198/0x1b0 > > > > > kernel: lr : refcount_dec_not_one+0x198/0x1b0 > > > > > kernel: sp : ffff80008a627930 > > > > > kernel: x29: ffff80008a627990 x28: ffff0000bf3bca00 x27: ffff0000= ba5c7000 > > > > > kernel: x26: 1fffe000191eeb84 x25: 1ffff000114c4f48 x24: ffff0000= c8f75c24 > > > > > kernel: x23: 0000000000000007 x22: ffff80008a627950 x21: 1ffff000= 114c4f26 > > > > > kernel: x20: 00000000ffffffff x19: ffff0000bf3bca10 x18: 00000000= 00000310 > > > > > kernel: x17: 0000000000000000 x16: 0000000000000000 x15: 00000000= 00000000 > > > > > kernel: x14: 0000000000000000 x13: 0000000000000001 x12: ffff6000= 4fd90aa3 > > > > > kernel: x11: 1fffe0004fd90aa2 x10: ffff60004fd90aa2 x9 : dfff8000= 00000000 > > > > > kernel: x8 : 00009fffb026f55e x7 : ffff00027ec85513 x6 : 00000000= 00000001 > > > > > kernel: x5 : ffff00027ec85510 x4 : ffff60004fd90aa3 x3 : ffff8000= 80787bc0 > > > > > kernel: x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0000= a75a8000 > > > > > kernel: Call trace: > > > > > kernel: refcount_dec_not_one+0x198/0x1b0 (P) > > > > > kernel: refcount_dec_and_lock+0x1c/0xb8 > > > > > kernel: nlmsvc_put_lockowner+0x9c/0x250 [lockd] > > > > > kernel: __nlm4svc_proc_test+0x2a8/0x318 [lockd] > > > > > kernel: nlm4svc_proc_test+0x44/0xb78 [lockd] > > > > > kernel: nlmsvc_dispatch+0xb0/0x200 [lockd] > > > > > kernel: svc_process_common+0xb20/0x17b0 [sunrpc] > > > > > kernel: svc_process+0x414/0x900 [sunrpc] > > > > > kernel: svc_handle_xprt+0x5c8/0xd60 [sunrpc] > > > > > kernel: svc_recv+0x1a4/0x520 [sunrpc] > > > > > kernel: lockd+0x154/0x298 [lockd] > > > > > kernel: kthread+0x2f8/0x398 > > > > > kernel: ret_from_fork+0x10/0x20 > > > > > kernel: ---[ end trace 0000000000000000 ]--- > > > > >=20 > > > > > Signed-off-by: Olga Kornievskaia > > > > > --- > > > > > fs/lockd/svclock.c | 1 + > > > > > 1 file changed, 1 insertion(+) > > > > >=20 > > > > > diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c > > > > > index a31dc9588eb8..1dd0fec186de 100644 > > > > > --- a/fs/lockd/svclock.c > > > > > +++ b/fs/lockd/svclock.c > > > > > @@ -652,6 +652,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struc= t nlm_file *file, > > > > > conflock->fl.c.flc_type =3D lock->fl.c.flc_type; > > > > > conflock->fl.fl_start =3D lock->fl.fl_start; > > > > > conflock->fl.fl_end =3D lock->fl.fl_end; > > > > > + conflock->fl.fl_lmops =3D NULL; > > > > > locks_release_private(&lock->fl); > > > > >=20 > > > > > ret =3D nlm_lck_denied; > > > >=20 > > > > The problem sounds real, but I'm not sure I like this solution. > > >=20 > > > I have no claim that this solution is the best. I was contemplating o= n > > > setting this to NULL only in the case when ->f_ops->lock() is NULL > > > thus restricting it to the path that does not call posix_test_lock(). > > >=20 > > > > It seems like this is gaming the refcounting such that we take a > > > > reference in locks_copy_conflock() but then you zero out fl_lmops > > > > before that reference can be put. > > >=20 > > > IF lock_copy_conflock() is called then fl_lmops is already NULL. > > >=20 > > > Let me try to lay out the sequence of steps for both cases. > > >=20 > > > Reexport > > > 1. when nlmsvc_test_lock() is called file->f_file[mode]->f_ops->lock > > > is set (fl_lmops is set too) prior to calling vfs_test_lock. > > > 2. Because ->lock is set vfs_test_lock() calls the ->lock function > > > (instead of posix_test_lock) > > > 3. After vfs_test_lock() fl_lmops is still set so lock_release_privat= e > > > is called and calls nlmscv_put_lockowner(). > > >=20 > > > Normal export > > > 1. when nlmsvc_test_lock() is called ->lock is not set (fl_lmops is > > > set) prior to calling vfs_test_lock > > > 2. Because -> is not set posix_test_lock() is called which will call > > > local_copy_conflock() which will set fl_lmops to NULL. > > > 3. Since fl_lmops is NULL put_lockowner isn't called. > > >=20 > > > Reexport is where I'm hazy. I'm assuming that reexported server opene= d > > > a file and the "file" is the NFS file object and that's why > > > file->f_file[mode]->f_ops->lock is set? So perhaps if we take the > > > presence of ->lock to mean reexport, we can do as I did (ie., set > > > fl_lmops to null), or maybe we can take an extra reference knowing > > > that we'd need to put it in lock_release_private() ( -- this > > > suggestion ties to your next question). I don't see any difference to > > > either setting it to NULL or taking an extra reference for when > > > ->lock() is set . Both are confusing and I would say warrant a commen= t > > > for why we are doing it. > > >=20 > >=20 > > To be clear, there is nothing "special" about NFS reexport here. The > > NFS client just has some limitations as to what it can do when it's > > being (re)exported. Exporting other sorts of network or clustered > > filesystems can also be problematic for similar reasons. > >=20 > > So, we should focus on making this generically work, and not take - > > > lock being set to mean that this is an NFS reexport. >=20 > I guess it doesn't matter what kind of re-export but the fact that if > ->lock is set we know that posix_test_lock and then > local_copy_conflock won't be called and thus there is a great chance > that fl_lmops will still be set on return from vfs_test_lock(). >=20 > > A question: you mentioned this is a reexporting server. Are you > > reexporting an NFSv4 mount as NFSv3? Or is this a v3->v3 reexport? >=20 > v3->v3 reexport. >=20 >=20 Ok, looking now: The test_owner in __nlm4svc_proc_test() comes from the args, which happens during the decode phase. That gets a valid reference to an NLM lockowner in nlmsvc_locks_init_private(). Therefore, this call in=20 __nlm4svc_proc_test() seems legit. nlmsvc_put_lockowner(test_owner); Now, between those two gets/puts, there is the call to vfs_test_lock() in nlmsvc_testlock(). That uses the same file_lock argument structure to represent both the lock and the conflock. error =3D vfs_test_lock(file->f_file[mode], &lock->fl); ...so the flc_owner field at this point is still set to the (original) nlmclient's owner. In this case, that call ends up calling down in nlmclnt_test(), which ignores the flc_owner field. It also ends up overwriting the other fields in &fl with conflock info. I think the bug is actually there. Before nlmclnt_test() overwrites the fields in "fl", it needs to release the owner reference (and zero out the owner). Would this patch fix the bug? ---------------------8------------------------ diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c index cebcc283b7ce..200309ee1a74 100644 --- a/fs/lockd/clntproc.c +++ b/fs/lockd/clntproc.c @@ -438,6 +438,8 @@ nlmclnt_test(struct nlm_rqst *req, struct file_lock *fl) if (status < 0) goto out; =20 + locks_release_private(&fl); + switch (req->a_res.status) { case nlm_granted: fl->c.flc_type =3D F_UNLCK; --=20 Jeff Layton