For glibc-2.23, the CMSG_FIRSTHDR macro is defined as
#define CMSG_FIRSTHDR(mhdr) \
((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0)
In recv_cred_buffer(), pass_afd() and dispose_fds() the on-stack
ancillary data buffer is not necessarily aligned. The pointer is
cast to struct cmsghdr *, then dereferenced, resulting in undefined
behaviour due to the lack of alignment.
This patch asks the compiler to align the ancillary data buffers.
{
struct msghdr msg = {.msg_iov = NULL};
struct cmsghdr *cmsg;
- char control[255];
+ char control[255] __a_aligned(8);
int ret;
struct iovec iov;
*/
int recv_cred_buffer(int fd, char *buf, size_t size)
{
- char control[255];
+ char control[255] __a_aligned(8);
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov;
static int recv_afs_msg(int afs_socket, int *fd, uint32_t *code, uint32_t *data)
{
- char control[255], buf[8];
+ char control[255] __a_aligned(8), buf[8];
struct msghdr msg = {.msg_iov = NULL};
struct cmsghdr *cmsg;
struct iovec iov;