Commit 2a0d49f
committed
fix(security): protect shared SBOM Data with per-Data lock
Data races found via a race-detector-enabled build in staging (see #54333).
The *Data object is shared across SBOMs that run the same image via the
dataCache, but each SBOM has its own sync.RWMutex. So sbomA.Lock() and
sbomB.Lock() don't protect the shared Data.packages slice. The forwarding
debouncer's copy(packages, sbom.data.packages) races with ResolvePackage's
pkg.LastAccess = time.Now() when two containers share the same image.
Fix: add a sync.RWMutex to Data. Take data.mu.RLock() in the forwarding
snapshot (reader) and data.mu.Lock() in ResolvePackage and
processPendingFileEvents (writers). This mirrors the existing pattern in
fixedSizeQueue, which already has its own lock for the same reason.1 parent 768df0b commit 2a0d49f
2 files changed
Lines changed: 73 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
435 | 437 | | |
436 | 438 | | |
437 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
438 | 443 | | |
439 | 444 | | |
| 445 | + | |
440 | 446 | | |
441 | 447 | | |
442 | 448 | | |
| |||
776 | 782 | | |
777 | 783 | | |
778 | 784 | | |
| 785 | + | |
779 | 786 | | |
780 | 787 | | |
781 | 788 | | |
| |||
787 | 794 | | |
788 | 795 | | |
789 | 796 | | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
790 | 804 | | |
791 | 805 | | |
792 | | - | |
793 | | - | |
| 806 | + | |
| 807 | + | |
794 | 808 | | |
795 | 809 | | |
796 | 810 | | |
| |||
855 | 869 | | |
856 | 870 | | |
857 | 871 | | |
| 872 | + | |
| 873 | + | |
858 | 874 | | |
859 | 875 | | |
860 | 876 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
0 commit comments