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 D6CAC23C51C for ; Tue, 21 Oct 2025 17:45:17 +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=1761068717; cv=none; b=kTkr3lHPQNglyD8KtkT/C3atXxHXTSQz0mfd/J0TWU96Idfq2AD4+alFy1TqJUhoenC6rTiqWikk9Wxmpltu+IjbF72RkJlMQLynnvL523el+0lKnFKPmidNbMYrnZVpylf4XOda01SwOGzxBunH87RiTtVGWB41ARd2KLHwXbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761068717; c=relaxed/simple; bh=pYI7vNYHyHxxbRNOLtm7QPMyM9todIWhdWm1iIBLzpA=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=CMexFxOyAl81I2Vu+HF52NeyXX35GzHC4bUJe9BwYmAX6h58jhr+cQopWM5CP3I2wKf62aVP/h6qdo/GIwbfW+Mmu5gq18B/kz3z6U9dDxoQ856cFzVS/W+935RymTNJJdxBU3jdG2dFPS1fxvbH3E2RVxmX2u5ZPEt7mfgHg10= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mI7ia2el; 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="mI7ia2el" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D38CC4CEF1; Tue, 21 Oct 2025 17:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761068717; bh=pYI7vNYHyHxxbRNOLtm7QPMyM9todIWhdWm1iIBLzpA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mI7ia2el6N+ZHDqLeUmk3P4AmTpQekygtYRuJf969r/zVfg0qIgYzdz5wtDyg+qG9 74easYfGcHnkE6VZDFo5SawgcMmh/R43hJSLThXwYEaVW/Iou5YXbnDE110734yJUN XDF+Cxa2XjR6HV3HE5TEgSwJIr4tnp3no+SDNj0fnkhBLGf2HjU2u2Zu/Wz+Uweitv MdkX7E8gwLpGz7oJLEE2Y0Vl+IB//0vpwN7nUOlplYUYYqucBsqoas0li5DdWaz/pn vml+1wPlfSnppvoVBOmrB++kNAAjK1LjlDsWCzMqoCt9+zACWLIjWp4Kt1ewCZRQ1Q krxMQHzjXj1PQ== 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:45:16 -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 0OX6MYPtv76hka8lW4mnRmZqqx3UtfH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3EaiZfdXKhiQqSGdK4La3OTJOJYZphPdGgnkvDV9Pl1QZ0ijXQrVIy3zd6VCNaKYq7B 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 13:15 -0400, Jeff Layton wrote: > On Tue, 2025-10-21 at 13:03 -0400, Jeff Layton wrote: > > 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() i= n > > > > > > > calling nlmsvc_testlock() with a lock conflict lock_release_p= rivate() > > > > > > > call would end up calling nlmsvc_put_lockowner() and then bac= k in > > > > > > > nlm4svc_proc_test() function there will be another call to > > > > > > > nlmsvc_put_lockowner() for the same owner leading to use-afte= r-free > > > > > > > violation (below). > > > > > > >=20 > > > > > > > The problem only arises when the underlying file system has b= een > > > > > > > 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= _lock() > > > > > > > is done fl_lmops pointer is non-null. When it's regular expor= t, > > > > > > > vfs_test_lock() calls posix_test_lock() which ends up calling > > > > > > > locks_copy_conflock() and it copies NULL into fl_lmops and th= en > > > > > > > calling into lock_release_private() does not call > > > > > > > nlmsvc_put_lockowner(). > > > > > > >=20 > > > > > > > The proposed solution is to intentionally clear fl_lmops poin= ter to > > > > > > > make sure that if there is a conflict (be it a local file sys= tem > > > > > > > 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_lockown= er+0x30/0x250 [lockd] > > > > > > > kernel: Read of size 4 at addr ffff0000bf3bca10 by task lockd= /6092 > > > > > > > kernel: > > > > > > > kernel: CPU: 0 UID: 0 PID: 6092 Comm: lockd Kdump: loaded Not= tainted 6.18.0-rc1+ #23 PREEMPT(voluntary) > > > > > > > kernel: Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW= 201.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 ffff0000bf= 3bca00 > > > > > > > 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, ffff0000bf3bc= a40) > > > > > > > kernel: > > > > > > > kernel: The buggy address belongs to the physical page: > > > > > > > kernel: page: refcount:0 mapcount:0 mapping:0000000000000000 = index:0x0 pfn:0x13f3bc > > > > > > > kernel: flags: 0x2fffff00000000(node=3D0|zone=3D2|lastcpupid= =3D0xfffff) > > > > > > > kernel: page_type: f5(slab) > > > > > > > kernel: raw: 002fffff00000000 ffff0000800028c0 dead0000000001= 22 0000000000000000 > > > > > > > kernel: raw: 0000000000000000 0000000080200020 00000000f50000= 00 0000000000000000 > > > > > > > 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 f= c fc fc fc fc > > > > > > > kernel: ffff0000bf3bc980: fa fb fb fb fb fb fb fb fc fc fc f= c fc fc fc fc > > > > > > > kernel: >ffff0000bf3bca00: fa fb fb fb fb fb fb fb fc fc fc f= c fc fc fc fc > > > > > > > kernel: ^ > > > > > > > kernel: ffff0000bf3bca80: fa fb fb fb fb fb fb fb fc fc fc f= c fc fc fc fc > > > > > > > kernel: ffff0000bf3bcb00: fc fc fc fc fc fc fc fc fc fc fc f= c 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 Tai= nted: G B 6.18.0-rc1+ #23 PREEMPT(voluntary) > > > > > > > kernel: Tainted: [B]=3DBAD_PAGE > > > > > > > kernel: Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW= 201.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 refcou= nt_dec_not_one+0x198/0x1b0 > > > > > > > kernel: Modules linked in: rpcrdma rdma_cm iw_cm ib_cm ib_cor= e nfsd nfsv3 nfs_acl nfs lockd grace nfs_localio netfs ext4 crc16 mbcache j= bd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo = snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc snd_hda_intel = videobuf2_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 soundco= re sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw= _vsock_vmci_transport vmw_vmci vsock xfs 8021q garp stp llc mrp nvme nvme_c= ore nvme_keyring nvme_auth ghash_ce hkdf e1000e sr_mod cdrom vmwgfx drm_ttm= _helper ttm sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp l= ibiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink > > > > > > > kernel: CPU: 0 UID: 0 PID: 6092 Comm: lockd Kdump: loaded Tai= nted: G B 6.18.0-rc1+ #23 PREEMPT(voluntary) > > > > > > > kernel: Tainted: [B]=3DBAD_PAGE > > > > > > > kernel: Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW= 201.00V.24006586.BA64.2406042154 06/04/2024 > > > > > > > kernel: pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS= BTYPE=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: ffff= 0000ba5c7000 > > > > > > > kernel: x26: 1fffe000191eeb84 x25: 1ffff000114c4f48 x24: ffff= 0000c8f75c24 > > > > > > > kernel: x23: 0000000000000007 x22: ffff80008a627950 x21: 1fff= f000114c4f26 > > > > > > > kernel: x20: 00000000ffffffff x19: ffff0000bf3bca10 x18: 0000= 000000000310 > > > > > > > kernel: x17: 0000000000000000 x16: 0000000000000000 x15: 0000= 000000000000 > > > > > > > kernel: x14: 0000000000000000 x13: 0000000000000001 x12: ffff= 60004fd90aa3 > > > > > > > kernel: x11: 1fffe0004fd90aa2 x10: ffff60004fd90aa2 x9 : dfff= 800000000000 > > > > > > > kernel: x8 : 00009fffb026f55e x7 : ffff00027ec85513 x6 : 0000= 000000000001 > > > > > > > kernel: x5 : ffff00027ec85510 x4 : ffff60004fd90aa3 x3 : ffff= 800080787bc0 > > > > > > > kernel: x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff= 0000a75a8000 > > > > > > > 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, s= truct 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 contemplati= ng on > > > > > setting this to NULL only in the case when ->f_ops->lock() is NUL= L > > > > > thus restricting it to the path that does not call posix_test_loc= k(). > > > > >=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_lmo= ps > > > > > > 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->l= ock > > > > > is set (fl_lmops is set too) prior to calling vfs_test_lock. > > > > > 2. Because ->lock is set vfs_test_lock() calls the ->lock functio= n > > > > > (instead of posix_test_lock) > > > > > 3. After vfs_test_lock() fl_lmops is still set so lock_release_pr= ivate > > > > > 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 c= all > > > > > 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 o= pened > > > > > 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 knowin= g > > > > > that we'd need to put it in lock_release_private() ( -- this > > > > > suggestion ties to your next question). I don't see any differenc= e 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 co= mment > > > > > for why we are doing it. > > > > >=20 > > > >=20 > > > > To be clear, there is nothing "special" about NFS reexport here. Th= e > > > > 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 > >=20 > > Ok, looking now: > >=20 > > 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. > >=20 > > nlmsvc_put_lockowner(test_owner); > >=20 > > 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. > >=20 > > error =3D vfs_test_lock(file->f_file[mode], &lock->fl); > >=20 > > ...so the flc_owner field at this point is still set to the (original) > > nlmclient's owner. > >=20 > > 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. > >=20 > > 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? > >=20 > > ---------------------8------------------------ > >=20 > > 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 >=20 > Sorry, I take it back. That alone won't fix it because of the pointer- > saving shenanigans in __nlm4svc_proc_test. We'll need to do this a bit > more carefully, I think. How about this patch? The changelog still needs some work, but I think this is the most correct way to handle it: -------------------------8<---------------------------- [PATCH] nlm: fix handling of conflocks by NLM The handling of conflocks can result in a refcount overput on the flc_owner in the case of a reexported NFSv3 fs. lockd will pass down a file_lock structure in its arguments with flc_owner set to an NLM owner and a valid reference. Once that gets down to the reexported NFS client, it will ignore that field and leave it intact when copying in conflock info. The NLM server code will then end up releasing the conflock, and then releasing the one from the arguments, not realizing that the lock has already been released. The owner info in the arguments to vfs_test_lock() is there to give information about the requestor. Once nlmclnt_test() is going to copy in the conflock info however, it needs to release the old owner. Have nlmclnt_test() do call locks_release_private() after testing the lock to release any info that was in the old file_lock structure. This creates another problem: __nlm4svc_proc_test() and __nlmsvc_proc_test() both call nlmsvc_put_lockowner() unconditionally on the original lockowner that it got from decoding the args. Switch them both to just call locks_release_private() on &argp->lock instead, which should handle the case properly where the info in argp->lock has already been released. With that changed, we can also eliminate the call to locks_release_private() in nlmsvc_testlock() since the callers will now handle that. Reported-by: Olga Kornievskaia Signed-off-by: Jeff Layton --- fs/lockd/clntproc.c | 3 +++ fs/lockd/svc4proc.c | 4 +--- fs/lockd/svclock.c | 1 - fs/lockd/svcproc.c | 5 +---- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c index cebcc283b7ce..d3dd04137677 100644 --- a/fs/lockd/clntproc.c +++ b/fs/lockd/clntproc.c @@ -438,6 +438,9 @@ nlmclnt_test(struct nlm_rqst *req, struct file_lock *fl= ) if (status < 0) goto out; =20 + /* Release any references held by fl before copying in conflock info */ + locks_release_private(fl); + switch (req->a_res.status) { case nlm_granted: fl->c.flc_type =3D F_UNLCK; diff --git a/fs/lockd/svc4proc.c b/fs/lockd/svc4proc.c index 109e5caae8c7..cbfec12296a4 100644 --- a/fs/lockd/svc4proc.c +++ b/fs/lockd/svc4proc.c @@ -97,7 +97,6 @@ __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_re= s *resp) struct nlm_args *argp =3D rqstp->rq_argp; struct nlm_host *host; struct nlm_file *file; - struct nlm_lockowner *test_owner; __be32 rc =3D rpc_success; =20 dprintk("lockd: TEST4 called\n"); @@ -107,7 +106,6 @@ __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_= res *resp) if ((resp->status =3D nlm4svc_retrieve_args(rqstp, argp, &host, &file))) return resp->status =3D=3D nlm_drop_reply ? rpc_drop_reply :rpc_success; =20 - test_owner =3D argp->lock.fl.c.flc_owner; /* Now check for conflicting locks */ resp->status =3D nlmsvc_testlock(rqstp, file, host, &argp->lock, &resp->lock); @@ -116,7 +114,7 @@ __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_= res *resp) else dprintk("lockd: TEST4 status %d\n", ntohl(resp->status)); =20 - nlmsvc_put_lockowner(test_owner); + locks_release_private(&argp->lock.fl); nlmsvc_release_host(host); nlm_release_file(file); return rc; diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c index a31dc9588eb8..7ff3d75a5ca3 100644 --- a/fs/lockd/svclock.c +++ b/fs/lockd/svclock.c @@ -652,7 +652,6 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct 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; - locks_release_private(&lock->fl); =20 ret =3D nlm_lck_denied; out: diff --git a/fs/lockd/svcproc.c b/fs/lockd/svcproc.c index f53d5177f267..6f3e669a3532 100644 --- a/fs/lockd/svcproc.c +++ b/fs/lockd/svcproc.c @@ -117,7 +117,6 @@ __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_r= es *resp) struct nlm_args *argp =3D rqstp->rq_argp; struct nlm_host *host; struct nlm_file *file; - struct nlm_lockowner *test_owner; __be32 rc =3D rpc_success; =20 dprintk("lockd: TEST called\n"); @@ -127,8 +126,6 @@ __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_r= es *resp) if ((resp->status =3D nlmsvc_retrieve_args(rqstp, argp, &host, &file))) return resp->status =3D=3D nlm_drop_reply ? rpc_drop_reply :rpc_success; =20 - test_owner =3D argp->lock.fl.c.flc_owner; - /* Now check for conflicting locks */ resp->status =3D cast_status(nlmsvc_testlock(rqstp, file, host, &argp->lock, &resp->lock)); @@ -138,7 +135,7 @@ __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_r= es *resp) dprintk("lockd: TEST status %d vers %d\n", ntohl(resp->status), rqstp->rq_vers); =20 - nlmsvc_put_lockowner(test_owner); + locks_release_private(&argp->lock.fl); nlmsvc_release_host(host); nlm_release_file(file); return rc; --=20 2.51.0