Skip to content

Commit 5f77620

Browse files
marysakabbrezillon
authored andcommitted
drm/panthor: Restrict high priorities on group_create
We were allowing any users to create a high priority group without any permission checks. As a result, this was allowing possible denial of service. We now only allow the DRM master or users with the CAP_SYS_NICE capability to set higher priorities than PANTHOR_GROUP_PRIORITY_MEDIUM. As the sole user of that uAPI lives in Mesa and hardcode a value of MEDIUM [1], this should be safe to do. Additionally, as those checks are performed at the ioctl level, panthor_group_create now only check for priority level validity. [1]https://gitlab.freedesktop.org/mesa/mesa/-/blob/f390835074bdf162a63deb0311d1a6de527f9f89/src/gallium/drivers/panfrost/pan_csf.c#L1038 Signed-off-by: Mary Guillemard <[email protected]> Fixes: de85488 ("drm/panthor: Add the scheduler logical block") Cc: [email protected] Reviewed-by: Boris Brezillon <[email protected]> Signed-off-by: Boris Brezillon <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 9a71cf8 commit 5f77620

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

drivers/gpu/drm/panthor/panthor_drv.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/platform_device.h>
1111
#include <linux/pm_runtime.h>
1212

13+
#include <drm/drm_auth.h>
1314
#include <drm/drm_debugfs.h>
1415
#include <drm/drm_drv.h>
1516
#include <drm/drm_exec.h>
@@ -996,6 +997,24 @@ static int panthor_ioctl_group_destroy(struct drm_device *ddev, void *data,
996997
return panthor_group_destroy(pfile, args->group_handle);
997998
}
998999

1000+
static int group_priority_permit(struct drm_file *file,
1001+
u8 priority)
1002+
{
1003+
/* Ensure that priority is valid */
1004+
if (priority > PANTHOR_GROUP_PRIORITY_HIGH)
1005+
return -EINVAL;
1006+
1007+
/* Medium priority and below are always allowed */
1008+
if (priority <= PANTHOR_GROUP_PRIORITY_MEDIUM)
1009+
return 0;
1010+
1011+
/* Higher priorities require CAP_SYS_NICE or DRM_MASTER */
1012+
if (capable(CAP_SYS_NICE) || drm_is_current_master(file))
1013+
return 0;
1014+
1015+
return -EACCES;
1016+
}
1017+
9991018
static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
10001019
struct drm_file *file)
10011020
{
@@ -1011,6 +1030,10 @@ static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
10111030
if (ret)
10121031
return ret;
10131032

1033+
ret = group_priority_permit(file, args->priority);
1034+
if (ret)
1035+
return ret;
1036+
10141037
ret = panthor_group_create(pfile, args, queue_args);
10151038
if (ret >= 0) {
10161039
args->group_handle = ret;

drivers/gpu/drm/panthor/panthor_sched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3092,7 +3092,7 @@ int panthor_group_create(struct panthor_file *pfile,
30923092
if (group_args->pad)
30933093
return -EINVAL;
30943094

3095-
if (group_args->priority > PANTHOR_CSG_PRIORITY_HIGH)
3095+
if (group_args->priority >= PANTHOR_CSG_PRIORITY_COUNT)
30963096
return -EINVAL;
30973097

30983098
if ((group_args->compute_core_mask & ~ptdev->gpu_info.shader_present) ||

include/uapi/drm/panthor_drm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,11 @@ enum drm_panthor_group_priority {
692692
/** @PANTHOR_GROUP_PRIORITY_MEDIUM: Medium priority group. */
693693
PANTHOR_GROUP_PRIORITY_MEDIUM,
694694

695-
/** @PANTHOR_GROUP_PRIORITY_HIGH: High priority group. */
695+
/**
696+
* @PANTHOR_GROUP_PRIORITY_HIGH: High priority group.
697+
*
698+
* Requires CAP_SYS_NICE or DRM_MASTER.
699+
*/
696700
PANTHOR_GROUP_PRIORITY_HIGH,
697701
};
698702

0 commit comments

Comments
 (0)