Commit 719fdd32 authored by David Howells's avatar David Howells Committed by Linus Torvalds

afs: Fix storage of cell names

The cell name stored in the afs_cell struct is a 64-char + NUL buffer -
when it needs to be able to handle up to AFS_MAXCELLNAME (256 chars) + NUL.

Fix this by changing the array to a pointer and allocating the string.

Found using Coverity.

Fixes: 989782dc ("afs: Overhaul cell database management")
Reported-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 916a3b0f
...@@ -154,10 +154,17 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, ...@@ -154,10 +154,17 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
cell->name = kmalloc(namelen + 1, GFP_KERNEL);
if (!cell->name) {
kfree(cell);
return ERR_PTR(-ENOMEM);
}
cell->net = net; cell->net = net;
cell->name_len = namelen; cell->name_len = namelen;
for (i = 0; i < namelen; i++) for (i = 0; i < namelen; i++)
cell->name[i] = tolower(name[i]); cell->name[i] = tolower(name[i]);
cell->name[i] = 0;
atomic_set(&cell->usage, 2); atomic_set(&cell->usage, 2);
INIT_WORK(&cell->manager, afs_manage_cell); INIT_WORK(&cell->manager, afs_manage_cell);
...@@ -207,6 +214,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, ...@@ -207,6 +214,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
if (ret == -EINVAL) if (ret == -EINVAL)
printk(KERN_ERR "kAFS: bad VL server IP address\n"); printk(KERN_ERR "kAFS: bad VL server IP address\n");
error: error:
kfree(cell->name);
kfree(cell); kfree(cell);
_leave(" = %d", ret); _leave(" = %d", ret);
return ERR_PTR(ret); return ERR_PTR(ret);
...@@ -489,6 +497,7 @@ static void afs_cell_destroy(struct rcu_head *rcu) ...@@ -489,6 +497,7 @@ static void afs_cell_destroy(struct rcu_head *rcu)
afs_put_vlserverlist(cell->net, rcu_access_pointer(cell->vl_servers)); afs_put_vlserverlist(cell->net, rcu_access_pointer(cell->vl_servers));
afs_put_cell(cell->net, cell->alias_of); afs_put_cell(cell->net, cell->alias_of);
key_put(cell->anonymous_key); key_put(cell->anonymous_key);
kfree(cell->name);
kfree(cell); kfree(cell);
_leave(" [destroyed]"); _leave(" [destroyed]");
......
...@@ -388,7 +388,7 @@ struct afs_cell { ...@@ -388,7 +388,7 @@ struct afs_cell {
struct afs_vlserver_list __rcu *vl_servers; struct afs_vlserver_list __rcu *vl_servers;
u8 name_len; /* Length of name */ u8 name_len; /* Length of name */
char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */ char *name; /* Cell name, case-flattened and NUL-padded */
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment