Skip to contentSkip to conversation

cve-check: get_cve_info should open the database read-only

PATCH In review Ross Burton 3 participants 9 messages Feb 23, 2022 – Mar 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cve-check: get_cve_info should open the database read-only

All of the function in cve-check should open the database read-only, as the only writer is the fetch task in cve-update-db. However, get_cve_info() was failing to do this, which might be causing locking issues with sqlite.

---
 meta/classes/cve-check.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/cve-check.bbclass +2 -1
index 2d69aeba4b..d715fbf4d8 100644
@@ -265,7 +265,8 @@ def get_cve_info(d, cves):
     import sqlite3
 
     cve_data = {}
-    conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
+    db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
+    conn = sqlite3.connect(db_file, uri=True)
 
     for cve in cves:
         for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 Revert "cve-check: add lockfile to task"

Now that all of the functions in cve-check open the database read-only, we can remove this lockfile.

This means cve-check can run in parallal again, improving runtimes massively.

This reverts commit d55fbf4779483d2cfd71df78d0f733b599fef739.

---
 meta/classes/cve-check.bbclass | 1 -
 1 file changed, 1 deletion(-)
meta/classes/cve-check.bbclass +0 -1
index d715fbf4d8..079d09a76f 100644
@@ -111,7 +111,6 @@ python do_cve_check () {
 }
 
 addtask cve_check before do_build after do_fetch
-do_cve_check[lockfiles] += "${CVE_CHECK_DB_FILE_LOCK}"
 do_cve_check[depends] = "cve-update-db-native:do_fetch"
 do_cve_check[nostamp] = "1"
 
Signature · 1 line
2.25.1
#2 lore raw
In reply to Ross Burton

Sadly I encountered this here last night

NOTE: recipe cve-update-db-native-1.0-r0: task do_cve_check: Started
ERROR: cve-update-db-native-1.0-r0 do_cve_check: Error executing a python function in exec_func_python() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>

     0001:
 *** 0002:do_cve_check(d)
     0003:

File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno: 104, function: do_cve_check
0100: try:
0101: patched_cves = get_patched_cves(d)
0102: except FileNotFoundError:
0103: bb.fatal("Failure in searching patches")
*** 0104: whitelisted, patched, unpatched = check_cves(d,
patched_cves)
0105: if patched or unpatched:
0106: cve_data = get_cve_info(d, patched + unpatched)
0107: cve_write_data(d, patched, unpatched,
whitelisted, cve_data)

     0108:    else:
File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno: 198, function: check_cves
     0194:        else:
     0195:            vendor = "%"
     0196:
     0197:        # Find all relevant CVE IDs.

