6.1.189-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 765/982 wifi: wilc1000: fix RX buffer OOB-write in wilc_wlan_handle_isr_ext()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit c1ba7f7f18465e259cf1b4d9c73fc73853d7f790 upstream.
wilc_wlan_handle_isr_ext() takes the RX transfer size from the device-reported interrupt status register (a 15-bit field shifted left by 2, up to 131068 bytes) and reads that many bytes from the device into rx_buffer, which is only WILC_RX_BUFF_SIZE (96K) large. The wrap check only handles the current offset; the size itself is never compared against the buffer, so a bogus SDIO device can make the driver OOB-write rx_buffer by up to ~32K with data it controls.
The oversized transfer also leaves rx_buffer_offset past the end of the buffer, after which the unsigned wrap check stops working and the overflow can repeat.
Drop any transfer whose size exceeds the RX buffer, acknowledging the data interrupt and re-arming the RX engine so the bogus frame is discarded and reception can continue. This also restores the rx_buffer_offset <= WILC_RX_BUFF_SIZE invariant the wrap check relies on.
This is not expected to change driver behavior in most cases:
without this check, an oversized transfer would most likely corrupt neighboring kernel memory instead of completing anyway, and the drop path performs the same interrupt acknowledgment and RX engine re-arming as the normal path, so subsequent transfers are received unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/microchip/wilc1000/wlan.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/microchip/wilc1000/wlan.c +9 -0
@@ -1040,6 +1040,15 @@ static void wilc_wlan_handle_isr_ext(strif (size <=0 )return ; +/* A size exceeding the RX buffer is bogus; drop the transfer +* instead of overflowing the buffer. +*/ +if (size >WILC_RX_BUFF_SIZE ) { + wilc->hif_func->hif_clear_int_ext (wilc, +DATA_INT_CLR |ENABLE_RX_VMM ); +return ; + } +if (WILC_RX_BUFF_SIZE - offset < size) offset =0 ;
Greg Kroah-Hartman
maintainerPATCH 766/982 wifi: p54: validate curve data length in the calibration curve converters
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit ce858fa6b8a214dee5adb82358885fa024cdd887 upstream.
p54_convert_rev0() and p54_convert_rev1() read calibration curve data from the device-supplied EEPROM entry using channel and points-per-channel counts taken verbatim from that same entry, so an entry that declares more data than it carries drives an out-of-bounds read past the EEPROM buffer (verified with a KASAN reproducer of the conversion loop). The sibling converters p54_convert_output_limits() and p54_convert_db() already validate their counts against the entry length; this path was missed.
Reject the entry when the counts do not fit in the entry data.
--- drivers/net/wireless/intersil/p54/eeprom.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/wireless/intersil/p54/eeprom.c +15 -4
@@ -418,17 +418,22 @@ free: }static int p54_convert_rev0 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev0 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +2 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kmalloc (sizeof (*priv->curve_data) + cd_len,GFP_KERNEL );if (!priv->curve_data)
@@ -470,17 +475,22 @@ static int p54_convert_rev0(struct ieee8 }static int p54_convert_rev1 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev1 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +3 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kzalloc (cd_len +sizeof (*priv->curve_data),GFP_KERNEL );if (!priv->curve_data)
@@ -767,6 +777,7 @@ int p54_parse_eeprom(struct ieee80211_hwcase PDR_PRISM_PA_CAL_CURVE_DATA : {struct pda_pa_curve_data *curve_data = (struct pda_pa_curve_data *)entry->data; +if (data_len <sizeof (*curve_data)) { err = -EINVAL ; goto err;
@@ -774,10 +785,10 @@ int p54_parse_eeprom(struct ieee80211_hwswitch (curve_data->cal_method_rev) {case 0 : - err =p54_convert_rev0 (dev, curve_data); + err =p54_convert_rev0 (dev, curve_data, data_len);break ;case 1 : - err =p54_convert_rev1 (dev, curve_data); + err =p54_convert_rev1 (dev, curve_data, data_len);break ;default : wiphy_err(dev->wiphy,
Greg Kroah-Hartman
maintainerPATCH 767/982 wifi: p54: require a full exp_if record in PDR_INTERFACE_LIST
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit d8efd84f49379ed28624098821f80e992657d935 upstream.
The PDR_INTERFACE_LIST loop only checks that the record start is within the entry before reading an entire struct exp_if from it. A truncated trailing record makes the if_id/variant reads cross the entry boundary into the heap beyond the EEPROM buffer (verified with a KASAN reproducer of the loop). The variant also feeds the synth front-end selection, so this is not only a leak.
Advance only while a full record still fits in the entry.
--- drivers/net/wireless/intersil/p54/eeprom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/intersil/p54/eeprom.c +2 -1
@@ -816,7 +816,8 @@ int p54_parse_eeprom(struct ieee80211_hwbreak ;case PDR_INTERFACE_LIST : tmp = entry->data; -while ((u8 *)tmp < entry->data + data_len) { +while ((u8 *)tmp +sizeof (struct exp_if ) <= + entry->data + data_len) {struct exp_if *exp_if = tmp;if (exp_if->if_id ==cpu_to_le16 (IF_ID_ISL39000 )) synth =le16_to_cpu (exp_if->variant);
Greg Kroah-Hartman
maintainerPATCH 768/982 wifi: mwifiex: bound the pairwise-cipher OUI walk to the IE length
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit e667aee1c192d67d27c803007bfa9c6e0873e959 upstream.
mwifiex_search_oui_in_ie() reads a pairwise-cipher (PTK) count from a beacon/probe-response RSN or WPA information element and then walks that many 4-byte OUIs, comparing each with memcmp(). The count comes straight from the (attacker-supplied) IE and is never checked against the element's own length, and the callers admit the element on element_id alone (has_ieee_hdr() / has_vendor_hdr(), no length check). A crafted RSN/WPA IE with a large pairwise count therefore makes the walk read up to 255 * 4 bytes past the element -- an out-of-bounds read of the kmemdup()'d beacon buffer, reachable from any AP whose beacon/probe response is processed during scan-result parsing.
Pass the number of IE bytes available at the OUI list and bound the walk to the element. Keep the length signed and reject a negative value before any unsigned arithmetic, so a small or zero IE length cannot underflow to a large size_t and defeat the bound.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/wireless/marvell/mwifiex/scan.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +22 -3
@@ -104,12 +104,24 @@ has_vendor_hdr(struct ieee_types_vendor_* a given oui in PTK. */ static u8 -mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui) +mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui,int ie_len) { +const size_t ptk_body_offset = offsetof(struct ie_body , ptk_body);u8 count; +/* ie_len is the number of bytes available at iebody. Keep it signed +* and reject a negative (underflowed) length before the unsigned +* comparisons below, so a small or zero IE length cannot wrap. +*/ +if (ie_len <0 || (size_t )ie_len < ptk_body_offset) +return MWIFIEX_OUI_NOT_PRESENT ; + count = iebody->ptk_cnt[0 ]; +/* Reject an OUI count whose list would run past the element. */ +if (ptk_body_offset + count *sizeof (iebody->ptk_body) > (size_t )ie_len) +return MWIFIEX_OUI_NOT_PRESENT ; +/* There could be multiple OUIs for PTK hence 1) Take the length. 2) Check all the OUIs for AES.
@@ -143,11 +155,14 @@ mwifiex_is_rsn_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_ieee_hdr (bss_desc->bcn_rsn_ie,WLAN_EID_RSN )) { +int ie_len = (int )bss_desc->bcn_rsn_ie->ieee_hdr.len - +RSN_GTK_OUI_OFFSET ; + iebody = (struct ie_body *) (((u8 *) bss_desc->bcn_rsn_ie->data) +RSN_GTK_OUI_OFFSET ); oui = &mwifiex_rsn_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
@@ -169,10 +184,14 @@ mwifiex_is_wpa_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_vendor_hdr (bss_desc->bcn_wpa_ie,WLAN_EID_VENDOR_SPECIFIC )) { +int ie_len = (int )bss_desc->bcn_wpa_ie->vend_hdr.len - + (int )sizeof (bss_desc->bcn_wpa_ie->vend_hdr.oui) - +WPA_GTK_OUI_OFFSET ; + iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data +WPA_GTK_OUI_OFFSET ); oui = &mwifiex_wpa_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
Greg Kroah-Hartman
maintainerPATCH 769/982 wifi: mwifiex: validate scan response extents
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit 3687d7d48070838cc2953431b3a27717cab0aaf6 upstream.
mwifiex_ret_802_11_scan() subtracts the fixed response fields and the firmware-provided BSS length from resp->size without first proving that either extent fits. A short response or oversized BSS length can therefore underflow tlv_buf_size and make the TLV parser walk beyond the command response.
Compute the fixed extent from the selected normal or background scan response. Validate that the fixed fields and BSS data fit before deriving the TLV extent and entering the parser.
--- drivers/net/wireless/marvell/mwifiex/scan.c | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +19 -10
@@ -2130,6 +2130,7 @@ int mwifiex_ret_802_11_scan(struct mwifiu32 bytes_left;u32 idx;u32 tlv_buf_size; +size_t fixed_size;struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;struct chan_band_param_set *chan_band;u8 is_bgscan_resp;
@@ -2145,6 +2146,14 @@ int mwifiex_ret_802_11_scan(struct mwifielse scan_rsp = &resp->params.scan_resp; + scan_resp_size =le16_to_cpu (resp->size); + fixed_size = scan_rsp->bss_desc_and_tlv_buffer - (u8 *)resp; +if (scan_resp_size < fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: response is too short\n" ); + ret =-1 ; + goto check_next_scan; + }if (scan_rsp->number_of_sets >MWIFIEX_MAX_AP ) { mwifiex_dbg(adapter, ERROR,
@@ -2162,8 +2171,6 @@ int mwifiex_ret_802_11_scan(struct mwifi"info: SCAN_RESP: bss_descript_size %d\n" , bytes_left); - scan_resp_size =le16_to_cpu (resp->size); -mwifiex_dbg (adapter,INFO ,"info: SCAN_RESP: returned %d APs before parsing\n" , scan_rsp->number_of_sets);
@@ -2171,15 +2178,17 @@ int mwifiex_ret_802_11_scan(struct mwifi bss_info = scan_rsp->bss_desc_and_tlv_buffer;/* -* The size of the TLV buffer is equal to the entire command response -* size (scan_resp_size) minus the fixed fields (sizeof()'s), the -* BSS Descriptions (bss_descript_size as bytesLef) and the command -* response header (S_DS_GEN) +* The TLV buffer follows the command-specific fixed fields and the BSS +* descriptions. Background-scan responses have an additional fixed +* field before scan_rsp, which is included in fixed_size. */ - tlv_buf_size = scan_resp_size - (bytes_left - +sizeof (scan_rsp->bss_descript_size) - +sizeof (scan_rsp->number_of_sets) - +S_DS_GEN ); +if (bytes_left > scan_resp_size - fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: BSS data exceeds response\n" ); + ret =-1 ; + goto check_next_scan; + } + tlv_buf_size = scan_resp_size - fixed_size - bytes_left; tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp-> bss_desc_and_tlv_buffer +
Greg Kroah-Hartman
maintainerPATCH 770/982 wifi: mwifiex: validate action frame fixed fields
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
commit 1c25bfad93e69ce13f744a2fb919f02ea396a985 upstream.
mwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a frame equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A truncated frame can therefore make the parser consume up to two bytes past the firmware-declared frame length. If those bytes look like a TDLS discovery response, the malformed frame can spuriously update peer signal state.
Require the category and public action-code fields before reading them. Use sizeof(*ieee_hdr) so the checks and field accesses directly match the firmware four-address layout being parsed before address4 is removed.
--- drivers/net/wireless/marvell/mwifiex/util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/util.c +8 -2
@@ -335,10 +335,16 @@ mwifiex_parse_mgmt_packet(struct mwifiexswitch (stype) {case IEEE80211_STYPE_ACTION : - category = *(payload +sizeof (struct ieee80211_hdr )); +if (len <sizeof (*ieee_hdr) +1 ) +return -1 ; + + category = *(payload +sizeof (*ieee_hdr));switch (category) {case WLAN_CATEGORY_PUBLIC : - action_code = *(payload +sizeof (struct ieee80211_hdr ) +if (len <sizeof (*ieee_hdr) +2 ) +return -1 ; + + action_code = *(payload +sizeof (*ieee_hdr) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) { addr2 = ieee_hdr->addr2;
Greg Kroah-Hartman
maintainerPATCH 771/982 wifi: mac80211: avoid WARN in set_bitrate_mask when sdata not in driver
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rik van Riel <[email protected]>
commit da2ca406f45a6e21760243152ed8d2e8e72915c2 upstream.
ieee80211_set_bitrate_mask() checks if the interface is running via ieee80211_sdata_running(), but it does not check if the interface is still present in the driver.
When sdata is running but IEEE80211_SDATA_IN_DRIVER is not set, the call reaches drv_set_bitrate_mask() in driver-ops.h which hits
wlan1: Failed check-sdata-in-driver check, flags: 0x0
WARNING: net/mac80211/driver-ops.h:884 at drv_set_bitrate_mask
Syzkaller triggers this via wext SIOCSIWRATE ioctl. The Call Trace shows wext_ioctl_dispatch() in wext-core.c dispatching the ioctl, calling ioctl_standard_call() for SIOCSIWRATE, which calls cfg80211_wext_siwrate() in wext-compat.c. That builds a bitrate mask and calls rdev_set_bitrate_mask() which ends up in ieee80211_set_bitrate_mask() in cfg.c. The interface is marked running via SDATA_STATE_RUNNING but flags is 0, so check_sdata_in_driver() fails.
When the interface is being torn down, or when wext ioctl is issued during interface bringup before drv_add_interface() sets IN_DRIVER, the running check passes while IN_DRIVER is clear.
Check IEEE80211_SDATA_IN_DRIVER in ieee80211_set_bitrate_mask() before calling the driver, returning -ENETDOWN. This avoids the WARN_ONCE in driver-ops.h and matches other cfg.c operations that bail early when not in driver.
This change should be safe because wiphy mutex is held in cfg80211_wext_siwrate() via guard(wiphy), and IN_DRIVER is set/cleared under RTNL and wiphy paths in drv_add_interface() and drv_remove_interface() in driver-ops.c, so the check is race-free against driver add/remove. Returning -ENETDOWN is the same error other not-running paths use and does not introduce new locking.
--- net/mac80211/cfg.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/cfg.c +3 -0
@@ -3266,6 +3266,9 @@ static int ieee80211_set_bitrate_mask(stif (!ieee80211_sdata_running (sdata))return -ENETDOWN ; +if (!(sdata->flags &IEEE80211_SDATA_IN_DRIVER )) +return -ENETDOWN ; +/* * If active validate the setting and reject it if it doesn't leave * at least one basic rate usable, since we really have to be able
Greg Kroah-Hartman
maintainerPATCH 772/982 drm/gud: fix out-of-bounds write in gud_plane_atomic_check()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sajal Gupta <[email protected]>
commit 59ced288fcba9e91bd38e61a972ad782c4edb7d0 upstream.
The plane property loop uses req->properties[num_properties + i] as write index while simultaneously incrementing num_properties inside the loop. At iteration i, num_properties has also incremented by i, so the write is done at initial_num_properties + 2*i, skipping every other index and advancing by 2 per iteration.
With just 2 connector and 32 plane properties the last write happens at index 64, one slot past the end of the 64-slot (indices 0–63) allocation. A USB device can trigger OOB by advertising the maximum number of properties.
Fix by dropping the redundant + i; num_properties is already the correct running index, as gud_connector_fill_properties() fills the preceding slots.
--- drivers/gpu/drm/gud/gud_pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +2 -2
@@ -547,8 +547,8 @@ int gud_pipe_check(struct drm_simple_dis goto out; } - req->properties[num_properties + i].prop =cpu_to_le16 (prop); - req->properties[num_properties + i].val =cpu_to_le64 (val); + req->properties[num_properties].prop =cpu_to_le16 (prop); + req->properties[num_properties].val =cpu_to_le64 (val); num_properties++; }
Greg Kroah-Hartman
maintainerPATCH 773/982 drm/msm/adreno: fix autosuspend cleanup during teardown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 6fbbf1e152f34ad3913e4a6476680aba672c5068 upstream.
adreno_gpu_init() calls pm_runtime_use_autosuspend(), but adreno_gpu_cleanup() does not call the matching pm_runtime_dont_use_autosuspend() during teardown.
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during teardown, this reference is not dropped and usage_count remains unbalanced.
The documentation for pm_runtime_use_autosuspend() also notes that it is important to undo it with pm_runtime_dont_use_autosuspend() at driver exit time, unless runtime PM was initially enabled with devm_pm_runtime_enable().
Add the missing pm_runtime_dont_use_autosuspend() call to adreno_gpu_cleanup().
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/745110/
--- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -0
@@ -1088,6 +1088,8 @@ void adreno_gpu_cleanup(struct adreno_gpfor (i =0 ; i <ARRAY_SIZE (adreno_gpu->info->fw); i++)release_firmware (adreno_gpu->fw[i]); +pm_runtime_dont_use_autosuspend (&gpu->pdev->dev); +if (priv &&pm_runtime_enabled (&priv->gpu_pdev->dev))pm_runtime_disable (&priv->gpu_pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 774/982 drm/msm/hdmi_phy: fix runtime PM cleanup on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit f4fae975db08a9aeec0b15e145c7d4d0fe02a0ec upstream.
msm_hdmi_phy_probe() enables runtime PM before enabling the PHY resources and initializing the PLL, but failures from either operation return without calling the matching pm_runtime_disable().
The remove path disables runtime PM, but it is not called when probe fails. As a result, runtime PM remains enabled after an unsuccessful probe.
Route failures after pm_runtime_enable() through a common error path and disable runtime PM before returning.
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/753043/
--- drivers/gpu/drm/msm/hdmi/hdmi_phy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/hdmi/hdmi_phy.c +6 -2
@@ -160,13 +160,13 @@ static int msm_hdmi_phy_probe(struct pla ret =msm_hdmi_phy_resource_enable (phy);if (ret) -return ret; + goto err_pm_disable; ret =msm_hdmi_phy_pll_init (pdev, phy->cfg->type);if (ret) {DRM_DEV_ERROR (dev,"couldn't init PLL\n" );msm_hdmi_phy_resource_disable (phy); -return ret; + goto err_pm_disable; }msm_hdmi_phy_resource_disable (phy);
@@ -174,6 +174,10 @@ static int msm_hdmi_phy_probe(struct plaplatform_set_drvdata (pdev, phy);return 0 ; + +err_pm_disable: +pm_runtime_disable (dev); +return ret; }static int msm_hdmi_phy_remove (struct platform_device *pdev)
Greg Kroah-Hartman
maintainerPATCH 775/982 smb: client: reject short Next offsets in parse_server_interfaces()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 1b3221bb121079ad79a1f3c3aa360ba649832e7a upstream.
In parse_server_interfaces(), the server-supplied Next offset is validated against bytes_left, but not against the size of the interface structure itself.
A small, non-zero Next value can pass the bounds check but advance the pointer by less than sizeof(*p). This causes the next iteration of the loop to read misaligned, overlapping structure fields.
Fix this by ensuring the Next offset is at least sizeof(*p).
--- fs/smb/client/smb2ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2ops.c +3 -3
@@ -736,9 +736,9 @@ next_iface:break ; }/* Validate that Next doesn't point beyond the buffer */ -if (next > bytes_left) { -cifs_dbg (VFS ,"%s: invalid Next pointer %zu > %zd\n" , - __func__, next, bytes_left); +if (next <sizeof (*p) || next > bytes_left) { +cifs_dbg (VFS ,"%s: invalid Next pointer %zu out of range [%zu, %zd]\n" , + __func__, next,sizeof (*p), bytes_left); rc = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 776/982 smb: client: fix smbd_connection leak on cifs_get_tcp_session() error
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit e75c96157d45e498970158c8f7373d90102e33b9 upstream.
When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.
Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -1894,6 +1894,7 @@ out_err:kfree (tcp_ses->hostname);if (tcp_ses->ssocket)sock_release (tcp_ses->ssocket); +smbd_destroy (tcp_ses);kfree (tcp_ses); }return ERR_PTR (rc);
Greg Kroah-Hartman
maintainerPATCH 777/982 smb: client: fix next_buffer UAF and NextCommand bounds in compound PDUs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 05762c5bc1cfdcac36747994fde2c04387a457f1 upstream.
Fix several related bounds checking and pointer lifecycle issues in receive_encrypted_standard()'s handling of compound encrypted frames:
- Clear next_buffer after assigning it to server->bigbuf. A stale next_buffer pointer can lead to a use-after-free on subsequent error paths.
- Update pdu_length to the decrypted plaintext size (buf_size). Using the pre-decryption length allows NextCommand to point into stale ciphertext residue.
- Reject next_cmd values smaller than MID_HEADER_SIZE(server).
- Fix an integer overflow in the upper bound check by verifying pdu_length - next_cmd < MID_HEADER_SIZE(server), ensuring the trailing slice is large enough for a header.
--- fs/smb/client/smb2ops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +10 -1
@@ -5205,6 +5205,7 @@ receive_encrypted_standard(struct TCP_Se length =decrypt_raw_data (server, buf, buf_size,NULL ,0 ,0 , false);if (length)return length; + pdu_length = buf_size; next_is_large = server->large_buf; one_more:
@@ -5217,8 +5218,15 @@ one_more: }if (next_cmd) { -if (WARN_ON_ONCE (next_cmd > pdu_length)) +if (next_cmd <MID_HEADER_SIZE (server) || + next_cmd > pdu_length || + pdu_length - next_cmd <MID_HEADER_SIZE (server)) { +unsigned int max_next = pdu_length > (unsigned int )MID_HEADER_SIZE (server) ? + pdu_length - (unsigned int )MID_HEADER_SIZE (server) :0 ; +cifs_server_dbg (VFS ,"invalid NextCommand offset %u out of range [%zu, %u]\n" , + next_cmd,MID_HEADER_SIZE (server), max_next);return -1 ; + }if (next_is_large) next_buffer = (char *)cifs_buf_get ();else
@@ -5254,6 +5262,7 @@ one_more: server->bigbuf = buf = next_buffer; else server->smallbuf = buf = next_buffer; + next_buffer =NULL ; goto one_more; }else if (ret !=0 ) {/*
Greg Kroah-Hartman
maintainerPATCH 778/982 smb: client: fix potential OOB read in smb3_enum_snapshots()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 4775c3b7a597907e0b97556c7986fda238a377ae upstream.
If snapshot_array_size is smaller than GMT_TOKEN_SIZE, smb3_enum_snapshots() sets ret_data_len tosizeof(struct smb_snapshot_array) without verifying the actual length of the server's reply.
Because SMB2_ioctl() places no lower bound on the server-supplied OutputCount and allocates retbuf to exactly that length, a short reply results in ret_data_len exceeding the size of retbuf. The subsequent copy_to_user() then reads past the end of retbuf, leaking adjacent slab memory to userspace. The subsequent clamp check is ineffective as it only reduces ret_data_len.
Fix this by rejecting replies shorter thansizeof(struct smb_snapshot_array) with -EIO. Note that the bound is set to the 12-byte struct size rather than the 16-byte MIN_SNAPSHOT_ARRAY_SIZE defined in MS-SMB2 3.3.5.15.1, because 12 bytes is exactly what copy_to_user() attempts to read.
--- fs/smb/client/smb2ops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +7 -1
@@ -2148,8 +2148,14 @@ smb3_enum_snapshots(const unsigned int x* and retry the ioctl again with larger array size sufficient * to hold all of the snapshot GMT tokens on the second try. */ -if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) +if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) { +if (ret_data_len <sizeof (struct smb_snapshot_array )) { + rc = -EIO ; +kfree (retbuf); +return rc; + } ret_data_len =sizeof (struct smb_snapshot_array ); + }/* * We return struct SRV_SNAPSHOT_ARRAY, followed by
Greg Kroah-Hartman
maintainerPATCH 779/982 smb: client: fix server->total_read for compound encrypted PDUs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit f73726b83e4756fdaa099e1bc1143293bd57ad79 upstream.
In receive_encrypted_standard(), server->total_read is left at the full decrypted frame size when walking sub-PDUs of a compound encrypted frame. As a result, cifs_handle_standard() passes this full size to smb2_check_message(), causing the PDU length guards to incorrectly validate the entire compound frame instead of the current sub-PDU.
This allows truncated non-last sub-PDUs to bypass length validation, leading to out-of-bounds reads in smb2_get_data_area_len().
Fix this by setting server->total_read to the true length of the current sub-PDU: next_cmd for non-last sub-PDUs, and the remaining pdu_length for the last one.
--- fs/smb/client/smb2ops.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2ops.c +1 -0
@@ -5217,6 +5217,7 @@ receive_encrypted_standard(struct TCP_Se one_more: shdr = (struct smb2_hdr *)buf; next_cmd =le32_to_cpu (shdr->NextCommand); + server->total_read = next_cmd ? next_cmd : pdu_length;if (*num_mids >=MAX_COMPOUND ) {cifs_server_dbg (VFS ,"too many PDUs in compound\n" );
Greg Kroah-Hartman
maintainerPATCH 780/982 smb: client: fix missing lower-bound check on DFS referral string offsets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit e83330c55edc0c3ac08aa6c95e49e4694c65523b upstream.
parse_dfs_referrals() checks that DfsPathOffset and NetworkAddressOffset do not exceed the buffer end, but fails to check that they don't point inside the referral header itself.
If a server provides an offset smaller thansizeof(struct dfs_referral_level_3), the derived string pointer overlaps with the struct fields, causing cifs_strndup_from_utf16() to interpret header data as UTF-16 strings.
Fix this by enforcing that string offsets are at least sizeof(*ref).
--- fs/smb/client/misc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
fs/smb/client/misc.c +10 -2
@@ -1005,7 +1005,11 @@ parse_dfs_referrals(struct get_dfs_refer node->ref_flag =le16_to_cpu (ref->ReferralEntryFlags);/* copy DfsPath */ -if (le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->DfsPathOffset) <sizeof (*ref) || +le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: DfsPathOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->DfsPathOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
@@ -1019,7 +1023,11 @@ parse_dfs_referrals(struct get_dfs_refer }/* copy link target UNC */ -if (le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->NetworkAddressOffset) <sizeof (*ref) || +le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: NetworkAddressOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->NetworkAddressOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
Greg Kroah-Hartman
maintainerPATCH 781/982 ASoC: SOF: avoid a NULL dereference with unsupported widgets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guennadi Liakhovetski <[email protected]>
[ Upstream commit e3720f92e0237921da537e47a0b24e27899203f8 ]
If an IPC4 topology contains an unsupported widget, its .module_info field won't be set, then sof_ipc4_route_setup() will cause a kernel Oops trying to dereference it. Add a check for such cases.
[ Backport to 6.1.y: although the upstream stable tag names 6.2, the
same module_info dereference is present here; the source change is otherwise unchanged. ]
--- sound/soc/sof/ipc4-topology.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/soc/sof/ipc4-topology.c +8 -0
@@ -1600,6 +1600,14 @@ static int sof_ipc4_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route *int dst_queue =0 ;int ret; +if (!src_fw_module || !sink_fw_module) { +/* The NULL module will print as "(efault)" */ +dev_err (sdev->dev,"source %s or sink %s widget weren't set up properly\n" , + src_fw_module->man4_module_entry.name, + sink_fw_module->man4_module_entry.name); +return -ENODEV ; + } +dev_dbg (sdev->dev,"bind %s -> %s\n" , src_widget->widget->name, sink_widget->widget->name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 782/982 ASoC: SOF: ipc4-topology: Clarify bind failure caused by missing fw_module
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit de6aa72b265b72bca2b1897d5000c8f0147d3157 ]
The original patch uses a feature in lib/vsprintf.c to handle the invalid address when tring to print *_fw_module->man4_module_entry.name when the *rc_fw_module is NULL.
This case is handled by check_pointer_msg() internally and turns the invalid pointer to '(efault)' for printing but it is hiding useful information about the circumstances. Change the print to emmit the name of the widget and a note on which side's fw_module is missing.
Rule: 'Cc: [email protected]' or 'commit <sha1> upstream.'
[ Backport to 6.1.y follow-up to e3720f92e023: replace its (efault)
pointer formatting with source/sink diagnostics; only hunk locations differ. ]
--- sound/soc/sof/ipc4-topology.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
sound/soc/sof/ipc4-topology.c +6 -4
@@ -1601,10 +1601,12 @@ static int sof_ipc4_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route *int ret;if (!src_fw_module || !sink_fw_module) { -/* The NULL module will print as "(efault)" */ -dev_err (sdev->dev,"source %s or sink %s widget weren't set up properly\n" , - src_fw_module->man4_module_entry.name, - sink_fw_module->man4_module_entry.name); +dev_err (sdev->dev, +"cannot bind %s -> %s, no firmware module for: %s%s\n" , + src_widget->widget->name, sink_widget->widget->name, + src_fw_module ?"" :" source" , + sink_fw_module ?"" :" sink" ); +return -ENODEV ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 783/982 HID: logitech-hidpp: fix race condition when accessing stale stack pointer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benoît Sevens <[email protected]>
commit e2aaf2d3ad92ac4a8afa6b69ad4c38e7747d3d6e upstream.
The driver uses hidpp->send_receive_buf to point to a stack-allocated buffer in the synchronous command path (__do_hidpp_send_message_sync). However, this pointer is not cleared when the function returns.
If an event is processed (e.g. by a different thread) while the send_mutex is held by a new command, but before that command has updated send_receive_buf, the handler (hidpp_raw_hidpp_event) will observe that the mutex is locked and dereference the stale pointer.
This results in an out-of-bounds access on a different thread's kernel stack (or a NULL pointer dereference on the very first command).
Fix this by:
1. Clearing hidpp->send_receive_buf to NULL before releasing the mutex in the synchronous command path.
2. Moving the assignment of the local 'question' and 'answer' pointers inside the mutex_is_locked() block in the handler, and adding a NULL check before dereferencing.
[Lee: Clear hidpp->send_receive_buf at exit label in hidpp_send_message_sync()
as __do_hidpp_send_message_sync() was split out later in 60165ab774cb]
--- drivers/hid/hid-logitech-hidpp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/hid/hid-logitech-hidpp.c +8 -2
@@ -315,6 +315,7 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, } exit: + hidpp->send_receive_buf =NULL ;mutex_unlock (&hidpp->send_mutex);return ret;
@@ -3620,8 +3621,7 @@ static int hidpp_input_configured(struct hid_device *hdev,static int hidpp_raw_hidpp_event (struct hidpp_device *hidpp,u8 *data,int size) { -struct hidpp_report *question = hidpp->send_receive_buf; -struct hidpp_report *answer = hidpp->send_receive_buf; +struct hidpp_report *question, *answer;struct hidpp_report *report = (struct hidpp_report *)data;int ret;
@@ -3630,6 +3630,12 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,* previously sent command. */ if (unlikely (mutex_is_locked (&hidpp->send_mutex))) { + question = hidpp->send_receive_buf; + answer = hidpp->send_receive_buf; + +if (!question) +return 0 ; +/* * Check for a correct hidpp20 answer or the corresponding * error
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 784/982 blk-mq: fix tags leak when shrink nr_hw_queues
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengming Zhou <[email protected]>
[ Upstream commit e1dd7bc93029024af5688253b0c05181d6e01f8e ]
Although we don't need to realloc set->tags[] when shrink nr_hw_queues, we need to free them. Or these tags will be leaked.
How to reproduce:
1. mount -t configfs configfs /mnt
2. modprobe null_blk nr_devices=0 submit_queues=8
3. mkdir /mnt/nullb/nullb0
4. echo 1 > /mnt/nullb/nullb0/power
5. echo 4 > /mnt/nullb/nullb0/submit_queues
6. rmdir /mnt/nullb/nullb0
In step 4, will alloc 9 tags (8 submit queues and 1 poll queue), then in step 5, new_nr_hw_queues = 5 (4 submit queues and 1 poll queue). At last in step 6, only these 5 tags are freed, the other 4 tags leaked.
[ Backport to 6.1.y: use this tree's cur_nr_hw_queues snapshot when
freeing excess tag sets. ]
--- block/blk-mq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/blk-mq.c +5 -1
@@ -4509,9 +4509,13 @@ static int blk_mq_realloc_tag_set_tags(struct blk_mq_tag_set *set, int cur_nr_hw_queues, int new_nr_hw_queues) {struct blk_mq_tags **new_tags; +int i; -if (cur_nr_hw_queues >= new_nr_hw_queues) +if (cur_nr_hw_queues >= new_nr_hw_queues) { +for (i = new_nr_hw_queues; i < cur_nr_hw_queues; i++) +__blk_mq_free_map_and_rqs (set, i);return 0 ; + } new_tags =kcalloc_node (new_nr_hw_queues,sizeof (struct blk_mq_tags *),GFP_KERNEL , set->numa_node);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 785/982 blk-mq: fix tags UAF when shrinking q->nr_hw_queues
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengming Zhou <[email protected]>
[ Upstream commit 6be6d112419713334ddd9c01f219ca16adaa4c76 ]
When nr_hw_queues shrink, we free the excess tags before realloc'ing hw_ctxs for each queue. During that resize, we may need to access those tags, like blk_mq_tag_idle(hctx) will access queue shared tags.
This can cause a slab use-after-free, as reported by KASAN. Fix it by moving the releasing of excess tags to the end.
[ Backport to 6.1.y follow-up to e1dd7bc93029: move those frees after
hctx resizing using cur_nr_hw_queues, preventing its tag UAF. ]
--- block/blk-mq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
block/blk-mq.c +7 -7
@@ -4509,13 +4509,9 @@ static int blk_mq_realloc_tag_set_tags(struct blk_mq_tag_set *set, int cur_nr_hw_queues, int new_nr_hw_queues) {struct blk_mq_tags **new_tags; -int i; -if (cur_nr_hw_queues >= new_nr_hw_queues) { -for (i = new_nr_hw_queues; i < cur_nr_hw_queues; i++) -__blk_mq_free_map_and_rqs (set, i); +if (cur_nr_hw_queues >= new_nr_hw_queues)return 0 ; - } new_tags =kcalloc_node (new_nr_hw_queues,sizeof (struct blk_mq_tags *),GFP_KERNEL , set->numa_node);
@@ -4804,7 +4800,8 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, {struct request_queue *q;LIST_HEAD (head); -int prev_nr_hw_queues; +int prev_nr_hw_queues = set->nr_hw_queues; +int i;lockdep_assert_held (&set->tag_list_lock);
@@ -4831,7 +4828,6 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,blk_mq_sysfs_unregister_hctxs (q); } - prev_nr_hw_queues = set->nr_hw_queues;if (blk_mq_realloc_tag_set_tags (set, set->nr_hw_queues, nr_hw_queues) <0 ) goto reregister;
@@ -4869,6 +4865,10 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,list_for_each_entry (q, &set->tag_list, tag_set_list)blk_mq_unfreeze_queue (q); + +/* Free the excess tags when nr_hw_queues shrink. */ +for (i = set->nr_hw_queues; i < prev_nr_hw_queues; i++) +__blk_mq_free_map_and_rqs (set, i); }void blk_mq_update_nr_hw_queues (struct blk_mq_tag_set *set,int nr_hw_queues)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 786/982 Bluetooth: hci_sync: Fix UAF in hci_disconnect_all_sync
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit 94d9ba9f9888b748d4abd2aa1547af56ae85f772 ]
Use-after-free can occur in hci_disconnect_all_sync if a connection is deleted by concurrent processing of a controller event.
To prevent this the code now tries to iterate over the list backwards to ensure the links are cleanup before its parents, also it no longer relies on a cursor, instead it always uses the last element since hci_abort_conn_sync is guaranteed to call hci_conn_del.
UAF crash log:
==================================================================
BUG: KASAN: slab-use-after-free in hci_set_powered_sync (net/bluetooth/hci_sync.c:5424) [bluetooth] Read of size 8 at addr ffff888009d9c000 by task kworker/u9:0/124 CPU: 0 PID: 124 Comm: kworker/u9:0 Tainted: G W 6.5.0-rc1+ #10 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014 Workqueue: hci0 hci_cmd_sync_work [bluetooth] Call Trace: <TASK> dump_stack_lvl+0x5b/0x90 print_report+0xcf/0x670 ? __virt_addr_valid+0xdd/0x160 ? hci_set_powered_sync+0x2c9/0x4a0 [bluetooth] kasan_report+0xa6/0xe0 ? hci_set_powered_sync+0x2c9/0x4a0 [bluetooth] ? __pfx_set_powered_sync+0x10/0x10 [bluetooth] hci_set_powered_sync+0x2c9/0x4a0 [bluetooth] ? __pfx_hci_set_powered_sync+0x10/0x10 [bluetooth] ? __pfx_lock_release+0x10/0x10 ? __pfx_set_powered_sync+0x10/0x10 [bluetooth] hci_cmd_sync_work+0x137/0x220 [bluetooth] process_one_work+0x526/0x9d0 ? __pfx_process_one_work+0x10/0x10 ? __pfx_do_raw_spin_lock+0x10/0x10 ? mark_held_locks+0x1a/0x90 worker_thread+0x92/0x630 ? __pfx_worker_thread+0x10/0x10 kthread+0x196/0x1e0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2c/0x50 </TASK> Allocated by task 1782: kasan_save_stack+0x33/0x60 kasan_set_track+0x25/0x30 __kasan_kmalloc+0x8f/0xa0 hci_conn_add+0xa5/0xa80 [bluetooth] hci_bind_cis+0x881/0x9b0 [bluetooth] iso_connect_cis+0x121/0x520 [bluetooth] iso_sock_connect+0x3f6/0x790 [bluetooth] __sys_connect+0x109/0x130 __x64_sys_connect+0x40/0x50 do_syscall_64+0x60/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 Freed by task 695: kasan_save_stack+0x33/0x60 kasan_set_track+0x25/0x30 kasan_save_free_info+0x2b/0x50 __kasan_slab_free+0x10a/0x180 __kmem_cache_free+0x14d/0x2e0 device_release+0x5d/0xf0 kobject_put+0xdf/0x270 hci_disconn_complete_evt+0x274/0x3a0 [bluetooth] hci_event_packet+0x579/0x7e0 [bluetooth] hci_rx_work+0x287/0xaa0 [bluetooth] process_one_work+0x526/0x9d0 worker_thread+0x92/0x630 kthread+0x196/0x1e0 ret_from_fork+0x2c/0x50 ==================================================================
[ Backport to 6.1.y: the source change is unchanged; only hunk locations
in hci_sync.c differ. ]
--- net/bluetooth/hci_sync.c | 55 +++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 20 deletions(-)
net/bluetooth/hci_sync.c +35 -20
@@ -5589,6 +5589,7 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) {int err =0 ;u16 handle = conn->handle; +struct hci_conn *c;switch (conn->state) {case BT_CONNECTED :
@@ -5602,43 +5603,57 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) err =hci_reject_conn_sync (hdev, conn, reason);break ;default : +hci_dev_lock (hdev); conn->state =BT_CLOSED ; +hci_disconn_cfm (conn, reason); +hci_conn_del (conn); +hci_dev_unlock (hdev);return 0 ; } +hci_dev_lock (hdev); + +/* Check if the connection hasn't been cleanup while waiting +* commands to complete. +*/ + c =hci_conn_hash_lookup_handle (hdev, handle); +if (!c || c != conn) { + err =0 ; + goto unlock; + } +/* Cleanup hci_conn object if it cannot be cancelled as it * likelly means the controller and host stack are out of sync * or in case of LE it was still scanning so it can be cleanup * safely. */ -if (err) { -struct hci_conn *c; - -/* Check if the connection hasn't been cleanup while waiting -* commands to complete. -*/ - c =hci_conn_hash_lookup_handle (hdev, handle); -if (!c || c != conn) -return 0 ; - -hci_dev_lock (hdev); -hci_conn_failed (conn, err); -hci_dev_unlock (hdev); - } +hci_conn_failed (conn, reason); +unlock: +hci_dev_unlock (hdev);return err; }static int hci_disconnect_all_sync (struct hci_dev *hdev,u8 reason) { -struct hci_conn *conn, *tmp; -int err; +struct list_head *head = &hdev->conn_hash.list; +struct hci_conn *conn; -list_for_each_entry_safe (conn, tmp, &hdev->conn_hash.list, list) { - err =hci_abort_conn_sync (hdev, conn, reason); -if (err) -return err; +rcu_read_lock (); + while ((conn = list_first_or_null_rcu(head, struct hci_conn, list))) { +/* Make sure the connection is not freed while unlocking */ + conn =hci_conn_get (conn); +rcu_read_unlock (); +/* Disregard possible errors since hci_conn_del shall have been +* called even in case of errors had occurred since it would +* then cause hci_conn_failed to be called which calls +* hci_conn_del internally. +*/ +hci_abort_conn_sync (hdev, conn, reason); +hci_conn_put (conn); +rcu_read_lock (); } +rcu_read_unlock ();return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 787/982 Bluetooth: hci_sync: always check if connection is alive before deleting
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit a239110ee8e0b0aafa265f0d54f7a16744855e70 ]
In hci_abort_conn_sync it is possible that conn is deleted concurrently by something else, also e.g. when waiting for hdev->lock. This causes double deletion of the conn, so UAF or conn_hash.list corruption.
Fix by having all code paths check that the connection is still in conn_hash before deleting it, while holding hdev->lock which prevents any races.
Log (when powering off while BAP streaming, occurs rarely):
=======================================================================
kernel BUG at lib/list_debug.c:56!
...
? __list_del_entry_valid (lib/list_debug.c:56) hci_conn_del (net/bluetooth/hci_conn.c:154) bluetooth hci_abort_conn_sync (net/bluetooth/hci_sync.c:5415) bluetooth
? __pfx_hci_abort_conn_sync+0x10/0x10 [bluetooth] ? lock_release+0x1d5/0x3c0 ? hci_disconnect_all_sync.constprop.0+0xb2/0x230 [bluetooth] ? __pfx_lock_release+0x10/0x10 ? __kmem_cache_free+0x14d/0x2e0 hci_disconnect_all_sync.constprop.0+0xda/0x230 [bluetooth] ? __pfx_hci_disconnect_all_sync.constprop.0+0x10/0x10 [bluetooth] ? hci_clear_adv_sync+0x14f/0x170 [bluetooth] ? __pfx_set_powered_sync+0x10/0x10 [bluetooth] hci_set_powered_sync+0x293/0x450 [bluetooth] =======================================================================
[ Backport to 6.1.y follow-up to 94d9ba9f9888: this tree lacks the later
BT_OPEN and BT_BOUND special cases, so retain its existing state switch and add the common liveness check. ]
--- net/bluetooth/hci_sync.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
net/bluetooth/hci_sync.c +11 -10
@@ -5589,6 +5589,7 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) {int err =0 ;u16 handle = conn->handle; +bool disconnect = false;struct hci_conn *c;switch (conn->state) {
@@ -5603,19 +5604,13 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) err =hci_reject_conn_sync (hdev, conn, reason);break ;default : -hci_dev_lock (hdev); - conn->state =BT_CLOSED ; -hci_disconn_cfm (conn, reason); -hci_conn_del (conn); -hci_dev_unlock (hdev); -return 0 ; + disconnect = true; +break ; }hci_dev_lock (hdev); -/* Check if the connection hasn't been cleanup while waiting -* commands to complete. -*/ +/* Check if the connection has been cleaned up concurrently */ c =hci_conn_hash_lookup_handle (hdev, handle);if (!c || c != conn) { err =0 ;
@@ -5627,7 +5622,13 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason)* or in case of LE it was still scanning so it can be cleanup * safely. */ -hci_conn_failed (conn, reason); +if (disconnect) { + conn->state =BT_CLOSED ; +hci_disconn_cfm (conn, reason); +hci_conn_del (conn); + }else { +hci_conn_failed (conn, reason); + } unlock:hci_dev_unlock (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 788/982 btrfs: dont check PageError in __extent_writepage
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 3e92499e3b004baffb479d61e191b41b604ece9a ]
__extent_writepage currenly sets PageError whenever any error happens, and the also checks for PageError to decide if to call error handling. This leads to very unclear responsibility for cleaning up on errors. In the VM and generic writeback helpers the basic idea is that once I/O is fired off all error handling responsibility is delegated to the end I/O handler. But if that end I/O handler sets the PageError bit, and the submitter checks it, the bit could in some cases leak into the submission context for fast enough I/O.
Fix this by simply not checking PageError and just using the local ret variable to check for submission errors. This also fundamentally solves the long problem documented in a comment in __extent_writepage by never leaking the error bit into the submission context.
[ Backport to 6.1.y: apply the PageError-to-ret change in this tree's
pre-btrfs_bio_ctrl __extent_writepage(). ]
--- fs/btrfs/extent_io.c | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-)
fs/btrfs/extent_io.c +1 -32
@@ -2299,38 +2299,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,set_page_writeback (page);end_page_writeback (page); } -/* -* Here we used to have a check for PageError() and then set @ret and -* call end_extent_writepage(). -* -* But in fact setting @ret here will cause different error paths -* between subpage and regular sectorsize. -* -* For regular page size, we never submit current page, but only add -* current page to current bio. -* The bio submission can only happen in next page. -* Thus if we hit the PageError() branch, @ret is already set to -* non-zero value and will not get updated for regular sectorsize. -* -* But for subpage case, it's possible we submit part of current page, -* thus can get PageError() set by submitted bio of the same page, -* while our @ret is still 0. -* -* So here we unify the behavior and don't set @ret. -* Error can still be properly passed to higher layer as page will -* be set error, here we just don't handle the IO failure. -* -* NOTE: This is just a hotfix for subpage. -* The root fix will be properly ending ordered extent when we hit -* an error during writeback. -* -* But that needs a bigger refactoring, as we not only need to grab the -* submitted OE, but also need to know exactly at which bytenr we hit -* the error. -* Currently the full page based __extent_writepage_io() is not -* capable of that. -*/ -if (PageError (page)) +if (ret)end_extent_writepage (page, ret, page_start, page_end);if (epd->extent_locked) {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 789/982 io_uring/io-wq: Fix memory leak in io_wq_create() on success path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Xiaokun <[email protected]>
[ This is a stable-only patch for 6.1.y ]
Commit 657ca82526d0 ("io_uring/io-wq: inherit cpuset of cgroup in io worker") was backported from upstream commit 84eacf177faa to 6.1.y.
In linux-6.1.y, this backport introduced a temporary allowed_mask variable in io_wq_create(). It is correctly freed on the error path, but is not freed on the success path. As a result, every successful call to io_wq_create() leaks cpumask_size() bytes of memory.
This is a 6.1-specific backport issue caused by the differences in the io-wq implementation, so the fix only applies to 6.1.y.
--- io_uring/io-wq.c | 1 + 1 file changed, 1 insertion(+)
io_uring/io-wq.c +1 -0
@@ -1221,6 +1221,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data) wq->task =get_task_struct (data->task);atomic_set (&wq->worker_refs,1 );init_completion (&wq->worker_done); +free_cpumask_var (allowed_mask);return wq; err:io_wq_put_hash (data->hash);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 790/982 spi: spi-zynqmp-gqspi: stop the controller on shutdown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Itai Handler <[email protected]>
commit e922bad8b2d5028c51a096d083fea41cd0987154 upstream.
The driver has no ->shutdown, and platform_drv_shutdown() has no fallback of its own. Unlike pci_device_shutdown(), which clears bus mastering when kexec_in_progress, nothing on the platform bus disarms a device that can still write to memory. The normal kexec path never calls ->suspend either, so the quiesce in zynqmp_qspi_suspend() is not reached.
A controller that is still executing a DMA read may therefore keep writing to memory across a kexec. QSPIDMA_DST_ADDR still points at memory owned by the kernel that called kexec, DST_SIZE is non-zero and the flash is still clocked, so data can keep landing in RAM while the new kernel is being relocated, and after it has started executing.
That destination is a physical address which means nothing to the new kernel, so the writes can corrupt whatever now occupies it: kernel text or data, page tables, or the initrd. Nothing reports an error and the resulting behaviour is undefined.
This can be observed by reading GQSPI_EN (offset 0x114) and QSPIDMA_DST_ADDR/SIZE/STS/CTRL (offsets 0x800 to 0x80c) early in the new kernel, before the driver probes: without this patch GQSPI_EN reads 1 and QSPIDMA_DST_ADDR still points into the previous kernel's memory.
Add a ->shutdown that stops the controller the way zynqmp_qspi_suspend() already does. spi_controller_suspend() stops the queue, waits for a message that is already executing and makes any later transfer fail with -ESHUTDOWN, so nothing can be cut short by the register write that follows. It may sleep, which is fine here: device_shutdown() runs in process context. Unlike ->suspend this cannot abort on error, because a controller left mastering the bus is worse than a truncated transfer, so a failure to drain is only logged.
GQSPI_EN_OFST is then cleared, as zynqmp_qspi_remove() and zynqmp_qspi_suspend() already do. Skip that write only when pm_runtime_get_if_in_use() returns 0, i.e. runtime suspended: the clocks are gated, so the registers are unreachable and the controller cannot be mastering the bus. A negative return is not the same thing - it is what the CONFIG_PM=n stub always returns, and there probe() has enabled pclk and refclk for good, so the controller is running and must be stopped.
[ itai: context only - zynqmp_qspi_of_match[] still sits between
zynqmp_qspi_remove() and MODULE_DEVICE_TABLE() in this tree, hoisted to the top of the file upstream by commit 29f4d95b97bc ("spi:
spi-zynqmp-gqspi: Add tap delay support for GQSPI controller on Versal platform"), so zynqmp_qspi_shutdown() is placed above it ]
--- drivers/spi/spi-zynqmp-gqspi.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/spi/spi-zynqmp-gqspi.c +34 -0
@@ -1257,6 +1257,39 @@ static int zynqmp_qspi_remove(struct platform_device *pdev)return 0 ; } +static void zynqmp_qspi_shutdown (struct platform_device *pdev) +{ +struct zynqmp_qspi *xqspi =platform_get_drvdata (pdev); +int ret; + +/* +* Stop the queue and reject any later transfer first, so the write +* below cannot cut into a message that is still being executed. +* Unlike ->suspend this cannot abort on error: a controller left +* mastering the bus is worse than a truncated transfer. +*/ + ret =spi_controller_suspend (xqspi->ctlr); +if (ret) +dev_warn (&pdev->dev,"could not stop the queue: %d\n" , ret); + +/* +* Only a runtime suspended controller can be left alone: its clocks +* are gated, so it cannot be mastering the bus, and its registers +* must not be accessed either. Any other answer means it may be +* running and has to be stopped. In particular, on a kernel built +* without runtime PM this returns -EINVAL, and there the clocks +* enabled in probe() are never gated at all. +*/ + ret =pm_runtime_get_if_in_use (&pdev->dev); +if (!ret) +return ; + +zynqmp_gqspi_write (xqspi,GQSPI_EN_OFST ,0x0 ); + +if (ret >0 ) +pm_runtime_put_noidle (&pdev->dev); +} +static const struct of_device_id zynqmp_qspi_of_match[] = { { .compatible ="xlnx,zynqmp-qspi-1.0" , }, {/* End of table */ }
@@ -1267,6 +1300,7 @@ MODULE_DEVICE_TABLE(of, zynqmp_qspi_of_match);static struct platform_driver zynqmp_qspi_driver = { .probe = zynqmp_qspi_probe, .remove = zynqmp_qspi_remove, + .shutdown = zynqmp_qspi_shutdown, .driver = { .name ="zynqmp-qspi" , .of_match_table = zynqmp_qspi_of_match,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 791/982 bpf: bpf_sk_storage: Fix invalid wait context lockdep report
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin KaFai Lau <[email protected]>
[ Upstream commit a96a44aba556c42b432929d37d60158aca21ad4c ]
'./test_progs -t test_local_storage' reported a splat:
[ 27.137569] =============================
[ 27.138122] [ BUG: Invalid wait context ]
[ 27.138650] 6.5.0-03980-gd11ae1b16b0a #247 Tainted: G O
[ 27.139542] -----------------------------
[ 27.140106] test_progs/1729 is trying to lock:
[ 27.140713] ffff8883ef047b88 (stock_lock){-.-.}-{3:3}, at: local_lock_acquire+0x9/0x130
[ 27.141834] other info that might help us debug this:
[ 27.142437] context-{5:5}
[ 27.142856] 2 locks held by test_progs/1729:
[ 27.143352] #0: ffffffff84bcd9c0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x40
[ 27.144492] #1: ffff888107deb2c0 (&storage->lock){..-.}-{2:2}, at: bpf_local_storage_update+0x39e/0x8e0
[ 27.145855] stack backtrace:
[ 27.146274] CPU: 0 PID: 1729 Comm: test_progs Tainted: G O 6.5.0-03980-gd11ae1b16b0a #247
[ 27.147550] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
[ 27.149127] Call Trace:
[ 27.149490] <TASK>
[ 27.149867] dump_stack_lvl+0x130/0x1d0
[ 27.152609] dump_stack+0x14/0x20
[ 27.153131] __lock_acquire+0x1657/0x2220
[ 27.153677] lock_acquire+0x1b8/0x510
[ 27.157908] local_lock_acquire+0x29/0x130
[ 27.159048] obj_cgroup_charge+0xf4/0x3c0
[ 27.160794] slab_pre_alloc_hook+0x28e/0x2b0
[ 27.161931] __kmem_cache_alloc_node+0x51/0x210
[ 27.163557] __kmalloc+0xaa/0x210
[ 27.164593] bpf_map_kzalloc+0xbc/0x170
[ 27.165147] bpf_selem_alloc+0x130/0x510
[ 27.166295] bpf_local_storage_update+0x5aa/0x8e0
[ 27.167042] bpf_fd_sk_storage_update_elem+0xdb/0x1a0
[ 27.169199] bpf_map_update_value+0x415/0x4f0
[ 27.169871] map_update_elem+0x413/0x550
[ 27.170330] __sys_bpf+0x5e9/0x640
[ 27.174065] __x64_sys_bpf+0x80/0x90
[ 27.174568] do_syscall_64+0x48/0xa0
[ 27.175201] entry_SYSCALL_64_after_hwframe+0x6e/0xd8
[ 27.175932] RIP: 0033:0x7effb40e41ad
[ 27.176357] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d8
[ 27.179028] RSP: 002b:00007ffe64c21fc8 EFLAGS: 00000202 ORIG_RAX: 0000000000000141
[ 27.180088] RAX: ffffffffffffffda RBX: 00007ffe64c22768 RCX: 00007effb40e41ad
[ 27.181082] RDX: 0000000000000020 RSI: 00007ffe64c22008 RDI: 0000000000000002
[ 27.182030] RBP: 00007ffe64c21ff0 R08: 0000000000000000 R09: 00007ffe64c22788
[ 27.183038] R10: 0000000000000064 R11: 0000000000000202 R12: 0000000000000000
[ 27.184006] R13: 00007ffe64c22788 R14: 00007effb42a1000 R15: 0000000000000000
[ 27.184958] </TASK>It complains about acquiring a local_lock while holding a raw_spin_lock. It means it should not allocate memory while holding a raw_spin_lock since it is not safe for RT.
raw_spin_lock is needed because bpf_local_storage supports tracing context. In particular for task local storage, it is easy to get a "current" task PTR_TO_BTF_ID in tracing bpf prog. However, task (and cgroup) local storage has already been moved to bpf mem allocator which can be used after raw_spin_lock.
The splat is for the sk storage. For sk (and inode) storage, it has not been moved to bpf mem allocator. Using raw_spin_lock or not, kzalloc(GFP_ATOMIC) could theoretically be unsafe in tracing context. However, the local storage helper requires a verifier accepted sk pointer (PTR_TO_BTF_ID), it is hypothetical if that (mean running a bpf prog in a kzalloc unsafe context and also able to hold a verifier accepted sk pointer) could happen.
This patch avoids kzalloc after raw_spin_lock to silent the splat. There is an existing kzalloc before the raw_spin_lock. At that point, a kzalloc is very likely required because a lookup has just been done before. Thus, this patch always does the kzalloc before acquiring the raw_spin_lock and remove the later kzalloc usage after the raw_spin_lock. After this change, it will have a charge and then uncharge during the syscall bpf_map_update_elem() code path. This patch opts for simplicity and not continue the old optimization to save one charge and uncharge.
This issue is dated back to the very first commit of bpf_sk_storage which had been refactored multiple times to create task, inode, and cgroup storage. This patch uses a Fixes tag with a more recent commit that should be easier to do backport.
[ Backport to 6.1.y: retain the pre-reuse_now unlink/free API while
moving the charged element allocation outside local_storage->lock. ]
--- kernel/bpf/bpf_local_storage.c | 47 ++++++++++------------------------ 1 file changed, 14 insertions(+), 33 deletions(-)
kernel/bpf/bpf_local_storage.c +14 -33
@@ -373,7 +373,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap, void *value, u64 map_flags, gfp_t gfp_flags) { struct bpf_local_storage_data *old_sdata = NULL; -struct bpf_local_storage_elem *selem =NULL ; +struct bpf_local_storage_elem *alloc_selem, *selem =NULL ;struct bpf_local_storage *local_storage;unsigned long flags;int err;
@@ -427,11 +427,12 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap, } } -if (gfp_flags ==GFP_KERNEL ) { - selem =bpf_selem_alloc (smap, owner, value, true, gfp_flags); -if (!selem) -return ERR_PTR (-ENOMEM ); - } +/* A lookup has just been done before and concluded a new selem is +* needed. The chance of an unnecessary alloc is unlikely. +*/ + alloc_selem = selem =bpf_selem_alloc (smap, owner, value, true, gfp_flags); +if (!alloc_selem) +return ERR_PTR (-ENOMEM );raw_spin_lock_irqsave (&local_storage->lock, flags);
@@ -443,13 +444,13 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,* simple. */ err = -EAGAIN ; - goto unlock_err; + goto unlock; } old_sdata =bpf_local_storage_lookup (local_storage, smap, false); err =check_flags (old_sdata, map_flags);if (err) - goto unlock_err; + goto unlock;if (old_sdata && (map_flags &BPF_F_LOCK )) { copy_map_value_locked(&smap->map, old_sdata->data, value,
@@ -458,23 +459,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap, goto unlock; } -if (gfp_flags !=GFP_KERNEL ) { -/* local_storage->lock is held. Hence, we are sure -* we can unlink and uncharge the old_sdata successfully -* later. Hence, instead of charging the new selem now -* and then uncharge the old selem later (which may cause -* a potential but unnecessary charge failure), avoid taking -* a charge at all here (the "!old_sdata" check) and the -* old_sdata will not be uncharged later during -* bpf_selem_unlink_storage_nolock(). -*/ - selem =bpf_selem_alloc (smap, owner, value, !old_sdata, gfp_flags); -if (!selem) { - err = -ENOMEM ; - goto unlock_err; - } - } - + alloc_selem =NULL ;/* First, link the new selem to the map */ bpf_selem_link_map (smap, selem);
@@ -485,20 +470,16 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,if (old_sdata) {bpf_selem_unlink_map (SELEM (old_sdata));bpf_selem_unlink_storage_nolock (local_storage,SELEM (old_sdata), - false, true); + true, true); } unlock:raw_spin_unlock_irqrestore (&local_storage->lock, flags); -return SDATA (selem); - -unlock_err: -raw_spin_unlock_irqrestore (&local_storage->lock, flags); -if (selem) { +if (alloc_selem) {mem_uncharge (smap, owner, smap->elem_size); -kfree (selem); +kfree (alloc_selem); } -return ERR_PTR (err); +return err ?ERR_PTR (err) :SDATA (selem); }static u16 bpf_local_storage_cache_idx_get (struct bpf_local_storage_cache *cache)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 792/982 drm/msm/dp: Drop aux devices together with DP controller
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit a7bfb2ad2184a1fba78be35209b6019aa8cc8d4d ]
Using devres to depopulate the aux bus made sure that upon a probe deferral the EDP panel device would be destroyed and recreated upon next attempt.
But the struct device which the devres is tied to is the DPUs (drm_dev->dev), which may be happen after the DP controller is torn down.
Indications of this can be seen in the commonly seen EDID-hexdump full of zeros in the log, or the occasional/rare KASAN fault where the panel's attempt to read the EDID information causes a use after free on DP resources.
It's tempting to move the devres to the DP controller's struct device, but the resources used by the device(s) on the aux bus are explicitly torn down in the error path. The KASAN-reported use-after-free also remains, as the DP aux "module" explicitly frees its devres-allocated memory in this code path.
As such, explicitly depopulate the aux bus in the error path, and in the component unbind path, to avoid these issues.
Patchwork: https://patchwork.freedesktop.org/patch/542163/
[ Backport to 6.1.y: the source change is unchanged; refresh context
around the older DP bridge layout. ]
--- drivers/gpu/drm/msm/dp/dp_display.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +3 -11
@@ -322,6 +322,8 @@ static void dp_display_unbind(struct device *dev, struct device *master,kthread_stop (dp->ev_tsk); +of_dp_aux_depopulate_bus (dp->aux); +dp_power_client_deinit (dp->power);dp_unregister_audio_driver (dev, dp->audio);dp_aux_unregister (dp->aux);
@@ -1535,11 +1537,6 @@ void msm_dp_debugfs_init(struct msm_dp *dp_display, struct drm_minor *minor) } } -static void of_dp_aux_depopulate_bus_void (void *data) -{ -of_dp_aux_depopulate_bus (data); -} -static int dp_display_get_next_bridge (struct msm_dp *dp) {int rc;
@@ -1568,12 +1565,6 @@ static int dp_display_get_next_bridge(struct msm_dp *dp)of_node_put (aux_bus);if (rc) goto error; - - rc =devm_add_action_or_reset (dp->drm_dev->dev, - of_dp_aux_depopulate_bus_void, - dp_priv->aux); -if (rc) - goto error; }else if (dp->is_edp) {DRM_ERROR ("eDP aux_bus not found\n" );return -ENODEV ;
@@ -1597,6 +1588,7 @@ static int dp_display_get_next_bridge(struct msm_dp *dp) error:if (dp->is_edp) { +of_dp_aux_depopulate_bus (dp_priv->aux);disable_irq (dp_priv->irq);dp_display_host_phy_exit (dp_priv);dp_display_host_deinit (dp_priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 793/982 erofs: Fix detection of atomic context
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sandeep Dhavale <[email protected]>
[ Upstream commit 12d0a24afd9ea58e581ea64d64e066f2027b28d9 ]
Current check for atomic context is not sufficient as z_erofs_decompressqueue_endio can be called under rcu lock from blk_mq_flush_plug_list(). See the stacktrace [1]
In such case we should hand off the decompression work for async processing rather than trying to do sync decompression in current context. Patch fixes the detection by checking for rcu_read_lock_any_held() and while at it use more appropriate !in_task() check than in_atomic().
Background: Historically erofs would always schedule a kworker for decompression which would incur the scheduling cost regardless of the context. But z_erofs_decompressqueue_endio() may not always be in atomic context and we could actually benefit from doing the decompression in z_erofs_decompressqueue_endio() if we are in thread context, for example when running with dm-verity. This optimization was later added in patch [2] which has shown improvement in performance benchmarks.
==============================================
[1] Problem stacktrace
[name:core&]BUG: sleeping function called from invalid context at kernel/locking/mutex.c:291 [name:core&]in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 1615, name: CpuMonitorServi [name:core&]preempt_count: 0, expected: 0
[name:core&]RCU nest depth: 1, expected: 0
CPU: 7 PID: 1615 Comm: CpuMonitorServi Tainted: G S W OE 6.1.25-android14-5-maybe-dirty-mainline #1 Hardware name: MT6897 (DT) Call trace: dump_backtrace+0x108/0x15c show_stack+0x20/0x30 dump_stack_lvl+0x6c/0x8c dump_stack+0x20/0x48 __might_resched+0x1fc/0x308 __might_sleep+0x50/0x88 mutex_lock+0x2c/0x110 z_erofs_decompress_queue+0x11c/0xc10 z_erofs_decompress_kickoff+0x110/0x1a4 z_erofs_decompressqueue_endio+0x154/0x180 bio_endio+0x1b0/0x1d8 __dm_io_complete+0x22c/0x280 clone_endio+0xe4/0x280 bio_endio+0x1b0/0x1d8 blk_update_request+0x138/0x3a4 blk_mq_plug_issue_direct+0xd4/0x19c blk_mq_flush_plug_list+0x2b0/0x354 __blk_flush_plug+0x110/0x160 blk_finish_plug+0x30/0x4c read_pages+0x2fc/0x370 page_cache_ra_unbounded+0xa4/0x23c page_cache_ra_order+0x290/0x320 do_sync_mmap_readahead+0x108/0x2c0 filemap_fault+0x19c/0x52c __do_fault+0xc4/0x114 handle_mm_fault+0x5b4/0x1168 do_page_fault+0x338/0x4b4 do_translation_fault+0x40/0x60 do_mem_abort+0x60/0xc8 el0_da+0x4c/0xe0 el0t_64_sync_handler+0xd4/0xfc el0t_64_sync+0x1a0/0x1a4
[2] Link: https://lore.kernel.org/all/[email protected]/
[ Backport to 6.1.y: the source change is unchanged; only its location
in z_erofs_decompress_kickoff() differs. ]
--- fs/erofs/zdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/zdata.c +1 -1
@@ -1271,7 +1271,7 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,if (atomic_add_return (bios, &io->pending_bios))return ;/* Use workqueue and sync decompression for atomic contexts only */ -if (in_atomic () ||irqs_disabled ()) { +if (!in_task () ||irqs_disabled () ||rcu_read_lock_any_held ()) {queue_work (z_erofs_workqueue, &io->u.work);/* enable sync decompression for readahead */ if (sbi->opt.sync_decompress ==EROFS_SYNC_DECOMPRESS_AUTO )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 794/982 selftests/landlock: Add layout1.refer_mount_root
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mickaël Salaün <[email protected]>
[ Upstream commit 0055f53aac80fd938bf7cdfad7ad414ca6c0e198 ]
Add tests to check error codes when linking or renaming a mount root directory. This previously triggered a kernel warning, but it is fixed with the previous commit.
--- tools/testing/selftests/landlock/fs_test.c | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
tools/testing/selftests/landlock/fs_test.c +50 -0
@@ -21,6 +21,12 @@#include <sys/sysmacros.h> #include <unistd.h> +/* +* Intentionally included last to work around header conflict. +* See https://sourceware.org/glibc/wiki/Synchronizing_Headers. +*/ +#include <linux/mount.h> +#include "common.h" #ifndef renameat2
@@ -32,6 +38,13 @@ int renameat2(int olddirfd, const char * }#endif +#ifndef open_tree +int open_tree (int dfd,const char *filename,unsigned int flags) +{ +return syscall (__NR_open_tree, dfd, filename, flags); +} +#endif +#ifndef RENAME_EXCHANGE #define RENAME_EXCHANGE (1 << 1)#endif
@@ -2400,6 +2413,43 @@ TEST_F_FORK(layout1, refer_denied_by_def layer_dir_s1d1_refer); } +/* +* Tests walking through a denied root mount. +*/ +TEST_F_FORK(layout1, refer_mount_root_deny) +{ +const struct landlock_ruleset_attr ruleset_attr = { + .handled_access_fs =LANDLOCK_ACCESS_FS_MAKE_DIR , + }; +int root_fd, ruleset_fd; + +/* Creates a mount object from a non-mount point. */ +set_cap (_metadata,CAP_SYS_ADMIN ); + root_fd = +open_tree (AT_FDCWD , dir_s1d1, +AT_EMPTY_PATH |OPEN_TREE_CLONE |OPEN_TREE_CLOEXEC ); +clear_cap (_metadata,CAP_SYS_ADMIN ); +ASSERT_LE (0 , root_fd); + + ruleset_fd = +landlock_create_ruleset (&ruleset_attr,sizeof (ruleset_attr),0 ); +ASSERT_LE (0 , ruleset_fd); + +ASSERT_EQ (0 ,prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 )); +ASSERT_EQ (0 ,landlock_restrict_self (ruleset_fd,0 )); +EXPECT_EQ (0 ,close (ruleset_fd)); + +/* Link denied by Landlock: EACCES. */ +EXPECT_EQ (-1 ,linkat (root_fd,"." , root_fd,"does_not_exist" ,0 )); +EXPECT_EQ (EACCES , errno); + +/* renameat2() always returns EBUSY. */ +EXPECT_EQ (-1 ,renameat2 (root_fd,"." , root_fd,"does_not_exist" ,0 )); +EXPECT_EQ (EBUSY , errno); + +EXPECT_EQ (0 ,close (root_fd)); +} + TEST_F_FORK(layout1, reparent_link) {const struct rule layer1[] = {
Greg Kroah-Hartman
maintainerPATCH 795/982 erofs: fix atomic context detection when !CONFIG_DEBUG_LOCK_ALLOC
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junli Liu <[email protected]>
[ Upstream commit c99fab6e80b76422741d34aafc2f930a482afbdd ]
Since EROFS handles decompression in non-atomic contexts due to uncontrollable decompression latencies and vmap() usage, it tries to detect atomic contexts and only kicks off a kworker on demand in order to reduce unnecessary scheduling overhead.
However, the current approach is insufficient and can lead to sleeping function calls in invalid contexts, causing kernel warnings and potential system instability. See the stacktrace [1] and previous discussion [2].
The current implementation only checks rcu_read_lock_any_held(), which behaves inconsistently across different kernel configurations:
- When CONFIG_DEBUG_LOCK_ALLOC is enabled: correctly detects RCU critical sections by checking rcu_lock_map
- When CONFIG_DEBUG_LOCK_ALLOC is disabled: compiles to "!preemptible()", which only checks preempt_count and misses RCU critical sections
This patch introduces z_erofs_in_atomic() to provide comprehensive atomic context detection:
1. Check RCU preemption depth when CONFIG_PREEMPTION is enabled, as RCU critical sections may not affect preempt_count but still require atomic handling
2. Always use async processing when CONFIG_PREEMPT_COUNT is disabled, as preemption state cannot be reliably determined
3. Fall back to standard preemptible() check for remaining cases
The function replaces the previous complex condition check and ensures that z_erofs always uses (kthread_)work in atomic contexts to minimize scheduling overhead and prevent sleeping in invalid contexts.
[1] Problem stacktrace
[ 61.266692] BUG: sleeping function called from invalid context at kernel/locking/rtmutex_api.c:510 [ 61.266702] in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 107, name: irq/54-ufshcd [ 61.266704] preempt_count: 0, expected: 0 [ 61.266705] RCU nest depth: 2, expected: 0 [ 61.266710] CPU: 0 UID: 0 PID: 107 Comm: irq/54-ufshcd Tainted: G W O 6.12.17 #1 [ 61.266714] Tainted: [W]=WARN, [O]=OOT_MODULE [ 61.266715] Hardware name: schumacher (DT) [ 61.266717] Call trace: [ 61.266718] dump_backtrace+0x9c/0x100 [ 61.266727] show_stack+0x20/0x38 [ 61.266728] dump_stack_lvl+0x78/0x90 [ 61.266734] dump_stack+0x18/0x28 [ 61.266736] __might_resched+0x11c/0x180 [ 61.266743] __might_sleep+0x64/0xc8 [ 61.266745] mutex_lock+0x2c/0xc0 [ 61.266748] z_erofs_decompress_queue+0xe8/0x978 [ 61.266753] z_erofs_decompress_kickoff+0xa8/0x190 [ 61.266756] z_erofs_endio+0x168/0x288 [ 61.266758] bio_endio+0x160/0x218 [ 61.266762] blk_update_request+0x244/0x458 [ 61.266766] scsi_end_request+0x38/0x278 [ 61.266770] scsi_io_completion+0x4c/0x600 [ 61.266772] scsi_finish_command+0xc8/0xe8 [ 61.266775] scsi_complete+0x88/0x148 [ 61.266777] blk_mq_complete_request+0x3c/0x58 [ 61.266780] scsi_done_internal+0xcc/0x158 [ 61.266782] scsi_done+0x1c/0x30 [ 61.266783] ufshcd_compl_one_cqe+0x12c/0x438 [ 61.266786] __ufshcd_transfer_req_compl+0x2c/0x78 [ 61.266788] ufshcd_poll+0xf4/0x210 [ 61.266789] ufshcd_transfer_req_compl+0x50/0x88 [ 61.266791] ufshcd_intr+0x21c/0x7c8 [ 61.266792] irq_forced_thread_fn+0x44/0xd8 [ 61.266796] irq_thread+0x1a4/0x358 [ 61.266799] kthread+0x12c/0x138 [ 61.266802] ret_from_fork+0x10/0x20
[2] https://lore.kernel.org/r/58b661d0-0ebb-4b45-a10d-c5927fb791cd@paulmck-laptop
--- fs/erofs/zdata.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/erofs/zdata.c +11 -2
@@ -1255,6 +1255,16 @@ static void z_erofs_decompressqueue_work(struct work_struct *work)kvfree (bgq); } +/* Use workqueue and sync decompression for atomic contexts only */ +static inline bool z_erofs_in_atomic (void ) +{ +if (IS_ENABLED (CONFIG_PREEMPTION ) &&rcu_preempt_depth ()) +return true; +if (!IS_ENABLED (CONFIG_PREEMPT_COUNT )) +return true; +return !preemptible (); +} +static void z_erofs_decompress_kickoff (struct z_erofs_decompressqueue *io,int bios) {
@@ -1270,8 +1280,7 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,if (atomic_add_return (bios, &io->pending_bios))return ; -/* Use workqueue and sync decompression for atomic contexts only */ -if (!in_task () ||irqs_disabled () ||rcu_read_lock_any_held ()) { +if (z_erofs_in_atomic ()) {queue_work (z_erofs_workqueue, &io->u.work);/* enable sync decompression for readahead */ if (sbi->opt.sync_decompress ==EROFS_SYNC_DECOMPRESS_AUTO )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 796/982 spi: zynqmp-gqspi: Use devm_spi_alloc_host()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
[ Upstream commit 64640f6c972e80f52196416a8d4dc3c0ffcbc82d ]
Use devm_spi_alloc_host() so that there's no need to call spi_controller_put() in the error path.
--- drivers/spi/spi-zynqmp-gqspi.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +6 -12
@@ -1104,7 +1104,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)struct device_node *np = dev->of_node;u32 num_cs; - ctlr =spi_alloc_master (&pdev->dev,sizeof (*xqspi)); + ctlr =devm_spi_alloc_host (&pdev->dev,sizeof (*xqspi));if (!ctlr)return -ENOMEM ;
@@ -1114,29 +1114,25 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, xqspi); xqspi->regs =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (xqspi->regs)) { - ret =PTR_ERR (xqspi->regs); - goto remove_master; - } +if (IS_ERR (xqspi->regs)) +return PTR_ERR (xqspi->regs); xqspi->pclk =devm_clk_get (&pdev->dev,"pclk" );if (IS_ERR (xqspi->pclk)) {dev_err (dev,"pclk clock not found.\n" ); - ret =PTR_ERR (xqspi->pclk); - goto remove_master; +return PTR_ERR (xqspi->pclk); } xqspi->refclk =devm_clk_get (&pdev->dev,"ref_clk" );if (IS_ERR (xqspi->refclk)) {dev_err (dev,"ref_clk clock not found.\n" ); - ret =PTR_ERR (xqspi->refclk); - goto remove_master; +return PTR_ERR (xqspi->refclk); } ret =clk_prepare_enable (xqspi->pclk);if (ret) {dev_err (dev,"Unable to enable APB clock.\n" ); - goto remove_master; +return ret; } ret =clk_prepare_enable (xqspi->refclk);
@@ -1221,8 +1217,6 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)clk_disable_unprepare (xqspi->refclk); clk_dis_pclk:clk_disable_unprepare (xqspi->pclk); -remove_master: -spi_controller_put (ctlr);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 797/982 bpf: bpf_sk_storage: Fix the missing uncharge in sk_omem_alloc
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin KaFai Lau <[email protected]>
[ Upstream commit 55d49f750b1cb1f177fb1b00ae02cba4613bcfb7 ]
The commit c83597fa5dc6 ("bpf: Refactor some inode/task/sk storage functions for reuse"), refactored the bpf_{sk,task,inode}_storage_free() into bpf_local_storage_unlink_nolock() which then later renamed to bpf_local_storage_destroy(). The commit accidentally passed the "bool uncharge_mem = false" argument to bpf_selem_unlink_storage_nolock() which then stopped the uncharge from happening to the sk->sk_omem_alloc.
This missing uncharge only happens when the sk is going away (during __sk_destruct).
This patch fixes it by always passing "uncharge_mem = true". It is a noop to the task/inode/cgroup storage because they do not have the map_local_storage_(un)charge enabled in the map_ops. A followup patch will be done in bpf-next to remove the uncharge_mem argument.
A selftest is added in the next patch.
--- kernel/bpf/bpf_local_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/bpf_local_storage.c +1 -1
@@ -577,7 +577,7 @@ bool bpf_local_storage_unlink_nolock(struct bpf_local_storage *local_storage)* of the loop will set the free_cgroup_storage to true. */ free_storage =bpf_selem_unlink_storage_nolock ( - local_storage, selem, false, false); + local_storage, selem, true, false); }return free_storage;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 798/982 HID: hyperv: streamline driver probe to avoid devres issues
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vitaly Kuznetsov <[email protected]>
commit 66ef47faa90d838cda131fe1f7776456cc3b59f2 upstream
It was found that unloading 'hid_hyperv' module results in a devres complaint:
...
hv_vmbus: unregistering driver hid_hyperv
------------[ cut here ]------------ WARNING: CPU: 2 PID: 3983 at drivers/base/devres.c:691 devres_release_group+0x1f2/0x2c0 ... Call Trace: <TASK> ? devres_release_group+0x1f2/0x2c0 ? __warn+0xd1/0x1c0 ? devres_release_group+0x1f2/0x2c0 ? report_bug+0x32a/0x3c0 ? handle_bug+0x53/0xa0 ? exc_invalid_op+0x18/0x50 ? asm_exc_invalid_op+0x1a/0x20 ? devres_release_group+0x1f2/0x2c0 ? devres_release_group+0x90/0x2c0 ? rcu_is_watching+0x15/0xb0 ? __pfx_devres_release_group+0x10/0x10 hid_device_remove+0xf5/0x220 device_release_driver_internal+0x371/0x540 ? klist_put+0xf3/0x170 bus_remove_device+0x1f1/0x3f0 device_del+0x33f/0x8c0 ? __pfx_device_del+0x10/0x10 ? cleanup_srcu_struct+0x337/0x500 hid_destroy_device+0xc8/0x130 mousevsc_remove+0xd2/0x1d0 [hid_hyperv] device_release_driver_internal+0x371/0x540 driver_detach+0xc5/0x180 bus_remove_driver+0x11e/0x2a0 ? __mutex_unlock_slowpath+0x160/0x5e0 vmbus_driver_unregister+0x62/0x2b0 [hv_vmbus] ...
And the issue seems to be that the corresponding devres group is not allocated. Normally, devres_open_group() is called from __hid_device_probe() but Hyper-V HID driver overrides 'hid_dev->driver' with 'mousevsc_hid_driver' stub and basically re-implements __hid_device_probe() by calling hid_parse() and hid_hw_start() but not devres_open_group(). hid_device_probe() does not call __hid_device_probe() for it. Later, when the driver is removed, hid_device_remove() calls devres_release_group() as it doesn't check whether hdev->driver was initially overridden or not.
The issue seems to be related to the commit 62c68e7cee33 ("HID: ensure timely release of driver-allocated resources") but the commit itself seems to be correct.
Fix the issue by dropping the 'hid_dev->driver' override and using hid_register_driver()/hid_unregister_driver() instead. Alternatively, it would have been possible to rely on the default handling but HID_CONNECT_DEFAULT implies HID_CONNECT_HIDRAW and it doesn't seem to work for mousevsc as-is.
[ 6.1: context adjusted only - mousevsc_ll_driver is non-const in 6.1
because the hid_ll_driver constification (for-6.12/constify-rdesc, e.g. 054e0bd34577) is not present; the applied diff is identical to the upstream commit, no functional change ]
--- drivers/hid/hid-hyperv.c | 58 ++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-)
drivers/hid/hid-hyperv.c +41 -17
@@ -456,6 +456,25 @@ static int mousevsc_hid_raw_request(struct hid_device *hid,return 0 ; } +static int mousevsc_hid_probe (struct hid_device *hid_dev,const struct hid_device_id *id) +{ +int ret; + + ret =hid_parse (hid_dev); +if (ret) { +hid_err (hid_dev,"parse failed\n" ); +return ret; + } + + ret =hid_hw_start (hid_dev,HID_CONNECT_HIDINPUT |HID_CONNECT_HIDDEV ); +if (ret) { +hid_err (hid_dev,"hw start failed\n" ); +return ret; + } + +return 0 ; +} +static struct hid_ll_driver mousevsc_ll_driver = { .parse = mousevsc_hid_parse, .open = mousevsc_hid_open,
@@ -465,7 +484,16 @@ static struct hid_ll_driver mousevsc_ll_driver = { .raw_request = mousevsc_hid_raw_request, }; -static struct hid_driver mousevsc_hid_driver; +static const struct hid_device_id mousevsc_devices[] = { + {HID_DEVICE (BUS_VIRTUAL ,HID_GROUP_ANY ,0x045E ,0x0621 ) }, + { } +}; + +static struct hid_driver mousevsc_hid_driver = { + .name ="hid-hyperv" , + .id_table = mousevsc_devices, + .probe = mousevsc_hid_probe, +};static int mousevsc_probe (struct hv_device *device,const struct hv_vmbus_device_id *dev_id)
@@ -507,7 +535,6 @@ static int mousevsc_probe(struct hv_device *device, } hid_dev->ll_driver = &mousevsc_ll_driver; - hid_dev->driver = &mousevsc_hid_driver; hid_dev->bus =BUS_VIRTUAL ; hid_dev->vendor = input_dev->hid_dev_info.vendor; hid_dev->product = input_dev->hid_dev_info.product;
@@ -522,20 +549,6 @@ static int mousevsc_probe(struct hv_device *device,if (ret) goto probe_err2; - - ret =hid_parse (hid_dev); -if (ret) { -hid_err (hid_dev,"parse failed\n" ); - goto probe_err2; - } - - ret =hid_hw_start (hid_dev,HID_CONNECT_HIDINPUT |HID_CONNECT_HIDDEV ); - -if (ret) { -hid_err (hid_dev,"hw start failed\n" ); - goto probe_err2; - } -device_init_wakeup (&device->device, true); input_dev->connected = true;
@@ -615,12 +628,23 @@ static struct hv_driver mousevsc_drv = {static int __init mousevsc_init (void ) { -return vmbus_driver_register (&mousevsc_drv); +int ret; + + ret =hid_register_driver (&mousevsc_hid_driver); +if (ret) +return ret; + + ret =vmbus_driver_register (&mousevsc_drv); +if (ret) +hid_unregister_driver (&mousevsc_hid_driver); + +return ret; } static void __exit mousevsc_exit(void) {vmbus_driver_unregister (&mousevsc_drv); +hid_unregister_driver (&mousevsc_hid_driver); }MODULE_LICENSE ("GPL" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 799/982 start_kernel: Add __no_stack_protector function attribute
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: [email protected] <[email protected]>
[ Upstream commit 514ca14ed5444b911de59ed3381dfd195d99fe4b ]
Back during the discussion of
commit a9a3ed1eff36 ("x86: Fix early boot crash on gcc-10, third try") we discussed the need for a function attribute to control the omission of stack protectors on a per-function basis; at the time Clang had support for no_stack_protector but GCC did not. This was fixed in gcc-11. Now that the function attribute is available, let's start using it.
Callers of boot_init_stack_canary need to use this function attribute unless they're compiled with -fno-stack-protector, otherwise the canary stored in the stack slot of the caller will differ upon the call to boot_init_stack_canary. This will lead to a call to __stack_chk_fail() then panic.
[ Backport to 6.1.y: retain this tree's start_kernel() signature, which
predates its upstream __noreturn annotation, and add __no_stack_protector. ]
--- arch/powerpc/kernel/smp.c | 1 + include/linux/compiler_attributes.h | 12 ++++++++++++ init/main.c | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +1 -0
@@ -1608,6 +1608,7 @@ static void add_cpu_to_masks(int cpu) }/* Activate a secondary processor. */ +__no_stack_protector void start_secondary(void *unused) {unsigned int cpu =raw_smp_processor_id ();
include/linux/compiler_attributes.h +12 -0
@@ -277,6 +277,18 @@*/ #define __noreturn __attribute__((__noreturn__)) +/* +* Optional: only supported since GCC >= 11.1, clang >= 7.0. +* +* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fstack_005fprotector-function-attribute +* clang: https://clang.llvm.org/docs/AttributeReference.html#no-stack-protector-safebuffers +*/ +#if __has_attribute (__no_stack_protector__) +# define __no_stack_protector __attribute__((__no_stack_protector__)) +#else +# define __no_stack_protector +#endif +/* * Optional: not supported by gcc. * Optional: not supported by icc.
init/main.c +2 -1
@@ -908,7 +908,8 @@ static void __init print_unknown_bootoptions(void)memblock_free (unknown_options, len); } -asmlinkage __visible void __init __no_sanitize_address start_kernel(void) +asmlinkage __visible __init __no_sanitize_address __no_stack_protector +void start_kernel (void ) {char *command_line;char *after_dashes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 800/982 media: ipu-bridge: Fix null pointer deref on SSDB/PLD parsing warnings
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
[ Upstream commit 284be5693163343e1cf17c03917eecd1d6681bcf ]
When ipu_bridge_parse_rotation() and ipu_bridge_parse_orientation() run sensor->adev is not set yet.
So if either of the dev_warn() calls about unknown values are hit this will lead to a NULL pointer deref.
Set sensor->adev earlier, with a borrowed ref to avoid making unrolling on errors harder, to fix this.
[ Backport to 6.1.y: apply the sensor adev assignment in this tree's
older ipu3/cio2-bridge.c and cio2_bridge_connect_sensor(). ]
--- drivers/media/pci/intel/ipu3/cio2-bridge.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/pci/intel/ipu3/cio2-bridge.c +5 -0
@@ -280,6 +280,11 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, } sensor = &bridge->sensors[bridge->n_sensors]; +/* +* Borrow our adev ref to the sensor for now, on success +* acpi_dev_get(adev) is done further below. +*/ + sensor->adev = adev;strscpy (sensor->name, cfg->hid,sizeof (sensor->name)); ret = cio2_bridge_read_acpi_buffer(adev, "SSDB",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 801/982 net/mlx5e: TC, Fix internal port memory leak
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianbo Liu <[email protected]>
[ Upstream commit ac5da544a3c2047cbfd715acd9cec8380d7fe5c6 ]
The flow rule can be splited, and the extra post_act rules are added to post_act table. It's possible to trigger memleak when the rule forwards packets from internal port and over tunnel, in the case that, for example, CT 'new' state offload is allowed. As int_port object is assigned to the flow attribute of post_act rule, and its refcnt is incremented by mlx5e_tc_int_port_get(), but mlx5e_tc_int_port_put() is not called, the refcnt is never decremented, then int_port is never freed.
The kmemleak reports the following error:
unreferenced object 0xffff888128204b80 (size 64):
comm "handler20", pid 50121, jiffies 4296973009 (age 642.932s) hex dump (first 32 bytes):
01 00 00 00 19 00 00 00 03 f0 00 00 04 00 00 00 ................
98 77 67 41 81 88 ff ff 98 77 67 41 81 88 ff ff .wgA.....wgA....
backtrace:
[<00000000e992680d>] kmalloc_trace+0x27/0x120
[<000000009e945a98>] mlx5e_tc_int_port_get+0x3f3/0xe20 [mlx5_core]
[<0000000035a537f0>] mlx5e_tc_add_fdb_flow+0x473/0xcf0 [mlx5_core]
[<0000000070c2cec6>] __mlx5e_add_fdb_flow+0x7cf/0xe90 [mlx5_core]
[<000000005cc84048>] mlx5e_configure_flower+0xd40/0x4c40 [mlx5_core]
[<000000004f8a2031>] mlx5e_rep_indr_offload.isra.0+0x10e/0x1c0 [mlx5_core]
[<000000007df797dc>] mlx5e_rep_indr_setup_tc_cb+0x90/0x130 [mlx5_core]
[<0000000016c15cc3>] tc_setup_cb_add+0x1cf/0x410
[<00000000a63305b4>] fl_hw_replace_filter+0x38f/0x670 [cls_flower]
[<000000008bc9e77c>] fl_change+0x1fd5/0x4430 [cls_flower]
[<00000000e7f766e4>] tc_new_tfilter+0x867/0x2010
[<00000000e101c0ef>] rtnetlink_rcv_msg+0x6fc/0x9f0
[<00000000e1111d44>] netlink_rcv_skb+0x12c/0x360
[<0000000082dd6c8b>] netlink_unicast+0x438/0x710
[<00000000fc568f70>] netlink_sendmsg+0x794/0xc50
[<0000000016e92590>] sock_sendmsg+0xc5/0x190So fix this by moving int_port cleanup code to the flow attribute free helper, which is used by all the attribute free cases.
[ Backport to 6.1.y: this tree already releases the primary flow-attribute
references in mlx5e_tc_del_fdb_flow() and lacks mlx5_free_flow_attr_actions(); release only cloned post-action attribute references from the corresponding free_flow_post_acts() cleanup. ]
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +11 -0
@@ -3692,6 +3692,7 @@ free_flow_post_acts(struct mlx5e_tc_flow *flow) {struct mlx5_core_dev *counter_dev =get_flow_counter_dev (flow);struct mlx5e_post_act *post_act =get_post_action (flow->priv); +struct mlx5_esw_flow_attr *esw_attr;struct mlx5_flow_attr *attr, *tmp;bool vf_tun;
@@ -3713,6 +3714,16 @@ free_flow_post_acts(struct mlx5e_tc_flow *flow)mlx5_modify_header_dealloc (flow->priv->mdev, attr->modify_hdr); } +if (mlx5e_is_eswitch_flow (flow)) { + esw_attr = attr->esw_attr; +if (esw_attr->int_port) +mlx5e_tc_int_port_put (mlx5e_get_int_port_priv (flow->priv), + esw_attr->int_port); +if (esw_attr->dest_int_port) +mlx5e_tc_int_port_put (mlx5e_get_int_port_priv (flow->priv), + esw_attr->dest_int_port); + } +list_del (&attr->list);kvfree (attr->parse_attr);kfree (attr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 802/982 sh: push-switch: Reorder cleanup operations to avoid use-after-free bug
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Duoming Zhou <[email protected]>
[ Upstream commit 246f80a0b17f8f582b2c0996db02998239057c65 ]
The original code puts flush_work() before timer_shutdown_sync() in switch_drv_remove(). Although we use flush_work() to stop the worker, it could be rescheduled in switch_timer(). As a result, a use-after-free bug can occur. The details are shown below:
(cpu 0) | (cpu 1)
switch_drv_remove() |
flush_work() |
... | switch_timer // timer
| schedule_work(&psw->work)
timer_shutdown_sync() |
... | switch_work_handler // worker
kfree(psw) // free |
| psw->state = 0 // useThis patch puts timer_shutdown_sync() before flush_work() to mitigate the bugs. As a result, the worker and timer will be stopped safely before the deallocate operations.
[ Backport to 6.1.y: use timer_shutdown_sync(), already available here,
so the timer cannot rearm before the queued work is flushed. ]
--- arch/sh/drivers/push-switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/drivers/push-switch.c +1 -1
@@ -101,8 +101,8 @@ static int switch_drv_remove(struct platform_device *pdev)device_remove_file (&pdev->dev, &dev_attr_switch);platform_set_drvdata (pdev,NULL ); +timer_shutdown_sync (&psw->debounce);flush_work (&psw->work); -del_timer_sync (&psw->debounce);free_irq (irq, pdev);kfree (psw);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 803/982 wifi: rtw88: delete timer and free skb queue when unloading
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Antipov <[email protected]>
[ Upstream commit 634fcbcaa4062db39aeb5ac6ed1bc1feb8dd5216 ]
Fix possible crash and memory leak on driver unload by deleting TX purge timer and freeing C2H queue in 'rtw_core_deinit()', shrink critical section in the latter by freeing COEX queue out of TX report lock scope.
[ Backport to 6.1.y: the source change is unchanged; only hunk locations
in rtw_core_deinit() differ. The target-only Fixes trailer names the initial rtw88 driver commit, which introduced this lifetime. ]
--- drivers/net/wireless/realtek/rtw88/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/main.c +3 -1
@@ -2135,10 +2135,12 @@ void rtw_core_deinit(struct rtw_dev *rtwdev)release_firmware (wow_fw->firmware);destroy_workqueue (rtwdev->tx_wq); +timer_delete_sync (&rtwdev->tx_report.purge_timer);spin_lock_irqsave (&rtwdev->tx_report.q_lock, flags);ieee80211_purge_tx_queue (rtwdev->hw, &rtwdev->tx_report.queue); -skb_queue_purge (&rtwdev->coex.queue);spin_unlock_irqrestore (&rtwdev->tx_report.q_lock, flags); +skb_queue_purge (&rtwdev->coex.queue); +skb_queue_purge (&rtwdev->c2h_queue);list_for_each_entry_safe (rsvd_pkt, tmp, &rtwdev->rsvd_page_list, build_list) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 804/982 btrfs: insert tree mod log move in push_node_left
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boris Burkov <[email protected]>
[ Upstream commit 5cead5422a0e3d13b0bcee986c0f5c4ebb94100b ]
There is a fairly unlikely race condition in tree mod log rewind that can result in a kernel panic which has the following trace:
[530.569] BTRFS critical (device sda3): unable to find logical 0 length 4096 [530.585] BTRFS critical (device sda3): unable to find logical 0 length 4096 [530.602] BUG: kernel NULL pointer dereference, address: 0000000000000002 [530.618] #PF: supervisor read access in kernel mode [530.629] #PF: error_code(0x0000) - not-present page [530.641] PGD 0 P4D 0 [530.647] Oops: 0000 [#1] SMP [530.654] CPU: 30 PID: 398973 Comm: below Kdump: loaded Tainted: G S O K 5.12.0-0_fbk13_clang_7455_gb24de3bdb045 #1 [530.680] Hardware name: Quanta Mono Lake-M.2 SATA 1HY9U9Z001G/Mono Lake-M.2 SATA, BIOS F20_3A15 08/16/2017 [530.703] RIP: 0010:__btrfs_map_block+0xaa/0xd00 [530.755] RSP: 0018:ffffc9002c2f7600 EFLAGS: 00010246 [530.767] RAX: ffffffffffffffea RBX: ffff888292e41000 RCX: f2702d8b8be15100 [530.784] RDX: ffff88885fda6fb8 RSI: ffff88885fd973c8 RDI: ffff88885fd973c8 [530.800] RBP: ffff888292e410d0 R08: ffffffff82fd7fd0 R09: 00000000fffeffff [530.816] R10: ffffffff82e57fd0 R11: ffffffff82e57d70 R12: 0000000000000000 [530.832] R13: 0000000000001000 R14: 0000000000001000 R15: ffffc9002c2f76f0 [530.848] FS: 00007f38d64af000(0000) GS:ffff88885fd80000(0000) knlGS:0000000000000000 [530.866] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [530.880] CR2: 0000000000000002 CR3: 00000002b6770004 CR4: 00000000003706e0 [530.896] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [530.912] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [530.928] Call Trace: [530.934] ? btrfs_printk+0x13b/0x18c [530.943] ? btrfs_bio_counter_inc_blocked+0x3d/0x130 [530.955] btrfs_map_bio+0x75/0x330 [530.963] ? kmem_cache_alloc+0x12a/0x2d0 [530.973] ? btrfs_submit_metadata_bio+0x63/0x100 [530.984] btrfs_submit_metadata_bio+0xa4/0x100 [530.995] submit_extent_page+0x30f/0x360 [531.004] read_extent_buffer_pages+0x49e/0x6d0 [531.015] ? submit_extent_page+0x360/0x360 [531.025] btree_read_extent_buffer_pages+0x5f/0x150 [531.037] read_tree_block+0x37/0x60 [531.046] read_block_for_search+0x18b/0x410 [531.056] btrfs_search_old_slot+0x198/0x2f0 [531.066] resolve_indirect_ref+0xfe/0x6f0 [531.076] ? ulist_alloc+0x31/0x60 [531.084] ? kmem_cache_alloc_trace+0x12e/0x2b0 [531.095] find_parent_nodes+0x720/0x1830 [531.105] ? ulist_alloc+0x10/0x60 [531.113] iterate_extent_inodes+0xea/0x370 [531.123] ? btrfs_previous_extent_item+0x8f/0x110 [531.134] ? btrfs_search_path_in_tree+0x240/0x240 [531.146] iterate_inodes_from_logical+0x98/0xd0 [531.157] ? btrfs_search_path_in_tree+0x240/0x240 [531.168] btrfs_ioctl_logical_to_ino+0xd9/0x180 [531.179] btrfs_ioctl+0xe2/0x2eb0
This occurs when logical inode resolution takes a tree mod log sequence number, and then while backref walking hits a rewind on a busy node which has the following sequence of tree mod log operations (numbers filled in from a specific example, but they are somewhat arbitrary)
REMOVE_WHILE_FREEING slot 532
REMOVE_WHILE_FREEING slot 531
REMOVE_WHILE_FREEING slot 530
...
REMOVE_WHILE_FREEING slot 0
REMOVE slot 455
REMOVE slot 454
REMOVE slot 453
...
REMOVE slot 0
ADD slot 455
ADD slot 454
ADD slot 453
...
ADD slot 0
MOVE src slot 0 -> dst slot 456 nritems 533
REMOVE slot 455
REMOVE slot 454
REMOVE slot 453
...
REMOVE slot 0
When this sequence gets applied via btrfs_tree_mod_log_rewind, it allocates a fresh rewind eb, and first inserts the correct key info for the 533 elements, then overwrites the first 456 of them, then decrements the count by 456 via the add ops, then rewinds the move by doing a memmove from 456:988->0:532. We have never written anything past 532, so that memmove writes garbage into the 0:532 range. In practice, this results in a lot of fully 0 keys. The rewind then puts valid keys into slots 0:455 with the last removes, but 456:532 are still invalid.
When search_old_slot uses this eb, if it uses one of those invalid slots, it can then read the extent buffer and issue a bio for offset 0 which ultimately panics looking up extent mappings.
This bad tree mod log sequence gets generated when the node balancing code happens to do a balance_node_right followed by a push_node_left while logging in the tree mod log. Illustrated for ebs L and R (left and right):
L R
start:
[XXX|YYY|...] [ZZZ|...|...]
balance_node_right:
[XXX|YYY|...] [...|ZZZ|...] move Z to make room for Y [XXX|...|...] [YYY|ZZZ|...] copy Y from L to R push_node_left: [XXX|YYY|...] [...|ZZZ|...] copy Y from R to L [XXX|YYY|...] [ZZZ|...|...] move Z into emptied space (NOT LOGGED!)
This is because balance_node_right logs a move, but push_node_left explicitly doesn't. That is because logging the move would remove the overwritten src < dst range in the right eb, which was already logged when we called btrfs_tree_mod_log_eb_copy. The correct sequence would include a move from 456:988 to 0:532 after remove 0:455 and before removing 0:532. Reversing that sequence would entail creating keys for 0:532, then moving those keys out to 456:988, then creating more keys for 0:455.
i.e.,
REMOVE_WHILE_FREEING slot 532
REMOVE_WHILE_FREEING slot 531
REMOVE_WHILE_FREEING slot 530
...
REMOVE_WHILE_FREEING slot 0
MOVE src slot 456 -> dst slot 0 nritems 533
REMOVE slot 455
REMOVE slot 454
REMOVE slot 453
...
REMOVE slot 0
ADD slot 455
ADD slot 454
ADD slot 453
...
ADD slot 0
MOVE src slot 0 -> dst slot 456 nritems 533
REMOVE slot 455
REMOVE slot 454
REMOVE slot 453
...
REMOVE slot 0
Fix this to log the move but avoid the double remove by putting all the logging logic in btrfs_tree_mod_log_eb_copy which has enough information to detect these cases and properly log moves, removes, and adds. Leave btrfs_tree_mod_log_insert_move to handle insert_ptr and delete_ptr's tree mod logging.
(Un)fortunately, this is quite difficult to reproduce, and I was only able to reproduce it by adding sleeps in btrfs_search_old_slot that would encourage more log rewinding during ino_to_logical ioctls. I was able to hit the warning in the previous patch in the series without the fix quite quickly, but not after this patch.
[ Backport to 6.1.y: retain the older btrfs_node_key_ptr_offset() call
signature and pass GFP_NOFS to alloc_tree_mod_elem(). The tree-mod-log ordering change is otherwise identical to upstream. ]
--- fs/btrfs/ctree.c | 10 +++--- fs/btrfs/tree-mod-log.c | 73 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 13 deletions(-)
fs/btrfs/ctree.c +6 -4
@@ -2653,8 +2653,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,if (push_items < src_nritems) {/* -* Don't call btrfs_tree_mod_log_insert_move() here, key removal -* was already fully logged by btrfs_tree_mod_log_eb_copy() above. +* btrfs_tree_mod_log_eb_copy handles logging the move, so we +* don't need to do an explicit tree mod log operation for it. */ memmove_extent_buffer(src, btrfs_node_key_ptr_offset(0), btrfs_node_key_ptr_offset(push_items),
@@ -2715,8 +2715,10 @@ static int balance_node_right(struct btrfs_trans_handle *trans,btrfs_abort_transaction (trans, ret);return ret; } - ret =btrfs_tree_mod_log_insert_move (dst, push_items,0 , dst_nritems); -BUG_ON (ret <0 ); +/* +* btrfs_tree_mod_log_eb_copy handles logging the move, so we don't +* need to do an explicit tree mod log operation for it. +*/ memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(push_items), btrfs_node_key_ptr_offset(0), (dst_nritems) *
fs/btrfs/tree-mod-log.c +64 -9
118 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 805/982 scsi: hisi_sas: Grab sas_dev lock when traversing the members of sas_dev.list
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xingui Yang <[email protected]>
[ Upstream commit 71fb36b5ff113a7674710b9d6063241eada84ff7 ]
When freeing slots in function slot_complete_v3_hw(), it is possible that sas_dev.list is being traversed elsewhere, and it may trigger a NULL pointer exception, such as follows:
==>cq thread ==>scsi_eh_6
==>scsi_error_handler()
==>sas_eh_handle_sas_errors()
==>sas_scsi_find_task()
==>lldd_abort_task()
==>slot_complete_v3_hw() ==>hisi_sas_abort_task()
==>hisi_sas_slot_task_free() ==>dereg_device_v3_hw()
==>list_del_init() ==>list_for_each_entry_safe()[ 7165.434918] sas: Enter sas_scsi_recover_host busy: 32 failed: 32 [ 7165.434926] sas: trying to find task 0x00000000769b5ba5 [ 7165.434927] sas: sas_scsi_find_task: aborting task 0x00000000769b5ba5 [ 7165.434940] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(00000000769b5ba5) aborted [ 7165.434964] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(00000000c9f7aa07) ignored [ 7165.434965] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(00000000e2a1cf01) ignored [ 7165.434968] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 7165.434972] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(0000000022d52d93) ignored [ 7165.434975] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(0000000066a7516c) ignored [ 7165.434976] Mem abort info: [ 7165.434982] ESR = 0x96000004 [ 7165.434991] Exception class = DABT (current EL), IL = 32 bits [ 7165.434992] SET = 0, FnV = 0 [ 7165.434993] EA = 0, S1PTW = 0 [ 7165.434994] Data abort info: [ 7165.434994] ISV = 0, ISS = 0x00000004 [ 7165.434995] CM = 0, WnR = 0 [ 7165.434997] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000f29543f2 [ 7165.434998] [0000000000000000] pgd=0000000000000000 [ 7165.435003] Internal error: Oops: 96000004 [#1] SMP [ 7165.439863] Process scsi_eh_6 (pid: 4109, stack limit = 0x00000000c43818d5) [ 7165.468862] pstate: 00c00009 (nzcv daif +PAN +UAO) [ 7165.473637] pc : dereg_device_v3_hw+0x68/0xa8 [hisi_sas_v3_hw] [ 7165.479443] lr : dereg_device_v3_hw+0x2c/0xa8 [hisi_sas_v3_hw] [ 7165.485247] sp : ffff00001d623bc0 [ 7165.488546] x29: ffff00001d623bc0 x28: ffffa027d03b9508 [ 7165.493835] x27: ffff80278ed50af0 x26: ffffa027dd31e0a8 [ 7165.499123] x25: ffffa027d9b27f88 x24: ffffa027d9b209f8 [ 7165.504411] x23: ffffa027c45b0d60 x22: ffff80278ec07c00 [ 7165.509700] x21: 0000000000000008 x20: ffffa027d9b209f8 [ 7165.514988] x19: ffffa027d9b27f88 x18: ffffffffffffffff [ 7165.520276] x17: 0000000000000000 x16: 0000000000000000 [ 7165.525564] x15: ffff0000091d9708 x14: ffff0000093b7dc8 [ 7165.530852] x13: ffff0000093b7a23 x12: 6e7265746e692067 [ 7165.536140] x11: 0000000000000000 x10: 0000000000000bb0 [ 7165.541429] x9 : ffff00001d6238f0 x8 : ffffa027d877af00 [ 7165.546718] x7 : ffffa027d6329600 x6 : ffff7e809f58ca00 [ 7165.552006] x5 : 0000000000001f8a x4 : 000000000000088e [ 7165.557295] x3 : ffffa027d9b27fa8 x2 : 0000000000000000 [ 7165.562583] x1 : 0000000000000000 x0 : 000000003000188e [ 7165.567872] Call trace: [ 7165.570309] dereg_device_v3_hw+0x68/0xa8 [hisi_sas_v3_hw] [ 7165.575775] hisi_sas_abort_task+0x248/0x358 [hisi_sas_main] [ 7165.581415] sas_eh_handle_sas_errors+0x258/0x8e0 [libsas] [ 7165.586876] sas_scsi_recover_host+0x134/0x458 [libsas] [ 7165.592082] scsi_error_handler+0xb4/0x488 [ 7165.596163] kthread+0x134/0x138 [ 7165.599380] ret_from_fork+0x10/0x18 [ 7165.602940] Code: d5033e9f b9000040 aa0103e2 eb03003f (f9400021) [ 7165.609004] kernel fault(0x1) notification starting on CPU 75 [ 7165.700728] ---[ end trace fc042cbbea224efc ]--- [ 7165.705326] Kernel panic - not syncing: Fatal exception
To fix the issue, grab sas_dev lock when traversing the members of sas_dev.list in dereg_device_v3_hw() and hisi_sas_release_tasks() to avoid concurrency of adding and deleting member. When function hisi_sas_release_tasks() calls hisi_sas_do_release_task() to free slot, the lock cannot be grabbed again in hisi_sas_slot_task_free(), then a bool parameter need_lock is added.
[ Backport to 6.1.y: omit the SATA NCQ-error call-site update because that
path does not call hisi_sas_do_release_task() in 6.1.y. The list locking change is otherwise identical to upstream. ]
--- drivers/scsi/hisi_sas/hisi_sas.h | 3 ++- drivers/scsi/hisi_sas/hisi_sas_main.c | 23 +++++++++++++++-------- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 2 +- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 2 +- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 4 +++- 5 files changed, 22 insertions(+), 12 deletions(-)
drivers/scsi/hisi_sas/hisi_sas.h +2 -1
@@ -652,7 +652,8 @@ extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy,extern void hisi_sas_phy_bcast (struct hisi_sas_phy *phy);extern void hisi_sas_slot_task_free (struct hisi_hba *hisi_hba,struct sas_task *task, -struct hisi_sas_slot *slot); +struct hisi_sas_slot *slot, +bool need_lock);extern void hisi_sas_init_mem (struct hisi_hba *hisi_hba);extern void hisi_sas_rst_work_handler (struct work_struct *work);extern void hisi_sas_sync_rst_work_handler (struct work_struct *work);
drivers/scsi/hisi_sas/hisi_sas_main.c +15 -8
@@ -205,7 +205,7 @@ static int hisi_sas_slot_index_alloc(struct hisi_hba *hisi_hba, }void hisi_sas_slot_task_free (struct hisi_hba *hisi_hba,struct sas_task *task, -struct hisi_sas_slot *slot) +struct hisi_sas_slot *slot,bool need_lock) {int device_id = slot->device_id;struct hisi_sas_device *sas_dev = &hisi_hba->devices[device_id];
@@ -239,9 +239,13 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, } } -spin_lock (&sas_dev->lock); -list_del_init (&slot->entry); -spin_unlock (&sas_dev->lock); +if (need_lock) { +spin_lock (&sas_dev->lock); +list_del_init (&slot->entry); +spin_unlock (&sas_dev->lock); + }else { +list_del_init (&slot->entry); + }memset (slot,0 , offsetof(struct hisi_sas_slot , buf));
@@ -1059,7 +1063,7 @@ static void hisi_sas_port_notify_formed(struct asd_sas_phy *sas_phy) }static void hisi_sas_do_release_task (struct hisi_hba *hisi_hba,struct sas_task *task, -struct hisi_sas_slot *slot) +struct hisi_sas_slot *slot,bool need_lock) {if (task) {unsigned long flags;
@@ -1076,7 +1080,7 @@ static void hisi_sas_do_release_task(struct hisi_hba *hisi_hba, struct sas_taskspin_unlock_irqrestore (&task->task_state_lock, flags); } -hisi_sas_slot_task_free (hisi_hba, task, slot); +hisi_sas_slot_task_free (hisi_hba, task, slot, need_lock); } static void hisi_sas_release_task(struct hisi_hba *hisi_hba,
@@ -1085,8 +1089,11 @@ static void hisi_sas_release_task(struct hisi_hba *hisi_hba,struct hisi_sas_slot *slot, *slot2;struct hisi_sas_device *sas_dev = device->lldd_dev; +spin_lock (&sas_dev->lock);list_for_each_entry_safe (slot, slot2, &sas_dev->list, entry) -hisi_sas_do_release_task (hisi_hba, slot->task, slot); +hisi_sas_do_release_task (hisi_hba, slot->task, slot, false); + +spin_unlock (&sas_dev->lock); }void hisi_sas_release_tasks (struct hisi_hba *hisi_hba)
@@ -1620,7 +1627,7 @@ static int hisi_sas_abort_task(struct sas_task *task)*/ if (rc ==TMF_RESP_FUNC_COMPLETE && rc2 !=TMF_RESP_FUNC_SUCC ) {if (task->lldd_task) -hisi_sas_do_release_task (hisi_hba, task, slot); +hisi_sas_do_release_task (hisi_hba, task, slot, true); } }else if (task->task_proto &SAS_PROTOCOL_SATA || task->task_proto &SAS_PROTOCOL_STP ) {
drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +1 -1
@@ -1310,7 +1310,7 @@ static void slot_complete_v1_hw(struct hisi_hba *hisi_hba, } out: -hisi_sas_slot_task_free (hisi_hba, task, slot); +hisi_sas_slot_task_free (hisi_hba, task, slot, true);if (task->task_done) task->task_done (task);
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +1 -1
@@ -2473,7 +2473,7 @@ static void slot_complete_v2_hw(struct hisi_hba *hisi_hba, } task->task_state_flags |=SAS_TASK_STATE_DONE ;spin_unlock_irqrestore (&task->task_state_lock, flags); -hisi_sas_slot_task_free (hisi_hba, task, slot); +hisi_sas_slot_task_free (hisi_hba, task, slot, true);if (!is_internal && (task->task_proto !=SAS_PROTOCOL_SMP )) {spin_lock_irqsave (&device->done_lock, flags);
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +3 -1
@@ -873,6 +873,7 @@ static void dereg_device_v3_hw(struct hisi_hba *hisi_hba, cfg_abt_set_query_iptt =hisi_sas_read32 (hisi_hba,CFG_ABT_SET_QUERY_IPTT ); +spin_lock (&sas_dev->lock);list_for_each_entry_safe (slot, slot2, &sas_dev->list, entry) { cfg_abt_set_query_iptt &= ~CFG_SET_ABORTED_IPTT_MSK ; cfg_abt_set_query_iptt |= (1 << CFG_SET_ABORTED_EN_OFF) |
@@ -880,6 +881,7 @@ static void dereg_device_v3_hw(struct hisi_hba *hisi_hba,hisi_sas_write32 (hisi_hba,CFG_ABT_SET_QUERY_IPTT , cfg_abt_set_query_iptt); } +spin_unlock (&sas_dev->lock); cfg_abt_set_query_iptt &= ~(1 <<CFG_SET_ABORTED_EN_OFF );hisi_sas_write32 (hisi_hba,CFG_ABT_SET_QUERY_IPTT , cfg_abt_set_query_iptt);
@@ -2364,7 +2366,7 @@ static void slot_complete_v3_hw(struct hisi_hba *hisi_hba, } task->task_state_flags |=SAS_TASK_STATE_DONE ;spin_unlock_irqrestore (&task->task_state_lock, flags); -hisi_sas_slot_task_free (hisi_hba, task, slot); +hisi_sas_slot_task_free (hisi_hba, task, slot, true);if (!is_internal && (task->task_proto !=SAS_PROTOCOL_SMP )) {spin_lock_irqsave (&device->done_lock, flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 806/982 KVM: s390: Fix IRQ injection with SIGP Stop and Store Status
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudio Imbrenda <[email protected]>
[ Upstream commit d343407b728a80b74be3c24b59f15e60289ea527 ]
When __inject_sigp_stop() is called for a Stop and Store Status operation, if the vCPU is running, the interrupt is marked as pending and the status is stored by the thread performing the KVM_RUN IOCTL.
If the vCPU is already stopped, the status is stored immediately.
Storing the status means writing into userspace, which might fault, and __inject_sigp_stop() is called from do_inject_vcpu() which in turn is always called holding a spinlock, which is obviously an issue.
Fix this by returning -EWOULDBLOCK from __inject_sigp_stop(), and adding a bool flag to indicate whether a store status is needed. The callers of do_inject_vcpu() are modified to pass the pointer to the bool flag; whenever a Store Status operation is needed, the callers can now perform it outside the spinlock.
Opportunistically refactor kvm_s390_set_irq_state() to use scoped_guard() and __free().
Message-ID: <[email protected]>
--- arch/s390/kvm/interrupt.c | 70 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 32 deletions(-)
arch/s390/kvm/interrupt.c +38 -32
@@ -1582,23 +1582,21 @@ static int __inject_set_prefix(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) }#define KVM_S390_STOP_SUPP_FLAGS (KVM_S390_STOP_FLAG_STORE_STATUS) -static int __inject_sigp_stop (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) +static int __inject_sigp_stop (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq,bool *storestatus) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;struct kvm_s390_stop_info *stop = &li->irq.stop; -int rc =0 ; vcpu->stat.inject_stop_signal++;trace_kvm_s390_inject_vcpu (vcpu->vcpu_id,KVM_S390_SIGP_STOP ,0 ,0 );if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS )return -EINVAL ; -if (is_vcpu_stopped (vcpu)) { -if (irq->u.stop.flags &KVM_S390_STOP_FLAG_STORE_STATUS ) - rc =kvm_s390_store_status_unloaded (vcpu, -KVM_S390_STORE_STATUS_NOADDR ); -return rc; +if (!(irq->u.stop.flags &KVM_S390_STOP_FLAG_STORE_STATUS )) +return 0 ; + *storestatus = true; +return -EWOULDBLOCK ; }if (test_and_set_bit (IRQ_PEND_SIGP_STOP , &li->pending_irqs))
@@ -2138,7 +2136,7 @@ void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu)spin_unlock (&li->lock); } -static int do_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) +static int do_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq,bool *storestatus) {int rc;
@@ -2150,7 +2148,7 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) rc =__inject_set_prefix (vcpu, irq);break ;case KVM_S390_SIGP_STOP : - rc =__inject_sigp_stop (vcpu, irq); + rc =__inject_sigp_stop (vcpu, irq, storestatus);break ;case KVM_S390_RESTART : rc =__inject_sigp_restart (vcpu);
@@ -2186,11 +2184,16 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)int kvm_s390_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; +bool storestatus = false;int rc;spin_lock (&li->lock); - rc =do_inject_vcpu (vcpu, irq); + rc =do_inject_vcpu (vcpu, irq, &storestatus);spin_unlock (&li->lock); + +if (rc == -EWOULDBLOCK && storestatus) + rc =kvm_s390_store_status_unloaded (vcpu,KVM_S390_STORE_STATUS_NOADDR ); +if (!rc)kvm_s390_vcpu_wakeup (vcpu);return rc;
@@ -2926,7 +2929,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,int kvm_s390_set_irq_state (struct kvm_vcpu *vcpu,void __user *irqstate,int len) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; -struct kvm_s390_irq *buf; + struct kvm_s390_irq *buf __free(kvfree) = NULL; +bool tmp, storestatus = false;int r =0 ;int n;
@@ -2934,31 +2938,33 @@ int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, void __user *irqstate, int lenif (!buf)return -ENOMEM ; -if (copy_from_user ((void *) buf, irqstate, len)) { - r = -EFAULT ; - goto out_free; - } +if (copy_from_user ((void *)buf, irqstate, len)) +return -EFAULT ; -/* -* Don't allow setting the interrupt state -* when there are already interrupts pending -*/ -spin_lock (&li->lock); -if (li->pending_irqs) { - r = -EBUSY ; - goto out_unlock; - } + scoped_guard(spinlock, &li->lock) { +/* +* Don't allow setting the interrupt state +* when there are already interrupts pending +*/ +if (li->pending_irqs) +return -EBUSY ; -for (n =0 ; n < len /sizeof (*buf); n++) { - r =do_inject_vcpu (vcpu, &buf[n]); -if (r) -break ; +for (n =0 ; n < len /sizeof (*buf); n++) { + tmp = false; + r =do_inject_vcpu (vcpu, &buf[n], &tmp); +if (r == -EWOULDBLOCK && tmp) { + storestatus = true; + r =0 ; + } +if (r) +break ; + } } -out_unlock: -spin_unlock (&li->lock); -out_free: -vfree (buf); +if (storestatus) { + n =kvm_s390_store_status_unloaded (vcpu,KVM_S390_STORE_STATUS_NOADDR ); +return r ? r : n; + }return r; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 807/982 bpf: Fix bpf_skb_change_tail wrt csum partial skbs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 3b55f350c68a0aceff108f47f9d31f47ebffaf7b ]
Cilium generates ICMP "frag needed" replies from BPF when a LB DSR packet exceeds the egress MTU. The reply is built by first trimming the packet down to target size via bpf_skb_change_tail(), and then pushing the ICMP error headers in front of it.
The trim is rejected for skbs which carry a checksum offload, e.g. TCP packets aggregated by GRO on ingress where tcp_gro_complete() leaves the skb as CHECKSUM_PARTIAL. __bpf_skb_min_len() raises the minimum length to the end of the L4 checksum field, so a trim to 42 bytes bails out with -EINVAL given a min_len of 52 in this case, and due to that the ICMP generator fails. This is not the case if GRO is turned off.
Fix this bpf_skb_change_tail() restriction and drop the checksum offload when the new length no longer covers the checksum field. The BPF program rewrites the skb into an ICMP error and computes the checksum itself anyway.
--- net/core/filter.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/core/filter.c +5 -6
@@ -3772,12 +3772,6 @@ static u32 __bpf_skb_min_len(const struct sk_buff *skb)if (offset >0 ) min_len = offset; } -if (skb->ip_summed ==CHECKSUM_PARTIAL ) { - offset =skb_checksum_start_offset (skb) + - skb->csum_offset +sizeof (__sum16); -if (offset >0 ) - min_len = offset; - }return min_len; }
@@ -3794,6 +3788,11 @@ static int bpf_skb_grow_rcsum(struct sk_buff *skb, unsigned int new_len)static int bpf_skb_trim_rcsum (struct sk_buff *skb,unsigned int new_len) { +if (skb->ip_summed ==CHECKSUM_PARTIAL && + new_len <skb_checksum_start_offset (skb) + skb->csum_offset + +sizeof (__sum16)) + skb->ip_summed =CHECKSUM_NONE ; +return __skb_trim_rcsum (skb, new_len); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 808/982 bpf: Disallow bpf_skb_pull_data() for LWT_SEG6LOCAL
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit e4a62833adff6ef0fe7c0b90393204fe3c26b5c5 ]
An LWT_SEG6LOCAL program can invalidate its cached SRH with bpf_lwt_seg6_adjust_srh() and then call bpf_skb_pull_data(). The latter may reallocate skb->head, leaving the per-CPU SRH pointer dangling. Post-program SRH validation then writes through that pointer.
Disallow bpf_skb_pull_data() for LWT_SEG6LOCAL programs so the verifier rejects this unsafe helper combination. Other LWT program types continue to expose the helper through lwt_out_func_proto().
--- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/filter.c +2 -0
@@ -8535,6 +8535,8 @@ static const struct bpf_func_proto * lwt_seg6local_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { switch (func_id) { + case BPF_FUNC_skb_pull_data: + return NULL;#if IS_ENABLED (CONFIG_IPV6_SEG6_BPF )case BPF_FUNC_lwt_seg6_store_bytes:return &bpf_lwt_seg6_store_bytes_proto;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 809/982 selftests/ftrace: Fix unique symbol check in kprobe_non_uniq_symbol.tc
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Schnelle <[email protected]>
[ Upstream commit d22c3e0088e85be8131f7a9283f759cdbb20726d ]
The current regex also matches symbols in modules, which makes the test fail on s390 where name_show is present only once in the kernel, but also multiple times in modules:
000001b1401cdc20 t name_show000001b0c05e6c40 t name_show [mdev]000001b0c0495f30 t name_show [i2c_core]
Fix this by changing the regular expression to only match the function name.
--- .../selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +1 -1
@@ -6,7 +6,7 @@ SYMBOL='name_show' # We skip this test on kernel where SYMBOL is unique or does not exist. -if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}" /proc/kallsyms)" -le '1' ]; then +if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}$" /proc/kallsyms)" -le '1' ]; then exit_unsupported fi
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 810/982 bpf: support access variable length array of integer type
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Zhou <[email protected]>
[ Upstream commit 2569c7b8726fc06d946a4f999fb1be15b68f3f3c ]
After this commit:
bpf: Support variable length array in tracing programs (9c5f8a1008a1) Trace programs can access variable length array, but for structure type. This patch adds support for integer type.
Example:
Hook load_balance
struct sched_domain {
...
unsigned long span[];
}The access: sd->span[0].
Stable-dep-of: b0b3dc665296 ("bpf: Fix divide-by-zero in btf_struct_walk()")
--- kernel/bpf/btf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/bpf/btf.c +5 -3
@@ -5626,11 +5626,13 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,if (off < moff) goto error; -/* Only allow structure for now, can be relaxed for -* other types later. -*/ +/* allow structure and integer */ t =btf_type_skip_modifiers (btf, array_elem->type,NULL ); + +if (btf_type_is_int (t)) +return WALK_SCALAR ; +if (!btf_type_is_struct (t)) goto error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 811/982 bpf: Fix divide-by-zero in btf_struct_walk()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit b0b3dc66529676228cb938cbcad66920f735c223 ]
When an access goes past the struct and the last member is a flexible array, btf_struct_walk() folds the offset back into a single element with (off - moff) % t->size, but never checks that the element type has a size.
BTF takes an empty struct, so this in program BTF
/* event could be empty */
struct event {
#ifdef HAVE_TIMESTAMP
__u64 ts;
#endif
};
struct batch {
int nr;
struct event events[];
};divides by zero at prog load time. Getting there needs a PTR_TO_BTF_ID that is not MEM_ALLOC, e.g. a plain read of a local kptr stashed in a map from a sleepable program.
Oops: divide error: 0000 [#1] SMP KASAN PTI RIP: 0010:btf_struct_walk+0x53f/0x1570 Call Trace: <TASK> btf_struct_access+0x42a/0xcd0 check_ptr_to_btf_access+0x4dc/0x1160 check_mem_access+0x3a45/0x8740 check_load_mem+0x36a/0xd10 do_check_common+0x3ef0/0xb210 bpf_check+0x6d3b/0x8580 bpf_prog_load+0xf7c/0x2720 __sys_bpf+0xa83/0x3690 __x64_sys_bpf+0xc7/0x150 x64_sys_call+0x1f3f/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
Reject a zero-sized element type. The fixed array path in the same function already bails out on the same thing:
btf_struct_walk() ... /* skip empty array */ if (moff == mtrue_end) continue; msize /= total_nelems;
--- kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
@@ -5633,7 +5633,7 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,if (btf_type_is_int (t))return WALK_SCALAR ; -if (!btf_type_is_struct (t)) +if (!btf_type_is_struct (t) || !t->size) goto error; off = (off - moff) % t->size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 812/982 HID: elecom: fix bus type for M-XGL20DLBK
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oscar Priego Verdugo <[email protected]>
[ Upstream commit 8e2a4b458ad25e13422bb059758c30a6562aa9cf ]
The M-XGL20DLBK is matched as a USB device by hid-elecom, but its entry in hid_have_special_driver[] uses HID_BLUETOOTH_DEVICE.
This prevents the special-driver quirk entry from matching the USB device handled by hid-elecom. Use HID_USB_DEVICE there as well.
--- drivers/hid/hid-quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-quirks.c +1 -1
@@ -404,7 +404,7 @@ static const struct hid_device_id hid_have_special_driver[] = {#endif #if IS_ENABLED(CONFIG_HID_ELECOM) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AC) }, { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_00FB) }, { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_018F) },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 813/982 bpf: Avoid soft lockup in __htab_map_lookup_and_delete_batch()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Fernandez (Anthropic) <[email protected]>
[ Upstream commit 85136bf22404474a815fc0ed26ec0d1cbc1bc3f9 ]
__htab_map_lookup_and_delete_batch() has no rescheduling point. The batch count bounds how many entries are copied out, not how many buckets are visited, so one BPF_MAP_LOOKUP_BATCH call can walk the map end to end. The empty-bucket fast path is worse: it stays inside a single rcu_read_lock() / bpf_disable_instrumentation() section for any run of consecutive empty buckets.
That holds up on small maps, but it falls apart at scale. On a 144-CPU arm64 host running a CONFIG_PREEMPT_NONE kernel, periodic BPF_MAP_LOOKUP_BATCH calls against an LRU hash map with 16,777,216 buckets held a CPU inside the batch op for 77+ seconds and triggered the soft lockup watchdog.
Commit 75134f16e7dd ("bpf: Add schedule points in batch ops") fixed this same problem in the generic batch ops, but not in this htab-native path, which every htab-based hash map variant uses for its lookup[_and_delete] batch ops.
Complete that fix here. Leave the critical section after 64 consecutive empty buckets, call cond_resched_tasks_rcu_qs(), and resume at the saved bucket cursor. No locks are held at that point, and resuming from the cursor is already the function's behavior for non-empty buckets. Add the same call to the per-bucket loop after copy_to_user(), where every lock has been dropped. cond_resched_rcu() is not enough here: sleeping with bpf_prog_active elevated makes tracing programs on that CPU silently skip their invocations.
Plain cond_resched() is not enough either. It is a no-op under PREEMPT and PREEMPT_LAZY, the only models arm64 and x86 have offered since commit 7dadeaa6e851 ("sched: Further restrict the preemption modes"). It is also never a Tasks RCU quiescent state, in any model: the reschedule counts as a preemption. The walking task stays a holdout and stalls every synchronize_rcu_tasks() caller, ftrace and BPF trampoline teardown included, until the syscall returns [1]. cond_resched_tasks_rcu_qs() is the usual tool for that [2]. It reports the quiescent state at each yield and still reschedules as cond_resched() does on PREEMPT_NONE and PREEMPT_VOLUNTARY kernels.
--- kernel/bpf/hashtab.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
kernel/bpf/hashtab.c +21 -3
@@ -1653,6 +1653,12 @@ static int htab_lru_percpu_map_lookup_and_delete_elem(struct bpf_map *map, flags); } +/* +* Max consecutive empty buckets to walk in one RCU + +* instrumentation-disabled section before rescheduling. +*/ +#define HTAB_BATCH_EMPTY_RESCHED 64 + static int __htab_map_lookup_and_delete_batch(struct bpf_map *map, const union bpf_attr *attr,
@@ -1674,6 +1680,7 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map,unsigned long flags =0 ;bool locked = false;struct htab_elem *l; +u32 empty_cnt =0 ;struct bucket *b;int ret =0 ;
@@ -1839,12 +1846,21 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, } next_batch: -/* If we are not copying data, we can go to next bucket and avoid -* unlocking the rcu. +/* +* If we are not copying data, we can go to next bucket and avoid +* unlocking the rcu. Bound the walk though: after +* HTAB_BATCH_EMPTY_RESCHED consecutive empty buckets, fully exit +* the critical section (no locks are held here) and reschedule. */ if (!bucket_cnt && (batch +1 < htab->n_buckets)) { batch++; - goto again_nocopy; +if (++empty_cnt <HTAB_BATCH_EMPTY_RESCHED ) + goto again_nocopy; + empty_cnt =0 ; +rcu_read_unlock (); +bpf_enable_instrumentation (); +cond_resched_tasks_rcu_qs (); + goto again; }rcu_read_unlock ();
@@ -1858,11 +1874,13 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, } total += bucket_cnt; + empty_cnt =0 ; batch++;if (batch >= htab->n_buckets) { ret = -ENOENT ; goto after_loop; } +cond_resched_tasks_rcu_qs (); goto again; after_loop:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 814/982 bpf: Fix out-of-bounds read of rtt_min in sock_ops
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 75f8cf22463d82bb1fb0239a3d485fc8f4c8ef03 ]
A sockops prog reading skops->rtt_min never checks the sk type: on the tcp_conn_request() path sock_ops->sk is a request_sock (non-full), and the ctx rewrite casts it to a tcp_sock (full) and reads rtt_min past the end of the request_sock, returning dirty adjacent memory.
SEC("sockops")
int prog(struct bpf_sock_ops *skops)
{
switch (skops->op) {
case BPF_SOCK_OPS_RWND_INIT:
leak = skops->rtt_min; /* reads the request_sock OOB */
...
}
}For instance one such read returned rtt_min=0xffff8881, the high half of a leaked kernel pointer.
Guarding that cast is exactly what SOCK_OPS_GET_FIELD() does -- it checks is_locked_tcp_sock and returns 0 when sock_ops->sk is not a locked full socket. Every other tcp_sock field in sock_ops goes through it; rtt_min is the only one open-coded, so it skips the check.
Read rtt_min through SOCK_OPS_GET_FIELD() too. rtt_min is a bit special:
it is a struct minmax and we only want the current min, so pass rtt_min.s[0].v. That is equivalent to the old hand-computed offset
offsetof(struct tcp_sock, rtt_min) + sizeof_field(struct minmax_sample, t)
(s[0] sits at rtt_min + 0 and .v at + sizeof(.t), i.e. what minmax_get() returns), so the loaded field is unchanged and only the full-sock guard is added. The two BUILD_BUG_ON()s that protected the hand-computed offset are no longer needed.
Before patch:
0: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk 1: r1 = *(u32 *)(r1 +2324) ; ((tcp_sock *)sk)->rtt_min.s[0].v
After patch:
0: *(u64 *)(r1 +56) = r9 1: r9 = *(u8 *)(r1 +50) ; is_locked_tcp_sock 2: if r9 == 0 goto pc+4 ; not a locked full sock -> 0 3: r9 = *(u64 *)(r1 +56) 4: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk 5: r1 = *(u32 *)(r1 +2324) ; rtt_min.s[0].v 6: goto pc+2 7: r9 = *(u64 *)(r1 +56) 8: r1 = 0
--- net/core/filter.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
net/core/filter.c +1 -12
@@ -10593,18 +10593,7 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct bpf_sock_ops , rtt_min): - BUILD_BUG_ON(sizeof_field(struct tcp_sock, rtt_min) != - sizeof(struct minmax)); -BUILD_BUG_ON (sizeof (struct minmax ) < -sizeof (struct minmax_sample )); - - *insn++ =BPF_LDX_MEM (BPF_FIELD_SIZEOF ( - struct bpf_sock_ops_kern, sk), - si->dst_reg, si->src_reg, - offsetof(struct bpf_sock_ops_kern , sk)); - *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->dst_reg, - offsetof(struct tcp_sock , rtt_min) + - sizeof_field(struct minmax_sample, t)); + SOCK_OPS_GET_FIELD(rtt_min, rtt_min.s[0].v, struct tcp_sock);break ;case offsetof(struct bpf_sock_ops , bpf_sock_ops_cb_flags):
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 815/982 bpf, sockmap: Fix self-redirect copied_seq double-counting
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geliang Tang <[email protected]>
[ Upstream commit 490a83d6386eec1d29f470c8d7331677fb46c3b7 ]
When a BPF stream_verdict program redirects an skb back to the same socket (self-redirect with BPF_F_INGRESS), sk_psock_verdict_apply() calls tcp_eat_skb() which advances tcp_sk->copied_seq. However, the skb is then delivered to the socket's psock ingress queue and later read by tcp_bpf_recvmsg_parser(), which also advances copied_seq via the copied_from_self accounting path. This double-counting causes copied_seq to advance by 2x the actual data length, triggering:
TCP recvmsg seq # bug 2: copied BF2E806, seq BF2E7FD, \ rcvnxt BF2E806, fl 0 WARNING: net/ipv4/tcp.c:2745 at tcp_recvmsg_locked+0x72b/0x2640 Call Trace: tcp_recvmsg+0x10a/0x500 sock_recvmsg+0x168/0x1d0 __sys_recvfrom+0x19a/0x2a0 __x64_sys_recvfrom+0xe4/0x1f0 do_syscall_64+0xf7/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f
cleanup rbuf bug: copied BF2E806 seq BF2E806 rcvnxt BF2E806
WARNING: net/ipv4/tcp.c:1609 at tcp_cleanup_rbuf+0xf2/0x1c0 Call Trace: tcp_recvmsg_locked+0x8d1/0x2640 tcp_recvmsg+0x10a/0x500 sock_recvmsg+0x168/0x1d0 __sys_recvfrom+0x19a/0x2a0 __x64_sys_recvfrom+0xe4/0x1f0 do_syscall_64+0xf7/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fix this by converting self-redirect verdict to __SK_PASS at the beginning of sk_psock_verdict_apply(). This bypasses the __SK_REDIRECT case entirely (which calls sk_psock_eat_skb), letting the __SK_PASS path queue the skb to the psock ingress queue. The data is then read via tcp_bpf_recvmsg_parser(), which advances copied_seq exactly once through copied_from_self. Cross-socket redirects continue through __SK_REDIRECT with sk_psock_eat_skb() unchanged.
--- net/core/skmsg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/skmsg.c +4 -0
@@ -1031,6 +1031,10 @@ static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb,int err =0 ;u32 len, off; +if (verdict == __SK_REDIRECT &&skb_bpf_ingress (skb) && +skb_bpf_redirect_fetch (skb) == psock->sk) + verdict = __SK_PASS; +switch (verdict) {case __SK_PASS: err = -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 816/982 pinctrl: meson: Fix typo in s4 group name
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Anderson <[email protected]>
[ Upstream commit 692f32609a30f75ca3401e25b504bfd06bd5662a ]
One of the i2c pin groups has some junk at the end. The name should be i2c2_scl_h1, and indeed that's the name used by i2c2_pins3 in meson-s4.dtsi.
--- drivers/pinctrl/meson/pinctrl-meson-s4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/meson/pinctrl-meson-s4.c +1 -1
@@ -854,7 +854,7 @@ static const char * const i2c1_groups[] = {static const char *const i2c2_groups[] = {"i2c2_sda_d" ,"i2c2_scl_d" ,"i2c2_sda_h8" ,"i2c2_scl_h9" , -"i2c2_sda_h0" ,"i2c2_scl_h1l," +"i2c2_sda_h0" ,"i2c2_scl_h1" , };static const char *const i2c3_groups[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 817/982 HID: amd_sfh: Validate PCI BAR size before mapping
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Slawomir Stepien <[email protected]>
[ Upstream commit 65bcc5f89704efe5b9d69d4ea2c1002d90c31382 ]
The amd_sfh driver maps PCI BAR 2 using pcim_iomap_regions() and subsequently accesses MMIO registers at offsets up to 0x10958 (e.g., AMD_P2C_MSG3 at 0x1068C). However, the driver never validates that the BAR size is large enough to cover these accesses. If the driver is bound to a device with a smaller BAR 2, this leads to an out-of-bounds memory access and a page fault during the probe function.
For example, a page fault can occur when reading from privdata->mmio + AMD_P2C_MSG3 in mp2_select_ops():
BUG: unable to handle page fault for address: ffffc9000390368c PGD 100000067 P4D 100000067 PUD 1012c1067 PMD 105b64067 PTE 0 Oops: Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:readl arch/x86/include/asm/io.h:59 [inline] RIP: 0010:mp2_select_ops drivers/hid/amd-sfh-hid/amd_sfh_pcie.c:282 [inline] RIP: 0010:amd_mp2_pci_probe+0x337/0x5f0 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c:487 Call Trace: <TASK> local_pci_probe drivers/pci/pci-driver.c:332 [inline] pci_call_probe drivers/pci/pci-driver.c:394 [inline] __pci_device_probe drivers/pci/pci-driver.c:455 [inline] pci_device_probe+0x431/0xc90 drivers/pci/pci-driver.c:489
Fix this by verifying that the length of BAR 2 is at least 128KB before attempting to map it. Since the maximum accessed offset is 0x10958, and PCI BAR sizes are powers of 2, any legitimate hardware will have a BAR size of at least 128KB.
--- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 4 ++++ drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
drivers/hid/amd-sfh-hid/amd_sfh_common.h +4 -0
@@ -11,11 +11,15 @@#define AMD_SFH_COMMON_H #include <linux/pci.h> +#include <linux/sizes.h> #include "amd_sfh_hid.h" #define PCI_DEVICE_ID_AMD_MP2 0x15E4#define PCI_DEVICE_ID_AMD_MP2_1_1 0x164A +/* The BAR 2 size must cover the highest register offset (0x10958) */ +#define AMD_SFH_MIN_BAR_SIZE SZ_128K +#define AMD_C2P_MSG (regno) (0x10500 + ((regno) * 4))#define AMD_P2C_MSG (regno) (0x10680 + ((regno) * 4))
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +10 -0
@@ -345,6 +345,16 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *iif (rc)return rc; +if (!(pci_resource_flags (pdev,2 ) &IORESOURCE_MEM )) { +dev_err (&pdev->dev,"BAR 2 is not IORESOURCE_MEM\n" ); +return -ENODEV ; + } + +if (pci_resource_len (pdev,2 ) <AMD_SFH_MIN_BAR_SIZE ) { +dev_err (&pdev->dev,"BAR 2 is too small\n" ); +return -EINVAL ; + } + rc =pcim_iomap_regions (pdev,BIT (2 ),DRIVER_NAME );if (rc)return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 818/982 squashfs: Add dictionary size range check to prevent shift-out-of-bounds
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ran Hongyun <[email protected]>
[ Upstream commit 1f7745fb3580152ca902ef181b605f33cabfb1d0 ]
When an abnormal SquashFS image (COMP_OPTS flag is 1 but dictionary size is 0) is mounted, and performs shift operations using dictionarysize, the shift exponent is -1, causing a shift-out-of-bounds.
Detail as below:squashfs_comp_opts(msblk, buffer, length)
squashfs_xz_comp_opts()
if (comp_opts)
n = ffs(opts->dict_size) - 1;<----opts->dict_size=0, n=-1
if (opts->dict_size != (1 << n) && opts->dict_size !=
(1 << n) + (1 << (n + 1))) <----shift-out-of-boundsFix it by adding a dictionary size range check before the shift operation.
--- fs/squashfs/xz_wrapper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/squashfs/xz_wrapper.c +3 -3
@@ -57,10 +57,10 @@ static void *squashfs_xz_comp_opts(struct squashfs_sb_info *msblk, opts->dict_size =le32_to_cpu (comp_opts->dictionary_size); -/* the dictionary size should be 2^n or 2^n+2^(n+1) */ +/* the dictionary size should be positive and 2^n or 2^n+2^(n+1) */ n =ffs (opts->dict_size) -1 ; -if (opts->dict_size != (1 << n) && opts->dict_size != (1 << n) + - (1 << (n +1 ))) { +if (opts->dict_size <=0 || (opts->dict_size != (1 << n) && + opts->dict_size != (1 << n) + (1 << (n +1 )))) { err = -EIO ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 819/982 Bluetooth: SMP: reject Security Request over BR/EDR
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christiano Amora <[email protected]>
[ Upstream commit f033482d76a9f18080c7a40c5f9c678bd7adc8f3 ]
Bose QC Ultra Headphones (dual-mode, same public address on both transports) occasionally send an SMP Security Request on the BR/EDR SMP fixed channel right after the ACL link is encrypted. The kernel handles it as if it were an LE link: smp_cmd_security_req() has no transport check, smp_ltk_encrypt() looks up an LTK with the ACL connection's dst_type, and hci_find_ltk() matches the peer's LE LTK because the LE public address type is stored as ADDR_LE_DEV_PUBLIC (0), the same value as BDADDR_BREDR. HCI_OP_LE_START_ENC is then issued on the ACL handle, the controller rejects it with Invalid HCI Command Parameters, and hci_cs_le_start_enc() disconnects the link with HCI_ERROR_AUTH_FAILURE. The headphones drop within a second of connecting, before any profile is up; a manual reconnect works.
btmon (MediaTek MT7922, kernel 7.0.12):
Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4
Status: Success (0x00)
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)
Encryption: Enabled with AES-CCM (0x02)Quoted 1 line
ACL Data RX: Handle 50 flags
0x02dlen 6
BR/EDR SMP: Security Request (0x0b) len 1
Authentication requirement: No bonding, No MITM, SC (0x08)
< HCI Command: LE Start Encryption (0x08|0x0019) plen 28
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Start Encryption (0x08|0x0019) ncmd 1
Status: Invalid HCI Command Parameters (0x12)
< HCI Command: Disconnect (0x01|0x0006) plen 3
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)
Reason: Authentication Failure (0x05)SMP over BR/EDR is limited to cross-transport key derivation; the Security Request procedure (Core Specification Vol 3, Part H, Section 2.4.6, PDU in Section 3.6.7) has no BR/EDR counterpart. Reply with Pairing Failed / Command Not Supported on a non-LE link, before the PDU is parsed, and keep the connection. The reply is sent directly rather than through smp_failure(): rejecting a command on the wrong transport is not an authentication failure, and MGMT_EV_AUTH_FAILED would make bluetoothd disconnect the device.
Tested on the affected host (kernel 7.0.12, MediaTek MT7922, Bose QC Ultra) with the patched module built out of tree: 7 days and 49 reconnects without a drop, against 2 drops in the 3 days before the patch. Every disconnect in that week had a userspace or remote reason.
--- net/bluetooth/smp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/bluetooth/smp.c +17 -0
@@ -2295,6 +2295,23 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)bt_dev_dbg (hdev,"conn %p" , conn); +/* SMP over BR/EDR only covers cross-transport key derivation; the +* Security Request procedure has no BR/EDR counterpart. Reject it +* here, otherwise smp_ltk_encrypt() finds the peer's LE LTK +* (ADDR_LE_DEV_PUBLIC and BDADDR_BREDR are both 0) and issues +* HCI_OP_LE_START_ENC on the ACL handle, which the controller +* rejects and hci_cs_le_start_enc() turns into a disconnect. Reply +* without smp_failure(): this is not an authentication failure, and +* MGMT_EV_AUTH_FAILED would make bluetoothd drop the device. +*/ +if (hcon->type !=LE_LINK ) { +u8 reason =SMP_CMD_NOTSUPP ; + +smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), + &reason); +return 0 ; + } +if (skb->len <sizeof (*rp))return SMP_INVALID_PARAMS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 820/982 Bluetooth: mgmt: Dequeue pending mesh_send_sync entries on cancel
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit 71af682ba4692c2ed9ace4c3d4ca462ae368c029 ]
In send_cancel(), pending mesh_tx objects are removed from the hdev->mesh_pending list and freed via mesh_send_complete(). However, if a mesh transmission was already queued onto hdev->cmd_sync_work_list via mesh_next(), the queued entry retains a raw pointer to mesh_tx.
When hci_cmd_sync_work later processes the entry, it attempts to execute mesh_send_sync and its destroy callback mesh_send_start_complete using the already freed mesh_tx pointer, leading to a use-after-free.
Fix this by invoking hci_cmd_sync_dequeue() for mesh_send_sync on the target mesh_tx before completing it. If the entry is found and dequeued, its destroy callback will complete and free the object; otherwise, mesh_send_complete() is called directly.
Additionally, ensure the transmission queue advances after cancellation or errors. In mesh_send_start_complete(), call mesh_next() on error unless err is -ECANCELED, because hci_cmd_sync_dequeue() holds hdev->cmd_sync_work_lock and calling mesh_next() synchronously would deadlock. Instead, advance the queue in send_cancel() once the lock is released and if no transmission is in progress.
--- net/bluetooth/mgmt.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/bluetooth/mgmt.c +15 -4
@@ -2217,6 +2217,8 @@ static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err)hci_dev_clear_flag (hdev,HCI_MESH_SENDING );/* Send Complete Error Code for handle */ mesh_send_complete (hdev, mesh_tx, false); +if (err != -ECANCELED ) +mesh_next (hdev,NULL ,0 );return ; }
@@ -2326,19 +2328,28 @@ static int send_cancel(struct hci_dev *hdev, void *data)do { mesh_tx =mgmt_mesh_next (hdev, cmd->sk); -if (mesh_tx) -mesh_send_complete (hdev, mesh_tx, false); +if (mesh_tx) { +if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, + mesh_tx,NULL )) +mesh_send_complete (hdev, mesh_tx, false); + } }while (mesh_tx); }else { mesh_tx =mgmt_mesh_find (hdev, cancel->handle); -if (mesh_tx && mesh_tx->sk == cmd->sk) -mesh_send_complete (hdev, mesh_tx, false); +if (mesh_tx && mesh_tx->sk == cmd->sk) { +if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, + mesh_tx,NULL )) +mesh_send_complete (hdev, mesh_tx, false); + } }mgmt_cmd_complete (cmd->sk, hdev->id,MGMT_OP_MESH_SEND_CANCEL ,0 ,NULL ,0 ); +if (!hci_dev_test_flag (hdev,HCI_MESH_SENDING )) +mesh_next (hdev,NULL ,0 ); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 821/982 scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 42d1221d321e55afc7bba9109a77aaf5a817c8a3 ]
Protect the megasas_get_ctrl_info() call in megasas_resume() with instance->reset_mutex using scoped_guard().
megasas_get_ctrl_info() may release and reacquire instance->reset_mutex. Hence, calling this function without holding instance->reset_mutex is not safe.
--- drivers/scsi/megaraid/megaraid_sas_base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/megaraid/megaraid_sas_base.c +3 -1
@@ -7872,7 +7872,9 @@ megasas_resume(struct device *dev) goto fail_init_mfi; } -if (megasas_get_ctrl_info (instance) !=DCMD_SUCCESS ) +scoped_guard (mutex, &instance->reset_mutex) + rval = megasas_get_ctrl_info(instance); +if (rval !=DCMD_SUCCESS ) goto fail_init_mfi; tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 822/982 Documentation: s390: correct spelling
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
[ Upstream commit ac56c666f80df0b1dc9c3ef53d0798b74629a116 ]
Correct spelling problems for Documentation/s390/ as reported by codespell.
Stable-dep-of: 4525a9110495 ("s390/pci/docs: Fix sriov_numvfs attribute name")
--- Documentation/s390/pci.rst | 4 ++-- Documentation/s390/vfio-ccw.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Documentation/s390/pci.rst +2 -2
@@ -51,7 +51,7 @@ Entries specific to zPCI functions and entries that hold zPCI information. The slot entries are set up using the function identifier (FID) of the PCI function. The format depicted as XXXXXXXX above is 8 hexadecimal digits - with 0 padding and lower case hexadecimal digitis. + with 0 padding and lower case hexadecimal digits. - /sys/bus/pci/slots/XXXXXXXX/power
@@ -66,7 +66,7 @@ Entries specific to zPCI functions and entries that hold zPCI information. - function_handle Low-level identifier used for a configured PCI function. - It might be useful for debuging. + It might be useful for debugging. - pchid Model-dependent location of the I/O adapter.
Documentation/s390/vfio-ccw.rst +1 -1
@@ -176,7 +176,7 @@ The process of how these work together. Use the 'mdev_create' sysfs file, we need to manually create one (and only one for our case) mediated device. 3. vfio_mdev.ko drives the mediated ccw device. - vfio_mdev is also the vfio device drvier. It will probe the mdev and + vfio_mdev is also the vfio device driver. It will probe the mdev and add it to an iommu_group and a vfio_group. Then we could pass through the mdev to a guest.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 823/982 docs: s390/pci: Improve and update PCI documentation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Schnelle <[email protected]>
[ Upstream commit 737c4f4a241ca85c597ca2ef1a6f8446bf681ab5 ]
Update the s390 specific PCI documentation to better reflect current behavior and terms such as the handling of Isolated VFs via commit 25f39d3dcb48 ("s390/pci: Ignore RID for isolated VFs").
Add a descriptions for /sys/firmware/clp/uid_checking which was added in commit b043a81ce3ee ("s390/pci: Expose firmware provided UID Checking state in sysfs") but missed documentation.
Similarly add documentation for the fidparm attribute added by commit 99ad39306a62 ("s390/pci: Expose FIDPARM attribute in sysfs") and add a list of pft values and their names.
Finally improve formatting of the different attribute descriptions by adding a separating colon.
Stable-dep-of: 4525a9110495 ("s390/pci/docs: Fix sriov_numvfs attribute name")
--- Documentation/s390/pci.rst | 152 ++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 51 deletions(-)
Documentation/s390/pci.rst +101 -51
@@ -6,6 +6,7 @@ S/390 PCI Authors: - Pierre Morel + - Niklas Schnelle Copyright, IBM Corp. 2020
@@ -27,14 +28,16 @@ Command line parameters debugfs entries --------------- -The S/390 debug feature (s390dbf) generates views to hold various debug results in sysfs directories of the form: +The S/390 debug feature (s390dbf) generates views to hold various debug results +in sysfs directories of the form: * /sys/kernel/debug/s390dbf/pci_*/ For example: - /sys/kernel/debug/s390dbf/pci_msg/sprintf - Holds messages from the processing of PCI events, like machine check handling + + holds messages from the processing of PCI events, like machine check handling and setting of global functionality, like UID checking. Change the level of logging to be more or less verbose by piping
@@ -47,87 +50,134 @@ Sysfs entries Entries specific to zPCI functions and entries that hold zPCI information. -* /sys/bus/pci/slots/XXXXXXXX +* /sys/bus/pci/slots/XXXXXXXX: - The slot entries are set up using the function identifier (FID) of the - PCI function. The format depicted as XXXXXXXX above is 8 hexadecimal digits - with 0 padding and lower case hexadecimal digits. + The slot entries are set up using the function identifier (FID) of the PCI + function as slot name. The format depicted as XXXXXXXX above is 8 hexadecimal + digits with 0 padding and lower case hexadecimal digits. - /sys/bus/pci/slots/XXXXXXXX/power A physical function that currently supports a virtual function cannot be powered off until all virtual functions are removed with: - echo 0 > /sys/bus/pci/devices/XXXX:XX:XX.X/sriov_numvf + echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvf -* /sys/bus/pci/devices/XXXX:XX:XX.X/ +* /sys/bus/pci/devices/DDDD:BB:dd.f/: - - function_id - A zPCI function identifier that uniquely identifies the function in the Z server. + - function_id: + The zPCI function identifier (FID) is a 32-bit hexadecimal value that + uniquely identifies the PCI function. Unless the hypervisor provides + a virtual FID e.g. on KVM this identifier is unique across the machine even + between different partitions. - - function_handle - Low-level identifier used for a configured PCI function. - It might be useful for debugging. + - function_handle: + This 32-bit hexadecimal value is a low-level identifier used for a PCI + function. Note that the function handle may be changed and become invalid + on PCI events and when enabling/disabling the PCI function. - - pchid - Model-dependent location of the I/O adapter. + - pchid: + This 16-bit hexadecimal value encodes a model-dependent location for + the PCI function. - - pfgid - PCI function group ID, functions that share identical functionality + - pfgid: + PCI function group ID; functions that share identical functionality use a common identifier. A PCI group defines interrupts, IOMMU, IOTLB, and DMA specifics. - - vfn + - vfn: The virtual function number, from 1 to N for virtual functions, 0 for physical functions. - - pft - The PCI function type - - - port - The port corresponds to the physical port the function is attached to. - It also gives an indication of the physical function a virtual function - is attached to. - - - uid - The user identifier (UID) may be defined as part of the machine - configuration or the z/VM or KVM guest configuration. If the accompanying - uid_is_unique attribute is 1 the platform guarantees that the UID is unique - within that instance and no devices with the same UID can be attached - during the lifetime of the system. - - - uid_is_unique - Indicates whether the user identifier (UID) is guaranteed to be and remain - unique within this Linux instance. - - - pfip/segmentX + - pft: + The PCI function type is an s390-specific type attribute. It indicates + a more general, usage oriented, type than PCI Specification + class/vendor/device identifiers. That is PCI functions with the same pft + value may be backed by different hardware implementations. At the same time + apart from unclassified functions (pft is 0x00) the same pft value + generally implies a similar usage model. At the same time the same + PCI hardware device may appear with different pft values when in a + different usage model. For example NETD and NETH VFs may be implemented + by the same PCI hardware device but in NETD the parent Physical Function + is user managed while with NETH it is platform managed. + + Currently the following PFT values are defined: + + - 0x00 (UNC): Unclassified + - 0x02 (ROCE): RoCE Express + - 0x05 (ISM): Internal Shared Memory + - 0x0a (ROC2): RoCE Express 2 + - 0x0b (NVMe): NVMe + - 0x0c (NETH): Network Express hybrid + - 0x0d (CNW): Cloud Network Adapter + - 0x0f (NETD): Network Express direct + + - port: + The port is a decimal value corresponding to the physical port the function + is attached to. Virtual Functions (VFs) share the port with their parent + Physical Function (PF). A value of 0 indicates that the port attribute is + not applicable for that PCI function type. + + - uid: + The user-defined identifier (UID) for a PCI function is a 32-bit + hexadecimal value. It is defined on a per instance basis as part of the + partition, KVM guest, or z/VM guest configuration. If UID Checking is + enabled the platform ensures that the UID is unique within that instance + and no two PCI functions with the same UID will be visible to the instance. + + Independent of this guarantee and unlike the function ID (FID) the UID may + be the same in different partitions within the same machine. This allows to + create PCI configurations in multiple partitions to be identical in the + UID-namespace. + + - uid_is_unique: + A 0 or 1 flag indicating whether the user-defined identifier (UID) is + guaranteed to be and remain unique within this Linux instance. This + platform feature is called UID Checking. + + - pfip/segmentX: The segments determine the isolation of a function. They correspond to the physical path to the function. The more the segments are different, the more the functions are isolated. + - fidparm: + Contains an 8-bit-per-PCI function parameter field in hexadecimal provided + by the platform. The meaning of this field is PCI function type specific. + For NETH VFs a value of 0x01 indicates that the function supports + promiscuous mode. + +* /sys/firmware/clp/uid_checking: + + In addition to the per-device uid_is_unique attribute this presents a + global indication of whether UID Checking is enabled. This allows users + to check for UID Checking even when no PCI functions are configured. + Enumeration and hotplug ======================= The PCI address consists of four parts: domain, bus, device and function, -and is of this form: DDDD:BB:dd.f +and is of this form: DDDD:BB:dd.f. -* When not using multi-functions (norid is set, or the firmware does not - support multi-functions): +* For a PCI function for which the platform does not expose the RID, the + pci=norid kernel parameter is used, or a so-called isolated Virtual Function + which does have RID information but is used without its parent Physical + Function being part of the same PCI configuration: - There is only one function per domain. - - The domain is set from the zPCI function's UID as defined during the - LPAR creation. + - The domain is set from the zPCI function's UID if UID Checking is on; + otherwise the domain ID is generated dynamically and is not stable + across reboots or hot plug. -* When using multi-functions (norid parameter is not set), - zPCI functions are addressed differently: +* For a PCI function for which the platform exposes the RID and which + is not an Isolated Virtual Function: - There is still only one bus per domain. - - There can be up to 256 functions per bus. + - There can be up to 256 PCI functions per bus. - - The domain part of the address of all functions for - a multi-Function device is set from the zPCI function's UID as defined - in the LPAR creation for the function zero. + - The domain part of the address of all functions within the same topology is + that of the configured PCI function with the lowest devfn within that + topology. - - New functions will only be ready for use after the function zero - (the function with devfn 0) has been enumerated. + - Virtual Functions generated by an SR-IOV capable Physical Function only + become visible once SR-IOV is enabled.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 824/982 s390/pci/docs: Fix sriov_numvfs attribute name
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 4525a911049543c23885a540a788d13be318a486 ]
The attribute is sriov_numvfs (drivers/pci/iov.c); the document names it sriov_numvf, which does not exist.
Use sriov_numvfs.
--- Documentation/s390/pci.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/s390/pci.rst +1 -1
@@ -60,7 +60,7 @@ Entries specific to zPCI functions and entries that hold zPCI information. A physical function that currently supports a virtual function cannot be powered off until all virtual functions are removed with: - echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvf + echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvfs * /sys/bus/pci/devices/DDDD:BB:dd.f/:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 825/982 s390/cio: Fix cio_update_schib() to not cache invalid schib
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit 29d9e5835d89223aa913dcf7b942cc1c148bdd25 ]
When pmcw.dnv is 0, the contents of all SCHIB fields are unpredictable. Zero sch->schib in that case to prevent subsequent code from making decisions based on unpredictable data.
--- drivers/s390/cio/cio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/s390/cio/cio.c +7 -4
@@ -453,7 +453,8 @@ EXPORT_SYMBOL_GPL(cio_commit_config);/** * cio_update_schib - Perform stsch and update schib if subchannel is valid. * @sch: subchannel on which to perform stsch -* Return zero on success, -ENODEV otherwise. +* Return zero on success, -ENODEV if the subchannel is not operational, +* -EACCES if the subchannel has no valid device. */ int cio_update_schib (struct subchannel *sch) {
@@ -462,10 +463,12 @@ int cio_update_schib(struct subchannel *sch)if (stsch (sch->schid, &schib))return -ENODEV ; -memcpy (&sch->schib, &schib,sizeof (schib)); - -if (!css_sch_is_valid (&schib)) +if (!css_sch_is_valid (&schib)) { +memset (&sch->schib,0 ,sizeof (sch->schib));return -EACCES ; + } + +memcpy (&sch->schib, &schib,sizeof (schib));return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 826/982 s390/cio: Check pmcw.dnv before pmcw.ena in I/O entry points
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit f6f2985eabdb2bfdc82ce90a1ea3ec53ba795f34 ]
The device number valid (dnv) bit in the PMCW must be checked before acting on any other PMCW fields for IO-type subchannels. A subchannel with dnv=0 has no valid device number associated, making it meaningless to evaluate the enabled (ena) state or issue any I/O instruction against it.
--- drivers/s390/cio/device_ops.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/s390/cio/device_ops.c +12 -0
@@ -142,6 +142,8 @@ int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -198,6 +200,8 @@ int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -375,6 +379,8 @@ int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -409,6 +415,8 @@ int ccw_device_resume(struct ccw_device *cdev)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -544,6 +552,8 @@ int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,int rc; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_VERIFY ) {
@@ -686,6 +696,8 @@ int ccw_device_tm_intrg(struct ccw_device *cdev) {struct subchannel *sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state !=DEV_STATE_ONLINE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 827/982 fs: avoid repeated scans in evict_inodes()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit 7459c021874246c196f397686e100702f059b9e7 ]
We observed hung tasks when users attempted to unmount a filesystem after its disk had been removed while still in use. During device removal, fs_bdev_mark_dead() calls evict_inodes() while holding s_umount.
Each time evict_inodes() drops s_inode_list_lock to reschedule, it restarts the walk from the head of s_inodes. With many referenced inodes at the head of the list, these restarts repeatedly scan the same inodes without reclaiming them. This can keep s_umount held for a long time, blocking concurrent umount attempts and triggering hung-task reports.
Keep the current inode, already marked I_FREEING, out of the disposal batch until s_inode_list_lock is reacquired. Resume the walk from this inode and dispose of it in a later batch or at the end of the walk.
The zero-refcount and state checks under i_lock allow this walker to claim the inode by setting I_FREEING and removing it from the LRU. Other reclaimers skip the inode, leaving this walker responsible for eviction. Only evict() removes it from s_inodes, so keeping it out of the disposal batch ensures that it remains on the list while the lock is dropped. After reacquiring the lock, reading its current next pointer accounts for concurrent removal of following inodes.
The existing inode lifetime rules prohibit acquiring a reference to an inode marked I_FREEING or I_WILL_FREE. __iget() requires its caller to hold i_lock and establish that taking a reference is valid. Inode lookup and igrab() check these flags under i_lock when acquiring a reference from zero. ihold() requires an existing reference, which would keep i_count nonzero and prevent this walker from claiming the inode. These rules already allow iput_final() and the inode shrinker to release i_lock after setting I_FREEING and before eviction completes.
A temporary __iget() reference would also keep the inode on the list, but its release must preserve last-reference handling. Another user can acquire a reference, update lazy timestamps and drop its reference while the pin is held. If the pin becomes the last reference, dropping it with atomic_dec_and_test() and evicting directly bypasses iput()'s lazytime handling and can lose those timestamp updates.
Releasing the pin with iput() preserves that handling, but does not guarantee eviction. fs_bdev_mark_dead() runs with SB_ACTIVE set, so iput() may retain the inode in cache, whereas evict_inodes() must evict eligible zero-reference inodes. The inode may also have been freed when iput() returns, so the walker cannot then use it to force eviction. Using I_FREEING preserves the existing eviction behavior without introducing an additional last-reference transition.
The xfstests auto group passed on ext4 and XFS with known unrelated failures excluded. No new issues were observed, and the previously reproducible hung task no longer occurs with this patch.
--- fs/inode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/inode.c +5 -6
@@ -754,7 +754,6 @@ void evict_inodes(struct super_block *sb)struct inode *inode, *next;LIST_HEAD (dispose); -again:spin_lock (&sb->s_inode_list_lock);list_for_each_entry_safe (inode, next, &sb->s_inodes, i_sb_list) {if (atomic_read (&inode->i_count))
@@ -773,19 +772,19 @@ void evict_inodes(struct super_block *sb) inode->i_state |=I_FREEING ;inode_lru_list_del (inode);spin_unlock (&inode->i_lock); -list_add (&inode->i_lru, &dispose);/* -* We can have a ton of inodes to evict at unmount time given -* enough memory, check to see if we need to go to sleep for a -* bit so we don't livelock. +* Keep this inode out of dispose so it stays on s_inodes while +* the list lock is dropped. I_FREEING prevents new references +* and leaves eviction to us, so we can resume the walk from it. */ if (need_resched ()) {spin_unlock (&sb->s_inode_list_lock);cond_resched ();dispose_list (&dispose); - goto again; +spin_lock (&sb->s_inode_list_lock); } +list_add (&inode->i_lru, &dispose); }spin_unlock (&sb->s_inode_list_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 828/982 xsk: Use a 32-bit compare in xsk_map_gen_lookup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 70504de0bb627848667207bec7ccfd647deb8814 ]
xsk_map_gen_lookup() loads a u32 key and compares it with max_entries using BPF_JMP_IMM. BPF immediates are sign-extended to 64 bits, so a max_entries value of 0x80000000 or higher becomes a threshold larger than every zero-extended 32-bit key. An out-of-range index then skips the bounds check and the generated lookup reads past xsk_map[].
Compare with BPF_JMP32_IMM so the check stays in 32-bit unsigned range.
--- net/xdp/xskmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xdp/xskmap.c +1 -1
@@ -116,7 +116,7 @@ static int xsk_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)struct bpf_insn *insn = insn_buf; *insn++ =BPF_LDX_MEM (BPF_W , ret, index,0 ); - *insn++ =BPF_JMP_IMM (BPF_JGE , ret, map->max_entries,5 ); + *insn++ =BPF_JMP32_IMM (BPF_JGE , ret, map->max_entries,5 ); *insn++ =BPF_ALU64_IMM (BPF_LSH , ret,ilog2 (sizeof (struct xsk_sock *))); *insn++ =BPF_ALU64_IMM (BPF_ADD , mp, offsetof(struct xsk_map , xsk_map)); *insn++ =BPF_ALU64_REG (BPF_ADD , ret, mp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 829/982 bpf: Skip unsettled links in link iterator
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 50e80e2bb5e2be8515205b9c496b9640ddefa434 ]
bpf_link_prime() inserts a link into link_idr before anon_inode_getfile() succeeds and before bpf_link_settle() publishes the ID in link->id. bpf_link_by_id() treats such an ID-zero link as unsettled, but the link iterator takes a reference without this check.
If anon_inode_getfile() then fails, the creator removes the ID and frees its still-private link directly. The iterator is left with a dangling reference and its next bpf_link_put() accesses freed memory.
Treat ID-zero entries as transient in bpf_link_get_curr_or_next(), just as bpf_link_by_id() does.
BUG: KASAN: slab-use-after-free in bpf_link_put Write of size 8 by task exp/384 Call Trace: bpf_link_put kernel/bpf/syscall.c:3372 bpf_link_seq_next kernel/bpf/link_iter.c:33 bpf_seq_read kernel/bpf/bpf_iter.c:158 vfs_read fs/read_write.c:572 ksys_read fs/read_write.c:716 do_syscall_64 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe arch/x86/entry/entry_64.S:121 Kernel panic - not syncing: KASAN: panic_on_warn set ...
--- kernel/bpf/syscall.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +4 -1
@@ -4800,7 +4800,10 @@ struct bpf_link *bpf_link_get_curr_or_next(u32 *id) again: link =idr_get_next (&link_idr, id);if (link) { - link =bpf_link_inc_not_zero (link); +if (link->id) + link =bpf_link_inc_not_zero (link); +else + link =ERR_PTR (-EAGAIN );if (IS_ERR (link)) { (*id)++; goto again;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 830/982 net/sched: cls_u32: fix manual hash table handle IDR aliasing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 0a5f5d9e94dead312d32c366b917c64e552b72f7 ]
A u32 hash table created with an explicit handle ('tc filter add ... handle 801: u32 divisor N') keys its IDR entry on the raw handle, while the destroy paths free it under handle2id(handle). The two key domains disagree for handles in the 0x800..0xFFF htid range:handle2id() folds them back into the auto-allocated id space (1..0x7FF).
A manual table therefore leaves its raw-keyed IDR entry unreachable on delete (a permanent leak), and its delete can drop the idr entry of an unrelated live auto table. A later auto allocation can then hand out a handle that aliases the live manual table; u32_lookup_ht() first-match routes lookups and TCA_U32_LINK for that htid to the wrong table.
Key the divisor-path alloc on handle2id(handle) so allocation and removal share one key domain. A manual handle that maps onto an id already in use is rejected with -ENOSPC, and auto allocation skips ids held by live manual tables.
Conditions to recreate:
ip link add test0 type dummy
tc qdisc add dev test0 clsact
tc filter add dev test0 ingress protocol ip pref 1 \
handle 801: u32 divisor 16 tc filter add dev test0 ingress protocol ip pref 2 u32 divisor 16 tc -d filter show dev test0 ingress | grep 'fh 801:' # unpatched: two live tables with handle 0x80100000 (the pref 2 root # hnode is auto-allocated id 1); patched: the auto hnode takes id 2.
Also tested with a poc with a live u32 table on the block, add/delete a manual table 'handle 901: u32 divisor 1' twice; unpatched, the re-add fails with -ENOSPC because the raw key leaked on the first delete.
--- net/sched/cls_u32.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/sched/cls_u32.c +10 -2
@@ -996,8 +996,16 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,return -ENOMEM ; } }else { - err =idr_alloc_u32 (&tp_c->handle_idr, ht, &handle, - handle,GFP_KERNEL ); +/* The IDR is keyed on the mapped id, and that is +* what the destroy paths remove. Ask for it here, +* so a manual handle colliding with the +* auto-allocated id space is rejected (-ENOSPC) +* instead of aliasing a future auto id. +*/ +u32 id =handle2id (handle); + + err =idr_alloc_u32 (&tp_c->handle_idr, ht, &id, id, +GFP_KERNEL );if (err) {kfree (ht);return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 831/982 bpf: Restrict CO-RE poisoning to relocatable instructions
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit 394ae398337c5f87e567f6cd63b937fc2b2f6ddc ]
CO-RE relocation records can name any instruction offset. When a relocation cannot be resolved, bpf_core_patch_insn() currently poisons its target before checking whether that instruction is a valid relocation target. Malformed metadata can therefore replace jumps, calls, exits, register-source arithmetic, or non-immediate loads instead of failing at the relocation step.
Handle poisoning only after the instruction has passed the same class and operand-form checks used for a resolved relocation. Route invalid forms through the existing diagnostic and return a hard error. Keep poisoning supported instructions, including both halves of a plain ldimm64, so an unresolved relocation in dead code remains valid.
Extend bpf_core_poison_insn() to poison both halves of ldimm64, and return its status directly from each validated instruction case. This avoids routing the success path through a common label and leaves the helper free to report errors.
The shared relocation code applies this restriction to both libbpf and in-kernel CO-RE.
--- tools/lib/bpf/relo_core.c | 58 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 27 deletions(-)
tools/lib/bpf/relo_core.c +31 -27
@@ -965,23 +965,30 @@ static int bpf_core_calc_relo(const char *prog_name, }/* -* Turn instruction for which CO_RE relocation failed into invalid one with +* Turn instruction for which CO-RE relocation failed into invalid one with * distinct signature. */ -static void bpf_core_poison_insn (const char *prog_name,int relo_idx, -int insn_idx,struct bpf_insn *insn) +static int bpf_core_poison_insn (const char *prog_name,int relo_idx, +struct bpf_insn *insn,int insn_idx) { -pr_debug ("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n" , - prog_name, relo_idx, insn_idx); - insn->code =BPF_JMP |BPF_CALL ; - insn->dst_reg =0 ; - insn->src_reg =0 ; - insn->off =0 ; -/* if this instruction is reachable (not a dead code), -* verifier will complain with the following message: -* invalid func unknown#195896080 -*/ - insn->imm =195896080 ;/* => 0xbad2310 => "bad relo" */ +int insn_cnt =is_ldimm64_insn (insn) ?2 :1 ; +int i; + +for (i =0 ; i < insn_cnt; i++) { +pr_debug ("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n" , + prog_name, relo_idx, insn_idx + i); + insn[i].code =BPF_JMP |BPF_CALL ; + insn[i].dst_reg =0 ; + insn[i].src_reg =0 ; + insn[i].off =0 ; +/* +* If this instruction is reachable (not dead code), the verifier +* will complain with "invalid func unknown#195896080". +*/ + insn[i].imm =195896080 ;/* => 0xbad2310 => "bad relo" */ + } + +return 0 ; }static int insn_bpf_size_to_bytes (struct bpf_insn *insn)
@@ -1032,17 +1039,6 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn, class =BPF_CLASS (insn->code); -if (res->poison) { -poison: -/* poison second part of ldimm64 to avoid confusing error from -* verifier about "unknown opcode 00" -*/ -if (is_ldimm64_insn (insn)) -bpf_core_poison_insn (prog_name, relo_idx, insn_idx +1 , insn +1 ); -bpf_core_poison_insn (prog_name, relo_idx, insn_idx, insn); -return 0 ; - } - orig_val = res->orig_val; new_val = res->new_val;
@@ -1050,7 +1046,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,case BPF_ALU :case BPF_ALU64 :if (BPF_SRC (insn->code) !=BPF_K ) -return -EINVAL ; + goto bad_insn; +if (res->poison) +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx);if (res->validate && insn->imm != orig_val) { pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, exp %llu -> %llu\n", prog_name, relo_idx,
@@ -1067,6 +1065,8 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,case BPF_LDX :case BPF_ST :case BPF_STX : +if (res->poison) +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx);if (res->validate && insn->off != orig_val) { pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, exp %llu -> %llu\n", prog_name, relo_idx, insn_idx, insn->off, (unsigned long long)orig_val,
@@ -1082,7 +1082,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,pr_warn ("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. " "Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n" , prog_name, relo_idx, insn_idx); - goto poison; +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx); } orig_val = insn->off;
@@ -1125,6 +1125,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,return -EINVAL ; } +if (res->poison) +return bpf_core_poison_insn (prog_name, relo_idx, insn, insn_idx); + imm = (__u32 )insn[0 ].imm | ((__u64 )insn[1 ].imm <<32 );if (res->validate && imm != orig_val) { pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %llu -> %llu\n",
@@ -1142,6 +1145,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,break ; }default : +bad_insn:pr_warn ("prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\n" , prog_name, relo_idx, insn_idx, insn->code, insn->src_reg, insn->dst_reg, insn->off, insn->imm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 832/982 libbpf: Reject truncated ldimm64 CO-RE relocations
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit b4e875d397da451fb4e9c573ff4b86db53caba05 ]
CO-RE relocation of an ldimm64 instruction operates on two instruction slots. A malformed BPF ELF can end a function after the first slot and attach a CO-RE relocation to it. libbpf allocates the instruction array according to the function symbol size, so the shared relocation code would then access beyond the allocation.
Reject a terminal ldimm64 in libbpf's relocation loop, where the program length is available, before resolving or applying the relocation. Both resolved and unresolved relocations validate the absent second slot, and unresolved relocation poisoning would additionally write past the array.
The in-kernel caller is protected by the verifier's early instruction-stream check before it applies CO-RE relocations.
--- tools/lib/bpf/libbpf.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/lib/bpf/libbpf.c +7 -0
@@ -5741,6 +5741,13 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)return -EINVAL ; insn = &prog->insns[insn_idx]; +if (is_ldimm64_insn (insn) && (size_t )insn_idx +1 >= prog->insns_cnt) { +pr_warn ("prog '%s': relo #%d: insn #%d (LDIMM64) is truncated\n" , + prog->name, i, insn_idx); + err = -EINVAL ; + goto out; + } + err =record_relo_core (prog, rec, insn_idx);if (err) { pr_warn("prog '%s': relo #%d: failed to record relocation: %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 833/982 netfilter: flowtable: publish HW_DEAD after worker is done
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit d644b23afe1ef509c9961a6d84a093c2587edf02 ]
flow_offload_work_del() sets NF_FLOW_HW_DEAD before the work handler clears NF_FLOW_HW_PENDING. Once a flow is both HW_DYING and HW_DEAD, a concurrent garbage collection pass can remove it and schedule it for RCU freeing.
The offload worker holds neither an RCU read lock nor a reference to the flow. If it is preempted after publishing HW_DEAD, the RCU callback can free the flow before the worker resumes and clears HW_PENDING, resulting in a use-after-free.
Move HW_DEAD publication to the common worker epilogue after the pending bit is cleared, making it the final flow access by destroy work. Order all preceding flow accesses before publishing the bit that allows garbage collection to free the object.
--- net/netfilter/nf_flow_table_offload.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_offload.c +6 -1
@@ -993,7 +993,6 @@ static void flow_offload_work_del(struct flow_offload_work *offload)flow_offload_tuple_del (offload,FLOW_OFFLOAD_DIR_ORIGINAL );if (test_bit (NF_FLOW_HW_BIDIRECTIONAL , &offload->flow->flags))flow_offload_tuple_del (offload,FLOW_OFFLOAD_DIR_REPLY ); -set_bit (NF_FLOW_HW_DEAD , &offload->flow->flags); } static void flow_offload_tuple_stats(struct flow_offload_work *offload,
@@ -1057,6 +1056,12 @@ static void flow_offload_work_handler(struct work_struct *work) }clear_bit (NF_FLOW_HW_PENDING , &offload->flow->flags); +if (offload->cmd ==FLOW_CLS_DESTROY ) { +/* Publish after the worker's last flow access. */ +smp_mb__before_atomic (); +set_bit (NF_FLOW_HW_DEAD , &offload->flow->flags); + } +kfree (offload); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 834/982 netfilter: nfnetlink_queue: nfqnl_instance GFP_ATOMIC -> GFP_KERNEL_ACCOUNT allocation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Scott Mitchell <[email protected]>
[ Upstream commit a4400a5b343d1bc4aa8f685608515413238e7ee2 ]
Currently, instance_create() uses GFP_ATOMIC because it's called while holding instances_lock spinlock. This makes allocation more likely to fail under memory pressure.
Refactor nfqnl_recv_config() to drop RCU lock after instance_lookup() and peer_portid verification. A socket cannot simultaneously send a message and close, so the queue owned by the sending socket cannot be destroyed while processing its CONFIG message. This allows instance_create() to allocate with GFP_KERNEL_ACCOUNT before taking the spinlock.
Stable-dep-of: 9461613afc59 ("netfilter: nfnetlink_queue: hold nfnl mutex in event notifier")
--- net/netfilter/nfnetlink_queue.c | 75 +++++++++++++++------------------ 1 file changed, 34 insertions(+), 41 deletions(-)
net/netfilter/nfnetlink_queue.c +34 -41
@@ -119,17 +119,9 @@ instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid)unsigned int h;int err; -spin_lock (&q->instances_lock); -if (instance_lookup (q, queue_num)) { - err = -EEXIST ; - goto out_unlock; - } - - inst =kzalloc (sizeof (*inst),GFP_ATOMIC ); -if (!inst) { - err = -ENOMEM ; - goto out_unlock; - } + inst =kzalloc (sizeof (*inst),GFP_KERNEL_ACCOUNT ); +if (!inst) +return ERR_PTR (-ENOMEM ); inst->queue_num = queue_num; inst->peer_portid = portid;
@@ -139,9 +131,15 @@ instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid)spin_lock_init (&inst->lock);INIT_LIST_HEAD (&inst->queue_list); +spin_lock (&q->instances_lock); +if (instance_lookup (q, queue_num)) { + err = -EEXIST ; + goto out_unlock; + } +if (!try_module_get (THIS_MODULE )) { err = -EAGAIN ; - goto out_free; + goto out_unlock; } h =instance_hashfn (queue_num);
@@ -151,10 +149,9 @@ instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid)return inst; -out_free: -kfree (inst); out_unlock:spin_unlock (&q->instances_lock); +kfree (inst);return ERR_PTR (err); }
@@ -1322,7 +1319,8 @@ static int nfqnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,struct nfqnl_msg_config_cmd *cmd =NULL ;struct nfqnl_instance *queue;__u32 flags =0 , mask =0 ; -int ret =0 ; + +WARN_ON_ONCE (!lockdep_nfnl_is_held (NFNL_SUBSYS_QUEUE ));if (nfqa[NFQA_CFG_CMD ]) { cmd =nla_data (nfqa[NFQA_CFG_CMD ]);
@@ -1368,47 +1366,44 @@ static int nfqnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info, } } +/* Lookup queue under RCU. After peer_portid check (or for new queue +* in BIND case), the queue is owned by the socket sending this message. +* A socket cannot simultaneously send a message and close, so while +* processing this CONFIG message, nfqnl_rcv_nl_event() (triggered by +* socket close) cannot destroy this queue. Safe to use without RCU. +*/ rcu_read_lock (); queue =instance_lookup (q, queue_num);if (queue && queue->peer_portid !=NETLINK_CB (skb).portid) { - ret = -EPERM ; - goto err_out_unlock; +rcu_read_unlock (); +return -EPERM ; } +rcu_read_unlock ();if (cmd !=NULL ) {switch (cmd->command) {case NFQNL_CFG_CMD_BIND : -if (queue) { - ret = -EBUSY ; - goto err_out_unlock; - } - queue =instance_create (q, queue_num, -NETLINK_CB (skb).portid); -if (IS_ERR (queue)) { - ret =PTR_ERR (queue); - goto err_out_unlock; - } +if (queue) +return -EBUSY ; + queue =instance_create (q, queue_num,NETLINK_CB (skb).portid); +if (IS_ERR (queue)) +return PTR_ERR (queue);break ;case NFQNL_CFG_CMD_UNBIND : -if (!queue) { - ret = -ENODEV ; - goto err_out_unlock; - } +if (!queue) +return -ENODEV ;instance_destroy (q, queue); - goto err_out_unlock; +return 0 ;case NFQNL_CFG_CMD_PF_BIND :case NFQNL_CFG_CMD_PF_UNBIND :break ;default : - ret = -ENOTSUPP ; - goto err_out_unlock; +return -EOPNOTSUPP ; } } -if (!queue) { - ret = -ENODEV ; - goto err_out_unlock; - } +if (!queue) +return -ENODEV ;if (nfqa[NFQA_CFG_PARAMS ]) { struct nfqnl_msg_config_params *params =
@@ -1433,9 +1428,7 @@ static int nfqnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,spin_unlock_bh (&queue->lock); } -err_out_unlock: -rcu_read_unlock (); -return ret; +return 0 ; }static const struct nfnl_callback nfqnl_cb[NFQNL_MSG_MAX ] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 835/982 netfilter: nfnetlink_queue: hold nfnl mutex in event notifier
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 9461613afc59acef44a0071b0dd5075f6e993ffe ]
We must serialize the release notifier and the config netlink function. A concurrent thread can issue close() which can call the release function while unrelated socket processes UNBIND request for same portid:
Oops: general protection fault, [..] RIP: 0010:__instance_destroy+0x60/0x210 [nfnetlink_queue] Call Trace: nfqnl_recv_config+0x9b0/0xdc0 [nfnetlink_queue] nfnetlink_rcv_msg+0x7c2/0xeb0 ? __pfx_nfnetlink_rcv_msg+0x10/0x10
After this, parallel UNBIND and URELEASE events are impossible.
This change isn't nice, but its the shortest fix given instances are not refcounted and the nfnetlink config callback drops the rcu read lock early due to need for sleeping allocations.
--- net/netfilter/nfnetlink_queue.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_queue.c +5 -3
@@ -1034,6 +1034,7 @@ nfqnl_rcv_nl_event(struct notifier_block *this,if (event ==NETLINK_URELEASE && n->protocol ==NETLINK_NETFILTER ) {int i; +nfnl_lock (NFNL_SUBSYS_QUEUE );/* destroy all instances for this portid */ spin_lock (&q->instances_lock);for (i =0 ; i <INSTANCE_BUCKETS ; i++) {
@@ -1047,6 +1048,7 @@ nfqnl_rcv_nl_event(struct notifier_block *this, } }spin_unlock (&q->instances_lock); +nfnl_unlock (NFNL_SUBSYS_QUEUE ); }return NOTIFY_DONE ; }
@@ -1368,9 +1370,9 @@ static int nfqnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,/* Lookup queue under RCU. After peer_portid check (or for new queue * in BIND case), the queue is owned by the socket sending this message. -* A socket cannot simultaneously send a message and close, so while -* processing this CONFIG message, nfqnl_rcv_nl_event() (triggered by -* socket close) cannot destroy this queue. Safe to use without RCU. +* nfqnl_rcv_nl_event() will block on the nfnl subsys mutex that is +* held by the caller, so the queue cannot be destroyed in parallel, +* even after we drop the RCU read lock. */ rcu_read_lock (); queue =instance_lookup (q, queue_num);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 836/982 netfilter: nft_synproxy: use the family-aware checksum helper
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit a311a898172743558b82f6035ef2aa8c310a4223 ]
nft_synproxy_do_eval() verifies the TCP checksum before it switches on skb->protocol. It uses nf_ip_checksum(), which constructs an IPv4 pseudo header and relies on the IPv4 header checksum when folding the whole skb. Neither operation is valid for an IPv6 packet.
A correctly checksummed IPv6 segment can therefore fail verification when it reaches the hook as CHECKSUM_NONE or, at NF_INET_LOCAL_IN, CHECKSUM_COMPLETE. nft_synproxy_do_eval() returns NF_DROP before nft_synproxy_eval_v6() can send a SYN-ACK.
nft_synproxy_validate() deliberately admits NFPROTO_IPV6 and NFPROTO_INET, and the xtables counterpart ip6t_SYNPROXY.c already calls nf_ip6_checksum().
Use nf_checksum() with nft_pf() so the checksum helper dispatches to the packet family's implementation.
--- net/netfilter/nft_synproxy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_synproxy.c +2 -1
@@ -117,7 +117,8 @@ static void nft_synproxy_do_eval(const struct nft_synproxy *priv,return ; } -if (nf_ip_checksum (skb,nft_hook (pkt), thoff,IPPROTO_TCP )) { +if (nf_checksum (skb,nft_hook (pkt), thoff,IPPROTO_TCP , +nft_pf (pkt))) { regs->verdict.code =NF_DROP ;return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 837/982 ipvs: revalidate ihl before icmp_send
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
[ Upstream commit e290145564886d6a3038810c621f738c1fe9fa51 ]
While the outer IP header is already pulled into the skb head, we must be careful and revalidate the embedded headers after reading them from the skb frags to prevent possible out-of-bounds access.
One such place reported by Sashiko is ip_vs_in_icmp() where local process can change the ihl field and after pskb_may_pull() we can see larger value. Even if icmp_send() has checks to prevent out-of-bounds access, play safe and add check to drop the packet if the ihl field is changed. As the outer headers are pulled, make sure the transport header is updated too, it was used before commit 7fcc2fe39fed ("net:
icmp: avoid invalid transport header access in icmp_send tracepoint")
--- net/netfilter/ipvs/ip_vs_core.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_core.c +6 -0
@@ -1781,6 +1781,12 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,/* Ensure the IP header is present in headroom */ if (!pskb_may_pull (skb, hlen_orig)) goto ignore_tunnel; +skb_set_transport_header (skb, hlen_orig); +/* Before now we may used ihl from skb frag, revalidate it after +* copying it into skb head to prevent out-of-bounds access +*/ +if (ip_hdr (skb)->ihl *4 != hlen_orig) + goto ignore_tunnel;IP_VS_DBG (12 ,"Sending ICMP for %pI4->%pI4: t=%u, c=%u, i=%u\n" , &ip_hdr (skb)->saddr, &ip_hdr (skb)->daddr, type, code,ntohl (info));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 838/982 netfilter: ctnetlink: fix suspicious RCU usage in expect_iter_name
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naman Gulati <[email protected]>
[ Upstream commit 207d591c353201f3bd3e0c89bb7d44a849c8fd59 ]
expect_iter_name() is invoked by nf_ct_expect_iterate_net() under spin_lock_bh(&nf_conntrack_expect_lock). It does not hold rcu_read_lock().
When accessing exp->helper with rcu_dereference() in syzbot's report, lockdep warns:
=============================
WARNING: suspicious RCU usage
syzkaller #0 Not tainted
-----------------------------
net/netfilter/nf_conntrack_netlink.c:3393 suspicious rcu_dereference_check() usage!
locks held by syz-executor381/5628: 2, last CPU#1:
#0: ffffffff9aee42a0 (nfnl_subsys_ctnetlink_exp){+.+.}-{4:4},
at: nfnetlink_rcv_msg+0xa69/0x12b0
#1: ffffffff8ea74d58 (nf_conntrack_expect_lock){+...}-{3:3},
at: nf_ct_expect_iterate_net+0x38/0x180Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lockdep_rcu_suspicious+0x140/0x1d0 expect_iter_name+0xfb/0x100 nf_ct_expect_iterate_net+0xf2/0x180 ctnetlink_del_expect+0x45d/0x640 nfnetlink_rcv_msg+0xcc2/0x12b0 netlink_rcv_skb+0x226/0x4a0 nfnetlink_rcv+0x2b9/0x28c0 netlink_unicast+0x7bd/0x940 netlink_sendmsg+0x813/0xb40 ____sys_sendmsg+0x54e/0x850 ___sys_sendmsg+0x2a5/0x360 __sys_sendmsg+0x2a5/0x360 do_syscall_64+0x166/0x520 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Use rcu_dereference_protected() with lockdep_is_held() on nf_conntrack_expect_lock instead, similar to expect_iter_me() in nf_conntrack_helper.c.
--- net/netfilter/nf_conntrack_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +2 -1
@@ -3388,7 +3388,8 @@ static bool expect_iter_name(struct nf_conntrack_expect *exp, void *data)struct nf_conntrack_helper *helper;const char *name = data; - helper =rcu_dereference (exp->helper); + helper =rcu_dereference_protected (exp->helper, +lockdep_is_held (&nf_conntrack_expect_lock));if (!helper)return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 839/982 ocfs2: make ocfs2_calc_xattr_init() return void
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 525c0edc032b3297d0c1056cf1fa20cf1f9e6184 ]
ocfs2_calc_xattr_init() used to read the default ACL off the parent inode itself, so it could return an error from ocfs2_xattr_get_nolock(). Commit bd7c05fb4a47 ("ocfs2: fix circular locking dependency in ocfs2_init_acl()") moved that lookup before the transaction starts and deleted the error path, but left the now vestigial 'int ret = 0' declaration and both 'return ret' statements behind, along with an unreachable error branch in ocfs2_mknod().
Drop the leftover variable and convert the return type to void, so the callee states that it always succeeds and the caller no longer carries a check that can never trigger.
No functional change.
--- fs/ocfs2/namei.c | 9 ++------- fs/ocfs2/xattr.c | 13 +++++-------- fs/ocfs2/xattr.h | 8 ++++---- 3 files changed, 11 insertions(+), 19 deletions(-)
fs/ocfs2/namei.c +2 -7
@@ -332,13 +332,8 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns, goto leave;/* calculate meta data/clusters for setting security and acl xattr */ - status =ocfs2_calc_xattr_init (dir, mode, &si, &want_clusters, - &xattr_credits, &want_meta, - &acl_state); -if (status <0 ) { -mlog_errno (status); - goto leave; - } +ocfs2_calc_xattr_init (dir, mode, &si, &want_clusters, &xattr_credits, + &want_meta, &acl_state);/* Reserve a cluster if creating an extent based directory. */ if (S_ISDIR (mode) && !ocfs2_supports_inline_data (osb)) {
fs/ocfs2/xattr.c +5 -8
@@ -611,12 +611,11 @@ int ocfs2_calc_security_init(struct inode *dir,return ret; } -int ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, -struct ocfs2_security_xattr_info *si, -int *want_clusters,int *xattr_credits, -int *want_meta,struct ocfs2_acl_state *acl_state) +void ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, +struct ocfs2_security_xattr_info *si, +int *want_clusters,int *xattr_credits, +int *want_meta,struct ocfs2_acl_state *acl_state) { -int ret =0 ;struct ocfs2_super *osb =OCFS2_SB (dir->i_sb);int s_size =0 , a_size =0 , acl_len =0 , new_clusters;
@@ -638,7 +637,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, }if (!(s_size + a_size)) -return ret; +return ;/* * The max space of security xattr taken inline is
@@ -704,8 +703,6 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, } } } - -return ret; } static int ocfs2_xattr_extend_allocation(struct inode *inode,
fs/ocfs2/xattr.h +4 -4
@@ -57,10 +57,10 @@ int ocfs2_calc_security_init(struct inode *, int *, int *, struct ocfs2_alloc_context **);struct ocfs2_acl_state ; -int ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, -struct ocfs2_security_xattr_info *si, -int *want_clusters,int *xattr_credits, -int *want_meta,struct ocfs2_acl_state *acl_state); +void ocfs2_calc_xattr_init (struct inode *dir,umode_t mode, +struct ocfs2_security_xattr_info *si, +int *want_clusters,int *xattr_credits, +int *want_meta,struct ocfs2_acl_state *acl_state);/* * xattrs can live inside an inode, as part of an external xattr block,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 840/982 drm/nouveau/clk: fix list cursor use after loop in nvkm_clk_ustate_update
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit aff09d9e37e02dc60bde79035ac15b136d602259 ]
If list_for_each_entry() exits without hitting a break then "pstate" is not a valid pstate pointer. Introduce a "found" variable instead.
The check is reachable from userspace: nvkm_clk_ustate_update() takes the pstate id straight from the 'pstate' debugfs file, so requesting an id that is not in clk->states - or any id at all when the perf tables are broken and the list is empty - makes the pstate->pstate != req test dereference the list head cast to a struct nvkm_pstate, which is an out-of-bounds read.
--- drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +5 -2
@@ -473,6 +473,7 @@ static int nvkm_clk_ustate_update(struct nvkm_clk *clk, int req) {struct nvkm_pstate *pstate; +bool found = false;int i =0 ;if (!clk->allow_reclock)
@@ -480,12 +481,14 @@ nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)if (req !=-1 && req !=-2 ) {list_for_each_entry (pstate, &clk->states, head) { -if (pstate->pstate == req) +if (pstate->pstate == req) { + found = true;break ; + } i++; } -if (pstate->pstate != req) +if (!found)return -EINVAL ; req = i; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 841/982 drm/nouveau/clk: dont clobber reclock status when restoring volt/fan
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Magazzu <[email protected]>
[ Upstream commit e5cccdafc855cd5f96f4b51d38114a0360b075d7 ]
nvkm_cstate_prog() reuses 'ret' for the voltage and fan-speed restore calls it makes after reprogramming the clocks. Those calls almost always succeed, so the status of the reclock itself is overwritten and the function reports success even when clk->func->calc() or clk->func->prog() failed. The converse is also true: a successful reclock is reported as an error if the final restore call fails, even though that failure is only logged and otherwise ignored.
The only consumer of the return value is the error message in nvkm_pstate_work(), so in practice a failing reclock is simply never reported. Nothing else changes, but a function that returns success on failure is a trap for the next caller.
Keep the calc/prog status in 'ret' and use a separate local for the restore calls.
--- drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +9 -7
@@ -199,16 +199,18 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei) }if (volt) { - ret =nvkm_volt_set_id (volt, cstate->voltage, - pstate->base.voltage, clk->temp,-1 ); -if (ret && ret != -ENODEV ) -nvkm_error (subdev,"failed to lower voltage: %d\n" , ret); +int err =nvkm_volt_set_id (volt, cstate->voltage, + pstate->base.voltage, clk->temp,-1 ); + +if (err && err != -ENODEV ) +nvkm_error (subdev,"failed to lower voltage: %d\n" , err); }if (therm) { - ret =nvkm_therm_cstate (therm, pstate->fanspeed,-1 ); -if (ret && ret != -ENODEV ) -nvkm_error (subdev,"failed to lower fan speed: %d\n" , ret); +int err =nvkm_therm_cstate (therm, pstate->fanspeed,-1 ); + +if (err && err != -ENODEV ) +nvkm_error (subdev,"failed to lower fan speed: %d\n" , err); }return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 842/982 net/sched: act_ct: dont WARN on benign flow_offload_alloc() failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Ngoc Thang <[email protected]>
[ Upstream commit 47abe7a5c4eb53269aca3506446f851572a059a3 ]
flow_offload_alloc() returns NULL when the conntrack entry is dying (e.g. raced with a conntrack flush) or when the GFP_ATOMIC allocation fails; both are expected under load and neither is a kernel bug. This path runs from softirq on every committed packet, so with panic_on_warn=1 an unprivileged user can panic the box just by racing a conntrack flush against a tc ... action ct commit classifier.
Reproduced with a custom repro under QEMU: a small, fixed set of UDP flows through tc filter ... action ct commit on lo, raced against threads flooding bare ctnetlink CT_DELETE (flush) requests. Hits
WARNING: net/sched/act_ct.c:437 (tcf_ct_flow_table_add(), inlined
into tcf_ct_act() in this build) within ~15s on the unpatched kernel; same setup is clean on the patched kernel. The fix itself is
behavior-preserving: both branches already did goto err_alloc before and after, only the WARN is removed.
--- net/sched/act_ct.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/sched/act_ct.c +2 -3
@@ -428,11 +428,10 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft,if (test_and_set_bit (IPS_OFFLOAD_BIT , &ct->status))return ; +/* NULL if ct is dying (raced flush) or the atomic alloc failed. */ entry =flow_offload_alloc (ct); -if (!entry) { -WARN_ON_ONCE (1 ); +if (!entry) goto err_alloc; - }if (tcp) { ct->proto.tcp.seen[0 ].flags |=IP_CT_TCP_FLAG_BE_LIBERAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 843/982 net: gue: reject invalid REMCSUM offsets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 2566866fc30965d915d0b52b5c3323b362619f0e ]
The REMCSUM option carries an absolute checksum start and checksum field offset. gue_remcsum() passes them to skb_remcsum_process(), whose partial path stores offset - start in the u16 skb->csum_offset variable. If offset is less than start, this underflows.
A forwarded packet can retain CHECKSUM_PARTIAL and reach a NETIF_F_HW_CSUM driver which trusts the metadata, leading skb_copy_and_csum_dev() to write two bytes about 64 KiB beyond the destination buffer.
Reject reversed tuples in validate_gue_flags(), after the existing length validation, so all GUE parsers enforce the ordering in one place.
--- include/net/gue.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
include/net/gue.h +15 -4
@@ -84,8 +84,9 @@ static inline size_t guehdr_priv_flags_len(__be32 flags) }/* Validate standard and private flags. Returns non-zero (meaning invalid) -* if there is an unknown standard or private flags, or the options length for -* the flags exceeds the options length specific in hlen of the GUE header. +* if there is an unknown standard or private flags, if the options length for +* the flags exceeds the options length specified in hlen of the GUE header, or +* if a private option contains invalid data. */ static inline int validate_gue_flags (struct guehdr *guehdr,size_t optlen) {
@@ -103,8 +104,8 @@ static inline int validate_gue_flags(struct guehdr *guehdr, size_t optlen)/* Private flags are last four bytes accounted in * guehdr_flags_len */ -__be32 pflags = *(__be32 *)((void *)&guehdr[1 ] + - len -GUE_LEN_PRIV ); +void *data = (void *)&guehdr[1 ] + len; +__be32 pflags = *(__be32 *)(data -GUE_LEN_PRIV );if (pflags & ~GUE_PFLAGS_ALL )return 1 ;
@@ -112,6 +113,16 @@ static inline int validate_gue_flags(struct guehdr *guehdr, size_t optlen) len +=guehdr_priv_flags_len (pflags);if (len > optlen)return 1 ; + +if (pflags &GUE_PFLAG_REMCSUM ) { +__be16 *pd = data; + +/* The field offset pd[1] must not be less +* than the start pd[0]. +*/ +if (ntohs (pd[1 ]) <ntohs (pd[0 ])) +return 1 ; + } }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 844/982 ip6_gre: Call ip6erspan_tunnel_unlink_md() in ip6erspan_changelink().
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit dd47bcf279f1083f09bf5266890b26263361022b ]
The cited commit accidentally added ip6gre_tunnel_unlink_md() in ip6erspan_changelink().
Let's correct it to ip6erspan_tunnel_unlink_md().
--- net/ipv6/ip6_gre.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_gre.c +1 -1
@@ -2337,7 +2337,7 @@ static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],return PTR_ERR (t);ip6erspan_set_version (data, &p); -ip6gre_tunnel_unlink_md (ign, t); +ip6erspan_tunnel_unlink_md (ign, t);ip6gre_tunnel_unlink (ign, t);ip6erspan_tnl_change (t, &p, !tb[IFLA_MTU ]);ip6erspan_tunnel_link_md (ign, t);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 845/982 sctp: avoid livelock while updating retransmit path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiqi Sun <[email protected]>
[ Upstream commit d2c31b837406395e576afeb25958c98e9938f3f6 ]
sctp_assoc_update_retran_path() can loop forever when every remaining transport, including retran_path, is SCTP_UNCONFIRMED: the state check runs before the wraparound test, so the loop cannot observe that it has completed a full pass.
Fix this by considering a transport only when it is not UNCONFIRMED, then checking whether the walk has returned to retran_path. This makes the full-pass termination independent of the transport state while preserving the existing fallback selection semantics.
Also restore the NULL guard around the retran_path assignment. In the all-UNCONFIRMED case there is no eligible replacement transport, and installing NULL would leave later retransmit-path users and the debug print with a NULL path.
--- net/sctp/associola.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
net/sctp/associola.c +8 -7
@@ -1305,18 +1305,19 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)/* Manually skip the head element. */ if (&trans->transports == &asoc->peer.transport_addr_list)continue ; -if (trans->state ==SCTP_UNCONFIRMED ) -continue ; - trans_next =sctp_trans_elect_best (trans, trans_next); -/* Active is good enough for immediate return. */ -if (trans_next->state ==SCTP_ACTIVE ) -break ; +if (trans->state !=SCTP_UNCONFIRMED ) { + trans_next =sctp_trans_elect_best (trans, trans_next); +/* Active is good enough for immediate return. */ +if (trans_next->state ==SCTP_ACTIVE ) +break ; + }/* We've reached the end, time to update path. */ if (trans == asoc->peer.retran_path)break ; } - asoc->peer.retran_path = trans_next; +if (trans_next) + asoc->peer.retran_path = trans_next;pr_debug ("%s: association:%p updated new path to addr:%pISpc\n" , __func__, asoc, &asoc->peer.retran_path->ipaddr.sa);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 846/982 net: usb: catc: bound the RX packet length in catc_rx_done()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
[ Upstream commit 9d565b6b72fe3f41fd43636e143072848105189f ]
catc_rx_done() walks a multi-packet URB, reading a two-byte length from each packet header. Its bound, pkt_len > urb->actual_length, ignores the header offset and compares against the whole transfer rather than the bytes left from pkt_start, so a crafted packet header makes skb_copy_to_linear_data() read past the buffer.
A length below ETH_HLEN is also accepted, including zero, and eth_type_trans() then reads a MAC header from the uninitialised tailroom of a shorter skb. The is_f5u011 branch takes its length straight from the transfer, so a zero-length URB reaches the same path.
Track the bytes remaining from the current packet, and reject a header that does not fit, a length past what is left, and a length below an Ethernet header.
A transfer shorter than an Ethernet header, including a zero-length one, previously became a runt skb passed to netif_rx() and counted as received; it is now counted in rx_length_errors and ends the walk.
--- drivers/net/usb/catc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/net/usb/catc.c +12 -3
@@ -239,17 +239,26 @@ static void catc_rx_done(struct urb *urb) } do { - if(!catc->is_f5u011) { - pkt_len = le16_to_cpup((__le16*)pkt_start); - if (pkt_len > urb->actual_length) { + int remaining = urb->actual_length - + (pkt_start - (u8 *)urb->transfer_buffer); + + if (!catc->is_f5u011) { + if (remaining < pkt_offset) { catc->netdev->stats.rx_length_errors++; catc->netdev->stats.rx_errors++; break; } + pkt_len = le16_to_cpup((__le16 *)pkt_start); } else { pkt_len = urb->actual_length; } + if (pkt_len < ETH_HLEN || pkt_len + pkt_offset > remaining) { + catc->netdev->stats.rx_length_errors++; + catc->netdev->stats.rx_errors++; + break; + } + if (!(skb = dev_alloc_skb(pkt_len))) return;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 847/982 net/sched: sch_hfsc: bound the classify inner-filter walk with a drift budget
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 8a60ade2277e1f0e0d0578d565354e52292fa46d ]
hfsc_classify() applies the "filter may only point downwards" level check only when the filter result carries no bound class. A filter created with a flowid gets res.class set once at bind time, so the check never runs for it during classification. hfsc_adjust_levels() can later raise a class's level without revalidating existing bindings, leaving two binds that were each legal at bind time pointing at each other; the classify walk then bounces between two interior classes forever with the qdisc lock held and BH disabled — a soft lockup from a single packet. The stuck walk trips the watchdog:
watchdog: BUG: soft lockup - CPU#3 stuck for 13s! [ping:444] RIP: 0010:u32_classify+0x542/0x17f0 ... tcf_classify+0x66/0xa0 hfsc_enqueue+0x166/0xdf0
Bound the traversal with a budget of non-descending hops, the only way a configured walk can move without descending the class tree once levels drift after bind time. The budget is cumulative over the whole walk and is deliberately not reset on a descending hop: a chain that alternates a descent with a lateral hop would return the budget every lap and never trip. Descending hops never decrement it, so legitimately deep trees are unaffected and a terminating lateral chain still classifies normally. Drop the packet with a rate-limited warning once the budget is exhausted, mirroring the merged HTB fix.
This is a follow-up to commit 729c4896ab82 ("net/sched: sch_htb: limit htb_classify inner-class filter hops"), which bounded the same classify loop on the HTB side but left the HFSC walk unbounded.
Conditions to recreate the bug:
- CONFIG_NET_SCHED, CONFIG_NET_SCH_HFSC, CONFIG_NET_CLS_U32, CONFIG_LOCKUP_DETECTOR.
- Build a cycle with two legal-at-bind-time flowid binds and a level
drift: class X 1:1 (child of root) with leaf child 1:10; class Y 1:2 (sibling of X) with children 1:20 and 1:200; root u32 filter flowid 1:1; filter on X flowid 1:2 (legal when Y is a leaf); after Y's level rises to 2, filter on Y flowid 1:1 (legal then). Send one packet (ping on the device). Unfixed kernel: classify spins with the qdisc lock held; with softlockup_panic=1 it panics.
- Reachable from unprivileged user via unshare -Urn (CAP_NET_ADMIN).
--- net/sched/sch_hfsc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
net/sched/sch_hfsc.c +22 -0
@@ -387,6 +387,15 @@ cftree_update(struct hfsc_class *cl)#define SM_MASK ((1ULL << SM_SHIFT) - 1)#define ISM_MASK ((1ULL << ISM_SHIFT) - 1) +/* +* Cap on the non-descending hops a classify walk may take before its +* filter chain is treated as misconfigured. A flowid binding that was +* legal at bind time can become lateral once hfsc_adjust_levels() +* raises a class level; a few such hops are legitimate, an unbounded +* run means the chain cycles. +*/ +#define HFSC_CLASSIFY_MAX_DRIFT 8 +static inline u64 seg_x2y (u64 x,u64 sm) {
@@ -1131,6 +1140,7 @@ hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)struct hfsc_class *head, *cl;struct tcf_result res;struct tcf_proto *tcf; +unsigned int drift;int result; if (TC_H_MAJ(skb->priority ^ sch->handle) == 0 &&
@@ -1140,6 +1150,7 @@ hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) *qerr =NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; head = &q->root; + drift =HFSC_CLASSIFY_MAX_DRIFT ; tcf =rcu_dereference_bh (q->root.filter_list);while (tcf && (result =tcf_classify (skb,NULL , tcf, &res, false)) >=0 ) {#ifdef CONFIG_NET_CLS_ACT
@@ -1165,6 +1176,17 @@ hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)if (cl->level ==0 )return cl;/* hit leaf class */ +/* +* flowid binds skip the level check above (res.class is set +* at bind time and levels drift after), so a walk can follow +* lateral hops without descending; a bounded number of them +* is legal, more means the chain cycles. +*/ +if (cl->level >= head->level && drift-- ==0 ) { +pr_warn_ratelimited ("hfsc: classify hop budget exhausted, dropping packet\n" ); +return NULL ; + } +/* apply inner filter chain */ tcf =rcu_dereference_bh (cl->filter_list); head = cl;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 848/982 drm/virtio: fix object leak when drm_gem_handle_create() fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 36570ef2244cc4d7563b1f0157bc0f032498638c ]
virtio_gpu_gem_create() owns the reference taken by virtio_gpu_object_create(). On the drm_gem_handle_create() error path it calls drm_gem_object_release() instead of dropping that reference.
drm_gem_object_release() is the inverse of drm_gem_object_init() and does not touch the reference count or call obj->funcs->free(), so it is only correct as the last step of a destructor, as in virtio_gpu_cleanup_object(). Using it here leaves the bo at refcount 1 with no remaining reference, so virtio_gpu_free_object() never runs and the shmem pages, sg table and virtio_gpu_object are leaked. Since virtio_gpu_object_create() has already set bo->created, VIRTIO_GPU_CMD_RESOURCE_UNREF is not queued either, leaking the host-side resource and the resource id.
drm_gem_handle_create_tail() drops the handle reference on all of its internal error paths, so the caller only has to drop its own. Use drm_gem_object_put(), matching the success path below.
--- drivers/gpu/drm/virtio/virtgpu_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_gem.c +1 -1
@@ -45,7 +45,7 @@ static int virtio_gpu_gem_create(struct drm_file *file, ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) { -drm_gem_object_release (&obj->base.base); +drm_gem_object_put (&obj->base.base);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 849/982 drm/virtio: fix object leak in virtio_gpu_resource_create_ioctl()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 477bc3068fc3777b9d8ffd79e265b0dfdf2d3a6b ]
virtio_gpu_resource_create_ioctl() calls drm_gem_object_release() on the drm_gem_handle_create() error path instead of dropping the reference it owns, so obj->funcs->free() never runs and the virtio_gpu_object, its pages and sg table, the resource id and the host-side resource are leaked.
Use drm_gem_object_put() instead.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -1
@@ -358,7 +358,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, ret =drm_gem_handle_create (file, obj, &handle);if (ret) { -drm_gem_object_release (obj); +drm_gem_object_put (obj);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 850/982 drm/virtio: fix object leaks in virtio_gpu_resource_create_blob_ioctl()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 24b6d5c7641412c9ebef0d4c8b888d49a0e6b880 ]
virtio_gpu_resource_create_blob_ioctl() calls drm_gem_object_release() on both the virtio_gpu_resource_assign_uuid() and drm_gem_handle_create() error paths instead of dropping the reference it owns, so obj->funcs->free() never runs and the virtio_gpu_object, the resource id and the host-side resource are leaked.
Use drm_gem_object_put() instead.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -2
@@ -724,14 +724,14 @@ static int virtio_gpu_resource_create_blob_ioctl(struct drm_device *dev,if (params.blob_flags &VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE ) { ret =virtio_gpu_resource_assign_uuid (vgdev, bo);if (ret) { -drm_gem_object_release (obj); +drm_gem_object_put (obj);return ret; } } ret =drm_gem_handle_create (file, obj, &handle);if (ret) { -drm_gem_object_release (obj); +drm_gem_object_put (obj);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 851/982 drm/virtio: release the GEM object on virtio_gpu_vram_create() errors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 036d28db1818af2f9d80db771f5405da84d7732d ]
virtio_gpu_vram_create() frees the object with a bare kfree(vram) on both error paths after drm_gem_private_object_init() has run, and on the second one after drm_gem_create_mmap_offset() has linked obj->vma_node into the device's VMA offset manager. The freed object stays in that interval tree, so a later lookup or insertion walks freed memory, and the dma_resv and gpuva lock are never destroyed.
Call drm_gem_object_release() before kfree() on both paths.
--- drivers/gpu/drm/virtio/virtgpu_vram.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vram.c +9 -8
@@ -202,16 +202,12 @@ int virtio_gpu_vram_create(struct virtio_gpu_device *vgdev,/* Create fake offset */ ret =drm_gem_create_mmap_offset (obj); -if (ret) { -kfree (vram); -return ret; - } +if (ret) + goto err_release_obj; ret =virtio_gpu_resource_id_get (vgdev, &vram->base.hw_res_handle); -if (ret) { -kfree (vram); -return ret; - } +if (ret) + goto err_release_obj;virtio_gpu_cmd_resource_create_blob (vgdev, &vram->base, params,NULL ,0 );
@@ -225,4 +221,9 @@ int virtio_gpu_vram_create(struct virtio_gpu_device *vgdev, *bo_ptr = &vram->base;return 0 ; + +err_release_obj: +drm_gem_object_release (obj); +kfree (vram); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 852/982 Bluetooth: bnep: fix out-of-bounds reads on short RX/TX frames and control fallthrough
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit f0ca020cbb9bb7f3f4ea8ba1dfcf30a282aec91e ]
Fix multiple out-of-bounds reads in Bluetooth BNEP frame processing:
1. In bnep_rx_frame() and bnep_ctrl_frame() (net/bluetooth/bnep/core.c), use pskb_may_pull() to verify the BNEP header, control type byte, filter count, and extension headers exist before reading them, and return 0 after handling BNEP_CONTROL instead of falling through to Ethernet frame submission when no extension headers follow.
2. In bnep_net_xmit() (net/bluetooth/bnep/netdev.c), verify skb->len >= ETH_HLEN with pskb_may_pull() before reading the 14-byte Ethernet header to prevent an out-of-bounds heap read and infoleak on short AF_PACKET TX frames.
--- net/bluetooth/bnep/core.c | 17 ++++++++++++++++- net/bluetooth/bnep/netdev.c | 8 +++++++- 2 files changed, 23 insertions(+), 2 deletions(-)
net/bluetooth/bnep/core.c +16 -1
@@ -273,9 +273,14 @@ static int bnep_rx_extension(struct bnep_session *s, struct sk_buff *skb)BT_DBG ("type 0x%x len %u" , h->type, h->len); +if (skb->len < h->len) { + err = -EILSEQ ; +break ; + } +switch (h->type &BNEP_TYPE_MASK ) {case BNEP_EXT_CONTROL : -bnep_rx_control (s, skb->data, skb->len); +bnep_rx_control (s, skb->data, h->len);break ;default :
@@ -376,6 +381,11 @@ static int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb) goto badframe; } +if ((type &BNEP_TYPE_MASK ) ==BNEP_CONTROL ) { +kfree_skb (skb); +return 0 ; + } +/* Strip 802.1p header */ if (ntohs (s->eh.h_proto) ==ETH_P_8021Q ) {if (!skb_pull (skb,4 ))
@@ -454,6 +464,11 @@ static int bnep_tx_frame(struct bnep_session *s, struct sk_buff *skb) goto send; } +if (skb->len <ETH_HLEN ) { +kfree_skb (skb); +return 0 ; + } + iv[il++] = (struct kvec ) { &type,1 }; len++;
net/bluetooth/bnep/netdev.c +7 -1
@@ -169,6 +169,12 @@ static netdev_tx_t bnep_net_xmit(struct sk_buff *skb,BT_DBG ("skb %p, dev %p" , skb, dev); +if (!pskb_may_pull (skb,ETH_HLEN )) { + dev->stats.tx_dropped++; +kfree_skb (skb); +return NETDEV_TX_OK ; + } +#ifdef CONFIG_BT_BNEP_MC_FILTER if (bnep_net_mc_filter (skb, s)) {kfree_skb (skb);
@@ -221,7 +227,7 @@ void bnep_net_setup(struct net_device *dev) dev->addr_len =ETH_ALEN ;ether_setup (dev); - dev->min_mtu =0 ; + dev->min_mtu =ETH_MIN_MTU ; dev->max_mtu =ETH_MAX_MTU ; dev->priv_flags &= ~IFF_TX_SKB_SHARING ; dev->netdev_ops = &bnep_netdev_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 853/982 Bluetooth: RFCOMM: Reject short EA=0 frames in rfcomm_recv_frame()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit 6d91041bb38b97e2feb625123cc0529d7b83a0e1 ]
While rfcomm_recv_frame() verifies that skb->len is at least sizeof(*hdr) + 1 (4 bytes: 3-byte header + 1-byte FCS), an RFCOMM frame with an extended 2-byte length field (!__test_ea(hdr->len)) has a 4-byte header plus a 1-byte FCS (5 bytes minimum, sizeof(*hdr) + 2).
When a 4-byte RFCOMM frame with EA == 0 arrives:
1. The initial skb->len < sizeof(*hdr) + 1 check passes (4 < 4 is false).
2. Trimming the FCS byte decrements skb->len to 3.
3. If __check_fcs() succeeds, skb_pull(skb, 4) fails (4 > 3) and returns NULL without advancing skb->data.
4. Because the return value of skb_pull() is ignored, the un-pulled 3-byte struct rfcomm_hdr remains at skb->data and is either queued as application payload via rfcomm_recv_data() or parsed as a multiplexer control command via rfcomm_recv_mcc() on DLCI 0.
Fix this by extending the length check in rfcomm_recv_frame() to also require skb->len >= sizeof(*hdr) + 2 when !__test_ea(hdr->len).
--- net/bluetooth/rfcomm/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/rfcomm/core.c +2 -1
@@ -1813,7 +1813,8 @@ static struct rfcomm_session *rfcomm_recv_frame(struct rfcomm_session *s,return s; } -if (skb->len <sizeof (*hdr) +1 ) { +if (skb->len <sizeof (*hdr) +1 || + (!__test_ea (hdr->len) && skb->len <sizeof (*hdr) +2 )) {kfree_skb (skb);return s; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 854/982 net: usb: sr9700: include receive overhead in the length check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit c06bde80ae7a7b595732f7cabcb92cf08db9d56a ]
The receive fixup subtracts the Ethernet CRC from the reported packet length, but compares that payload length against the whole remaining receive buffer. The following copy starts after the three-byte header, and the cursor advance consumes both that header and the four-byte CRC.
Require the payload to fit after SR_RX_OVERHEAD before copying it or advancing to the next packet. The loop already ensures that the remaining buffer is larger than the overhead, so the subtraction is safe.
The issue was found by our static-analysis tool.
--- drivers/net/usb/sr9700.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/usb/sr9700.c +2 -1
@@ -403,7 +403,8 @@ static int sr9700_rx_fixup(struct usbnet *dev, struct sk_buff *skb)/* ignore the CRC length */ len = (skb->data[1 ] | (skb->data[2 ] <<8 )) -4 ; -if (len >ETH_FRAME_LEN || len > skb->len || len <0 ) +if (len >ETH_FRAME_LEN || len <0 || + len > skb->len -SR_RX_OVERHEAD )return 0 ;/* the last packet of current skb */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 855/982 tg3: clean up PHYLIB resources on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit a92e1a412c53dc0d9ad639e7abf8b3fc70a5b6ad ]
tg3_get_invariants() can register an MDIO bus and connect a PHY for USE_PHYLIB devices. If tg3_init_one() later fails, its common error path releases the mappings and netdev without undoing those PHYLIB resources.
Disconnect the PHY and unregister the MDIO bus before the remaining teardown. Guard PHY cleanup with USE_PHYLIB to match tg3_phy_init(), and call tg3_mdio_fini() unconditionally to match tg3_mdio_init(). The existing IS_CONNECTED and MDIOBUS_INITED flags make both helpers safe when initialization only completed partially.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/net/ethernet/broadcom/tg3.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/broadcom/tg3.c +4 -0
@@ -17969,6 +17969,10 @@ static int tg3_init_one(struct pci_dev *pdev,return 0 ; err_out_apeunmap: +if (tg3_flag (tp,USE_PHYLIB )) +tg3_phy_fini (tp); +tg3_mdio_fini (tp); +if (tp->aperegs) {iounmap (tp->aperegs); tp->aperegs =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 856/982 s390/debug: Do not register views for failed static debug areas
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Zaslonko <[email protected]>
[ Upstream commit 28e29992b034acffc9342df216c06097825ce610 ]
__REGISTER_STATIC_DEBUG_INFO() calls debug_register_view() unconditionally, even when debug_register_static() has failed. In that case _debug_register() was never reached and id->debugfs_root_entry is still NULL, so debugfs_create_file() places the view file in the debugfs root directory. For sclp_err this leaves a /sys/kernel/debug/hex_ascii file with nothing to indicate which debug log it belongs to.
debug_register_static() is not exported and the macro is its only caller, so let it return an error code and skip the view registration when it fails. No debugfs files are created for such an area then.
Reproduce by booting with s390dbf=sclp_err::100000000. The sclp_err registration fails, no s390dbf/sclp_err/ directory is created, and a hex_ascii file appears in the debugfs root instead.
--- arch/s390/include/asm/debug.h | 8 ++++++-- arch/s390/kernel/debug.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-)
arch/s390/include/asm/debug.h +6 -2
@@ -451,7 +451,11 @@ static int VNAME(var, active_entries)[EARLY_AREAS] __initdata#define __REGISTER_STATIC_DEBUG_INFO (var, name, pages, areas, view) \ static int __init VNAME(var, reg)(void) \ { \ - debug_register_static(&var, (pages), (areas)); \ + int rc; \ + \ + rc = debug_register_static(&var, (pages), (areas)); \ + if (rc) \ + return rc; \ debug_register_view(&var, (view)); \ return 0; \ } \
@@ -483,7 +487,7 @@ static debug_info_t __refdata var = \__DEBUG_INFO_INIT (var, (name), (buf_size)); \ __REGISTER_STATIC_DEBUG_INFO(var, name, pages, nr_areas, view) -void debug_register_static (debug_info_t *id,int pages_per_area,int nr_areas); +int debug_register_static (debug_info_t *id,int pages_per_area,int nr_areas);#endif /* MODULE */
arch/s390/kernel/debug.c +9 -3
@@ -703,8 +703,12 @@ EXPORT_SYMBOL(debug_register);* * Note: This function is called automatically via an initcall generated by * DEFINE_STATIC_DEBUG_INFO. +* +* Return: +* - 0 on success +* - negative error code on failure */ -void debug_register_static (debug_info_t *id,int pages_per_area,int nr_areas) +int debug_register_static (debug_info_t *id,int pages_per_area,int nr_areas) {unsigned long flags;debug_info_t *copy;
@@ -712,7 +716,7 @@ void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas)if (!initialized) {pr_err ("Tried to register debug feature %s too early\n" , id->name); -return ; +return -EINVAL ; } copy = debug_info_alloc("", pages_per_area, nr_areas, id->buf_size,
@@ -727,7 +731,7 @@ void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas) id->active_entries =NULL ;spin_unlock_irqrestore (&id->lock, flags); -return ; +return -ENOMEM ; }/* Replace static trace area with dynamic copy. */
@@ -745,6 +749,8 @@ void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas)mutex_lock (&debug_mutex);_debug_register (id);mutex_unlock (&debug_mutex); + +return 0 ; }/* Remove debugfs entries. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 857/982 s390/debug: Fix NULL pointer dereference in debug_info_copy()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Zaslonko <[email protected]>
[ Upstream commit 012bfcd5a51082d5a65f096dfb9ca652b5267965 ]
When debug_register_static() fails, it clears areas, active_pages and active_entries but leaves the area bounds unchanged. Copying such an area, either by opening its view file or via debug_dump(), makes debug_info_copy() dereference the NULL pointers.
Skip the copy loop when the source has no areas.
--- arch/s390/kernel/debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/debug.c +2 -1
@@ -345,7 +345,8 @@ static debug_info_t *debug_info_copy(debug_info_t *in, int mode)debug_info_free (rc); }while (1 ); -if (mode ==NO_AREAS ) +/* debug_register_static() failure leaves areas NULL, bounds intact */ +if (mode ==NO_AREAS || !in->areas) goto out;for (i =0 ; i < in->nr_areas; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 858/982 net: ethernet: ti: netcp: fix pm_runtime usage counter leak on error
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit ac4334522e4ba4a3b6710dd5d4cc98092824b8ca ]
pm_runtime_get_sync() leaves the runtime PM usage counter incremented even when it fails, but the error path in netcp_probe() does not call pm_runtime_put_noidle() to balance it, leaking a reference each time resume fails.
Use pm_runtime_resume_and_get() instead, which automatically drops the usage counter on failure, fixing the leak.
--- drivers/net/ethernet/ti/netcp_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ti/netcp_core.c +1 -1
@@ -2167,7 +2167,7 @@ static int netcp_probe(struct platform_device *pdev)return -ENOMEM ;pm_runtime_enable (&pdev->dev); - ret =pm_runtime_get_sync (&pdev->dev); + ret =pm_runtime_resume_and_get (&pdev->dev);if (ret <0 ) {dev_err (dev,"Failed to enable NETCP power-domain\n" );pm_runtime_disable (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 859/982 bpf: Fix bpf_sock context code generation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Emil Tsalapatis <[email protected]>
[ Upstream commit 4a4852376e3a2727ea40e61143d6d7c22bb6dfad ]
Currently, the ctx access code reads the rx_queue_mapping field with either a 4-byte or 2-byte load. The rest of the bits in the register are marked known zero by the verifier. However, the emitted ctx access code places in the register on certain the special value (-1) using BPF_MOV_IMM64, which gets sign-extended to turn on all the bits in the register. By shifting this value right, the program ends up with a value at runtime above what the verifier assumes is possible.
Fix this by ensuring the read value is as wide as the assumed size. Use MOV32 instructions instead of MOV64 instructions to keep the upper bits zero as assumed by the verifier. Also properly report the size of the destination variable (the bpf_sock field, 4 bytes) instead of the source (the socket field, 2 bytes).
--- net/core/filter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/core/filter.c +4 -3
@@ -10049,11 +10049,12 @@ u32 bpf_sock_convert_ctx_access(enum bpf_access_type type, target_size)); *insn++ =BPF_JMP_IMM (BPF_JNE , si->dst_reg,NO_QUEUE_MAPPING ,1 ); - *insn++ =BPF_MOV64_IMM (si->dst_reg,-1 ); + *insn++ =BPF_MOV32_IMM (si->dst_reg,-1 );#else - *insn++ =BPF_MOV64_IMM (si->dst_reg,-1 ); - *target_size =2 ; + *insn++ =BPF_MOV32_IMM (si->dst_reg,-1 );#endif + *target_size = sizeof_field(struct bpf_sock, rx_queue_mapping); +break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 860/982 bpf, sockmap: Reject max_entries > INT_MAX in sock_map_alloc
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Gongyi <[email protected]>
[ Upstream commit 814a81c842bd88f6bd8a4ce550d560df071a5d03 ]
sock_map_alloc() only rejects max_entries == 0 and otherwise allows any u32 value. sock_map_free() then walks the sks[] array with a signed int iterator:
int i; for (i = 0; i < stab->map.max_entries; i++) struct sock **psk = &stab->sks[i];
When a SOCKMAP is created with max_entries = 0xffffffff (UINT_MAX), the allocation of 32 GiB can succeed on large-memory hosts. During free the counter reaches 0x80000000, wraps to INT_MIN, is sign-extended by movslq and turned into a ~16 GiB negative offset from stab->sks, pointing far below the allocation.
The faulting access is an xchg() write in sock_map_free(). Without KASAN, the same out-of-bounds write can fault on an unmapped vmalloc page or corrupt an unrelated allocation if that vmalloc address is populated. On a KASAN kernel with CONFIG_KASAN_VMALLOC=y, the shadow check for that address hits an unmapped shadow page and oopses first:
BUG: unable to handle page fault for address: fffff521b59c5a00 RIP: 0010:kasan_check_range+0x107/0x190 Call Trace: sock_map_free+0x93/0x190 map_create+0x68d/0xb30 __sys_bpf+0x21e/0x2e70
Vmcore confirmed stab->map.max_entries == 0xffffffff, stab->sks == 0xffffc911ace2d000, and the faulting address sks + (s64)INT_MIN * 8 exactly at 0xffffc90dace2d000. The same buggy path is reached on the normal close()/bpf_map_free_deferred() path whenever such a map is destroyed.
sock_map_alloc() used to bound its allocation size through bpf_map_charge_init(), but the bound was dropped when rlimit-based memory accounting was removed. Reject max_entries > INT_MAX at creation time so the signed iterator in sock_map_free() never sees a value that would overflow.
Triggered by syzkaller and reproduced on both a 6.6-based KASAN kernel and the upstream v7.3-rc2 kernel.
--- net/core/sock_map.c | 1 + 1 file changed, 1 insertion(+)
net/core/sock_map.c +1 -0
@@ -35,6 +35,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)if (!capable (CAP_NET_ADMIN ))return ERR_PTR (-EPERM ); if (attr->max_entries == 0 || + attr->max_entries > INT_MAX || attr->key_size != 4 || (attr->value_size != sizeof(u32) && attr->value_size != sizeof(u64)) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 861/982 net/mlx5: Add mlx5_ifc definitions for bridge multicast support
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit e5688f6fb9e3d0254a8fb1c714c38e407f0baa64 ]
Add the required hardware definitions to mlx5_ifc: fdb_uplink_hairpin, fdb_multi_path_any_table_limit_regc, fdb_multi_path_any_table.
Stable-dep-of: 35e6f970f553 ("net/mlx5: Bridge, don't fail switchdev events of sibling eswitch ports")
--- include/linux/mlx5/mlx5_ifc.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/linux/mlx5/mlx5_ifc.h +6 -1
@@ -865,7 +865,12 @@ enum {struct mlx5_ifc_flow_table_eswitch_cap_bits {u8 fdb_to_vport_reg_c_id[0x8 ]; -u8 reserved_at_8[0xd ]; +u8 reserved_at_8[0x5 ]; +u8 fdb_uplink_hairpin[0x1 ]; +u8 fdb_multi_path_any_table_limit_regc[0x1 ]; +u8 reserved_at_f[0x3 ]; +u8 fdb_multi_path_any_table[0x1 ]; +u8 reserved_at_13[0x2 ];u8 fdb_modify_header_fwd_to_table[0x1 ];u8 fdb_ipv4_ttl_modify[0x1 ];u8 flow_source[0x1 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 862/982 net/mlx5: Bridge, increase bridge tables sizes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit 9071b423c302b70eff80da715d724c4e75c1c46a ]
Bridge ingress and egress tables got more flow groups recently for QinQ support and will get more in following patches of this series. Increase the sizes of the tables to allow offloading more flows in each mode.
Stable-dep-of: 35e6f970f553 ("net/mlx5: Bridge, don't fail switchdev events of sibling eswitch ports")
--- drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +6 -6
@@ -13,8 +13,8 @@#define CREATE_TRACE_POINTS #include "diag/bridge_tracepoint.h" -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE 12000 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE 16000 +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE 131072 +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE 524288#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_FROM 0#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_TO \ (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1)
@@ -40,10 +40,10 @@ MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE - 1)#define MLX5_ESW_BRIDGE_INGRESS_TABLE_SIZE \ (MLX5_ESW_BRIDGE_INGRESS_TABLE_MAC_GRP_IDX_TO + 1) -static_assert (MLX5_ESW_BRIDGE_INGRESS_TABLE_SIZE ==64000 ); +static_assert (MLX5_ESW_BRIDGE_INGRESS_TABLE_SIZE ==1048576 ); -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_SIZE 16000 -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_SIZE (32000 - 1) +#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_SIZE 131072 +#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_SIZE (262144 - 1)#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_IDX_FROM 0#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_IDX_TO \ (MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_SIZE - 1)
@@ -63,7 +63,7 @@ static_assert(MLX5_ESW_BRIDGE_INGRESS_TABLE_SIZE == 64000); MLX5_ESW_BRIDGE_EGRESS_TABLE_MISS_GRP_IDX_FROM#define MLX5_ESW_BRIDGE_EGRESS_TABLE_SIZE \ (MLX5_ESW_BRIDGE_EGRESS_TABLE_MISS_GRP_IDX_TO + 1) -static_assert (MLX5_ESW_BRIDGE_EGRESS_TABLE_SIZE ==64000 ); +static_assert (MLX5_ESW_BRIDGE_EGRESS_TABLE_SIZE ==524288 );#define MLX5_ESW_BRIDGE_SKIP_TABLE_SIZE 0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 863/982 net/mlx5: Bridge, move additional data structures to priv header
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit 6767c97d7adc3c4283c0167a9716de3953f251b1 ]
Following patches in series will require accessing flow tables and groups sizes, table levels and struct mlx5_esw_bridge from new the new source file dedicated to multicast code. Expose these data in bridge_priv.h to reduce clutter in following patches that will implement the actual functionality.
Stable-dep-of: 35e6f970f553 ("net/mlx5: Bridge, don't fail switchdev events of sibling eswitch ports")
--- .../ethernet/mellanox/mlx5/core/esw/bridge.c | 85 ------------------- .../mellanox/mlx5/core/esw/bridge_priv.h | 85 +++++++++++++++++++ 2 files changed, 85 insertions(+), 85 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +0 -85
@@ -13,66 +13,6 @@#define CREATE_TRACE_POINTS #include "diag/bridge_tracepoint.h" -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE 131072 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE 524288 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_FROM 0 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_FILTER_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_FILTER_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_FILTER_GRP_IDX_FROM + \ - MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_FILTER_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_GRP_IDX_FROM + \ - MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_FILTER_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_FILTER_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_FILTER_GRP_IDX_FROM + \ - MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_MAC_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_QINQ_FILTER_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_MAC_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_MAC_GRP_IDX_FROM + \ - MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_SIZE \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_MAC_GRP_IDX_TO + 1) -static_assert (MLX5_ESW_BRIDGE_INGRESS_TABLE_SIZE ==1048576 ); - -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_SIZE 131072 -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_SIZE (262144 - 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_IDX_FROM 0 -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_QINQ_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_QINQ_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_QINQ_GRP_IDX_FROM + \ - MLX5_ESW_BRIDGE_EGRESS_TABLE_VLAN_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_QINQ_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_IDX_FROM + \ - MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_SIZE - 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MISS_GRP_IDX_FROM \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_MAC_GRP_IDX_TO + 1) -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_MISS_GRP_IDX_TO \ - MLX5_ESW_BRIDGE_EGRESS_TABLE_MISS_GRP_IDX_FROM -#define MLX5_ESW_BRIDGE_EGRESS_TABLE_SIZE \ - (MLX5_ESW_BRIDGE_EGRESS_TABLE_MISS_GRP_IDX_TO + 1) -static_assert (MLX5_ESW_BRIDGE_EGRESS_TABLE_SIZE ==524288 ); - -#define MLX5_ESW_BRIDGE_SKIP_TABLE_SIZE 0 - -enum { -MLX5_ESW_BRIDGE_LEVEL_INGRESS_TABLE , -MLX5_ESW_BRIDGE_LEVEL_EGRESS_TABLE , -MLX5_ESW_BRIDGE_LEVEL_SKIP_TABLE , -}; -static const struct rhashtable_params fdb_ht_params = { .key_offset = offsetof(struct mlx5_esw_bridge_fdb_entry , key), .key_len =sizeof (struct mlx5_esw_bridge_fdb_key ),
@@ -80,31 +20,6 @@ static const struct rhashtable_params fdb_ht_params = { .automatic_shrinking = true, }; -enum { -MLX5_ESW_BRIDGE_VLAN_FILTERING_FLAG =BIT (0 ), -}; - -struct mlx5_esw_bridge { -int ifindex; -int refcnt; -struct list_head list; -struct mlx5_esw_bridge_offloads *br_offloads; - -struct list_head fdb_list; -struct rhashtable fdb_ht; - -struct mlx5_flow_table *egress_ft; -struct mlx5_flow_group *egress_vlan_fg; -struct mlx5_flow_group *egress_qinq_fg; -struct mlx5_flow_group *egress_mac_fg; -struct mlx5_flow_group *egress_miss_fg; -struct mlx5_pkt_reformat *egress_miss_pkt_reformat; -struct mlx5_flow_handle *egress_miss_handle; -unsigned long ageing_time; -u32 flags; -u16 vlan_proto; -}; -static void mlx5_esw_bridge_fdb_offload_notify (struct net_device *dev,const unsigned char *addr,u16 vid,unsigned long val)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge_priv.h +85 -0
95 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 864/982 net/mlx5: Bridge, extract code to lookup parent bridge of port
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit b99c4ef29e278ab0b91406e52df4fa9b634b117e ]
The pattern when function looks up a port by vport_num+vhca_id tuple in order to just obtain its parent bridge is repeated multiple times in bridge.c file. Further commits in this series use the pattern even more. Extract the pattern to standalone mlx5_esw_bridge_from_port_lookup() function to improve code readability.
This commits doesn't change functionality.
Stable-dep-of: 35e6f970f553 ("net/mlx5: Bridge, don't fail switchdev events of sibling eswitch ports")
--- .../ethernet/mellanox/mlx5/core/esw/bridge.c | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +26 -21
@@ -933,6 +933,19 @@ static void mlx5_esw_bridge_port_erase(struct mlx5_esw_bridge_port *port,xa_erase (&br_offloads->ports,mlx5_esw_bridge_port_key (port)); } +static struct mlx5_esw_bridge * +mlx5_esw_bridge_from_port_lookup (u16 vport_num,u16 esw_owner_vhca_id, +struct mlx5_esw_bridge_offloads *br_offloads) +{ +struct mlx5_esw_bridge_port *port; + + port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +if (!port) +return NULL ; + +return port->bridge; +} +static void mlx5_esw_bridge_fdb_entry_refresh (struct mlx5_esw_bridge_fdb_entry *entry) {trace_mlx5_esw_bridge_fdb_entry_refresh (entry);
@@ -1388,28 +1401,26 @@ mlx5_esw_bridge_fdb_entry_init(struct net_device *dev, u16 vport_num, u16 esw_owint mlx5_esw_bridge_ageing_time_set (u16 vport_num,u16 esw_owner_vhca_id,unsigned long ageing_time,struct mlx5_esw_bridge_offloads *br_offloads) { -struct mlx5_esw_bridge_port *port; +struct mlx5_esw_bridge *bridge; - port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); -if (!port) + bridge =mlx5_esw_bridge_from_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +if (!bridge)return -EINVAL ; - port->bridge->ageing_time =clock_t_to_jiffies (ageing_time); + bridge->ageing_time =clock_t_to_jiffies (ageing_time);return 0 ; }int mlx5_esw_bridge_vlan_filtering_set (u16 vport_num,u16 esw_owner_vhca_id,bool enable,struct mlx5_esw_bridge_offloads *br_offloads) { -struct mlx5_esw_bridge_port *port;struct mlx5_esw_bridge *bridge;bool filtering; - port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); -if (!port) + bridge =mlx5_esw_bridge_from_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +if (!bridge)return -EINVAL ; - bridge = port->bridge; filtering = bridge->flags &MLX5_ESW_BRIDGE_VLAN_FILTERING_FLAG ;if (filtering == enable)return 0 ;
@@ -1426,15 +1437,13 @@ int mlx5_esw_bridge_vlan_filtering_set(u16 vport_num, u16 esw_owner_vhca_id, booint mlx5_esw_bridge_vlan_proto_set (u16 vport_num,u16 esw_owner_vhca_id,u16 proto,struct mlx5_esw_bridge_offloads *br_offloads) { -struct mlx5_esw_bridge_port *port;struct mlx5_esw_bridge *bridge; - port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, - br_offloads); -if (!port) + bridge =mlx5_esw_bridge_from_port_lookup (vport_num, esw_owner_vhca_id, + br_offloads); +if (!bridge)return -EINVAL ; - bridge = port->bridge;if (bridge->vlan_proto == proto)return 0 ;if (proto !=ETH_P_8021Q && proto !=ETH_P_8021AD ) {
@@ -1626,14 +1635,12 @@ void mlx5_esw_bridge_fdb_update_used(struct net_device *dev, u16 vport_num, u16 struct switchdev_notifier_fdb_info *fdb_info) {struct mlx5_esw_bridge_fdb_entry *entry; -struct mlx5_esw_bridge_port *port;struct mlx5_esw_bridge *bridge; - port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); -if (!port) + bridge =mlx5_esw_bridge_from_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +if (!bridge)return ; - bridge = port->bridge; entry =mlx5_esw_bridge_fdb_lookup (bridge, fdb_info->addr, fdb_info->vid);if (!entry) { esw_debug(br_offloads->esw->dev,
@@ -1680,14 +1687,12 @@ void mlx5_esw_bridge_fdb_remove(struct net_device *dev, u16 vport_num, u16 esw_o {struct mlx5_eswitch *esw = br_offloads->esw;struct mlx5_esw_bridge_fdb_entry *entry; -struct mlx5_esw_bridge_port *port;struct mlx5_esw_bridge *bridge; - port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); -if (!port) + bridge =mlx5_esw_bridge_from_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +if (!bridge)return ; - bridge = port->bridge; entry =mlx5_esw_bridge_fdb_lookup (bridge, fdb_info->addr, fdb_info->vid);if (!entry) { esw_warn(esw->dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 865/982 net/mlx5: Bridge, snoop igmp/mld packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit 18c2916cee12137f32669d42ac1fbb87cba343bb ]
Handle SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED attribute notification to dynamically toggle bridge multicast offload. Set new MLX5_ESW_BRIDGE_MCAST_FLAG bridge flag when multicast offload is enabled. Put multicast-specific code into new bridge_mcast.c file.
When initializing bridge multicast pipeline create a static rule for snooping on IGMP traffic and three rules for snooping on MLD traffic (for query, report and done message types). Note that matching MLD traffic requires having flexparser MLX5_FLEX_PROTO_ICMPV6 capability enabled.
By default Linux bridge is created with multicast enabled which can be modified by 'mcast_snooping' argument:
$ ip link set name my_bridge type bridge mcast_snooping 0
Stable-dep-of: 35e6f970f553 ("net/mlx5: Bridge, don't fail switchdev events of sibling eswitch ports")
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../mellanox/mlx5/core/en/rep/bridge.c | 4 + .../ethernet/mellanox/mlx5/core/esw/bridge.c | 31 ++ .../ethernet/mellanox/mlx5/core/esw/bridge.h | 9 + .../mellanox/mlx5/core/esw/bridge_mcast.c | 316 ++++++++++++++++++ .../mellanox/mlx5/core/esw/bridge_priv.h | 27 +- 6 files changed, 384 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/bridge_mcast.c
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -75,7 +75,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += esw/acl/helper.o \ esw/acl/egress_lgcy.o esw/acl/egress_ofld.o \ esw/acl/ingress_lgcy.o esw/acl/ingress_ofld.o -mlx5_core-$(CONFIG_MLX5_BRIDGE) += esw/bridge.o en/rep/bridge.o +mlx5_core-$(CONFIG_MLX5_BRIDGE) += esw/bridge.o esw/bridge_mcast.o en/rep/bridge.o mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o mlx5_core-$(CONFIG_VXLAN) += lib/vxlan.o
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c +4 -0
@@ -301,6 +301,10 @@ mlx5_esw_bridge_port_obj_attr_set(struct net_device *dev, attr->u.vlan_protocol, br_offloads);break ; +case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED : + err =mlx5_esw_bridge_mcast_set (vport_num, esw_owner_vhca_id, + !attr->u.mc_disabled, br_offloads); +break ;default : err = -EOPNOTSUPP ; }
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +31 -0
@@ -868,6 +868,7 @@ static void mlx5_esw_bridge_put(struct mlx5_esw_bridge_offloads *br_offloads,return ;mlx5_esw_bridge_egress_table_cleanup (bridge); +mlx5_esw_bridge_mcast_disable (bridge);list_del (&bridge->list);rhashtable_destroy (&bridge->fdb_ht);kvfree (bridge);
@@ -1458,6 +1459,36 @@ int mlx5_esw_bridge_vlan_proto_set(u16 vport_num, u16 esw_owner_vhca_id, u16 proreturn 0 ; } +int mlx5_esw_bridge_mcast_set (u16 vport_num,u16 esw_owner_vhca_id,bool enable, +struct mlx5_esw_bridge_offloads *br_offloads) +{ +struct mlx5_eswitch *esw = br_offloads->esw; +struct mlx5_esw_bridge *bridge; +int err =0 ; +bool mcast; + +if (!(MLX5_CAP_ESW_FLOWTABLE ((esw)->dev, fdb_multi_path_any_table) || +MLX5_CAP_ESW_FLOWTABLE ((esw)->dev, fdb_multi_path_any_table_limit_regc)) || + !MLX5_CAP_ESW_FLOWTABLE ((esw)->dev, fdb_uplink_hairpin) || + !MLX5_CAP_ESW_FLOWTABLE_FDB ((esw)->dev, ignore_flow_level)) +return -EOPNOTSUPP ; + + bridge =mlx5_esw_bridge_from_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +if (!bridge) +return -EINVAL ; + + mcast = bridge->flags &MLX5_ESW_BRIDGE_MCAST_FLAG ; +if (mcast == enable) +return 0 ; + +if (enable) + err =mlx5_esw_bridge_mcast_enable (bridge); +else +mlx5_esw_bridge_mcast_disable (bridge); + +return err; +} +static int mlx5_esw_bridge_vport_init (u16 vport_num,u16 esw_owner_vhca_id,u16 flags,struct mlx5_esw_bridge_offloads *br_offloads,struct mlx5_esw_bridge *bridge)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.h +9 -0
@@ -25,12 +25,19 @@ struct mlx5_esw_bridge_offloads {struct delayed_work update_work;struct mlx5_flow_table *ingress_ft; +struct mlx5_flow_group *ingress_igmp_fg; +struct mlx5_flow_group *ingress_mld_fg;struct mlx5_flow_group *ingress_vlan_fg;struct mlx5_flow_group *ingress_vlan_filter_fg;struct mlx5_flow_group *ingress_qinq_fg;struct mlx5_flow_group *ingress_qinq_filter_fg;struct mlx5_flow_group *ingress_mac_fg; +struct mlx5_flow_handle *igmp_handle; +struct mlx5_flow_handle *mld_query_handle; +struct mlx5_flow_handle *mld_report_handle; +struct mlx5_flow_handle *mld_done_handle; +struct mlx5_flow_table *skip_ft; };
@@ -64,6 +71,8 @@ int mlx5_esw_bridge_vlan_filtering_set(u16 vport_num, u16 esw_owner_vhca_id, boo struct mlx5_esw_bridge_offloads *br_offloads);int mlx5_esw_bridge_vlan_proto_set (u16 vport_num,u16 esw_owner_vhca_id,u16 proto,struct mlx5_esw_bridge_offloads *br_offloads); +int mlx5_esw_bridge_mcast_set (u16 vport_num,u16 esw_owner_vhca_id,bool enable, +struct mlx5_esw_bridge_offloads *br_offloads);int mlx5_esw_bridge_port_vlan_add (u16 vport_num,u16 esw_owner_vhca_id,u16 vid,u16 flags,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack);
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge_mcast.c new file +316 -0
316 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge_priv.h +23 -4
@@ -12,11 +12,26 @@#include <linux/xarray.h> #include "fs_core.h" +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_IGMP_GRP_SIZE 1 +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_SIZE 3#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE 131072 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE 524288 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_FROM 0 -#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_TO \ - (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1) +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_UNTAGGED_GRP_SIZE \ + (524288 - MLX5_ESW_BRIDGE_INGRESS_TABLE_IGMP_GRP_SIZE - \ + MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_SIZE) + +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_IGMP_GRP_IDX_FROM 0 +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_IGMP_GRP_IDX_TO \ + (MLX5_ESW_BRIDGE_INGRESS_TABLE_IGMP_GRP_SIZE - 1) +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_IDX_FROM \ + (MLX5_ESW_BRIDGE_INGRESS_TABLE_IGMP_GRP_IDX_TO + 1) +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_IDX_TO \ + (MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_IDX_FROM + \ + MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_SIZE - 1) +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_FROM \ + (MLX5_ESW_BRIDGE_INGRESS_TABLE_MLD_GRP_IDX_TO + 1) +#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_TO \ + (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_FROM + \ + MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_SIZE - 1)#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_FILTER_GRP_IDX_FROM \ (MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_GRP_IDX_TO + 1)#define MLX5_ESW_BRIDGE_INGRESS_TABLE_VLAN_FILTER_GRP_IDX_TO \
@@ -74,6 +89,7 @@ enum {enum {MLX5_ESW_BRIDGE_VLAN_FILTERING_FLAG =BIT (0 ), +MLX5_ESW_BRIDGE_MCAST_FLAG =BIT (1 ), };struct mlx5_esw_bridge_fdb_key {
@@ -145,4 +161,7 @@ struct mlx5_esw_bridge { u16 vlan_proto; }; +int mlx5_esw_bridge_mcast_enable (struct mlx5_esw_bridge *bridge); +void mlx5_esw_bridge_mcast_disable (struct mlx5_esw_bridge *bridge); +#endif /* _MLX5_ESW_BRIDGE_PRIVATE_ */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 866/982 net/mlx5: Bridge, dont fail switchdev events of sibling eswitch ports
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernardo Soares <[email protected]>
[ Upstream commit 35e6f970f553954d92ba20afa885139a8e7dd0d7 ]
mlx5 registers the bridge offload switchdev notifiers once per eswitch instance, but the notifier chains are global, so every instance sees every event and must filter out the ones that aren't its own. The existing filter, mlx5_esw_bridge_dev_same_hw(), only checks that the event netdevice sits on the same HCA - intentional for merged eswitch, where one bridge can span representors of several eswitches on one HCA - but same-HCA doesn't mean the instance actually has that port:
peer ports are only created reactively from NETDEV_CHANGEUPPER, so an instance brought up after a sibling PF's port was already enslaved has none. The port object and attribute handlers claim the event anyway once same-HW passes, then fail the port lookup and return -EINVAL, which gets reported to user space even though the owning instance already handled it (e.g. "bridge vlan add ... RTNETLINK answers:
Invalid argument"). Fix by filtering on the tracked port instead.
The same gap exists in the generic recursive lower-device walk used by attribute changes on a bridge with more than one representor enslaved
directly: mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get() is entered with the bridge master netdevice, falls through to its generic netdev_for_each_lower_dev() loop, and returns as soon as the recursion into any one lower device yields a non-NULL rep - the underlying base case, mlx5_esw_bridge_rep_vport_num_vhca_id_get(), only checks mlx5_esw_bridge_dev_same_hw(), not ownership by the calling instance's br_offloads. mlx5_esw_bridge_lag_rep_get(), used for the LAG-master case, already filters on mlx5_esw_bridge_dev_same_esw() per candidate and so cannot select a sibling's rep; it is not the source of this bug. On a merged-eswitch HCA with a bridge spanning representors of more than one eswitch instance directly, the walk can return a sibling's rep instead of continuing to the one the calling instance actually owns, so the attribute change fails the same way as above. Fix by checking mlx5_esw_bridge_port_exists() at the point each rep is picked, same as the previous fix did for the notifier filter.
--- .../mellanox/mlx5/core/en/rep/bridge.c | 45 +++++++++++++++---- .../ethernet/mellanox/mlx5/core/esw/bridge.c | 6 +++ .../ethernet/mellanox/mlx5/core/esw/bridge.h | 2 + 3 files changed, 44 insertions(+), 9 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c +36 -9
@@ -85,9 +85,16 @@ mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get(struct net_device *dev, struct mstruct net_device *lower_dev;struct list_head *iter; -if (netif_is_lag_master (dev) ||mlx5e_eswitch_rep (dev)) -return mlx5_esw_bridge_rep_vport_num_vhca_id_get (dev, esw, vport_num, - esw_owner_vhca_id); +if (netif_is_lag_master (dev) ||mlx5e_eswitch_rep (dev)) { +struct net_device *rep; + + rep =mlx5_esw_bridge_rep_vport_num_vhca_id_get (dev, esw, vport_num, + esw_owner_vhca_id); +if (rep && !mlx5_esw_bridge_port_exists (*vport_num, *esw_owner_vhca_id, + esw->br_offloads)) +return NULL ; +return rep; + }netdev_for_each_lower_dev (dev, lower_dev, iter) {struct net_device *rep;
@@ -104,6 +111,28 @@ mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get(struct net_device *dev, struct mreturn NULL ; } +static bool mlx5_esw_bridge_rep_port_lookup (struct net_device *dev, +struct mlx5_esw_bridge_offloads *br_offloads, +u16 *vport_num,u16 *esw_owner_vhca_id) +{ +if (!mlx5_esw_bridge_rep_vport_num_vhca_id_get (dev, br_offloads->esw, vport_num, + esw_owner_vhca_id)) +return false; + +return mlx5_esw_bridge_port_exists (*vport_num, *esw_owner_vhca_id, br_offloads); +} + +static bool mlx5_esw_bridge_lower_rep_port_lookup (struct net_device *dev, +struct mlx5_esw_bridge_offloads *br_offloads, +u16 *vport_num,u16 *esw_owner_vhca_id) +{ +if (!mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get (dev, br_offloads->esw, vport_num, + esw_owner_vhca_id)) +return false; + +return mlx5_esw_bridge_port_exists (*vport_num, *esw_owner_vhca_id, br_offloads); +} +static bool mlx5_esw_bridge_is_local (struct net_device *dev,struct net_device *rep,struct mlx5_eswitch *esw) {
@@ -218,8 +247,7 @@ mlx5_esw_bridge_port_obj_add(struct net_device *dev,u16 vport_num, esw_owner_vhca_id;int err; -if (!mlx5_esw_bridge_rep_vport_num_vhca_id_get (dev, br_offloads->esw, &vport_num, - &esw_owner_vhca_id)) +if (!mlx5_esw_bridge_rep_port_lookup (dev, br_offloads, &vport_num, &esw_owner_vhca_id))return 0 ; port_obj_info->handled = true;
@@ -245,8 +273,7 @@ mlx5_esw_bridge_port_obj_del(struct net_device *dev,const struct switchdev_obj_port_vlan *vlan;u16 vport_num, esw_owner_vhca_id; -if (!mlx5_esw_bridge_rep_vport_num_vhca_id_get (dev, br_offloads->esw, &vport_num, - &esw_owner_vhca_id)) +if (!mlx5_esw_bridge_rep_port_lookup (dev, br_offloads, &vport_num, &esw_owner_vhca_id))return 0 ; port_obj_info->handled = true;
@@ -272,8 +299,8 @@ mlx5_esw_bridge_port_obj_attr_set(struct net_device *dev,u16 vport_num, esw_owner_vhca_id;int err =0 ; -if (!mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get (dev, br_offloads->esw, &vport_num, - &esw_owner_vhca_id)) +if (!mlx5_esw_bridge_lower_rep_port_lookup (dev, br_offloads, &vport_num, + &esw_owner_vhca_id))return 0 ; port_attr_info->handled = true;
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +6 -0
@@ -1618,6 +1618,12 @@ int mlx5_esw_bridge_vport_peer_unlink(int ifindex, u16 vport_num, u16 esw_owner_ extack); } +bool mlx5_esw_bridge_port_exists (u16 vport_num,u16 esw_owner_vhca_id, +struct mlx5_esw_bridge_offloads *br_offloads) +{ +return mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); +} +int mlx5_esw_bridge_port_vlan_add (u16 vport_num,u16 esw_owner_vhca_id,u16 vid,u16 flags,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.h +2 -0
@@ -73,6 +73,8 @@ int mlx5_esw_bridge_vlan_proto_set(u16 vport_num, u16 esw_owner_vhca_id, u16 pro struct mlx5_esw_bridge_offloads *br_offloads);int mlx5_esw_bridge_mcast_set (u16 vport_num,u16 esw_owner_vhca_id,bool enable,struct mlx5_esw_bridge_offloads *br_offloads); +bool mlx5_esw_bridge_port_exists (u16 vport_num,u16 esw_owner_vhca_id, +struct mlx5_esw_bridge_offloads *br_offloads);int mlx5_esw_bridge_port_vlan_add (u16 vport_num,u16 esw_owner_vhca_id,u16 vid,u16 flags,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 867/982 net/mlx5: Bridge, pass net device when linking vport to bridge
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit ade19f0d6a3a395e7936227811acbf897ee186fc ]
Following patch requires access to additional data in bridge net_device. Pass the whole structure down the stack instead of adding necessary fields as function arguments one-by-one.
Stable-dep-of: 2e51097c982b ("net/mlx5: Bridge, don't fail unlink of untracked/unsupported peer ports")
--- .../mellanox/mlx5/core/en/rep/bridge.c | 9 +++-- .../ethernet/mellanox/mlx5/core/esw/bridge.c | 35 ++++++++++--------- .../ethernet/mellanox/mlx5/core/esw/bridge.h | 10 +++--- 3 files changed, 29 insertions(+), 25 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c +4 -5
@@ -160,7 +160,6 @@ static int mlx5_esw_bridge_port_changeupper(struct notifier_block *nb, void *ptrstruct mlx5_eswitch *esw = br_offloads->esw;u16 vport_num, esw_owner_vhca_id;struct netlink_ext_ack *extack; -int ifindex = upper->ifindex;int err =0 ;if (!netif_is_bridge_master (upper))
@@ -174,15 +173,15 @@ static int mlx5_esw_bridge_port_changeupper(struct notifier_block *nb, void *ptrif (mlx5_esw_bridge_is_local (dev, rep, esw)) err = info->linking ? -mlx5_esw_bridge_vport_link (ifindex, vport_num, esw_owner_vhca_id, +mlx5_esw_bridge_vport_link (upper, vport_num, esw_owner_vhca_id, br_offloads, extack) : -mlx5_esw_bridge_vport_unlink (ifindex, vport_num, esw_owner_vhca_id, +mlx5_esw_bridge_vport_unlink (upper, vport_num, esw_owner_vhca_id, br_offloads, extack);else if (mlx5_esw_bridge_dev_same_hw (rep, esw)) err = info->linking ? -mlx5_esw_bridge_vport_peer_link (ifindex, vport_num, esw_owner_vhca_id, +mlx5_esw_bridge_vport_peer_link (upper, vport_num, esw_owner_vhca_id, br_offloads, extack) : -mlx5_esw_bridge_vport_peer_unlink (ifindex, vport_num, esw_owner_vhca_id, +mlx5_esw_bridge_vport_peer_unlink (upper, vport_num, esw_owner_vhca_id, br_offloads, extack);return err;
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +19 -16
@@ -821,7 +821,7 @@ mlx5_esw_bridge_egress_miss_flow_create(struct mlx5_flow_table *egress_ft,return handle; } -static struct mlx5_esw_bridge *mlx5_esw_bridge_create (int ifindex, +static struct mlx5_esw_bridge *mlx5_esw_bridge_create (struct net_device *br_netdev,struct mlx5_esw_bridge_offloads *br_offloads) {struct mlx5_esw_bridge *bridge;
@@ -841,7 +841,7 @@ static struct mlx5_esw_bridge *mlx5_esw_bridge_create(int ifindex, goto err_fdb_ht;INIT_LIST_HEAD (&bridge->fdb_list); - bridge->ifindex = ifindex; + bridge->ifindex = br_netdev->ifindex; bridge->refcnt =1 ; bridge->ageing_time =clock_t_to_jiffies (BR_DEFAULT_AGEING_TIME ); bridge->vlan_proto =ETH_P_8021Q ;
@@ -878,14 +878,14 @@ static void mlx5_esw_bridge_put(struct mlx5_esw_bridge_offloads *br_offloads, }static struct mlx5_esw_bridge * -mlx5_esw_bridge_lookup (int ifindex,struct mlx5_esw_bridge_offloads *br_offloads) +mlx5_esw_bridge_lookup (struct net_device *br_netdev,struct mlx5_esw_bridge_offloads *br_offloads) {struct mlx5_esw_bridge *bridge;ASSERT_RTNL ();list_for_each_entry (bridge, &br_offloads->bridges, list) { -if (bridge->ifindex == ifindex) { +if (bridge->ifindex == br_netdev->ifindex) {mlx5_esw_bridge_get (bridge);return bridge; }
@@ -898,7 +898,7 @@ mlx5_esw_bridge_lookup(int ifindex, struct mlx5_esw_bridge_offloads *br_offloadsreturn ERR_PTR (err); } - bridge =mlx5_esw_bridge_create (ifindex, br_offloads); + bridge =mlx5_esw_bridge_create (br_netdev, br_offloads);if (IS_ERR (bridge) &&list_empty (&br_offloads->bridges))mlx5_esw_bridge_ingress_table_cleanup (br_offloads);return bridge;
@@ -1541,15 +1541,15 @@ static int mlx5_esw_bridge_vport_cleanup(struct mlx5_esw_bridge_offloads *br_offreturn 0 ; } -static int mlx5_esw_bridge_vport_link_with_flags (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, -u16 flags, +static int mlx5_esw_bridge_vport_link_with_flags (struct net_device *br_netdev,u16 vport_num, +u16 esw_owner_vhca_id,u16 flags,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack) {struct mlx5_esw_bridge *bridge;int err; - bridge =mlx5_esw_bridge_lookup (ifindex, br_offloads); + bridge =mlx5_esw_bridge_lookup (br_netdev, br_offloads);if (IS_ERR (bridge)) {NL_SET_ERR_MSG_MOD (extack,"Error checking for existing bridge with same ifindex" );return PTR_ERR (bridge);
@@ -1567,15 +1567,16 @@ static int mlx5_esw_bridge_vport_link_with_flags(int ifindex, u16 vport_num, u16return err; } -int mlx5_esw_bridge_vport_link (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_link (struct net_device *br_netdev,u16 vport_num,u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack) { -return mlx5_esw_bridge_vport_link_with_flags (ifindex, vport_num, esw_owner_vhca_id,0 , +return mlx5_esw_bridge_vport_link_with_flags (br_netdev, vport_num, esw_owner_vhca_id,0 , br_offloads, extack); } -int mlx5_esw_bridge_vport_unlink (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_unlink (struct net_device *br_netdev,u16 vport_num, +u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack) {
@@ -1587,7 +1588,7 @@ int mlx5_esw_bridge_vport_unlink(int ifindex, u16 vport_num, u16 esw_owner_vhca_NL_SET_ERR_MSG_MOD (extack,"Port is not attached to any bridge" );return -EINVAL ; } -if (port->bridge->ifindex != ifindex) { +if (port->bridge->ifindex != br_netdev->ifindex) {NL_SET_ERR_MSG_MOD (extack,"Port is attached to another bridge" );return -EINVAL ; }
@@ -1598,23 +1599,25 @@ int mlx5_esw_bridge_vport_unlink(int ifindex, u16 vport_num, u16 esw_owner_vhca_return err; } -int mlx5_esw_bridge_vport_peer_link (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_peer_link (struct net_device *br_netdev,u16 vport_num, +u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack) {if (!MLX5_CAP_ESW (br_offloads->esw->dev, merged_eswitch))return 0 ; -return mlx5_esw_bridge_vport_link_with_flags (ifindex, vport_num, esw_owner_vhca_id, +return mlx5_esw_bridge_vport_link_with_flags (br_netdev, vport_num, esw_owner_vhca_id,MLX5_ESW_BRIDGE_PORT_FLAG_PEER , br_offloads, extack); } -int mlx5_esw_bridge_vport_peer_unlink (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_peer_unlink (struct net_device *br_netdev,u16 vport_num, +u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack) { -return mlx5_esw_bridge_vport_unlink (ifindex, vport_num, esw_owner_vhca_id, br_offloads, +return mlx5_esw_bridge_vport_unlink (br_netdev, vport_num, esw_owner_vhca_id, br_offloads, extack); }
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.h +6 -4
@@ -43,16 +43,18 @@ struct mlx5_esw_bridge_offloads {struct mlx5_esw_bridge_offloads *mlx5_esw_bridge_init (struct mlx5_eswitch *esw);void mlx5_esw_bridge_cleanup (struct mlx5_eswitch *esw); -int mlx5_esw_bridge_vport_link (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_link (struct net_device *br_netdev,u16 vport_num,u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack); -int mlx5_esw_bridge_vport_unlink (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_unlink (struct net_device *br_netdev,u16 vport_num,u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack); -int mlx5_esw_bridge_vport_peer_link (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_peer_link (struct net_device *br_netdev,u16 vport_num, +u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack); -int mlx5_esw_bridge_vport_peer_unlink (int ifindex,u16 vport_num,u16 esw_owner_vhca_id, +int mlx5_esw_bridge_vport_peer_unlink (struct net_device *br_netdev,u16 vport_num, +u16 esw_owner_vhca_id,struct mlx5_esw_bridge_offloads *br_offloads,struct netlink_ext_ack *extack); void mlx5_esw_bridge_fdb_update_used(struct net_device *dev, u16 vport_num, u16 esw_owner_vhca_id,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 868/982 net/mlx5: Bridge, dont fail unlink of untracked/unsupported peer ports
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernardo Soares <[email protected]>
[ Upstream commit 2e51097c982b7b22382fda3202ba29f0ea33e8c0 ]
mlx5_esw_bridge_vport_unlink() returns -EINVAL when the port isn't tracked by this instance's br_offloads. This is reachable on a sibling instance that registered its notifier after the port was already
enslaved: it never saw the NETDEV_CHANGEUPPER link event, so peer_link() never created a peer port for it, but it does see the later unlink event and fails. Return 0 instead, and give mlx5_esw_bridge_vport_peer_unlink() the same merged_eswitch capability guard peer_link() already has, since without it peer_link() likewise never creates a port to unlink.
This also matters beyond the -EINVAL itself:mlx5_esw_bridge_switchdev_port_event() runs on the per-netns netdev_chain, and notifier_from_errno(-EINVAL) sets NOTIFY_STOP_MASK, which call_netdevice_notifiers_info() checks to stop calling further listeners on that chain - so the old -EINVAL silently dropped the event for any listener registered later on the same chain, even though none of it was visible to user space since __netdev_upper_dev_unlink() discards the return value.
--- drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +5 -4
@@ -1584,10 +1584,8 @@ int mlx5_esw_bridge_vport_unlink(struct net_device *br_netdev, u16 vport_num,int err; port =mlx5_esw_bridge_port_lookup (vport_num, esw_owner_vhca_id, br_offloads); -if (!port) { -NL_SET_ERR_MSG_MOD (extack,"Port is not attached to any bridge" ); -return -EINVAL ; - } +if (!port) +return 0 ;if (port->bridge->ifindex != br_netdev->ifindex) {NL_SET_ERR_MSG_MOD (extack,"Port is attached to another bridge" );return -EINVAL ;
@@ -1617,6 +1615,9 @@ int mlx5_esw_bridge_vport_peer_unlink(struct net_device *br_netdev, u16 vport_nu struct mlx5_esw_bridge_offloads *br_offloads, struct netlink_ext_ack *extack) { +if (!MLX5_CAP_ESW (br_offloads->esw->dev, merged_eswitch)) +return 0 ; +return mlx5_esw_bridge_vport_unlink (br_netdev, vport_num, esw_owner_vhca_id, br_offloads, extack); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 869/982 sctp: hold asoc or transport before mod_timer() in timer handlers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit cae23ae3f7887a1cf8a75da38edcebeef695040f ]
Take the association or transport reference before rearming a timer in the timer handlers.
The existing code calls mod_timer() before taking the reference needed by the rearmed timer without holding the sock lock. This creates a race with timer cleanup: if the timer is deleted after mod_timer() returns but before the reference is taken, the cleanup path can drop the timer's reference and destroy the transport or association. The timer handler then takes a reference on the already freed object and eventually drops it, causing a refcount underflow.
Hold the object before mod_timer() and drop the reference if mod_timer() reports that the timer was already pending in timer handlers. Apply the same ordering to the proto-unreachable path, which can rearm a transport timer outside the timer handlers without holding the sock lock.
--- net/sctp/input.c | 7 ++++--- net/sctp/sm_sideeffect.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 18 deletions(-)
net/sctp/input.c +4 -3
@@ -451,9 +451,10 @@ void sctp_icmp_proto_unreachable(struct sock *sk,if (timer_pending (&t->proto_unreach_timer))return ;else { -if (!mod_timer (&t->proto_unreach_timer, - jiffies + (HZ /20 ))) -sctp_transport_hold (t); +sctp_transport_hold (t); +if (mod_timer (&t->proto_unreach_timer, + jiffies + (HZ /20 ))) +sctp_transport_put (t); } }else {struct net *net =sock_net (sk);
net/sctp/sm_sideeffect.c +22 -15
@@ -244,8 +244,9 @@ void sctp_generate_t3_rtx_event(struct timer_list *t)pr_debug ("%s: sock is busy\n" , __func__);/* Try again later. */ -if (!mod_timer (&transport->T3_rtx_timer, jiffies + (HZ /20 ))) -sctp_transport_hold (transport); +sctp_transport_hold (transport); +if (mod_timer (&transport->T3_rtx_timer, jiffies + (HZ /20 ))) +sctp_transport_put (transport); goto out_unlock; }
@@ -280,8 +281,9 @@ static void sctp_generate_timeout_event(struct sctp_association *asoc, timeout_type);/* Try again later. */ -if (!mod_timer (&asoc->timers[timeout_type], jiffies + (HZ /20 ))) -sctp_association_hold (asoc); +sctp_association_hold (asoc); +if (mod_timer (&asoc->timers[timeout_type], jiffies + (HZ /20 ))) +sctp_association_put (asoc); goto out_unlock; }
@@ -373,8 +375,9 @@ void sctp_generate_heartbeat_event(struct timer_list *t)pr_debug ("%s: sock is busy\n" , __func__);/* Try again later. */ -if (!mod_timer (&transport->hb_timer, jiffies + (HZ /20 ))) -sctp_transport_hold (transport); +sctp_transport_hold (transport); +if (mod_timer (&transport->hb_timer, jiffies + (HZ /20 ))) +sctp_transport_put (transport); goto out_unlock; }
@@ -383,8 +386,9 @@ void sctp_generate_heartbeat_event(struct timer_list *t) timeout =sctp_transport_timeout (transport);if (elapsed < timeout) { elapsed = timeout - elapsed; -if (!mod_timer (&transport->hb_timer, jiffies + elapsed)) -sctp_transport_hold (transport); +sctp_transport_hold (transport); +if (mod_timer (&transport->hb_timer, jiffies + elapsed)) +sctp_transport_put (transport); goto out_unlock; }
@@ -417,9 +421,10 @@ void sctp_generate_proto_unreach_event(struct timer_list *t)pr_debug ("%s: sock is busy\n" , __func__);/* Try again later. */ -if (!mod_timer (&transport->proto_unreach_timer, - jiffies + (HZ /20 ))) -sctp_transport_hold (transport); +sctp_transport_hold (transport); +if (mod_timer (&transport->proto_unreach_timer, + jiffies + (HZ /20 ))) +sctp_transport_put (transport); goto out_unlock; }
@@ -453,8 +458,9 @@ void sctp_generate_reconf_event(struct timer_list *t)pr_debug ("%s: sock is busy\n" , __func__);/* Try again later. */ -if (!mod_timer (&transport->reconf_timer, jiffies + (HZ /20 ))) -sctp_transport_hold (transport); +sctp_transport_hold (transport); +if (mod_timer (&transport->reconf_timer, jiffies + (HZ /20 ))) +sctp_transport_put (transport); goto out_unlock; }
@@ -489,8 +495,9 @@ void sctp_generate_probe_event(struct timer_list *t)pr_debug ("%s: sock is busy\n" , __func__);/* Try again later. */ -if (!mod_timer (&transport->probe_timer, jiffies + (HZ /20 ))) -sctp_transport_hold (transport); +sctp_transport_hold (transport); +if (mod_timer (&transport->probe_timer, jiffies + (HZ /20 ))) +sctp_transport_put (transport); goto out_unlock; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 870/982 net: stmmac: selftests: Support running selftests on DSA conduits
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Chevallier <[email protected]>
[ Upstream commit d68acbf93531abdb5b02b21994cd4c15a3c95b42 ]
Most stmmac selftests rely on dev_add_pack() to add custom handlers, that validate the packets sent to ourselves through MAC loopback.
However, when the stmmac-driven interface is a DSA CPU conduit, all frames that are received have ETH_P_XDSA as a protocol, even though they don't actually contain any tag as they come from the loopback and not the switch.
This will prevent any incoming packet to match our packet handlers.
Let's register a ETH_P_ALL packet handler when we detect that we're a DSA conduit, and use a proxy packet handler to filter the h_proto.
As this allows external frames to be received through our .func(), the packet handler is added after the dev->addr field is populated in our selftest attributes.
Note that we may still receive incoming packets from the switch, but these frames shouldn't interfere with the very specific frames used for selftests, and stmmac selftests in general aren't safe against external traffic interferences.
This was validated on a WPQ864 devkit for IPQ8064, that has the SoC connected to a QCA8k switch.
The ARP offload's packet handler is left alone, this feature is just not implemented in stmmac and due for removal.
--- .../stmicro/stmmac/stmmac_selftests.c | 89 +++++++++++++++---- 1 file changed, 71 insertions(+), 18 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +71 -18
@@ -13,6 +13,7 @@#include <linux/ip.h> #include <linux/phy.h> #include <linux/udp.h> +#include <net/dsa.h> #include <net/pkt_cls.h> #include <net/pkt_sched.h> #include <net/tcp.h>
@@ -238,6 +239,9 @@ struct stmmac_test_priv {struct stmmac_packet_attrs *packet;struct packet_type pt;struct completion comp; +__be16 packet_type; +int (*func)(struct sk_buff *skb,struct net_device *ndev, +struct packet_type *pt,struct net_device *orig_ndev);int double_vlan;int vlan_id;int ok;
@@ -317,6 +321,50 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb,return 0 ; } +static int stmmac_sft_filter (struct sk_buff *skb,struct net_device *ndev, +struct packet_type *pt, +struct net_device *orig_ndev) +{ +struct stmmac_test_priv *tpriv = pt->af_packet_priv; +struct ethhdr *hdr =eth_hdr (skb); +int ret =0 ; + +if (hdr->h_proto == tpriv->packet_type) { +struct sk_buff *nskb =skb_clone (skb,GFP_ATOMIC ); + +if (nskb) + ret = tpriv->func (nskb, ndev, pt, orig_ndev); + } + +kfree_skb (skb); +return ret; +} + +static void stmmac_sft_add_pack (struct packet_type *pt) +{ +struct stmmac_test_priv *tpriv = pt->af_packet_priv; + +if (netdev_uses_dsa (tpriv->pt.dev)) { + tpriv->packet_type = tpriv->pt.type; + tpriv->func = tpriv->pt.func; + +/* DSA conduit will report ETH_P_XDSA, so our packet handler +* won't match. Let's register a ETH_P_ALL match and filter +* manually in stmmac_sft_filter. +*/ + tpriv->pt.type =htons (ETH_P_ALL ); + tpriv->pt.func = stmmac_sft_filter; + tpriv->pt.ignore_outgoing = true; + } + +dev_add_pack (pt); +} + +static void stmmac_sft_remove_pack (struct packet_type *pt) +{ +dev_remove_pack (pt); +} +static int __stmmac_test_loopback (struct stmmac_priv *priv,struct stmmac_packet_attrs *attr) {
@@ -338,7 +386,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv, tpriv->packet = attr;if (!attr->dont_wait) -dev_add_pack (&tpriv->pt); +stmmac_sft_add_pack (&tpriv->pt); skb =stmmac_test_get_udp_skb (priv, attr);if (!skb) {
@@ -361,7 +409,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv, cleanup:if (!attr->dont_wait) -dev_remove_pack (&tpriv->pt); +stmmac_sft_remove_pack (&tpriv->pt);kfree (tpriv);return ret; }
@@ -775,7 +823,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv) tpriv->pt.func = stmmac_test_flowctrl_validate; tpriv->pt.dev = priv->dev; tpriv->pt.af_packet_priv = tpriv; -dev_add_pack (&tpriv->pt); +stmmac_sft_add_pack (&tpriv->pt);/* Compute minimum number of packets to make FIFO full */ pkt_count = priv->plat->rx_fifo_size;
@@ -833,7 +881,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv) cleanup:dev_mc_del (priv->dev, paddr);dev_set_promiscuity (priv->dev,-1 ); -dev_remove_pack (&tpriv->pt); +stmmac_sft_remove_pack (&tpriv->pt);kfree (tpriv);return ret; }
@@ -938,18 +986,20 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *priv)* HASH values. */ tpriv->vlan_id =0x123 ; -dev_add_pack (&tpriv->pt); ret =vlan_vid_add (priv->dev,htons (ETH_P_8021Q ), tpriv->vlan_id);if (ret) goto cleanup; + attr.vlan =1 ; + attr.dst = priv->dev->dev_addr; + attr.sport =9 ; + attr.dport =9 ; + +stmmac_sft_add_pack (&tpriv->pt); +for (i =0 ; i <4 ; i++) { - attr.vlan =1 ; attr.vlan_id_out = tpriv->vlan_id + i; - attr.dst = priv->dev->dev_addr; - attr.sport =9 ; - attr.dport =9 ; skb =stmmac_test_get_udp_skb (priv, &attr);if (!skb) {
@@ -976,9 +1026,9 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *priv) } vlan_del: +stmmac_sft_remove_pack (&tpriv->pt);vlan_vid_del (priv->dev,htons (ETH_P_8021Q ), tpriv->vlan_id); cleanup: -dev_remove_pack (&tpriv->pt);kfree (tpriv);return ret; }
@@ -1032,18 +1082,20 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv)* HASH values. */ tpriv->vlan_id =0x123 ; -dev_add_pack (&tpriv->pt); ret =vlan_vid_add (priv->dev,htons (ETH_P_8021AD ), tpriv->vlan_id);if (ret) goto cleanup; + attr.vlan =2 ; + attr.dst = priv->dev->dev_addr; + attr.sport =9 ; + attr.dport =9 ; + +stmmac_sft_add_pack (&tpriv->pt); +for (i =0 ; i <4 ; i++) { - attr.vlan =2 ; attr.vlan_id_out = tpriv->vlan_id + i; - attr.dst = priv->dev->dev_addr; - attr.sport =9 ; - attr.dport =9 ; skb =stmmac_test_get_udp_skb (priv, &attr);if (!skb) {
@@ -1070,9 +1122,9 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv) } vlan_del: +stmmac_sft_remove_pack (&tpriv->pt);vlan_vid_del (priv->dev,htons (ETH_P_8021AD ), tpriv->vlan_id); cleanup: -dev_remove_pack (&tpriv->pt);kfree (tpriv);return ret; }
@@ -1303,7 +1355,6 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan) tpriv->pt.af_packet_priv = tpriv; tpriv->packet = &attr; tpriv->vlan_id =0x123 ; -dev_add_pack (&tpriv->pt); ret =vlan_vid_add (priv->dev,htons (proto), tpriv->vlan_id);if (ret)
@@ -1311,6 +1362,8 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan) attr.dst = priv->dev->dev_addr; +stmmac_sft_add_pack (&tpriv->pt); + skb =stmmac_test_get_udp_skb (priv, &attr);if (!skb) { ret = -ENOMEM ;
@@ -1328,9 +1381,9 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan) ret = tpriv->ok ?0 : -ETIMEDOUT ; vlan_del: +stmmac_sft_remove_pack (&tpriv->pt);vlan_vid_del (priv->dev,htons (proto), tpriv->vlan_id); cleanup: -dev_remove_pack (&tpriv->pt);kfree (tpriv);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 871/982 net: stmmac: selftests: Check the dev->features for S-TAG offload testing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Chevallier <[email protected]>
[ Upstream commit ba804b23d76d278ee475b8427fa7c5623ce5e270 ]
The S-TAG offload insertion incorrectly checks the dvlan (double vlan) DMA cap, which is different than S-TAG support. Use NETIF_F_HW_VLAN_STAG_TX to check if the feature is supported instead.
Note that this flag isn't set in stmmac yet, but contrary to ARP offload, this is a feature that has a chance to get there eventually so let's leave the selftest here for now. It'll report -EOPNOTSUPP in the meantime.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -1
@@ -1395,7 +1395,7 @@ static int stmmac_test_vlanoff(struct stmmac_priv *priv)static int stmmac_test_svlanoff (struct stmmac_priv *priv) { -if (!priv->dma_cap.dvlan) +if (!(priv->dev->features &NETIF_F_HW_VLAN_STAG_TX ))return -EOPNOTSUPP ;return stmmac_test_vlanoff_common (priv, true); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 872/982 net: stmmac: selftests: Capture all packets for vlan checks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Chevallier <[email protected]>
[ Upstream commit 960db6f65788c21249ea04a947d5c01e38d19294 ]
While we use vlan_vid_add to trigger the tag filtering machinery in the driver, there's no netdev associated to the VLAN. This causes the skb to arrive with empty skb->vlan_tci fields, as the packet is marked OTHERHOST in __netif_receive_skb_core(), and we fail our validation.
Let's use the proxy mechanism introduced for DSA, that registers a ETH_P_ALL packet handler that runs earlier, before the vlan netdev lookup, then filters for the correct ethertype before passing an skb clone to our validation function.
As we may receive external frames with the right tag from the outside, let's move the address check in the vlan validation function earlier.
--- .../stmicro/stmmac/stmmac_selftests.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +13 -6
@@ -242,6 +242,7 @@ struct stmmac_test_priv {__be16 packet_type;int (*func)(struct sk_buff *skb,struct net_device *ndev,struct packet_type *pt,struct net_device *orig_ndev); +bool capture_all;int double_vlan;int vlan_id;int ok;
@@ -344,13 +345,15 @@ static void stmmac_sft_add_pack(struct packet_type *pt) {struct stmmac_test_priv *tpriv = pt->af_packet_priv; -if (netdev_uses_dsa (tpriv->pt.dev)) { +if (netdev_uses_dsa (tpriv->pt.dev) || tpriv->capture_all) { tpriv->packet_type = tpriv->pt.type; tpriv->func = tpriv->pt.func;/* DSA conduit will report ETH_P_XDSA, so our packet handler * won't match. Let's register a ETH_P_ALL match and filter -* manually in stmmac_sft_filter. +* manually in stmmac_sft_filter. This is also useful for +* VLAN tests, to capture packets otherwise marked as +* OTHERHOST. */ tpriv->pt.type =htons (ETH_P_ALL ); tpriv->pt.func = stmmac_sft_filter;
@@ -923,6 +926,11 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb, goto out;if (skb_headlen (skb) < (STMMAC_TEST_PKT_SIZE -ETH_HLEN )) goto out; + + ehdr = (struct ethhdr *)skb_mac_header (skb); +if (!ether_addr_equal_unaligned (ehdr->h_dest, tpriv->packet->dst)) + goto out; +if (tpriv->vlan_id) {if (skb->vlan_proto !=htons (proto)) goto out;
@@ -934,10 +942,6 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb, } } - ehdr = (struct ethhdr *)skb_mac_header (skb); -if (!ether_addr_equal_unaligned (ehdr->h_dest, tpriv->packet->dst)) - goto out; - ihdr =ip_hdr (skb);if (tpriv->double_vlan) ihdr = (struct iphdr *)(skb_network_header (skb) +4 );
@@ -979,6 +983,7 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *priv) tpriv->pt.dev = priv->dev; tpriv->pt.af_packet_priv = tpriv; tpriv->packet = &attr; + tpriv->capture_all = true;/* * As we use HASH filtering, false positives may appear. This is a
@@ -1075,6 +1080,7 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv) tpriv->pt.dev = priv->dev; tpriv->pt.af_packet_priv = tpriv; tpriv->packet = &attr; + tpriv->capture_all = true;/* * As we use HASH filtering, false positives may appear. This is a
@@ -1355,6 +1361,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan) tpriv->pt.af_packet_priv = tpriv; tpriv->packet = &attr; tpriv->vlan_id =0x123 ; + tpriv->capture_all = true; ret =vlan_vid_add (priv->dev,htons (proto), tpriv->vlan_id);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 873/982 net: stmmac: dwmac4: Use the correct bufzise when the len is exactly 8K
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Chevallier <[email protected]>
[ Upstream commit b42e7012773a0e81e97a2dda6ef907f5147a6658 ]
DMA bufsize selection isn't made on the MTU but the actual frame length, so including the L2 header. On DWMAC4, if the len is exactly BUF_SIZE_8KiB, the next larger size is incorrectly selected.
Lets fix the comparison and while at it, rename the parameter from len to mtu.
--- drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 4 ++-- drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 +- drivers/net/ethernet/stmicro/stmmac/ring_mode.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +2 -2
@@ -477,11 +477,11 @@ static void dwmac4_set_sarc(struct dma_desc *p, u32 sarc_type) p->des3 |=cpu_to_le32 (sarc_type &TDES3_SA_INSERT_CTRL_MASK ); } -static int set_16kib_bfsize (int mtu) +static int set_16kib_bfsize (int len) {int ret =0 ; -if (unlikely (mtu >= BUF_SIZE_8KiB)) +if (unlikely (len > BUF_SIZE_8KiB)) ret = BUF_SIZE_16KiB;return ret; }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
@@ -565,7 +565,7 @@ struct stmmac_mode_ops {unsigned int (*is_jumbo_frm) (int len,int ehn_desc);int (*jumbo_frm)(struct stmmac_tx_queue *tx_q,struct sk_buff *skb,int csum); -int (*set_16kib_bfsize)(int mtu); +int (*set_16kib_bfsize)(int len);void (*init_desc3)(struct dma_desc *p);void (*refill_desc3)(struct stmmac_rx_queue *rx_q,struct dma_desc *p);void (*clean_desc3)(struct stmmac_tx_queue *tx_q,struct dma_desc *p);
drivers/net/ethernet/stmicro/stmmac/ring_mode.c +2 -2
@@ -128,10 +128,10 @@ static void clean_desc3(struct stmmac_tx_queue *tx_q, struct dma_desc *p) p->des3 =0 ; } -static int set_16kib_bfsize (int mtu) +static int set_16kib_bfsize (int len) {int ret =0 ; -if (unlikely (mtu > BUF_SIZE_8KiB)) +if (unlikely (len > BUF_SIZE_8KiB)) ret = BUF_SIZE_16KiB;return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 874/982 nfc: nfcmrvl: validate helper command length before pull
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 686f942332b1667f13f3b8d6a2f50bcfbf42e277 ]
The firmware download receive path removes the NCI data header and reads the helper command before validating the remaining packet length. A short frame can therefore reach the data access before the malformed packet is rejected.
Validate the complete helper command length before stripping the NCI data header.
--- drivers/nfc/nfcmrvl/fw_dnld.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nfc/nfcmrvl/fw_dnld.c +8 -3
@@ -262,9 +262,14 @@ static int process_state_fw_dnld(struct nfcmrvl_private *priv,* B8..N: payload */ -/* Remove NCI HDR */ -skb_pull (skb,3 ); -if (skb->data[0 ] !=HELPER_CMD_PACKET_FORMAT || skb->len !=5 ) { +if (skb->len !=NCI_DATA_HDR_SIZE +5 ) { +nfc_err (priv->dev,"bad command" ); +return -EINVAL ; + } + +/* Remove NCI header */ +skb_pull (skb,NCI_DATA_HDR_SIZE ); +if (skb->data[0 ] !=HELPER_CMD_PACKET_FORMAT ) {nfc_err (priv->dev,"bad command" );return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 875/982 nfc: st21nfca: validate received frame size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit a653c01ce447f10c36b901646888c0330363af4f ]
st21nfca_hci_i2c_repack() trims a received frame at its EOF marker before removing byte stuffing. It then assumes the truncated frame contains the LLC header and two CRC bytes, and it unconditionally reads the byte after an escape marker.
A malformed frame can place EOF immediately after the start marker or can end its data portion with an escape marker. The former leaves too few bytes for check_crc(), while the latter makes the unstuffing loop read past the current skb length.
Require the minimum framing bytes both before and after unstuffing. Use separate input and output cursors while removing byte stuffing, and reject an escape marker without its encoded byte. This keeps malformed frames within the received frame boundary before CRC processing.
--- drivers/nfc/st21nfca/i2c.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/nfc/st21nfca/i2c.c +19 -10
@@ -290,27 +290,36 @@ static int check_crc(u8 *buf, int buflen)*/ static int st21nfca_hci_i2c_repack (struct sk_buff *skb) { -int i, j, r, size; +int read, write, r, size; -if (skb->len <1 || (skb->len >1 && skb->data[1 ] !=0 )) +if (skb->len <ST21NFCA_FRAME_HEADROOM || + !IS_START_OF_FRAME (skb->data))return -EBADMSG ; size =get_frame_size (skb->data, skb->len);if (size >0 ) { +if (size <ST21NFCA_FRAME_HEADROOM +2 ) +return -EBADMSG ; +skb_trim (skb, size);/* remove ST21NFCA byte stuffing for upper layer */ -for (i =1 , j =0 ; i < skb->len; i++) { -if (skb->data[i + j] == +for (read =1 , write =1 ; read < skb->len;) { +if (skb->data[read] == (u8 )ST21NFCA_ESCAPE_BYTE_STUFFING ) { - skb->data[i] = skb->data[i + j +1 ] - |ST21NFCA_BYTE_STUFFING_MASK ; - i++; - j++; +if (read +1 == skb->len) +return -EBADMSG ; + + skb->data[write++] = skb->data[read +1 ] + |ST21NFCA_BYTE_STUFFING_MASK ; + read +=2 ; + }else { + skb->data[write++] = skb->data[read++]; } - skb->data[i] = skb->data[i + j]; }/* remove byte stuffing useless byte */ -skb_trim (skb, i - j); +skb_trim (skb, write); +if (skb->len <ST21NFCA_FRAME_HEADROOM +2 ) +return -EBADMSG ;/* remove ST21NFCA_SOF_EOF from head */ skb_pull (skb,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 876/982 nfc: llcp: Fix list corruption / refcount desync in nfc_llcp_recv_dm()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
[ Upstream commit bf1460acdf8cf5a07c819f59785d40f20d113099 ]
nfc_llcp_recv_dm() handles DM(NOBOUND)/DM(REJ) for a socket that is still linked on local->connecting_sockets: it looks the socket up with nfc_llcp_connecting_sock_get(), sets sk->sk_state = LLCP_CLOSED and returns, without taking the socket lock and without unlinking the socket from the connecting_sockets list.
llcp_sock_release() selects the list to unlink from by sk_state: a socket in LLCP_CONNECTING is unlinked from connecting_sockets, otherwise from the sockets list. Because recv_dm left the socket physically on connecting_sockets but in the LLCP_CLOSED state, release() takes the else branch and calls nfc_llcp_sock_unlink(&local->sockets, sk). That runs sk_del_node_init() while holding sockets.lock, i.e. it removes the socket from the connecting_sockets hlist under the wrong lock. A concurrent connect() linking another socket onto connecting_sockets under connecting_sockets.lock then mutates the same hlist unserialized, which corrupts the list and desyncs the sk_add_node()/sk_del_node_init() sock_hold()/__sock_put() pairing. An unprivileged local process holding LLCP sockets, with the DM supplied by the remote peer over an established LLCP link, can drive this to leak kernel sockets without bound (the mis-decrement goes through the non-freeing __sock_put() path, so the object is never released), leading to memory exhaustion / DoS.
This is the same class of bug that was fixed in the sibling handler nfc_llcp_recv_cc() by commit b493ea2765cc ("nfc: llcp: Fix use-after-free race in nfc_llcp_recv_cc()"); recv_dm did not receive the equivalent fix.
Fix it the same way: take lock_sock(), re-check that the socket is still hashed (release() may have won the race), and for the NOBOUND/REJ case unlink it from connecting_sockets before moving it to LLCP_CLOSED. The unlink drops the connecting_sockets membership reference via sk_del_node_init(), leaving the socket unhashed, so the later nfc_llcp_sock_unlink() in llcp_sock_release() becomes a no-op and no double put occurs.
--- net/nfc/llcp_core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
net/nfc/llcp_core.c +25 -0
@@ -1249,6 +1249,7 @@ static void nfc_llcp_recv_dm(struct nfc_llcp_local *local,struct nfc_llcp_sock *llcp_sock;struct sock *sk;u8 dsap, ssap, reason; +bool connecting = false; dsap =nfc_llcp_dsap (skb); ssap =nfc_llcp_ssap (skb);
@@ -1260,6 +1261,7 @@ static void nfc_llcp_recv_dm(struct nfc_llcp_local *local,case LLCP_DM_NOBOUND :case LLCP_DM_REJ : llcp_sock =nfc_llcp_connecting_sock_get (local, dsap); + connecting = true;break ;default :
@@ -1274,10 +1276,33 @@ static void nfc_llcp_recv_dm(struct nfc_llcp_local *local, sk = &llcp_sock->sk; +lock_sock (sk); + +/* Check if socket was destroyed whilst waiting for the lock */ +if (!sk_hashed (sk)) { +release_sock (sk); +nfc_llcp_sock_put (llcp_sock); +return ; + } + +/* +* For DM(NOBOUND)/DM(REJ) the socket is still linked on the +* connecting_sockets list. Unlink it here, under the socket lock, +* before moving it to LLCP_CLOSED: llcp_sock_release() selects the +* list to unlink from by sk_state, so leaving a connecting socket +* in the CLOSED state would make it unlink from the wrong list and +* corrupt the connecting_sockets list / desync the socket refcount. +* This mirrors nfc_llcp_recv_cc(). +*/ +if (connecting) +nfc_llcp_sock_unlink (&local->connecting_sockets, sk); + sk->sk_err =ENXIO ; sk->sk_state =LLCP_CLOSED ; sk->sk_state_change (sk); +release_sock (sk); +nfc_llcp_sock_put (llcp_sock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 877/982 selftests: nci: Correct pthread_create return value check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lei Zhu <[email protected]>
[ Upstream commit 3d8afc5243ea2ee803d98e69eb4a01748167ac1b ]
The pthread_create() functions returns 0 on success and a positive value on failure. Modify the return value check to correctly detect failure cases.
--- tools/testing/selftests/nci/nci_dev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
tools/testing/selftests/nci/nci_dev.c +7 -5
@@ -438,7 +438,7 @@ FIXTURE_SETUP(NCI)else rc =pthread_create (&thread_t,NULL , virtual_dev_open, (void *)&self->virtual_nci_fd); -ASSERT_GT (rc,-1 ); +ASSERT_EQ (rc,0 ); rc =send_cmd_with_idx (self->sd, self->fid, self->pid,NFC_CMD_DEV_UP , self->dev_idex);
@@ -509,7 +509,7 @@ FIXTURE_TEARDOWN(NCI) rc =pthread_create (&thread_t,NULL , virtual_deinit, (void *)&self->virtual_nci_fd); -ASSERT_GT (rc,-1 ); +ASSERT_EQ (rc,0 ); rc =send_cmd_with_idx (self->sd, self->fid, self->pid,NFC_CMD_DEV_DOWN , self->dev_idex);EXPECT_EQ (rc,0 );
@@ -590,7 +590,7 @@ int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int p rc =pthread_create (&thread_t,NULL , virtual_poll_start, (void *)&virtual_fd); -if (rc <0 ) +if (rc)return rc; rc = send_cmd_mt_nla(sd, fid, pid, NFC_CMD_START_POLL, 2, nla_start_poll_type,
@@ -610,7 +610,7 @@ int stop_polling(int dev_idx, int virtual_fd, int sd, int fid, int pid) rc =pthread_create (&thread_t,NULL , virtual_poll_stop, (void *)&virtual_fd); -if (rc <0 ) +if (rc)return rc; rc = send_cmd_with_idx(sd, fid, pid,
@@ -830,6 +830,8 @@ int disconnect_tag(int nfc_sock, int virtual_fd) status =pthread_create (&thread_t,NULL , virtual_deactivate_proc, (void *)&virtual_fd); +if (status) +return status;close (nfc_sock);pthread_join (thread_t, (void **)&status);
@@ -874,7 +876,7 @@ TEST_F(NCI, deinit)else rc =pthread_create (&thread_t,NULL , virtual_deinit, (void *)&self->virtual_nci_fd); -ASSERT_GT (rc,-1 ); +ASSERT_EQ (rc,0 ); rc =send_cmd_with_idx (self->sd, self->fid, self->pid,NFC_CMD_DEV_DOWN , self->dev_idex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 878/982 nfc: llcp: Fix race condition in accept_queue lifecycle
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit c3eef2f988a3db9690369d7cef9a3344dd9788d3 ]
In nfc_llcp_socket_release(), sockets and listener accept queues are walked under the local sockets rwlock and bh_lock_sock(). However, bh_lock_sock() does not synchronise against process-context lock_sock() held by nfc_llcp_accept_dequeue() during accept(). Because socket_release() does not check sock_owned_by_user(), both paths can concurrently unlink and release the same child socket, resulting in use-after-free or a NULL pointer dereference of child->parent in nfc_llcp_accept_unlink().
Fix this synchronisation race by having nfc_llcp_socket_release() use process-context lock_sock() instead of bh_lock_sock():
1. Pop sockets from the local sockets list under the write lock using nfc_llcp_sock_list_pop() so lock_sock() can be acquired without holding the rwlock.
2. Because lock_sock() can sleep, defer the final release of the nfc_llcp_local structure to a workqueue (release_work). This avoids a sleeping-in-atomic bug when the last local reference is dropped from softirq context. Additionally, hold a single device reference on local from registration until final destruction.
3. In nfc_llcp_local_get(), use kref_get_unless_zero() to prevent resurrecting a local object whose teardown has been scheduled.
4. In llcp_sock_accept(), verify that the listener socket state is still LLCP_LISTEN after waking from schedule_timeout() to prevent hangs if the listener is closed concurrently.
5. When unlinking unaccepted child sockets during listener release, unlink them from local->sockets, call sock_orphan(), and drop their initial sk_alloc creation reference via sock_put().
6. Make nfc_llcp_accept_unlink() idempotent by guarding parent access with a NULL check.
--- net/nfc/llcp.h | 1 + net/nfc/llcp_core.c | 125 +++++++++++++++++++++++++++----------------- net/nfc/llcp_sock.c | 49 ++++++++++++----- 3 files changed, 116 insertions(+), 59 deletions(-)
net/nfc/llcp.h +1 -0
@@ -91,6 +91,7 @@ struct nfc_llcp_local {struct hlist_head pending_sdreqs;struct timer_list sdreq_timer;struct work_struct sdreq_timeout_work; +struct work_struct release_work;u8 sdreq_next_tid;/* sockets array */
net/nfc/llcp_core.c +78 -47
217 lines not on this page · raw message
net/nfc/llcp_sock.c +37 -12
87 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 879/982 selftests: nci: Fix uninitialized family ID on missing attribute
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chaithanya Lagisetty <[email protected]>
[ Upstream commit eda518d2cdb6074a0bcdfa06af291616bcb5c421 ]
get_family_id() walks the generic netlink CTRL_CMD_GETFAMILY reply looking for the CTRL_ATTR_FAMILY_ID attribute and returns the parsed value in the local variable "id". If the reply does not carry that attribute, the parsing loop never assigns "id" and the function returns an indeterminate stack value, which the caller stores in self->fid and uses for subsequent netlink requests.
Initialize "id" to 0 so a missing attribute yields a deterministic (invalid) family ID instead of a garbage value.
--- tools/testing/selftests/nci/nci_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/nci/nci_dev.c +1 -1
@@ -182,7 +182,7 @@ static int get_family_id(int sd, __u32 pid, __u32 *event_group) } ans;struct nlattr *na;int resp_len; -__u16 id; +__u16 id =0 ;int len;int rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 880/982 selftests/nci: Fix out-of-bounds store on thread join
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Gellermann <[email protected]>
[ Upstream commit 6be581aeffc215bfc77939cd59902b0dbc4af23e ]
The NCI test collects the exit status of its helper threads by passing the address of an int to pthread_join():
int status; ... pthread_join(thread_t, (void **) &status);
pthread_join() stores a void pointer to the memory location. On 64-bit systems, a void pointer is wider than an int, so the store overruns the 4 bytes of space allocated on the stack for the integer and corrupts the adjacent stack. On our CHERI system, this caused a fault due to a capability bounds violation.
Fix this by introducing a helper that joins a thread through a void pointer and converts the result back to an integer, which is what the helper threads return.
While here, also fix the logic in disconnect_tag() if the helper thread creation failed. Previously, it would have joined a thread that was never created when pthread_create() failed.
--- tools/testing/selftests/nci/nci_dev.c | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-)
tools/testing/selftests/nci/nci_dev.c +20 -11
@@ -8,6 +8,7 @@#include <stdlib.h> #include <errno.h> +#include <stdint.h> #include <string.h> #include <sys/ioctl.h> #include <fcntl.h>
@@ -87,6 +88,16 @@ struct msgtemplate {char buf[MAX_MSG_SIZE ]; }; +static int join_thread_status (pthread_t thread) +{ +void *thread_ret =NULL ; + +if (pthread_join (thread, &thread_ret)) +return -1 ; + +return (int )(intptr_t )thread_ret; +} +static int create_nl_socket (void ) {int fd;
@@ -444,7 +455,7 @@ FIXTURE_SETUP(NCI) NFC_CMD_DEV_UP, self->dev_idex);EXPECT_EQ (rc,0 ); -pthread_join (thread_t, (void **)&status); + status =join_thread_status (thread_t);ASSERT_EQ (status,0 ); self->open_state = true; }
@@ -514,7 +525,7 @@ FIXTURE_TEARDOWN(NCI) NFC_CMD_DEV_DOWN, self->dev_idex);EXPECT_EQ (rc,0 ); -pthread_join (thread_t, (void **)&status); + status =join_thread_status (thread_t);ASSERT_EQ (status,0 ); }
@@ -585,7 +596,6 @@ int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pvoid *nla_start_poll_data[2 ] = {&dev_idx, &proto};int nla_start_poll_len[2 ] = {4 ,4 };pthread_t thread_t; -int status;int rc; rc = pthread_create(&thread_t, NULL, virtual_poll_start,
@@ -598,14 +608,12 @@ int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pif (rc !=0 )return rc; -pthread_join (thread_t, (void **)&status); -return status; +return join_thread_status (thread_t); }int stop_polling (int dev_idx,int virtual_fd,int sd,int fid,int pid) {pthread_t thread_t; -int status;int rc; rc = pthread_create(&thread_t, NULL, virtual_poll_stop,
@@ -618,8 +626,7 @@ int stop_polling(int dev_idx, int virtual_fd, int sd, int fid, int pid)if (rc !=0 )return rc; -pthread_join (thread_t, (void **)&status); -return status; +return join_thread_status (thread_t); }TEST_F (NCI , start_poll)
@@ -834,8 +841,10 @@ int disconnect_tag(int nfc_sock, int virtual_fd)return status;close (nfc_sock); -pthread_join (thread_t, (void **)&status); -return status; +if (status) +return -1 ; + +return join_thread_status (thread_t); }TEST_F (NCI , t4t_tag_read)
@@ -882,7 +891,7 @@ TEST_F(NCI, deinit) NFC_CMD_DEV_DOWN, self->dev_idex);EXPECT_EQ (rc,0 ); -pthread_join (thread_t, (void **)&status); + status =join_thread_status (thread_t); self->open_state =0 ;ASSERT_EQ (status,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 881/982 nfc: virtual_ncidev: Add missing ioctl compat handler
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Gellermann <[email protected]>
[ Upstream commit 51814683e28fc64eceb415962376956c3cfc75a7 ]
The compat handler for ioctls to the virtual nci device is missing. So, nci-specific ioctls of a compat task return with -1 and errno set to ENOTTY. Add a handler.
The handling of an ioctl() call of a compat task to get the index of virtual nci device (IOCTL_GET_NCIDEV_IDX) lands in the default case of the ioctl compat handler (see fs/ioctl.c):
COMPAT_SYSCALL_DEFINE3(ioctl, ...)
{
...
default:
error = do_vfs_ioctl(fd_file(f), fd, cmd, ...);
if (error != -ENOIOCTLCMD)
break;
if (fd_file(f)->f_op->compat_ioctl)
error = fd_file(f)->f_op->compat_ioctl(fd_file(f), cmd, arg);
if (error == -ENOIOCTLCMD)
error = -ENOTTY;
...
}There, do_vfs_ioctl() returns -ENOIOCTLCMD and compat_ioctl is not set for virtual_ncidev_fops, i.e. f_op->compat_ioctl == NULL. So, the ioctl() syscall returns with -1 and errno set to ENOTTY to the compat task.
To fix this, use the compat_ptr_ioctl helper for compat handling here. It shall be used for ioctls that "either ignore the argument or pass a pointer to a compatible data type". The driver's sole ioctl takes a user void pointer and copies nfc_dev->idx to it, a 4-byte integer across all ABIs.
This issue has been found by running the nci_dev kernel selftest as rv64 binary on top of a CHERI kernel, where the ioctl() ends up in the ioctl compat handler, similar to a 32-bit application on top of a 64-bit kernel.
--- drivers/nfc/virtual_ncidev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nfc/virtual_ncidev.c +2 -1
@@ -196,7 +196,8 @@ static const struct file_operations virtual_ncidev_fops = { .write = virtual_ncidev_write, .open = virtual_ncidev_open, .release = virtual_ncidev_close, - .unlocked_ioctl = virtual_ncidev_ioctl + .unlocked_ioctl = virtual_ncidev_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static int __init virtual_ncidev_init (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 882/982 nfc: llcp: fix sdreq TLV list leak on parse/alloc/send failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
[ Upstream commit 66f4300206b82b0b143ef0d9be90cd8d29f23a47 ]
nfc_genl_llc_sdreq() builds a list of TLV nodes while walking nested netlink attrs, but 3 error paths (nested-attr parse failure, TLV alloc ENOMEM, nfc_llcp_send_snl_sdreq() failure) all skip freeing what was already queued.
Route them through a new free_list label, mirroring the SDRES path in the same file which already does this. Harmless on the success path too -- send_snl_sdreq() drains the list as it moves nodes, so it's already empty by the time free_list runs.
--- net/nfc/netlink.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/nfc/netlink.c +5 -2
@@ -1178,7 +1178,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)if (rc !=0 ) { rc = -EINVAL ; - goto put_local; + goto free_list; }if (!sdp_attrs[NFC_SDP_ATTR_URI ])
@@ -1197,7 +1197,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info) sdreq =nfc_llcp_build_sdreq_tlv (tid, uri, uri_len);if (sdreq ==NULL ) { rc = -ENOMEM ; - goto put_local; + goto free_list; } tlvs_len += sdreq->tlv_len;
@@ -1212,6 +1212,9 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info) rc =nfc_llcp_send_snl_sdreq (local, &sdreq_list, tlvs_len); +free_list: +nfc_llcp_free_sdp_tlv_list (&sdreq_list); + put_local:nfc_llcp_local_put (local);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 883/982 nfc: st21nfca: validate ISO15693 inventory length
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 7f2ea5ed588c03d481f0301e6c3d4240132383fb ]
The ISO15693 inventory helper removes a two-byte prefix without checking that it exists, then accepts a one-byte remainder before reading data[1] as the DSFID.
Require the prefix and at least two remaining bytes before copying the UID data and reading the DSFID.
--- drivers/nfc/st21nfca/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/nfc/st21nfca/core.c +1 -3
@@ -577,9 +577,7 @@ static int st21nfca_get_iso15693_inventory(struct nfc_hci_dev *hdev,if (r <0 ) goto exit; -skb_pull (inventory_skb,2 ); - -if (inventory_skb->len ==0 || +if (!skb_pull (inventory_skb,2 ) || inventory_skb->len <2 || inventory_skb->len >NFC_ISO15693_UID_MAXSIZE ) { r = -EPROTO ; goto exit;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 884/982 nfc: llcp: fix -ENOMEM on connect with zero-length service name
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit c04981e42d94f39c1dba965cc462a046e946a6c5 ]
When service_name_len is 0, kmemdup() returns ZERO_SIZE_PTR which passes the NULL check, causing nfc_llcp_send_connect() to attempt building a zero-length service name TLV and fail with -ENOMEM.
Fix by setting service_name to NULL directly when service_name_len is 0.
--- net/nfc/llcp_sock.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/nfc/llcp_sock.c +10 -6
@@ -759,12 +759,16 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, llcp_sock->service_name_len = min_t(unsigned int, addr->service_name_len,NFC_LLCP_MAX_SERVICE_NAME ); - llcp_sock->service_name =kmemdup (addr->service_name, - llcp_sock->service_name_len, -GFP_KERNEL ); -if (!llcp_sock->service_name) { - ret = -ENOMEM ; - goto sock_llcp_release; +if (llcp_sock->service_name_len ==0 ) { + llcp_sock->service_name =NULL ; + }else { + llcp_sock->service_name =kmemdup (addr->service_name, + llcp_sock->service_name_len, +GFP_KERNEL ); +if (!llcp_sock->service_name) { + ret = -ENOMEM ; + goto sock_llcp_release; + } }nfc_llcp_sock_link (&local->connecting_sockets, sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 885/982 nfc: llcp: fix WKS SAP hijacking via prefix match in nfc_llcp_wks_sap()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 408cff6bd60636df201274d320edfdfde9ed41db ]
nfc_llcp_wks_sap() compares only service_name_len bytes, so a short service_name like "u" matches longer WKS strings like "urn:nfc:sn:snep". Fix by requiring exact length match before strncmp().
--- net/nfc/llcp_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/nfc/llcp_core.c +2 -1
@@ -367,7 +367,8 @@ static int nfc_llcp_wks_sap(const char *service_name, size_t service_name_len)if (wks[sap] ==NULL )continue ; -if (strncmp (wks[sap], service_name, service_name_len) ==0 ) +if (strlen (wks[sap]) == service_name_len && + !strncmp (wks[sap], service_name, service_name_len))return sap; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 886/982 nfc: llcp: fix slab-out-of-bounds reads when logging service names
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 7dcf371a35632f035baf77bcf2c129165f772ce4 ]
nfc_llcp_wks_sap() and nfc_llcp_build_sdreq_tlv() pass non-null- terminated strings to pr_debug() using the %s format specifier. The buffers are allocated via kmemdup() or come from netlink attributes and are not guaranteed to be null-terminated, causing __dynamic_pr_debug() to read beyond the allocated region:
KASAN: slab-out-of-bounds Read in __dynamic_pr_debug
Fix both call sites by using %.*s with the explicit length to limit the output to the actual length of the string.
--- net/nfc/llcp_commands.c | 2 +- net/nfc/llcp_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/nfc/llcp_commands.c +1 -1
@@ -135,7 +135,7 @@ struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, const char *uri, {struct nfc_llcp_sdp_tlv *sdreq; -pr_debug ("uri: %s, len: %zu\n" , uri, uri_len); +pr_debug ("uri: %.*s, len: %zu\n" , (int )uri_len, uri, uri_len);/* sdreq->tlv_len is u8, takes uri_len, + 3 for header, + 1 for NULL */ if (WARN_ON_ONCE (uri_len >U8_MAX -4 ))
net/nfc/llcp_core.c +1 -1
@@ -356,7 +356,7 @@ static int nfc_llcp_wks_sap(const char *service_name, size_t service_name_len) {int sap, num_wks; -pr_debug ("%s\n" , service_name); +pr_debug ("%.*s\n" , (int )service_name_len, service_name);if (service_name ==NULL )return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 887/982 nfc: pn533: fix OOB read in pn533_acr122_is_rx_frame_valid()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Deepanshu Kartikey <[email protected]>
[ Upstream commit b61732f47316d45f27706db7812950145d3327b5 ]
frame->ccid.datalen is read directly from the USB response frame and used, unchecked, as an index into frame->data[]. A malicious or malfunctioning device can set this field to an arbitrary value, causing the driver to read far outside the received buffer.
Bound ccid.datalen against the maximum possible ACR122 frame size before using it. This replaces the existing datalen == 0 check, since datalen < 2 already covers that case and additionally rejects datalen == 1, which would still underflow the "datalen - 2" offset used below.
--- drivers/nfc/pn533/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nfc/pn533/usb.c +3 -1
@@ -320,7 +320,9 @@ static bool pn533_acr122_is_rx_frame_valid(void *_frame, struct pn533 *dev)if (frame->ccid.type !=0x83 )return false; -if (!frame->ccid.datalen) +if (frame->ccid.datalen <2 || + frame->ccid.datalen >PN533_ACR122_FRAME_MAX_PAYLOAD_LEN + +PN533_ACR122_RX_FRAME_TAIL_LEN )return false;if (frame->data[frame->ccid.datalen -2 ] ==0x63 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 888/982 net/sched: act_gate: budget the per-entry list in get_fill_size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit cfa165cbfbed9d0f4bbc22fef4309f595a3ab187 ]
tcf_gate_get_fill_size returns only the TCA_GATE_PARMS size, but tcf_gate_dump also emits three 64-bit timestamps, the clock id, flags, priority and the variable-length TCA_GATE_ENTRY_LIST nest. The per-entry nest is unbounded: parse_gate_list places no cap on the number of sched-entries, so a gate with many entries can push the real dump well past the skb that tca_get_fill allocates from this size.
RTM_NEWACTION then fails the add-notify with -EINVAL while the action is already committed to the IDR, and a subsequent RTM_GETACTION on the installed gate also returns -EINVAL because its dump no longer fits.
Fix this by accounting for the missing fields in tcf_gate_get_fill_size along with all elements in the entries list.
Note that sizing the reply from the action lets an oversized gate install cleanly for the first time: with the input unbounded by parse_gate_list, the sized skb can now grow well above NLMSG_GOODSIZE per netlink request (a transient GFP_KERNEL allocation reachable only with namespace-local CAP_NET_ADMIN). Overload from a malicious netns admin is hardening material, not net, per the discussion at
https://lore.kernel.org/netdev/[email protected]/;
a follow-up patch for net-next will cap the sched-entry count.
--- net/sched/act_gate.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
net/sched/act_gate.c +29 -1
@@ -682,7 +682,35 @@ static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u64 packets,static size_t tcf_gate_get_fill_size (const struct tc_action *act) { -return nla_total_size (sizeof (struct tc_gate )); +struct tcf_gate *gact =to_gate (act); +const struct tcf_gate_params *p; +struct tcfg_gate_entry *entry; +size_t size =nla_total_size (sizeof (struct tc_gate ))/* TCA_GATE_PARMS */ + +3 *nla_total_size_64bit (sizeof (u64))/* TCA_GATE_BASE_TIME +* TCA_GATE_CYCLE_TIME +* TCA_GATE_CYCLE_TIME_EXT +*/ + +nla_total_size (sizeof (s32))/* TCA_GATE_CLOCKID */ + +nla_total_size (sizeof (u32))/* TCA_GATE_FLAGS */ + +nla_total_size (sizeof (s32))/* TCA_GATE_PRIORITY */ + +nla_total_size (0 );/* TCA_GATE_ENTRY_LIST */ +/* TCA_GATE_TM is budgeted by tcf_action_shared_attrs_size() */ + +rcu_read_lock (); + p =rcu_dereference (gact->param); +if (p) { +list_for_each_entry_rcu (entry, &p->entries, list) +/* TCA_GATE_ONE_ENTRY nest and its attributes */ + size +=nla_total_size (0 ) + +nla_total_size (sizeof (u32))/* TCA_GATE_ENTRY_INDEX */ + +nla_total_size (0 )/* TCA_GATE_ENTRY_GATE */ + +nla_total_size (sizeof (u32))/* TCA_GATE_ENTRY_INTERVAL */ + +nla_total_size (sizeof (s32))/* TCA_GATE_ENTRY_MAX_OCTETS */ + +nla_total_size (sizeof (s32));/* TCA_GATE_ENTRY_IPV */ + } +rcu_read_unlock (); + +return size; }static void tcf_gate_entry_destructor (void *priv)
Signature · 1 line
2.53.0