-
Notifications
You must be signed in to change notification settings - Fork 255
lib/chkname.c, src/: Strictly disallow really bad names #1158
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
base: master
Are you sure you want to change the base?
lib/chkname.c, src/: Strictly disallow really bad names #1158
Conversation
dfb9f11 to
1c5acb5
Compare
|
The CI fails because I need to merge several PRs before this one:
|
5c45a5a to
5369182
Compare
|
Before reviewing this PR I would like to come to an agreement on the long term path for this option, so let's wait for people to come and give us feedback at #1149. It will take some time to come to an agreement, but I think this is the best way forward. |
Hmmm, I was thinking the other way around: Whatever the agreement is for the future, some things should never be allowed. The files I would also include slashes and backslashes in the ban, but I don't know if this will mess with Microsoft Windows users. Anyone knows? |
|
Not allowing backslashes might cause issues with Windows, and Slashes in the user name are probably a bad idea because of usage in shell scripts. In any case, an implicitly generated home directory from a user name containing slashes is bad, so if slashes stay allowed in user names, the home directory MUST be explicitly given, or alternatively sanitized, e.g. s//_/g |
|
On Wed, Dec 25, 2024 at 11:27:49AM -0800, Zugschlus wrote:
Not allowing backslashes might cause issues with Windows, and Slashes in the user name are probably a bad idea because of usage in shell scripts. In any case, an implicitly generated home directory from a user name containing slashes is bad, so if slashes stay allowed in user names, the home directory MUST be explicitly given, or alternatively sanitized, e.g. s/\/_/g
Okay, so I'll add forward slashes to the ban.
Thanks!
…
--
Reply to this email directly or view it on GitHub:
#1158 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
5369182 to
810bc45
Compare
Done in v4 of this patch. |
|
I'm good with the intent of the patch. Would like to take a closer look at the details (have to look up the particulars of things like strpbrk every time) before merging. |
Thanks!
Sure. I need to check them every now and then. :) strpbrk() is kind of like strchr(), but with several chars for matching. The name is unfortunate, but that's a simple way of thinking about it. Here's a comparison of the descriptions in the manual pages: I might have called it strchrs() instead... |
|
BTW, some of the APIs used in this patch are not yet merged. They are proposed in other PRs, which is why this thing is still a draft. Just in case you look up some definitions, they're not yet available. |
810bc45 to
5ddbdca
Compare
8be46b3 to
0716561
Compare
0716561 to
74b5422
Compare
|
I've added |
831b11b to
2e6ba45
Compare
2e6ba45 to
a1159f6
Compare
Hmmm, now it makes sense. |
So that's an interesting question for the debian codebase. They used to allow some |
|
@alejandro-colomar ok, so, I don't think we should do this. It's not our place to stop I think we should a) allow --baduser to be specified twice to say "no, really", b) not allow creating a homedir named for the user, and c) relax the rules for passwd, bc if you can passwd, then the user already exists. |
|
Now the ':' actually fails anyway The only problem with , ~, /, and # appears to be that even though it doesn't create I need to think more about |, &, and ;. |
I've been thinking this evening about this, and my idea was:
That would allow using |
|
TBH I think for backslash the ship has sailed. From my PoV a minimal set of bad characters (like : and ) should be absolutely forbidden with no override mechanism. And everything else left to the users, effectively removing I think that was basically also where this entire thing started. |
I personally think But maybe we could analyze that after the release and allow it (after all, Debian is proof that |
|
@zeha by 'the ship has sailed for backslash' do you mean people are using it and it I'm aware that posix is quite strict, and systemd as well. I'm happy to have the @alejandro-colomar to be clear, I think you should not make any changes to the pr until |
@hallyn sorry for being unclear. I think most distros did not allow it and it should not be supported. So if this ends up completely denying |
Ok, thanks for clarifying. I'm trying to poke a few people to find out whether there is
Ok, i think I'm good with this, but I'm thinking we should have two charsets, badset and I still think that passwd, userdel and usermod should support a wider set than useradd ':' is not even worth considering since useradd doesn't even 'refuse', just fails to I'm still wondering how we feel about other shell control chars - "&;|" in particular. |
Agreed, provided that this cannot be abused to modify another user than intended. |
I'm not so sure. I think existing users should seriously consider transitioning to not using these characters at all. A couple of edits by hand in the transition wouldn't hurt. In the long term, I would prefer if all programs have the same set of reallybad characters, and they all refuse them. Otherwise, we risk having some bugs in passwd that could accidentally modify unintended users. |
If it was myself and my team, I'd strongly agree. But I don't feel that's acceptable
For reallybad characters, like :, those are fine to be the same across all Out of bad characters, again, we have some that are bad because they can impact
Agreed for ':', but what else do you foresee? |
We also separate strings on And we use the home directory, so And there might be others; we'd have to check the code more carefully. $ grep -rhoi 'st.sep[a-z_2]* *([^3][^)]\+)' src/ lib* | grep -o '".*"' | sort | uniq
" \t"
" \t\n"
", "
", \t"
","
",:"
":"
"="
"@"
"\""
"\n" |
|
These two PRs would be interesting to make that research easier:
Please consider merging them soonish. |
|
Yes, but 1. '.' and '..' have always been excluded on their own, and will continue to be. As will any usernames which begin with '-', or are only digits. Those are not part of the 'reallybad' or 'bad' charsets, they're a separate check for the whole username. 2. only : is used to separate the username in shadow or passwd. I don't believe the other separators are really relevant. |
Line 225 in e562faf
That's not about /etc/passwd nor /etc/shadow, but it's code where we do username separation, and we use Are you sure we'd be okay accepting Also, while we don't separate users on commas, we do separate groups on commas (and whitespace), and we have the same validator for users and for groups, so the validator should probably reject commas (and whitespace). |
d333a6f to
235e72a
Compare
Self-correction: I didn't forget about tabs. Tabs (and newlines) are control characters, and thus rejected in the |
|
BTW, I've been wondering about that dollar we allow for Samba. There's a comment that says it's for Samba 3.0. I see that Samba is in version 4., and that 3. seems to be EOL. Does Samba 4.* still use that dollar? Do we want to keep supporting that? Does anyone know of a maintainer that knows anything about Samba that could comment? |
|
Good point about commas in groups. And about @. So both belong in reallybadchars. |
Let's have a look at all the characters again: " !\"#&*+,/:;@|~"
|
|
One thing I'm not sure (I don't remember) is in which moment we run these checks. Because if we disallow the Does anyone have any system that uses |
235e72a to
58f4dc9
Compare
Some names are bad, and some names are really bad. '--badname' should only allow the mildly bad ones, which we can handle. Some names are too bad, and it's not possible to deal with them. Reject them unconditionally. - A leading '-' is too dangerous. It breaks things like execve(2), and almost every command. - Spaces are used for delimiting lists of users and groups. - '"' is special in many languages, including the shell. Having it in user names would be unnecessarily dangerous. - '#' is used for delimiting comments in several of our config files. Having it in usernames could result in incorrect configuration files. - ',' is used for delimiting lists of users and groups. - '/' is used for delimiting files, and thus could result in incorrect handling of users and groups. - ':' is the main delimiter in /etc/shadow and /etc/passwd. - ';' is special in many languages, including the shell. Having it in user names would be unnecessarily dangerous. There are other characters that we should disallow, but they need more research to make sure we don't introduce regressions. This set should be less problematic. Acked-by: Chris Hofstaedtler <[email protected]> Acked-by: Tobias Stoeckmann <[email protected]> Cc: Marc 'Zugschlus' Haber <[email protected]> Cc: Iker Pedrosa <[email protected]> Cc: Serge Hallyn <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
Some names are bad, and some names are really bad. '--badname' should only allow the mildly bad ones, which we can handle. Some names are too bad, and it's not possible to deal with them. Reject them unconditionally. Acked-by: Chris Hofstaedtler <[email protected]> Acked-by: Tobias Stoeckmann <[email protected]> Cc: Marc 'Zugschlus' Haber <[email protected]> Cc: Iker Pedrosa <[email protected]> Cc: Serge Hallyn <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
58f4dc9 to
3b4d01e
Compare
Cc: @zeha
Cc: @Zugschlus
Cc: @ikerexxe
Cc: @hallyn
Revisions:
v1b
v2
v3
Spaces are used as structuring characters in several programs (e.g., id(1)). Don't mess with them.
v4
/to the ban. [@Zugschlus ]v4b
Whoops, it seems this was supposed to be based after the streq branch.
v4c
v4d
v5
". This is so that we don't need to call audit_value_needs_encoding(3) and audit_encode_value(3).v6
@, and disallow a few case-insensitive names:none,all, andexcept. [@stoeckmann ]v7
#to the ban. [@stoeckmann ]v8
|,&,;,+,*,!v8b
v9
strcaseeq()is already available inmaster.v9b
v10
v11
~to the ban list. (Debian forbid that character for a long time.)v11b
v11c
v11d
v11e
v11f
v11g
v11h
v11i
v11j
v11k
v11l
v11m
v11n
v11o
v11p
v11q
v11r
v11s
v11t
v11u
v12
v12b
v12c
v13
v13b
v13c
v14