Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getcwd01,readlinkat02 fails in Alpine 3.18 container #1084

Closed
richiejp opened this issue Sep 26, 2023 · 6 comments
Closed

getcwd01,readlinkat02 fails in Alpine 3.18 container #1084

richiejp opened this issue Sep 26, 2023 · 6 comments
Labels

Comments

@richiejp
Copy link
Contributor

The test passes NULL as the buffer to getcwd. This causes musl to allocate a buffer and ignore the length argument. The test then passes unexpectedly.

glibc should do the same, but it possibly checks the length argument or passes it to the syscall.

@richiejp richiejp added the bug label Sep 26, 2023
@metan-ucw
Copy link
Member

Looks like glibc uses the size argument to allocate the buffer unless it's 0. So I suppose that musl ignores the size completely and allocates the buffer so that it fits the path.

@richiejp
Copy link
Contributor Author

readlinkat02 fails for a similar reason. Except that this time musl checks the buffer size instead and uses a stack buffer.

@richiejp
Copy link
Contributor Author

uclibc-ng does the same as glibc

@richiejp richiejp changed the title getcwd01 fails in Alpine 3.18 container getcwd01,readlinkat02 fails in Alpine 3.18 container Sep 27, 2023
1 similar comment
pevik pushed a commit to pevik/ltp that referenced this issue Nov 28, 2023
@pevik pevik closed this as completed in 0ad8e81 Dec 1, 2023
@pevik
Copy link
Member

pevik commented Dec 27, 2023

Both malloc buffer if buf==NULL. https://patchwork.ozlabs.org/project/ltp/patch/20230928010808.15862-1-wegao@suse.com/

@coolgw malloc() is not relevant to the problem, MUSL fails due the reason described by Richie original report #1084 (comment): musl on null buffer allocates a buffer but ignore the length argument. Unlike glibc, uclibc{,-ng}. IMHO also bionic is compatible with glibc, uclibc{,-ng}(https://android.googlesource.com/platform/bionic.git/+/refs/heads/main/libc/bionic/getcwd.cpp), because it uses size on null buffer.

coolgw added a commit to coolgw/ltp that referenced this issue Feb 9, 2024
Fixes: linux-test-project#1084

User space wrap getcwd with different implementation, for example
glibc will directly input parameter into kernel in normal situation
but uclibc-ng and musl will malloc buffer when buffer is NULL, so for
uclibc and musl the parameter size will be ignored. Use system call
directly check invalid argument can be a solution.

Signed-off-by: Wei Gao <wegao@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants