Skip to content

sched/nsh: Remove Hard-coded Default Password#18396

Open
Abhishekmishra2808 wants to merge 3 commits intoapache:masterfrom
Abhishekmishra2808:Issue-16822
Open

sched/nsh: Remove Hard-coded Default Password#18396
Abhishekmishra2808 wants to merge 3 commits intoapache:masterfrom
Abhishekmishra2808:Issue-16822

Conversation

@Abhishekmishra2808
Copy link

@Abhishekmishra2808 Abhishekmishra2808 commented Feb 15, 2026

Summary

This PR introduces build-time generation of the /etc/passwd file for the ROMFS image when authentication is enabled.

Instead of relying on a static etc/passwd file embedded in the source tree, the passwd entry is now generated during the build using the configuration values:

  • CONFIG_ETC_ROMFS_PASSWD_USER
  • CONFIG_ETC_ROMFS_PASSWD_PASSWORD
  • CONFIG_ETC_ROMFS_PASSWD_UID
  • CONFIG_ETC_ROMFS_PASSWD_GID
  • CONFIG_ETC_ROMFS_PASSWD_HOME

The generated passwd entry is written into the ROMFS staging directory and included in the firmware image.

Behavior

Authentication disabled

  • No passwd generation occurs.
  • System behavior remains unchanged.

Authentication enabled

  • The build generates /etc/passwd automatically.
  • The password is hashed before being stored in the ROMFS image.
  • The plaintext password is never embedded in the firmware.

Password missing

  • If CONFIG_ETC_ROMFS_GENPASSWD=y but the password is empty, the build fails with an explicit error.

This ensures that credentials are always explicitly configured when authentication is enabled and prevents firmware images from being built with empty passwords.

Security Improvement

Previously /etc/passwd could be included as a static file in the ROMFS source tree.
With this change, the credentials are generated at build time and must be explicitly configured, avoiding implicit or default credentials in firmware images.

Testing

Generated passwd entry

image

Plaintext password check
image

(no output)

Build failure when password is empty

image

@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Area: Tooling Area: Build system Area: OS Components OS Components issues Board: risc-v Board: simulator Size: M The size of the change in this PR is medium labels Feb 15, 2026
@Abhishekmishra2808 Abhishekmishra2808 changed the title sched/nsh: Remove hard-coded default password and implement build-tim… sched/nsh: Remove Hard-coded Default Password (Security Fix for Issue #16822) Feb 15, 2026
@acassis
Copy link
Contributor

acassis commented Feb 15, 2026

@Abhishekmishra2808 the Documentation and the boardshould be (each one) in a separated. Normally we separate the logic implementation from the board support and Documentation.

@cederom
Copy link
Contributor

cederom commented Feb 15, 2026

Thank you @Abhishekmishra2808 :-)

  • I have updated description from "critical security vulnerability" to "improve security", as setting password is optional and user controllable, so it was always matter or user choice and decision what the password would be.. here we want to remove the default, correct?
  • Do you use AI for code and description generation?

@Abhishekmishra2808
Copy link
Author

Hi @cederom ,
Yes, the goal is to remove the default password from the defconfigs and avoid having any hardcoded credentials. Password generation should be explicitly enabled and configured by the user when needed.

I used AI tools only to help refine wording and improve clarity in the description, but the implementation, debugging, and testing were done by me.

@Abhishekmishra2808
Copy link
Author

@acassis I have fixed the changes suggested by you, and CI was failing because password generation was enabled in the defconfig files without setting a password. I have now removed CONFIG_ETC_ROMFS_GENPASSWD from the affected defconfigs so that password generation is not enabled by default. This ensures there is no default password while allowing users to explicitly enable and configure it if needed.

