Skip to content

Commit 2b3fd77

Browse files
evdenisSomasundaram Krishnasamy
authored andcommitted
floppy: fix out-of-bounds read in copy_buffer
[ Upstream commit da99466 ] This fixes a global out-of-bounds read access in the copy_buffer function of the floppy driver. The FDDEFPRM ioctl allows one to set the geometry of a disk. The sect and head fields (unsigned int) of the floppy_drive structure are used to compute the max_sector (int) in the make_raw_rw_request function. It is possible to overflow the max_sector. Next, max_sector is passed to the copy_buffer function and used in one of the memcpy calls. An unprivileged user could trigger the bug if the device is accessible, but requires a floppy disk to be inserted. The patch adds the check for the .sect * .head multiplication for not overflowing in the set_geometry function. The bug was found by syzkaller. Signed-off-by: Denis Efremov <[email protected]> Tested-by: Willy Tarreau <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit ff54c44f103825a426e46d08b5d3d76e44791a87) Orabug: 30318217 CVE: CVE-2019-14283 Signed-off-by: Larry Bassel <[email protected]> Reviewed-by: Allen Pais <[email protected]> Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent ca1d2aa commit 2b3fd77

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/block/floppy.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,8 +3236,12 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
32363236
int cnt;
32373237

32383238
/* sanity checking for parameters. */
3239-
if (g->sect <= 0 ||
3240-
g->head <= 0 ||
3239+
if ((int)g->sect <= 0 ||
3240+
(int)g->head <= 0 ||
3241+
/* check for overflow in max_sector */
3242+
(int)(g->sect * g->head) <= 0 ||
3243+
/* check for zero in F_SECT_PER_TRACK */
3244+
(unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
32413245
g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
32423246
/* check if reserved bits are set */
32433247
(g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)

0 commit comments

Comments
 (0)