Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1413226pxk; Sun, 13 Sep 2020 01:39:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI6krvBMBOhxnK/1oND4MiLduWapjDMOw9pFD92AYwfBFlFeoLdsnwdsr9MOZWBWgThxLW X-Received: by 2002:a05:6402:456:: with SMTP id p22mr11623257edw.177.1599986367174; Sun, 13 Sep 2020 01:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599986367; cv=none; d=google.com; s=arc-20160816; b=IslAcZKMR4/vjDX/w6IPFsceXx3I/fUfDUvOdYAiF3hpOI5U9As1yHulrMu6e3/RDv GQL8cQr9sZw7WogUvGj57eCbRK+LCccHSeGXVR82sITSHw8Lgvo1bUlRHc1BZ4vTqc7c 056+XJZOFCHTprJLvdAW6jciJarR8IDRIES2V0rpjb6d7AiEObQEFYzmcHdcxwJewcYr Vl5mS81QlHHgYZx5zA5/HOQhW+lIPiLjRgyeFRb9WUhDAQErI9g45hQoOJVw/OzVhbXM ouFtcf2EjUSY+DbhfuXGIfkZ5ikHXd81GUkCZRUnH3EUpeQkFdX5FGs0Y7vSgJV6O/bm ILWQ== 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=AGEkovunS7dU2Ykk0C3iWfQOmlfDqLZBafXQ/zScJJ8=; b=n96/5aRaPPa21rcE5qV+7V05gWzXSSgO1Gqs2Z2ir859KaK8VrU6+IJHwRrY14U5u6 qb3WQXSLLBrPRM/YIk/zF8zjQRemZLuUCC88dwsuKrzSES2JZHyaZ6aMlUZQiBdWlksb ZKGam9PRZI8JEUY+4JMP5bbZKd1vGmsHmwtRTLdGKwLU+WhHp7kbtRCQiI3JZ4YfbyPu A0mUS3sIaT/PvEpxmtMCiXeKGsyWEb8bQoHV3LIlb25JOdXMUEGPlBNcs7Yy3kYsBXrG 5SGhx1lYTADWCqNT8HPpLIl7QHm6d/+NZv0YrGRRpZzkmEugr9WqcaXw0KvHlenTPmNr nYoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=htn5yvO7; 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 df7si5335688edb.271.2020.09.13.01.39.04; Sun, 13 Sep 2020 01:39:27 -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=htn5yvO7; 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 S1726010AbgIMIim (ORCPT + 99 others); Sun, 13 Sep 2020 04:38:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:60892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725968AbgIMIiD (ORCPT ); Sun, 13 Sep 2020 04:38:03 -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 ADEDA21897; 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=ZzMv1pUhY0NvnbJHjrS2ra7ESt6vtXPBJHTWIdsGFCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=htn5yvO7LimZHQRe0sNzsC6HWpNV2ozCcjLCoxA2U9dMCvVUhX+F3sLgJGNsNeThm Qpm56LCeKLX/y+YPmuNFV3XiL6WWzw4EGH/L7x1ZgQem4c6oYP9lj9QNygbClngGw9 gIDlHOloDtyrRG1uzwwilmGP9u8I6vN0pvLAbntk= 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 07/11] fscrypt: require that fscrypt_encrypt_symlink() already has key Date: Sun, 13 Sep 2020 01:36:16 -0700 Message-Id: <20200913083620.170627-8-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 Now that all filesystems have been converted to use fscrypt_prepare_new_inode(), the encryption key for new symlink inodes is now already set up whenever we try to encrypt the symlink target. Enforce this rather than try to set up the key again when it may be too late to do so safely. Signed-off-by: Eric Biggers --- fs/crypto/hooks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c index 491b252843eb9..7748db5092409 100644 --- a/fs/crypto/hooks.c +++ b/fs/crypto/hooks.c @@ -217,9 +217,13 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target, struct fscrypt_symlink_data *sd; unsigned int ciphertext_len; - err = fscrypt_require_key(inode); - if (err) - return err; + /* + * fscrypt_prepare_new_inode() should have already set up the new + * symlink inode's encryption key. We don't wait until now to do it, + * since we may be in a filesystem transaction now. + */ + if (WARN_ON_ONCE(!fscrypt_has_encryption_key(inode))) + return -ENOKEY; if (disk_link->name) { /* filesystem-provided buffer */ -- 2.28.0