@Abhishekmishra2808 Abhishekmishra2808 changed the title sched/nsh: Remove Hard-coded Default Password (Security Fix for Issue #16822) sched/nsh: Remove Hard-coded Default Password Feb 15, 2026
@github-actions github-actions bot added the Size: L The size of the change in this PR is large label Mar 4, 2026
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

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

Thank you @Abhishekmishra2808 :-)

  • Thanks for updating the PR description to closed match the change, it looks a lot better now :-)
  • Please update "tools/mkpasswd: replace mkpasswd.py with C host tool" git commit title and body.
    • It does not match the content, it touches more things.
    • We did not have this tool before so we cannot reference it out of nowhere.
    • Looks like you were working directly from a master of your clone, and had your local changes over there, thus confusion. I can see you use working branch for the PR already, very good! This is why clone master should always resemble upstream master and then you work on your local branch to have a solid reference point :-)
  • Please update "sched: Remove hard-coded default password and add build-time generation" git commit title and body.
    • This is BOARD functionality but not SCHED as @xiaoxiang781216 noted :-)
    • Please describe other changes introduced in this commit.
  • As there is one functional change you can put all passwd related changes into one single commit. But we prefer having incremental changes, like tools/mkpasswd introduction into one commit, boards changes separate commit, documentation changes separate commit, etc :-)

@Abhishekmishra2808
Copy link
Author

@cederom! I've addressed the feedback

  • Moved the passwd generation config from sched/Kconfig to boards/Kconfig.
  • Renamed the option to CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE.
  • Updated references in boards/Board.mk and cmake/nuttx_add_romfs.cmake.
  • Split the changes into three commits: (noted this for future :) )
    1. tools/mkpasswd: add host tool for build-time passwd hashing
    2. boards: add CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE
    3. Documentation: describe build-time passwd generation

Documentation and commit messages were updated to clarify that /etc/passwd entries are generated at build time using TEA hashing.

Please let me know if anything else should be adjusted.

acassis
acassis previously approved these changes Mar 5, 2026
jerpelea
jerpelea previously approved these changes Mar 5, 2026
@Abhishekmishra2808 Abhishekmishra2808 dismissed stale reviews from jerpelea and acassis via f6a23b4 March 5, 2026 14:55
@simbit18
Copy link
Contributor

simbit18 commented Mar 5, 2026

@Abhishekmishra2808 please fix

../nuttx/tools/checkpatch.sh -c -u -m -g b3656d34b6f895076e5b91a8d167a23a870196ed..HEAD
❌ Commit subject missing colon (e.g. 'subsystem: msg')
❌ Missing Signed-off-by
❌ Commit subject missing colon (e.g. 'subsystem: msg')
❌ Missing Signed-off-by
Used config files:
    1: .codespellrc
Some checks failed. For contributing guidelines, see:
  https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md
Error: Process completed with exit code 1.

@Abhishekmishra2808
Copy link
Author

@simbit18 @acassis I have fixed the signed commit msg error, and now this PR is ready for the final review.

@Abhishekmishra2808 Abhishekmishra2808 force-pushed the Issue-16822 branch 2 times, most recently from 61dc245 to da1f7b4 Compare March 6, 2026 12:07
@Abhishekmishra2808
Copy link
Author

Abhishekmishra2808 commented Mar 6, 2026

CI turned red agaim ! :-(
@acassis, Is there something missing from my end or its failing on the main ?

@acassis
Copy link
Contributor

acassis commented Mar 6, 2026

CI turned red agaim ! :-( @acassis, Is there something missing from my end or its failing on the main ?

@Abhishekmishra2808 not, everything is fine, the error in the ESP32 is not related to this PR

@cederom
Copy link
Contributor

cederom commented Mar 6, 2026

Yup, CI needs a fix, will show up soon, guys are working on this already :-) #18501 (comment)

@acassis
Copy link
Contributor

acassis commented Mar 6, 2026

@Abhishekmishra2808 after the esp32 fix, please update your upstream branch and rebase your branch to it.

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

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

Very cool, thank you @Abhishekmishra2808, lets just wait with merge until CI is fixed :-)

@xiaoxiang781216 sources updated could you please take a look? :-)

@simbit18
Copy link
Contributor

simbit18 commented Mar 6, 2026

@Abhishekmishra2808 One question:
Has this change been tested on a board with Make and CMake?

