prevent double cell registration
Subsystems (2)
kafs doesn't check if the cell already exists - so if you do an echo "add newcell.org 1.2.3.4" >/proc/fs/afs/cells it will try to create this cell again. kobject will also complain about a double registration. To prevent such problems, return -EEXIST in that case.
--- fs/afs/cell.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
fs/afs/cell.c +9 -0
@@ -127,6 +127,15 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist)_enter ("%s,%s" , name, vllist); +read_lock (&afs_cells_lock); +list_for_each_entry (cell, &afs_cells, link) { +if (!strcasecmp (cell->name, name)) { +read_unlock (&afs_cells_lock); +return ERR_PTR (-EEXIST ); + } + } +read_unlock (&afs_cells_lock); + cell =afs_cell_alloc (name, vllist);if (IS_ERR (cell)) {_leave (" = %ld" ,PTR_ERR (cell));
Signature · 1 line
1.5.4.3
David Howells
maintainerQuoted 4 lines · Sven Schnelle
kafs doesn't check if the cell already exists - so if you do an echo "add newcell.org 1.2.3.4" >/proc/fs/afs/cells it will try to create this cell again. kobject will also complain about a double registration. To prevent such problems, return
-EEXISTin that case.
Hmmm... I thought I had that covered. Thanks. Any chance of a Signed-off-by line?
David
Quoted 8 lines · David Howells
Quoted 4 lines · Sven Schnelle
kafs doesn't check if the cell already exists - so if you do an echo "add newcell.org 1.2.3.4" >/proc/fs/afs/cells it will try to create this cell again. kobject will also complain about a double registration. To prevent such problems, return
-EEXISTin that case.Hmmm... I thought I had that covered. Thanks. Any chance of a Signed-off-by line?
oops, sorry. Here it is:
Sven.
David Howells
maintainerYour patch needs a bit of adjustment. The check must be done inside the write lock on afs_cells_sem otherwise there's a race.
David
---
AFS: prevent double cell registration
From: Sven Schnelle <[email protected]>
kafs doesn't check if the cell already exists - so if you do an echo "add newcell.org 1.2.3.4" >/proc/fs/afs/cells it will try to create this cell again. kobject will also complain about a double registration. To prevent such problems, return -EEXIST in that case.
---
fs/afs/cell.c | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)
fs/afs/cell.c +13 -2
@@ -127,14 +127,20 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist)_enter ("%s,%s" , name, vllist); +down_write (&afs_cells_sem); +read_lock (&afs_cells_lock); +list_for_each_entry (cell, &afs_cells, link) { +if (strcasecmp (cell->name, name) ==0 ) + goto duplicate_name; + } +read_unlock (&afs_cells_lock); + cell =afs_cell_alloc (name, vllist);if (IS_ERR (cell)) {_leave (" = %ld" ,PTR_ERR (cell));return cell; } -down_write (&afs_cells_sem); -/* add a proc directory for this cell */ ret =afs_proc_cell_setup (cell);if (ret <0 )
@@ -167,6 +173,11 @@ error:kfree (cell);_leave (" = %d" , ret);return ERR_PTR (ret); + +duplicate_name: +read_unlock (&afs_cells_lock); +up_write (&afs_cells_sem); +return ERR_PTR (-EEXIST ); }/*
Hi David,
Quoted 30 lines · David Howells
Your patch needs a bit of adjustment. The check must be done inside the write lock on
afs_cells_semotherwise there's a race.David
---
AFS: prevent double cell registrationFrom: Sven Schnelle <[email protected]>
kafs doesn't check if the cell already exists - so if you do an echo "add newcell.org 1.2.3.4" >/proc/fs/afs/cells it will try to create this cell again. kobject will also complain about a double registration. To prevent such problems, return
-EEXISTin that case.Signed-off-by Sven Schnelle <[email protected]>Signed-off-by David Howells <[email protected]>---
fs/afs/cell.c | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)fs/afs/cell.c +0
-0@@ -127,14 +127,20 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist)_enter ("%s,%s" , name, vllist);
fs/afs/cell.c struct afs_cell *afs_cell_create(const char *name, char *vllist) · line 139
Quoted 10 lines
fs/afs/cell.c +7
-0+down_write (&afs_cells_sem); +list_for_each_entry (cell, &afs_cells, link) { +if (strcasecmp (cell->name, name) ==0 ) + goto duplicate_name; + } +read_unlock (&afs_cells_lock); + cell =afs_cell_alloc (name, vllist);if (IS_ERR (cell)) {
Just digged again into afs, and stumbled upon this return. I think there should be some up_write(&afs_cells_sem); before the return, or am i on the wrong track?
Quoted 21 lines
fs/afs/cell.c +5
-2_leave (" = %ld" ,PTR_ERR (cell));return cell; } -down_write (&afs_cells_sem); -/* add a proc directory for this cell */ ret =afs_proc_cell_setup (cell);if (ret <0 )@@ -167,6 +173,11 @@ error:kfree (cell);_leave (" = %d" , ret);return ERR_PTR (ret); + +duplicate_name: +read_unlock (&afs_cells_lock); +up_write (&afs_cells_sem); +return ERR_PTR (-EEXIST ); }/*
David Howells
maintainerQuoted 3 lines · Sven Schnelle
Just digged again into afs, and stumbled upon this return. I think there should be some
up_write(&afs_cells_sem); before the return, or am i on the wrong track?
Unfortunately not:-(
David
PATCH 1/1 afs: add missing up_write() on return
if afs_cell_alloc() fails, afs_cells_sem doesn't get unlocked, which leads to a deadlock. Unlock it before returning.
--- fs/afs/cell.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/afs/cell.c +1 -0
@@ -138,6 +138,7 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist) cell =afs_cell_alloc (name, vllist);if (IS_ERR (cell)) {_leave (" = %ld" ,PTR_ERR (cell)); +up_write (&afs_cells_sem);return cell; }
Signature · 1 line
1.5.4.5