Skip to content

Commit 9cbef30

Browse files
committed
Merge tag 'staging-5.15-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging driver fixes from Greg KH: "Here are two small staging driver fixes for 5.15-rc3: - greybus tty use-after-free bugfix - r8188eu ioctl overlap build warning fix Note, the r8188eu ioctl has been entirely removed for 5.16-rc1, but it's good to get this fixed now for people using this in 5.15. Both of these have been in linux-next for a while with no reported issues" * tag 'staging-5.15-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: staging: r8188eu: fix -Wrestrict warnings staging: greybus: uart: fix tty use after free
2 parents f9d4be2 + aa3233e commit 9cbef30

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

drivers/staging/greybus/uart.c

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,17 @@ static void gb_tty_port_shutdown(struct tty_port *port)
761761
gbphy_runtime_put_autosuspend(gb_tty->gbphy_dev);
762762
}
763763

764+
static void gb_tty_port_destruct(struct tty_port *port)
765+
{
766+
struct gb_tty *gb_tty = container_of(port, struct gb_tty, port);
767+
768+
if (gb_tty->minor != GB_NUM_MINORS)
769+
release_minor(gb_tty);
770+
kfifo_free(&gb_tty->write_fifo);
771+
kfree(gb_tty->buffer);
772+
kfree(gb_tty);
773+
}
774+
764775
static const struct tty_operations gb_ops = {
765776
.install = gb_tty_install,
766777
.open = gb_tty_open,
@@ -786,6 +797,7 @@ static const struct tty_port_operations gb_port_ops = {
786797
.dtr_rts = gb_tty_dtr_rts,
787798
.activate = gb_tty_port_activate,
788799
.shutdown = gb_tty_port_shutdown,
800+
.destruct = gb_tty_port_destruct,
789801
};
790802

791803
static int gb_uart_probe(struct gbphy_device *gbphy_dev,
@@ -798,39 +810,43 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
798810
int retval;
799811
int minor;
800812

801-
gb_tty = kzalloc(sizeof(*gb_tty), GFP_KERNEL);
802-
if (!gb_tty)
803-
return -ENOMEM;
804-
805813
connection = gb_connection_create(gbphy_dev->bundle,
806814
le16_to_cpu(gbphy_dev->cport_desc->id),
807815
gb_uart_request_handler);
808-
if (IS_ERR(connection)) {
809-
retval = PTR_ERR(connection);
810-
goto exit_tty_free;
811-
}
816+
if (IS_ERR(connection))
817+
return PTR_ERR(connection);
812818

813819
max_payload = gb_operation_get_payload_size_max(connection);
814820
if (max_payload < sizeof(struct gb_uart_send_data_request)) {
815821
retval = -EINVAL;
816822
goto exit_connection_destroy;
817823
}
818824

825+
gb_tty = kzalloc(sizeof(*gb_tty), GFP_KERNEL);
826+
if (!gb_tty) {
827+
retval = -ENOMEM;
828+
goto exit_connection_destroy;
829+
}
830+
831+
tty_port_init(&gb_tty->port);
832+
gb_tty->port.ops = &gb_port_ops;
833+
gb_tty->minor = GB_NUM_MINORS;
834+
819835
gb_tty->buffer_payload_max = max_payload -
820836
sizeof(struct gb_uart_send_data_request);
821837

822838
gb_tty->buffer = kzalloc(gb_tty->buffer_payload_max, GFP_KERNEL);
823839
if (!gb_tty->buffer) {
824840
retval = -ENOMEM;
825-
goto exit_connection_destroy;
841+
goto exit_put_port;
826842
}
827843

828844
INIT_WORK(&gb_tty->tx_work, gb_uart_tx_write_work);
829845

830846
retval = kfifo_alloc(&gb_tty->write_fifo, GB_UART_WRITE_FIFO_SIZE,
831847
GFP_KERNEL);
832848
if (retval)
833-
goto exit_buf_free;
849+
goto exit_put_port;
834850

835851
gb_tty->credits = GB_UART_FIRMWARE_CREDITS;
836852
init_completion(&gb_tty->credits_complete);
@@ -844,7 +860,7 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
844860
} else {
845861
retval = minor;
846862
}
847-
goto exit_kfifo_free;
863+
goto exit_put_port;
848864
}
849865

