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

ldiskfs: FORTIFY_SOURCE WARNING in ldiskfs_set_dirdata() for names of 238+ bytes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • Lustre 2.18.0
    • None
    • 3
    • 9223372036854775807

      On kernels built with CONFIG_FORTIFY_SOURCE=y (all EL10 kernels), creating a file with a long name on an ldiskfs MDT triggers a kernel WARNING in ldiskfs_set_dirdata():

      ------------[ cut here ]------------
      memcpy: detected field-spanning write (size 17) of single field "&de->name[de->name_len + 1]" at /lustre/ldiskfs/namei.c:1720 (size 16)
      WARNING: CPU: 1 PID: 10681 at /lustre/ldiskfs/namei.c:1720 ldiskfs_set_dirdata+0xc2/0xe0 [ldiskfs]
      CPU: 1 UID: 0 PID: 10681 Comm: mdt00_002 Kdump: loaded Tainted: G OE ------ --- 6.12.0-124.56.1.el10_1_lustre #1
       add_dirent_to_buf+0xe4/0x210 [ldiskfs]
       ldiskfs_add_entry_locked+0x185/0x4d0 [ldiskfs]
       osd_ldiskfs_add_entry+0x3d/0x260 [osd_ldiskfs]
       __osd_ea_add_rec+0x21c/0x4f0 [osd_ldiskfs]
       osd_ea_add_rec+0x9d/0x2e0 [osd_ldiskfs]
       osd_index_ea_insert+0x238/0x970 [osd_ldiskfs]
       __mdd_index_insert_only+0x86/0x140 [mdd]
       __mdd_index_insert+0x3e/0x150 [mdd]
       mdd_create+0x88b/0x11c0 [mdd]
       mdt_create+0xc01/0x21d0 [mdt]
       mdt_reint_create+0x1a3/0x410 [mdt]
       mdt_reint_rec+0x120/0x270 [mdt]
       mdt_reint_internal+0x4c8/0x8a0 [mdt]
       mdt_reint+0x61/0x120 [mdt]
       tgt_request_handle+0x232/0xd50 [ptlrpc]
       ptlrpc_main+0xaeb/0xed0 [ptlrpc]
      

      Cause

      ext4_set_dirdata() (ext4-dirdata-core.patch) writes the LUFID record after the filename through de->name[]:

      int data_offset = de->name_len + 1;
      if (data) {
      	de->name[de->name_len] = 0;
      	memcpy(&de->name[de->name_len + 1], data, *(char *)data);   /* namei.c:1720 */
      	de->file_type |= EXT4_DIRENT_LUFID;
      	...
      

      de->name is declared char name[EXT4_NAME_LEN] (255 bytes) and the LUFID record is 17 bytes. For names of 238 bytes or longer the copy runs past the declared array, and FORTIFY_SOURCE reports a field-spanning write. The bytes are still inside the directory record (rec_len reserves the space), so no memory is corrupted, but every EL10 MDS logs a WARNING the first time a client creates such a name, and a server running with panic_on_warn panics.

      Reproducer

      Plain long names are enough; encryption is not needed. Single-node ltvm VM, rocky10, kernel 6.12.0-124.56.1.el10_1_lustre, Lustre master b5131ea46c:

      mkdir /mnt/lustre/d
      for n in $(seq 200 255); do touch /mnt/lustre/d/$(printf 'a%.0s' $(seq 1 $n)); done
      dmesg | grep field-spanning
      

      The first name to warn is 238 bytes long (255 - 238 - 1 = 16 bytes left in name[] for the 17-byte record). It was first seen in sanity-sec test_46 (long ciphertext names) and is hit by any client create with a name of 238+ bytes.

      Affected

      ldiskfs/kernel_patches/patches/

      {rhel10.0,rhel10.1,linux-6.12,linux-6.18,linux-7.0}

      /ext4-dirdata-core.patch, used by the ldiskfs-6.12-rhel10.0, 6.12-rhel10.1, 6.12-rhel10.2, 6.12-ml, 6.18-ml, 7.0-ml and 7.0.0-14-ubuntu26 series.

      Fix

      Address the dirdata area from the start of the name instead of through de->name[], so the write is not bounded by the declared array size. The on-disk format and the bytes written are unchanged. A patch follows.

      Tested with the fix on the same VM: no warning for names of 200-255 bytes, a 255-byte directory and a rename to a 255-byte name; LFSCK namespace makes no repairs and e2fsck -fn on the MDT is clean. Lustre builds cleanly for rhel10.0, rhel10.1, rhel10.2 and ubuntu26; on mainline 6.12.95, 6.18.22 and 7.0 ldiskfs compiles with the fix (the full build there fails at modpost on obd_dif_ip_fn/obd_dif_crc_fn in osd_ldiskfs.ko, which unfixed master hits too).

            ablagodarenko Artem Blagodarenko
            ablagodarenko Artem Blagodarenko
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: