Skip to content

Bugfix: useradd: fix btrfs subvolume home creation#1617

Merged
alejandro-colomar merged 1 commit intoshadow-maint:masterfrom
silverhadch:master
Apr 28, 2026
Merged

Bugfix: useradd: fix btrfs subvolume home creation#1617
alejandro-colomar merged 1 commit intoshadow-maint:masterfrom
silverhadch:master

Conversation

@silverhadch
Copy link
Copy Markdown
Contributor

dirname() replaces broken stpcpy index arithmetic that produced an empty string for single-component paths, causing statfs to fail and fall back to a regular directory. Gate subvolume creation on user_id >= UID_MIN to exclude system users regardless of their home path.

Closes #1616

@silverhadch
Copy link
Copy Markdown
Contributor Author

@alejandro-colomar
CC: @Conan-Kudo

@silverhadch silverhadch changed the title useradd: fix btrfs subvolume creation for non-/home paths and system users Bugfix: useradd: fix btrfs subvolume home creation Apr 28, 2026
Comment thread src/useradd.c Outdated
Comment thread src/useradd.c Outdated
Comment thread src/useradd.c Outdated
@silverhadch silverhadch force-pushed the master branch 2 times, most recently from 0985b06 to a7f67f8 Compare April 28, 2026 10:23
Comment thread src/useradd.c Outdated
@silverhadch silverhadch force-pushed the master branch 2 times, most recently from 45ba5b3 to 6fe1f17 Compare April 28, 2026 10:55
Comment thread src/useradd.c
Comment thread src/useradd.c Outdated
@alejandro-colomar
Copy link
Copy Markdown
Collaborator

alejandro-colomar commented Apr 28, 2026

CI seems to be consistently failing some test. Could you please check why?

Cc: @ikerexxe

@alejandro-colomar
Copy link
Copy Markdown
Collaborator

CI seems to be consistently failing some test. Could you please check why?

Cc: @ikerexxe

I think this is the relevant part of the log:

