Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kernel-open/common/inc/nvkms-kapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,9 @@ struct NvKmsKapiFunctionsTable {
* \param [out] pMaxSubmittedMap Returns a CPU mapping of the semaphore
* surface's semaphore memory to the client.
*
* \param [out] pSurfaceSize Returns the size of the imported semaphore
* surface in bytes. May be NULL.
*
* \return struct NvKmsKapiSemaphoreSurface* on success, NULL on failure.
*/
struct NvKmsKapiSemaphoreSurface* (*importSemaphoreSurface)
Expand All @@ -1365,7 +1368,8 @@ struct NvKmsKapiFunctionsTable {
NvU64 nvKmsParamsUser,
NvU64 nvKmsParamsSize,
void **pSemaphoreMap,
void **pMaxSubmittedMap
void **pMaxSubmittedMap,
NvU64 *pSurfaceSize
);

/*!
Expand Down
25 changes: 24 additions & 1 deletion kernel-open/nvidia-drm/nvidia-drm-fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,13 +1231,15 @@ __nv_drm_semsurf_fence_ctx_new(
struct NvKmsKapiSemaphoreSurface *pSemSurface;
uint8_t *semMapping;
uint8_t *maxSubmittedMapping;
NvU64 surfaceSize = 0;
char worker_name[20+16+1]; /* strlen(nvidia-drm/timeline-) + 16 for %llx + NUL */

pSemSurface = nvKms->importSemaphoreSurface(nv_dev->pDevice,
p->nvkms_params_ptr,
p->nvkms_params_size,
(void **)&semMapping,
(void **)&maxSubmittedMapping);
(void **)&maxSubmittedMapping,
&surfaceSize);
if (!pSemSurface) {
NV_DRM_DEV_LOG_ERR(
nv_dev,
Expand All @@ -1246,6 +1248,27 @@ __nv_drm_semsurf_fence_ctx_new(
goto failed;
}

/*
* The index is provided by userspace as a 64-bit value. Reject values
* outside the imported surface before shifting the CPU mappings by them,
* and before truncating to the 32-bit RM semaphore index below. The
* max-submitted value must fit within one stride so that indexing the
* semaphore mapping also bounds the max-submitted mapping.
*/
if (nv_dev->semsurf_stride == 0 ||
(nv_dev->semsurf_max_submitted_offset + sizeof(NvU64)) >
nv_dev->semsurf_stride ||
p->index >= (surfaceSize / nv_dev->semsurf_stride) ||
p->index > NV_U32_MAX) {
NV_DRM_DEV_LOG_ERR(
nv_dev,
"Invalid semaphore index %" NvU64_fmtu " for semaphore surface of %"
NvU64_fmtu " bytes",
p->index, surfaceSize);

goto failed_alloc_fence_context;
}

/*
* Allocate a fence context object and initialize it.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/nvidia-modeset/kapi/include/nvkms-kapi-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ nvKmsKapiImportSemaphoreSurface(struct NvKmsKapiDevice *device,
NvU64 nvKmsParamsUser,
NvU64 nvKmsParamsSize,
void **pSemaphoreMap,
void **pMaxSubmittedMap);
void **pMaxSubmittedMap,
NvU64 *pSurfaceSize);

void
nvKmsKapiFreeSemaphoreSurface(struct NvKmsKapiDevice *device,
Expand Down
6 changes: 5 additions & 1 deletion src/nvidia-modeset/kapi/interface/nvkms-kapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,9 @@ struct NvKmsKapiFunctionsTable {
* \param [out] pMaxSubmittedMap Returns a CPU mapping of the semaphore
* surface's semaphore memory to the client.
*
* \param [out] pSurfaceSize Returns the size of the imported semaphore
* surface in bytes. May be NULL.
*
* \return struct NvKmsKapiSemaphoreSurface* on success, NULL on failure.
*/
struct NvKmsKapiSemaphoreSurface* (*importSemaphoreSurface)
Expand All @@ -1365,7 +1368,8 @@ struct NvKmsKapiFunctionsTable {
NvU64 nvKmsParamsUser,
NvU64 nvKmsParamsSize,
void **pSemaphoreMap,
void **pMaxSubmittedMap
void **pMaxSubmittedMap,
NvU64 *pSurfaceSize
);

/*!
Expand Down
7 changes: 6 additions & 1 deletion src/nvidia-modeset/kapi/src/nvkms-kapi-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ nvKmsKapiImportSemaphoreSurface
NvU64 nvKmsParamsUser,
NvU64 nvKmsParamsSize,
void **pSemaphoreMap,
void **pMaxSubmittedMap
void **pMaxSubmittedMap,
NvU64 *pSurfaceSize
)
{
struct NvKmsKapiSemaphoreSurface *ss = NULL;
Expand Down Expand Up @@ -311,6 +312,10 @@ nvKmsKapiImportSemaphoreSurface
*pMaxSubmittedMap = NULL;
}

if (pSurfaceSize != NULL) {
*pSurfaceSize = p.semaphoreSurfaceSize;
}

return ss;

fail:
Expand Down