Skip to content

Commit a89936c

Browse files
jhovoldgregkh
authored andcommitted
ipack: ipoctal: fix stack information leak
The tty driver name is used also after registering the driver and must specifically not be allocated on the stack to avoid leaking information to user space (or triggering an oops). Drivers should not try to encode topology information in the tty device name but this one snuck in through staging without anyone noticing and another driver has since copied this malpractice. Fixing the ABI is a separate issue, but this at least plugs the security hole. Fixes: ba4dc61 ("Staging: ipack: add support for IP-OCTAL mezzanine board") Cc: [email protected] # 3.5 Acked-by: Samuel Iglesias Gonsalvez <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 913581b commit a89936c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/ipack/devices/ipoctal.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
264264
int res;
265265
int i;
266266
struct tty_driver *tty;
267-
char name[20];
268267
struct ipoctal_channel *channel;
269268
struct ipack_region *region;
270269
void __iomem *addr;
@@ -355,8 +354,11 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
355354
/* Fill struct tty_driver with ipoctal data */
356355
tty->owner = THIS_MODULE;
357356
tty->driver_name = KBUILD_MODNAME;
358-
sprintf(name, KBUILD_MODNAME ".%d.%d.", bus_nr, slot);
359-
tty->name = name;
357+
tty->name = kasprintf(GFP_KERNEL, KBUILD_MODNAME ".%d.%d.", bus_nr, slot);
358+
if (!tty->name) {
359+
res = -ENOMEM;
360+
goto err_put_driver;
361+
}
360362
tty->major = 0;
361363

362364
tty->minor_start = 0;
@@ -371,8 +373,7 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
371373
res = tty_register_driver(tty);
372374
if (res) {
373375
dev_err(&ipoctal->dev->dev, "Can't register tty driver.\n");
374-
tty_driver_kref_put(tty);
375-
return res;
376+
goto err_free_name;
376377
}
377378

378379
/* Save struct tty_driver for use it when uninstalling the device */
@@ -409,6 +410,13 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
409410
ipoctal_irq_handler, ipoctal);
410411

411412
return 0;
413+
414+
err_free_name:
415+
kfree(tty->name);
416+
err_put_driver:
417+
tty_driver_kref_put(tty);
418+
419+
return res;
412420
}
413421

414422
static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel,
@@ -696,6 +704,7 @@ static void __ipoctal_remove(struct ipoctal *ipoctal)
696704
}
697705

698706
tty_unregister_driver(ipoctal->tty_drv);
707+
kfree(ipoctal->tty_drv->name);
699708
tty_driver_kref_put(ipoctal->tty_drv);
700709
kfree(ipoctal);
701710
}

0 commit comments

Comments
 (0)