• Zhihao Cheng's avatar
    ubifs: Fix AA deadlock when setting xattr for encrypted file · a0c51565
    Zhihao Cheng authored
    Following process:
    vfs_setxattr(host)
      ubifs_xattr_set
        down_write(host_ui->xattr_sem)   <- lock first time
          create_xattr
            ubifs_new_inode(host)
              fscrypt_prepare_new_inode(host)
                fscrypt_policy_to_inherit(host)
                  if (IS_ENCRYPTED(inode))
                    fscrypt_require_key(host)
                      fscrypt_get_encryption_info(host)
                        ubifs_xattr_get(host)
                          down_read(host_ui->xattr_sem) <- AA deadlock
    
    , which may trigger an AA deadlock problem:
    
    [  102.620871] INFO: task setfattr:1599 blocked for more than 10 seconds.
    [  102.625298]       Not tainted 5.19.0-rc7-00001-gb666b6823ce0-dirty #711
    [  102.628732] task:setfattr        state:D stack:    0 pid: 1599
    [  102.628749] Call Trace:
    [  102.628753]  <TASK>
    [  102.628776]  __schedule+0x482/0x1060
    [  102.629964]  schedule+0x92/0x1a0
    [  102.629976]  rwsem_down_read_slowpath+0x287/0x8c0
    [  102.629996]  down_read+0x84/0x170
    [  102.630585]  ubifs_xattr_get+0xd1/0x370 [ubifs]
    [  102.630730]  ubifs_crypt_get_context+0x1f/0x30 [ubifs]
    [  102.630791]  fscrypt_get_encryption_info+0x7d/0x1c0
    [  102.630810]  fscrypt_policy_to_inherit+0x56/0xc0
    [  102.630817]  fscrypt_prepare_new_inode+0x35/0x160
    [  102.630830]  ubifs_new_inode+0xcc/0x4b0 [ubifs]
    [  102.630873]  ubifs_xattr_set+0x591/0x9f0 [ubifs]
    [  102.630961]  xattr_set+0x8c/0x3e0 [ubifs]
    [  102.631003]  __vfs_setxattr+0x71/0xc0
    [  102.631026]  vfs_setxattr+0x105/0x270
    [  102.631034]  do_setxattr+0x6d/0x110
    [  102.631041]  setxattr+0xa0/0xd0
    [  102.631087]  __x64_sys_setxattr+0x2f/0x40
    
    Fetch a reproducer in [Link].
    
    Just like ext4 does, which skips encrypting for inode with
    EXT4_EA_INODE_FL flag. Stop encypting xattr inode for ubifs.
    
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=216260
    Fixes: f4e3634a ("ubifs: Fix races between xattr_{set|get} ...")
    Fixes: d475a507 ("ubifs: Add skeleton for fscrypto")
    Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
    Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
    a0c51565
ubifs.h 72.2 KB