Bug#1021737: lava: CVE-2022-42902

2022-10-21 Thread Antonio Terceiro
On Wed, Oct 19, 2022 at 09:57:34PM +0200, Moritz Muehlenhoff wrote:
> On Tue, Oct 18, 2022 at 06:09:42PM -0300, Antonio Terceiro wrote:
> > Hi,
> > 
> > On Thu, Oct 13, 2022 at 09:13:18PM +0200, Moritz Mühlenhoff wrote:
> > > Source: lava
> > > X-Debbugs-CC: t...@security.debian.org
> > > Severity: grave
> > > Tags: security
> > > 
> > > Hi,
> > > 
> > > The following vulnerability was published for lava.
> > > 
> > > CVE-2022-42902[0]:
> > > | In Linaro Automated Validation Architecture (LAVA) before 2022.10,
> > > | there is dynamic code execution in lava_server/lavatable.py. Due to
> > > | improper input sanitization, an anonymous user can force the lava-
> > > | server-gunicorn service to execute user-provided code on the server.
> > > 
> > > https://git.lavasoftware.org/lava/lava/-/merge_requests/1834
> > > https://git.lavasoftware.org/lava/lava/-/commit/e66b74cd6c175ff8826b8f3431740963be228b52?merge_request_iid=1834
> > > 
> > > If you fix the vulnerability please also make sure to include the
> > > CVE (Common Vulnerabilities & Exposures) id in your changelog entry.
> > > 
> > > For further information see:
> > > 
> > > [0] https://security-tracker.debian.org/tracker/CVE-2022-42902
> > > https://www.cve.org/CVERecord?id=CVE-2022-42902
> > > 
> > > Please adjust the affected versions in the BTS as needed.
> > 
> > I have uploaded a fix version to unstable (latest upstream), and I would
> > like to upload the attached debdiff to -security. That package builds
> > cleanly and passes its autopkgtest on bullseye. Let me know.
> 
> Ack, we can fix this via a DSA. The debdiff looks fine content-wise,
> but the deb111u1 version is slightly off by 100 Debian releases ;-)
> 
> So please change to +deb11u1 and upload to security-master.

Heh, my mistake.

Just uploaded.


signature.asc
Description: PGP signature


Bug#1021737: lava: CVE-2022-42902

2022-10-19 Thread Moritz Muehlenhoff
On Tue, Oct 18, 2022 at 06:09:42PM -0300, Antonio Terceiro wrote:
> Hi,
> 
> On Thu, Oct 13, 2022 at 09:13:18PM +0200, Moritz Mühlenhoff wrote:
> > Source: lava
> > X-Debbugs-CC: t...@security.debian.org
> > Severity: grave
> > Tags: security
> > 
> > Hi,
> > 
> > The following vulnerability was published for lava.
> > 
> > CVE-2022-42902[0]:
> > | In Linaro Automated Validation Architecture (LAVA) before 2022.10,
> > | there is dynamic code execution in lava_server/lavatable.py. Due to
> > | improper input sanitization, an anonymous user can force the lava-
> > | server-gunicorn service to execute user-provided code on the server.
> > 
> > https://git.lavasoftware.org/lava/lava/-/merge_requests/1834
> > https://git.lavasoftware.org/lava/lava/-/commit/e66b74cd6c175ff8826b8f3431740963be228b52?merge_request_iid=1834
> > 
> > If you fix the vulnerability please also make sure to include the
> > CVE (Common Vulnerabilities & Exposures) id in your changelog entry.
> > 
> > For further information see:
> > 
> > [0] https://security-tracker.debian.org/tracker/CVE-2022-42902
> > https://www.cve.org/CVERecord?id=CVE-2022-42902
> > 
> > Please adjust the affected versions in the BTS as needed.
> 
> I have uploaded a fix version to unstable (latest upstream), and I would
> like to upload the attached debdiff to -security. That package builds
> cleanly and passes its autopkgtest on bullseye. Let me know.

