From patchwork Thu Jan 25 04:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 766878 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2B45179C3 for ; Thu, 25 Jan 2024 04:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706158240; cv=none; b=loeDpOLmL37D4yuWOlM9j6dveJwlf4N6BD93n7jPRyceGQtrYULDEu9qmtkuxvJBLu4xYfIBtCdlCv2eO72qyle7Hm1L4iSV+9kJLZKKbkxdrh/BePWtV+Nvn7jVGgwD55UWuboKAh8/gwnqwTyCi4fjd74oTDqGMOwRP8avp5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706158240; c=relaxed/simple; bh=2RWN9M36qX+9GZm4Tq3aYzHlPiLa+w1ufmGXtNpU1A8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=I+ji7Sw9Ybzo89eZx9ykHEXoBecmMWwoYH6creRbd64DKkwcltCSyDu23ST/+gdB/H3szKxlbHXDhugXfz/lUClAggqj2jTkYEr0NcWxWF0SWeWMP6u++Yvv+E2F27QE+MjHru4qahg4PUI8qAA0sVq4KztqTmtfjJFgeylWyEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TbYH6oks; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TbYH6oks" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706158238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=G6eOL3R6irziHLXuND4grbP4rQI+ngEPSNB6hi5Up78=; b=TbYH6oksI8e8MqAQHTwjXPHY8gPMAdb+RffWm1q21UDcwXbi8VtDXJniiHZihZQHUr8709 jYZkMrigiFmXWWNgSBq1FYkXce/EUCUcsWurlxChqalmdNVLA9BlAuKIhq5NqRCLeGmhQ8 ZyiKzfk6xz7kZP+JKZcOeYYk3Itfp7o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-206-7r5lIxgdMr2uRCoLCWVw7g-1; Wed, 24 Jan 2024 23:50:34 -0500 X-MC-Unique: 7r5lIxgdMr2uRCoLCWVw7g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 090658828C3; Thu, 25 Jan 2024 04:50:34 +0000 (UTC) Received: from li-a71a4dcc-35d1-11b2-a85c-951838863c8d.ibm.com.com (unknown [10.72.112.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CAE93C2E; Thu, 25 Jan 2024 04:50:29 +0000 (UTC) From: xiubli@redhat.com To: linux-fscrypt@vger.kernel.org Cc: ebiggers@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, Xiubo Li Subject: [PATCH] fscrypt: to make sure the inode->i_blkbits is correctly set Date: Thu, 25 Jan 2024 12:48:25 +0800 Message-ID: <20240125044826.1294268-1-xiubli@redhat.com> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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) * 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; + if (WARN_ON_ONCE(inode->i_mode == 0)) return -EINVAL;