#940533 qemu-user-static: MasterCard in /proc/self/stat emulation causes sudo(8) to fail

Package:
src:qemu
Source:
src:qemu
Submitter:
Thorsten Glaser
Date:
2025-08-13 09:09:02 UTC
Severity:
normal
Tags:
#940533#5
Date:
2019-09-16 22:33:26 UTC
From:
To:
linux-user/syscall.c:open_self_stat() fills the emulated
/proc/self/stat with a lot of 0s, whereas sudo reads the
tty from it, making it fail in chroots using qemu-user-static.

Workaround: use sudo -S

#940533#12
Date:
2019-09-16 23:20:12 UTC
From:
To:
The weird thing is that /proc/$$/stat a.k.a. $(readlink /proc/self)/stat
is correct…

It ought to be still fixed ☻

bye,
//mirabilos

#940533#17
Date:
2021-02-24 20:24:18 UTC
From:
To:
Hi Thorsten,

So the contents of /proc/self/stat has the correct number of fields, but
all zeroes?

How exactly does sudo fail? Is this worth reporting upstream?

Greetings
Marc, with the new sudo maintainer hat on

#940533#20
Date:
2021-02-24 20:24:18 UTC
From:
To:
Hi Thorsten,

So the contents of /proc/self/stat has the correct number of fields, but
all zeroes?

How exactly does sudo fail? Is this worth reporting upstream?

Greetings
Marc, with the new sudo maintainer hat on

#940533#25
Date:
2021-02-25 10:56:04 UTC
From:
To:
This bug is still pertinent. I’ve reproduced it locally right now as:

 # mount an RPi Debian buster image (pristine Debian/arm64, not Raspian)
$ sudo losetup /dev/loop3 ~/tmp/rpi.img
$ sudo kpartx -a -v /dev/loop3
$ sudo mount /dev/mapper/loop3p2 /mnt
 # mount extra filesystems
$ mpt=/mnt
$ sudo mount -t tmpfs swap "$mpt/dev/shm"
$ sudo mount -t proc  proc "$mpt/proc"
$ sudo mount -t tmpfs swap "$mpt/tmp"
$ sudo mount --bind /dev/pts "$mpt/dev/pts"
 # go into the chroot
$ tty
/dev/pts/2
$ sudo chroot /mnt su -
chroot# tty
/dev/pts/2
chroot# su - test
chroot$ tty
/dev/pts/2
chroot$ sudo id
sudo: no tty present and no askpass program specified
chroot$ sudo -S id
[sudo] password for test: ***
uid=0(root) gid=0(root) groups=0(root)


zugschlus dixit:

chroot$ /bin/cat /proc/self/stat
8903 (cat) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1099013312 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
$ /bin/cat /proc/self/stat
8909 (cat) R 8173 8909 8173 34818 8909 4194304 83 0 0 0 0 0 0 0 20 0 1 0 2027189139 2854912 114 18446744073709551615 4198400 4215449 4292526912 0 0 0 0 0 0 0 0 0 17 2 0 0 0 0 0 4235008 4235844 8646656 4292528960 4292528985 4292528985 4292530159 0
chroot# /bin/cat /proc/self/stat
8932 (cat) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1099013472 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

So, yes. But watch this:

 # avoid use of mksh changing something
chroot$ /bin/dash
chdash$ echo $$
8974
chdash$ cat /proc/8974/stat
8974 (dash) S 8942 8974 8173 34818 8980 4194304 666 0 1 0 7 2 0 0 20 0 2 0 2027195261 64946176 2611 18446744073709551615 134516736 138848748 4287049936 0 0 0 0 2637828 2004991739 0 0 0 17 3 0 0 5 0 0 143243668 144636888 186900480 4287053448 4287053510 4287053510 4287053806 0

Erm… but watch THIS:

chdash$ cat /proc/9045/stat
9045 (cat) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1099013296 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

(9045 was me lucky-guessing the pid the cat binary became)

#940533#30
Date:
2021-02-25 10:58:45 UTC
From:
To:
Marc Haber dixit:

Basically sudo does not ask for the password because it cannot
find its tty. I’ve mailed to the bugreport with you in X-Debbugs-CC
(hope it’ll arrive, if not, check the BTS in a few minutes) with
more information.

