5.15.226-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 374/2214 HID: cp2112: validate response report lengths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit fc54e71a063c0dcc4bceba6d0f71805a9b84082d upstream.
The HID core invokes raw_event callbacks before validating the report length. cp2112_raw_event() reads every field of a transfer status response without checking size. For a data response, it reads the length at offset two and copies that many bytes from offset three, again without ensuring that the input report contains them.
Require a complete transfer status structure. For data responses, first require the header and then ensure the clamped payload length fits in the received report before copying it.
Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw_event length validation to hid-asus.
--- drivers/hid/hid-cp2112.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/hid/hid-cp2112.c +8 -1
@@ -1424,6 +1424,9 @@ static int cp2112_raw_event(struct hid_dswitch (data[0 ]) {case CP2112_TRANSFER_STATUS_RESPONSE : +if (size <sizeof (*xfer)) +return 0 ; +hid_dbg (hdev,"xfer status: %02x %02x %04x %04x\n" , xfer->status0, xfer->status1,be16_to_cpu (xfer->retries),be16_to_cpu (xfer->length));
@@ -1457,11 +1460,16 @@ static int cp2112_raw_event(struct hid_datomic_set (&dev->xfer_avail,1 );break ;case CP2112_DATA_READ_RESPONSE : +if (size <3 ) +return 0 ; +hid_dbg (hdev,"read response: %02x %02x\n" , data[1 ], data[2 ]); dev->read_length = data[2 ];if (dev->read_length >sizeof (dev->read_data)) dev->read_length =sizeof (dev->read_data); +if (dev->read_length > size -3 ) +return 0 ;memcpy (dev->read_data, &data[3 ], dev->read_length);atomic_set (&dev->read_avail,1 );
@@ -1488,4 +1496,3 @@ module_hid_driver(cp2112_driver);MODULE_DESCRIPTION ("Silicon Labs HID USB to SMBus master bridge" );MODULE_AUTHOR ("David Barksdale <[email protected]>" );MODULE_LICENSE ("GPL" ); -
Greg Kroah-Hartman
maintainerPATCH 375/2214 HID: elo: reject short touchscreen reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 1cb92fcb2ac344d78737e3c5cb7b061dfb2850b1 upstream.
The HID core invokes raw_event callbacks before validating the report length. elo_raw_event() only checks the first-byte packet marker before elo_process_data() reads coordinates, flags, and pressure through offset seven. A truncated packet beginning with the expected marker can therefore cause an out-of-bounds read.
Require the complete eight-byte SmartSet packet before parsing it.
Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw_event length validation to hid-asus.
--- drivers/hid/hid-elo.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-elo.c +3 -0
@@ -85,6 +85,9 @@ static int elo_raw_event(struct hid_deviif (!(hdev->claimed &HID_CLAIMED_INPUT ) ||list_empty (&hdev->inputs))return 0 ; +if (size <ELO_SMARTSET_PACKET_SIZE ) +return 0 ; + hidinput = list_first_entry(&hdev->inputs, struct hid_input, list);switch (report->id) {
Greg Kroah-Hartman
maintainerPATCH 376/2214 HID: logitech-dj: validate unnumbered keyboard reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit c2deafcb4c8227771f768d77ed3c0a489250e9b2 upstream.
The HID core invokes raw_event callbacks before validating the report length. For an unnumbered keyboard report, logi_dj_raw_event() uses the second byte as temporary storage while prepending a report ID. A one-byte report therefore makes both the initial write and the later restoration access data beyond the received report.
Reject unnumbered keyboard reports that do not provide the temporary byte.
Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw_event length validation to hid-asus.
--- drivers/hid/hid-logitech-dj.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-logitech-dj.c +3 -0
@@ -1682,6 +1682,9 @@ static int logi_dj_raw_event(struct hid_if (!hdev->report_enum[HID_INPUT_REPORT ].numbered) {if (djrcv_dev->unnumbered_application ==HID_GD_KEYBOARD ) { +if (size <2 ) +return false; +/* * For the keyboard, we can reuse the same report by * using the second byte which is constant in the USB
Greg Kroah-Hartman
maintainerPATCH 377/2214 HID: mcp2221: validate response report length
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 1ae40774d386b7a51e4799200106429a7e14e8ec upstream.
MCP2221 responses are 64-byte reports, but mcp2221_raw_event() currently accepts any report of at least four bytes. Several response handlers read far beyond that minimum. In particular, the I2C status response reads offset 20 and copies ADC samples starting at offset 50. Other GPIO, SRAM, and flash response handlers also access fixed offsets beyond byte three.
The HID core invokes raw_event callbacks before validating the report length, so a truncated response can cause an out-of-bounds read. Require a complete protocol report before dispatching any response handler.
Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw_event length validation to hid-asus.
--- drivers/hid/hid-mcp2221.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-mcp2221.c +1 -1
@@ -739,7 +739,7 @@ static int mcp2221_raw_event(struct hid_u8 *buf;struct mcp2221 *mcp =hid_get_drvdata (hdev); -if (size <4 ) +if (size <sizeof (mcp->txbuf))return 0 ;switch (data[0 ]) {
Greg Kroah-Hartman
maintainerPATCH 378/2214 HID: picoLCD: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
commit feade898fc958ff355101adf12d5632272e64220 upstream.
fb_deferred_io_init() allocates deferred I/O state, populating info->fbdefio_state, or leaving it NULL if an error occurs.
Currently picolcd_init_framebuffer() ignores its return value.
Therefore if an error arises in fb_deferred_io_init() (for instance, due to an allocation failure) info->fbdefio_state is left NULL.
When the file is subsequently opened, fb_open() will dereference a NULL pointer (calling fb_deferred_io_open()).
Fix this by checking for the error.
Also correct cleanup ordering - defio is initialised after the sysfs file, so cleanup defio first.
--- drivers/hid/hid-picolcd_fb.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/hid/hid-picolcd_fb.c +9 -3
@@ -557,17 +557,23 @@ int picolcd_init_framebuffer(struct pico goto err_cleanup; } -fb_deferred_io_init (info); + error =fb_deferred_io_init (info); +if (error) { +dev_err (dev,"failed to initialize deferred I/O\n" ); + goto err_sysfs; + } + error =register_framebuffer (info);if (error) {dev_err (dev,"failed to register framebuffer\n" ); - goto err_sysfs; + goto err_defio; }return 0 ; +err_defio: +fb_deferred_io_cleanup (info); err_sysfs:device_remove_file (dev, &dev_attr_fb_update_rate); -fb_deferred_io_cleanup (info); err_cleanup: data->fb_info =NULL ;
Greg Kroah-Hartman
maintainerPATCH 379/2214 HID: quirks: Always poll the Anne Pro 2 with product ID a292
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabor Tanz <[email protected]>
commit cbc13a78a89d087252947d0a51048e576cfcb3ef upstream.
The wired Anne Pro 2 identifying as 04d9:a292 stops delivering keyboard input after a period of inactivity. Unplugging and reconnecting the keyboard restores input.
Keeping ObinsKit running prevents the problem. A read-only userspace reader that keeps USB HID interface 1 open also prevents it, as does usbhid.quirks=0x04d9:0xa292:0x00000400 without either application running.
Commit ca28aff0e1dc ("HID: quirks: Always poll Obins Anne Pro 2 keyboard") added HID_QUIRK_ALWAYS_POLL for product ID a293. The variant identifying as 04d9:a292 exhibits the same symptom. Apply the quirk to this product ID as well.
--- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-quirks.c | 1 + 2 files changed, 2 insertions(+)
drivers/hid/hid-ids.h +1 -0
@@ -669,6 +669,7 @@#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081 0xa081#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2 0xa0c2#define USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD_A096 0xa096 +#define USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD_A292 0xa292#define USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD_A293 0xa293#define USB_VENDOR_ID_IMATION 0x0718
drivers/hid/hid-quirks.c +1 -0
@@ -102,6 +102,7 @@ static const struct hid_device_id hid_qu { HID_USB_DEVICE(USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING), HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, { HID_USB_DEVICE(USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING), HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD_A096), HID_QUIRK_NO_INIT_REPORTS }, + { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD_A292), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD_A293), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0A4A), HID_QUIRK_ALWAYS_POLL }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_ELITE_PRESENTER_MOUSE_464A), HID_QUIRK_MULTI_INPUT },
Greg Kroah-Hartman
maintainerPATCH 380/2214 HID: roccat: isku: reject short button reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 93e5f7f6189af76a2b2e2dfe647838a7b9f99d21 upstream.
The raw event callback runs before HID core validates and zero-pads the report. It passes the buffer to helpers which inspect data[0] and, for a button report, read the complete struct isku_report_button. A truncated report can therefore cause an out-of-bounds read.
Require enough data for the button report before calling either helper. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-isku.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-isku.c +3 -0
@@ -408,6 +408,9 @@ static int isku_raw_event(struct hid_devif (isku ==NULL )return 0 ; +if (size <sizeof (struct isku_report_button )) +return 0 ; +isku_keep_values_up_to_date (isku, data);if (isku->roccat_claimed)
Greg Kroah-Hartman
maintainerPATCH 381/2214 HID: roccat: koneplus: reject short button reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit d879e17a8b4c572c0b53b4e42a36849484e8f00c upstream.
The raw event callback runs before HID core validates and zero-pads the report. It passes the buffer to helpers which inspect data[0] and, for a button report, read the complete struct koneplus_mouse_report_button. A truncated report can therefore cause an out-of-bounds read.
Require enough data for the button report before calling either helper. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-koneplus.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-koneplus.c +3 -0
@@ -520,6 +520,9 @@ static int koneplus_raw_event(struct hidif (koneplus ==NULL )return 0 ; +if (size <sizeof (struct koneplus_mouse_report_button )) +return 0 ; +koneplus_keep_values_up_to_date (koneplus, data);if (koneplus->roccat_claimed)
Greg Kroah-Hartman
maintainerPATCH 382/2214 HID: roccat: konepure: reject short button reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 1590b7c9bea0abe7a5d25dbfe06287c48c238a6f upstream.
The raw event callback runs before HID core validates and zero-pads the report. It reads the report number without checking the received length and passes matching data to roccat_report_event(), which copies a complete struct konepure_mouse_report_button. A truncated report can therefore cause an out-of-bounds read and expose adjacent data through the Roccat character device.
Require a complete button report before inspecting or forwarding it. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-konepure.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-konepure.c +3 -0
@@ -178,6 +178,9 @@ static int konepure_raw_event(struct hid != USB_INTERFACE_PROTOCOL_MOUSE)return 0 ; +if (size <sizeof (struct konepure_mouse_report_button )) +return 0 ; +if (data[0 ] !=KONEPURE_MOUSE_REPORT_NUMBER_BUTTON )return 0 ;
Greg Kroah-Hartman
maintainerPATCH 383/2214 HID: roccat: kovaplus: reject short button reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit e95917a606f486e46f5136fc1b72190742a091d6 upstream.
The raw event callback runs before HID core validates and zero-pads the report. It passes the buffer to helpers which inspect data[0] and read a complete struct kovaplus_mouse_report_button for button reports. A truncated report can therefore cause an out-of-bounds read.
Require enough data for the button report before calling either helper. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-kovaplus.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-kovaplus.c +3 -0
@@ -611,6 +611,9 @@ static int kovaplus_raw_event(struct hidif (kovaplus ==NULL )return 0 ; +if (size <sizeof (struct kovaplus_mouse_report_button )) +return 0 ; +kovaplus_keep_values_up_to_date (kovaplus, data);if (kovaplus->roccat_claimed)
Greg Kroah-Hartman
maintainerPATCH 384/2214 HID: roccat: pyra: reject short button reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 493268f459bb6aeeecbc77f2204c11ad74d05213 upstream.
The raw event callback runs before HID core validates and zero-pads the report. It passes the buffer to helpers which inspect data[0] and read a complete struct pyra_mouse_event_button for button reports. A truncated report can therefore cause an out-of-bounds read.
Require enough data for the button report before calling either helper. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-pyra.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-pyra.c +3 -0
@@ -554,6 +554,9 @@ static int pyra_raw_event(struct hid_devif (pyra ==NULL )return 0 ; +if (size <sizeof (struct pyra_mouse_event_button )) +return 0 ; +pyra_keep_values_up_to_date (pyra, data);if (pyra->roccat_claimed)
Greg Kroah-Hartman
maintainerPATCH 385/2214 HID: roccat: ryos: reject short special reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 02f3607d0beb82e76481568bf631235e6a319b47 upstream.
The raw event callback runs before HID core validates and zero-pads the report. It reads the report number without checking the received length and passes matching data to roccat_report_event(), which copies a complete struct ryos_report_special. A truncated report can therefore cause an out-of-bounds read and expose adjacent data through the Roccat character device.
Require a complete special report before inspecting or forwarding it. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-ryos.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-ryos.c +3 -0
@@ -186,6 +186,9 @@ static int ryos_raw_event(struct hid_dev != RYOS_USB_INTERFACE_PROTOCOL)return 0 ; +if (size <sizeof (struct ryos_report_special )) +return 0 ; +if (data[0 ] !=RYOS_REPORT_NUMBER_SPECIAL )return 0 ;
Greg Kroah-Hartman
maintainerPATCH 386/2214 HID: roccat: savu: reject short special reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 76c51fdc825a0486f8d88ff896d39acec8f377b4 upstream.
The raw event callback runs before HID core validates and zero-pads the report. It passes the buffer to a helper which inspects data[0] and, for a special report, reads the complete struct savu_mouse_report_special. A truncated report can therefore cause an out-of-bounds read.
Require enough data for the special report before calling the helper. Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw-event length validation to hid-asus.
--- drivers/hid/hid-roccat-savu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-roccat-savu.c +3 -0
@@ -179,6 +179,9 @@ static int savu_raw_event(struct hid_devif (savu ==NULL )return 0 ; +if (size <sizeof (struct savu_mouse_report_special )) +return 0 ; +if (savu->roccat_claimed)savu_report_to_chrdev (savu, data);
Greg Kroah-Hartman
maintainerPATCH 387/2214 drm/amdgpu/powerplay: Align get_tonga_state_array() header with prototype
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivasan Shanmugam <[email protected]>
commit 4986757d3207383c052689532e505edccc6df7c8 upstream.
The function header above get_tonga_state_array() still refers to check_powerplay_tables() and does not describe all of the function parameters.
Update it to match the current function prototype and include the missing parameter description.
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +4 -3
@@ -1502,11 +1502,12 @@ static int init_thermal_controller( }/** -* check_powerplay_tables - Private Function used during initialization. -* Inspect the PowerPlay table for obvious signs of corruption. +* get_tonga_state_array - Get the Tonga state array from the PowerPlay table. * @hwmgr: Pointer to the hardware manager. * @powerplay_table: Pointer to the PowerPlay Table. -* Exception: 2 if the powerplay table is incorrect. +* @state_array: Pointer to the returned Tonga state array. +* +* Return: 0 on success, negative error code on failure. */ static int get_tonga_state_array(struct pp_hwmgr *hwmgr, const ATOM_Tonga_POWERPLAYTABLE *powerplay_table,
Greg Kroah-Hartman
maintainerPATCH 388/2214 netfilter: conntrack: always lower timeout for non-closing RST packets
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
commit 73df81b38cb7f70a347a97370386378a86e53019 upstream.
The existing check might extend the timeout if the ESTABLISHED timeout has been tuned to be lower than UNACK via sysctl. Reported by sashiko.
--- net/netfilter/nf_conntrack_proto_tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_proto_tcp.c +2 -1
@@ -1222,7 +1222,8 @@ int nf_conntrack_tcp_packet(struct nf_co timeouts[new_state] > timeouts[TCP_CONNTRACK_RETRANS]) timeout = timeouts[TCP_CONNTRACK_RETRANS ]; else if (unlikely(index == TCP_RST_SET && - new_state == TCP_CONNTRACK_ESTABLISHED)) + new_state == TCP_CONNTRACK_ESTABLISHED) && + timeouts[new_state] > timeouts[TCP_CONNTRACK_UNACK]) timeout = timeouts[TCP_CONNTRACK_UNACK ]; else if ((ct->proto.tcp.seen[0].flags | ct->proto.tcp.seen[1].flags) & IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED &&
Greg Kroah-Hartman
maintainerPATCH 389/2214 tun: Require CAP_NET_ADMIN to attach to an ownerless device
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Woodhouse <[email protected]>
commit ffdf678dd16610e3f006dac904bd37c09684673c upstream.
Twenty years ago I made creating a tuntap device require CAP_NET_ADMIN in commit ca6bb5d7ab22 ("[NET]: Require CAP_NET_ADMIN to create tuntap devices.")
The idea was to allow the permissions on /dev/net/tun to be relaxed to 0666 and thus allow owners of tun devices assigned with TUNSETOWNER to actually open it and get at their devices.
What we missed at the time was that persistent devices with *no* owner were already essentially world-consumable, and anyone who could open the device node could also attach to those.
Even then, using persistent devices with no explicitly set owner — on the (false) presumption that CAP_NET_ADMIN would be required to open them — wasn't an egregious userspace bug. There are cases where it does make sense to separate the creation/configuration of the netdevice, from the process which shovels packets into it.
Since then, TUNSETGROUP was added a year later in commit 8c644623fe7e ("[NET]: Allow group ownership of TUN/TAP devices."). Its commit message noted that if both uid and gid are set, both have to match (in itself a bizarre choice) — but still not that with *neither* set, no permission at all was required.
Then in 2012 commit c8d68e6be1c3 ("tuntap: multiqueue support") allowed new queues to be attached to a device from the moment of its creation, with no way for userspace to close the race between creation and a subsequent TUNSET{OWNER,GROUP}.
In 2024, commit 3ca459eaba1bf ("tun: fix group permission check") tried to fix things to be saner: only require the user *or* the group to match, in line with standard POSIX permissions, and require CAP_NET_ADMIN if neither the user nor group authorised the access (although it put the CAP_NET_ADMIN check first, and would wrongly have reported the capability as having been used even when it was not).
That fix was reverted in commit a70c7b3cbc06 ("tun: revert fix group permission check") due to allegedly causing a regression in an selinux test suite which *expected* the attachment to succeed when authorised by none of user, group, nor CAP_NET_ADMIN:
https://lore.kernel.org/netdev/CAFqZXNtkCBT4f+PwyVRmQGoT3p1eVa01fCG_aNtpt6dakXncUg@mail.gmail.com/
We should not break UAPI. But we don't have to consider an selinux test case which deliberately exercises a security flaw to be UAPI worth preserving either. To which end, I have fixed it in selinux-testsuite commit b2f894f0016b ("tests/tun_tap: set an owner on the device for the relabel tests").
So: fix the lack of CAP_NET_ADMIN check on devices which *haven't* been assigned an owner or group, while leaving the weird tun ownership model as it was (user *and* group have to match, if both are set). If someone still wants to fix the latter (which wasn't actually the reason the previous attempt was reverted), they can do it under separate cover.
Permit attaching to an existing device only if an owner and/or group was set and the caller matches all that were set, or if the caller has CAP_NET_ADMIN. The only behavioural change is that a device with no owner or group now requires CAP_NET_ADMIN to attach — precisely the loophole we want to close.
And put the CAP_NET_ADMIN check in the right place this time.
--- drivers/net/tun.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/tun.c +9 -5
@@ -575,14 +575,18 @@ static u16 tun_select_queue(struct net_dreturn ret; } -static inline bool tun_not_capable (struct tun_struct *tun) +static inline bool tun_permitted (struct tun_struct *tun) {const struct cred *cred =current_cred ();struct net *net =dev_net (tun->dev); -return ((uid_valid (tun->owner) && !uid_eq (cred->euid, tun->owner)) || - (gid_valid (tun->group) && !in_egroup_p (tun->group))) && - !ns_capable (net->user_ns,CAP_NET_ADMIN ); +/* If both uid and gid are set, *both* must match */ +if ((uid_valid (tun->owner) ||gid_valid (tun->group)) && + (!uid_valid (tun->owner) ||uid_eq (cred->euid, tun->owner)) && + (!gid_valid (tun->group) ||in_egroup_p (tun->group))) +return true; + +return ns_capable (net->user_ns,CAP_NET_ADMIN ); }static void tun_set_real_num_queues (struct tun_struct *tun)
@@ -2732,7 +2736,7 @@ static int tun_set_iff(struct net *net, !!(tun->flags & IFF_MULTI_QUEUE))return -EINVAL ; -if (tun_not_capable (tun)) +if (!tun_permitted (tun))return -EPERM ; err =security_tun_dev_open (tun->security);if (err <0 )
Greg Kroah-Hartman
maintainerPATCH 390/2214 ksmbd: validate security descriptor offsets before pointer arithmetic
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 3474e1a304fbf9f7c996b24adcd519e031227a90 ]
parse_sec_desc() constructs SID and DACL pointers by adding untrusted 32-bit offsets to the security descriptor before checking their bounds. The existing checks reject offsets into the descriptor header, but do not reject offsets beyond the descriptor's length.
On a 32-bit kernel, a large offset can wrap the pointer before the descriptor. The end-only checks in parse_sid() and parse_dacl() can then accept it, allowing an authenticated SMB2 SET_INFO request to access memory outside the security descriptor and fault the kernel.
Check each nonzero offset against acl_len before constructing its pointer. Initialize the optional owner and group SID pointers to NULL so an omitted SID remains absent when parsing the DACL.
The 5.15 tree keeps this code in fs/ksmbd/smbacl.c and uses a void parse_dacl(). Preserve those interfaces in this backport.
--- fs/ksmbd/smbacl.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
fs/ksmbd/smbacl.c +17 -6
@@ -830,7 +830,7 @@ int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, int acl_len, struct smb_fattr *fattr) { int rc = 0; -struct smb_sid *owner_sid_ptr, *group_sid_ptr; +struct smb_sid *owner_sid_ptr =NULL , *group_sid_ptr =NULL ;struct smb_acl *dacl_ptr;/* no need for SACL ptr */ char *end_of_acl = ((char *)pntsd) + acl_len;__u32 dacloffset;
@@ -842,12 +842,7 @@ int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,if (acl_len <sizeof (struct smb_ntsd ))return -EINVAL ; - owner_sid_ptr = (struct smb_sid *)((char *)pntsd + -le32_to_cpu (pntsd->osidoffset)); - group_sid_ptr = (struct smb_sid *)((char *)pntsd + -le32_to_cpu (pntsd->gsidoffset)); dacloffset =le32_to_cpu (pntsd->dacloffset); - dacl_ptr = (struct smb_acl *)((char *)pntsd + dacloffset); ksmbd_debug(SMB, "revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n", pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset),
@@ -863,6 +858,12 @@ int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, pntsd->type =cpu_to_le16 (DACL_PRESENT );if (pntsd->osidoffset) { +if (le32_to_cpu (pntsd->osidoffset) <sizeof (struct smb_ntsd ) || +le32_to_cpu (pntsd->osidoffset) >= acl_len) +return -EINVAL ; + + owner_sid_ptr = (struct smb_sid *)((char *)pntsd + +le32_to_cpu (pntsd->osidoffset)); rc =parse_sid (owner_sid_ptr, end_of_acl);if (rc) {pr_err ("%s: Error %d parsing Owner SID\n" , __func__, rc);
@@ -878,6 +879,12 @@ int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, }if (pntsd->gsidoffset) { +if (le32_to_cpu (pntsd->gsidoffset) <sizeof (struct smb_ntsd ) || +le32_to_cpu (pntsd->gsidoffset) >= acl_len) +return -EINVAL ; + + group_sid_ptr = (struct smb_sid *)((char *)pntsd + +le32_to_cpu (pntsd->gsidoffset)); rc =parse_sid (group_sid_ptr, end_of_acl);if (rc) { pr_err("%s: Error %d mapping Owner SID to gid\n",
@@ -899,6 +906,10 @@ int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, pntsd->type |=cpu_to_le16 (DACL_PROTECTED );if (dacloffset) { +if (dacloffset <sizeof (struct smb_ntsd ) || dacloffset >= acl_len) +return -EINVAL ; + + dacl_ptr = (struct smb_acl *)((char *)pntsd + dacloffset);parse_dacl (user_ns, dacl_ptr, end_of_acl, owner_sid_ptr, group_sid_ptr, fattr); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/2214 smb: client: fix early procfs exposure race
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fredric Cover <[email protected]>
[ Upstream commit 7b1afb631395c958993cda4631002258ef4151ea ]
Currently, init_cifs() calls cifs_proc_init() near the beginning of the function, before INIT_LIST_HEAD, leading to a momentarily uninitialized, but exposed, procfs. If a userspace process reads this empty procfs, iterating over a zeroed list_head leads to a NULL pointer dereference and a kernel oops/panic.
For example, if a delay is added between cifs_proc_init() and INIT_LIST_HEAD, and a userspace process is polling /proc/fs/cifs/DebugData, the following oops occurs:
BUG: kernel NULL pointer dereference, address: 0000000000000608 Oops: Oops: 0000 [#1] SMP PTI CPU: 0 UID: 0 PID: 3477 Comm: cat Not tainted 7.3.0-02212-g4df4d2a577db-dirty #6 PREEMPT(lazy) RIP: 0010:cifs_debug_data_proc_show+0x103/0xd80 [cifs] Call Trace: <TASK> ? seq_read_iter+0x86/0x400 ? seq_read_iter+0x86/0x400 seq_read_iter+0x183/0x400 proc_reg_read_iter+0x62/0x90 copy_splice_read+0x215/0x310 splice_file_to_pipe+0xec/0x1c0 do_splice+0x4b8/0x780 __se_sys_splice+0x18f/0x250 do_syscall_64+0x109/0x330 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
Fix this by moving cifs_proc_init() down in init_cifs(), ensuring it runs only after all internal lists, locks, counters, and workqueues are fully ready, but before registering the filesystem. Update the error cleanup ladder and exit_cifs() to maintain proper LIFO order.
--- fs/cifs/cifsfs.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
fs/cifs/cifsfs.c +9 -11
@@ -1590,7 +1590,6 @@ static int __initinit_cifs (void) {int rc =0 ; -cifs_proc_init ();INIT_LIST_HEAD (&cifs_tcp_ses_list);/* * Initialize Global counters
@@ -1633,10 +1632,8 @@ init_cifs(void) } cifsiod_wq =alloc_workqueue ("cifsiod" ,WQ_FREEZABLE |WQ_MEM_RECLAIM ,0 ); -if (!cifsiod_wq) { - rc = -ENOMEM ; - goto out_clean_proc; - } +if (!cifsiod_wq) +return -ENOMEM ;/* * Consider in future setting limit!=0 maybe to min(num_of_cores - 1, 3)
@@ -1709,19 +1706,22 @@ init_cifs(void)if (rc) goto out_cifs_swn_init; +cifs_proc_init (); + rc =register_filesystem (&cifs_fs_type);if (rc) - goto out_init_cifs_idmap; + goto out_clean_proc; rc =register_filesystem (&smb3_fs_type);if (rc) {unregister_filesystem (&cifs_fs_type); - goto out_init_cifs_idmap; + goto out_clean_proc; }return 0 ; -out_init_cifs_idmap: +out_clean_proc: +cifs_proc_clean ();exit_cifs_idmap (); out_cifs_swn_init: #ifdef CONFIG_CIFS_SWN_UPCALL
@@ -1753,8 +1753,6 @@ init_cifs(void)destroy_workqueue (decrypt_wq); out_destroy_cifsiod_wq:destroy_workqueue (cifsiod_wq); -out_clean_proc: -cifs_proc_clean ();return rc; }
@@ -1764,6 +1762,7 @@ exit_cifs(void)cifs_dbg (NOISY ,"exit_smb3\n" );unregister_filesystem (&cifs_fs_type);unregister_filesystem (&smb3_fs_type); +cifs_proc_clean ();cifs_dfs_release_automount_timer ();exit_cifs_idmap ();#ifdef CONFIG_CIFS_SWN_UPCALL
@@ -1784,7 +1783,6 @@ exit_cifs(void)destroy_workqueue (decrypt_wq);destroy_workqueue (fileinfo_put_wq);destroy_workqueue (cifsiod_wq); -cifs_proc_clean (); }MODULE_AUTHOR ("Steve French" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/2214 smb: client: do not pass a NULL buf to is_oplock_break()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zikang Gao <[email protected]>
[ Upstream commit 2225ab306575e424b3dad2ee1be2521c89249d15 ]
receive_encrypted_read() sets *num_mids = 1 and never writes the caller's bufs[]. Offload returns -1 with *num_mids = 0, so the demultiplex thread skips the frame. The inline decrypt path returns 0 even when smb2_find_mid() fails.
cifs_demultiplex_thread() then treats mids[i] == NULL as an oplock break and calls is_oplock_break(bufs[i], server) with bufs[i] still NULL. smb2_is_valid_oplock_break() reads hdr.Command at offset 12 and oopses.
A large encrypted READ whose MessageId does not match is enough to panic cifsd.
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000001: 0000 [#1] SMP KASAN PTI
KASAN: null-ptr-deref in range
[0x0000000000000008-0x000000000000000f]
CPU: 0 PID: 100 Comm: cifsd
RIP: smb2_is_valid_oplock_break+0xc8/0x2270 [cifs]
cifs_demultiplex_thread
Kernel panic - not syncing: Fatal exceptionReturn -1 when inline decrypt finds no mid, and skip is_oplock_break() plus the unknown-frame dump when bufs[i] is NULL. receive_encrypted_standard() already assigns bufs[*num_mids].
--- fs/cifs/connect.c | 4 +++- fs/cifs/smb2ops.c | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-)
fs/cifs/connect.c +3 -1
@@ -1089,12 +1089,14 @@ cifs_demultiplex_thread(void *p) mids[i]->callback (mids[i]);cifs_mid_q_entry_release (mids[i]); - }else if (server->ops->is_oplock_break && + }else if (bufs[i] && server->ops->is_oplock_break && server->ops->is_oplock_break (bufs[i], server)) {smb2_add_credits_from_hdr (bufs[i], server);cifs_dbg (FYI ,"Received oplock break\n" ); }else { +if (!bufs[i]) +continue ;cifs_server_dbg (VFS ,"No task to wake, unknown frame received! NumMids %d\n" ,atomic_read (&midCount)); cifs_dump_mem("Received Data is: ", bufs[i],
fs/cifs/smb2ops.c +3 -2
@@ -5208,9 +5208,10 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, goto free_pages; *mid =smb2_find_mid (server, buf); -if (*mid ==NULL ) +if (*mid ==NULL ) {cifs_dbg (FYI ,"mid not found\n" ); -else { + rc =-1 ; + }else {cifs_dbg (FYI ,"mid found\n" ); (*mid)->decrypted = true; rc = handle_read_data(server, *mid, buf,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/2214 net/sched: sch_teql: fix use-after-free on lower qdisc drop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: owen kwan <[email protected]>
[ Upstream commit 782d6bb8f9b8e9d8591181662222bf74cd3ecf79 ]
The issue: teql_master_xmit() tests the slave's ndo_start_xmit() return value against NETDEV_TX_OK alone. A slave that consumes the skb but returns an error code (rc < NET_XMIT_MASK, e.g. NET_XMIT_DROP) is treated as if the skb were still owned, so the loop restores skb->dev and calls __skb_pull() on it. A VLAN slave returns the result of dev_queue_xmit() from its ndo_start_xmit() (propagated since cbbef5e18307), and when the lower qdisc drops the packet that value is NET_XMIT_DROP after the skb has been freed, giving a use-after-free in teql_master_xmit().
The Fix: test for consumption with dev_xmit_complete(), which accepts NETDEV_TX_OK and every rc < NET_XMIT_MASK, matching other callers that need to distinguish consumed results from busy. Only NETDEV_TX_OK keeps the packet counted in tx_packets/tx_bytes and advances the slave; a consumed result that is neither a success nor NET_XMIT_CN ends the attempt and is charged to tx_dropped, so lower-qdisc drops are no longer reported as good transmits. NET_XMIT_CN is counted like success because it can accompany acceptance of the current packet: pfifo_head_drop drops the old head, enqueues the current skb and returns NET_XMIT_CN.
Conditions to recreate the bug:
With CONFIG_NET_SCH_TEQL,CONFIG_VLAN_8021Q and CONFIG_DUMMY enabled, add lkrdummy0 (dummy) and lkrvlan0 (VLAN id 37 on lkrdummy0); set a pfifo limit 0 root on lkrdummy0 and a teql0 root on lkrvlan0; bring teql0 up with an address and send one UDP packet to it. The VLAN xmit returns NET_XMIT_DROP from the lower qdisc while holding a freed skb.
--- net/sched/sch_teql.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
net/sched/sch_teql.c +9 -5
@@ -311,19 +311,23 @@ static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)case 0 :if (__netif_tx_trylock (slave_txq)) {unsigned int length =qdisc_pkt_len (skb); +int rc =NETDEV_TX_BUSY ; skb->dev = slave; -if (!netif_xmit_frozen_or_stopped (slave_txq) && -netdev_start_xmit (skb, slave, slave_txq, false) == -NETDEV_TX_OK ) { -__netif_tx_unlock (slave_txq); +if (!netif_xmit_frozen_or_stopped (slave_txq)) + rc =netdev_start_xmit (skb, slave, slave_txq, false); +__netif_tx_unlock (slave_txq); +if (dev_xmit_complete (rc)) { +if (rc !=NETDEV_TX_OK && rc !=NET_XMIT_CN ) { + master->tx_dropped++; +return NETDEV_TX_OK ; + } master->slaves =NEXT_SLAVE (q);netif_wake_queue (dev); master->tx_packets++; master->tx_bytes += length;return NETDEV_TX_OK ; } -__netif_tx_unlock (slave_txq); }if (netif_xmit_stopped (netdev_get_tx_queue (dev,0 ))) busy =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/2214 driver core: fix parent lock use-after-free on USB disconnect
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 0f554506a3fc6a21e714adf38cc3eb0ffe1bb452 ]
USB interfaces should be probed with their parent USB device lock held and the USB bus therefore sets the need_parent_lock bus flag so that driver core takes the parent lock when needed.
Driver core is only guaranteed to hold a reference to the parent device during initial probe however and nothing prevents the device and its parent from being deregistered and the parent potentially freed, for example, while iterating over devices in driver_attach() or bus_rescan_devices_helper().
Since commit 524134d42231 ("USB: don't cancel queued resets when unbinding drivers") USB interfaces hold a reference to their parent USB device, but a parent hub may still go away while probing a USB device (e.g. via the drivers_probe sysfs interface). This can lead to a use-after-free when taking the parent device lock before checking the device->p->dead flag of the device being probed.
As only USB interfaces actually need the parent lock, make the need_parent_lock feature even more fine grained by making it a device type rather than bus feature. By requiring that any users also make sure that their devices hold a reference to their parents (like USB does), driver core can lock a device and its parent without first checking if the device has been deregistered.
Note that this will also increase parallelism when using asynchronous probe as USB devices connected to the same hub can now be probed in parallel.
[ Fix mention of bus vs. device type in __device_driver_{un}lock().
- Danilo ]
--- drivers/base/bus.c | 4 ++-- drivers/base/dd.c | 8 ++++---- drivers/usb/core/driver.c | 1 - drivers/usb/core/message.c | 1 + include/linux/device.h | 5 +++++ include/linux/device/bus.h | 3 --- 6 files changed, 12 insertions(+), 10 deletions(-)
drivers/base/bus.c +2 -2
@@ -689,10 +689,10 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,int ret =0 ;if (!dev->driver) { -if (dev->parent && dev->bus->need_parent_lock) +if (dev->type && dev->type->need_parent_lock)device_lock (dev->parent); ret =device_attach (dev); -if (dev->parent && dev->bus->need_parent_lock) +if (dev->type && dev->type->need_parent_lock)device_unlock (dev->parent); }return ret <0 ? ret :0 ;
drivers/base/dd.c +4 -4
@@ -1051,7 +1051,7 @@ void device_initial_probe(struct device *dev)/* * __device_driver_lock - acquire locks needed to manipulate dev->drv * @dev: Device we will update driver info for -* @parent: Parent device. Needed if the bus requires parent lock +* @parent: Parent device. Needed if the device type requires parent lock * * This function will take the required locks for manipulating dev->drv. * Normally this will just be the @dev lock, but when called for a USB
@@ -1059,7 +1059,7 @@ void device_initial_probe(struct device *dev)*/ static void __device_driver_lock (struct device *dev,struct device *parent) { -if (parent && dev->bus->need_parent_lock) +if (dev->type && dev->type->need_parent_lock && parent)device_lock (parent);device_lock (dev); }
@@ -1067,7 +1067,7 @@ static void __device_driver_lock(struct device *dev, struct device *parent)/* * __device_driver_unlock - release locks needed to manipulate dev->drv * @dev: Device we will update driver info for -* @parent: Parent device. Needed if the bus requires parent lock +* @parent: Parent device. Needed if the device type requires parent lock * * This function will release the required locks for manipulating dev->drv. * Normally this will just be the the @dev lock, but when called for a
@@ -1076,7 +1076,7 @@ static void __device_driver_lock(struct device *dev, struct device *parent)static void __device_driver_unlock (struct device *dev,struct device *parent) {device_unlock (dev); -if (parent && dev->bus->need_parent_lock) +if (dev->type && dev->type->need_parent_lock && parent)device_unlock (parent); }
drivers/usb/core/driver.c +0 -1
@@ -2027,5 +2027,4 @@ struct bus_type usb_bus_type = { .name = "usb", .match = usb_device_match, .uevent = usb_uevent, - .need_parent_lock = true, };
drivers/usb/core/message.c +1 -0
@@ -1915,6 +1915,7 @@ struct device_type usb_if_device_type = { .name = "usb_interface", .release = usb_release_interface, .uevent = usb_if_uevent, + .need_parent_lock = true, }; static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
include/linux/device.h +5 -0
@@ -84,6 +84,10 @@ int subsys_virtual_register(struct bus_type *subsys,* information, equivalent to the kobj_type of a kobject. * If "name" is specified, the uevent will contain it in * the DEVTYPE variable. +* +* @need_parent_lock: When probing or removing a device of this type, +* driver core should lock the device's parent. Note that +* the device must hold a reference to its parent. */ struct device_type {const char *name;
@@ -94,6 +98,7 @@ struct device_type {void (*release)(struct device *dev);const struct dev_pm_ops *pm; +bool need_parent_lock; };/* interface for exporting device attributes */
include/linux/device/bus.h +0 -3
@@ -67,8 +67,6 @@ struct fwnode_handle;* @p: The private data of the driver core, only the driver core can * touch this. * @lock_key: Lock class key for use by the lock validator -* @need_parent_lock: When probing or removing a device on this bus, the -* device core should lock the device's parent. * * A bus is a channel between the processor and one or more devices. For the * purposes of the device model, all devices are connected via a bus, even if
@@ -111,7 +109,6 @@ struct bus_type {struct subsys_private *p;struct lock_class_key lock_key; -bool need_parent_lock; };extern int __must_check bus_register (struct bus_type *bus);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/2214 net/sched: cls_flower: avoid stale mask references after delete
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuhang Zheng <[email protected]>
[ Upstream commit 58f7989da6e715ce834ac861b7ba6ae9f9bdb098 ]
Flower releases a mask reference when a filter is removed from the classifier. The filter object can remain alive while dump, walk, or hardware reoffload paths hold a reference to it. Those paths can then dereference f->mask after the mask has already been released.
Keep the mask reference until the filter reference count reaches zero. Release the mask synchronously from the final __fl_put() while the caller still holds the tcf_proto reference, and leave the existing RCU work to free the mask. This keeps the mask available to every reader that still holds the filter.
The filter is still removed from the classifier indexes immediately. Therefore, a deleted filter can temporarily retain an otherwise empty mask; fl_delete() uses the handle IDR, rather than the mask list, to determine whether the classifier has become empty.
Failed mask assignment can leave fnew->mask as an error or borrowed pointer without an owned mask reference. Clear it before the common failure path so the final put cannot release an unowned reference.
This fix does not add fields, snapshots, or per-filter memory.
--- net/sched/cls_flower.c | 49 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-)
net/sched/cls_flower.c +28 -21
@@ -504,15 +504,22 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f, cls_flower.stats.used_hw_stats_valid); } -static void __fl_put (struct cls_fl_filter *f) +static bool __fl_put (struct tcf_proto *tp,struct cls_fl_filter *f) { +bool last = false; +if (!refcount_dec_and_test (&f->refcnt)) -return ; +return false; + +if (f->mask) + last =fl_mask_put (fl_head_dereference (tp), f->mask);if (tcf_exts_get_net (&f->exts))tcf_queue_work (&f->rwork, fl_destroy_filter_work);else __fl_destroy_filter (f); + +return last; }static struct cls_fl_filter *__fl_get (struct cls_fl_head *head,u32 handle)
@@ -549,11 +556,10 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,list_del_rcu (&f->list);spin_unlock (&tp->lock); - *last =fl_mask_put (head, f->mask);if (!tc_skip_hw (f->flags))fl_hw_destroy_filter (tp, f, rtnl_held, extack);tcf_unbind_filter (tp, &f->res); -__fl_put (f); + *last =__fl_put (tp, f);return 0 ; }
@@ -594,7 +600,7 @@ static void fl_put(struct tcf_proto *tp, void *arg) {struct cls_fl_filter *f = arg; -__fl_put (f); +__fl_put (tp, f); }static void *fl_get (struct tcf_proto *tp,u32 handle)
@@ -2063,12 +2069,14 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout; err =fl_check_assign_mask (head, fnew, fold, mask); -if (err) +if (err) { + fnew->mask =NULL ; goto errout; + } err =fl_ht_insert_unique (fnew, fold, &in_ht);if (err) - goto errout_mask; + goto errout;if (!tc_skip_hw (fnew->flags)) { err =fl_hw_replace_filter (tp, fnew, rtnl_held, extack);
@@ -2120,7 +2128,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,spin_unlock (&tp->lock); -fl_mask_put (head, fold->mask);if (!tc_skip_hw (fold->flags))fl_hw_destroy_filter (tp, fold, rtnl_held,NULL );tcf_unbind_filter (tp, &fold->res);
@@ -2128,7 +2135,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,* after this. */ refcount_dec (&fold->refcnt); -__fl_put (fold); +__fl_put (tp, fold); }else {if (handle) {/* user specifies a handle and it doesn't exist */
@@ -2173,17 +2180,15 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,if (in_ht)rhashtable_remove_fast (&fnew->mask->ht, &fnew->ht_node, fnew->mask->filter_ht_params); -errout_mask: -fl_mask_put (head, fnew->mask); errout: -__fl_put (fnew); +__fl_put (tp, fnew); errout_tb:kfree (tb); errout_mask_alloc:tcf_queue_work (&mask->rwork, fl_uninit_mask_free_work); errout_fold:if (fold) -__fl_put (fold); +__fl_put (tp, fold);return err; }
@@ -2196,8 +2201,10 @@ static int fl_delete(struct tcf_proto *tp, void *arg, bool *last,int err =0 ; err =__fl_delete (tp, f, &last_on_mask, rtnl_held, extack); - *last =list_empty (&head->masks); -__fl_put (f); +spin_lock (&tp->lock); + *last =idr_is_empty (&head->handle_idr); +spin_unlock (&tp->lock); +__fl_put (tp, f);return err; }
@@ -2219,12 +2226,12 @@ static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg,rcu_read_unlock ();if (arg->fn (tp, f, arg) <0 ) { -__fl_put (f); +__fl_put (tp, f); arg->stop =1 ;rcu_read_lock ();break ; } -__fl_put (f); +__fl_put (tp, f); arg->count++;rcu_read_lock (); }
@@ -2275,7 +2282,7 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, cls_flower.rule =flow_rule_alloc (tcf_exts_num_actions (&f->exts));if (!cls_flower.rule) { -__fl_put (f); +__fl_put (tp, f);return -ENOMEM ; }
@@ -2293,7 +2300,7 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb,kfree (cls_flower.rule);if (tc_skip_sw (f->flags)) {NL_SET_ERR_MSG_MOD (extack,"Failed to setup flow action" ); -__fl_put (f); +__fl_put (tp, f);return err; } goto next_flow;
@@ -2309,11 +2316,11 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb,kfree (cls_flower.rule);if (err) { -__fl_put (f); +__fl_put (tp, f);return err; } next_flow: -__fl_put (f); +__fl_put (tp, f); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/2214 ksmbd: fix overflow in dacloffset bounds check in build_sec_desc()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giorgi Kobakhia <[email protected]>
[ Upstream commit eb96e2a0e817807c48dc8387ca6a5249fdeae3a0 ]
When the large dacl_offset is provided, dacl_offset + sizeof(struct smb_acl) overflows on 32-bit builds and the check is passed, Which makes le16_to_cpu(ppdacl_ptr->size) read out-of-bounds. This only happens for dacl_offset in range [0xFFFFFFF8, 0xFFFFFFFF]. So the oob read is max 8 bytes preceding the allocated ppntsd.
unsigned int dacl_offset = le32_to_cpu(ppntsd->dacloffset);
int ppdacl_size, ntacl_size = ppntsd_size - dacl_offset;
if (!dacl_offset ||
(dacl_offset + sizeof(struct smb_acl) > ppntsd_size))
goto out;Commit beff0bc9d69b ("ksmbd: fix overflow in dacloffset bounds check") fixes similar checks in other functions. But leaves this one out, because it is only valid for 32-bit builds.
Reproduced on 32-bit ARM with KASAN, by a client sending SMB2 SET_INFO(SEC) with dacloffset=0xfffffff8, then QUERY_INFO(SEC) on the same file:
BUG: KASAN: slab-out-of-bounds in build_sec_desc (fs/smb/server/smbacl.c:1105) Read of size 2 at addr c2a273fa by task kworker/1:1/35 CPU: 1 UID: 0 PID: 35 Comm: kworker/1:1 Not tainted 7.3.0-rc2+ #5 Workqueue: ksmbd-io handle_ksmbd_work Call trace: kasan_check_range from build_sec_desc (fs/smb/server/smbacl.c:1105) build_sec_desc from smb2_query_info (fs/smb/server/smb2pdu.c:7676) smb2_query_info from handle_ksmbd_work (fs/smb/server/server.c:160) handle_ksmbd_work from process_one_work (kernel/workqueue.c:3401) process_one_work from worker_thread (kernel/workqueue.c:3473) worker_thread from kthread (kernel/kthread.c:436)
Add overflow check.
--- fs/ksmbd/smbacl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ksmbd/smbacl.c +4 -1
@@ -984,9 +984,12 @@ int build_sec_desc(struct user_namespace *user_ns,struct smb_acl *ppdacl_ptr;unsigned int dacl_offset =le32_to_cpu (ppntsd->dacloffset);int ppdacl_size, ntacl_size = ppntsd_size - dacl_offset; +size_t dacl_struct_end;if (!dacl_offset || - (dacl_offset +sizeof (struct smb_acl ) > ppntsd_size)) +check_add_overflow (dacl_offset,sizeof (struct smb_acl ), + &dacl_struct_end) || + dacl_struct_end > (size_t )ppntsd_size) goto out; ppdacl_ptr = (struct smb_acl *)((char *)ppntsd + dacl_offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/2214 ksmbd: reserve space for the UTF-16 terminator in stream info
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdifatah Suruur <[email protected]>
[ Upstream commit a025c4991a7d83edc4dd339e3ea86d8ff6226eca ]
smb_strtoUTF16() always writes a terminating zero UTF-16 unit after the converted characters, but get_file_stream_info() budgets only sizeof(struct smb2_file_stream_info) + streamlen * 2 for a stream entry and sizeof(struct smb2_file_stream_info) + 7 * 2 for the trailing "::$DATA" entry. When an entry exactly fills the 448-byte small response buffer, the terminator is written two bytes past the allocation.
Reserve one extra UTF-16 unit in both budget checks. The terminator is not part of the wire format, so the reported lengths are unchanged.
--- fs/ksmbd/smb2pdu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ksmbd/smb2pdu.c +3 -2
@@ -4773,7 +4773,8 @@ static void get_file_stream_info(struct ksmbd_work *work, ":%s", &stream_name[XATTR_NAME_STREAM_LEN]); next =sizeof (struct smb2_file_stream_info ) + streamlen *2 ; -if (next > buf_free_len) { +/* smbConvertToUTF16() also writes a terminating UTF-16 unit. */ +if (next +sizeof (__le16) > buf_free_len) {kfree (stream_buf);break ; }
@@ -4795,7 +4796,7 @@ static void get_file_stream_info(struct ksmbd_work *work, out:if (!S_ISDIR (stat.mode) && - buf_free_len >=sizeof (struct smb2_file_stream_info ) +7 *2 ) { + buf_free_len >=sizeof (struct smb2_file_stream_info ) + (7 +1 ) *2 ) { file_info = (struct smb2_file_stream_info *) &rsp->Buffer[nbytes]; streamlen = smbConvertToUTF16((__le16 *)file_info->StreamName,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/2214 ksmbd: prevent stale data from being written by SMB2 WRITE requests
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit bc0e0f5ac1d7b044d403f859406b4b66d4b1ce9b ]
Initialize the compatibility byte in request buffers without zeroing the entire allocation. Keep the one-byte compatibility exception for SMB2 messages so valid zero-length WRITE requests remain compatible, and validate the data range in the WRITE handlers against the current compound request before accessing it.
This prevents stale request-buffer data from being written to files or sent to IPC pipes.
--- fs/ksmbd/connection.c | 1 + fs/ksmbd/smb2pdu.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-)
fs/ksmbd/connection.c +1 -0
@@ -399,6 +399,7 @@ int ksmbd_conn_handler_loop(void *p)if (!conn->request_buf)break ; + conn->request_buf[pdu_size +4 ] =0 ;memcpy (conn->request_buf, hdr_buf,sizeof (hdr_buf));/*
fs/ksmbd/smb2pdu.c +25 -9
@@ -6553,23 +6553,28 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work)int err =0 , ret =0 ;char *data_buf;size_t length; +unsigned int data_offset, req_len;WORK_BUFFERS (work, req, rsp); length =le32_to_cpu (req->Length); id = req->VolatileFileId; + data_offset =le16_to_cpu (req->DataOffset); + req_len =le32_to_cpu (req->hdr.NextCommand); +if (!req_len) + req_len =get_rfc1002_len (work->request_buf) - + work->next_smb2_rcv_hdr_off; -if ((u64 )le16_to_cpu (req->DataOffset) + length > -get_rfc1002_len (work->request_buf)) { -pr_err ("invalid write data offset %u, smb_len %u\n" , -le16_to_cpu (req->DataOffset), -get_rfc1002_len (work->request_buf)); +if (data_offset < offsetof(struct smb2_write_req , Buffer) || + data_offset > req_len || length > req_len - data_offset) { +pr_err ("invalid write data offset %u, length %zu, req_len %u\n" , + data_offset, length, req_len); err = -EINVAL ; goto out; } data_buf = (char *)(((char *)&req->hdr.ProtocolId) + -le16_to_cpu (req->DataOffset)); + data_offset); rpc_resp =ksmbd_rpc_write (work->sess, id, data_buf, length);if (rpc_resp) {
@@ -6720,14 +6725,25 @@ int smb2_write(struct ksmbd_work *work) writethrough = true;if (is_rdma_channel == false) { -if (le16_to_cpu (req->DataOffset) < - offsetof(struct smb2_write_req , Buffer)) { +unsigned int data_offset =le16_to_cpu (req->DataOffset); +unsigned int req_len =le32_to_cpu (req->hdr.NextCommand); + +if (!req_len) + req_len =get_rfc1002_len (work->request_buf) - + work->next_smb2_rcv_hdr_off; + +if (data_offset < offsetof(struct smb2_write_req , Buffer) || + data_offset > req_len || + length > req_len - data_offset) { +ksmbd_debug (SMB , +"invalid write data offset %u, length %zu, req_len %u\n" , + data_offset, length, req_len); err = -EINVAL ; goto out; } data_buf = (char *)(((char *)&req->hdr.ProtocolId) + -le16_to_cpu (req->DataOffset)); + data_offset);ksmbd_debug (SMB ,"filename %pD, offset %lld, len %zu\n" , fp->filp, offset, length);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/2214 ksmbd: prevent share root removal through empty paths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 9fd1fcbbf84986a7bcf601a2b90540899069d263 ]
A FileLinkInformation request can supply "/" as the new link name. smb2_get_name() strips the trailing slash and passes an empty string to ksmbd_vfs_kern_path_start_removing().
ksmbd_vfs_path_lookup() resolves an empty pathname as the configured share path, without LOOKUP_BENEATH. With ReplaceIfExists set, smb2_create_link() can therefore remove the share root from its parent before link creation fails. An authenticated client with a writable share and DELETE access to a file can trigger this if the share root is empty and the mapped user has write and search permission on its parent directory.
Return -EINVAL for empty pathnames when for_remove is set, before resolving the share path or acquiring removal resources. Ordinary lookups continue to accept empty pathnames for opening the share root.
--- fs/ksmbd/smb2pdu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -1
@@ -5712,7 +5712,8 @@ static int smb2_create_link(struct ksmbd_work *work, link_name =smb2_get_name (file_info->FileName,le32_to_cpu (file_info->FileNameLength), local_nls); -if (IS_ERR (link_name) ||S_ISDIR (file_inode (filp)->i_mode)) { +if (IS_ERR (link_name) || link_name[0 ] =='\0' || +S_ISDIR (file_inode (filp)->i_mode)) { rc = -EINVAL ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/2214 ksmbd: fix out-of-bounds read when padding the final compound response
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 714f27729121d59f103ca4dad7b0c2d1c125cd71 ]
Compound response handling pads the last response of a compound to an 8-byte boundary by growing the final iov and the RFC1002 length. smb2_allocate_rsp_buf() allocates exactly response_sz. A command can fill the response buffer to within 7 bytes of its end, for example a QUERY_INFO whose output is bounded only by the space left. The padding can then run past the allocation, and ksmbd_tcp_writev() reads those bytes when it sends the response.
BUG: KASAN: slab-out-of-bounds in _copy_from_iter+0x744/0x10e0 Call Trace: _copy_from_iter+0x744/0x10e0 tcp_sendmsg_locked+0x2290/0x3f80 ksmbd_tcp_writev+0x10c7/0x1ab0 [ksmbd]
Allocate room for the padding when the request is a compound, as smb2_read() and smb2_read_pipe() do for their payloads. response_sz is unchanged, so commands still fill only up to it, and kvzalloc() zeroes the padding.
--- fs/ksmbd/smb2pdu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/ksmbd/smb2pdu.c +10 -3
@@ -532,7 +532,7 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work)struct smb2_hdr *hdr =smb_get_msg (work->request_buf);size_t small_sz =MAX_CIFS_SMALL_BUFFER_SIZE ;size_t large_sz = small_sz + work->conn->vals->max_trans_size; -size_t sz = small_sz; +size_t sz = small_sz, pad_sz =0 ;int cmd =le16_to_cpu (hdr->Command);if (cmd ==SMB2_IOCTL_HE || cmd ==SMB2_QUERY_DIRECTORY_HE )
@@ -554,10 +554,17 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work) }/* allocate large response buf for chained commands */ -if (le32_to_cpu (hdr->NextCommand) >0 ) +if (le32_to_cpu (hdr->NextCommand) >0 ) { sz = large_sz; +/* +* is_chained_smb2_message() pads the last response of a +* compound to 8 bytes, which can take it past response_sz. +* Leave room for the padding. kvzalloc() zeroes it. +*/ + pad_sz =ALIGN (sz -sizeof (__be32),8 ) - (sz -sizeof (__be32)); + } - work->response_buf =kvzalloc (sz,GFP_KERNEL ); + work->response_buf =kvzalloc (sz + pad_sz,GFP_KERNEL );if (!work->response_buf)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/2214 ksmbd: verify transform SessionId matches the decrypted header
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dairui Zhang <[email protected]>
[ Upstream commit 798214e6fafcdcc29f5ba2661a473232b5e70cfb ]
When an encrypted request comes in, the decryption key is picked by the SessionId in the transform header, but the request is then authorized under whatever session the decrypted inner header names. Nothing ever compares the two, so on a connection with more than one session a client can get a request decrypted with one session's key and run it as another session. Encrypted requests are exempt from signing too, so a valid AEAD tag is the only proof of session identity, and it is checked against the wrong session.
MS-SMB2 says the server must check that the transform SessionId matches the one in the decrypted SMB2 header and treat a mismatch as a protocol error. Add that check in __handle_ksmbd_work() after decryption, before dispatching: the message has to be at least one fixed SMB2 header, the first operation must not set SMB2_FLAGS_RELATED_OPERATIONS and its SessionId must match the transform SessionId, and every following non-related operation in a compound chain must carry the same SessionId. NextCommand offsets must be 8-byte aligned and stay inside the message; the bounds check is done by subtraction so it cannot wrap.
When the decrypted payload is a compression transform, the existing decompression step runs first and the decompressed SMB2 message is checked instead, since a compression transform header carries no SessionId.
--- fs/ksmbd/server.c | 16 ++++++++++++++ fs/ksmbd/smb2pdu.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ksmbd/smb2pdu.h | 1 + 3 files changed, 71 insertions(+)
fs/ksmbd/server.c +16 -0
@@ -169,10 +169,26 @@ static void __handle_ksmbd_work(struct ksmbd_work *work,if (conn->ops->is_transform_hdr && conn->ops->is_transform_hdr (work->request_buf)) { +u64 tr_sess_id; + +if (get_rfc1002_len (work->request_buf) < +sizeof (struct smb2_transform_hdr )) { +ksmbd_conn_set_exiting (conn); +return ; + } + tr_sess_id =le64_to_cpu (((struct smb2_transform_hdr *) +smb_get_msg (work->request_buf))->SessionId); + rc = conn->ops->decrypt_req (work);if (rc <0 )return ; work->encrypted = true; + + rc =ksmbd_check_transform_session (work, tr_sess_id); +if (rc <0 ) { +ksmbd_conn_set_exiting (conn); +return ; + } }if (conn->ops->allocate_rsp_buf (work))
fs/ksmbd/smb2pdu.c +54 -0
60 lines not on this page · raw message
fs/ksmbd/smb2pdu.h +1 -0
@@ -1674,6 +1674,7 @@ struct channel *lookup_chann_list(struct ksmbd_session *sess,void smb3_preauth_hash_rsp (struct ksmbd_work *work);bool smb3_is_transform_hdr (void *buf);int smb3_decrypt_req (struct ksmbd_work *work); +int ksmbd_check_transform_session (struct ksmbd_work *work,u64 tr_sess_id);int smb3_encrypt_resp (struct ksmbd_work *work);bool smb3_11_final_sess_setup_resp (struct ksmbd_work *work);int smb2_set_rsp_credits (struct ksmbd_work *work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/2214 KVM: VMX: Preserve negative return value in vmx_handle_exit() with bus lock detected
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiaoyao Li <[email protected]>
[ Upstream commit cef48693da1e964e9f192bfc16cd0ed287c48337 ]
Preserve the negative return value from __vmx_handle_exit() when a bus lock is detected, instead of always overwriting it with 0.
The purpose of bus_lock_detected handling is to force a userspace exit to inform userspace that a bus lock happened. The negative return value can achieve this purpose, and changing the negative value to 0 fails to return an error to userspace. So, preserve the negative return value.
--- arch/x86/kvm/vmx/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/vmx.c +3 -2
@@ -6192,11 +6192,12 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)* a bus lock in guest. */ if (to_vmx (vcpu)->exit_reason.bus_lock_detected) { -if (ret >0 ) +if (ret >0 ) { vcpu->run->exit_reason =KVM_EXIT_X86_BUS_LOCK ; + ret =0 ; + } vcpu->run->flags |=KVM_RUN_X86_BUS_LOCK ; -return 0 ; }return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/2214 ksmbd: fix extended session security negotiation for raw NTLMSSP
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 6868f857514bbfd2ed10b9b566664dc4a8ca039d ]
ksmbd_build_ntlmssp_challenge_blob() only advertises extended session security when conn->use_spnego is true. As a result, raw NTLMSSP negotiation drops NTLMSSP_NEGOTIATE_EXTENDED_SEC from the challenge even when the client requested it.
A Windows capture shows an initial SPNEGO authentication succeeding, followed by a raw NTLMSSP negotiation on the same TCP connection. The raw challenge omits extended session security, and the client does not send an AUTHENTICATE message. The unfinished session then occupies the pending session slot, causing subsequent SESSION_SETUP requests to fail with STATUS_INSUFFICIENT_RESOURCES.
Set NTLMSSP_NEGOTIATE_EXTENDED_SEC whenever the client requests it, independently of the SPNEGO wrapper, as required by [MS-NLMP].
--- fs/ksmbd/auth.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ksmbd/auth.c +1 -2
@@ -442,8 +442,7 @@ ksmbd_build_ntlmssp_challenge_blob(struct challenge_message *chgblob,if (cflags &NTLMSSP_REQUEST_TARGET ) flags |=NTLMSSP_REQUEST_TARGET ; -if (conn->use_spnego && - (cflags &NTLMSSP_NEGOTIATE_EXTENDED_SEC )) +if (cflags &NTLMSSP_NEGOTIATE_EXTENDED_SEC ) flags |=NTLMSSP_NEGOTIATE_EXTENDED_SEC ;if (cflags &NTLMSSP_NEGOTIATE_KEY_XCH )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/2214 ksmbd: avoid restoring only in-memory EOF after allocation change
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit 9455e920aebe41217cabff3f81e90da4c407fdb6 ]
When SetAllocation requests a size below the allocated block count but above EOF, ksmbd truncates the file to that size and restores only the in-memory i_size. The larger EOF remains on disk and reappears after a reboot. A 3-byte file preallocated to 64 KiB can acquire a 4 KiB EOF after reducing its allocation to 4 KiB. Extending EOF this way is not a reliable way to reclaim the preallocation beyond the old EOF either.
Only use this truncate path when the requested allocation is at or below the observed EOF. A truncate to the existing EOF still lets filesystems release preallocated blocks beyond EOF. Remove the in-memory-only i_size restoration. The size check still precedes vfs_truncate() taking the inode lock, so a concurrent shrink can make the truncate extend EOF; that race also existed in the original path.
--- fs/ksmbd/smb2pdu.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
fs/ksmbd/smb2pdu.c +4 -11
@@ -5896,24 +5896,17 @@ static int set_file_allocation_info(struct ksmbd_work *work,pr_err ("vfs_fallocate is failed : %d\n" , rc);return rc; } - }else if (alloc_blks < stat.blocks) { -loff_t size; - + }else if (alloc_blks < stat.blocks && + alloc_blks *512 <=i_size_read (inode)) {/* -* Allocation size could be smaller than original one -* which means allocated blocks in file should be -* deallocated. use truncate to cut out it, but inode -* size is also updated with truncate offset. -* inode size is retained by backup inode size. +* Truncate at or below EOF to discard excess allocation. +* Truncating above EOF would extend the file on disk. */ - size =i_size_read (inode); rc =ksmbd_vfs_truncate (work, fp, alloc_blks *512 );if (rc) {pr_err ("truncate failed!, err %d\n" , rc);return rc; } -if (size < alloc_blks *512 ) -i_size_write (inode, size); }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/2214 backlight: lm3630a_bl: Remove redundant flush_workqueue() calls
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Wang <[email protected]>
[ Upstream commit adc122011125682932ef279d717153670feedde4 ]
'destroy_workqueue()' already drains the queue before destroying it, so there is no need to flush it explicitly.
Remove the redundant 'flush_workqueue()' calls.
Stable-dep-of: 2cf184caab8b ("backlight: lm3630a: Cancel delayed work before destroying workqueue")
--- drivers/video/backlight/lm3630a_bl.c | 1 - 1 file changed, 1 deletion(-)
drivers/video/backlight/lm3630a_bl.c +0 -1
@@ -589,7 +589,6 @@ static int lm3630a_remove(struct i2c_client *client)if (pchip->irq) {free_irq (pchip->irq, pchip); -flush_workqueue (pchip->irqthread);destroy_workqueue (pchip->irqthread); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/2214 backlight: lm3630a: Cancel delayed work before destroying workqueue
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 2cf184caab8b406fdd9db126ee40d62418237456 ]
The interrupt handler queues delayed work to read the interrupt status. After free_irq() stops the producer, this work can still be waiting on its timer. destroy_workqueue() cannot drain delayed work that has not yet been queued by its timer, so the timer can outlive both the workqueue and the devm-allocated chip containing the work.
Cancel the delayed work synchronously after freeing the IRQ and before destroying the workqueue. This also waits for any running status read to finish before the chip's resources are released.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/video/backlight/lm3630a_bl.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/backlight/lm3630a_bl.c +1 -0
@@ -589,6 +589,7 @@ static int lm3630a_remove(struct i2c_client *client)if (pchip->irq) {free_irq (pchip->irq, pchip); +cancel_delayed_work_sync (&pchip->work);destroy_workqueue (pchip->irqthread); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/2214 ksmbd: preserve unreadable named streams on open
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit 80c816c047f7cae3c99cc75740c1f5d2c4d97b45 ]
A write-only client can open an existing named stream with FILE_OPEN_IF without permission to read the underlying file. The case-insensitive lookup finds the xattr name, but querying its value length then fails with -EACCES. smb2_set_stream_name_xattr() treats every negative result as a missing stream and replaces the existing xattr with an empty value.
A failed xattr list is not proof that the stream is absent either:
for example, -ENOMEM can lead to the same empty replacement. Preserve listing errors and create a stream only for -ENOENT or -ENODATA. The latter can occur if the xattr is removed between listing its name and querying its value. Return other lookup errors without changing the stream.
A write-only FILE_OPEN now reports access denied instead of name not found. FILE_OVERWRITE_IF and FILE_SUPERSEDE on an unreadable stream also fail instead of appearing to replace it. Stream writes and EOF changes already need to read the old value, so such handles cannot update the stream after opening either.
--- fs/ksmbd/smb2pdu.c | 2 ++ fs/ksmbd/vfs.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +2 -0
@@ -2519,6 +2519,8 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, xattr_stream_size);if (rc >=0 )return 0 ; +if (rc != -ENOENT && rc != -ENODATA ) +return rc;if (fp->cdoption ==FILE_OPEN_LE ) {ksmbd_debug (SMB ,"XATTR stream name lookup failed: %d\n" , rc);
fs/ksmbd/vfs.c +5 -1
@@ -1713,7 +1713,11 @@ ssize_t ksmbd_vfs_casexattr_len(struct user_namespace *user_ns,ssize_t value_len = -ENOENT , xattr_list_len; xattr_list_len =ksmbd_vfs_listxattr (dentry, &xattr_list); -if (xattr_list_len <=0 ) +if (xattr_list_len <0 ) { + value_len = xattr_list_len; + goto out; + } +if (!xattr_list_len) goto out; for (name = xattr_list; name - xattr_list < xattr_list_len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/2214 ksmbd: return end of file for reads past a named streams data
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit 626611dc22a3b63b3264a7a797d9dbc530234fcd ]
A READ on a non-empty named stream at or beyond its end fails with STATUS_INVALID_PARAMETER. ksmbd_vfs_stream_read() returns -EINVAL when the offset is not below the stream length, and smb2_read() maps -EINVAL to that status.
smb2_read() already turns a zero-byte read into STATUS_END_OF_FILE, the status a regular file returns at its end, and an empty stream already takes that path. Return 0 instead of -EINVAL so that non-empty streams do the same. Clients that read a stream until end of file otherwise get an error once they have read all of its data.
The buffered copychunk path converts a zero-byte source read to -EIO, as it does for a regular file that shrinks during copying.
--- fs/ksmbd/vfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/vfs.c +1 -1
@@ -299,7 +299,7 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos,return (int )v_len;if (v_len <= *pos) { - count = -EINVAL ; + count =0 ; goto free_buf; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/2214 ksmbd: fix session reference leak on compounded SESSION_SETUP
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 03bd8f5279e490e15e0c0f0fa388ffbd2fbacd65 ]
A compound request can place SESSION_SETUP after another command. That earlier command leaves a reference to its session in work->sess. smb2_sess_setup() then overwrites work->sess with the session it looks up or creates, and the dispatcher later puts work->sess only once. The inherited reference is never dropped. That leaks the session, together with its setup connection and socket, and every repeat of the compound leaks another.
unreferenced object (size 512):
__kmalloc_cache_noprof+0x32c/0x3a0
ksmbd_smb2_session_create+0xf6/0x9c0 [ksmbd]
smb2_sess_setup+0xda4/0x6280 [ksmbd]
handle_ksmbd_work+0x88c/0x1cb0 [ksmbd]Save the inherited session on entry. After the request has been processed, release it once, but only when smb2_sess_setup() has replaced work->sess with its own session or cleared it. Do this after ksmbd_conn_unlock() so the put does not run under srv_mutex. An error path may instead leave the inherited session in work->sess. Keep it there, so the dispatcher still puts it and the error response is still signed or encrypted with it as before.
--- fs/ksmbd/smb2pdu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/ksmbd/smb2pdu.c +11 -0
@@ -1710,6 +1710,8 @@ int smb2_sess_setup(struct ksmbd_work *work)struct smb2_sess_setup_req *req;struct smb2_sess_setup_rsp *rsp;struct ksmbd_session *sess; +struct ksmbd_session *prev_sess = work->sess; +bool installed = false;struct negotiate_message *negblob;unsigned int negblob_len, negblob_off;int rc =0 ;
@@ -1826,6 +1828,7 @@ int smb2_sess_setup(struct ksmbd_work *work) conn->binding = false; } work->sess = sess; + installed = true; negblob_off =le16_to_cpu (req->SecurityBufferOffset); negblob_len =le16_to_cpu (req->SecurityBufferLength);
@@ -1983,6 +1986,14 @@ int smb2_sess_setup(struct ksmbd_work *work) }ksmbd_conn_unlock (conn); + +/* +* Later in a compound, work->sess holds the reference that an +* earlier command took. Drop it once this request has installed +* its own session there or cleared it. +*/ +if (prev_sess && (installed || !work->sess)) +ksmbd_user_session_put (prev_sess);return rc; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/2214 ksmbd: ignore network devices of other namespaces
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Koester <[email protected]>
[ Upstream commit 1f5ce2b8b9164b3fcb93a18fe1e7b451c2fc6eea ]
With no interface list configured, ksmbd binds every interface that comes up. ksmbd_netdev_event() does not look at the device's namespace, and create_socket() opens the listener in the namespace of the task raising NETDEV_UP. A container with its own address on a bridge brings up its interface and finds port 445 in its namespace already taken by ksmbd, so an SMB server running inside the container fails with "Address already in use".
Interfaces are also matched by name only, so a container's eth0 going down would stop the listener on the host's eth0.
Only handle netdev events for devices in init_net.
--- fs/ksmbd/transport_tcp.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ksmbd/transport_tcp.c +9 -0
@@ -514,6 +514,15 @@ static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,struct interface *iface;int ret, found =0 ; +/* +* ksmbd serves the initial namespace only. create_socket() listens in +* the namespace of the task raising the event, so a container bringing +* up its own interface would get a listener on its port 445, and the +* name-only interface lookup would let its interfaces stop ours. +*/ +if (!net_eq (dev_net (netdev), &init_net)) +return NOTIFY_DONE ; +switch (event) {case NETDEV_UP :if (netif_is_bridge_port (netdev))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/2214 ksmbd: fix invalid pointer dereference when get_inode_acl() fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Hu <[email protected]>
[ Upstream commit 19d180c7baab7126af5848ed87d5f7b5add0cef2 ]
When get_inode_acl() fails, it returns an ERR_PTR(), but ksmbd_acls_fattr() stored that pointer in smb_fattr without checking for errors. Later callers then passed the error pointer to security descriptor helpers or posix_acl_release(), resulting in an invalid pointer dereference.
This was reproduced on an XFS-backed share when xfs_get_acl() returned ERR_PTR(-ENOMEM). Querying the SMB ACL from a CIFS client triggered the crash:
BUG: unable to handle page fault for address: fffffffffffffff8 RIP: smb_acl_sec_desc_scratch_len+0x58/0x90 [ksmbd] Call Trace: smb2_query_info+0x40d/0x17c0 [ksmbd] handle_ksmbd_work+0x1ca/0x770 [ksmbd]
Fix this by checking the return values from get_inode_acl() in ksmbd_acls_fattr(). Treat -EOPNOTSUPP as indicating that no ACL is available, and propagate all other errors to the callers. Update smb2_open() and smb2_get_info_sec() to handle these errors.
--- fs/ksmbd/smb2pdu.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-)
fs/ksmbd/smb2pdu.c +35 -8
@@ -2706,10 +2706,12 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work, le32_to_cpu(sd_buf->ccontext.DataLength), true, false); } -static void ksmbd_acls_fattr (struct smb_fattr *fattr, -struct user_namespace *mnt_userns, -struct inode *inode) +static int ksmbd_acls_fattr (struct smb_fattr *fattr, +struct user_namespace *mnt_userns, +struct inode *inode) { +struct posix_acl *acl; + fattr->cf_uid =i_uid_into_mnt (mnt_userns, inode); fattr->cf_gid =i_gid_into_mnt (mnt_userns, inode); fattr->cf_mode = inode->i_mode;
@@ -2717,10 +2719,28 @@ static void ksmbd_acls_fattr(struct smb_fattr *fattr, fattr->cf_dacls =NULL ;if (IS_ENABLED (CONFIG_FS_POSIX_ACL )) { - fattr->cf_acls =get_acl (inode,ACL_TYPE_ACCESS ); -if (S_ISDIR (inode->i_mode)) - fattr->cf_dacls =get_acl (inode,ACL_TYPE_DEFAULT ); + acl =get_acl (inode,ACL_TYPE_ACCESS ); +if (IS_ERR (acl)) { +if (acl !=ERR_PTR (-EOPNOTSUPP )) +return PTR_ERR (acl); + acl =NULL ; + } + fattr->cf_acls = acl; + +if (S_ISDIR (inode->i_mode)) { + acl =get_acl (inode,ACL_TYPE_DEFAULT ); +if (IS_ERR (acl)) { +if (acl !=ERR_PTR (-EOPNOTSUPP )) { +posix_acl_release (fattr->cf_acls); +return PTR_ERR (acl); + } + acl =NULL ; + } + fattr->cf_dacls = acl; + } } + +return 0 ; }/**
@@ -3209,7 +3229,10 @@ int smb2_open(struct ksmbd_work *work)struct smb_ntsd *pntsd;int pntsd_size, ace_num =0 ; -ksmbd_acls_fattr (&fattr, user_ns, inode); + rc =ksmbd_acls_fattr (&fattr, user_ns, inode); +if (rc) + goto err_out; +if (fattr.cf_acls) ace_num = fattr.cf_acls->a_count;if (fattr.cf_dacls)
@@ -5387,7 +5410,11 @@ static int smb2_get_info_sec(struct ksmbd_work *work, user_ns =file_mnt_user_ns (fp->filp); inode =file_inode (fp->filp); -ksmbd_acls_fattr (&fattr, user_ns, inode); + rc =ksmbd_acls_fattr (&fattr, user_ns, inode); +if (rc) { +ksmbd_fd_put (work, fp); +return rc; + }if (test_share_config_flag (work->tcon->share_conf,KSMBD_SHARE_FLAG_ACL_XATTR ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/2214 ksmbd: fix named stream write and EOF handling
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit 02165c8d402392278a5cd2cf97645ed73a7ad4a1 ]
An SMB WRITE to an existing named stream can silently discard data after its written range. ksmbd stores streams as xattr values, but the write path passes offset + count as the length of the replacement xattr even when the old stream is longer. Writing 26 bytes at offset 0 to a 60-byte stream reports 26 bytes written while discarding the remaining 34 bytes.
Keep the existing xattr length when an in-place write ends before EOF. Reject writes that cross XATTR_SIZE_MAX rather than storing only the portion that fits while reporting the full requested count.
Commit 4ea0bb8aaedf ("ksmbd: handle set/get info file for streamed file") intentionally skipped ordinary inode truncation for stream handles: an EOF SetInfo on an ADS had truncated the base file. That fixed the base file corruption but left stream EOF changes reporting success without resizing the stream. Handle these requests by resizing only the stream xattr; the base file size remains untouched. Zero-fill stream extensions. This is needed alongside the write fix: a short write's accidental truncation previously masked an ignored explicit EOF change. The stream resize helper returns xattr errors directly rather than using the base-file truncate path's EBADF conversion.
--- fs/ksmbd/smb2pdu.c | 2 ++ fs/ksmbd/vfs.c | 71 ++++++++++++++++++++++++++++++++++++++++++---- fs/ksmbd/vfs.h | 1 + 3 files changed, 69 insertions(+), 5 deletions(-)
fs/ksmbd/smb2pdu.c +2 -0
@@ -5963,6 +5963,8 @@ static int set_end_of_file_info(struct ksmbd_work *work, struct ksmbd_file *fp, newsize =le64_to_cpu (file_eof_info->EndOfFile); inode =file_inode (fp->filp); +if (ksmbd_stream_fd (fp)) +return ksmbd_vfs_stream_truncate (fp, newsize);/* * If FILE_END_OF_FILE_INFORMATION of set_info_file is called
fs/ksmbd/vfs.c +66 -5
97 lines not on this page · raw message
fs/ksmbd/vfs.h +1 -0
@@ -120,6 +120,7 @@ int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count,int ksmbd_vfs_write (struct ksmbd_work *work,struct ksmbd_file *fp,char *buf,size_t count,loff_t *pos,bool sync,ssize_t *written); +int ksmbd_vfs_stream_truncate (struct ksmbd_file *fp,loff_t newsize);int ksmbd_vfs_fsync (struct ksmbd_work *work,u64 fid,u64 p_id);int ksmbd_vfs_remove_file (struct ksmbd_work *work,const struct path *path); int ksmbd_vfs_link(struct ksmbd_work *work,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/2214 driver core: Limit the messages on a refused uevent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit a01c8e5b1dff1ce489e6b339139e744db36b8bb3 ]
A write to a "uevent" file which is no valid action makes kobject_synth_uevent() print a warning and uevent_store() an error every time. This is generally considered a bad thing so rate limit these messages.
--- drivers/base/core.c | 4 +++- lib/kobject_uevent.c | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/base/core.c +3 -1
@@ -2428,7 +2428,9 @@ static ssize_t uevent_store(struct device *dev, struct device_attribute *attr, rc =kobject_synth_uevent (&dev->kobj, buf, count);if (rc) { -dev_err (dev,"uevent: failed to send synthetic uevent\n" ); +dev_err_ratelimited (dev, +"uevent: failed to send synthetic uevent: %d\n" , + rc);return rc; }
lib/kobject_uevent.c +3 -3
@@ -224,9 +224,9 @@ int kobject_synth_uevent(struct kobject *kobj, const char *buf, size_t count) out:if (r) { devpath =kobject_get_path (kobj,GFP_KERNEL ); -pr_warn ("synth uevent: %s: %s\n" , - devpath ?:"unknown device" , - msg ?:"failed to send uevent" ); +pr_warn_ratelimited ("synth uevent: %s: %s\n" , + devpath ?:"unknown device" , + msg ?:"failed to send uevent" );kfree (devpath); }return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/2214 inet: reject unhashed sockets during established lookups
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunwoo Kim <[email protected]>
[ Upstream commit 4e2b3ef19e0e04adca38442f07dd6bc93c712bf1 ]
TCP established ehash lookups are lockless. The socket caches involved use SLAB_TYPESAFE_BY_RCU, so memory can be reused before an RCU reader that retained its old address has finished.
After a tuple match, __inet_lookup_established() and __inet6_lookup_established() acquire a reference and repeat the tuple check. They do not check whether the new object is hashed. If the address is reused for a socket with the same tuple, the lookup can acquire a reference to the new object and return it while its nulls node is unhashed.
A PoC that drives reuse with a SYN cookie request socket reproduced the crash. The new request socket is unhashed and has a NULL rsk_listener. A lookup that had loaded the address of the old request socket acquired the reference published by tcp_get_cookie_sock() and returned the new object. tcp_v4_rcv() then read sk_state through the NULL listener.
The resulting crash was:
BUG: kernel NULL pointer dereference, address: 0000000000000012 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page ... Oops: Oops: 0000 [#1] SMP NOPTI CPU: 4 UID: 0 PID: 0 Comm: swapper/4 Not tainted 7.3.0-00591-g0e135910deec #1 PREEMPT(lazy) ... RIP: 0010:tcp_v4_rcv+0x44e/0x1280 ... R10: 0000000000000001 R11: 00000000024ca8c0 R12: 0000000000000000 ... CR2: 0000000000000012 CR3: 0000000103d50004 CR4: 0000000000770ef0 ... Call Trace: <IRQ> ? raw_local_deliver+0xae/0x240 ip_protocol_deliver_rcu+0x2d/0x180 ip_local_deliver_finish+0x84/0x100 ip_sublist_rcv_finish+0x5f/0x70 ip_sublist_rcv+0x12a/0x1d0 ip_list_rcv+0xfd/0x130 __netif_receive_skb_list_core+0x223/0x250 netif_receive_skb_list_internal+0x1d2/0x2c0 ? try_fill_recv+0x39/0x7b0 napi_complete_done+0x74/0x170 virtnet_poll+0x445/0x600 __napi_poll+0x27/0x1e0 net_rx_action+0x2fe/0x3b0 handle_softirqs+0xc2/0x2c0 __irq_exit_rcu+0x74/0xd0 common_interrupt+0x7f/0x90 </IRQ> ... Kernel panic - not syncing: Fatal exception in interrupt
After taking a reference, check whether the nulls node is unhashed in both IPv4 and IPv6 established lookups. If it is unhashed or the tuple no longer matches, drop the reference and restart the lookup.
Lookups racing with the TIME_WAIT hashdance, or with a request being replaced by its child, now restart and find the new socket instead of returning the old one.
Request sockets that were never inserted into ehash can have a nonzero refcount, and a stale lookup can hold a transient reference. Therefore, when SYN cookie, Fast Open, and request migration paths fail after setting a nonzero refcount, release the references held by those paths with reqsk_put() instead of freeing the request directly.
[ Hyunwoo Kim: Keep the pre-rename INET_MATCH() function name used by
5.15.y. ]
--- net/ipv4/inet_connection_sock.c | 10 +++++++--- net/ipv4/inet_hashtables.c | 5 +++-- net/ipv4/syncookies.c | 2 ++ net/ipv4/tcp_input.c | 4 +++- net/ipv6/inet6_hashtables.c | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-)
net/ipv4/inet_connection_sock.c +7 -3
@@ -939,10 +939,14 @@ static void reqsk_timer_handler(struct timer_list *t)*/ if (nreq) {__NET_INC_STATS (net,LINUX_MIB_TCPMIGRATEREQFAILURE ); +/* The timer was not armed, drop its reference here. */ +reqsk_put (nreq); no_ownership:reqsk_migrate_reset (nreq);reqsk_queue_removed (queue, nreq); -__reqsk_free (nreq); +/* Drop the temporary reference and the one reserved for ehash. */ +reqsk_put (nreq); +reqsk_put (nreq); } drop:
@@ -1226,7 +1230,7 @@ struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMIGRATEREQFAILURE );reqsk_migrate_reset (nreq); -__reqsk_free (nreq); +reqsk_put (nreq); }else if (inet_csk_reqsk_queue_add (sk, req, child)) {return child; }
@@ -1282,7 +1286,7 @@ void inet_csk_listen_stop(struct sock *sk)__NET_INC_STATS (sock_net (nsk),LINUX_MIB_TCPMIGRATEREQFAILURE );reqsk_migrate_reset (nreq); -__reqsk_free (nreq); +reqsk_put (nreq); }rcu_read_unlock ();
net/ipv4/inet_hashtables.c +3 -2
@@ -383,8 +383,9 @@ struct sock *__inet_lookup_established(struct net *net,if (likely (INET_MATCH (net, sk, acookie, ports, dif, sdif))) {if (unlikely (!refcount_inc_not_zero (&sk->sk_refcnt))) goto out; -if (unlikely (!INET_MATCH (net, sk, acookie, - ports, dif, sdif))) { +if (unlikely (hlist_nulls_unhashed_lockless (&sk->sk_nulls_node) || + !INET_MATCH (net, sk, acookie, ports, dif, + sdif))) {sock_gen_put (sk); goto begin; }
net/ipv4/syncookies.c +2 -0
@@ -217,6 +217,8 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,bh_unlock_sock (child);sock_put (child); +reqsk_put (req); +return NULL ; }__reqsk_free (req);
net/ipv4/tcp_input.c +3 -1
@@ -7069,7 +7069,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,if (!inet_csk_reqsk_queue_add (sk, req, fastopen_sk)) {bh_unlock_sock (fastopen_sk);sock_put (fastopen_sk); - goto drop_and_free; +/* tcp_disconnect() already dropped one reqsk ref. */ +reqsk_put (req); + goto drop; } sk->sk_data_ready (sk);bh_unlock_sock (fastopen_sk);
net/ipv6/inet6_hashtables.c +3 -1
@@ -77,7 +77,9 @@ struct sock *__inet6_lookup_established(struct net *net,if (unlikely (!refcount_inc_not_zero (&sk->sk_refcnt))) goto out; -if (unlikely (!inet6_match (net, sk, saddr, daddr, ports, dif, sdif))) { +if (unlikely (hlist_nulls_unhashed_lockless (&sk->sk_nulls_node) || + !inet6_match (net, sk, saddr, daddr, ports, dif, + sdif))) {sock_gen_put (sk); goto begin; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/2214 smb: smbdirect: fix buffer length underflow in RDMA transfers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefan Metzmacher <[email protected]>
[ Upstream commit 7193241a49c958782ba4b8df06da3734d1e317d2 ]
When a remote buffer descriptor is larger than the remaining local buffer, smbdirect_connection_rdma_xmit() clamps its length and sets buf_len to zero. The common accounting code then subtracts the clamped length from buf_len, causing it to underflow. If another descriptor follows, the loop processes it with a wrapped remaining length and includes memory beyond the local buffer in the RDMA transfer.
A client can trigger an out-of-bounds kernel write with an SMB WRITE request, or an out-of-bounds kernel read with an SMB READ request, by supplying multiple RDMA buffer descriptors with an oversized descriptor before the last one.
Remove the premature assignment to buf_len. Subtracting the clamped length already consumes the remaining buffer, so the next iteration stops and only descriptors within the local buffer are used to build work requests.
[ metze: in 5.15 the code is smb_direct_rdma_xmit() in
fs/ksmbd/transport_rdma.c ]
--- fs/ksmbd/transport_rdma.c | 1 - 1 file changed, 1 deletion(-)
fs/ksmbd/transport_rdma.c +0 -1
@@ -1361,7 +1361,6 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,if (desc_buf_len > buf_len) { desc_buf_len = buf_len; desc[i].length =cpu_to_le32 (desc_buf_len); - buf_len =0 ; } credits_needed +=calc_rw_credits (t, desc_buf, desc_buf_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/2214 mm/hugetlb: fix use-after-free in hugetlb_mfill_atomic_pte()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit d8a9cd7fd2fb01211430c933932da58839b8ca65 ]
Let's fix another instance where we use a folio after dropping the PTL, where someone else could e.g., MADV_DONTNEED it once we drop the PTL, making us trigger a use-after-free on the folio.
--- mm/hugetlb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/hugetlb.c +6 -1
@@ -5390,11 +5390,16 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,/* No need to invalidate - it was non-present before */ update_mmu_cache (dst_vma, dst_addr, dst_pte); -spin_unlock (ptl);if (!is_continue)SetHPageMigratable (page);if (vm_shared || is_continue)unlock_page (page); + +/* +* Hold the PTL until we're done with the page: the page table owns the +* page reference now. +*/ +spin_unlock (ptl); ret =0 ; out:return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/2214 smb: client: fix warning in CIFSFindFirst()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 032137fe136a6073dcc699ee15fa3fd05fd77f21 ]
This fixes the following warning reported by kernel test robot
fs/smb/client/cifssmb.c:4089 CIFSFindFirst() warn: missing error code? 'rc'
Stable-dep-of: 59131dd72f62 ("smb: client: fix use-after-free infoleak via the readdir resume name")
--- fs/cifs/cifssmb.c | 94 +++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 52 deletions(-)
fs/cifs/cifssmb.c +42 -52
@@ -4333,11 +4333,12 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon,TRANSACTION2_FFIRST_REQ *pSMB =NULL ;TRANSACTION2_FFIRST_RSP *pSMBr =NULL ;T2_FFIRST_RSP_PARMS *parms; -int rc =0 ; +struct nls_table *nls_codepage; +unsigned int lnoff; +__u16 params, byte_count;int bytes_returned =0 ;int name_len, remap; -__u16 params, byte_count; -struct nls_table *nls_codepage; +int rc =0 ;cifs_dbg (FYI ,"In FindFirst for %s\n" , searchName);
@@ -4428,63 +4429,52 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, (struct smb_hdr *) pSMBr, &bytes_returned, 0);cifs_stats_inc (&tcon->stats.cifs_stats.num_ffirst); -if (rc) {/* BB add logic to retry regular search if Unix search -rejected unexpectedly by server */ -/* BB Add code to handle unsupported level rc */ +if (rc) { +/* +* BB: add logic to retry regular search if Unix search rejected +* unexpectedly by server. +*/ +/* BB: add code to handle unsupported level rc */ cifs_dbg (FYI ,"Error in FindFirst = %d\n" , rc); -cifs_buf_release (pSMB); - -/* BB eventually could optimize out free and realloc of buf */ -/* for this case */ +/* +* BB: eventually could optimize out free and realloc of buf for +* this case. +*/ if (rc == -EAGAIN ) goto findFirstRetry; - }else {/* decode response */ -/* BB remember to free buffer if error BB */ - rc =validate_t2 ((struct smb_t2_rsp *)pSMBr); -if (rc ==0 ) { -unsigned int lnoff; - -if (pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ) - psrch_inf->unicode = true; -else - psrch_inf->unicode = false; - - psrch_inf->ntwrk_buf_start = (char *)pSMBr; - psrch_inf->smallBuf = false; - psrch_inf->srch_entries_start = - (char *) &pSMBr->hdr.Protocol + -le16_to_cpu (pSMBr->t2.DataOffset); - parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + -le16_to_cpu (pSMBr->t2.ParameterOffset)); - -if (parms->EndofSearch) - psrch_inf->endOfSearch = true; -else - psrch_inf->endOfSearch = false; +return rc; + } +/* decode response */ + rc =validate_t2 ((struct smb_t2_rsp *)pSMBr); +if (rc) { +cifs_buf_release (pSMB); +return rc; + } - psrch_inf->entries_in_buffer = -le16_to_cpu (parms->SearchCount); - psrch_inf->index_of_last_entry =2 /* skip . and .. */ + - psrch_inf->entries_in_buffer; - lnoff =le16_to_cpu (parms->LastNameOffset); -if (CIFSMaxBufSize < lnoff) { -cifs_dbg (VFS ,"ignoring corrupt resume name\n" ); - psrch_inf->last_entry =NULL ; -return rc; - } + psrch_inf->unicode = !!(pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ); + psrch_inf->ntwrk_buf_start = (char *)pSMBr; + psrch_inf->smallBuf = false; + psrch_inf->srch_entries_start = (char *)&pSMBr->hdr.Protocol + +le16_to_cpu (pSMBr->t2.DataOffset); - psrch_inf->last_entry = psrch_inf->srch_entries_start + - lnoff; + parms = (T2_FFIRST_RSP_PARMS *)((char *)&pSMBr->hdr.Protocol + +le16_to_cpu (pSMBr->t2.ParameterOffset)); + psrch_inf->endOfSearch = !!parms->EndofSearch; -if (pnetfid) - *pnetfid = parms->SearchHandle; - }else { -cifs_buf_release (pSMB); - } + psrch_inf->entries_in_buffer =le16_to_cpu (parms->SearchCount); + psrch_inf->index_of_last_entry =2 /* skip . and .. */ + + psrch_inf->entries_in_buffer; + lnoff =le16_to_cpu (parms->LastNameOffset); +if (CIFSMaxBufSize < lnoff) { +cifs_dbg (VFS ,"ignoring corrupt resume name\n" ); + psrch_inf->last_entry =NULL ; + }else { + psrch_inf->last_entry = psrch_inf->srch_entries_start + lnoff; +if (pnetfid) + *pnetfid = parms->SearchHandle; } - -return rc; +return 0 ; } int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/2214 smb: client: fix warning in CIFSFindNext()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 215533f888dcf18f7cfbbf520bdd52e67ac6265a ]
This fixes the following warning reported by kernel test robot
fs/smb/client/cifssmb.c:4216 CIFSFindNext() warn: missing error code? 'rc'
Stable-dep-of: 59131dd72f62 ("smb: client: fix use-after-free infoleak via the readdir resume name")
--- fs/cifs/cifssmb.c | 111 +++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 60 deletions(-)
fs/cifs/cifssmb.c +51 -60
@@ -4484,11 +4484,12 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,TRANSACTION2_FNEXT_REQ *pSMB =NULL ;TRANSACTION2_FNEXT_RSP *pSMBr =NULL ;T2_FNEXT_RSP_PARMS *parms; -char *response_data; -int rc =0 ; -int bytes_returned;unsigned int name_len; +unsigned int lnoff;__u16 params, byte_count; +char *response_data; +int bytes_returned; +int rc =0 ;cifs_dbg (FYI ,"In FindNext\n" );
@@ -4533,8 +4534,8 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, pSMB->ResumeFileName[name_len] =0 ; pSMB->ResumeFileName[name_len+1 ] =0 ; }else { - rc = -EINVAL ; - goto FNext2_err_exit; +cifs_buf_release (pSMB); +return -EINVAL ; } byte_count = params +1 /* pad */ ; pSMB->TotalParameterCount =cpu_to_le16 (params);
@@ -4545,71 +4546,61 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, (struct smb_hdr *) pSMBr, &bytes_returned,0 );cifs_stats_inc (&tcon->stats.cifs_stats.num_fnext); +if (rc) { +cifs_buf_release (pSMB);if (rc == -EBADF ) { psrch_inf->endOfSearch = true; -cifs_buf_release (pSMB); rc =0 ;/* search probably was closed at end of search*/ - }else + }else {cifs_dbg (FYI ,"FindNext returned = %d\n" , rc); - }else {/* decode response */ - rc =validate_t2 ((struct smb_t2_rsp *)pSMBr); - -if (rc ==0 ) { -unsigned int lnoff; - -/* BB fixme add lock for file (srch_info) struct here */ -if (pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ) - psrch_inf->unicode = true; -else - psrch_inf->unicode = false; - response_data = (char *) &pSMBr->hdr.Protocol + -le16_to_cpu (pSMBr->t2.ParameterOffset); - parms = (T2_FNEXT_RSP_PARMS *)response_data; - response_data = (char *)&pSMBr->hdr.Protocol + -le16_to_cpu (pSMBr->t2.DataOffset); -if (psrch_inf->smallBuf) -cifs_small_buf_release ( - psrch_inf->ntwrk_buf_start); -else -cifs_buf_release (psrch_inf->ntwrk_buf_start); - psrch_inf->srch_entries_start = response_data; - psrch_inf->ntwrk_buf_start = (char *)pSMB; - psrch_inf->smallBuf = false; -if (parms->EndofSearch) - psrch_inf->endOfSearch = true; -else - psrch_inf->endOfSearch = false; - psrch_inf->entries_in_buffer = -le16_to_cpu (parms->SearchCount); - psrch_inf->index_of_last_entry += - psrch_inf->entries_in_buffer; - lnoff =le16_to_cpu (parms->LastNameOffset); -if (CIFSMaxBufSize < lnoff) { -cifs_dbg (VFS ,"ignoring corrupt resume name\n" ); - psrch_inf->last_entry =NULL ; -return rc; - }else - psrch_inf->last_entry = - psrch_inf->srch_entries_start + lnoff; - -/* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", -psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ - -/* BB fixme add unlock here */ } +return rc; + } +/* decode response */ + rc =validate_t2 ((struct smb_t2_rsp *)pSMBr); +if (rc) { +cifs_buf_release (pSMB); +return rc; } +/* BB fixme add lock for file (srch_info) struct here */ + psrch_inf->unicode = !!(pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ); + response_data = (char *)&pSMBr->hdr.Protocol + +le16_to_cpu (pSMBr->t2.ParameterOffset); + parms = (T2_FNEXT_RSP_PARMS *)response_data; + response_data = (char *)&pSMBr->hdr.Protocol + +le16_to_cpu (pSMBr->t2.DataOffset); -/* BB On error, should we leave previous search buf (and count and -last entry fields) intact or free the previous one? */ +if (psrch_inf->smallBuf) +cifs_small_buf_release (psrch_inf->ntwrk_buf_start); +else +cifs_buf_release (psrch_inf->ntwrk_buf_start); -/* Note: On -EAGAIN error only caller can retry on handle based calls -since file handle passed in no longer valid */ -FNext2_err_exit: -if (rc !=0 ) -cifs_buf_release (pSMB); -return rc; + psrch_inf->srch_entries_start = response_data; + psrch_inf->ntwrk_buf_start = (char *)pSMB; + psrch_inf->smallBuf = false; + psrch_inf->endOfSearch = !!parms->EndofSearch; + psrch_inf->entries_in_buffer =le16_to_cpu (parms->SearchCount); + psrch_inf->index_of_last_entry += psrch_inf->entries_in_buffer; + lnoff =le16_to_cpu (parms->LastNameOffset); +if (CIFSMaxBufSize < lnoff) { +cifs_dbg (VFS ,"ignoring corrupt resume name\n" ); + psrch_inf->last_entry =NULL ; + }else { + psrch_inf->last_entry = + psrch_inf->srch_entries_start + lnoff; + } +/* BB fixme add unlock here */ + +/* +* BB: On error, should we leave previous search buf +* (and count and last entry fields) intact or free the previous one? +* +* Note: On -EAGAIN error only caller can retry on handle based calls +* since file handle passed in no longer valid. +*/ +return 0 ; }int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/2214 smb: client: fix use-after-free infoleak via the readdir resume name
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diego Oliva <[email protected]>
[ Upstream commit 59131dd72f62b198fc9ea1489ad9d3573154f684 ]
CIFSFindNext() copies the resume name that cifs_save_resume_key() recorded from the last entry of the previous response into its request; psrch_inf->presume_name points into the response buffer that entry came from, and nothing ever clears it. find_cifs_entry() records a new name only from a response with a usable last entry, and cifs_readdir() only from an entry it walks to, so a response that carries no entries and leaves last_entry NULL, because CIFSFindFirst() or CIFSFindNext() rejected LastNameOffset, refreshes neither and presume_name keeps pointing into the previous response. That buffer has already been
released: by CIFSFindNext() before it installs the new response, or by find_cifs_entry() when it rewinds the search, which does not drop the name either and can then fail in initiate_cifs_search() before a new response replaces it. The next CIFSFindNext() then copies up to PATH_MAX - 1 bytes of the resume name out of the released buffer into its request and sends them to the server: a use-after-free read that leaks kernel memory to a malicious or compromised server, which can provoke it with a single FindNext response that carries no entries and a LastNameOffset above CIFSMaxBufSize, which is all the existing check rejects.
With KASAN enabled, a server that answers a listing that way gives:
CIFS: VFS: ignoring corrupt resume name
==================================================================
BUG: KASAN: slab-use-after-free in CIFSFindNext+0x8ca/0x14c0 Read of size 4080 at addr ffff88807c823f98 by task ls/83 CPU: 0 UID: 0 PID: 83 Comm: ls Tainted: G B 7.3.0-rc4-00457-gf14572c203d5 #69 PREEMPT(lazy) Tainted: [B]=BAD_PAGE Call Trace: <TASK> kasan_report+0xdf/0x1a0 kasan_check_range+0x10f/0x1e0 __asan_memcpy+0x23/0x60 CIFSFindNext+0x8ca/0x14c0 cifs_readdir+0xf51/0x29c0 iterate_dir+0x1c0/0x570 __x64_sys_getdents64+0x133/0x270 do_syscall_64+0x109/0x5d0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Allocated by task 83 on cpu 1 at 13.497119s: cifs_buf_get+0x36/0x90 smb_init+0x4f/0x110 CIFSFindNext+0xf7/0x14c0 cifs_readdir+0xf51/0x29c0 Freed by task 83 on cpu 0 at 13.584018s: cifs_buf_release+0x41/0x80 CIFSFindNext+0xfce/0x14c0 cifs_readdir+0xf51/0x29c0
The buggy address is located 16280 bytes inside of
freed 16588-byte region [ffff88807c820000, ffff88807c8240cc)
==================================================================
The same memcpy() first reads past the end of that object while it is still live, a slab-out-of-bounds read that the following patches bound; that is the taint the report above carries.
SMB1 is not negotiated by default; reaching this code requires an explicit vers=1.0 mount.
Clear presume_name and resume_name_len whenever a new response is installed and when the rewind path releases the search buffer, so that the name never outlives the buffer it points into, and reset resume_key with them, since it was taken from the same entry and would otherwise be sent with an empty name. A response without a usable last entry then continues the search with an empty resume name rather than a stale one; CIFSFindNext() skips the copy of a zero-length name so that it never runs on the NULL pointer.
The next patch in the series leaves last_entry NULL for a response that carries no entries, and bounds LastNameOffset against the received response rather than against CIFSMaxBufSize. Responses that are given a last entry today then take the path fixed here, so that patch must not be applied without this one.
--- fs/cifs/cifssmb.c | 11 ++++++++++- fs/cifs/readdir.c | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-)
fs/cifs/cifssmb.c +10 -1
@@ -4465,6 +4465,9 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, psrch_inf->entries_in_buffer =le16_to_cpu (parms->SearchCount); psrch_inf->index_of_last_entry =2 /* skip . and .. */ + psrch_inf->entries_in_buffer; + psrch_inf->presume_name =NULL ; + psrch_inf->resume_name_len =0 ; + psrch_inf->resume_key =0 ; lnoff =le16_to_cpu (parms->LastNameOffset);if (CIFSMaxBufSize < lnoff) {cifs_dbg (VFS ,"ignoring corrupt resume name\n" );
@@ -4528,7 +4531,10 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, name_len = psrch_inf->resume_name_len; params += name_len;if (name_len <PATH_MAX ) { -memcpy (pSMB->ResumeFileName, psrch_inf->presume_name, name_len); +if (name_len) { +memcpy (pSMB->ResumeFileName, + psrch_inf->presume_name, name_len); + } byte_count += name_len;/* 14 byte parm len above enough for 2 byte null terminator */ pSMB->ResumeFileName[name_len] =0 ;
@@ -4583,6 +4589,9 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, psrch_inf->endOfSearch = !!parms->EndofSearch; psrch_inf->entries_in_buffer =le16_to_cpu (parms->SearchCount); psrch_inf->index_of_last_entry += psrch_inf->entries_in_buffer; + psrch_inf->presume_name =NULL ; + psrch_inf->resume_name_len =0 ; + psrch_inf->resume_key =0 ; lnoff =le16_to_cpu (parms->LastNameOffset);if (CIFSMaxBufSize < lnoff) {cifs_dbg (VFS ,"ignoring corrupt resume name\n" );
fs/cifs/readdir.c +3 -0
@@ -766,6 +766,9 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos, cfile->srch_inf.ntwrk_buf_start =NULL ; cfile->srch_inf.srch_entries_start =NULL ; cfile->srch_inf.last_entry =NULL ; + cfile->srch_inf.presume_name =NULL ; + cfile->srch_inf.resume_name_len =0 ; + cfile->srch_inf.resume_key =0 ; } rc =initiate_cifs_search (xid, file, full_path);if (rc) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/2214 smb: client: fix OOB last_entry pointer from unbounded LastNameOffset
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diego Oliva <[email protected]>
[ Upstream commit 570c783a96f054dd3ac409a92772e9afb705d21c ]
CIFSFindFirst() and CIFSFindNext() locate the last entry of a TRANS2_FIND_FIRST2 or TRANS2_FIND_NEXT2 response by adding the LastNameOffset of the response parameters to the start of the data area, and store the result in psrch_inf->last_entry. MS-CIFS 2.2.6.2.2 defines that offset as the offset of the entry's file name; the client follows the reading of NT and Samba servers, which point it at the entry. LastNameOffset is only checked against CIFSMaxBufSize, which says nothing about the response actually received: validate_t2() lets the data area start up to 1024 bytes into the buffer, and SendReceive() copies at most CIFSMaxBufSize + MAX_CIFS_HDR_SIZE bytes of a response, 16468 by default, into a cifs_request allocation of CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes, 16588 by default. The pointer itself can therefore be placed anywhere from the end of the received data to 820 bytes past the end of the allocation.
The read through that pointer is far larger than its displacement. find_cifs_entry() hands last_entry to cifs_save_resume_key() after every FindNext and after the FindFirst of a search rewind, and cifs_fill_dirent() takes the length of the name from the entry itself: a __le32 FileNameLength for most levels, a __u8 for SMB_FIND_FILE_INFO_STANDARD, and for SMB_FIND_FILE_UNIX the result of a scan for the terminating NUL over up to PATH_MAX + 1 UTF-16 units. The name is recorded as the resume name of the search, and the next CIFSFindNext() rejects only a recorded length of PATH_MAX or more before copying the name into the ResumeFileName of its request and sending it with the resume key taken from the same entry: up to 4 KiB of memory from past the end of the allocation leaks to the server, and for SMB_FIND_FILE_UNIX the NUL scan runs about twice as far before the length is even known. The entry does not have to lie outside the response for that either: a maximal response ends about 120 bytes before the end of the allocation, so an entry in its last bytes with a name just under PATH_MAX has nearly all of that name copied from past the allocation.
It needs nothing unusual from the client: a FindNext response that reports no entries and does not end the search makes find_cifs_entry() send the next FindNext at once, carrying whatever was parsed at LastNameOffset, and a search rewind can do the same after its FindFirst. SMB1 is not negotiated by default: this takes a malicious or compromised server, a mount of it with an explicit vers=1.0, which CONFIG_CIFS_ALLOW_INSECURE_LEGACY (default y) permits, and a directory listing on that mount.
With KASAN enabled, a response that places the last entry past the buffer, with a large DataOffset and a LastNameOffset near the end of its range, gives:
==================================================================
BUG: KASAN: slab-out-of-bounds in cifs_save_resume_key.isra.0+0x7aa/0x7f0 Read of size 4 at addr ffff88807b55c33b by task ls/83 CPU: 1 UID: 0 PID: 83 Comm: ls Not tainted 7.3.0-rc4-00457-gf14572c203d5 #69 PREEMPT(lazy) Call Trace: <TASK> kasan_report+0xdf/0x1a0 cifs_save_resume_key.isra.0+0x7aa/0x7f0 cifs_readdir+0x1ed6/0x29c0 iterate_dir+0x1c0/0x570 __x64_sys_getdents64+0x133/0x270 do_syscall_64+0x109/0x5d0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Allocated by task 83 on cpu 0 at 19.317556s: cifs_buf_get+0x36/0x90 smb_init+0x4f/0x110 CIFSFindNext+0xf7/0x14c0 cifs_readdir+0xf51/0x29c0 The buggy address belongs to the object at ffff88807b558000 which belongs to the cache cifs_request of size 16588 The buggy address is located 623 bytes to the right of allocated 16588-byte region [ffff88807b558000, ffff88807b55c0cc) ==================================================================
The four bytes read there are the FileNameLength of the entry, which cifs_fill_dirent() takes before anything checks where the entry lies.
Ignore the last entry when it does not start inside the received response or the response holds no entries; for a response without entries, last_entry pointed into or past its empty data area and cifs_save_resume_key() parsed whatever the buffer held there. The entry is bounded by the response that was received, which is what the buffer holds, rather than by the data area the response declares, which a later patch checks against the received length. Record the search handle before the last entry is examined, since a response without a usable last entry still carries the handle that the search is continued and closed with; leaving the assignment in the else branch would drop the handle of every response without entries.
This bounds where the last entry starts, not how far it is parsed: an entry that starts within the final bytes of the response still has its fixed part read past the end of the received data and its name, up to 4095 bytes, copied from past the end of the allocation, until the following patch bounds the parse itself. A response without a usable last entry continues the search with an empty resume name, since the preceding patch, "smb: client: fix use-after-free infoleak via the readdir resume name", drops the recorded name whenever a new response is installed. This patch applies on top of that one and relies on it: without it, every response rejected here would leave the previous name in place, pointing into a buffer that has been released.
A conforming server is not affected: the last entry lies inside the data area of the response.
--- fs/cifs/cifssmb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
fs/cifs/cifssmb.c +10 -4
@@ -4468,14 +4468,17 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, psrch_inf->presume_name =NULL ; psrch_inf->resume_name_len =0 ; psrch_inf->resume_key =0 ; +if (pnetfid) + *pnetfid = parms->SearchHandle; lnoff =le16_to_cpu (parms->LastNameOffset); -if (CIFSMaxBufSize < lnoff) { +if (!psrch_inf->entries_in_buffer) { + psrch_inf->last_entry =NULL ; + }else if (psrch_inf->srch_entries_start + lnoff >= + psrch_inf->ntwrk_buf_start + bytes_returned) {cifs_dbg (VFS ,"ignoring corrupt resume name\n" ); psrch_inf->last_entry =NULL ; }else { psrch_inf->last_entry = psrch_inf->srch_entries_start + lnoff; -if (pnetfid) - *pnetfid = parms->SearchHandle; }return 0 ; }
@@ -4593,7 +4596,10 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, psrch_inf->resume_name_len =0 ; psrch_inf->resume_key =0 ; lnoff =le16_to_cpu (parms->LastNameOffset); -if (CIFSMaxBufSize < lnoff) { +if (!psrch_inf->entries_in_buffer) { + psrch_inf->last_entry =NULL ; + }else if (psrch_inf->srch_entries_start + lnoff >= + psrch_inf->ntwrk_buf_start + bytes_returned) {cifs_dbg (VFS ,"ignoring corrupt resume name\n" ); psrch_inf->last_entry =NULL ; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/2214 HID: wacom: Redesign shared sibling data lifecycle
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit 480c9cb14ae81f8e112ff83f8778b3d7b9324dc8 ]
The Wacom driver coordinates state between sibling interfaces of the same physical device using a shared structure 'wacom_shared' inside 'wacom_hdev_data'. The driver kept a volatile representative pointer 'data->dev' pointing to a sibling 'hid_device' for physical path comparisons during sibling matching.
This pointer management is fragile. When the representative device is disconnected, wacom_remove_shared_data() failed to clear/update 'data->dev', leading to a Use-After-Free vulnerability when subsequent sibling probes dereference the dangling 'data->dev' pointer.
Resolve this issue by redesigning the sibling data lifecycle:
- Eliminate the volatile 'data->dev' representative pointer completely
- Redesign 'wacom_hdev_data' to store stable static copies of the required attributes upon first allocation: 'phys' path string, 'vendor', 'product' IDs and the sibling's 'device_type'
- Use these static attributes for stable sibling matching in wacom_are_sibling() and wacom_get_hdev_data()
This ensures sibling matching remains safe and stable even if individual siblings are dynamically added or removed.
To secure the lifecycle against concurrent probe/disconnect races:
- Switch kref_put() to kref_put_mutex() in wacom_remove_shared_data() to serialize refcount drops with list traversal and lookup
- Modify wacom_release_shared_data() to assume the list lock is already held
Also, do not accumulate the 'device_type' capability flag during subsequent sibling probes. Keeping only the first probed sibling's device_type exactly preserves the original sibling matching behavior without introducing side effects.
--- drivers/hid/wacom_sys.c | 70 +++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 24 deletions(-)
drivers/hid/wacom_sys.c +46 -24
@@ -750,27 +750,47 @@ static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,struct wacom_hdev_data {struct list_head list;struct kref kref; -struct hid_device *dev; +char phys[64 ]; +__u32 vendor; +__u32 product; +__u32 device_type;struct wacom_shared shared; }; +static bool wacom_compare_device_paths (struct hid_device *hdev_a, +const char *phys_b,char separator) +{ +const char *p1 =strrchr (hdev_a->phys, separator); +const char *p2 =strrchr (phys_b, separator); +int n1, n2; + +if (!p1 || !p2) +return false; + + n1 = p1 - hdev_a->phys; + n2 = p2 - phys_b; + +if (n1 != n2 || n1 <=0 || n2 <=0 ) +return false; + +return !strncmp (hdev_a->phys, phys_b, n1); +} +static LIST_HEAD (wacom_udev_list);static DEFINE_MUTEX (wacom_udev_list_lock);static bool wacom_are_sibling (struct hid_device *hdev, -struct hid_device *sibling) +struct wacom_hdev_data *data) {struct wacom *wacom =hid_get_drvdata (hdev);struct wacom_features *features = &wacom->wacom_wac.features; -struct wacom *sibling_wacom =hid_get_drvdata (sibling); -struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features;__u32 oVid = features->oVid ? features->oVid : hdev->vendor;__u32 oPid = features->oPid ? features->oPid : hdev->product;/* The defined oVid/oPid must match that of the sibling */ -if (features->oVid !=HID_ANY_ID && sibling->vendor != oVid) +if (features->oVid !=HID_ANY_ID && data->vendor != oVid)return false; -if (features->oPid !=HID_ANY_ID && sibling->product != oPid) +if (features->oPid !=HID_ANY_ID && data->product != oPid)return false;/*
@@ -778,11 +798,11 @@ static bool wacom_are_sibling(struct hid_device *hdev,* device path, while those with different VID/PID must share * the same physical parent device path. */ -if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) { -if (!hid_compare_device_paths (hdev, sibling,'/' )) +if (hdev->vendor == data->vendor && hdev->product == data->product) { +if (!wacom_compare_device_paths (hdev, data->phys,'/' ))return false; }else { -if (!hid_compare_device_paths (hdev, sibling,'.' )) +if (!wacom_compare_device_paths (hdev, data->phys,'.' ))return false; }
@@ -795,7 +815,7 @@ static bool wacom_are_sibling(struct hid_device *hdev,* devices. */ if ((features->device_type &WACOM_DEVICETYPE_DIRECT ) && - !(sibling_features->device_type &WACOM_DEVICETYPE_DIRECT )) + !(data->device_type &WACOM_DEVICETYPE_DIRECT ))return false;/*
@@ -803,17 +823,17 @@ static bool wacom_are_sibling(struct hid_device *hdev,* devices. */ if (!(features->device_type &WACOM_DEVICETYPE_DIRECT ) && - (sibling_features->device_type &WACOM_DEVICETYPE_DIRECT )) + (data->device_type &WACOM_DEVICETYPE_DIRECT ))return false;/* Pen devices may only be siblings of touch devices */ if ((features->device_type &WACOM_DEVICETYPE_PEN ) && - !(sibling_features->device_type &WACOM_DEVICETYPE_TOUCH )) + !(data->device_type &WACOM_DEVICETYPE_TOUCH ))return false;/* Touch devices may only be siblings of pen devices */ if ((features->device_type &WACOM_DEVICETYPE_TOUCH ) && - !(sibling_features->device_type &WACOM_DEVICETYPE_PEN )) + !(data->device_type &WACOM_DEVICETYPE_PEN ))return false;/*
@@ -829,7 +849,7 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)/* Try to find an already-probed interface from the same device */ list_for_each_entry (data, &wacom_udev_list, list) { -if (hid_compare_device_paths (hdev, data->dev,'/' )) { +if (wacom_compare_device_paths (hdev, data->phys,'/' )) {kref_get (&data->kref);return data; }
@@ -837,7 +857,7 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)/* Fallback to finding devices that appear to be "siblings" */ list_for_each_entry (data, &wacom_udev_list, list) { -if (wacom_are_sibling (hdev, data->dev)) { +if (wacom_are_sibling (hdev, data)) {kref_get (&data->kref);return data; }
@@ -851,29 +871,28 @@ static void wacom_release_shared_data(struct kref *kref)struct wacom_hdev_data *data = container_of(kref, struct wacom_hdev_data, kref); -mutex_lock (&wacom_udev_list_lock);list_del (&data->list); -mutex_unlock (&wacom_udev_list_lock); -kfree (data); }static void wacom_remove_shared_data (void *res) { -struct wacom *wacom = res; +struct wacom *res_wacom = res;struct wacom_hdev_data *data; -struct wacom_wac *wacom_wac = &wacom->wacom_wac; +struct wacom_wac *wacom_wac = &res_wacom->wacom_wac;if (wacom_wac->shared) { data = container_of(wacom_wac->shared, struct wacom_hdev_data, shared); -if (wacom_wac->shared->touch == wacom->hdev) +if (wacom_wac->shared->touch == res_wacom->hdev) wacom_wac->shared->touch =NULL ; -else if (wacom_wac->shared->pen == wacom->hdev) +else if (wacom_wac->shared->pen == res_wacom->hdev) wacom_wac->shared->pen =NULL ; -kref_put (&data->kref, wacom_release_shared_data); +if (kref_put_mutex (&data->kref, wacom_release_shared_data, &wacom_udev_list_lock)) +mutex_unlock (&wacom_udev_list_lock); + wacom_wac->shared =NULL ; } }
@@ -896,7 +915,10 @@ static int wacom_add_shared_data(struct hid_device *hdev) }kref_init (&data->kref); - data->dev = hdev; +strscpy (data->phys, hdev->phys,sizeof (data->phys)); + data->vendor = hdev->vendor; + data->product = hdev->product; + data->device_type = wacom_wac->features.device_type;list_add_tail (&data->list, &wacom_udev_list); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/2214 genirq: Defer kfree(irqaction) until irq_thread_dtor() finishes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Richard Patel <[email protected]>
[ Upstream commit d04adff6860587e843948b0c31174f8ae11b8dfe ]
When an interrupt thread exits abnormally via do_exit() (e.g. the interrupt handler oopses) without returning from irq_thread(), a concurrent call to free_irq() could free the irqaction before the irq_thread_dtor() exit task work runs.
irq thread (oopsed) free_irq()
------------------- ----------
do_exit()
exit_mm()
complete_vfork_done() -------> kthread_stop() returns
exit_files() ... kfree(action)
exit_task_work()
irq_thread_dtor()
action->... <- use-after-freeTrack the pending exit work with the IRQTF_EXIT_WORK thread flag, and have __free_irq() wait for the bit to clear before kfree().
irq_thread_dtor() only runs on irq_thread abnormal exit. If that dtor also faults, free_irq() will hang indefinitely, but double IRQ thread faults require a reboot anyways.
[ tglx: Add missing include ]
--- kernel/irq/internals.h | 2 ++ kernel/irq/manage.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-)
kernel/irq/internals.h +2 -0
@@ -30,6 +30,7 @@ extern struct irqaction chained_action;* IRQTF_AFFINITY - irq thread is requested to adjust affinity * IRQTF_FORCED_THREAD - irq action is force threaded * IRQTF_READY - signals that irq thread is ready +* IRQTF_EXIT_WORK - irq thread exit task_work is pending */ enum {IRQTF_RUNTHREAD ,
@@ -37,6 +38,7 @@ enum {IRQTF_AFFINITY ,IRQTF_FORCED_THREAD ,IRQTF_READY , + IRQTF_EXIT_WORK, };/*
kernel/irq/manage.c +22 -10
@@ -21,6 +21,7 @@#include <linux/sched/isolation.h> #include <uapi/linux/sched/types.h> #include <linux/task_work.h> +#include <linux/wait_bit.h> #include "internals.h"
@@ -1224,17 +1225,14 @@ static void wake_threads_waitq(struct irq_desc *desc)wake_up (&desc->wait_for_threads); } -static void irq_thread_dtor (struct callback_head *unused) +static void __irq_thread_dtor (struct irqaction *action) {struct task_struct *tsk = current;struct irq_desc *desc; -struct irqaction *action;if (WARN_ON_ONCE (!(current->flags &PF_EXITING )))return ; - action =kthread_data (tsk); -pr_err ("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n" , tsk->comm, tsk->pid, action->irq);
@@ -1251,6 +1249,14 @@ static void irq_thread_dtor(struct callback_head *unused)irq_finalize_oneshot (desc, action); } +static void irq_thread_dtor (struct callback_head *unused) +{ +struct irqaction *action =kthread_data (current); + +__irq_thread_dtor (action); +clear_and_wake_up_bit (IRQTF_EXIT_WORK , &action->thread_flags); +} +static void irq_wake_secondary (struct irq_desc *desc,struct irqaction *action) {struct irqaction *secondary = action->secondary;
@@ -1307,6 +1313,7 @@ static int irq_thread(void *data)else handler_fn = irq_thread_fn; +set_bit (IRQTF_EXIT_WORK , &action->thread_flags);init_task_work (&on_exit_work, irq_thread_dtor);task_work_add (current, &on_exit_work,TWA_NONE );
@@ -1331,6 +1338,7 @@ static int irq_thread(void *data)* oneshot mask bit can be set. */ task_work_cancel_func (current, irq_thread_dtor); +clear_and_wake_up_bit (IRQTF_EXIT_WORK , &action->thread_flags);return 0 ; }
@@ -1867,6 +1875,13 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)return ret; } +static void irq_stop_thread (struct irqaction *action) +{ +kthread_stop (action->thread); +put_task_struct (action->thread); +wait_on_bit (&action->thread_flags,IRQTF_EXIT_WORK ,TASK_UNINTERRUPTIBLE ); +} +/* * Internal function to unregister an irqaction - used to free * regular and special interrupts that are part of the architecture.
@@ -1971,12 +1986,9 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)* the same bit to a newly requested action. */ if (action->thread) { -kthread_stop (action->thread); -put_task_struct (action->thread); -if (action->secondary && action->secondary->thread) { -kthread_stop (action->secondary->thread); -put_task_struct (action->secondary->thread); - } +irq_stop_thread (action); +if (action->secondary && action->secondary->thread) +irq_stop_thread (action->secondary); }/* Last action releases resources */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/2214 staging: rtl8723bs: fix protected RX frame validation in decrypt path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
[ Upstream commit 495cb31c791bdf3f9efef255a9587b05b0526c9d ]
The RX software decrypt path mishandles crafted protected frames from a malicious AP in two ways:
1) decryptor() never checks that a protected frame is long enough to hold the 802.11 header plus the per-cipher trailer. All of rtw_wep_decrypt(), rtw_tkip_decrypt() and rtw_aes_decrypt() compute
length = hdr.len - hdrlen - iv_len;
and act on the result, and recvframe_chkmic() similarly computes
datalen = hdr.len - hdrlen - iv_len - icv_len - 8;
for TKIP (the 8-byte Michael MIC is not accounted for in icv_len). A frame shorter than hdrlen + iv_len + icv_len (+ 8 for TKIP) underflows these unsigned subtractions, turning into a ~4 GiB iteration count in aes_decipher()/arc4_crypt()/rtw_seccalctkipmic() or a ~4 GiB crc32_le() length, causing out-of-bounds reads/writes of up to ~4 GiB starting from the rx skb. Reject such frames in decryptor() before touching the IV; this covers all three ciphers and the TKIP MIC check, and also keeps the unconditional iv[3] access within the frame.
2) validate_80211w_mgmt() keeps using the frame - two memcpys through the stale rx_data pointer and a pkt_len update - before checking whether decryptor() returned NULL. On decrypt failure (e.g. a unicast protected deauth/disassoc/action frame with a bad MIC, which this path always software-decrypts) the skb has already been freed, so this is a use-after-free read/write, and the caller's error path frees the frame a second time, drifting free_recvframe_cnt. Bail out immediately when decryptor() fails, freeing the temporary mgmt_DATA buffer first.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/staging/rtl8723bs/core/rtw_recv.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +19 -4
@@ -392,7 +392,21 @@ static union recv_frame *decryptor(struct adapter *padapter, union recv_frame *pu32 res = _SUCCESS;if (prxattrib->encrypt >0 ) { -u8 *iv = precv_frame->u.hdr.rx_data+prxattrib->hdrlen; +u8 *iv; +u32 min_len = prxattrib->hdrlen + prxattrib->iv_len + prxattrib->icv_len; + +/* TKIP appends an 8-byte Michael MIC that icv_len doesn't account for */ +if (prxattrib->encrypt == _TKIP_) + min_len +=8 ; + +/* a protected frame must be long enough to hold the IV and ICV/MIC */ +if (precv_frame->u.hdr.len < min_len) { +rtw_free_recvframe (precv_frame, + &padapter->recvpriv.free_recv_queue); +return NULL ; + } + + iv = precv_frame->u.hdr.rx_data + prxattrib->hdrlen; prxattrib->key_index = (((iv[3 ])>>6 )&0x3 );if (prxattrib->key_index >WEP_KEYS ) {
@@ -1374,6 +1388,10 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame goto validate_80211w_fail; } precv_frame =decryptor (adapter, precv_frame); +if (!precv_frame) { +kfree (mgmt_DATA); + goto validate_80211w_fail; + }/* save actual management data frame body */ memcpy (mgmt_DATA, ptr+pattrib->hdrlen+pattrib->iv_len, data_len);/* overwrite the iv field */
@@ -1381,9 +1399,6 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame/* remove the iv and icv length */ pattrib->pkt_len = pattrib->pkt_len - pattrib->iv_len - pattrib->icv_len;kfree (mgmt_DATA); -if (!precv_frame) { - goto validate_80211w_fail; - } }else if (IS_MCAST (GetAddr1Ptr (ptr)) && (subtype ==WIFI_DEAUTH || subtype ==WIFI_DISASSOC )) {signed int BIP_ret = _SUCCESS;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/2214 mptcp: hold MP_JOIN msk ref when cloning reqsk
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruide Cao <[email protected]>
[ Upstream commit c9c90cf437a9e6597611b6d3aad6e255fad22867 ]
TCP request migration clones pending request sockets with inet_reqsk_clone(). For MPTCP MP_JOIN requests this byte-copies subflow_req->msk, but the clone does not own a reference.
The original and cloned requests can consequently drop the same msk reference, leaving one request with a dangling pointer. This manifests as a KASAN slab-use-after-free in subflow_req_destructor():
BUG: KASAN: slab-use-after-free in subflow_req_destructor (net/mptcp/subflow.c:45) Write of size 4 at addr ff1100010e008d40 by task swapper/0/0 CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.2.0-rc5-00353-gc27e36054537 #10 PREEMPT(full) Call Trace: subflow_req_destructor (net/mptcp/subflow.c:45) subflow_v4_req_destructor (net/mptcp/subflow.c:694) __reqsk_free (net/ipv4/inet_connection_sock.c:906) reqsk_timer_handler (include/net/request_sock.h:137 net/ipv4/inet_connection_sock.c:1147) Allocated by task 10014: sk_prot_alloc (net/core/sock.c:2246) sk_clone (net/core/sock.c:2488) mptcp_sk_clone_init (include/net/sock.h:1848 net/mptcp/protocol.c:3564) subflow_syn_recv_sock (net/mptcp/subflow.c:883) tcp_check_req (net/ipv4/tcp_minisocks.c:934) Freed by task 0: slab_free_after_rcu_debug (include/linux/kasan.h:235 mm/slub.c:2677 mm/slub.c:6439) rcu_core (kernel/rcu/tree.c:2645 kernel/rcu/tree.c:2897) Last potentially related work creation: kmem_cache_free (mm/slub.c:2638 mm/slub.c:6377 mm/slub.c:6504) __sk_destruct (net/core/sock.c:2289 net/core/sock.c:2391) sk_destruct (net/core/sock.c:2419) __sk_free (net/core/sock.c:2430) sk_free (net/core/sock.c:2441) mptcp_close (include/net/sock.h:2020 net/mptcp/protocol.c:3399) inet_release (net/ipv4/af_inet.c:442) The buggy address belongs to the cache MPTCP of size 2968 The buggy address is 128 bytes inside a freed 2968-byte region
A non-NULL subflow_req->msk means that the request owns one reference. The third ACK can concurrently transfer the original request reference to the child and release it, so taking an unconditional hold on the copied pointer is unsafe.
MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all current inet_reqsk_clone() callers run in an RCU read-side critical section. Document and lockdep-check that calling-context requirement. Read the pointer from the original request and acquire a reference only if it is still live. Use refcount_inc_not_zero_acquire() so the subsequent ownership validation cannot be reordered before the try-get, then re-read the original request to verify that it still owns the same msk. If either check fails, clear the clone pointer; otherwise its normal destructor balances the new reference. Mark the ownership-transfer store with WRITE_ONCE() to match the lockless reads.
The following patch completes the clone fixup for MP_CAPABLE token ownership. Both patches carry the same Fixes tag and are required for stable backports.
--- include/net/mptcp.h | 9 ++++++++ net/ipv4/inet_connection_sock.c | 4 ++++ net/mptcp/subflow.c | 38 ++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-)
include/net/mptcp.h +9 -0
@@ -183,6 +183,9 @@ int mptcp_subflow_init_cookie_req(struct request_sock *req,struct request_sock *mptcp_subflow_reqsk_alloc (const struct request_sock_ops *ops,struct sock *sk_listener,bool attach_listener); +/* Caller must hold an RCU read-side lock. */ +void mptcp_subflow_reqsk_clone (struct request_sock *req, +struct request_sock *new_req);__be32 mptcp_get_reset_option (const struct sk_buff *skb);
@@ -282,6 +285,12 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct reques return NULL; } +/* Caller must hold an RCU read-side lock. */ +static inline void mptcp_subflow_reqsk_clone (struct request_sock *req, +struct request_sock *new_req) +{ +} +static inline __be32 mptcp_reset_option (const struct sk_buff *skb) {return htonl (0u ); }#endif /* CONFIG_MPTCP */
net/ipv4/inet_connection_sock.c +4 -0
@@ -20,6 +20,7 @@#include <net/tcp_states.h> #include <net/xfrm.h> #include <net/tcp.h> +#include <net/mptcp.h> #include <net/sock_reuseport.h> #include <net/addrconf.h>
@@ -768,6 +769,9 @@ static struct request_sock *inet_reqsk_clone(struct request_sock *req,rcu_assign_pointer (tcp_sk (nreq->sk)->fastopen_rsk, nreq); } +if (rsk_is_mptcp (req)) +mptcp_subflow_reqsk_clone (req, nreq); +return nreq; }
net/mptcp/subflow.c +37 -1
@@ -47,6 +47,42 @@ static void subflow_req_destructor(struct request_sock *req)mptcp_token_destroy_request (req); } +void mptcp_subflow_reqsk_clone (struct request_sock *req, +struct request_sock *new_req) +{ +struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req); +struct mptcp_subflow_request_sock *new_subflow_req; +struct mptcp_sock *msk; + + new_subflow_req =mptcp_subflow_rsk (new_req); +RCU_LOCKDEP_WARN (!rcu_read_lock_any_held (), +"MPTCP reqsk clone called without RCU" ); + +/* A non-NULL ->msk means the request owns one reference. The clone +* copied only the pointer, while the original request can concurrently +* transfer its reference to the child. Acquire a reference for the +* clone, then verify that the original request still owns the same msk. +* MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all clone callers run in +* an RCU read-side critical section, keeping the memory stable here. +*/ + msk =READ_ONCE (subflow_req->msk); +if (msk) { +struct sock *sk = (struct sock *)msk; + +if (!refcount_inc_not_zero (&sk->sk_refcnt)) { + msk =NULL ; + }else { +smp_acquire__after_ctrl_dep (); +if (READ_ONCE (subflow_req->msk) != msk) { +sock_put (sk); + msk =NULL ; + } + } + } + + new_subflow_req->msk = msk; +} +static void subflow_generate_hmac (u64 key1,u64 key2,u32 nonce1,u32 nonce2,void *hmac) {
@@ -803,7 +839,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, }/* move the msk reference ownership to the subflow */ - subflow_req->msk =NULL ; +WRITE_ONCE (subflow_req->msk,NULL ); ctx->conn = (struct sock *)owner;if (subflow_use_different_sport (owner, sk)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/2214 xen-blkfront: unbind irq before tearing down ring and shadow requests
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuchao Zhang <[email protected]>
[ Upstream commit f3e27b7955727a4d7c0e9264a2a209fbba788bdc ]
In blkif_free_ring(), the driver tears down the ring's persistent grants, shadow request arrays, and shared ring structure (xenbus_teardown_ring), and only calls unbind_from_irqhandler() at the very end.
While blkif_free_ring() is freeing persistent grants and clearing the shadow array, the event channel interrupt (blkif_interrupt) is still registered and active. If an interrupt arrives from the backend during this teardown window, blkif_interrupt() reads rinfo->ring.sring and, via blkif_completion(), accesses rinfo->shadow[id].grants_used and rinfo->shadow[id].sg. blkif_free_ring() tears these structures down without holding rinfo->ring_lock, and the handler only checks info->connected at entry, so this is a real race resulting in a use-after-free or NULL pointer dereference.
Fix this by moving unbind_from_irqhandler() to the beginning of blkif_free_ring(). Calling unbind_from_irqhandler() first frees the IRQ and synchronizes with any in-flight interrupt handlers on other CPUs before ring memory and shadow request structures are deallocated, matching the teardown order in drivers/net/xen-netfront.c.
Message-ID: <[email protected]>
--- drivers/block/xen-blkfront.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/block/xen-blkfront.c +8 -4
@@ -1215,6 +1215,14 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)struct blkfront_info *info = rinfo->dev_info;int i, j, segs; +/* +* Interrupt teardown must be done ahead of freeing queue-related +* data, otherwise the interrupt handler can race with the cleanup. +*/ +if (rinfo->irq) +unbind_from_irqhandler (rinfo->irq, rinfo); + rinfo->evtchn = rinfo->irq =0 ; +/* * Remove indirect pages, this only happens when using indirect * descriptors but not persistent grants
@@ -1304,10 +1312,6 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)free_pages_exact (rinfo->ring.sring, info->nr_ring_pages *XEN_PAGE_SIZE ); rinfo->ring.sring =NULL ; - -if (rinfo->irq) -unbind_from_irqhandler (rinfo->irq, rinfo); - rinfo->evtchn = rinfo->irq =0 ; }static void blkif_free (struct blkfront_info *info,int suspend)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/2214 serial: core: shut down initialized port on removal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Putko <[email protected]>
[ Upstream commit 810d467c11f0c85107874d08dfdd11acba6aa0c0 ]
When a serial port configured as a console is opened and subsequently closed, tty_port_shutdown() skips invoking port->ops->shutdown() because port->console is true. As a result, tty_port_initialized() remains true and the port's interrupt handler stays registered in the irq subsystem.
If the underlying device is later unbound or removed (e.g. via sysfs driver unbind or device hot-unplug), serial_core_remove_one_port() unregisters the console, frees uport->name via kfree(), and tears down the port without shutting it down or freeing its IRQ. Consequently, the irqaction descriptor remains registered in genirq with action->name pointing to freed memory.
This triggers a use-after-free read whenever genirq accesses action->name, such as when reading /proc/interrupts:
BUG: KASAN: slab-use-after-free in string+0x476/0x570 Call Trace: string+0x476/0x570 vsnprintf+0x422/0x1300 seq_printf+0x... show_interrupts+...
Fix this by acquiring port->mutex in serial_core_remove_one_port() after console unregistration, clearing port->console under the mutex to prevent data races with concurrent tty_port_shutdown(), and invoking uart_shutdown(NULL, state) if the port remains initialized. This ensures that port->ops->shutdown() is called and the IRQ is freed before kfree(uport->name).
--- drivers/tty/serial/serial_core.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/tty/serial/serial_core.c +7 -0
@@ -3071,6 +3071,13 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)if (uart_console (uport))unregister_console (uport->cons); +mutex_lock (&port->mutex); + port->console = false; + +if (tty_port_initialized (port)) +uart_shutdown (NULL , state); +mutex_unlock (&port->mutex); +/* * Free the port IO and memory resources, if any. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/2214 ovl: set OVL_WHITEOUTS before publishing the upper dir
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit cbec8610ec5aaf35df50094ff639febc23f20773 ]
Listing a directory while it is copied up causes a use-after-free of the readdir cache.
A merge directory must never be iterated as a real upper directory:
that mode frees the cache in OVL_I(inode)->cache without looking at its refcount, while files opened in merged mode still use it. ovl_copy_up_workdir() publishes the upper dentry before it sets OVL_WHITEOUTS, and ovl_dir_open() samples both without a lock, so an open between the two stores finds the upper directory and takes it for a real one.
With a delay between the two stores, an unprivileged process that listed a directory during its copy-up saw only "." and "..", and its next getdents freed the readdir cache of another descriptor.
Fix this by setting OVL_WHITEOUTS before ovl_inode_update(), so that ovl_dir_reset() agrees with ovl_dir_open(), and by testing OVL_TYPE_MERGE() of the path type in ovl_dir_open(), so that an open that observes the upper dentry never iterates a merge dir as a real dir, regardless of the order in which it observes the flag.
--- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/readdir.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
fs/overlayfs/copy_up.c +1 -1
@@ -711,9 +711,9 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)if (!c->metacopy)ovl_set_upperdata (d_inode (c->dentry)); inode =d_inode (c->dentry); -ovl_inode_update (inode, temp);if (S_ISDIR (inode->i_mode))ovl_set_flag (OVL_WHITEOUTS , inode); +ovl_inode_update (inode, temp); unlock:unlock_rename (c->workdir, c->destdir);
fs/overlayfs/readdir.c +2 -1
@@ -942,7 +942,8 @@ static int ovl_dir_open(struct inode *inode, struct file *file)return PTR_ERR (realfile); } od->realfile = realfile; - od->is_real =ovl_dir_is_real (file->f_path.dentry); + od->is_real = !OVL_TYPE_MERGE (type) && + !ovl_test_flag (OVL_WHITEOUTS , inode); od->is_upper =OVL_TYPE_UPPER (type); file->private_data = od;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/2214 s390/cpum_cf: Check session mask before cpu offline
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sumanth Korikkar <[email protected]>
[ Upstream commit 99a95985dfc85eecad97f0991a2401d2fcef294c ]
cfset_offline_cpu() stops counter sets for every active session without checking whether the outgoing cpu belongs to the session mask.
For example, run an hwctr session on cpu0 and a cpu bound perf event on cpu1:
lshwc -l 9999 -i 5 0:b
perf stat -C 1 -e cpum_cf/CPU_CYCLES/ sleep 120
chcpu -d 1
chcpu -e 1
Although the hwctr session does not include cpu1, cfset_offline_cpu() decrements its counter set reference count. The subsequent perf teardown decrements it again, causing it to underflow.
The perf event keeps the percpu state alive across hotplug. When cpu1 comes online, the hwctr session is started there and the reference count moves from -1 to 0. Stopping the hwctr session then decrements it to -1 again, so the zero triggered counter set disable path is skipped.
Check the session mask before stopping counter sets on the outgoing cpu. This prevents the unmatched decrement and the resulting reference count underflow.
--- arch/s390/kernel/perf_cpum_cf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/perf_cpum_cf.c +2 -1
@@ -1223,7 +1223,8 @@ int cfset_offline_cpu(unsigned int cpu)struct cfset_call_on_cpu_parm p;mutex_lock (&cfset_ctrset_mutex); -if (cfset_request.ctrset) { +if (cfset_request.ctrset && +cpumask_test_cpu (cpu, &cfset_request.mask)) { p.sets = cfset_request.ctrset;cfset_ioctl_off (&p);cpumask_clear_cpu (cpu, &cfset_request.mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/2214 HID: wacom: Advertise SW_MUTE_DEVICE capability prior to registration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit ba16e5ffbaa10fde960918d69af5e49f2b3fdd5e ]
Input subsystem guidelines require that device capabilities are advertised before the input device is registered. The Wacom driver was violating this by advertising the SW_MUTE_DEVICE capability post-registration in wacom_set_shared_values() (and duplicating it in device-specific setup cases).
Resolve this by moving the SW_MUTE_DEVICE capability setup to wacom_setup_touch_input_capabilities() for all touch devices that support it.
For generic touch devices whose capabilities depend on mute switch usages parsed from a sibling Pen/Pad interface, defer registration with -EPROBE_DEFER until the sibling has parsed its descriptors and initialized shared capabilities.
--- drivers/hid/wacom_sys.c | 88 ++++++++++++++++++++++++++++++++++------- drivers/hid/wacom_wac.c | 5 +++ 2 files changed, 78 insertions(+), 15 deletions(-)
drivers/hid/wacom_sys.c +73 -15
@@ -924,6 +924,9 @@ static int wacom_add_shared_data(struct hid_device *hdev) wacom_wac->shared = &data->shared; +if (wacom_wac->has_mute_touch_switch) +WRITE_ONCE (wacom_wac->shared->has_mute_touch_switch, true); + retval =devm_add_action (&hdev->dev, wacom_remove_shared_data, wacom);if (retval) {mutex_unlock (&wacom_udev_list_lock);
@@ -931,11 +934,6 @@ static int wacom_add_shared_data(struct hid_device *hdev)return retval; } -if (wacom_wac->features.device_type &WACOM_DEVICETYPE_TOUCH ) - wacom_wac->shared->touch = hdev; -else if (wacom_wac->features.device_type &WACOM_DEVICETYPE_PEN ) - wacom_wac->shared->pen = hdev; - out:mutex_unlock (&wacom_udev_list_lock);return retval;
@@ -2336,13 +2334,12 @@ static void wacom_release_resources(struct wacom *wacom)static void wacom_set_shared_values (struct wacom_wac *wacom_wac) { -if (wacom_wac->features.device_type &WACOM_DEVICETYPE_TOUCH ) { - wacom_wac->shared->type = wacom_wac->features.type; - wacom_wac->shared->touch_input = wacom_wac->touch_input; - } + struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); + +guard (mutex)(&wacom_udev_list_lock);if (wacom_wac->has_mute_touch_switch) { - wacom_wac->shared->has_mute_touch_switch = true; +WRITE_ONCE (wacom_wac->shared->has_mute_touch_switch, true);/* Hardware touch switch may be off. Wait until * we know the switch state to decide is_touch_on. * Softkey state should be initialized to "on" to
@@ -2352,12 +2349,67 @@ static void wacom_set_shared_values(struct wacom_wac *wacom_wac)WRITE_ONCE (wacom_wac->shared->is_touch_on, true); } -if (wacom_wac->shared->has_mute_touch_switch && - wacom_wac->shared->touch_input) { -set_bit (EV_SW , wacom_wac->shared->touch_input->evbit); -input_set_capability (wacom_wac->shared->touch_input,EV_SW , -SW_MUTE_DEVICE ); +if (wacom_wac->features.device_type &WACOM_DEVICETYPE_TOUCH ) { + wacom_wac->shared->type = wacom_wac->features.type; + wacom_wac->shared->touch_input = wacom_wac->touch_input; + wacom_wac->shared->touch = wacom->hdev; + }else if (wacom_wac->features.device_type &WACOM_DEVICETYPE_PEN ) { +/* Pairs with smp_load_acquire() in wacom_sibling_pending() */ +smp_store_release (&wacom_wac->shared->pen, wacom->hdev); + } +} + +static bool wacom_sibling_pending (struct wacom *wacom) +{ +const struct wacom_features *features = &wacom->wacom_wac.features; +struct hid_device *hdev = wacom->hdev; +struct usb_interface *sibling_intf; +int ifnum; + +if (features->type !=HID_GENERIC || + !(features->device_type &WACOM_DEVICETYPE_TOUCH )) +return false; + +if (wacom->wacom_wac.shared) { +/* Pairs with smp_store_release() in wacom_set_shared_values() */ +if (smp_load_acquire (&wacom->wacom_wac.shared->pen)) +return false; } + +if (!hid_is_usb (hdev) || !wacom->usbdev || !wacom->intf || + !wacom->intf->cur_altsetting) +return false; + + ifnum = wacom->intf->cur_altsetting->desc.bInterfaceNumber; + +/* +* On composite Wacom devices, the Pen interface is always interface 0. +* If the Touch interface is interface 0, there is no sibling Pen +* interface on this device (standalone touch device). +*/ +if (ifnum ==0 ) +return false; + +/* Look for the sibling Pen interface at interface 0 */ + sibling_intf =usb_ifnum_to_if (wacom->usbdev,0 ); +if (!sibling_intf || !sibling_intf->cur_altsetting) +return false; + +if (sibling_intf->cur_altsetting->desc.bInterfaceClass != +USB_INTERFACE_CLASS_HID ) +return false; + +if (sibling_intf->cur_altsetting->desc.bInterfaceSubClass ==1 && + (sibling_intf->cur_altsetting->desc.bInterfaceProtocol ==1 || + sibling_intf->cur_altsetting->desc.bInterfaceProtocol ==2 )) +return false; + +/* +* Interface 0 is a candidate HID interface on this composite device +* whose probe has not completed yet (shared->pen is NULL). Defer until +* interface 0 finishes probing and registers shared values. +*/ +return true; }static int wacom_parse_and_register (struct wacom *wacom,bool wireless)
@@ -2433,6 +2485,11 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)if (error) goto fail; +if (wacom_sibling_pending (wacom)) { + error = -EPROBE_DEFER ; + goto fail; + } +if (!(features->device_type &WACOM_DEVICETYPE_WL_MONITOR ) && (features->quirks &WACOM_QUIRK_BATTERY )) { error =wacom_initialize_battery (wacom);
@@ -2497,6 +2554,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless) fail_hw_stop:hid_hw_stop (hdev); +cancel_delayed_work_sync (&wacom->init_work); fail:wacom_release_resources (wacom);return error;
drivers/hid/wacom_wac.c +5 -0
@@ -3912,6 +3912,11 @@ int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,if (features->type ==HID_GENERIC ) {hid_dbg (hdev,"generic touch setup\n" ); +if (wacom_wac->has_mute_touch_switch || + (wacom_wac->shared &&READ_ONCE (wacom_wac->shared->has_mute_touch_switch))) { +input_set_capability (input_dev,EV_SW ,SW_MUTE_DEVICE ); + wacom_wac->has_mute_touch_switch = true; + }/* setup has already been done */ return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/2214 HID: wacom: Setup SW_MUTE_DEVICE according to the order of input registration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ping Cheng <[email protected]>
[ Upstream commit 97ce491bcef2d231b8d51cee8e579183319a5ba4 ]
The refactored SW_MUTE_DEVICE code assumed that stylus will be the first regiestered input. In reality, touch can be registered before stylus, such as the Wacom Cintiq Pro 13 and 16.
This patch covers both touch-first and stylus-first cases.
--- drivers/hid/wacom_wac.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/hid/wacom_wac.c +30 -3
@@ -3912,10 +3912,18 @@ int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,if (features->type ==HID_GENERIC ) {hid_dbg (hdev,"generic touch setup\n" ); -if (wacom_wac->has_mute_touch_switch || - (wacom_wac->shared &&READ_ONCE (wacom_wac->shared->has_mute_touch_switch))) { + +/* +* This is to setup the touch switch for those devices that report +* pen interface first. The setup can only be done here since this +* routine is only called once. When we are here, the shared +* has_mute_touch_switch has been set by the pad. + +* There are two ways of reporting inputs from firmware: stylus first +* or touch first. This path covers the stylus input first case. +*/ +if (wacom_wac->shared &&READ_ONCE (wacom_wac->shared->has_mute_touch_switch)) {input_set_capability (input_dev,EV_SW ,SW_MUTE_DEVICE ); - wacom_wac->has_mute_touch_switch = true; }/* setup has already been done */ return 0 ;
@@ -4338,7 +4346,26 @@ int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,break ;case INTUOSHT3_BT : +break ; +case HID_GENERIC : +if (wacom_wac->shared) { +/* +* The setup of touch switch capability can only be done +* here for those devices, such as Cintiq Pro 13 and 16, +* that have touch input registered before stylus and pad +* inputs. +* +* There are two ways of reporting inputs from firmware: +* stylus first or touch first. This path covers the touch +* input first case. +*/ +if (wacom_wac->has_mute_touch_switch && + wacom_wac->shared->touch_input) { +input_set_capability (wacom_wac->shared->touch_input, +EV_SW ,SW_MUTE_DEVICE ); + } + }break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/2214 media: microchip-isc: take a reference on the parsed endpoints
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit f2eb2fd388bf3f1959556a326e797cacca341c86 ]
for_each_endpoint_of_node() drops the reference on the current node as it advances. xisc_parse_dt() and isc_parse_dt() store the node in subdev_entity->epn and release it later with of_node_put(), but never took their own reference, so the stored pointer refers to an already-released node. This underflows the refcount and can use-after-free, reachable through the camera device tree overlay.
Take a reference with of_node_get() when storing the node, and drop it in microchip_isc_subdev_cleanup() so the entities the bind loop never reaches on an early exit do not leak it.
--- drivers/media/platform/atmel/atmel-isc-base.c | 6 ++++++ drivers/media/platform/atmel/atmel-sama5d2-isc.c | 5 ++++- drivers/media/platform/atmel/atmel-sama7g5-isc.c | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +6 -0
@@ -2219,6 +2219,12 @@ void isc_subdev_cleanup(struct isc_device *isc)list_for_each_entry (subdev_entity, &isc->subdev_entities, list) {v4l2_async_notifier_unregister (&subdev_entity->notifier);v4l2_async_notifier_cleanup (&subdev_entity->notifier); +/* +* Release the endpoint reference taken while parsing. It is +* NULL for entities the bind loop already consumed, so this +* only drops the ones left over on an early exit. +*/ +of_node_put (subdev_entity->epn); }INIT_LIST_HEAD (&isc->subdev_entities);
drivers/media/platform/atmel/atmel-sama5d2-isc.c +4 -1
@@ -354,7 +354,7 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc) ret = -ENOMEM ;break ; } - subdev_entity->epn = epn; + subdev_entity->epn =of_node_get (epn); flags = v4l2_epn.bus.parallel.flags;
@@ -375,6 +375,9 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc) }of_node_put (epn); +list_for_each_entry (subdev_entity, &isc->subdev_entities, list) +of_node_put (subdev_entity->epn); +return ret; }
drivers/media/platform/atmel/atmel-sama7g5-isc.c +4 -1
@@ -344,7 +344,7 @@ static int xisc_parse_dt(struct device *dev, struct isc_device *isc) ret = -ENOMEM ;break ; } - subdev_entity->epn = epn; + subdev_entity->epn =of_node_get (epn); flags = v4l2_epn.bus.parallel.flags;
@@ -368,6 +368,9 @@ static int xisc_parse_dt(struct device *dev, struct isc_device *isc) }of_node_put (epn); +list_for_each_entry (subdev_entity, &isc->subdev_entities, list) +of_node_put (subdev_entity->epn); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/2214 media: s5p-mfc: use timer_shutdown_sync() for the self-rearming watchdog
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 63069b5917cba2e15b1a78b3f4ff99e45102c56f ]
The MFC watchdog timer (s5p_mfc_watchdog) is self-rearming: every callback re-arms itself with add_timer() and, on a timeout, schedules watchdog_work. s5p_mfc_remove() tears this down with timer_delete_sync() followed by flush_work().
timer_delete_sync() dequeues the timer and waits for a callback that is already running, but it does not prevent a subsequent re-arm. Because the watchdog callback re-arms via add_timer(), this is the wrong shutdown
primitive: once the wait returns nothing guarantees a just-queued re-arm will not fire later, dereferencing dev (clock on/off, deinit_hw, load_firmware, init_hw) after video_unregister_device(), DMA teardown and s5p_mfc_final_pm() have run, a potential use-after-free.
Use timer_shutdown_sync(), which puts the timer into a shutdown state so that any add_timer()/mod_timer() from the callback becomes a no-op and no later firing is possible. Switch flush_work() to cancel_work_sync() so any watchdog_work that was already queued before the timer was stopped is cancelled rather than allowed to run to completion against the torn-down device.
This issue was found by an in-house static analysis tool. No runtime reproducer is available.
--- drivers/media/platform/s5p-mfc/s5p_mfc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc.c +2 -2
@@ -1447,8 +1447,8 @@ static int s5p_mfc_remove(struct platform_device *pdev) }mutex_unlock (&dev->mfc_mutex); -del_timer_sync (&dev->watchdog_timer); -flush_work (&dev->watchdog_work); +timer_shutdown_sync (&dev->watchdog_timer); +cancel_work_sync (&dev->watchdog_work);video_unregister_device (dev->vfd_enc);video_unregister_device (dev->vfd_dec);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/2214 scsi: dc395x: sync the waiting_timer before freeing the host
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 0b1a79f2791a06f139dce5450e487307cf0e241f ]
The waiting_timer callback re-arms itself and takes the host lock. adapter_uninit() currently stops it with timer_delete(), which does not wait for a callback already running on another CPU. The final scsi_host_put() that frees the host (and the host lock the callback dereferences) runs right after adapter_uninit(), so a concurrent or just re-armed callback can fire after the free, leaving a potential use-after-free window.
Replace timer_delete() with timer_shutdown_sync() at the top of adapter_uninit(), before the host-lock section: the timer is dequeued, a running callback is waited for and rearming is blocked before the chip is halted, so it cannot fire at all once the adapter has ceased to function. Waiting outside the lock avoids the self-deadlock that would result from syncing a callback blocked on the lock we still hold.
No shutdown is needed for selto_timer because it has no reachable armer or callback.
This issue was found by an in-house static analysis tool.
--- drivers/scsi/dc395x.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/scsi/dc395x.c +4 -6
@@ -4416,13 +4416,11 @@ static void adapter_uninit_chip(struct AdapterCtlBlk *acb)static void adapter_uninit (struct AdapterCtlBlk *acb) {unsigned long flags; -DC395x_LOCK_IO (acb->scsi_host, flags); -/* remove timers */ -if (timer_pending (&acb->waiting_timer)) -del_timer (&acb->waiting_timer); -if (timer_pending (&acb->selto_timer)) -del_timer (&acb->selto_timer); +/* Drain the self-rearming timer; must not run under host_lock. */ +timer_shutdown_sync (&acb->waiting_timer); + +DC395x_LOCK_IO (acb->scsi_host, flags);adapter_uninit_chip (acb);adapter_remove_and_free_all_devices (acb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/2214 media: rc: Fix ABBA deadlock by making locks more fine grained
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit c6d68866ad8aa1e957a3e5a6ede971148f1e3d59 ]
The ir_raw_event_unregister() function takes the ir_raw_handler_lock first and then the rc_dev->lock. Other functions like change_protocol do this in the reverse order.
This means that an ir decoder module unload and writing to the protocol sysfs file can cause a deadlock.
ir_raw_handler_lock protects the client list, amongst other things. Split this out into a separate lock so we can ensure the locking order is always the same.
--- drivers/media/rc/rc-ir-raw.c | 38 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-)
drivers/media/rc/rc-ir-raw.c +24 -14
@@ -10,7 +10,8 @@#include <linux/sched.h> #include "rc-core-priv.h" -/* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ +/* Used to keep track of IR raw clients, protected by ir_raw_client_lock */ +static DEFINE_MUTEX (ir_raw_client_lock);static LIST_HEAD (ir_raw_client_list);/* Used to handle IR raw handler extensions */
@@ -290,13 +291,6 @@ static int change_protocol(struct rc_dev *dev, u64 *rc_proto)return 0 ; } -static void ir_raw_disable_protocols (struct rc_dev *dev,u64 protocols) -{ -mutex_lock (&dev->lock); - dev->enabled_protocols &= ~protocols; -mutex_unlock (&dev->lock); -} -/** * ir_raw_gen_manchester() - Encode data with Manchester (bi-phase) modulation. * @ev: Pointer to pointer to next free event. *@ev is incremented for
@@ -634,15 +628,18 @@ int ir_raw_event_register(struct rc_dev *dev) {struct task_struct *thread; +/* Holding dev->lock could result in a dead-lock */ +lockdep_assert_not_held (&dev->lock); + thread =kthread_run (ir_raw_event_thread, dev->raw,"rc%u" , dev->minor);if (IS_ERR (thread))return PTR_ERR (thread); dev->raw->thread = thread; -mutex_lock (&ir_raw_handler_lock); +mutex_lock (&ir_raw_client_lock);list_add_tail (&dev->raw->list, &ir_raw_client_list); -mutex_unlock (&ir_raw_handler_lock); +mutex_unlock (&ir_raw_client_lock);return 0 ; }
@@ -666,8 +663,10 @@ void ir_raw_event_unregister(struct rc_dev *dev)kthread_stop (dev->raw->thread);del_timer_sync (&dev->raw->edge_handle); -mutex_lock (&ir_raw_handler_lock); +mutex_lock (&ir_raw_client_lock);list_del (&dev->raw->list); + +mutex_lock (&ir_raw_handler_lock);list_for_each_entry (handler, &ir_raw_handler_list, list)if (handler->raw_unregister && (handler->protocols & dev->enabled_protocols))
@@ -683,6 +682,8 @@ void ir_raw_event_unregister(struct rc_dev *dev)* "device gone" is checked. */ mutex_unlock (&ir_raw_handler_lock); + +mutex_unlock (&ir_raw_client_lock); }/*
@@ -705,15 +706,24 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)struct ir_raw_event_ctrl *raw;u64 protocols = ir_raw_handler->protocols; +mutex_lock (&ir_raw_client_lock); +mutex_lock (&ir_raw_handler_lock);list_del (&ir_raw_handler->list); +atomic64_andnot (protocols, &available_protocols); +mutex_unlock (&ir_raw_handler_lock); +list_for_each_entry (raw, &ir_raw_client_list, list) { +mutex_lock (&raw->dev->lock); +mutex_lock (&ir_raw_handler_lock);if (ir_raw_handler->raw_unregister && (raw->dev->enabled_protocols & protocols)) ir_raw_handler->raw_unregister (raw->dev); -ir_raw_disable_protocols (raw->dev, protocols); + raw->dev->enabled_protocols &= ~protocols; +mutex_unlock (&ir_raw_handler_lock); +mutex_unlock (&raw->dev->lock); } -atomic64_andnot (protocols, &available_protocols); -mutex_unlock (&ir_raw_handler_lock); + +mutex_unlock (&ir_raw_client_lock); }EXPORT_SYMBOL (ir_raw_handler_unregister);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/2214 ocfs2: snapshot dentry names in file and setattr traces
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8cd3ff30659775a6831c66687a69d2b83d163591 ]
Patch series "ocfs2: stabilize dentry names in file and setattr traces", v4.
Snapshot names at all six users of ocfs2__file_ops and at the separate setattr event. Patch 1 handles the five ordinary file-operation callers and setattr. Patch 2 handles release separately to preserve its locked open-count sample and take the snapshot outside that critical section.
The release explanation distinguishes its existing RCU lifetime coverage from name/length consistency. It does not claim that the ordinary callers' external-name UAF interleaving crosses the held inode spinlock. The release source change is unchanged from v3.
Patch 1 also removes the read callback's redundant NULL-inode check. The two patches apply independently and leave trace formats unchanged.
This patch (of 2):
The open, fsync, read, write and splice-read trace calls pass the live dentry name and length to the shared ocfs2__file_ops event class. ocfs2_setattr() passes the same unprotected arguments to its own event. Both events size and copy a __string field separately. A reference to the dentry does not pin the external storage backing an individual name.
With an event enabled, a caller can be preempted after loading the name pointer. A long-to-short rename can then replace the name and reclaim its old external allocation before the trace callback sizes or copies it, provided no other snapshot retains that allocation.
The setattr inode lock does not exclude every rename: a same-directory rename of a source directory need not take that directory's inode lock. It can therefore change the dentry name while setattr records its event. Inline names and separately loaded lengths can also change during trace record sizing and copying.
Take a dentry name snapshot around each of these six trace calls and pass both the string and length from the snapshot. Check event enablement before taking a snapshot. Keep the event classes and formats unchanged.
Also remove the redundant NULL-inode check in the read callback. file_inode() returns the open file's inode, which is already used by the trace call above the check.
The historical report below is from the read path.
KASAN report as below:
BUG: KASAN: slab-use-after-free in strlen+0x85/0xa0
Read of size 1 at addr ffff88810a5b2b18 by task python3/496 [CPU and host details omitted.]
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? strlen+0x85/0xa0
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20e/0x420
? strlen+0x85/0xa0
kasan_report+0xe0/0x110
? strlen+0x85/0xa0
strlen+0x85/0xa0
trace_event_raw_event_ocfs2__file_ops+0xf0/0x480
? __pfx_trace_event_raw_event_ocfs2__file_ops+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? pmbd_probe_hit_cookie+0xe7/0x1c0
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_pmbd_probe_hit_cookie+0x10/0x10
ocfs2_file_read_iter+0x6cd/0xb30
? __pfx_ocfs2_file_read_iter+0x10/0x10
? selinux_file_permission+0x11d/0x540
? srso_alias_return_thunk+0x5/0xfbef5
? security_file_permission+0x26/0x80
vfs_read+0x7d2/0xc20
? __pfx_vfs_read+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_do_sys_openat2+0x10/0x10
ksys_read+0x111/0x200
? __pfx_ksys_read+0x10/0x10
? irqentry_exit+0xbe/0x820
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on_prepare+0x11d/0x150
? srso_alias_return_thunk+0x5/0xfbef5
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
[User register dump omitted.]
</TASK>
Allocated by task 489:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_noprof+0x2de/0x780
__d_alloc+0x5fc/0x8c0
d_alloc_parallel+0x106/0x11d0
lookup_open+0x3ff/0x13e0
path_openat+0x95e/0x2020
do_file_open+0x21e/0x470
do_sys_openat2+0xf4/0x1b0
__x64_sys_openat+0x136/0x1e0
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 0:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
__rcu_free_sheaf_prepare+0x65/0x2a0
rcu_free_sheaf_nobarn+0x1d/0x50
rcu_core+0x6be/0x1ed0
handle_softirqs+0x1fa/0x8d0
__irq_exit_rcu+0x113/0x1e0
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x6c/0x80
asm_sysvec_apic_timer_interrupt+0x1a/0x20
The buggy address belongs to the object at ffff88810a5b2b00
which belongs to the cache kmalloc-rcl-192 of size 192
The buggy address is located 24 bytes inside of
freed 192-byte region [ffff88810a5b2b00, ffff88810a5b2bc0)
[Page and shadow-memory dumps omitted.]--- fs/ocfs2/file.c | 84 +++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 31 deletions(-)
fs/ocfs2/file.c +53 -31
@@ -84,10 +84,17 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)int mode = file->f_flags;struct ocfs2_inode_info *oi =OCFS2_I (inode); -trace_ocfs2_file_open (inode, file, file->f_path.dentry, - (unsigned long long )oi->ip_blkno, - file->f_path.dentry->d_name.len, - file->f_path.dentry->d_name.name, mode); +if (trace_ocfs2_file_open_enabled ()) { +struct dentry *dentry = file->f_path.dentry; +struct name_snapshot name; + +take_dentry_name_snapshot (&name, dentry); +trace_ocfs2_file_open (inode, file, dentry, + oi->ip_blkno, + name.name.len, name.name.name, + mode); +release_dentry_name_snapshot (&name); + }if (file->f_mode &FMODE_WRITE ) { status =dquot_initialize (inode);
@@ -173,11 +180,17 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,tid_t commit_tid;bool needs_barrier = false; -trace_ocfs2_sync_file (inode, file, file->f_path.dentry, - oi->ip_blkno, - file->f_path.dentry->d_name.len, - file->f_path.dentry->d_name.name, - (unsigned long long )datasync); +if (trace_ocfs2_sync_file_enabled ()) { +struct dentry *dentry = file->f_path.dentry; +struct name_snapshot name; + +take_dentry_name_snapshot (&name, dentry); +trace_ocfs2_sync_file (inode, file, dentry, + oi->ip_blkno, + name.name.len, name.name.name, + (unsigned long long )datasync); +release_dentry_name_snapshot (&name); + }if (ocfs2_is_hard_readonly (osb) ||ocfs2_is_soft_readonly (osb))return -EROFS ;
@@ -1129,15 +1142,19 @@ int ocfs2_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,int had_lock;struct ocfs2_lock_holder oh; -trace_ocfs2_setattr (inode, dentry, - (unsigned long long )OCFS2_I (inode)->ip_blkno, - dentry->d_name.len, dentry->d_name.name, - attr->ia_valid, - attr->ia_valid &ATTR_MODE ? attr->ia_mode :0 , - attr->ia_valid &ATTR_UID ? +if (trace_ocfs2_setattr_enabled ()) { +struct name_snapshot name; + +take_dentry_name_snapshot (&name, dentry); +trace_ocfs2_setattr (inode, dentry,OCFS2_I (inode)->ip_blkno, + name.name.len, name.name.name, attr->ia_valid, + attr->ia_valid &ATTR_MODE ? attr->ia_mode :0 , + attr->ia_valid &ATTR_UID ?from_kuid (&init_user_ns, attr->ia_uid) :0 , - attr->ia_valid &ATTR_GID ? + attr->ia_valid &ATTR_GID ?from_kgid (&init_user_ns, attr->ia_gid) :0 ); +release_dentry_name_snapshot (&name); + }/* ensuring we don't even attempt to truncate a symlink */ if (S_ISLNK (inode->i_mode))
@@ -2383,11 +2400,17 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,int direct_io = iocb->ki_flags &IOCB_DIRECT ?1 :0 ;int nowait = iocb->ki_flags &IOCB_NOWAIT ?1 :0 ; -trace_ocfs2_file_write_iter (inode, file, file->f_path.dentry, - (unsigned long long )OCFS2_I (inode)->ip_blkno, - file->f_path.dentry->d_name.len, - file->f_path.dentry->d_name.name, - (unsigned int )from->nr_segs);/* GRRRRR */ +if (trace_ocfs2_file_write_iter_enabled ()) { +struct dentry *dentry = file->f_path.dentry; +struct name_snapshot name; + +take_dentry_name_snapshot (&name, dentry); +trace_ocfs2_file_write_iter (inode, file, dentry, +OCFS2_I (inode)->ip_blkno, + name.name.len, name.name.name, + (unsigned int )from->nr_segs); +release_dentry_name_snapshot (&name); + }if (!direct_io && nowait)return -EOPNOTSUPP ;
@@ -2533,17 +2556,16 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,int direct_io = iocb->ki_flags &IOCB_DIRECT ?1 :0 ;int nowait = iocb->ki_flags &IOCB_NOWAIT ?1 :0 ; -trace_ocfs2_file_read_iter (inode, filp, filp->f_path.dentry, - (unsigned long long )OCFS2_I (inode)->ip_blkno, - filp->f_path.dentry->d_name.len, - filp->f_path.dentry->d_name.name, - to->nr_segs);/* GRRRRR */ - +if (trace_ocfs2_file_read_iter_enabled ()) { +struct dentry *dentry = filp->f_path.dentry; +struct name_snapshot name; -if (!inode) { - ret = -EINVAL ; -mlog_errno (ret); - goto bail; +take_dentry_name_snapshot (&name, dentry); +trace_ocfs2_file_read_iter (inode, filp, dentry, +OCFS2_I (inode)->ip_blkno, + name.name.len, name.name.name, + to->nr_segs); +release_dentry_name_snapshot (&name); }if (!direct_io && nowait)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/2214 drm/nouveau: reject zero-size notifier object allocation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenhao Wan <[email protected]>
[ Upstream commit 38125d38d850bd2fdd5d7840c3bd52d9d208995b ]
nouveau_abi16_ioctl_notifierobj_alloc() passes the userspace-controlled info->size to nvkm_mm_head() as both size_max and size_min without a lower bound. A zero size satisfies the allocator's "e - s < size_min" gate (size_min == 0 makes the unsigned comparison inert) and yields a zero-length node, after which
args.limit = ntfy->node->offset + ntfy->node->length - 1;
underflows (offset 0, length 0 -> 0xffffffff) into an oversized ~4 GiB DMA window. The dma object constructor only rejects start > limit, so the validly ordered [base, base + 0xffffffff] range passes and is programmed into the GPU DMA context. The ioctl is DRM_RENDER_ALLOW, so any render node client can trigger this on pre-Fermi hardware.
Reject a zero-size request before allocating anything.
--- drivers/gpu/drm/nouveau/nouveau_abi16.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/nouveau/nouveau_abi16.c +4 -0
@@ -534,6 +534,10 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)return nouveau_abi16_put (abi16, -EINVAL ); client = abi16->device.object.client; +/* zero size yields a zero-length node, underflowing args.limit */ +if (unlikely (!info->size)) +return nouveau_abi16_put (abi16, -EINVAL ); + chan =nouveau_abi16_chan (abi16, info->channel);if (!chan)return nouveau_abi16_put (abi16, -ENOENT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/2214 media: streamzap: Add missing rc_unregister_device()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 3982d2eeb1bdf7a9c14e4ff69015cb456f11da51 ]
If usb_submit_urb() fails during probe, then the error path is missing a call to rc_unregister_device(), which will leak various things like the input device.
--- drivers/media/rc/streamzap.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/rc/streamzap.c +1 -0
@@ -403,6 +403,7 @@ static int streamzap_probe(struct usb_interface *intf,return 0 ; rc_submit_fail: +rc_unregister_device (sz->rdev);rc_free_device (sz->rdev);usb_set_intfdata (intf,NULL ); rc_dev_fail:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/2214 media: redrat3: Ensure we dont read beyond the end of the packet
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit cd49f62f4161c7340d9c9f53b67757575900c0bc ]
The length and offset is provided by the usb device, so it should be validated.
--- drivers/media/rc/redrat3.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/media/rc/redrat3.c +16 -0
@@ -358,8 +358,24 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)/* process each rr3 encoded byte into an int */ sig_size =be16_to_cpu (rr3->irdata.sig_size); + +/* +* Note we are not checking if we are reading beyond the end of the +* packet which was sent, and reading stale data. If the device +* sends a packet which is short then we get garbage IR, but no +* out of bounds read. +*/ +if (sig_size >RR3_MAX_SIG_SIZE ) { +dev_err (dev,"length %u is incorrect\n" , sig_size); +return ; + } +for (i =0 ; i < sig_size; i++) { offset = rr3->irdata.sigdata[i]; +if (offset >=RR3_DRIVER_MAXLENS ) { +dev_err (dev,"offset %u is incorrect\n" , offset); +return ; + } val =get_unaligned_be16 (&rr3->irdata.lens[offset]);/* we should always get pulse/space/pulse/space samples */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/2214 media: redrat3: Ensure all urbs are suspended
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 1582f545273f2aa4eb4ee6f3a89b433f5c85c68f ]
Ensure that the learn urb is stopped before suspend.
--- drivers/media/rc/redrat3.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/rc/redrat3.c +1 -0
@@ -1168,6 +1168,7 @@ static int redrat3_dev_suspend(struct usb_interface *intf, pm_message_t message)usb_kill_urb (rr3->narrow_urb);usb_kill_urb (rr3->wide_urb);usb_kill_urb (rr3->flash_urb); +usb_kill_urb (rr3->learn_urb);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/2214 media: meson-ir-tx: Ensure clock is disabled on unbind
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 1517326fcc9dfdb9acb24f42472366ac1b4b8237 ]
clk_prepare_enable() needs a call to clk_disable_unprepare() on driver unbind. Make it devm managed.
--- drivers/media/rc/meson-ir-tx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/rc/meson-ir-tx.c +4 -3
@@ -288,11 +288,12 @@ static int meson_irtx_mod_clock_probe(struct meson_irtx *ir,if (!np)return -ENODEV ; - clock =devm_clk_get (ir->dev,"xtal" ); -if (IS_ERR (clock) ||clk_prepare_enable (clock)) + *clk_nr =IRB_MOD_XTAL3_CLK ; + + clock =devm_clk_get_enabled (ir->dev,"xtal" ); +if (IS_ERR (clock))return -ENODEV ; - *clk_nr =IRB_MOD_XTAL3_CLK ; ir->clk_rate =clk_get_rate (clock) /3 ;if (ir->clk_rate <IRB_MOD_1US_CLK_RATE ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/2214 media: ir-hix5hd2: Ensure rdev is setup before interrupts are enabled
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit f7509d2567cf92eeccc31c363a2e2ae43188930c ]
Once the interrupt handler is enabled, priv->rdev can be used. Ensure it is setup correctly so there is no race condition.
--- drivers/media/rc/ir-hix5hd2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/rc/ir-hix5hd2.c +3 -2
@@ -318,6 +318,9 @@ static int hix5hd2_ir_probe(struct platform_device *pdev)if (ret <0 ) goto clkerr; + priv->rdev = rdev; + priv->dev = dev; +if (devm_request_irq (dev, priv->irq, hix5hd2_ir_rx_interrupt,0 , pdev->name, priv) <0 ) {dev_err (dev,"IRQ %d register failed\n" , priv->irq);
@@ -325,8 +328,6 @@ static int hix5hd2_ir_probe(struct platform_device *pdev) goto regerr; } - priv->rdev = rdev; - priv->dev = dev;platform_set_drvdata (pdev, priv);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/2214 aio: prevent eventfd/epoll recursion on poll
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit 398e3fa789aa5ffddc8689d8cbc7b31e1824130c ]
aio_poll_wake() can complete a keyed poll request inline while the provider waitqueue lock is held. If the polled file is an epoll instance and the AIO result eventfd is watched by that same instance, signaling the result can feed back into epoll and try to take the provider waitqueue lock again.
For example, a timerfd wake can follow this path:
timerfd -> ep_poll_callback -> aio_poll_wake -> aio_complete
-> eventfd_signal -> ep_poll_callback -> ep_poll_safewake
The second ep_poll_safewake() recursively acquires ep->poll_wait.lock. eventfd_signal_allowed() does not prevent this because the wake chain did not begin in eventfd, so the task's eventfd recursion bit is still clear when aio_poll_wake() decides to complete inline.
An unprivileged process can construct this graph and make a CPU spin on the recursive lock. DEBUG_SPINLOCK reports "BUG: spinlock recursion", and lockdep reports the same epoll waitqueue lock as both held and requested.
Always defer eventfd-backed poll completions through the existing aio_poll_put_work() path. At this point the request has already been detached from the waitqueue and active request list, so the work item can publish the completion after the provider callback releases its lock. Poll completions without a result eventfd remain inline.
--- fs/aio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/aio.c +6 -1
@@ -1776,7 +1776,12 @@ static int aio_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,list_del_init (&req->wait.entry);list_del (&iocb->ki_list); iocb->ki_res.res =mangle_poll (mask); -if (iocb->ki_eventfd && !eventfd_signal_allowed ()) { +/* +* We hold an arbitrary provider waitqueue lock here. Signaling a +* result eventfd can feed back through epoll and try to take the same +* lock again. Defer all eventfd-backed poll completions. +*/ +if (iocb->ki_eventfd) { iocb =NULL ;INIT_WORK (&req->work, aio_poll_put_work);schedule_work (&req->work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/2214 ipc/mqueue: release notification resources during inode eviction
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit eb85469f0dd69ca145d63117450e14c31f67f698 ]
mqueue_flush_file() removes an mq_notify() registration only when the closing task belongs to the thread group stored in notify_owner.
A task in a separate thread group created with CLONE_FILES can register SIGEV_THREAD notification and exit without closing the shared file table. If another thread group then unlinks and last-closes the queue, ->flush() skips the registration and inode eviction loses the only pointers to its resources.
The orphaned registration permanently retains the notification skb, its netlink socket, a pid reference and a user namespace reference. An unprivileged process can repeat the sequence with new queues and sockets.
No inode users remain during eviction. Remove any stale registration there after dropping info->lock, since netlink_sendskb() may release the final socket reference.
--- ipc/mqueue.c | 7 +++++++ 1 file changed, 7 insertions(+)
ipc/mqueue.c +7 -0
@@ -530,6 +530,13 @@ static void mqueue_evict_inode(struct inode *inode)list_add_tail (&msg->m_list, &tmp_msg);kfree (info->node_cache);spin_unlock (&info->lock); +/* +* A shared file table can let the notification owner exit without +* running ->flush(). No users of the inode remain during eviction, so +* tear down any stale notification after dropping info->lock because +* netlink_sendskb() may release the final socket reference. +*/ +remove_notification (info);list_for_each_entry_safe (msg, nmsg, &tmp_msg, m_list) {list_del (&msg->m_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/2214 remoteproc: elf_loader: Bound the section header table
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit b32177ead5f8925aa66ceed2bd533a85196f4f0c ]
The rproc_elf_sanity_check() only checks the image is big enough to hold one section header. But find_table() walks e_shnum of them, and first dereferences the header at e_shstrndx to locate the section name table. Both fields are u16 and both come from the image, so an e_shstrndx of 65535 reads about 4 MB past the buffer.
The commit 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header") added the same check to the MDT loader, and says the header "is sanitized beforehand" under remoteproc. That is what this patch makes true.
Check e_shoff against the image size first, so the two bounds can use size_add() without an e_shoff above SIZE_MAX wrapping on 32-bit. The bounds are separate because e_shnum may be zero while find_table() still reads the e_shstrndx header.
--- drivers/remoteproc/remoteproc_elf_loader.c | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_elf_loader.c +21 -2
@@ -46,8 +46,9 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)struct elf32_hdr *ehdr;u32 elf_shdr_get_size;u64 phoff, shoff; +size_t shend;char class; -u16 phnum; +u16 phnum, shnum, shstrndx;if (!fw) {dev_err (dev,"failed to load %s\n" , name);
@@ -90,9 +91,27 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw) phoff =elf_hdr_get_e_phoff (class, fw->data); shoff =elf_hdr_get_e_shoff (class, fw->data); phnum =elf_hdr_get_e_phnum (class, fw->data); + shnum =elf_hdr_get_e_shnum (class, fw->data); + shstrndx =elf_hdr_get_e_shstrndx (class, fw->data); elf_shdr_get_size =elf_size_of_shdr (class); -if (fw->size < shoff + elf_shdr_get_size) { +/* keeps shoff in size_t range for the two bounds below */ +if (shoff > fw->size) { +dev_err (dev,"Section header table is out of bounds\n" ); +return -EINVAL ; + } + +if (shnum) { + shend =size_add (size_mul (elf_shdr_get_size, shnum), shoff); +if (shend > fw->size) { +dev_err (dev,"Section headers are out of bounds\n" ); +return -EINVAL ; + } + } + +/* find_table() reads the header at shstrndx even with no sections */ + shend =size_add (size_mul (elf_shdr_get_size, (size_t )shstrndx +1 ), shoff); +if (shend > fw->size) {dev_err (dev,"Image is too small\n" );return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/2214 microblaze: reserve the ABI argument-home area in the signal frame
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ramin Moussavi <[email protected]>
[ Upstream commit c5947d28c20955de897eeb98430f96db0494f7d7 ]
The MicroBlaze procedure call standard reserves [r1+0] for the return address and lets a callee store its incoming register arguments r5..r10 into the caller-provided home slots at [r1+4]..[r1+24]. When the kernel enters a signal handler it sets r1 to point at struct rt_sigframe, whose leading member is the siginfo prepared for the handler. A handler that homes its arguments - which an unoptimised (-O0) build always does - therefore overwrites the first 24 bytes of that siginfo, so an SA_SIGINFO handler reads corrupted values. The stores stay within siginfo (128 bytes) and do not reach the ucontext behind it.
Reserve the home area by making a seven-word gap -- the return-address slot plus the six argument slots, 28 bytes -- the first member of struct rt_sigframe, so the handler's argument stores land in scratch space instead of clobbering siginfo.
Tested on qemu-system-microblazeel (petalogix-s3adsp1800) with the uClibc-ng NPTL test suite: tst-timer4, tst-timer5, tst-mqueue5 and tst-signal6 pass; before this change they failed because the handler clobbered the signal frame.
--- arch/microblaze/kernel/signal.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/microblaze/kernel/signal.c +8 -0
@@ -49,6 +49,14 @@ struct sigframe { };struct rt_sigframe { +/* +* Home area for the handler's register arguments: the MicroBlaze +* ABI reserves [r1+0] for the return address and lets the callee +* store r5..r10 at [r1+4]..[r1+24], and r1 points at this frame +* when the handler is entered. Without the gap those stores +* corrupt frame->info. +*/ +unsigned long abi_gap[7 ];struct siginfo info;struct ucontext uc;unsigned long tramp[2 ];/* signal trampoline */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/2214 microblaze: dont clobber r3/r4 restored by rt_sigreturn
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ramin Moussavi <[email protected]>
[ Upstream commit da6829138a39fa3b9ec318ca54ff89af9d94d350 ]
ret_from_trap begins by storing the system call return values r3 and r4 back into the saved user pt_regs. That is right for an ordinary system call, but sys_rt_sigreturn() returns through the same path and has to be
transparent: restore_sigcontext() has just filled pt_regs from the signal frame, and every register must reach userspace exactly as saved. The two stores overwrite the restored r3/r4 with whatever the C function left in those registers.
Only r4 is actually lost, and that follows from how sigreturn is written everywhere rather than from chance. Architectures have sys_rt_sigreturn() return the restored return-value register precisely so that this writeback stores the restored value -- arm returns regs->ARM_r0, riscv and csky regs->a0, arc regs->r0 -- and microblaze does the same through *rval_p = regs->r3 in restore_sigcontext(). But the entry macros treat r3 and r4 as a pair, so ret_from_trap writes back two registers while a C function has only one return value; nothing carries the restored r4.
Commit 791d0a169b91 ("microblaze: Fix sys_rt_sigreturn_wrapper") introduced this in v2.6.37. The old wrapper saved r3/r4 before the call and reloaded them from pt_regs afterwards; switching brlid to brid removed the only point where they were reloaded, and the stores have been overwriting them ever since.
Fix it the way the sibling paths already behave: ret_from_irq and ret_from_exc restore the full register set and do not perform these stores at all. Label the instruction after the stores ret_from_trap_no_rval and enter there, biasing r15 by -8 so that the ABI return "rtsd r15, 8" lands on it; naming the entry rather than computing ret_from_trap + 8 keeps it correct if the number of stores ever changes. Restoring the old save/reload would work too, but costs four memory accesses and a branch to undo damage that is better not done.
Any value the compiler keeps in r4 across a signal is lost. The tightest windows are the lwx/swx compare-and-swap retry loops gcc emits for atomics:
in uClibc-ng's libc.so alone, 50 of 364 such loops hold the address in r4. This is not specific to one libc -- musl passes the address as "r"(p), and glibc has no microblaze atomic-machine.h and so uses gcc's __atomic builtins, which expand the same way. Triggering it needs threads plus a signal storm, which is why it survived 15 years.
Reproduced on qemu-system-microblazeel (petalogix-s3adsp1800) by running the uClibc-ng NPTL test tst-eintr1 40 times against an unchanged userspace:
on v7.2 built with gcc 16.2.0, 23 of 40 iterations died with SIGSEGV without this patch and 0 of 40 with it; on v7.0 built with gcc 12.5.0 the same comparison gave 6 of 40 against 0 of 40. The register dump of a failing iteration shows the signature: a zero r4 and a fault at address 0, while r3 came back intact.
--- arch/microblaze/kernel/entry.S | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
arch/microblaze/kernel/entry.S +16 -1
@@ -394,7 +394,13 @@ C_ENTRY(_user_exception): C_ENTRY(ret_from_trap): swi r3, r1, PT_R3 swi r4, r1, PT_R4 - +/* + * Entry point for returns that must not store r3/r4 back into pt_regs, + * i.e. rt_sigreturn, which has already restored them from the signal + * context. Reached as "rtsd r15, 8" with r15 set to this label minus 8, + * so it stays correct if the number of stores above ever changes. + */ +ret_from_trap_no_rval: lwi r11, r1, PT_MODE; /* See if returning to kernel mode, if so, skip resched &c. */ bnei r11, 2f;
@@ -478,6 +484,15 @@ C_ENTRY(ret_from_kernel_thread): C_ENTRY(sys_rt_sigreturn_wrapper): addik r30, r0, 0 /* no restarts */ + /* + * rt_sigreturn restores the full register set from the signal + * context, so it must skip the r3/r4 syscall-return stores at the + * head of ret_from_trap which would otherwise overwrite the + * just-restored r3/r4. Every C function returns with "rtsd r15, 8" + * -- the ABI return, where the 8 skips the caller's branch and its + * delay slot -- so bias r15 by -8 to land on ret_from_trap_no_rval. + */ + addik r15, r0, ret_from_trap_no_rval - 8 brid sys_rt_sigreturn /* Do real work */ addik r5, r1, 0; /* add user context as 1st arg */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/2214 microblaze: preserve the MSR carry flags across signals
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sam Price <[email protected]>
[ Upstream commit ca35dd21a5f8343f47a23e4e5b3f0ffccf76a4ae ]
setup_sigcontext() and restore_sigcontext() copy r0-r31, pc, ear, esr and fsr to and from the signal frame but never touch MSR. The interrupted MSR is therefore dropped from the signal context entirely: the handler's ucontext does not expose it, a handler cannot adjust the resumed arithmetic flags through uc_mcontext.regs.msr, and -- because restore_sigcontext() leaves regs->msr as whatever the rt_sigreturn trap left in it -- the interrupted context resumes with the carry produced by the syscall entry path (_user_exception does "addi r14, r14, 4", which writes carry), not with its own.
Other architectures round-trip the user-visible flags through the signal frame (arm's cpsr, csky's carry, x86's eflags), so a handler can both read and adjust the resumed flags; purely privileged status registers such as riscv's sstatus are left out. MicroBlaze should do the same for the user-writable bits.
Concretely, MSR[C] (carry) is lost across signal delivery. Code that keeps a live carry across a point where a signal can be delivered -- for example an lwx/swx compare-and-swap retry loop, between the swx and the carry test -- resumes with the handler's carry and mis-evaluates the result; the same failure class as the rt_sigreturn r3/r4 clobber, reached through a different register. Demonstrated under qemu-system-microblazeel (machine petalogix-s3adsp1800): a handler that sets MSR_C in uc_mcontext.regs.msr has no effect before this change (0 of 132 in-window signals propagated) and takes effect after (130 of 132).
Save MSR in setup_sigcontext() so the handler's ucontext exposes it. The signal frame is user-writable, so restore_sigcontext() must not restore it
verbatim: MicroBlaze packs the user-writable carry (MSR_C, MSR_CC) and the privileged control bits (MSR_UM, MSR_VM, MSR_IE, MSR_EE, ...) into the one register, and a verbatim restore would let userspace alter privileged return state -- rtbd derives the resumed mode from MSR_UMS/MSR_VMS. Restore only MSR_C | MSR_CC from the frame and keep the rest from the current regs->msr. This mirrors x86'srestore_sigcontext(), which masks the restored EFLAGS to FIX_EFLAGS for the same reason; arches whose status register is purely privileged (e.g. riscv sstatus) simply do not restore it at all.
Comment on the exposed MSR reworded: it is not read-only, restore_sigcontext() applies MSR_C|MSR_CC from the frame. Author's Signed-off-by kept; he agreed to comment and changelog cleanups.
--- arch/microblaze/kernel/signal.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/microblaze/kernel/signal.c +18 -0
@@ -33,6 +33,7 @@#include <linux/linkage.h> #include <linux/tracehook.h> #include <asm/entry.h> +#include <asm/registers.h> #include <asm/ucontext.h> #include <linux/uaccess.h> #include <linux/syscalls.h>
@@ -81,6 +82,22 @@ static int restore_sigcontext(struct pt_regs *regs,COPY (pc);COPY (ear);COPY (esr);COPY (fsr);#undef COPY +/* +* The frame is user-writable, so restore only the user-writable +* status flags (carry) and keep the kernel-controlled MSR bits +* (UMS/VMS/IE/EE/...) from regs->msr: rtbd derives the resumed mode +* from UMS/VMS, so a verbatim restore would hand userspace the +* privileged return state. Same idea as x86 masking the restored +* EFLAGS to FIX_EFLAGS. +*/ + { +unsigned long msr; + + err |=__get_user (msr, &sc->regs.msr); + regs->msr = (regs->msr & ~(MSR_C |MSR_CC )) | + (msr & (MSR_C |MSR_CC )); + } + *rval_p = regs->r3;return err;
@@ -140,6 +157,7 @@ setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,COPY (r26);COPY (r27);COPY (r28);COPY (r29);COPY (r30);COPY (r31);COPY (pc);COPY (ear);COPY (esr);COPY (fsr); +COPY (msr);/* restore_sigcontext() accepts only carry state */ #undef COPY err |=__put_user (mask, &sc->oldmask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 448/2214 memory: brcmstb_dpfe: Fix out-of-bounds access due to DCPU offset
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Chen <[email protected]>
[ Upstream commit 7c0b82d087908765c6c7daeb06943e21b78d523e ]
On API v1/v2 boards, the DCPU coprocessor can steer kernel readl_relaxed() and writel_relaxed() to any address within 256 MB of the ioremapped DPFE dmem or regs base. The DCPU firmware provides a 28-bit offset which the driver adds to the ioremap base without any bounds checking in get_msg_ptr().
This allows a compromised DCPU firmware to trick the host kernel into reading or writing arbitrary memory-mapped I/O registers in vmalloc space. When combined with a root-writable sysfs file like dpfe_refresh, it provides an arbitrary MMIO write primitive. Similarly, world-readable sysfs files can be used to leak other devices' register contents.
Fix this by recording the resource_size() of the dmem and regs ioremaps at probe time, and rejecting any offset that, along with the largest field accessed (DRAM_VENDOR_ERROR + sizeof(u32)), exceeds the recorded mapping size.
--- drivers/memory/brcmstb_dpfe.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/memory/brcmstb_dpfe.c +15 -0
@@ -183,6 +183,8 @@ struct brcmstb_dpfe_priv {void __iomem *regs;void __iomem *dmem;void __iomem *imem; +resource_size_t regs_size; +resource_size_t dmem_size;struct device *dev;const struct dpfe_api *dpfe_api;struct mutex lock;
@@ -402,9 +404,14 @@ static void __iomem *get_msg_ptr(struct brcmstb_dpfe_priv *priv, u32 response,*/ switch (msg_type) {case 1 : +if (DCPU_MSG_RAM_START + offset +DRAM_VENDOR_ERROR + +sizeof (u32) > priv->regs_size) + goto bad_offset; ptr = priv->regs +DCPU_MSG_RAM_START + offset;break ;case 0 : +if (offset +DRAM_VENDOR_ERROR +sizeof (u32) > priv->dmem_size) + goto bad_offset; ptr = priv->dmem + offset;break ;default :
@@ -416,6 +423,12 @@ static void __iomem *get_msg_ptr(struct brcmstb_dpfe_priv *priv, u32 response, }return ptr; + +bad_offset: +dev_err (priv->dev,"DCPU returned out-of-range offset %#x\n" , offset); +if (buf && size) + *size =sprintf (buf,"ERROR: DCPU offset out of range\n" ); +return NULL ; }static void __finalize_command (struct brcmstb_dpfe_priv *priv)
@@ -877,6 +890,7 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev)dev_err (dev,"couldn't map DCPU registers\n" );return -ENODEV ; } + priv->regs_size =resource_size (res); res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"dpfe-dmem" ); priv->dmem =devm_ioremap_resource (dev, res);
@@ -884,6 +898,7 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev)dev_err (dev,"Couldn't map DCPU data memory\n" );return -ENOENT ; } + priv->dmem_size =resource_size (res); res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"dpfe-imem" ); priv->imem =devm_ioremap_resource (dev, res);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/2214 memory: brcmstb_dpfe: Bounds check DCPU-supplied MSG_ARG_COUNT
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Chen <[email protected]>
[ Upstream commit 6b07f8c06caca015a0db69e3f323b5186469bc66 ]
A compromised or buggy DCPU coprocessor can make any user who reads world-readable /sys/devices/.../dpfe_info|dpfe_dram trigger a kernel stack out-of-bounds read of arbitrary extent. This bounds checks chksum_idx against MSG_FIELD_MAX after reading the response from DCPU message RAM.
--- drivers/memory/brcmstb_dpfe.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/memory/brcmstb_dpfe.c +2 -0
@@ -504,6 +504,8 @@ static int __send_command(struct brcmstb_dpfe_priv *priv, unsigned int cmd,for (i =0 ; i <MSG_FIELD_MAX ; i++) result[i] =readl_relaxed (regs +DCPU_MSG_RAM (i)); chksum_idx = result[MSG_ARG_COUNT ] +MSG_ARG_COUNT +1 ; +if (chksum_idx >=MSG_FIELD_MAX ) + ret = -EINVAL ; }/* Tell DCPU we are done */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 450/2214 wifi: rtw88: fix out-of-bounds CAM write when key table is full
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: イムティヤズ <[email protected]>
[ Upstream commit 10d58823cb44681466c022054030b8e68d94ce2f ]
In rtw_ops_set_key(), when the CAM table is full, rtw_sec_get_free_cam() returns RTW_MAX_SEC_CAM_NUM (32) because find_next_zero_bit()/find_first_zero_bit() return the bitmap size when no free slot exists. The bounds check compares the returned index with ">" against total_cam_num (32), so the invalid index 32 passes the check.
rtw_sec_write_cam() then indexes cam_table[32], an array declared with RTW_MAX_SEC_CAM_NUM (32) entries, causing an out-of-bounds write that corrupts the cam_map allocation bitmap. The write also sets bit 32 of cam_map, which overruns the bitmap as well.
Fix the off-by-one by rejecting indices >= total_cam_num.
Tested on: RTL8821CE (PCIe) on kernel 7.2.0-rc6-rtw88test-00059-g0d8395707651. The patched module loaded and associated to a WPA2 network; ping traffic passed with 0% packet loss. Reassociation and disconnect/reconnect cycles completed without errors, and the CAM table (debugfs dump_cam) showed valid key entries. The CAM-full boundary (28+ pairwise keys) requires an access point with 28+ clients and is not reachable in a single-client setup, so that path was verified by code inspection.
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/mac80211.c +1 -1
@@ -512,7 +512,7 @@ static int rtw_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, hw_key_idx = key->keyidx; } -if (hw_key_idx > sec->total_cam_num) { +if (hw_key_idx >= sec->total_cam_num) { ret = -ENOSPC ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/2214 clk: mstar: msc313-mpll: fix off-by-one in clock array allocation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: hanzhijian <[email protected]>
[ Upstream commit 712b75152c00a8ab0c56dbfe34caf88e3870ddde ]
The hws array of mpll->clk_data is allocated with struct_size() using ARRAY_SIZE(output_dividers) as the element count, giving it 7 elements. But the probe function stores the MPLL clock at hws[0] and one fixed-factor clock for each output divider at hws[i + 1] for i in [0, ARRAY_SIZE(output_dividers)), writing 8 elements in total. The final write to hws[7] is past the end of the allocation.
clk_data->num is also set to NUMOUTPUTS (8), so the clock framework reads hws[0..7], again accessing hws[7] out of bounds.
Use NUMOUTPUTS as the element count so the allocation matches the number of clocks actually stored and exposed.
Found by smatch:
drivers/clk/mstar/clk-msc313-mpll.c:134 msc313_mpll_probe()
error: buffer overflow 'mpll->clk_data->hws' 7 <= 7
--- drivers/clk/mstar/clk-msc313-mpll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/mstar/clk-msc313-mpll.c +1 -1
@@ -105,7 +105,7 @@ static int msc313_mpll_probe(struct platform_device *pdev)return PTR_ERR (mpll->loop_div_second); mpll->clk_data =devm_kzalloc (dev,struct_size (mpll->clk_data, hws, -ARRAY_SIZE (output_dividers)),GFP_KERNEL ); +NUMOUTPUTS ),GFP_KERNEL );if (!mpll->clk_data)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/2214 bpf: Fix queue/stack map u32 index overflow
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 802a30c5db726639df7f93b3a1982ecc64202abe ]
The queue/stack map addresses elements[] with the product of a u32 head/tail index and value_size, but the storage itself is allocated in 64-bit arithmetic. When max_entries * value_size reaches or exceeds U32_MAX, the product wraps and push/peek/pop operate on the wrong element, corrupting map data and leaking stale values to user space. max_entries == U32_MAX would also make the u32 capacity counter qs->size (max_entries + 1) wrap to 0 and permanently break the map.
The original bound check was removed by commit a37fb7ef24a4 ("bpf:
Eliminate rlimit-based memory accounting for queue_stack_maps maps"), which deleted the bpf_map_charge_init() call and with it the U32_MAX - PAGE_SIZE check that had earlier been moved into bpf_map_charge_init() by c85d69135a91. Oversized queue/stack maps can therefore be created again.
Restore the bound in queue_stack_map_alloc_check() with a single comparison that rejects any max_entries/value_size combination whose element storage would reach or exceed U32_MAX bytes, keeping the u32 index multiplication overflow-free and the capacity counter valid.
--- kernel/bpf/queue_stack_maps.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/queue_stack_maps.c +3 -0
@@ -61,6 +61,9 @@ static int queue_stack_map_alloc_check(union bpf_attr *attr)*/ return -E2BIG ; +if (attr->max_entries >=U32_MAX / attr->value_size) +return -E2BIG ; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/2214 wifi: ath11k: Fix possible memory leak in ath11k_dp_srng_setup()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
[ Upstream commit 6132d70d0890c03546f6970893fd71938efb2a2f ]
In ath11k_dp_srng_setup(), the memory allocated for ring->vaddr_unaligned is not freed in the error paths that follow. Fix that by calling ath11k_dp_srng_cleanup() in those error paths.
Compile tested only. Issue found using a prototype static analysis tool built on the LLVM compiler infrastructure.
--- drivers/net/wireless/ath/ath11k/dp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/wireless/ath/ath11k/dp.c +2 -0
@@ -288,12 +288,14 @@ int ath11k_dp_srng_setup(struct ath11k_base *ab, struct dp_srng *ring,case HAL_RXDMA_DIR_BUF :break ;default : +ath11k_dp_srng_cleanup (ab, ring);ath11k_warn (ab,"Not a valid ring type in dp :%d\n" , type);return -EINVAL ; } ret =ath11k_hal_srng_setup (ab, type, ring_num, mac_id, ¶ms);if (ret <0 ) { +ath11k_dp_srng_cleanup (ab, ring);ath11k_warn (ab,"failed to setup srng: %d ring_id %d\n" , ret, ring_num);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/2214 media: i2c: ov8856: fix debug message to report actual CSI-2 lane count
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serin Yeh <[email protected]>
[ Upstream commit a15976e69b1c70ea16ef1f7172a846f6ef5dfa14 ]
The driver currently prints the number of data lanes using ov8856->cur_mode->data_lanes in ov8856_get_hwcfg(). However, the ov8856->cur_mode structure is not assigned to a clearly supported mode at that point. Due to the missing pointer, enabling dynamic debug may lead to a kernel panic.
Instead, the correct number of CSI-2 data lanes should be taken from bus_cfg.bus.mipi_csi2.num_data_lanes, which represents the real hardware configuration determined at runtime.
--- drivers/media/i2c/ov8856.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/i2c/ov8856.c +2 -1
@@ -2348,7 +2348,8 @@ static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev) goto check_hwcfg_error; } -dev_dbg (dev,"Using %u data lanes\n" , ov8856->cur_mode->data_lanes); +dev_dbg (dev,"Using %u data lanes\n" , + bus_cfg.bus.mipi_csi2.num_data_lanes);if (bus_cfg.bus.mipi_csi2.num_data_lanes ==2 ) ov8856->priv_lane = &lane_cfg_2;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/2214 mtd: spi-nor: sfdp: check the length of the xSPI Profile 1.0 table
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit b9f34a95a81021fa1f3c9cb8cfd458e66824cad6 ]
The spi_nor_parse_profile1() sizes its buffer from the table length the flash reports in the SFDP parameter header. But it then reads DWORD1, DWORD4 and DWORD5 without ever checking the table is that long.
So if a flash reports a length of one, the buffer is only four bytes while DWORD4 and DWORD5 sit at byte offsets 12 and 16. With a length of zero kmalloc() returns ZERO_SIZE_PTR rather than an error, so the NULL check doesn't catch it and the first read dereferences it. And the value doesn't just get thrown away. It ends up as the dummy cycle count for 8D-8D-8D fast reads.
To fix this, reject a table that's too short for the highest DWORD the parser reads, the way spi_nor_parse_4bait() already does. The table is optional, so this isn't fatal. The spi_nor_parse_sfdp() warns and carries on.
--- drivers/mtd/spi-nor/sfdp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mtd/spi-nor/sfdp.c +4 -0
@@ -1114,6 +1114,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,#define PROFILE1_DWORD5_DUMMY_166MHZ GENMASK(31, 27)#define PROFILE1_DWORD5_DUMMY_133MHZ GENMASK(21, 17)#define PROFILE1_DWORD5_DUMMY_100MHZ GENMASK(11, 7) +#define SFDP_PROFILE1_DWORD_MIN 5/** * spi_nor_parse_profile1() - parse the xSPI Profile 1.0 table
@@ -1131,6 +1132,9 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,int ret;u8 dummy, opcode; +if (profile1_header->length <SFDP_PROFILE1_DWORD_MIN ) +return -EINVAL ; + len = profile1_header->length *sizeof (*dwords); dwords =kmalloc (len,GFP_KERNEL );if (!dwords)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/2214 fs_pin: publish pins with RCU list helpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 8d01d6b4c17c406f37a9b6edac93dfb858af30d0 ]
pin_insert() initializes a pin before adding it under pin_lock. The kill paths read the list heads under RCU without taking that lock. Plain hlist insertion does not publish the earlier initialization to those readers.
KCSAN weak-memory checking reported acct_on() callback initialization racing with pin_kill() after the superblock-list publication. The corresponding LKMM model permits the stale read with plain publication; the RCU release/acquire pair forbids it.
Use the RCU hlist add and dereference helpers for both pin lists.
--- fs/fs_pin.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/fs_pin.c +5 -4
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/fs.h> +#include <linux/rculist.h> #include <linux/sched.h> #include <linux/slab.h> #include "internal.h"
@@ -22,8 +23,8 @@ void pin_remove(struct fs_pin *pin)void pin_insert (struct fs_pin *pin,struct vfsmount *m) {spin_lock (&pin_lock); -hlist_add_head (&pin->s_list, &m->mnt_sb->s_pins); -hlist_add_head (&pin->m_list, &real_mount (m)->mnt_pins); +hlist_add_head_rcu (&pin->s_list, &m->mnt_sb->s_pins); +hlist_add_head_rcu (&pin->m_list, &real_mount (m)->mnt_pins);spin_unlock (&pin_lock); }
@@ -73,7 +74,7 @@ void mnt_pin_kill(struct mount *m)while (1 ) {struct hlist_node *p;rcu_read_lock (); - p =READ_ONCE (m->mnt_pins.first); + p =rcu_dereference (hlist_first_rcu (&m->mnt_pins));if (!p) {rcu_read_unlock ();break ;
@@ -87,7 +88,7 @@ void group_pin_kill(struct hlist_head *p)while (1 ) {struct hlist_node *q;rcu_read_lock (); - q =READ_ONCE (p->first); + q =rcu_dereference (hlist_first_rcu (p));if (!q) {rcu_read_unlock ();break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/2214 thermal: intel: powerclamp: Reject invalid window_size values
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 40989202104e498ff9adfb8c575d6cd159f13988 ]
window_size_set() sets ret to -EINVAL if new_window_size is outside the valid range, but then falls through and still updates window_size to the clamped value.
Return -EINVAL immediately and do not update window_size. Also drop the now-redundant clamp() call.
--- drivers/thermal/intel/intel_powerclamp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/intel/intel_powerclamp.c +2 -1
@@ -154,9 +154,10 @@ static int window_size_set(const char *arg, const struct kernel_param *kp)pr_err ("Out of recommended window size %lu, between 2-10\n" , new_window_size); ret = -EINVAL ; + goto exit_win; } - window_size =clamp (new_window_size,2ul ,10ul ); + window_size = new_window_size;smp_mb (); exit_win:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/2214 isofs: fix Rock Ridge CE extent validation on multisession media
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baolin Liu <[email protected]>
[ Upstream commit 43de050fa4a31f7e7a73cf8974dcf6037e161a39 ]
Commit a36d990f5913 ("isofs: validate Rock Ridge CE continuation extent against volume size") compares the CE extent directly with s_nzones. The extent is an absolute block number, while s_nzones is the number of blocks relative to the selected ISO session. The comparison is therefore wrong when a multisession disc starts at a non-zero block.
isofs_get_last_session() selects the last session on multisession media, and its volume descriptors describe a volume beginning at that session's LBA.
For example, a session beginning at LBA 45447 with 64 blocks can contain a valid CE at absolute LBA 45467. The existing check rejects that CE, so the ER continuation record is not read, Rock Ridge is disabled, and the mount falls back to Joliet names.
Save the selected session start in filesystem-block units and validate the CE extent against the half-open interval [session_start, session_end). Scale the session length to the same block units and retain a separate block-device limit. The lower bound is intentional: accepting arbitrary blocks before the selected session could make a CE read data from a previous session or another filesystem on the device.
Only apply the bounds check when cont_extent is non-zero. A zero extent is the in-memory sentinel indicating that no CE continuation was found, rather than a request to read block zero.
For a single-session image, session_start is zero and the effective volume boundary remains unchanged.
Build-tested with:
make CONFIG_RUST= CONFIG_RUST_DRIVERS= fs/isofs/
--- fs/isofs/inode.c | 2 ++ fs/isofs/isofs.h | 2 ++ fs/isofs/rock.c | 11 +++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-)
fs/isofs/inode.c +2 -0
@@ -862,6 +862,8 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)if (!sb_set_blocksize (s, orig_zonesize)) goto out_freesbi; + sbi->s_session_start = (sector_t )vol_desc_start << + (ISOFS_BLOCK_BITS - s->s_blocksize_bits); sbi->s_nls_iocharset =NULL ;#ifdef CONFIG_JOLIET
fs/isofs/isofs.h +2 -0
@@ -35,6 +35,8 @@ struct isofs_sb_info {unsigned long s_firstdatazone;unsigned long s_log_zone_size;unsigned long s_max_size; +/* Session start in filesystem block units. */ +sector_t s_session_start;int s_rock_offset;/* offset of SUSP fields within SU area */ s32 s_sbsector;
fs/isofs/rock.c +9 -2
@@ -9,6 +9,7 @@#include <linux/slab.h> #include <linux/pagemap.h> +#include <linux/blkdev.h> #include "isofs.h" #include "rock.h"
@@ -84,6 +85,10 @@ static void init_rock_state(struct rock_state *rs, struct inode *inode)*/ static int rock_continue (struct rock_state *rs) { +struct super_block *sb = rs->inode->i_sb; +struct isofs_sb_info *sbi =ISOFS_SB (sb); +sector_t session_end = sbi->s_session_start + + ((sector_t )sbi->s_nzones << (ISOFS_BLOCK_BITS - sb->s_blocksize_bits));int ret =1 ;int blocksize =1 << rs->inode->i_blkbits;const int min_de_size = offsetof(struct rock_ridge , u);
@@ -101,11 +106,13 @@ static int rock_continue(struct rock_state *rs) goto out; } -if ((unsigned )rs->cont_extent >=ISOFS_SB (rs->inode->i_sb)->s_nzones) { +if (rs->cont_extent && + (rs->cont_extent < sbi->s_session_start || + rs->cont_extent >= session_end)) {printk (KERN_NOTICE "rock: corrupted directory entry. " "extent=%u out of volume (nzones=%lu)\n" , (unsigned )rs->cont_extent, -ISOFS_SB (rs->inode->i_sb)->s_nzones); + sbi->s_nzones); ret = -EIO ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/2214 media: cx231xx: Fix cleanup path on failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andi Shyti <[email protected]>
[ Upstream commit 6e30287eaf3e41b86dfb86df3b811526693d74b4 ]
If cx231xx_init_v4l2() fails the probe currently jumps to err_init, which only unregisters the V4L2 device. The analog devices and I2C resources are left registered while the driver state can be released.
A subsequent driver bind attempts to create the same I2C mux channel links and triggers a warning when the existing "channel-0" link is encountered. The remaining devices may also access released driver state. This produces the following warning
can't create symlink to channel 0
WARNING: drivers/i2c/i2c-mux.c:403 at i2c_mux_add_adapter+0xcd8/0xeb0
Call Trace:
i2c_mux_add_adapter+0xcdc/0xeb0
cx231xx_dev_init+0x2fb/0x1260
cx231xx_usb_probe+0xc48/0x2140
usb_probe_interface+0x657/0xc70
...Jump to err_video_alt instead, which performs the full device cleanup before unregistering the V4L2 device.
--- drivers/media/usb/cx231xx/cx231xx-cards.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/cx231xx/cx231xx-cards.c +1 -1
@@ -1830,7 +1830,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, retval =cx231xx_init_v4l2 (dev, udev, interface, isoc_pipe);if (retval) - goto err_init; + goto err_video_alt;if (dev->current_pcb_config.ts1_source !=0xff ) {/* compute alternate max packet sizes for TS1 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/2214 media: au0828: Free URBs when starting DVB streaming fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit b8dd133d96a40012f4b67fd48d8ddd7306a3e024 ]
start_urb_transfer() stores each allocated URB in dev->urbs[], but sets urb_streaming only after all URBs have been submitted. If a later URB or transfer buffer allocation fails, earlier entries are left allocated. A submission failure calls stop_urb_transfer(), but that function returns immediately while urb_streaming is false, leaving both submitted and unsubmitted URBs behind.
Make stop_urb_transfer() release every populated slot regardless of the streaming flag and clear each slot after release. Route all start errors through this cleanup. usb_kill_urb() safely handles both submitted and unsubmitted URBs, while the existing preallocation check preserves the lifetime of shared transfer buffers.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/media/usb/au0828/au0828-dvb.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/media/usb/au0828/au0828-dvb.c +11 -8
@@ -163,9 +163,6 @@ static int stop_urb_transfer(struct au0828_dev *dev)dprintk (2 ,"%s()\n" , __func__); -if (!dev->urb_streaming) -return 0 ; -if (dev->bulk_timeout_running ==1 ) { dev->bulk_timeout_running =0 ;del_timer (&dev->bulk_timeout);
@@ -179,6 +176,7 @@ static int stop_urb_transfer(struct au0828_dev *dev)kfree (dev->urbs[i]->transfer_buffer);usb_free_urb (dev->urbs[i]); + dev->urbs[i] =NULL ; } }
@@ -200,8 +198,10 @@ static int start_urb_transfer(struct au0828_dev *dev)for (i =0 ; i <URB_COUNT ; i++) { dev->urbs[i] =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!dev->urbs[i]) -return -ENOMEM ; +if (!dev->urbs[i]) { + ret = -ENOMEM ; + goto err; + } purb = dev->urbs[i];
@@ -217,7 +217,7 @@ static int start_urb_transfer(struct au0828_dev *dev) ret = -ENOMEM ;pr_err ("%s: failed big buffer allocation, err = %d\n" , __func__, ret); -return ret; + goto err; } purb->status = -EINPROGRESS ;
@@ -235,10 +235,9 @@ static int start_urb_transfer(struct au0828_dev *dev)for (i =0 ; i <URB_COUNT ; i++) { ret =usb_submit_urb (dev->urbs[i],GFP_ATOMIC );if (ret !=0 ) { -stop_urb_transfer (dev);pr_err ("%s: failed urb submission, err = %d\n" , __func__, ret); -return ret; + goto err; } }
@@ -249,6 +248,10 @@ static int start_urb_transfer(struct au0828_dev *dev) dev->bulk_timeout_running =1 ;return 0 ; + +err: +stop_urb_transfer (dev); +return ret; }static void au0828_start_transport (struct au0828_dev *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/2214 media: i2c: tc358743: add missing color-space strings
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit cb37e83f1bbdf0964ed0a9524ce45a0694f98205 ]
VI_STATUS3 S_V_COLOR is four bits, so the index after the shift is 0-15. input_color_space[] only has 14 entries. Add the two reserved values so log_status() cannot walk off the table.
--- drivers/media/i2c/tc358743.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/i2c/tc358743.c +2 -1
@@ -1268,7 +1268,8 @@ static int tc358743_log_status(struct v4l2_subdev *sd)static const char *const input_color_space[] = {"RGB" ,"YCbCr 601" ,"opRGB" ,"YCbCr 709" ,"NA (4)" ,"xvYCC 601" ,"NA(6)" ,"xvYCC 709" ,"NA(8)" ,"sYCC601" , -"NA(10)" ,"NA(11)" ,"NA(12)" ,"opYCC 601" }; +"NA(10)" ,"NA(11)" ,"NA(12)" ,"opYCC 601" ,"NA(14)" , +"NA(15)" };v4l2_info (sd,"-----Chip status-----\n" ); v4l2_info(sd, "Chip ID: 0x%02x\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/2214 media: go7007: bound EZ-USB I2C transfers to the usb_buf size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
[ Upstream commit 816c4628b23e8c3d925978433f4dd1a13620c01b ]
go7007_usb_i2c_master_xfer() copies msgs[i].len bytes into go->usb_buf, a 16-byte buffer embedded in struct go7007, without any length check. The adapter declares no transfer limits, so an SMBus block transfer issued through /dev/i2c-N can write up to 34 bytes into it and corrupt the struct fields that follow the buffer.
Bound the transfer size with i2c_adapter_quirks so the I2C core rejects oversized messages before they reach the driver.
--- drivers/media/usb/go7007/go7007-usb.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/media/usb/go7007/go7007-usb.c +6 -0
@@ -1029,10 +1029,16 @@ static const struct i2c_algorithm go7007_usb_algo = { .functionality = go7007_usb_functionality, }; +static const struct i2c_adapter_quirks go7007_usb_quirks = { + .max_write_len =12 , + .max_read_len =15 , +}; +static struct i2c_adapter go7007_usb_adap_templ = { .owner =THIS_MODULE , .name ="WIS GO7007SB EZ-USB" , .algo = &go7007_usb_algo, + .quirks = &go7007_usb_quirks, };/********************* USB add/remove functions *********************/
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 463/2214 media: saa7146: Initialize interrupt lock before requesting IRQ
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit e07c75a6bc4adf1ed09ede31756261e2c6bdede5 ]
The saa7146 interrupt handler can call SAA7146_IER_DISABLE(), which serializes register access with dev->int_slock. request_irq() allows the shared handler to run before saa7146_init_one() reaches the current lock initialization block.
Initialize dev->int_slock before requesting the interrupt so every handler path sees an initialized lock.
--- drivers/media/common/saa7146/saa7146_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/common/saa7146/saa7146_core.c +2 -1
@@ -352,6 +352,8 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent goto out; } +spin_lock_init (&dev->int_slock); +/* create a nice device name */ sprintf (dev->name,"saa7146 (%d)" , saa7146_num);
@@ -437,7 +439,6 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent dev->ext = ext;mutex_init (&dev->v4l2_lock); -spin_lock_init (&dev->int_slock);spin_lock_init (&dev->slock);mutex_init (&dev->i2c_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 464/2214 media: vim2m: keep transaction buffer count stable while streaming
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Younho Choi <[email protected]>
[ Upstream commit 50f5fed44d8e24081e8feed5154746fe193f11b8 ]
V4L2_CID_TRANS_NUM_BUFS controls how many buffer pairs a vim2m mem2mem job processes before the job is completed. The driver stores the value in ctx->translen and device_work() uses it later to decide whether the current transaction should continue.
Letting userspace change this control while streaming is active can make a queued job observe a different transaction length than the one it started with. That leaves the transaction state inconsistent with the buffers currently queued for the job.
Grab the transaction buffer count control while either queue is streaming, and release it only after both queues have stopped streaming. The V4L2 control framework then rejects changes with -EBUSY while the value is in use, while still allowing userspace to configure the value before streaming starts.
Keep the control handler alive until after v4l2_m2m_ctx_release(), since releasing the mem2mem context can call stop_streaming(), which now ungrabs the control.
--- drivers/media/test-drivers/vim2m.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/media/test-drivers/vim2m.c +26 -3
@@ -205,6 +205,7 @@ struct vim2m_ctx {struct vim2m_dev *dev;struct v4l2_ctrl_handler hdl; +struct v4l2_ctrl *trans_num_bufs_ctrl;/* Processed buffers in this transaction */ u8 num_processed;
@@ -1068,9 +1069,27 @@ static int vim2m_start_streaming(struct vb2_queue *q, unsigned int count) ctx->aborting =0 ; q_data->sequence =0 ; +v4l2_ctrl_grab (ctx->trans_num_bufs_ctrl, true); +return 0 ; } +static bool vim2m_other_queue_is_streaming (struct vim2m_ctx *ctx, +struct vb2_queue *q) +{ +struct vb2_queue *other_vq; + +if (!ctx->fh.m2m_ctx) +return false; + +if (V4L2_TYPE_IS_OUTPUT (q->type)) + other_vq =v4l2_m2m_get_dst_vq (ctx->fh.m2m_ctx); +else + other_vq =v4l2_m2m_get_src_vq (ctx->fh.m2m_ctx); + +return vb2_is_streaming (other_vq); +} +static void vim2m_stop_streaming (struct vb2_queue *q) {struct vim2m_ctx *ctx =vb2_get_drv_priv (q);
@@ -1084,11 +1103,14 @@ static void vim2m_stop_streaming(struct vb2_queue *q)else vbuf =v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);if (!vbuf) -return ; +break ;v4l2_ctrl_request_complete (vbuf->vb2_buf.req_obj.req, &ctx->hdl);v4l2_m2m_buf_done (vbuf,VB2_BUF_STATE_ERROR ); } + +if (!vim2m_other_queue_is_streaming (ctx, q)) +v4l2_ctrl_grab (ctx->trans_num_bufs_ctrl, false); }static void vim2m_buf_request_complete (struct vb2_buffer *vb)
@@ -1191,7 +1213,8 @@ static int vim2m_open(struct file *file) vim2m_ctrl_trans_time_msec.def = default_transtime;v4l2_ctrl_new_custom (hdl, &vim2m_ctrl_trans_time_msec,NULL ); -v4l2_ctrl_new_custom (hdl, &vim2m_ctrl_trans_num_bufs,NULL ); + ctx->trans_num_bufs_ctrl = +v4l2_ctrl_new_custom (hdl, &vim2m_ctrl_trans_num_bufs,NULL );if (hdl->error) { rc = hdl->error;v4l2_ctrl_handler_free (hdl);
@@ -1245,10 +1268,10 @@ static int vim2m_release(struct file *file)v4l2_fh_del (&ctx->fh);v4l2_fh_exit (&ctx->fh); -v4l2_ctrl_handler_free (&ctx->hdl);mutex_lock (&dev->dev_mutex);v4l2_m2m_ctx_release (ctx->fh.m2m_ctx);mutex_unlock (&dev->dev_mutex); +v4l2_ctrl_handler_free (&ctx->hdl);kfree (ctx);atomic_dec (&dev->num_inst);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 465/2214 media: vicodec: fix out-of-bounds write on under-rounded coded dimensions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 0183746ebca4c478027e2261b904f844f1443b19 ]
A capture format whose width or height is one more than a multiple of 16 makes the FWHT codec write one 8x8 block row, or column, past the end of the capture plane, and read the same block out of the reference frame for P-coded frames.
vic_round_dim() is documented to round a frame dimension up so that both the luma and the chroma plane end up a multiple of 8, but it only rounds the chroma plane:
round_up((dim) / (div), 8) * (div)
For div == 2 the result is a multiple of 16 in every case but one: when dim % 16 == 1, dim / div is already a multiple of 8 and the macro returns dim - 1. encode_plane() and decode_plane() round the same dimension with round_up(dim, 8), which yields dim + 7 -- one block more than the coded dimension that sized the buffer.
On a KASAN-enabled kernel, a 641x360 YUYV P-frame triggers:
BUG: KASAN: slab-out-of-bounds in add_deltas+0x450/0xcc0 Read of size 1 at addr ffff888009070800 by task trigger_bin/70 Call Trace: add_deltas+0x450/0xcc0 decode_plane+0x1916/0x3390 fwht_decode_frame+0x173/0x620 v4l2_fwht_decode+0x751/0x1120 device_run+0x6bb/0x1850
Round the dimension itself up to a multiple of 8 * div. The rounding changes only for div == 2 and dim % 16 == 1, and MAX_WIDTH and MAX_HEIGHT are both multiples of 16, so the rounded value still fits the advertised limits.
--- drivers/media/test-drivers/vicodec/codec-fwht.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/test-drivers/vicodec/codec-fwht.h +1 -1
@@ -61,7 +61,7 @@* both luma and chroma components resolutions are rounded up to * a multiple of 8 */ -#define vic_round_dim (dim, div) (round_up((dim) / (div), 8) * (div)) +#define vic_round_dim (dim, div) round_up(dim, 8 * (div))struct fwht_cframe_hdr {u32 magic1;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 466/2214 media: vicodec: make encoder CAPTURE dimensions read-only
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 2532e9d2f8ccb330a9c924b1ee34c5629240d352 ]
Setting the encoder's compressed CAPTURE format to a smaller resolution than the raw OUTPUT format makes the encoder write past the end of the CAPTURE buffer.
For a stateful encoder the CAPTURE width and height are not client-settable; Documentation/userspace-api/media/v4l/dev-encoder.rst specifies them as "ignored (read-only)" on VIDIOC_S_FMT. vicodec only implements half of that: vidioc_s_fmt_vid_out() derives the CAPTURE coded size and sizeimage from the OUTPUT format, but S_FMT on the CAPTURE queue overwrites them. The encoder then takes its geometry from the OUTPUT queue alone, and v4l2_fwht_encode() gets no destination length.
Overwrite the requested width and height with the OUTPUT queue's coded dimensions in vidioc_try_fmt_vid_cap(), making them read-only as the interface requires.
--- drivers/media/test-drivers/vicodec/vicodec-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/media/test-drivers/vicodec/vicodec-core.c +10 -0
@@ -895,6 +895,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) {struct vicodec_ctx *ctx =file2ctx (file); +struct vicodec_q_data *q_data_out = +get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT );struct v4l2_pix_format_mplane *pix_mp;struct v4l2_pix_format *pix;
@@ -905,6 +907,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, pix = &f->fmt.pix; pix->pixelformat = ctx->is_enc ?V4L2_PIX_FMT_FWHT :find_fmt (f->fmt.pix.pixelformat)->id; +if (ctx->is_enc) { + pix->width = q_data_out->coded_width; + pix->height = q_data_out->coded_height; + } pix->colorspace = ctx->state.colorspace; pix->xfer_func = ctx->state.xfer_func; pix->ycbcr_enc = ctx->state.ycbcr_enc;
@@ -916,6 +922,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, pix_mp = &f->fmt.pix_mp; pix_mp->pixelformat = ctx->is_enc ?V4L2_PIX_FMT_FWHT :find_fmt (pix_mp->pixelformat)->id; +if (ctx->is_enc) { + pix_mp->width = q_data_out->coded_width; + pix_mp->height = q_data_out->coded_height; + } pix_mp->colorspace = ctx->state.colorspace; pix_mp->xfer_func = ctx->state.xfer_func; pix_mp->ycbcr_enc = ctx->state.ycbcr_enc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 467/2214 media: vidtv: fix frontend reference leak on unbind
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Piyush Patle <[email protected]>
[ Upstream commit 6f412f9fe6a1f3ce9694757f50353bbec221d832 ]
dvb_register_frontend() keeps two references to the frontend. One is released by dvb_unregister_frontend(), and the other by dvb_frontend_detach(). vidtv only called dvb_unregister_frontend(), so the second reference was never released. As a result, __dvb_frontend_free() was never called, leaking the frontend private data and its struct dvb_device.
The detach call was removed by commit 63101b756893 ("media: vidtv: fix driver unbind/remove") because it caused an OOPS. The demod .release callback freed vidtv_demod_state, and the I2C remove callbacks then accessed the freed state.
That commit also removed those accesses from the I2C remove callbacks. Restore the detach call, but remove the demod .release callback. vidtv_demod_state is owned by the I2C client and is already freed by vidtv_demod_i2c_remove(), so the frontend detach path should not free it.
Tested with kmemleak and KASAN over 10 bind/unbind cycles. The reported frontend and dvb_device leaks were present before the fix and were gone after it, with no KASAN reports.
--- drivers/media/test-drivers/vidtv/vidtv_bridge.c | 2 ++ drivers/media/test-drivers/vidtv/vidtv_demod.c | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-)
drivers/media/test-drivers/vidtv/vidtv_bridge.c +2 -0
@@ -474,6 +474,7 @@ static int vidtv_bridge_dvb_init(struct vidtv_dvb *dvb) fail_demod_probe:for (i = i -1 ; i >=0 ; --i) {dvb_unregister_frontend (dvb->fe[i]); +dvb_frontend_detach (dvb->fe[i]); fail_fe:dvb_module_release (dvb->i2c_client_tuner[i]); fail_tuner_probe:
@@ -552,6 +553,7 @@ static int vidtv_bridge_remove(struct platform_device *pdev)for (i =0 ; i <NUM_FE ; ++i) {dvb_unregister_frontend (dvb->fe[i]); +dvb_frontend_detach (dvb->fe[i]);dvb_module_release (dvb->i2c_client_tuner[i]);dvb_module_release (dvb->i2c_client_demod[i]); }
drivers/media/test-drivers/vidtv/vidtv_demod.c +0 -9
@@ -343,13 +343,6 @@ static int vidtv_diseqc_send_burst(struct dvb_frontend *fe,return 0 ; } -static void vidtv_demod_release (struct dvb_frontend *fe) -{ -struct vidtv_demod_state *state = fe->demodulator_priv; - -kfree (state); -} -static const struct dvb_frontend_ops vidtv_demod_ops = { .delsys = {SYS_DVBT ,
@@ -390,8 +383,6 @@ static const struct dvb_frontend_ops vidtv_demod_ops = { FE_CAN_HIERARCHY_AUTO, }, - .release = vidtv_demod_release, - .set_frontend = vidtv_demod_set_frontend, .get_frontend = vidtv_demod_get_frontend,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 468/2214 media: vidtv: fix uaf in vidtv_bridge_on_new_pkts_avail
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
[ Upstream commit 2af02ccd048b77713695d7817cf645ca50bf349e ]
Attempting to unbind a dvbdevice that is in the process of feeding data causes a UAF as we free the underlying device without stopping the feed first. Fix this by stopping the stream first using vidtv_stop_streaming(). However, our codepath in the reproducer (mentioned in the below reply) does not decrement our users (dmxdev->dvr_dvbdev->users) to 1 after it has been incremented to 2 by our read() in the reproducer, that is only possible on .release. This can cause a task hang as dvb_dmxdev_release() uses wait_event() in the wait_queue unless we use a close(fd)(in the reproducer). Is this a problem? Please advise.
--- drivers/media/test-drivers/vidtv/vidtv_bridge.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/test-drivers/vidtv/vidtv_bridge.c +2 -0
@@ -551,6 +551,8 @@ static int vidtv_bridge_remove(struct platform_device *pdev)mutex_destroy (&dvb->feed_lock); +vidtv_stop_streaming (dvb); +for (i =0 ; i <NUM_FE ; ++i) {dvb_unregister_frontend (dvb->fe[i]);dvb_frontend_detach (dvb->fe[i]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 469/2214 media: marvell-cam: fix unmet dependency for VIDEO_MMP_CAMERA
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Braha <[email protected]>
[ Upstream commit 1179929b3abd4adb6ca7fae91d649c64a7293aca ]
VIDEO_MMP_CAMERA selects I2C_GPIO without ensuring
'GPIOLIB || COMPILE_TEST' is enabled, despite I2C_GPIO depending on it.
Let's add the same dependency to VIDEO_MMP_CAMERA.
This unmet dependency bug was found by kconfirm, a static analysis tool for Kconfig.
--- drivers/media/platform/marvell-ccic/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/marvell-ccic/Kconfig +1 -0
@@ -16,6 +16,7 @@ config VIDEO_MMP_CAMERA tristate "Marvell Armada 610 integrated camera controller support" depends on I2C && VIDEO_V4L2 depends on ARCH_MMP || COMPILE_TEST + depends on GPIOLIB || COMPILE_TEST depends on COMMON_CLK select VIDEO_OV7670 select I2C_GPIO
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 470/2214 staging: media: av7110: fix corrupted BER reporting in sp8870
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Punnay Sharma <[email protected]>
[ Upstream commit 5764f9bd7b7a72c6df49db6c8c00d4f9994a55ba ]
In sp8870_read_ber(), the 14-bit Bit Error Rate (BER) is assembled by reading two I2C registers: 0xC08 (lower 6 bits) and 0xC07 (upper 8 bits).
The current implementation masks the lower bits via tmp = ret & 0x3F; but subsequently overwrites tmp entirely when processing the upper bits using a direct assignment (tmp = ret << 6;). This logical error causes the lower 6 bits of the BER hardware metric to be silently discarded.
Fix this by using a bitwise OR (tmp |= ret << 6;) to correctly merge the MSB and LSB payloads before returning the metric to the DVB core.
--- drivers/staging/media/av7110/sp8870.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/av7110/sp8870.c +1 -1
@@ -384,7 +384,7 @@ static int sp8870_read_ber (struct dvb_frontend* fe, u32 * ber)if (ret <0 )return -EIO ; - tmp = ret <<6 ; + tmp |= ret <<6 ;if (tmp >=0x3FFF0 ) tmp = ~0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 471/2214 media: m2m-deinterlace: fix default capture field
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 4ee3ebede5d01efdcdd88c94f9df271d2eb237de ]
queue_init() initializes default formats for both the source and capture queues. It first sets the source field to V4L2_FIELD_SEQ_TB, but then stores the capture default, V4L2_FIELD_INTERLACED_TB, in the source queue again while initializing the capture queue.
This overwrites the valid source default and leaves the capture field at its zero-initialized value, V4L2_FIELD_ANY. vidioc_streamon() accepts only V4L2_FIELD_SEQ_TB or V4L2_FIELD_SEQ_BT on the source queue, and requires the capture queue to use a compatible interlaced or NONE field. Userspace that relies on the default formats can therefore get -EINVAL when starting streaming.
Initialize the capture field instead. The bug is usually hidden because mem2mem applications commonly call S_FMT on both queues before streaming; the TRY_FMT paths normalize the fields and S_FMT overwrites q_data[].field.
--- drivers/media/platform/m2m-deinterlace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/m2m-deinterlace.c +1 -1
@@ -830,7 +830,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, q_data[V4L2_M2M_DST ].width =640 ; q_data[V4L2_M2M_DST ].height =480 ; q_data[V4L2_M2M_DST ].sizeimage = (640 *480 *3 ) /2 ; - q_data[V4L2_M2M_SRC ].field =V4L2_FIELD_INTERLACED_TB ; + q_data[V4L2_M2M_DST ].field =V4L2_FIELD_INTERLACED_TB ;return vb2_queue_init (dst_vq); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 472/2214 mtd: rawnand: sunxi: reject ECC maximization on small pages
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
[ Upstream commit a3c84084a73e170374b7dd493947efdef4ee57bc ]
When nand-ecc-maximize is set, the driver selects a 1024-byte ECC step and divides the available OOB bytes by the resulting number of steps. A NAND with a smaller page therefore produces zero steps and a division by zero.
The older controllers also provide a 512-byte ECC block mode, but the hardware documentation describes that as an ECC block size within NAND pages whose supported sizes start at 1024 bytes. It does not document a 512-byte NAND page mode.
Reject pages smaller than 1024 bytes before deriving the step count. This prevents the division by zero at the point where the incompatible maximized geometry is selected without changing explicitly configured 512-byte ECC block handling.
--- drivers/mtd/nand/raw/sunxi_nand.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/nand/raw/sunxi_nand.c +3 -0
@@ -1642,6 +1642,9 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,if (nanddev->ecc.user_conf.flags &NAND_ECC_MAXIMIZE_STRENGTH ) {int bytes; +if (mtd->writesize <1024 ) +return -EINVAL ; + ecc->size =1024 ; nsectors = mtd->writesize / ecc->size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 473/2214 media: adv7604: avoid negative array index in log_status when cp_read fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 10d8dfda1c08f6788049aa100685e223d857f901 ]
cp_read() returns the negative errno from regmap_read() on I2C failure. adv76xx_log_status() shifts the result right by 4 and uses it directly to index csc_coeff_sel_rb[16] causing the right shift of a negative number to result in -1, reading a negative place in the array.
Commit 8163419e3e05 ("media: adv7842: Avoid possible out-of-bounds array accesses in adv7842_cp_log_status()") fixed the identical pattern in the adv7842, so do the same thing here.
--- drivers/media/i2c/adv7604.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/i2c/adv7604.c +2 -1
@@ -2635,8 +2635,9 @@ static int adv76xx_log_status(struct v4l2_subdev *sd) "(16-235)" : "(0-255)", (reg_io_0x02 & 0x08) ? "enabled" : "disabled"); } + ret =cp_read (sd, info->cp_csc) >>4 ;v4l2_info (sd,"Color space conversion: %s\n" , - csc_coeff_sel_rb[cp_read (sd, info->cp_csc) >>4 ]); + ret <0 ?"" : csc_coeff_sel_rb[ret]);if (!is_digital_input (sd))return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 474/2214 media: stv090x: bound DiSEqC reply length to msg[] size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit bad6ce6e0856f344910ba95b006e6c0ebee2d9c8 ]
The FIFO_BYTENBR_FIELD register field is 4 bits wide, giving a length of 0..15, but reply->msg is __u8[4] in struct dvb_diseqc_slave_reply. A faulty or malicious DiSEqC slave (or i2c bus glitch) reporting more than 4 bytes will the array and clobber the stack.
The stb0899, tda10071, and s5h1420 drivers all properly bound the FIFO count against sizeof(reply->msg) before the read loop, so do the same thing in this driver.
--- drivers/media/dvb-frontends/stv090x.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/dvb-frontends/stv090x.c +2 -0
@@ -3897,6 +3897,8 @@ static int stv090x_recv_slave_reply(struct dvb_frontend *fe, struct dvb_diseqc_sif (rx_end) { reply->msg_len =STV090x_GETFIELD_Px (reg,FIFO_BYTENBR_FIELD ); +if (reply->msg_len >sizeof (reply->msg)) + reply->msg_len =sizeof (reply->msg);for (i =0 ; i < reply->msg_len; i++) reply->msg[i] =STV090x_READ_DEMOD (state,DISRXDATA ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 475/2214 media: stv0900: bound DiSEqC reply length to msg[] size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 6d7e70111b9c80a9e4cb17fe6a6c4f5470847722 ]
The FIFO_BYTENBR field is 4 bits (mask 0x0f), giving a length of 0..15 but reply->msg is __u8[4] in struct dvb_diseqc_slave_reply. A faulty or malicious device reporting more than 4 bytes will the array and clobber the stack.
The stb0899, tda10071, and s5h1420 drivers all properly bound the FIFO count against sizeof(reply->msg) before the read loop, so do the same thing in this driver.
--- drivers/media/dvb-frontends/stv0900_core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/dvb-frontends/stv0900_core.c +2 -0
@@ -1775,6 +1775,8 @@ static int stv0900_recv_slave_reply(struct dvb_frontend *fe,if (stv0900_get_bits (intp,RX_END )) { reply->msg_len =stv0900_get_bits (intp,FIFO_BYTENBR ); +if (reply->msg_len >sizeof (reply->msg)) + reply->msg_len =sizeof (reply->msg);for (i =0 ; i < reply->msg_len; i++) reply->msg[i] =stv0900_read_reg (intp,DISRXDATA );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 476/2214 drm/bridge: analogix_dp: Restore mandatory samsung DP DT properties
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damon Ding <[email protected]>
[ Upstream commit 02f569dd66c94dd67b2586f776235cf4177409ed ]
Revert the change that made samsung,link-rate and samsung,lane-count optional for Exynos DP. Add error checking to fail probe early if the required DT properties are missing.
If these properties are missing, video_info->max_link_rate and video_info->max_lane_count remain zero, and so do link_train.link_rate and link_train.lane_count used in the subsequent link training flow, resulting in link training failure.
There is no way at all a device can work without these properties. Here is the code flow when either max_link_rate or max_lane_count is 0:
analogix_dp_commit()
-> analogix_dp_full_link_train(dp, max_lanes = 0, max_rate = 0)
analogix_dp_full_link_train(max_lanes, max_rate):
// Read sink capabilities via DPCD and sanitize them
link_rate = read_dpcd(DP_MAX_LINK_RATE); // >= 0x06 after fixup
lane_count = read_dpcd(DP_MAX_LANE_COUNT); // >= 1 after fixup
// Clamp by the limits from DT
if (link_rate > max_rate) // 0x06 > 0, always true
link_rate = max_rate; // link_rate = 0
if (lane_count > max_lanes) // 1 > 0, always true
lane_count = max_lanes; // lane_count = 0
// Configure TX with the zeroed values
set_link_bandwidth(link_rate = 0)
// writel() is only executed for bwtype == 0x06/0x0a,
// so LINK_BW_SET is never written and stays at
// reset value; phy_configure() gets link_rate = 0.
set_lane_count(lane_count = 0)
// writel(0, ANALOGIX_DP_LANE_COUNT_SET) enables 0 lanes;
// phy_configure() is called with lanes = 0.
// Program sink for link training
drm_dp_dpcd_write(DP_LINK_BW_SET, {link_rate = 0/lane_count = 0})
// DP spec requires link rate in {0x06, 0x0a, 0x14} and
// lane count in {1, 2, 4}. Writing zeros is illegal, so
// the sink cannot enter the training state.
// Training loop
for (lane = 0; lane < lane_count /* 0 */; lane++)
// loop body never executes; training_lane[] stays
// uninitialized and no training register is programmedSince the sanitized sink values are always non-zero (link_rate >= 0x06, lane_count >= 1), the clamping with a zero maximum unconditionally forces the training parameters to zero. Clock recovery can never be achieved, so link training fails deterministically.
Consequently, making these properties mandatory again cannot break any existing device: a DT without them could never have worked in the first place. Failing probe early with a clear error message is more helpful than a silent link training failure at runtime.
--- drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +9 -4
@@ -1636,6 +1636,7 @@ static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp) {struct device_node *dp_node = dp->dev->of_node;struct video_info *video_info = &dp->video_info; +u32 val;switch (dp->plat_data->dev_type) {case RK3288_DP :
@@ -1652,10 +1653,14 @@ static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)* NOTE: those property parseing code is used for * providing backward compatibility for samsung platform. */ -of_property_read_u32 (dp_node,"samsung,link-rate" , - &video_info->max_link_rate); -of_property_read_u32 (dp_node,"samsung,lane-count" , - &video_info->max_lane_count); +if (of_property_read_u32 (dp_node,"samsung,link-rate" , &val)) +return dev_err_probe (dp->dev, -EINVAL , +"Failed to get samsung,link-rate\n" ); + video_info->max_link_rate = val; +if (of_property_read_u32 (dp_node,"samsung,lane-count" , &val)) +return dev_err_probe (dp->dev, -EINVAL , +"Failed to get samsung,lane-count\n" ); + video_info->max_lane_count = val;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 477/2214 dmaengine: altera-msgdma: initialize state before requesting IRQ
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit a5f8e3471fc20567df888267885dec3eb340eb37 ]
msgdma_probe() registers the IRQ before initializing the tasklet, lock, and descriptor lists used by the interrupt handler. A pending interrupt can access incomplete state during probe.
Initialize the handler state before requesting the IRQ so the interrupt path observes ready software state.
--- drivers/dma/altera-msgdma.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/altera-msgdma.c +5 -5
@@ -841,11 +841,6 @@ static int msgdma_probe(struct platform_device *pdev)if (mdev->irq <0 )return -ENXIO ; - ret =devm_request_irq (&pdev->dev, mdev->irq, msgdma_irq_handler, -0 ,dev_name (&pdev->dev), mdev); -if (ret) -return ret; -tasklet_setup (&mdev->irq_tasklet, msgdma_tasklet);dma_cookie_init (&mdev->dmachan);
@@ -857,6 +852,11 @@ static int msgdma_probe(struct platform_device *pdev)INIT_LIST_HEAD (&mdev->done_list);INIT_LIST_HEAD (&mdev->free_list); + ret =devm_request_irq (&pdev->dev, mdev->irq, msgdma_irq_handler, +0 ,dev_name (&pdev->dev), mdev); +if (ret) +return ret; + dma_dev = &mdev->dmadev;/* Set DMA capabilities */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 478/2214 iio: imu: inv_icm42600: fix odr change not caught in certain cases
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jean-Baptiste Maneyrol <[email protected]>
[ Upstream commit f670d4d3477386d62017936f0121909f93ac17f8 ]
When using both accel and gyro with different frequencies, the ODR change flag in the FIFO header can be sometime in a packet with invalid data. Since we are ignoring these packets, we miss the ODR change and any further change are blocked until sensor is turned off.
Fix this by moving the packet data validity check after the ODR change flag check.
--- drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 8 ++++---- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +4 -4
@@ -771,15 +771,15 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)if (size <=0 )return size; -/* skip packet if no accel data or data is invalid */ -if (accel ==NULL || !inv_icm42600_fifo_is_data_valid (accel)) -continue ; -/* update odr */ if (odr &INV_ICM42600_SENSOR_ACCEL )inv_sensors_timestamp_apply_odr (ts, st->fifo.period, st->fifo.nb.total, no); +/* skip packet if no accel data or data is invalid */ +if (accel ==NULL || !inv_icm42600_fifo_is_data_valid (accel)) +continue ; +memcpy (&buffer.accel, accel,sizeof (buffer.accel));/* convert 8 bits FIFO temperature in high resolution format */ buffer.temp = temp ? (*temp *64 ) :0 ;
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +4 -4
@@ -783,15 +783,15 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)if (size <=0 )return size; -/* skip packet if no gyro data or data is invalid */ -if (gyro ==NULL || !inv_icm42600_fifo_is_data_valid (gyro)) -continue ; -/* update odr */ if (odr &INV_ICM42600_SENSOR_GYRO )inv_sensors_timestamp_apply_odr (ts, st->fifo.period, st->fifo.nb.total, no); +/* skip packet if no gyro data or data is invalid */ +if (gyro ==NULL || !inv_icm42600_fifo_is_data_valid (gyro)) +continue ; +memcpy (&buffer.gyro, gyro,sizeof (buffer.gyro));/* convert 8 bits FIFO temperature in high resolution format */ buffer.temp = temp ? (*temp *64 ) :0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 479/2214 sched/fair: Reset NUMA fault locality after scan period update
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Kim <[email protected]>
[ Upstream commit e81ee06308379a5f2ededf997bcf17551bce5db7 ]
When updating the task scan period for NUMA locality checks, update_task_scan_period() checks whether there were no faults or failed migration on the last scan window, at which it prolongs the scan period.
However, p->numa_faults_locality, which is used to check for migration failure and number of faults at the previous scan window is not cleared after changing the scan period, which unintentionally increases numa_scan_period up to numa_scan_period_max even when there were no migration failures or no faults at previous scan.
Fix this by jumping to the out label on early exit at this case to ensure p->numa_faults_locality is always cleared before returning.
--- kernel/sched/fair.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/sched/fair.c +5 -2
@@ -2186,7 +2186,7 @@ static void update_task_scan_period(struct task_struct *p, p->mm->numa_next_scan = jiffies +msecs_to_jiffies (p->numa_scan_period); -return ; + goto out; }/*
@@ -2230,7 +2230,10 @@ static void update_task_scan_period(struct task_struct *p, p->numa_scan_period =clamp (p->numa_scan_period + diff,task_scan_min (p),task_scan_max (p)); -memset (p->numa_faults_locality,0 ,sizeof (p->numa_faults_locality)); + +out: +memset (p->numa_faults_locality,0 , +sizeof (p->numa_faults_locality)); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 480/2214 media: vivid: round the height down to the vertical subsampling factor
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxim Skokov <[email protected]>
[ Upstream commit a2ec28dd2a88d0721fc4a30242861e2be01d4023 ]
syzbot reports a vmalloc out-of-bounds write in the test pattern generator:
BUG: KASAN: vmalloc-out-of-bounds in tpg_fill_plane_pattern drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2617 [inline] BUG: KASAN: vmalloc-out-of-bounds in tpg_fill_plane_buffer+0x2063/0x4160 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2705 Write of size 720 at addr ffffc900038f9d50 by task vivid-000-vid-c/6017
The reproducer requests a 720x49 NV12 capture format, i.e. an odd height for a format whose chroma plane is vertically subsampled.
The buffer size is derived from the height by a truncating division:
sizes[p] = (tpg_g_line_width(&dev->tpg, p) * h) / dev->fmt_cap->vdownsampling[p] + dev->fmt_cap->data_offset[p];
For a single buffer holding both planes tpg_g_line_width() returns 720 + 720 / 2 = 1080, so 1080 * 49 = 52920 bytes get allocated.
tpg_fill_plane_buffer() however emits one chroma line for every two luma lines, i.e. DIV_ROUND_UP(49, 2) = 25 lines, and thus needs 49 * 720 + 25 * 720 = 53280 bytes. The memcpy() of the last chroma line runs 360 bytes past the end of the buffer.
An odd height is not meaningful for a 4:2:0 format in the first place, since the chroma plane would have to hold half a line. Rather than fixing up each of the ~10 sites that divide the height by vdownsampling[], round the height down to a multiple of the vertical subsampling factor where it enters the driver. Adjusting the format is what TRY_FMT/S_FMT are for, and it keeps every later division exact.
Formats without vertical subsampling are unaffected and keep accepting odd heights.
Tested with the syzbot reproducer, which no longer triggers the splat, and by streaming NV12, NV21, YUV420, YVU420 and YUYV at heights 47, 48, 49, 51, 480, 481 and 1081. v4l2-compliance gives identical results before and after (48 of 50 succeeded on the vivid device in both cases; the two failures are pre-existing and unrelated).
--- drivers/media/test-drivers/vivid/vivid-vid-cap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/media/test-drivers/vivid/vivid-vid-cap.c +13 -0
@@ -571,6 +571,7 @@ int vivid_try_fmt_vid_cap(struct file *file, void *priv,const struct vivid_fmt *fmt;unsigned bytesperline, max_bpl;unsigned factor =1 ; +unsigned int vdiv =1 ;unsigned w, h;unsigned p;bool user_set_csc = !!(mp->flags &V4L2_PIX_FMT_FLAG_SET_CSC );
@@ -623,6 +624,18 @@ int vivid_try_fmt_vid_cap(struct file *file, void *priv, mp->height = r.height / factor; } +/* +* The chroma planes of vertically subsampled formats hold +* height / vdownsampling lines. If the height is not a multiple of +* the subsampling factor, then the buffer size calculations round +* that number down while the test pattern generator rounds it up, +* so the generator writes one line past the end of the buffer. +* Round the height down to keep both in sync. +*/ +for (p =0 ; p < fmt->planes; p++) + vdiv =max (vdiv, fmt->vdownsampling[p]); + mp->height =rounddown (mp->height, vdiv); +/* This driver supports custom bytesperline values */ mp->num_planes = fmt->buffers;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 481/2214 media: cx231xx: preserve I2C transfer length
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Juan Perdomo <[email protected]>
[ Upstream commit a19c9502a69bbd42c18816b09cbefdeb4cb68066 ]
The I2C core stores message lengths in u16, but cx231xx truncates them to u8 when populating cx231xx_i2c_xfer_data. A 0x700-byte read therefore becomes a zero-length request. USB treats zero-length control transfers as OUT regardless of bRequestType, so the IN control pipe trips the usb_submit_urb() direction warning.
Use u16 for buf_size, matching both i2c_msg.len and VENDOR_REQUEST_IN.wLength. Oversized transfers then reach the existing URB_MAX_CTRL_SIZE check and return -EINVAL.
--- drivers/media/usb/cx231xx/cx231xx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/cx231xx/cx231xx.h +1 -1
@@ -460,7 +460,7 @@ struct cx231xx_i2c_xfer_data {u8 direction;/* 1 - IN, 0 - OUT */ u8 saddr_len;/* sub address len */ u16 saddr_dat;/* sub addr data */ -u8 buf_size;/* buffer size */ +u16 buf_size;/* buffer size */ u8 *p_buffer;/* pointer to the buffer */ };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 482/2214 media: vicodec: zero-initialize stateful decoder heap buffers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 27953c044974baf7e24dee3e9342fe0103dea80c ]
The stateful decoder leaks uninitialized kernel heap memory to userspace. A process that can open the decoder video node gets it back in the CAPTURE buffers it dequeues.
The reference frame and the compressed frame buffer are allocated with kvmalloc() in vicodec_start_streaming(), and the decoder can read them before they have been written. The first frame is allowed to be a P-frame, in which case it is decoded against a reference frame that was never produced, and the padding rows below the visible area are never written for any frame.
Use kvzalloc() for both allocations.
--- drivers/media/test-drivers/vicodec/vicodec-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/test-drivers/vicodec/vicodec-core.c +2 -2
@@ -1603,9 +1603,9 @@ static int vicodec_start_streaming(struct vb2_queue *q, } state->ref_stride = q_data->coded_width * info->luma_alpha_step; - state->ref_frame.buf =kvmalloc (total_planes_size,GFP_KERNEL ); + state->ref_frame.buf =kvzalloc (total_planes_size,GFP_KERNEL ); state->ref_frame.luma = state->ref_frame.buf; - new_comp_frame =kvmalloc (ctx->comp_max_size,GFP_KERNEL ); + new_comp_frame =kvzalloc (ctx->comp_max_size,GFP_KERNEL );if (!state->ref_frame.luma || !new_comp_frame) {kvfree (state->ref_frame.luma);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 483/2214 crypto: atmel-tdes - zero-initialize device state
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit dbe70508d507acd677e67eaf029040f5e3a3b2b3 ]
Commit c659d07f11a3 ("crypto: atmel-tdes - Switch to managed version of kzalloc") accidentally replaced kzalloc() with devm_kmalloc(), so the device state is no longer zeroed.
atmel_tdes_hw_init() tests dd->flags during probe: a stale TDES_FLAGS_INIT skips the hardware reset, and a stale TDES_FLAGS_BUSY makes atmel_tdes_handle_queue() treat the engine as permanently busy, leaving every request queued and never dispatched.
Seen on a SAM9X75 Curiosity: the first TDES request after boot never completes and the TDES interrupt count stays at zero, while the AES and SHA engines on the same SoC work normally.
Switch to devm_kzalloc(), matching the Atmel AES and SHA drivers.
--- drivers/crypto/atmel-tdes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/atmel-tdes.c +1 -1
@@ -1157,7 +1157,7 @@ static int atmel_tdes_probe(struct platform_device *pdev)struct resource *tdes_res;int err; - tdes_dd =devm_kmalloc (&pdev->dev,sizeof (*tdes_dd),GFP_KERNEL ); + tdes_dd =devm_kzalloc (&pdev->dev,sizeof (*tdes_dd),GFP_KERNEL );if (!tdes_dd)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 484/2214 crypto: atmel-aes - fix AADLENR for standalone GHASH
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 0dd8cded0e6f8c9635fe1d79d60dc7b2599b099b ]
atmel_aes_gcm_ghash_init() writes dd->total, the request's text length, to AES_AADLENR. But the GHASH it runs hashes the dd->datalen bytes passed
in: the 16-byte length block, or the padded IV when the IV is not 96 bits. The data sheet requires AES_AADLENR to hold the length of that input.
With empty plaintext and empty AAD, dd->total is 0 and the tag comes out wrong. Later requests only pass because dd->total still holds the previous request's length.
This is testmgr's first gcm(aes) vector, so CONFIG_CRYPTO_SELFTESTS=y fails at boot:
alg: aead: atmel-gcm-aes encryption test failed (wrong result) on test vector 0, cfg="in-place (one sglist)"
Without selftests the broken atmel-gcm-aes is preferred at priority 300. Seen on a SAM9X75 Curiosity with 6.18 and current mainline.
Write dd->datalen instead.
--- drivers/crypto/atmel-aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/atmel-aes.c +1 -1
@@ -1471,7 +1471,7 @@ static int atmel_aes_gcm_ghash_init(struct atmel_aes_dev *dd)struct atmel_aes_gcm_ctx *ctx =atmel_aes_gcm_ctx_cast (dd->ctx);/* Set the data length. */ -atmel_aes_write (dd,AES_AADLENR , dd->total); +atmel_aes_write (dd,AES_AADLENR , dd->datalen);atmel_aes_write (dd,AES_CLENR ,0 );/* If needed, overwrite the GCM Intermediate Hash Word Registers */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 485/2214 lib/842: reject output overflows from index and short data
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 38ed7182f3491ec1449ff246551e11ad82adba45 ]
The output length passed to sw842_decompress() is the caller's buffer capacity. Indexed copies write 2, 4 or 8 bytes and short-data templates write up to 7, but neither checks that capacity before writing and decrementing p->olen.
Overwriting an undersized destination then underflows p->olen, which is unsigned, so every later bounds check in the stream passes. Subsequent operations keep writing past the destination, and a matching CRC lets sw842_decompress() return success with an output length larger than the capacity the caller supplied.
This is reachable through zram's compressed writeback path. With 842 selected, targeted corruption of the compressed data on its backing device made a KASAN kernel report vmalloc-out-of-bounds writes in __do_index() and sw842_decompress() when zram read the page back.
Check the remaining output before both operations and return -ENOSPC, matching the other output-producing templates.
--- lib/842/842_decompress.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/842/842_decompress.c +5 -0
@@ -165,6 +165,9 @@ static int __do_index(struct sw842_param *p, u8 size, u8 bits, u64 fsize)u64 index, offset, total =round_down (p->out - p->ostart,8 );int ret; +if (size > p->olen) +return -ENOSPC ; + ret =next_bits (p, &index, bits);if (ret)return ret;
@@ -344,6 +347,8 @@ int sw842_decompress(const u8 *in, unsigned int ilen,if (!bytes || bytes >SHORT_DATA_BITS_MAX )return -EINVAL ; +if (bytes > p.olen) +return -ENOSPC ;while (bytes-- >0 ) { ret =next_bits (&p, &tmp,8 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 486/2214 lib/842: require a complete history block for repeat templates
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit deb631649882bbf43f7c2fc79b5990139fd744ba ]
An 842 repeat template copies the preceding eight-byte output block. The decoder rejects a repeat only when no output has been produced. A short-data operation can produce between one and seven bytes before a repeat.
Such a stream makes the repeat copy read before the start of the output buffer. Depending on the surrounding mapping, this can fault or bring preceding memory into the decompressed data.
This is also reachable through zram's compressed writeback path. With 842 selected, targeted corruption of the compressed data on its backing device to a short-data-then-repeat stream made a KASAN kernel report a vmalloc-out-of-bounds read when zram read the page back.
Require at least one complete output block before accepting a repeat.
--- lib/842/842_decompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/842/842_decompress.c +1 -1
@@ -309,7 +309,7 @@ int sw842_decompress(const u8 *in, unsigned int ilen,if (ret)return ret; -if (p.out == out)/* no previous bytes */ +if (p.out - p.ostart <8 )/* no complete previous block */ return -EINVAL ;/* copy rep + 1 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 487/2214 PM: CPU: Restore synchronize_rcu() to cpu_pm_unregister_notifier()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 61f7eee7d4664079fbce821576891c3ee5ccf597 ]
cpu_pm_notify() walks the notifier chain lockless under only rcu_read_lock(). That only works if a removed notifier block is not freed until every concurrent walker is done with it.
The chain used to be an atomic_notifier, whose unregister ends in synchronize_rcu(). Commit b2f6662ac08d ("PM: cpu: Make notifier chain use a raw_spinlock_t") switched it over to a raw_notifier, and in doing so replaced that with raw_notifier_chain_unregister(), which does not synchronize. The grace period quietly went away, so a driver that frees the memory holding its notifier block right after cpu_pm_unregister_notifier() returns can race with a concurrent walker:
cpu1 (idle exit) cpu2 (driver remove)
---------------- --------------------
cpu_pm_notify(CPU_PM_EXIT)
rcu_read_lock()
nb = rcu_dereference_raw(*nl)
cpu_pm_unregister_notifier(&od->nb)
unlink, no grace period
remove() frees od (devm)
nb->notifier_call(nb, ...)
/* use after free */The rcu_read_lock() on cpu1 does not stop cpu2 from freeing the block, and nothing else does. The read side is the idle exit path, so this can hit on any system where a driver with a cpu_pm notifier gets unbound.
Add the grace period back. It is only needed when a notifier was actually removed, so wait on success and return -ENOENT without waiting otherwise. The kerneldoc gets back the "may sleep" note that the same commit dropped.
--- kernel/cpu_pm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/cpu_pm.c +8 -1
@@ -10,6 +10,7 @@#include <linux/cpu_pm.h> #include <linux/module.h> #include <linux/notifier.h> +#include <linux/rcupdate.h> #include <linux/spinlock.h> #include <linux/syscore_ops.h>
@@ -85,7 +86,8 @@ EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);* * Remove a driver from the CPU PM notifier list. * -* This function has the same return conditions as raw_notifier_chain_unregister. +* This function may sleep, and has the same return conditions as +* raw_notifier_chain_unregister. */ int cpu_pm_unregister_notifier (struct notifier_block *nb) {
@@ -95,6 +97,11 @@ int cpu_pm_unregister_notifier(struct notifier_block *nb)raw_spin_lock_irqsave (&cpu_pm_notifier.lock, flags); ret =raw_notifier_chain_unregister (&cpu_pm_notifier.chain, nb);raw_spin_unlock_irqrestore (&cpu_pm_notifier.lock, flags); + +/* Wait for the rcu_read_lock() walkers in cpu_pm_notify(). */ +if (!ret) +synchronize_rcu (); +return ret; }EXPORT_SYMBOL_GPL (cpu_pm_unregister_notifier);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 488/2214 affs: validate blocks before freeing them
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 78ea2058abf3ee053c0bd9c1b9a77304cb4ae58b ]
affs_free_block() accepts block numbers from on-disk file block tables when truncating or unlinking files. The function currently rejects only block numbers greater than s_partition_size before subtracting s_reserved and using the result to index the in-memory bitmap descriptor array.
That check still accepts reserved blocks and the one-past-end block at s_partition_size. A crafted image can therefore make the subtraction underflow or make the computed bitmap index equal to s_bmap_count, leading to an out-of-bounds access on s_bitmap before the bitmap block is read and updated.
Use the existing AFFS block validity helper so freeing uses the same range as block reads and writes: s_reserved <= block < s_partition_size.
--- fs/affs/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/affs/bitmap.c +1 -1
@@ -46,7 +46,7 @@ affs_free_block(struct super_block *sb, u32 block)pr_debug ("%s(%u)\n" , __func__, block); -if (block > sbi->s_partition_size) +if (!affs_validblock (sb, block)) goto err_range; blk = block - sbi->s_reserved;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 489/2214 f2fs: compress: fix to handle race between truncate and writeback
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit c0337e331b065074ce20e4258a578e07dd7e4083 ]
fsstress reports a kernel BUG in f2fs_truncate_partial_cluster():
kernel BUG at fs/f2fs/compress.c:1238!
RIP: 0010:f2fs_truncate_partial_cluster+0x292/0x2a0 Call Trace: <TASK> f2fs_truncate+0xf6/0x210 f2fs_setattr+0x6b7/0x770 notify_change+0x33b/0x520 do_truncate+0xc2/0xf0 vfs_truncate+0x153/0x1d0 ksys_truncate+0x78/0xd0 __x64_sys_truncate+0x16/0x20 do_syscall_64+0xbe/0x540
The root cause is that Thread A (truncate) and Thread B (background writeback or fsync) can race as follows:
Thread A Thread B
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_truncate_partial_cluster
- f2fs_is_compressed_cluster
return 1
- f2fs_write_cache_pages
- f2fs_write_multi_pages
- f2fs_write_raw_pages
- f2fs_write_single_data_page dn.data_blkaddr != COMPRESS_ADDR (cluster converted to normal)
- f2fs_prepare_compress_overwrite
- f2fs_is_compressed_cluster
return 0
- return 0
- f2fs_bug_on(sbi, err == 0): BUG!
Writeback path does not acquire i_gc_rwsem or filemap_invalidate_lock. When a compressed cluster fails compression during writeback, it is overwritten with raw data blocks. If Thread A checked f2fs_is_compressed_cluster() before the conversion, but calls f2fs_prepare_compress_overwrite() after the conversion, f2fs_prepare_compress_overwrite() returns 0 because the cluster is no longer a compressed cluster.
To fix this, remove the f2fs_bug_on() and retry checking the cluster status when f2fs_prepare_compress_overwrite() returns 0, so that it can fall back to f2fs_do_truncate_blocks() to handle it as a normal cluster.
--- fs/f2fs/compress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +5 -5
@@ -1175,6 +1175,7 @@ int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock) log_cluster_size;int err; +repeat: err =f2fs_is_compressed_cluster (inode, start_idx);if (err <0 )return err;
@@ -1186,12 +1187,11 @@ int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock)/* truncate compressed cluster */ err =f2fs_prepare_compress_overwrite (inode, &pagep, start_idx, &fsdata); - -/* should not be a normal cluster */ -f2fs_bug_on (F2FS_I_SB (inode), err ==0 ); - -if (err <=0 ) +if (err <0 )return err; +else if (err ==0 ) +/* the cluster became non-compressed one due to race case */ + goto repeat;if (err >0 ) {struct page **rpages = fsdata;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 490/2214 ata: ahci_st: Do not ignore errors when getting the reset controls
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit c74ee9230a8d1d2f6fcbceff55f56f7dd9b9cccd ]
st_ahci_probe_resets() treats any error from devm_reset_control_get() as "reset control not defined" and continues with a NULL reset control:
drv_data->pwr = devm_reset_control_get(dev, "pwr-dwn");
if (IS_ERR(drv_data->pwr)) {
dev_info(dev, "power reset control not defined\n");
drv_data->pwr = NULL;
}This also swallows -EPROBE_DEFER, which is returned when the reset controller providing the reset has not been probed yet. probe() then continues as if the device tree did not specify any reset, so the resets of the SATA IP are never deasserted, and st_ahci_configure_oob() and ahci_platform_init_host() access the MMIO of an IP which is still held in reset and powered down, which can result in an external abort.
The resets are optional in the binding, as they are not part of its required properties, so use devm_reset_control_get_optional(), which returns NULL if the reset is not specified in the device tree, and propagate all other errors.
Note that an absent reset is now indicated by a NULL reset control instead of an error, so the "reset control not defined" messages are dropped.
--- drivers/ata/ahci_st.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
drivers/ata/ahci_st.c +14 -17
@@ -105,23 +105,20 @@ static int st_ahci_probe_resets(struct ahci_host_priv *hpriv, {struct st_ahci_drv_data *drv_data = hpriv->plat_data; - drv_data->pwr =devm_reset_control_get (dev,"pwr-dwn" ); -if (IS_ERR (drv_data->pwr)) { -dev_info (dev,"power reset control not defined\n" ); - drv_data->pwr =NULL ; - } - - drv_data->sw_rst =devm_reset_control_get (dev,"sw-rst" ); -if (IS_ERR (drv_data->sw_rst)) { -dev_info (dev,"soft reset control not defined\n" ); - drv_data->sw_rst =NULL ; - } - - drv_data->pwr_rst =devm_reset_control_get (dev,"pwr-rst" ); -if (IS_ERR (drv_data->pwr_rst)) { -dev_dbg (dev,"power soft reset control not defined\n" ); - drv_data->pwr_rst =NULL ; - } + drv_data->pwr =devm_reset_control_get_optional (dev,"pwr-dwn" ); +if (IS_ERR (drv_data->pwr)) +return dev_err_probe (dev,PTR_ERR (drv_data->pwr), +"failed to get pwr-dwn reset\n" ); + + drv_data->sw_rst =devm_reset_control_get_optional (dev,"sw-rst" ); +if (IS_ERR (drv_data->sw_rst)) +return dev_err_probe (dev,PTR_ERR (drv_data->sw_rst), +"failed to get sw-rst reset\n" ); + + drv_data->pwr_rst =devm_reset_control_get_optional (dev,"pwr-rst" ); +if (IS_ERR (drv_data->pwr_rst)) +return dev_err_probe (dev,PTR_ERR (drv_data->pwr_rst), +"failed to get pwr-rst reset\n" );return st_ahci_deassert_resets (hpriv, dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 491/2214 ata: ahci_st: Assert the power down reset in the probe() error path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 91e0a7452d7a81e924a499b23f30f3bf85fddbd2 ]
st_ahci_probe_resets() deasserts the "pwr-dwn" reset, but the probe() error path of st_ahci_probe() only releases the host resources, so the SATA IP is left powered up when probe() fails after st_ahci_probe_resets() has succeeded, e.g. when ahci_platform_enable_resources() fails.
The reset is asserted by st_ahci_host_stop(), however ->host_stop() is only called through the ata_host_stop() devres action registered by ata_host_start(), so it does not cover any failure happening before the host has been started.
Factor the assert out into st_ahci_assert_pwrdwn() and call it when either ahci_platform_enable_resources() or ahci_platform_init_host() fails. The "pwr-dwn" reset control is an exclusive one, so asserting it once more from st_ahci_host_stop() is harmless.
No functional change intended for ->host_stop() and st_ahci_suspend().
--- drivers/ata/ahci_st.c | 51 +++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)
drivers/ata/ahci_st.c +30 -21
@@ -84,18 +84,27 @@ static int st_ahci_deassert_resets(struct ahci_host_priv *hpriv,return 0 ; } -static void st_ahci_host_stop (struct ata_host *host) +static int st_ahci_assert_pwrdwn (struct ahci_host_priv *hpriv, +struct device *dev) { -struct ahci_host_priv *hpriv = host->private_data;struct st_ahci_drv_data *drv_data = hpriv->plat_data; -struct device *dev = host->dev;int err; -if (drv_data->pwr) { - err =reset_control_assert (drv_data->pwr); -if (err) -dev_err (dev,"unable to pwrdwn\n" ); - } +if (!drv_data->pwr) +return 0 ; + + err =reset_control_assert (drv_data->pwr); +if (err) +dev_err (dev,"unable to pwrdwn\n" ); + +return err; +} + +static void st_ahci_host_stop (struct ata_host *host) +{ +struct ahci_host_priv *hpriv = host->private_data; + +st_ahci_assert_pwrdwn (hpriv, host->dev);ahci_platform_disable_resources (hpriv); }
@@ -161,7 +170,7 @@ static int st_ahci_probe(struct platform_device *pdev) err =ahci_platform_enable_resources (hpriv);if (err) -return err; + goto assert_pwrdwn;st_ahci_configure_oob (hpriv->mmio);
@@ -170,12 +179,17 @@ static int st_ahci_probe(struct platform_device *pdev) err =ahci_platform_init_host (pdev, hpriv, &st_ahci_port_info, &ahci_platform_sht); -if (err) { -ahci_platform_disable_resources (hpriv); -return err; - } +if (err) + goto disable_resources;return 0 ; + +disable_resources: +ahci_platform_disable_resources (hpriv); +assert_pwrdwn: +st_ahci_assert_pwrdwn (hpriv, &pdev->dev); + +return err; }#ifdef CONFIG_PM_SLEEP
@@ -183,20 +197,15 @@ static int st_ahci_suspend(struct device *dev) {struct ata_host *host =dev_get_drvdata (dev);struct ahci_host_priv *hpriv = host->private_data; -struct st_ahci_drv_data *drv_data = hpriv->plat_data;int err; err =ahci_platform_suspend_host (dev);if (err)return err; -if (drv_data->pwr) { - err =reset_control_assert (drv_data->pwr); -if (err) { -dev_err (dev,"unable to pwrdwn" ); -return err; - } - } + err =st_ahci_assert_pwrdwn (hpriv, dev); +if (err) +return err;ahci_platform_disable_resources (hpriv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 492/2214 ntfs3: bound index head insertions by buffer capacity
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yousef Alhouseen <[email protected]>
[ Upstream commit 2f497d23652ff23da07b08cfb4b4a1c2a87f1892 ]
hdr_insert_head() shifts the existing index entries by ins_bytes without checking that the resulting used size fits within hdr->total. A directory index root larger than the newly allocated index buffer can therefore make the memmove write beyond the buffer.
Reject insertions whose size would exceed the index header capacity and make both split callers unwind the new node when that happens.
--- fs/ntfs3/index.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/ntfs3/index.c +11 -2
@@ -595,6 +595,8 @@ static const struct NTFS_DE *hdr_insert_head(struct INDEX_HDR *hdr,if (!e)return NULL ; +if (size_add (used, ins_bytes) >le32_to_cpu (hdr->total)) +return NULL ;/* Now we just make room for the inserted entries and jam it in. */ to_move = used -le32_to_cpu (hdr->de_off);
@@ -1794,7 +1796,10 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni, }/* Copy root entries into new buffer. */ -hdr_insert_head (hdr, re, to_move); +if (!hdr_insert_head (hdr, re, to_move)) { + err = -EINVAL ; + goto out_put_n; + }/* Update bitmap attribute. */ indx_mark_used (indx, ni, new_vbn >> indx->idx2vbn_bits);
@@ -1946,7 +1951,11 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,/* Copy all the entries <= sp into the new buffer. */ de_t =hdr_first_de (hdr1); to_copy =PtrOffset (de_t, sp); -hdr_insert_head (hdr2, de_t, to_copy); +if (!hdr_insert_head (hdr2, de_t, to_copy)) { + err = -EINVAL ; +put_indx_node (n2); + goto out; + }/* Remove all entries (sp including) from hdr1. */ used = used1 - to_copy - sp_size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 493/2214 crypto: atmel-tdes - sync output bounce buffer before DMA
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit a38fdcb9c944525ca71e6aaf35e708586d0ae87d ]
The slow path maps its output bounce buffer once at probe time with dma_map_single() and DMA_FROM_DEVICE, then reuses the mapping for every request. After the CPU copies a result from the buffer, dma_sync_single_for_device() must hand the buffer back to the device before the next DMA transfer. The driver omits this call, so cache lines from the previous result can remain valid while the device writes the next one.
This bug was masked by the completion paths calling dma_sync_single_for_device() immediately before the CPU copied the output, where dma_sync_single_for_cpu() was required. For DMA_FROM_DEVICE on ARM926, dma_sync_single_for_device() invokes arm926_dma_map_area(), which invalidates the cache lines. The misplaced call therefore discarded the stale lines before every copy-out.
Commit c8a9a647532f ("crypto: atmel-tdes - fix DMA sync direction") correctly changed the completion paths to call dma_sync_single_for_cpu(). On ARM926, that function invokes arm926_dma_unmap_area(), which is a no-op. The missing pre-DMA dma_sync_single_for_device() was therefore exposed on ARM926-based SAM9X60 and SAM9X7 SoCs.
With CONFIG_CRYPTO_SELFTESTS=y all four DES/TDES algorithms fail on SAM9X75:
alg: skcipher: atmel-ecb-tdes encryption test failed (wrong result) on test vector 2, cfg="unaligned buffer, offset=1"
Call dma_sync_single_for_device() for the output buffer before starting DMA in both atmel_tdes_crypt_pdc() and atmel_tdes_crypt_dma().
--- drivers/crypto/atmel-tdes.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/crypto/atmel-tdes.c +4 -0
@@ -384,6 +384,8 @@ static int atmel_tdes_crypt_pdc(struct atmel_tdes_dev *dd,if (!(dd->flags &TDES_FLAGS_FAST )) {dma_sync_single_for_device (dd->dev, dma_addr_in, length,DMA_TO_DEVICE ); +dma_sync_single_for_device (dd->dev, dma_addr_out, length, +DMA_FROM_DEVICE ); }switch (rctx->mode &TDES_FLAGS_OPMODE_MASK ) {
@@ -429,6 +431,8 @@ static int atmel_tdes_crypt_dma(struct atmel_tdes_dev *dd,if (!(dd->flags &TDES_FLAGS_FAST )) {dma_sync_single_for_device (dd->dev, dma_addr_in, length,DMA_TO_DEVICE ); +dma_sync_single_for_device (dd->dev, dma_addr_out, length, +DMA_FROM_DEVICE ); }switch (rctx->mode &TDES_FLAGS_OPMODE_MASK ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 494/2214 usb: fotg210: validate endpoint index in ep0 handlers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Chao <[email protected]>
[ Upstream commit bbddb219b00af0792242a0ad1dc7fb3344f38733 ]
fotg210_set_feature(), fotg210_clear_feature() and fotg210_get_status() use wIndex from the USB setup packet to index the fotg210->ep[] array without verifying that the endpoint number falls below FOTG210_MAX_NUM_EP (5). USB_ENDPOINT_NUMBER_MASK is 0x0f, so a malicious host can issue a setup packet with wIndex 5..15, resulting in an out-of-bounds array read. The resulting wild pointer is then dereferenced in fotg210_set_epnstall() or fotg210_is_epnstall(), which compute an MMIO register offset from ep->epnum and perform iowrite32 through it.
fotg210_clear_feature() is especially problematic: the out-of-bounds access occurs at function entry (source-level) regardless of which USB_RECIP_* case is taken, because the ep pointer is computed before the switch statement.
Add upper-bound checks on the endpoint number derived from wIndex in all three functions. Invalid endpoint numbers in clear_feature now trigger fotg210_request_error() (STALL) instead of silently falling through to fotg210_set_cxdone(). Also add the missing le16_to_cpu() conversion for ctrl->wIndex in fotg210_get_status() to fix a sparse endianness warning.
--- drivers/usb/gadget/udc/fotg210-udc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/usb/gadget/udc/fotg210-udc.c +11 -6
@@ -650,7 +650,7 @@ static void fotg210_set_feature(struct fotg210_udc *fotg210,case USB_RECIP_ENDPOINT : {u8 epnum; epnum =le16_to_cpu (ctrl->wIndex) &USB_ENDPOINT_NUMBER_MASK ; -if (epnum) +if (epnum && epnum <FOTG210_MAX_NUM_EP )fotg210_set_epnstall (fotg210->ep[epnum]);else fotg210_set_cxstall (fotg210);
@@ -666,8 +666,8 @@ static void fotg210_set_feature(struct fotg210_udc *fotg210,static void fotg210_clear_feature (struct fotg210_udc *fotg210,struct usb_ctrlrequest *ctrl) { -struct fotg210_ep *ep = - fotg210->ep[ctrl->wIndex &USB_ENDPOINT_NUMBER_MASK ]; +u8 epnum =le16_to_cpu (ctrl->wIndex) &USB_ENDPOINT_NUMBER_MASK ; +struct fotg210_ep *ep;switch (ctrl->bRequestType &USB_RECIP_MASK ) {case USB_RECIP_DEVICE :
@@ -677,7 +677,12 @@ static void fotg210_clear_feature(struct fotg210_udc *fotg210,fotg210_set_cxdone (fotg210);break ;case USB_RECIP_ENDPOINT : -if (ctrl->wIndex &USB_ENDPOINT_NUMBER_MASK ) { +if (epnum >=FOTG210_MAX_NUM_EP ) { +fotg210_request_error (fotg210); +break ; + } +if (epnum) { + ep = fotg210->ep[epnum];if (ep->wedged) {fotg210_set_cxdone (fotg210);break ;
@@ -733,8 +738,8 @@ static void fotg210_get_status(struct fotg210_udc *fotg210, fotg210->ep0_data =cpu_to_le16 (0 );break ;case USB_RECIP_ENDPOINT : - epnum = ctrl->wIndex &USB_ENDPOINT_NUMBER_MASK ; -if (epnum) + epnum =le16_to_cpu (ctrl->wIndex) &USB_ENDPOINT_NUMBER_MASK ; +if (epnum && epnum <FOTG210_MAX_NUM_EP ) fotg210->ep0_data =cpu_to_le16 (fotg210_is_epnstall (fotg210->ep[epnum]) <<USB_ENDPOINT_HALT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 495/2214 ASoC: wm8994: Fix runtime PM imbalance in wm8994_component_probe()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 480a5528cb6268d626632d45d4a1f29b4c0c11df ]
In wm8994_component_probe(), pm_runtime_get_sync() is invoked before reading the GPIO configuration registers. If either regmap_read() fails, the function jumps to err_irq without calling pm_runtime_put(), leaving the runtime PM usage count incremented and causing a leak.
Add pm_runtime_put() on both GPIO read failure paths before jumping to err_irq.
--- sound/soc/codecs/wm8994.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/codecs/wm8994.c +2 -0
@@ -4352,6 +4352,7 @@ static int wm8994_component_probe(struct snd_soc_component *component) ret =regmap_read (control->regmap,WM8994_GPIO_1 , ®);if (ret <0 ) {dev_err (component->dev,"Failed to read GPIO1 state: %d\n" , ret); +pm_runtime_put (component->dev); goto err_irq; }if ((reg &WM8994_GPN_FN_MASK ) !=WM8994_GP_FN_PIN_SPECIFIC ) {
@@ -4364,6 +4365,7 @@ static int wm8994_component_probe(struct snd_soc_component *component) ret =regmap_read (control->regmap,WM8994_GPIO_6 , ®);if (ret <0 ) {dev_err (component->dev,"Failed to read GPIO6 state: %d\n" , ret); +pm_runtime_put (component->dev); goto err_irq; }if ((reg &WM8994_GPN_FN_MASK ) !=WM8994_GP_FN_PIN_SPECIFIC ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 496/2214 ASoC: arizona-jack: Fix runtime PM imbalance in arizona_start_hpdet_acc_id()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit e04dcb895b4622d67164e218a1179785e2c75999 ]
In arizona_start_hpdet_acc_id(), pm_runtime_get_sync() is called to keep the device powered during headphone detection. If setting the HPDET mode or starting the measurement fails and the function jumps to err, pm_runtime_put_autosuspend() was not called while info->hpdet_active was set to false, resulting in a runtime PM usage count leak.
Add pm_runtime_put_autosuspend() in the err error path to keep runtime PM balanced.
--- sound/soc/codecs/arizona-jack.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/codecs/arizona-jack.c +1 -0
@@ -704,6 +704,7 @@ static void arizona_start_hpdet_acc_id(struct arizona_priv *info)snd_soc_jack_report (info->jack,SND_JACK_HEADPHONE ,SND_JACK_LINEOUT |SND_JACK_HEADPHONE ); +pm_runtime_put_autosuspend (arizona->dev); info->hpdet_active = false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 497/2214 iio: accel: kxcjk-1013: Disable autosuspend on remove
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 1de1206a42741adfb72ca8b37dc71a6bc80cb074 ]
kxcjk1013_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/iio/accel/kxcjk-1013.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/accel/kxcjk-1013.c +1 -0
@@ -1617,6 +1617,7 @@ static int kxcjk1013_remove(struct i2c_client *client)iio_device_unregister (indio_dev); +pm_runtime_dont_use_autosuspend (&client->dev);pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 498/2214 iio: accel: mma9551: disable autosuspend on remove
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 8061720f6be1811478914f8b6143778d70f6033f ]
mma9551_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/iio/accel/mma9551.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/accel/mma9551.c +1 -0
@@ -516,6 +516,7 @@ static int mma9551_remove(struct i2c_client *client)iio_device_unregister (indio_dev); +pm_runtime_dont_use_autosuspend (&client->dev);pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 499/2214 iio: accel: mma9553: disable autosuspend on remove
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 4dda1f9d25fb889649e81bbf015809daa512a049 ]
mma9553_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/iio/accel/mma9553.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/accel/mma9553.c +1 -0
@@ -1155,6 +1155,7 @@ static int mma9553_remove(struct i2c_client *client)iio_device_unregister (indio_dev); +pm_runtime_dont_use_autosuspend (&client->dev);pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 500/2214 md/raid5: track disks array size to fix extra_page leak on error paths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cao Guanghui <[email protected]>
[ Upstream commit 5028ceee173bfcf844469cfb0d1c151d3f6d0296 ]
free_conf() iterates conf->pool_size entries to free extra_page allocations, but pool_size may not reflect the actual size of the conf->disks array. Two scenarios cause a mismatch:
1. setup_conf() early abort: pool_size is 0 (not yet set by grow_stripes) but conf->disks has max_disks entries with extra_page allocated. The loop iterates 0 times, leaking all pages.
2. resize_stripes() Step 4 failure: conf->disks was replaced with a newsize-entry array in Step 3, but pool_size is only updated on success. The loop iterates pool_size (old, smaller value) times, leaking (newsize - pool_size) pages.
Add a dedicated disks_cnt field to track the actual number of entries in conf->disks. Set it immediately after each allocation or replacement (in setup_conf and resize_stripes Step 3, where the array is safely stalled with no concurrent access), and use it in free_conf() instead of pool_size.
This leaves pool_size untouched, preserving the check_reshape() retry behavior that depends on pool_size only being updated on full success.
--- drivers/md/raid5.c | 5 +++-- drivers/md/raid5.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/md/raid5.c +3 -2
@@ -2582,6 +2582,7 @@ static int resize_stripes(struct r5conf *conf, int newsize) }else {kfree (conf->disks); conf->disks = ndisks; + conf->disks_cnt = newsize; } }else err = -ENOMEM ;
@@ -7106,7 +7107,7 @@ static void free_conf(struct r5conf *conf)free_thread_groups (conf);shrink_stripes (conf);raid5_free_percpu (conf); -for (i =0 ; i < conf->pool_size; i++) +for (i =0 ; i < conf->disks_cnt; i++)if (conf->disks[i].extra_page)put_page (conf->disks[i].extra_page);kfree (conf->disks);
@@ -7288,7 +7289,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (!conf->disks) goto abort; - + conf->disks_cnt = max_disks;for (i =0 ; i < max_disks; i++) { conf->disks[i].extra_page =alloc_page (GFP_KERNEL );if (!conf->disks[i].extra_page)
drivers/md/raid5.h +1 -0
@@ -667,6 +667,7 @@ struct r5conf {unsigned long cache_state;struct shrinker shrinker;int pool_size;/* number of disks in stripeheads in pool */ +int disks_cnt;/* number of entries in disks[] array */ spinlock_t device_lock;struct disk_info *disks;struct bio_set bio_split;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 501/2214 md/raid5: fix NULL pointer dereference in raid5_free_percpu
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cao Guanghui <[email protected]>
[ Upstream commit 41742e35268d6a45161b187f51f42bc2ade14d0d ]
If cpuhp_state_add_instance() fails in raid5_alloc_percpu() (e.g., the startup callback raid456_cpu_up_prepare fails due to an allocation failure), conf->node is never added to the cpuhp instance list and its pprev remains NULL (from kzalloc initialization).
When setup_conf() then jumps to abort, free_conf() calls raid5_free_percpu(), which checks conf->percpu (non-NULL, since it was allocated before the cpuhp failure) and proceeds to call cpuhp_state_remove_instance(). This calls hlist_del() on the unhashed node, which dereferences node->pprev (NULL), causing a kernel panic.
Guard the removal with hlist_unhashed_lockless() so that the cpuhp instance is only removed if it was actually added. The lockless variant uses READ_ONCE() for the pprev read, which is safe here because the actual removal is synchronized by cpuhp_state_mutex inside cpuhp_state_remove_instance().
--- drivers/md/raid5.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/raid5.c +2 -1
@@ -7093,7 +7093,8 @@ static void raid5_free_percpu(struct r5conf *conf)if (!conf->percpu)return ; -cpuhp_state_remove_instance (CPUHP_MD_RAID5_PREPARE , &conf->node); +if (!hlist_unhashed_lockless (&conf->node)) +cpuhp_state_remove_instance (CPUHP_MD_RAID5_PREPARE , &conf->node);free_percpu (conf->percpu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 502/2214 md/raid5: validate payload size before calculating payload_len
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Wilck <[email protected]>
[ Upstream commit 38c795105992bbaa3418dd39cbff7348ad17537c ]
Commit b0cc3ae97e89 ("md/raid5: validate payload size before accessing journal metadata") introduced a bounds check to verify that a given payload fits into the current metadata block. In order to calculate the payload size, it has to access the members payload->header.type and payload->size, the offset of which may already be past the end of the metadata block, because the loop condition only checks that the first byte of the payload is inside, and the payload entries have variable sizes. Later on, payload->checksum[0] and payload->checksum[1] are accessed without verifying that payload->size is large enough.
Add another check to make sure that payload->size can be safely accessed, and make sure that the checksum fields are accessible.
This issue has been found by AI (gemma4, Gemini) during a backport review.
--- drivers/md/raid5-cache.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
drivers/md/raid5-cache.c +26 -8
@@ -2016,27 +2016,36 @@ r5l_recovery_verify_data_checksum_for_mb(struct r5l_log *log,if (!page)return -ENOMEM ; -while (mb_offset <le32_to_cpu (mb->meta_size)) { +while (mb_offset +sizeof (struct r5l_payload_header ) <=le32_to_cpu (mb->meta_size)) { +u32 payload_size;sector_t payload_len; payload = (void *)mb + mb_offset; payload_flush = (void *)mb + mb_offset;if (le16_to_cpu (payload->header.type) ==R5LOG_PAYLOAD_DATA ) { +if (mb_offset +sizeof (struct r5l_payload_data_parity ) + >le32_to_cpu (mb->meta_size)) + goto mismatch; + payload_size =le32_to_cpu (payload->size) >> (PAGE_SHIFT -9 ); payload_len =sizeof (struct r5l_payload_data_parity ) + - (sector_t )sizeof (__le32) * - (le32_to_cpu (payload->size) >> (PAGE_SHIFT -9 )); -if (mb_offset + payload_len >le32_to_cpu (mb->meta_size)) + (sector_t )sizeof (__le32) * payload_size; +if (mb_offset + payload_len >le32_to_cpu (mb->meta_size) || + payload_size <1 ) goto mismatch;if (r5l_recovery_verify_data_checksum ( log, ctx, page, log_offset, payload->checksum[0 ]) <0 ) goto mismatch; }else if (le16_to_cpu (payload->header.type) ==R5LOG_PAYLOAD_PARITY ) { +if (mb_offset +sizeof (struct r5l_payload_data_parity ) + >le32_to_cpu (mb->meta_size)) + goto mismatch; + payload_size =le32_to_cpu (payload->size) >> (PAGE_SHIFT -9 ); payload_len =sizeof (struct r5l_payload_data_parity ) + - (sector_t )sizeof (__le32) * - (le32_to_cpu (payload->size) >> (PAGE_SHIFT -9 )); -if (mb_offset + payload_len >le32_to_cpu (mb->meta_size)) + (sector_t )sizeof (__le32) * payload_size; +if (mb_offset + payload_len >le32_to_cpu (mb->meta_size) || + payload_size < conf->max_degraded) goto mismatch; if (r5l_recovery_verify_data_checksum( log, ctx, page, log_offset,
@@ -2050,6 +2059,9 @@ r5l_recovery_verify_data_checksum_for_mb(struct r5l_log *log, payload->checksum[1]) < 0) goto mismatch; }else if (le16_to_cpu (payload->header.type) ==R5LOG_PAYLOAD_FLUSH ) { +if (mb_offset +sizeof (struct r5l_payload_flush ) + >le32_to_cpu (mb->meta_size)) + goto mismatch; payload_len =sizeof (struct r5l_payload_flush ) + (sector_t )le32_to_cpu (payload_flush->size);if (mb_offset + payload_len >le32_to_cpu (mb->meta_size))
@@ -2111,7 +2123,7 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log, mb_offset =sizeof (struct r5l_meta_block ); log_offset =r5l_ring_add (log, ctx->pos,BLOCK_SECTORS ); -while (mb_offset <le32_to_cpu (mb->meta_size)) { +while (mb_offset +sizeof (struct r5l_payload_header ) <le32_to_cpu (mb->meta_size)) {sector_t payload_len;int dd;
@@ -2121,6 +2133,9 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log,if (le16_to_cpu (payload->header.type) ==R5LOG_PAYLOAD_FLUSH ) {int i, count; +if (mb_offset +sizeof (struct r5l_payload_flush ) > +le32_to_cpu (mb->meta_size)) +return -EINVAL ; payload_len =sizeof (struct r5l_payload_flush ) + (sector_t )le32_to_cpu (payload_flush->size); if (mb_offset + payload_len >
@@ -2145,6 +2160,9 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log, }/* DATA or PARITY payload */ +if (mb_offset +sizeof (struct r5l_payload_data_parity ) > +le32_to_cpu (mb->meta_size)) +return -EINVAL ; payload_len =sizeof (struct r5l_payload_data_parity ) + (sector_t )sizeof (__le32) * (le32_to_cpu (payload->size) >> (PAGE_SHIFT -9 ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 503/2214 cpufreq: conservative: Restrict deferred downscaling to low load
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengming Hu <[email protected]>
[ Upstream commit 0fa55c5539173bceaeb400c69b1974aaa0cdb8dc ]
For a shared cpufreq policy, dbs_update() derives the load used for the frequency decision from the maximum load among its CPUs, but it may also record deferred idle periods accumulated by an idle CPU in the policy.
Consequently, a single update can contain both a high decision load from one CPU and multiple deferred idle periods from another CPU. The conservative governor applies the deferred down steps before evaluating the decision load. If that load subsequently triggers an up step, the deferred down steps can outweigh the single up step and produce a net frequency reduction.
This was observed on a policy shared by CPUs 2 and 3. A CPU-bound SCHED_EXT task kept CPU 2 fully utilized while CPU 3 remained idle. On this system, SCHED_EXT generated update-util callbacks less frequently than CFS, resulting in sparse DBS updates such as:
load=100 idle_periods=7 interval=59 ms
load=100 idle_periods=4 interval=39 ms
load=100 idle_periods=2 interval=19 ms
load=100 idle_periods=7 interval=59 ms
With the default 5% frequency step and a 2.6 GHz policy maximum, seven deferred periods reduce the requested frequency by seven 130 MHz steps before the high decision load adds only one step. Repeated updates therefore keep the policy near 530 MHz even though CPU 2 is fully utilized.
There are two load values relevant to this behavior:
* sample_load is calculated from the busy and elapsed time of the current sample.
* decision_load is returned by dbs_update() for the governor's frequency decision. After a long idle interval, it may reuse prev_load to improve the response to a waking task and can therefore differ from sample_load.
The problem is that idle_periods is derived from accumulated idle time and is applied independently of whether the current sample load is in the conservative governor's downscaling region. A high sample load and multiple deferred idle periods can therefore coexist, particularly when updates are sparse.
As suggested by Zhongqiu Han, calculate the sample load separately from the decision load. If no time has elapsed, use prev_load for the sample load as the existing load calculation does, since no load can be calculated for that interval.
Record the maximum sample load for the policy and apply deferred down steps only when it is below down_threshold. This makes deferred downscaling follow the same threshold that the conservative governor normally uses to determine whether the policy load is low enough to reduce the frequency.
The existing code applies deferred down steps whenever idle_periods is valid, regardless of the sample load. When the decision load is in the hold region, the locally adjusted frequency is not submitted unless another frequency-update branch is taken. Thus, when the sample and decision loads are the same and both are in the hold region, this change does not alter the requested frequency.
The difference becomes visible when the decision load causes a frequency update. In particular, if it exceeds up_threshold, the governor applies a single up step after the deferred down steps and submits the resulting request. Multiple deferred down steps can then outweigh that up step and cause a frequency reduction even when the sample load is above down_threshold.
With this change, deferred down steps are skipped whenever the maximum sample load is at or above down_threshold, keeping deferred downscaling consistent with the conservative governor's threshold semantics. The requested frequency may therefore be higher than with the existing behavior when deferred idle periods are present and the decision load causes a frequency update. This is intentional, because the lower request previously resulted from applying deferred downscaling while the sampled policy load was outside the governor's downscaling region. Accelerated deferred downscaling remains available when the policy sample load is below down_threshold, including after a workload has completed and the policy has become idle.
--- drivers/cpufreq/cpufreq_conservative.c | 8 ++++--- drivers/cpufreq/cpufreq_governor.c | 29 +++++++++++++++++++------- drivers/cpufreq/cpufreq_governor.h | 2 ++ 3 files changed, 29 insertions(+), 10 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +5 -3
@@ -85,10 +85,12 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy) freq_step =get_freq_step (cs_tuners, policy);/* -* Decrease requested_freq one freq_step for each idle period that -* we didn't update the frequency. +* Apply deferred down steps only when the policy sample load is +* below down_threshold. Otherwise, multiple deferred down steps may +* cause a net frequency decrease outside the downscaling region. */ -if (policy_dbs->idle_periods <UINT_MAX ) { +if (policy_dbs->max_sample_load < cs_tuners->down_threshold && + policy_dbs->idle_periods <UINT_MAX ) {unsigned int freq_steps = policy_dbs->idle_periods * freq_step;if (requested_freq > policy->min + freq_steps)
drivers/cpufreq/cpufreq_governor.c +22 -7
@@ -116,7 +116,8 @@ unsigned int dbs_update(struct cpufreq_policy *policy)struct policy_dbs_info *policy_dbs = policy->governor_data;struct dbs_data *dbs_data = policy_dbs->dbs_data;unsigned int ignore_nice = dbs_data->ignore_nice_load; -unsigned int max_load =0 , idle_periods =UINT_MAX ; +unsigned int max_load =0 , max_sample_load =0 ; +unsigned int idle_periods =UINT_MAX ;unsigned int sampling_rate, io_busy, j;/*
@@ -138,7 +139,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy)struct cpu_dbs_info *j_cdbs = &per_cpu (cpu_dbs, j);u64 update_time, cur_idle_time;unsigned int idle_time, time_elapsed; -unsigned int load; +unsigned int load, sample_load; cur_idle_time =get_cpu_idle_time (j, &update_time, io_busy);
@@ -171,6 +172,20 @@ unsigned int dbs_update(struct cpufreq_policy *policy) j_cdbs->prev_cpu_nice = cur_nice; } +/* +* Compute the sample load separately from the prev_load value +* that may be reused after a long idle interval. The conservative +* governor uses it to decide whether to apply deferred down steps. +* If no time has elapsed, retain the existing behavior and use +* prev_load. +*/ +if (unlikely (!time_elapsed)) + sample_load = j_cdbs->prev_load; +else if (time_elapsed > idle_time) + sample_load =100 * (time_elapsed - idle_time) / time_elapsed; +else + sample_load =0 ; +if (unlikely (!time_elapsed)) {/* * That can only happen when this function is called
@@ -205,11 +220,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy) load = j_cdbs->prev_load; j_cdbs->prev_load =0 ; }else { -if (time_elapsed > idle_time) - load =100 * (time_elapsed - idle_time) / time_elapsed; -else - load =0 ; - + load = sample_load; j_cdbs->prev_load = load; }
@@ -222,9 +233,13 @@ unsigned int dbs_update(struct cpufreq_policy *policy)if (load > max_load) max_load = load; + +if (sample_load > max_sample_load) + max_sample_load = sample_load; } policy_dbs->idle_periods = idle_periods; + policy_dbs->max_sample_load = max_sample_load;return max_load; }
drivers/cpufreq/cpufreq_governor.h +2 -0
@@ -96,6 +96,8 @@ struct policy_dbs_info {/* Multiplier for increasing sample delay temporarily. */ unsigned int rate_mult;unsigned int idle_periods;/* For conservative */ +/* Maximum load from the current policy sample. */ +unsigned int max_sample_load;/* Status indicators */ bool is_shared;/* This object is used by multiple CPUs */ bool work_in_progress;/* Work is being queued up or in progress */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 504/2214 regulator: core: Fix c_rdev reference leak in regulator_resolve_coupling()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit c41b69e9f76fd9632662714c1d37860468e8d773 ]
of_parse_coupled_regulator() returns the coupled regulator with its device reference incremented, but regulator_resolve_coupling() returns without dropping it when the coupled regulator belongs to a different coupler, leaking the reference.
--- drivers/regulator/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/regulator/core.c +1 -0
@@ -5341,6 +5341,7 @@ static void regulator_resolve_coupling(struct regulator_dev *rdev)if (c_rdev->coupling_desc.coupler != coupler) {rdev_err (rdev,"coupler mismatch with %s\n" ,rdev_get_name (c_rdev)); +put_device (&c_rdev->dev);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 505/2214 regulator: core: Fix rdev reference leak in regulator_resolve_supply()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 195bbe5e1c29aa1349655a6162958149c1176034 ]
regulator_resolve_supply() takes a reference on the looked-up regulator with regulator_dev_lookup(), but when the supply resolves to the regulator itself that reference is never dropped: it leaks on the early return and is lost as well when r is replaced with the dummy regulator.
Release the reference before handling the self-referent case.
--- drivers/regulator/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/regulator/core.c +1 -0
@@ -2086,6 +2086,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)if (r == rdev) {dev_err (dev,"Supply for %s (%s) resolved to itself\n" , rdev->desc->name, rdev->supply_name); +put_device (&rdev->dev);if (!have_full_constraints ()) { ret = -EINVAL ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 506/2214 ASoC: codecs: wm8994: Fix runtime PM leak in wm8994_mic_detect()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit b2c0e5bf750e33b0e1dcdfbb2df8103a06c7caab ]
wm8994_mic_detect() resumes the component before configuring the MICBIAS pins, but the default case of the micbias switch returns -EINVAL right after taking that reference, skipping the pm_runtime_put() on the success path. This leaks a runtime PM reference on every call with an invalid micbias.
Release the reference before returning -EINVAL.
--- sound/soc/codecs/wm8994.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/codecs/wm8994.c +1 -0
@@ -3533,6 +3533,7 @@ int wm8994_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *break ;default :dev_warn (component->dev,"Invalid MICBIAS %d\n" , micbias); +pm_runtime_put (component->dev);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 507/2214 fpga: Fix of_fpga_mgr_get() reference in fpga_mgr_lock() docs
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit ac02245b0ca28388ba16273f2fa683c90da2e5dc ]
The fpga_mgr_lock() comment lists of_fpga_mgr_put() as a source of a manager pointer. The helper which obtains that pointer is of_fpga_mgr_get(). Correct the reference.
--- drivers/fpga/fpga-mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/fpga-mgr.c +1 -1
@@ -563,7 +563,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_put);* @mgr: fpga manager * * Given a pointer to FPGA Manager (from fpga_mgr_get() or -* of_fpga_mgr_put()) attempt to get the mutex. The user should call +* of_fpga_mgr_get()) attempt to get the mutex. The user should call * fpga_mgr_lock() and verify that it returns 0 before attempting to * program the FPGA. Likewise, the user should call fpga_mgr_unlock * when done programming the FPGA.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 508/2214 iio: accel: adis16201: fix channel order for buffer mode
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shehryar Ahmad <[email protected]>
[ Upstream commit a4b9f1137b76faab6891ce0bd3f5c02dda7c392d ]
Reshuffle adis16201_channels to ascending scan_index order to avoid data corruption during IIO core demultiplexing since the ADIS driver builds the buffer in channel array order, while the IIO core demultiplexes it in scan_index order.
This changes the raw buffer byte layout for existing adis16201 users reading buffered data directly.
--- drivers/iio/accel/adis16201.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/accel/adis16201.c +5 -5
@@ -202,19 +202,19 @@ static int adis16201_write_raw(struct iio_dev *indio_dev, }static const struct iio_chan_spec adis16201_channels[] = { -ADIS_SUPPLY_CHAN (ADIS16201_SUPPLY_OUT_REG ,ADIS16201_SCAN_SUPPLY ,0 , -12 ), -ADIS_TEMP_CHAN (ADIS16201_TEMP_OUT_REG ,ADIS16201_SCAN_TEMP ,0 ,12 ),ADIS_ACCEL_CHAN (X ,ADIS16201_XACCL_OUT_REG ,ADIS16201_SCAN_ACC_X ,BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,14 ),ADIS_ACCEL_CHAN (Y ,ADIS16201_YACCL_OUT_REG ,ADIS16201_SCAN_ACC_Y ,BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,14 ), -ADIS_AUX_ADC_CHAN (ADIS16201_AUX_ADC_REG ,ADIS16201_SCAN_AUX_ADC ,0 ,12 ),ADIS_INCLI_CHAN (X ,ADIS16201_XINCL_OUT_REG ,ADIS16201_SCAN_INCLI_X ,BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,12 ),ADIS_INCLI_CHAN (Y ,ADIS16201_YINCL_OUT_REG ,ADIS16201_SCAN_INCLI_Y ,BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,12 ), -IIO_CHAN_SOFT_TIMESTAMP (7 ) +ADIS_SUPPLY_CHAN (ADIS16201_SUPPLY_OUT_REG ,ADIS16201_SCAN_SUPPLY ,0 , +12 ), +ADIS_AUX_ADC_CHAN (ADIS16201_AUX_ADC_REG ,ADIS16201_SCAN_AUX_ADC ,0 ,12 ), +ADIS_TEMP_CHAN (ADIS16201_TEMP_OUT_REG ,ADIS16201_SCAN_TEMP ,0 ,12 ), +IIO_CHAN_SOFT_TIMESTAMP (7 ), };static const struct iio_info adis16201_info = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 509/2214 ata: libata-scsi: abort multi-sector pass-through commands when multi_count is 0
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit 3bab8c7e0c6ba187a47163a1f71477213a278c48 ]
When an ATA_12, ATA_16, or ATA_32 pass-through command with a multi-sector PIO command opcode (ATA_CMD_READ_MULTI, ATA_CMD_WRITE_MULTI, ATA_CMD_READ_MULTI_EXT, ATA_CMD_WRITE_MULTI_EXT, or ATA_CMD_WRITE_MULTI_FUA_EXT) is submitted via SG_IO on a device where multiple-sector mode is not configured (dev->multi_count == 0), ata_scsi_pass_thru() currently logs a warning and still dispatches the taskfile. When the DRQ interrupt fires, ata_pio_sectors() triggers WARN_ON_ONCE(qc->dev->multi_count == 0) and computes
nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, 0) = 0, failing to transfer any sectors:
ata1.00: invalid multi_count 1 ignored
WARNING: drivers/ata/libata-sff.c:666 at ata_pio_sectors+0x27d/0x300 Call Trace: <IRQ> ata_sff_hsm_move+0x211/0x22e0 __ata_sff_port_intr+0x1c8/0x520 ata_bmdma_port_intr+0xa1/0x5b0 ata_bmdma_interrupt+0x1f5/0x550
Per ACS-3 section 7.12.7.21, if IDENTIFY DEVICE word 59 bit 8 is cleared to zero (multi_count == 0) and a READ MULTIPLE or WRITE MULTIPLE command is received without a preceding successful SET MULTIPLE MODE command, the device returns command aborted (ABRT). Per the SAT specification, an ABRT error translates to the ABORTED COMMAND sense key with NO ADDITIONAL SENSE INFORMATION (0x00, 0x00).
Fail multi-sector taskfile commands in ata_scsi_pass_thru() with ata_scsi_set_sense(dev, scmd, ABORTED_COMMAND, 0, 0) when dev->multi_count == 0.
--- drivers/ata/libata-scsi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/ata/libata-scsi.c +5 -0
@@ -3031,6 +3031,11 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)if (is_multi_taskfile (tf)) {unsigned int multi_count =1 << (cdb[1 ] >>5 ); +if (!dev->multi_count) { +ata_scsi_set_sense (dev, scmd,ABORTED_COMMAND ,0 ,0 ); +return 1 ; + } +/* compare the passed through multi_count * with the cached multi_count of libata */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 510/2214 PCI: pciehp: Make pciehp_poll_mode parameter read-only
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 5ab17178fca6026d329cb6ced33c30f3b7d3e50a ]
pciehp_request_irq() and pciehp_free_irq() select different resources based on the global pciehp_poll_mode parameter. The parameter is currently writable through sysfs, so changing it while a controller is active can make teardown try to stop a nonexistent polling thread or call free_irq() for an IRQ that was not requested.
Keep the parameter available for boot and module configuration, but prevent runtime changes to the registration mode.
Reproducer:
Boot an x86_64 guest in QEMU with a native PCIe hotplug root port and an e1000 device, using these device options:
-device pcie-root-port,id=rp1,chassis=1,slot=1 -device e1000,bus=rp1
Pass "pcie_ports=native pciehp.pciehp_poll_mode=1" to the guest kernel. As root in the guest, replace the device name below with a bound pciehp service device and run:
# dev=0000:00:1c.0:pcie004
# driver=/sys/bus/pci_express/drivers/pciehp
# echo 0 > /sys/module/pciehp/parameters/poll_mode # echo "$dev" > "$driver/unbind" # dmesg | grep 'Trying to free already-free IRQ'
The unfixed kernel accepts the runtime mode change and reports the warning when the service device is removed. The fixed kernel rejects the write and removes the device without the warning. The mode change is a deliberate privileged test action and is not expected during ordinary operation.
--- drivers/pci/hotplug/pciehp_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/hotplug/pciehp_core.c +1 -1
@@ -37,7 +37,7 @@ int pciehp_poll_time;* not really modular, but the easiest way to keep compat with existing * bootargs behaviour is to continue using module_param here. */ -module_param (pciehp_poll_mode, bool,0644 ); +module_param (pciehp_poll_mode, bool,0444 );module_param (pciehp_poll_time, int,0644 );MODULE_PARM_DESC (pciehp_poll_mode,"Using polling mechanism for hot-plug events or not" );MODULE_PARM_DESC (pciehp_poll_time,"Polling mechanism frequency, in seconds" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 511/2214 staging: media: imx: csc-scaler: fix ipu_image_convert_run leak on queue error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
[ Upstream commit 07643be7b1eff94f7a49e142c1e92a1029d3db21 ]
device_run() allocates an ipu_image_convert_run object and, on the success path, hands it to the IPU image conversion core via ipu_image_convert_queue(); the run object is then freed asynchronously by the completion callback ipu_ic_pp_complete().
However, if ipu_image_convert_queue() fails, the core never takes ownership of the run object and the completion callback is never invoked. The "err" label finishes the mem2mem job and reports the buffers as errored, but never frees the run object that was just allocated, leaking it on every queue failure.
Free the run object in the error path. There is no risk of a double
free: the completion callback only runs after the object was successfully queued, which is mutually exclusive with reaching the error path. It is also safe for the earlier "goto err" on allocation failure, since run is NULL there and kfree(NULL) is a no-op.
--- drivers/staging/media/imx/imx-media-csc-scaler.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/media/imx/imx-media-csc-scaler.c +1 -0
@@ -144,6 +144,7 @@ static void device_run(void *_ctx)v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR );v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR );v4l2_m2m_job_finish (priv->m2m_dev, ctx->fh.m2m_ctx); +kfree (run); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 512/2214 media: meson-ir-tx: Prevent divide by zero in meson_irtx_prepare_pulse()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 05d9c515cf13056875abbf73adb4a19dd7ba32eb ]
If an excesively high carrier is set, meson_irtx_prepare_pulse() will cause a divide by zero if tb_us is 0. Prevent such a carrier from being set.
--- drivers/media/rc/meson-ir-tx.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/rc/meson-ir-tx.c +3 -0
@@ -219,6 +219,9 @@ static int meson_irtx_set_carrier(struct rc_dev *rc, u32 carrier)if (carrier ==0 )return -EINVAL ; +if (!DIV_ROUND_CLOSEST (USEC_PER_SEC , carrier)) +return -EINVAL ; + ir->carrier = carrier;meson_irtx_set_mod (ir);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 513/2214 ASoC: ti: davinci-mcasp: Fix runtime PM imbalance in __davinci_mcasp_set_clkdiv()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit ba593d662183de74d2b733b4c6e8cd26f04f0a65 ]
In __davinci_mcasp_set_clkdiv(), pm_runtime_get_sync() is called at the entry of the function. If an invalid div_id is provided, the function hits the default switch case and directly returns -EINVAL without calling pm_runtime_put(), resulting in a runtime PM reference leak.
Add pm_runtime_put() in the default case before returning -EINVAL.
--- sound/soc/ti/davinci-mcasp.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/ti/davinci-mcasp.c +1 -0
@@ -649,6 +649,7 @@ static int __davinci_mcasp_set_clkdiv(struct davinci_mcasp *mcasp, int div_id,break ;default : +pm_runtime_put (mcasp->dev);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 514/2214 drm/mali-dp: Fix runtime PM leak in malidp_crtc_atomic_enable()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 73ef663c75688168e31dbe9c585b939be410a945 ]
malidp_crtc_atomic_enable() resumes the device with pm_runtime_get_sync() and returns early when the resume fails. The runtime PM usage count is incremented by pm_runtime_get_sync() even when the resume fails, so returning without dropping the reference leaks it and, once the error has been hit, prevents the device from ever suspending again.
Drop the runtime PM reference with pm_runtime_put_noidle() on the resume failure path before returning.
--- drivers/gpu/drm/arm/malidp_crtc.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/arm/malidp_crtc.c +1 -0
@@ -55,6 +55,7 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc,if (err <0 ) {DRM_DEBUG_DRIVER ("Failed to enable runtime power management: %d\n" , err); +pm_runtime_put_noidle (crtc->dev->dev);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/2214 nilfs2: fix checkpoint root lifetime on sysfs errors
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
[ Upstream commit 2cb947450e0e5a88bb6bb5fca6dbfda1910e74b0 ]
nilfs_find_or_create_root() links a new checkpoint root into the checkpoint tree and drops ns_cptree_lock before creating the root's sysfs group. If nilfs_sysfs_create_snapshot_group() then fails, the root is freed while it is still reachable from ns_cptree, so a concurrent nilfs_lookup_root() can dereference freed memory.
nilfs_sysfs_create_snapshot_group() allocates memory and creates sysfs nodes and may sleep, so it cannot run under the ns_cptree_lock spinlock. Reorder the creation path so that the sysfs group is set up before the root is published: initialize the root, create its sysfs group outside the lock, and only then take ns_cptree_lock to link it into the tree. On sysfs failure the root was never visible and is freed directly; in the unlikely case a root with the same checkpoint number is already present, the sysfs group of the new root is removed before it is freed. Concurrent insertions are already serialized by ns_snapshot_mount_mutex, so only the race against nilfs_lookup_root() needs to be closed.
Because kobject_put() does not guarantee that the embedded kobject's release callback has run by the time it returns (CONFIG_DEBUG_KOBJECT_RELEASE defers it), the container must not be freed until the release completes. Keep that wait_for_completion() of snapshot_kobj_unregister inside the sysfs helpers, so both the creation error path and nilfs_sysfs_delete_snapshot_group() wait for the release before their callers free the root.
--- fs/nilfs2/sysfs.c | 5 ++++- fs/nilfs2/the_nilfs.c | 34 +++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-)
fs/nilfs2/sysfs.c +4 -1
@@ -194,8 +194,10 @@ int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root) "%llu", root->cno); } -if (err) +if (err) {kobject_put (&root->snapshot_kobj); +wait_for_completion (&root->snapshot_kobj_unregister); + }return err; }
@@ -203,6 +205,7 @@ int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root)void nilfs_sysfs_delete_snapshot_group (struct nilfs_root *root) {kobject_put (&root->snapshot_kobj); +wait_for_completion (&root->snapshot_kobj_unregister); }/************************************************************************
fs/nilfs2/the_nilfs.c +21 -13
@@ -869,6 +869,26 @@ nilfs_find_or_create_root(struct the_nilfs *nilfs, __u64 cno)if (!new)return NULL ; + new->cno = cno; + new->ifile =NULL ; + new->nilfs = nilfs; +refcount_set (&new->count,1 ); +atomic64_set (&new->inodes_count,0 ); +atomic64_set (&new->blocks_count,0 ); + +/* +* Register the sysfs group before publishing the root in the +* checkpoint tree. nilfs_sysfs_create_snapshot_group() can sleep, +* so it must run outside ns_cptree_lock; creating it first also +* ensures a concurrent nilfs_lookup_root() can never observe a root +* whose sysfs registration later fails and gets freed. +*/ + err =nilfs_sysfs_create_snapshot_group (new); +if (err) { +kfree (new); +return NULL ; + } +spin_lock (&nilfs->ns_cptree_lock); p = &nilfs->ns_cptree.rb_node;
@@ -885,29 +905,17 @@ nilfs_find_or_create_root(struct the_nilfs *nilfs, __u64 cno) }else {refcount_inc (&root->count);spin_unlock (&nilfs->ns_cptree_lock); +nilfs_sysfs_delete_snapshot_group (new);kfree (new);return root; } } - new->cno = cno; - new->ifile =NULL ; - new->nilfs = nilfs; -refcount_set (&new->count,1 ); -atomic64_set (&new->inodes_count,0 ); -atomic64_set (&new->blocks_count,0 ); -rb_link_node (&new->rb_node, parent, p);rb_insert_color (&new->rb_node, &nilfs->ns_cptree);spin_unlock (&nilfs->ns_cptree_lock); - err =nilfs_sysfs_create_snapshot_group (new); -if (err) { -kfree (new); - new =NULL ; - } -return new; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 516/2214 md: validate bblog_size when loading v1.x badblocks metadata
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuchao Zhang <[email protected]>
[ Upstream commit ae5f89b23cb88667cfa1273b42d6a551db9c651e ]
In super_1_load(), when the on-disk feature_map does not have MD_FEATURE_BAD_BLOCKS set but sb->bblog_offset is non-zero, rdev->badblocks.shift is initialized to 0 without validating sb->bblog_size. The same field is validated in the MD_FEATURE_BAD_BLOCKS branch ("sectors > (PAGE_SIZE / 512)"), but this branch bypasses that check.
A forged on-disk superblock (malicious storage device or crafted image) can therefore carry an oversized sb->bblog_size. When bad blocks are later recorded, super_1_sync() sets bb->size from sb->bblog_size and md_write_metadata() issues a bio larger than the single rdev->bb_page, reading beyond the page and leaking kernel memory contents to disk.
sb->bblog_size is never modified by the kernel between load and sync, and the MD_FEATURE_BAD_BLOCKS branch already validates it, so checking it in this branch is sufficient to cover both paths.
Fix this by rejecting an oversized sb->bblog_size with -EINVAL, matching the existing check in the MD_FEATURE_BAD_BLOCKS branch.
--- drivers/md/md.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/md.c +4 -1
@@ -1765,8 +1765,11 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_if (badblocks_set (&rdev->badblocks, sector, count,1 ))return -EINVAL ; } - }else if (sb->bblog_offset !=0 ) + }else if (sb->bblog_offset !=0 ) { +if (le16_to_cpu (sb->bblog_size) > (PAGE_SIZE /512 )) +return -EINVAL ; rdev->badblocks.shift =0 ; + }if ((le32_to_cpu (sb->feature_map) & (MD_FEATURE_PPL |MD_FEATURE_MULTIPLE_PPLS ))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 517/2214 crypto: amlogic - Fix IRQ handler return value and fallthrough logic
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohamad Raizudeen <[email protected]>
[ Upstream commit 4b8ae2732070c5669adee2d5d3bb97b14af53a63 ]
In meson_irq_handler(), when an interrupt matches a flow but the status register is empty, the driver prints an error but doesn't return. It falls through the loop and incorrectly prints an unknown irq message.
Fix this by returning immediately. For empty status registers, return IRQ_NONE instead of IRQ_HANDLED to avoid masking spurious interrupts and allow the kernel to detect interrupt storms. Also use dev_err_ratelimited() to prevent console lockups during an interrupt storm.
Additionally, the handler returned IRQ_HANDLED for genuinely unknown interrupts. Return IRQ_NONE instead for unhandled interrupts.
--- drivers/crypto/amlogic/amlogic-gxl-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/amlogic/amlogic-gxl-core.c +4 -3
@@ -35,12 +35,13 @@ static irqreturn_t meson_irq_handler(int irq, void *data)complete (&mc->chanlist[flow].complete);return IRQ_HANDLED ; } -dev_err (mc->dev,"%s %d Got irq for flow %d but ctrl is empty\n" , __func__, irq, flow); +dev_err_ratelimited (mc->dev,"%s %d Got irq for flow %d but ctrl is empty\n" , __func__, irq, flow); +return IRQ_NONE ; } } -dev_err (mc->dev,"%s %d from unknown irq\n" , __func__, irq); -return IRQ_HANDLED ; +dev_err_ratelimited (mc->dev,"%s %d from unknown irq\n" , __func__, irq); +return IRQ_NONE ; }static struct meson_alg_template mc_algs[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 518/2214 crypto: hisilicon/hpre - fix pointer dereference before length check
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weili Qian <[email protected]>
[ Upstream commit 9770bb7d335f8f8db01e99168bbdd9ce2cb6238c ]
In hpre_rsa_drop_leading_zeros(), the loop condition dereferences *ptr before checking *len, causing an out-of-bounds read when *len is zero.
Swap to while (*len && !**ptr) to test length first.
--- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/hisilicon/hpre/hpre_crypto.c +1 -1
@@ -746,7 +746,7 @@ static void hpre_dh_exit_tfm(struct crypto_kpp *tfm)static void hpre_rsa_drop_leading_zeros (const char **ptr,size_t *len) { -while (!**ptr && *len) { +while (*len && !**ptr) { (*ptr)++; (*len)--; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 519/2214 crypto: hisilicon/hpre - return -EOVERFLOW for small ECDH output buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weili Qian <[email protected]>
[ Upstream commit 232804a5ed70a8ace32c46d341d438aeba54bc67 ]
hpre_ecdh_msg_request_set() returns -EINVAL when the output buffer is too small, after setting req->dst_len to the required size. -EINVAL is misleading because the caller can retry with a larger buffer. Return -EOVERFLOW as other kpp implementations do.
--- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/hisilicon/hpre/hpre_crypto.c +1 -1
@@ -1480,7 +1480,7 @@ static int hpre_ecdh_msg_request_set(struct hpre_ctx *ctx,if (req->dst_len < ctx->key_sz <<1 ) { req->dst_len = ctx->key_sz <<1 ; -return -EINVAL ; +return -EOVERFLOW ; } tmp =kpp_request_ctx (req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 520/2214 crypto: hisilicon/hpre - fix ECDH destination DMA mapping
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weili Qian <[email protected]>
[ Upstream commit 12d8edda8cdb41d18c4891851e25bf58be6be995 ]
hpre_ecdh_dst_data_init() rejects valid requests whose output length does not equal ctx->key_sz << 1, and maps the user buffer using the user-provided len instead of the hardware transfer size. Drop the redundant length check and use ctx->key_sz << 1 for dma_map_single() so the whole hardware output is mapped.
--- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/hisilicon/hpre/hpre_crypto.c +3 -3
@@ -1543,13 +1543,13 @@ static int hpre_ecdh_dst_data_init(struct hpre_asym_request *hpre_req,struct device *dev = ctx->dev;dma_addr_t dma; -if (unlikely (!data || !sg_is_last (data) || len != ctx->key_sz <<1 )) { -dev_err (dev,"data or data length is illegal!\n" ); +if (unlikely (!data || !sg_is_last (data))) { +dev_err (dev,"data is illegal!\n" );return -EINVAL ; } hpre_req->dst =NULL ; - dma =dma_map_single (dev,sg_virt (data), len,DMA_FROM_DEVICE ); + dma =dma_map_single (dev,sg_virt (data), ctx->key_sz <<1 ,DMA_FROM_DEVICE );if (unlikely (dma_mapping_error (dev, dma))) {dev_err (dev,"dma map data err!\n" );return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 521/2214 crypto: hisilicon/hpre - fix GFP flags for dma_alloc_coherent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weili Qian <[email protected]>
[ Upstream commit 40ec9605cb195e065470f8f23ef94b1b541411a3 ]
The HPRE driver hard-codes GFP_ATOMIC for RSA/DH and GFP_KERNEL for ECDH. This may cause "scheduling while atomic" in atomic context or unnecessary allocation failures under memory pressure.
Select GFP flags dynamically based on CRYPTO_TFM_REQ_MAY_SLEEP and store them in hpre_asym_request::flags. The areq field is a union of rsa/dh/ecdh request pointers; reading base.flags through any union member other than the one that was written would be type-punning, so a dedicated flags field avoids that.
--- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/crypto/hisilicon/hpre/hpre_crypto.c +8 -2
@@ -139,6 +139,7 @@ struct hpre_asym_request {int req_id;hpre_cb cb;struct timespec64 req_time; +u32 flags; };static int hpre_alloc_req_id (struct hpre_ctx *ctx)
@@ -243,6 +244,7 @@ static int hpre_prepare_dma_buf(struct hpre_asym_request *hpre_req, struct scatterlist *data, unsigned int len, int is_src, dma_addr_t *tmp) { + gfp_t gfp = hpre_req->flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC;struct hpre_ctx *ctx = hpre_req->ctx;struct device *dev = ctx->dev;void *ptr;
@@ -252,7 +254,7 @@ static int hpre_prepare_dma_buf(struct hpre_asym_request *hpre_req,if (unlikely (shift <0 ))return -EINVAL ; - ptr =dma_alloc_coherent (dev, ctx->key_sz, tmp,GFP_ATOMIC ); + ptr =dma_alloc_coherent (dev, ctx->key_sz, tmp, gfp);if (unlikely (!ptr))return -ENOMEM ;
@@ -514,6 +516,7 @@ static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa) h_req =PTR_ALIGN (tmp,HPRE_ALIGN_SZ ); h_req->cb = hpre_rsa_cb; h_req->areq.rsa = akreq; + h_req->flags = akreq->base.flags; msg = &h_req->req;memset (msg,0 ,sizeof (*msg)); }else {
@@ -528,6 +531,7 @@ static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa) h_req =PTR_ALIGN (tmp,HPRE_ALIGN_SZ ); h_req->cb = hpre_dh_cb; h_req->areq.dh = kreq; + h_req->flags = kreq->base.flags; msg = &h_req->req;memset (msg,0 ,sizeof (*msg)); msg->key =cpu_to_le64 (ctx->dh.dma_xa_p);
@@ -1487,6 +1491,7 @@ static int hpre_ecdh_msg_request_set(struct hpre_ctx *ctx, h_req =PTR_ALIGN (tmp,HPRE_ALIGN_SZ ); h_req->cb = hpre_ecdh_cb; h_req->areq.ecdh = req; + h_req->flags = req->base.flags; msg = &h_req->req;memset (msg,0 ,sizeof (*msg)); msg->in =cpu_to_le64 (DMA_MAPPING_ERROR );
@@ -1508,6 +1513,7 @@ static int hpre_ecdh_msg_request_set(struct hpre_ctx *ctx,static int hpre_ecdh_src_data_init (struct hpre_asym_request *hpre_req,struct scatterlist *data,unsigned int len) { +gfp_t gfp = hpre_req->flags &CRYPTO_TFM_REQ_MAY_SLEEP ?GFP_KERNEL :GFP_ATOMIC ;struct hpre_sqe *msg = &hpre_req->req;struct hpre_ctx *ctx = hpre_req->ctx;struct device *dev = ctx->dev;
@@ -1521,7 +1527,7 @@ static int hpre_ecdh_src_data_init(struct hpre_asym_request *hpre_req,if (unlikely (shift <0 ))return -EINVAL ; - ptr =dma_alloc_coherent (dev, ctx->key_sz <<2 , &dma,GFP_KERNEL ); + ptr =dma_alloc_coherent (dev, ctx->key_sz <<2 , &dma, gfp);if (unlikely (!ptr))return -ENOMEM ;
Signature · 1 line
2.53.0