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

usage of sscanf with format %s is unsafe #4366

Open
DawningRain opened this issue Nov 9, 2023 · 6 comments · May be fixed by #4438
Open

usage of sscanf with format %s is unsafe #4366

DawningRain opened this issue Nov 9, 2023 · 6 comments · May be fixed by #4438
Assignees

Comments

@DawningRain
Copy link

if oparg length is bigger than name buffer length, it will cause buffer overflow because the width of %s is not provied.

insecure code:

if (sscanf(oparg, "%s", name) < 1) {

https://github.com/lxc/lxc/blob/9c1d70ef8b393d42fc089e89b16a3ec7d8769ff1/src/lxc/tools/lxc_unshare.c#L166C1-L166C1

maybe we should fix it like this:

if (sscanf(oparg, "%4095s", name) < 1)
@anooprac
Copy link

anooprac commented Apr 4, 2024

Hello, we're UT Austin students working on open-source contributions for a final project. Would it be fine to have this assigned to us? Thank you!

@DevonSchwartz
Copy link

Hi. I am on the same project team as anooprac. Should we return an error code if the length of oparg is larger than the name buffer length, or should we limit the size of the input buffer to 4095?

@DevonSchwartz
Copy link

When you run lxc-unshare, what username should you specify? Does it need to be mapped beforehand?

@DevonSchwartz
Copy link

Screenshot from 2024-04-30 11-30-33
This is the output from calling lxc-unshare with an input for the -u flag

@DevonSchwartz DevonSchwartz linked a pull request May 1, 2024 that will close this issue
@stgraber
Copy link
Member

stgraber commented May 7, 2024

Looking back at this, the issue really is with sscanf using %s where the target buffer can be smaller than the source and cause issues, but the code being modified here uses %u which does not suffer from the same issue.

So I'm wondering if this was perhaps about a prior implementation of that function and we don't actually have a problem here anymore.

@DevonSchwartz
Copy link

That could be. Was the purpose of the “%s” implementation to get a non-numerical username?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants