Silent/confusing failure when /etc/subuid and/or /etc/subgid are empty #9

Closed
opened 3 years ago by frebib · 4 comments
frebib commented 3 years ago

I spent a good hour debugging this assuming it was a kernel/system related issue, not a me issue. I later realised that Debian populates these files for all users by default, it seems. Full disclosure: I was trying to run this on Arch with no success yet.

The code doesn't actually check if the loops iterated in read_subuid_subgid before pushing them into the array, hence the silent failure. I've never written perl before but this seems to make the error more obvious, at least:

diff --git a/mmdebstrap b/mmdebstrap
index 730bd1a..4269ee5 100755
--- a/mmdebstrap
+++ b/mmdebstrap
@@ -345,6 +345,10 @@ sub read_subuid_subgid() {
         last if ($n eq $username);
     }
     close $fh;
+    if (!length $subid) {
+        error("subuid is empty");
+        return;
+    }
     push @result, ["u", 0, $subid, $num_subid];

     if (scalar(@result) < 1) {
@@ -363,6 +367,10 @@ sub read_subuid_subgid() {
         last if ($n eq $username);
     }
     close $fh;
+    if (!length $subid) {
+        error("subuid is empty");
+        return;
+    }
     push @result, ["g", 0, $subid, $num_subid];

     if (scalar(@result) < 2) {
@@ -5425,7 +5433,9 @@ sub main() {
         # sanity check
         if (   scalar(@idmap) != 2
             || $idmap[0][0] ne 'u'
-            || $idmap[1][0] ne 'g') {
+            || $idmap[1][0] ne 'g'
+            || ! length $idmap[0][2]
+            || ! length $idmap[1][2]) {
             error "invalid idmap";
         }

Before:

frebib@frebib-PC /t/debootstrap.kccW44TI> ./mmdebstrap testing /dev/null
I: automatically chosen mode: unshare
I: chroot architecture amd64 is equal to the host's architecture
I: automatically chosen format: null
I: using /tmp/mmdebstrap.LlveOMoZAl as tempdir
Use of uninitialized value $nsid in concatenation (.) or string at ./mmdebstrap line 507.
Use of uninitialized value $nsid in concatenation (.) or string at ./mmdebstrap line 510.
ranges: 2 argc: 5
newuidmap: Not enough arguments to form 2 mappings
usage: newuidmap <pid> <uid> <loweruid> <count> [ <uid> <loweruid> <count> ] ...
E: newuidmap 516114  0 1000 1 1  1 failed:
E: child had a non-zero exit status: 1
E: chown failed

After:

frebib@frebib-PC /t/debootstrap.kccW44TI> ./mmdebstrap testing /dev/null       
I: automatically chosen mode: unshare
I: chroot architecture amd64 is equal to the host's architecture
I: automatically chosen format: null
I: using /tmp/mmdebstrap.APVZbMlseG as tempdir
E: subuid is empty
I spent a good hour debugging this assuming it was a kernel/system related issue, not a me issue. I later realised that Debian populates these files for all users by default, it seems. Full disclosure: I was trying to run this on Arch with no success yet. The code doesn't actually check if the loops iterated in `read_subuid_subgid` before pushing them into the array, hence the silent failure. I've never written perl before but this seems to make the error more obvious, at least: ```perl diff --git a/mmdebstrap b/mmdebstrap index 730bd1a..4269ee5 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -345,6 +345,10 @@ sub read_subuid_subgid() { last if ($n eq $username); } close $fh; + if (!length $subid) { + error("subuid is empty"); + return; + } push @result, ["u", 0, $subid, $num_subid]; if (scalar(@result) < 1) { @@ -363,6 +367,10 @@ sub read_subuid_subgid() { last if ($n eq $username); } close $fh; + if (!length $subid) { + error("subuid is empty"); + return; + } push @result, ["g", 0, $subid, $num_subid]; if (scalar(@result) < 2) { @@ -5425,7 +5433,9 @@ sub main() { # sanity check if ( scalar(@idmap) != 2 || $idmap[0][0] ne 'u' - || $idmap[1][0] ne 'g') { + || $idmap[1][0] ne 'g' + || ! length $idmap[0][2] + || ! length $idmap[1][2]) { error "invalid idmap"; } ``` Before: ``` frebib@frebib-PC /t/debootstrap.kccW44TI> ./mmdebstrap testing /dev/null I: automatically chosen mode: unshare I: chroot architecture amd64 is equal to the host's architecture I: automatically chosen format: null I: using /tmp/mmdebstrap.LlveOMoZAl as tempdir Use of uninitialized value $nsid in concatenation (.) or string at ./mmdebstrap line 507. Use of uninitialized value $nsid in concatenation (.) or string at ./mmdebstrap line 510. ranges: 2 argc: 5 newuidmap: Not enough arguments to form 2 mappings usage: newuidmap <pid> <uid> <loweruid> <count> [ <uid> <loweruid> <count> ] ... E: newuidmap 516114 0 1000 1 1 1 failed: E: child had a non-zero exit status: 1 E: chown failed ``` After: ``` frebib@frebib-PC /t/debootstrap.kccW44TI> ./mmdebstrap testing /dev/null I: automatically chosen mode: unshare I: chroot architecture amd64 is equal to the host's architecture I: automatically chosen format: null I: using /tmp/mmdebstrap.APVZbMlseG as tempdir E: subuid is empty ```
josch commented 3 years ago
Owner

Uuuuh! Nice catch, thank you!

Also please feel free to file more bugs that you run into when running mmdebstrap on arch. Since I'm only running it on Debian, I'm quite certain this will not be the last you find. 😀

Uuuuh! Nice catch, thank you! Also please feel free to file more bugs that you run into when running mmdebstrap on arch. Since I'm only running it on Debian, I'm quite certain this will not be the last you find. 😀
josch commented 3 years ago
Owner

With which name and email can I attribute you in the git commit implementing the diff you posted?

With which name and email can I attribute you in the git commit implementing the diff you posted?
frebib commented 3 years ago
Poster

https://github.com/frebib/dotfiles/blob/master/git/config#L2-L3

I might suggest you revise the error messages, that's just something I threw together quickly.
Thanks

https://github.com/frebib/dotfiles/blob/master/git/config#L2-L3 I might suggest you revise the error messages, that's just something I threw together quickly. Thanks
josch commented 2 years ago
Owner

Closed by 15029c1c3b

Closed by 15029c1c3bb3057c7105be19a004c1974c37950c
josch closed this issue 2 years ago
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: josch/mmdebstrap#9
Loading…
There is no content yet.