Skip to contentSkip to conversation

prevent double cell registration

AFS New Sven Schnelle 2 participants 7 messages Mar 21, 2008 – Apr 2, 2008

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

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
index 970d38f..87934b3 100644
@@ -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
maintainer
#1 lore raw
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 -EEXIST in that case.

Hmmm... I thought I had that covered. Thanks. Any chance of a Signed-off-by line?

David

#2 lore raw
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 -EEXIST in that case.

Hmmm... I thought I had that covered. Thanks. Any chance of a Signed-off-by line?

oops, sorry. Here it is:

Sven.

maintainer
#3 lore raw

Your 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
index 970d38f..788865d 100644
@@ -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);
 }
 
 /*
#4 lore raw

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_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 +0 -0
index 970d38f..788865d 100644
@@ -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);
 }
 
 /*
maintainer
#5 lore raw
Quoted 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

#6 lore raw

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
index 788865d..584bb0f 100644
@@ -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