6.12.117-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 805/1536 KVM: PPC: Fix get_d_signext() 12-bit displacement for paired-single D-form
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amit Machhiwal <[email protected]>
commit 31895b0ff96778b524c74b43a108090581271603 upstream.
get_d_signext() has two compounding bugs since its introduction in 2010:
1. The extraction mask 0x8FF silently drops bits 8-10 of the 12-bit D field (PPC ISA bits 21-23), corrupting any displacement that has any of those bits set.
2. The sign-magnitude idiom "-(d & 0x7ff)" is wrong for two's-complement:
for D=0xFFC (encoding of -4) it returns -252 instead of -4.
Together these errors produce a wrong effective address for psq_l, psq_lu, psq_st, and psq_stu whenever the displacement is negative or is a positive value >= 0x100 with bits 8-10 set — essentially any real-world paired- single stack-relative access.
The D field occupies the bottom 12 bits of the instruction word (confirmed by the adjacent W and I extractions via inst_get_field(inst,16,16) and inst_get_field(inst,17,19)). Replace the open-coded logic with the standard sign_extend32(inst & 0xfff, 11), which correctly performs two's-complement sign extension from 12 bits to 32 bits.
--- arch/powerpc/kvm/book3s_paired_singles.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/powerpc/kvm/book3s_paired_singles.c +1 -6
@@ -479,12 +479,7 @@ static bool kvmppc_inst_is_paired_singlestatic int get_d_signext (u32 inst) { -int d = inst &0x8ff ; - -if (d &0x800 ) -return -(d &0x7ff ); - -return (d &0x7ff ); +return sign_extend32 (inst &0xfff ,11 ); } static int kvmppc_ps_three_in(struct kvm_vcpu *vcpu, bool rc,
Greg Kroah-Hartman
maintainerPATCH 806/1536 HID: zydacron: validate key report length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 9932c9af185f8586e883d44ca562c12f4487c762 upstream.
The HID core invokes raw_event callbacks before validating the report length. zc_raw_event() verifies the report ID in byte zero and then reads the key code from byte one for report IDs 0x02 and 0x03 without checking that the second byte is present.
A one-byte report reproduced the issue under KASAN:
BUG: KASAN: slab-out-of-bounds in zc_raw_event+0x54c/0x580 Read of size 1 by task hidtrigger/93 Call Trace: zc_raw_event+0x54c/0x580 __hid_input_report+0x2ef/0x3a0 inject_store+0x479/0x490 [faketrans]
Require both the report ID and key code before processing the report.
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-zydacron.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-zydacron.c +3 -0
@@ -114,6 +114,9 @@ static int zc_raw_event(struct hid_devicunsigned key;unsigned short index; +if (size <2 ) +return 0 ; +if (report->id == data[0 ] && (hdev->claimed &HID_CLAIMED_INPUT )) {/* break keys */
Greg Kroah-Hartman
maintainerPATCH 807/1536 HID: amd_sfh: Remove unsupported motion-state field from accelerometer report
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Basavaraj Natikar <[email protected]>
commit 6ff86122906357687735dd379c6279e3b2fa26af upstream.
The accelerometer HID report descriptor declares a trailing motion-state field (usage 0x0451), but the Sensor Fusion Hub never reports this data, so each accelerometer input report is one byte shorter than the descriptor advertises.
This was previously harmless because hid-core zero-padded short reports. Since commit 0a3fe972a7cb ("HID: core: Mitigate potential OOB by removing bogus memset()") such reports are rejected instead:
hid-sensor-hub 0020:1022:0001.0003: Event data for report 1 was too short (15 vs 14)
As a result the accelerometer input events are dropped and screen auto-rotation stops working on AMD SFH systems.
Remove the motion-state field from the accelerometer report descriptor and drop the unused in_accel_shake_detection member, so the descriptor matches the report actually provided by the hardware.
--- drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h | 2 -- drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h | 7 ------- 2 files changed, 9 deletions(-)
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h +0 -2
@@ -48,8 +48,6 @@ struct accel3_input_report {int in_accel_x_value;int in_accel_y_value;int in_accel_z_value; -/* include if required to support the "shake" event */ -u8 in_accel_shake_detection; } __packed;struct gyro_feature_report {
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h +0 -7
@@ -169,13 +169,6 @@ static const u8 accel3_report_descriptor0x95 ,1 ,/* HID report count (1) */ 0x55 ,0x0E ,/* HID unit exponent(0x0E) */ 0X81 ,0x02 ,/* HID Input (Data_Arr_Abs) */ - -0x0A ,0x51 ,0x04 ,/* HID usage sensor data motion state */ -0x15 ,0 ,/* HID logical Min_8(0) False = Still*/ -0x25 ,1 ,/* HID logical Min_8(1) True = In motion */ -0x75 ,8 ,/* HID report size(8) */ -0x95 ,1 ,/* HID report count (1) */ -0X81 ,0x02 ,/* HID Input (Data_Arr_Abs) */ 0xC0 /* HID end collection */ };
Greg Kroah-Hartman
maintainerPATCH 808/1536 HID: amd_sfh: Use report type from request node
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Basavaraj Natikar <[email protected]>
commit 85f1bea97f1909f81577cfcf3e4db9017e7f5337 upstream.
Use report type from request node while sending feature and input reports to HID core. The cli_data report type array is never assigned and feature reports are sent as input reports.
--- drivers/hid/amd-sfh-hid/amd_sfh_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +2 -2
@@ -95,7 +95,7 @@ void amd_sfh_work(struct work_struct *wo cli_data->feature_report[current_index]);if (report_size)hid_input_report (cli_data->hid_sensor_hubs[current_index], - cli_data->report_type[current_index], + node_type, cli_data->feature_report[current_index], report_size,0 );else pr_err ("AMDSFH: Invalid report size\n" );
@@ -104,7 +104,7 @@ void amd_sfh_work(struct work_struct *wo report_size = mp2_ops->get_in_rep (current_index, sensor_index, report_id, in_data);if (report_size)hid_input_report (cli_data->hid_sensor_hubs[current_index], - cli_data->report_type[current_index], + node_type, in_data->input_report[current_index], report_size,0 );else pr_err ("AMDSFH: Invalid report size\n" );
Greg Kroah-Hartman
maintainerPATCH 809/1536 HID: core: Fix out-of-bounds left shift by 32 in s32ton()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 5fe63b415c636c7f4f6848a8e53bdd4bbf0c300d upstream.
Syzbot reported an out-of-bounds shift (32-bit integer shifted left by
32) in the s32ton() routine in the HID core. This routine converts a signed 32-bit integer to a signed n-bit integer, and it caps the value of n at 32. But when n == 32 there's no need to do anything; it can simply return the input value. This will avoid calculating (1 << n) when n is 32, which was the cause of the invalid shift.
--- drivers/hid/hid-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +2 -2
@@ -71,8 +71,8 @@ static u32 s32ton(__s32 value, unsignedif (!value || !n)return 0 ; -if (n >32 ) - n =32 ; +if (n >=32 ) +return (u32 ) value; a = value >> (n -1 );if (a && a !=-1 )
Greg Kroah-Hartman
maintainerPATCH 810/1536 HID: cougar: reject short special-key reports
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit c6c0df8a4b73a0d563c5e64de640ef5ff525fc82 upstream.
The HID core invokes raw_event callbacks before validating the report length. cougar_raw_event() reads the key code and action from offsets one and two without checking that those bytes are present. A short report on the special interface can therefore cause an out-of-bounds read.
Consume reports that do not contain the action field before accessing the fixed offsets, consistent with the callback's handling of other reports on the special interface.
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-cougar.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-cougar.c +3 -0
@@ -270,6 +270,9 @@ static int cougar_raw_event(struct hid_dif (!shared->enabled || !shared->input)return -EPERM ; +if (size <=COUGAR_FIELD_ACTION ) +return -EPERM ; + code = data[COUGAR_FIELD_CODE ]; action = data[COUGAR_FIELD_ACTION ];for (i =0 ; cougar_mapping[i][0 ]; i++) {
Greg Kroah-Hartman
maintainerPATCH 811/1536 HID: cp2112: validate response report lengths
In reply to Greg Kroah-Hartman6.12-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
@@ -1369,6 +1369,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));
@@ -1402,11 +1405,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 );
@@ -1433,4 +1441,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 812/1536 HID: elo: reject short touchscreen reports
In reply to Greg Kroah-Hartman6.12-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 813/1536 HID: logitech-dj: validate unnumbered keyboard reports
In reply to Greg Kroah-Hartman6.12-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 814/1536 HID: mcp2200: validate READ_ALL response length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 26ce0e6bf0b27fc6a2f490f38555dfd0a27c9605 upstream.
The HID core invokes raw_event callbacks before validating the report length. mcp2200_raw_event() casts a READ_ALL response to struct mcp_read_all_resp and reads fields through offset ten without checking that the response contains the structure.
A one-byte READ_ALL response reproduced the issue under KASAN:
BUG: KASAN: slab-out-of-bounds in mcp2200_raw_event+0x24b/0x3a0 Read of size 1 by task hidtrigger/89 Call Trace: mcp2200_raw_event+0x24b/0x3a0 kasan_report+0x139/0x170
Reject an incomplete READ_ALL response with a protocol error before reading its fields. The common completion path then wakes the command waiter with the error instead of leaving it to time out.
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-mcp2200.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hid/hid-mcp2200.c +5 -0
@@ -296,6 +296,11 @@ static int mcp2200_raw_event(struct hid_switch (data[0 ]) {case READ_ALL : +if (size <sizeof (*all_resp)) { + mcp->status = -EPROTO ; +break ; + } + all_resp = (struct mcp_read_all_resp *) data; mcp->status =0 ; mcp->gpio_inval = all_resp->io_port_val_bmap;
Greg Kroah-Hartman
maintainerPATCH 815/1536 HID: mcp2221: validate response report length
In reply to Greg Kroah-Hartman6.12-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
@@ -766,7 +766,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 816/1536 HID: picoLCD: check for fb_deferred_io_init() error
In reply to Greg Kroah-Hartman6.12-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
@@ -527,17 +527,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 817/1536 HID: prodikeys: validate fixed-format MIDI reports
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 0ff37294c41bd925258893310398bc2b45fcd4a7 upstream.
The HID core invokes raw_event callbacks before validating the report length. Prodikeys reports 0x01 and 0x04 are passed to handlers that always read bytes one through three, regardless of the supplied size. A truncated report can therefore cause an out-of-bounds read.
Require four bytes for the two fixed-format reports. Keep report 0x03 on its existing variable-length path, which derives the number of note pairs from size and only accesses complete pairs.
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-prodikeys.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hid/hid-prodikeys.c +6 -1
@@ -772,8 +772,13 @@ static int pk_raw_event(struct hid_devicif (report->id == data[0 ])switch (report->id) {case 0x01 :/* midi keys (qwerty)*/ -case 0x03 :/* midi keyboard (musical)*/ case 0x04 :/* extra/midi keys (qwerty)*/ +if (size <4 ) +break ; + ret =pcmidi_handle_report (pm, report->id, + data, size); +break ; +case 0x03 :/* midi keyboard (musical)*/ ret =pcmidi_handle_report (pm, report->id, data, size);break ;
Greg Kroah-Hartman
maintainerPATCH 818/1536 HID: pxrc: reject short input reports
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
commit 0deb22da5a8c6663c3e071f55fd7d7e3189f5517 upstream.
The HID core invokes raw_event callbacks before validating the report length. pxrc_raw_event() reads byte seven and writes bytes one and seven without checking that the report contains those bytes.
A one-byte input report reproduced the first invalid access under KASAN:
BUG: KASAN: slab-out-of-bounds in pxrc_raw_event+0x161/0x260 Read of size 1 by task hidtrigger/90 Call Trace: pxrc_raw_event+0x161/0x260 kasan_report+0x139/0x170
Require all eight bytes before reading or rewriting the report.
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-pxrc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-pxrc.c +3 -0
@@ -55,6 +55,9 @@ static int pxrc_raw_event(struct hid_dev {struct pxrc_priv *priv =hid_get_drvdata (hdev); +if (size <8 ) +return 0 ; +if (priv->alternate) priv->slider = data[7 ];else
Greg Kroah-Hartman
maintainerPATCH 819/1536 HID: quirks: Always poll the Anne Pro 2 with product ID a292
In reply to Greg Kroah-Hartman6.12-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
@@ -711,6 +711,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 820/1536 HID: roccat: isku: reject short button reports
In reply to Greg Kroah-Hartman6.12-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
@@ -411,6 +411,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 821/1536 HID: roccat: koneplus: reject short button reports
In reply to Greg Kroah-Hartman6.12-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
@@ -523,6 +523,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 822/1536 HID: roccat: konepure: reject short button reports
In reply to Greg Kroah-Hartman6.12-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
@@ -181,6 +181,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 823/1536 HID: roccat: kovaplus: reject short button reports
In reply to Greg Kroah-Hartman6.12-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
@@ -614,6 +614,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 824/1536 HID: roccat: pyra: reject short button reports
In reply to Greg Kroah-Hartman6.12-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
@@ -557,6 +557,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 825/1536 HID: roccat: ryos: reject short special reports
In reply to Greg Kroah-Hartman6.12-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
@@ -189,6 +189,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 826/1536 HID: roccat: savu: reject short special reports
In reply to Greg Kroah-Hartman6.12-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
@@ -182,6 +182,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 827/1536 ovl: set OVL_WHITEOUTS before publishing the upper dir
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit cbec8610ec5aaf35df50094ff639febc23f20773 upstream.
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.
---
[ backport: context: the store is followed by the unlock: label ]
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
@@ -845,9 +845,9 @@ static int ovl_copy_up_workdir(struct ovif (!c->metacopy)ovl_set_upperdata (inode); -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); out:
fs/overlayfs/readdir.c +2 -1
@@ -961,7 +961,8 @@ static int ovl_dir_open(struct inode *inreturn PTR_ERR (realfile); } od->realfile = realfile; - od->is_real =ovl_dir_is_real (inode); + od->is_real = !OVL_TYPE_MERGE (type) && + !ovl_test_flag (OVL_WHITEOUTS , inode); od->is_upper =OVL_TYPE_UPPER (type); file->private_data = od;
Greg Kroah-Hartman
maintainerPATCH 828/1536 io_uring/kbuf: advance head when a pickup empties the buffer ring
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
Commit 8742f4b5a472c347fe568a73468a2d9e4d630b33 upstream.
io_ring_buffers_peek() flags the request with REQ_F_BL_EMPTY if the buffers it picked were the last ones available, comparing head to tail. When the loop breaks because max_len was exhausted the buffer was picked, but head is left pointing at it, so the flag isn't set if it was the last buffer. A bundle receive then retries, finds no buffer, and the request, which has received data, is marked as failed on account of the -ENOBUFS. That severs a link, and ends a multishot.
--- io_uring/kbuf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
io_uring/kbuf.c +3 -1
@@ -302,8 +302,10 @@ static int io_ring_buffers_peek(struct i arg->out_len += len; arg->max_len -= len; -if (!arg->max_len) +if (!arg->max_len) { + head++;break ; + } buf =io_ring_head_to_buf (br, ++head, bl->mask); }while (--nr_iovs);
Greg Kroah-Hartman
maintainerPATCH 829/1536 io_uring/net: keep recvmsg buffer select length within MAX_RW_COUNT
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
Commit 18d3f56eb6e6500a65d81cf265f0fe74fd9ecab6 upstream.
io_recvmsg() takes the transfer length from the ring provided buffer when sqe->len is 0, and such a buffer can be up to 4G. min_ret is an int, so 2G or more makes it negative and the (ret < min_ret) block is skipped, and the oversized length reaches the socket layer unchanged: an empty socket then completes with 0 instead of arming poll, and a short read is reported as complete. Clamp the length to MAX_RW_COUNT, as io_recv() does.
--- io_uring/net.c | 1 + 1 file changed, 1 insertion(+)
io_uring/net.c +1 -0
@@ -1061,6 +1061,7 @@ retry_multishot: sel =io_buffer_select (req, &len, issue_flags);if (!sel.addr)return -ENOBUFS ; + len =min_t (size_t, len,MAX_RW_COUNT );if (req->flags &REQ_F_APOLL_MULTISHOT ) { ret =io_recvmsg_prep_multishot (kmsg, sr, &sel.addr, &len);
Greg Kroah-Hartman
maintainerPATCH 830/1536 io_uring/net: dont retry a non-blocking connect() that fails with -EAGAIN
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daan De Meyer <[email protected]>
Commit 71537ed811107c514c0342e98902d489d6d2b7cd upstream.
IORING_OP_CONNECT on an O_NONBLOCK AF_UNIX stream socket retries a connect that fails with -EAGAIN because the listener's backlog is full. Polling the client socket doesn't help: an unconnected stream socket reports EPOLLOUT and EPOLLHUP right away, before the backlog drains. So io_uring retries the connect until the apoll retry limit is hit, then punts the request to io-wq. With a full backlog, io_connect() runs 128 times in the submitting task and once more in a new io-wq worker. That worker stays in the task's thread group, so a later unshare(CLONE_NEWUSER) fails with -EINVAL.
None of this changes the result. __sys_connect_file() adds the socket's own O_NONBLOCK to every attempt, so the attempt from io-wq fails with -EAGAIN as well. That -EAGAIN becomes the CQE result, and connect(2) returns the same -EAGAIN.
Let's complete the request with -EAGAIN right away when the socket has O_NONBLOCK set, like connect(2) does. io_accept() already completes -EAGAIN this way for IORING_ACCEPT_DONTWAIT. -EINPROGRESS still waits for the connection to complete. A blocking socket still ends up in io-wq, where the connect sleeps until the listener accepts.
--- io_uring/net.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
io_uring/net.c +11 -0
@@ -1811,6 +1811,17 @@ int io_connect(struct io_kiocb *req, unsif (connect->seen_econnaborted) goto out; connect->seen_econnaborted = true; + }else if (req->file->f_flags &O_NONBLOCK ) { +/* +* __sys_connect_file() adds O_NONBLOCK from the socket +* to every attempt, so a retry from io-wq fails with +* -EAGAIN as well. A poll on the socket doesn't wait +* until a retry can succeed. For example, an AF_UNIX +* client reports EPOLLOUT right away while the +* listener's backlog is full. Complete the request +* with -EAGAIN, like connect(2) does. +*/ + goto out; }return -EAGAIN ; }
Greg Kroah-Hartman
maintainerPATCH 831/1536 io_uring/io-wq: no new workers once the exit has begun
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
Commit 47c68f925062a6013235d06add85a59f7d91e0fb upstream.
io_wq_exit_start() sets IO_WQ_BIT_EXIT, but worker creation task_work queued before that stays queued until io_wq_exit_workers() cancels it. In between the task runs its task_work while canceling requests, and a worker can still get created.
That's a problem for exec. begin_new_exec() calls io_uring_task_cancel() after de_thread(), when it's supposedly the only thread left, and io_wq_exit_workers() only waits for ->worker_done, which a worker completes before do_exit(). So the exiting worker is still in the thread group, using the mm, files and sighand, while exec replaces them. Easy to hit with a signal pending when create_io_thread() fails and the retry gets queued right before execve().
Cancel the queued creation task_work as soon as the exit bit is set. Pending work that isn't otherwise canceled now ends with -ECANCELED when the io-wq is destroyed, rather than depending on whether the task happened to run its task_work first.
[axboe: the barrier is already upstream, see 0e5663856b69, only the
cancel is new]
--- io_uring/io-wq.c | 6 ++++++ 1 file changed, 6 insertions(+)
io_uring/io-wq.c +6 -0
@@ -1320,6 +1320,12 @@ void io_wq_exit_start(struct io_wq *wq)set_bit (IO_WQ_BIT_EXIT , &wq->state);/* Pairs with task_work_add() in io_queue_worker_create(). */ smp_mb__after_atomic (); +/* +* No more workers from here on. The caller is going to run its task +* work, and on exec a thread that is created now would still be +* around, exiting, by the time that the caller must be on its own. +*/ +io_wq_cancel_tw_create (wq); }static void io_wq_cancel_tw_create (struct io_wq *wq)
Greg Kroah-Hartman
maintainerPATCH 832/1536 io_uring/rsrc: charge buffer arrays and nodes to memcg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
Commit 075d5837bafc317e796548f721b8fbf7add6821d upstream.
The io_mapped_ubuf of a registered buffer has one bio_vec per page, unless the pages coalesce into huge pages. Huge pages only count against RLIMIT_MEMLOCK once per ring, so a buffer that maps the same 2MB folio over and over in a way that defeats coalescing gets a full bvec array per registration while only the one folio counts as locked. 1GB of that registered in 100 slots took several times a 64MB memory.max, with 2.6MB charged.
Allocate the io_mapped_ubuf and the io_rsrc_node with GFP_KERNEL_ACCOUNT. An object reused from the ring caches stays charged to whoever allocated it first, same as the io_kiocb cache.
[axboe: 6.12 predates the rsrc node rework, charge the imu kvmalloc() and the node kzalloc() instead]
--- io_uring/rsrc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/rsrc.c +2 -2
@@ -183,7 +183,7 @@ struct io_rsrc_node *io_rsrc_node_alloc( ref_node =io_alloc_cache_get (&ctx->rsrc_node_cache);if (!ref_node) { - ref_node =kzalloc (sizeof (*ref_node),GFP_KERNEL ); + ref_node =kzalloc (sizeof (*ref_node),GFP_KERNEL_ACCOUNT );if (!ref_node)return NULL ; }
@@ -982,7 +982,7 @@ static int io_sqe_buffer_register(struct/* If it's huge page(s), try to coalesce them into fewer bvec entries */ coalesced =io_try_coalesce_buffer (&pages, &nr_pages, &data); - imu =kvmalloc (struct_size (imu, bvec, nr_pages),GFP_KERNEL ); + imu =kvmalloc (struct_size (imu, bvec, nr_pages),GFP_KERNEL_ACCOUNT );if (!imu) goto done;
Greg Kroah-Hartman
maintainerPATCH 833/1536 io_uring: charge tctx nodes and personalities
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
Commit 0b34e7b20a48710b6f53716bf7030920b69fdbdd upstream.
The io_tctx_node allocated the first time a task touches a ring, and the XArray nodes behind tctx->xa and ctx->personalities, are plain GFP_KERNEL. tctx->xa is indexed by the ring pointer, so nearly every entry needs nodes of its own, and a task gets one entry per ring it has used. 642 threads on 4000 rings held 2.3GB with 59MB charged against a 64MB memory.max.
Allocate the node with GFP_KERNEL_ACCOUNT and set XA_FLAGS_ACCOUNT on both XArrays.
[axboe: 6.12 has kmalloc() for the node, inline in __io_uring_add_tctx_node()]
--- io_uring/io_uring.c | 2 +- io_uring/tctx.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
io_uring/io_uring.c +1 -1
@@ -319,7 +319,7 @@ static __cold struct io_ring_ctx *io_rinif (ret) goto free_ref;init_completion (&ctx->ref_comp); -xa_init_flags (&ctx->personalities,XA_FLAGS_ALLOC1 ); +xa_init_flags (&ctx->personalities,XA_FLAGS_ALLOC1 |XA_FLAGS_ACCOUNT );mutex_init (&ctx->uring_lock);init_waitqueue_head (&ctx->cq_wait);init_waitqueue_head (&ctx->poll_wq);
io_uring/tctx.c +2 -2
@@ -93,7 +93,7 @@ __cold int io_uring_alloc_task_context(sreturn ret; } -xa_init (&tctx->xa); +xa_init_flags (&tctx->xa,XA_FLAGS_ACCOUNT );init_waitqueue_head (&tctx->wait);atomic_set (&tctx->in_cancel,0 );atomic_set (&tctx->inflight_tracked,0 );
@@ -125,7 +125,7 @@ int __io_uring_add_tctx_node(struct io_r } }if (!xa_load (&tctx->xa, (unsigned long )ctx)) { - node =kmalloc (sizeof (*node),GFP_KERNEL ); + node =kmalloc (sizeof (*node),GFP_KERNEL_ACCOUNT );if (!node)return -ENOMEM ; node->ctx = ctx;
Greg Kroah-Hartman
maintainerPATCH 834/1536 io_uring: free XArray nodes left by a failed store
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
Commit 51bab09b7ca1a9a6dd9303a3b7ee346f8128c963 upstream.
A failed xa_store() can leave nodes without entries in the tree, and erasing every entry doesn't free those. An XArray needs xa_destroy() before it goes away, even an empty one. That was dropped for tctx->xa in commit ca6484cd308a ("io_uring: no need to call xa_destroy() on empty xarray") over a lockdep report from freeing the tctx in softirq context, and ctx->personalities never had it.
Now that the nodes are charged, a store can fail at memory.max and the leaked nodes stay charged. Call xa_destroy() in io_uring_clean_tctx(), which the task runs itself in process context before the tctx is freed, in the error path of __io_uring_add_tctx_node(), and for ctx->personalities in io_ring_ctx_free().
[axboe: 6.12 installs the tctx before adding the node and has no error path that frees it, drop that hunk. There's no ctx->hpage_acct either]
--- io_uring/io_uring.c | 1 + io_uring/tctx.c | 2 ++ 2 files changed, 3 insertions(+)
io_uring/io_uring.c +1 -0
@@ -2856,6 +2856,7 @@ static __cold void io_ring_ctx_free(strukfree (ctx->cancel_table.hbs);kfree (ctx->cancel_table_locked.hbs);xa_destroy (&ctx->io_bl_xa); +xa_destroy (&ctx->personalities);kfree (ctx); }
io_uring/tctx.c +2 -0
@@ -197,6 +197,8 @@ __cold void io_uring_clean_tctx(struct iio_uring_del_tctx_node (index);cond_resched (); } +/* A failed xa_store() leaves nodes with no entry behind. */ +xa_destroy (&tctx->xa);if (wq) {/* * Must be after io_uring_del_tctx_node() (removes nodes under
Greg Kroah-Hartman
maintainerPATCH 835/1536 io_uring/sqpoll: dont wait for the thread to exit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
Commit 360395e8dbf9d23579f74b84a1af11190813b0f8 upstream.
io_sq_thread_stop() wakes the SQPOLL thread and waits for it to exit. The thread belongs to the thread group that created the ring, so a SIGSTOP or the cgroup freezer holds it in get_signal(), and the wake up doesn't change that. io_ring_exit_work() then sleeps in that wait until someone continues or kills the process. iou_exit has 64 slots, so 64 closed SQPOLL rings of a stopped process keep every other ring from being freed, for everyone.
Don't wait. Set the stop bit, wake the thread, and let it exit when it gets to run again. The sqd can now outlive its last ring, so give it a second refcount with one reference for the rings and one for the thread, and free it with the last one. The thread can't reach a freed ring, rings leave ctx_list before dropping their reference, and the io-wq hash is refcounted.
--- io_uring/sqpoll.c | 28 +++++++++++++++++++++++----- io_uring/sqpoll.h | 3 ++- 2 files changed, 25 insertions(+), 6 deletions(-)
io_uring/sqpoll.c +23 -5
@@ -59,6 +59,24 @@ void io_sq_thread_park(struct io_sq_data } } +/* +* The sqd has two holders: its rings, as one, and its thread. Neither waits +* for the other to let go. The one that lets go last frees the sqd. +*/ +static void io_sq_data_release (struct io_sq_data *sqd) +{ +if (refcount_dec_and_test (&sqd->free_refs)) +kfree (sqd); +} + +/* +* Ask the thread to exit, and don't wait for it. A thread that is stopped or +* frozen exits only when a user lets it run again, and the exit work of the +* ring would keep its place in the workqueue until then. All rings have left +* ctx_list by now and have no request left, so the thread can reach none of +* them. What it still uses is its own or counted: the sqd by free_refs, the +* hash of its io-wq by hash->refs. +*/ void io_sq_thread_stop (struct io_sq_data *sqd) {struct task_struct *tsk;
@@ -73,7 +91,6 @@ void io_sq_thread_stop(struct io_sq_datawake_up_process (tsk); }mutex_unlock (&sqd->lock); -wait_for_completion (&sqd->exited); }void io_put_sq_data (struct io_sq_data *sqd)
@@ -82,7 +99,7 @@ void io_put_sq_data(struct io_sq_data *sWARN_ON_ONCE (atomic_read (&sqd->park_pending));io_sq_thread_stop (sqd); -kfree (sqd); +io_sq_data_release (sqd); } }
@@ -156,10 +173,10 @@ static struct io_sq_data *io_get_sq_dataatomic_set (&sqd->park_pending,0 );refcount_set (&sqd->refs,1 ); +refcount_set (&sqd->free_refs,2 );INIT_LIST_HEAD (&sqd->ctx_list);mutex_init (&sqd->lock);init_waitqueue_head (&sqd->wait); -init_completion (&sqd->exited);return sqd; }
@@ -426,7 +443,7 @@ static int io_sq_thread(void *data)io_run_task_work ();mutex_unlock (&sqd->lock); err_out: -complete (&sqd->exited); +io_sq_data_release (sqd);do_exit (0 ); }
@@ -540,7 +557,8 @@ __cold int io_sq_offload_create(struct i }return 0 ; err_sqpoll: -complete (&ctx->sq_data->exited); +/* no thread was made: let go of its share */ +io_sq_data_release (ctx->sq_data); err:io_sq_thread_finish (ctx);return ret;
io_uring/sqpoll.h +2 -1
@@ -2,6 +2,8 @@struct io_sq_data {refcount_t refs; +/* one for all the rings, one for the thread: the last put frees */ +refcount_t free_refs;atomic_t park_pending;struct mutex lock;
@@ -18,7 +20,6 @@ struct io_sq_data {u64 work_time;unsigned long state; -struct completion exited; };int io_sq_offload_create (struct io_ring_ctx *ctx,struct io_uring_params *p);
Greg Kroah-Hartman
maintainerPATCH 836/1536 io_uring/timeout: count cancelled timeouts in cq_timeouts
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Yongkang <[email protected]>
Commit 1c8b49851543f41fc8bb18bcd1f15cc93d14b530 upstream.
io_timeout_cancel() posts the cancelled timeout's -ECANCELED CQE without advancing ctx->cq_timeouts. io_timeout_fn() and io_kill_timeout() advance it for every timeout CQE they post, and io_flush_timeouts() computes the number of non-timeout completions as
seq = cached_cq_tail - cq_timeouts
to compare against each off timeout's target_seq. The cancelled timeout's CQE is therefore counted as a regular completion, so every cancellation makes an already armed off timeout fire one completion early.
A ring with a keep-alive timeout of off=4 completes it after two NOPs when one off=100 victim is cancelled through IORING_OP_ASYNC_CANCEL, and before any NOP when two victims are cancelled. The cancel CQE should count, but the cancelled timeouts' -ECANCELED CQEs must not: the expected counts are three and two NOPs respectively.
Advance cq_timeouts when io_timeout_extract() succeeds, under timeout_lock and before the -ECANCELED completion is queued, matching io_timeout_fn() and io_kill_timeout(). The -ENOENT and -EALREADY paths post no new timeout CQE and keep their accounting. Both the ASYNC_CANCEL and the TIMEOUT_REMOVE path go through io_timeout_cancel().
--- io_uring/timeout.c | 3 +++ 1 file changed, 3 insertions(+)
io_uring/timeout.c +3 -0
@@ -303,6 +303,9 @@ int io_timeout_cancel(struct io_ring_ctxspin_lock_irq (&ctx->timeout_lock); req =io_timeout_extract (ctx, cd); +if (!IS_ERR (req)) +atomic_set (&ctx->cq_timeouts, +atomic_read (&ctx->cq_timeouts) +1 );spin_unlock_irq (&ctx->timeout_lock);if (IS_ERR (req))
Greg Kroah-Hartman
maintainerPATCH 837/1536 media: rc: Fix build failure with CONFIG_LIRC disabled
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
commit 0c795849fd70d6bdb99aea5dd08d9b43128612f6 upstream.
commit 37efd09ba2c6 ("media: rc: Ensure registered is cleared in error path") broke the build if CONFIG_LIRC was not enabled.
--- drivers/media/rc/lirc_dev.c | 3 +++ drivers/media/rc/rc-main.c | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/media/rc/lirc_dev.c +3 -0
@@ -775,6 +775,9 @@ void lirc_unregister(struct rc_dev *dev)unsigned long flags;struct lirc_fh *fh; +if (!device_is_registered (&dev->lirc_dev)) +return ; +dev_dbg (&dev->dev,"lirc_dev: driver %s unregistered from minor = %d\n" , dev->driver_name,MINOR (dev->lirc_dev.devt));
drivers/media/rc/rc-main.c +1 -2
@@ -1981,8 +1981,7 @@ out_lirc:scoped_guard (mutex, &dev->lock) dev->registered = false; -if (device_is_registered (&dev->lirc_dev)) -lirc_unregister (dev); +lirc_unregister (dev);device_del (&dev->dev);/* registered already cleared above */ goto out_free_table;
Greg Kroah-Hartman
maintainerPATCH 838/1536 drm/amdgpu/powerplay: Align get_tonga_state_array() header with prototype
In reply to Greg Kroah-Hartman6.12-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
@@ -1500,11 +1500,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 839/1536 netfilter: conntrack: always lower timeout for non-closing RST packets
In reply to Greg Kroah-Hartman6.12-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
@@ -1326,7 +1326,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 840/1536 opp: fix use after free in _update_opp_table_clk()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Griffin <[email protected]>
commit 1f6de65e3314519ce462bfd3a1d29e918f97e4e5 upstream.
dev_pm_opp_put_opp_table() frees the opp_table which is subsquently used by dev_err_probe(). This causes an Oops during boot on gs101-oriole.
cpu cpu0: error 000000006b6b6b6b: Couldn't find clock
Unable to handle kernel paging request at virtual address 006b6b6b6b6b6cd3 ... Hardware name: Oriole (DT) pstate: 00400005 (nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : _of_add_table_indexed+0x80/0xbb0 lr : _of_add_table_indexed+0x6c/0xbb0 ... Call trace: _of_add_table_indexed+0x80/0xbb0 (P) dev_pm_opp_of_cpumask_add_table+0x70/0x120 dt_cpufreq_probe+0x23c/0x480 platform_probe+0x64/0xb8
--- drivers/opp/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/opp/core.c +4 -2
@@ -1512,6 +1512,8 @@ static struct opp_table *_update_opp_tab struct opp_table *opp_table, bool getclk) { +int ret; +/* * Return early if we don't need to get clk or we have already done it * earlier.
@@ -1538,9 +1540,9 @@ static struct opp_table *_update_opp_tab opp_table->clk =clk_get_optional (dev,NULL );if (IS_ERR (opp_table->clk)) { + ret =dev_err_probe (dev,PTR_ERR (opp_table->clk),"Couldn't find clock\n" );dev_pm_opp_put_opp_table (opp_table); -dev_err_probe (dev,PTR_ERR (opp_table->clk),"Couldn't find clock\n" ); -return ERR_CAST (opp_table->clk); +return ERR_PTR (ret); }if (opp_table->clk)
Greg Kroah-Hartman
maintainerPATCH 841/1536 tun: Require CAP_NET_ADMIN to attach to an ownerless device
In reply to Greg Kroah-Hartman6.12-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
@@ -574,14 +574,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)
@@ -2795,7 +2799,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 842/1536 mm/rmap: dont discard lazyfree THPs at PMD level
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zi Yan <[email protected]>
[ Upstream commit 984c0700854e35779a2bcce6b02783e709b6efa2 ]
__discard_anon_folio_pmd_locked() clears a lazyfree THP's PMD before it determines whether the folio can be discarded, and restores it if the folio is dirty or has extra references. It is done under only the PMD lock and the anon_vma read lock inside try_to_unmap_one() and no mmap lock is held. The temporarily none PMD causes UAF.
A parallel munmap() or mremap() is supposed to serialize with it on the PMD lock, but zap_pmd_range() (called by munmap()) and move_page_tables() (called by mremap()) do not take the lock when they see the temporarily none PMD and skip the PMD. There is no more page table walk after the none PMD is restored:
- munmap(): free_pgtables() waits in unlink_anon_vmas() for the anon_vma lock, then free_pmd_range() drops the restored PMD as bad without removing the rmap, so the folio keeps a stale mapcount.
- whole-VMA MREMAP_DONTUNMAP: dontunmap_complete() unlinks the source VMA from its anon_vma while the restored PMD still maps the folio.
- plain mremap(): the THP is not moved but unmapped, so the THP's data is lost.
In the first two cases, the folio stays mapped, but no VMA that maps it is linked to its anon_vma. When the anon_vma is freed, it is still reachable when one rmap walks the folio. Racing lazyfree reclaim against MREMAP_DONTUNMAP as an unprivileged user reproduces a KASAN use-after-free in folio_lock_anon_vma_read() as reported in the Closes link.
One solution is to use an invalidated PMD instead of a cleared one until the discard is committed, but it needs arch fixes first.
1. GUP-fast still follows an invalidated PMD on riscv, LoongArch and s390.
2. sparc64 miscounts thp_pte_count when an invalidated PMD is set again or cleared.
To keep the fix simple for backport, stop discarding lazyfree THPs at PMD level instead. try_to_unmap_one() splits the PMD and discards the folio at PTE level.
unmap_huge_pmd_locked() and __discard_anon_folio_pmd_locked() are left in place, unused, to minimize this fix for backport and the invalidated PMD approach is planned as a follow-up series to use them again.
--- mm/rmap.c | 4 ---- 1 file changed, 4 deletions(-)
mm/rmap.c +0 -4
@@ -1698,10 +1698,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, }if (!pvmw.pte) { -if (unmap_huge_pmd_locked (vma, pvmw.address, pvmw.pmd, - folio)) - goto walk_done; -if (flags &TTU_SPLIT_HUGE_PMD ) {/* * We temporarily have to drop the PTL and
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 843/1536 smb: client: fix early procfs exposure race
In reply to Greg Kroah-Hartman6.12-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/smb/client/cifsfs.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
fs/smb/client/cifsfs.c +9 -11
@@ -1916,7 +1916,6 @@ static int __initinit_cifs (void) {int rc =0 ; -cifs_proc_init ();INIT_LIST_HEAD (&cifs_tcp_ses_list);/* * Initialize Global counters
@@ -1965,10 +1964,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)
@@ -2055,19 +2052,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
@@ -2103,8 +2103,6 @@ init_cifs(void)destroy_workqueue (decrypt_wq); out_destroy_cifsiod_wq:destroy_workqueue (cifsiod_wq); -out_clean_proc: -cifs_proc_clean ();return rc; }
@@ -2114,6 +2112,7 @@ exit_cifs(void)cifs_dbg (NOISY ,"exit_smb3\n" );unregister_filesystem (&cifs_fs_type);unregister_filesystem (&smb3_fs_type); +cifs_proc_clean ();cifs_release_automount_timer ();exit_cifs_idmap ();#ifdef CONFIG_CIFS_SWN_UPCALL
@@ -2136,7 +2135,6 @@ exit_cifs(void)destroy_workqueue (serverclose_wq);destroy_workqueue (cfid_put_wq);destroy_workqueue (cifsiod_wq); -cifs_proc_clean (); }MODULE_AUTHOR ("Steve French" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 844/1536 smb: client: do not pass a NULL buf to is_oplock_break()
In reply to Greg Kroah-Hartman6.12-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/smb/client/connect.c | 4 +++- fs/smb/client/smb2ops.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
fs/smb/client/connect.c +3 -1
@@ -1318,12 +1318,14 @@ cifs_demultiplex_thread(void *p) mids[i]->callback (mids[i]);release_mid (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 (&mid_count)); cifs_dump_mem("Received Data is: ", bufs[i],
fs/smb/client/smb2ops.c +1 -0
@@ -5290,6 +5290,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, *mid =smb2_find_mid (server, buf);if (*mid ==NULL ) {cifs_dbg (FYI ,"mid not found\n" ); + rc =-1 ; }else {cifs_dbg (FYI ,"mid found\n" ); (*mid)->decrypted = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 845/1536 ksmbd: deny access for an empty DACL instead of granting the request
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
[ Upstream commit de0cffef897c1c232ed973f89928cd6c93d0b1e3 ]
smb_check_perm_dacl() returns the access mask it computes to the SMB2 CREATE handler, which uses it as the granted access for the open. For a security descriptor whose DACL is present but contains no ACEs, the function is supposed to deny access: an empty (non-NULL) DACL grants no access to anyone except the object owner's implicit READ_CONTROL and WRITE_DAC (MS-DTYP 2.4.5).
The empty-DACL branch only denies when both
- the DACL has no trailing bytes (pdacl_size == sizeof(struct smb_acl)), and
- the request contains bits beyond READ_CONTROL / WRITE_DAC.
In every other case it takes the shared "goto err_out" with rc still 0, which returns success without modifying *pdaccess, so the caller grants the full requested access. Three problems follow:
- The READ_CONTROL / WRITE_DAC carve-out models the owner's implicit rights, but the check runs before is_owner is computed, so those rights are handed to *every* caller, not just the owner. For READ_CONTROL the SMB2 CREATE path does not fall back to inode_permission(), so any user can read the security descriptor of an object whose empty DACL is meant to deny them.
- A request of exactly READ_CONTROL and/or WRITE_DAC is granted to any caller. WRITE_DAC lets the handle rewrite the DACL.
- A DACL that declares zero ACEs but carries trailing bytes (pdacl_size > sizeof(struct smb_acl)) skips the deny entirely and is granted whatever was requested.
On shares where the NT ACL is the authoritative access control -- e.g. "force user" shares, where every client maps to one POSIX identity so POSIX cannot distinguish users -- this is an access-control bypass.
Compute is_owner before the empty-DACL branch and deny access from an empty DACL unless the caller is the owner requesting no more than READ_CONTROL / WRITE_DAC.
--- fs/smb/server/smbacl.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
fs/smb/server/smbacl.c +18 -8
@@ -1469,6 +1469,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,struct posix_acl_entry *pa_entry;unsigned int sid_type =SIDOWNER ;unsigned short ace_size; +bool is_owner; +vfsuid_t vfsuid;ksmbd_debug (SMB ,"check permission using windows acl\n" ); pntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap,
@@ -1489,19 +1491,27 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,if (pdacl_size > acl_size || pdacl_size <sizeof (struct smb_acl )) goto err_out; +if (!uid) + sid_type =SIDUNIX_USER ; +id_to_sid (uid, sid_type, &sid); + vfsuid =i_uid_into_vfsuid (idmap,d_inode (path->dentry)); + is_owner = uid ==from_kuid (&init_user_ns,vfsuid_into_kuid (vfsuid)); +if (!pdacl->num_aces) { -if (!(pdacl_size -sizeof (struct smb_acl )) && - *pdaccess & ~(FILE_READ_CONTROL_LE |FILE_WRITE_DAC_LE )) { +/* +* An empty (present, zero-ACE) DACL grants no access to +* anyone except the object owner's implicit READ_CONTROL +* and WRITE_DAC (MS-DTYP 2.4.5). Deny every other caller, +* deny the owner any access beyond those two bits, and do +* not let trailing bytes after a zero-ACE DACL become an +* implicit grant. +*/ +if (!is_owner || + (*pdaccess & ~(FILE_READ_CONTROL_LE |FILE_WRITE_DAC_LE ))) rc = -EACCES ; - goto err_out; - } goto err_out; } -if (!uid) - sid_type =SIDUNIX_USER ; -id_to_sid (uid, sid_type, &sid); -if (*pdaccess &FILE_MAXIMAL_ACCESS_LE ) { access_bits =READ_CONTROL |WRITE_DAC |FILE_READ_ATTRIBUTES |DELETE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 846/1536 ksmbd: prevent stale data from being written by SMB2 WRITE requests
In reply to Greg Kroah-Hartman6.12-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/smb/server/connection.c | 1 + fs/smb/server/smb2pdu.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-)
fs/smb/server/connection.c +1 -0
@@ -520,6 +520,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/smb/server/smb2pdu.c +25 -9
@@ -7173,23 +7173,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) {
@@ -7340,14 +7345,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 847/1536 ksmbd: prevent share root removal through empty paths
In reply to Greg Kroah-Hartman6.12-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/smb/server/smb2pdu.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/smb/server/smb2pdu.c +6 -0
@@ -6339,6 +6339,12 @@ static int smb2_create_link(struct ksmbd_work *work, }ksmbd_debug (SMB ,"target name is %s\n" , target_name); +/* The share root must never be removed. */ +if (link_name[0 ] =='\0' ) { + rc = -EINVAL ; + goto out; + } + rc =ksmbd_vfs_kern_path_locked (work, link_name,LOOKUP_NO_SYMLINKS , &parent_path, &path,0 );if (rc) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 848/1536 ksmbd: fix out-of-bounds read when padding the final compound response
In reply to Greg Kroah-Hartman6.12-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/smb/server/smb2pdu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/smb/server/smb2pdu.c +10 -3
@@ -538,7 +538,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 )
@@ -560,10 +560,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,KSMBD_DEFAULT_GFP ); + work->response_buf =kvzalloc (sz + pad_sz,KSMBD_DEFAULT_GFP );if (!work->response_buf)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 849/1536 ksmbd: verify transform SessionId matches the decrypted header
In reply to Greg Kroah-Hartman6.12-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/smb/server/server.c | 16 ++++++++++++ fs/smb/server/smb2pdu.c | 54 +++++++++++++++++++++++++++++++++++++++++ fs/smb/server/smb2pdu.h | 1 + 3 files changed, 71 insertions(+)
fs/smb/server/server.c +16 -0
@@ -169,12 +169,28 @@ 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_abort (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 ) {ksmbd_conn_abort (conn);return ; } work->encrypted = true; + + rc =ksmbd_check_transform_session (work, tr_sess_id); +if (rc <0 ) { +ksmbd_conn_abort (conn); +return ; + } }if (conn->ops->allocate_rsp_buf (work))
fs/smb/server/smb2pdu.c +54 -0
60 lines not on this page · raw message
fs/smb/server/smb2pdu.h +1 -0
@@ -447,6 +447,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 850/1536 ksmbd: fix use-after-free after a failed durable reconnect
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 248b5819591c577727930e4e255a455235fab50a ]
ksmbd_reopen_durable_fd() republishes a detached durable handle in the reconnecting session's file table and takes no reference for that entry. If smb2_open() then fails, cleanup relies on the final ksmbd_fd_put() to remove the volatile id.
Two reconnects of the same handle can both take a lookup reference before either attaches it. If the one that reopens first then fails and drops its references first, the other request makes the final put through ksmbd_put_durable_fd(). That frees the handle without removing the first session's table entry, so tearing that session down writes to freed memory.
BUG: KASAN: slab-use-after-free in __close_file_table_ids+0x14d/0x740 [ksmbd] Call Trace: __close_file_table_ids+0x14d/0x740 [ksmbd] ksmbd_destroy_file_table+0x76/0x100 [ksmbd] ksmbd_session_destroy+0xf8/0x480 [ksmbd] ksmbd_dispose_sessions+0x13e/0x200 [ksmbd] ksmbd_conn_sessions_cleanup+0x4c3/0x6d0 [ksmbd] Freed by task 1030: __ksmbd_close_fd+0x97d/0x1000 [ksmbd] smb2_open+0x14eb/0xd9f0 [ksmbd]
Commit 3515503322f4 ("ksmbd: fix durable reconnect error path file lifetime") handles a final put made by the reconnecting request, but not one made by another holder.
Remove the volatile id under the file-table lock on this error path, before the references are dropped, as ksmbd_close_fd() does on the request_open path just above. Removal then no longer depends on which holder makes the final put. The stale comment in the reconnect cleanup is updated to match. A successful reconnect is unchanged.
--- fs/smb/server/smb2pdu.c | 12 +++++++----- fs/smb/server/vfs_cache.c | 28 ++++++++++++++++++++++++++++ fs/smb/server/vfs_cache.h | 2 ++ 3 files changed, 37 insertions(+), 5 deletions(-)
fs/smb/server/smb2pdu.c +7 -5
@@ -3900,8 +3900,11 @@ int smb2_open(struct ksmbd_work *work)if (!rsp->hdr.Status) rsp->hdr.Status =STATUS_UNEXPECTED_IO_ERROR ; -if (fp) +if (fp) { +if (dh_info.reconnected && fp == dh_info.fp) +ksmbd_unpublish_reopened_fd (work, fp);ksmbd_fd_put (work, fp); + }smb2_set_err_rsp (work);ksmbd_debug (SMB ,"Error response: %x\n" , rsp->hdr.Status); }
@@ -3909,10 +3912,9 @@ int smb2_open(struct ksmbd_work *work)if (dh_info.reconnected) {/* * If reconnect succeeded, fp was republished in the -* session file table. On a later error, ksmbd_fd_put() -* above drops the session reference; drop the durable -* lookup reference through the same session-aware path so -* final close removes the volatile id before freeing fp. +* session file table, and the error path above has +* already removed its volatile id. Drop the durable +* lookup reference through the same session-aware path. */ if (rc && fp == dh_info.fp)ksmbd_fd_put (work, dh_info.fp);
fs/smb/server/vfs_cache.c +28 -0
@@ -486,6 +486,34 @@ static void set_close_state_blocked_works(struct ksmbd_file *fp)spin_unlock (&fp->f_lock); } +/** +* ksmbd_unpublish_reopened_fd() - remove a reopened durable handle from the +* session file table after its CREATE failed +* @work: smb work of the failed CREATE +* @fp: durable handle republished by ksmbd_reopen_durable_fd() +* +* The reopen publishes @fp in this session's table without taking a reference +* for the entry, so the CREATE error path's puts need not be the last ones. +* Another holder of a global-table reference, such as a concurrent reconnect +* of the same handle, can drop the last one through ksmbd_put_durable_fd(), +* which frees @fp without touching this table. Remove the id here, while +* the caller still holds its references. +* +* Every path that removes the id before the final put also clears +* @fp->volatile_id under ft->lock, so a valid id is still @fp's entry. +*/ +void ksmbd_unpublish_reopened_fd (struct ksmbd_work *work,struct ksmbd_file *fp) +{ +struct ksmbd_file_table *ft = &work->sess->file_table; + +write_lock (&ft->lock); +if (has_file_id (fp->volatile_id)) { +idr_remove (ft->idr, fp->volatile_id); + fp->volatile_id =KSMBD_NO_FID ; + } +write_unlock (&ft->lock); +} +int ksmbd_close_fd (struct ksmbd_work *work,u64 id) {struct ksmbd_file *fp;
fs/smb/server/vfs_cache.h +2 -0
@@ -155,6 +155,8 @@ static inline bool ksmbd_stream_fd(struct ksmbd_file *fp)int ksmbd_init_file_table (struct ksmbd_file_table *ft);void ksmbd_destroy_file_table (struct ksmbd_session *sess);int ksmbd_close_fd (struct ksmbd_work *work,u64 id); +void ksmbd_unpublish_reopened_fd (struct ksmbd_work *work, +struct ksmbd_file *fp);struct ksmbd_file *ksmbd_lookup_fd_fast (struct ksmbd_work *work,u64 id);struct ksmbd_file *ksmbd_lookup_foreign_fd (struct ksmbd_work *work,u64 id); struct ksmbd_file *ksmbd_lookup_fd_slow(struct ksmbd_work *work, u64 id,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 851/1536 KVM: VMX: Preserve negative return value in vmx_handle_exit() with bus lock detected
In reply to Greg Kroah-Hartman6.12-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
@@ -6625,11 +6625,12 @@ 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 852/1536 driver core: Check drivers_autoprobe for all added devices
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Liu <[email protected]>
[ Upstream commit ea34511aaf755349999a1067b2984a541bee1492 ]
When a device is hot-plugged, the drivers_autoprobe sysfs attribute is not checked (at least for PCI devices). This means that drivers_autoprobe is not working as intended, e.g. hot-plugged PCI devices will still be autoprobed and bound to drivers even with drivers_autoprobe disabled.
The problem likely started when device_add() was removed from pci_bus_add_device() in commit 4f535093cf8f ("PCI: Put pci_dev in device tree as early as possible") which means that the check for drivers_autoprobe which used to happen in bus_probe_device() is no longer present (previously bus_add_device() calls bus_probe_device()). Conveniently, in commit 91703041697c ("PCI: Allow built-in drivers to use async initial probing") device_attach() was replaced with device_initial_probe() which faciliates this change to push the check for drivers_autoprobe into device_initial_probe().
Make sure all devices check drivers_autoprobe by pushing the drivers_autoprobe check into device_initial_probe(). This will only affect devices on the PCI bus for now as device_initial_probe() is only called by pci_bus_add_device() and bus_probe_device(), but bus_probe_device() already checks for autoprobe, so callers of bus_probe_device() should not observe changes on autoprobing. Note also that pushing this check into device_initial_probe() rather than device_attach() makes it only affect automatic probing of drivers (e.g. when a device is hot-plugged), userspace can still choose to manually bind a driver by writing to drivers_probe sysfs attribute, even with autoprobe disabled.
Any future callers of device_initial_probe() will respect the drivers_autoprobe sysfs attribute, which is the intended purpose of drivers_autoprobe.
Adapt the bus-side change to __bus_probe_device(), which is shared by the normal and deferred probe entry points. Preserve the deferred probe wrapper and its parent locking.
Retain this change to provide the device_initial_probe() layout needed by the asynchronous attach parent-lock fix. PCI still calls device_attach() directly, so this change does not alter PCI probing.
Stable-dep-of: 187a62f99da2 ("driver core: take parent lock in async device attach")
--- drivers/base/bus.c | 3 +-- drivers/base/dd.c | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/base/bus.c +1 -2
@@ -570,8 +570,7 @@ static void __bus_probe_device(struct device *dev)if (!sp)return ; -if (sp->drivers_autoprobe) -device_initial_probe (dev); +device_initial_probe (dev);mutex_lock (&sp->mutex);list_for_each_entry (sif, &sp->interfaces, node)
drivers/base/dd.c +9 -1
@@ -1155,7 +1155,15 @@ EXPORT_SYMBOL_GPL(device_attach);void device_initial_probe (struct device *dev) { -__device_attach (dev, true); +struct subsys_private *sp =bus_to_subsys (dev->bus); + +if (!sp) +return ; + +if (sp->drivers_autoprobe) +__device_attach (dev, true); + +subsys_put (sp); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 853/1536 driver core: take parent lock in async device attach
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Peter <[email protected]>
[ Upstream commit 187a62f99da29b1a55602b0d401a783d8dc86161 ]
For device types with need_parent_lock set (only USB interfaces), probe() must run with the parent device locked. A synchronous attach after device_add() gets this from the caller, e.g. usb_set_configuration() holds the udev lock while adding interfaces. __device_attach_async_helper() runs the probe from an async worker instead, where that lock isn't held, and only takes device_lock(dev).
With async probing enabled for the hub driver (e.g. driver_async_probe=* or driver_async_probe=hub), this races when a multi-TT hub is configured. For multi-TT hubs, hub_probe() calls usb_set_interface(hdev, 0, 1) to select the TT-per-port altsetting, and usb_set_interface() creates the endpoint devices of the interface a second time:
usb_set_configuration() async worker
[udev locked]
device_add(intf)
queues the probe ----------> __device_attach_async_helper()
[intf locked, udev not locked]
hub_probe()
usb_set_interface(hdev, 0, 1)
create_intf_ep_devs(intf) create_intf_ep_devs(intf)create_intf_ep_devs() checks and sets intf->ep_devs_created without a lock of its own. If usb_set_configuration() has created ep_81 but not yet set the flag, usb_set_interface() skips removing the endpoint devices of the old altsetting and creates ep_81 again. With a synchronous probe, hub_probe() runs inside device_add() with the udev lock held, and usb_set_configuration() then finds ep_devs_created already set.
Single-TT hubs don't call usb_set_interface() from hub_probe() and don't show this warning, but their probe runs without the udev lock as well.
On an i.MX8MM board with an onboard USB2514 hub this hit 11 of 100 boots:
sysfs: cannot create duplicate filename '.../1-1/1-1:1.0/ep_81'
Call trace: sysfs_warn_dup usb_create_ep_devs create_intf_ep_devs usb_set_interface hub_probe usb_probe_interface really_probe __device_attach_async_helper async_run_entry_fn
It also shows on v7.3-rc6 in QEMU, with dummy_hcd and a raw-gadget program emulating a multi-TT hub: re-authorizing the hub in a loop, while a SCHED_FIFO task preempts the writing task at random points for 3 ms, hit the warning in 29 of 6000 iterations.
Take the parent lock in __device_attach_async_helper() as well, like __driver_attach_async_helper() does, and move __device_driver_lock/unlock() up for that. With this the warning was gone in 300 boots on the board and in 6000 iterations in QEMU.
[ johan: switch to async_schedule_dev_nocall() to avoid deadlock if
async_schedule_dev() runs synchronously when parent lock is held ]
[ Fold the nested conditions into a single if statement; correct commit
message to mention "device types" rather than "buses" for "need_parent_lock". - Danilo ]
--- drivers/base/dd.c | 83 +++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 38 deletions(-)
drivers/base/dd.c +45 -38
@@ -1040,6 +1040,38 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)return ret ==0 ; } +/* +* __device_driver_lock - acquire locks needed to manipulate dev->drv +* @dev: Device we will update driver info for +* @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 +* interface, @parent lock will be held as well. +*/ +static void __device_driver_lock (struct device *dev,struct device *parent) +{ +if (dev->type && dev->type->need_parent_lock && parent) +device_lock (parent); +device_lock (dev); +} + +/* +* __device_driver_unlock - release locks needed to manipulate dev->drv +* @dev: Device we will update driver info for +* @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 @dev lock, but when called for a +* USB interface, @parent lock will be released as well. +*/ +static void __device_driver_unlock (struct device *dev,struct device *parent) +{ +device_unlock (dev); +if (dev->type && dev->type->need_parent_lock && parent) +device_unlock (parent); +} +static void __device_attach_async_helper (void *_dev,async_cookie_t cookie) {struct device *dev = _dev;
@@ -1049,7 +1081,7 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie) .want_async = true, }; -device_lock (dev); +__device_driver_lock (dev, dev->parent);/* * Check if device has already been removed or claimed. This may
@@ -1071,7 +1103,7 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)if (dev->parent)pm_runtime_put (dev->parent); out_unlock: -device_unlock (dev); +__device_driver_unlock (dev, dev->parent);put_device (dev); }
@@ -1128,8 +1160,11 @@ static int __device_attach(struct device *dev, bool allow_async) } out_unlock:device_unlock (dev); -if (async) -async_schedule_dev (__device_attach_async_helper, dev); +if (async && !async_schedule_dev_nocall (__device_attach_async_helper, dev)) { +put_device (dev); + ret =2 ;/* retry synchronously */ + } +return ret; }
@@ -1156,48 +1191,20 @@ EXPORT_SYMBOL_GPL(device_attach);void device_initial_probe (struct device *dev) {struct subsys_private *sp =bus_to_subsys (dev->bus); +int ret;if (!sp)return ; -if (sp->drivers_autoprobe) -__device_attach (dev, true); +if (sp->drivers_autoprobe) { + ret =__device_attach (dev, true); +if (ret ==2 ) +__device_attach (dev, false); + }subsys_put (sp); } -/* -* __device_driver_lock - acquire locks needed to manipulate dev->drv -* @dev: Device we will update driver info for -* @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 -* interface, @parent lock will be held as well. -*/ -static void __device_driver_lock (struct device *dev,struct device *parent) -{ -if (dev->type && dev->type->need_parent_lock && parent) -device_lock (parent); -device_lock (dev); -} - -/* -* __device_driver_unlock - release locks needed to manipulate dev->drv -* @dev: Device we will update driver info for -* @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 @dev lock, but when called for a -* USB interface, @parent lock will be released as well. -*/ -static void __device_driver_unlock (struct device *dev,struct device *parent) -{ -device_unlock (dev); -if (dev->type && dev->type->need_parent_lock && parent) -device_unlock (parent); -} -/** * device_driver_attach - attach a specific driver to a specific device * @drv: Driver to attach
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 854/1536 ksmbd: fix session reference leak on compounded SESSION_SETUP
In reply to Greg Kroah-Hartman6.12-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/smb/server/smb2pdu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/server/smb2pdu.c +11 -0
@@ -1714,6 +1714,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 ;
@@ -1851,6 +1853,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);
@@ -2004,6 +2007,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 855/1536 ksmbd: fix invalid pointer dereference when get_inode_acl() fails
In reply to Greg Kroah-Hartman6.12-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/smb/server/smb2pdu.c | 42 +++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-)
fs/smb/server/smb2pdu.c +34 -8
@@ -2742,10 +2742,11 @@ 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 mnt_idmap *idmap, -struct inode *inode) +static int ksmbd_acls_fattr (struct smb_fattr *fattr, +struct mnt_idmap *idmap, +struct inode *inode) { +struct posix_acl *acl;vfsuid_t vfsuid =i_uid_into_vfsuid (idmap, inode);vfsgid_t vfsgid =i_gid_into_vfsgid (idmap, inode);
@@ -2756,10 +2757,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_inode_acl (inode,ACL_TYPE_ACCESS ); -if (S_ISDIR (inode->i_mode)) - fattr->cf_dacls =get_inode_acl (inode,ACL_TYPE_DEFAULT ); + acl =get_inode_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_inode_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 ; }enum {
@@ -3491,7 +3510,10 @@ int smb2_open(struct ksmbd_work *work)int pntsd_size;size_t scratch_len; -ksmbd_acls_fattr (&fattr, idmap, inode); + rc =ksmbd_acls_fattr (&fattr, idmap, inode); +if (rc) + goto err_out; + scratch_len = smb_acl_sec_desc_scratch_len(&fattr, NULL, 0, OWNER_SECINFO | GROUP_SECINFO |
@@ -5948,7 +5970,11 @@ static int smb2_get_info_sec(struct ksmbd_work *work, idmap =file_mnt_idmap (fp->filp); inode =file_inode (fp->filp); -ksmbd_acls_fattr (&fattr, idmap, inode); + rc =ksmbd_acls_fattr (&fattr, idmap, 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 856/1536 ksmbd: use the existing xattr name for a named stream
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit a7d1d52748e0fe4d06fdb871fc9899904fbba93f ]
SMB stream names are case-insensitive, but ksmbd stores each named stream in an xattr whose name is case-sensitive. Opening an existing stream finds its xattr with a case-insensitive match, yet the handle keeps the name as the client spelled it, and every later operation that needs an exact name uses that spelling:
- a WRITE or an end-of-file change creates a second xattr, so a stream created as "Foo" and written through "foo" ends up stored twice, and which value a later lookup returns depends on xattr list order;
- delete-on-close and delete-pending removal can fail with -ENODATA, or remove only a case-variant copy and leave the original;
- the share mode check compares stream names with strcmp(), so two opens of the same stream that differ only in case do not conflict.
Have ksmbd_vfs_casexattr_len() copy the matching xattr's name into the handle when the stream is opened, so later operations use the name already on disk. The match must have the same length as the name it replaces; the stream lookup passes a length that includes the terminating NUL, which already guarantees that, and the check makes the copy safe for any caller. A stream that does not exist yet keeps the client's spelling, as before.
smb2_rename() compares and looks up fp->stream.name case-insensitively, so it behaves the same with either spelling.
--- fs/smb/server/smb2pdu.c | 8 ++++---- fs/smb/server/vfs.c | 7 ++++++- fs/smb/server/vfs.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-)
fs/smb/server/smb2pdu.c +4 -4
@@ -2487,7 +2487,7 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, path->dentry, attr_name,XATTR_USER_PREFIX_LEN + - eabuf->EaNameLength); + eabuf->EaNameLength, NULL);/* delete the EA only when it exits */ if (rc >0 ) {
@@ -2559,11 +2559,11 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, fp->stream.name = xattr_stream_name; fp->stream.size = xattr_stream_size; -/* Check if there is stream prefix in xattr space */ +/* Keep the existing xattr's case for subsequent writes and removal. */ rc =ksmbd_vfs_casexattr_len (idmap, path->dentry, xattr_stream_name, - xattr_stream_size); + xattr_stream_size, xattr_stream_name);if (rc >=0 )return 0 ;if (rc != -ENOENT && rc != -ENODATA )
@@ -5285,7 +5285,7 @@ static int get_file_stream_info(struct ksmbd_work *work,*/ slen =ksmbd_vfs_casexattr_len (file_mnt_idmap (fp->filp), path->dentry, stream_name, -strlen (stream_name) +1 ); +strlen (stream_name) +1 ,NULL ); ssize = slen <0 ?0 : (loff_t )slen; file_info->StreamSize =cpu_to_le64 (ssize); file_info->StreamAllocationSize =cpu_to_le64 (ssize);
fs/smb/server/vfs.c +6 -1
@@ -1812,7 +1812,7 @@ int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,ssize_t ksmbd_vfs_casexattr_len (struct mnt_idmap *idmap,struct dentry *dentry,char *attr_name, -int attr_name_len) +int attr_name_len,char *actual_name) {char *name, *xattr_list =NULL ;ssize_t value_len = -ENOENT , xattr_list_len;
@@ -1830,8 +1830,13 @@ ssize_t ksmbd_vfs_casexattr_len(struct mnt_idmap *idmap,ksmbd_debug (VFS ,"%s, len %zd\n" , name,strlen (name));if (strncasecmp (attr_name, name, attr_name_len))continue ; +if (actual_name &&strlen (name) +1 != attr_name_len) +continue ; value_len =ksmbd_vfs_xattr_len (idmap, dentry, name); +/* The caller provides attr_name_len bytes for the actual name. */ +if (value_len >=0 && actual_name) +memcpy (actual_name, name, attr_name_len);break ; }
fs/smb/server/vfs.h +1 -1
@@ -107,7 +107,7 @@ ssize_t ksmbd_vfs_getxattr(struct mnt_idmap *idmap, char **xattr_buf);ssize_t ksmbd_vfs_casexattr_len (struct mnt_idmap *idmap,struct dentry *dentry,char *attr_name, -int attr_name_len); +int attr_name_len,char *actual_name); int ksmbd_vfs_setxattr(struct mnt_idmap *idmap, const struct path *path, const char *attr_name, void *attr_value, size_t attr_size, int flags,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 857/1536 ksmbd: fix named stream write and EOF handling
In reply to Greg Kroah-Hartman6.12-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/smb/server/smb2pdu.c | 2 ++ fs/smb/server/vfs.c | 72 ++++++++++++++++++++++++++++++++++++----- fs/smb/server/vfs.h | 1 + 3 files changed, 67 insertions(+), 8 deletions(-)
fs/smb/server/smb2pdu.c +2 -0
@@ -6577,6 +6577,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/smb/server/vfs.c +64 -8
106 lines not on this page · raw message
fs/smb/server/vfs.h +1 -0
@@ -82,6 +82,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 858/1536 KVM: VMX: Formally define KVMs "0xdead" exit reason used for failed VM-Enter
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit d85f7dc8cf3c91a131946dae4c3aa8d9c97322d7 ]
Add EXIT_REASON_UNDEFINED to track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).
Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
No functional change intended.
--- arch/x86/include/asm/vmx.h | 8 ++++++++ arch/x86/kvm/vmx/vmx.c | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-)
arch/x86/include/asm/vmx.h +8 -0
@@ -20,6 +20,14 @@#include <asm/trapnr.h> #include <asm/vmxfeatures.h> +/* +* UNDEFINED is a KVM-defined value used to indicate that the basic exit reason +* is undefined/invalid, e.g. on VM-Fail or if TDX never attempted VM-Enter. +* The value itself is arbitrary, it just needs to not collide with a real exit +* reason. +*/ +#define EXIT_REASON_UNDEFINED 0xdead +#define VMCS_CONTROL_BIT (x) BIT(VMX_FEATURE_##x & 0x1f)/*
arch/x86/kvm/vmx/vmx.c +3 -1
@@ -6151,6 +6151,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +static_assert (EXIT_REASON_UNDEFINED >=ARRAY_SIZE (kvm_vmx_exit_handlers)); +void vmx_get_exit_info (struct kvm_vcpu *vcpu,u32 *reason,u64 *info1,u64 *info2,u32 *intr_info,u32 *error_code) {
@@ -7314,7 +7316,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,vmx_enable_fb_clear (vmx);if (unlikely (vmx->fail)) { - vmx->exit_reason.full =0xdead ; + vmx->exit_reason.full =EXIT_REASON_UNDEFINED ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 859/1536 x86/mm/pat: Use pr_warn() for early W^X warnings
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Rapoport (Microsoft) <[email protected]>
[ Upstream commit ea6fd393cb9e6811a748c7551de0dd3090f9dcde ]
Nathan Chancellor reports the following warning:
CPA detected W^X violation: 8000000000000123 -> 0000000000000123 range: 0xffffffffc0400000 - 0xffffffffc0400fff PFN 100e00
from its_alloc() doing set_memory_x() during early retpoline setup.
The warning is not factually wrong but it is unproductive. First, the RWX permission is temporary and fixed up by execmem_restore_rox(). Second, at the time of the warning, all kernel text is mapped RWX. So there is not even a transient actual security issue.
The right way to fix this up is to relax RWX detection during boot but make a final verification pass over all kernel page tables before running userspace. There is code to do that today (debug_checkwx()) but it must be enabled explicitly in Kconfig.
For now, retain the warning even if it's unproductive, but make it scream less loudly: use pr_warn_once() rather than WARN_ONCE().
Remove the warning once debug_checkwx() behavior becomes unconditional.
--- arch/x86/mm/pat/set_memory.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/x86/mm/pat/set_memory.c +15 -0
@@ -647,6 +647,21 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long starreturn new; end = start + npg *PAGE_SIZE -1 ; + +/* +* If the kernel text is still RWX, gently complain, this could be a +* false positive. +* Once debug_checkwx() becomes mandatory for CONFIG_STRICT_KERNEL_RWX, +* the warning can be removed completely. +*/ +if (!kernel_set_to_readonly) { +pr_warn_once ("CPA detected W^X violation: %016llx -> %016llx range: 0x%016lx - 0x%016lx PFN %lx\n" , + (unsigned long long )pgprot_val (old), + (unsigned long long )pgprot_val (new), + start, end, pfn); +return new; + } + WARN_ONCE(1, "CPA detected W^X violation: %016llx -> %016llx range: 0x%016lx - 0x%016lx PFN %lx\n", (unsigned long long)pgprot_val(old), (unsigned long long)pgprot_val(new),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 860/1536 inet: reject unhashed sockets during established lookups
In reply to Greg Kroah-Hartman6.12-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.
--- 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
@@ -1177,10 +1177,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:
@@ -1467,7 +1471,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; }
@@ -1523,7 +1527,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
@@ -512,8 +512,9 @@ struct sock *__inet_lookup_established(const 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
@@ -7379,7 +7379,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; }READ_ONCE (sk->sk_data_ready)(sk);bh_unlock_sock (fastopen_sk);
net/ipv6/inet6_hashtables.c +3 -1
@@ -74,7 +74,9 @@ struct sock *__inet6_lookup_established(const 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 861/1536 ovl: check that the parents of volatile/dirty are dirs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit e34d2ef818e4c7676d8d8e1bf43e6a1ed39efb2a upstream.
An unprivileged user crashes the kernel by mounting overlayfs with the volatile option.
A dentry that serves as the parent of a lookup must be a directory. ovl_create_volatile_dirty() walks work/incompat/volatile/dirty by name, and ovl_lookup_or_create() returns an existing entry whatever its type. A file or a symlink that another task creates during the mount becomes the parent of the next lookup, which calls a NULL ->lookup.
An unprivileged user mounted overlayfs with "volatile" in a user namespace while a second process created a symlink named work/incompat, and the mount task oopsed on a NULL ->lookup call.
Fix this by returning -ENOTDIR from ovl_lookup_or_create() when the caller asked for a directory and the existing entry is a non-dir.
[backport: no ovl_start_creating_upper(), check the child of
ovl_lookup_upper() in ovl_lookup_or_create() instead]
--- fs/overlayfs/super.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
fs/overlayfs/super.c +12 -5
@@ -594,16 +594,23 @@ static int ovl_check_rename_whiteout(struct ovl_fs *ofs)static struct dentry *ovl_lookup_or_create (struct ovl_fs *ofs,struct dentry *parent, -const char *name,umode_t mode) +const char *name,bool is_dir) {size_t len =strlen (name);struct dentry *child;inode_lock_nested (parent->d_inode,I_MUTEX_PARENT ); child =ovl_lookup_upper (ofs, name, parent, len); -if (!IS_ERR (child) && !child->d_inode) - child =ovl_create_real (ofs, parent->d_inode, child, -OVL_CATTR (mode)); +if (!IS_ERR (child)) { +if (!child->d_inode) { + child =ovl_create_real (ofs, parent->d_inode, child, +OVL_CATTR (is_dir ?S_IFDIR : +S_IFREG )); + }else if (is_dir && !d_can_lookup (child)) { +dput (child); + child =ERR_PTR (-ENOTDIR ); + } + }inode_unlock (parent->d_inode);dput (parent);
@@ -624,7 +631,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs)const char *const *name = volatile_path;for (ctr =ARRAY_SIZE (volatile_path); ctr; ctr--, name++) { - d =ovl_lookup_or_create (ofs, d, *name, ctr >1 ?S_IFDIR :S_IFREG ); + d =ovl_lookup_or_create (ofs, d, *name, ctr >1 );if (IS_ERR (d))return PTR_ERR (d); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 862/1536 ovl: hold a reference on the parent in readdir
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit 16d319e12328acafeafd3eecdf09c46d7fb43452 upstream.
Listing a directory on an overlay uses a freed dentry and crashes the kernel when a lookup moves the directory at the same time.
Code that can sleep may only use d_parent without a reference while something stops a move of the dentry. ovl_iterate_real(), ovl_need_adjust_d_ino() and ovl_cache_update() use the d_parent of the listed directory and hold only the lock of that directory. When a lookup finds the directory under another parent after a change to a layer, d_splice_alias() moves it without that lock and drops its reference on the old parent.
With a delay in ovl_iterate_real(), getdents64 on an overlay directory raced a rename in the lower layer and a lookup that moved its dentry, and after an rmdir of the old parent KASAN reported a use-after-free in security_inode_getattr().
Fix this by using dget_parent() in the three functions.
[backport: no ovl_need_adjust_d_ino(), take the parent with dget_parent()
in ovl_iterate() and test a local flag]
--- fs/overlayfs/readdir.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
fs/overlayfs/readdir.c +19 -7
@@ -486,8 +486,8 @@ static int ovl_cache_update(const struct path *path, struct ovl_cache_entry *p, goto get; }if (p->len ==2 && p->name[1 ] =='.' ) { -/* we shall not be moved */ - this =dget (dir->d_parent); +/* d_splice_alias() can move even a locked dir */ + this =dget_parent (dir); goto get; } }
@@ -711,6 +711,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)struct dentry *dir = file->f_path.dentry;struct ovl_fs *ofs =OVL_FS (dir->d_sb);const struct ovl_layer *lower_layer =ovl_layer_lower (dir); +struct dentry *parent;struct ovl_readdir_translate rdt = { .ctx.actor = ovl_fill_real, .orig_ctx = ctx,
@@ -721,18 +722,26 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)if (rdt.xinobits && lower_layer) rdt.fsid = lower_layer->fsid; -if (OVL_TYPE_MERGE (ovl_path_type (dir->d_parent))) { +/* +* The lock on dir does not stop d_splice_alias() from moving it to +* another parent, which drops the reference dir holds on this one. +*/ + parent =dget_parent (dir); +if (OVL_TYPE_MERGE (ovl_path_type (parent))) {struct kstat stat;struct path statpath = file->f_path; - statpath.dentry = dir->d_parent; + statpath.dentry = parent; err =vfs_getattr (&statpath, &stat,STATX_INO ,0 ); -if (err) +if (err) { +dput (parent);return err; + }WARN_ON_ONCE (dir->d_sb->s_dev != stat.dev); rdt.parent_ino = stat.ino; } +dput (parent);if (ovl_is_impure_dir (file)) { rdt.cache =ovl_cache_get_impure (&file->f_path);
@@ -761,6 +770,10 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)ovl_dir_reset (file);if (od->is_real) { +struct dentry *parent =dget_parent (dentry); +bool parent_merge =OVL_TYPE_MERGE (ovl_path_type (parent)); + +dput (parent);/* * If parent is merge, then need to adjust d_ino for '..', if * dir is impure then need to adjust d_ino for copied up
@@ -768,8 +781,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)*/ if (ovl_xino_bits (ofs) || (ovl_same_fs (ofs) && - (ovl_is_impure_dir (file) || -OVL_TYPE_MERGE (ovl_path_type (dentry->d_parent))))) { + (ovl_is_impure_dir (file) || parent_merge))) { err =ovl_iterate_real (file, ctx); }else { err =iterate_dir (od->realfile, ctx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 863/1536 ovl: do not copy up a dentry that was removed
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit f635192ad223d2009ee640b63adf5ce3198aa338 upstream.
A change to a removed file through an open descriptor replaces whatever has its old name in the upper layer.
Copy up must only create a name in the upper directory, never replace one. After an unlink, an rmdir or a rename over a lower dentry, a dentry that an open file keeps alive still has its old parent and name, but in the upper directory that name is now a whiteout or a new object. ovl_copy_up_workdir() renames the copy over it, which brings back the removed object and destroys whatever took its name.
An unprivileged user opened a lower FIFO and unlinked it, root created a file at that name, and fchmod on the old descriptor replaced the file of root with the FIFO.
Fix this by looking up the target name of the rename in ovl_copy_up_workdir() with LOOKUP_EXCL, so that copy up fails with -EEXIST if the name is taken, as copy up with O_TMPFILE already does when it links the copy to the name.
[backport: no start_renaming_dentry() and LOOKUP_EXCL, fail with -EEXIST if
the target of ovl_lookup_upper() is positive]
--- fs/overlayfs/copy_up.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/overlayfs/copy_up.c +7 -0
@@ -831,6 +831,13 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)if (IS_ERR (upper)) goto cleanup; +/* The name may have been taken since lookup, never replace it */ + err = -EEXIST ; +if (d_is_positive (upper)) { +dput (upper); + goto cleanup; + } + err =ovl_do_rename (ofs, wdir, temp, udir, upper,0 );dput (upper);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 864/1536 smb: smbdirect: fix buffer length underflow in RDMA transfers
In reply to Greg Kroah-Hartman6.12-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 6.12 the code is smb_direct_rdma_xmit() in
fs/smb/server/transport_rdma.c ]
--- fs/smb/server/transport_rdma.c | 1 - 1 file changed, 1 deletion(-)
fs/smb/server/transport_rdma.c +0 -1
@@ -1388,7 +1388,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 865/1536 drm/amdgpu: drop retry loop in amdgpu_hmm_range_get_pages
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Honglei Huang <[email protected]>
[ Upstream commit 342981fff32802a819d6fc7cf3c9fedf9f3d9d60 ]
Since commit c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") moved mmu_interval_read_begin() out of the per-chunk loop, the captured notifier_seq is no longer refreshed across retries. As a result, the existing -EBUSY retry path can never make progress:
hmm_range_fault() returns -EBUSY only when mmu_interval_check_retry(notifier, notifier_seq) reports that the sequence is stale. Once the sequence has advanced, the stored seq will never match again, so every subsequent call within the same invocation returns -EBUSY immediately.
The "goto retry" therefore degenerates into a busy spin that simply burns CPU for the full HMM_RANGE_DEFAULT_TIMEOUT (~1s) window before finally bailing out with -EAGAIN. This is pure latency with no chance of recovery, and it actively hurts the KFD userptr stack: the caller ends up blocked for a second while holding mmap_lock, only to return -EAGAIN to the restore worker (or to userspace) which would have re-driven the operation immediately anyway.
Drop the retry/timeout entirely and let -EBUSY propagate straight to out_free_pfns, where it is already translated to -EAGAIN. Recovery is handled at a higher level: the KFD restore_userptr_worker reschedules itself, and the userptr ioctl path returns -EAGAIN to userspace.
No functional regression: the previous behaviour on -EBUSY was already to fail with -EAGAIN after a 1s stall; we just skip the stall.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -8
@@ -171,7 +171,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,const u64 max_bytes =SZ_2G ;struct hmm_range *hmm_range; -unsigned long timeout;unsigned long *pfns;unsigned long end;unsigned long i;
@@ -203,15 +202,9 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,pr_debug ("hmm range: start = 0x%lx, end = 0x%lx" , hmm_range->start, hmm_range->end); - timeout = jiffies +msecs_to_jiffies (HMM_RANGE_DEFAULT_TIMEOUT ); - -retry: r =hmm_range_fault (hmm_range); -if (unlikely (r)) { -if (r == -EBUSY && !time_after (jiffies, timeout)) - goto retry; +if (unlikely (r)) goto out_free_pfns; - }if (hmm_range->end == end)break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 866/1536 iommufd: Fix event queue release use-after-free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nirmoy Das <[email protected]>
[ Upstream commit 440ca8a4b69f40088065b9e05ef11373292a254e ]
iommufd_eventq_fops_release() drops the file's users reference before reading eventq->ictx. Once that reference is dropped, IOMMU_DESTROY in another thread can remove and free the event queue, so the later load accesses freed memory.
Read ictx while the users reference still pins the event queue, then drop the reference and put the saved context. The context reference taken by iommufd_eventq_init() keeps ictx valid until the put. Fault and vEVENTQ file descriptors share this release path.
--- drivers/iommu/iommufd/fault.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/fault.c +3 -1
@@ -373,9 +373,11 @@ static __poll_t iommufd_fault_fops_poll(struct file *filep,static int iommufd_fault_fops_release (struct inode *inode,struct file *filep) {struct iommufd_fault *fault = filep->private_data; +/* fault may be freed once the users reference is dropped. */ +struct iommufd_ctx *ictx = fault->ictx;refcount_dec (&fault->obj.users); -iommufd_ctx_put (fault->ictx); +iommufd_ctx_put (ictx);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 867/1536 mm/hugetlb: stop using avoid_reserve flag in fork()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Xu <[email protected]>
[ Upstream commit be8d7314b18ede1c6cdebbb982c9659020e2f1f2 ]
When fork() and stumble on top of a dma-pinned hugetlb private page, CoW must happen during fork() to guarantee dma coherency.
In this specific path, hugetlb pages need to be allocated for the child process. Stop using avoid_reserve=1 flag here: it's not required to be used here, as dest_vma (which is destined to be a MAP_PRIVATE hugetlb vma) will have no private vma resv map, and that will make sure it won't be able to use a vma reservation later.
No functional change intended with this change. Said that, it's still wanted to do this, so as to reduce the usage of avoid_reserve to the only one user, which is also why this flag was introduced initially in commit 04f2cbe35699 ("hugetlb: guarantee that COW faults for a process that called mmap(MAP_PRIVATE) on hugetlbfs will succeed"). I don't see whoever else should set it at all.
Further patch will clean up resv accounting based on this.
Stable-dep-of: 824cc56bf43c ("mm/hugetlb: fix use-after-free of a new anon folio")
--- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +1 -1
@@ -5366,7 +5366,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,spin_unlock (src_ptl);spin_unlock (dst_ptl);/* Do not use reserve as it's private owned */ - new_folio =alloc_hugetlb_folio (dst_vma, addr,1 ); + new_folio =alloc_hugetlb_folio (dst_vma, addr,0 );if (IS_ERR (new_folio)) {folio_put (pte_folio); ret =PTR_ERR (new_folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 868/1536 mm/hugetlb: rename avoid_reserve to cow_from_owner
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Xu <[email protected]>
[ Upstream commit 30cef82bc6e8975a360ec05b707f7fb194c875ed ]
The old name "avoid_reserve" can be too generic and can be used wrongly in the new call sites that want to allocate a hugetlb folio.
It's confusing on two things: (1) whether one can opt-in to avoid global reservation, and (2) whether it should take more than one count.
In reality, this flag is only used in an extremely hacky path, in an extremely hacky way in hugetlb CoW path only, and always use with 1 saying "skip global reservation". Rename the flag to avoid future abuse of this flag, making it a boolean so as to reflect its true representation that it's not a counter. To make it even harder to abuse, add a comment above the function to explain it.
Stable-dep-of: 824cc56bf43c ("mm/hugetlb: fix use-after-free of a new anon folio")
--- fs/hugetlbfs/inode.c | 2 +- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 33 ++++++++++++++++++++------------- 3 files changed, 23 insertions(+), 16 deletions(-)
fs/hugetlbfs/inode.c +1 -1
@@ -884,7 +884,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,* folios in these areas, we need to consume the reserves * to keep reservation accounting consistent. */ - folio =alloc_hugetlb_folio (&pseudo_vma, addr,0 ); + folio =alloc_hugetlb_folio (&pseudo_vma, addr, false);if (IS_ERR (folio)) {mutex_unlock (&hugetlb_fault_mutex_table[hash]); error =PTR_ERR (folio);
include/linux/hugetlb.h +2 -2
@@ -691,7 +691,7 @@ struct huge_bootmem_page {int isolate_or_dissolve_huge_page (struct page *page,struct list_head *list);void wait_for_freed_hugetlb_folios (void );struct folio *alloc_hugetlb_folio (struct vm_area_struct *vma, -unsigned long addr,int avoid_reserve); +unsigned long addr,bool cow_from_owner);struct folio *alloc_hugetlb_folio_nodemask (struct hstate *h,int preferred_nid,nodemask_t *nmask,gfp_t gfp_mask,bool allow_alloc_fallback);
@@ -1083,7 +1083,7 @@ static inline void wait_for_freed_hugetlb_folios(void)static inline struct folio *alloc_hugetlb_folio (struct vm_area_struct *vma,unsigned long addr, -int avoid_reserve) +bool cow_from_owner) {return NULL ; }
mm/hugetlb.c +20 -13
@@ -2991,8 +2991,15 @@ void wait_for_freed_hugetlb_folios(void)flush_work (&free_hpage_work); } +/* +* NOTE! "cow_from_owner" represents a very hacky usage only used in CoW +* faults of hugetlb private mappings on top of a non-page-cache folio (in +* which case even if there's a private vma resv map it won't cover such +* allocation). New call sites should (probably) never set it to true!! +* When it's set, the allocation will bypass all vma level reservations. +*/ struct folio *alloc_hugetlb_folio (struct vm_area_struct *vma, -unsigned long addr,int avoid_reserve) +unsigned long addr,bool cow_from_owner) {struct hugepage_subpool *spool =subpool_vma (vma);struct hstate *h =hstate_vma (vma);
@@ -3034,7 +3041,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,* Allocations for MAP_NORESERVE mappings also need to be * checked against any subpool limit. */ -if (map_chg || avoid_reserve) { +if (map_chg || cow_from_owner) { gbl_chg =hugepage_subpool_get_pages (spool,1 );if (gbl_chg <0 ) goto out_end_reservation;
@@ -3042,7 +3049,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,/* If this allocation is not consuming a reservation, charge it now. */ - deferred_reserve = map_chg || avoid_reserve; + deferred_reserve = map_chg || cow_from_owner;if (deferred_reserve) { ret =hugetlb_cgroup_charge_cgroup_rsvd ( idx,pages_per_huge_page (h), &h_cg_rsvd);
@@ -3067,7 +3074,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,if (!folio) goto out_uncharge_cgroup;spin_lock_irq (&hugetlb_lock); -if (!avoid_reserve &&vma_has_reserves (vma, gbl_chg)) { +if (!cow_from_owner &&vma_has_reserves (vma, gbl_chg)) {folio_set_hugetlb_restore_reserve (folio); h->resv_huge_pages--; }
@@ -3125,7 +3132,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,hugetlb_cgroup_uncharge_cgroup_rsvd (idx,pages_per_huge_page (h), h_cg_rsvd); out_subpool_put: -if (map_chg || avoid_reserve) +if (map_chg || cow_from_owner)hugepage_subpool_put_pages (spool,1 ); out_end_reservation:vma_end_reservation (h, vma, addr);
@@ -5366,7 +5373,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,spin_unlock (src_ptl);spin_unlock (dst_ptl);/* Do not use reserve as it's private owned */ - new_folio =alloc_hugetlb_folio (dst_vma, addr,0 ); + new_folio =alloc_hugetlb_folio (dst_vma, addr, false);if (IS_ERR (new_folio)) {folio_put (pte_folio); ret =PTR_ERR (new_folio);
@@ -5827,7 +5834,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio,struct hstate *h =hstate_vma (vma);struct folio *old_folio;struct folio *new_folio; -int outside_reserve =0 ; +bool cow_from_owner =0 ;vm_fault_t ret =0 ;struct mmu_notifier_range range;
@@ -5896,7 +5903,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio,*/ if (is_vma_resv_set (vma,HPAGE_RESV_OWNER ) && old_folio != pagecache_folio) - outside_reserve =1 ; + cow_from_owner = true;folio_get (old_folio);
@@ -5905,7 +5912,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio,* be acquired again before returning to the caller, as expected. */ spin_unlock (vmf->ptl); - new_folio =alloc_hugetlb_folio (vma, vmf->address, outside_reserve); + new_folio =alloc_hugetlb_folio (vma, vmf->address, cow_from_owner);if (IS_ERR (new_folio)) {/*
@@ -5915,7 +5922,7 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio,* reliability, unmap the page from child processes. The child * may get SIGKILLed if it later faults. */ -if (outside_reserve) { +if (cow_from_owner) {struct address_space *mapping = vma->vm_file->f_mapping;pgoff_t idx;u32 hash;
@@ -6166,7 +6173,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, goto out; } - folio =alloc_hugetlb_folio (vma, vmf->address,0 ); + folio =alloc_hugetlb_folio (vma, vmf->address, false);if (IS_ERR (folio)) {/* * Returning error will result in faulting task being
@@ -6630,7 +6637,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } - folio =alloc_hugetlb_folio (dst_vma, dst_addr,0 ); + folio =alloc_hugetlb_folio (dst_vma, dst_addr, false);if (IS_ERR (folio)) { ret = -ENOMEM ; goto out;
@@ -6672,7 +6679,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } - folio =alloc_hugetlb_folio (dst_vma, dst_addr,0 ); + folio =alloc_hugetlb_folio (dst_vma, dst_addr, false);if (IS_ERR (folio)) {folio_put (*foliop); ret = -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 869/1536 mm,hugetlb: change mechanism to detect a COW on private mapping
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oscar Salvador <[email protected]>
[ Upstream commit 2ae1ab9934c785b855583e3eabd208d6f3ac91e1 ]
Patch series "Misc rework on hugetlb faulting path", v4.
This patchset aims to give some love to the hugetlb faulting path, doing so by removing obsolete comments that are no longer true, sorting out the folio lock, and changing the mechanism we use to determine whether we are COWing a private mapping already.
The most important patch of the series is #1, as it fixes a deadlock that was described in [1], where two processes were holding the same lock for the folio in the pagecache, and then deadlocked in the mutex. Note that this can also happen for anymous folios. This has been tested using this reproducer, below
Looking up and locking the folio in the pagecache was done to check whether that folio was the same folio we had mapped in our pagetables, meaning that if it was different we knew that we already mapped that folio privately, so any further CoW would be made on a private mapping, which lead us to the question: __Was the reservation for that address consumed?__ That is all we care about, because if it was indeed consumed and we are the owner and we cannot allocate more folios, we need to unmap the folio from the processes pagetables and make it exclusive for us.
We figured we do not need to look up the folio at all, and it is just enough to check whether the folio we have mapped is anonymous, which means we mapped it privately, so the reservation was indeed consumed.
Patch#2 sorts out folio locking in the faulting path, reducing the scope of it ,only taking it when we are dealing with an anonymous folio and document it. More details in the patch.
Patch#3-5 are cleanups.
Here is the reproducer:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
#define PROTECTION (PROT_READ | PROT_WRITE)
#define LENGTH (2UL*1024*1024)
#define ADDR (void *)(0x0UL)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB)
void __read(char *addr)
{
int i = 0;
printf("a[%d]: %c\n", i, addr[i]);
}
void fill(char *addr)
{
addr[0] = 'd';
printf("addr: %c\n", addr[0]);
}
int main(void)
{
void *addr;
pid_t pid, wpid;
int status;
addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, -1, 0); if (addr == MAP_FAILED) {
perror("mmap");
return -1;
}
printf("Parent faulting in RO\n");
__read(addr);
sleep (10);
printf("Forking\n");
pid = fork();
switch (pid) {
case -1:
perror("fork");
break;
case 0:
sleep (4);
printf("Child: Faulting in\n"); fill(addr);
exit(0);
break;
default:
printf("Parent: Faulting in\n"); fill(addr);
while((wpid = wait(&status)) > 0); if (munmap(addr, LENGTH))
perror("munmap");
}
return 0;
}
You will also have to add a delay in hugetlb_wp, after releasing the mutex and before unmapping, so the window is large enough to reproduce it reliably.
: --- a/mm/hugetlb.c : +++ b/mm/hugetlb.c : @@ -38,6 +38,7 @@ : #include <linux/memory.h> : #include <linux/mm_inline.h> : #include <linux/padata.h>
: +#include <linux/delay.h>
:
: #include <asm/page.h>
: #include <asm/pgalloc.h>
: @@ -6261,6 +6262,8 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf)
: hugetlb_vma_unlock_read(vma);
: mutex_unlock(&hugetlb_fault_mutex_table[hash]);
:
: + mdelay(8000);
: +
: unmap_ref_private(mm, vma, old_folio, vmf->address);
:
: mutex_lock(&hugetlb_fault_mutex_table[hash]);
This patch (of 5):
hugetlb_wp() checks whether the process is trying to COW on a private mapping in order to know whether the reservation for that address was already consumed. If it was consumed and we are the ownner of the mapping, the folio will have to be unmapped from the other processes.
Currently, that check is done by looking up the folio in the pagecache and compare it to the folio which is mapped in our pagetables. If it differs, it means we already mapped it privately before, consuming a reservation on the way. All we are interested in is whether the mapped folio is anonymous, so we can simplify and check for that instead.
:
: #include <asm/page.h>
: #include <asm/pgalloc.h>
: @@ -6261,6 +6262,8 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf)
: hugetlb_vma_unlock_read(vma);
: mutex_unlock(&hugetlb_fault_mutex_table[hash]);
:
: + mdelay(8000);
: +
: unmap_ref_private(mm, vma, old_folio, vmf->address);
:
Stable-dep-of: 824cc56bf43c ("mm/hugetlb: fix use-after-free of a new anon folio")
--- mm/hugetlb.c | 88 ++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 54 deletions(-)
mm/hugetlb.c +34 -54
@@ -5824,8 +5824,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,* cannot race with other handlers or page migration. * Keep the pte_same checks anyway to make transition from the mutex easier. */ -static vm_fault_t hugetlb_wp (struct folio *pagecache_folio, -struct vm_fault *vmf) +static vm_fault_t hugetlb_wp (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct mm_struct *mm = vma->vm_mm;
@@ -5893,16 +5892,17 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio, PageAnonExclusive(&old_folio->page), &old_folio->page);/* -* If the process that created a MAP_PRIVATE mapping is about to -* perform a COW due to a shared page count, attempt to satisfy -* the allocation without using the existing reserves. The pagecache -* page is used to determine if the reserve at this address was -* consumed or not. If reserves were used, a partial faulted mapping -* at the time of fork() could consume its reserves on COW instead -* of the full address range. +* If the process that created a MAP_PRIVATE mapping is about to perform +* a COW due to a shared page count, attempt to satisfy the allocation +* without using the existing reserves. +* In order to determine where this is a COW on a MAP_PRIVATE mapping it +* is enough to check whether the old_folio is anonymous. This means that +* the reserve for this address was consumed. If reserves were used, a +* partial faulted mapping at the fime of fork() could consume its reserves +* on COW instead of the full address range. */ if (is_vma_resv_set (vma,HPAGE_RESV_OWNER ) && - old_folio != pagecache_folio) +folio_test_anon (old_folio)) cow_from_owner = true;folio_get (old_folio);
@@ -6283,7 +6283,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,hugetlb_count_add (pages_per_huge_page (h), mm);if ((vmf->flags &FAULT_FLAG_WRITE ) && !(vma->vm_flags &VM_SHARED )) {/* Optimization, do the COW without a second fault */ - ret =hugetlb_wp (folio, vmf); + ret =hugetlb_wp (vmf); }spin_unlock (vmf->ptl);
@@ -6351,10 +6351,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,vm_fault_t ret;u32 hash;struct folio *folio =NULL ; -struct folio *pagecache_folio =NULL ;struct hstate *h =hstate_vma (vma);struct address_space *mapping; -int need_wait_lock =0 ; +bool need_wait_lock = false;struct vm_fault vmf = { .vma = vma, .address = address &huge_page_mask (h),
@@ -6445,8 +6444,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,* If we are going to COW/unshare the mapping later, we examine the * pending reservations for this page now. This will ensure that any * allocations necessary to record that reservation occur outside the -* spinlock. Also lookup the pagecache page now as it is used to -* determine if a reservation has been consumed. +* spinlock. */ if ((flags & (FAULT_FLAG_WRITE |FAULT_FLAG_UNSHARE )) && !(vma->vm_flags &VM_MAYSHARE ) && !huge_pte_write (vmf.orig_pte)) {
@@ -6456,11 +6454,6 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, }/* Just decrements count, does not deallocate */ vma_end_reservation (h, vma, vmf.address); - - pagecache_folio =filemap_lock_hugetlb_folio (h, mapping, - vmf.pgoff); -if (IS_ERR (pagecache_folio)) - pagecache_folio =NULL ; } vmf.ptl =huge_pte_lock (h, mm, vmf.pte);
@@ -6474,10 +6467,6 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, (flags & FAULT_FLAG_WRITE) && !huge_pte_write(vmf.orig_pte)) {if (!userfaultfd_wp_async (vma)) {spin_unlock (vmf.ptl); -if (pagecache_folio) { -folio_unlock (pagecache_folio); -folio_put (pagecache_folio); - }hugetlb_vma_unlock_read (vma);mutex_unlock (&hugetlb_fault_mutex_table[hash]);return handle_userfault (&vmf,VM_UFFD_WP );
@@ -6489,24 +6478,19 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,/* Fallthrough to CoW */ } -/* -* hugetlb_wp() requires page locks of pte_page(vmf.orig_pte) and -* pagecache_folio, so here we need take the former one -* when folio != pagecache_folio or !pagecache_folio. -*/ - folio =page_folio (pte_page (vmf.orig_pte)); -if (folio != pagecache_folio) -if (!folio_trylock (folio)) { - need_wait_lock =1 ; - goto out_ptl; - } - -folio_get (folio); -if (flags & (FAULT_FLAG_WRITE |FAULT_FLAG_UNSHARE )) {if (!huge_pte_write (vmf.orig_pte)) { - ret =hugetlb_wp (pagecache_folio, &vmf); - goto out_put_page; +/* hugetlb_wp() requires page locks of pte_page(vmf.orig_pte) */ + folio =page_folio (pte_page (vmf.orig_pte)); +if (!folio_trylock (folio)) { + need_wait_lock = true; + goto out_ptl; + } +folio_get (folio); + ret =hugetlb_wp (&vmf); +folio_unlock (folio); +folio_put (folio); + goto out_ptl; }else if (likely (flags &FAULT_FLAG_WRITE )) { vmf.orig_pte =huge_pte_mkdirty (vmf.orig_pte); }
@@ -6515,17 +6499,8 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,if (huge_ptep_set_access_flags (vma, vmf.address, vmf.pte, vmf.orig_pte, flags &FAULT_FLAG_WRITE ))update_mmu_cache (vma, vmf.address, vmf.pte); -out_put_page: -if (folio != pagecache_folio) -folio_unlock (folio); -folio_put (folio); out_ptl:spin_unlock (vmf.ptl); - -if (pagecache_folio) { -folio_unlock (pagecache_folio); -folio_put (pagecache_folio); - } out_mutex:hugetlb_vma_unlock_read (vma);
@@ -6538,11 +6513,16 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,mutex_unlock (&hugetlb_fault_mutex_table[hash]);/* -* Generally it's safe to hold refcount during waiting page lock. But -* here we just wait to defer the next page fault to avoid busy loop and -* the page is not used after unlocked before returning from the current -* page fault. So we are safe from accessing freed page, even if we wait -* here without taking refcount. +* hugetlb_wp drops all the locks, but the folio lock, before trying to +* unmap the folio from other processes. During that window, if another +* process mapping that folio faults in, it will take the mutex and then +* it will wait on folio_lock, causing an ABBA deadlock. +* Use trylock instead and bail out if we fail. +* +* Ideally, we should hold a refcount on the folio we wait for, but we do +* not want to use the folio after it becomes unlocked, but rather just +* wait for it to become unlocked, so hopefully next fault successes on +* the trylock. */ if (need_wait_lock)folio_wait_locked (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 870/1536 mm,hugetlb: sort out folio locking in the faulting path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oscar Salvador <[email protected]>
[ Upstream commit 9293fb4765527c0d2375eb441d045a5a75f5210d ]
Recent conversations showed that there was a misunderstanding about why we were locking the folio prior to call in hugetlb_wp(). In fact, as soon as we have the folio mapped into the pagetables, we no longer need to hold it locked, because we know that no concurrent truncation could have happened.
There is only one case where the folio needs to be locked, and that is when we are handling an anonymous folio, because hugetlb_wp() will check whether it can re-use it exclusively for the process that is faulting it in.
So, pass the folio locked to hugetlb_wp() when that is the case.
Stable-dep-of: 824cc56bf43c ("mm/hugetlb: fix use-after-free of a new anon folio")
--- mm/hugetlb.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
mm/hugetlb.c +19 -4
@@ -6116,6 +6116,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,pte_t new_pte;bool new_folio, new_pagecache_folio = false;u32 hash =hugetlb_fault_mutex_hash (mapping, vmf->pgoff); +bool folio_locked = true;/* * Currently, we are forced to kill the process in the event the
@@ -6282,6 +6283,14 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,hugetlb_count_add (pages_per_huge_page (h), mm);if ((vmf->flags &FAULT_FLAG_WRITE ) && !(vma->vm_flags &VM_SHARED )) { +/* +* No need to keep file folios locked. See comment in +* hugetlb_fault(). +*/ +if (!anon_rmap) { + folio_locked = false; +folio_unlock (folio); + }/* Optimization, do the COW without a second fault */ ret =hugetlb_wp (vmf); }
@@ -6296,7 +6305,8 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,if (new_folio)folio_set_hugetlb_migratable (folio); -folio_unlock (folio); +if (folio_locked) +folio_unlock (folio); out:hugetlb_vma_unlock_read (vma);
@@ -6480,15 +6490,20 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,if (flags & (FAULT_FLAG_WRITE |FAULT_FLAG_UNSHARE )) {if (!huge_pte_write (vmf.orig_pte)) { -/* hugetlb_wp() requires page locks of pte_page(vmf.orig_pte) */ +/* +* Anonymous folios need to be lock since hugetlb_wp() +* checks whether we can re-use the folio exclusively +* for us in case we are the only user of it. +*/ folio =page_folio (pte_page (vmf.orig_pte)); -if (!folio_trylock (folio)) { +if (folio_test_anon (folio) && !folio_trylock (folio)) { need_wait_lock = true; goto out_ptl; }folio_get (folio); ret =hugetlb_wp (&vmf); -folio_unlock (folio); +if (folio_test_anon (folio)) +folio_unlock (folio);folio_put (folio); goto out_ptl; }else if (likely (flags &FAULT_FLAG_WRITE )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 871/1536 mm/hugetlb: fix use-after-free of a new anon folio
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 824cc56bf43c714319992bad3558803cac6e77c0 ]
For a fault in a private mapping with nothing in the page cache, hugetlb_no_page() allocates a folio, locks it and maps it. The folio has one reference, which belongs to the page table entry from then on. After dropping the page table lock the function still sets the migratable flag of the folio and unlocks it.
Whoever zaps the entry in between frees the folio. The fault holds the fault mutex and the lock of the vma. MADV_DONTNEED and the first unmap of a hole punch, hugetlb_vmdelete_list(), do not take the fault mutex, and a private vma only has a lock if it owns a reservation map: not with MAP_NORESERVE, and not in the child after fork().
Then the flag is set in, and folio_unlock() is called on, a folio that is free or has a new owner. A surplus page goes back to the page allocator while it is locked:
BUG: Bad page state in process init pfn:108e00 flags: 0x200000000000059(locked|uptodate|dirty|head|node=0|zone=2) page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set
A page of the pool can be given to the next user, of any file, who locks it and loses the lock to the late folio_unlock():
kernel BUG at mm/filemap.c:1532!
hugetlb_no_page+0x111b/0x23e0 hugetlb_fault+0x3a9/0x14a0
An unprivileged process is enough: threads that write to a MAP_PRIVATE | MAP_NORESERVE hugetlb mapping, threads that call MADV_DONTNEED on it, and one that takes the freed pages for another file.
Until commit 3a47c54f09c4 ("hugetlbfs: revert use i_mmap_rwsem for more pmd sharing synchronization") the fault held i_mmap_rwsem for reading, which everybody who zaps takes for writing. The lock that commit bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs") gave to private vmas closed the window again, but only for those with a reservation map.
Be done with the folio before the page table lock is dropped, as hugetlb_wp() is with its copy. The function already unlocks page cache folios under that lock.
Original fix generated by an LLM and sent in private by Josef.
--- mm/hugetlb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/hugetlb.c +6 -2
@@ -6295,8 +6295,6 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, ret =hugetlb_wp (vmf); } -spin_unlock (vmf->ptl); -/* * Only set hugetlb_migratable in newly allocated pages. Existing pages * found in the pagecache may not have hugetlb_migratable if they have
@@ -6307,6 +6305,12 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,if (folio_locked)folio_unlock (folio); + +/* +* Hold the PTL until we're done with the folio: the page table owns the +* folio reference now. +*/ +spin_unlock (vmf->ptl); out:hugetlb_vma_unlock_read (vma);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 872/1536 KVM: guest_memfd: Gracefully handle xarray errors when binding a memslot
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit e6ecb88711d93b9e014532f17d3d29b57e80932c ]
If inserting a memslot into a guest_memfd's bindings xarray fails, propagate the error back to the caller, i.e. fail memslot creation as well. Signalling success and continuing on with memslot creation results in use-after-free, as the guest_memfd instance will remain reachable via the memslot after the file is freed (kvm_gmem_release() won't nullify the file pointer due to lack of a valid binding).
Opportunistically WARN and reject binding if KVM_MEMSLOT_GMEM_ONLY is already set, partly to guard against goofs elsewhere, but mostly so that KVM doesn't need to worry about clobbering flags when unwinding on failure.
Regarding the unwind, the slot must be fully prepared before inserting it into the bindings, at which point the slot becomes reachable. I.e. waiting to update the slot in order to avoid the ugly unwind isn't an option. And as part of the unwind, explicitly nullify the relevant bindings, as xarray can store a subset of entries when populating a range.
--- virt/kvm/guest_memfd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
virt/kvm/guest_memfd.c +6 -2
@@ -520,7 +520,12 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,WRITE_ONCE (slot->gmem.file, file); slot->gmem.pgoff = start; -xa_store_range (&gmem->bindings, start, end -1 , slot,GFP_KERNEL ); + r =xa_err (xa_store_range (&gmem->bindings, start, end -1 , slot,GFP_KERNEL )); +if (r) { +xa_store_range (&gmem->bindings, start, end -1 ,NULL ,GFP_KERNEL ); + slot->gmem.file =NULL ; + slot->gmem.pgoff =0 ; + }filemap_invalidate_unlock (inode->i_mapping);/*
@@ -528,7 +533,6 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,* not the other way 'round. Active bindings are invalidated if the * file is closed before memslots are destroyed. */ - r =0 ; err:fput (file);return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 873/1536 staging: rtl8723bs: fix spacing around operators in rtw_recv.c
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Khasar Munkh-Erdene <[email protected]>
[ Upstream commit 393b267e6f04a11d4b18b7dc1423fa59f173f72b ]
Fix coding style issues by adding missing spaces around binary and ternary operators, as reported by checkpatch.pl.
Omit the spacing change in rtw_handle_tkip_mic_err(), which remains in the receive OS glue. Keep the other operator-spacing fixes, including the decrypt and management-frame contexts required by the protected RX frame validation fix.
Stable-dep-of: 495cb31c791b ("staging: rtl8723bs: fix protected RX frame validation in decrypt path")
--- drivers/staging/rtl8723bs/core/rtw_recv.c | 82 +++++++++++------------ 1 file changed, 41 insertions(+), 41 deletions(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +41 -41
@@ -332,13 +332,13 @@ static signed int recvframe_chkmic(struct adapter *adapter, union recv_frame *p mickey = &stainfo->dot11tkiprxmickey.skey[0 ]; } - datalen = precvframe->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len-prxattrib->icv_len-8 ;/* icv_len included the mic code */ + datalen = precvframe->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len - prxattrib->icv_len -8 ;/* icv_len included the mic code */ pframe = precvframe->u.hdr.rx_data; - payload = pframe+prxattrib->hdrlen+prxattrib->iv_len; + payload = pframe + prxattrib->hdrlen + prxattrib->iv_len;rtw_seccalctkipmic (mickey, pframe, payload, datalen, &miccode[0 ], (unsigned char )prxattrib->priority);/* care the length of the data */ - pframemic = payload+datalen; + pframemic = payload + datalen; bmic_err = false;
@@ -386,9 +386,9 @@ 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 = precv_frame->u.hdr.rx_data + prxattrib->hdrlen; - prxattrib->key_index = (((iv[3 ])>>6 )&0x3 ); + prxattrib->key_index = (((iv[3 ]) >>6 ) &0x3 );if (prxattrib->key_index >WEP_KEYS ) {switch (prxattrib->encrypt) {
@@ -510,7 +510,7 @@ static signed int recv_decache(union recv_frame *precv_frame, u8 bretry, struct {signed int tid = precv_frame->u.hdr.attrib.priority; -u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num&0xffff ) <<4 ) | +u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num &0xffff ) <<4 ) | (precv_frame->u.hdr.attrib.frag_num &0xf );if (tid >15 )
@@ -574,29 +574,29 @@ static void process_wmmps_data(struct adapter *padapter, union recv_frame *precvif (!psta->qos_option)return ; -if (!(psta->qos_info&0xf )) +if (!(psta->qos_info &0xf ))return ; -if (psta->state&WIFI_SLEEP_STATE ) { +if (psta->state &WIFI_SLEEP_STATE ) {u8 wmmps_ac =0 ;switch (pattrib->priority) {case 1 :case 2 : - wmmps_ac = psta->uapsd_bk&BIT (1 ); + wmmps_ac = psta->uapsd_bk &BIT (1 );break ;case 4 :case 5 : - wmmps_ac = psta->uapsd_vi&BIT (1 ); + wmmps_ac = psta->uapsd_vi &BIT (1 );break ;case 6 :case 7 : - wmmps_ac = psta->uapsd_vo&BIT (1 ); + wmmps_ac = psta->uapsd_vo &BIT (1 );break ;case 0 :case 3 :default : - wmmps_ac = psta->uapsd_be&BIT (1 ); + wmmps_ac = psta->uapsd_be &BIT (1 );break ; }
@@ -921,20 +921,20 @@ static signed int validate_recv_ctrl_frame(struct adapter *padapter, union recv_switch (pattrib->priority) {case 1 :case 2 : - wmmps_ac = psta->uapsd_bk&BIT (0 ); + wmmps_ac = psta->uapsd_bk &BIT (0 );break ;case 4 :case 5 : - wmmps_ac = psta->uapsd_vi&BIT (0 ); + wmmps_ac = psta->uapsd_vi &BIT (0 );break ;case 6 :case 7 : - wmmps_ac = psta->uapsd_vo&BIT (0 ); + wmmps_ac = psta->uapsd_vo &BIT (0 );break ;case 0 :case 3 :default : - wmmps_ac = psta->uapsd_be&BIT (0 ); + wmmps_ac = psta->uapsd_be &BIT (0 );break ; }
@@ -946,7 +946,7 @@ static signed int validate_recv_ctrl_frame(struct adapter *padapter, union recv_ psta->state ^=WIFI_STA_ALIVE_CHK_STATE ; } -if ((psta->state&WIFI_SLEEP_STATE ) && (pstapriv->sta_dz_bitmap&BIT (psta->aid))) { +if ((psta->state &WIFI_SLEEP_STATE ) && (pstapriv->sta_dz_bitmap &BIT (psta->aid))) {struct list_head *xmitframe_plist, *xmitframe_phead;struct xmit_frame *pxmitframe =NULL ;struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
@@ -990,7 +990,7 @@ static signed int validate_recv_ctrl_frame(struct adapter *padapter, union recv_/* spin_unlock_bh(&psta->sleep_q.lock); */ spin_unlock_bh (&pxmitpriv->lock); -if (pstapriv->tim_bitmap&BIT (psta->aid)) { +if (pstapriv->tim_bitmap &BIT (psta->aid)) {if (psta->sleepq_len ==0 ) {/* issue nulldata with More data bit = 0 to indicate we have no buffered packets */ issue_nulldata_in_interrupt (padapter, psta->hwaddr);
@@ -1372,9 +1372,9 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame goto validate_80211w_fail; precv_frame =decryptor (adapter, precv_frame);/* save actual management data frame body */ -memcpy (mgmt_DATA, ptr+pattrib->hdrlen+pattrib->iv_len, data_len); +memcpy (mgmt_DATA, ptr + pattrib->hdrlen + pattrib->iv_len, data_len);/* overwrite the iv field */ -memcpy (ptr+pattrib->hdrlen, mgmt_DATA, data_len); +memcpy (ptr + pattrib->hdrlen, mgmt_DATA, data_len);/* remove the iv and icv length */ pattrib->pkt_len = pattrib->pkt_len - pattrib->iv_len - pattrib->icv_len;kfree (mgmt_DATA);
@@ -1430,7 +1430,7 @@ static signed int validate_recv_frame(struct adapter *adapter, union recv_framestruct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;u8 *ptr = precv_frame->u.hdr.rx_data; -u8 ver = (unsigned char ) (*ptr)&0x3 ; +u8 ver = (unsigned char ) (*ptr) &0x3 ;/* add version chk */ if (ver !=0 ) {
@@ -1468,7 +1468,7 @@ static signed int validate_recv_frame(struct adapter *adapter, union recv_frame retval = _FAIL;/* only data frame return _SUCCESS */ break ;case WIFI_DATA_TYPE :/* data */ - pattrib->qos = (subtype &BIT (7 )) ?1 :0 ; + pattrib->qos = (subtype &BIT (7 )) ?1 :0 ; retval =validate_recv_data_frame (adapter, precv_frame);if (retval == _FAIL) {struct recv_priv *precvpriv = &adapter->recvpriv;
@@ -1513,8 +1513,8 @@ static signed int wlanhdr_to_ethhdr(union recv_frame *precvframe)if (pattrib->encrypt)recvframe_pull_tail (precvframe, pattrib->icv_len); - psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len); - psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE ; + psnap = (struct ieee80211_snap_hdr *)(ptr + pattrib->hdrlen + pattrib->iv_len); + psnap_type = ptr + pattrib->hdrlen + pattrib->iv_len +SNAP_SIZE ;/* convert hdr + possible LLC headers into Ethernet header */ /* eth_type = (psnap_type[0] << 8) | psnap_type[1]; */ if ((!memcmp(psnap, rfc1042_header, SNAP_SIZE) &&
@@ -1528,37 +1528,37 @@ static signed int wlanhdr_to_ethhdr(union recv_frame *precvframe)/* Leave Ethernet header part of hdr and full payload */ bsnaphdr = false; - rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr?SNAP_SIZE :0 ); + rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ?SNAP_SIZE :0 ); len = precvframe->u.hdr.len - rmv_len; -memcpy (&be_tmp, ptr+rmv_len,2 ); +memcpy (&be_tmp, ptr + rmv_len,2 ); eth_type =ntohs (be_tmp);/* pattrib->ether_type */ pattrib->eth_type = eth_type;if ((check_fwstate (pmlmepriv,WIFI_MP_STATE ) == true)) { ptr += rmv_len; *ptr =0x87 ; - *(ptr+1 ) =0x12 ; + *(ptr +1 ) =0x12 ; eth_type =0x8712 ;/* append rx status for mp test packets */ - ptr =recvframe_pull (precvframe, (rmv_len-sizeof (struct ethhdr )+2 )-24 ); + ptr =recvframe_pull (precvframe, (rmv_len -sizeof (struct ethhdr ) +2 ) -24 );if (!ptr)return _FAIL;memcpy (ptr,get_rxmem (precvframe),24 ); ptr +=24 ; }else { - ptr =recvframe_pull (precvframe, (rmv_len-sizeof (struct ethhdr ) + (bsnaphdr?2 :0 ))); + ptr =recvframe_pull (precvframe, (rmv_len -sizeof (struct ethhdr ) + (bsnaphdr ?2 :0 )));if (!ptr)return _FAIL; }memcpy (ptr, pattrib->dst,ETH_ALEN ); -memcpy (ptr+ETH_ALEN , pattrib->src,ETH_ALEN ); +memcpy (ptr +ETH_ALEN , pattrib->src,ETH_ALEN );if (!bsnaphdr) { be_tmp =htons (len); -memcpy (ptr+12 , &be_tmp,2 ); +memcpy (ptr +12 , &be_tmp,2 ); }return _SUCCESS;
@@ -1609,7 +1609,7 @@ static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe) pdata += nSubframe_Length; a_len -= nSubframe_Length;if (a_len !=0 ) { - padding_len =4 - ((nSubframe_Length +ETH_HLEN ) & (4 -1 )); + padding_len =4 - ((nSubframe_Length +ETH_HLEN ) & (4 -1 ));if (padding_len ==4 ) padding_len =0 ;
@@ -1841,7 +1841,7 @@ static int recv_indicatepkt_reorder(struct adapter *padapter, union recv_frame *rtw_recv_indicatepkt (padapter, prframe); - preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq +1 )%4096 ; + preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq +1 ) %4096 ;return _SUCCESS; }
@@ -1851,7 +1851,7 @@ static int recv_indicatepkt_reorder(struct adapter *padapter, union recv_frame * retval =amsdu_to_msdu (padapter, prframe); - preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq +1 )%4096 ; + preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq +1 ) %4096 ;if (retval != _SUCCESS) { }
@@ -2043,7 +2043,7 @@ static int recv_func(struct adapter *padapter, union recv_frame *rframe) !psecuritypriv->busetkipkey) {rtw_enqueue_recvframe (rframe, &padapter->recvpriv.uc_swdec_pending_queue); -if (recvpriv->free_recvframe_cnt <NR_RECVFRAME /4 ) { +if (recvpriv->free_recvframe_cnt <NR_RECVFRAME /4 ) {/* to prevent from recvframe starvation, get recvframe from uc_swdec_pending_queue to free_recvframe_cnt */ rframe =rtw_alloc_recvframe (&padapter->recvpriv.uc_swdec_pending_queue);if (rframe)
@@ -2132,19 +2132,19 @@ static void rtw_signal_stat_timer_hdl(struct timer_list *t) }/* update value of signal_strength, rssi, signal_qual */ - tmp_s = (avg_signal_strength+(_alpha-1 )*recvpriv->signal_strength); + tmp_s = (avg_signal_strength + (_alpha -1 ) * recvpriv->signal_strength);if (tmp_s % _alpha) - tmp_s = tmp_s/_alpha +1 ; + tmp_s = tmp_s / _alpha +1 ;else - tmp_s = tmp_s/_alpha; + tmp_s = tmp_s / _alpha;if (tmp_s >100 ) tmp_s =100 ; - tmp_q = (avg_signal_qual+(_alpha-1 )*recvpriv->signal_qual); + tmp_q = (avg_signal_qual + (_alpha -1 ) * recvpriv->signal_qual);if (tmp_q % _alpha) - tmp_q = tmp_q/_alpha +1 ; + tmp_q = tmp_q / _alpha +1 ;else - tmp_q = tmp_q/_alpha; + tmp_q = tmp_q / _alpha;if (tmp_q >100 ) tmp_q =100 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 874/1536 staging: rtl8723bs: fix protected RX frame validation in decrypt path
In reply to Greg Kroah-Hartman6.12-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 | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +18 -3
@@ -386,8 +386,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 ) {
@@ -1371,6 +1384,10 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frameif (!mgmt_DATA) 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 */
@@ -1378,8 +1395,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_multicast_ether_addr (GetAddr1Ptr (ptr)) && (subtype ==WIFI_DEAUTH || subtype ==WIFI_DISASSOC )) {signed int BIP_ret = _SUCCESS;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 875/1536 wifi: mt76: mt7996: unlink TWT flow if the MCU rejects the agreement
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit 022f5f8b7a0580da50fcbc34da853d03d4321fe2 ]
mt7996_mac_add_twt_setup() links a new flow into dev->twt_list before asking the MCU to add the agreement, but exits without unlinking the flow if the request fails. The flow-ID and table masks are only committed after MCU success, so the still-linked flow is invisible to the mask-gated teardown paths.
If the station retries the setup, the same slot is cleared and its embedded list node reinitialized while it is still linked, corrupting dev->twt_list. If the station disassociates instead, teardown skips the flow and station storage can be freed while the node remains linked. A later scheduling or debugfs twt_stats walk can then dereference the freed flow, resulting in a use-after-free.
Unlink the flow when the MCU rejects the agreement. This restores the list to its pre-request state while leaving the unchanged mask and agreement accounting untouched.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +3 -1
@@ -2654,8 +2654,10 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, } flow->tsf =le64_to_cpu (twt_agrt->twt); -if (mt7996_mcu_twt_agrt_update (dev, msta->vif, flow,MCU_TWT_AGRT_ADD )) +if (mt7996_mcu_twt_agrt_update (dev, msta->vif, flow,MCU_TWT_AGRT_ADD )) { +list_del (&flow->list); goto unlock; + } setup_cmd =TWT_SETUP_CMD_ACCEPT ; dev->twt.table_mask |=BIT (table_id);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 876/1536 mptcp: hold MP_JOIN msk ref when cloning reqsk
In reply to Greg Kroah-Hartman6.12-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 | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-)
include/net/mptcp.h +9 -0
@@ -213,6 +213,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);
@@ -308,6 +311,12 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct requesreturn 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 ); }static inline void mptcp_active_detect_blackhole (struct sock *sk,bool expired) { }
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>
@@ -1005,6 +1006,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 +34 -1
@@ -47,6 +47,39 @@ 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_acquire (&sk->sk_refcnt)) { + msk =NULL ; + }else 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) {
@@ -928,7 +961,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 877/1536 virtio_net: atomically disable rx mode work
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 1234707482053f1d1ac7c5756207d2c29057974c ]
virtio-net uses a boolean to gate rx_mode_work during device teardown. The flag is changed under RTNL, but ndo_set_rx_mode checks it under the address-list lock. A callback can therefore pass the check and enqueue work after teardown has flushed it. The work is also enabled before late probe operations that can fail, allowing probe unwind to free the netdev with work still queued.
KASAN reports the worker using a virtqueue that probe unwind already freed:
BUG: KASAN: slab-use-after-free in virtqueue_add_split Workqueue: events virtnet_rx_mode_work Call Trace: virtqueue_add_split (drivers/virtio/virtio_ring.c:706) virtqueue_add_sgs (drivers/virtio/virtio_ring.c:2839) virtnet_send_command_reply (drivers/net/virtio_net.c:3565) virtnet_rx_mode_work (drivers/net/virtio_net.c:3833) process_one_work (kernel/workqueue.c:3322) worker_thread (kernel/workqueue.c:3405) Freed by task 119: kfree (mm/slub.c:6625) vp_del_vq.isra.0 (drivers/virtio/virtio_pci_common.c:259) vp_del_vqs (drivers/virtio/virtio_pci_common.c:285) virtnet_probe (drivers/net/virtio_net.c:7129)
Use the workqueue disable mechanism to atomically reject new queue attempts and drain running work. Keep work disabled until probe succeeds or restore has reattached the netdev, then enable it and replay receive-mode state for a running interface. Disable it before resource teardown in freeze and remove.
--- drivers/net/virtio_net.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/net/virtio_net.c +9 -16
@@ -437,9 +437,6 @@ struct virtnet_info {/* Work struct for setting rx mode */ struct work_struct rx_mode_work; -/* OK to queue work setting RX mode? */ -bool rx_mode_work_enabled; -/* Does the affinity hint is set for virtqueues? */ bool affinity_hint_set;
@@ -678,16 +675,13 @@ static void disable_delayed_refill(struct virtnet_info *vi)static void enable_rx_mode_work (struct virtnet_info *vi) { -rtnl_lock (); - vi->rx_mode_work_enabled = true; -rtnl_unlock (); +if (enable_work (&vi->rx_mode_work) &&netif_running (vi->dev)) +schedule_work (&vi->rx_mode_work); }static void disable_rx_mode_work (struct virtnet_info *vi) { -rtnl_lock (); - vi->rx_mode_work_enabled = false; -rtnl_unlock (); +disable_work_sync (&vi->rx_mode_work); } static void virtqueue_napi_schedule(struct napi_struct *napi,
@@ -3688,8 +3682,7 @@ static void virtnet_set_rx_mode(struct net_device *dev) {struct virtnet_info *vi =netdev_priv (dev); -if (vi->rx_mode_work_enabled) -schedule_work (&vi->rx_mode_work); +schedule_work (&vi->rx_mode_work); } static int virtnet_vlan_rx_add_vid(struct net_device *dev,
@@ -5515,7 +5508,6 @@ static void virtnet_freeze_down(struct virtio_device *vdev)/* Make sure no work handler is accessing the device */ flush_work (&vi->config_work);disable_rx_mode_work (vi); -flush_work (&vi->rx_mode_work);netif_tx_lock_bh (vi->dev);netif_device_detach (vi->dev);
@@ -5538,7 +5530,6 @@ static int virtnet_restore_up(struct virtio_device *vdev)virtio_device_ready (vdev);enable_delayed_refill (vi); -enable_rx_mode_work (vi);if (netif_running (vi->dev)) { err =virtnet_open (vi->dev);
@@ -5549,6 +5540,8 @@ static int virtnet_restore_up(struct virtio_device *vdev)netif_tx_lock_bh (vi->dev);netif_device_attach (vi->dev);netif_tx_unlock_bh (vi->dev); + +enable_rx_mode_work (vi);return err; }
@@ -6610,6 +6603,7 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);INIT_WORK (&vi->rx_mode_work, virtnet_rx_mode_work); +disable_work (&vi->rx_mode_work);spin_lock_init (&vi->refill_lock);if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) {
@@ -6752,8 +6746,6 @@ static int virtnet_probe(struct virtio_device *vdev)if (vi->has_rss || vi->has_rss_hash_report)virtnet_init_default_rss (vi); -enable_rx_mode_work (vi); -/* serialize netdev register + virtio_device_ready() with ndo_open() */ rtnl_lock ();
@@ -6849,6 +6841,8 @@ static int virtnet_probe(struct virtio_device *vdev) goto free_unregister_netdev; } +enable_rx_mode_work (vi); +pr_debug ("virtnet: registered device %s with %d RX and TX vq's\n" , dev->name, max_queue_pairs);
@@ -6900,7 +6894,6 @@ static void virtnet_remove(struct virtio_device *vdev)/* Make sure no work handler is accessing the device. */ flush_work (&vi->config_work);disable_rx_mode_work (vi); -flush_work (&vi->rx_mode_work);virtnet_free_irq_moder (vi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 878/1536 nvmet: replace use of system_wq with system_percpu_wq
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Crivellari <[email protected]>
[ Upstream commit 3d553be6d295b6cca8fd35cb673fd13934ac4cbc ]
This patch continues the effort to refactor workqueue APIs, which has begun with the changes introducing new workqueues and a new alloc_workqueue flag:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq -> system_percpu_wq
system_unbound_wq -> system_dfl_wq
This way the old obsolete workqueues (system_wq, system_unbound_wq) can be removed in the future.
Stable-dep-of: 53f6efe00cea ("nvmet-auth: serialize access to DH-HMAC-CHAP state to fix UAF")
--- drivers/nvme/target/admin-cmd.c | 2 +- drivers/nvme/target/fabrics-cmd-auth.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +1 -1
@@ -1003,7 +1003,7 @@ void nvmet_execute_keep_alive(struct nvmet_req *req)pr_debug ("ctrl %d update keep-alive timer for %d secs\n" , ctrl->cntlid, ctrl->kato); -mod_delayed_work (system_wq, &ctrl->ka_work, ctrl->kato *HZ ); +mod_delayed_work (system_percpu_wq, &ctrl->ka_work, ctrl->kato *HZ ); out:nvmet_req_complete (req, status); }
drivers/nvme/target/fabrics-cmd-auth.c +1 -1
@@ -360,7 +360,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req) req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_FAILURE2) {unsigned long auth_expire_secs = ctrl->kato ? ctrl->kato :120 ; -mod_delayed_work (system_wq, &req->sq->auth_expired_work, +mod_delayed_work (system_percpu_wq, &req->sq->auth_expired_work, auth_expire_secs *HZ ); goto complete; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 879/1536 nvmet-auth: serialize access to DH-HMAC-CHAP state to fix UAF
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 53f6efe00cea0c0cf7bd99debe3cdac8567170b5 ]
A REPLY AUTH_SEND command can derive a dhchap_skey key while a concurrent AUTH_RECEIVE command observing this REPLY state executes the failure path and frees that key. The REPLY command then continues and writes into freed memory, causing a use-after-free. KASAN reports it as:
BUG: KASAN: slab-use-after-free in __sha256_final Write of size 4 at addr ffff88800359c540 ... nvmet_auth_sq_free (drivers/nvme/target/auth.c:237) nvmet_execute_auth_receive (drivers/nvme/target/fabrics-cmd-auth.c:621)
Add a mutex to each submission queue to serialize authentication commands and timeout handling. Unlock the mutex before completing requests and ignore outdated timeout callbacks. Limit timeout delays to prevent immediate expiry on 32-bit kernels.
--- drivers/nvme/target/auth.c | 1 + drivers/nvme/target/fabrics-cmd-auth.c | 32 ++++++++++++++++++++++---- drivers/nvme/target/nvmet.h | 2 ++ 3 files changed, 31 insertions(+), 4 deletions(-)
drivers/nvme/target/auth.c +1 -0
@@ -232,6 +232,7 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl)void nvmet_auth_sq_free (struct nvmet_sq *sq) { + sq->auth_expiry_active = false;cancel_delayed_work (&sq->auth_expired_work);kfree (sq->dhchap_c1); sq->dhchap_c1 =NULL ;
drivers/nvme/target/fabrics-cmd-auth.c +28 -4
@@ -6,6 +6,7 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/blkdev.h> +#include <linux/jiffies.h> #include <linux/random.h> #include <linux/nvme-auth.h> #include <crypto/hash.h>
@@ -18,16 +19,27 @@ static void nvmet_auth_expired_work(struct work_struct *work)struct nvmet_sq *sq =container_of (to_delayed_work (work), struct nvmet_sq, auth_expired_work); +mutex_lock (&sq->auth_lock); +/* A command may have cancelled or rearmed this timeout. */ +if (!sq->auth_expiry_active || +delayed_work_pending (&sq->auth_expired_work)) + goto out_unlock; + sq->auth_expiry_active = false; +pr_debug ("%s: ctrl %d qid %d transaction %u expired, resetting\n" , __func__, sq->ctrl->cntlid, sq->qid, sq->dhchap_tid); sq->dhchap_step =NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE ; sq->dhchap_tid =-1 ; +out_unlock: +mutex_unlock (&sq->auth_lock); }void nvmet_auth_sq_init (struct nvmet_sq *sq) {/* Initialize in-band authentication */ +mutex_init (&sq->auth_lock);INIT_DELAYED_WORK (&sq->auth_expired_work, nvmet_auth_expired_work); + sq->auth_expiry_active = false; sq->authenticated = false; sq->dhchap_step =NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE ; }
@@ -211,6 +223,8 @@ void nvmet_execute_auth_send(struct nvmet_req *req)u16 status =0 ;u8 dhchap_status; +mutex_lock (&req->sq->auth_lock); +if (req->cmd->auth_send.secp !=NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER ) { status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc =
@@ -236,8 +250,10 @@ void nvmet_execute_auth_send(struct nvmet_req *req) offsetof(struct nvmf_auth_send_command , tl); goto done; } -if (!nvmet_check_transfer_len (req, tl)) { +if (unlikely (tl != req->transfer_len)) {pr_debug ("%s: transfer length mismatch (%u)\n" , __func__, tl); +mutex_unlock (&req->sq->auth_lock); +nvmet_check_transfer_len (req, tl);return ; }
@@ -358,10 +374,12 @@ void nvmet_execute_auth_send(struct nvmet_req *req) status, req->error_loc);if (req->sq->dhchap_step !=NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2 && req->sq->dhchap_step !=NVME_AUTH_DHCHAP_MESSAGE_FAILURE2 ) { -unsigned long auth_expire_secs = ctrl->kato ? ctrl->kato :120 ; +unsigned long auth_expire =min_t (u64,MAX_JIFFY_OFFSET , + (u64)(ctrl->kato ? ctrl->kato :120 ) *HZ ); + req->sq->auth_expiry_active = true;mod_delayed_work (system_percpu_wq, &req->sq->auth_expired_work, - auth_expire_secs *HZ ); + auth_expire); goto complete; }/* Final states, clear up variables */
@@ -370,6 +388,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req)nvmet_ctrl_fatal_error (ctrl); complete: +mutex_unlock (&req->sq->auth_lock);nvmet_req_complete (req, status); }
@@ -488,6 +507,8 @@ void nvmet_execute_auth_receive(struct nvmet_req *req)u32 al;u16 status =0 ; +mutex_lock (&req->sq->auth_lock); +if (req->cmd->auth_receive.secp !=NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER ) { status =NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; req->error_loc =
@@ -513,8 +534,10 @@ void nvmet_execute_auth_receive(struct nvmet_req *req) offsetof(struct nvmf_auth_receive_command , al); goto done; } -if (!nvmet_check_transfer_len (req, al)) { +if (unlikely (al != req->transfer_len)) {pr_debug ("%s: transfer length mismatch (%u)\n" , __func__, al); +mutex_unlock (&req->sq->auth_lock); +nvmet_check_transfer_len (req, al);return ; }
@@ -573,5 +596,6 @@ void nvmet_execute_auth_receive(struct nvmet_req *req)nvmet_auth_sq_free (req->sq);nvmet_ctrl_fatal_error (ctrl); } +mutex_unlock (&req->sq->auth_lock);nvmet_req_complete (req, status); }
drivers/nvme/target/nvmet.h +2 -0
@@ -110,8 +110,10 @@ struct nvmet_sq {u32 sqhd;bool sqhd_disabled;#ifdef CONFIG_NVME_TARGET_AUTH +struct mutex auth_lock;bool authenticated;struct delayed_work auth_expired_work; +bool auth_expiry_active;u16 dhchap_tid;u8 dhchap_status;u8 dhchap_step;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 880/1536 media: ipu-bridge: Fix use-after-free in IVSC error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yibo Tan <[email protected]>
[ Upstream commit 3d42d1c82717f0853379b516a7fab54b636e09cc ]
ipu_bridge_get_ivsc_acpi_dev() returns an ACPI device with a reference held. If no matching CSI device is found, ipu_bridge_check_ivsc_dev() drops that reference before passing the device to dev_err(). Concurrent CSI device and ACPI namespace removal can drop the other references, making this the final put. dev_err() then reads the freed struct acpi_device and its kobject name.
This was reproduced without kprobes by racing normal CSI platform-device unregistration and ACPI configfs table removal against the production ipu_bridge_init() entry. KASAN reported the final free through device_release(), followed by invalid reads through _dev_err().
Emit the error message while the lookup reference is still held, then drop the reference as before.
Source reproducers and vulnerable/fixed serial logs, with only the build hostname redacted, are available at:
https://github.com/kimaiden1984-boop/linux-ipu-bridge-acpi-uaf-reproducer
The fixed target builds with W=1 on x86-64. This was not tested on physical IPU hardware. The tests establish runtime reachability but do not measure occurrence frequency on shipping systems or establish exploitability.
--- drivers/media/pci/intel/ipu-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/intel/ipu-bridge.c +1 -1
@@ -191,8 +191,8 @@ static int ipu_bridge_check_ivsc_dev(struct ipu_sensor *sensor,if (adev) { csi_dev =ipu_bridge_get_ivsc_csi_dev (adev);if (!csi_dev) { -acpi_dev_put (adev);dev_err (ADEV_DEV (adev),"Failed to find MEI CSI dev\n" ); +acpi_dev_put (adev);return -ENODEV ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 881/1536 ASoC: amd: ps: fix snd_acp63_remove() teardown ordering
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit c53791d673ed4da6759d276078627ec4d0c6536b ]
The ACP IRQ handlers dereference the SoundWire, SoundWire DMA, and PDM child platform devices, but snd_acp63_remove() unregisters them while the interrupt is still held by devres, which frees it only after remove returns. An interrupt in this window is a use-after-free.
Mask the ACP interrupt sources and call devm_free_irq() before the first child device is unregistered. The masking goes through the new acp_hw_ops->disable_interrupts callback, keeping the remove path platform-agnostic. The interrupt line is shared, and acp_hw_deinit() clears the sources only after the children are gone, which would leave the line raised with no handler left to ack it. The window predates the tagged refactor, which only reshaped the dereferences.
devm_free_irq() waits for in-flight handlers, but not for work the hardirq has already queued: acp63_irq_handler() schedules amd_sdw_irq_thread on the SoundWire manager. Draining that work in the manager's remove path is a soundwire-side change and follows separately.
This issue was found by an in-house static analysis tool.
--- sound/soc/amd/ps/pci-ps.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/amd/ps/pci-ps.c +2 -0
@@ -724,6 +724,8 @@ static void snd_acp63_remove(struct pci_dev *pci)int ret; adata =pci_get_drvdata (pci); +acp63_disable_interrupts (adata->acp63_base); +devm_free_irq (&pci->dev, pci->irq, adata);if (adata->sdw) {amd_sdw_exit (adata);platform_device_unregister (adata->sdw_dma_dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 882/1536 mm: khugepaged: fix swap entry value to folio_pfn()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vernon Yang <[email protected]>
[ Upstream commit 942c8ec27aa4ffc587511650718349964e1696e6 ]
Patch series "mm: khugepaged: fix tracepoint UAF", v5.
The khugepaged tracepoints take a folio pointer and call folio_pfn(), but by then the folio may no longer be valid: freed after folio_put(), folio_unlock() or pte_unmap_unlock(), or not a folio at all but an xarray-encoded swap entry. On classic SPARSEMEM, dereferencing it oopses khugepaged as soon as the trace event is enabled; on other memory models it merely prints a bogus pfn.
Pass the pfn to the tracepoints directly, captured while the folio is still pinned, closing the use-after-free windows in mm_khugepaged_scan_file(), mm_khugepaged_scan_pmd() and mm_khugepaged_collapse_file().
This patch (of 3):
When the swap entries found exceed max_ptes_swap, the loop is left via break with folio still holding the xarray value that encodes the swap entry, not valid folio pointer.
That value is passed to trace_mm_khugepaged_scan_file(), which feeds it to folio_pfn(). On FLATMEM and SPARSEMEM_VMEMMAP, the page_to_pfn() is plain pointer arithmetic, so the trace event merely prints bogus scan_pfn. On classic SPARSEMEM, the page_to_pfn() reads page->flags, dereferencing the tiny encoded integer and oopsing khugepaged whenever the trace event is enabled.
So when folio is the swap entry value, simply set pfn to -1, just like exhausted scan naturally.
And the folio_put() has maybe dropped the last reference of folio. The trace_mm_khugepaged_scan_file() is left with a dangling folio pointer. so using the folio_pfn() before dropping the reference, closing use-after-free window.
--- include/trace/events/huge_memory.h | 6 +++--- mm/khugepaged.c | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-)
include/trace/events/huge_memory.h +3 -3
@@ -174,10 +174,10 @@ TRACE_EVENT(mm_collapse_huge_page_swapin, TRACE_EVENT(mm_khugepaged_scan_file, - TP_PROTO(struct mm_struct *mm, struct folio *folio, struct file *file, + TP_PROTO(struct mm_struct *mm, unsigned long pfn, struct file *file, int present, int swap, int result), - TP_ARGS(mm, folio, file, present, swap, result), + TP_ARGS(mm, pfn, file, present, swap, result), TP_STRUCT__entry( __field(struct mm_struct *, mm)
@@ -190,7 +190,7 @@ TRACE_EVENT(mm_khugepaged_scan_file,TP_fast_assign ( __entry->mm = mm; - __entry->pfn = folio ?folio_pfn (folio) :-1 ; + __entry->pfn = pfn;__assign_str (filename); __entry->present = present; __entry->swap = swap;
mm/khugepaged.c +6 -1
@@ -2258,6 +2258,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr,int present, swap;int node =NUMA_NO_NODE ;int result =SCAN_SUCCEED ; +unsigned long failed_pfn =-1 ; present =0 ; swap =0 ;
@@ -2283,6 +2284,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, folio->index == start) {/* Maybe PMD-mapped */ result =SCAN_PTE_MAPPED_HUGEPAGE ; + failed_pfn =folio_pfn (folio);/* * For SCAN_PTE_MAPPED_HUGEPAGE, further processing * by the caller won't touch the page cache, and so
@@ -2295,17 +2297,20 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, node =folio_nid (folio);if (hpage_collapse_scan_abort (node, cc)) { result =SCAN_SCAN_ABORT ; + failed_pfn =folio_pfn (folio);break ; } cc->node_load[node]++;if (!folio_test_lru (folio)) { result =SCAN_PAGE_LRU ; + failed_pfn =folio_pfn (folio);break ; }if (!is_refcount_suitable (folio)) { result =SCAN_PAGE_COUNT ; + failed_pfn =folio_pfn (folio);break ; }
@@ -2335,7 +2340,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, } } -trace_mm_khugepaged_scan_file (mm, folio, file, present, swap, result); +trace_mm_khugepaged_scan_file (mm, failed_pfn, file, present, swap, result);return result; }#else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 883/1536 media: s5p-mfc: use timer_shutdown_sync() for the self-rearming watchdog
In reply to Greg Kroah-Hartman6.12-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/samsung/s5p-mfc/s5p_mfc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +2 -2
@@ -1458,8 +1458,8 @@ static void 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 884/1536 scsi: dc395x: sync the waiting_timer before freeing the host
In reply to Greg Kroah-Hartman6.12-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
@@ -4411,13 +4411,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 885/1536 media: rc: Fix race between bpf(BPG_PROG_ATTACH) and device unregister
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit b3f5daf3222999d3f92f606a4eb5e35ab90fd0e4 ]
Mark the device as unregistered before tearing down raw IR/bpf state, so that racing bpf(BPF_PROG_{ATTACH,DETACH,QUERY}) calls cannot slip in between ir_raw_event_unregister() completing and dev->registered being cleared.
--- drivers/media/rc/rc-main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/media/rc/rc-main.c +6 -6
@@ -2030,18 +2030,18 @@ void rc_unregister_device(struct rc_dev *dev)if (!dev)return ; +mutex_lock (&dev->lock); + dev->registered = false; +if (dev->users && dev->close) + dev->close (dev); +mutex_unlock (&dev->lock); +if (dev->driver_type ==RC_DRIVER_IR_RAW )ir_raw_event_unregister (dev);del_timer_sync (&dev->timer_keyup);del_timer_sync (&dev->timer_repeat); -mutex_lock (&dev->lock); -if (dev->users && dev->close) - dev->close (dev); - dev->registered = false; -mutex_unlock (&dev->lock); -rc_free_rx_device (dev);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 886/1536 drm/nouveau: reject zero-size notifier object allocation
In reply to Greg Kroah-Hartman6.12-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
@@ -631,6 +631,10 @@ nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)if (unlikely (device->info.family >=NV_DEVICE_INFO_V0_FERMI ))return nouveau_abi16_put (abi16, -EINVAL ); +/* 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 887/1536 drm/nouveau/svm: drain fault handler before freeing svmm
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenhao Wan <[email protected]>
[ Upstream commit b46ddaf0823405f81e681eb26ec98508f3eb9a07 ]
The SVM fault handler nouveau_svm_fault() looks up each fault's nouveau_svmm under svm->mutex, caches it in the fault array, then drops svm->mutex and dereferences the svmm across blocking faults (mmu_interval_notifier_insert(), hmm_range_fault()).
nouveau_svmm is not refcounted. On DRM file close nouveau_svmm_fini() -> mmu_notifier_put() frees it asynchronously via call_srcu() without waiting for the handler, and mmget_not_zero() pins the mm, not the svmm. flush_work() on the fault buffer otherwise runs only at device removal and suspend, never on close, so a fault handled concurrently with a close can dereference a freed svmm.
The instance is already unlinked by nouveau_svmm_part() earlier in the same close, so no new fault can resolve to it. Drain the handler in nouveau_svmm_fini() before the free, guarding the flush with a NULL check on drm->svm: on device teardown nouveau_svm_fini() runs first and frees drm->svm (NULL) after blocking the notify and flushing the buffer, so the handler is already drained; on per-client close drm->svm is alive and the flush runs.
--- drivers/gpu/drm/nouveau/nouveau_svm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/nouveau/nouveau_svm.c +13 -0
@@ -304,6 +304,19 @@ nouveau_svmm_fini(struct nouveau_svmm **psvmm) {struct nouveau_svmm *svmm = *psvmm;if (svmm) { +struct nouveau_svm *svm = svmm->vmm->cli->drm->svm; + +/* The fault handler caches svmm pointers under svm->mutex and +* dereferences them after dropping it, across blocking faults. +* The instance is already unlinked (nouveau_svmm_part), so drain +* the handler before the free to release any in-flight reference. +* +* On device teardown nouveau_svm_fini() ran first and freed +* drm->svm (NULL) after draining the buffer; nothing to flush. +*/ +if (svm) +flush_work (&svm->buffer[0 ].work); +mutex_lock (&svmm->mutex); svmm->vmm =NULL ;mutex_unlock (&svmm->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 888/1536 drm/nouveau: disable the fence uevent work instead of just cancelling it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Czernohous <[email protected]>
[ Upstream commit 827eb9328eaed831d7cc426ac2705038a40835b6 ]
nouveau_fence_context_del() drains the uevent work while the event that feeds it is still armed:
cancel_work_sync(&fctx->uevent_work); nouveau_fence_context_kill(fctx, 0); nvif_event_dtor(&fctx->event);
nouveau_fence_wait_uevent_handler() queues the work unconditionally:
schedule_work(&fctx->uevent_work); return NVIF_EVENT_KEEP;
so a non-stall interrupt arriving after cancel_work_sync() has returned re-arms the work that was just drained. The window closes in two steps, neither of which is the drain. The kill blocks the event when the last fence holding a notify_ref is signalled, which reaches atomic_xchg(&ntfy->allowed, 0) (nvkm/core/event.c:104), and nvkm_event_ntfy() skips a ntfy that is not allowed (:183). That stops further handlers from starting, but not one that is already inside nvkm_event_ntfy(): the event is created with wait = false (nouveau_fence.c:201), so nvkm_event_ntfy_block_() leaves it on the list and never takes event->list_lock. Only nvif_event_dtor() waits that one
out: nvkm_event_ntfy_del() (:141) goes through nvkm_event_ntfy_remove(), which takes write_lock_irq() on that same list_lock (:84).
Either way the re-arm happens after the drain, and the caller drops its reference immediately afterwards, for example nv84_fence_context_del():
nouveau_fence_context_del(&fctx->base); chan->fence = NULL; nouveau_fence_context_free(&fctx->base);
That is a kref_put() on fctx->fence_ref, so the context outlives the teardown only while emitted fences still hold a reference of their own. That is no safety net: whenever none do, the count reaches zero right there and nouveau_fence_context_put() kfree()s fctx while the work is still queued. &fctx->uevent_work is embedded in that allocation, so the workqueue already dereferences freed memory when it picks the item up, and nouveau_fence_uevent_work() can then take fctx->lock on it. With CONFIG_DEBUG_OBJECTS_WORK and CONFIG_DEBUG_OBJECTS_FREE, kfree() of a still-queued work item is reported as the free of an active object.
On live memory the re-armed work has nothing left to do:nouveau_fence_context_kill() empties fctx->pending and sets fctx->killed under fctx->lock, nouveau_fence_emit() then returns -ENODEV rather than queueing anything new, and nouveau_fence_update() only reaches nvif_event_block() if it signalled something off that list. The defect is the access to freed memory, not what the work would have found.
Only chips from G84 on can reach this at all: nouveau_fence_context_new() returns before nvif_event_ctor() when priv->uevent is clear, and nv84_fence_create() is the only place that sets it. nv84_fence_context_del() is the context_del for all of those, because nvc0_fence_create() and gv100_fence_create() build on nv84_fence_create() and override only context_new.
Use disable_work_sync() instead. It drains the work exactly like cancel_work_sync() does, and additionally increments the work item's disable count, after which "any attempt to queue @work will fail and return %false" (kernel/workqueue.c, disable_work()). The handler's schedule_work() then has nothing to re-arm, and the teardown order stays as it is.
Draining a second time after nvif_event_dtor() would close the window as well, and without the newer API: once nvkm_event_ntfy_remove() has returned, no handler can start or still be running, so nothing re-arms the work past that point. disable_work_sync() is preferred here because it needs one synchronisation point instead of two, it keeps the work from being queued at all rather than cleaning up after it, and it is what drm has settled on for this (drm/xe, drm/panthor, drm_pagemap). Blocking the event rather than the work is not an option: fctx->event is created with wait = false, so a handler already inside nvkm_event_ntfy() can still queue the work.
Note for backports: disable_work_sync() arrived in v6.10 with commit 86898fa6b8cd ("workqueue: Implement disable/enable for (delayed) work items"), while the fix being corrected here reached 6.6.18 and 6.7.6. linux-6.6.y therefore carries this bug without the API, and this patch would apply there and then fail to build. A 6.6.y backport wants the second drain described above instead, as its own patch.
--- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_fence.c +1 -1
@@ -103,7 +103,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)void nouveau_fence_context_del (struct nouveau_fence_chan *fctx) { -cancel_work_sync (&fctx->uevent_work); +disable_work_sync (&fctx->uevent_work);nouveau_fence_context_kill (fctx,0 );nvif_event_dtor (&fctx->event); fctx->dead =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 889/1536 drm/nouveau: cancel the DP IRQ work before freeing the connector
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Czernohous <[email protected]>
[ Upstream commit f60849975a886d70883bcb6b3658c0fa83c6971f ]
nouveau_connector_destroy() tears the two nvif events down and then frees the connector, but never cancels the work the IRQ event queues:
nvif_event_dtor(&nv_connector->irq); nvif_event_dtor(&nv_connector->hpd); kfree(nv_connector->edid); ... kfree(connector);
nouveau_connector_irq() queues that work unconditionally:
schedule_work(&nv_connector->irq_work); return NVIF_EVENT_KEEP;
A DP IRQ arriving just before nvif_event_dtor() therefore leaves nv_connector->irq_work on the system queue past the kfree(). When it runs, nouveau_dp_irq() derives both nv_connector and connector from the work_struct and dereferences them, and goes on to take outp->dp.hpd_irq_lock.
There is no cancel_work_sync() for irq_work anywhere in the driver, so nothing else covers this. Add it after the event teardown, where no further work can be queued, and before anything is freed.
Reported by the Sashiko review bot as a pre-existing issue, in its review of an earlier nv04 FIFO series of mine, and confirmed against the source.
--- drivers/gpu/drm/nouveau/nouveau_connector.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_connector.c +1 -0
@@ -397,6 +397,7 @@ nouveau_connector_destroy(struct drm_connector *connector)struct nouveau_connector *nv_connector =nouveau_connector (connector);nvif_event_dtor (&nv_connector->irq);nvif_event_dtor (&nv_connector->hpd); +cancel_work_sync (&nv_connector->irq_work);kfree (nv_connector->edid);drm_connector_unregister (connector);drm_connector_cleanup (connector);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 890/1536 drm/nouveau: dont dereference outp before checking it in nouveau_dp_irq
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Czernohous <[email protected]>
[ Upstream commit 843bc34db94bff0612c8294861b156489958897b ]
nouveau_dp_irq() looks the encoder up and dereferences it in the same breath, five lines before testing it:
struct nouveau_encoder *outp = find_encoder(connector, DCB_OUTPUT_DP); struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev); ... if (!outp) return;
find_encoder() walks the connector's possible encoders and returns NULL when none of them matches the requested type, so the NULL test is not
decoration: it is the author saying this can happen. The initialiser above it dereferences the same pointer regardless.
The NULL test predates the dereference. commit 773eb04d14a1 ("drm/nouveau/disp: expose conn event class") turned nouveau_dp_irq() into a work callback, and since the drm pointer was no longer passed in as an argument it was recovered from the encoder in the declaration block, which put the dereference above the existing test.
Move the drm lookup below the test. No functional change when outp is non-NULL.
--- drivers/gpu/drm/nouveau/nouveau_dp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_dp.c +3 -1
@@ -499,7 +499,7 @@ nouveau_dp_irq(struct work_struct *work)container_of (work,typeof (*nv_connector), irq_work);struct drm_connector *connector = &nv_connector->base;struct nouveau_encoder *outp =find_encoder (connector,DCB_OUTPUT_DP ); -struct nouveau_drm *drm =nouveau_drm (outp->base.base.dev); +struct nouveau_drm *drm;struct nv50_mstm *mstm;u64 hpd =0 ;int ret;
@@ -507,6 +507,8 @@ nouveau_dp_irq(struct work_struct *work)if (!outp)return ; + drm =nouveau_drm (outp->base.base.dev); + mstm = outp->dp.mstm;NV_DEBUG (drm,"service %s\n" , connector->name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 891/1536 drm/amdgpu: recompute the dw estimate after allocating a new VM update job
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: YuBiao Wang <[email protected]>
[ Upstream commit a74c7832b11827907de560169c7d4ac94505fd87 ]
amdgpu_vm_sdma_update() keeps the number of free dwords of the current job in a local variable. When the job runs out of room it is committed and a new one is allocated, but that local variable is not refreshed and still describes the job which was just submitted.
The stale value is then used to decide how many PTEs fit into the new job. If it happens to be copy_pte_num_dw + 7, or one more than that, the result is zero. copy_pte() encodes the transfer size as count * 8 - 1, so a count of zero asks the engine for a 1GB copy starting inside the IB pool. That runs off the end of the pool, faults on the first unmapped GART page above it and hangs the ring.
Re-initialize the estimate from the newly allocated job, which is empty and therefore has its full budget available.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +5 -0
@@ -254,6 +254,11 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, AMDGPU_KERNEL_JOB_ID_VM_UPDATE);if (r)return r; + +/* The estimate above describes the job which was just +* submitted, take the budget of the newly allocated one. +*/ + ndw = p->num_dw_left; }if (!p->pages_addr) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 892/1536 drm/amd/display: Force GAMCOR for subsampled surfaces with PQ/Gamma22/HLG
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Wentland <[email protected]>
[ Upstream commit 2ffaa7c4050605cb27756f5336f778d1b21268b9 ]
The ROM early-return checks for PQ, Gamma 2.2, and HLG in mod_color_calculate_degamma_params() do not consider the map_user_ramp parameter. When map_user_ramp is true (indicating a subsampled surface that requires post-scaler degamma via GAMCOR), the function still takes the ROM path, programming PRE_DEGAM instead.
For subsampled formats the chroma channels must be upsampled by the scaler before degamma is applied. PRE_DEGAM sits before the scaler in the pipeline (CNVC domain), while GAMCOR sits after it (CM domain). Using the ROM for subsampled surfaces means degamma is applied to subsampled chroma before upsampling, producing incorrect results.
Fix by gating the dcn_arch ROM capability checks on !map_user_ramp, forcing PQ/Gamma22/HLG through the GAMCOR LUT path when the surface is subsampled.
--- drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/modules/color/color_gamma.c +2 -1
@@ -2001,7 +2001,8 @@ bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,return true;if (dc_caps !=NULL && - dc_caps->dpp.dcn_arch ==1 ) { + dc_caps->dpp.dcn_arch ==1 && + !map_user_ramp) {if (input_tf->tf ==TRANSFER_FUNCTION_PQ && dc_caps->dpp.dgam_rom_caps.pq ==1 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 893/1536 media: streamzap: Add missing rc_unregister_device()
In reply to Greg Kroah-Hartman6.12-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
@@ -365,6 +365,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 894/1536 media: redrat3: Ensure we dont read beyond the end of the packet
In reply to Greg Kroah-Hartman6.12-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 895/1536 media: redrat3: Ensure all urbs are suspended
In reply to Greg Kroah-Hartman6.12-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
@@ -1170,6 +1170,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 896/1536 media: sunxi-cir: Ensure no more interrupts can occur before free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit f9b33ec404200c03dd490ec133b8f9bf599c5444 ]
Only call rc_free_device() once the hardware has been stopped.
--- drivers/media/rc/sunxi-cir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/sunxi-cir.c +1 -1
@@ -374,8 +374,8 @@ static void sunxi_ir_remove(struct platform_device *pdev)struct sunxi_ir *ir =platform_get_drvdata (pdev);rc_unregister_device (ir->rc); -rc_free_device (ir->rc);sunxi_ir_hw_exit (&pdev->dev); +rc_free_device (ir->rc); }static void sunxi_ir_shutdown (struct platform_device *pdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 897/1536 media: meson-ir-tx: Ensure clock is disabled on unbind
In reply to Greg Kroah-Hartman6.12-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 898/1536 media: meson-ir-tx: Ensure rc_free_device() is called on unbind
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 32999b8a9d5c4f497c9739e70ac4ee390cd650a7 ]
Make rc_dev devm managed.
--- drivers/media/rc/meson-ir-tx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/rc/meson-ir-tx.c +2 -4
@@ -346,7 +346,7 @@ static int meson_irtx_probe(struct platform_device *pdev)if (ret)return dev_err_probe (dev, ret,"irq request failed\n" ); - rc =rc_allocate_device (RC_DRIVER_IR_RAW_TX ); + rc =devm_rc_allocate_device (dev,RC_DRIVER_IR_RAW_TX );if (!rc)return -ENOMEM ;
@@ -359,10 +359,8 @@ static int meson_irtx_probe(struct platform_device *pdev) rc->s_tx_duty_cycle = meson_irtx_set_duty_cycle; ret =devm_rc_register_device (dev, rc); -if (ret <0 ) { -rc_free_device (rc); +if (ret <0 )return dev_err_probe (dev, ret,"rc_dev registration failed\n" ); - }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 899/1536 media: meson-ir-tx: Ensure probe error is propagated
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 2eb8a4cba70f521a8217021e227cfa28ba17724b ]
devm_clk_get_enabled() may return -EPROBE_DEFER which needs to be propagated else the probe will not be deferred, it will fail instead.
--- drivers/media/rc/meson-ir-tx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/meson-ir-tx.c +2 -2
@@ -292,7 +292,7 @@ static int meson_irtx_mod_clock_probe(struct meson_irtx *ir, clock =devm_clk_get_enabled (ir->dev,"xtal" );if (IS_ERR (clock)) -return -ENODEV ; +return PTR_ERR (clock); ir->clk_rate =clk_get_rate (clock) /3 ;
@@ -325,7 +325,7 @@ static int meson_irtx_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );if (irq <0 ) -return -ENODEV ; +return irq; ir->dev = dev; ir->carrier =MIRTX_DEFAULT_CARRIER ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 900/1536 media: ir-hix5hd2: Ensure rdev is setup before interrupts are enabled
In reply to Greg Kroah-Hartman6.12-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
@@ -316,6 +316,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);
@@ -323,8 +326,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 901/1536 media: imx-jpeg: finish the job on device_run() error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 30b35fd2b999e1b8c26f8191d974d20c8848d2d6 ]
mxc_jpeg_device_run() returns early through a shared "end" label on several error paths (no free slot, mxc_jpeg_alloc_slot_data() failure, or missing buffers or queue data), and none of them calls v4l2_m2m_job_finish(). Since the delayed work is queued only after the hardware is started, those paths neither finish the job directly nor queue timeout work that could finish it later. The job is left with TRANS_RUNNING set, so the wait_event() in v4l2_m2m_cancel_job() (reached from v4l2_m2m_ctx_release() at close) waits indefinitely and the close hangs.
mxc_jpeg_alloc_slot_data() uses dma_alloc_coherent(), so the failure path is reachable under memory pressure.
Return the src/dst buffers with VB2_BUF_STATE_ERROR and call v4l2_m2m_job_finish() on those paths: paths that have buffers use a "buf_finish" label; the no-buffer path uses "job_finish" directly. This mirrors the existing jpeg_parse_error path.
This bug was found by static analysis.
--- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +15 -6
@@ -1450,15 +1450,15 @@ static void mxc_jpeg_device_run(void *priv) dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx);if (!src_buf || !dst_buf) {dev_err (dev,"Null src or dst buf\n" ); - goto end; + goto job_finish; } q_data_cap =mxc_jpeg_get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE );if (!q_data_cap) - goto end; + goto buf_finish; q_data_out =mxc_jpeg_get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT );if (!q_data_out) - goto end; + goto buf_finish; src_buf->sequence = q_data_out->sequence++; dst_buf->sequence = q_data_cap->sequence++;
@@ -1496,11 +1496,11 @@ static void mxc_jpeg_device_run(void *priv) ctx->slot =mxc_get_free_slot (&jpeg->slot_data);if (ctx->slot <0 ) {dev_err (dev,"No more free slots\n" ); - goto end; + goto buf_finish; }if (!mxc_jpeg_alloc_slot_data (jpeg)) {dev_err (dev,"Cannot allocate slot data\n" ); - goto end; + goto buf_finish; }mxc_jpeg_enable_slot (reg, ctx->slot);
@@ -1522,8 +1522,17 @@ static void mxc_jpeg_device_run(void *priv)mxc_jpeg_dec_mode_go (dev, reg); }schedule_delayed_work (&ctx->task_timer,msecs_to_jiffies (hw_timeout)); -end: +spin_unlock_irqrestore (&ctx->mxc_jpeg->hw_lock, flags); +return ; +buf_finish: +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); +job_finish: +spin_unlock_irqrestore (&ctx->mxc_jpeg->hw_lock, flags); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 902/1536 microblaze: Fix MB_MANAGER build with older binutils
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 79c8aa4da3d5453dd956d2170d1c9c716311ea06 ]
Commit 88707ebe77e2 ("microblaze: Add custom break vector handler for mb manager") added the suspend mnemonic to the MB Manager break handler.
GNU as only learned this mnemonic in binutils 2.42. Linux supports binutils 2.30, where enabling CONFIG_MB_MANAGER fails:
arch/microblaze/kernel/entry.S:946: Error: unknown opcode "suspend"
The suspend mnemonic is an alias for mbar 24, and both encode as 0xbb020004. Use the underlying instruction, which GNU as 2.30 already supports.
--- arch/microblaze/kernel/entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/microblaze/kernel/entry.S +1 -1
@@ -943,7 +943,7 @@ ret_from_break: mbar 1 mbar 2 bri 4 - suspend + mbar 24 /* suspend */ nop #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 903/1536 udf: Make sure theres enough space for LVID implementation use field
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
[ Upstream commit a61fb39759d719a4f4966742b4d28387e33d81c4 ]
udf_lvid_valid() verifies that the LVID has enough space for all the tables and the reported length of ImplementationUse field. However it doesn't make sure the reported length is large enough to contain logicalVolIntegrityDescImpUse structure which OSTA specification requires. This can thus lead to accesses beyond the end of LVID buffer for suitably corrupted UDF filesystem. Add the length check.
--- fs/udf/super.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/udf/super.c +4 -1
@@ -1611,7 +1611,10 @@ static bool udf_lvid_valid(struct super_block *sb, parts =le32_to_cpu (lvid->numOfPartitions); impuselen =le32_to_cpu (lvid->lengthOfImpUse); -if (parts >= sb->s_blocksize || impuselen >= sb->s_blocksize || +if (sizeof (struct logicalVolIntegrityDescImpUse ) > impuselen || + impuselen >= sb->s_blocksize) +return false; +if (parts >= sb->s_blocksize ||sizeof (struct logicalVolIntegrityDesc ) + impuselen +2 * parts *sizeof (u32) > sb->s_blocksize)return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 904/1536 aio: prevent eventfd/epoll recursion on poll
In reply to Greg Kroah-Hartman6.12-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
@@ -1815,7 +1815,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 905/1536 ipc/mqueue: release notification resources during inode eviction
In reply to Greg Kroah-Hartman6.12-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
@@ -528,6 +528,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 906/1536 remoteproc: elf_loader: Bound the section header table
In reply to Greg Kroah-Hartman6.12-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 907/1536 microblaze: reserve the ABI argument-home area in the signal frame
In reply to Greg Kroah-Hartman6.12-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 908/1536 microblaze: dont clobber r3/r4 restored by rt_sigreturn
In reply to Greg Kroah-Hartman6.12-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
@@ -434,7 +434,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;
@@ -518,6 +524,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 909/1536 microblaze: preserve the MSR carry flags across signals
In reply to Greg Kroah-Hartman6.12-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/resume_user_mode.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 910/1536 memory: brcmstb_dpfe: Fix out-of-bounds access due to DCPU offset
In reply to Greg Kroah-Hartman6.12-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 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/memory/brcmstb_dpfe.c +20 -2
@@ -182,6 +182,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;
@@ -401,9 +403,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 :
@@ -415,6 +422,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)
@@ -858,6 +871,7 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct brcmstb_dpfe_priv *priv; +struct resource *res;int ret; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
@@ -869,17 +883,21 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev)mutex_init (&priv->lock);platform_set_drvdata (pdev, priv); - priv->regs =devm_platform_ioremap_resource_byname (pdev,"dpfe-cpu" ); + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"dpfe-cpu" ); + priv->regs =devm_ioremap_resource (dev, res);if (IS_ERR (priv->regs)) {dev_err (dev,"couldn't map DCPU registers\n" );return -ENODEV ; } + priv->regs_size =resource_size (res); - priv->dmem =devm_platform_ioremap_resource_byname (pdev,"dpfe-dmem" ); + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"dpfe-dmem" ); + priv->dmem =devm_ioremap_resource (dev, res);if (IS_ERR (priv->dmem)) {dev_err (dev,"Couldn't map DCPU data memory\n" );return -ENOENT ; } + priv->dmem_size =resource_size (res); priv->imem =devm_platform_ioremap_resource_byname (pdev,"dpfe-imem" );if (IS_ERR (priv->imem)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 911/1536 memory: brcmstb_dpfe: Bounds check DCPU-supplied MSG_ARG_COUNT
In reply to Greg Kroah-Hartman6.12-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
@@ -503,6 +503,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 912/1536 wifi: rtw88: fix out-of-bounds CAM write when key table is full
In reply to Greg Kroah-Hartman6.12-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
@@ -595,7 +595,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 913/1536 wifi: rtw89: 8851b: fix swapped DPK channel/bandwidth backup fields
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yi Cong <[email protected]>
[ Upstream commit 7e080e17ca38b72f6cf01e3bc750c243573e69a7 ]
The .ch and .bw backup fields are swapped; .ch should store the channel and .bw the bandwidth, matching all other chips.
--- drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8851b_rfk.c +2 -2
@@ -1758,8 +1758,8 @@ static void _dpk_information(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy,u8 kidx = dpk->cur_idx[path]; dpk->bp[path][kidx].band = chan->band_type; - dpk->bp[path][kidx].ch = chan->band_width; - dpk->bp[path][kidx].bw = chan->channel; + dpk->bp[path][kidx].ch = chan->channel; + dpk->bp[path][kidx].bw = chan->band_width; rtw89_debug(rtwdev, RTW89_DBG_RFK, "[DPK] S%d[%d] (PHY%d): TSSI %s/ DBCC %s/ %s/ CH%d/ %s\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 914/1536 wifi: rtw89: cap firmware section_num before parsing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
[ Upstream commit 273b0a8be083df6d0319ce62caa870e927f94a31 ]
rtw89_fw_bin_info.section_info has FWDL_SECTION_MAX_NUM (10) entries. The v0/v1 header parsers take section_num from an 8-bit firmware field (0..255) and write info->section_info[i] with no cap. rtw89_fw_download_suit() keeps that object on the stack, so a crafted firmware blob overflows the stack.
Reject a truncated header and a section table that does not fit in the firmware image before reading fw_hdr->sections[i].
--- drivers/net/wireless/realtek/rtw89/fw.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/wireless/realtek/rtw89/fw.c +32 -0
@@ -146,8 +146,24 @@ static int rtw89_fw_hdr_parser_v0(struct rtw89_dev *rtwdev, const u8 *fw, u32 leif (!info)return -EINVAL ; +if (len <sizeof (*fw_hdr)) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_W6_SEC_NUM ); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + base_hdr_len =struct_size (fw_hdr, sections, info->section_num); +if (base_hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_W7_DYN_HDR );if (info->dynamic_hdr_en) {
@@ -407,9 +423,25 @@ static int rtw89_fw_hdr_parser_v1(struct rtw89_dev *rtwdev, const u8 *fw, u32 leint ret;u32 i; +if (len <sizeof (*fw_hdr)) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_SEC_NUM ); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + info->dsp_checksum =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_DSP_CHKSUM ); base_hdr_len =struct_size (fw_hdr, sections, info->section_num); +if (base_hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_V1_W7_DYN_HDR );if (info->dynamic_hdr_en) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 915/1536 clk: mstar: msc313-mpll: fix off-by-one in clock array allocation
In reply to Greg Kroah-Hartman6.12-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 916/1536 ARM: imx: Fix suspend/resume crash with Clang CFI
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yo'av Moshe <[email protected]>
[ Upstream commit 242757d109bd5c9b8fb7194fb4d44625be0b859a ]
The suspend code that runs from OCRAM is copied there with fncpy(), which does not copy the kCFI type hash preceding the function. With CONFIG_CFI=y the indirect call through imx6_suspend_in_ocram_fn therefore panics.
Keep the call covered by CFI instead of exempting it:
- Add SYM_TYPED_FUNC_START_ALIGNED(), a variant of SYM_TYPED_FUNC_START() that aligns the function entry rather than the type hash preceding it, and use it to declare imx6_suspend():
fncpy() requires the entry point of the function it copies to be 8-byte aligned. The macro lives in arch/arm/include/asm/linkage.h since the requirement comes from arm's fncpy().
- Add a cfi_type member at the end of struct imx6_cpu_pm_info, which directly precedes the OCRAM copy of the function. It fits in the struct's tail padding, so no sizes or offsets change. Fill it using cfi_get_func_hash(), putting the hash where the caller's CFI check expects it: four bytes before the function entry.
Also mark ccm_base, suspend_ocram_base and imx6_suspend_in_ocram_fn as __ro_after_init: they are only written during __init, and the function pointer in particular should not be writable afterwards.
--- arch/arm/include/asm/linkage.h | 29 +++++++++++++++++++++++++++++ arch/arm/mach-imx/pm-imx6.c | 26 +++++++++++++++++++++++--- arch/arm/mach-imx/suspend-imx6.S | 6 ++++-- 3 files changed, 56 insertions(+), 5 deletions(-)
arch/arm/include/asm/linkage.h +29 -0
@@ -9,4 +9,33 @@ .type name, %function; \ END(name) +#ifdef __ASSEMBLY__ + +/* +* Variants of SYM_TYPED_START/SYM_TYPED_FUNC_START that align the +* function entry itself instead of the kCFI type hash preceding it, +* for functions whose entry point must meet an alignment requirement, +* such as the 8-byte alignment fncpy() demands of its source. +*/ +#ifdef CONFIG_CFI + +#define SYM_TYPED_START_ALIGNED (name, linkage, align) \ + linkage(name) ASM_NL \ + .balign align ASM_NL \ + .fill (align) - 4, 1, 0 ASM_NL \ + __CFI_TYPE(name) ASM_NL \ + name: + +#else /* CONFIG_CFI */ + +#define SYM_TYPED_START_ALIGNED (name, linkage, align) \ + SYM_START(name, linkage, .balign align) + +#endif /* CONFIG_CFI */ + +#define SYM_TYPED_FUNC_START_ALIGNED (name, align) \ + SYM_TYPED_START_ALIGNED(name, SYM_L_GLOBAL, align) + +#endif /* __ASSEMBLY__ */ +#endif
arch/arm/mach-imx/pm-imx6.c +23 -3
@@ -4,6 +4,8 @@* Copyright 2011 Linaro Ltd. */ +#include <linux/build_bug.h> +#include <linux/cfi.h> #include <linux/clk/imx.h> #include <linux/delay.h> #include <linux/init.h>
@@ -18,6 +20,7 @@#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/regmap.h> +#include <linux/stddef.h> #include <linux/suspend.h> #include <asm/cacheflush.h> #include <asm/fncpy.h>
@@ -61,9 +64,9 @@#define MX6Q_SUSPEND_OCRAM_SIZE 0x1000#define MX6_MAX_MMDC_IO_NUM 33 -static void __iomem *ccm_base; -static void __iomem *suspend_ocram_base; -static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase); +static void __iomem *ccm_base__ro_after_init ; +static void __iomem *suspend_ocram_base__ro_after_init ; +static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase)__ro_after_init ;/* * suspend ocram space layout:
@@ -229,8 +232,18 @@ struct imx6_cpu_pm_info {struct imx6_pm_base l2_base;u32 mmdc_io_num;/* Number of MMDC IOs which need saved/restored. */ u32 mmdc_io_val[MX6_MAX_MMDC_IO_NUM ][2 ];/* To save offset and value */ +u32 cfi_type;/* kCFI type hash of imx6_suspend() */ }__aligned(8) ; +/* +* The ocram copy of imx6_suspend() starts right after struct imx6_cpu_pm_info, +* and the CFI check on the indirect call reads the kCFI type hash from the +* four bytes preceding the function entry, so cfi_type must occupy the last +* four bytes of the struct, i.e. fit into its tail padding. +*/ +static_assert(offsetofend(struct imx6_cpu_pm_info, cfi_type) == + sizeof(struct imx6_cpu_pm_info)); +void imx6_set_int_mem_clk_lpm (bool enable) {u32 val =readl_relaxed (ccm_base +CGPR );
@@ -568,6 +581,13 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata) mmdc_offset_array[i]); } +/* +* Mask out the Thumb bit, as cfi_get_func_hash() expects the +* function's actual start address. Returns 0 if CONFIG_CFI=n. +*/ + pm_info->cfi_type = +cfi_get_func_hash ((void *)((uintptr_t )&imx6_suspend & ~1UL )); + imx6_suspend_in_ocram_fn = fncpy( suspend_ocram_base + sizeof(*pm_info), &imx6_suspend,
arch/arm/mach-imx/suspend-imx6.S +4 -2
@@ -3,6 +3,7 @@ * Copyright 2014 Freescale Semiconductor, Inc. */ +#include <linux/cfi_types.h> #include <linux/linkage.h> #include <asm/assembler.h> #include <asm/asm-offsets.h>
@@ -148,7 +149,8 @@ .endm -ENTRY(imx6_suspend) +/* fncpy() requires an 8-byte-aligned entry; see arch/arm/include/asm/fncpy.h */ +SYM_TYPED_FUNC_START_ALIGNED(imx6_suspend, 8) ldr r1, [r0, #PM_INFO_PBASE_OFFSET] ldr r2, [r0, #PM_INFO_RESUME_ADDR_OFFSET] ldr r3, [r0, #PM_INFO_DDR_TYPE_OFFSET]
@@ -329,4 +331,4 @@ resume: resume_mmdc ret lr -ENDPROC(imx6_suspend) +SYM_FUNC_END(imx6_suspend)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 917/1536 bpf: Fix queue/stack map u32 index overflow
In reply to Greg Kroah-Hartman6.12-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
@@ -58,6 +58,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 918/1536 hte: tegra194: Initialize slice locks before registering chip
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 1329abe1bae416ab2cff89c3312d33f745d341c7 ]
Registering the HTE chip publishes its request callbacks to consumers. Initialize every slice lock before registration so a concurrent HTE request cannot use an uninitialized lock.
--- drivers/hte/hte-tegra194.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/hte/hte-tegra194.c +5 -5
@@ -787,17 +787,17 @@ static int tegra_hte_probe(struct platform_device *pdev) hte_dev->chip = gc; +for (i =0 ; i < slices; i++) { + hte_dev->sl[i].flags =0 ; +spin_lock_init (&hte_dev->sl[i].s_lock); + } + ret =devm_hte_register_chip (hte_dev->chip);if (ret) {dev_err (gc->dev,"hte chip register failed" );return ret; } -for (i =0 ; i < slices; i++) { - hte_dev->sl[i].flags =0 ; -spin_lock_init (&hte_dev->sl[i].s_lock); - } - val =HTE_TECTRL_ENABLE_ENABLE | (HTE_TECTRL_INTR_ENABLE <<HTE_TECTRL_INTR_SHIFT ) | (hte_dev->itr_thrshld <<HTE_TECTRL_OCCU_SHIFT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 919/1536 wifi: ath11k: Fix possible memory leak in ath11k_dp_srng_setup()
In reply to Greg Kroah-Hartman6.12-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
@@ -314,6 +314,7 @@ 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 ; }
@@ -325,6 +326,7 @@ int ath11k_dp_srng_setup(struct ath11k_base *ab, struct dp_srng *ring, 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 920/1536 media: i2c: ov8856: fix debug message to report actual CSI-2 lane count
In reply to Greg Kroah-Hartman6.12-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
@@ -2327,7 +2327,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 921/1536 mtd: spi-nor: sfdp: check the length of the xSPI Profile 1.0 table
In reply to Greg Kroah-Hartman6.12-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
@@ -1171,6 +1171,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
@@ -1188,6 +1189,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 922/1536 mtd: spi-nor: sfdp: check the length of the SCCR map
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 1413f38f37194673502e61cd3749e091c031370b ]
The spi_nor_parse_sccr() sizes its buffer from the table length the flash reports in the SFDP parameter header. But it then reads DWORD1 and DWORD22 without ever checking the table is that long.
So if a flash reports a length of one, the buffer is only four bytes while DWORD22 sits at byte offset 84. 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.
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.
The spi_nor_parse_sccr_mc() doesn't need the same check. It works out the number of dice from the length it allocated with, so its highest index stays inside the buffer.
--- drivers/mtd/spi-nor/sfdp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mtd/spi-nor/sfdp.c +4 -0
@@ -1262,6 +1262,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor, }#define SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE BIT(31) +#define SFDP_SCCR_DWORD_MIN 22/** * spi_nor_parse_sccr() - Parse the Status, Control and Configuration Register
@@ -1280,6 +1281,9 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,size_t len;int ret; +if (sccr_header->length <SFDP_SCCR_DWORD_MIN ) +return -EINVAL ; + len = sccr_header->length *sizeof (*dwords); dwords =kmalloc (len,GFP_KERNEL );if (!dwords)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 923/1536 mtd: spi-nor: Unprepare legacy controllers upon RWW wait interruption
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
[ Upstream commit f594a33f9721f08facd98d0a31adc14ff6da9d70 ]
All the parallel locking helpers (spi_nor_prep_and_lock(), spi_nor_prep_and_lock_pe() and spi_nor_prep_and_lock_rd()) call spi_nor_prep() then wait with a killable sleep. If the sleep gets killed, we leave the controller in its prepared state.
Call ->unprepare() in these cases.
--- drivers/mtd/spi-nor/core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mtd/spi-nor/core.c +9 -0
@@ -1292,6 +1292,9 @@ int spi_nor_prep_and_lock(struct spi_nor *nor) ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_exclusive (nor)); +if (ret) +spi_nor_unprep (nor); +return ret; }
@@ -1369,6 +1372,9 @@ static int spi_nor_prep_and_lock_pe(struct spi_nor *nor, loff_t start, size_t le ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_pe (nor, start, len)); +if (ret) +spi_nor_unprep (nor); +return ret; }
@@ -1448,6 +1454,9 @@ static int spi_nor_prep_and_lock_rd(struct spi_nor *nor, loff_t start, size_t le ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_rd (nor, start, len)); +if (ret) +spi_nor_unprep (nor); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 924/1536 fs_pin: publish pins with RCU list helpers
In reply to Greg Kroah-Hartman6.12-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 925/1536 fs: make sure to call fsnotify_inoderemove() only once when inode is dead
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 669bb5af15d41a21359d00a441490f87a88eb52a ]
Daehyeon reported a race wherein fsnotify_removeinode() can be called when inode still has a live alias. This can lead to several undesired outcomes such as crashes in fsnotify code or avoidance of inode mark notifications.
Check that inode is really "dead", meaning no nlink and no more aliases before calling fsnotify_inoderemove() for final cleanup of inode marks. Also do not allow open_by_handle() to add new aliases to a "dead" inode.
Ideally, we'd call fsnotify_inoderemove() once last inode reference is dropped to make things simpler. Alas fsnotify inode marks currently hold inode references and thus this doesn't work. Once we teach fsnotify to avoid holding inode references, these games with dead inodes can go as well.
--- fs/dcache.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
fs/dcache.c +24 -3
@@ -388,6 +388,17 @@ static void dentry_free(struct dentry *dentry)call_rcu (&dentry->d_u.d_rcu, __d_free); } +/* +* If inode is unlinked and doesn't have any aliases (i.e., all fds pointing to +* it are closed), it is pretty much dead. Except that file handle lookup could +* still revive it which causes issues to fsnotify. So once inode reaches this +* state we make sure to block creating any new aliases. +*/ +static bool inode_notify_dead (struct inode *inode) +{ +return !inode->i_nlink &&hlist_empty (&inode->i_dentry); +} +/* * Release the dentry's inode, using the filesystem * d_iput() operation if defined.
@@ -397,14 +408,16 @@ static void dentry_unlink_inode(struct dentry * dentry) __releases(dentry->d_inode->i_lock) {struct inode *inode = dentry->d_inode; +bool notify_dead;raw_write_seqcount_begin (&dentry->d_seq);__d_clear_type_and_inode (dentry);hlist_del_init (&dentry->d_u.d_alias);raw_write_seqcount_end (&dentry->d_seq); + notify_dead =inode_notify_dead (inode);spin_unlock (&dentry->d_lock);spin_unlock (&inode->i_lock); -if (!inode->i_nlink) +if (notify_dead)fsnotify_inoderemove (inode);if (dentry->d_op && dentry->d_op->d_iput) dentry->d_op->d_iput (dentry, inode);
@@ -1953,7 +1966,12 @@ static struct dentry *__d_obtain_alias(struct inode *inode, bool disconnected) sb = inode->i_sb; - res =d_find_any_alias (inode);/* existing alias? */ +spin_lock (&inode->i_lock); +if (!inode_notify_dead (inode)) + res =__d_find_any_alias (inode);/* existing alias? */ +else + res =ERR_PTR (-ESTALE ); +spin_unlock (&inode->i_lock);if (res) goto out;
@@ -1965,7 +1983,10 @@ static struct dentry *__d_obtain_alias(struct inode *inode, bool disconnected)security_d_instantiate (new, inode);spin_lock (&inode->i_lock); - res =__d_find_any_alias (inode);/* recheck under lock */ +if (!inode_notify_dead (inode)) + res =__d_find_any_alias (inode);/* recheck under lock */ +else + res =ERR_PTR (-ESTALE );if (likely (!res)) {/* still no alias, attach a disconnected dentry */ unsigned add_flags =d_flags_for_inode (inode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 926/1536 arm64: dts: ti: k3-am62-verdin: Set MMC clock pins as OUTPUT
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Dolcini <[email protected]>
[ Upstream commit 0ddd661c19ec1465e1f2c204fa9b2488acfabf4b ]
MMC clock pins must be configured as OUTPUT-only per TRM [0] with receiver disabled (RXACTIVE bit = 0). Change MMC CLK pins from PIN_INPUT to PIN_OUTPUT to match documentation.
--- arch/arm64/boot/dts/ti/k3-am62-verdin.dtsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/ti/k3-am62-verdin.dtsi +3 -3
@@ -567,7 +567,7 @@ AM62X_IOPAD(0x15c, PIN_INPUT, 0) /* (AB22) MDIO0_MDIO */ /* ETH_1_MDIO, SODIMM pinctrl_sdhci0: main-mmc0-default-pins { pinctrl-single,pins = < AM62X_IOPAD(0x220, PIN_INPUT, 0) /* (Y3) MMC0_CMD */ - AM62X_IOPAD(0x218, PIN_INPUT, 0) /* (AB1) MMC0_CLK */ + AM62X_IOPAD(0x218, PIN_OUTPUT, 0) /* (AB1) MMC0_CLK */ AM62X_IOPAD(0x214, PIN_INPUT, 0) /* (AA2) MMC0_DAT0 */ AM62X_IOPAD(0x210, PIN_INPUT_PULLUP, 0) /* (AA1) MMC0_DAT1 */ AM62X_IOPAD(0x20c, PIN_INPUT_PULLUP, 0) /* (AA3) MMC0_DAT2 */
@@ -583,7 +583,7 @@ AM62X_IOPAD(0x1f8, PIN_INPUT_PULLUP, 0) /* (AC2) MMC0_DAT7 */ pinctrl_sdhci1: main-mmc1-default-pins { pinctrl-single,pins = < AM62X_IOPAD(0x23c, PIN_INPUT, 0) /* (A21) MMC1_CMD */ /* SODIMM 74 */ - AM62X_IOPAD(0x234, PIN_INPUT, 0) /* (B22) MMC1_CLK */ /* SODIMM 78 */ + AM62X_IOPAD(0x234, PIN_OUTPUT, 0) /* (B22) MMC1_CLK */ /* SODIMM 78 */ AM62X_IOPAD(0x230, PIN_INPUT, 0) /* (A22) MMC1_DAT0 */ /* SODIMM 80 */ AM62X_IOPAD(0x22c, PIN_INPUT, 0) /* (B21) MMC1_DAT1 */ /* SODIMM 82 */ AM62X_IOPAD(0x228, PIN_INPUT, 0) /* (C21) MMC1_DAT2 */ /* SODIMM 70 */
@@ -595,7 +595,7 @@ AM62X_IOPAD(0x224, PIN_INPUT, 0) /* (D22) MMC1_DAT3 */ /* SODIMM 72 */ pinctrl_sdhci2: main-mmc2-default-pins { pinctrl-single,pins = < AM62X_IOPAD(0x120, PIN_INPUT, 0) /* (C24) MMC2_CMD */ /* WiFi_SDIO_CMD */ - AM62X_IOPAD(0x118, PIN_INPUT, 0) /* (D25) MMC2_CLK */ /* WiFi_SDIO_CLK */ + AM62X_IOPAD(0x118, PIN_OUTPUT,0) /* (D25) MMC2_CLK */ /* WiFi_SDIO_CLK */ AM62X_IOPAD(0x114, PIN_INPUT, 0) /* (B24) MMC2_DAT0 */ /* WiFi_SDIO_DATA0 */ AM62X_IOPAD(0x110, PIN_INPUT, 0) /* (C25) MMC2_DAT1 */ /* WiFi_SDIO_DATA1 */ AM62X_IOPAD(0x10c, PIN_INPUT, 0) /* (E23) MMC2_DAT2 */ /* WiFi_SDIO_DATA2 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 927/1536 thermal: intel: powerclamp: Reject invalid window_size values
In reply to Greg Kroah-Hartman6.12-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
@@ -290,9 +290,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 928/1536 thermal: intel: int340x: Fix temperature selection around 0 C
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit e56e2b49c67d132728e52ce493079e83cc914657 ]
Since commit 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to support negative CPU temperature"), intel_tcc_get_temp() can report negative temperatures.
proc_thermal_get_zone_temp() still uses *temp as the current maximum and as an implicit "no reading yet" marker. However, this breaks when a CPU reports 0 C, because a subsequent negative reading can overwrite it.
Use bool temp_valid to track whether a valid temperature has been read. Initialize *temp with the first valid reading and only update it with warmer readings.
--- .../intel/int340x_thermal/processor_thermal_device.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +7 -3
@@ -177,17 +177,21 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone, {int cpu;int curr_temp, ret; - - *temp =0 ; +bool temp_valid = false;for_each_online_cpu (cpu) { ret =intel_tcc_get_temp (cpu, &curr_temp, false);if (ret <0 )return ret; -if (!*temp || curr_temp > *temp) +if (!temp_valid || curr_temp > *temp) { *temp = curr_temp; + temp_valid = true; + } } +if (!temp_valid) +return -ENODATA ; + *temp *=1000 ;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 929/1536 isofs: fix Rock Ridge CE extent validation on multisession media
In reply to Greg Kroah-Hartman6.12-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
@@ -821,6 +821,8 @@ static int isofs_fill_super(struct super_block *s, struct fs_context *fc)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 930/1536 arm64: dts: mediatek: mt7986: correct timer frequency
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Pesaresi <[email protected]>
[ Upstream commit 1cf18e4b9815beaf0439c5b57b65b45151c82ad7 ]
The MT7986 architected timer runs at 12,986,200 Hz rather than 13 MHz. Firmware reports 13 MHz through CNTFRQ_EL0, causing the system clock to run slow by about 1062 ppm. This exceeds the kernel's 500 ppm NTP correction limit and leaves clock discipline saturated.
The corrected rate comes from MediaTek's downstream OpenWrt feed, where it is applied to both MT7986A and MT7986B. Since upstream mt7986b.dtsi includes mt7986a.dtsi, add it once to the common timer node so the architected timer driver uses the actual counter rate.
--- arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/mediatek/mt7986a.dtsi +1 -0
@@ -637,6 +637,7 @@ cpu_trip_active_low: active-low { timer { compatible = "arm,armv8-timer"; interrupt-parent = <&gic>; + clock-frequency = <12986200>; interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 11 IRQ_TYPE_LEVEL_LOW>,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 931/1536 media: cx231xx-audio: drain wq_trigger before audio fini
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit a691c54986412e1fa87f036d2577d5a78a75e658 ]
audio_trigger() is deferred work (dev->wq_trigger) armed from snd_cx231xx_capture_trigger() on every PCM START/STOP; it dereferences dev->adev state and may free the URBs via cx231xx_isoc_audio_deinit(). cx231xx_audio_fini() tore down that state without draining wq_trigger, so work armed before or racing fini ran against freed state.
Use disable_work_sync() in fini to drain the work and prevent further queueing. Initialize the work, lock and stream_started counter at the top of cx231xx_audio_init(), before any fallible allocation, and clear the partially-built audio state on its error path, so fini is safe even if a later step fails.
This issue was found by an in-house static analysis tool.
--- drivers/media/usb/cx231xx/cx231xx-audio.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/media/usb/cx231xx/cx231xx-audio.c +12 -3
@@ -576,12 +576,19 @@ static int cx231xx_audio_init(struct cx231xx *dev)dev_dbg (dev->dev,"probing for cx231xx non standard usbaudio\n" ); +/* +* Extension init errors are ignored by the cx231xx core, so fini() +* must be safe even if initialization fails part way through. +*/ +spin_lock_init (&adev->slock); +INIT_WORK (&dev->wq_trigger, audio_trigger); +atomic_set (&dev->stream_started,0 ); + err =snd_card_new (dev->dev, index[devnr],"Cx231xx Audio" ,THIS_MODULE ,0 , &card);if (err <0 )return err; -spin_lock_init (&adev->slock); err =snd_pcm_new (card,"Cx231xx Audio" ,0 ,0 ,1 , &pcm);if (err <0 ) goto err_free_card;
@@ -596,8 +603,6 @@ static int cx231xx_audio_init(struct cx231xx *dev)strscpy (card->shortname,"Cx231xx Audio" ,sizeof (card->shortname));strscpy (card->longname,"Conexant cx231xx Audio" ,sizeof (card->longname)); -INIT_WORK (&dev->wq_trigger, audio_trigger); - err =snd_card_register (card);if (err <0 ) goto err_free_card;
@@ -651,8 +656,10 @@ static int cx231xx_audio_init(struct cx231xx *dev) err_free_pkt_size:kfree (adev->alt_max_pkt_size); + adev->alt_max_pkt_size =NULL ; err_free_card:snd_card_free (card); + adev->sndcard =NULL ;return err; }
@@ -669,6 +676,8 @@ static int cx231xx_audio_fini(struct cx231xx *dev)return 0 ; } +disable_work_sync (&dev->wq_trigger); +if (dev->adev.sndcard) {snd_card_free_when_closed (dev->adev.sndcard);kfree (dev->adev.alt_max_pkt_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 932/1536 media: cx231xx: Fix cleanup path on failure
In reply to Greg Kroah-Hartman6.12-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 933/1536 firewire: core: fix source bus ID detection for AT context in big-endian systems
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Sakamoto <[email protected]>
[ Upstream commit 6393d75914a6ac95a05621db8d9d6a98eafe72f7 ]
The source bus ID bit in AT DMA context is not detected correctly on big-endian systems because the little-endian data is not converted to CPU endianness.
Fix the bug. The helper functions related to this are never used in driver code, so extend the test to check the field instead.
--- drivers/firewire/ohci-serdes-test.c | 4 ++-- drivers/firewire/ohci.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/firewire/ohci-serdes-test.c +2 -2
@@ -43,7 +43,7 @@ static void test_self_id_receive_buffer_deserialization(struct kunit *test)static void test_at_data_serdes (struct kunit *test) {static const __le32 expected[] = { -cpu_to_le32 (0x00020e80 ), +cpu_to_le32 (0x00820e80 ),cpu_to_le32 (0xffc2ffff ),cpu_to_le32 (0xe0000000 ), };
@@ -56,7 +56,7 @@ static void test_at_data_serdes(struct kunit *test)unsigned int destination_id =ohci1394_at_data_get_destination_id (expected);u64 destination_offset =ohci1394_at_data_get_destination_offset (expected); -KUNIT_EXPECT_FALSE (test, has_src_bus_id); +KUNIT_EXPECT_TRUE (test, has_src_bus_id);KUNIT_EXPECT_EQ (test,0x02 , speed);KUNIT_EXPECT_EQ (test,0x03 , tlabel);KUNIT_EXPECT_EQ (test,0x02 , retry);
drivers/firewire/ohci.h +1 -1
@@ -178,7 +178,7 @@static inline bool ohci1394_at_data_get_src_bus_id (const __le32 *data) { -return !!((data[0 ] & OHCI1394_AT_DATA_Q0_srcBusID_MASK) >> OHCI1394_AT_DATA_Q0_srcBusID_SHIFT); +return !!((le32_to_cpu (data[0 ]) & OHCI1394_AT_DATA_Q0_srcBusID_MASK) >> OHCI1394_AT_DATA_Q0_srcBusID_SHIFT); }static inline void ohci1394_at_data_set_src_bus_id (__le32 *data,bool src_bus_id)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 934/1536 media: au0828: Free URBs when starting DVB streaming fails
In reply to Greg Kroah-Hartman6.12-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 935/1536 media: i2c: tc358743: add missing color-space strings
In reply to Greg Kroah-Hartman6.12-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
@@ -1266,7 +1266,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 936/1536 media: go7007: bound EZ-USB I2C transfers to the usb_buf size
In reply to Greg Kroah-Hartman6.12-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 937/1536 media: saa7146: Initialize interrupt lock before requesting IRQ
In reply to Greg Kroah-Hartman6.12-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
@@ -340,6 +340,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);
@@ -425,7 +427,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 938/1536 media: vim2m: keep transaction buffer count stable while streaming
In reply to Greg Kroah-Hartman6.12-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
@@ -200,6 +200,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;
@@ -1063,9 +1064,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);
@@ -1079,11 +1098,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)
@@ -1186,7 +1208,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);
@@ -1240,10 +1263,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 939/1536 media: vicodec: fix out-of-bounds write on under-rounded coded dimensions
In reply to Greg Kroah-Hartman6.12-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 940/1536 media: vicodec: make encoder CAPTURE dimensions read-only
In reply to Greg Kroah-Hartman6.12-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
@@ -891,6 +891,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;
@@ -901,6 +903,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;
@@ -912,6 +918,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 941/1536 media: vidtv: fix frontend reference leak on unbind
In reply to Greg Kroah-Hartman6.12-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 void 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 942/1536 media: vidtv: fix uaf in vidtv_bridge_on_new_pkts_avail
In reply to Greg Kroah-Hartman6.12-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 void 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 943/1536 media: marvell-cam: fix unmet dependency for VIDEO_MMP_CAMERA
In reply to Greg Kroah-Hartman6.12-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/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/marvell/Kconfig +1 -0
@@ -22,6 +22,7 @@ config VIDEO_MMP_CAMERA depends on V4L_PLATFORM_DRIVERS depends on I2C && VIDEO_DEV depends on ARCH_MMP || COMPILE_TEST + depends on GPIOLIB || COMPILE_TEST depends on COMMON_CLK select VIDEO_OV7670 if MEDIA_SUBDRV_AUTOSELECT && VIDEO_CAMERA_SENSOR select I2C_GPIO
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 944/1536 staging: media: av7110: fix corrupted BER reporting in sp8870
In reply to Greg Kroah-Hartman6.12-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
@@ -401,7 +401,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 945/1536 staging: media: av7110: fix sp8870 initialization failure state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Punnay Sharma <[email protected]>
[ Upstream commit 30684fa98394bc0eb4362282908612aab7d4dad9 ]
The SP8870 DVB frontend driver prematurely flags the device as initialized at the very beginning of the sp8870_init() routine, prior to requesting the firmware (dvb-fe-sp8870.fw) and executing the I2C upload sequence.
If request_firmware() times out or sp8870_firmware_upload() encounters an I2C bus error, the function aborts and returns -EIO. However, because state->initialised is already set to 1, all subsequent invocations of fe->ops.init() by the DVB core will immediately return 0 (success) without attempting to load the firmware again. This leaves the demodulator microcontroller halted and the frontend permanently dead until the module is forcibly reloaded.
Relocate the state->initialised = 1 assignment to the end of sp8870_init(), ensuring the flag is only set after the firmware is successfully uploaded and the system controller is actually restarted.
--- drivers/staging/media/av7110/sp8870.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/media/av7110/sp8870.c +2 -1
@@ -315,7 +315,6 @@ static int sp8870_init(struct dvb_frontend *fe)sp8870_wake_up (state);if (state->initialised)return 0 ; - state->initialised =1 ;dprintk ("initialising frontend...\n" );
@@ -353,6 +352,8 @@ static int sp8870_init(struct dvb_frontend *fe)sp8870_writereg (state,0x0D00 ,0x010 );sp8870_writereg (state,0x0D01 ,0x000 ); + state->initialised =1 ; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 946/1536 media: m2m-deinterlace: fix default capture field
In reply to Greg Kroah-Hartman6.12-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
@@ -826,7 +826,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 947/1536 ASoC: codecs: lpass-wsa-macro: use v2.5 Compander1 addresses on v2.5+
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit 233d36a96009682208cc4ca1139b9e5641a8bf09 ]
wsa_macro_set_spkr_mode() unconditionally writes CDC_WSA_COMPANDER1_CTL3 (0x5CC) and CDC_WSA_COMPANDER1_CTL7 (0x5DC). On v2.5+ silicon these registers moved to CDC_2_5_WSA_COMPANDER1_CTL3 (0x5EC) and CDC_2_5_WSA_COMPANDER1_CTL7 (0x5FC); the v2.1 addresses are dead on that hardware, so the update_bits() calls take a bus error:
wsa_macro 6c90000.codec: ASoC error (-5): at
snd_soc_component_update_bits() on 6c90000.codec for
register: [0x000005dc]
The flat regcache had been hiding the read side of this by returning the zero-initialised cache slot instead of doing a bus read, so the error only becomes visible once the cache reports the miss honestly and regmap falls back to a real bus read.
Select the correct address for Compander1 CTL3/CTL7 based on codec_version. The Compander0 and Boost registers used in the same function have the same address across versions, so they stay unchanged. Also collapse the two mode branches to a single sequence with mode-selected values, which is what the switch was doing anyway.
--- sound/soc/codecs/lpass-wsa-macro.c | 42 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-)
sound/soc/codecs/lpass-wsa-macro.c +25 -17
@@ -1128,27 +1128,35 @@ static const struct regmap_config wsa_regmap_config = {int wsa_macro_set_spkr_mode (struct snd_soc_component *component,int mode) {struct wsa_macro *wsa =snd_soc_component_get_drvdata (component); +unsigned int comp1_ctl3, comp1_ctl7; +u8 comp_val, boost_val; wsa->spkr_mode = mode; -switch (mode) { -case WSA_MACRO_SPKR_MODE_1 : -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER0_CTL3 ,0x80 ,0x00 ); -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER1_CTL3 ,0x80 ,0x00 ); -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER0_CTL7 ,0x01 ,0x00 ); -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER1_CTL7 ,0x01 ,0x00 ); -snd_soc_component_update_bits (component,CDC_WSA_BOOST0_BOOST_CTL ,0x7C ,0x44 ); -snd_soc_component_update_bits (component,CDC_WSA_BOOST1_BOOST_CTL ,0x7C ,0x44 ); -break ; -default : -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER0_CTL3 ,0x80 ,0x80 ); -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER1_CTL3 ,0x80 ,0x80 ); -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER0_CTL7 ,0x01 ,0x01 ); -snd_soc_component_update_bits (component,CDC_WSA_COMPANDER1_CTL7 ,0x01 ,0x01 ); -snd_soc_component_update_bits (component,CDC_WSA_BOOST0_BOOST_CTL ,0x7C ,0x58 ); -snd_soc_component_update_bits (component,CDC_WSA_BOOST1_BOOST_CTL ,0x7C ,0x58 ); -break ; +/* Compander1 CTL3/CTL7 moved on v2.5+ silicon. */ +if (wsa->codec_version >=LPASS_CODEC_VERSION_2_5 ) { + comp1_ctl3 =CDC_2_5_WSA_COMPANDER1_CTL3 ; + comp1_ctl7 =CDC_2_5_WSA_COMPANDER1_CTL7 ; + }else { + comp1_ctl3 =CDC_WSA_COMPANDER1_CTL3 ; + comp1_ctl7 =CDC_WSA_COMPANDER1_CTL7 ; } + +if (mode ==WSA_MACRO_SPKR_MODE_1 ) { + comp_val =0x00 ; + boost_val =0x44 ; + }else { + comp_val =0x80 ; + boost_val =0x58 ; + } + +snd_soc_component_update_bits (component,CDC_WSA_COMPANDER0_CTL3 ,0x80 , comp_val); +snd_soc_component_update_bits (component, comp1_ctl3,0x80 , comp_val); +snd_soc_component_update_bits (component,CDC_WSA_COMPANDER0_CTL7 ,0x01 , comp_val ?0x01 :0x00 ); +snd_soc_component_update_bits (component, comp1_ctl7,0x01 , comp_val ?0x01 :0x00 ); +snd_soc_component_update_bits (component,CDC_WSA_BOOST0_BOOST_CTL ,0x7C , boost_val); +snd_soc_component_update_bits (component,CDC_WSA_BOOST1_BOOST_CTL ,0x7C , boost_val); +return 0 ; }EXPORT_SYMBOL (wsa_macro_set_spkr_mode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 948/1536 media: microchip-isc: fix awb_mutex and lock lifecycle
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 5540b48c0702f6a1389db3d473d7fd0db930422a ]
isc->lock and awb_mutex were initialised in isc_async_complete() and destroyed in isc_async_unbind(), tying their lifetime to the subdev bind/unbind cycle instead of the device:
- isc_async_unbind() destroyed awb_mutex before cancel_work_sync(), which takes it;
- a failed .complete() left them initialised, and isc->lock was destroyed only on the .complete() error path, so the normal unbind path leaked it;
- a rebind runs .complete() again and reinitialises a live mutex.
Initialise both with devm_mutex_init() at probe so they live for the whole device lifetime and are freed at remove, and drop the init and destroy from the .complete()/.unbind() callbacks.
isc_async_complete_err then only returned ret, so drop the label and return directly at each error site.
--- .../media/platform/microchip/microchip-isc-base.c | 15 ++++----------- .../platform/microchip/microchip-sama5d2-isc.c | 9 +++++++++ .../platform/microchip/microchip-sama7g5-isc.c | 9 +++++++++ 3 files changed, 22 insertions(+), 11 deletions(-)
drivers/media/platform/microchip/microchip-isc-base.c +4 -11
@@ -1705,7 +1705,6 @@ static void isc_async_unbind(struct v4l2_async_notifier *notifier, {struct isc_device *isc =container_of (notifier->v4l2_dev, struct isc_device, v4l2_dev); -mutex_destroy (&isc->awb_mutex);cancel_work_sync (&isc->awb_work);video_unregister_device (&isc->video_dev);v4l2_ctrl_handler_free (&isc->ctrls.handler);
@@ -1769,8 +1768,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc->current_subdev =container_of (notifier, struct isc_subdev_entity, notifier); -mutex_init (&isc->lock); -mutex_init (&isc->awb_mutex);init_completion (&isc->comp);
@@ -1789,7 +1786,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) ret =vb2_queue_init (q);if (ret <0 ) {dev_err (isc->dev,"vb2_queue_init() failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; }/* Init video dma queues */
@@ -1800,13 +1797,13 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) ret =isc_set_default_fmt (isc);if (ret) {dev_err (isc->dev,"Could not set default format\n" ); - goto isc_async_complete_err; +return ret; } ret =isc_ctrl_init (isc);if (ret) {dev_err (isc->dev,"Init isc ctrols failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; }/* Register video device */
@@ -1826,7 +1823,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) ret =video_register_device (vdev,VFL_TYPE_VIDEO ,-1 );if (ret <0 ) {dev_err (isc->dev,"video_register_device failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; } ret =isc_scaler_link (isc);
@@ -1841,10 +1838,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc_async_complete_unregister_device:video_unregister_device (vdev); - -isc_async_complete_err: -mutex_destroy (&isc->awb_mutex); -mutex_destroy (&isc->lock);return ret; }
drivers/media/platform/microchip/microchip-sama5d2-isc.c +9 -0
@@ -30,6 +30,7 @@#include <linux/interrupt.h> #include <linux/math64.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_graph.h> #include <linux/platform_device.h>
@@ -424,6 +425,14 @@ static int microchip_isc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, isc); isc->dev = dev; + ret =devm_mutex_init (dev, &isc->lock); +if (ret) +return ret; + + ret =devm_mutex_init (dev, &isc->awb_mutex); +if (ret) +return ret; + io_base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (io_base))return PTR_ERR (io_base);
drivers/media/platform/microchip/microchip-sama7g5-isc.c +9 -0
@@ -33,6 +33,7 @@#include <linux/interrupt.h> #include <linux/math64.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_graph.h> #include <linux/platform_device.h>
@@ -413,6 +414,14 @@ static int microchip_xisc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, isc); isc->dev = dev; + ret =devm_mutex_init (dev, &isc->lock); +if (ret) +return ret; + + ret =devm_mutex_init (dev, &isc->awb_mutex); +if (ret) +return ret; + io_base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (io_base))return PTR_ERR (io_base);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 949/1536 media: microchip-isc: synchronize the IRQ before disabling clocks on stop
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 19fa5407da5ef3e605cacfcd90f70d8b2c121cd7 ]
isc_stop_streaming() masks the DMA interrupt and then drops the runtime PM reference, which disables the ISC clocks. microchip_isc_interrupt() may still be executing on another CPU at that point; it reads ISC_INTSR over regmap, and touching the unclocked registers triggers an external abort.
Store the IRQ number at probe and call synchronize_irq() after masking the interrupt, before dropping the PM reference.
--- drivers/media/platform/microchip/microchip-isc-base.c | 3 +++ drivers/media/platform/microchip/microchip-isc.h | 1 + drivers/media/platform/microchip/microchip-sama5d2-isc.c | 2 ++ drivers/media/platform/microchip/microchip-sama7g5-isc.c | 2 ++ 4 files changed, 8 insertions(+)
drivers/media/platform/microchip/microchip-isc-base.c +3 -0
@@ -425,6 +425,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)/* Disable DMA interrupt */ regmap_write (isc->regmap,ISC_INTDIS ,ISC_INT_DDONE ); +/* let a running IRQ handler finish before the clock is disabled */ +synchronize_irq (isc->irq); +pm_runtime_put_sync (isc->dev);/* Disable stream on the sub device */
drivers/media/platform/microchip/microchip-isc.h +1 -0
@@ -287,6 +287,7 @@ struct isc_device {u32 dcfg;struct device *dev; +int irq;struct v4l2_device v4l2_dev;struct video_device video_dev;
drivers/media/platform/microchip/microchip-sama5d2-isc.c +2 -0
@@ -448,6 +448,8 @@ static int microchip_isc_probe(struct platform_device *pdev)if (irq <0 )return irq; + isc->irq = irq; + ret =devm_request_irq (dev, irq, microchip_isc_interrupt,0 ,"microchip-sama5d2-isc" , isc);if (ret <0 ) {
drivers/media/platform/microchip/microchip-sama7g5-isc.c +2 -0
@@ -437,6 +437,8 @@ static int microchip_xisc_probe(struct platform_device *pdev)if (irq <0 )return irq; + isc->irq = irq; + ret =devm_request_irq (dev, irq, microchip_isc_interrupt,0 ,"microchip-sama7g5-xisc" , isc);if (ret <0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 950/1536 media: microchip-isc: disable histogram and flush AWB work on teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 00d87c379915a3689b2488bd37f490875d79e20f ]
isc_stop_streaming() and the isc_start_streaming() error path dropped the runtime PM reference with the histogram still enabled. A HISDONE firing just before the stop, or a failed isc_update_profile() on the start path, can queue isc_awb_work(), which reads the histogram registers before taking its own PM reference and faults on the unclocked device.
Disable the histogram, synchronize the IRQ and flush the work before the device is left unclocked. isc_configure() is the one enabling the histogram and then calling isc_update_profile(), so do the cleanup in its own failure path; isc_stop_streaming() does the same on teardown. synchronize_irq() must come before cancel_work_sync(), so an in-flight handler cannot re-queue awb_work after it is cancelled.
--- .../media/platform/microchip/microchip-isc-base.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/media/platform/microchip/microchip-isc-base.c +14 -1
@@ -289,6 +289,7 @@ static int isc_configure(struct isc_device *isc)struct regmap *regmap = isc->regmap;u32 pfe_cfg0, dcfg, mask, pipeline;struct isc_subdev_entity *subdev = isc->current_subdev; +int ret; pfe_cfg0 = isc->config.sd_format->pfe_cfg0_bps; pipeline = isc->config.bits_pipeline;
@@ -321,7 +322,15 @@ static int isc_configure(struct isc_device *isc)isc_set_histogram (isc, false);/* Update profile */ -return isc_update_profile (isc); + ret =isc_update_profile (isc); +if (ret) { +/* flush the histogram work before the clocks are gated */ +isc_set_histogram (isc, false); +synchronize_irq (isc->irq); +cancel_work_sync (&isc->awb_work); + } + +return ret; }static int isc_prepare_streaming (struct vb2_queue *vq)
@@ -425,9 +434,13 @@ static void isc_stop_streaming(struct vb2_queue *vq)/* Disable DMA interrupt */ regmap_write (isc->regmap,ISC_INTDIS ,ISC_INT_DDONE ); +isc_set_histogram (isc, false); +/* let a running IRQ handler finish before the clock is disabled */ synchronize_irq (isc->irq); +cancel_work_sync (&isc->awb_work); +pm_runtime_put_sync (isc->dev);/* Disable stream on the sub device */
Signature · 1 line
2.53.0