[master,kirkstone] lua: fix CVE-2022-28805

Message ID 9e6a5e5366b6c6ea6cfb666d7e26d287ba9a42f0.1650303227.git.steve@sakoman.com
State Accepted, archived
Commit d2ba3b8850d461bc7b773240cdf15b22b31a3f9e
Headers show
Series [master,kirkstone] lua: fix CVE-2022-28805 | expand

Commit Message

Steve Sakoman April 18, 2022, 7:04 p.m. UTC
singlevar in lparser.c in Lua through 5.4.4 lacks a certain luaK_exp2anyregup
call, leading to a heap-based buffer over-read that might affect a system that
compiles untrusted Lua code.

https://nvd.nist.gov/vuln/detail/CVE-2022-28805

Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 .../lua/lua/CVE-2022-28805.patch              | 26 +++++++++++++++++++
 meta/recipes-devtools/lua/lua_5.4.4.bb        |  1 +
 2 files changed, 27 insertions(+)
 create mode 100644 meta/recipes-devtools/lua/lua/CVE-2022-28805.patch

Comments

Richard Purdie April 19, 2022, 1:17 p.m. UTC | #1
On Mon, 2022-04-18 at 09:04 -1000, Steve Sakoman wrote:
> singlevar in lparser.c in Lua through 5.4.4 lacks a certain luaK_exp2anyregup
> call, leading to a heap-based buffer over-read that might affect a system that
> compiles untrusted Lua code.
> 
> https://nvd.nist.gov/vuln/detail/CVE-2022-28805
> 
> Signed-off-by: Steve Sakoman <steve@sakoman.com>
> ---
>  .../lua/lua/CVE-2022-28805.patch              | 26 +++++++++++++++++++
>  meta/recipes-devtools/lua/lua_5.4.4.bb        |  1 +
>  2 files changed, 27 insertions(+)
>  create mode 100644 meta/recipes-devtools/lua/lua/CVE-2022-28805.patch
> 
> diff --git a/meta/recipes-devtools/lua/lua/CVE-2022-28805.patch b/meta/recipes-devtools/lua/lua/CVE-2022-28805.patch
> new file mode 100644
> index 0000000000..8a1a69d60e
> --- /dev/null
> +++ b/meta/recipes-devtools/lua/lua/CVE-2022-28805.patch
> @@ -0,0 +1,26 @@
> +From 1f3c6f4534c6411313361697d98d1145a1f030fa Mon Sep 17 00:00:00 2001
> +From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> +Date: Tue, 15 Feb 2022 12:28:46 -0300
> +Subject: [PATCH] Bug: Lua can generate wrong code when _ENV is <const>
> +
> +CVE: CVE-2022-28805
> +
> +Upstream-Status: Backport from upstream: https://github.com/lua/lua/commit/1f3c6f4534c6411313361697d98d1145a1f030fa

For consistency this should be:

Upstream-Status: Backport
[https://github.com/lua/lua/commit/1f3c6f4534c6411313361697d98d1145a1f030fa]

:)

I tweaked the patch.

Cheers,

Richard
Ranjitsinh Rathod April 25, 2022, 6:15 a.m. UTC | #2
Hi Steve,

Can you please cherry-pick this on the dunfell branch as well for this Lua CVE? or should I send a patch for this?

Ranjitsinh Rathod
Steve Sakoman April 25, 2022, 1:57 p.m. UTC | #3
On Sun, Apr 24, 2022 at 8:15 PM Ranjitsinh Rathod
<ranjitsinhrathod1991@gmail.com> wrote:
>
> Hi Steve,
>
> Can you please cherry-pick this on the dunfell branch as well for this Lua CVE? or should I send a patch for this?

Yes, of course!  Thanks for the reminder.

Steve
Steve Sakoman April 25, 2022, 3:08 p.m. UTC | #4
On Mon, Apr 25, 2022 at 3:57 AM Steve Sakoman via
lists.openembedded.org <steve=sakoman.com@lists.openembedded.org>
wrote:
>
> On Sun, Apr 24, 2022 at 8:15 PM Ranjitsinh Rathod
> <ranjitsinhrathod1991@gmail.com> wrote:
> >
> > Hi Steve,
> >
> > Can you please cherry-pick this on the dunfell branch as well for this Lua CVE? or should I send a patch for this?
>
> Yes, of course!  Thanks for the reminder.

Heh, now I know why I "forgot" to take this patch in dunfell -- there
is no lua recipe in dunfell :-)

It was moved from meta-oe to oe-core post dunfell release. So, you
should probably submit this patch for the meta-openembedded dunfell
branch using the meta-openembedded mailing list!

Steve

Steve
Ranjitsinh Rathod April 25, 2022, 3:29 p.m. UTC | #5
Hi Steve,

Sure, will send it for meta-openembedded.


Thanks,

Best Regards,

Ranjitsinh Rathod
Technical Leader |  | KPIT Technologies Ltd.
Cellphone: +91-84606 92403

Patch

diff --git a/meta/recipes-devtools/lua/lua/CVE-2022-28805.patch b/meta/recipes-devtools/lua/lua/CVE-2022-28805.patch
new file mode 100644
index 0000000000..8a1a69d60e
--- /dev/null
+++ b/meta/recipes-devtools/lua/lua/CVE-2022-28805.patch
@@ -0,0 +1,26 @@ 
+From 1f3c6f4534c6411313361697d98d1145a1f030fa Mon Sep 17 00:00:00 2001
+From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
+Date: Tue, 15 Feb 2022 12:28:46 -0300
+Subject: [PATCH] Bug: Lua can generate wrong code when _ENV is <const>
+
+CVE: CVE-2022-28805
+
+Upstream-Status: Backport from upstream: https://github.com/lua/lua/commit/1f3c6f4534c6411313361697d98d1145a1f030fa
+
+Signed-off-by: Steve Sakoman <steve@sakoman.com>
+---
+ src/lparser.c         |  1 +
+ 1 files changed, 1 insertions(+)
+
+diff --git a/src/lparser.c b/src/lparser.c
+index 3abe3d751..a5cd55257 100644
+--- a/src/lparser.c
++++ b/src/lparser.c
+@@ -468,6 +468,7 @@ static void singlevar (LexState *ls, expdesc *var) {
+     expdesc key;
+     singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */
+     lua_assert(var->k != VVOID);  /* this one must exist */
++    luaK_exp2anyregup(fs, var);  /* but could be a constant */
+     codestring(&key, varname);  /* key is variable name */
+     luaK_indexed(fs, var, &key);  /* env[varname] */
+   }
diff --git a/meta/recipes-devtools/lua/lua_5.4.4.bb b/meta/recipes-devtools/lua/lua_5.4.4.bb
index f50328ecfd..d704841378 100644
--- a/meta/recipes-devtools/lua/lua_5.4.4.bb
+++ b/meta/recipes-devtools/lua/lua_5.4.4.bb
@@ -6,6 +6,7 @@  HOMEPAGE = "http://www.lua.org/"
 
 SRC_URI = "http://www.lua.org/ftp/lua-${PV}.tar.gz;name=tarballsrc \
            file://lua.pc.in \
+           file://CVE-2022-28805.patch \
            ${@bb.utils.contains('DISTRO_FEATURES', 'ptest', 'http://www.lua.org/tests/lua-${PV_testsuites}-tests.tar.gz;name=tarballtest file://run-ptest ', '', d)} \
            "