]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: Assert at build time the assumptions we make about the CMSG header.
authorDavid S. Miller <davem@davemloft.net>
Wed, 4 Jan 2017 18:24:19 +0000 (13:24 -0500)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Jan 2017 18:24:19 +0000 (13:24 -0500)
It must always be the case that CMSG_ALIGN(sizeof(hdr)) == sizeof(hdr).

Otherwise there are missing adjustments in the various calculations
that parse and build these things.

Signed-off-by: David S. Miller <davem@davemloft.net>
net/compat.c
net/socket.c

index 4e27dd1cd3a66ee03ab81c00f834c171f2729f86..ba3ac722714dfda35aa766592a703a51caac80f5 100644 (file)
@@ -130,6 +130,9 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
        __kernel_size_t kcmlen, tmp;
        int err = -EFAULT;
 
+       BUILD_BUG_ON(sizeof(struct compat_cmsghdr) !=
+                    CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)));
+
        kcmlen = 0;
        kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
        ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
index 8487bf136e5c4f54801777c4ef0f4e51b765cd62..5f3b5a2c4f376537d9468becf103760458cd49f6 100644 (file)
@@ -1948,6 +1948,8 @@ static int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg,
                ctl_buf = msg_sys->msg_control;
                ctl_len = msg_sys->msg_controllen;
        } else if (ctl_len) {
+               BUILD_BUG_ON(sizeof(struct cmsghdr) !=
+                            CMSG_ALIGN(sizeof(struct cmsghdr)));
                if (ctl_len > sizeof(ctl)) {
                        ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL);
                        if (ctl_buf == NULL)