Skip to contentSkip to conversation

Debian woody dpkg no longer works with recent linux kernel.

DISCUSSION Junichi Uekawa 3 participants 6 messages Oct 9, 2005 – Oct 11, 2005

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

Quoted 10 lines · Junichi Uekawa

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

Signature · 2 lines
Have you ever, ever felt like this?
Had strange things happen?  Are you going round the twist?
#2 lore raw

Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

Hi,

Quoted 11 lines
Quoted 10 lines

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

#3 lore raw

Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

In reply to Scott James Remnant

Hi,

Quoted 11 lines
Quoted 10 lines

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

#4 lore raw

Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

Hi,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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);
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

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

#5 lore raw

Re: Bug#322309: Debian woody dpkg no longer works with recent linux kernel.

In reply to Junichi Uekawa
Quoted 10 lines · Junichi Uekawa
Quoted 9 lines
Quoted 9 lines

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.

Quoted 5 lines

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.

Quoted 2 lines

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 :-)

Quoted 2 lines

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

Yummy. Better than the previous hack.

Jon.