From: Sasha Levin Date: Mon, 13 Jun 2022 00:59:22 +0000 (-0400) Subject: Fixes for 4.14 X-Git-Tag: v4.9.318~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e0eef54777500c271fb6e32d671d12e29d37fdb1;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.14 Signed-off-by: Sasha Levin --- diff --git a/queue-4.14/clocksource-drivers-sp804-avoid-error-on-multiple-in.patch-11976 b/queue-4.14/clocksource-drivers-sp804-avoid-error-on-multiple-in.patch-11976 new file mode 100644 index 00000000000..dcc21d02ca9 --- /dev/null +++ b/queue-4.14/clocksource-drivers-sp804-avoid-error-on-multiple-in.patch-11976 @@ -0,0 +1,65 @@ +From d8db160044ccbf0e0d909e98f0882eeded21fb2b Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 6 May 2022 17:25:22 +0100 +Subject: clocksource/drivers/sp804: Avoid error on multiple instances + +From: Andre Przywara + +[ Upstream commit a98399cbc1e05f7b977419f03905501d566cf54e ] + +When a machine sports more than one SP804 timer instance, we only bring +up the first one, since multiple timers of the same kind are not useful +to Linux. As this is intentional behaviour, we should not return an +error message, as we do today: +=============== +[ 0.000800] Failed to initialize '/bus@8000000/motherboard-bus@8000000/iofpga-bus@300000000/timer@120000': -22 +=============== + +Replace the -EINVAL return with a debug message and return 0 instead. + +Also we do not reach the init function anymore if the DT node is +disabled (as this is now handled by OF_DECLARE), so remove the explicit +check for that case. + +This fixes a long standing bogus error when booting ARM's fastmodels. + +Signed-off-by: Andre Przywara +Reviewed-by: Robin Murphy +Link: https://lore.kernel.org/r/20220506162522.3675399-1-andre.przywara@arm.com +Signed-off-by: Daniel Lezcano +Signed-off-by: Sasha Levin +--- + drivers/clocksource/timer-sp804.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/drivers/clocksource/timer-sp804.c b/drivers/clocksource/timer-sp804.c +index 3ac9dec9a038..42cac9262630 100644 +--- a/drivers/clocksource/timer-sp804.c ++++ b/drivers/clocksource/timer-sp804.c +@@ -227,6 +227,11 @@ static int __init sp804_of_init(struct device_node *np) + struct clk *clk1, *clk2; + const char *name = of_get_property(np, "compatible", NULL); + ++ if (initialized) { ++ pr_debug("%pOF: skipping further SP804 timer device\n", np); ++ return 0; ++ } ++ + base = of_iomap(np, 0); + if (!base) + return -ENXIO; +@@ -235,11 +240,6 @@ static int __init sp804_of_init(struct device_node *np) + writel(0, base + TIMER_CTRL); + writel(0, base + TIMER_2_BASE + TIMER_CTRL); + +- if (initialized || !of_device_is_available(np)) { +- ret = -EINVAL; +- goto err; +- } +- + clk1 = of_clk_get(np, 0); + if (IS_ERR(clk1)) + clk1 = NULL; +-- +2.35.1 + diff --git a/queue-4.14/drivers-staging-rtl8192e-fix-deadlock-in-rtllib_beac.patch-17195 b/queue-4.14/drivers-staging-rtl8192e-fix-deadlock-in-rtllib_beac.patch-17195 new file mode 100644 index 00000000000..8fe79435de3 --- /dev/null +++ b/queue-4.14/drivers-staging-rtl8192e-fix-deadlock-in-rtllib_beac.patch-17195 @@ -0,0 +1,55 @@ +From f00f8769e02c36adc1582c00bb07eaeacb535405 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 17 Apr 2022 22:16:41 +0800 +Subject: drivers: staging: rtl8192e: Fix deadlock in rtllib_beacons_stop() + +From: Duoming Zhou + +[ Upstream commit 9b6bdbd9337de3917945847bde262a34a87a6303 ] + +There is a deadlock in rtllib_beacons_stop(), which is shown +below: + + (Thread 1) | (Thread 2) + | rtllib_send_beacon() +rtllib_beacons_stop() | mod_timer() + spin_lock_irqsave() //(1) | (wait a time) + ... | rtllib_send_beacon_cb() + del_timer_sync() | spin_lock_irqsave() //(2) + (wait timer to stop) | ... + +We hold ieee->beacon_lock in position (1) of thread 1 and +use del_timer_sync() to wait timer to stop, but timer handler +also need ieee->beacon_lock in position (2) of thread 2. +As a result, rtllib_beacons_stop() will block forever. + +This patch extracts del_timer_sync() from the protection of +spin_lock_irqsave(), which could let timer handler to obtain +the needed lock. + +Signed-off-by: Duoming Zhou +Link: https://lore.kernel.org/r/20220417141641.124388-1-duoming@zju.edu.cn +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/staging/rtl8192e/rtllib_softmac.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c +index e4be85af31e7..1edece694fff 100644 +--- a/drivers/staging/rtl8192e/rtllib_softmac.c ++++ b/drivers/staging/rtl8192e/rtllib_softmac.c +@@ -654,9 +654,9 @@ static void rtllib_beacons_stop(struct rtllib_device *ieee) + spin_lock_irqsave(&ieee->beacon_lock, flags); + + ieee->beacon_txing = 0; +- del_timer_sync(&ieee->beacon_timer); + + spin_unlock_irqrestore(&ieee->beacon_lock, flags); ++ del_timer_sync(&ieee->beacon_timer); + + } + +-- +2.35.1 + diff --git a/queue-4.14/drivers-tty-serial-fix-deadlock-in-sa1100_set_termio.patch-18821 b/queue-4.14/drivers-tty-serial-fix-deadlock-in-sa1100_set_termio.patch-18821 new file mode 100644 index 00000000000..cd9762d4e00 --- /dev/null +++ b/queue-4.14/drivers-tty-serial-fix-deadlock-in-sa1100_set_termio.patch-18821 @@ -0,0 +1,61 @@ +From a4a111bd72e63017e08eb14127d936960fe16ec5 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 17 Apr 2022 19:16:26 +0800 +Subject: drivers: tty: serial: Fix deadlock in sa1100_set_termios() + +From: Duoming Zhou + +[ Upstream commit 62b2caef400c1738b6d22f636c628d9f85cd4c4c ] + +There is a deadlock in sa1100_set_termios(), which is shown +below: + + (Thread 1) | (Thread 2) + | sa1100_enable_ms() +sa1100_set_termios() | mod_timer() + spin_lock_irqsave() //(1) | (wait a time) + ... | sa1100_timeout() + del_timer_sync() | spin_lock_irqsave() //(2) + (wait timer to stop) | ... + +We hold sport->port.lock in position (1) of thread 1 and +use del_timer_sync() to wait timer to stop, but timer handler +also need sport->port.lock in position (2) of thread 2. As a result, +sa1100_set_termios() will block forever. + +This patch moves del_timer_sync() before spin_lock_irqsave() +in order to prevent the deadlock. + +Signed-off-by: Duoming Zhou +Link: https://lore.kernel.org/r/20220417111626.7802-1-duoming@zju.edu.cn +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/tty/serial/sa1100.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/tty/serial/sa1100.c b/drivers/tty/serial/sa1100.c +index fd3d1329d48c..68eb1c9faa29 100644 +--- a/drivers/tty/serial/sa1100.c ++++ b/drivers/tty/serial/sa1100.c +@@ -452,6 +452,8 @@ sa1100_set_termios(struct uart_port *port, struct ktermios *termios, + baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); + quot = uart_get_divisor(port, baud); + ++ del_timer_sync(&sport->timer); ++ + spin_lock_irqsave(&sport->port.lock, flags); + + sport->port.read_status_mask &= UTSR0_TO_SM(UTSR0_TFS); +@@ -482,8 +484,6 @@ sa1100_set_termios(struct uart_port *port, struct ktermios *termios, + UTSR1_TO_SM(UTSR1_ROR); + } + +- del_timer_sync(&sport->timer); +- + /* + * Update the per-port timeout. + */ +-- +2.35.1 + diff --git a/queue-4.14/drivers-usb-host-fix-deadlock-in-oxu_bus_suspend.patch-1678 b/queue-4.14/drivers-usb-host-fix-deadlock-in-oxu_bus_suspend.patch-1678 new file mode 100644 index 00000000000..d463e9da490 --- /dev/null +++ b/queue-4.14/drivers-usb-host-fix-deadlock-in-oxu_bus_suspend.patch-1678 @@ -0,0 +1,54 @@ +From cf65ea64df8de2031cf3200eecbd91a2a473754f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 17 Apr 2022 20:03:05 +0800 +Subject: drivers: usb: host: Fix deadlock in oxu_bus_suspend() + +From: Duoming Zhou + +[ Upstream commit 4d378f2ae58138d4c55684e1d274e7dd94aa6524 ] + +There is a deadlock in oxu_bus_suspend(), which is shown below: + + (Thread 1) | (Thread 2) + | timer_action() +oxu_bus_suspend() | mod_timer() + spin_lock_irq() //(1) | (wait a time) + ... | oxu_watchdog() + del_timer_sync() | spin_lock_irq() //(2) + (wait timer to stop) | ... + +We hold oxu->lock in position (1) of thread 1, and use +del_timer_sync() to wait timer to stop, but timer handler +also need oxu->lock in position (2) of thread 2. As a result, +oxu_bus_suspend() will block forever. + +This patch extracts del_timer_sync() from the protection of +spin_lock_irq(), which could let timer handler to obtain +the needed lock. + +Signed-off-by: Duoming Zhou +Link: https://lore.kernel.org/r/20220417120305.64577-1-duoming@zju.edu.cn +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/host/oxu210hp-hcd.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c +index 1d3a79c2eba2..c986dcb7a87c 100644 +--- a/drivers/usb/host/oxu210hp-hcd.c ++++ b/drivers/usb/host/oxu210hp-hcd.c +@@ -3489,8 +3489,10 @@ static int oxu_bus_suspend(struct usb_hcd *hcd) + } + } + ++ spin_unlock_irq(&oxu->lock); + /* turn off now-idle HC */ + del_timer_sync(&oxu->watchdog); ++ spin_lock_irq(&oxu->lock); + ehci_halt(oxu); + hcd->state = HC_STATE_SUSPENDED; + +-- +2.35.1 + diff --git a/queue-4.14/drm-radeon-fix-a-possible-null-pointer-dereference.patch-16535 b/queue-4.14/drm-radeon-fix-a-possible-null-pointer-dereference.patch-16535 new file mode 100644 index 00000000000..45d86344447 --- /dev/null +++ b/queue-4.14/drm-radeon-fix-a-possible-null-pointer-dereference.patch-16535 @@ -0,0 +1,47 @@ +From fc6d4ad4cd841dac369321f29939a64a58c2de5f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 17 May 2022 17:57:00 +0800 +Subject: drm/radeon: fix a possible null pointer dereference + +From: Gong Yuanjun + +[ Upstream commit a2b28708b645c5632dc93669ab06e97874c8244f ] + +In radeon_fp_native_mode(), the return value of drm_mode_duplicate() +is assigned to mode, which will lead to a NULL pointer dereference +on failure of drm_mode_duplicate(). Add a check to avoid npd. + +The failure status of drm_cvt_mode() on the other path is checked too. + +Signed-off-by: Gong Yuanjun +Signed-off-by: Alex Deucher +Signed-off-by: Sasha Levin +--- + drivers/gpu/drm/radeon/radeon_connectors.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c +index fc021b8e4077..dd7d771d13b5 100644 +--- a/drivers/gpu/drm/radeon/radeon_connectors.c ++++ b/drivers/gpu/drm/radeon/radeon_connectors.c +@@ -489,6 +489,8 @@ static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encode + native_mode->vdisplay != 0 && + native_mode->clock != 0) { + mode = drm_mode_duplicate(dev, native_mode); ++ if (!mode) ++ return NULL; + mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; + drm_mode_set_name(mode); + +@@ -503,6 +505,8 @@ static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encode + * simpler. + */ + mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false); ++ if (!mode) ++ return NULL; + mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; + DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name); + } +-- +2.35.1 + diff --git a/queue-4.14/extcon-modify-extcon-device-to-be-created-after-driv.patch-24531 b/queue-4.14/extcon-modify-extcon-device-to-be-created-after-driv.patch-24531 new file mode 100644 index 00000000000..e99994d5f09 --- /dev/null +++ b/queue-4.14/extcon-modify-extcon-device-to-be-created-after-driv.patch-24531 @@ -0,0 +1,100 @@ +From c1a0aeb6341564246b7423c9790fb000f810999f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 27 Apr 2022 12:00:05 +0900 +Subject: extcon: Modify extcon device to be created after driver data is set + +From: bumwoo lee + +[ Upstream commit 5dcc2afe716d69f5112ce035cb14f007461ff189 ] + +Currently, someone can invoke the sysfs such as state_show() +intermittently before dev_set_drvdata() is done. +And it can be a cause of kernel Oops because of edev is Null at that time. +So modified the driver registration to after setting drviver data. + +- Oops's backtrace. + +Backtrace: +[] (state_show) from [] (dev_attr_show) +[] (dev_attr_show) from [] (sysfs_kf_seq_show) +[] (sysfs_kf_seq_show) from [] (kernfs_seq_show) +[] (kernfs_seq_show) from [] (seq_read) +[] (seq_read) from [] (kernfs_fop_read) +[] (kernfs_fop_read) from [] (__vfs_read) +[] (__vfs_read) from [] (vfs_read) +[] (vfs_read) from [] (ksys_read) +[] (ksys_read) from [] (sys_read) +[] (sys_read) from [] (__sys_trace_return) + +Signed-off-by: bumwoo lee +Signed-off-by: Chanwoo Choi +Signed-off-by: Sasha Levin +--- + drivers/extcon/extcon.c | 29 +++++++++++++++++------------ + 1 file changed, 17 insertions(+), 12 deletions(-) + +diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c +index e9fe3e3bac2b..81a552654cc7 100644 +--- a/drivers/extcon/extcon.c ++++ b/drivers/extcon/extcon.c +@@ -1241,19 +1241,14 @@ int extcon_dev_register(struct extcon_dev *edev) + edev->dev.type = &edev->extcon_dev_type; + } + +- ret = device_register(&edev->dev); +- if (ret) { +- put_device(&edev->dev); +- goto err_dev; +- } +- + spin_lock_init(&edev->lock); +- edev->nh = devm_kcalloc(&edev->dev, edev->max_supported, +- sizeof(*edev->nh), GFP_KERNEL); +- if (!edev->nh) { +- ret = -ENOMEM; +- device_unregister(&edev->dev); +- goto err_dev; ++ if (edev->max_supported) { ++ edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), ++ GFP_KERNEL); ++ if (!edev->nh) { ++ ret = -ENOMEM; ++ goto err_alloc_nh; ++ } + } + + for (index = 0; index < edev->max_supported; index++) +@@ -1264,6 +1259,12 @@ int extcon_dev_register(struct extcon_dev *edev) + dev_set_drvdata(&edev->dev, edev); + edev->state = 0; + ++ ret = device_register(&edev->dev); ++ if (ret) { ++ put_device(&edev->dev); ++ goto err_dev; ++ } ++ + mutex_lock(&extcon_dev_list_lock); + list_add(&edev->entry, &extcon_dev_list); + mutex_unlock(&extcon_dev_list_lock); +@@ -1271,6 +1272,9 @@ int extcon_dev_register(struct extcon_dev *edev) + return 0; + + err_dev: ++ if (edev->max_supported) ++ kfree(edev->nh); ++err_alloc_nh: + if (edev->max_supported) + kfree(edev->extcon_dev_type.groups); + err_alloc_groups: +@@ -1331,6 +1335,7 @@ void extcon_dev_unregister(struct extcon_dev *edev) + if (edev->max_supported) { + kfree(edev->extcon_dev_type.groups); + kfree(edev->cables); ++ kfree(edev->nh); + } + + put_device(&edev->dev); +-- +2.35.1 + diff --git a/queue-4.14/iio-dummy-iio_simple_dummy-check-the-return-value-of.patch-27365 b/queue-4.14/iio-dummy-iio_simple_dummy-check-the-return-value-of.patch-27365 new file mode 100644 index 00000000000..ca70179ee94 --- /dev/null +++ b/queue-4.14/iio-dummy-iio_simple_dummy-check-the-return-value-of.patch-27365 @@ -0,0 +1,88 @@ +From 4c174484bde598f16de27062fdca77add7fa6050 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 5 Mar 2022 11:14:05 +0800 +Subject: iio: dummy: iio_simple_dummy: check the return value of kstrdup() + +From: Xiaoke Wang + +[ Upstream commit ba93642188a6fed754bf7447f638bc410e05a929 ] + +kstrdup() is also a memory allocation-related function, it returns NULL +when some memory errors happen. So it is better to check the return +value of it so to catch the memory error in time. Besides, there should +have a kfree() to clear up the allocation if we get a failure later in +this function to prevent memory leak. + +Signed-off-by: Xiaoke Wang +Link: https://lore.kernel.org/r/tencent_C920CFCC33B9CC1C63141FE1334A39FF8508@qq.com +Signed-off-by: Jonathan Cameron +Signed-off-by: Sasha Levin +--- + drivers/iio/dummy/iio_simple_dummy.c | 20 ++++++++++++-------- + 1 file changed, 12 insertions(+), 8 deletions(-) + +diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c +index ad3410e528b6..7fef76f0b5c7 100644 +--- a/drivers/iio/dummy/iio_simple_dummy.c ++++ b/drivers/iio/dummy/iio_simple_dummy.c +@@ -572,10 +572,9 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) + struct iio_sw_device *swd; + + swd = kzalloc(sizeof(*swd), GFP_KERNEL); +- if (!swd) { +- ret = -ENOMEM; +- goto error_kzalloc; +- } ++ if (!swd) ++ return ERR_PTR(-ENOMEM); ++ + /* + * Allocate an IIO device. + * +@@ -587,7 +586,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) + indio_dev = iio_device_alloc(sizeof(*st)); + if (!indio_dev) { + ret = -ENOMEM; +- goto error_ret; ++ goto error_free_swd; + } + + st = iio_priv(indio_dev); +@@ -618,6 +617,10 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) + * indio_dev->name = spi_get_device_id(spi)->name; + */ + indio_dev->name = kstrdup(name, GFP_KERNEL); ++ if (!indio_dev->name) { ++ ret = -ENOMEM; ++ goto error_free_device; ++ } + + /* Provide description of available channels */ + indio_dev->channels = iio_dummy_channels; +@@ -634,7 +637,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) + + ret = iio_simple_dummy_events_register(indio_dev); + if (ret < 0) +- goto error_free_device; ++ goto error_free_name; + + ret = iio_simple_dummy_configure_buffer(indio_dev); + if (ret < 0) +@@ -651,11 +654,12 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) + iio_simple_dummy_unconfigure_buffer(indio_dev); + error_unregister_events: + iio_simple_dummy_events_unregister(indio_dev); ++error_free_name: ++ kfree(indio_dev->name); + error_free_device: + iio_device_free(indio_dev); +-error_ret: ++error_free_swd: + kfree(swd); +-error_kzalloc: + return ERR_PTR(ret); + } + +-- +2.35.1 + diff --git a/queue-4.14/kernfs-separate-kernfs_pr_cont_buf-and-rename_lock.patch-27977 b/queue-4.14/kernfs-separate-kernfs_pr_cont_buf-and-rename_lock.patch-27977 new file mode 100644 index 00000000000..a94ea0f83c3 --- /dev/null +++ b/queue-4.14/kernfs-separate-kernfs_pr_cont_buf-and-rename_lock.patch-27977 @@ -0,0 +1,142 @@ +From d981fb5210ab5f81f00bec608cf7ab46d391c1c9 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 16 May 2022 12:09:51 -0700 +Subject: kernfs: Separate kernfs_pr_cont_buf and rename_lock. + +From: Hao Luo + +[ Upstream commit 1a702dc88e150487c9c173a249b3d236498b9183 ] + +Previously the protection of kernfs_pr_cont_buf was piggy backed by +rename_lock, which means that pr_cont() needs to be protected under +rename_lock. This can cause potential circular lock dependencies. + +If there is an OOM, we have the following call hierarchy: + + -> cpuset_print_current_mems_allowed() + -> pr_cont_cgroup_name() + -> pr_cont_kernfs_name() + +pr_cont_kernfs_name() will grab rename_lock and call printk. So we have +the following lock dependencies: + + kernfs_rename_lock -> console_sem + +Sometimes, printk does a wakeup before releasing console_sem, which has +the dependence chain: + + console_sem -> p->pi_lock -> rq->lock + +Now, imagine one wants to read cgroup_name under rq->lock, for example, +printing cgroup_name in a tracepoint in the scheduler code. They will +be holding rq->lock and take rename_lock: + + rq->lock -> kernfs_rename_lock + +Now they will deadlock. + +A prevention to this circular lock dependency is to separate the +protection of pr_cont_buf from rename_lock. In principle, rename_lock +is to protect the integrity of cgroup name when copying to buf. Once +pr_cont_buf has got its content, rename_lock can be dropped. So it's +safe to drop rename_lock after kernfs_name_locked (and +kernfs_path_from_node_locked) and rely on a dedicated pr_cont_lock +to protect pr_cont_buf. + +Acked-by: Tejun Heo +Signed-off-by: Hao Luo +Link: https://lore.kernel.org/r/20220516190951.3144144-1-haoluo@google.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + fs/kernfs/dir.c | 31 +++++++++++++++++++------------ + 1 file changed, 19 insertions(+), 12 deletions(-) + +diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c +index 8697b750b1c9..fa2dee322ee9 100644 +--- a/fs/kernfs/dir.c ++++ b/fs/kernfs/dir.c +@@ -20,7 +20,15 @@ + + DEFINE_MUTEX(kernfs_mutex); + static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */ +-static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by rename_lock */ ++/* ++ * Don't use rename_lock to piggy back on pr_cont_buf. We don't want to ++ * call pr_cont() while holding rename_lock. Because sometimes pr_cont() ++ * will perform wakeups when releasing console_sem. Holding rename_lock ++ * will introduce deadlock if the scheduler reads the kernfs_name in the ++ * wakeup path. ++ */ ++static DEFINE_SPINLOCK(kernfs_pr_cont_lock); ++static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by pr_cont_lock */ + static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */ + + #define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb) +@@ -229,12 +237,12 @@ void pr_cont_kernfs_name(struct kernfs_node *kn) + { + unsigned long flags; + +- spin_lock_irqsave(&kernfs_rename_lock, flags); ++ spin_lock_irqsave(&kernfs_pr_cont_lock, flags); + +- kernfs_name_locked(kn, kernfs_pr_cont_buf, sizeof(kernfs_pr_cont_buf)); ++ kernfs_name(kn, kernfs_pr_cont_buf, sizeof(kernfs_pr_cont_buf)); + pr_cont("%s", kernfs_pr_cont_buf); + +- spin_unlock_irqrestore(&kernfs_rename_lock, flags); ++ spin_unlock_irqrestore(&kernfs_pr_cont_lock, flags); + } + + /** +@@ -248,10 +256,10 @@ void pr_cont_kernfs_path(struct kernfs_node *kn) + unsigned long flags; + int sz; + +- spin_lock_irqsave(&kernfs_rename_lock, flags); ++ spin_lock_irqsave(&kernfs_pr_cont_lock, flags); + +- sz = kernfs_path_from_node_locked(kn, NULL, kernfs_pr_cont_buf, +- sizeof(kernfs_pr_cont_buf)); ++ sz = kernfs_path_from_node(kn, NULL, kernfs_pr_cont_buf, ++ sizeof(kernfs_pr_cont_buf)); + if (sz < 0) { + pr_cont("(error)"); + goto out; +@@ -265,7 +273,7 @@ void pr_cont_kernfs_path(struct kernfs_node *kn) + pr_cont("%s", kernfs_pr_cont_buf); + + out: +- spin_unlock_irqrestore(&kernfs_rename_lock, flags); ++ spin_unlock_irqrestore(&kernfs_pr_cont_lock, flags); + } + + /** +@@ -850,13 +858,12 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent, + + lockdep_assert_held(&kernfs_mutex); + +- /* grab kernfs_rename_lock to piggy back on kernfs_pr_cont_buf */ +- spin_lock_irq(&kernfs_rename_lock); ++ spin_lock_irq(&kernfs_pr_cont_lock); + + len = strlcpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf)); + + if (len >= sizeof(kernfs_pr_cont_buf)) { +- spin_unlock_irq(&kernfs_rename_lock); ++ spin_unlock_irq(&kernfs_pr_cont_lock); + return NULL; + } + +@@ -868,7 +875,7 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent, + parent = kernfs_find_ns(parent, name, ns); + } + +- spin_unlock_irq(&kernfs_rename_lock); ++ spin_unlock_irq(&kernfs_pr_cont_lock); + + return parent; + } +-- +2.35.1 + diff --git a/queue-4.14/lkdtm-usercopy-expand-size-of-out-of-frame-object.patch-16982 b/queue-4.14/lkdtm-usercopy-expand-size-of-out-of-frame-object.patch-16982 new file mode 100644 index 00000000000..43c5340f4d1 --- /dev/null +++ b/queue-4.14/lkdtm-usercopy-expand-size-of-out-of-frame-object.patch-16982 @@ -0,0 +1,75 @@ +From 52c598669ad3a9a1f75b5f9db54a8fd385fd63af Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 16 Feb 2022 12:15:03 -0800 +Subject: lkdtm/usercopy: Expand size of "out of frame" object + +From: Kees Cook + +[ Upstream commit f387e86d3a74407bdd9c5815820ac9d060962840 ] + +To be sufficiently out of range for the usercopy test to see the lifetime +mismatch, expand the size of the "bad" buffer, which will let it be +beyond current_stack_pointer regardless of stack growth direction. +Paired with the recent addition of stack depth checking under +CONFIG_HARDENED_USERCOPY=y, this will correctly start tripping again. + +Reported-by: Muhammad Usama Anjum +Cc: Arnd Bergmann +Cc: Greg Kroah-Hartman +Reviewed-by: Muhammad Usama Anjum +Link: https://lore.kernel.org/lkml/762faf1b-0443-5ddf-4430-44a20cf2ec4d@collabora.com/ +Signed-off-by: Kees Cook +Signed-off-by: Sasha Levin +--- + drivers/misc/lkdtm_usercopy.c | 17 ++++++++++++++--- + 1 file changed, 14 insertions(+), 3 deletions(-) + +diff --git a/drivers/misc/lkdtm_usercopy.c b/drivers/misc/lkdtm_usercopy.c +index a64372cc148d..178b55141772 100644 +--- a/drivers/misc/lkdtm_usercopy.c ++++ b/drivers/misc/lkdtm_usercopy.c +@@ -30,12 +30,12 @@ static const unsigned char test_text[] = "This is a test.\n"; + */ + static noinline unsigned char *trick_compiler(unsigned char *stack) + { +- return stack + 0; ++ return stack + unconst; + } + + static noinline unsigned char *do_usercopy_stack_callee(int value) + { +- unsigned char buf[32]; ++ unsigned char buf[128]; + int i; + + /* Exercise stack to avoid everything living in registers. */ +@@ -43,7 +43,12 @@ static noinline unsigned char *do_usercopy_stack_callee(int value) + buf[i] = value & 0xff; + } + +- return trick_compiler(buf); ++ /* ++ * Put the target buffer in the middle of stack allocation ++ * so that we don't step on future stack users regardless ++ * of stack growth direction. ++ */ ++ return trick_compiler(&buf[(128/2)-32]); + } + + static noinline void do_usercopy_stack(bool to_user, bool bad_frame) +@@ -66,6 +71,12 @@ static noinline void do_usercopy_stack(bool to_user, bool bad_frame) + bad_stack -= sizeof(unsigned long); + } + ++#ifdef ARCH_HAS_CURRENT_STACK_POINTER ++ pr_info("stack : %px\n", (void *)current_stack_pointer); ++#endif ++ pr_info("good_stack: %px-%px\n", good_stack, good_stack + sizeof(good_stack)); ++ pr_info("bad_stack : %px-%px\n", bad_stack, bad_stack + sizeof(good_stack)); ++ + user_addr = vm_mmap(NULL, 0, PAGE_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_ANONYMOUS | MAP_PRIVATE, 0); +-- +2.35.1 + diff --git a/queue-4.14/md-protect-md_unregister_thread-from-reentrancy.patch-16041 b/queue-4.14/md-protect-md_unregister_thread-from-reentrancy.patch-16041 new file mode 100644 index 00000000000..927a62a7ff3 --- /dev/null +++ b/queue-4.14/md-protect-md_unregister_thread-from-reentrancy.patch-16041 @@ -0,0 +1,63 @@ +From 73ddaa4b9cd7e1b7a7060eb04395364e54fa0251 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 29 Apr 2022 16:49:09 +0800 +Subject: md: protect md_unregister_thread from reentrancy + +From: Guoqing Jiang + +[ Upstream commit 1e267742283a4b5a8ca65755c44166be27e9aa0f ] + +Generally, the md_unregister_thread is called with reconfig_mutex, but +raid_message in dm-raid doesn't hold reconfig_mutex to unregister thread, +so md_unregister_thread can be called simulitaneously from two call sites +in theory. + +Then after previous commit which remove the protection of reconfig_mutex +for md_unregister_thread completely, the potential issue could be worse +than before. + +Let's take pers_lock at the beginning of function to ensure reentrancy. + +Reported-by: Donald Buczek +Signed-off-by: Guoqing Jiang +Signed-off-by: Song Liu +Signed-off-by: Sasha Levin +--- + drivers/md/md.c | 15 ++++++++++----- + 1 file changed, 10 insertions(+), 5 deletions(-) + +diff --git a/drivers/md/md.c b/drivers/md/md.c +index 9b0270dc37f4..36d4cc1d7429 100644 +--- a/drivers/md/md.c ++++ b/drivers/md/md.c +@@ -7590,17 +7590,22 @@ EXPORT_SYMBOL(md_register_thread); + + void md_unregister_thread(struct md_thread **threadp) + { +- struct md_thread *thread = *threadp; +- if (!thread) +- return; +- pr_debug("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); +- /* Locking ensures that mddev_unlock does not wake_up a ++ struct md_thread *thread; ++ ++ /* ++ * Locking ensures that mddev_unlock does not wake_up a + * non-existent thread + */ + spin_lock(&pers_lock); ++ thread = *threadp; ++ if (!thread) { ++ spin_unlock(&pers_lock); ++ return; ++ } + *threadp = NULL; + spin_unlock(&pers_lock); + ++ pr_debug("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk)); + kthread_stop(thread->tsk); + kfree(thread); + } +-- +2.35.1 + diff --git a/queue-4.14/misc-rtsx-set-null-intfdata-when-probe-fails.patch-995 b/queue-4.14/misc-rtsx-set-null-intfdata-when-probe-fails.patch-995 new file mode 100644 index 00000000000..c879303b1cd --- /dev/null +++ b/queue-4.14/misc-rtsx-set-null-intfdata-when-probe-fails.patch-995 @@ -0,0 +1,39 @@ +From 686ebed0fa5db536ce8f9427d7ef36ca1d58fc2a Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 29 Apr 2022 15:09:13 -0600 +Subject: misc: rtsx: set NULL intfdata when probe fails + +From: Shuah Khan + +[ Upstream commit f861d36e021e1ac4a0a2a1f6411d623809975d63 ] + +rtsx_usb_probe() doesn't call usb_set_intfdata() to null out the +interface pointer when probe fails. This leaves a stale pointer. +Noticed the missing usb_set_intfdata() while debugging an unrelated +invalid DMA mapping problem. + +Fix it with a call to usb_set_intfdata(..., NULL). + +Signed-off-by: Shuah Khan +Link: https://lore.kernel.org/r/20220429210913.46804-1-skhan@linuxfoundation.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/mfd/rtsx_usb.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c +index 691dab791f7a..e94f855eac15 100644 +--- a/drivers/mfd/rtsx_usb.c ++++ b/drivers/mfd/rtsx_usb.c +@@ -678,6 +678,7 @@ static int rtsx_usb_probe(struct usb_interface *intf, + return 0; + + out_init_fail: ++ usb_set_intfdata(ucr->pusb_intf, NULL); + usb_free_coherent(ucr->pusb_dev, IOBUF_SIZE, ucr->iobuf, + ucr->iobuf_dma); + return ret; +-- +2.35.1 + diff --git a/queue-4.14/modpost-fix-undefined-behavior-of-is_arm_mapping_sym.patch-15924 b/queue-4.14/modpost-fix-undefined-behavior-of-is_arm_mapping_sym.patch-15924 new file mode 100644 index 00000000000..2d4db5d5bfe --- /dev/null +++ b/queue-4.14/modpost-fix-undefined-behavior-of-is_arm_mapping_sym.patch-15924 @@ -0,0 +1,63 @@ +From 16a7c84b32278c1d115c1935ac0cc0046f9de13e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 24 May 2022 01:46:22 +0900 +Subject: modpost: fix undefined behavior of is_arm_mapping_symbol() + +From: Masahiro Yamada + +[ Upstream commit d6b732666a1bae0df3c3ae06925043bba34502b1 ] + +The return value of is_arm_mapping_symbol() is unpredictable when "$" +is passed in. + +strchr(3) says: + The strchr() and strrchr() functions return a pointer to the matched + character or NULL if the character is not found. The terminating null + byte is considered part of the string, so that if c is specified as + '\0', these functions return a pointer to the terminator. + +When str[1] is '\0', strchr("axtd", str[1]) is not NULL, and str[2] is +referenced (i.e. buffer overrun). + +Test code +--------- + + char str1[] = "abc"; + char str2[] = "ab"; + + strcpy(str1, "$"); + strcpy(str2, "$"); + + printf("test1: %d\n", is_arm_mapping_symbol(str1)); + printf("test2: %d\n", is_arm_mapping_symbol(str2)); + +Result +------ + + test1: 0 + test2: 1 + +Signed-off-by: Masahiro Yamada +Reviewed-by: Nick Desaulniers +Signed-off-by: Sasha Levin +--- + scripts/mod/modpost.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c +index bc2c860f88ef..f35fb7fcd98c 100644 +--- a/scripts/mod/modpost.c ++++ b/scripts/mod/modpost.c +@@ -1229,7 +1229,8 @@ static int secref_whitelist(const struct sectioncheck *mismatch, + + static inline int is_arm_mapping_symbol(const char *str) + { +- return str[0] == '$' && strchr("axtd", str[1]) ++ return str[0] == '$' && ++ (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x') + && (str[2] == '\0' || str[2] == '.'); + } + +-- +2.35.1 + diff --git a/queue-4.14/nbd-call-genl_unregister_family-first-in-nbd_cleanup.patch-23844 b/queue-4.14/nbd-call-genl_unregister_family-first-in-nbd_cleanup.patch-23844 new file mode 100644 index 00000000000..98dd96762a1 --- /dev/null +++ b/queue-4.14/nbd-call-genl_unregister_family-first-in-nbd_cleanup.patch-23844 @@ -0,0 +1,74 @@ +From 5452b0a276d39708e34ab5057b10ffa1bd229716 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 21 May 2022 15:37:44 +0800 +Subject: nbd: call genl_unregister_family() first in nbd_cleanup() + +From: Yu Kuai + +[ Upstream commit 06c4da89c24e7023ea448cadf8e9daf06a0aae6e ] + +Otherwise there may be race between module removal and the handling of +netlink command, which can lead to the oops as shown below: + + BUG: kernel NULL pointer dereference, address: 0000000000000098 + Oops: 0002 [#1] SMP PTI + CPU: 1 PID: 31299 Comm: nbd-client Tainted: G E 5.14.0-rc4 + Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) + RIP: 0010:down_write+0x1a/0x50 + Call Trace: + start_creating+0x89/0x130 + debugfs_create_dir+0x1b/0x130 + nbd_start_device+0x13d/0x390 [nbd] + nbd_genl_connect+0x42f/0x748 [nbd] + genl_family_rcv_msg_doit.isra.0+0xec/0x150 + genl_rcv_msg+0xe5/0x1e0 + netlink_rcv_skb+0x55/0x100 + genl_rcv+0x29/0x40 + netlink_unicast+0x1a8/0x250 + netlink_sendmsg+0x21b/0x430 + ____sys_sendmsg+0x2a4/0x2d0 + ___sys_sendmsg+0x81/0xc0 + __sys_sendmsg+0x62/0xb0 + __x64_sys_sendmsg+0x1f/0x30 + do_syscall_64+0x3b/0xc0 + entry_SYSCALL_64_after_hwframe+0x44/0xae + Modules linked in: nbd(E-) + +Signed-off-by: Hou Tao +Signed-off-by: Yu Kuai +Reviewed-by: Josef Bacik +Link: https://lore.kernel.org/r/20220521073749.3146892-2-yukuai3@huawei.com +Signed-off-by: Jens Axboe +Signed-off-by: Sasha Levin +--- + drivers/block/nbd.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c +index 826b3877a157..1c9f866d9338 100644 +--- a/drivers/block/nbd.c ++++ b/drivers/block/nbd.c +@@ -2319,6 +2319,12 @@ static void __exit nbd_cleanup(void) + struct nbd_device *nbd; + LIST_HEAD(del_list); + ++ /* ++ * Unregister netlink interface prior to waiting ++ * for the completion of netlink commands. ++ */ ++ genl_unregister_family(&nbd_genl_family); ++ + nbd_dbg_close(); + + mutex_lock(&nbd_index_mutex); +@@ -2334,7 +2340,6 @@ static void __exit nbd_cleanup(void) + } + + idr_destroy(&nbd_index_idr); +- genl_unregister_family(&nbd_genl_family); + unregister_blkdev(NBD_MAJOR, "nbd"); + } + +-- +2.35.1 + diff --git a/queue-4.14/nbd-fix-io-hung-while-disconnecting-device.patch-5217 b/queue-4.14/nbd-fix-io-hung-while-disconnecting-device.patch-5217 new file mode 100644 index 00000000000..226ccb9e676 --- /dev/null +++ b/queue-4.14/nbd-fix-io-hung-while-disconnecting-device.patch-5217 @@ -0,0 +1,78 @@ +From 432cedd086bf81c24a8feafda40bacef3b33b24e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 21 May 2022 15:37:47 +0800 +Subject: nbd: fix io hung while disconnecting device + +From: Yu Kuai + +[ Upstream commit 09dadb5985023e27d4740ebd17e6fea4640110e5 ] + +In our tests, "qemu-nbd" triggers a io hung: + +INFO: task qemu-nbd:11445 blocked for more than 368 seconds. + Not tainted 5.18.0-rc3-next-20220422-00003-g2176915513ca #884 +"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. +task:qemu-nbd state:D stack: 0 pid:11445 ppid: 1 flags:0x00000000 +Call Trace: + + __schedule+0x480/0x1050 + ? _raw_spin_lock_irqsave+0x3e/0xb0 + schedule+0x9c/0x1b0 + blk_mq_freeze_queue_wait+0x9d/0xf0 + ? ipi_rseq+0x70/0x70 + blk_mq_freeze_queue+0x2b/0x40 + nbd_add_socket+0x6b/0x270 [nbd] + nbd_ioctl+0x383/0x510 [nbd] + blkdev_ioctl+0x18e/0x3e0 + __x64_sys_ioctl+0xac/0x120 + do_syscall_64+0x35/0x80 + entry_SYSCALL_64_after_hwframe+0x44/0xae +RIP: 0033:0x7fd8ff706577 +RSP: 002b:00007fd8fcdfebf8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 +RAX: ffffffffffffffda RBX: 0000000040000000 RCX: 00007fd8ff706577 +RDX: 000000000000000d RSI: 000000000000ab00 RDI: 000000000000000f +RBP: 000000000000000f R08: 000000000000fbe8 R09: 000055fe497c62b0 +R10: 00000002aff20000 R11: 0000000000000246 R12: 000000000000006d +R13: 0000000000000000 R14: 00007ffe82dc5e70 R15: 00007fd8fcdff9c0 + +"qemu-ndb -d" will call ioctl 'NBD_DISCONNECT' first, however, following +message was found: + +block nbd0: Send disconnect failed -32 + +Which indicate that something is wrong with the server. Then, +"qemu-nbd -d" will call ioctl 'NBD_CLEAR_SOCK', however ioctl can't clear +requests after commit 2516ab1543fd("nbd: only clear the queue on device +teardown"). And in the meantime, request can't complete through timeout +because nbd_xmit_timeout() will always return 'BLK_EH_RESET_TIMER', which +means such request will never be completed in this situation. + +Now that the flag 'NBD_CMD_INFLIGHT' can make sure requests won't +complete multiple times, switch back to call nbd_clear_sock() in +nbd_clear_sock_ioctl(), so that inflight requests can be cleared. + +Signed-off-by: Yu Kuai +Reviewed-by: Josef Bacik +Link: https://lore.kernel.org/r/20220521073749.3146892-5-yukuai3@huawei.com +Signed-off-by: Jens Axboe +Signed-off-by: Sasha Levin +--- + drivers/block/nbd.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c +index 9596f93d98b2..338d02a67afb 100644 +--- a/drivers/block/nbd.c ++++ b/drivers/block/nbd.c +@@ -1275,7 +1275,7 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b + static void nbd_clear_sock_ioctl(struct nbd_device *nbd, + struct block_device *bdev) + { +- sock_shutdown(nbd); ++ nbd_clear_sock(nbd); + __invalidate_device(bdev, true); + nbd_bdev_reset(bdev); + if (test_and_clear_bit(NBD_HAS_CONFIG_REF, +-- +2.35.1 + diff --git a/queue-4.14/nbd-fix-race-between-nbd_alloc_config-and-module-rem.patch-3389 b/queue-4.14/nbd-fix-race-between-nbd_alloc_config-and-module-rem.patch-3389 new file mode 100644 index 00000000000..1847caa11f7 --- /dev/null +++ b/queue-4.14/nbd-fix-race-between-nbd_alloc_config-and-module-rem.patch-3389 @@ -0,0 +1,124 @@ +From 38b62b1d936ede3d83be2608d2f7180b4e30db4c Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 21 May 2022 15:37:45 +0800 +Subject: nbd: fix race between nbd_alloc_config() and module removal + +From: Yu Kuai + +[ Upstream commit c55b2b983b0fa012942c3eb16384b2b722caa810 ] + +When nbd module is being removing, nbd_alloc_config() may be +called concurrently by nbd_genl_connect(), although try_module_get() +will return false, but nbd_alloc_config() doesn't handle it. + +The race may lead to the leak of nbd_config and its related +resources (e.g, recv_workq) and oops in nbd_read_stat() due +to the unload of nbd module as shown below: + + BUG: kernel NULL pointer dereference, address: 0000000000000040 + Oops: 0000 [#1] SMP PTI + CPU: 5 PID: 13840 Comm: kworker/u17:33 Not tainted 5.14.0+ #1 + Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) + Workqueue: knbd16-recv recv_work [nbd] + RIP: 0010:nbd_read_stat.cold+0x130/0x1a4 [nbd] + Call Trace: + recv_work+0x3b/0xb0 [nbd] + process_one_work+0x1ed/0x390 + worker_thread+0x4a/0x3d0 + kthread+0x12a/0x150 + ret_from_fork+0x22/0x30 + +Fixing it by checking the return value of try_module_get() +in nbd_alloc_config(). As nbd_alloc_config() may return ERR_PTR(-ENODEV), +assign nbd->config only when nbd_alloc_config() succeeds to ensure +the value of nbd->config is binary (valid or NULL). + +Also adding a debug message to check the reference counter +of nbd_config during module removal. + +Signed-off-by: Hou Tao +Signed-off-by: Yu Kuai +Reviewed-by: Josef Bacik +Link: https://lore.kernel.org/r/20220521073749.3146892-3-yukuai3@huawei.com +Signed-off-by: Jens Axboe +Signed-off-by: Sasha Levin +--- + drivers/block/nbd.c | 28 +++++++++++++++++++--------- + 1 file changed, 19 insertions(+), 9 deletions(-) + +diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c +index 1c9f866d9338..9596f93d98b2 100644 +--- a/drivers/block/nbd.c ++++ b/drivers/block/nbd.c +@@ -1382,15 +1382,20 @@ static struct nbd_config *nbd_alloc_config(void) + { + struct nbd_config *config; + ++ if (!try_module_get(THIS_MODULE)) ++ return ERR_PTR(-ENODEV); ++ + config = kzalloc(sizeof(struct nbd_config), GFP_NOFS); +- if (!config) +- return NULL; ++ if (!config) { ++ module_put(THIS_MODULE); ++ return ERR_PTR(-ENOMEM); ++ } ++ + atomic_set(&config->recv_threads, 0); + init_waitqueue_head(&config->recv_wq); + init_waitqueue_head(&config->conn_wait); + config->blksize = NBD_DEF_BLKSIZE; + atomic_set(&config->live_connections, 0); +- try_module_get(THIS_MODULE); + return config; + } + +@@ -1417,12 +1422,13 @@ static int nbd_open(struct block_device *bdev, fmode_t mode) + mutex_unlock(&nbd->config_lock); + goto out; + } +- config = nbd->config = nbd_alloc_config(); +- if (!config) { +- ret = -ENOMEM; ++ config = nbd_alloc_config(); ++ if (IS_ERR(config)) { ++ ret = PTR_ERR(config); + mutex_unlock(&nbd->config_lock); + goto out; + } ++ nbd->config = config; + refcount_set(&nbd->config_refs, 1); + refcount_inc(&nbd->refs); + mutex_unlock(&nbd->config_lock); +@@ -1803,13 +1809,14 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info) + nbd_put(nbd); + return -EINVAL; + } +- config = nbd->config = nbd_alloc_config(); +- if (!nbd->config) { ++ config = nbd_alloc_config(); ++ if (IS_ERR(config)) { + mutex_unlock(&nbd->config_lock); + nbd_put(nbd); + printk(KERN_ERR "nbd: couldn't allocate config\n"); +- return -ENOMEM; ++ return PTR_ERR(config); + } ++ nbd->config = config; + refcount_set(&nbd->config_refs, 1); + set_bit(NBD_BOUND, &config->runtime_flags); + +@@ -2334,6 +2341,9 @@ static void __exit nbd_cleanup(void) + while (!list_empty(&del_list)) { + nbd = list_first_entry(&del_list, struct nbd_device, list); + list_del_init(&nbd->list); ++ if (refcount_read(&nbd->config_refs)) ++ printk(KERN_ERR "nbd: possibly leaking nbd_config (ref %d)\n", ++ refcount_read(&nbd->config_refs)); + if (refcount_read(&nbd->refs) != 1) + printk(KERN_ERR "nbd: possibly leaking a device\n"); + nbd_put(nbd); +-- +2.35.1 + diff --git a/queue-4.14/nodemask-fix-return-values-to-be-unsigned.patch-27598 b/queue-4.14/nodemask-fix-return-values-to-be-unsigned.patch-27598 new file mode 100644 index 00000000000..ccdc4763dd2 --- /dev/null +++ b/queue-4.14/nodemask-fix-return-values-to-be-unsigned.patch-27598 @@ -0,0 +1,189 @@ +From bcb1a10940646ec0a5256d728a32bcf597f7163d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 May 2022 13:52:23 -0700 +Subject: nodemask: Fix return values to be unsigned +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Kees Cook + +[ Upstream commit 0dfe54071d7c828a02917b595456bfde1afdddc9 ] + +The nodemask routines had mixed return values that provided potentially +signed return values that could never happen. This was leading to the +compiler getting confusing about the range of possible return values +(it was thinking things could be negative where they could not be). Fix +all the nodemask routines that should be returning unsigned +(or bool) values. Silences: + + mm/swapfile.c: In function ‘setup_swap_info’: + mm/swapfile.c:2291:47: error: array subscript -1 is below array bounds of ‘struct plist_node[]’ [-Werror=array-bounds] + 2291 | p->avail_lists[i].prio = 1; + | ~~~~~~~~~~~~~~^~~ + In file included from mm/swapfile.c:16: + ./include/linux/swap.h:292:27: note: while referencing ‘avail_lists’ + 292 | struct plist_node avail_lists[]; /* + | ^~~~~~~~~~~ + +Reported-by: Christophe de Dinechin +Link: https://lore.kernel.org/lkml/20220414150855.2407137-3-dinechin@redhat.com/ +Cc: Alexey Dobriyan +Cc: Yury Norov +Cc: Andy Shevchenko +Cc: Rasmus Villemoes +Cc: Andrew Morton +Cc: Zhen Lei +Signed-off-by: Kees Cook +Signed-off-by: Yury Norov +Signed-off-by: Sasha Levin +--- + include/linux/nodemask.h | 38 +++++++++++++++++++------------------- + lib/nodemask.c | 4 ++-- + 2 files changed, 21 insertions(+), 21 deletions(-) + +diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h +index da9f53586932..13f6248151b9 100644 +--- a/include/linux/nodemask.h ++++ b/include/linux/nodemask.h +@@ -42,11 +42,11 @@ + * void nodes_shift_right(dst, src, n) Shift right + * void nodes_shift_left(dst, src, n) Shift left + * +- * int first_node(mask) Number lowest set bit, or MAX_NUMNODES +- * int next_node(node, mask) Next node past 'node', or MAX_NUMNODES +- * int next_node_in(node, mask) Next node past 'node', or wrap to first, ++ * unsigned int first_node(mask) Number lowest set bit, or MAX_NUMNODES ++ * unsigend int next_node(node, mask) Next node past 'node', or MAX_NUMNODES ++ * unsigned int next_node_in(node, mask) Next node past 'node', or wrap to first, + * or MAX_NUMNODES +- * int first_unset_node(mask) First node not set in mask, or ++ * unsigned int first_unset_node(mask) First node not set in mask, or + * MAX_NUMNODES + * + * nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set +@@ -144,7 +144,7 @@ static inline void __nodes_clear(nodemask_t *dstp, unsigned int nbits) + + #define node_test_and_set(node, nodemask) \ + __node_test_and_set((node), &(nodemask)) +-static inline int __node_test_and_set(int node, nodemask_t *addr) ++static inline bool __node_test_and_set(int node, nodemask_t *addr) + { + return test_and_set_bit(node, addr->bits); + } +@@ -191,7 +191,7 @@ static inline void __nodes_complement(nodemask_t *dstp, + + #define nodes_equal(src1, src2) \ + __nodes_equal(&(src1), &(src2), MAX_NUMNODES) +-static inline int __nodes_equal(const nodemask_t *src1p, ++static inline bool __nodes_equal(const nodemask_t *src1p, + const nodemask_t *src2p, unsigned int nbits) + { + return bitmap_equal(src1p->bits, src2p->bits, nbits); +@@ -199,7 +199,7 @@ static inline int __nodes_equal(const nodemask_t *src1p, + + #define nodes_intersects(src1, src2) \ + __nodes_intersects(&(src1), &(src2), MAX_NUMNODES) +-static inline int __nodes_intersects(const nodemask_t *src1p, ++static inline bool __nodes_intersects(const nodemask_t *src1p, + const nodemask_t *src2p, unsigned int nbits) + { + return bitmap_intersects(src1p->bits, src2p->bits, nbits); +@@ -207,20 +207,20 @@ static inline int __nodes_intersects(const nodemask_t *src1p, + + #define nodes_subset(src1, src2) \ + __nodes_subset(&(src1), &(src2), MAX_NUMNODES) +-static inline int __nodes_subset(const nodemask_t *src1p, ++static inline bool __nodes_subset(const nodemask_t *src1p, + const nodemask_t *src2p, unsigned int nbits) + { + return bitmap_subset(src1p->bits, src2p->bits, nbits); + } + + #define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES) +-static inline int __nodes_empty(const nodemask_t *srcp, unsigned int nbits) ++static inline bool __nodes_empty(const nodemask_t *srcp, unsigned int nbits) + { + return bitmap_empty(srcp->bits, nbits); + } + + #define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES) +-static inline int __nodes_full(const nodemask_t *srcp, unsigned int nbits) ++static inline bool __nodes_full(const nodemask_t *srcp, unsigned int nbits) + { + return bitmap_full(srcp->bits, nbits); + } +@@ -251,15 +251,15 @@ static inline void __nodes_shift_left(nodemask_t *dstp, + > MAX_NUMNODES, then the silly min_ts could be dropped. */ + + #define first_node(src) __first_node(&(src)) +-static inline int __first_node(const nodemask_t *srcp) ++static inline unsigned int __first_node(const nodemask_t *srcp) + { +- return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES)); ++ return min_t(unsigned int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES)); + } + + #define next_node(n, src) __next_node((n), &(src)) +-static inline int __next_node(int n, const nodemask_t *srcp) ++static inline unsigned int __next_node(int n, const nodemask_t *srcp) + { +- return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1)); ++ return min_t(unsigned int, MAX_NUMNODES, find_next_bit(srcp->bits, MAX_NUMNODES, n+1)); + } + + /* +@@ -267,7 +267,7 @@ static inline int __next_node(int n, const nodemask_t *srcp) + * the first node in src if needed. Returns MAX_NUMNODES if src is empty. + */ + #define next_node_in(n, src) __next_node_in((n), &(src)) +-int __next_node_in(int node, const nodemask_t *srcp); ++unsigned int __next_node_in(int node, const nodemask_t *srcp); + + static inline void init_nodemask_of_node(nodemask_t *mask, int node) + { +@@ -287,9 +287,9 @@ static inline void init_nodemask_of_node(nodemask_t *mask, int node) + }) + + #define first_unset_node(mask) __first_unset_node(&(mask)) +-static inline int __first_unset_node(const nodemask_t *maskp) ++static inline unsigned int __first_unset_node(const nodemask_t *maskp) + { +- return min_t(int,MAX_NUMNODES, ++ return min_t(unsigned int, MAX_NUMNODES, + find_first_zero_bit(maskp->bits, MAX_NUMNODES)); + } + +@@ -425,11 +425,11 @@ static inline int num_node_state(enum node_states state) + + #define first_online_node first_node(node_states[N_ONLINE]) + #define first_memory_node first_node(node_states[N_MEMORY]) +-static inline int next_online_node(int nid) ++static inline unsigned int next_online_node(int nid) + { + return next_node(nid, node_states[N_ONLINE]); + } +-static inline int next_memory_node(int nid) ++static inline unsigned int next_memory_node(int nid) + { + return next_node(nid, node_states[N_MEMORY]); + } +diff --git a/lib/nodemask.c b/lib/nodemask.c +index 3aa454c54c0d..e22647f5181b 100644 +--- a/lib/nodemask.c ++++ b/lib/nodemask.c +@@ -3,9 +3,9 @@ + #include + #include + +-int __next_node_in(int node, const nodemask_t *srcp) ++unsigned int __next_node_in(int node, const nodemask_t *srcp) + { +- int ret = __next_node(node, srcp); ++ unsigned int ret = __next_node(node, srcp); + + if (ret == MAX_NUMNODES) + ret = __first_node(srcp); +-- +2.35.1 + diff --git a/queue-4.14/revert-net-af_key-add-check-for-pfkey_broadcast-in-f.patch-16871 b/queue-4.14/revert-net-af_key-add-check-for-pfkey_broadcast-in-f.patch-16871 new file mode 100644 index 00000000000..9bfd212e01b --- /dev/null +++ b/queue-4.14/revert-net-af_key-add-check-for-pfkey_broadcast-in-f.patch-16871 @@ -0,0 +1,60 @@ +From d95bd245fc174220177b14ff357967c15df5c00d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 23 May 2022 22:05:24 +0200 +Subject: Revert "net: af_key: add check for pfkey_broadcast in function + pfkey_process" + +From: Michal Kubecek + +[ Upstream commit 9c90c9b3e50e16d03c7f87d63e9db373974781e0 ] + +This reverts commit 4dc2a5a8f6754492180741facf2a8787f2c415d7. + +A non-zero return value from pfkey_broadcast() does not necessarily mean +an error occurred as this function returns -ESRCH when no registered +listener received the message. In particular, a call with +BROADCAST_PROMISC_ONLY flag and null one_sk argument can never return +zero so that this commit in fact prevents processing any PF_KEY message. +One visible effect is that racoon daemon fails to find encryption +algorithms like aes and refuses to start. + +Excluding -ESRCH return value would fix this but it's not obvious that +we really want to bail out here and most other callers of +pfkey_broadcast() also ignore the return value. Also, as pointed out by +Steffen Klassert, PF_KEY is kind of deprecated and newer userspace code +should use netlink instead so that we should only disturb the code for +really important fixes. + +v2: add a comment explaining why is the return value ignored + +Signed-off-by: Michal Kubecek +Signed-off-by: Steffen Klassert +Signed-off-by: Sasha Levin +--- + net/key/af_key.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/net/key/af_key.c b/net/key/af_key.c +index 990de0702b79..035123bf7259 100644 +--- a/net/key/af_key.c ++++ b/net/key/af_key.c +@@ -2834,10 +2834,12 @@ static int pfkey_process(struct sock *sk, struct sk_buff *skb, const struct sadb + void *ext_hdrs[SADB_EXT_MAX]; + int err; + +- err = pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL, +- BROADCAST_PROMISC_ONLY, NULL, sock_net(sk)); +- if (err) +- return err; ++ /* Non-zero return value of pfkey_broadcast() does not always signal ++ * an error and even on an actual error we may still want to process ++ * the message so rather ignore the return value. ++ */ ++ pfkey_broadcast(skb_clone(skb, GFP_KERNEL), GFP_KERNEL, ++ BROADCAST_PROMISC_ONLY, NULL, sock_net(sk)); + + memset(ext_hdrs, 0, sizeof(ext_hdrs)); + err = parse_exthdrs(skb, hdr, ext_hdrs); +-- +2.35.1 + diff --git a/queue-4.14/serial-msm_serial-disable-interrupts-in-__msm_consol.patch-29321 b/queue-4.14/serial-msm_serial-disable-interrupts-in-__msm_consol.patch-29321 new file mode 100644 index 00000000000..6e96f38a537 --- /dev/null +++ b/queue-4.14/serial-msm_serial-disable-interrupts-in-__msm_consol.patch-29321 @@ -0,0 +1,59 @@ +From ee043580c98b5fc139c8b5dee0545cc26fc3137f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 6 May 2022 23:39:24 +0206 +Subject: serial: msm_serial: disable interrupts in __msm_console_write() + +From: John Ogness + +[ Upstream commit aabdbb1b7a5819e18c403334a31fb0cc2c06ad41 ] + +__msm_console_write() assumes that interrupts are disabled, but +with threaded console printers it is possible that the write() +callback of the console is called with interrupts enabled. + +Explicitly disable interrupts using local_irq_save() to preserve +the assumed context. + +Reported-by: Marek Szyprowski +Reviewed-by: Petr Mladek +Signed-off-by: John Ogness +Link: https://lore.kernel.org/r/20220506213324.470461-1-john.ogness@linutronix.de +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/tty/serial/msm_serial.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c +index 7848e9455950..3df3716caa56 100644 +--- a/drivers/tty/serial/msm_serial.c ++++ b/drivers/tty/serial/msm_serial.c +@@ -1587,6 +1587,7 @@ static inline struct uart_port *msm_get_port_from_line(unsigned int line) + static void __msm_console_write(struct uart_port *port, const char *s, + unsigned int count, bool is_uartdm) + { ++ unsigned long flags; + int i; + int num_newlines = 0; + bool replaced = false; +@@ -1604,6 +1605,8 @@ static void __msm_console_write(struct uart_port *port, const char *s, + num_newlines++; + count += num_newlines; + ++ local_irq_save(flags); ++ + if (port->sysrq) + locked = 0; + else if (oops_in_progress) +@@ -1649,6 +1652,8 @@ static void __msm_console_write(struct uart_port *port, const char *s, + + if (locked) + spin_unlock(&port->lock); ++ ++ local_irq_restore(flags); + } + + static void msm_console_write(struct console *co, const char *s, +-- +2.35.1 + diff --git a/queue-4.14/series b/queue-4.14/series index a20ec56a7c9..cef58fdd161 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -179,3 +179,75 @@ net-xfrm-unexport-__init-annotated-xfrm4_protocol_in.patch net-ipv6-unexport-__init-annotated-seg6_hmac_init.patch net-altera-fix-refcount-leak-in-altera_tse_mdio_crea.patch drm-imx-fix-compiler-warning-with-gcc-12.patch +iio-dummy-iio_simple_dummy-check-the-return-value-of.patch +lkdtm-usercopy-expand-size-of-out-of-frame-object.patch +tty-synclink_gt-fix-null-pointer-dereference-in-slgt.patch +tty-fix-a-possible-resource-leak-in-icom_probe.patch +drivers-staging-rtl8192e-fix-deadlock-in-rtllib_beac.patch +usb-host-isp116x-check-return-value-after-calling-pl.patch +drivers-tty-serial-fix-deadlock-in-sa1100_set_termio.patch +drivers-usb-host-fix-deadlock-in-oxu_bus_suspend.patch +usb-hcd-pci-fully-suspend-across-freeze-thaw-cycle.patch +usb-dwc2-gadget-don-t-reset-gadget-s-driver-bus.patch +misc-rtsx-set-null-intfdata-when-probe-fails.patch +extcon-modify-extcon-device-to-be-created-after-driv.patch +clocksource-drivers-sp804-avoid-error-on-multiple-in.patch +staging-rtl8712-fix-uninit-value-in-r871xu_drv_init.patch +serial-msm_serial-disable-interrupts-in-__msm_consol.patch +kernfs-separate-kernfs_pr_cont_buf-and-rename_lock.patch +md-protect-md_unregister_thread-from-reentrancy.patch +revert-net-af_key-add-check-for-pfkey_broadcast-in-f.patch +drm-radeon-fix-a-possible-null-pointer-dereference.patch +modpost-fix-undefined-behavior-of-is_arm_mapping_sym.patch +nbd-call-genl_unregister_family-first-in-nbd_cleanup.patch +nbd-fix-race-between-nbd_alloc_config-and-module-rem.patch +nbd-fix-io-hung-while-disconnecting-device.patch +nodemask-fix-return-values-to-be-unsigned.patch +iio-dummy-iio_simple_dummy-check-the-return-value-of.patch-2294 +lkdtm-usercopy-expand-size-of-out-of-frame-object.patch-21637 +tty-synclink_gt-fix-null-pointer-dereference-in-slgt.patch-11127 +tty-fix-a-possible-resource-leak-in-icom_probe.patch-15832 +drivers-staging-rtl8192e-fix-deadlock-in-rtllib_beac.patch-27667 +usb-host-isp116x-check-return-value-after-calling-pl.patch-16910 +drivers-tty-serial-fix-deadlock-in-sa1100_set_termio.patch-1994 +drivers-usb-host-fix-deadlock-in-oxu_bus_suspend.patch-6358 +usb-hcd-pci-fully-suspend-across-freeze-thaw-cycle.patch-28138 +usb-dwc2-gadget-don-t-reset-gadget-s-driver-bus.patch-25185 +misc-rtsx-set-null-intfdata-when-probe-fails.patch-14171 +extcon-modify-extcon-device-to-be-created-after-driv.patch-9552 +clocksource-drivers-sp804-avoid-error-on-multiple-in.patch-29639 +staging-rtl8712-fix-uninit-value-in-r871xu_drv_init.patch-22812 +serial-msm_serial-disable-interrupts-in-__msm_consol.patch-32587 +kernfs-separate-kernfs_pr_cont_buf-and-rename_lock.patch-9187 +md-protect-md_unregister_thread-from-reentrancy.patch-3153 +revert-net-af_key-add-check-for-pfkey_broadcast-in-f.patch-8464 +drm-radeon-fix-a-possible-null-pointer-dereference.patch-21070 +modpost-fix-undefined-behavior-of-is_arm_mapping_sym.patch-25557 +nbd-call-genl_unregister_family-first-in-nbd_cleanup.patch-20567 +nbd-fix-race-between-nbd_alloc_config-and-module-rem.patch-24376 +nbd-fix-io-hung-while-disconnecting-device.patch-29843 +nodemask-fix-return-values-to-be-unsigned.patch-29413 +iio-dummy-iio_simple_dummy-check-the-return-value-of.patch-27365 +lkdtm-usercopy-expand-size-of-out-of-frame-object.patch-16982 +tty-synclink_gt-fix-null-pointer-dereference-in-slgt.patch-18352 +tty-fix-a-possible-resource-leak-in-icom_probe.patch-27680 +drivers-staging-rtl8192e-fix-deadlock-in-rtllib_beac.patch-17195 +usb-host-isp116x-check-return-value-after-calling-pl.patch-17824 +drivers-tty-serial-fix-deadlock-in-sa1100_set_termio.patch-18821 +drivers-usb-host-fix-deadlock-in-oxu_bus_suspend.patch-1678 +usb-hcd-pci-fully-suspend-across-freeze-thaw-cycle.patch-17904 +usb-dwc2-gadget-don-t-reset-gadget-s-driver-bus.patch-3513 +misc-rtsx-set-null-intfdata-when-probe-fails.patch-995 +extcon-modify-extcon-device-to-be-created-after-driv.patch-24531 +clocksource-drivers-sp804-avoid-error-on-multiple-in.patch-11976 +staging-rtl8712-fix-uninit-value-in-r871xu_drv_init.patch-28512 +serial-msm_serial-disable-interrupts-in-__msm_consol.patch-29321 +kernfs-separate-kernfs_pr_cont_buf-and-rename_lock.patch-27977 +md-protect-md_unregister_thread-from-reentrancy.patch-16041 +revert-net-af_key-add-check-for-pfkey_broadcast-in-f.patch-16871 +drm-radeon-fix-a-possible-null-pointer-dereference.patch-16535 +modpost-fix-undefined-behavior-of-is_arm_mapping_sym.patch-15924 +nbd-call-genl_unregister_family-first-in-nbd_cleanup.patch-23844 +nbd-fix-race-between-nbd_alloc_config-and-module-rem.patch-3389 +nbd-fix-io-hung-while-disconnecting-device.patch-5217 +nodemask-fix-return-values-to-be-unsigned.patch-27598 diff --git a/queue-4.14/staging-rtl8712-fix-uninit-value-in-r871xu_drv_init.patch-28512 b/queue-4.14/staging-rtl8712-fix-uninit-value-in-r871xu_drv_init.patch-28512 new file mode 100644 index 00000000000..491cd7a82df --- /dev/null +++ b/queue-4.14/staging-rtl8712-fix-uninit-value-in-r871xu_drv_init.patch-28512 @@ -0,0 +1,88 @@ +From 9691e2d2dae9f93c3ca7901c6a58e4dbaf987b09 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 16 May 2022 17:22:41 +0800 +Subject: staging: rtl8712: fix uninit-value in r871xu_drv_init() + +From: Wang Cheng + +[ Upstream commit 0458e5428e5e959d201a40ffe71d762a79ecedc4 ] + +When 'tmpU1b' returns from r8712_read8(padapter, EE_9346CR) is 0, +'mac[6]' will not be initialized. + +BUG: KMSAN: uninit-value in r871xu_drv_init+0x2d54/0x3070 drivers/staging/rtl8712/usb_intf.c:541 + r871xu_drv_init+0x2d54/0x3070 drivers/staging/rtl8712/usb_intf.c:541 + usb_probe_interface+0xf19/0x1600 drivers/usb/core/driver.c:396 + really_probe+0x653/0x14b0 drivers/base/dd.c:596 + __driver_probe_device+0x3e9/0x530 drivers/base/dd.c:752 + driver_probe_device drivers/base/dd.c:782 [inline] + __device_attach_driver+0x79f/0x1120 drivers/base/dd.c:899 + bus_for_each_drv+0x2d6/0x3f0 drivers/base/bus.c:427 + __device_attach+0x593/0x8e0 drivers/base/dd.c:970 + device_initial_probe+0x4a/0x60 drivers/base/dd.c:1017 + bus_probe_device+0x17b/0x3e0 drivers/base/bus.c:487 + device_add+0x1fff/0x26e0 drivers/base/core.c:3405 + usb_set_configuration+0x37e9/0x3ed0 drivers/usb/core/message.c:2170 + usb_generic_driver_probe+0x13c/0x300 drivers/usb/core/generic.c:238 + usb_probe_device+0x309/0x570 drivers/usb/core/driver.c:293 + really_probe+0x653/0x14b0 drivers/base/dd.c:596 + __driver_probe_device+0x3e9/0x530 drivers/base/dd.c:752 + driver_probe_device drivers/base/dd.c:782 [inline] + __device_attach_driver+0x79f/0x1120 drivers/base/dd.c:899 + bus_for_each_drv+0x2d6/0x3f0 drivers/base/bus.c:427 + __device_attach+0x593/0x8e0 drivers/base/dd.c:970 + device_initial_probe+0x4a/0x60 drivers/base/dd.c:1017 + bus_probe_device+0x17b/0x3e0 drivers/base/bus.c:487 + device_add+0x1fff/0x26e0 drivers/base/core.c:3405 + usb_new_device+0x1b8e/0x2950 drivers/usb/core/hub.c:2566 + hub_port_connect drivers/usb/core/hub.c:5358 [inline] + hub_port_connect_change drivers/usb/core/hub.c:5502 [inline] + port_event drivers/usb/core/hub.c:5660 [inline] + hub_event+0x58e3/0x89e0 drivers/usb/core/hub.c:5742 + process_one_work+0xdb6/0x1820 kernel/workqueue.c:2307 + worker_thread+0x10b3/0x21e0 kernel/workqueue.c:2454 + kthread+0x3c7/0x500 kernel/kthread.c:377 + ret_from_fork+0x1f/0x30 + +Local variable mac created at: + r871xu_drv_init+0x1771/0x3070 drivers/staging/rtl8712/usb_intf.c:394 + usb_probe_interface+0xf19/0x1600 drivers/usb/core/driver.c:396 + +KMSAN: uninit-value in r871xu_drv_init +https://syzkaller.appspot.com/bug?id=3cd92b1d85428b128503bfa7a250294c9ae00bd8 + +Reported-by: +Tested-by: +Reviewed-by: Dan Carpenter +Signed-off-by: Wang Cheng +Link: https://lore.kernel.org/r/14c3886173dfa4597f0704547c414cfdbcd11d16.1652618244.git.wanngchenng@gmail.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/staging/rtl8712/usb_intf.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c +index 8be4fcc54ad6..b7bd37b62861 100644 +--- a/drivers/staging/rtl8712/usb_intf.c ++++ b/drivers/staging/rtl8712/usb_intf.c +@@ -569,13 +569,13 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf, + } else { + AutoloadFail = false; + } +- if (((mac[0] == 0xff) && (mac[1] == 0xff) && ++ if ((!AutoloadFail) || ++ ((mac[0] == 0xff) && (mac[1] == 0xff) && + (mac[2] == 0xff) && (mac[3] == 0xff) && + (mac[4] == 0xff) && (mac[5] == 0xff)) || + ((mac[0] == 0x00) && (mac[1] == 0x00) && + (mac[2] == 0x00) && (mac[3] == 0x00) && +- (mac[4] == 0x00) && (mac[5] == 0x00)) || +- (!AutoloadFail)) { ++ (mac[4] == 0x00) && (mac[5] == 0x00))) { + mac[0] = 0x00; + mac[1] = 0xe0; + mac[2] = 0x4c; +-- +2.35.1 + diff --git a/queue-4.14/tty-fix-a-possible-resource-leak-in-icom_probe.patch-27680 b/queue-4.14/tty-fix-a-possible-resource-leak-in-icom_probe.patch-27680 new file mode 100644 index 00000000000..67ba9021209 --- /dev/null +++ b/queue-4.14/tty-fix-a-possible-resource-leak-in-icom_probe.patch-27680 @@ -0,0 +1,37 @@ +From c132b64a9d0ec2698db9c3b9d11ccf21ebb08be3 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 31 Mar 2022 17:10:05 +0800 +Subject: tty: Fix a possible resource leak in icom_probe + +From: Huang Guobin + +[ Upstream commit ee157a79e7c82b01ae4c25de0ac75899801f322c ] + +When pci_read_config_dword failed, call pci_release_regions() and +pci_disable_device() to recycle the resource previously allocated. + +Reviewed-by: Jiri Slaby +Signed-off-by: Huang Guobin +Link: https://lore.kernel.org/r/20220331091005.3290753-1-huangguobin4@huawei.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/tty/serial/icom.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c +index fe92d74f4ea5..4711b3ec2c56 100644 +--- a/drivers/tty/serial/icom.c ++++ b/drivers/tty/serial/icom.c +@@ -1515,7 +1515,7 @@ static int icom_probe(struct pci_dev *dev, + retval = pci_read_config_dword(dev, PCI_COMMAND, &command_reg); + if (retval) { + dev_err(&dev->dev, "PCI Config read FAILED\n"); +- return retval; ++ goto probe_exit0; + } + + pci_write_config_dword(dev, PCI_COMMAND, +-- +2.35.1 + diff --git a/queue-4.14/tty-synclink_gt-fix-null-pointer-dereference-in-slgt.patch-18352 b/queue-4.14/tty-synclink_gt-fix-null-pointer-dereference-in-slgt.patch-18352 new file mode 100644 index 00000000000..40a6a04c7f3 --- /dev/null +++ b/queue-4.14/tty-synclink_gt-fix-null-pointer-dereference-in-slgt.patch-18352 @@ -0,0 +1,47 @@ +From a87ee6aa276bd44454e1c40f0a3bc640e44cbf76 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 10 Apr 2022 19:48:14 +0800 +Subject: tty: synclink_gt: Fix null-pointer-dereference in slgt_clean() + +From: Zheyu Ma + +[ Upstream commit 689ca31c542687709ba21ec2195c1fbce34fd029 ] + +When the driver fails at alloc_hdlcdev(), and then we remove the driver +module, we will get the following splat: + +[ 25.065966] general protection fault, probably for non-canonical address 0xdffffc0000000182: 0000 [#1] PREEMPT SMP KASAN PTI +[ 25.066914] KASAN: null-ptr-deref in range [0x0000000000000c10-0x0000000000000c17] +[ 25.069262] RIP: 0010:detach_hdlc_protocol+0x2a/0x3e0 +[ 25.077709] Call Trace: +[ 25.077924] +[ 25.078108] unregister_hdlc_device+0x16/0x30 +[ 25.078481] slgt_cleanup+0x157/0x9f0 [synclink_gt] + +Fix this by checking whether the 'info->netdev' is a null pointer first. + +Reviewed-by: Jiri Slaby +Signed-off-by: Zheyu Ma +Link: https://lore.kernel.org/r/20220410114814.3920474-1-zheyuma97@gmail.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/tty/synclink_gt.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c +index 9d68f89a2bf8..4b5ff6e173bd 100644 +--- a/drivers/tty/synclink_gt.c ++++ b/drivers/tty/synclink_gt.c +@@ -1822,6 +1822,8 @@ static int hdlcdev_init(struct slgt_info *info) + */ + static void hdlcdev_exit(struct slgt_info *info) + { ++ if (!info->netdev) ++ return; + unregister_hdlc_device(info->netdev); + free_netdev(info->netdev); + info->netdev = NULL; +-- +2.35.1 + diff --git a/queue-4.14/usb-dwc2-gadget-don-t-reset-gadget-s-driver-bus.patch-3513 b/queue-4.14/usb-dwc2-gadget-don-t-reset-gadget-s-driver-bus.patch-3513 new file mode 100644 index 00000000000..5b1fa99bf98 --- /dev/null +++ b/queue-4.14/usb-dwc2-gadget-don-t-reset-gadget-s-driver-bus.patch-3513 @@ -0,0 +1,66 @@ +From 5f02601eed365676f83f4bd736c176ee41d9e502 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 5 May 2022 12:46:18 +0200 +Subject: usb: dwc2: gadget: don't reset gadget's driver->bus + +From: Marek Szyprowski + +[ Upstream commit 3120aac6d0ecd9accf56894aeac0e265f74d3d5a ] + +UDC driver should not touch gadget's driver internals, especially it +should not reset driver->bus. This wasn't harmful so far, but since +commit fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") gadget +subsystem got it's own bus and messing with ->bus triggers the +following NULL pointer dereference: + +dwc2 12480000.hsotg: bound driver g_ether +8<--- cut here --- +Unable to handle kernel NULL pointer dereference at virtual address 00000000 +[00000000] *pgd=00000000 +Internal error: Oops: 5 [#1] SMP ARM +Modules linked in: ... +CPU: 0 PID: 620 Comm: modprobe Not tainted 5.18.0-rc5-next-20220504 #11862 +Hardware name: Samsung Exynos (Flattened Device Tree) +PC is at module_add_driver+0x44/0xe8 +LR is at sysfs_do_create_link_sd+0x84/0xe0 +... +Process modprobe (pid: 620, stack limit = 0x(ptrval)) +... + module_add_driver from bus_add_driver+0xf4/0x1e4 + bus_add_driver from driver_register+0x78/0x10c + driver_register from usb_gadget_register_driver_owner+0x40/0xb4 + usb_gadget_register_driver_owner from do_one_initcall+0x44/0x1e0 + do_one_initcall from do_init_module+0x44/0x1c8 + do_init_module from load_module+0x19b8/0x1b9c + load_module from sys_finit_module+0xdc/0xfc + sys_finit_module from ret_fast_syscall+0x0/0x54 +Exception stack(0xf1771fa8 to 0xf1771ff0) +... +dwc2 12480000.hsotg: new device is high-speed +---[ end trace 0000000000000000 ]--- + +Fix this by removing driver->bus entry reset. + +Signed-off-by: Marek Szyprowski +Link: https://lore.kernel.org/r/20220505104618.22729-1-m.szyprowski@samsung.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/dwc2/gadget.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c +index dddc5d02b552..14f907cf71a3 100644 +--- a/drivers/usb/dwc2/gadget.c ++++ b/drivers/usb/dwc2/gadget.c +@@ -4302,7 +4302,6 @@ static int dwc2_hsotg_udc_start(struct usb_gadget *gadget, + + WARN_ON(hsotg->driver); + +- driver->driver.bus = NULL; + hsotg->driver = driver; + hsotg->gadget.dev.of_node = hsotg->dev->of_node; + hsotg->gadget.speed = USB_SPEED_UNKNOWN; +-- +2.35.1 + diff --git a/queue-4.14/usb-hcd-pci-fully-suspend-across-freeze-thaw-cycle.patch-17904 b/queue-4.14/usb-hcd-pci-fully-suspend-across-freeze-thaw-cycle.patch-17904 new file mode 100644 index 00000000000..8319403749f --- /dev/null +++ b/queue-4.14/usb-hcd-pci-fully-suspend-across-freeze-thaw-cycle.patch-17904 @@ -0,0 +1,50 @@ +From d235020a4f44037b634c5ea6c20d9221d9d60150 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 21 Apr 2022 10:39:27 -0700 +Subject: USB: hcd-pci: Fully suspend across freeze/thaw cycle + +From: Evan Green + +[ Upstream commit 63acaa8e9c65dc34dc249440216f8e977f5d2748 ] + +The documentation for the freeze() method says that it "should quiesce +the device so that it doesn't generate IRQs or DMA". The unspoken +consequence of not doing this is that MSIs aimed at non-boot CPUs may +get fully lost if they're sent during the period where the target CPU is +offline. + +The current callbacks for USB HCD do not fully quiesce interrupts, +specifically on XHCI. Change to use the full suspend/resume flow for +freeze/thaw to ensure interrupts are fully quiesced. This fixes issues +where USB devices fail to thaw during hibernation because XHCI misses +its interrupt and cannot recover. + +Acked-by: Alan Stern +Signed-off-by: Evan Green +Link: https://lore.kernel.org/r/20220421103751.v3.2.I8226c7fdae88329ef70957b96a39b346c69a914e@changeid +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/core/hcd-pci.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c +index 5340d433cdf0..18b3a5e518cd 100644 +--- a/drivers/usb/core/hcd-pci.c ++++ b/drivers/usb/core/hcd-pci.c +@@ -632,10 +632,10 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops = { + .suspend_noirq = hcd_pci_suspend_noirq, + .resume_noirq = hcd_pci_resume_noirq, + .resume = hcd_pci_resume, +- .freeze = check_root_hub_suspended, ++ .freeze = hcd_pci_suspend, + .freeze_noirq = check_root_hub_suspended, + .thaw_noirq = NULL, +- .thaw = NULL, ++ .thaw = hcd_pci_resume, + .poweroff = hcd_pci_suspend, + .poweroff_noirq = hcd_pci_suspend_noirq, + .restore_noirq = hcd_pci_resume_noirq, +-- +2.35.1 + diff --git a/queue-4.14/usb-host-isp116x-check-return-value-after-calling-pl.patch-17824 b/queue-4.14/usb-host-isp116x-check-return-value-after-calling-pl.patch-17824 new file mode 100644 index 00000000000..240ce672a98 --- /dev/null +++ b/queue-4.14/usb-host-isp116x-check-return-value-after-calling-pl.patch-17824 @@ -0,0 +1,43 @@ +From 9e0f336d5ccefbcffa64bf8eae9709092e97c916 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 2 Mar 2022 11:37:16 +0800 +Subject: USB: host: isp116x: check return value after calling + platform_get_resource() + +From: Zhen Ni + +[ Upstream commit 134a3408c2d3f7e23eb0e4556e0a2d9f36c2614e ] + +It will cause null-ptr-deref if platform_get_resource() returns NULL, +we need check the return value. + +Signed-off-by: Zhen Ni +Link: https://lore.kernel.org/r/20220302033716.31272-1-nizhen@uniontech.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/host/isp116x-hcd.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c +index 73fec38754f9..83eb62001679 100644 +--- a/drivers/usb/host/isp116x-hcd.c ++++ b/drivers/usb/host/isp116x-hcd.c +@@ -1551,10 +1551,12 @@ static int isp116x_remove(struct platform_device *pdev) + + iounmap(isp116x->data_reg); + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); +- release_mem_region(res->start, 2); ++ if (res) ++ release_mem_region(res->start, 2); + iounmap(isp116x->addr_reg); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); +- release_mem_region(res->start, 2); ++ if (res) ++ release_mem_region(res->start, 2); + + usb_put_hcd(hcd); + return 0; +-- +2.35.1 +