Issues of 64-bit code in real applications: and what about Linux?

11.10.2010 Evgeniy Ryzhkov

While telling programmers about 64-bit issues they may encounter when porting their programs, I often hear reproaches: "Yes, surely - such is your Windows... How good it is that Linux has had no problems with 64-bit code for a long time!".

"It is not so, my inquisitive readers". Today's post is about a 64-bit error in the Linux kernel. A wonderful site with bug tracking system by the kernel's developers contains the description of bug 16603 (send of data > 4 GB fails on 64 bit systems). The issue is simple: "Send of data using the Linux-function send() leads to an error if the data's size is too large". This is how the function looks in glibc:

ssize_t send(int sockfd, const void *buf, size_t len, int flags);

Everything is correct and the size is passed as a memsize-type size_t. But this argument is saved in the msgheader structure and after that there are the following lines inside the tcp_sendmsg function:

while (--iovlen >= 0) {
                int seglen = iov->iov_len;
                unsigned char __user *from = iov->iov_base;

Here, the length is saved in int and it is certainly a bad thing. That is, if you send a block of 5 Gbytes using send(), only 1 Gbyte will be sent while sending a 4-Gbyte block will have no result (due to truncation to zero).

Of course, the workaround is clear - we should specify length not larger than 0x8000000, but it is an error and of course we should fix it.

Yes, by the way, it is not a sample from the nineties - the bug was discovered in August, 2010, and refers to the kernel of version 2.5. And it is still (October 11, 2010) not fixed. And you tell me that Linux does not have 64-bit issues...