-
Notifications
You must be signed in to change notification settings - Fork 1.5k
sched/nsh: Remove Hard-coded Default Password #18396
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?
Changes from all commits
cebde41
e6f4cb5
4585eb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| *.dSYM | ||
| *.elf | ||
| *.exe | ||
| etctmp/ | ||
| *.gcno | ||
| *.gcda | ||
| *.hex | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,11 +30,35 @@ $(RCOBJS): $(ETCDIR)$(DELIM)%: % | |
| $(Q) mkdir -p $(dir $@) | ||
| $(call PREPROCESS, $<, $@) | ||
|
|
||
| $(ETCSRC): $(foreach raw,$(RCRAWS), $(if $(wildcard $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw)), $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw), $(if $(wildcard $(BOARD_COMMON_DIR)$(DELIM)$(raw)), $(BOARD_COMMON_DIR)$(DELIM)$(raw), $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw)))) $(RCOBJS) | ||
| $(ETCSRC): $(foreach raw,$(RCRAWS), $(if $(wildcard $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw)), $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw), $(if $(wildcard $(BOARD_COMMON_DIR)$(DELIM)$(raw)), $(BOARD_COMMON_DIR)$(DELIM)$(raw), $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw)))) $(RCOBJS) $(TOPDIR)$(DELIM).config $(TOPDIR)$(DELIM)tools$(DELIM)mkpasswd.c | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need add the dependence, since you build mkpasswd in action manually |
||
| $(foreach raw, $(RCRAWS), \ | ||
| $(shell rm -rf $(ETCDIR)$(DELIM)$(raw)) \ | ||
| $(shell mkdir -p $(dir $(ETCDIR)$(DELIM)$(raw))) \ | ||
| $(shell cp -rfp $(if $(wildcard $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw)), $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw), $(if $(wildcard $(BOARD_COMMON_DIR)$(DELIM)$(raw)), $(BOARD_COMMON_DIR)$(DELIM)$(raw), $(BOARD_DIR)$(DELIM)src$(DELIM)$(raw))) $(ETCDIR)$(DELIM)$(raw))) | ||
| ifeq ($(CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE),y) | ||
| ifeq ($(CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD),) | ||
| $(error CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD must be set when BOARD_ETC_ROMFS_PASSWD_ENABLE is enabled. Run 'make menuconfig' to set a password.) | ||
| endif | ||
| ifeq ($(CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD),"") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the check since mkpasswd already do the check
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the idea here is to verify if the user defined the password in the "menuconfig"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mkpasswd already check it, why dup the check in many places
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, maybe keeping the testing only is mkpasswd is enough, but we need to understand where is better to report the error. I think failing early is better to let user to fix the issue. @Abhishekmishra2808 please comment your idea here |
||
| $(error CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD must be set when BOARD_ETC_ROMFS_PASSWD_ENABLE is enabled. Run 'make menuconfig' to set a password.) | ||
| endif | ||
| $(Q) if [ ! -f $(TOPDIR)$(DELIM)tools$(DELIM)mkpasswd$(HOSTEXEEXT) ] || \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why need change the existence of mkpasswd? make will do it automatically |
||
| [ $(TOPDIR)$(DELIM)tools$(DELIM)mkpasswd.c -nt $(TOPDIR)$(DELIM)tools$(DELIM)mkpasswd$(HOSTEXEEXT) ]; then \ | ||
| $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mkpasswd$(HOSTEXEEXT); \ | ||
| fi | ||
| $(Q) mkdir -p $(ETCDIR)$(DELIM)$(CONFIG_ETC_ROMFSMOUNTPT) | ||
| $(Q) $(TOPDIR)$(DELIM)tools$(DELIM)mkpasswd$(HOSTEXEEXT) \ | ||
| --user $(CONFIG_BOARD_ETC_ROMFS_PASSWD_USER) \ | ||
| --password $(CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD) \ | ||
| --uid $(CONFIG_BOARD_ETC_ROMFS_PASSWD_UID) \ | ||
| --gid $(CONFIG_BOARD_ETC_ROMFS_PASSWD_GID) \ | ||
| --home $(CONFIG_BOARD_ETC_ROMFS_PASSWD_HOME) \ | ||
| $(if $(CONFIG_FSUTILS_PASSWD_KEY1),--key1 $(CONFIG_FSUTILS_PASSWD_KEY1)) \ | ||
| $(if $(CONFIG_FSUTILS_PASSWD_KEY2),--key2 $(CONFIG_FSUTILS_PASSWD_KEY2)) \ | ||
| $(if $(CONFIG_FSUTILS_PASSWD_KEY3),--key3 $(CONFIG_FSUTILS_PASSWD_KEY3)) \ | ||
| $(if $(CONFIG_FSUTILS_PASSWD_KEY4),--key4 $(CONFIG_FSUTILS_PASSWD_KEY4)) \ | ||
| -o $(ETCDIR)$(DELIM)$(CONFIG_ETC_ROMFSMOUNTPT)$(DELIM)passwd | ||
| endif | ||
| $(Q) genromfs -f romfs.img -d $(ETCDIR)$(DELIM)$(CONFIG_ETC_ROMFSMOUNTPT) -V "NSHInitVol" | ||
| $(Q) echo "#include <nuttx/compiler.h>" > $@ | ||
| $(Q) xxd -i romfs.img | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >> $@ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5423,3 +5423,53 @@ config BOARD_MEMORY_RANGE | |
| end: end address of memory range | ||
| flags: Executable 0x1, Writable 0x2, Readable 0x4 | ||
| example:{0x1000,0x2000,0x4},{0x2000,0x3000,0x6},{0x3000,0x4000,0x7} ... {0x0,0x0,0x0} | ||
|
|
||
| config BOARD_ETC_ROMFS_PASSWD_ENABLE | ||
| bool "Auto-generate /etc/passwd at build time" | ||
| default n | ||
| depends on ETC_ROMFS | ||
| ---help--- | ||
| Generate the /etc/passwd file at build time from a user-supplied | ||
| password. This avoids shipping a hard-coded default password | ||
| (CWE-798). When enabled, the build will fail if no password | ||
| is configured, forcing each build to set its own credentials. | ||
|
|
||
| The password is hashed at build time by the host tool | ||
| tools/mkpasswd (compiled from tools/mkpasswd.c) using the Tiny | ||
| Encryption Algorithm (TEA) — the same algorithm used at runtime | ||
| in libs/libc/misc/lib_tea_encrypt.c. The plaintext password is | ||
| never stored in the firmware image. | ||
|
|
||
| See Documentation/components/passwd_autogen.rst for details. | ||
|
|
||
| if BOARD_ETC_ROMFS_PASSWD_ENABLE | ||
|
|
||
| config BOARD_ETC_ROMFS_PASSWD_USER | ||
| string "Admin username" | ||
| default "admin" | ||
| ---help--- | ||
| The username for the auto-generated /etc/passwd entry. | ||
|
|
||
| config BOARD_ETC_ROMFS_PASSWD_PASSWORD | ||
| string "Admin password (required)" | ||
| default "" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the default value
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the test to verify if the user defined a password is used, I think the default password needs to be defined here as empty, so seems correct, isn't it? |
||
| ---help--- | ||
| The plaintext password for the auto-generated /etc/passwd entry. | ||
| This value is hashed with TEA at build time; the plaintext is NOT | ||
| stored in the firmware image. The build will fail if this is left | ||
| empty or shorter than 8 characters. Set this via | ||
| 'make menuconfig'. | ||
|
|
||
| config BOARD_ETC_ROMFS_PASSWD_UID | ||
| int "Admin user ID" | ||
| default 0 | ||
|
|
||
| config BOARD_ETC_ROMFS_PASSWD_GID | ||
| int "Admin group ID" | ||
| default 0 | ||
|
|
||
| config BOARD_ETC_ROMFS_PASSWD_HOME | ||
| string "Admin home directory" | ||
| default "/" | ||
|
|
||
| endif # BOARD_ETC_ROMFS_PASSWD_ENABLE | ||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abhishekmishra2808 could you please add at the end of this Documentation explaining that to avoid leaking user password (CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD) and keys (CONFIG_FSUTILS_PASSWD_KEY1-4) when user run "make savedefconfig" it will not be saved in the defconfig. And if the user needs it in their local defconfig they need to add it manually in their defconfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks- addressed this in the latest commit.