Busybox sleep 0.5 crashed Ash (but not Bash)

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Tue Mar 05, 2024 8:25    Post subject: Busybox sleep 0.5 crashed Ash (but not Bash) Reply with quote
What happen if you execute the following command in a shell(not Admin->Commands)? Did it crash the shell?? Smile
Code:
# sleep 0.5
sh: invalid number '0.5'
Connection to 192.168.1.1 closed.

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw


Last edited by mwchang on Wed Mar 06, 2024 8:10; edited 1 time in total
Sponsor
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1959

PostPosted: Tue Mar 05, 2024 14:59    Post subject: Reply with quote
No, sleep uses whole numbers.

https://busybox.net/downloads/BusyBox.html#sleep

https://www.man7.org/linux/man-pages/man1/sleep.1.html

https://www.man7.org/linux/man-pages/man3/sleep.3.html

You probably kicked yourself out.

_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Wed Mar 06, 2024 5:01    Post subject: Reply with quote
dale_gribble39 wrote:
No, sleep uses whole numbers.
...
You probably kicked yourself out.

I know sleep needs integers. But that shouldn't have killed the shell session! The Busybox in DD-WRT should have just reported an error and exited gracefully, not exiting the Ash shell.

BTW, I did NOT press the wrong key to "kick...out" myself. It happened just after I entered "sleep 0.5"!

Update:

For the sake of curiosity, Bash did NOT "kick...out" me! I wish this would not become an exploit! Smile
Code:
# echo $0
-sh
# bash
# sleep 0.5
sleep: invalid number '0.5'
# echo $0
bash
# exit
exit
# echo $0
-sh
# sleep 0.5
sh: invalid number '0.5'
Connection to 192.168.1.1 closed.


I opned a ticket anyway.

#7742 (Busybox command 'sleep 0.5' crashed Ash shell but not Bash shell) – DD-WRT
https://svn.dd-wrt.com/ticket/7742#ticket

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
ArjenR49
DD-WRT Guru


Joined: 05 Oct 2008
Posts: 666
Location: Helsinki, Finland / nr. Alkmaar, Netherlands

PostPosted: Wed Mar 06, 2024 9:44    Post subject: Reply with quote
The Netgear XR500 is not a broadcom router, but it exhibits similar behaviour (build 55262). The initial shell is ash (per the banner announcement) and sleep with an invalid argument reports the invalid argument and the session ends right away.
There is apparently no bash, but if you invoke ash in the ssh session, it reports the invalid argument and does not crash.
...
DD-WRT v3.0-r55262 std (c) 2024 NewMedia-NET GmbH
Release: 03/03/24
Board: Netgear XR500
...
==========================================================


BusyBox v1.36.1 (2024-03-03 04:07:01 +07) built-in shell (ash)

root@XR500:~# echo $0
-sh
root@XR500:~# sleep 0.5
sh: invalid number '0.5'
Connection to xr500.arnet closed.

New session:
arjen@NUC10i5:~$ ssh -o VisualHostKey=yes root@xr500.arnet
...
BusyBox v1.36.1 (2024-03-03 04:07:01 +07) built-in shell (ash)

root@XR500:~# echo $0
-sh
root@XR500:~# bash
-sh: bash: not found
root@XR500:~# ash


BusyBox v1.36.1 (2024-03-03 04:07:01 +07) built-in shell (ash)

root@XR500:~# echo $0
ash
root@XR500:~# sleep 0.5
ash: invalid number '0.5'
root@XR500:~#


The banner says ash, echo $0 reports -sh, but upon the second invocation echo $0 reports ash and so does the error message.
Apparently not all ashes are the same, though.

EDIT: On second thoughts it is likely that in the latter test, where the session didn't end, the sleep command error ended the ash shell invoked from the command line, but as this was not the 'outermost' shell, the ssh session to the router didn't end.

The original bug remains in that the command which produces the error, obviously crashes the shell in addition to printing an error message.


Last edited by ArjenR49 on Wed Mar 06, 2024 12:36; edited 1 time in total
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Wed Mar 06, 2024 10:50    Post subject: Reply with quote
ArjenR49 wrote:
There is apparently no bash, but if you invoke ash in the ssh session, it reports the invalid argument and does not crash.

My Bash comes from Entware. FYI, Bash is the standard shell for most Linux distributions.

bash linux distribution - Google Search
https://www.google.com/search?q=bash+linux+distribution
Quote:
The banner says ash, echo $0 reports -sh, but upon the second invocation echo $0 reports ash and so does the error message.
Apparently not all ashes are the same, though.

I always thought that Busybox's shell was a fully functional Ash shell. Maybe it's wrong. Smile

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12921
Location: Netherlands

PostPosted: Wed Mar 06, 2024 11:13    Post subject: Reply with quote
ash is not bash
_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Wed Mar 06, 2024 11:43    Post subject: Reply with quote
egc wrote:
ash is not bash

Knew that, but thanks!

Almquist shell - Wikipedia
https://en.wikipedia.org/wiki/Almquist_shell
Quote:
History

ash was first released via a posting to the comp.sources.unix Usenet news group, approved and moderated by Rich Salz on 30 May 1989. It was described as "a reimplementation of the System V shell [with] most features of that shell, plus some additions".[1]