I’d like to have this fixed in qemu, but given that probably won’t
make it into bullseye, if the issue can be worked around in sudo
(by using a workable way to determine the tty) for bullseye, that
might be useful.

Thanks,
//mirabilos

#940533#45
Date:
2022-03-18 14:44:28 UTC
From:
To:
We believe that the bug you reported is fixed in the latest version of
sudo, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 940533@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Marc Haber <mh+debian-packages@zugschlus.de> (supplier of updated sudo package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)
Format: 1.8
Date: Fri, 18 Mar 2022 14:31:30 +0100
Source: sudo
Architecture: source
Version: 1.9.10-1
Distribution: experimental
Urgency: medium
Maintainer: Sudo Maintainers <sudo@packages.debian.org>
Changed-By: Marc Haber <mh+debian-packages@zugschlus.de>
Closes: 793660 940533 945366 976307 1004730 1004909 1006273
Changes:
 sudo (1.9.10-1) experimental; urgency=medium
 .
   * new upstream version
     * unverified upstream changelog
     * implement workaround if /proc/self/stat is invalid.
       (Closes: #940533)
     * Fix compilation problem on kFreeBSD. (Closes: #1004909)
       (different fix than the Debian patch, disable Debian patch)
     * get rid of e-mails "problem with defaults entries" in sss
       configurations. (Closes: #793660)
     * regular expression support for sudoers. (Closes: #945366)
     * handle /proc/self/fd in qemu.
     * Apply Upstream Patch to allow test suite with non-english LANG
https://bugzilla.sudo.ws/show_bug.cgi?id=1025
     * Apply Upstream Patch to allow test suite with faketime
   * re-introduce MVPROG patch that got lost in dh migration.
     Thanks to Vagrant Cascadian (Closes: #976307)
   * revert back to directly shipping the mask symlink in the package.
     Thanks to Michael Biebl (Closes: #1004730)
   * adopt configure changes from Ubuntu
     --without-lecture --with-tty-tickets --enable-admin-flag (Closes: #1006273)
   * fix wrong handling of --with-systemd-tmpfiles.d
   * bring OPTIONS up to date.
   * have upstream install docs directly to correct directory
   * let debhelper handle the upstream changelog
   * remove LICENSE.md in both packages
   * autopkgtest: send deluser stderr to null in cleanup
   * Add cron to autopkgtest 03-getroot-ldap dependencies
   * improve lintian overrides
Checksums-Sha1:
 4b71625782067d829a3f1672b114cd7cbabbf7bf 2447 sudo_1.9.10-1.dsc
 234358ed08b8f69bff1d9db0161f2616c8f05fbc 4516568 sudo_1.9.10.orig.tar.gz
 9c70c970fbfcbf661bc3648985dd03e9bda41a2a 566 sudo_1.9.10.orig.tar.gz.asc
 62befab06fb4e791410ad33afd77408f5f15330a 35224 sudo_1.9.10-1.debian.tar.xz
 2bd0644d5565aecda9351f49f65d4c13ffe666be 6388 sudo_1.9.10-1_source.buildinfo
Checksums-Sha256:
 9a728857299163d5bfa54571f0edf120e1755bc49f945aee3170e0cbb0eef0a7 2447 sudo_1.9.10-1.dsc
 44a1461098e7c7b8e6ac597499c24fb2e43748c0c139a8b4944e57d1349a64f4 4516568 sudo_1.9.10.orig.tar.gz
 0aae259dc5cb2b02301ad8d57dde7021e3a771ed1665314c0f3305401409b57e 566 sudo_1.9.10.orig.tar.gz.asc
 65b941e09eb7d942ac2a9f53df8993ed78b05bc95bd96e1d19eef4fb4eec3fd7 35224 sudo_1.9.10-1.debian.tar.xz
 bd672b5632ed88a50eebb3eafba21a4294fab3d60a23eb8be266885254df843a 6388 sudo_1.9.10-1_source.buildinfo
Files:
 c564f29be9c5574305e5160dd00c20f5 2447 admin optional sudo_1.9.10-1.dsc
 f9327d4838c28f5a9421b909c21cd442 4516568 admin optional sudo_1.9.10.orig.tar.gz
 f01656b29b19e5a30d5d2d2b303b0bca 566 admin optional sudo_1.9.10.orig.tar.gz.asc
 387e4bafb04ef09e28ababdef5254a96 35224 admin optional sudo_1.9.10-1.debian.tar.xz
 ca2c205609d2edc39cd3a59ced053d0b 6388 admin optional sudo_1.9.10-1_source.buildinfo
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE6QL5UJ/L0pcuNEbjj3cgEwEyBEIFAmI0kIMACgkQj3cgEwEy
BEKYHBAAwuFg+KnHjS48cVjoOq+PD33jsa34uAPYvmDdKLQ48mEVkP+sQihzoaMu
uQ1xxLWBgaP7bwst83fSpSEkbZZ3g2AaMMyf2knus92mRpxVz8g9XPRWYxPoaWuh
ax17HvKqk7dZQ+ramyZzfqhBn5/6nJRIpCTKcs7aecczftvG2BeD2xftq2FGDAFp
xkhUDPZ9BjVbUQbnoGXDAdnJb3AkLkBu54Puy6Bv8fOJBapukFV3mSqda6XrW5sZ
+llbed6QTZQ3l31Om10hdi1++8vf6jeo9Q7Y86e8FYur16fMDJ6VF3C/FjNi+lgs
C+q4CVgcXMqX0yJa1BFp5znYNXqT17OPAQFXY6WYftp/i//o+Z5+/s85t+ZLmtzf
RkImy3WGHwDHLmXVzQdxyvaVlK0/lpyF7vhGVotvF2m9Hp6LDDOAwFMBPYrch7kn
mk7QsHclIzCZDQpIDf/brMITHDJ+2JtNLlRTCQ1OfPLuxWoNHKc9u7JLTUoEvk73
yCoAXCisVnhmoyimmW30oGTBX0Zp73V9l/Z9DdCyCtRMcUhNGgGqPJy34+aqv6Rr
Fr6/hEy3ixUyrtmVk8S/Qv26TSqUfjAionbbyAXGSZ4cm6X7WAPohpMYSdhblhuC
FxOyY9K+vyKFCo0gWP69x0OTSXJfoC/O/bjMUN/9UQMwLN2YAPY=
=pyU/
-----END PGP SIGNATURE-----

#940533#50
Date:
2022-03-21 11:35:39 UTC
From:
To:
We believe that the bug you reported is fixed in the latest version of
sudo, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 940533@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Marc Haber <mh+debian-packages@zugschlus.de> (supplier of updated sudo package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)
Format: 1.8
Date: Mon, 21 Mar 2022 11:49:06 +0100
Source: sudo
Architecture: source
Version: 1.9.10-2
Distribution: unstable
Urgency: medium
Maintainer: Sudo Maintainers <sudo@packages.debian.org>
Changed-By: Marc Haber <mh+debian-packages@zugschlus.de>
Closes: 793660 940533 945366 976307 1004730 1004909 1006273
Changes:
 sudo (1.9.10-2) unstable; urgency=medium
 .
   * upload to unstable (fixed autopkgtest is needed to allow
     adduser to migrate)
 .
 sudo (1.9.10-1) experimental; urgency=medium
 .
   * new upstream version
     * unverified upstream changelog
     * implement workaround if /proc/self/stat is invalid.
       (Closes: #940533)
     * Fix compilation problem on kFreeBSD. (Closes: #1004909)
       (different fix than the Debian patch, disable Debian patch)
     * get rid of e-mails "problem with defaults entries" in sss
       configurations. (Closes: #793660)
     * regular expression support for sudoers. (Closes: #945366)
     * handle /proc/self/fd in qemu.
     * Apply Upstream Patch to allow test suite with non-english LANG
https://bugzilla.sudo.ws/show_bug.cgi?id=1025
     * Apply Upstream Patch to allow test suite with faketime
   * re-introduce MVPROG patch that got lost in dh migration.
     Thanks to Vagrant Cascadian (Closes: #976307)
   * revert back to directly shipping the mask symlink in the package.
     Thanks to Michael Biebl (Closes: #1004730)
   * adopt configure changes from Ubuntu
     --without-lecture --with-tty-tickets --enable-admin-flag (Closes: #1006273)
   * fix wrong handling of --with-systemd-tmpfiles.d
   * bring OPTIONS up to date.
   * have upstream install docs directly to correct directory
   * let debhelper handle the upstream changelog
   * remove LICENSE.md in both packages
   * autopkgtest: send deluser stderr to null in cleanup
   * Add cron to autopkgtest 03-getroot-ldap dependencies
   * improve lintian overrides
Checksums-Sha1:
 fbc82d7f3b4ae5704e16ee8ad823ba68d9cf5427 2447 sudo_1.9.10-2.dsc
 a58246b2238ea90f894de448192bb3470458ccf7 35276 sudo_1.9.10-2.debian.tar.xz
 397051486eb6da6be6f08e37a08b0c934a650038 6388 sudo_1.9.10-2_source.buildinfo
Checksums-Sha256:
 2148e9296c3fe766c34bf7cf654657882d5b83ac769dd1568edb8a1ee81f3928 2447 sudo_1.9.10-2.dsc
 258fd180b01b192060792127cc9a3527df658feb87233b15e824ef0a36841534 35276 sudo_1.9.10-2.debian.tar.xz
 6e645521ebeafe827e627550512a0002d08f1c1a4a9d3c18e8e697427ea9afac 6388 sudo_1.9.10-2_source.buildinfo
Files:
 8c059190daf5bdd263f61408bb112d52 2447 admin optional sudo_1.9.10-2.dsc
 52bfb592ab5b8e31a141ccf8a29f90cd 35276 admin optional sudo_1.9.10-2.debian.tar.xz
 61e241aae5d7d82218ef7b5f5d0bf5f0 6388 admin optional sudo_1.9.10-2_source.buildinfo
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE6QL5UJ/L0pcuNEbjj3cgEwEyBEIFAmI4XqoACgkQj3cgEwEy
BEIeEA//YkOWwXJoHcaYysXaJf86/htSIrlAfPUxAPDBi0N4DNUW2EoMt6g+gaR5
hUJUBnfpf2ZcVPg66GTJiQ2oMNW/sr9rv5judREKNoRixnx1zLZcAPc9nz8rNiMW
isEcrMPpafn5DwKWZk8DZ6LkBIScFM4rsmlc99IK3CnGEguzrLs/4UjwTVgh6Nck
1MNNSYssEndU10Vn42kqCVseDqsoY3pWc749IPED7BDLRw68EFMV5fy+L4H8vt2z
fwwXrs9XcUKoC242c23iTEJNuqE52jAptQORVa6BwLKjO+wEjKmlbitY0+0k5B0Z
2omdAFuIEa1+9tsOe+th6odnCYIflaQ3W0GzAk4XKlksDgMH5HUYNCiqJ9VR1KNp
L0zhlhfrhKyWquoDr2DfjzRvkfCkcgtUMdmaNCGPFQqrH7RZW+9bv7PSkK7Cjfen
sa3BncjD4gRr8jsvQmRxVbEdDmWqnrcbDq0McrGnd4g/Sdx3mmWqquDlC6G4MyRS
F1pjhdZgagaDN2AJFjp1gNhsu2ytTZCtg4geZvwiJwNc/ltRK/fyn6PGuU+MtayP
011K3yWMLkzI4EEybx439/l4COj5ywmVQZR+rUaQEWrLc0KwV7xWu5UC66vU7UU0
iS/ijsb2nM6A08pmgz6J2yVM/90itBLOiCmRMJJdf229qSk4e5w=
=RoRf
-----END PGP SIGNATURE-----

#940533#75
Date:
2025-08-11 09:46:53 UTC
From:
To:
Control: found -1 1:10.0.0+ds-1
I dunno if sudo still relies on this field (field #7, tty_nr)
of /proc/self/stat to do its work.  But qemu, as of version
10.0 and 10.1, still doesn't provide it.  See
https://gitlab.com/qemu-project/qemu/-/blob/stable-10.0/linux-user/syscall.c?ref_type=heads#L8218

FWIW.

Thanks,

/mjt

#940533#82
Date:
2025-08-13 07:17:59 UTC
From:
To:
Control: severity -1 minor
Control: tag -1 + upstream confirmed
Control: reassign -1 qemu-user
Control: retitle -1 qemu-user: tty_nr field (7) in /proc/self/stat is
not emulated
Since this is a very niche thing which doesn't affect a lot of
software (and even this bug report is questionable now, - it looks
like this particular aspect has been fixed in sudo already), and
since this is actually a confirmed upstream issue, let's adjust
the bug report metadata.

Other fields in /proc/self/stat are also not emulated, and this also
causes no big harm.

Also, the package is qemu-user now.

Thanks,

/mjt