From patchwork Tue Jul 12 00:15:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunwei Chen X-Patchwork-Id: 9224441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B2C960760 for ; Tue, 12 Jul 2016 00:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D44D527F17 for ; Tue, 12 Jul 2016 00:22:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C83D527F46; Tue, 12 Jul 2016 00:22:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6439B27F10 for ; Tue, 12 Jul 2016 00:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932088AbcGLAWc (ORCPT ); Mon, 11 Jul 2016 20:22:32 -0400 Received: from p3plsmtpa11-06.prod.phx3.secureserver.net ([68.178.252.107]:37810 "EHLO p3plsmtpa11-06.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751698AbcGLAWb (ORCPT ); Mon, 11 Jul 2016 20:22:31 -0400 X-Greylist: delayed 432 seconds by postgrey-1.27 at vger.kernel.org; Mon, 11 Jul 2016 20:22:31 EDT Received: from david-dev.osnexus.net ([63.229.31.161]) by p3plsmtpa11-06.prod.phx3.secureserver.net with id HcFG1t0043Uav1K01cFHmg; Mon, 11 Jul 2016 17:15:18 -0700 From: Chunwei Chen To: linux-kernel@vger.kernel.org Cc: Chunwei Chen , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] vfs: check i_count under lock in evict_inodes Date: Mon, 11 Jul 2016 17:15:04 -0700 Message-Id: <1468282504-2272-1-git-send-email-david.chen@osnexus.com> X-Mailer: git-send-email 2.7.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need to check i_count again with i_lock held, because iput might re-add i_count when lazytime is on. Without this check, we could end up with double-free or use-after-free. Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Chunwei Chen --- fs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 4ccbc21..10bb020 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -607,7 +607,12 @@ again: continue; spin_lock(&inode->i_lock); - if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) { + /* + * check i_count again with lock, because iput might re-add + * it when lazytime is on. + */ + if (atomic_read(&inode->i_count) || + (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE))) { spin_unlock(&inode->i_lock); continue; }