runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Process.MainModule.FileName incorrect with kernel 5.0.0-27-generic (causing MSBuild to be broken)

Open qmfrederik opened this issue 7 years ago • 35 comments

See https://github.com/dotnet/core/issues/3312 and https://github.com/dotnet/core/issues/3309 .

There are various reports of Process.GetCurrentProcess().MainModule.FileName returning an incorrect value when running .NET Core inside a container on Ubuntu 19.04 using kernel 5.0.0-27-generic. Reverting back to kernel 5.0.0-25-generic fixes this issue.

The same issue also reproduces on the Azure variant of Ubuntu, with kernel version 5.0.0-1018.

The simplest steps to repro that I know of are in https://github.com/dotnet/core/issues/3309 .

qmfrederik avatar Sep 05 '19 19:09 qmfrederik

Opening an issue here as the MSBuild team believes this is not related to MSBuild itself. I don't have time to dig into this myself (I just reverted to the previous kernel) but thought I'd be good to have a corefx issue open for this.

qmfrederik avatar Sep 05 '19 19:09 qmfrederik

Interesting. Perhaps @tmds has thoughts about what we may be doing wrong here.

danmoseley avatar Sep 05 '19 19:09 danmoseley

We read this from the /proc/<pid>/maps file. Using kernel 5.0.0-27-generic on Ubuntu 18.04 in a container, every pathname is / instead of the mapped file path.

5.0.0-25-generic (working):

$ sudo docker run ubuntu cat /proc/1/maps
56324a3f5000-56324a3fd000 r-xp 00000000 fc:01 665673                     /bin/cat
56324a5fc000-56324a5fd000 r--p 00007000 fc:01 665673                     /bin/cat
56324a5fd000-56324a5fe000 rw-p 00008000 fc:01 665673                     /bin/cat
56324a8eb000-56324a90c000 rw-p 00000000 00:00 0                          [heap]
7f8ab5f91000-7f8ab6178000 r-xp 00000000 fc:01 666073                     /lib/x86_64-linux-gnu/libc-2.27.so
7f8ab6178000-7f8ab6378000 ---p 001e7000 fc:01 666073                     /lib/x86_64-linux-gnu/libc-2.27.so
7f8ab6378000-7f8ab637c000 r--p 001e7000 fc:01 666073                     /lib/x86_64-linux-gnu/libc-2.27.so
7f8ab637c000-7f8ab637e000 rw-p 001eb000 fc:01 666073                     /lib/x86_64-linux-gnu/libc-2.27.so
7f8ab637e000-7f8ab6382000 rw-p 00000000 00:00 0 
7f8ab6382000-7f8ab63a9000 r-xp 00000000 fc:01 666055                     /lib/x86_64-linux-gnu/ld-2.27.so
7f8ab6583000-7f8ab65a7000 rw-p 00000000 00:00 0 
7f8ab65a9000-7f8ab65aa000 r--p 00027000 fc:01 666055                     /lib/x86_64-linux-gnu/ld-2.27.so
7f8ab65aa000-7f8ab65ab000 rw-p 00028000 fc:01 666055                     /lib/x86_64-linux-gnu/ld-2.27.so
7f8ab65ab000-7f8ab65ac000 rw-p 00000000 00:00 0 
7ffc25954000-7ffc25975000 rw-p 00000000 00:00 0                          [stack]
7ffc259f1000-7ffc259f4000 r--p 00000000 00:00 0                          [vvar]
7ffc259f4000-7ffc259f5000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

5.0.0-27-generic (broken):

$ sudo docker run ubuntu cat /proc/1/maps
55de0e052000-55de0e05a000 r-xp 00000000 fc:01 665673                     /
55de0e259000-55de0e25a000 r--p 00007000 fc:01 665673                     /
55de0e25a000-55de0e25b000 rw-p 00008000 fc:01 665673                     /
55de0fcb3000-55de0fcd4000 rw-p 00000000 00:00 0                          [heap]
7f7a8d881000-7f7a8da68000 r-xp 00000000 fc:01 666073                     /
7f7a8da68000-7f7a8dc68000 ---p 001e7000 fc:01 666073                     /
7f7a8dc68000-7f7a8dc6c000 r--p 001e7000 fc:01 666073                     /
7f7a8dc6c000-7f7a8dc6e000 rw-p 001eb000 fc:01 666073                     /
7f7a8dc6e000-7f7a8dc72000 rw-p 00000000 00:00 0 
7f7a8dc72000-7f7a8dc99000 r-xp 00000000 fc:01 666055                     /
7f7a8de73000-7f7a8de97000 rw-p 00000000 00:00 0 
7f7a8de99000-7f7a8de9a000 r--p 00027000 fc:01 666055                     /
7f7a8de9a000-7f7a8de9b000 rw-p 00028000 fc:01 666055                     /
7f7a8de9b000-7f7a8de9c000 rw-p 00000000 00:00 0 
7ffc744bd000-7ffc744de000 rw-p 00000000 00:00 0                          [stack]
7ffc7452d000-7ffc74530000 r--p 00000000 00:00 0                          [vvar]
7ffc74530000-7ffc74531000 r-xp 00000000 00:00 0                          [vdso]

