Skip to content

Commit 3567ffa

Browse files
sareluziclaude
andcommitted
Fix security vulnerabilities across codebase
- Add bounds checking for buffer access in ds5_fw_logger.cpp - Fix buffer overflow in hwmc.cpp (increased buffer size + validation) - Replace VLA with heap allocation in StreamView.cpp to prevent stack overflow - Add malloc null-check in StreamView.cpp - Quote shell variables and add validation in build_all.sh - Replace unsafe strcpy with strncpy in framesextract.c - Add input validation for device paths in test_fw_version.py - Add security warning for NOPASSWD sudoers in install.tegra.artifacts.sh - Use GitHub actor variable instead of hardcoded git identity in workflows Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b43d8b6 commit 3567ffa

12 files changed

Lines changed: 89 additions & 23 deletions

File tree

.github/workflows/build-jp502.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- name: setup workspace
2121
run: yes | ./setup_workspace.sh 5.0.2
2222
- name: apply patches
23-
run: git config --global user.email "builder@example.com" && git config --global user.name "builder" && ./apply_patches.sh 5.0.2
23+
run: |
24+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
25+
git config --global user.name "${{ github.actor }}"
26+
./apply_patches.sh 5.0.2
2427
- name: build
2528
run: ./build_all.sh 5.0.2

.github/workflows/build-jp512.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- name: setup workspace
2121
run: yes | ./setup_workspace.sh 5.1.2
2222
- name: apply patches
23-
run: git config --global user.email "builder@example.com" && git config --global user.name "builder" && ./apply_patches.sh 5.1.2
23+
run: |
24+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
25+
git config --global user.name "${{ github.actor }}"
26+
./apply_patches.sh 5.1.2
2427
- name: build
2528
run: ./build_all.sh 5.1.2

.github/workflows/build-jp6.1.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- name: setup workspace
2121
run: yes | ./setup_workspace.sh 6.1
2222
- name: apply patches
23-
run: git config --global user.email "builder@example.com" && git config --global user.name "builder" && ./apply_patches.sh 6.1
23+
run: |
24+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
25+
git config --global user.name "${{ github.actor }}"
26+
./apply_patches.sh 6.1
2427
- name: build
2528
run: ./build_all.sh 6.1

.github/workflows/build-jp6.2.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- name: setup workspace
2121
run: yes | ./setup_workspace.sh 6.2
2222
- name: apply patches
23-
run: git config --global user.email "builder@example.com" && git config --global user.name "builder" && ./apply_patches.sh 6.2
23+
run: |
24+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
25+
git config --global user.name "${{ github.actor }}"
26+
./apply_patches.sh 6.2
2427
- name: build
2528
run: ./build_all.sh 6.2

.github/workflows/build-jp6.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- name: setup workspace
2121
run: yes | ./setup_workspace.sh 6.0
2222
- name: apply patches
23-
run: git config --global user.email "builder@example.com" && git config --global user.name "builder" && ./apply_patches.sh 6.0
23+
run: |
24+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
25+
git config --global user.name "${{ github.actor }}"
26+
./apply_patches.sh 6.0
2427
- name: build
2528
run: ./build_all.sh 6.0

build_all.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ export TEGRA_KERNEL_OUT="$DEVDIR/images/$1"
5959
# Clean if requested
6060
if [[ $CLEAN == 1 ]]; then
6161
echo "Cleaning build artifacts for $1..."
62-
rm -rf $TEGRA_KERNEL_OUT
63-
rm -rf $SRCS/out
62+
if [[ -z "$TEGRA_KERNEL_OUT" ]]; then
63+
echo "Error: TEGRA_KERNEL_OUT is not set"
64+
exit 1
65+
fi
66+
rm -rf "$TEGRA_KERNEL_OUT"
67+
rm -rf "$SRCS/out"
6468
fi
6569

6670
mkdir -p $TEGRA_KERNEL_OUT
@@ -75,7 +79,7 @@ export KERNEL_MODULES_OUT=$TEGRA_KERNEL_OUT/modules
7579
if [[ "$JETPACK_VERSION" == "6.x" ]]; then
7680
cd $SRCS
7781
export KERNEL_HEADERS=$SRCS/kernel/kernel-jammy-src
78-
ln -sf $TEGRA_KERNEL_OUT $SRCS/out
82+
ln -sf "$TEGRA_KERNEL_OUT" "$SRCS/out"
7983
if [[ "$DEVDBG" == "1" ]]; then
8084
cd $KERNEL_HEADERS
8185
# Generate .config file from default defconfig

test/install.tegra.artifacts.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/bash
22
set -e
33