Ack, we can fix this via a DSA. The debdiff looks fine content-wise,
but the deb111u1 version is slightly off by 100 Debian releases ;-)

So please change to +deb11u1 and upload to security-master.

Cheers,
Moritz



Bug#1021737: lava: CVE-2022-42902

2022-10-18 Thread Antonio Terceiro
On Tue, Oct 18, 2022 at 06:09:45PM -0300, Antonio Terceiro wrote:
> Hi,
> 
> On Thu, Oct 13, 2022 at 09:13:18PM +0200, Moritz Mühlenhoff wrote:
> > Source: lava
> > X-Debbugs-CC: t...@security.debian.org
> > Severity: grave
> > Tags: security
> > 
> > Hi,
> > 
> > The following vulnerability was published for lava.
> > 
> > CVE-2022-42902[0]:
> > | In Linaro Automated Validation Architecture (LAVA) before 2022.10,
> > | there is dynamic code execution in lava_server/lavatable.py. Due to
> > | improper input sanitization, an anonymous user can force the lava-
> > | server-gunicorn service to execute user-provided code on the server.
> > 
> > https://git.lavasoftware.org/lava/lava/-/merge_requests/1834
> > https://git.lavasoftware.org/lava/lava/-/commit/e66b74cd6c175ff8826b8f3431740963be228b52?merge_request_iid=1834
> > 
> > If you fix the vulnerability please also make sure to include the
> > CVE (Common Vulnerabilities & Exposures) id in your changelog entry.
> > 
> > For further information see:
> > 
> > [0] https://security-tracker.debian.org/tracker/CVE-2022-42902
> > https://www.cve.org/CVERecord?id=CVE-2022-42902
> > 
> > Please adjust the affected versions in the BTS as needed.
> 
> I have uploaded a fix version to unstable (latest upstream), and I would
> like to upload the attached debdiff to -security. That package builds
> cleanly and passes its autopkgtest on bullseye. Let me know.

Correction: it fails the autopkgtest, but it fails in the exact same way
as the package already in bullseye fails.


signature.asc
Description: PGP signature


Bug#1021737: lava: CVE-2022-42902

2022-10-18 Thread Antonio Terceiro
Hi,

On Thu, Oct 13, 2022 at 09:13:18PM +0200, Moritz Mühlenhoff wrote:
> Source: lava
> X-Debbugs-CC: t...@security.debian.org
> Severity: grave
> Tags: security
> 
> Hi,
> 
> The following vulnerability was published for lava.
> 
> CVE-2022-42902[0]:
> | In Linaro Automated Validation Architecture (LAVA) before 2022.10,
> | there is dynamic code execution in lava_server/lavatable.py. Due to
> | improper input sanitization, an anonymous user can force the lava-
> | server-gunicorn service to execute user-provided code on the server.
> 
> https://git.lavasoftware.org/lava/lava/-/merge_requests/1834
> https://git.lavasoftware.org/lava/lava/-/commit/e66b74cd6c175ff8826b8f3431740963be228b52?merge_request_iid=1834
> 
> If you fix the vulnerability please also make sure to include the
> CVE (Common Vulnerabilities & Exposures) id in your changelog entry.
> 
> For further information see:
> 
> [0] https://security-tracker.debian.org/tracker/CVE-2022-42902
> https://www.cve.org/CVERecord?id=CVE-2022-42902
> 
> Please adjust the affected versions in the BTS as needed.

I have uploaded a fix version to unstable (latest upstream), and I would
like to upload the attached debdiff to -security. That package builds
cleanly and passes its autopkgtest on bullseye. Let me know.

I'm also attaching the 2 patches included directly, since they are
easier to read than the diff-in-diff. The main patch for the security
issue is exactly the one that was applied upstream.
From e66b74cd6c175ff8826b8f3431740963be228b52 Mon Sep 17 00:00:00 2001
From: Igor Ponomarev 
Date: Mon, 26 Sep 2022 18:51:47 +0300
Subject: [PATCH] Replace dynamic code execution in lava_server/lavatable.py

