Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5252984imu; Tue, 15 Jan 2019 14:08:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN6NZr+Xhn3DyuhrDZhVAb+ZMbfahpkkr7rq8QOrG/OIxWQm7s1s6UBmh5lwf+y6+fbV/jbU X-Received: by 2002:a17:902:50e:: with SMTP id 14mr6287225plf.141.1547590110690; Tue, 15 Jan 2019 14:08:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547590110; cv=none; d=google.com; s=arc-20160816; b=Jo0fn+QBJ7KJwyI7+m/X7b1hDuGsMhE5XzV0jqeIhOHj77pngvOddWtJ3rdzGPAl3A v6tF6FLcBQLwQWb0gsXMCfyV1z1J7LxCXbq/56w9rICgB2w+7coxk9umHtZMW5RcMakB 6K5Yz9McNxsuJgvFp7OP4kPcHPvyLz0x49CwkbJvlyUiWEKUfNAzoFLsFCSOJRjaRxRe LLxm57w8kWtWSYM7Xhs2vURZTM34vBWAmPKBRxBMYwHkICszW1UsluLn6UFt/2yAxuiA KIMFtjILoBVomJ3Lv/bp8InhJUXvZ5xFrrHCMsiVmFOu4Ozbs2eMJ0Hn+1ftfYujskj4 khJQ== 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=UEcFe+CXUwDewxahE5oFzyGXMlVi2q2Vw/qFQYq1cyQ=; b=Xi2Wb/Z6V6i51YZEea9nupeUZH3WplOEdPa/grdjZ3za1q64g9P2/D2s6yum1KycQK S0IOPIKZ4X3XpxG3WNs1p79YentKTjcwOLudn3Z2xI8G/0bcYSp1vQzZAjOn1Oay+9yo YLBlSP5FPD9kZhv+f8Px3ojNzJ5uuKWe264t/UC9tNwOGelqBiAxvQC911pmiVEiiLWE FABnuhES4Xq55M1c+blvXk/S8tM2NbP1R+lSs1txvfTyeadmagYjB6FYlutj0MBxClCJ m9NvmW4q1e580Rjejl14ZYbFwiAcLuG6HK6WuEZ138891ZKmxkAK8Jj8Ac8EXlibx9sc y8rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qHTS9Rzd; 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 37si4136290pgs.447.2019.01.15.14.08.14; Tue, 15 Jan 2019 14:08:30 -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=qHTS9Rzd; 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 S2387869AbfAOQpx (ORCPT + 99 others); Tue, 15 Jan 2019 11:45:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:35580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730777AbfAOQpw (ORCPT ); Tue, 15 Jan 2019 11:45:52 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 91DCA20645; Tue, 15 Jan 2019 16:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570751; bh=Z6IkQSb6jGEafGufY4dvP7q6EyNqPQKsU7x+QePa3Fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qHTS9RzdYJoAGaWiKM0g5zkoGLM9Fe29anOSBvyp+fdn2xRhnGOnTUvHTwP0SBcc2 1blULrBLgGfJMdxg8rrq2pzhj9XtIy7HHleaFqCohR7SG8K2ofQCvTldCYx7Xsc+30 5C+cnl9EE3wcgynT/CCMDG0RmnreQYhmDhYiLnKU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Filipe Manana , David Sterba Subject: [PATCH 4.20 57/57] Btrfs: use nofs context when initializing security xattrs to avoid deadlock Date: Tue, 15 Jan 2019 17:36:38 +0100 Message-Id: <20190115154914.200006528@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit 827aa18e7b903c5ff3b3cd8fec328a99b1dbd411 upstream. When initializing the security xattrs, we are holding a transaction handle therefore we need to use a GFP_NOFS context in order to avoid a deadlock with reclaim in case it's triggered. Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations") Reviewed-by: Nikolay Borisov Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/xattr.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "ctree.h" #include "btrfs_inode.h" #include "transaction.h" @@ -422,9 +423,15 @@ static int btrfs_initxattrs(struct inode { const struct xattr *xattr; struct btrfs_trans_handle *trans = fs_info; + unsigned int nofs_flag; char *name; int err = 0; + /* + * We're holding a transaction handle, so use a NOFS memory allocation + * context to avoid deadlock if reclaim happens. + */ + nofs_flag = memalloc_nofs_save(); for (xattr = xattr_array; xattr->name != NULL; xattr++) { name = kmalloc(XATTR_SECURITY_PREFIX_LEN + strlen(xattr->name) + 1, GFP_KERNEL); @@ -440,6 +447,7 @@ static int btrfs_initxattrs(struct inode if (err < 0) break; } + memalloc_nofs_restore(nofs_flag); return err; }