lkml.org 
[lkml]   [2020]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 3/3] floppy: suppress UBSAN warning in setup_rw_floppy()
From
Date
On Sun, 2020-04-26 at 16:07 +0300, Denis Efremov wrote:
> UBSAN: array-index-out-of-bounds in drivers/block/floppy.c:1521:45
> index 16 is out of range for type 'unsigned char [16]'
[]
> This out-of-bounds access is intentional. The command in struct
> floppy_raw_cmd may take up the space initially intended for the reply
> and the reply count. It is needed for long 82078 commands such as
> RESTORE, which takes 17 command bytes. Initial cmd size is not enough
> and since struct setup_rw_floppy is a part of uapi we check that
> cmd_count is in [0:16+1+16] in raw_cmd_copyin().
>
> The patch adds union with original cmd,reply_count,reply fields and
> fullcmd field of equivalent size. The cmd accesses are turned to
> fullcmd where appropriate to suppress UBSAN warning.
[]
> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
[]
> @@ -1072,7 +1072,7 @@ static void setup_DMA(void)
>
> pr_info("zero dma transfer size:");
> for (i = 0; i < raw_cmd->cmd_count; i++)
> - pr_cont("%x,", raw_cmd->cmd[i]);
> + pr_cont("%x,", raw_cmd->fullcmd[i]);
> pr_cont("\n");

slightly unrelated trivia: perhaps better as:

print_hex_dump(KERN_INFO, "zero dma transfer size: ",
DUMP_PREFIX_NONE, 16, 1,
raw_cmd->fullcmd, raw_cmd->cmd_count, false);

to avoid pr_cont use.


\
 
 \ /
  Last update: 2020-04-27 01:20    [W:0.691 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site