iio: dummy: iio_simple_dummy: check the return value of kstrdup()
Subsystems (10)
Sasha Levin
maintainerPATCH 1/19 iio: dummy: iio_simple_dummy: check the return value of kstrdup()
From: Xiaoke Wang <[email protected]>
[ 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.
--- drivers/iio/dummy/iio_simple_dummy.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/iio/dummy/iio_simple_dummy.c +12 -8
@@ -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); }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 2/19 lkdtm/usercopy: Expand size of "out of frame" object
From: Kees Cook <[email protected]>
[ 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.
--- drivers/misc/lkdtm_usercopy.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/misc/lkdtm_usercopy.c +14 -3
@@ -28,12 +28,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. */
@@ -41,7 +41,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)
@@ -64,6 +69,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 );
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 3/19 tty: synclink_gt: Fix null-pointer-dereference in slgt_clean()
In reply to Sasha LevinFrom: Zheyu Ma <[email protected]>
[ 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] <TASK> [ 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.
--- drivers/tty/synclink_gt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/synclink_gt.c +2 -0
@@ -1823,6 +1823,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 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 4/19 tty: Fix a possible resource leak in icom_probe
In reply to Sasha LevinFrom: Huang Guobin <[email protected]>
[ Upstream commit ee157a79e7c82b01ae4c25de0ac75899801f322c ]
When pci_read_config_dword failed, call pci_release_regions() and pci_disable_device() to recycle the resource previously allocated.
--- drivers/tty/serial/icom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/icom.c +1 -1
@@ -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,
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 5/19 drivers: staging: rtl8192e: Fix deadlock in rtllib_beacons_stop()
In reply to Sasha LevinFrom: Duoming Zhou <[email protected]>
[ 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.
--- drivers/staging/rtl8192e/rtllib_softmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_softmac.c +1 -1
@@ -655,9 +655,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); }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 6/19 USB: host: isp116x: check return value after calling platform_get_resource()
In reply to Sasha LevinFrom: Zhen Ni <[email protected]>
[ Upstream commit 134a3408c2d3f7e23eb0e4556e0a2d9f36c2614e ]
It will cause null-ptr-deref if platform_get_resource() returns NULL, we need check the return value.
--- drivers/usb/host/isp116x-hcd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/host/isp116x-hcd.c +4 -2
@@ -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 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 7/19 drivers: tty: serial: Fix deadlock in sa1100_set_termios()
In reply to Sasha LevinFrom: Duoming Zhou <[email protected]>
[ 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.
--- drivers/tty/serial/sa1100.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/sa1100.c +2 -2
@@ -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. */
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 8/19 drivers: usb: host: Fix deadlock in oxu_bus_suspend()
In reply to Sasha LevinFrom: Duoming Zhou <[email protected]>
[ 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.
--- drivers/usb/host/oxu210hp-hcd.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/host/oxu210hp-hcd.c +2 -0
@@ -3491,8 +3491,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 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 9/19 USB: hcd-pci: Fully suspend across freeze/thaw cycle
In reply to Sasha LevinFrom: Evan Green <[email protected]>
[ 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.
--- drivers/usb/core/hcd-pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/core/hcd-pci.c +2 -2
@@ -637,10 +637,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,
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 10/19 usb: dwc2: gadget: don't reset gadget's driver->bus
In reply to Sasha LevinFrom: Marek Szyprowski <[email protected]>
[ 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.
--- drivers/usb/dwc2/gadget.c | 1 - 1 file changed, 1 deletion(-)
drivers/usb/dwc2/gadget.c +0 -1
@@ -3445,7 +3445,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 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 11/19 misc: rtsx: set NULL intfdata when probe fails
In reply to Sasha LevinFrom: Shuah Khan <[email protected]>
[ 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).
--- drivers/mfd/rtsx_usb.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/rtsx_usb.c +1 -0
@@ -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;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 12/19 clocksource/drivers/sp804: Avoid error on multiple instances
In reply to Sasha LevinFrom: Andre Przywara <[email protected]>
[ 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.
--- drivers/clocksource/timer-sp804.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clocksource/timer-sp804.c +5 -5
@@ -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 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 13/19 staging: rtl8712: fix uninit-value in r871xu_drv_init()
In reply to Sasha LevinFrom: Wang Cheng <[email protected]>
[ 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
--- drivers/staging/rtl8712/usb_intf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8712/usb_intf.c +3 -3
@@ -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 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 14/19 serial: msm_serial: disable interrupts in __msm_console_write()
In reply to Sasha LevinFrom: John Ogness <[email protected]>
[ 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.
--- drivers/tty/serial/msm_serial.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/tty/serial/msm_serial.c +5 -0
@@ -1578,6 +1578,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;
@@ -1595,6 +1596,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)
@@ -1640,6 +1643,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,
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 15/19 md: protect md_unregister_thread from reentrancy
In reply to Sasha LevinFrom: Guoqing Jiang <[email protected]>
[ 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.
--- drivers/md/md.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/md/md.c +10 -5
@@ -7252,17 +7252,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); }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 16/19 Revert "net: af_key: add check for pfkey_broadcast in function pfkey_process"
In reply to Sasha LevinFrom: Michal Kubecek <[email protected]>
[ 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
--- net/key/af_key.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/key/af_key.c +6 -4
@@ -2861,10 +2861,12 @@ static int pfkey_process(struct sock *sk, struct sk_buff *skb, const struct sadbvoid *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);
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 17/19 drm/radeon: fix a possible null pointer dereference
In reply to Sasha LevinFrom: Gong Yuanjun <[email protected]>
[ 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.
--- drivers/gpu/drm/radeon/radeon_connectors.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/radeon/radeon_connectors.c +4 -0
@@ -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); }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 18/19 modpost: fix undefined behavior of is_arm_mapping_symbol()
In reply to Sasha LevinFrom: Masahiro Yamada <[email protected]>
[ 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
--- scripts/mod/modpost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/mod/modpost.c +2 -1
@@ -1212,7 +1212,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 ] =='.' ); }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 19/19 nodemask: Fix return values to be unsigned
In reply to Sasha LevinFrom: Kees Cook <[email protected]>
[ 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[]; /*
| ^~~~~~~~~~~--- include/linux/nodemask.h | 38 +++++++++++++++++++------------------- lib/nodemask.c | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-)
include/linux/nodemask.h +19 -19
@@ -41,11 +41,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
@@ -143,7 +143,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); }
@@ -190,7 +190,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);
@@ -198,7 +198,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);
@@ -206,20 +206,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); }
@@ -250,15 +250,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)); }/*
@@ -266,7 +266,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) {
@@ -286,9 +286,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 )); }
@@ -429,11 +429,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 ]); }
lib/nodemask.c +2 -2
@@ -2,9 +2,9 @@#include <linux/module.h> #include <linux/random.h> -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);
Signature · 1 line
2.35.1