Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FF2CC433DF for ; Thu, 14 May 2020 18:34:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D99620671 for ; Thu, 14 May 2020 18:34:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbgENSeB (ORCPT ); Thu, 14 May 2020 14:34:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:57264 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726188AbgENSeB (ORCPT ); Thu, 14 May 2020 14:34:01 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3807EADFE; Thu, 14 May 2020 18:34:03 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 9E3E51E04CF; Thu, 14 May 2020 20:26:29 +0200 (CEST) From: Jan Kara To: Al Viro Cc: , Jan Kara Subject: [PATCH] fs: Check freed inode is not left on dirty list Date: Thu, 14 May 2020 20:26:17 +0200 Message-Id: <20200514182617.20087-1-jack@suse.cz> X-Mailer: git-send-email 2.16.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add check that freed inode is not left on dirty list. ext4 had a bug that could do that resulting in difficult to debug use-after-free issues with inodes. Also add a comment in evict() explaining why dirty list handling there is safe. Signed-off-by: Jan Kara --- fs/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 93d9252a00ab..15260b6d5590 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -534,6 +534,7 @@ void clear_inode(struct inode *inode) BUG_ON(!(inode->i_state & I_FREEING)); BUG_ON(inode->i_state & I_CLEAR); BUG_ON(!list_empty(&inode->i_wb_list)); + BUG_ON(!list_empty(&inode->i_io_list)); /* don't need i_lock here, no concurrent mods to i_state */ inode->i_state = I_FREEING | I_CLEAR; } @@ -559,6 +560,13 @@ static void evict(struct inode *inode) BUG_ON(!(inode->i_state & I_FREEING)); BUG_ON(!list_empty(&inode->i_lru)); + /* + * We are the only holder of the inode so it cannot be marked dirty. + * Flusher thread won't start new writeback because I_FREEING is set + * but there can be still redirty_tail() running from + * writeback_sb_inodes(). However this list_move() cannot result in + * list_empty() returning true. + */ if (!list_empty(&inode->i_io_list)) inode_io_list_del(inode); -- 2.16.4