Bug 2018697

Summary: shadow-utils: useradd crashes with --prefix
Product: [Fedora] Fedora Reporter: fedora.dm0
Component: shadow-utilsAssignee: Iker Pedrosa <ipedrosa>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 35CC: ipedrosa, pvrabec, tm
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: shadow-utils-4.9-7.fc35 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2020238 (view as bug list) Environment:
Last Closed: 2021-11-15 05:47:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2020238    

Description fedora.dm0 2021-10-30 14:02:03 UTC
Description of problem:
The useradd program fails to add users into a chroot.

Version-Release number of selected component (if applicable):
4.9

How reproducible:
Always

Steps to Reproduce:
1. useradd --prefix "$root" ...

Actual results:
It aborts with "free(): invalid pointer".

Expected results:
It should add the user.

Additional info:
It is fixed upstream, so it could be backported: https://github.com/shadow-maint/shadow/issues/394

Comment 1 Iker Pedrosa 2021-11-03 14:48:26 UTC
Can you provide the exact reproduction steps? I've tried with the following ones and it works correctly:
1- mkdir -p $HOME/custom_root/etc/ && touch $HOME/custom_root/etc/passwd
2- sudo useradd -P $HOME/custom_root user4

Comment 2 fedora.dm0 2021-11-03 18:29:00 UTC
It doesn't seem to reproduce with an empty root, but copying in a bunch of stuff from a real system causes it:

[root@buildroot ~]# rm -fr /tmp/newroot && mkdir -p /tmp/newroot/etc && cp -at /tmp/newroot/etc /etc/{passwd,group,sub[ug]id,gshadow,shadow,login.defs,default} 
[root@buildroot ~]# useradd --prefix /tmp/newroot --groups=wheel --create-home --password= test 
free(): invalid pointer
Aborted (core dumped)

Apparently openSUSE hit this as well and backported the upstream commit: https://build.opensuse.org/package/view_file/openSUSE:Factory/shadow/shadow-fix-sigabrt.patch

Comment 3 Iker Pedrosa 2021-11-04 11:22:46 UTC
Thanks for the steps! I'll include this in Fedora soon.

Comment 4 Fedora Update System 2021-11-09 15:30:25 UTC
FEDORA-2021-7a723060da has been submitted as an update to Fedora 35. https://bodhi.fedoraproject.org/updates/FEDORA-2021-7a723060da

Comment 5 Fedora Update System 2021-11-10 04:11:30 UTC
FEDORA-2021-7a723060da has been pushed to the Fedora 35 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2021-7a723060da`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-7a723060da

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 6 Fedora Update System 2021-11-14 02:39:54 UTC
FEDORA-2021-2709419aea has been pushed to the Fedora 35 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2021-2709419aea`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-2709419aea

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2021-11-15 05:47:26 UTC
FEDORA-2021-2709419aea has been pushed to the Fedora 35 stable repository.
If problem still persists, please make note of it in this bug report.