Compare commits

...

11 Commits

Author SHA1 Message Date
openeuler-ci-bot
e069d530c5
!149 [sync] PR-147: fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-11-15 08:23:49 +00:00
liuxu
609583e36a fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366
Signed-off-by: liuxu <liuxu156@huawei.com>
(cherry picked from commit 7d017232adb7e2f41a583896cda027b95a1d5cbd)
2024-11-15 15:50:36 +08:00
openeuler-ci-bot
8f60779e0b
!132 [sync] PR-128: fix CVE-2023-42363
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-07-24 09:22:23 +00:00
liuxu
6b3858ecdb fix CVE-2023-42363
Signed-off-by: liuxu <liuxu156@huawei.com>
(cherry picked from commit abc2598ec43a41ef38d68ebb18c356955fe9927a)
2024-07-22 15:40:03 +08:00
openeuler-ci-bot
157bde01ba
!123 [sync] PR-120: revert fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366 CVE-2023-42363
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-07-01 02:21:09 +00:00
liuxu
9955388acb revert fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366 CVE-2023-42363
Signed-off-by: liuxu <liuxu156@huawei.com>
(cherry picked from commit 7564944a90c9819e89a1966e177439da6116d686)
2024-07-01 09:26:58 +08:00
openeuler-ci-bot
64777734b3
!118 [sync] PR-114: fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366 CVE-2023-42363
From: @openeuler-sync-bot 
Reviewed-by: @xuxuepeng 
Signed-off-by: @xuxuepeng
2024-06-20 02:01:17 +00:00
liuxu
7725ff0c68 fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366 CVE-2023-42363
Signed-off-by: liuxu <liuxu156@huawei.com>
(cherry picked from commit d635a4264d050b64722ddafcc348cac0a0773b25)
2024-06-19 17:07:26 +08:00
openeuler-ci-bot
bbad932343
!107 sync CVE-2022-48174
From: @liuxu180400617 
Reviewed-by: @flyflyflypeng 
Signed-off-by: @flyflyflypeng
2023-11-29 09:21:41 +00:00
openeuler-ci-bot
e36fcd96ea
!106 [sync] PR-102: re-fixed CVE-2022-48174
From: @openeuler-sync-bot 
Reviewed-by: @duguhaotian 
Signed-off-by: @duguhaotian
2023-08-31 06:38:41 +00:00
songbuhuang
24b63f5848 re-fixed CVE-2022-48174
Signed-off-by: songbuhuang <544824346@qq.com>
(cherry picked from commit 41ced1d003c6c513daa3d7d953d5cc20a5c2cc4e)
2023-08-31 14:21:10 +08:00
5 changed files with 388 additions and 14 deletions

View File

