Skip to content

Commit 4a3113c

Browse files
authored
properly validate open("dev/nvidia-uvm")
1 parent 77eee0e commit 4a3113c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

driverapi/src/librecuda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ libreCudaStatus_t libreCuInit(int flags) {
101101
// initialize mm
102102
{
103103
int fd_uvm_2 = open("/dev/nvidia-uvm", O_RDWR | O_CLOEXEC);
104+
LIBRECUDA_VALIDATE(fd_uvm_2 != -1, LIBRECUDA_ERROR_INVALID_DEVICE);
105+
104106
UVM_MM_INITIALIZE_PARAMS params{
105107
.uvmFd = fd_uvm
106108
};
@@ -119,9 +121,11 @@ libreCudaStatus_t libreCuInit(int flags) {
119121
} else {
120122
LIBRECUDA_DEBUG("UVM_MM_INITIALIZE failed with return code " + std::to_string(ret) + " and status " +
121123
std::to_string(status));
124+
close(fd_uvm_2);
122125
LIBRECUDA_FAIL(LIBRECUDA_ERROR_UNKNOWN);
123126
}
124127
} else {
128+
close(fd_uvm_2);
125129
driver_type = OPEN_KERNEL_MODULES;
126130
}
127131
}

0 commit comments

Comments
 (0)