Revert "NFSD: Defer sub-object cleanup in export put callbacks"
Subsystems (2)
PATCH v2 1/1 Revert "NFSD: Defer sub-object cleanup in export put callbacks"
This reverts commit 48db892356d6cb80f6942885545de4a6dd8d2a29.
Commit 48db892356d6 ("NFSD: Defer sub-object cleanup in export put callbacks") describes an issue where calling svc_export_put, path_put, and auth_domain_put directly can cause use-after-free (UAF) errors when accessing ex_path or ex_client->name. But after discussion in [1], it seems cannot happen and either will introduce a gression that was already fixed by commit 69d803c40ede ("nfsd: Revert "nfsd: release svc_expkey/svc_export with rcu_work""). Therefore, reverting commit 48db892356d6 ("NFSD: Defer sub-object cleanup in export put callbacks") is necessary to fix this regression.
--- fs/nfsd/export.c | 63 +++++++----------------------------------------- fs/nfsd/export.h | 7 ++---- fs/nfsd/nfsctl.c | 8 +----- 3 files changed, 12 insertions(+), 66 deletions(-)
v1->v2:
1. rewrite commit message
2. add reviewed-by tag
fs/nfsd/export.c +9 -54
@@ -39,30 +39,19 @@* second map contains a reference to the entry in the first map. */ -static struct workqueue_struct *nfsd_export_wq; -#define EXPKEY_HASHBITS 8#define EXPKEY_HASHMAX (1 << EXPKEY_HASHBITS)#define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1) -static void expkey_release (struct work_struct *work) +static void expkey_put (struct kref *ref) { -struct svc_expkey *key =container_of (to_rcu_work (work), - struct svc_expkey, ek_rwork); + struct svc_expkey *key = container_of(ref, struct svc_expkey, h.ref);if (test_bit (CACHE_VALID , &key->h.flags) && !test_bit (CACHE_NEGATIVE , &key->h.flags))path_put (&key->ek_path);auth_domain_put (key->ek_client); -kfree (key); -} - -static void expkey_put (struct kref *ref) -{ - struct svc_expkey *key = container_of(ref, struct svc_expkey, h.ref); - -INIT_RCU_WORK (&key->ek_rwork, expkey_release); -queue_rcu_work (nfsd_export_wq, &key->ek_rwork); +kfree_rcu (key, ek_rcu); }static int expkey_upcall (struct cache_detail *cd,struct cache_head *h)
@@ -633,13 +622,11 @@ static void export_stats_destroy(struct export_stats *stats) EXP_STATS_COUNTERS_NUM); } -static void svc_export_release (struct work_struct *work) +static void svc_export_release (struct rcu_head *rcu_head) { -struct svc_export *exp =container_of (to_rcu_work (work), - struct svc_export, ex_rwork); + struct svc_export *exp = container_of(rcu_head, struct svc_export, + ex_rcu); -path_put (&exp->ex_path); -auth_domain_put (exp->ex_client);nfsd4_fslocs_free (&exp->ex_fslocs);export_stats_destroy (exp->ex_stats);kfree (exp->ex_stats);
@@ -651,8 +638,9 @@ static void svc_export_put(struct kref *ref) { struct svc_export *exp = container_of(ref, struct svc_export, h.ref); -INIT_RCU_WORK (&exp->ex_rwork, svc_export_release); -queue_rcu_work (nfsd_export_wq, &exp->ex_rwork); +path_put (&exp->ex_path); +auth_domain_put (exp->ex_client); +call_rcu (&exp->ex_rcu, svc_export_release); }/**
@@ -2194,36 +2182,6 @@ const struct seq_operations nfs_exports_op = { .show = e_show, }; -/** -* nfsd_export_wq_init - allocate the export release workqueue -* -* Called once at module load. The workqueue runs deferred svc_export and -* svc_expkey release work scheduled by queue_rcu_work() in the cache put -* callbacks. -* -* Return values: -* %0: workqueue allocated -* %-ENOMEM: allocation failed -*/ -int nfsd_export_wq_init (void ) -{ - nfsd_export_wq =alloc_workqueue ("nfsd_export" ,WQ_UNBOUND ,0 ); -if (!nfsd_export_wq) -return -ENOMEM ; -return 0 ; -} - -/** -* nfsd_export_wq_shutdown - drain and free the export release workqueue -* -* Called once at module unload. Per-namespace teardown in -* nfsd_export_shutdown() has already drained all deferred work. -*/ -void nfsd_export_wq_shutdown (void ) -{ -destroy_workqueue (nfsd_export_wq); -} -/* * Initialize the exports module. */
@@ -2285,9 +2243,6 @@ nfsd_export_shutdown(struct net *net)cache_unregister_net (nn->svc_expkey_cache, net);cache_unregister_net (nn->svc_export_cache, net); -/* Drain deferred export and expkey release work. */ -rcu_barrier (); -flush_workqueue (nfsd_export_wq);cache_destroy_net (nn->svc_expkey_cache, net);cache_destroy_net (nn->svc_export_cache, net);svcauth_unix_purge (net);
fs/nfsd/export.h +2 -5
@@ -7,7 +7,6 @@#include <linux/sunrpc/cache.h> #include <linux/percpu_counter.h> -#include <linux/workqueue.h> #include <uapi/linux/nfsd/export.h> #include <linux/nfs4.h>
@@ -76,7 +75,7 @@ struct svc_export {u32 ex_layout_types;struct nfsd4_deviceid_map *ex_devid_map;struct cache_detail *cd; -struct rcu_work ex_rwork; +struct rcu_head ex_rcu;unsigned long ex_xprtsec_modes;struct export_stats *ex_stats; };
@@ -93,7 +92,7 @@ struct svc_expkey {u32 ek_fsid[6 ];struct path ek_path; -struct rcu_work ek_rwork; +struct rcu_head ek_rcu; };#define EX_ISSYNC (exp) (!((exp)->ex_flags & NFSEXP_ASYNC))
@@ -111,8 +110,6 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp,/* * Function declarations */ -int nfsd_export_wq_init (void ); -void nfsd_export_wq_shutdown (void );int nfsd_export_init (struct net *);void nfsd_export_shutdown (struct net *);void nfsd_export_flush (struct net *);
fs/nfsd/nfsctl.c +1 -7
@@ -2536,12 +2536,9 @@ static int __init init_nfsd(void)if (retval) goto out_free_pnfs;nfsd_lockd_init ();/* lockd->nfsd callbacks */ - retval =nfsd_export_wq_init (); -if (retval) - goto out_free_lockd; retval =register_pernet_subsys (&nfsd_net_ops);if (retval <0 ) - goto out_free_export_wq; + goto out_free_lockd; retval =register_cld_notifier ();if (retval) goto out_free_subsys;
@@ -2570,8 +2567,6 @@ static int __init init_nfsd(void)unregister_cld_notifier (); out_free_subsys:unregister_pernet_subsys (&nfsd_net_ops); -out_free_export_wq: -nfsd_export_wq_shutdown (); out_free_lockd:nfsd_lockd_shutdown ();nfsd_drc_slab_free ();
@@ -2592,7 +2587,6 @@ static void __exit exit_nfsd(void)nfsd4_destroy_laundry_wq ();unregister_cld_notifier ();unregister_pernet_subsys (&nfsd_net_ops); -nfsd_export_wq_shutdown ();nfsd_drc_slab_free ();nfsd_lockd_shutdown ();nfsd4_free_slabs ();
Signature · 1 line
2.52.0
Chuck Lever
maintainerFrom: Chuck Lever <[email protected]>
Quoted 12 lines · Yang Erkun
This reverts commit
48db892356d6cb80f6942885545de4a6dd8d2a29.Commit
48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") describes an issue where callingsvc_export_put,path_put, andauth_domain_putdirectly can cause use-after-free (UAF) errors when accessingex_pathorex_client->name. But after discussion in [1], it seems cannot happen and either will introduce a gression that was already fixed by commit69d803c40ede("nfsd: Revert "nfsd: release svc_expkey/svc_export withrcu_work""). Therefore, reverting commit48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") is necessary to fix this regression.
Quoted 1 line
[...]
Applied to nfsd-testing with an expanded commit message to preserve the context of our discussions.
[1/1] Revert "NFSD: Defer sub-object cleanup in export put callbacks"
commit: ef4e34669aa1a15d2f5ba86fd433fcac9aee81c9
--
Chuck Lever <[email protected]>
Quoted 15 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Quoted 12 lines · Yang Erkun
This reverts commit
48db892356d6cb80f6942885545de4a6dd8d2a29.Commit
48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") describes an issue where callingsvc_export_put,path_put, andauth_domain_putdirectly can cause use-after-free (UAF) errors when accessingex_pathorex_client->name. But after discussion in [1], it seems cannot happen and either will introduce a gression that was already fixed by commit69d803c40ede("nfsd: Revert "nfsd: release svc_expkey/svc_export withrcu_work""). Therefore, reverting commit48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") is necessary to fix this regression.
Quoted 4 lines
Quoted 1 line
[...]
Applied to nfsd-testing with an expanded commit message to preserve the context of our discussions.
Certainly, this commit message could be more detailed. Thank you for taking the time to do this!
Quoted 6 lines
[1/1] Revert "NFSD: Defer sub-object cleanup in export put callbacks"
commit: ef4e34669aa1a15d2f5ba86fd433fcac9aee81c9--
Chuck Lever <[email protected]>
Calum Mackay
Tested-by Alexandr AlexandrovQuoted 15 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Quoted 12 lines · Yang Erkun
This reverts commit
48db892356d6cb80f6942885545de4a6dd8d2a29.Commit
48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") describes an issue where callingsvc_export_put,path_put, andauth_domain_putdirectly can cause use-after-free (UAF) errors when accessingex_pathorex_client->name. But after discussion in [1], it seems cannot happen and either will introduce a gression that was already fixed by commit69d803c40ede("nfsd: Revert "nfsd: release svc_expkey/svc_export withrcu_work""). Therefore, reverting commit48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") is necessary to fix this regression.
Quoted 4 lines
Quoted 1 line
[...]
Applied to nfsd-testing with an expanded commit message to preserve the context of our discussions.
Testing looks good, Chuck: no crashes, sosreport no longer hangs, no seq_file warnings.
cheers,
c.
Quoted 7 lines
[1/1] Revert "NFSD: Defer sub-object cleanup in export put callbacks"
commit: ef4e34669aa1a15d2f5ba86fd433fcac9aee81c9--
Chuck Lever <[email protected]>
Chuck Lever
maintainerQuoted 18 lines · Calum Mackay
Quoted 17 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Quoted 13 lines · Yang Erkun
This reverts commit
48db892356d6cb80f6942885545de4a6dd8d2a29.Commit
48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") describes an issue where callingsvc_export_put,path_put, andauth_domain_putdirectly can cause use-after-free (UAF) errors when accessingex_pathorex_client->name. But after discussion in [1], it seems cannot happen and either will introduce a gression that was already fixed by commit69d803c40ede("nfsd: Revert "nfsd: release svc_expkey/svc_export withrcu_work""). Therefore, reverting commit48db892356d6("NFSD: Defer sub-object cleanup in export put callbacks") is necessary to fix this regression.[...]
Quoted 7 lines
Quoted 2 lines
Applied to nfsd-testing with an expanded commit message to preserve the context of our discussions.
Testing looks good, Chuck: no crashes, sosreport no longer hangs, no
seq_filewarnings.Tested-by Alexandr Alexandrov <[email protected]>
Thanks. Marked in my private tree, will appear in nfsd-testing on the next push.
Quoted 8 lines
Quoted 6 lines
[1/1] Revert "NFSD: Defer sub-object cleanup in export put callbacks"
commit:ef4e34669aa1a15d2f5ba86fd433fcac9aee81c9Signature · 1 line
Chuck Lever <[email protected]>
Signature · 1 line
Chuck Lever