`exec` was used to create query parameters for the tables searches.
`exec` is extremely dangerous and can lead to remote code execution.
It is also very slow.
The new implementation is equivalent in function but uses
dictionaries and unpacking to create arguments.
---
 lava_server/lavatable.py | 76 ++--
 1 file changed, 26 insertions(+), 50 deletions(-)

--- a/lava_server/lavatable.py
+++ b/lava_server/lavatable.py
@@ -41,8 +41,6 @@ class LavaView(tables.SingleTableView):
 """
 bespoke time-based field handling
 """
-local_namespace = locals()
-local_namespace["q"] = query
 time_queries = {}
 if hasattr(self.table_class.Meta, "times"):
 # filter the possible list by the request
@@ -50,26 +48,20 @@ class LavaView(tables.SingleTableView):
 # check if the request includes the current time filter & get the value
 match = self.request.GET.get(key)
 if match and match != "":
-self.terms[key] = "%s within %s %s" % (
-key,
-match,
-value,
-)  # the label for this query in the search list
+self.terms[key] = f"{key} within {match} {value}"
+# the label for this query in the search list
 time_queries[key] = value
 for key, value in time_queries.items():
 match = escape(self.request.GET.get(key))
 # escape converts None into u'None'
 if not match or match == "" or match == "None":
 continue
-args = "q = q.__and__(Q({0}__gte=timezone.now()-timedelta({1}={2})))".format(
-key, value, match
+
+query &= Q(
+**{f"{key}__gte": timezone.now() - timedelta(**{value: int(match)})}
 )
-try:
-exec(args, globals(), local_namespace)  # sets the value of q
-except SyntaxError:
-# should log the exception somewhere...
-continue  # just skip this term - results in a query matching All.
-return local_namespace["q"]
+
+return query
 
 def get_table_data(self, prefix=None):
 """
@@ -145,60 +137,44 @@ class LavaView(tables.SingleTableView):
 if not self.request:
 return data
 
-local_namespace = locals()
-local_namespace["q"] = Q()
+q = Q()
 self.terms = {}
 # discrete searches
 for key, val in distinct.items():
 if key in self.table_class.Meta.searches:
-args = 'q = q.__and__(Q({0}__contains="{1}"))'.format(key, val)
-try:
-exec(args, globals(), local_namespace)  # sets the value of q
-except SyntaxError:
-# should log exception somewhere...
-continue  # just skip this term - results in a query matching All.
+q &= Q(**{f"{key}__contains": val})
+
 if (
 hasattr(self.table_class.Meta, "queries")
 and key in self.table_class.Meta.queries.keys()
 

Bug#1021737: lava: CVE-2022-42902

2022-10-13 Thread Moritz Mühlenhoff
Source: lava
X-Debbugs-CC: t...@security.debian.org
Severity: grave
Tags: security

Hi,

The following vulnerability was published for lava.

CVE-2022-42902[0]:
| In Linaro Automated Validation Architecture (LAVA) before 2022.10,
| there is dynamic code execution in lava_server/lavatable.py. Due to
| improper input sanitization, an anonymous user can force the lava-
| server-gunicorn service to execute user-provided code on the server.

https://git.lavasoftware.org/lava/lava/-/merge_requests/1834
https://git.lavasoftware.org/lava/lava/-/commit/e66b74cd6c175ff8826b8f3431740963be228b52?merge_request_iid=1834

If you fix the vulnerability please also make sure to include the
CVE (Common Vulnerabilities & Exposures) id in your changelog entry.

For further information see:

[0] https://security-tracker.debian.org/tracker/CVE-2022-42902
https://www.cve.org/CVERecord?id=CVE-2022-42902

Please adjust the affected versions in the BTS as needed.