public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@redhat.com>
To: Sasha Levin <Alexander.Levin@microsoft.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Trond Myklebust <trond.myklebust@primarydata.com>
Subject: Re: [PATCH AUTOSEL for 4.4 19/35] nfsd: Ensure we don't recognise lock stateids after freeing them
Date: Wed, 24 Jan 2018 10:48:27 -0500	[thread overview]
Message-ID: <20180124154827.GD31619@parsley.fieldses.org> (raw)
In-Reply-To: <20180124041645.32420-19-alexander.levin@microsoft.com>

Ditto.--b.

On Wed, Jan 24, 2018 at 04:17:02AM +0000, Sasha Levin wrote:
> From: Trond Myklebust <trond.myklebust@primarydata.com>
> 
> [ Upstream commit 659aefb68eca28ba9aa482a9fc64de107332e256 ]
> 
> In order to deal with lookup races, nfsd4_free_lock_stateid() needs
> to be able to signal to other stateful functions that the lock stateid
> is no longer valid. Right now, nfsd_lock() will check whether or not an
> existing stateid is still hashed, but only in the "new lock" path.
> 
> To ensure the stateid invalidation is also recognised by the "existing lock"
> path, and also by a second call to nfsd4_free_lock_stateid() itself, we can
> change the type to NFS4_CLOSED_STID under the stp->st_mutex.
> 
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
> ---
>  fs/nfsd/nfs4state.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index d31b6cdefb9d..439f01a0bc49 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -4934,7 +4934,9 @@ nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s)
>  	struct nfs4_ol_stateid *stp = openlockstateid(s);
>  	__be32 ret;
>  
> -	mutex_lock(&stp->st_mutex);
> +	ret = nfsd4_lock_ol_stateid(stp);
> +	if (ret)
> +		goto out_put_stid;
>  
>  	ret = check_stateid_generation(stateid, &s->sc_stateid, 1);
>  	if (ret)
> @@ -4945,11 +4947,13 @@ nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s)
>  			    lockowner(stp->st_stateowner)))
>  		goto out;
>  
> +	stp->st_stid.sc_type = NFS4_CLOSED_STID;
>  	release_lock_stateid(stp);
>  	ret = nfs_ok;
>  
>  out:
>  	mutex_unlock(&stp->st_mutex);
> +out_put_stid:
>  	nfs4_put_stid(s);
>  	return ret;
>  }
> @@ -5489,6 +5493,8 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp)
>  	lockdep_assert_held(&clp->cl_lock);
>  
>  	list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) {
> +		if (lst->st_stid.sc_type != NFS4_LOCK_STID)
> +			continue;
>  		if (lst->st_stid.sc_file == fp) {
>  			atomic_inc(&lst->st_stid.sc_count);
>  			return lst;
> @@ -5563,7 +5569,6 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
>  	struct nfs4_lockowner *lo;
>  	struct nfs4_ol_stateid *lst;
>  	unsigned int strhashval;
> -	bool hashed;
>  
>  	lo = find_lockowner_str(cl, &lock->lk_new_owner);
>  	if (!lo) {
> @@ -5586,15 +5591,7 @@ retry:
>  		goto out;
>  	}
>  
> -	mutex_lock(&lst->st_mutex);
> -
> -	/* See if it's still hashed to avoid race with FREE_STATEID */
> -	spin_lock(&cl->cl_lock);
> -	hashed = !list_empty(&lst->st_perfile);
> -	spin_unlock(&cl->cl_lock);
> -
> -	if (!hashed) {
> -		mutex_unlock(&lst->st_mutex);
> +	if (nfsd4_lock_ol_stateid(lst) != nfs_ok) {
>  		nfs4_put_stid(&lst->st_stid);
>  		goto retry;
>  	}
> -- 
> 2.11.0

  reply	other threads:[~2018-01-24 15:48 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24  4:16 [PATCH AUTOSEL for 4.4 01/35] KVM: x86: emulator: Return to user-mode on L1 CPL=0 emulation failure Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 02/35] KVM: x86: Don't re-execute instruction when not passing CR2 value Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 03/35] KVM: X86: Fix operand/address-size during instruction decoding Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 04/35] KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC reconfigure race Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 05/35] KVM: x86: ioapic: Clear Remote IRR when entry is switched to edge-triggered Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 06/35] KVM: x86: ioapic: Preserve read-only values in the redirection table Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 07/35] ACPI / bus: Leave modalias empty for devices which are not present Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 08/35] cpufreq: Add Loongson machine dependencies Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 10/35] drm/amdgpu: Fix SDMA load/unload sequence on HWS disabled mode Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 09/35] bcache: check return value of register_shrinker Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 11/35] drm/amdkfd: Fix SDMA ring buffer size calculation Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 12/35] drm/amdkfd: Fix SDMA oversubsription handling Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 13/35] openvswitch: fix the incorrect flow action alloc size Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 14/35] mac80211: fix the update of path metric for RANN frame Sasha Levin
2018-01-24  4:16 ` [PATCH AUTOSEL for 4.4 15/35] btrfs: fix deadlock when writing out space cache Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 16/35] KVM: VMX: Fix rflags cache during vCPU reset Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 17/35] xen-netfront: remove warning when unloading module Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 18/35] nfsd: CLOSE SHOULD return the invalid special stateid for NFSv4.x (x>0) Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 19/35] nfsd: Ensure we don't recognise lock stateids after freeing them Sasha Levin
2018-01-24 15:48   ` J. Bruce Fields [this message]
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 20/35] nfsd: Ensure we check stateid validity in the seqid operation checks Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 22/35] nfsd: check for use of the closed special stateid Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 21/35] grace: replace BUG_ON by WARN_ONCE in exit_net hook Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 23/35] lockd: fix "list_add double add" caused by legacy signal interface Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 24/35] hwmon: (pmbus) Use 64bit math for DIRECT format values Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 25/35] net: ethernet: xilinx: Mark XILINX_LL_TEMAC broken on 64-bit Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 27/35] SUNRPC: Allow connect to return EHOSTUNREACH Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 26/35] quota: Check for register_shrinker() failure Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 28/35] kmemleak: add scheduling point to kmemleak_scan() Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 29/35] drm/omap: Fix error handling path in 'omap_dmm_probe()' Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 31/35] scsi: aacraid: Prevent crash in case of free interrupt during scsi EH path Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 30/35] xfs: ubsan fixes Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 33/35] media: usbtv: add a new usbid Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 32/35] scsi: ufs: ufshcd: fix potential NULL pointer dereference in ufshcd_config_vreg Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 34/35] usb: gadget: don't dereference g until after it has been null checked Sasha Levin
2018-01-24  4:17 ` [PATCH AUTOSEL for 4.4 35/35] staging: rtl8188eu: Fix incorrect response to SIOCGIWESSID Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180124154827.GD31619@parsley.fieldses.org \
    --to=bfields@redhat.com \
    --cc=Alexander.Levin@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox