Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1539956rdb; Wed, 24 Jan 2024 20:50:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMfXRbCSIACeLiTFt+d1mVVVweBtXork+nlLAZM+vHpZJjdSgmLBbpSUAAd9gEXFZjS8W4 X-Received: by 2002:a17:907:a07:b0:a2f:17b0:a193 with SMTP id bb7-20020a1709070a0700b00a2f17b0a193mr821876ejc.14.1706158253841; Wed, 24 Jan 2024 20:50:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706158253; cv=pass; d=google.com; s=arc-20160816; b=g/DDkuf4MrUhQKFkY00rCcTtR+/enRQpRYCbyH09GKyfprH6jxYQXYtY6ulI6hlFul Ksd7UOQSVWDISdauwdYIzAmpuVBJV51KKAUsXCskixiDdYh4AhF6merAevUV2NsrqGrE eXIkOgYmEZojNziepPvqn87o4O/Vvu/QbBP6myggw3lL4dMX5FzToZA6b2RUtLMhlrJU 5GoowHzQIgL855JOEp4Kx/DWJaN8XEcVlmPVoSxGnO0yvFyiNuyLLqrBNS/+82EAzYg2 v+0VTtB146jFA7H+Dqxn0A9F3wYNEF6faM755twOI3SSR9YCgltxDV6EaZ5FciGvCrhv Q4Bw== 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=G6eOL3R6irziHLXuND4grbP4rQI+ngEPSNB6hi5Up78=; fh=8Yx9X70jBH/iUdWbmF/3dSXjyvAPZZj2oH55Z8GJSr4=; b=HeZWS1QHzIjxEHy05JleD8StyCN2aOlHtBXVRupMGTi+M/xYP2cwTtbhjOlZSVS7Km 4tUDN4Th2/9AJ4HCTgbF8l7NVdi0irzPFMsLZp74TAi95+5JuZfw4zLzEZWaq3xo8jki f85A1tVwmHKs8Kn8GrssmWwAzRiLeVdZIC1mpk8v7C1z661cRKwbGJaIT5y3DkFPR3D0 tucx38VOdfTXBdXWYC9ETOxGbm1nHS6N4hYYkEhB6BO43xIyXMKrCKdq4QMd/RPWkBcr 6qB6Rw+FjSQiqQg3sqQF0XNEESAqDXpX9Ci8ocHT9lN3yhw8HRQPsQGtk9JjscwlCpGT HELQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G+IdD3WA; 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-37956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b8-20020a17090691c800b00a3124e4fda8si549826ejx.942.2024.01.24.20.50.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 20:50:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G+IdD3WA; 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-37956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37956-linux.lists.archive=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 9A2DE1F24687 for ; Thu, 25 Jan 2024 04:50:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E4A78493; Thu, 25 Jan 2024 04:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G+IdD3WA" 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 0C25E79C6 for ; Thu, 25 Jan 2024 04:50:39 +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=1706158242; cv=none; b=UpHpXj75FvTTjwdK9ZqN4wIwTCXTnNVcOWs4XvjMKF4VUDCO/gzTnbNSBB2yCXMT4XjNMycENPOgU0WWV7jleAGoY0l6bDTGi+6QkGnBdaOEF6pWlx/u8N1eDt6GraxEpcpyC35PUyww5U+K70kPm7/chNwD+yCvUoCJ4CNLmWU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706158242; c=relaxed/simple; bh=2RWN9M36qX+9GZm4Tq3aYzHlPiLa+w1ufmGXtNpU1A8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Cw9tpv5K5jqctLJS90EEWqColovUXSDdb7W792KwrhrVyFwkaEsY+NKCZF7PYOpNaD2yls+XEHaRPv8USu4Z/t1OECCH3U1KefuP175THHUsbsNn51vgH/aqHc2tbBGZ2HhK0hbvQ/2GP2sJAiugT15Revro8GGIfoGc5XkC8qM= 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=G+IdD3WA; 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=1706158239; 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=G+IdD3WA1yrcgdJsB03bB2s9bBpjEc2RknbD+FhqNMFQKDz1jDgarHApdG25E96/9w5tcp wWL9fZR27K1doTps08offnl9evngyVtPKog7XmsJ+FjDSGwNJwt153HdIWEjJv2Dxlpqee E4ad0dyCfpu/ptIf5CbMaFjvg8Folmw= 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; -- 2.43.0