Skip to content

[GLUTEN-8471][VL] Fix usage of uninitialized variables#8470

Merged
FelixYBW merged 1 commit intoapache:mainfrom
jkhaliqi:jk_cve_variables
Jan 11, 2025
Merged

[GLUTEN-8471][VL] Fix usage of uninitialized variables#8470
FelixYBW merged 1 commit intoapache:mainfrom
jkhaliqi:jk_cve_variables

Conversation

@jkhaliqi
Copy link
Contributor

@jkhaliqi jkhaliqi commented Jan 8, 2025

Use of Uninitialized Variables

false positives(mainly since the file was most likely deleted and only contains 1480 lines now. Went over that file and tried to find any other Uninitialized Variables and change them accordingly. There is 9 FP below and also 9 changes in that file after taking a look at what could have been the line numbers):
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1902
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1762
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1680
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1653
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1927
pp/velox/substrait/SubstraitToVeloxPlan.cc:2539
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1960
cpp/velox/substrait/SubstraitToVeloxPlan.cc:1932
cpp/velox/substrait/SubstraitToVeloxPlan.cc:2441

(Fixes: #8471)

@github-actions github-actions bot added the VELOX label Jan 8, 2025
@github-actions
Copy link

github-actions bot commented Jan 8, 2025

Thanks for opening a pull request!

Could you open an issue for this pull request on Github Issues?

https://github.com/apache/incubator-gluten/issues

Then could you also rename commit message and pull request title in the following format?

[GLUTEN-${ISSUES_ID}][COMPONENT]feat/fix: ${detailed message}

See also:

@FelixYBW FelixYBW changed the title Fix C++ CVEs [VL] Fix C++ CVEs Jan 8, 2025
@FelixYBW FelixYBW changed the title [VL] Fix C++ CVEs [GLUTEN-8471][VL] Fix C++ CVEs Jan 8, 2025
@github-actions
Copy link

github-actions bot commented Jan 8, 2025

#8471

velox::RowVectorPtr vector = nullptr;
while (true) {
auto future = velox::ContinueFuture::makeEmpty();
if (task == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task_?

we shouldn't check null in side of the loop.

Copy link
Collaborator

@majetideepak majetideepak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkhaliqi Let's limit changes to Use of Uninitialized Variables
Please update the title. "[VL] Fix usage of uninitialized variables"

velox::RowVectorPtr vector = nullptr;
while (true) {
auto future = velox::ContinueFuture::makeEmpty();
if (task == nullptr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of Uninitialized Variable@cpp/velox/compute/WholeStageResultIterator.cc:212
Use of Uninitialized Variable@cpp/velox/compute/WholeStageResultIterator.cc:209
Assuming the task_ needed to be checked to make sure it was not nullptr in order to be used for task_->next(&future); and task_->taskId()

velox::memory::ScopedMemoryArbitrationContext ctx{};
facebook::velox::exec::MemoryReclaimer::Stats status;
velox::memory::MemoryPool* pool;
facebook::velox::exec::MemoryReclaimer::Stats status{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not required. facebook::velox::exec::MemoryReclaimer::Stats initializes its fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing


Stats stats() const override {
Stats stats; // no-op
Stats stats{}; // no-op
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing

VeloxMemoryManager::VeloxMemoryManager(const std::string& kind, std::unique_ptr<AllocationListener> listener)
: MemoryManager(kind), listener_(std::move(listener)) {
: MemoryManager(kind) {
if (listener == nullptr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this check? Is it related to the CVE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there was some CVE's for
VeloxMemoryManager.cc:243
Use of Uninitialized Variable@cpp/velox/memory/VeloxMemoryManager.cc:250
Use of Uninitialized Variable@cpp/velox/memory/VeloxMemoryManager.cc:253
which was around here so I figured it might be with the listener being passed in as nullptr so figured I would check that before the method goes in.

namespace {
MemoryUsageStats collectVeloxMemoryUsageStats(const velox::memory::MemoryPool* pool) {
MemoryUsageStats stats;
if (pool == nullptr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No related to the CVE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of Uninitialized Variable@cpp/velox/memory/VeloxMemoryManager.cc:255
Use of Uninitialized Variable@cpp/velox/memory/VeloxMemoryManager.cc:256
Use of Uninitialized Variable@cpp/velox/memory/VeloxMemoryManager.cc:257
55 being the pool in the paramter I figured I would check if that is nullPtr
then stats being 56 I just added {}
and then 57 was using pool->usedBytes so the assuming the nullptr check above should fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as false positive.

std::string subPlanPath = FilePathGenerator::getDataFilePath(file);

::substrait::Plan substraitPlan;
::substrait::Plan substraitPlan{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required.

Copy link
Contributor Author

@jkhaliqi jkhaliqi Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of Uninitialized Variable@cpp/velox/tests/Substrait2VeloxPlanValidatorTest.cc:45

kHiveConnectorId, "hive_table", filterPushdownEnabled, connector::hive::SubfieldFilters{}, nullptr);
} else {
connector::hive::SubfieldFilters subfieldFilters;
connector::hive::SubfieldFilters subfieldFilters{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required.

const ::substrait::WindowType& type,
const RowTypePtr& inputType) {
core::WindowNode::Frame frame;
core::WindowNode::Frame frame{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required.

variants.reserve(literals.size());
VELOX_CHECK_GE(literals.size(), 0, "List should have at least one item.");
std::optional<TypePtr> literalType;
std::optional<TypePtr> literalType = std::nullopt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required. std::optional is initialized by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of Uninitialized Variable@cpp/velox/substrait/SubstraitToVeloxExpr.cc:318
if (!literalType.has_value()) {
figured i'd explicitly initialize as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required. The constructor of std::optional does this.

case ::substrait::Expression_Literal::LiteralTypeCase::kEmptyList:
case ::substrait::Expression_Literal::LiteralTypeCase::kList: {
ArrayVectorPtr elements;
ArrayVectorPtr elements = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required. ArrayVectorPtr is a std::shared_ptr which is initialized by default.
Same below for RowVectorPtr and MapVectorPtr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of Uninitialized Variable@cpp/velox/substrait/SubstraitToVeloxExpr.cc:448 (if (!elements)
454 (return elements;)
472 (!mapVector)
478 (return mapVector;)
485 (!rowVector)
491 (return rowVector;)
Im assuming it would initialize it by default but the errors happening at these lines all point to these variables so I figured to explicitly call it nullptr? Should it be resolved some other way, or we can call these false positives?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive.

@jkhaliqi jkhaliqi force-pushed the jk_cve_variables branch 2 times, most recently from c3b05d2 to bdab7c5 Compare January 8, 2025 22:29
@jkhaliqi jkhaliqi changed the title [GLUTEN-8471][VL] Fix C++ CVEs [GLUTEN-8471][VL] Fix usage of uninitialized variables Jan 8, 2025

std::shared_ptr<ColumnarBatch> WholeStageResultIterator::next() {
tryAddSplitsToTask();
if (task_ == nullptr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we throw exception instead of returning nullptr?

return nullptr;
}
velox::RowVectorPtr vector;
velox::RowVectorPtr vector = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant since RowVectorPtr is a shared pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr<connector::hive::HiveBucketProperty> bucketProperty = nullptr;
I see the above as well, but not sure if assignment should be removed. Will not add in nullptr for share pointers in this PR for Uninitialized variables though, should be updated as false positives

if (listener == nullptr) {
throw gluten::GlutenException("VeloxMemoryManager failed");
}
listener_(std::move(listener))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move this here?
You can keep it as is and check for listener_ above


MemoryUsageStats collectGlutenAllocatorMemoryUsageStats(const MemoryAllocator* allocator) {
MemoryUsageStats stats;
MemoryUsageStats stats{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant.

variants.reserve(literals.size());
VELOX_CHECK_GE(literals.size(), 0, "List should have at least one item.");
std::optional<TypePtr> literalType;
std::optional<TypePtr> literalType = std::nullopt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required. The constructor of std::optional does this.

case ::substrait::Expression_Literal::LiteralTypeCase::kEmptyList:
case ::substrait::Expression_Literal::LiteralTypeCase::kList: {
ArrayVectorPtr elements;
ArrayVectorPtr elements = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive.

@jkhaliqi jkhaliqi force-pushed the jk_cve_variables branch 3 times, most recently from 4750239 to 41f2e96 Compare January 10, 2025 21:13
Use of Uninitialized Variables
@FelixYBW FelixYBW merged commit a7301e1 into apache:main Jan 11, 2025
47 of 48 checks passed
@GlutenPerfBot
Copy link
Contributor

===== Performance report for TPCDS SF2000 with Velox backend, for reference only ====

query log/native_master_01_11_2025_time.csv log/native_master_01_10_2025_6c60fd3af6_time.csv difference percentage
q1 15.34 15.93 0.591 103.85%
q2 18.65 15.45 -3.205 82.82%
q3 5.09 4.55 -0.537 89.45%
q4 84.85 86.80 1.949 102.30%
q5 11.47 13.31 1.832 115.96%
q6 5.43 4.06 -1.367 74.83%
q7 7.19 6.11 -1.081 84.98%
q8 4.56 4.57 0.005 100.12%
q9 27.08 27.46 0.385 101.42%
q10 13.20 13.46 0.257 101.95%
q11 41.29 41.40 0.118 100.28%
q12 2.20 2.35 0.151 106.89%
q13 8.89 8.20 -0.687 92.27%
q14a 64.22 63.41 -0.816 98.73%
q14b 54.51 59.22 4.704 108.63%
q15 3.58 3.72 0.140 103.92%
q16 28.93 30.82 1.891 106.54%
q17 7.29 7.88 0.594 108.15%
q18 9.95 10.53 0.581 105.84%
q19 4.91 5.28 0.371 107.56%
q20 2.52 2.04 -0.475 81.14%
q21 1.94 2.17 0.229 111.85%
q22 9.25 9.78 0.534 105.77%
q23a 137.52 136.62 -0.898 99.35%
q23b 162.51 163.74 1.225 100.75%
q24a 107.96 99.35 -8.605 92.03%
q24b 97.28 92.74 -4.537 95.34%
q25 6.99 6.35 -0.648 90.73%
q26 4.02 5.43 1.405 134.94%
q27 4.64 4.67 0.031 100.67%
q28 38.56 37.20 -1.366 96.46%
q29 20.56 19.82 -0.746 96.37%
q30 7.79 6.24 -1.553 80.08%
q31 10.42 10.75 0.326 103.13%
q32 2.37 2.05 -0.320 86.51%
q33 7.20 8.07 0.878 112.21%
q34 4.83 4.70 -0.126 97.38%
q35 10.13 11.66 1.530 115.11%
q36 5.88 5.64 -0.233 96.04%
q37 5.13 5.47 0.340 106.62%
q38 17.21 29.94 12.732 174.00%
q39a 4.57 5.15 0.577 112.63%
q39b 4.71 5.03 0.321 106.82%
q40 5.29 5.58 0.295 105.58%
q41 0.89 1.28 0.393 144.31%
q42 1.33 1.33 0.001 100.09%
q43 4.92 4.58 -0.333 93.22%
q44 12.60 13.33 0.735 105.84%
q45 4.44 4.66 0.222 104.99%
q46 5.50 5.46 -0.038 99.31%
q47 19.90 20.96 1.062 105.33%
q48 6.17 6.95 0.781 112.66%
q49 10.60 10.76 0.164 101.55%
q50 38.57 37.85 -0.728 98.11%
q51 14.20 16.03 1.825 112.85%
q52 1.31 1.18 -0.129 90.18%
q53 2.97 3.38 0.404 113.58%
q54 6.87 6.77 -0.103 98.50%
q55 1.72 1.49 -0.226 86.82%
q56 7.38 6.96 -0.415 94.38%
q57 14.20 13.16 -1.037 92.70%
q58 3.37 3.26 -0.112 96.69%
q59 7.20 7.02 -0.183 97.46%
q60 7.56 7.68 0.119 101.58%
q61 10.10 8.12 -1.972 80.47%
q62 4.90 5.37 0.476 109.72%
q63 3.08 3.20 0.121 103.95%
q64 62.46 63.09 0.623 101.00%
q65 29.94 30.07 0.122 100.41%
q66 4.44 4.80 0.360 108.11%
q67 224.83 226.44 1.605 100.71%
q68 4.30 4.17 -0.124 97.12%
q69 7.40 7.03 -0.367 95.04%
q70 12.61 12.50 -0.112 99.11%
q71 4.42 4.69 0.276 106.25%
q72 40.68 37.93 -2.747 93.25%
q73 3.35 3.29 -0.063 98.14%
q74 26.51 26.44 -0.070 99.73%
q75 43.43 43.69 0.258 100.59%
q76 14.09 14.53 0.446 103.17%
q77 3.07 3.62 0.541 117.59%
q78 83.93 84.11 0.176 100.21%
q79 5.02 5.08 0.059 101.17%
q80 16.50 16.51 0.008 100.05%
q81 8.37 8.59 0.221 102.64%
q82 10.15 10.47 0.316 103.11%
q83 2.65 2.98 0.326 112.29%
q84 4.62 3.47 -1.146 75.18%
q85 9.83 9.76 -0.063 99.35%
q86 4.50 5.01 0.507 111.27%
q87 18.08 18.98 0.895 104.95%
q88 23.24 24.37 1.130 104.86%
q89 5.11 4.61 -0.508 90.06%
q90 3.32 3.26 -0.066 98.02%
q91 4.89 5.23 0.345 107.06%
q92 2.34 2.19 -0.154 93.41%
q93 54.48 55.14 0.657 101.21%
q94 17.39 17.91 0.524 103.01%
q9 96.40 95.46 -0.939 99.03%
q5 3.60 3.17 -0.429 88.07%
q96 27.93 27.99 0.061 100.22%
q97 2.70 3.00 0.300 111.09%
q98 10.64 9.79 -0.853 91.98%
q99 10.64 9.79 -0.853 91.98%
total 2184.92 2194.86 9.938 100.45%

@GlutenPerfBot
Copy link
Contributor

===== Performance report for TPCH SF2000 with Velox backend, for reference only ====

query log/native_master_01_11_2025_time.csv log/native_master_01_10_2025_6c60fd3af6_time.csv difference percentage
q1 42.91 44.52 1.617 103.77%
q2 42.71 43.95 1.245 102.92%
q3 91.84 89.91 -1.930 97.90%
q4 69.15 69.87 0.717 101.04%
q5 179.28 181.37 2.091 101.17%
q6 17.87 18.83 0.961 105.37%
q7 104.89 104.98 0.087 100.08%
q8 184.18 186.60 2.427 101.32%
q9 278.59 279.44 0.854 100.31%
q10 104.92 101.52 -3.402 96.76%
q11 33.65 34.56 0.908 102.70%
q12 44.25 44.12 -0.130 99.71%
q13 76.86 76.12 -0.739 99.04%
q14 36.27 37.96 1.694 104.67%
q15 67.08 66.91 -0.177 99.74%
q16 27.02 26.33 -0.696 97.43%
q17 234.23 232.10 -2.125 99.09%
q18 362.13 370.39 8.267 102.28%
q19 37.80 36.65 -1.150 96.96%
q20 61.51 60.18 -1.325 97.85%
q21 533.06 530.96 -2.104 99.61%
q22 24.73 24.52 -0.207 99.16%
total 2654.94 2661.82 6.884 100.26%

zml1206 pushed a commit to zml1206/incubator-gluten that referenced this pull request Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VL] Security Voliations

5 participants