Skip to contentSkip to conversation

nfsd: set SC_STATUS_FREED in nfsd4_drop_revoked_stid for delegations

PATCH In review Zhenghang Xiao 3 participants 3 messages May 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsd: set SC_STATUS_FREED in nfsd4_drop_revoked_stid for delegations

nfsd4_drop_revoked_stid() handles FREE_STATEID for admin-revoked delegations but does not set SC_STATUS_FREED before releasing cl_lock. revoke_delegation() uses this flag to detect whether FREE_STATEID has already processed the delegation — without it, the freed delegation is added to cl_revoked via list_add(), producing a use-after-free when cl_revoked is later traversed in __release_client().

The SC_STATUS_REVOKED path in nfsd4_free_stateid() (line 7590) already sets SC_STATUS_FREED correctly. Apply the same pattern to the SC_STATUS_ADMIN_REVOKED path in nfsd4_drop_revoked_stid().

Fixes 8be12e0cf211 ("nfsd: convert global state_lock to per-net deleg_lock")
---
 fs/nfsd/nfs4state.c | 1 +
 1 file changed, 1 insertion(+)
fs/nfsd/nfs4state.c +1 -0
index 6837b63d9864..e1ef88bc9793 100644
@@ -5071,6 +5071,7 @@ static void nfsd4_drop_revoked_stid(struct nfs4_stid *s)
 	case SC_TYPE_DELEG:
 		dp = delegstateid(s);
 		list_del_init(&dp->dl_recall_lru);
+		s->sc_status |= SC_STATUS_FREED;
 		spin_unlock(&cl->cl_lock);
 		nfs4_put_stid(s);
 		break;
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Zhenghang Xiao

nfsd4_drop_revoked_stid() handles FREE_STATEID for admin-revoked delegations but does not set SC_STATUS_FREED before releasing cl_lock. revoke_delegation() uses this flag to detect whether FREE_STATEID has already processed the delegation — without it, the freed delegation is added to cl_revoked via list_add(), producing a use-after-free when cl_revoked is later traversed in __release_client().

The SC_STATUS_REVOKED path in nfsd4_free_stateid() (line 7590) already sets SC_STATUS_FREED correctly. Apply the same pattern to the SC_STATUS_ADMIN_REVOKED path in nfsd4_drop_revoked_stid().

Fixes 8be12e0cf211 ("nfsd: convert global state_lock to per-net deleg_lock")
---
 fs/nfsd/nfs4state.c | 1 +
 1 file changed, 1 insertion(+)
fs/nfsd/nfs4state.c +0 -0
index 6837b63d9864..e1ef88bc9793 100644

fs/nfsd/nfs4state.c static void nfsd4_drop_revoked_stid(struct nfs4_stid *s) · line 5077

Quoted 7 lines
fs/nfsd/nfs4state.c +1 -0
@@ -5071,6 +5071,7 @@ static void nfsd4_drop_revoked_stid(struct nfs4_stid *s)
 	case SC_TYPE_DELEG:
 		dp = delegstateid(s);
 		list_del_init(&dp->dl_recall_lru);
+		s->sc_status |= SC_STATUS_FREED;
 		spin_unlock(&cl->cl_lock);
 		nfs4_put_stid(s);
 		break;

The Fixes tag doesn't look right. I think it should be:

Fixes 8dd91e8d31fe ("nfsd: fix race between laundromat and free_stateid")

The patch looks OK though.

maintainer
#2 lore raw
In reply to Zhenghang Xiao

From: Chuck Lever <[email protected]>

Quoted 8 lines · Zhenghang Xiao

nfsd4_drop_revoked_stid() handles FREE_STATEID for admin-revoked delegations but does not set SC_STATUS_FREED before releasing cl_lock. revoke_delegation() uses this flag to detect whether FREE_STATEID has already processed the delegation — without it, the freed delegation is added to cl_revoked via list_add(), producing a use-after-free when cl_revoked is later traversed in __release_client().

[...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: set SC_STATUS_FREED in nfsd4_drop_revoked_stid for delegations

      commit: a1da502807b6b63963f2b1064df76e0a58fb3479

--
Chuck Lever <[email protected]>