*** 0198: for cverow in conn.execute("SELECT DISTINCT ID FROM
PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
0199: cve = cverow[0]
0200:
0201: if cve in cve_whitelist:
0202: bb.note("%s-%s has been whitelisted for %s" %
(product, pv, cve))
Exception: sqlite3.OperationalError: attempt to write a readonly database

So it seems your patch doesn't solve the issue

Quoted 35 lines · Ross Burton

All of the function in cve-check should open the database read-only, as the only writer is the fetch task in cve-update-db. However, get_cve_info() was failing to do this, which might be causing locking issues with sqlite.

---
  meta/classes/cve-check.bbclass | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/cve-check.bbclass +2 -2
index 2d69aeba4b..d715fbf4d8 100644
@@ -265,7 +265,8 @@ def get_cve_info(d, cves):
      import sqlite3
 
      cve_data = {}
-    conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
+    db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
+    conn = sqlite3.connect(db_file, uri=True)
 
      for cve in cves:
          for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#162258): https://lists.openembedded.org/g/openembedded-core/message/162258
Mute This Topic: https://lists.openembedded.org/mt/89339702/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

What's the scenario where this is happening? Multiple build directories using the same DL_DIR? Or was this a single build?

Ross

Quoted 80 lines · Konrad Weihmann

Sadly I encountered this here last night

NOTE: recipe cve-update-db-native-1.0-r0: task do_cve_check: Started
ERROR: cve-update-db-native-1.0-r0 do_cve_check: Error executing a python function in exec_func_python() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>

      0001:
  *** 0002:do_cve_check(d)
      0003:

File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
104, function: do_cve_check
0100: try:
0101: patched_cves = get_patched_cves(d)
0102: except FileNotFoundError:
0103: bb.fatal("Failure in searching patches")
*** 0104: whitelisted, patched, unpatched = check_cves(d,
patched_cves)
0105: if patched or unpatched:
0106: cve_data = get_cve_info(d, patched + unpatched)
0107: cve_write_data(d, patched, unpatched,
whitelisted, cve_data)

      0108:    else:
File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
198, function: check_cves
      0194:        else:
      0195:            vendor = "%"
      0196:
      0197:        # Find all relevant CVE IDs.

*** 0198: for cverow in conn.execute("SELECT DISTINCT ID FROM
PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
0199: cve = cverow[0]
0200:
0201: if cve in cve_whitelist:
0202: bb.note("%s-%s has been whitelisted for %s" %
(product, pv, cve))
Exception: sqlite3.OperationalError: attempt to write a readonly database

So it seems your patch doesn't solve the issue

Quoted 35 lines · Ross Burton

All of the function in cve-check should open the database read-only, as the only writer is the fetch task in cve-update-db. However, get_cve_info() was failing to do this, which might be causing locking issues with sqlite.

---
  meta/classes/cve-check.bbclass | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/cve-check.bbclass +2 -2
index 2d69aeba4b..d715fbf4d8 100644
@@ -265,7 +265,8 @@ def get_cve_info(d, cves):
      import sqlite3
 
      cve_data = {}
-    conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
+    db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
+    conn = sqlite3.connect(db_file, uri=True)
 
      for cve in cves:
          for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#162258): https://lists.openembedded.org/g/openembedded-core/message/162258
Mute This Topic: https://lists.openembedded.org/mt/89339702/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw

Single from scratch build of core-image-minimal

Quoted 86 lines · Ross Burton

What's the scenario where this is happening? Multiple build directories using the same DL_DIR? Or was this a single build?

Ross

Quoted 80 lines · Konrad Weihmann

Sadly I encountered this here last night

NOTE: recipe cve-update-db-native-1.0-r0: task do_cve_check: Started
ERROR: cve-update-db-native-1.0-r0 do_cve_check: Error executing a python function in exec_func_python() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>

       0001:
   *** 0002:do_cve_check(d)
       0003:

File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
104, function: do_cve_check
0100: try:
0101: patched_cves = get_patched_cves(d)
0102: except FileNotFoundError:
0103: bb.fatal("Failure in searching patches")
*** 0104: whitelisted, patched, unpatched = check_cves(d,
patched_cves)
0105: if patched or unpatched:
0106: cve_data = get_cve_info(d, patched + unpatched)
0107: cve_write_data(d, patched, unpatched,
whitelisted, cve_data)

       0108:    else:
File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
198, function: check_cves
       0194:        else:
       0195:            vendor = "%"
       0196:
       0197:        # Find all relevant CVE IDs.

*** 0198: for cverow in conn.execute("SELECT DISTINCT ID FROM
PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
0199: cve = cverow[0]
0200:
0201: if cve in cve_whitelist:
0202: bb.note("%s-%s has been whitelisted for %s" %
(product, pv, cve))
Exception: sqlite3.OperationalError: attempt to write a readonly database

So it seems your patch doesn't solve the issue

Quoted 35 lines · Ross Burton

All of the function in cve-check should open the database read-only, as the only writer is the fetch task in cve-update-db. However, get_cve_info() was failing to do this, which might be causing locking issues with sqlite.

---
   meta/classes/cve-check.bbclass | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/cve-check.bbclass +2 -2
index 2d69aeba4b..d715fbf4d8 100644
@@ -265,7 +265,8 @@ def get_cve_info(d, cves):
       import sqlite3
 
       cve_data = {}
-    conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
+    db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
+    conn = sqlite3.connect(db_file, uri=True)
 
       for cve in cves:
           for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#162258): https://lists.openembedded.org/g/openembedded-core/message/162258
Mute This Topic: https://lists.openembedded.org/mt/89339702/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#5 lore raw

:tableflip:

Thanks, I guess!

Can you share the full bitbake log from that run? I'd like to see what jobs are running in parallel.

Ross

Quoted 90 lines · Konrad Weihmann

Single from scratch build of core-image-minimal

Quoted 86 lines · Ross Burton

What's the scenario where this is happening? Multiple build directories using the same DL_DIR? Or was this a single build?

Ross

Quoted 80 lines · Konrad Weihmann

Sadly I encountered this here last night

NOTE: recipe cve-update-db-native-1.0-r0: task do_cve_check: Started
ERROR: cve-update-db-native-1.0-r0 do_cve_check: Error executing a python function in exec_func_python() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>

       0001:
   *** 0002:do_cve_check(d)
       0003:

File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
104, function: do_cve_check
0100: try:
0101: patched_cves = get_patched_cves(d)
0102: except FileNotFoundError:
0103: bb.fatal("Failure in searching patches")
*** 0104: whitelisted, patched, unpatched = check_cves(d,
patched_cves)
0105: if patched or unpatched:
0106: cve_data = get_cve_info(d, patched + unpatched)
0107: cve_write_data(d, patched, unpatched,
whitelisted, cve_data)

       0108:    else:
File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
198, function: check_cves
       0194:        else:
       0195:            vendor = "%"
       0196:
       0197:        # Find all relevant CVE IDs.

*** 0198: for cverow in conn.execute("SELECT DISTINCT ID FROM
PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
0199: cve = cverow[0]
0200:
0201: if cve in cve_whitelist:
0202: bb.note("%s-%s has been whitelisted for %s" %
(product, pv, cve))
Exception: sqlite3.OperationalError: attempt to write a readonly database

So it seems your patch doesn't solve the issue

Quoted 35 lines · Ross Burton

All of the function in cve-check should open the database read-only, as the only writer is the fetch task in cve-update-db. However, get_cve_info() was failing to do this, which might be causing locking issues with sqlite.

---
   meta/classes/cve-check.bbclass | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/cve-check.bbclass +2 -2
index 2d69aeba4b..d715fbf4d8 100644
@@ -265,7 +265,8 @@ def get_cve_info(d, cves):
       import sqlite3
 
       cve_data = {}
-    conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
+    db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
+    conn = sqlite3.connect(db_file, uri=True)
 
       for cve in cves:
           for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#162258): https://lists.openembedded.org/g/openembedded-core/message/162258
Mute This Topic: https://lists.openembedded.org/mt/89339702/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#6 lore raw

This one is odd...

After scrolling through the log that I can get from a github pipeline (sorry no runner log available) - I noticed

2022-03-03T05:39:23.2334189Z WARNING: cve-update-db-native-1.0-r0 do_fetch: Failed to fetch CVE data ([Errno 99] Cannot assign requested address)
2022-03-03T05:39:23.2569941Z NOTE: recipe cve-update-db-native-1.0-r0: task do_fetch: Succeeded

and then do_cve_check run on that recipe

2022-03-03T05:39:56.6239005Z NOTE: Running task 4428 of 5120 (/opt/build/sources/poky/meta/recipes-core/meta/cve-update-db-native.bb:do_cve_check)

before failing with 2022-03-03T05:39:56.8063851Z Exception: sqlite3.OperationalError: attempt to write a readonly database

this doesn't look right to me - maybe there's something special about my settings - I will try to recreate that locally

Quoted 100 lines · Ross Burton

:tableflip:

Thanks, I guess!

Can you share the full bitbake log from that run? I'd like to see what jobs are running in parallel.

Ross

Quoted 90 lines · Konrad Weihmann

Single from scratch build of core-image-minimal

Quoted 86 lines · Ross Burton

What's the scenario where this is happening? Multiple build directories using the same DL_DIR? Or was this a single build?

Ross

Quoted 80 lines · Konrad Weihmann

Sadly I encountered this here last night

NOTE: recipe cve-update-db-native-1.0-r0: task do_cve_check: Started
ERROR: cve-update-db-native-1.0-r0 do_cve_check: Error executing a python function in exec_func_python() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>

        0001:
    *** 0002:do_cve_check(d)
        0003:

File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
104, function: do_cve_check
0100: try:
0101: patched_cves = get_patched_cves(d)
0102: except FileNotFoundError:
0103: bb.fatal("Failure in searching patches")
*** 0104: whitelisted, patched, unpatched = check_cves(d,
patched_cves)
0105: if patched or unpatched:
0106: cve_data = get_cve_info(d, patched + unpatched)
0107: cve_write_data(d, patched, unpatched,
whitelisted, cve_data)

        0108:    else:
File: '/opt/build/sources/poky/meta/classes/cve-check.bbclass', lineno:
198, function: check_cves
        0194:        else:
        0195:            vendor = "%"
        0196:
        0197:        # Find all relevant CVE IDs.
    *** 0198:        for cverow in conn.execute("SELECT DISTINCT ID FROM

PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
0199: cve = cverow[0]
0200:
0201: if cve in cve_whitelist:
0202: bb.note("%s-%s has been whitelisted for %s" %
(product, pv, cve))
Exception: sqlite3.OperationalError: attempt to write a readonly database

So it seems your patch doesn't solve the issue

Quoted 35 lines · Ross Burton

All of the function in cve-check should open the database read-only, as the only writer is the fetch task in cve-update-db. However, get_cve_info() was failing to do this, which might be causing locking issues with sqlite.

---
    meta/classes/cve-check.bbclass | 3 ++-
    1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/cve-check.bbclass +2 -2
index 2d69aeba4b..d715fbf4d8 100644
@@ -265,7 +265,8 @@ def get_cve_info(d, cves):
        import sqlite3
 
        cve_data = {}
-    conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
+    db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
+    conn = sqlite3.connect(db_file, uri=True)
 
        for cve in cves:
            for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#162258): https://lists.openembedded.org/g/openembedded-core/message/162258
Mute This Topic: https://lists.openembedded.org/mt/89339702/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#7 lore raw
Quoted 8 lines · Konrad Weihmann

After scrolling through the log that I can get from a github pipeline (sorry no runner log available) - I noticed

2022-03-03T05:39:23.2334189Z WARNING: cve-update-db-native-1.0-r0
do_fetch: Failed to fetch CVE data ([Errno 99] Cannot assign requested
address)
2022-03-03T05:39:23.2569941Z NOTE: recipe cve-update-db-native-1.0-r0:

task do_fetch: Succeeded

That's... special.

Quoted 10 lines

and then do_cve_check run on that recipe

2022-03-03T05:39:56.6239005Z NOTE: Running task 4428 of 5120

(/opt/build/sources/poky/meta/recipes-core/meta/cve-update-db-native.bb:do_cve_check)

before failing with 2022-03-03T05:39:56.8063851Z Exception:
sqlite3.OperationalError: attempt to write a readonly database

this doesn't look right to me - maybe there's something special about my settings - I will try to recreate that locally

Have you managed to reproduce this failure since?

Ross

#8 lore raw
Quoted 17 lines · Ross Burton
Quoted 8 lines · Konrad Weihmann

After scrolling through the log that I can get from a github pipeline (sorry no runner log available) - I noticed

2022-03-03T05:39:23.2334189Z WARNING: cve-update-db-native-1.0-r0
do_fetch: Failed to fetch CVE data ([Errno 99] Cannot assign requested
address)
2022-03-03T05:39:23.2569941Z NOTE: recipe cve-update-db-native-1.0-r0:

task do_fetch: Succeeded

That's... special.

Quoted 5 lines

and then do_cve_check run on that recipe

2022-03-03T05:39:56.6239005Z NOTE: Running task 4428 of 5120

(/opt/build/sources/poky/meta/recipes-core/meta/cve-update-db-native.bb:do_cve_check)

Quoted 7 lines
Quoted 5 lines

before failing with 2022-03-03T05:39:56.8063851Z Exception:
sqlite3.OperationalError: attempt to write a readonly database

this doesn't look right to me - maybe there's something special about my settings - I will try to recreate that locally

Have you managed to reproduce this failure since?

I tried, but without success - but I did a bit of reading on the reported Error 99, which seems to be related to using containers (in the pipeline itself a container based on ubuntu 18.04 is used) to run the build.

looking at the code block from cve-update-db-native:do_fetch

try:
response = urllib.request.urlopen(meta_url)
except urllib.error.URLError as e:
cve_f.write('Warning: CVE db update error, Unable to
fetch CVE data.\n\n')
bb.warn("Failed to fetch CVE data (%s)" % e.reason) return

I'm not a 100% sure, if the sudden return doesn't leave the pre-populated DB file in a limbo state.
I at least would expect a flush + close of the DB file here, or even better a recreation of an empty DB + flush and close - but I'm not sure what to do in the case the network stack of the OS fails us

But as I mentioned a couple of times, this issue is hard to reproduce and just hits me in on those mentioned GH pipelines every now and then.

BTW just one idea for improvement would be to globally exclude cve-update-db-native from running do_cve_check... as this doesn't make much sense to me - guess setting CVE_CHECK_SKIP_RECIPE = "cve-update-db-native" as a sane default in cve-check class should do it - any thoughts?

Quoted 2 lines

Ross