Skip to content

Commit 719fdd3

Browse files
dhowellstorvalds
authored andcommitted
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: 989782d ("afs: Overhaul cell database management") Reported-by: Colin Ian King <[email protected]> Signed-off-by: David Howells <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 916a3b0 commit 719fdd3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

fs/afs/cell.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,17 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
154154
return ERR_PTR(-ENOMEM);
155155
}
156156

157+
cell->name = kmalloc(namelen + 1, GFP_KERNEL);
158+
if (!cell->name) {
159+
kfree(cell);
160+
return ERR_PTR(-ENOMEM);
161+
}
162+
157163
cell->net = net;
158164
cell->name_len = namelen;
159165
for (i = 0; i < namelen; i++)
160166
cell->name[i] = tolower(name[i]);
167+
cell->name[i] = 0;
161168

162169
atomic_set(&cell->usage, 2);
163170
INIT_WORK(&cell->manager, afs_manage_cell);
@@ -207,6 +214,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
207214
if (ret == -EINVAL)
208215
printk(KERN_ERR "kAFS: bad VL server IP address\n");
209216
error:
217+
kfree(cell->name);
210218
kfree(cell);
211219
_leave(" = %d", ret);
212220
return ERR_PTR(ret);
@@ -489,6 +497,7 @@ static void afs_cell_destroy(struct rcu_head *rcu)
489497
afs_put_vlserverlist(cell->net, rcu_access_pointer(cell->vl_servers));
490498
afs_put_cell(cell->net, cell->alias_of);
491499
key_put(cell->anonymous_key);
500+
kfree(cell->name);
492501
kfree(cell);
493502

494503
_leave(" [destroyed]");

fs/afs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ struct afs_cell {
388388
struct afs_vlserver_list __rcu *vl_servers;
389389

390390
u8 name_len; /* Length of name */
391-
char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
391+
char *name; /* Cell name, case-flattened and NUL-padded */
392392
};
393393

394394
/*

0 commit comments

Comments
 (0)