From patchwork Thu Feb 1 00:35: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: 195107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp119447dyc; Wed, 31 Jan 2024 16:38:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHa8072Ybee9tr2+A3mqTuAfOqt4R4GaVgJNBtEebA+ovE9cfqlmNVHz+96d9DLpoVh6JrT X-Received: by 2002:a17:906:4f0a:b0:a35:43d8:a297 with SMTP id t10-20020a1709064f0a00b00a3543d8a297mr2329152eju.0.1706747918599; Wed, 31 Jan 2024 16:38:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706747918; cv=pass; d=google.com; s=arc-20160816; b=suFX3ws0A8O/ceAo/wy/SL/ysLjCfaGEy3ULdMMCzAJXQmyPsuI0paMyGb3uNP0+9u dTwW1myc8I+XyH1Ca3RX3RNhvi7EFqE6Dv7ThJNvHck+L1mt9E76K+Tt+vXwXR2OaYx8 NY013f2WFIqWkKW1qM+ZZX3BhMh3lpsIJGb/Gao92IcQooRb8UZx31o4pVXSZRTnTTVq yMgWD1QKUVGqF70Wn0IGS6LoepGm32iuJjBsFn0H/fKScCY/iU+lqTzRkPbBMNxDI/O5 7McyPLmVlnp2WB6c+28c4ZXEhZetJnxMv5Tsb78Xdasou7EPcJ+QXrtU0i8wURYDT9ol 8law== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ah1RKuhRRRnaXJKeyFjE6ASX3Aql4IiSaABAAELIE4M=; fh=eB6yDtc4veUlF9mFHvNU8uokuKMzpN7QlxX/Gw/R3R0=; b=naLU0LM4dYLM5ywz/VCJJ+UtbVloVsaEqkHSt2eA/LXDD4lU9vE5r2SCUwyA04gkY5 Bm8WjqbIyZSGm0hpH9uNrfZbAKaNmqvqqX5Wlkd5UqG/GY2wNZP+HSX3DOtUqQzyY+3v 91EvgteAW454HpxDvRDGhkdnlaIbbcp8K/W2GU2Bp4O8mIJ183GlOSo4kDzTI1ReuRIB 4jD1WEoF4QX7PCUrNXt2D75vQhRW1rIlaK1kBM5O2KhIS0IQJ1PxWIt67hZr5vPniems T6yjoqXPCZq9eigv3+R71oexmkwDg6Fh0AoYeaxk0zW4crGbraQH7TthCRTxQqEuBLjj bFYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PZXNDsk9; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47438-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47438-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCVtZmRX4vev0BaxdsTOK6QNdT/VHcCCaV1Oj4jkNYpa1gBGRzS2enmwVz54TAMQdyAx1nQLrwYkgo5t1U43KY1YGvQtfw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a24-20020a1709066d5800b00a35a5768abasi3844158ejt.998.2024.01.31.16.38.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:38:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47438-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PZXNDsk9; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47438-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47438-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 867021F29156 for ; Thu, 1 Feb 2024 00:38:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 837B03FE1; Thu, 1 Feb 2024 00:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PZXNDsk9" 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 510B41FC4 for ; Thu, 1 Feb 2024 00:37:52 +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=1706747873; cv=none; b=Eomv+WuZYLZOehQtp/gNa8yLv8APXFdoxt7X2XASj483jUc06HCxgnHrK30Bt39JMtlOIljfYldNF6Ar8Hy6+7HJELGVLUkjLW5PhTLn2KNkNzP0HNAIQnbvOkRvsjv9qKkPWTN/Os2SkmvProruDH6R0ef9IPg7BexUj+XCyJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706747873; c=relaxed/simple; bh=qr8rACMNs5RIY8f9kv6asHpnLhXEAXtdGkLGoE0MlO4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=G6l7tcsldaizd5/mVf5vGPOP92dJhzrPyeCiPmD422sLSl6/uqJNYo6O21QcFk9f7/XpwrseVlCYyFTVD1iyClqhq76r1fxLg3A5ESIcQbs+dR5fldPvbaLRbpP0pdVkDMcj4/6dn8EyjTfIoUD4t3M6rSW6XkwkOfXgmhuSBVk= 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=PZXNDsk9; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706747871; 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=ah1RKuhRRRnaXJKeyFjE6ASX3Aql4IiSaABAAELIE4M=; b=PZXNDsk9+1Bu35dZDS550PLN14viR1ntCFnPMAwKT5URh9XW2C7ncCqSSPIWJ88M3HHwFd ZeRmWpXeKe1nKhW3FdQBheBye4w/9R1aTai/O7e9OiVfEmGf+wBJpRd/QOTST4Wmmv1wpl tzwV59TVR9a2PC02YU+dnyqEiXjXDKY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-Yrwu-v3rPWCE82p2J6UpYg-1; Wed, 31 Jan 2024 19:37:47 -0500 X-MC-Unique: Yrwu-v3rPWCE82p2J6UpYg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 3FED138005CC; Thu, 1 Feb 2024 00:37:47 +0000 (UTC) Received: from li-a71a4dcc-35d1-11b2-a85c-951838863c8d.ibm.com.com (unknown [10.72.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1874C1C060AF; Thu, 1 Feb 2024 00:37:41 +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, mchangir@redhat.com, Xiubo Li Subject: [PATCH v2] fscrypt: to make sure the inode->i_blkbits is correctly set Date: Thu, 1 Feb 2024 08:35:25 +0800 Message-ID: <20240201003525.1788594-1-xiubli@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789036603937895327 X-GMAIL-MSGID: 1789654905338837403 From: Xiubo Li The inode->i_blkbits should be already set before calling fscrypt_get_encryption_info() and it will use this to setup the ci_data_unit_bits later. URL: https://tracker.ceph.com/issues/64035 Signed-off-by: Xiubo Li --- V2: - Fixed the comments suggested by Eric, thanks. fs/crypto/keysetup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c index d71f7c799e79..9a0a40c81bf2 100644 --- a/fs/crypto/keysetup.c +++ b/fs/crypto/keysetup.c @@ -687,7 +687,7 @@ 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. + * @inode: the new inode. ->i_mode and ->i_blkbits must be set already. * ->i_ino doesn't need to be set yet. * @encrypt_ret: (output) set to %true if the new inode will be encrypted * @@ -717,6 +717,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;