|
| 1 | +From 46496da2ec13ac56b7aa687832f0a3bb355361ab Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sanghyun Park <sanghyun.park.cnu@gmail.com> |
| 3 | +Date: Mon, 20 Jul 2026 06:28:50 +0000 |
| 4 | +Subject: [PATCH] CVE-2026-38755 |
| 5 | + |
| 6 | +Recursive shell functions can repeatedly enter evalfun() until the |
| 7 | +process stack is exhausted. Track active shell function calls and raise a |
| 8 | +normal shell error when the recursion limit is reached. |
| 9 | + |
| 10 | +The counter is decremented through the existing funcdone cleanup path so |
| 11 | +errors raised from inside the function body unwind it correctly. |
| 12 | + |
| 13 | +Signed-off-by: Sanghyun Park <sanghyun.park.cnu@gmail.com> |
| 14 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 15 | +Upstream-reference: https://lists.busybox.net/pipermail/busybox/2026-June/092354.html |
| 16 | +--- |
| 17 | + shell/ash.c | 8 ++++++++ |
| 18 | + 1 file changed, 8 insertions(+) |
| 19 | + |
| 20 | +diff --git a/shell/ash.c b/shell/ash.c |
| 21 | +index 7bdd5f0..974fb57 100644 |
| 22 | +--- a/shell/ash.c |
| 23 | ++++ b/shell/ash.c |
| 24 | +@@ -402,6 +402,7 @@ struct globals_misc { |
| 25 | + int shlvl; |
| 26 | + #define rootshell (!shlvl) |
| 27 | + int errlinno; |
| 28 | ++ unsigned func_depth; |
| 29 | + |
| 30 | + char *minusc; /* argument to -c option */ |
| 31 | + |
| 32 | +@@ -489,6 +490,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; |
| 33 | + #define rootpid (G_misc.rootpid ) |
| 34 | + #define shlvl (G_misc.shlvl ) |
| 35 | + #define errlinno (G_misc.errlinno ) |
| 36 | ++#define func_depth (G_misc.func_depth ) |
| 37 | + #define minusc (G_misc.minusc ) |
| 38 | + #define curdir (G_misc.curdir ) |
| 39 | + #define physdir (G_misc.physdir ) |
| 40 | +@@ -9930,6 +9932,10 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) |
| 41 | + int savefuncline; |
| 42 | + char *savefuncname; |
| 43 | + char *savetrap = NULL; |
| 44 | ++ enum { MAX_ASH_FUNC_DEPTH = 1000 }; |
| 45 | ++ |
| 46 | ++ if (func_depth >= MAX_ASH_FUNC_DEPTH) |
| 47 | ++ ash_msg_and_raise_error("function recursion limit exceeded"); |
| 48 | + |
| 49 | + if (!Eflag) { |
| 50 | + savetrap = trap[NTRAP_ERR]; |
| 51 | +@@ -9948,6 +9954,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) |
| 52 | + exception_handler = &jmploc; |
| 53 | + shellparam.malloced = 0; |
| 54 | + func->count++; |
| 55 | ++ func_depth++; |
| 56 | + funcname = func->n.ndefun.text; |
| 57 | + funcline = func->n.ndefun.linno; |
| 58 | + INT_ON; |
| 59 | +@@ -9969,6 +9976,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) |
| 60 | + } |
| 61 | + funcline = savefuncline; |
| 62 | + lineno = savelineno; |
| 63 | ++ func_depth--; |
| 64 | + freefunc(func); |
| 65 | + freeparam(&shellparam); |
| 66 | + shellparam = saveparam; |
| 67 | +-- |
| 68 | +2.45.4 |
| 69 | + |
0 commit comments