sunrpc: only free unix grouplist after RCU settles
Subsystems (3)
Jeff Layton
maintainerPATCH 1/1 sunrpc: only free unix grouplist after RCU settles
While the unix_gid object is rcu-freed, the group_info list that it contains is not. Ensure that we only put the group list reference once we are really freeing the unix_gid object.
--- net/sunrpc/svcauth_unix.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
net/sunrpc/svcauth_unix.c +13 -4
@@ -416,14 +416,23 @@ static int unix_gid_hash(kuid_t uid)return hash_long (from_kuid (&init_user_ns, uid),GID_HASHBITS ); } -static void unix_gid_put (struct kref *kref) +static void unix_gid_free (struct rcu_head *rcu) { - struct cache_head *item = container_of(kref, struct cache_head, ref); - struct unix_gid *ug = container_of(item, struct unix_gid, h); + struct unix_gid *ug = container_of(rcu, struct unix_gid, rcu); +struct cache_head *item = &ug->h; +if (test_bit (CACHE_VALID , &item->flags) && !test_bit (CACHE_NEGATIVE , &item->flags))put_group_info (ug->gi); -kfree_rcu (ug, rcu); +kfree (ug); +} + +static void unix_gid_put (struct kref *kref) +{ + struct cache_head *item = container_of(kref, struct cache_head, ref); + struct unix_gid *ug = container_of(item, struct unix_gid, h); + +call_rcu (&ug->rcu, unix_gid_free); }static int unix_gid_match (struct cache_head *corig,struct cache_head *cnew)
Signature · 1 line
2.39.2
Hi Jeff-
Quoted 7 lines · Jeff Layton
While the
unix_gidobject is rcu-freed, thegroup_infolist that it contains is not. Ensure that we only put the group list reference once we are really freeing theunix_gidobject.Reported-by Zhi Li <[email protected]>
Should we also add
Quoted 1 line
This bug isn't publicly accessible, fwiw.
Quoted 40 lines
Signed-off-by Jeff Layton <[email protected]>---
net/sunrpc/svcauth_unix.c| 17 +++++++++++++----1 file changed, 13 insertions(+), 4 deletions(-)net/sunrpc/svcauth_unix.c +13
-4@@ -416,14 +416,23 @@ static int unix_gid_hash(kuid_t uid)return hash_long (from_kuid (&init_user_ns, uid),GID_HASHBITS ); } -static void unix_gid_put (struct kref *kref) +static void unix_gid_free (struct rcu_head *rcu) { - struct cache_head *item = container_of(kref, struct cache_head, ref); - struct unix_gid *ug = container_of(item, struct unix_gid, h); + struct unix_gid *ug = container_of(rcu, struct unix_gid, rcu); +struct cache_head *item = &ug->h; +if (test_bit (CACHE_VALID , &item->flags) && !test_bit (CACHE_NEGATIVE , &item->flags))put_group_info (ug->gi); -kfree_rcu (ug, rcu); +kfree (ug); +} + +static void unix_gid_put (struct kref *kref) +{ + struct cache_head *item = container_of(kref, struct cache_head, ref); + struct unix_gid *ug = container_of(item, struct unix_gid, h); + +call_rcu (&ug->rcu, unix_gid_free); }static int unix_gid_match (struct cache_head *corig,struct cache_head *cnew)Signature · 1 line
2.39.2
--
Chuck Lever
Jeff Layton
maintainerQuoted 8 lines · Chuck Lever III
Hi Jeff-
Quoted 6 lines · Jeff Layton
While the
unix_gidobject is rcu-freed, thegroup_infolist that it contains is not. Ensure that we only put the group list reference once we are really freeing theunix_gidobject.
Quoted 7 lines
Quoted 1 line
Reported-by Zhi Li <[email protected]>Should we also add
Fixes fd5d2f78261b ("SUNRPC: Make server side AUTH_UNIX use lockless lookups") ?
Sure. That does look like when that particular bug crept in.
Quoted 4 lines
Quoted 1 line
This bug isn't publicly accessible, fwiw.
Thanks. It should be now.
Quoted 46 lines
Quoted 41 lines
Signed-off-by Jeff Layton <[email protected]>---
net/sunrpc/svcauth_unix.c| 17 +++++++++++++----1 file changed, 13 insertions(+), 4 deletions(-)net/sunrpc/svcauth_unix.c +13
-4@@ -416,14 +416,23 @@ static int unix_gid_hash(kuid_t uid)return hash_long (from_kuid (&init_user_ns, uid),GID_HASHBITS ); } -static void unix_gid_put (struct kref *kref) +static void unix_gid_free (struct rcu_head *rcu) { - struct cache_head *item = container_of(kref, struct cache_head, ref); - struct unix_gid *ug = container_of(item, struct unix_gid, h); + struct unix_gid *ug = container_of(rcu, struct unix_gid, rcu); +struct cache_head *item = &ug->h; +if (test_bit (CACHE_VALID , &item->flags) && !test_bit (CACHE_NEGATIVE , &item->flags))put_group_info (ug->gi); -kfree_rcu (ug, rcu); +kfree (ug); +} + +static void unix_gid_put (struct kref *kref) +{ + struct cache_head *item = container_of(kref, struct cache_head, ref); + struct unix_gid *ug = container_of(item, struct unix_gid, h); + +call_rcu (&ug->rcu, unix_gid_free); }static int unix_gid_match (struct cache_head *corig,struct cache_head *cnew)Signature · 1 line
2.39.2--
Chuck Lever
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 21 lines · Jeff Layton
Quoted 8 lines · Chuck Lever III
Hi Jeff-
Quoted 6 lines · Jeff Layton
While the
unix_gidobject is rcu-freed, thegroup_infolist that it contains is not. Ensure that we only put the group list reference once we are really freeing theunix_gidobject.Quoted 7 lines
Quoted 1 line
Reported-by Zhi Li <[email protected]>Should we also add
Fixes fd5d2f78261b ("SUNRPC: Make server side AUTH_UNIX use lockless lookups") ?
Quoted 8 lines
Sure. That does look like when that particular bug crept in.
Quoted 4 lines
Quoted 1 line
This bug isn't publicly accessible, fwiw.
Thanks. It should be now.
OK, applied to nfsd-fixes!
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Signed-off-by Jeff Layton <[email protected]>---
net/sunrpc/svcauth_unix.c| 17 +++++++++++++----1 file changed, 13 insertions(+), 4 deletions(-)net/sunrpc/svcauth_unix.c +13
-4@@ -416,14 +416,23 @@ static int unix_gid_hash(kuid_t uid)return hash_long (from_kuid (&init_user_ns, uid),GID_HASHBITS ); } -static void unix_gid_put (struct kref *kref) +static void unix_gid_free (struct rcu_head *rcu) { - struct cache_head *item = container_of(kref, struct cache_head, ref); - struct unix_gid *ug = container_of(item, struct unix_gid, h); + struct unix_gid *ug = container_of(rcu, struct unix_gid, rcu); +struct cache_head *item = &ug->h; +if (test_bit (CACHE_VALID , &item->flags) && !test_bit (CACHE_NEGATIVE , &item->flags))put_group_info (ug->gi); -kfree_rcu (ug, rcu); +kfree (ug); +} + +static void unix_gid_put (struct kref *kref) +{ + struct cache_head *item = container_of(kref, struct cache_head, ref); + struct unix_gid *ug = container_of(item, struct unix_gid, h); + +call_rcu (&ug->rcu, unix_gid_free); }
Quoted 12 lines
Quoted 9 lines
Quoted 4 lines
net/sunrpc/svcauth_unix.c +0
-0static int unix_gid_match (struct cache_head *corig,struct cache_head *cnew)Signature · 1 line
2.39.2--
Chuck LeverSignature · 1 line
Jeff Layton <[email protected]>
--
Chuck Lever