Re: v2.6.28-rc1: readlink /proc/*/exe returns uninitialized datato userspace

From: Alexey Dobriyan
Date: Tue Nov 04 2008 - 05:31:21 EST


On Tue, Nov 04, 2008 at 01:07:57PM +0300, Alexey Dobriyan wrote:
> On Tue, Nov 04, 2008 at 01:00:50PM +0300, Alexey Dobriyan wrote:
> > On Tue, Nov 04, 2008 at 10:39:19AM +0100, Vegard Nossum wrote:
> > > # uname -a
> > > Linux ubuntu 2.6.28-rc2-next-20081031 #60 SMP Sat Nov 1 13:19:49 CET
> > > 2008 i686 GNU/Linux
> > > # prelink -mRf /sbin/udevd
> > > # ./a.out /proc/4764/exe
> > > warning: /proc/4764/exe: got return value 38, expected 11
> > > 2f7362696e2f756465766400fffffffffdfffffffffffff7ffffbfff202864656c6574656429
> > > /sbin/udevd (deleted)
> >
> > reproduced
>
> prelink does
>
> rename("/sbin/udevd.#prelink#.N6pvOJ", "/sbin/udevd")

OK, here is obvious (lame) reproducer, second readlink returns 32 while first
returns 18:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
int fd, fd1;
char buf[64], buf1[64], img[42000];
ssize_t len;

fd = open("/proc/self/exe", O_RDONLY);

readlink("/proc/self/exe", buf, sizeof(buf));
strcpy(buf1, buf);
strcat(buf1, ".xxx");
unlink(buf1);
fd1 = open(buf1, O_WRONLY|O_CREAT);
len = read(fd, img, sizeof(img));
close(fd);
write(fd1, img, len);
close(fd1);
rename(buf1, buf);

readlink("/proc/self/exe", buf, sizeof(buf));

return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/