11 Apr, 2020

1 commit

  • When removing files containing extended attributes, the hfsplus driver may
    remove the wrong entries from the attributes b-tree, causing major
    filesystem damage and in some cases even kernel crashes.

    To remove a file, all its extended attributes have to be removed as well.
    The driver does this by looking up all keys in the attributes b-tree with
    the cnid of the file. Each of these entries then gets deleted using the
    key used for searching, which doesn't contain the attribute's name when it
    should. Since the key doesn't contain the name, the deletion routine will
    not find the correct entry and instead remove the one in front of it. If
    parent nodes have to be modified, these become corrupt as well. This
    causes invalid links and unsorted entries that not even macOS's fsck_hfs
    is able to fix.

    To fix this, modify the search key before an entry is deleted from the
    attributes b-tree by copying the found entry's key into the search key,
    therefore ensuring that the correct entry gets removed from the tree.

    Signed-off-by: Simon Gander
    Signed-off-by: Andrew Morton
    Reviewed-by: Anton Altaparmakov
    Cc:
    Link: http://lkml.kernel.org/r/20200327155541.1521-1-simon@tuxera.com
    Signed-off-by: Linus Torvalds

    Simon Gander
     

31 Oct, 2018

1 commit

  • Inserting or deleting a record in a btree may require splitting several of
    its nodes. If we hit ENOSPC halfway through, the new nodes will be left
    orphaned and their records will be lost. This could mean lost inodes,
    extents or xattrs.

    Henceforth, check the available disk space before making any changes.
    This still leaves the potential problem of corruption on ENOMEM.

    The patch can be tested with xfstests generic/027.

    Link: http://lkml.kernel.org/r/4596eef22fbda137b4ffa0272d92f0da15364421.1536269129.git.ernesto.mnd.fernandez@gmail.com
    Signed-off-by: Ernesto A. Fernández
    Cc: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ernesto A. Fernández
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

07 Jun, 2014

