2005-10-09 15:16:29

by Junichi Uekawa

[permalink] [raw]
Subject: Debian woody dpkg no longer works with recent linux kernel.


Hi,

dpkg in Debian woody (3.0) is broken by recent linux kernels;
due to the following command changing behavior (mmap of
zero-byte length):

addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);

These bugs are caused by mmap changing behavior;
it used to return NULL when given a length of 0.
However, it now returns -1, and gives back an errno=EINVAL.

This triggers problems in Debian installation.
The workaround is to give some content to the files:
/var/lib/status
/var/lib/available



$ uname -r
2.6.14-rc3dancer-gedb4a353
$ ./a.c b
a.c: In function 'main':
a.c:26: warning: comparison between pointer and integer
mmap: Invalid argument
$ ls -l b
-rw-r--r-- 1 dancer dancer 0 2005-10-09 22:29 b




$ uname -r
2.2.26
$ cat a.c
/*BINFMTC:
* */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>

int main(int argc, char **argv)
{
int fd;
void*addr;
if (argc < 2)
{
fprintf(stderr, "Filename required\n");
return 1;
}

if((fd=open(argv[1], O_RDONLY))==-1)
{
perror("open");
return 1;
}
addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);
if (addr==-1)
{
perror("mmap");
return 1;
}
printf ("%p\n", addr);
if(close(fd)==-1)
{
perror("close");
return 1;
}
return 0;
}
$ ./a.out b
(nil)






regards,
junichi


2005-10-09 22:33:35

by Scott James Remnant

[permalink] [raw]
Subject: Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

On Mon, 2005-10-10 at 00:16 +0900, Junichi Uekawa wrote:

> dpkg in Debian woody (3.0) is broken by recent linux kernels;
> due to the following command changing behavior (mmap of
> zero-byte length):
>
> addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);
>
> These bugs are caused by mmap changing behavior;
> it used to return NULL when given a length of 0.
> However, it now returns -1, and gives back an errno=EINVAL.
>
Indeed. This was the sole change in the 1.13.8 release.

Scott
--
Have you ever, ever felt like this?
Had strange things happen? Are you going round the twist?


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2005-10-10 01:07:24

by Junichi Uekawa

[permalink] [raw]
Subject: Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

Hi,

> > dpkg in Debian woody (3.0) is broken by recent linux kernels;
> > due to the following command changing behavior (mmap of
> > zero-byte length):
> >
> > addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);
> >
> > These bugs are caused by mmap changing behavior;
> > it used to return NULL when given a length of 0.
> > However, it now returns -1, and gives back an errno=EINVAL.
> >
> Indeed. This was the sole change in the 1.13.8 release.

Thanks, I didn't notice it was since 2.6.12. woody dpkg
was long broken. I've only seen more recent reports about this.

To fix this problem, will require update to
dpkg in woody; which might not be feasible.
We could drop support of woody chroots in etch.
It might be possible to add a workaround hack
in [c]debootstrap to trap mmap; or fill
status/available files before invoking dpkg.


I'm not quite sure why sarge manages to bootstrap despite
having a dpkg version (1.10.28) that shouldn't work.


regards,
junichi


Attachments:
(No filename) (189.00 B)

2005-10-11 14:24:14

by Junichi Uekawa

[permalink] [raw]
Subject: Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

Hi,

> > dpkg in Debian woody (3.0) is broken by recent linux kernels;
> > due to the following command changing behavior (mmap of
> > zero-byte length):
> >
> > addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);
> >
> > These bugs are caused by mmap changing behavior;
> > it used to return NULL when given a length of 0.
> > However, it now returns -1, and gives back an errno=EINVAL.
> >
> Indeed. This was the sole change in the 1.13.8 release.

1.13.8 is more recent than sarge; and I'm not quite sure
why sarge successfully installs, and woody fails.


I'm seeing several potential solutions.

0.
Backport dpkg change to woody and update woody
(maybe impossible due to Debian oldstable
update infrastructure)

1.
Modify [c]debootstrap to dump dummy data in
/var/lib/dpkg/{status,available}

2.
write a kernel patch to return 0 when mmap is
called with length=0

3.
Create a LD_PRELOAD or ptrace hack to return
0 when mmap is called with length=0


regards,
junichi

2005-10-11 15:14:57

by Junichi Uekawa

[permalink] [raw]
Subject: Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

Hi,

> > > dpkg in Debian woody (3.0) is broken by recent linux kernels;
> > > due to the following command changing behavior (mmap of
> > > zero-byte length):
> > >
> > > addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);
> > >
> > > These bugs are caused by mmap changing behavior;
> > > it used to return NULL when given a length of 0.
> > > However, it now returns -1, and gives back an errno=EINVAL.
> > >
> > Indeed. This was the sole change in the 1.13.8 release.
>
> 1.13.8 is more recent than sarge; and I'm not quite sure
> why sarge successfully installs, and woody fails.

Okay, I've verified that dpkg on sarge doesn't call mmap.
strace snippet:

umask(022) = 022
open("/var/lib/dpkg/status", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
close(3) = 0
open("/var/lib/dpkg/updates/", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
getdents64(3, /* 2 entries */, 4096) = 48
getdents64(3, /* 0 entries */, 4096) = 0
close(3) = 0
open("/var/lib/dpkg/available", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
close(3) = 0
exit_group(0, 0, 0x2aaaaadfc530, 0x2, 0x2aaaaae00640 <unfinished ... exit status


So, the impact is restricted on trying to run woody dpkg
on newer kernels.


regards,
junichi

2005-10-11 15:19:23

by Jon Masters

[permalink] [raw]
Subject: Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

On 10/11/05, Junichi Uekawa <[email protected]> wrote:

> > > dpkg in Debian woody (3.0) is broken by recent linux kernels;
> > > due to the following command changing behavior (mmap of
> > > zero-byte length):
> > >
> > > addr=mmap(NULL, 0, PROT_READ, MAP_SHARED, fd, 0);
> > >
> > > These bugs are caused by mmap changing behavior;
> > > it used to return NULL when given a length of 0.
> > > However, it now returns -1, and gives back an errno=EINVAL.

> I'm seeing several potential solutions.

> Backport dpkg change to woody and update woody
> (maybe impossible due to Debian oldstable
> update infrastructure)

That's probably the best fix.

> write a kernel patch to return 0 when mmap is
> called with length=0

Bad idea. I'm not the greatest authority on what the standards say
mmap should be doing, but this change seems logical and there's no
point in changing the kernel to revert the behaviour just for Debian
systems. It'd be another pointless Debian kernel patch :-)

> Create a LD_PRELOAD or ptrace hack to return
> 0 when mmap is called with length=0

Yummy. Better than the previous hack.

Jon.