Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6948744imm; Tue, 24 Jul 2018 06:03:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcEH5R18dhGWNTVb/89Wrrlh6AD9DchXmjiVNJxt2Ag8LUSM7Q8GzWI384vPZFhgVjgWG34 X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr17141066plc.11.1532437416978; Tue, 24 Jul 2018 06:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532437416; cv=none; d=google.com; s=arc-20160816; b=c5Vi5nshoYp30H5rgF9qfvxcoWHld70LcYT/mYuP+RZ+C9qynpfiS18PEEN31pqKog z0SKJJ+rxuxrpCgei2lrwuaEHiv0T4PLb8rgWZjdPkg9pHcRPPCs1mc4alfJpW+qzJ62 rgeRaPcoln4gvoR/V5QKQ1pgxJTI0YGEWeB1is9RipwtRoMZijWa7UD3HmgVMHYjopVY PVcoyc4mckrNCko2pozU7xCx1OqR4ltFKR2T/99IOefPTAQxG/kX1aLeZC4MMziaO0oL 9eqTO9mg2T+yeeLBU7+m5zGlDzm9N6MFISh/XxpFOjfpyOPGrmuUgZP6uGuRSKgrNue7 1dXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=3BgljC+3PT0Ic4dJXbKfRELkvUnoZrlTurBgY1AEfa0=; b=FTDQv8O5rxIKorUoGEUSNUh9wgHOm/SZkkVxXP/mDWsh5sMGlJgFXMRQ/XtxknBwGr qcAHv/FRX/TXZ0mPp1G9/0oiNgiKvAuNevywP02onPOXaRSEjoz/4X+TZBU1NFTmAjzq GB1IRHh/Lv8g0DgUAsgHwgwX2iLBoM86f2FQUCJRW5+xtTkd51l7Rj3oM9qW9dbcXh+0 XgtSDUBwi9gtXntflGPSfBeChYd6cZQzLbQkjV0KhFrwxnP/aO/hkffT9z0Zn2U9BJsz 9wmShYwwonGHO4HrSZf27lTWKq5RJx2V6xbx2JJs5jtEb4iixW3yWSIAqhuaIY1N9Rfm Wbuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f19-v6si6853926pgv.383.2018.07.24.06.03.22; Tue, 24 Jul 2018 06:03:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388382AbeGXOI0 (ORCPT + 99 others); Tue, 24 Jul 2018 10:08:26 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:54825 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388302AbeGXOIZ (ORCPT ); Tue, 24 Jul 2018 10:08:25 -0400 Received: by mail-wm0-f68.google.com with SMTP id c14-v6so2439662wmb.4 for ; Tue, 24 Jul 2018 06:02:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3BgljC+3PT0Ic4dJXbKfRELkvUnoZrlTurBgY1AEfa0=; b=W7Cp76Lq6Zc/RLjjNl+LcQZQ63NkODfPP8/aJ2mUo27lshJUnQtt/aaYH1UPE4Ltph OqITstqKvRKl9U1zwBP9bkeSH9SV2wyBWi7vHPZ+EXD9uRelVwSZivYWnCz/g3JoytfT P1WJpLN+LH5b/Rb0dBwavnPEtgxGPxTxiJ/SIGPYbhb7cCHh3i5ejHStRV0QSBfE3Jni d1ElMqc3Lo3c750fkDwarhwJ7x36hM2c/qD9ZwpDd9xN4I/6bAYqZy+agTsEya3pC9jK pLag2x3dG89bvrO0dFzC6dQtol8lOgmvpTfS/kim8E6QKnYJ2O1kTCSYoXECc/ROXSXu Sy2A== X-Gm-Message-State: AOUpUlHdIJxKm6LNmh3avw/lckXILStc5fQPoEm/rVYLrFGbNGy0UXt0 8+0+ABW5OxVyvZ5T7Kg0w2OLSp+Z2DY= X-Received: by 2002:a1c:7506:: with SMTP id o6-v6mr1945308wmc.60.1532437320892; Tue, 24 Jul 2018 06:02:00 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id f20-v6sm1993358wmd.3.2018.07.24.06.01.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 06:02:00 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3] vfs: don't evict uninitialized inode Date: Tue, 24 Jul 2018 15:01:55 +0200 Message-Id: <20180724130155.20641-1-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180724064929.GD19722@shao2-debian> References: <20180724064929.GD19722@shao2-debian> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org iput() ends up calling ->evict() on new inode, which is not yet initialized by owning fs. So use destroy_inode() instead. Add to sb->s_inodes list only if inode is not in I_CREATING state (meaning that it wasn't allocated with new_inode(), which already does the insertion). Reported-by: Al Viro Signed-off-by: Miklos Szeredi Fixes: 80ea09a002bf ("vfs: factor out inode_insert5()") --- fs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 04dd7e0d5142..0aa5b29b6f87 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1050,6 +1050,7 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, { struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); struct inode *old; + bool creating = inode->i_state & I_CREATING; again: spin_lock(&inode_hash_lock); @@ -1083,6 +1084,8 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, inode->i_state |= I_NEW; hlist_add_head(&inode->i_hash, head); spin_unlock(&inode->i_lock); + if (!creating) + inode_sb_list_add(inode); unlock: spin_unlock(&inode_hash_lock); @@ -1117,12 +1120,13 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, struct inode *inode = ilookup5(sb, hashval, test, data); if (!inode) { - struct inode *new = new_inode(sb); + struct inode *new = alloc_inode(sb); if (new) { + new->i_state = 0; inode = inode_insert5(new, hashval, test, set, data); if (unlikely(inode != new)) - iput(new); + destroy_inode(new); } } return inode; -- 2.14.3