• Eric Biggers's avatar
    cifs: clear PF_MEMALLOC before exiting demultiplex thread · dc920277
    Eric Biggers authored
    Leaving PF_MEMALLOC set when exiting a kthread causes it to remain set
    during do_exit().  That can confuse things.  For example, if BSD process
    accounting is enabled and the accounting file has FS_SYNC_FL set and is
    located on an ext4 filesystem without a journal, then do_exit() can end
    up calling ext4_write_inode().  That triggers the
    WARN_ON_ONCE(current->flags & PF_MEMALLOC) there, as it assumes
    (appropriately) that inodes aren't written when allocating memory.
    
    This was originally reported for another kernel thread, xfsaild() [1].
    cifs_demultiplex_thread() also exits with PF_MEMALLOC set, so it's
    potentially subject to this same class of issue -- though I haven't been
    able to reproduce the WARN_ON_ONCE() via CIFS, since unlike xfsaild(),
    cifs_demultiplex_thread() is sent SIGKILL before exiting, and that
    interrupts the write to the BSD process accounting file.
    
    Either way, leaving PF_MEMALLOC set is potentially problematic.  Let's
    clean this up by properly saving and restoring PF_MEMALLOC.
    
    [1] https://lore.kernel.org/r/0000000000000e7156059f751d7b@google.comSigned-off-by: default avatarEric Biggers <ebiggers@google.com>
    Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
    dc920277
connect.c 144 KB