tmds avatar Sep 05 '19 20:09 tmds

@tmds, presumably then this is a Linux bug?

stephentoub avatar Sep 05 '19 20:09 stephentoub

if it is, then sdk and runtime containers should be updated accordingly to prevent any other duplicate issues.

olcayseker avatar Sep 05 '19 21:09 olcayseker

@MichaelSimons

danmoseley avatar Sep 05 '19 22:09 danmoseley

@tmds, presumably then this is a Linux bug?

Yes, I think so too, specific to the 5.0.0-27-generic on Ubuntu. I don't have issues on Fedora with 5.1.15 kernel.

tmds avatar Sep 06 '19 07:09 tmds

OK, I opened https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1843018 . I hope that's the right location to report Ubuntu kernel bugs. If anyone knows about a better way of contacting the Ubuntu team, let me know :).

qmfrederik avatar Sep 06 '19 08:09 qmfrederik

PS: There's a "Does this bug affect you?" link at the top of the page (green text, below the but title) that those who are interested can use to upvote this issue in Launchpad.

qmfrederik avatar Sep 06 '19 08:09 qmfrederik

I can confirm that, Linux host users should downgrade or upgrade kernel to build successfully. For me, i upgraded my Ubuntu host to kernel 5.2.12 and everything is fine now. There is nothing to do for sdk and runtime containers actually.

olcayseker avatar Sep 06 '19 15:09 olcayseker

I logged a Docker issue for this as well because they are involved - https://github.com/moby/moby/issues/39875

MichaelSimons avatar Sep 06 '19 16:09 MichaelSimons

@MichaelSimons can we close this issue now then?

danmoseley avatar Sep 06 '19 17:09 danmoseley

@danmosemsft, @MichaelSimons: Just so you know, I believe this is still an issue on Azure Ubuntu VMs.

mikeharder avatar Sep 06 '19 17:09 mikeharder

@MichaelSimons I imagine the only reason for us to have an issue at this point is if we need to adjust the kernel versions of any docker images we own, which would be better tracked in your repo.

danmoseley avatar Sep 09 '19 00:09 danmoseley

@danmosemsft - A Docker container has no kernel inside it; it just installed and started on the kernel which is used on the host. Because of this, I am not seeing a workaround that can be applied to our docker images. Are there any potential alternative implementations of Process.MainModule.FileName?

Users affected by this, please chime in on the respective issues https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1843018 and https://github.com/moby/moby/issues/39875.

MichaelSimons avatar Sep 09 '19 14:09 MichaelSimons

@MichaelSimons /proc/PID/exe should be a link to the executable of the current process.

qmfrederik avatar Sep 09 '19 15:09 qmfrederik

I just checked, this seems to work on the latest Ubuntu kernel:

vagrant@vagrant:~$ uname -r
5.0.0-27-generic
vagrant@vagrant:~$ sudo docker run ubuntu ls -l /proc/1/exe
lrwxrwxrwx 1 root root 0 Sep  9 15:59 /proc/1/exe -> /bin/ls

Perhaps Process.MainModule.FileName could use this as a fallback?

qmfrederik avatar Sep 09 '19 16:09 qmfrederik

Can someone more familiar with the Linux ecosystem please answer this: why would we invest in a workaround for a single kernel version that seems to have a significant, subsequently fixed bug in it? It takes time to do, would exist in the code indefinitely, and presumably would need back porting to several .NET Core releases to be useful.

Perhaps the Linux community will backport a fix to this kernel. Meanwhile I think the answer here if someone hits this is "that kernel has a serious bug. please use a different kernel version". Right?

danmoseley avatar Sep 09 '19 17:09 danmoseley

BTW historically changes to what we parse from the proc filesystem have had a bug tail because we've discovered edge cases, eg., behaviors varying by kernel version, or in a recent case, we were pulling the process name but it turned out it would not return more than 15 characters. So I'd rather not change what we do here.

danmoseley avatar Sep 09 '19 17:09 danmoseley

imho this should be fixed in the Ubuntu kernel, because the issue is unique to that kernel.

tmds avatar Sep 09 '19 18:09 tmds