[parisc-linux-cvs] linux-2.5 tausq
Randolph Chung
Randolph Chung <randolph@tausq.org>
Sun, 30 Mar 2003 18:26:04 -0800
> 2.5.66-pa3
>
> Fixes recvmsg() so that it will correctly pass the CMSG_COMPAT flag to lower
> layers, and will not try to fixup the control data multiple times (because the
> underlying functions have already done it)
>
> Submitted upstream to sfr as well.
Because more is not always better.... :-)
Index: net/compat.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/compat.c,v
retrieving revision 1.4
diff -u -p -r1.4 compat.c
--- net/compat.c 30 Mar 2003 02:48:14 -0000 1.4
+++ net/compat.c 31 Mar 2003 02:17:20 -0000
@@ -296,103 +296,12 @@ void scm_detach_fds_compat(struct msghdr
__scm_destroy(scm);
}
-/* In these cases we (currently) can just copy to data over verbatim
- * because all CMSGs created by the kernel have well defined types which
- * have the same layout in both the 32-bit and 64-bit API. One must add
- * some special cased conversions here if we start sending control messages
- * with incompatible types.
- *
- * SCM_RIGHTS and SCM_CREDENTIALS are done by hand in recvmsg_compat right after
- * we do our work. The remaining cases are:
- *
- * SOL_IP IP_PKTINFO struct in_pktinfo 32-bit clean
- * IP_TTL int 32-bit clean
- * IP_TOS __u8 32-bit clean
- * IP_RECVOPTS variable length 32-bit clean
- * IP_RETOPTS variable length 32-bit clean
- * (these last two are clean because the types are defined
- * by the IPv4 protocol)
- * IP_RECVERR struct sock_extended_err +
- * struct sockaddr_in 32-bit clean
- * SOL_IPV6 IPV6_RECVERR struct sock_extended_err +
- * struct sockaddr_in6 32-bit clean
- * IPV6_PKTINFO struct in6_pktinfo 32-bit clean
- * IPV6_HOPLIMIT int 32-bit clean
- * IPV6_FLOWINFO u32 32-bit clean
- * IPV6_HOPOPTS ipv6 hop exthdr 32-bit clean
- * IPV6_DSTOPTS ipv6 dst exthdr(s) 32-bit clean
- * IPV6_RTHDR ipv6 routing exthdr 32-bit clean
- * IPV6_AUTHHDR ipv6 auth exthdr 32-bit clean
- */
-static void cmsg_compat_recvmsg_fixup(struct msghdr *kmsg, unsigned long orig_cmsg_uptr)
-{
- unsigned char *workbuf, *wp;
- unsigned long bufsz, space_avail;
- struct cmsghdr *ucmsg;
-
- bufsz = ((unsigned long)kmsg->msg_control) - orig_cmsg_uptr;
- space_avail = kmsg->msg_controllen + bufsz;
- wp = workbuf = kmalloc(bufsz, GFP_KERNEL);
- if(workbuf == NULL)
- goto fail;
-
- /* To make this more sane we assume the kernel sends back properly
- * formatted control messages. Because of how the kernel will truncate
- * the cmsg_len for MSG_TRUNC cases, we need not check that case either.
- */
- ucmsg = (struct cmsghdr *) orig_cmsg_uptr;
- while(((unsigned long)ucmsg) <=
- (((unsigned long)kmsg->msg_control) - sizeof(struct cmsghdr))) {
- struct compat_cmsghdr *kcmsg_compat = (struct compat_cmsghdr *) wp;
- int clen64, clen32;
-
- /* UCMSG is the 64-bit format CMSG entry in user-space.
- * KCMSG_COMPAT is within the kernel space temporary buffer
- * we use to convert into a 32-bit style CMSG.
- */
- __get_user(kcmsg_compat->cmsg_len, &ucmsg->cmsg_len);
- __get_user(kcmsg_compat->cmsg_level, &ucmsg->cmsg_level);
- __get_user(kcmsg_compat->cmsg_type, &ucmsg->cmsg_type);
-
- clen64 = kcmsg_compat->cmsg_len;
- copy_from_user(CMSG_COMPAT_DATA(kcmsg_compat), CMSG_DATA(ucmsg),
- clen64 - CMSG_ALIGN(sizeof(*ucmsg)));
- clen32 = ((clen64 - CMSG_ALIGN(sizeof(*ucmsg))) +
- CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)));
- kcmsg_compat->cmsg_len = clen32;
-
- ucmsg = (struct cmsghdr *) (((char *)ucmsg) + CMSG_ALIGN(clen64));
- wp = (((char *)kcmsg_compat) + CMSG_COMPAT_ALIGN(clen32));
- }
-
- /* Copy back fixed up data, and adjust pointers. */
- bufsz = (wp - workbuf);
- copy_to_user((void *)orig_cmsg_uptr, workbuf, bufsz);
-
- kmsg->msg_control = (struct cmsghdr *)
- (((char *)orig_cmsg_uptr) + bufsz);
- kmsg->msg_controllen = space_avail - bufsz;
-
- kfree(workbuf);
- return;
-
-fail:
- /* If we leave the 64-bit format CMSG chunks in there,
- * the application could get confused and crash. So to
- * ensure greater recovery, we report no CMSGs.
- */
- kmsg->msg_controllen += bufsz;
- kmsg->msg_control = (void *) orig_cmsg_uptr;
-}
-
int put_compat_msg_controllen(struct msghdr *msg_sys,
struct compat_msghdr *msg_compat, unsigned long cmsg_ptr)
{
unsigned long ucmsg_ptr;
compat_size_t uclen;
- if ((unsigned long)msg_sys->msg_control != cmsg_ptr)
- cmsg_compat_recvmsg_fixup(msg_sys, cmsg_ptr);
ucmsg_ptr = ((unsigned long)msg_sys->msg_control);
uclen = (compat_size_t) (ucmsg_ptr - cmsg_ptr);
return __put_user(uclen, &msg_compat->msg_controllen);
Index: net/socket.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/socket.c,v
retrieving revision 1.14
diff -u -p -r1.14 socket.c
--- net/socket.c 25 Mar 2003 03:20:26 -0000 1.14
+++ net/socket.c 31 Mar 2003 02:17:20 -0000
@@ -1692,6 +1692,8 @@ asmlinkage long sys_recvmsg(int fd, stru
cmsg_ptr = (unsigned long)msg_sys.msg_control;
msg_sys.msg_flags = 0;
+ if (MSG_CMSG_COMPAT & flags)
+ msg_sys.msg_flags = MSG_CMSG_COMPAT;
if (sock->file->f_flags & O_NONBLOCK)
flags |= MSG_DONTWAIT;
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/