2 commits

  • The directory/file catalog b-tree equivalent, hfsplus_build_key_uni(),
    is used by hfsplus_find_cat() for internal referencing between catalog
    records. There is no corresponding usage for attributes - attribute
    records do not refer to one another.

    Signed-off-by: Hin-Tak Leung
    Cc: Sougata Santra
    Cc: Anton Altaparmakov
    Cc: Vyacheslav Dubeyko
    Cc: Al Viro
    Cc: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hin-Tak Leung
     
  • HFSPLUS_ATTR_MAX_STRLEN (=127) is the limit of attribute names for the
    number of unicode character (UTF-16BE) storable in the HFS+ file system.
    Almost all the current usage of it is wrong, in relation to NLS to
    on-disk conversion.

    Except for one use calling hfsplus_asc2uni (which should stay the same)
    and its uses in calling hfsplus_uni2asc (which was corrected in the
    earlier patch in this series concerning usage of hfsplus_uni2asc), all
    the other uses are of the forms:

    - char buffer[size]

    - bound check: "if (namespace_adjusted_input_length > size) return failure;"

    Conversion between on-disk unicode representation and NLS char strings
    (in whichever direction) always needs to accommodate the worst-case NLS
    conversion, so all char buffers of that size need to have a
    NLS_MAX_CHARSET_SIZE x .

    The bound checks are all wrong, since they compare nls_length derived
    from strlen() to a unicode length limit.

    It turns out that all the bound-checks do is to protect
    hfsplus_asc2uni(), which can fail if the input is too large.

    There is only one usage of it as far as attributes are concerned, in
    hfsplus_attr_build_key(). It is in turn used by hfsplus_find_attr(),
    hfsplus_create_attr(), hfsplus_delete_attr(). Thus making sure that
    errors from hfsplus_asc2uni() is caught in hfsplus_attr_build_key() and
    propagated is sufficient to replace all the bound checks.

    Unpropagated errors from hfsplus_asc2uni() in the file catalog code was
    addressed recently in an independent patch "hfsplus: fix longname
    handling" by Sougata Santra.

    Before this patch, trying to set a 55 CJK character (in a UTF-8 locale,
    > 127/3=42) attribute plus user prefix fails with:

    $ setfattr -n user.`cat testing-string` -v `cat testing-string` \
    testing-string
    setfattr: testing-string: Operation not supported

    and retrieving a stored long attributes is particular ugly(!):

    find /mnt/* -type f -exec getfattr -d {} \;
    getfattr: /mnt/testing-string: Input/output error

    with console log:
    [268008.389781] hfsplus: unicode conversion failed

    After the patch, both of the above works.

    FYI, the test attribute string is prepared with:

    echo -e -n \
    "\xe9\x80\x99\xe6\x98\xaf\xe4\xb8\x80\xe5\x80\x8b\xe9\x9d\x9e\xe5" \
    "\xb8\xb8\xe6\xbc\xab\xe9\x95\xb7\xe8\x80\x8c\xe6\xa5\xb5\xe5\x85" \
    "\xb6\xe4\xb9\x8f\xe5\x91\xb3\xe5\x92\x8c\xe7\x9b\xb8\xe7\x95\xb6" \
    "\xe7\x84\xa1\xe8\xb6\xa3\xe3\x80\x81\xe4\xbb\xa5\xe5\x8f\x8a\xe7" \
    "\x84\xa1\xe7\x94\xa8\xe7\x9a\x84\xe3\x80\x81\xe5\x86\x8d\xe5\x8a" \
    "\xa0\xe4\xb8\x8a\xe6\xaf\xab\xe7\x84\xa1\xe6\x84\x8f\xe7\xbe\xa9" \
    "\xe7\x9a\x84\xe6\x93\xb4\xe5\xb1\x95\xe5\xb1\xac\xe6\x80\xa7\xef" \
    "\xbc\x8c\xe8\x80\x8c\xe5\x85\xb6\xe5\x94\xaf\xe4\xb8\x80\xe5\x89" \
    "\xb5\xe5\xbb\xba\xe7\x9b\xae\xe7\x9a\x84\xe5\x83\x85\xe6\x98\xaf" \
    "\xe7\x82\xba\xe4\xba\x86\xe6\xb8\xac\xe8\xa9\xa6\xe4\xbd\x9c\xe7" \
    "\x94\xa8\xe3\x80\x82" | tr -d ' '

    (= "pointlessly long attribute for testing", elaborate Chinese in
    UTF-8 enoding).

    However, it is not possible to set double the size (110 + 5 is still
    under 127) in a UTF-8 locale:

    $setfattr -n user.`cat testing-string testing-string` -v \
    `cat testing-string testing-string` testing-string
    setfattr: testing-string: Numerical result out of range

    110 CJK char in UTF-8 is 330 bytes - the generic get/set attribute
    system call code in linux/fs/xattr.c imposes a 255 byte limit. One can
    use a combination of iconv to encode content, changing terminal locale
    for viewing, and an nls=cp932/cp936/cp949/cp950 mount option to fully
    use 127-unicode attribute in a double-byte locale.

    Also, as an additional information, it is possible to (mis-)use unicode
    half-width/full-width forms (U+FFxx) to write attributes which looks
    like english but not actually ascii.

    Thanks Anton Altaparmakov for reviewing the earlier ideas behind this
    change.

    [akpm@linux-foundation.org: fix build]
    [akpm@linux-foundation.org: fix build]
    Signed-off-by: Hin-Tak Leung
    Cc: Anton Altaparmakov
    Cc: Vyacheslav Dubeyko
    Cc: Al Viro
    Cc: Christoph Hellwig
    Cc: Sougata Santra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hin-Tak Leung
     

04 Apr, 2014

1 commit


01 May, 2013

2 commits

  • Use a more current logging style.

    Add #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
    hfsplus now uses "hfsplus: " for all messages.
    Coalesce formats.
    Prefix debugging messages too.

    Signed-off-by: Joe Perches
    Cc: Vyacheslav Dubeyko
    Cc: Hin-Tak Leung
    Cc: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     
  • Use a more current logging style.

    Rename macro and uses.
    Add do {} while (0) to macro.
    Add DBG_ to macro.
    Add and use hfs_dbg_cont variant where appropriate.

    Signed-off-by: Joe Perches
    Cc: Vyacheslav Dubeyko
    Cc: Hin-Tak Leung
    Cc: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

28 Feb, 2013

1 commit