Skip to content

Commit

Permalink
habanalabs: block scalar load_and_exe on external queue
Browse files Browse the repository at this point in the history
In Gaudi, the user can't execute scalar load_and_exe on external queue
because it can be a security hole. The driver doesn't parse the commands
being loaded and it can be msg_prot, which the user isn't allowed to use.

Reviewed-by: Tomer Tayar <ttayar@habana.ai>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
  • Loading branch information
Oded Gabbay committed Jun 24, 2020
1 parent 8c289ea commit 64536ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 24 additions & 1 deletion drivers/misc/habanalabs/gaudi/gaudi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3790,6 +3790,25 @@ static int gaudi_validate_dma_pkt_no_mmu(struct hl_device *hdev,
src_in_host);
}

static int gaudi_validate_load_and_exe_pkt(struct hl_device *hdev,
struct hl_cs_parser *parser,
struct packet_load_and_exe *user_pkt)
{
u32 cfg;

cfg = le32_to_cpu(user_pkt->cfg);

if (cfg & GAUDI_PKT_LOAD_AND_EXE_CFG_DST_MASK) {
dev_err(hdev->dev,
"User not allowed to use Load and Execute\n");
return -EPERM;
}

parser->patched_cb_size += sizeof(struct packet_load_and_exe);

return 0;
}

static int gaudi_validate_cb(struct hl_device *hdev,
struct hl_cs_parser *parser, bool is_mmu)
{
Expand Down Expand Up @@ -3838,6 +3857,11 @@ static int gaudi_validate_cb(struct hl_device *hdev,
rc = -EPERM;
break;

case PACKET_LOAD_AND_EXE:
rc = gaudi_validate_load_and_exe_pkt(hdev, parser,
(struct packet_load_and_exe *) user_pkt);
break;

case PACKET_LIN_DMA:
parser->contains_dma_pkt = true;
if (is_mmu)
Expand All @@ -3855,7 +3879,6 @@ static int gaudi_validate_cb(struct hl_device *hdev,
case PACKET_FENCE:
case PACKET_NOP:
case PACKET_ARB_POINT:
case PACKET_LOAD_AND_EXE:
parser->patched_cb_size += pkt_size;
break;

Expand Down
3 changes: 3 additions & 0 deletions drivers/misc/habanalabs/include/gaudi/gaudi_packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ struct packet_wait {
__le32 ctl;
};

#define GAUDI_PKT_LOAD_AND_EXE_CFG_DST_SHIFT 0
#define GAUDI_PKT_LOAD_AND_EXE_CFG_DST_MASK 0x00000001

struct packet_load_and_exe {
__le32 cfg;
__le32 ctl;
Expand Down

0 comments on commit 64536ab

Please sign in to comment.