xfs_scrub: warn about unicode variation selectors in names
PATCH 1/1 xfs_scrub: warn about unicode variation selectors in names
From: Darrick J. Wong <[email protected]>
ArsTechnica recently wrote about a GitHub supply chain attack wherein non-rendering unicode sequences were embedded in javascript files to hide payloads that could be decrypted trivially later. While these are unlikely to appear in file and attribute names, we should warn about this sort of steganography.
Signed-off-by "Darrick J. Wong" <[email protected]>
--- scrub/unicrash.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
scrub/unicrash.c +25 -0
@@ -130,6 +130,9 @@ struct unicrash {/* Multiple names resolve to the same case-insensitive string. */ #define UNICRASH_SAMECASE ((__force badname_t)(1U << 7)) +/* More than one variation selector in a row. */ +#define UNICRASH_VARIATION_RUN ((__force badname_t)(1U << 8)) +/* FULL STOP (aka period), 0x2E */ #define UCHAR_PERIOD ((UChar32)'.')
@@ -504,9 +507,14 @@ name_entry_examine(UChar32 uchr;uint8_t mask =0 ;unsigned int ret =0 ; +/* Don't allow the first codepoint to be a variation */ +UBool was_variation = true;uiter_setString (&uiter, entry->normstr, entry->normstrlen);while ((uchr =uiter_next32 (&uiter)) !=U_SENTINEL ) { +UBool is_variation = +u_hasBinaryProperty (uchr,UCHAR_VARIATION_SELECTOR ); +/* characters are invisible */ if (is_nonrendering (uchr)) ret |=UNICRASH_INVISIBLE ;
@@ -537,6 +545,11 @@ name_entry_examine(default :break ; } + +if (is_variation && was_variation) + ret |=UNICRASH_VARIATION_RUN ; + + was_variation = is_variation; }/* mixing left-to-right and right-to-left chars */
@@ -841,6 +854,18 @@ _("Unicode name \"%s\" in %s contains control characters."), goto out; } +/* +* Variation codepoints only apply to the previous non-variation +* codepoint. Seeing multiple in a row or at the start of a name is +* weird. +*/ +if (badflags &UNICRASH_VARIATION_RUN ) { +str_warn (uc->ctx,descr_render (dsc), +_ ("Unicode name \"%s\" in %s contains a weird sequence of variation selectors." ), + bad1, what); + goto out; + } +/* * Skip the informational messages if the inode owning the name is * only writeable by root, because those files were put there by the
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>