@Abhishekmishra2808
Copy link
Author

@simbit18
Yes, tested on both build systems:
Make:

  • sim:nsh - baseline, no passwd feature
  • sim:login with BOARD_ETC_ROMFS_PASSWD_ENABLE=y - passwd file generated at build time: admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
  • stm32f4discovery:nsh - cross-compile with arm-none-eabi-gcc

CMake:

  • sim:nsh -baseline CMake/Ninja build
  • sim:login with BOARD_ETC_ROMFS_PASSWD_ENABLE=y - CMake passwd generation path

All 5 builds completed successfully. The mkpasswd host tool compiles and produces the correct 5-field passwd entry format, and empty passwords are correctly rejected at build time.

@acassis
Copy link
Contributor

acassis commented Mar 6, 2026

@Abhishekmishra2808 please update your upstream branch and rebase your branch to upstream

Add tools/mkpasswd.c, a self-contained C99 host tool that generates a
single /etc/passwd entry at build time.  The tool is invoked by the
board ROMFS build step when CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE is set.

The TEA encryption algorithm and custom base64 encoding match the
runtime implementations in:
  libs/libc/misc/lib_tea_encrypt.c
  apps/fsutils/passwd/passwd_encrypt.c
so passwords generated at build time are directly usable by the NuttX
login subsystem without any runtime re-hashing.  The plaintext password
is never stored in the firmware image.

Changes:
- tools/mkpasswd.c: new C host tool (pure C99, no external dependencies)
- tools/Makefile.host: add mkpasswd build rule
- tools/.gitignore: exclude compiled mkpasswd binary
- .gitignore: exclude etctmp/ (generated at build time, not to be committed)

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
…ation

Fixes apache#16822

Introduce CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE (and companion options
BOARD_ETC_ROMFS_PASSWD_USER/PASSWORD/UID/GID/HOME) in boards/Kconfig to
control build-time /etc/passwd generation.  Placing the option under
boards/ reflects that this is board-level functionality, not scheduler
functionality.

When BOARD_ETC_ROMFS_PASSWD_ENABLE=y the ROMFS build step calls
tools/mkpasswd to hash the configured plaintext password with TEA and
write the result into etctmp/<mountpoint>/passwd before genromfs packs
it into the ROMFS image.  The build fails if the password is left empty,
preventing firmware from shipping without credentials (CWE-798).

Changes:
- boards/Kconfig: new CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE option and
  companion BOARD_ETC_ROMFS_PASSWD_{USER,PASSWORD,UID,GID,HOME} options;
  depends on ETC_ROMFS
- boards/Board.mk: invoke tools/mkpasswd under BOARD_ETC_ROMFS_PASSWD_ENABLE
- cmake/nuttx_add_romfs.cmake: same guard for CMake builds
- boards/sim/sim/sim/src/{Makefile,CMakeLists.txt,etc/passwd}: remove
  static passwd file; let the build step generate it instead
- boards/risc-v/esp32c3-legacy/.../Make.defs,etc/passwd: same cleanup

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Add a central reference section in Documentation/components/tools/index.rst
that describes the build-time /etc/passwd generation mechanism:

- why it is needed (avoids hard-coded default password, CWE-798)
- how it works: tools/mkpasswd hashes the plaintext password with TEA,
  identical to the runtime algorithm in lib_tea_encrypt.c; the plaintext
  is never stored in firmware
- the Kconfig options to enable and configure it
  (CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE and companion options)
- the /etc/passwd file format
- step-by-step verification instructions

Update board-level documentation to reference the central section instead
of duplicating the explanation, and update all CONFIG_ names to the new
BOARD_ETC_ROMFS_PASSWD_* naming:

- Documentation/platforms/sim/sim/boards/sim/index.rst
- Documentation/platforms/renesas/rx65n/boards/rx65n-grrose/index.rst
- Documentation/platforms/risc-v/esp32c3-legacy/boards/esp32c3-legacy-devkit/ROMFS.txt

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Avoid hard-coded default password

8 participants