@ -1,27 +1,77 @@
From ba44d48bec1ced7d7706d84da33a5976f1d8c3cb Mon Sep 17 00:00:00 2001
From 4bfb95d9c2f8f80cc2d1e282823ce49c25f7e784 Mon Sep 17 00:00:00 2001
From: songbuhuang <544824346@qq.com>
Date: Wed, 30 Aug 2023 11:55:40 +0800
Date: Thu, 31 Aug 2023 12:08:23 +0800
Subject: [PATCH] fix CVE-2022-48174
Signed-off-by: songbuhuang <544824346@qq.com>
---
shell/math.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
shell/math.c | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/shell/math.c b/shell/math.c
index 2942cdd..8835e90 100644
index 2942cdd..e9bd62b 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -593,7 +593,8 @@ evaluate_string(arith_state_t *math_state, const char *expr)
/* The proof that there can be no more than strlen(startbuf)/2+1
* integers in any given correct or incorrect expression
* is left as an exercise to the reader. */
- var_or_num_t *const numstack = alloca((expr_len / 2) * sizeof(numstack[0]));
+ /* Counterexample: 09J results in three integers. */
+ var_or_num_t *const numstack = alloca((expr_len - 2) * sizeof(numstack[0]));
@@ -582,6 +582,28 @@ static arith_t strto_arith_t(const char *nptr, char **endptr)
# endif
#endif
+//TODO: much better estimation than expr_len/2? Such as:
+//static unsigned estimate_nums_and_names(const char *expr)
+//{
+// unsigned count = 0;
+// while (*(expr = skip_whitespace(expr)) != '\0') {
+// const char *p;
+// if (isdigit(*expr)) {
+// while (isdigit(*++expr))
+// continue;
+// count++;
+// continue;
+// }
+// p = endofname(expr);
+// if (p != expr) {
+// expr = p;
+// count++;
+// continue;
+// }
+// }
+// return count;
+//}
+
static arith_t
evaluate_string(arith_state_t *math_state, const char *expr)
{
@@ -589,10 +611,12 @@ evaluate_string(arith_state_t *math_state, const char *expr)
const char *errmsg;
const char *start_expr = expr = skip_whitespace(expr);
unsigned expr_len = strlen(expr) + 2;
- /* Stack of integers */
- /* The proof that there can be no more than strlen(startbuf)/2+1
- * integers in any given correct or incorrect expression
- * is left as an exercise to the reader. */
+ /* Stack of integers/names */
+ /* There can be no more than strlen(startbuf)/2+1
+ * integers/names in any given correct or incorrect expression.
+ * (modulo "09v09v09v09v09v" case,
+ * but we have code to detect that early)
+ */
var_or_num_t *const numstack = alloca((expr_len / 2) * sizeof(numstack[0]));
var_or_num_t *numstackptr = numstack;
/* Stack of operator tokens */
operator *const stack = alloca(expr_len * sizeof(stack[0]));
@@ -661,6 +685,13 @@ evaluate_string(arith_state_t *math_state, const char *expr)
numstackptr->var = NULL;
errno = 0;
numstackptr->val = strto_arith_t(expr, (char**) &expr);
+ /* A number can't be followed by another number, or a variable name.
+ * We'd catch this later anyway, but this would require numstack[]
+ * to be twice as deep to handle strings where _every_ char is
+ * a new number or name. Example: 09v09v09v09v09v09v09v09v09v
+ */
+ if (isalnum(*expr) || *expr == '_')
+ goto err;
if (errno)
numstackptr->val = 0; /* bash compat */
goto num;
--
2.26.2

View File

@ -0,0 +1,60 @@
From 695db66d27d4dd9b6ec554e49b34903256dd38ed Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Mon, 22 Jul 2024 11:43:51 +0800
Subject: [PATCH] fix CVE-2023-42363
backport from upstream:
https://git.busybox.net/busybox/commit/editors/awk.c?id=fb08d43d44d1fea1f741fafb9aa7e1958a5f69aa
Signed-off-by: liuxu <liuxu156@huawei.com>
---
editors/awk.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/editors/awk.c b/editors/awk.c
index 6a5846e..c202de3 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2889,19 +2889,14 @@ static var *evaluate(node *op, var *res)
if ((opinfo & OF_REQUIRED) && !op1)
syntax_error(EMSG_TOO_FEW_ARGS);
L.v = evaluate(op1, TMPVAR0);
- if (opinfo & OF_STR1) {
- L.s = getvar_s(L.v);
- debug_printf_eval("L.s:'%s'\n", L.s);
- }
if (opinfo & OF_NUM1) {
L_d = getvar_i(L.v);
debug_printf_eval("L_d:%f\n", L_d);
}
}
- /* NB: Must get string/numeric values of L (done above)
- * _before_ evaluate()'ing R.v: if both L and R are $NNNs,
- * and right one is large, then L.v points to Fields[NNN1],
- * second evaluate() reallocates and moves (!) Fields[],
+ /* NB: if both L and R are $NNNs, and right one is large,
+ * then at this pint L.v points to Fields[NNN1], second
+ * evaluate() below reallocates and moves (!) Fields[],
* R.v points to Fields[NNN2] but L.v now points to freed mem!
* (Seen trying to evaluate "$444 $44444")
*/
@@ -2914,6 +2909,16 @@ static var *evaluate(node *op, var *res)
debug_printf_eval("R.s:'%s'\n", R.s);
}
}
+ /* Get L.s _after_ R.v is evaluated: it may have realloc'd L.v
+ * so we must get the string after "old_Fields_ptr" correction
+ * above. Testcase: x = (v = "abc", gsub("b", "X", v));
+ */
+ if (opinfo & OF_RES1) {
+ if (opinfo & OF_STR1) {
+ L.s = getvar_s(L.v);
+ debug_printf_eval("L.s:'%s'\n", L.s);
+ }
+ }
debug_printf_eval("switch(0x%x)\n", XC(opinfo & OPCLSMASK));
switch (XC(opinfo & OPCLSMASK)) {
--
2.43.0

View File

@ -0,0 +1,197 @@
From 36738cfb66629b94f1594857d50cd57411a61a72 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Thu, 14 Nov 2024 16:00:16 +0800
Subject: [PATCH] awk: fix precedence of = relative to == Discovered while
adding code to disallow assignments to non-lvalues
Conflict:Yes
Reference:https://git.busybox.net/busybox/diff/?id=0256e00a9d077588bd3a39f5a1ef7e2eaa2911e4
function old new delta
parse_expr 936 991 +55
.rodata 105243 105247 +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0) Total: 59 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
editors/awk.c | 66 ++++++++++++++++++++++++++++++---------------
testsuite/awk.tests | 5 ++++
2 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/editors/awk.c b/editors/awk.c
index d65352e..3f6ad97 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -337,7 +337,9 @@ static void debug_parse_print_tc(uint32_t n)
#undef P
#undef PRIMASK
#undef PRIMASK2
-#define P(x) (x << 24)
+/* Smaller 'x' means _higher_ operator precedence */
+#define PRECEDENCE(x) (x << 24)
+#define P(x) PRECEDENCE(x)
#define PRIMASK 0x7F000000
#define PRIMASK2 0x7E000000
@@ -360,7 +362,7 @@ enum {
OC_MOVE = 0x1f00, OC_PGETLINE = 0x2000, OC_REGEXP = 0x2100,
OC_REPLACE = 0x2200, OC_RETURN = 0x2300, OC_SPRINTF = 0x2400,
OC_TERNARY = 0x2500, OC_UNARY = 0x2600, OC_VAR = 0x2700,
- OC_DONE = 0x2800,
+ OC_CONST = 0x2800, OC_DONE = 0x2900,
ST_IF = 0x3000, ST_DO = 0x3100, ST_FOR = 0x3200,
ST_WHILE = 0x3300
@@ -440,9 +442,9 @@ static const uint32_t tokeninfo[] ALIGN4 = {
#define TI_PREINC (OC_UNARY|xV|P(9)|'P')
#define TI_PREDEC (OC_UNARY|xV|P(9)|'M')
TI_PREINC, TI_PREDEC, OC_FIELD|xV|P(5),
- OC_COMPARE|VV|P(39)|5, OC_MOVE|VV|P(74), OC_REPLACE|NV|P(74)|'+', OC_REPLACE|NV|P(74)|'-',
- OC_REPLACE|NV|P(74)|'*', OC_REPLACE|NV|P(74)|'/', OC_REPLACE|NV|P(74)|'%', OC_REPLACE|NV|P(74)|'&',
- OC_BINARY|NV|P(29)|'+', OC_BINARY|NV|P(29)|'-', OC_REPLACE|NV|P(74)|'&', OC_BINARY|NV|P(15)|'&',
+ OC_COMPARE|VV|P(39)|5, OC_MOVE|VV|P(38), OC_REPLACE|NV|P(38)|'+', OC_REPLACE|NV|P(38)|'-',
+ OC_REPLACE|NV|P(38)|'*', OC_REPLACE|NV|P(38)|'/', OC_REPLACE|NV|P(38)|'%', OC_REPLACE|NV|P(38)|'&',
+ OC_BINARY|NV|P(29)|'+', OC_BINARY|NV|P(29)|'-', OC_REPLACE|NV|P(38)|'&', OC_BINARY|NV|P(15)|'&',
OC_BINARY|NV|P(25)|'/', OC_BINARY|NV|P(25)|'%', OC_BINARY|NV|P(15)|'&', OC_BINARY|NV|P(25)|'*',
OC_COMPARE|VV|P(39)|4, OC_COMPARE|VV|P(39)|3, OC_COMPARE|VV|P(39)|0, OC_COMPARE|VV|P(39)|1,
#define TI_LESS (OC_COMPARE|VV|P(39)|2)
@@ -1290,7 +1292,7 @@ static uint32_t next_token(uint32_t expected)
save_tclass = tc;
save_info = t_info;
tc = TC_BINOPX;
- t_info = OC_CONCAT | SS | P(35);
+ t_info = OC_CONCAT | SS | PRECEDENCE(35);
}
t_tclass = tc;
@@ -1350,9 +1352,8 @@ static node *parse_expr(uint32_t term_tc)
{
node sn;
node *cn = &sn;
- node *vn, *glptr;
+ node *glptr;
uint32_t tc, expected_tc;
- var *v;
debug_printf_parse("%s() term_tc(%x):", __func__, term_tc);
debug_parse_print_tc(term_tc);
@@ -1363,11 +1364,12 @@ static node *parse_expr(uint32_t term_tc)
expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP | term_tc;
while (!((tc = next_token(expected_tc)) & term_tc)) {
+ node *vn;
if (glptr && (t_info == TI_LESS)) {
/* input redirection (<) attached to glptr node */
debug_printf_parse("%s: input redir\n", __func__);
- cn = glptr->l.n = new_node(OC_CONCAT | SS | P(37));
+ cn = glptr->l.n = new_node(OC_CONCAT | SS | PRECEDENCE(37));
cn->a.n = glptr;
expected_tc = TS_OPERAND | TS_UOPPRE;
glptr = NULL;
@@ -1379,24 +1381,42 @@ static node *parse_expr(uint32_t term_tc)
* previous operators with higher priority */
vn = cn;
while (((t_info & PRIMASK) > (vn->a.n->info & PRIMASK2))
- || ((t_info == vn->info) && t_info == TI_COLON)
+ || (t_info == vn->info && t_info == TI_COLON)
) {
vn = vn->a.n;
if (!vn->a.n) syntax_error(EMSG_UNEXP_TOKEN);
}
if (t_info == TI_TERNARY)
//TODO: why?
- t_info += P(6);
+ t_info += PRECEDENCE(6);
cn = vn->a.n->r.n = new_node(t_info);
cn->a.n = vn->a.n;
if (tc & TS_BINOP) {
cn->l.n = vn;
-//FIXME: this is the place to detect and reject assignments to non-lvalues.
-//Currently we allow "assignments" to consts and temporaries, nonsense like this:
-// awk 'BEGIN { "qwe" = 1 }'
-// awk 'BEGIN { 7 *= 7 }'
-// awk 'BEGIN { length("qwe") = 1 }'
-// awk 'BEGIN { (1+1) += 3 }'
+
+ /* Prevent:
+ * awk 'BEGIN { "qwe" = 1 }'
+ * awk 'BEGIN { 7 *= 7 }'
+ * awk 'BEGIN { length("qwe") = 1 }'
+ * awk 'BEGIN { (1+1) += 3 }'
+ */
+ /* Assignment? (including *= and friends) */
+ if (((t_info & OPCLSMASK) == OC_MOVE)
+ || ((t_info & OPCLSMASK) == OC_REPLACE)
+ ) {
+ debug_printf_parse("%s: MOVE/REPLACE vn->info:%08x\n", __func__, vn->info);
+ /* Left side is a (variable or array element)
+ * or function argument
+ * or $FIELD ?
+ */
+ if ((vn->info & OPCLSMASK) != OC_VAR
+ && (vn->info & OPCLSMASK) != OC_FNARG
+ && (vn->info & OPCLSMASK) != OC_FIELD
+ ) {
+ syntax_error(EMSG_UNEXP_TOKEN); /* no. bad */
+ }
+ }
+
expected_tc = TS_OPERAND | TS_UOPPRE | TC_REGEXP;
if (t_info == TI_PGETLINE) {
/* it's a pipe */
@@ -1432,6 +1452,8 @@ static node *parse_expr(uint32_t term_tc)
/* one should be very careful with switch on tclass -
* only simple tclasses should be used (TC_xyz, not TS_xyz) */
switch (tc) {
+ var *v;
+
case TC_VARIABLE:
case TC_ARRAY:
debug_printf_parse("%s: TC_VARIABLE | TC_ARRAY\n", __func__);
@@ -1452,14 +1474,14 @@ static node *parse_expr(uint32_t term_tc)
case TC_NUMBER:
case TC_STRING:
debug_printf_parse("%s: TC_NUMBER | TC_STRING\n", __func__);
- cn->info = OC_VAR;
+ cn->info = OC_CONST;
v = cn->l.v = xzalloc(sizeof(var));
- if (tc & TC_NUMBER)
+ if (tc & TC_NUMBER) {
setvar_i(v, t_double);
- else {
+ } else {
setvar_s(v, t_string);
- expected_tc &= ~TC_UOPPOST; /* "str"++ is not allowed */
}
+ expected_tc &= ~TC_UOPPOST; /* NUM++, "str"++ not allowed */
break;
case TC_REGEXP:
@@ -3093,6 +3115,8 @@ static var *evaluate(node *op, var *res)
/* -- recursive node type -- */
+ case XC( OC_CONST ):
+ debug_printf_eval("CONST ");
case XC( OC_VAR ):
debug_printf_eval("VAR\n");
L.v = op->l.v;
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index bbf0fbf..a71ef3b 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -485,4 +485,9 @@ testing 'awk assign while test' \
"" \
"foo"
+testing "awk = has higher precedence than == (despite what gawk manpage claims)" \
+ "awk 'BEGIN { v=1; print 2==v; print 2==v=2; print v; print v=3==3; print v}'" \
+ '0\n1\n2\n1\n3\n' \
+ '' ''
+
exit $FAILCOUNT
--
2.43.0

View File

@ -0,0 +1,34 @@
From c55dcbb77bb0bd7e61ce5c7a074013be06b32629 Mon Sep 17 00:00:00 2001
From: Valery Ushakov <uwe@stderr.spb.ru>
Date: Wed, 24 Jan 2024 22:24:41 +0300
Subject: [PATCH] awk.c: fix CVE-2023-42366 (bug #15874)
Make sure we don't read past the end of the string in next_token()
when backslash is the last character in an (invalid) regexp.
Conflict:No
Reference:https://git.alpinelinux.org/aports/plain/main/busybox/0026-awk.c-fix-CVE-2023-42366-bug-15874.patch
https://bugs.busybox.net/show_bug.cgi?id=15874
---
editors/awk.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/editors/awk.c b/editors/awk.c
index 64e752f4b..222e6298d 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -1234,9 +1234,11 @@ static uint32_t next_token(uint32_t expected)
s[-1] = bb_process_escape_sequence((const char **)&pp);
if (*p == '\\')
*s++ = '\\';
- if (pp == p)
+ if (pp == p) {
+ if (*p == '\0')
+ syntax_error(EMSG_UNEXP_EOS);
*s++ = *p++;
- else
+ } else
p = pp;
}
}

View File

@ -4,7 +4,7 @@
%endif
%if "%{!?RELEASE:1}"
%define RELEASE 18
%define RELEASE 23
%endif
Epoch: 1
@ -24,6 +24,9 @@ Patch6000: backport-CVE-2022-28391.patch
Patch6001: backport-CVE-2022-30065.patch
Patch6002: backport-fix-use-after-free-in-bc-module.patch
Patch6003: backport-CVE-2022-48174.patch
Patch6004: backport-CVE-2023-42363.patch
Patch6005: backport-CVE-2023-42364-CVE-2023-42365.patch
Patch6006: backport-CVE-2023-42366.patch
BuildRoot: %_topdir/BUILDROOT
#Dependency
@ -99,6 +102,36 @@ install -m 644 docs/busybox.dynamic.1 $RPM_BUILD_ROOT/%{_mandir}/man1/busybox.1
%{_mandir}/man1/busybox.petitboot.1.gz
%changelog
* Fri Nov 15 2024 liuxu <liuxu156@huawei.com> - 1:1.34.1-23
- Type:CVE
- Id:NA
- SUG:NA
- DESC:fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366
* Mon Jul 22 2024 liuxu <liuxu156@huawei.com> - 1:1.34.1-22
- Type:CVE
- Id:NA
- SUG:NA
- DESC:fix CVE-2023-42363
* Tue Jun 25 2024 liuxu <liuxu156@huawei.com> - 1:1.34.1-21
- Type:CVE
- Id:NA
- SUG:NA
- DESC:revert fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366 CVE-2023-42363
* Wed Jun 19 2024 liuxu <liuxu156@huawei.com> - 1:1.34.1-20
- Type:CVE
- Id:NA
- SUG:NA
- DESC:fix CVE-2023-42364 CVE-2023-42365 CVE-2023-42366 CVE-2023-42363
* Thu Aug 31 2023 huangsong <huangsong14@huawei.com> - 1:1.34.1-19
- Type:CVE
- Id:NA
- SUG:NA
- DESC:re-fixed CVE-2022-48174
* Wed Aug 30 2023 huangsong <huangsong14@huawei.com> - 1:1.34.1-18
- Type:CVE
- Id:NA