]> git.hungrycats.org Git - bees/commitdiff
lib: fix btrfs_data_container pointer casts for 32-bit userspace on 64-bit kernels
authorZygo Blaxell <bees@furryterror.org>
Thu, 18 Apr 2024 03:07:41 +0000 (23:07 -0400)
committerZygo Blaxell <bees@furryterror.org>
Thu, 18 Apr 2024 03:07:41 +0000 (23:07 -0400)
Apparently reinterpret_cast<uint64_t> sign-extends 32-bit pointers.
This is OK when running on a 32-bit kernel that will truncate the pointer
to 32 bits, but when running on a 64-bit kernel, the extra bits are
interpreted as part of the (now very invalid) address.

Use <uintptr_t> instead, which is unsigned, integer, and the same word
size as the arch's pointer type.  Ordinary numeric conversion can take
it from there, filling the rest of the word with zeros.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
lib/fs.cc

index 4327c289ec8ffe64da78d5443f5b69fe7e913c4a..86bfba588b86cca8ad5ce04305f0f4816b3fb3f9 100644 (file)
--- a/lib/fs.cc
+++ b/lib/fs.cc
@@ -333,7 +333,7 @@ namespace crucible {
                btrfs_ioctl_logical_ino_args args = (btrfs_ioctl_logical_ino_args) {
                        .logical = m_logical,
                        .size = m_container_size,
-                       .inodes = reinterpret_cast<uint64_t>(m_container.prepare(m_container_size)),
+                       .inodes = reinterpret_cast<uintptr_t>(m_container.prepare(m_container_size)),
                };
                // We are still supporting building with old headers that don't have .flags yet
                *(&args.reserved[0] + 3) = m_flags;
@@ -416,7 +416,7 @@ namespace crucible {
        {
                btrfs_ioctl_ino_path_args *p = static_cast<btrfs_ioctl_ino_path_args *>(this);
                BtrfsDataContainer container(m_container_size);
-               fspath = reinterpret_cast<uint64_t>(container.prepare(m_container_size));
+               fspath = reinterpret_cast<uintptr_t>(container.prepare(m_container_size));
                size = container.get_size();
 
                m_paths.clear();