jffs2: Add checks for long file name

Add filename length checks to prevent the creation of files and folders
that cannot be listed, unlinked or renamed by subsequent calls.
These changes are sufficient to make the jffs2fsrenamelongname and
jffs2nandfsrenamelongname testcases pass.

Updates #5073
This commit is contained in:
Loris Nardo
2024-08-13 07:02:04 +02:00
committed by Joel Sherrill
parent c2b3a517f6
commit b5767d2c60
2 changed files with 13 additions and 9 deletions

View File

@@ -80,6 +80,10 @@ int jffs2_create(struct _inode *dir_i, const char *d_name, size_t d_namelen, int
qstr.name = d_name;
qstr.len = d_namelen;
if (d_namelen > JFFS2_MAX_NAME_LEN) {
return -ENAMETOOLONG;
}
ri = jffs2_alloc_raw_inode();
if (!ri)
return -ENOMEM;
@@ -148,6 +152,10 @@ int jffs2_link (struct _inode *old_d_inode, struct _inode *dir_i, const unsigned
uint8_t type = (old_d_inode->i_mode & S_IFMT) >> 12;
if (!type) type = DT_REG;
if (d_namelen > JFFS2_MAX_NAME_LEN) {
return -ENAMETOOLONG;
}
ret = jffs2_do_link(c, dir_f, f->inocache->ino, type,
(const char * )d_name,
d_namelen, get_seconds());
@@ -183,7 +191,7 @@ int jffs2_mknod(
/* FIXME: If you care. We'd need to use frags for the data
if it grows much more than this */
if (datalen > 254)
if (datalen > 254 || d_namelen > JFFS2_MAX_NAME_LEN)
return -ENAMETOOLONG;
ri = jffs2_alloc_raw_inode();
@@ -373,6 +381,10 @@ int jffs2_rename (struct _inode *old_dir_i, struct _inode *d_inode, const unsign
}
#endif
if (new_d_namelen > JFFS2_MAX_NAME_LEN) {
return -ENAMETOOLONG;
}
/* XXX: We probably ought to alloc enough space for
both nodes at the same time. Writing the new link,
then getting -ENOSPC, is quite bad :)

View File

@@ -65,14 +65,6 @@ actions:
- mdosfsfsrenamemaxlinks
- mimfsfsrenamemaxlinks
- mrfsfsrenamemaxlinks
- set-test-state:
reason: |
Fails because of #5073, JFFS2 seems to not have appart
limits on file name length
state: expected-fail
tests:
- jffs2fsrenamelongname
- jffs2nandfsrenamelongname
build-type: option
copyrights:
- Copyright (C) 2020 embedded brains GmbH & Co. KG