xfs_repair: allow '/' in attribute names
PATCH 1/1 xfs_repair: allow '/' in attribute names
For some reason, since the earliest days of XFS, a '/' character in an extended attribute name has been treated as corruption by xfs_repair. This despite nothing in other userspace tools or the kernel having this restriction.
My best guess is that this was an unintentional leftover from common code between dirs & attrs in the "da" code, and there has never been a good reason for it.
Since userspace and kernelspace allow such a name to be set, listed, and read, it seems wrong to flag it as corruption. So, make this test conditional on whether we're validating a name in a dir, as opposed to the name of an attr.
---
repair/attr_repair.c +4 -6
@@ -292,11 +292,9 @@ process_shortform_attr( } } -/* namecheck checks for / and null terminated for file names. -* attributes names currently follow the same rules. -*/ +/* namecheck checks for null chars in attr names. */ if (namecheck ((char *)¤tentry->nameval[0 ], - currententry->namelen)) { + currententry->namelen, false)) {do_warn (_ ("entry contains illegal character in shortform attribute name\n" )); junkit =1 ;
@@ -459,7 +457,7 @@ process_leaf_attr_local( local =xfs_attr3_leaf_name_local (leaf, i);if (local->namelen ==0 ||namecheck ((char *)&local->nameval[0 ], - local->namelen)) { + local->namelen, false)) {do_warn (_ ("attribute entry %d in attr block %u, inode %" PRIu64" has bad name (namelen = %d)\n" ), i, da_bno, ino, local->namelen);
@@ -514,7 +512,7 @@ process_leaf_attr_remote( remotep =xfs_attr3_leaf_name_remote (leaf, i); if (remotep->namelen == 0 || namecheck((char *)&remotep->name[0], - remotep->namelen) || + remotep->namelen, false) || be32_to_cpu(entry->hashval) != libxfs_da_hashname((unsigned char *)&remotep->name[0], remotep->namelen) ||
repair/da_util.c +12 -7
@@ -13,20 +13,25 @@#include "da_util.h" /* -* takes a name and length (name need not be null-terminated) -* and returns 1 if the name contains a '/' or a \0, returns 0 -* otherwise +* takes a name and length (name need not be null-terminated) and whether +* we are checking a dir (vs an attr), and returns 1 if the direntry contains +* a '/', or if anything contains a \0, and returns 0 otherwise */ int -namecheck (char *name,int length) +namecheck ( +char *name, +int length, +bool isadir) { -char *c; -int i; +char *c; +int i;ASSERT (length <MAXNAMELEN );for (c = name, i =0 ; i < length; i++, c++) { -if (*c =='/' || *c =='\0' ) +if (isadir && *c =='/' ) +return 0 ; +if (*c =='\0' )return 1 ; }
repair/da_util.h +2 -1
@@ -27,7 +27,8 @@ typedef struct da_bt_cursor {int namecheck (char *name, -int length); +int length, +bool isadir);struct xfs_buf * da_read_buf(
repair/dir2.c +2 -2
@@ -310,7 +310,7 @@ _("entry #%d %s in shortform dir %" PRIu64),* the length value is stored in a byte * so it can't be too big, it can only wrap */ -if (namecheck ((char *)&sfep->name[0 ], namelen)) { +if (namecheck ((char *)&sfep->name[0 ], namelen, true)) {/* * junk entry */
@@ -781,7 +781,7 @@ _("\twould clear inode number in entry at offset %" PRIdPTR "...\n"),* during phase 4. */ junkit = dep->name[0 ] =='/' ; - nm_illegal =namecheck ((char *)dep->name, dep->namelen); + nm_illegal =namecheck ((char *)dep->name, dep->namelen, true);if (ino_discovery && nm_illegal) { do_warn( _("entry at block %u offset %" PRIdPTR " in directory inode %" PRIu64 " has illegal name \"%*.*s\": "),
Quoted 5 lines · Eric Sandeen
For some reason, since the earliest days of XFS, a '/' character in an extended attribute name has been treated as corruption by
xfs_repair. This despite nothing in other userspace tools or the kernel having this restriction.
Quoted 8 lines
My best guess is that this was an unintentional leftover from common code between dirs & attrs in the "da" code, and there has never been a good reason for it.
Since userspace and kernelspace allow such a name to be set, listed, and read, it seems wrong to flag it as corruption. So, make this test conditional on whether we're validating a name in a dir, as opposed to the name of an attr.
Sounds fair.
Quoted 9 lines
Signed-off-by Eric Sandeen <[email protected]>---
repair/attr_repair.c +0
-0
repair/attr_repair.c process_shortform_attr( · line 297
Quoted 10 lines
repair/attr_repair.c +2
-4@@ -292,11 +292,9 @@ process_shortform_attr( } } -/* namecheck checks for / and null terminated for file names. -* attributes names currently follow the same rules. -*/ +/* namecheck checks for null chars in attr names. */ if (namecheck ((char *)¤tentry->nameval[0 ], - currententry->namelen)) { + currententry->namelen, false)) {
Hmmmm. that's kinda messy. How about:
/* attr_namecheck checks for null chars in attr names. */ bool
attr_namecheck(
uint8_t name,
int length)
{
return namecheck((char *)name, length, false);
}Quoted 13 lines
repair/attr_repair.c +1
-1do_warn (_ ("entry contains illegal character in shortform attribute name\n" )); junkit =1 ;@@ -459,7 +457,7 @@ process_leaf_attr_local( local =xfs_attr3_leaf_name_local (leaf, i);if (local->namelen ==0 ||namecheck ((char *)&local->nameval[0 ], - local->namelen)) { + local->namelen, false)) {do_warn (_ ("attribute entry %d in attr block %u, inode %" PRIu64" has bad name (namelen = %d)\n" ), i, da_bno, ino, local->namelen);
repair/attr_repair.c process_leaf_attr_remote( · line 518
Quoted 8 lines
repair/attr_repair.c +1
-1@@ -514,7 +512,7 @@ process_leaf_attr_remote( remotep =xfs_attr3_leaf_name_remote (leaf, i); if (remotep->namelen == 0 || namecheck((char *)&remotep->name[0], - remotep->namelen) || + remotep->namelen, false) || be32_to_cpu(entry->hashval) != libxfs_da_hashname((unsigned char *)&remotep->name[0], remotep->namelen) ||
That gets rid of the casts out of this code as well, and hides the boolean inside the scope where it has meaning.
Quoted 56 lines
repair/da_util.c +12
-7@@ -13,20 +13,25 @@#include "da_util.h" /* -* takes a name and length (name need not be null-terminated) -* and returns 1 if the name contains a '/' or a \0, returns 0 -* otherwise +* takes a name and length (name need not be null-terminated) and whether +* we are checking a dir (vs an attr), and returns 1 if the direntry contains +* a '/', or if anything contains a \0, and returns 0 otherwise */ int -namecheck (char *name,int length) +namecheck ( +char *name, +int length, +bool isadir) { -char *c; -int i; +char *c; +int i;ASSERT (length <MAXNAMELEN );for (c = name, i =0 ; i < length; i++, c++) { -if (*c =='/' || *c =='\0' ) +if (isadir && *c =='/' ) +return 0 ; +if (*c =='\0' )return 1 ; }repair/da_util.h +2
-1@@ -27,7 +27,8 @@ typedef struct da_bt_cursor {int namecheck (char *name, -int length); +int length, +bool isadir);struct xfs_buf * da_read_buf(repair/dir2.c +0
-0
repair/dir2.c _("entry #%d %s in shortform dir %" PRIu64), · line 313
Quoted 5 lines
repair/dir2.c +1
-1@@ -310,7 +310,7 @@ _("entry #%d %s in shortform dir %" PRIu64),* the length value is stored in a byte * so it can't be too big, it can only wrap */ -if (namecheck ((char *)&sfep->name[0 ], namelen)) { +if (namecheck ((char *)&sfep->name[0 ], namelen, true)) {
same for these - convert to a dir_namecheck() wrapper function....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 39 lines · Dave Chinner
Quoted 5 lines · Eric Sandeen
For some reason, since the earliest days of XFS, a '/' character in an extended attribute name has been treated as corruption by
xfs_repair. This despite nothing in other userspace tools or the kernel having this restriction.Quoted 8 lines
My best guess is that this was an unintentional leftover from common code between dirs & attrs in the "da" code, and there has never been a good reason for it.
Since userspace and kernelspace allow such a name to be set, listed, and read, it seems wrong to flag it as corruption. So, make this test conditional on whether we're validating a name in a dir, as opposed to the name of an attr.
Sounds fair.
Quoted 9 lines
Signed-off-by Eric Sandeen <[email protected]>---
repair/attr_repair.c +0
-0repair/attr_repair.c process_shortform_attr( · line 297
Quoted 10 lines
repair/attr_repair.c +2
-4@@ -292,11 +292,9 @@ process_shortform_attr( } } -/* namecheck checks for / and null terminated for file names. -* attributes names currently follow the same rules. -*/ +/* namecheck checks for null chars in attr names. */ if (namecheck ((char *)¤tentry->nameval[0 ], - currententry->namelen)) { + currententry->namelen, false)) {Hmmmm. that's kinda messy. How about:
Quoted 8 lines
/*
attr_namecheckchecks for null chars in attr names. */ bool
attr_namecheck(uint8_t name, int length) { return namecheck((char *)name, length, false); }
Ok, good idea.
-Eric
Quoted 49 lines · Eric Sandeen
Quoted 39 lines · Dave Chinner
Quoted 5 lines · Eric Sandeen
For some reason, since the earliest days of XFS, a '/' character in an extended attribute name has been treated as corruption by
xfs_repair. This despite nothing in other userspace tools or the kernel having this restriction.Quoted 8 lines
My best guess is that this was an unintentional leftover from common code between dirs & attrs in the "da" code, and there has never been a good reason for it.
Since userspace and kernelspace allow such a name to be set, listed, and read, it seems wrong to flag it as corruption. So, make this test conditional on whether we're validating a name in a dir, as opposed to the name of an attr.
Sounds fair.
Quoted 9 lines
Signed-off-by Eric Sandeen <[email protected]>---
repair/attr_repair.c +0
-0repair/attr_repair.c process_shortform_attr( · line 297
Quoted 10 lines
repair/attr_repair.c +2
-4@@ -292,11 +292,9 @@ process_shortform_attr( } } -/* namecheck checks for / and null terminated for file names. -* attributes names currently follow the same rules. -*/ +/* namecheck checks for null chars in attr names. */ if (namecheck ((char *)¤tentry->nameval[0 ], - currententry->namelen)) { + currententry->namelen, false)) {Hmmmm. that's kinda messy. How about:
Quoted 8 lines
/*
attr_namecheckchecks for null chars in attr names. */ bool
attr_namecheck(uint8_t name, int length) { return namecheck((char *)name, length, false); }
Quoted 1 line
Ok, good idea.
Can you put the dir/attr name verifier function(s) into libxfs so I can reuse it in scrub instead of opencoding the same in there? Pretty please? :D
--D
Quoted 1 line
-Eric
PATCH v2 1/1 xfs_repair: allow '/' in attribute names
In reply to Eric SandeenFor some reason, since the earliest days of XFS, a '/' character in an extended attribute name has been treated as corruption by xfs_repair. This despite nothing in other userspace tools or the kernel having this restriction.
My best guess is that this was an unintentional leftover from common code between dirs & attrs in the "da" code, and there has never been a good reason for it.
Since userspace and kernelspace allow such a name to be set, listed, and read, it seems wrong to flag it as corruption. So, make this test conditional on whether we're validating a name in a dir, as opposed to the name of an attr.
---
V2: refactor per dave's suggestion
djwong has new helpers in libxfs for this now, I'll pick them up and switch to them in...
... drumroll ...
...xfsprogs-5.0
-Eric
repair/attr_repair.c +13 -7
@@ -122,6 +122,14 @@ set_da_freemap(xfs_mount_t *mp, da_freemap_t *map, int start, int stop)* fork being emptied and put in shortform format. */ +static int +attr_namecheck ( +uint8_t *name, +int length) +{ +return namecheck ((char *)name, length, false); +} +/* * This routine just checks what security needs are for attribute values * only called when root flag is set, otherwise these names could exist in
@@ -292,11 +300,9 @@ process_shortform_attr( } } -/* namecheck checks for / and null terminated for file names. -* attributes names currently follow the same rules. -*/ -if (namecheck ((char *)¤tentry->nameval[0 ], - currententry->namelen)) { +/* namecheck checks for null chars in attr names. */ +if (attr_namecheck (currententry->nameval, + currententry->namelen)) {do_warn (_ ("entry contains illegal character in shortform attribute name\n" )); junkit =1 ;
@@ -458,7 +464,7 @@ process_leaf_attr_local(xfs_attr_leaf_name_local_t *local; local =xfs_attr3_leaf_name_local (leaf, i); -if (local->namelen ==0 ||namecheck ((char *)&local->nameval[0 ], +if (local->namelen ==0 ||attr_namecheck (local->nameval, local->namelen)) { do_warn( _("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"),
@@ -513,7 +519,7 @@ process_leaf_attr_remote( remotep =xfs_attr3_leaf_name_remote (leaf, i); -if (remotep->namelen ==0 ||namecheck ((char *)&remotep->name[0 ], +if (remotep->namelen ==0 ||attr_namecheck (remotep->name, remotep->namelen) ||be32_to_cpu (entry->hashval) != libxfs_da_hashname((unsigned char *)&remotep->name[0],
repair/da_util.c +12 -7
@@ -13,20 +13,25 @@#include "da_util.h" /* -* takes a name and length (name need not be null-terminated) -* and returns 1 if the name contains a '/' or a \0, returns 0 -* otherwise +* takes a name and length (name need not be null-terminated) and whether +* we are checking a dir (vs an attr), and returns 1 if the direntry contains +* a '/', or anything contains a \0, returns 0 otherwise */ int -namecheck (char *name,int length) +namecheck ( +char *name, +int length, +bool isadir) { -char *c; -int i; +char *c; +int i;ASSERT (length <MAXNAMELEN );for (c = name, i =0 ; i < length; i++, c++) { -if (*c =='/' || *c =='\0' ) +if (isadir && *c =='/' ) +return 0 ; +if (*c =='\0' )return 1 ; }
repair/da_util.h +2 -1
@@ -27,7 +27,8 @@ typedef struct da_bt_cursor {int namecheck (char *name, -int length); +int length, +bool isadir);struct xfs_buf * da_read_buf(
repair/dir2.c +10 -2
@@ -44,6 +44,14 @@ _("malloc failed (%zu bytes) dir2_add_badlist:ino %" PRIu64 "\n"), l->ino = ino; } +static int +dir_namecheck ( +uint8_t *name, +int length) +{ +return namecheck ((char *)name, length, true); +} +int dir2_is_badino (xfs_ino_t ino)
@@ -310,7 +318,7 @@ _("entry #%d %s in shortform dir %" PRIu64),* the length value is stored in a byte * so it can't be too big, it can only wrap */ -if (namecheck ((char *)&sfep->name[0 ], namelen)) { +if (dir_namecheck (sfep->name, namelen)) {/* * junk entry */
@@ -781,7 +789,7 @@ _("\twould clear inode number in entry at offset %" PRIdPTR "...\n"),* during phase 4. */ junkit = dep->name[0 ] =='/' ; - nm_illegal =namecheck ((char *)dep->name, dep->namelen); + nm_illegal =dir_namecheck (dep->name, dep->namelen);if (ino_discovery && nm_illegal) { do_warn( _("entry at block %u offset %" PRIdPTR " in directory inode %" PRIu64 " has illegal name \"%*.*s\": "),
Quoted 85 lines · Eric Sandeen
For some reason, since the earliest days of XFS, a '/' character in an extended attribute name has been treated as corruption by
xfs_repair. This despite nothing in other userspace tools or the kernel having this restriction.My best guess is that this was an unintentional leftover from common code between dirs & attrs in the "da" code, and there has never been a good reason for it.
Since userspace and kernelspace allow such a name to be set, listed, and read, it seems wrong to flag it as corruption. So, make this test conditional on whether we're validating a name in a dir, as opposed to the name of an attr.
Signed-off-by Eric Sandeen <[email protected]>---
V2: refactor per dave's suggestion
djwong has new helpers in libxfs for this now, I'll pick them up and switch to them in...
... drumroll ...
...xfsprogs-5.0
(quoted diff) +0
-1-Ericrepair/attr_repair.c +13
-7@@ -122,6 +122,14 @@ set_da_freemap(xfs_mount_t *mp, da_freemap_t *map, int start, int stop)* fork being emptied and put in shortform format. */ +static int +attr_namecheck ( +uint8_t *name, +int length) +{ +return namecheck ((char *)name, length, false); +} +/* * This routine just checks what security needs are for attribute values * only called when root flag is set, otherwise these names could exist in @@ -292,11 +300,9 @@ process_shortform_attr( } } -/* namecheck checks for / and null terminated for file names. -* attributes names currently follow the same rules. -*/ -if (namecheck ((char *)¤tentry->nameval[0 ], - currententry->namelen)) { +/* namecheck checks for null chars in attr names. */ +if (attr_namecheck (currententry->nameval, + currententry->namelen)) {do_warn (_ ("entry contains illegal character in shortform attribute name\n" )); junkit =1 ;@@ -458,7 +464,7 @@ process_leaf_attr_local(xfs_attr_leaf_name_local_t *local; local =xfs_attr3_leaf_name_local (leaf, i); -if (local->namelen ==0 ||namecheck ((char *)&local->nameval[0 ], +if (local->namelen ==0 ||attr_namecheck (local->nameval, local->namelen)) { do_warn( _("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"),@@ -513,7 +519,7 @@ process_leaf_attr_remote( remotep =xfs_attr3_leaf_name_remote (leaf, i); -if (remotep->namelen ==0 ||namecheck ((char *)&remotep->name[0 ], +if (remotep->namelen ==0 ||attr_namecheck (remotep->name, remotep->namelen) ||be32_to_cpu (entry->hashval) != libxfs_da_hashname((unsigned char *)&remotep->name[0],repair/da_util.c +0
-0
repair/da_util.c line 18
Quoted 9 lines
repair/da_util.c +3
-3@@ -13,20 +13,25 @@#include "da_util.h" /* -* takes a name and length (name need not be null-terminated) -* and returns 1 if the name contains a '/' or a \0, returns 0 -* otherwise +* takes a name and length (name need not be null-terminated) and whether +* we are checking a dir (vs an attr), and returns 1 if the direntry contains +* a '/', or anything contains a \0, returns 0 otherwise
Sort of a run-on sentence with no end marker
Maybe it's not such a big deal if it's all gonna get replaced with libxfs helpers next release anyway.
Looks ok as far as I can see, which today ain't much. :(
--D
Quoted 75 lines
repair/da_util.c +9
-4*/ int -namecheck (char *name,int length) +namecheck ( +char *name, +int length, +bool isadir) { -char *c; -int i; +char *c; +int i;ASSERT (length <MAXNAMELEN );for (c = name, i =0 ; i < length; i++, c++) { -if (*c =='/' || *c =='\0' ) +if (isadir && *c =='/' ) +return 0 ; +if (*c =='\0' )return 1 ; }repair/da_util.h +2
-1@@ -27,7 +27,8 @@ typedef struct da_bt_cursor {int namecheck (char *name, -int length); +int length, +bool isadir);struct xfs_buf * da_read_buf(repair/dir2.c +10
-2@@ -44,6 +44,14 @@ _("malloc failed (%zu bytes) dir2_add_badlist:ino %" PRIu64 "\n"), l->ino = ino; } +static int +dir_namecheck ( +uint8_t *name, +int length) +{ +return namecheck ((char *)name, length, true); +} +int dir2_is_badino (xfs_ino_t ino)@@ -310,7 +318,7 @@ _("entry #%d %s in shortform dir %" PRIu64),* the length value is stored in a byte * so it can't be too big, it can only wrap */ -if (namecheck ((char *)&sfep->name[0 ], namelen)) { +if (dir_namecheck (sfep->name, namelen)) {/* * junk entry */ @@ -781,7 +789,7 @@ _("\twould clear inode number in entry at offset %" PRIdPTR "...\n"),* during phase 4. */ junkit = dep->name[0 ] =='/' ; - nm_illegal =namecheck ((char *)dep->name, dep->namelen); + nm_illegal =dir_namecheck (dep->name, dep->namelen);if (ino_discovery && nm_illegal) { do_warn( _("entry at block %u offset %" PRIdPTR " in directory inode %" PRIu64 " has illegal name \"%*.*s\": "),