Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp118279rdb; Fri, 26 Jan 2024 22:38:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnSrvPBJLGac0KU1ynLJpZcbsDqF6kX9BPtuzqz02OsV40orD7dNYfNGUNzBb8NL3KneI/ X-Received: by 2002:ad4:5946:0:b0:681:7a1e:e36c with SMTP id eo6-20020ad45946000000b006817a1ee36cmr1314802qvb.72.1706337488244; Fri, 26 Jan 2024 22:38:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706337488; cv=pass; d=google.com; s=arc-20160816; b=Ujsi108PJhYzJ+Bw3siseeFIlqIRdpX0CEJ6t2M3n7bLhXc4Kqc1t7gZZerV0ROtHk D433DIFKwbReLkhnoznxg/janVbmyP/3SOawCPCu+xXBy1FkZ9qWA4ym88NOKZ0Tvy/+ qpZ78lDPKfwdGsOAxx2agiCvlnYqhfTEB6IoHj9pgJf3VoMg8h0sG2Rg5vSkw7gbckM4 cDSwjar/QIfktzxpF5axFm7F/yKRApukaMmKLfage6VvHEpIAENR3Cs1RIr98DExyHYW 45sGvt2wqXAIVqH2gC2LBRV88reSehYFc2pnaUuZPjkXudVw/b22mPybYRTVtDcKfslV 3KCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lrr1CYwHmYeIM92qM3gtWmZ29ijfcXwL/QfGuLt8OBg=; fh=rdVT5VBbbzKiSa3epdQkTj4xwq5hbNact1gWQyued9U=; b=SevWA6HtPOtSi/kOYVJg5C/78bify74y96xHxN530FUXNZP0yZ4BAVnO6nob0Fw1TX fdZXG2NkZ47+3AtniOmC06urLYzd2aC/SXlkfM1TbRgWaYABSecNX00PYfZz0R6clq2J GrDQ+sdajooh0VLVltWX7yh12MFP5wLcxtngHP8aTd1hvDRx3S99JI38JqfPKirEyILv L2kZRkA3dnXEJ3L+Go6jbXH86YsfRNcQLmG6amJ4Dvqz+eQtcO9t4VJ755gcePkBOvUf rR7uzESr6DF/Du8AIwsXIdHSnIxl+BY5CADr4ghCaiUdFr7V7JyooCB4gKWVevpW1HEm MZZQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lk6T48pI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41079-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41079-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jr3-20020a0562142a8300b006819a5cf1a7si2950733qvb.568.2024.01.26.22.38.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 22:38:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41079-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lk6T48pI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41079-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41079-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0741E1C22969 for ; Sat, 27 Jan 2024 06:38:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB72E1D528; Sat, 27 Jan 2024 06:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lk6T48pI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AFF7801; Sat, 27 Jan 2024 06:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706337477; cv=none; b=lIdrfZiA6pq/hBfh4R7aeG75pnvCtOVANffrdBgukmi8ZTUxp14CQEzlC3pQsitUZmMxDIuGNKJd/kcIxeF7hm0v3IoeuCp7nRLXeZmUmfFVd0Cj3bbK+8O53IISf7qMBi08sfh2Ai46l3E0737th7uH+9v8YgolRhR6zAAq5JM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706337477; c=relaxed/simple; bh=eiun4me+83JhgNCDe4y9ORXCfAlPGIdgEeQXmo7Bor8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rn0qnARSeKpBH9PmyhQNLTxtloXSae7DhpUECHPgV8ahHathVpEEMX0swARXYyWcejfnCMvMt8by5QTCykBTWHUnylNydxbeV8g4AkuSm8keiWBVEGJ1zk30GftiBs3AYrUzDVZwp4JBh1oFrmJsJSNCTQhHoQlXxh3LidhdvRM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lk6T48pI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1289AC433F1; Sat, 27 Jan 2024 06:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706337476; bh=eiun4me+83JhgNCDe4y9ORXCfAlPGIdgEeQXmo7Bor8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lk6T48pIofWov6dE1nAMdxwOCZRx/5CPJ2kUK7+BYj3Bf166s7nQOu/NX+lNl1am5 knxc/Uc15XNMmNX+3WwpDOeqybdbEasK0tw0toixzLq8LS9CgrIUKBEvf3hQbvmOYg yakTAw5+8whCrlkaI0Wq7LLyBnSXaos3qGiT7d2E6NSv16g4SZavpxc4anc0ALNS+u 5z9s4G4HlzSOqDOKOhhOYlC0oiUU0NXf/EYYyr7om7E5BxNZqeKOw9IGRCf6r91OMu YIiFrZ0NDMCGpIEAlTXGEzDJVf9UVBpGqAQhpVJGEdClcqB/Q9hQ9xWH/PZ4SsB4hG 3PVqtbe7kxpnQ== Date: Fri, 26 Jan 2024 22:37:54 -0800 From: Eric Biggers To: xiubli@redhat.com Cc: linux-fscrypt@vger.kernel.org, tytso@mit.edu, jaegeuk@kernel.org, linux-kernel@vger.kernel.org, idryomov@gmail.com, ceph-devel@vger.kernel.org, jlayton@kernel.org, vshankar@redhat.com Subject: Re: [PATCH] fscrypt: to make sure the inode->i_blkbits is correctly set Message-ID: <20240127063754.GA11935@sol.localdomain> References: <20240125044826.1294268-1-xiubli@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240125044826.1294268-1-xiubli@redhat.com> On Thu, Jan 25, 2024 at 12:48:25PM +0800, xiubli@redhat.com wrote: > From: Xiubo Li > > The inode->i_blkbits should be already set before calling > fscrypt_get_encryption_info() and it will be used this to setup the > ci_data_unit_bits. > > Signed-off-by: Xiubo Li > --- > fs/crypto/keysetup.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c > index d71f7c799e79..909187e52bae 100644 > --- a/fs/crypto/keysetup.c > +++ b/fs/crypto/keysetup.c > @@ -702,6 +702,9 @@ int fscrypt_get_encryption_info(struct inode *inode, bool allow_unsupported) > /** > * fscrypt_prepare_new_inode() - prepare to create a new inode in a directory > * @dir: a possibly-encrypted directory > * @inode: the new inode. ->i_mode must be set already. > * ->i_ino doesn't need to be set yet. Maybe just change the above to "->i_mode and ->i_blkbits", instead of adding a separate paragraph? > * @encrypt_ret: (output) set to %true if the new inode will be encrypted > * > * If the directory is encrypted, set up its ->i_crypt_info in preparation for > * encrypting the name of the new file. Also, if the new inode will be > * encrypted, set up its ->i_crypt_info and set *encrypt_ret=true. > * > * This isn't %GFP_NOFS-safe, and therefore it should be called before starting > * any filesystem transaction to create the inode. For this reason, ->i_ino > * isn't required to be set yet, as the filesystem may not have set it yet. > * > * This doesn't persist the new inode's encryption context. That still needs to > * be done later by calling fscrypt_set_context(). > * > + * Please note that the inode->i_blkbits should be already set before calling > + * this and later it will be used to setup the ci_data_unit_bits. > + * > * Return: 0 on success, -ENOKEY if the encryption key is missing, or another > * -errno code > */ > @@ -717,6 +720,9 @@ int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode, > if (IS_ERR(policy)) > return PTR_ERR(policy); > > + if (WARN_ON_ONCE(inode->i_blkbits == 0)) > + return -EINVAL; > + Thanks, - Eric