[Devel] [PATCH hci-8.1] fs/fuse/kio: do not panic on unaligned memory access in cs accel

Alexey Kuznetsov kuznet at virtuozzo.com
Mon Nov 30 17:57:17 MSK 2026


Actually, this assertion was deliberate and served its purpose.
We were not supposed to arrive at this place ever. Nevertheless,
new kernels have allowed O_DIRECT access to tmpfs
(e88e0d366f9c "tmpfs: trivial support for direct IO"), which does
not imply any memory alignment constraints. Our tests really use
tmpfs.

Notes:

- vstorage deliberately does not check memory alignment anywhere.
  The fact that linux fs used to reject unaligned direct io is considered
  as a kernel flaw, which is going to be fixed one day, so that we do not
  pollute our code with such checks. Cf. #VSTOR-53260 where
  the investigation has been undertaken
- alignment check in decrypt protects deficient algorithm
  in decrypt_data(), which is not able to handle a 512-byte crypto sector
  split over 2 pages. We could repair this instead of rejection,
  but it would complicate code significantly, and
  until this is required in production we do not want this.
- it is safe to fail any operation in cs accel with an error:
  any error condition causes fallback to slow path and
  as long as the condition is truly exceptional, it is all right.

Fixes: 5acc64b761cd ("fuse: implement fast access to encrypted CSes")
https://virtuozzo.atlassian.net/browse/VSTOR-157924

Affects: #VSTOR-157924

Signed-off-by: Alexey Kuznetsov <kuznet at virtuozzo.com>

Feature: vStorage
---
 fs/fuse/kio/pcs/pcs_cs_accel.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/kio/pcs/pcs_cs_accel.c b/fs/fuse/kio/pcs/pcs_cs_accel.c
index bc11f47352db..c8bdc606c63b 100644
--- a/fs/fuse/kio/pcs/pcs_cs_accel.c
+++ b/fs/fuse/kio/pcs/pcs_cs_accel.c
@@ -326,7 +326,15 @@ static int decrypt_data(struct pcs_int_request * ireq,  struct crypto_sync_skcip
 
 		len = iov_iter_get_pages2(it, &page, size - pos, 1, &offset);
 		BUG_ON(len <= 0);
-		BUG_ON(len & 511);
+		if (unlikely(len & 511)) {
+			put_page(page);
+			FUSE_KTRACE(ireq->cc->fc,
+				    "Unaligned memory, ireq:%px : %llu:%u+%u",
+				    ireq, (unsigned long long)ireq->iochunk.chunk,
+				    (unsigned int)ireq->iochunk.offset,
+				    (unsigned int)ireq->iochunk.size);
+			return -EINVAL;
+		}
 
 		if (is_ctr) {
 			for (; len > 0; len -= 512) {
-- 
2.47.1



More information about the Devel mailing list