4-
# add jenkins user to sudo group
5-
# add the following line to /etc/sudoers for jenkins user, here nvidia
4+
# SECURITY WARNING: The sudoers configuration below grants passwordless root access.
5+
# Only use in isolated CI/CD environments with restricted network access.
6+
# Never enable on production systems or systems with sensitive data.
7+
# Consider using dedicated CI service accounts with audit logging.
8+
#
9+
# To enable for jenkins/CI user (NOT RECOMMENDED for production):
610
# nvidia ALL=(root) NOPASSWD: /sbin/reboot, /sbin/install.tegra.artifacts.sh
711

812
RELEASE=$(ls lib/modules)

test/test_fw_version.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import subprocess
22
import pytest
3+
import re
4+
5+
def validate_video_device(device):
6+
"""Validate device is a safe video device path."""
7+
# Accept only video device numbers (0-99)
8+
if not re.match(r'^[0-9]{1,2}$', str(device)):
9+
raise ValueError(f"Invalid device: {device}. Expected video device number (0-99)")
10+
return str(device)
311

412
@pytest.mark.d457
513
@pytest.mark.parametrize("device", {'0'})
614
def test_fw_version(device):
715
try:
16+
device = validate_video_device(device)
817
key = "fw_version"
9-
result = subprocess.check_call(["v4l2-ctl", "-d"+device, "-C", key])
18+
result = subprocess.check_call(["v4l2-ctl", "-d", device, "-C", key])
1019
assert result == 0
1120

12-
std_output = subprocess.check_output(["v4l2-ctl", "-d"+device, "-C", key])
21+
std_output = subprocess.check_output(["v4l2-ctl", "-d", device, "-C", key])
1322
key += ": "
1423
assert key in std_output.decode(), "Couldn't fetch FW version"
1524

@@ -26,8 +35,14 @@ def test_fw_version(device):
2635
dfu_device = subprocess.check_output(["ls", "/sys/class/d4xx-class/"]).decode()
2736
assert "d4xx-dfu-" in dfu_device, "D4xx DFU device not found"
2837

38+
# Validate DFU device name to prevent path traversal
39+
dfu_device_name = dfu_device.strip()
40+
if not re.match(r'^d4xx-dfu-[0-9]+$', dfu_device_name):
41+
raise ValueError(f"Invalid DFU device name: {dfu_device_name}")
42+
2943
# Get FW version from DFU device info
30-
dfu_device_info = subprocess.check_output(["cat", "/dev/"+dfu_device.strip()]).decode()
44+
dfu_device_path = f"/dev/{dfu_device_name}"
45+
dfu_device_info = subprocess.check_output(["cat", dfu_device_path]).decode()
3146

3247
# Check whether the DFU info also has same FW version
3348
assert fw_version_str in dfu_device_info, "FW versions read through v4l2-ctl utility and DFU device info doesn't match"

test/test_metadata/framesextract.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ void process_frame_data(void){
7373
char *token;
7474
unsigned int col = 0;
7575
char tmp[1024];
76-
strcpy(tmp, line);
76+
strncpy(tmp, line, sizeof(tmp) - 1);
77+
tmp[sizeof(tmp) - 1] = '\0';
7778
token = strtok(tmp, ",");
7879
unsigned long int curr_val = 0;
7980
while (token && col < 3) {
@@ -128,7 +129,8 @@ void process_frame_data(void){
128129
while (fgets(line, sizeof(line), csv)) {
129130
lines[count] = strdup(line);
130131
char tmp[1024];
131-
strcpy(tmp, line);
132+
strncpy(tmp, line, sizeof(tmp) - 1);
133+
tmp[sizeof(tmp) - 1] = '\0';
132134
char *token = strtok(tmp, ",");
133135
int col = 0;
134136
while (token && col < 3) {

utilities/streamApp/ds5_fw_logger.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ int main(int argc, char *argv[])
112112
cout << "FW_Log_Data:";
113113
for (i = 4; i < sizeof(ds5_fw_log_msg) + HEADER_SIZE; i++)
114114
{
115-
cout << uppercase << std::setfill ('0') << setw(2) << std::hex << (int)log[j*sizeof(ds5_fw_log_msg)+i] << " ";
115+
size_t idx = j * sizeof(ds5_fw_log_msg) + i;
116+
if (idx >= sizeof(log))
117+
break;
118+
cout << uppercase << std::setfill ('0') << setw(2) << std::hex << (int)log[idx] << " ";
116119
}
117120
cout << endl;
118121
last_seq = msg->seq_id;

0 commit comments

Comments
 (0)