Skip to content

Commit 8fd56ad

Browse files
dhowellsbrauner
authored andcommitted
afs: Fix the maximum cell name length
The kafs filesystem limits the maximum length of a cell to 256 bytes, but a problem occurs if someone actually does that: kafs tries to create a directory under /proc/net/afs/ with the name of the cell, but that fails with a warning: WARNING: CPU: 0 PID: 9 at fs/proc/generic.c:405 because procfs limits the maximum filename length to 255. However, the DNS limits the maximum lookup length and, by extension, the maximum cell name, to 255 less two (length count and trailing NUL). Fix this by limiting the maximum acceptable cellname length to 253. This also allows us to be sure we can create the "/afs/.<cell>/" mountpoint too. Further, split the YFS VL record cell name maximum to be the 256 allowed by the protocol and ignore the record retrieved by YFSVL.GetCellName if it exceeds 253. Fixes: c3e9f88 ("afs: Implement client support for the YFSVL.GetCellName RPC op") Reported-by: [email protected] Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: [email protected] cc: Marc Dionne <[email protected]> cc: [email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 3ff93c5 commit 8fd56ad

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

fs/afs/afs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <linux/in.h>
1212

13-
#define AFS_MAXCELLNAME 256 /* Maximum length of a cell name */
13+
#define AFS_MAXCELLNAME 253 /* Maximum length of a cell name (DNS limited) */
1414
#define AFS_MAXVOLNAME 64 /* Maximum length of a volume name */
1515
#define AFS_MAXNSERVERS 8 /* Maximum servers in a basic volume record */
1616
#define AFS_NMAXNSERVERS 13 /* Maximum servers in a N/U-class volume record */

fs/afs/afs_vl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define AFS_VL_PORT 7003 /* volume location service port */
1414
#define VL_SERVICE 52 /* RxRPC service ID for the Volume Location service */
1515
#define YFS_VL_SERVICE 2503 /* Service ID for AuriStor upgraded VL service */
16+
#define YFS_VL_MAXCELLNAME 256 /* Maximum length of a cell name in YFS protocol */
1617

1718
enum AFSVL_Operations {
1819
VLGETENTRYBYID = 503, /* AFS Get VLDB entry by ID */

fs/afs/vl_alias.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ static char *afs_vl_get_cell_name(struct afs_cell *cell, struct key *key)
253253
static int yfs_check_canonical_cell_name(struct afs_cell *cell, struct key *key)
254254
{
255255
struct afs_cell *master;
256+
size_t name_len;
256257
char *cell_name;
257258

258259
cell_name = afs_vl_get_cell_name(cell, key);
@@ -264,8 +265,11 @@ static int yfs_check_canonical_cell_name(struct afs_cell *cell, struct key *key)
264265
return 0;
265266
}
266267

267-
master = afs_lookup_cell(cell->net, cell_name, strlen(cell_name),
268-
NULL, false);
268+
name_len = strlen(cell_name);
269+
if (!name_len || name_len > AFS_MAXCELLNAME)
270+
master = ERR_PTR(-EOPNOTSUPP);
271+
else
272+
master = afs_lookup_cell(cell->net, cell_name, name_len, NULL, false);
269273
kfree(cell_name);
270274
if (IS_ERR(master))
271275
return PTR_ERR(master);

fs/afs/vlclient.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static int afs_deliver_yfsvl_get_cell_name(struct afs_call *call)
697697
return ret;
698698

699699
namesz = ntohl(call->tmp);
700-
if (namesz > AFS_MAXCELLNAME)
700+
if (namesz > YFS_VL_MAXCELLNAME)
701701
return afs_protocol_error(call, afs_eproto_cellname_len);
702702
paddedsz = (namesz + 3) & ~3;
703703
call->count = namesz;

0 commit comments

Comments
 (0)