.... more ....

Dash

In 1997 Herbert Xu ported ash from NetBSD to Debian Linux. In September 2002, with release 0.4.1, this port was renamed to Dash (Debian Almquist shell). Xu's main priorities are POSIX conformance and slim implementation.[2]

... more ....

Embedded Linux

Ash (mainly the Dash fork) is also fairly popular in embedded Linux systems. Dash version 0.3.8-5 was incorporated into BusyBox, the catch-all executable often employed in this area, and is used in distributions like DSLinux, Alpine Linux, Tiny Core Linux and Linux-based router firmware such as OpenWrt, Tomato and DD-WRT.

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1959

PostPosted: Wed Mar 06, 2024 16:18    Post subject: Reply with quote
It's not a bug. It's not supported.

https://svn.dd-wrt.com/browser/src/router/busybox/shell/Config.src

https://svn.dd-wrt.com/browser/src/router/rules/busybox.mk

_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 373

PostPosted: Wed Mar 06, 2024 21:22    Post subject: Reply with quote
Log a bug in busybox bug tracking. I used to be on the busybox mailing list and people are constantly finding things that fail in ash and some get fixed. Keep in mind that busybox focuses on small size and efficiency not completeness.
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Thu Mar 07, 2024 11:28    Post subject: Reply with quote
yoyoma2 wrote:
Log a bug in busybox bug tracking. I used to be on the busybox mailing list and people are constantly finding things that fail in ash and some get fixed. Keep in mind that busybox focuses on small size and efficiency not completeness.

I know this. But you don't have to abort the shell because of a "." in an optional parameter. Just exit the program with an error message plus an error code, and return control to the shell.

However, I am not sure whether it's DD-WRT or Busybox responsibility. Smile

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 3006
Location: Germany

PostPosted: Thu Mar 07, 2024 12:30    Post subject: Reply with quote
This also works with "sleep --help"

Under OpenWRT there are no problems with the same busybox version.

So it is unclear what exactly the problem is.

_________________
Quickstart guides:
use Pi-Hole as simple DNS-Server with DD-WRT
VLAN configuration via GUI - 1 CPU port
VLAN configuration via GUI - 2 CPU ports (R7800, EA8500 etc)

Routers
Marvell OCTEON TX2 - QHora-322 - OpenWrt 23.05.3 - Gateway
Qualcomm IPQ8065 - R7800 - DD-WRT - WAP
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Fri Mar 08, 2024 3:24    Post subject: Reply with quote
ArjenR49 wrote:
New session:
arjen@NUC10i5:~$ ssh -o VisualHostKey=yes root@xr500.arnet
...
BusyBox v1.36.1 (2024-03-03 04:07:01 +07) built-in shell (ash)

root@XR500:~# echo $0
-sh
root@XR500:~# bash
-sh: bash: not found
root@XR500:~# ash


BusyBox v1.36.1 (2024-03-03 04:07:01 +07) built-in shell (ash)

root@XR500:~# echo $0
ash
root@XR500:~# sleep 0.5
ash: invalid number '0.5'
root@XR500:~#

I didn't think of this self-invocation test, Master! Thanks!

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Mon Mar 11, 2024 12:55    Post subject: Reply with quote
ArjenR49 wrote:
EDIT: On second thoughts it is likely that in the latter test, where the session didn't end, the sleep command error ended the ash shell invoked from the command line, but as this was not the 'outermost' shell, the ssh session to the router didn't end.

The original bug remains in that the command which produces the error, obviously crashes the shell in addition to printing an error message.

So I tried setting the base shell to Bash in /tmp/etc/passwd, and this was what happened:
Code:
-bash-5.2# echo $0
-bash
-bash-5.2# sh


BusyBox v1.36.1 (2024-03-03 04:49:40 +06) built-in shell (ash)

~ # echo $0
sh
~ # sleep 0.5
sh: invalid number '0.5'
-bash-5.2# echo $0
-bash
-bash-5.2#

Unrelated:

Setting shell to /opt/bin/bash can break scripts written for Busybox Ash, badly! You need to be careful of commands in /usr/bin vs /opt/bin because of $PATH changes in /opt/etc/profile vs /etc/profile!

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
lazardo
DD-WRT User


Joined: 17 Apr 2014
Posts: 140
Location: SF Bay Area

PostPosted: Sat Mar 16, 2024 6:50    Post subject: Reply with quote
Code:
ssh dd-wrt "nvram get os_version; date; for i in 1 2 3 4 5 6 7 8 9 0; do usleep 100000; done; date"
53633
Fri Mar 15 23:48:55 PDT 2024
Fri Mar 15 23:48:56 PDT 2024
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Sat Mar 16, 2024 9:48    Post subject: Reply with quote
lazardo wrote:
Code:
ssh dd-wrt "nvram get os_version; date; for i in 1 2 3 4 5 6 7 8 9 0; do usleep 100000; done; date"

usleep!? Thanks... at least a dot didn't cause a shell crash.
Code:
# echo $0
-sh
# usleep 0.5
usleep: invalid number '0.5'
# echo $0
-sh
#
# usleep 5 ; echo $?
0
# usleep 0.5 ; echo $?
usleep: invalid number '0.5'
1
# echo $0
-sh

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum