Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Potential UB: No static alignment check in IoUringSQE::SetData(const T &data) #1

Open
jbmln opened this issue Nov 23, 2023 · 0 comments

Comments

@jbmln
Copy link

jbmln commented Nov 23, 2023

Expected Behavior

io_uring_cpp::IoUringSQE::SetData(const T &data) allows caller to pass any properly sized and trivially constructible type to be copied to the user data portion of an IO_URING SQE.

Actual Behavior

Potentially leads to UB where T is <= 8 bytes but T's alignment is more than alignment of uint64_t / 8 bytes.

The issue would be compiler and possibly process dependent.

Steps to Reproduce the Problem

1.Code leading to potential UB:

struct alignas(16) MyStruct {
  int a;
  char b;
};

int main() {
  MyStruct myData;
  myData.a = 10;
  myData.b = 'X';

  //code to initialize ring, sqe etc.

  // Call liburing_cpp's SetData()
  io_uring_cpp::IoUringSQE::SetData(myData); // Potential UB!

  return 0;
}

Specifications

  • Version: Main Branch
  • Platform: Linux / n.a

Potential Fix:

Add this static assert to SetData(const T &data) in file ./include/IoUringSQE.h:

static_assert(alignof(T) <= alignof(uint64_t), "T must have same alignment as uint64_t");
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant