Skip to content

Commit de0babd

Browse files
Jerome Glisseairlied
authored andcommitted
drm/radeon: enforce use of radeon_get_ib_value when reading user cmd
When ever parsing cmd buffer supplied by userspace we need to use radeon_get_ib_value rather than directly accessing the ib as the user cmd might not yet be copied into the ib thus the parser might read value that does not correspond to what user is sending and possibly allowing user to send malicious command undected. Signed-off-by: Jerome Glisse <jglisse@redhat.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent e28f639 commit de0babd

2 files changed

Lines changed: 62 additions & 62 deletions

File tree

‎drivers/gpu/drm/radeon/evergreen_cs.c‎

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,14 +2909,14 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
29092909
return -EINVAL;
29102910
}
29112911
if (tiled) {
2912-
dst_offset = ib[idx+1];
2912+
dst_offset = radeon_get_ib_value(p, idx+1);
29132913
dst_offset <<= 8;
29142914

29152915
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset >> 8);
29162916
p->idx += count + 7;
29172917
} else {
2918-
dst_offset = ib[idx+1];
2919-
dst_offset |= ((u64)(ib[idx+2] & 0xff)) << 32;
2918+
dst_offset = radeon_get_ib_value(p, idx+1);
2919+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
29202920

29212921
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
29222922
ib[idx+2] += upper_32_bits(dst_reloc->lobj.gpu_offset) & 0xff;
@@ -2954,12 +2954,12 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
29542954
DRM_ERROR("bad L2T, frame to fields DMA_PACKET_COPY\n");
29552955
return -EINVAL;
29562956
}
2957-
dst_offset = ib[idx+1];
2957+
dst_offset = radeon_get_ib_value(p, idx+1);
29582958
dst_offset <<= 8;
2959-
dst2_offset = ib[idx+2];
2959+
dst2_offset = radeon_get_ib_value(p, idx+2);
29602960
dst2_offset <<= 8;
2961-
src_offset = ib[idx+8];
2962-
src_offset |= ((u64)(ib[idx+9] & 0xff)) << 32;
2961+
src_offset = radeon_get_ib_value(p, idx+8);
2962+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+9) & 0xff)) << 32;
29632963
if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
29642964
dev_warn(p->dev, "DMA L2T, frame to fields src buffer too small (%llu %lu)\n",
29652965
src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
@@ -3014,12 +3014,12 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
30143014
DRM_ERROR("bad L2T, broadcast DMA_PACKET_COPY\n");
30153015
return -EINVAL;
30163016
}
3017-
dst_offset = ib[idx+1];
3017+
dst_offset = radeon_get_ib_value(p, idx+1);
30183018
dst_offset <<= 8;
3019-
dst2_offset = ib[idx+2];
3019+
dst2_offset = radeon_get_ib_value(p, idx+2);
30203020
dst2_offset <<= 8;
3021-
src_offset = ib[idx+8];
3022-
src_offset |= ((u64)(ib[idx+9] & 0xff)) << 32;
3021+
src_offset = radeon_get_ib_value(p, idx+8);
3022+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+9) & 0xff)) << 32;
30233023
if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
30243024
dev_warn(p->dev, "DMA L2T, broadcast src buffer too small (%llu %lu)\n",
30253025
src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
@@ -3046,22 +3046,22 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
30463046
/* detile bit */
30473047
if (idx_value & (1 << 31)) {
30483048
/* tiled src, linear dst */
3049-
src_offset = ib[idx+1];
3049+
src_offset = radeon_get_ib_value(p, idx+1);
30503050
src_offset <<= 8;
30513051
ib[idx+1] += (u32)(src_reloc->lobj.gpu_offset >> 8);
30523052

3053-
dst_offset = ib[idx+7];
3054-
dst_offset |= ((u64)(ib[idx+8] & 0xff)) << 32;
3053+
dst_offset = radeon_get_ib_value(p, idx+7);
3054+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
30553055
ib[idx+7] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
30563056
ib[idx+8] += upper_32_bits(dst_reloc->lobj.gpu_offset) & 0xff;
30573057
} else {
30583058
/* linear src, tiled dst */
3059-
src_offset = ib[idx+7];
3060-
src_offset |= ((u64)(ib[idx+8] & 0xff)) << 32;
3059+
src_offset = radeon_get_ib_value(p, idx+7);
3060+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
30613061
ib[idx+7] += (u32)(src_reloc->lobj.gpu_offset & 0xfffffffc);
30623062
ib[idx+8] += upper_32_bits(src_reloc->lobj.gpu_offset) & 0xff;
30633063

3064-
dst_offset = ib[idx+1];
3064+
dst_offset = radeon_get_ib_value(p, idx+1);
30653065
dst_offset <<= 8;
30663066
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset >> 8);
30673067
}
@@ -3098,12 +3098,12 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
30983098
DRM_ERROR("bad L2T, broadcast DMA_PACKET_COPY\n");
30993099
return -EINVAL;
31003100
}
3101-
dst_offset = ib[idx+1];
3101+
dst_offset = radeon_get_ib_value(p, idx+1);
31023102
dst_offset <<= 8;
3103-
dst2_offset = ib[idx+2];
3103+
dst2_offset = radeon_get_ib_value(p, idx+2);
31043104
dst2_offset <<= 8;
3105-
src_offset = ib[idx+8];
3106-
src_offset |= ((u64)(ib[idx+9] & 0xff)) << 32;
3105+
src_offset = radeon_get_ib_value(p, idx+8);
3106+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+9) & 0xff)) << 32;
31073107
if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
31083108
dev_warn(p->dev, "DMA L2T, broadcast src buffer too small (%llu %lu)\n",
31093109
src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
@@ -3135,22 +3135,22 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
31353135
/* detile bit */
31363136
if (idx_value & (1 << 31)) {
31373137
/* tiled src, linear dst */
3138-
src_offset = ib[idx+1];
3138+
src_offset = radeon_get_ib_value(p, idx+1);
31393139
src_offset <<= 8;
31403140
ib[idx+1] += (u32)(src_reloc->lobj.gpu_offset >> 8);
31413141

3142-
dst_offset = ib[idx+7];
3143-
dst_offset |= ((u64)(ib[idx+8] & 0xff)) << 32;
3142+
dst_offset = radeon_get_ib_value(p, idx+7);
3143+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
31443144
ib[idx+7] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
31453145
ib[idx+8] += upper_32_bits(dst_reloc->lobj.gpu_offset) & 0xff;
31463146
} else {
31473147
/* linear src, tiled dst */
3148-
src_offset = ib[idx+7];
3149-
src_offset |= ((u64)(ib[idx+8] & 0xff)) << 32;
3148+
src_offset = radeon_get_ib_value(p, idx+7);
3149+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
31503150
ib[idx+7] += (u32)(src_reloc->lobj.gpu_offset & 0xfffffffc);
31513151
ib[idx+8] += upper_32_bits(src_reloc->lobj.gpu_offset) & 0xff;
31523152

3153-
dst_offset = ib[idx+1];
3153+
dst_offset = radeon_get_ib_value(p, idx+1);
31543154
dst_offset <<= 8;
31553155
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset >> 8);
31563156
}
@@ -3176,10 +3176,10 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
31763176
switch (misc) {
31773177
case 0:
31783178
/* L2L, byte */
3179-
src_offset = ib[idx+2];
3180-
src_offset |= ((u64)(ib[idx+4] & 0xff)) << 32;
3181-
dst_offset = ib[idx+1];
3182-
dst_offset |= ((u64)(ib[idx+3] & 0xff)) << 32;
3179+
src_offset = radeon_get_ib_value(p, idx+2);
3180+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
3181+
dst_offset = radeon_get_ib_value(p, idx+1);
3182+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff)) << 32;
31833183
if ((src_offset + count) > radeon_bo_size(src_reloc->robj)) {
31843184
dev_warn(p->dev, "DMA L2L, byte src buffer too small (%llu %lu)\n",
31853185
src_offset + count, radeon_bo_size(src_reloc->robj));
@@ -3216,12 +3216,12 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
32163216
DRM_ERROR("bad L2L, dw, broadcast DMA_PACKET_COPY\n");
32173217
return -EINVAL;
32183218
}
3219-
dst_offset = ib[idx+1];
3220-
dst_offset |= ((u64)(ib[idx+4] & 0xff)) << 32;
3221-
dst2_offset = ib[idx+2];
3222-
dst2_offset |= ((u64)(ib[idx+5] & 0xff)) << 32;
3223-
src_offset = ib[idx+3];
3224-
src_offset |= ((u64)(ib[idx+6] & 0xff)) << 32;
3219+
dst_offset = radeon_get_ib_value(p, idx+1);
3220+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
3221+
dst2_offset = radeon_get_ib_value(p, idx+2);
3222+
dst2_offset |= ((u64)(radeon_get_ib_value(p, idx+5) & 0xff)) << 32;
3223+
src_offset = radeon_get_ib_value(p, idx+3);
3224+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+6) & 0xff)) << 32;
32253225
if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
32263226
dev_warn(p->dev, "DMA L2L, dw, broadcast src buffer too small (%llu %lu)\n",
32273227
src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
@@ -3251,10 +3251,10 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
32513251
}
32523252
} else {
32533253
/* L2L, dw */
3254-
src_offset = ib[idx+2];
3255-
src_offset |= ((u64)(ib[idx+4] & 0xff)) << 32;
3256-
dst_offset = ib[idx+1];
3257-
dst_offset |= ((u64)(ib[idx+3] & 0xff)) << 32;
3254+
src_offset = radeon_get_ib_value(p, idx+2);
3255+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
3256+
dst_offset = radeon_get_ib_value(p, idx+1);
3257+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff)) << 32;
32583258
if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
32593259
dev_warn(p->dev, "DMA L2L, dw src buffer too small (%llu %lu)\n",
32603260
src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
@@ -3279,8 +3279,8 @@ int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
32793279
DRM_ERROR("bad DMA_PACKET_CONSTANT_FILL\n");
32803280
return -EINVAL;
32813281
}
3282-
dst_offset = ib[idx+1];
3283-
dst_offset |= ((u64)(ib[idx+3] & 0x00ff0000)) << 16;
3282+
dst_offset = radeon_get_ib_value(p, idx+1);
3283+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0x00ff0000)) << 16;
32843284
if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
32853285
dev_warn(p->dev, "DMA constant fill buffer too small (%llu %lu)\n",
32863286
dst_offset, radeon_bo_size(dst_reloc->robj));

‎drivers/gpu/drm/radeon/r600_cs.c‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,14 +2623,14 @@ int r600_dma_cs_parse(struct radeon_cs_parser *p)
26232623
return -EINVAL;
26242624
}
26252625
if (tiled) {
2626-
dst_offset = ib[idx+1];
2626+
dst_offset = radeon_get_ib_value(p, idx+1);
26272627
dst_offset <<= 8;
26282628

26292629
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset >> 8);
26302630
p->idx += count + 5;
26312631
} else {
2632-
dst_offset = ib[idx+1];
2633-
dst_offset |= ((u64)(ib[idx+2] & 0xff)) << 32;
2632+
dst_offset = radeon_get_ib_value(p, idx+1);
2633+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
26342634

26352635
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
26362636
ib[idx+2] += upper_32_bits(dst_reloc->lobj.gpu_offset) & 0xff;
@@ -2658,43 +2658,43 @@ int r600_dma_cs_parse(struct radeon_cs_parser *p)
26582658
/* detile bit */
26592659
if (idx_value & (1 << 31)) {
26602660
/* tiled src, linear dst */
2661-
src_offset = ib[idx+1];
2661+
src_offset = radeon_get_ib_value(p, idx+1);
26622662
src_offset <<= 8;
26632663
ib[idx+1] += (u32)(src_reloc->lobj.gpu_offset >> 8);
26642664

2665-
dst_offset = ib[idx+5];
2666-
dst_offset |= ((u64)(ib[idx+6] & 0xff)) << 32;
2665+
dst_offset = radeon_get_ib_value(p, idx+5);
2666+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+6) & 0xff)) << 32;
26672667
ib[idx+5] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
26682668
ib[idx+6] += upper_32_bits(dst_reloc->lobj.gpu_offset) & 0xff;
26692669
} else {
26702670
/* linear src, tiled dst */
2671-
src_offset = ib[idx+5];
2672-
src_offset |= ((u64)(ib[idx+6] & 0xff)) << 32;
2671+
src_offset = radeon_get_ib_value(p, idx+5);
2672+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+6) & 0xff)) << 32;
26732673
ib[idx+5] += (u32)(src_reloc->lobj.gpu_offset & 0xfffffffc);
26742674
ib[idx+6] += upper_32_bits(src_reloc->lobj.gpu_offset) & 0xff;
26752675

2676-
dst_offset = ib[idx+1];
2676+
dst_offset = radeon_get_ib_value(p, idx+1);
26772677
dst_offset <<= 8;
26782678
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset >> 8);
26792679
}
26802680
p->idx += 7;
26812681
} else {
26822682
if (p->family >= CHIP_RV770) {
2683-
src_offset = ib[idx+2];
2684-
src_offset |= ((u64)(ib[idx+4] & 0xff)) << 32;
2685-
dst_offset = ib[idx+1];
2686-
dst_offset |= ((u64)(ib[idx+3] & 0xff)) << 32;
2683+
src_offset = radeon_get_ib_value(p, idx+2);
2684+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
2685+
dst_offset = radeon_get_ib_value(p, idx+1);
2686+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff)) << 32;
26872687

26882688
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
26892689
ib[idx+2] += (u32)(src_reloc->lobj.gpu_offset & 0xfffffffc);
26902690
ib[idx+3] += upper_32_bits(dst_reloc->lobj.gpu_offset) & 0xff;
26912691
ib[idx+4] += upper_32_bits(src_reloc->lobj.gpu_offset) & 0xff;
26922692
p->idx += 5;
26932693
} else {
2694-
src_offset = ib[idx+2];
2695-
src_offset |= ((u64)(ib[idx+3] & 0xff)) << 32;
2696-
dst_offset = ib[idx+1];
2697-
dst_offset |= ((u64)(ib[idx+3] & 0xff0000)) << 16;
2694+
src_offset = radeon_get_ib_value(p, idx+2);
2695+
src_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff)) << 32;
2696+
dst_offset = radeon_get_ib_value(p, idx+1);
2697+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff0000)) << 16;
26982698

26992699
ib[idx+1] += (u32)(dst_reloc->lobj.gpu_offset & 0xfffffffc);
27002700
ib[idx+2] += (u32)(src_reloc->lobj.gpu_offset & 0xfffffffc);
@@ -2724,8 +2724,8 @@ int r600_dma_cs_parse(struct radeon_cs_parser *p)
27242724
DRM_ERROR("bad DMA_PACKET_WRITE\n");
27252725
return -EINVAL;
27262726
}
2727-
dst_offset = ib[idx+1];
2728-
dst_offset |= ((u64)(ib[idx+3] & 0x00ff0000)) << 16;
2727+
dst_offset = radeon_get_ib_value(p, idx+1);
2728+
dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0x00ff0000)) << 16;
27292729
if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
27302730
dev_warn(p->dev, "DMA constant fill buffer too small (%llu %lu)\n",
27312731
dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));

0 commit comments

Comments
 (0)