Skip to content

Commit ba4e033

Browse files
Kuo-Hsiang-Choutdz
authored andcommitted
drm/ast: Fixed CVE for DP501
[Bug][DP501] If ASPEED P2A (PCI to AHB) bridge is disabled and disallowed for CVE_2019_6260 item3, and then the monitor's EDID is unable read through Parade DP501. The reason is the DP501's FW is mapped to BMC addressing space rather than Host addressing space. The resolution is that using "pci_iomap_range()" maps to DP501's FW that stored on the end of FB (Frame Buffer). In this case, FrameBuffer reserves the last 2MB used for the image of DP501. Signed-off-by: KuoHsiang Chou <kuohsiang_chou@aspeedtech.com> Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Link: https://patchwork.freedesktop.org/patch/msgid/20210421085859.17761-1-kuohsiang_chou@aspeedtech.com
1 parent 749da85 commit ba4e033

3 files changed

Lines changed: 125 additions & 37 deletions

File tree

‎drivers/gpu/drm/ast/ast_dp501.c‎

Lines changed: 103 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
189189
u32 i, data;
190190
u32 boot_address;
191191

192+
if (ast->config_mode != ast_use_p2a)
193+
return false;
194+
192195
data = ast_mindwm(ast, 0x1e6e2100) & 0x01;
193196
if (data) {
194197
boot_address = get_fw_base(ast);
@@ -207,6 +210,9 @@ static bool ast_launch_m68k(struct drm_device *dev)
207210
u8 *fw_addr = NULL;
208211
u8 jreg;
209212

213+
if (ast->config_mode != ast_use_p2a)
214+
return false;
215+
210216
data = ast_mindwm(ast, 0x1e6e2100) & 0x01;
211217
if (!data) {
212218

@@ -271,25 +277,55 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
271277
struct ast_private *ast = to_ast_private(dev);
272278
u32 boot_address, offset, data;
273279
u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
280+
u32 *plinkcap;
274281

275-
boot_address = get_fw_base(ast);
276-
277-
/* validate FW version */
278-
offset = 0xf000;
279-
data = ast_mindwm(ast, boot_address + offset);
280-
if ((data & 0xf0) != 0x10) /* version: 1x */
281-
return maxclk;
282-
283-
/* Read Link Capability */
284-
offset = 0xf014;
285-
*(u32 *)linkcap = ast_mindwm(ast, boot_address + offset);
286-
if (linkcap[2] == 0) {
287-
linkrate = linkcap[0];
288-
linklanes = linkcap[1];
289-
data = (linkrate == 0x0a) ? (90 * linklanes) : (54 * linklanes);
290-
if (data > 0xff)
291-
data = 0xff;
292-
maxclk = (u8)data;
282+
if (ast->config_mode == ast_use_p2a) {
283+
boot_address = get_fw_base(ast);
284+
285+
/* validate FW version */
286+
offset = AST_DP501_GBL_VERSION;
287+
data = ast_mindwm(ast, boot_address + offset);
288+
if ((data & AST_DP501_FW_VERSION_MASK) != AST_DP501_FW_VERSION_1) /* version: 1x */
289+
return maxclk;
290+
291+
/* Read Link Capability */
292+
offset = AST_DP501_LINKRATE;
293+
plinkcap = (u32 *)linkcap;
294+
*plinkcap = ast_mindwm(ast, boot_address + offset);
295+
if (linkcap[2] == 0) {
296+
linkrate = linkcap[0];
297+
linklanes = linkcap[1];
298+
data = (linkrate == 0x0a) ? (90 * linklanes) : (54 * linklanes);
299+
if (data > 0xff)
300+
data = 0xff;
301+
maxclk = (u8)data;
302+
}
303+
} else {
304+
if (!ast->dp501_fw_buf)
305+
return AST_DP501_DEFAULT_DCLK; /* 1024x768 as default */
306+
307+
/* dummy read */
308+
offset = 0x0000;
309+
data = readl(ast->dp501_fw_buf + offset);
310+
311+
/* validate FW version */
312+
offset = AST_DP501_GBL_VERSION;
313+
data = readl(ast->dp501_fw_buf + offset);
314+
if ((data & AST_DP501_FW_VERSION_MASK) != AST_DP501_FW_VERSION_1) /* version: 1x */
315+
return maxclk;
316+
317+
/* Read Link Capability */
318+
offset = AST_DP501_LINKRATE;
319+
plinkcap = (u32 *)linkcap;
320+
*plinkcap = readl(ast->dp501_fw_buf + offset);
321+
if (linkcap[2] == 0) {
322+
linkrate = linkcap[0];
323+
linklanes = linkcap[1];
324+
data = (linkrate == 0x0a) ? (90 * linklanes) : (54 * linklanes);
325+
if (data > 0xff)
326+
data = 0xff;
327+
maxclk = (u8)data;
328+
}
293329
}
294330
return maxclk;
295331
}
@@ -298,26 +334,57 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
298334
{
299335
struct ast_private *ast = to_ast_private(dev);
300336
u32 i, boot_address, offset, data;
337+
u32 *pEDIDidx;
301338

302-
boot_address = get_fw_base(ast);
303-
304-
/* validate FW version */
305-
offset = 0xf000;
306-
data = ast_mindwm(ast, boot_address + offset);
307-
if ((data & 0xf0) != 0x10)
308-
return false;
309-
310-
/* validate PnP Monitor */
311-
offset = 0xf010;
312-
data = ast_mindwm(ast, boot_address + offset);
313-
if (!(data & 0x01))
314-
return false;
339+
if (ast->config_mode == ast_use_p2a) {
340+
boot_address = get_fw_base(ast);
315341

316-
/* Read EDID */
317-
offset = 0xf020;
318-
for (i = 0; i < 128; i += 4) {
319-
data = ast_mindwm(ast, boot_address + offset + i);
320-
*(u32 *)(ediddata + i) = data;
342+
/* validate FW version */
343+
offset = AST_DP501_GBL_VERSION;
344+
data = ast_mindwm(ast, boot_address + offset);
345+
if ((data & AST_DP501_FW_VERSION_MASK) != AST_DP501_FW_VERSION_1)
346+
return false;
347+
348+
/* validate PnP Monitor */
349+
offset = AST_DP501_PNPMONITOR;
350+
data = ast_mindwm(ast, boot_address + offset);
351+
if (!(data & AST_DP501_PNP_CONNECTED))
352+
return false;
353+
354+
/* Read EDID */
355+
offset = AST_DP501_EDID_DATA;
356+
for (i = 0; i < 128; i += 4) {
357+
data = ast_mindwm(ast, boot_address + offset + i);
358+
pEDIDidx = (u32 *)(ediddata + i);
359+
*pEDIDidx = data;
360+
}
361+
} else {
362+
if (!ast->dp501_fw_buf)
363+
return false;
364+
365+
/* dummy read */
366+
offset = 0x0000;
367+
data = readl(ast->dp501_fw_buf + offset);
368+
369+
/* validate FW version */
370+
offset = AST_DP501_GBL_VERSION;
371+
data = readl(ast->dp501_fw_buf + offset);
372+
if ((data & AST_DP501_FW_VERSION_MASK) != AST_DP501_FW_VERSION_1)
373+
return false;
374+
375+
/* validate PnP Monitor */
376+
offset = AST_DP501_PNPMONITOR;
377+
data = readl(ast->dp501_fw_buf + offset);
378+
if (!(data & AST_DP501_PNP_CONNECTED))
379+
return false;
380+
381+
/* Read EDID */
382+
offset = AST_DP501_EDID_DATA;
383+
for (i = 0; i < 128; i += 4) {
384+
data = readl(ast->dp501_fw_buf + offset + i);
385+
pEDIDidx = (u32 *)(ediddata + i);
386+
*pEDIDidx = data;
387+
}
321388
}
322389

323390
return true;

‎drivers/gpu/drm/ast/ast_drv.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct ast_private {
150150

151151
void __iomem *regs;
152152
void __iomem *ioregs;
153+
void __iomem *dp501_fw_buf;
153154

154155
enum ast_chip chip;
155156
bool vga2_clone;
@@ -325,6 +326,17 @@ int ast_mode_config_init(struct ast_private *ast);
325326
#define AST_MM_ALIGN_SHIFT 4
326327
#define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
327328

329+
#define AST_DP501_FW_VERSION_MASK GENMASK(7, 4)
330+
#define AST_DP501_FW_VERSION_1 BIT(4)
331+
#define AST_DP501_PNP_CONNECTED BIT(1)
332+
333+
#define AST_DP501_DEFAULT_DCLK 65
334+
335+
#define AST_DP501_GBL_VERSION 0xf000
336+
#define AST_DP501_PNPMONITOR 0xf010
337+
#define AST_DP501_LINKRATE 0xf014
338+
#define AST_DP501_EDID_DATA 0xf020
339+
328340
int ast_mm_init(struct ast_private *ast);
329341

330342
/* ast post */

‎drivers/gpu/drm/ast/ast_main.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void ast_detect_config_mode(struct drm_device *dev, u32 *scu_rev)
9999
if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) {
100100
/* Double check it's actually working */
101101
data = ast_read32(ast, 0xf004);
102-
if (data != 0xFFFFFFFF) {
102+
if ((data != 0xFFFFFFFF) && (data != 0x00)) {
103103
/* P2A works, grab silicon revision */
104104
ast->config_mode = ast_use_p2a;
105105

@@ -411,6 +411,7 @@ struct ast_private *ast_device_create(const struct drm_driver *drv,
411411
return ast;
412412
dev = &ast->base;
413413

414+
dev->pdev = pdev;
414415
pci_set_drvdata(pdev, dev);
415416

416417
ast->regs = pcim_iomap(pdev, 1, 0);
@@ -450,6 +451,14 @@ struct ast_private *ast_device_create(const struct drm_driver *drv,
450451
if (ret)
451452
return ERR_PTR(ret);
452453

454+
/* map reserved buffer */
455+
ast->dp501_fw_buf = NULL;
456+
if (dev->vram_mm->vram_size < pci_resource_len(dev->pdev, 0)) {
457+
ast->dp501_fw_buf = pci_iomap_range(dev->pdev, 0, dev->vram_mm->vram_size, 0);
458+
if (!ast->dp501_fw_buf)
459+
drm_info(dev, "failed to map reserved buffer!\n");
460+
}
461+
453462
ret = ast_mode_config_init(ast);
454463
if (ret)
455464
return ERR_PTR(ret);

0 commit comments

Comments
 (0)