Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-21214

lov_foreign_hsm_to_le() swabs destination field instead of source, corrupting foreign HSM layout EA

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • None
    • None
    • 3
    • 9223372036854775807

      lov_foreign_hsm_to_le() in include/uapi/linux/lustre/lustre_idl.h is
      supposed to byte-swap the caller-supplied `src` HSM base fields into
      the on-disk (little-endian) `dst` buffer embedded in the
      lov_foreign_md. Instead it reads and swabs dst's own (uninitialized)
      field back into itself, never touching src:
      static inline void lov_foreign_hsm_to_le(struct lov_foreign_md *lfm,
      struct lov_hsm_base *src)

      { struct lov_hsm_base *dst = (struct lov_hsm_base *)lfm->lfm_value; dst->lhb_archive_id = __cpu_to_le64(dst->lhb_archive_id); dst->lhb_archive_ver = __cpu_to_le64(dst->lhb_archive_ver); memcpy(dst->lhb_uuid, src->lhb_uuid, sizeof(dst->lhb_uuid)); }

      Compare with the inverse helper, lov_foreign_hsm_to_cpu(), which
      correctly reads from src and writes to dst:
      dst->lhb_archive_id = __le64_to_cpu(src->lhb_archive_id);
      dst->lhb_archive_ver = __le64_to_cpu(src->lhb_archive_ver);
      Effect: any code path that serializes an HSM-typed foreign layout
      component (e.g. lod_gen_component_ea_foreign() in
      lustre/lod/lod_lov.c)
      never actually writes the caller's lhb_archive_id/lhb_archive_ver
      into
      the on-disk lov_foreign_md - dst's pre-existing/uninitialized memory
      is swabbed in place instead, and the real values from src are
      silently dropped. Only lhb_uuid is copied correctly.
      Fix: swab from src into dst, matching lov_foreign_hsm_to_cpu()'s
      pattern:
      dst->lhb_archive_id = __cpu_to_le64(src->lhb_archive_id);
      dst->lhb_archive_ver = __cpu_to_le64(src->lhb_archive_ver);

      Found while adding kunit coverage for lod_gen_component_ea_foreign()
      under LU-21180.

            rsahlberg@whamcloud.com Ronnie Sahlberg
            rsahlberg@whamcloud.com Ronnie Sahlberg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: