Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1413976pxk; Sun, 13 Sep 2020 01:41:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7uYNWY116sBAYHpPoahZ6BCbi3TKCVEf/2K20mzuyQ375X8VbibPell7I9bAIVm7FfyT5 X-Received: by 2002:a50:9f6f:: with SMTP id b102mr11634702edf.272.1599986496616; Sun, 13 Sep 2020 01:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599986496; cv=none; d=google.com; s=arc-20160816; b=n/rsDuDEph5hyKsR2M0T7ikEIl/Uo0+2zanlrCfUl+BgP0mIOaXmgEIiHg6FO+0NTx pr/SznIjNN2Zb+9sF63quJoKz/6ZDCcBI/gKeTmS+XaLO0M4rr22xFPMrz6pzyp+8C/j wgrUjgiNvQYjM7/SxVrpzh7CwN7vMz5aoJNeGgVOvJFgKyfx3K54BNB7yEZsc++OjScE VZAsd1K1EnU75YsJKeIya5w+/+o+oKyamXqYw4nqsZZSMnScXPkByvYIMAg42tcPkJJp DCV55UOA6ktYO3IStKnIVG4vuGHQ5dPewszK2CK3fMXpvTB0ahkT5rJKkbcWWpK1toQW xHsg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jkNrjTt8shjtg+o0ygBkC+ogiOmaLBRtatna970dw3w=; b=1ELL3NpcM0Qk1Xnn8QxIMCfzTTSB6Ud46qouKEYUbMIURrTHy1/0+2JlBgmbnUi94p uFeD4P97iCana9KZG4eNjlKxQ6hc+skkVptYp+rFGPwGmarw6J9dqIV0YHBZaeZPeaeH 2CCRDLpHyyM7PpeMBbidXEizQVL+m+apO7p09q1AwyZq9su4PO4HtH56XEJuicKX3F9/ RizUI/oEG+JjPToEK8Jhko/gVPrTWgTVyeBjEIBvTQXJstBg1qOP/Ao2OzHVgLYgMzg5 oJnKRV4weACSkBI/Z6pRRxj0XOwkJcb4SRkMLUd+rQaao6JBB96t41VAXMGc9ohFCpwe VqGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dt37vv3o; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si4691356ejx.348.2020.09.13.01.41.13; Sun, 13 Sep 2020 01:41:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dt37vv3o; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726025AbgIMIiz (ORCPT + 99 others); Sun, 13 Sep 2020 04:38:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:60862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbgIMIiC (ORCPT ); Sun, 13 Sep 2020 04:38:02 -0400 Received: from sol.attlocal.net (172-10-235-113.lightspeed.sntcca.sbcglobal.net [172.10.235.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F82221974; Sun, 13 Sep 2020 08:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599986279; bh=kONvZL9ec2SBbE4EAel9mci0YCQN1pZc7hmFt/F6qwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dt37vv3oahYtgL3ZyctM6QKg97LdSKU34ArCqE9y/U84AQImmjJjp3IWpIeQl2boS KR5a1PsbxdPL8JYbUIX8BxdraDjfMGMuehFFlmoxAmRLN8Iu8UVTjj0WRil4BKsjzY V8lffoJKumHVSbQOwdTzejpV6lXUi6DoBaK6UQQ4= From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, ceph-devel@vger.kernel.org, Jeff Layton , Daniel Rosenberg Subject: [PATCH v2 05/11] ubifs: use fscrypt_prepare_new_inode() and fscrypt_set_context() Date: Sun, 13 Sep 2020 01:36:14 -0700 Message-Id: <20200913083620.170627-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200913083620.170627-1-ebiggers@kernel.org> References: <20200913083620.170627-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Convert ubifs to use the new functions fscrypt_prepare_new_inode() and fscrypt_set_context(). Unlike ext4 and f2fs, this doesn't appear to fix any deadlock bug. But it does shorten the code slightly and get all filesystems using the same helper functions, so that fscrypt_inherit_context() can be removed. It also fixes an incorrect error code where ubifs returned EPERM instead of the expected ENOKEY. Signed-off-by: Eric Biggers --- fs/ubifs/dir.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index a9c1f5a9c9bdd..155521e51ac57 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -81,19 +81,6 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, struct ubifs_inode *ui; bool encrypted = false; - if (IS_ENCRYPTED(dir)) { - err = fscrypt_get_encryption_info(dir); - if (err) { - ubifs_err(c, "fscrypt_get_encryption_info failed: %i", err); - return ERR_PTR(err); - } - - if (!fscrypt_has_encryption_key(dir)) - return ERR_PTR(-EPERM); - - encrypted = true; - } - inode = new_inode(c->vfs_sb); ui = ubifs_inode(inode); if (!inode) @@ -112,6 +99,12 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, current_time(inode); inode->i_mapping->nrpages = 0; + err = fscrypt_prepare_new_inode(dir, inode, &encrypted); + if (err) { + ubifs_err(c, "fscrypt_prepare_new_inode failed: %i", err); + goto out_iput; + } + switch (mode & S_IFMT) { case S_IFREG: inode->i_mapping->a_ops = &ubifs_file_address_operations; @@ -131,7 +124,6 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, case S_IFBLK: case S_IFCHR: inode->i_op = &ubifs_file_inode_operations; - encrypted = false; break; default: BUG(); @@ -151,9 +143,8 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, if (c->highest_inum >= INUM_WATERMARK) { spin_unlock(&c->cnt_lock); ubifs_err(c, "out of inode numbers"); - make_bad_inode(inode); - iput(inode); - return ERR_PTR(-EINVAL); + err = -EINVAL; + goto out_iput; } ubifs_warn(c, "running out of inode numbers (current %lu, max %u)", (unsigned long)c->highest_inum, INUM_WATERMARK); @@ -171,16 +162,19 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, spin_unlock(&c->cnt_lock); if (encrypted) { - err = fscrypt_inherit_context(dir, inode, &encrypted, true); + err = fscrypt_set_context(inode, NULL); if (err) { - ubifs_err(c, "fscrypt_inherit_context failed: %i", err); - make_bad_inode(inode); - iput(inode); - return ERR_PTR(err); + ubifs_err(c, "fscrypt_set_context failed: %i", err); + goto out_iput; } } return inode; + +out_iput: + make_bad_inode(inode); + iput(inode); + return ERR_PTR(err); } static int dbg_check_name(const struct ubifs_info *c, -- 2.28.0