Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2929424ybx; Fri, 8 Nov 2019 11:24:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwbB8K1oxvwhUG77qzSYPof7sCUTNKVy0mq3vkyPAi4B/ENrIrEyUpFcUUqlitP5/O4GKDn X-Received: by 2002:a50:91f6:: with SMTP id h51mr12055953eda.99.1573241061649; Fri, 08 Nov 2019 11:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573241061; cv=none; d=google.com; s=arc-20160816; b=Og+9TPtCdQTCuhDkW26rD2w+p7HswffE1PPbndE4HAZ7SSSaxyzSgu3pqzHSbbfxjp P8/X5y0FmsF/ESILrIiIvyNyeaAlPu2LjkO/ALy0gz9847lzfSg8OqO4Onty20aB62yq IarNcg2hBxPznDLGOGZrrXyi/NgFU+oeA3QXLi4NNWInqzVQjAcIG4So+YxY1OQanmbA D9yKti0XpBY5uUkesv/VXGDBbjDFkh+zUPsjjli+hAVF2GXwRmnud/wvQ4xuMqygq1DI Wh0BZJ5MmrwVWBZlePEo3ZLBINeD9WsleeQ/9vLAV9uKtM1uquHCCeFn6osOrnDxy6PU lipA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lkUz1GhEaHN2RpHoug6wBumAnFRmqbYvWyLRRkVRBVA=; b=Biorc2HPVwJC1+Cg9YqkKimcSeu2g/fo82w9wtvTer4xEwqbeQe1DhaN4M/glOZKKD 0ZpFSrA7rHAbdZJyrFk2FMCgX5K+3HYz1K8toZyS7Om5k230ziDfjceDpg4mtJDDieXA 4HUHdRK59IY4TZV+dKXfXq3HMF9hXR9+ywimxH7UPR7jRnLJbkMqCIyodHVUHEV0d6JV vUvSpfERNvri8xDYkbwAz4tfjBYmdoRG4RHfNP7qUdC8nzo4M8WBI9iX5iAYfinN4lwT M7ZZPh17afxmBbjZo5kiNfiQq5TIQu1GUl1HqSZ2bV2jrM1TIxLE4mQQUhLtwee72vqA 55nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="upDs/OkA"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e12si5589180edj.70.2019.11.08.11.23.58; Fri, 08 Nov 2019 11:24:21 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="upDs/OkA"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387478AbfKHSz2 (ORCPT + 99 others); Fri, 8 Nov 2019 13:55:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:52794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387450AbfKHSzZ (ORCPT ); Fri, 8 Nov 2019 13:55:25 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 81A8221D7B; Fri, 8 Nov 2019 18:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239325; bh=cf4fThauuWxzmQyRZyubd1OD81i0Gk+jhsiMiQj+k+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upDs/OkAlHv95wWVd3Drv64qTdVOmlsuW4Wut7lIkJR7Pe7xlhlahxU5U8MXaHgra 6v5DFoGdT9H17GLkfqhKkxi21CMhZH3u2ghKsKAs03uaIbx/B7XJBP6skX23VuFNp8 PmN6VoIjByYosQpQMvhd+VjDHZoaz7M6nIIvPy0s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "zhangyi (F)" Subject: [PATCH 4.4 75/75] fs/dcache: move security_d_instantiate() behind attaching dentry to inode Date: Fri, 8 Nov 2019 19:50:32 +0100 Message-Id: <20191108174814.283185120@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "zhangyi (F)" During backport 1e2e547a93a "do d_instantiate/unlock_new_inode combinations safely", there was a error instantiating sequence of attaching dentry to inode and calling security_d_instantiate(). Before commit ce23e640133 "->getxattr(): pass dentry and inode as separate arguments" and b96809173e9 "security_d_instantiate(): move to the point prior to attaching dentry to inode", security_d_instantiate() should be called beind __d_instantiate(), otherwise it will trigger below problem when CONFIG_SECURITY_SMACK on ext4 was enabled because d_inode(dentry) used by ->getxattr() is NULL before __d_instantiate() instantiate inode. [ 31.858026] BUG: unable to handle kernel paging request at ffffffffffffff70 ... [ 31.882024] Call Trace: [ 31.882378] [] ext4_xattr_get+0x8c/0x3e0 [ 31.883195] [] ext4_xattr_security_get+0x24/0x40 [ 31.884086] [] generic_getxattr+0x5b/0x90 [ 31.884907] [] smk_fetch+0xb4/0x150 [ 31.885634] [] smack_d_instantiate+0x1c2/0x550 [ 31.886508] [] security_d_instantiate+0x3a/0x80 [ 31.887389] [] d_instantiate_new+0x36/0x130 [ 31.888223] [] ext4_mkdir+0x4af/0x6a0 [ 31.888928] [] vfs_mkdir+0x100/0x280 [ 31.889536] [] SyS_mkdir+0xb6/0x170 [ 31.890255] [] ? trace_do_page_fault+0x95/0x2b0 [ 31.891134] [] entry_SYSCALL_64_fastpath+0x18/0x73 Cc: # 3.16, 4.4 Signed-off-by: zhangyi (F) Signed-off-by: Greg Kroah-Hartman --- fs/dcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1903,7 +1903,6 @@ void d_instantiate_new(struct dentry *en BUG_ON(!hlist_unhashed(&entry->d_u.d_alias)); BUG_ON(!inode); lockdep_annotate_inode_mutex_key(inode); - security_d_instantiate(entry, inode); spin_lock(&inode->i_lock); __d_instantiate(entry, inode); WARN_ON(!(inode->i_state & I_NEW)); @@ -1911,6 +1910,7 @@ void d_instantiate_new(struct dentry *en smp_mb(); wake_up_bit(&inode->i_state, __I_NEW); spin_unlock(&inode->i_lock); + security_d_instantiate(entry, inode); } EXPORT_SYMBOL(d_instantiate_new);