Skip to content

Commit 47d6a76

Browse files
committedJul 18, 2019
Merge branch 'floppy'
Merge floppy ioctl verification fixes from Denis Efremov. This also marks the floppy driver as orphaned - it turns out that Jiri no longer has working hardware. Actual working physical floppy hardware is getting hard to find, and while Willy was able to test this, I think the driver can be considered pretty much dead from an actual hardware standpoint. The hardware that is still sold seems to be mainly USB-based, which doesn't use this legacy driver at all. The old floppy disk controller is still emulated in various VM environments, so the driver isn't going away, but let's see if anybody is interested to step up to maintain it. The lack of hardware also likely means that the ioctl range verification fixes are probably mostly relevant to anybody using floppies in a virtual environment. Which is probably also going away in favor of USB storage emulation, but who knows. Will Decon reviewed the patches but I'm not rebasing them just for that, so I'll add a Reviewed-by: Will Deacon <will@kernel.org> here instead. * floppy: MAINTAINERS: mark floppy.c orphaned floppy: fix out-of-bounds read in copy_buffer floppy: fix invalid pointer dereference in drive_name floppy: fix out-of-bounds read in next_valid_format floppy: fix div-by-zero in setup_format_params
2 parents 22051d9 + be2ece4 commit 47d6a76

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed
 

‎MAINTAINERS

+2-3
Original file line numberDiff line numberDiff line change
@@ -6321,9 +6321,8 @@ F: Documentation/devicetree/bindings/counter/ftm-quaddec.txt
63216321
F: drivers/counter/ftm-quaddec.c
63226322

63236323
FLOPPY DRIVER
6324-
M: Jiri Kosina <jikos@kernel.org>
6325-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/floppy.git
6326-
S: Odd fixes
6324+
S: Orphan
6325+
L: linux-block@vger.kernel.org
63276326
F: drivers/block/floppy.c
63286327

63296328
FMC SUBSYSTEM

‎drivers/block/floppy.c

+32-2
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,9 @@ static void setup_format_params(int track)
21202120
raw_cmd->kernel_data = floppy_track_buffer;
21212121
raw_cmd->length = 4 * F_SECT_PER_TRACK;
21222122

2123+
if (!F_SECT_PER_TRACK)
2124+
return;
2125+
21232126
/* allow for about 30ms for data transport per track */
21242127
head_shift = (F_SECT_PER_TRACK + 5) / 6;
21252128

@@ -3230,8 +3233,12 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
32303233
int cnt;
32313234

32323235
/* sanity checking for parameters. */
3233-
if (g->sect <= 0 ||
3234-
g->head <= 0 ||
3236+
if ((int)g->sect <= 0 ||
3237+
(int)g->head <= 0 ||
3238+
/* check for overflow in max_sector */
3239+
(int)(g->sect * g->head) <= 0 ||
3240+
/* check for zero in F_SECT_PER_TRACK */
3241+
(unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
32353242
g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
32363243
/* check if reserved bits are set */
32373244
(g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
@@ -3375,6 +3382,24 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
33753382
return 0;
33763383
}
33773384

3385+
static bool valid_floppy_drive_params(const short autodetect[8],
3386+
int native_format)
3387+
{
3388+
size_t floppy_type_size = ARRAY_SIZE(floppy_type);
3389+
size_t i = 0;
3390+
3391+
for (i = 0; i < 8; ++i) {
3392+
if (autodetect[i] < 0 ||
3393+
autodetect[i] >= floppy_type_size)
3394+
return false;
3395+
}
3396+
3397+
if (native_format < 0 || native_format >= floppy_type_size)
3398+
return false;
3399+
3400+
return true;
3401+
}
3402+
33783403
static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
33793404
unsigned long param)
33803405
{
@@ -3501,6 +3526,9 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
35013526
SUPBOUND(size, strlen((const char *)outparam) + 1);
35023527
break;
35033528
case FDSETDRVPRM:
3529+
if (!valid_floppy_drive_params(inparam.dp.autodetect,
3530+
inparam.dp.native_format))
3531+
return -EINVAL;
35043532
*UDP = inparam.dp;
35053533
break;
35063534
case FDGETDRVPRM:
@@ -3698,6 +3726,8 @@ static int compat_setdrvprm(int drive,
36983726
return -EPERM;
36993727
if (copy_from_user(&v, arg, sizeof(struct compat_floppy_drive_params)))
37003728
return -EFAULT;
3729+
if (!valid_floppy_drive_params(v.autodetect, v.native_format))
3730+
return -EINVAL;
37013731
mutex_lock(&floppy_mutex);
37023732
UDP->cmos = v.cmos;
37033733
UDP->max_dtr = v.max_dtr;

0 commit comments

Comments
 (0)