850866
gb_tty->minor = minor;
@@ -853,17 +869,14 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
853869
init_waitqueue_head(&gb_tty->wioctl);
854870
mutex_init(&gb_tty->mutex);
855871

856-
tty_port_init(&gb_tty->port);
857-
gb_tty->port.ops = &gb_port_ops;
858-
859872
gb_tty->connection = connection;
860873
gb_tty->gbphy_dev = gbphy_dev;
861874
gb_connection_set_data(connection, gb_tty);
862875
gb_gbphy_set_data(gbphy_dev, gb_tty);
863876

864877
retval = gb_connection_enable_tx(connection);
865878
if (retval)
866-
goto exit_release_minor;
879+
goto exit_put_port;
867880

868881
send_control(gb_tty, gb_tty->ctrlout);
869882

@@ -890,16 +903,10 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
890903

891904
exit_connection_disable:
892905
gb_connection_disable(connection);
893-
exit_release_minor:
894-
release_minor(gb_tty);
895-
exit_kfifo_free:
896-
kfifo_free(&gb_tty->write_fifo);
897-
exit_buf_free:
898-
kfree(gb_tty->buffer);
906+
exit_put_port:
907+
tty_port_put(&gb_tty->port);
899908
exit_connection_destroy:
900909
gb_connection_destroy(connection);
901-
exit_tty_free:
902-
kfree(gb_tty);
903910

904911
return retval;
905912
}
@@ -930,15 +937,10 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
930937
gb_connection_disable_rx(connection);
931938
tty_unregister_device(gb_tty_driver, gb_tty->minor);
932939

933-
/* FIXME - free transmit / receive buffers */
934-
935940
gb_connection_disable(connection);
936-
tty_port_destroy(&gb_tty->port);
937941
gb_connection_destroy(connection);
938-
release_minor(gb_tty);
939-
kfifo_free(&gb_tty->write_fifo);
940-
kfree(gb_tty->buffer);
941-
kfree(gb_tty);
942+
943+
tty_port_put(&gb_tty->port);
942944
}
943945

944946
static int gb_tty_init(void)

drivers/staging/r8188eu/os_dep/ioctl_linux.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,8 +5372,8 @@ static int rtw_mp_read_reg(struct net_device *dev,
53725372

53735373
pnext++;
53745374
if (*pnext != '\0') {
5375-
strtout = simple_strtoul(pnext, &ptmp, 16);
5376-
sprintf(extra, "%s %d", extra, strtout);
5375+
strtout = simple_strtoul(pnext, &ptmp, 16);
5376+
sprintf(extra + strlen(extra), " %d", strtout);
53775377
} else {
53785378
break;
53795379
}
@@ -5405,7 +5405,7 @@ static int rtw_mp_read_reg(struct net_device *dev,
54055405
pnext++;
54065406
if (*pnext != '\0') {
54075407
strtout = simple_strtoul(pnext, &ptmp, 16);
5408-
sprintf(extra, "%s %d", extra, strtout);
5408+
sprintf(extra + strlen(extra), " %d", strtout);
54095409
} else {
54105410
break;
54115411
}
@@ -5512,7 +5512,7 @@ static int rtw_mp_read_rf(struct net_device *dev,
55125512
pnext++;
55135513
if (*pnext != '\0') {
55145514
strtou = simple_strtoul(pnext, &ptmp, 16);
5515-
sprintf(extra, "%s %d", extra, strtou);
5515+
sprintf(extra + strlen(extra), " %d", strtou);
55165516
} else {
55175517
break;
55185518
}

0 commit comments

Comments
 (0)