2026-04-28T11:36:21.4888039Z ##[group]Run set -e
2026-04-28T11:36:21.4888283Z �[36;1mset -e�[0m
2026-04-28T11:36:21.4888453Z �[36;1mcd tests�[0m
2026-04-28T11:36:21.4888640Z �[36;1mtrap 'cat testsuite.log' ERR�[0m
2026-04-28T11:36:21.4888877Z �[36;1msudo ./run_some�[0m
2026-04-28T11:36:21.4889073Z �[36;1mtrap - ERR�[0m
2026-04-28T11:36:21.4932368Z shell: /usr/bin/script -q -e -c "bash {0}"
2026-04-28T11:36:21.4932644Z ##[endgroup]
2026-04-28T11:36:21.5270783Z +: test passed
2026-04-28T11:36:21.5271211Z -: test failed
2026-04-28T11:36:49.2061345Z .+-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2026-04-28T11:36:49.2061933Z 75 test(s) passed
2026-04-28T11:36:49.2062237Z 1 test(s) failed
2026-04-28T11:36:49.2062542Z log written in 'testsuite.log'
2026-04-28T11:36:49.2062908Z the following tests failed:
2026-04-28T11:36:49.2063248Z  ./su/01/su_root.test
2026-04-28T11:36:49.2084657Z 
2026-04-28T11:36:49.2085118Z ###############################################################################
2026-04-28T11:36:49.2085883Z #
2026-04-28T11:36:49.2086171Z # Test: ./su/01/su_user.test
2026-04-28T11:36:49.2086518Z #
2026-04-28T11:36:49.2086860Z ###############################################################################
2026-04-28T11:36:49.2092574Z #
2026-04-28T11:36:49.2093076Z # Rationale: su can be used to switch to a non-root user
2026-04-28T11:36:49.2093640Z #
2026-04-28T11:36:49.2094014Z ###############################################################################
2026-04-28T11:36:49.2094721Z # switch to the passwordless 'testsuite' user
2026-04-28T11:36:49.2095354Z # and expect a '$ ' prompt
2026-04-28T11:36:49.2095833Z spawn /bin/su testsuite
2026-04-28T11:36:49.2096082Z 
2026-04-28T11:36:49.2096089Z 
2026-04-28T11:36:49.2096219Z FAIL (timeout)
2026-04-28T11:36:49.2096620Z ###############################################################################
2026-04-28T11:36:49.2097674Z #
2026-04-28T11:36:49.2098525Z # Status of test ./su/01/su_user.test: FAILURE
2026-04-28T11:36:49.2099111Z #
2026-04-28T11:36:49.2099537Z ###############################################################################
2026-04-28T11:36:49.2100033Z 
2026-04-28T11:36:49.2100234Z ###############################################################################
2026-04-28T11:36:49.2100740Z #
2026-04-28T11:36:49.2100982Z # Test: ./su/01/su_user.test
2026-04-28T11:36:49.2101289Z #
2026-04-28T11:36:49.2101576Z ###############################################################################
2026-04-28T11:36:49.2101991Z #
2026-04-28T11:36:49.2102313Z # Rationale: su can be used to switch to a non-root user
2026-04-28T11:36:49.2102761Z #
2026-04-28T11:36:49.2103049Z ###############################################################################
2026-04-28T11:36:49.2103533Z # switch to the passwordless 'testsuite' user
2026-04-28T11:36:49.2103962Z # and expect a '$ ' prompt
2026-04-28T11:36:49.2104294Z spawn /bin/su testsuite
2026-04-28T11:36:49.2104499Z 
2026-04-28T11:36:49.2104661Z groups: cannot find name for group ID 424243
2026-04-28T11:36:49.2104962Z 
2026-04-28T11:36:49.2105239Z testsuite@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ 
2026-04-28T11:36:49.2105789Z # make sure we are now 'testsuite'
2026-04-28T11:36:49.2106285Z # id should return 'uid=424243(testsuite) gid=424243 groups=424243'
2026-04-28T11:36:49.2106694Z 
2026-04-28T11:36:49.2106971Z testsuite@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ id
2026-04-28T11:36:49.2107752Z 
2026-04-28T11:36:49.2107911Z uid=424243(testsuite) gid=424243 groups=424243
2026-04-28T11:36:49.2108221Z 
2026-04-28T11:36:49.2108491Z testsuite@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ 
2026-04-28T11:36:49.2108909Z 
2026-04-28T11:36:49.2109033Z # now switch to user 'myuser'
2026-04-28T11:36:49.2109478Z # and expect a password prompt
2026-04-28T11:36:49.2109735Z 
2026-04-28T11:36:49.2110056Z testsuite@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ su myuser
2026-04-28T11:36:49.2110589Z 
2026-04-28T11:36:49.2110695Z Password: 
2026-04-28T11:36:49.2111259Z # password 'myuserF00barbaz' sent
2026-04-28T11:36:49.2111536Z 
2026-04-28T11:36:49.2111656Z # expect prompt '$ '
2026-04-28T11:36:49.2111852Z 
2026-04-28T11:36:49.2112102Z myuser@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ 
2026-04-28T11:36:49.2112507Z 
2026-04-28T11:36:49.2112623Z # make sure we are 'myuser'
2026-04-28T11:36:49.2112992Z # id should return '(myuser).*(myuser).*(myuser)
2026-04-28T11:36:49.2113294Z 
2026-04-28T11:36:49.2113552Z myuser@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ id
2026-04-28T11:36:49.2113961Z 
2026-04-28T11:36:49.2114166Z uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)
2026-04-28T11:36:49.2114401Z 
2026-04-28T11:36:49.2114569Z myuser@runnervmrc6n4:~/runner/work/shadow/shadow/tests/su/01$ exit
2026-04-28T11:36:49.2114818Z 
2026-04-28T11:36:49.2114873Z exit
2026-04-28T11:36:49.2114958Z 

Comment thread src/useradd.c Outdated
dirname() replaces broken stpcpy index arithmetic that produced an
empty string for single-component paths (e.g. /koolhome), causing
statfs to fail and fall back to a regular directory. Use path in
the error message since dirname() modifies btrfs_check in-place,
making it unusable for logging after the call.

Fixes: c1d36a8 (2019-05-04; "Add support for btrfs subvolumes for user homes")
Signed-off-by: Hadi Chokr <hadichokr@icloud.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Copy link
Copy Markdown
Collaborator

@alejandro-colomar alejandro-colomar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the CI error has vanished (ignoring the opensuse one, which is common, and known).

Thanks!

@alejandro-colomar alejandro-colomar merged commit bd1ea38 into shadow-maint:master Apr 28, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-d /not-under-home and --btrfs-subvolume-home flag are incompatible

2 participants