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

lib/chkname.c: Put limits for LOGIN_NAME_MAX and sysconf(_SC_LOGIN_NAME_MAX) #1169

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 4, 2025

GNU Hurd recommends having no system limits.  When a program needs a
limit, because it needs to validate user input, it is recommended that
each program defines its own limit macros.  The rationale is that this
avoids hard-coded limits in ABIs, which cannot be modified ever.

However, that doesn't mean that programs should have no limits at all.
We use this limit for validating user input, and so we shouldn't allow
anything just because the system doesn't want to set a limit.

So, when sysconf(2) returns -1, either due to an error or due to a claim
for no limits, we must fall back to the LOGIN_NAME_MAX value.  And if
the system doesn't define that value, we must define it ourselves (we're
more or less free to choose any value, so let's pick the one that glibc
provides nowadays).

Fixes: 6a1f45d (2024-02-04: "lib/chkname.c: Support unlimited user name lengths")
Closes: #1166
Cc: @zeha
Cc: @stoeckmann
Cc: @sthibaul


Revisions:

v1b
  • Remove credits to @zeha
  • Update copyright.
  • Mention in commit message explicitly that GNU Hurd doesn't define LOGIN_NAME_MAX. [@zeha]
$ git range-diff shadow/master gh/hurd hurd 
1:  1d87e944 ! 1:  f2698953 lib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_LOGIN_NAME_MAX)
    @@ Metadata
      ## Commit message ##
         lib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_LOGIN_NAME_MAX)
     
    -    GNU Hurd recommends having no system limits.  When a program needs a
    -    limit, because it needs to validate user input, it is recommended that
    -    each program defines its own limit macros.  The rationale is that this
    -    avoids hard-coded limits in ABIs, which cannot be modified ever.
    +    GNU Hurd doesn't define LOGIN_NAME_MAX.  GNU Hurd recommends having no
    +    system limits.  When a program needs a limit, because it needs to
    +    validate user input, it is recommended that each program defines its own
    +    limit macros.  The rationale is that this avoids hard-coded limits in
    +    ABIs, which cannot be modified ever.
     
         However, that doesn't mean that programs should have no limits at all.
         We use this limit for validating user input, and so we shouldn't allow
    @@ Commit message
     
         Fixes: 6a1f45d932c8 (2024-02-04; "lib/chkname.c: Support unlimited user name lengths")
         Closes: <https://github.com/shadow-maint/shadow/issues/1166>
    -    Co-developed-by: Chris Hofstaedtler <[email protected]>
    +    Cc: Chris Hofstaedtler <[email protected]>
         Cc: Tobias Stoeckmann <[email protected]>
         Cc: Samuel Thibault <[email protected]>
         Signed-off-by: Alejandro Colomar <[email protected]>
     
      ## lib/chkname.c ##
    +@@
    + // SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
    + // SPDX-FileCopyrightText: 2001-2005, Tomasz Kłoczko
    + // SPDX-FileCopyrightText: 2005-2008, Nicolas François
    +-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <[email protected]>
    ++// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <[email protected]>
    + // SPDX-License-Identifier: BSD-3-Clause
    + 
    + 
     @@
      #include <limits.h>
      #include <stdbool.h>
v1c
$ git range-diff shadow/master gh/hurd hurd 
1:  f2698953 ! 1:  87b8f5a3 lib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_LOGIN_NAME_MAX)
    @@ Commit message
         Fixes: 6a1f45d932c8 (2024-02-04; "lib/chkname.c: Support unlimited user name lengths")
         Closes: <https://github.com/shadow-maint/shadow/issues/1166>
         Cc: Chris Hofstaedtler <[email protected]>
    -    Cc: Tobias Stoeckmann <[email protected]>
    -    Cc: Samuel Thibault <[email protected]>
    +    Reviewed-by: Samuel Thibault <[email protected]>
    +    Reviewed-by: Tobias Stoeckmann <[email protected]>
    +    Reviewed-by: Iker Pedrosa <[email protected]>
         Signed-off-by: Alejandro Colomar <[email protected]>
     
      ## lib/chkname.c ##

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Jan 4, 2025

@zeha , I put a Co-developed-by because I based my patch on your Debian patch. However, if you think it differs too much from it and want that tag removed, just let me know.

If you want to keep it, feel free to sign the patch by sending a Signed-off-by.

@alejandro-colomar alejandro-colomar force-pushed the hurd branch 2 times, most recently from 4db388c to 1d87e94 Compare January 4, 2025 12:59
@zeha
Copy link
Contributor

zeha commented Jan 4, 2025

Yeah I don't think I want to take any credit for this.

BTW: do you want a comment next to the ifdef hinting that this is mostly for Hurd?

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Jan 4, 2025

Yeah I don't think I want to take any credit for this.

Okay. I've removed that line, and put a Cc one instead.

BTW: do you want a comment next to the ifdef hinting that this is mostly for Hurd?

I don't know. I tend to prefer to keep those in the commit message. A git-blame(1) on any of those three lines will bring up this commit. I've edited the commit message to be more explicit about it.

@alejandro-colomar alejandro-colomar marked this pull request as ready for review January 4, 2025 14:03
@alejandro-colomar
Copy link
Collaborator Author

@zeha , @sthibaul , @stoeckmann

Can you please review and (if appropriate) approve the PR?

@alejandro-colomar
Copy link
Collaborator Author

Thanks for the reviews!

Copy link
Collaborator

@ikerexxe ikerexxe left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for taking care of it.

…nd sysconf(_SC_LOGIN_NAME_MAX)

GNU Hurd doesn't define LOGIN_NAME_MAX.  GNU Hurd recommends having no
system limits.  When a program needs a limit, because it needs to
validate user input, it is recommended that each program defines its own
limit macros.  The rationale is that this avoids hard-coded limits in
ABIs, which cannot be modified ever.

However, that doesn't mean that programs should have no limits at all.
We use this limit for validating user input, and so we shouldn't allow
anything just because the system doesn't want to set a limit.

So, when sysconf(2) returns -1, either due to an error or due to a claim
for no limits, we must fall back to the LOGIN_NAME_MAX value.  And if
the system doesn't define that value, we must define it ourselves (we're
more or less free to choose any value, so let's pick the one that glibc
provides nowadays).

Fixes: 6a1f45d (2024-02-04; "lib/chkname.c: Support unlimited user name lengths")
Closes: <shadow-maint#1166>
Cc: Chris Hofstaedtler <[email protected]>
Reviewed-by: Samuel Thibault <[email protected]>
Reviewed-by: Tobias Stoeckmann <[email protected]>
Reviewed-by: Iker Pedrosa <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar alejandro-colomar merged commit 8b36662 into shadow-maint:master Jan 7, 2025
8 checks passed
@alejandro-colomar alejandro-colomar deleted the hurd branch January 7, 2025 14:28
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.

GNU Hurd and LOGIN_NAME_MAX
5 participants