Bug 10346 - Default shell missing
Summary: Default shell missing
Status: ASSIGNED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: unspecified
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-26 10:37 UTC by Andrej Valek
Modified: 2018-02-08 11:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrej Valek 2017-09-26 10:37:29 UTC
When .config consists:
# CONFIG_ASH is not set
# CONFIG_HUSH is not set
# CONFIG_SH_IS_ASH is not set
# CONFIG_SH_IS_HUSH is not set
# CONFIG_SH_IS_NONE is not set

"make oldconfig" will automatically select ASH as default shell (default SH_IS_ASH).
Commit https://git.busybox.net/busybox/commit/shell/Config.src?id=0b8835861b2e43cb45becdb560877bcc89aea827 removed dependency on ASH | HUSH. Previous versions had dependencies to these options, so when ASH|HUSH option has not been selected, last option was CONFIG_SH_IS_NONE.

This makes problem with suid/nosuid split. It will automatically add "/bin/sh" into busybox.cfg.suid > busybox.links.suid . It means that /bin/sh wants to link to both busybox.suid and busybox.nosuid and when suid wins, default shell is undefined.

Option CONFIG_SH_IS_NONE=y needs to created in busybox.cfg.suid .
Comment 1 Denys Vlasenko 2017-10-04 09:09:49 UTC
(In reply to Andrej Valek from comment #0)
>This makes problem with suid/nosuid split. It will automatically add
>"/bin/sh" into busybox.cfg.suid > busybox.links.suid . It means that
>/bin/sh wants to link to both busybox.suid and busybox.nosuid
>and when suid wins, default shell is undefined.

I don't understand this part of problem description. What is the actual problem? I never used busybox.cfg.[no]suid myself, so please phrase your explanation keeping that in mind.
Comment 2 Andrej Valek 2017-10-04 12:09:15 UTC
(In reply to Denys Vlasenko from comment #1)
I will try to explain it more properly. This method is used in openmebeded.

process for reproduction
make busybox.cfg.suid - creates busybox.cfg.suid
make busybox.cfg.nosuid - busybox.cfg.nosuid

Each of configuration is run over with make oldconfig. It means that suid configuration has no shell, so ASH is automatically selected like a default. In nosuid configuration is ASH set.

Previous version selected CONFIG_SH_IS_NONE=y because of default.

This causes:
- /bin/sh in both suid and nosuid version (and obviously we don't want suid /bin/sh)
- suid version does have ash, however it is not set as default interpreter
Comment 3 Denys Vlasenko 2017-10-05 10:00:52 UTC
(In reply to Andrej Valek from comment #2)
>process for reproduction
>make busybox.cfg.suid - creates busybox.cfg.suid
>make busybox.cfg.nosuid - busybox.cfg.nosuid
>
>Each of configuration is run over with make oldconfig. It means that suid configuration has no shell, so ASH is automatically selected like a default. In nosuid configuration is ASH set.

Okay, I did this and I see this:

$ grep _ASH busybox.cfg.suid busybox.cfg.nosuid
busybox.cfg.nosuid:CONFIG_SH_IS_ASH

>This causes:
>- /bin/sh in both suid and nosuid version (and obviously we don't want suid /bin/sh)
>- suid version does have ash, however it is not set as default interpreter

I still don't understand. Your procedure generated which you say are problematic, I do not understand IN WHAT WAY they are problematic?
HOW are you using these files?

Let me try harder:
I never used busybox.cfg.[no]suid files myself.
Also, I am not good at reading minds. You need to walk me through the ENTIRE procedure which ends with a problem.
Comment 4 Andrej Valek 2017-10-05 13:26:59 UTC
(In reply to Denys Vlasenko from comment #3)
At first, this issue will occur only on no/suid busybox using with open-embedded. So I will try explain it with examples.

.config consist:
#
# Shells
#
CONFIG_SH_IS_ASH=y
# CONFIG_SH_IS_HUSH is not set
# CONFIG_SH_IS_NONE is not set
# CONFIG_BASH_IS_ASH is not set
# CONFIG_BASH_IS_HUSH is not set
CONFIG_BASH_IS_NONE=y
CONFIG_ASH=y

So ASH is going to be used like a default shell.

configure + compilation procedure:
make a backup copy of .config
$ cp .config .config.orig

create suid and nosuid configurations
$ make busybox.cfg.suid
list configs in suid
$ cat busybox.cfg.suid
CONFIG_LOGIN
CONFIG_PASSWD
CONFIG_SU
CONFIG_VLOCK
CONFIG_PING
CONFIG_PING6
CONFIG_TRACEROUTE

$ make busybox.cfg.nosuid
$ cat busybox.cfg.nosuid
...
CONFIG_SH_IS_ASH
CONFIG_ASH
...
As you can see, ASH is in nosuid.

# create list of disabled applets
>$ for i in `cat busybox.cfg.suid busybox.cfg.nosuid`; do echo "# $i is not set" >> .config.disable.apps; done
Now are all "is not set" configs in one file ".config.disable.apps"

# merge configurations
$ merge_config.sh -m .config.orig .config.disable.apps

$ cat .config
...
# CONFIG_SH_IS_HUSH is not set
# CONFIG_SH_IS_NONE is not set
# CONFIG_BASH_IS_ASH is not set
# CONFIG_BASH_IS_HUSH is not set
# CONFIG_SH_IS_ASH is not set
# CONFIG_ASH is not set
...
Now ASH is not set, so SH is not set too.

# create a copy of actual .config
$ cp .config .config.nonapps

# loop over items in .config and split them into no/suid
for s in suid nosuid; do
	cat busybox.cfg.$s | while read item; do
		grep -w "$item" .config.orig
	done > .config.app.$s

# continue for suid
$ cat .config.app.suid
CONFIG_LOGIN=y
CONFIG_PASSWD=y
CONFIG_SU=y
CONFIG_VLOCK=y
CONFIG_PING=y
CONFIG_PING6=y
CONFIG_TRACEROUTE=y
So CONFIG_SH_IS_ASH is not mentioned here, what is ok. But CONFIG_SH_IS_NONE=y is missing.

# merge configurations
$ merge_config.sh -m .config.nonapps .config.app.suid
$ cat .config
...
# CONFIG_SH_IS_HUSH is not set
# CONFIG_SH_IS_NONE is not set
# CONFIG_BASH_IS_ASH is not set
# CONFIG_BASH_IS_HUSH is not set
CONFIG_BASH_IS_NONE=y
# CONFIG_SH_IS_ASH is not set
# CONFIG_ASH is not set
...
So ASH is not set.

# Now build the busybox. So it's seems to be, that ASH is not set, so default shell is none.
$ make busybox_unstripped
 # generate build files
 - ./scripts/gen_build_files.sh busybox busybox
 - # ! problem is here, create oldconfig
  - make -f Makefile V=1 oldconfig
>*
>* Shells
>*
>Choose which shell is aliased to 'sh' name
>> 1. ash (SH_IS_ASH)
>  2. hush (SH_IS_HUSH)
>  3. none (SH_IS_NONE)
>choice[1-3?]: 1
>Choose which shell is aliased to 'bash' name
>  1. ash (BASH_IS_ASH)
>  2. hush (BASH_IS_HUSH)
>> 3. none (BASH_IS_NONE)
>choice[1-3?]: 3
>!!!! ash (ASH) [N/y/?] n <---- it was selected automatically without dependency checking
>  Optimize for size instead of speed (ASH_OPTIMIZE_FOR_SIZE) [Y/n] y
>  Use internal glob() implementation (ASH_INTERNAL_GLOB) [Y/n/?] y
>  bash-compatible extensions (ASH_BASH_COMPAT) [Y/n] y
>  Job control (ASH_JOB_CONTROL) [Y/n] y
>  Alias support (ASH_ALIAS) [Y/n] y
>  Pseudorandom generator and $RANDOM variable (ASH_RANDOM_SUPPORT) [N/y/?] n
>  Expand prompt string (ASH_EXPAND_PRMT) [Y/n/?] y
>  Idle timeout variable $TMOUT (ASH_IDLE_TIMEOUT) [N/y/?] n
>  Check for new mail in interactive shell (ASH_MAIL) [N/y/?] n
>  echo builtin (ASH_ECHO) [Y/n] y
>  printf builtin (ASH_PRINTF) [Y/n] y
>  test builtin (ASH_TEST) [Y/n] y
>  help builtin (ASH_HELP) [Y/n] y
>  getopts builtin (ASH_GETOPTS) [Y/n] y
>  command builtin (ASH_CMDCMD) [Y/n/?] y
... continue in building process
$ mv busybox_unstripped busybox.suid

$ make busybox.links
# list created links
$ cat busybox.links.suid
/bin/ping
/bin/ping6
/bin/login
/bin/mount
/usr/bin/passwd
/bin/sh <--- what is wrong
/bin/su
/usr/bin/traceroute
/usr/bin/traceroute6
/usr/bin/vlock


Same process for busybox.nosuid, but SH_IS_ASH was set correctly.
$ cat busybox.links.nosuid
...
/bin/sh
...
So links are on both file, what is wrong. Default shell is not set. It reflect to, that scripts without shebang could not be run.

Version before the mentioned commit was depending on CONFIG_ASH and if SH_IS_xxx was not set, the default was SH_IS_NONE=y. It created a link only in explicit selected shell.
Comment 5 Andrej Valek 2018-02-08 11:01:33 UTC
Are there any news?