6.18.65-rc1 review
Greg Kroah-Hartman
maintainerPATCH 1750/2151 power: supply: gpio-charger: Report discharging without input power
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Velkov <[email protected]>
[ Upstream commit f0f400459bf6a037e70768de623fff3f8920b8bb ]
The status property follows only the charge-status GPIO. Without input power a charger such as the BQ24133 releases its open-drain STAT pin, and depending on the board the GPIO then reads as charging.
On Kobol Helios64 the board runs from its battery after a mains loss, and the charger reports online 0 with status "Charging".
Report "Discharging" whenever the online GPIO is present and inactive.
--- drivers/power/supply/gpio-charger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/gpio-charger.c +4 -1
@@ -101,7 +101,10 @@ static int gpio_charger_get_property(struct power_supply *psy, val->intval =gpiod_get_value_cansleep (gpio_charger->gpiod);break ;case POWER_SUPPLY_PROP_STATUS : -if (gpiod_get_value_cansleep (gpio_charger->charge_status)) +/* Without input power the battery discharges, whatever the status pin says */ +if (gpio_charger->gpiod && !gpiod_get_value_cansleep (gpio_charger->gpiod)) + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; +else if (gpiod_get_value_cansleep (gpio_charger->charge_status)) val->intval =POWER_SUPPLY_STATUS_CHARGING ;else val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1751/2151 RDMA/core: Preserve the selected source GID on failed AH modification
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit d01ee4c84193196b6e4be4caf1ff8fdcc441ed96 ]
When an address-handle modification fails, the core replaces its source-GID reference. The old address then loses the reference which keeps its source entry alive.
--- drivers/infiniband/core/verbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/core/verbs.c +2 -1
@@ -1005,7 +1005,8 @@ int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr) ah->device->ops.modify_ah(ah, ah_attr) : -EOPNOTSUPP ; - ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr); +if (!ret) + ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr);rdma_unfill_sgid_attr (ah_attr, old_sgid_attr);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1752/2151 RDMA/core: Free unpublished port statistics after initial-read failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit d74bdcfa89fa45d3a506cddc37b3bf1b76cea0ce ]
An initial port counter read can fail after allocating its statistics buffer and wrapper. Free these both allocations.
--- drivers/infiniband/core/sysfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/infiniband/core/sysfs.c +7 -2
@@ -1039,8 +1039,8 @@ static int setup_hw_port_stats(struct ib_port *port, data->stats->num_counters);if (ret != data->stats->num_counters) {if (WARN_ON (ret >=0 )) -return -EINVAL ; -return ret; + ret = -EINVAL ; + goto err_free_data; } data->stats->timestamp = jiffies;
@@ -1074,6 +1074,11 @@ static int setup_hw_port_stats(struct ib_port *port, port->hw_stats_data = data;return 0 ; + +err_free_data: +rdma_free_hw_stats_struct (data->stats); +kfree (data); +return ret; } struct rdma_hw_stats *ib_get_hw_stats_port(struct ib_device *ibdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1753/2151 RDMA/core: Reject LAG selection when source MAC lookup fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit fdfd099222d9de9e2f1b8d69e94494c5489272cc ]
GID deletion can clear the source device association after LAG lookup retains the bonding master. Ignoring the resulting L2 lookup failure copies uninitialized source MAC bytes into the synthetic hash packet.
Read the source MAC before allocating the packet and propagate lookup errors to the caller, so failed lookups cannot influence slave selection.
--- drivers/infiniband/core/lag.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/infiniband/core/lag.c +8 -4
@@ -19,6 +19,11 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,u8 smac[ETH_ALEN ];bool is_ipv4;int hdr_len; +int ret; + + ret =rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac); +if (ret) +return ERR_PTR (ret); is_ipv4 =ipv6_addr_v4mapped ((struct in6_addr *)ah_attr->grh.dgid.raw); hdr_len =ETH_HLEN +sizeof (struct udphdr ) +LL_RESERVED_SPACE (netdev);
@@ -26,7 +31,7 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev, skb =alloc_skb (hdr_len, flags);if (!skb) -return NULL ; +return ERR_PTR (-ENOMEM ); skb->dev = netdev;skb_reserve (skb, hdr_len);
@@ -70,7 +75,6 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,skb_reset_mac_header (skb); eth =eth_hdr (skb); skb->protocol = eth->h_proto =htons (is_ipv4 ?ETH_P_IP :ETH_P_IPV6 ); -rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac);memcpy (eth->h_source, smac,ETH_ALEN );memcpy (eth->h_dest, ah_attr->roce.dmac,ETH_ALEN );
@@ -86,8 +90,8 @@ static struct net_device *rdma_get_xmit_slave_udp(struct ib_device *device,struct sk_buff *skb; skb =rdma_build_skb (master, ah_attr, flags); -if (!skb) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (skb)) +return ERR_CAST (skb);rcu_read_lock (); slave = netdev_get_xmit_slave(master, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1754/2151 RDMA/srp: Avoid reading uninitialized has_port on srp_parse_in() failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 4b8f20dc8d25f575e8b8bb5abb09ab803a7e1a3f ]
srp_parse_in() returns -ENOMEM without initializing *has_port if kstrdup() fails. Only check has_port when srp_parse_in() succeeds.
--- drivers/infiniband/ulp/srp/ib_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -3479,7 +3479,7 @@ static int srp_parse_options(struct net *net, const char *buf, } ret =srp_parse_in (net, &target->rdma_cm.dst.ss, p, &has_port); -if (!has_port) +if (ret ==0 && !has_port) ret = -EINVAL ;if (ret <0 ) {pr_warn ("bad dest parameter '%s'\n" , p);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1755/2151 ASoC: codecs: sta32x: Fix definition of limiter threshold controls
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit e06bf60ee5bffa9eeacff0bf8b03d4572b04f67d ]
The limiter attack and release thresholds are the two 4-bit halves of one register, so their maximum is 15, not 16. With 16 the controls on bits 3:0 also write bit 4, which belongs to the other threshold.
--- sound/soc/codecs/sta32x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/sta32x.c +8 -8
@@ -510,21 +510,21 @@ SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta32x_limiter2_release_rate_enum),* two different enum definitions; provide both */ SOC_SINGLE_TLV ("Limiter1 Attack Threshold (AC Mode)" ,STA32X_L1ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_ac_attack_tlv), +15 ,0 , sta32x_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (AC Mode)" ,STA32X_L2ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_ac_attack_tlv), +15 ,0 , sta32x_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (AC Mode)" ,STA32X_L1ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_ac_release_tlv), +15 ,0 , sta32x_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (AC Mode)" ,STA32X_L2ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_ac_release_tlv), +15 ,0 , sta32x_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter1 Attack Threshold (DRC Mode)" ,STA32X_L1ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_drc_attack_tlv), +15 ,0 , sta32x_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (DRC Mode)" ,STA32X_L2ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_drc_attack_tlv), +15 ,0 , sta32x_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (DRC Mode)" ,STA32X_L1ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_drc_release_tlv), +15 ,0 , sta32x_limiter_drc_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (DRC Mode)" ,STA32X_L2ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_drc_release_tlv), +15 ,0 , sta32x_limiter_drc_release_tlv),BIQUAD_COEFS ("Ch1 - Biquad 1" ,0 ), BIQUAD_COEFS("Ch1 - Biquad 2", 5),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1756/2151 ASoC: codecs: sta350: Fix definition of limiter threshold controls
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 77623752c156763d7a80414afe5b769ba4532bd3 ]
The limiter attack and release thresholds are the two 4-bit halves of one register, so their maximum is 15, not 16. With 16 the controls on bits 3:0 also write bit 4, which belongs to the other threshold.
--- sound/soc/codecs/sta350.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/sta350.c +8 -8
@@ -506,28 +506,28 @@ SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta350_limiter2_release_rate_enum),*/ SOC_SINGLE_TLV ("Limiter1 Attack Threshold (AC Mode)" ,STA350_L1ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_ac_attack_tlv), +15 ,0 , sta350_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (AC Mode)" ,STA350_L2ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_ac_attack_tlv), +15 ,0 , sta350_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (AC Mode)" ,STA350_L1ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_ac_release_tlv), +15 ,0 , sta350_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (AC Mode)" ,STA350_L2ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_ac_release_tlv), +15 ,0 , sta350_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter1 Attack Threshold (DRC Mode)" ,STA350_L1ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_drc_attack_tlv), +15 ,0 , sta350_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (DRC Mode)" ,STA350_L2ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_drc_attack_tlv), +15 ,0 , sta350_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (DRC Mode)" ,STA350_L1ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_drc_release_tlv), +15 ,0 , sta350_limiter_drc_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (DRC Mode)" ,STA350_L2ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_drc_release_tlv), +15 ,0 , sta350_limiter_drc_release_tlv),BIQUAD_COEFS ("Ch1 - Biquad 1" ,0 ), BIQUAD_COEFS("Ch1 - Biquad 2", 5),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1757/2151 ASoC: tlv320aic32x4: move regmap_config into i2c and spi drivers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 2ba6a4dba620bcee0f2210f532b25510a0872cf1 ]
Move regmap_config definitions to be static const structures in tlv320aic32x4-i2c.c and tlv320aic32x4-spi.c instead of dynamically modifying a shared base regmap_config at runtime during probe. Export aic32x4_regmap_pages so both bus drivers can reference page ranges.
In addition, validate regmap initialization immediately upon creation in both bus probe routines and remove the redundant error check from core aic32x4_probe.
Stable-dep-of: f28c09b7e62f ("ASoC: tlv320aic32x4: Fix definition of TAS2505 HP Driver Gain Volume control")
--- sound/soc/codecs/tlv320aic32x4-i2c.c | 16 +++++++++++----- sound/soc/codecs/tlv320aic32x4-spi.c | 20 +++++++++++++------- sound/soc/codecs/tlv320aic32x4.c | 13 ++----------- sound/soc/codecs/tlv320aic32x4.h | 2 +- 4 files changed, 27 insertions(+), 24 deletions(-)
sound/soc/codecs/tlv320aic32x4-i2c.c +11 -5
@@ -16,17 +16,23 @@#include "tlv320aic32x4.h" +static const struct regmap_config aic32x4_i2c_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =AIC32X4_REFPOWERUP , + .ranges = aic32x4_regmap_pages, + .num_ranges =1 , +}; +static int aic32x4_i2c_probe (struct i2c_client *i2c) {struct regmap *regmap; -struct regmap_config config;enum aic32x4_type type; - config = aic32x4_regmap_config; - config.reg_bits =8 ; - config.val_bits =8 ; + regmap =devm_regmap_init_i2c (i2c, &aic32x4_i2c_regmap_config); +if (IS_ERR (regmap)) +return PTR_ERR (regmap); - regmap =devm_regmap_init_i2c (i2c, &config); type = (uintptr_t )i2c_get_match_data (i2c);return aic32x4_probe (&i2c->dev, regmap, type);
sound/soc/codecs/tlv320aic32x4-spi.c +13 -7
@@ -16,19 +16,25 @@#include "tlv320aic32x4.h" +static const struct regmap_config aic32x4_spi_regmap_config = { + .reg_bits =7 , + .pad_bits =1 , + .val_bits =8 , + .read_flag_mask =0x01 , + .max_register =AIC32X4_REFPOWERUP , + .ranges = aic32x4_regmap_pages, + .num_ranges =1 , +}; +static int aic32x4_spi_probe (struct spi_device *spi) {struct regmap *regmap; -struct regmap_config config;enum aic32x4_type type; - config = aic32x4_regmap_config; - config.reg_bits =7 ; - config.pad_bits =1 ; - config.val_bits =8 ; - config.read_flag_mask =0x01 ; + regmap =devm_regmap_init_spi (spi, &aic32x4_spi_regmap_config); +if (IS_ERR (regmap)) +return PTR_ERR (regmap); - regmap =devm_regmap_init_spi (spi, &config); type = (uintptr_t )spi_get_device_match_data (spi);return aic32x4_probe (&spi->dev, regmap, type);
sound/soc/codecs/tlv320aic32x4.c +2 -11
@@ -575,7 +575,7 @@ static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = { {"IN3_R to Left Mixer Negative Resistor", "40 kOhm", "IN3_R"}, }; -static const struct regmap_range_cfg aic32x4_regmap_pages[] = { +const struct regmap_range_cfg aic32x4_regmap_pages[] = { { .selector_reg = 0, .selector_mask = 0xff,
@@ -585,13 +585,7 @@ static const struct regmap_range_cfg aic32x4_regmap_pages[] = { .range_max = AIC32X4_REFPOWERUP, }, }; - -const struct regmap_config aic32x4_regmap_config = { - .max_register =AIC32X4_REFPOWERUP , - .ranges = aic32x4_regmap_pages, - .num_ranges =ARRAY_SIZE (aic32x4_regmap_pages), -}; -EXPORT_SYMBOL (aic32x4_regmap_config); +EXPORT_SYMBOL_GPL (aic32x4_regmap_pages);static int aic32x4_set_dai_sysclk (struct snd_soc_dai *codec_dai,int clk_id,unsigned int freq,int dir)
@@ -1355,9 +1349,6 @@ int aic32x4_probe(struct device *dev, struct regmap *regmap,struct device_node *np = dev->of_node;int ret; -if (IS_ERR (regmap)) -return PTR_ERR (regmap); - aic32x4 =devm_kzalloc (dev,sizeof (struct aic32x4_priv ),GFP_KERNEL );if (aic32x4 ==NULL )
sound/soc/codecs/tlv320aic32x4.h +1 -1
@@ -16,7 +16,7 @@ enum aic32x4_type { AIC32X4_TYPE_TAS2505, }; -extern const struct regmap_config aic32x4_regmap_config; +extern const struct regmap_range_cfg aic32x4_regmap_pages[];int aic32x4_probe (struct device *dev,struct regmap *regmap,enum aic32x4_type type);void aic32x4_remove (struct device *dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1758/2151 ASoC: tlv320aic32x4: clean up driver code formatting and logging
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit c3ac0aa6c3100f973b44bb0b0882f435075ed215 ]
Clean up coding style, SPDX comments, logging calls, and macro definitions across the tlv320aic32x4 driver files:
- Convert SPDX comment blocks to // style in bus and clk drivers.
- Replace printk(KERN_ERR/DEBUG ...) calls with dev_err/dev_dbg.
- Replace msleep(10) with usleep_range(10000, 20000) in the clock driver.
- Parenthesize parameters in AIC32X4_REG macro.
- Clean up double blank lines and null pointer checks.
Stable-dep-of: f28c09b7e62f ("ASoC: tlv320aic32x4: Fix definition of TAS2505 HP Driver Gain Volume control")
--- sound/soc/codecs/tlv320aic32x4-clk.c | 68 ++++--- sound/soc/codecs/tlv320aic32x4-i2c.c | 5 +- sound/soc/codecs/tlv320aic32x4-spi.c | 5 +- sound/soc/codecs/tlv320aic32x4.c | 270 +++++++++++++-------------- sound/soc/codecs/tlv320aic32x4.h | 3 +- 5 files changed, 163 insertions(+), 188 deletions(-)
sound/soc/codecs/tlv320aic32x4-clk.c +33 -35
@@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0 -* +// SPDX-License-Identifier: GPL-2.0 +/* * Clock Tree for the Texas Instruments TLV320AIC32x4 * * Copyright 2019 Annaliese McDermond
@@ -9,6 +9,7 @@#include <linux/clk-provider.h> #include <linux/clkdev.h> +#include <linux/delay.h> #include <linux/regmap.h> #include <linux/device.h>
@@ -57,7 +58,7 @@ static void clk_aic32x4_pll_unprepare(struct clk_hw *hw)struct clk_aic32x4 *pll =to_clk_aic32x4 (hw);regmap_update_bits (pll->regmap,AIC32X4_PLLPR , -AIC32X4_PLLEN ,0 ); +AIC32X4_PLLEN ,0 ); }static int clk_aic32x4_pll_is_prepared (struct clk_hw *hw)
@@ -75,7 +76,7 @@ static int clk_aic32x4_pll_is_prepared(struct clk_hw *hw) }static int clk_aic32x4_pll_get_muldiv (struct clk_aic32x4 *pll, -struct clk_aic32x4_pll_muldiv *settings) +struct clk_aic32x4_pll_muldiv *settings) {/* Change to use regmap_bulk_read? */ unsigned int val;
@@ -106,19 +107,19 @@ static int clk_aic32x4_pll_get_muldiv(struct clk_aic32x4 *pll, }static int clk_aic32x4_pll_set_muldiv (struct clk_aic32x4 *pll, -struct clk_aic32x4_pll_muldiv *settings) +struct clk_aic32x4_pll_muldiv *settings) {int ret;/* Change to use regmap_bulk_write for some if not all? */ ret =regmap_update_bits (pll->regmap,AIC32X4_PLLPR , -AIC32X4_PLL_R_MASK , settings->r); +AIC32X4_PLL_R_MASK , settings->r);if (ret <0 )return ret; ret =regmap_update_bits (pll->regmap,AIC32X4_PLLPR , -AIC32X4_PLL_P_MASK , - settings->p <<AIC32X4_PLL_P_SHIFT ); +AIC32X4_PLL_P_MASK , + settings->p <<AIC32X4_PLL_P_SHIFT );if (ret <0 )return ret;
@@ -136,23 +137,21 @@ static int clk_aic32x4_pll_set_muldiv(struct clk_aic32x4 *pll,return 0 ; } -static unsigned long clk_aic32x4_pll_calc_rate ( -struct clk_aic32x4_pll_muldiv *settings, -unsigned long parent_rate) +static unsigned long clk_aic32x4_pll_calc_rate (struct clk_aic32x4_pll_muldiv *settings, +unsigned long parent_rate) {u64 rate;/* * We scale j by 10000 to account for the decimal part of P and divide * it back out later. */ - rate = (u64 ) parent_rate * settings->r * - ((settings->j *10000 ) + settings->d); + rate = (u64 )parent_rate * settings->r * ((settings->j *10000 ) + settings->d); -return (unsigned long )DIV_ROUND_UP_ULL (rate, settings->p *10000 ); +return (unsigned long )DIV_ROUND_UP_ULL (rate, settings->p *10000 ); }static int clk_aic32x4_pll_calc_muldiv (struct clk_aic32x4_pll_muldiv *settings, -unsigned long rate,unsigned long parent_rate) +unsigned long rate,unsigned long parent_rate) {u64 multiplier;
@@ -165,14 +164,14 @@ static int clk_aic32x4_pll_calc_muldiv(struct clk_aic32x4_pll_muldiv *settings,* of the multiplier. This is because we can't do floating point * math in the kernel. */ - multiplier = (u64 ) rate * settings->p *10000 ; + multiplier = (u64 )rate * settings->p *10000 ;do_div (multiplier, parent_rate);/* * J can't be over 64, so R can scale this. * R can't be greater than 4. */ - settings->r = ((u32 ) multiplier /640000 ) +1 ; + settings->r = ((u32 )multiplier /640000 ) +1 ;if (settings->r >4 )return -1 ;do_div (multiplier, settings->r);
@@ -184,14 +183,14 @@ static int clk_aic32x4_pll_calc_muldiv(struct clk_aic32x4_pll_muldiv *settings,return -1 ;/* Figure out the integer part, J, and the fractional part, D. */ - settings->j = (u32 ) multiplier /10000 ; - settings->d = (u32 ) multiplier %10000 ; + settings->j = (u32 )multiplier /10000 ; + settings->d = (u32 )multiplier %10000 ;return 0 ; }static unsigned long clk_aic32x4_pll_recalc_rate (struct clk_hw *hw, -unsigned long parent_rate) +unsigned long parent_rate) {struct clk_aic32x4 *pll =to_clk_aic32x4 (hw);struct clk_aic32x4_pll_muldiv settings;
@@ -220,8 +219,8 @@ static int clk_aic32x4_pll_determine_rate(struct clk_hw *hw, }static int clk_aic32x4_pll_set_rate (struct clk_hw *hw, -unsigned long rate, -unsigned long parent_rate) +unsigned long rate, +unsigned long parent_rate) {struct clk_aic32x4 *pll =to_clk_aic32x4 (hw);struct clk_aic32x4_pll_muldiv settings;
@@ -236,7 +235,7 @@ static int clk_aic32x4_pll_set_rate(struct clk_hw *hw,return ret;/* 10ms is the delay to wait before the clocks are stable */ -msleep (10 ); +usleep_range (10000 ,20000 );return 0 ; }
@@ -261,7 +260,6 @@ static u8 clk_aic32x4_pll_get_parent(struct clk_hw *hw)return (val &AIC32X4_PLL_CLKIN_MASK ) >>AIC32X4_PLL_CLKIN_SHIFT ; } -static const struct clk_ops aic32x4_pll_ops = { .prepare = clk_aic32x4_pll_prepare, .unprepare = clk_aic32x4_pll_unprepare,
@@ -311,11 +309,11 @@ static void clk_aic32x4_div_unprepare(struct clk_hw *hw)struct clk_aic32x4 *div =to_clk_aic32x4 (hw);regmap_update_bits (div->regmap, div->reg, -AIC32X4_DIVEN ,0 ); +AIC32X4_DIVEN ,0 ); }static int clk_aic32x4_div_set_rate (struct clk_hw *hw,unsigned long rate, -unsigned long parent_rate) +unsigned long parent_rate) {struct clk_aic32x4 *div =to_clk_aic32x4 (hw);u8 divisor;
@@ -348,7 +346,7 @@ static int clk_aic32x4_div_determine_rate(struct clk_hw *hw, }static unsigned long clk_aic32x4_div_recalc_rate (struct clk_hw *hw, -unsigned long parent_rate) +unsigned long parent_rate) {struct clk_aic32x4 *div =to_clk_aic32x4 (hw);unsigned int val;
@@ -405,7 +403,7 @@ static struct aic32x4_clkdesc aic32x4_clkdesc_array[] = { { .name = "pll", .parent_names = - (const char* []) { "mclk", "bclk", "gpio", "din" }, + (const char *[]) { "mclk", "bclk", "gpio", "din" }, .num_parents = 4, .ops = &aic32x4_pll_ops, .reg = 0,
@@ -420,28 +418,28 @@ static struct aic32x4_clkdesc aic32x4_clkdesc_array[] = { }, { .name = "ndac", - .parent_names = (const char * []) { "codec_clkin" }, + .parent_names = (const char *[]) { "codec_clkin" }, .num_parents = 1, .ops = &aic32x4_div_ops, .reg = AIC32X4_NDAC, }, { .name = "mdac", - .parent_names = (const char * []) { "ndac" }, + .parent_names = (const char *[]) { "ndac" }, .num_parents = 1, .ops = &aic32x4_div_ops, .reg = AIC32X4_MDAC, }, { .name = "nadc", - .parent_names = (const char * []) { "codec_clkin" }, + .parent_names = (const char *[]) { "codec_clkin" }, .num_parents = 1, .ops = &aic32x4_div_ops, .reg = AIC32X4_NADC, }, { .name = "madc", - .parent_names = (const char * []) { "nadc" }, + .parent_names = (const char *[]) { "nadc" }, .num_parents = 1, .ops = &aic32x4_div_ops, .reg = AIC32X4_MADC,
@@ -457,7 +455,7 @@ static struct aic32x4_clkdesc aic32x4_clkdesc_array[] = { };static struct clk *aic32x4_register_clk (struct device *dev, -struct aic32x4_clkdesc *desc) +struct aic32x4_clkdesc *desc) {struct clk_init_data init;struct clk_aic32x4 *priv;
@@ -470,8 +468,8 @@ static struct clk *aic32x4_register_clk(struct device *dev, init.flags =0 ; priv =devm_kzalloc (dev,sizeof (struct clk_aic32x4 ),GFP_KERNEL ); -if (priv ==NULL ) -return (struct clk *) -ENOMEM ; +if (!priv) +return ERR_PTR (-ENOMEM ); priv->dev = dev; priv->hw.init = &init;
sound/soc/codecs/tlv320aic32x4-i2c.c +2 -3
@@ -1,11 +1,10 @@ -/* SPDX-License-Identifier: GPL-2.0 -* +// SPDX-License-Identifier: GPL-2.0 +/* * Copyright 2011-2019 NW Digital Radio * * Author: Annaliese McDermond <[email protected]> * * Based on sound/soc/codecs/wm8974 and TI driver for kernel 2.6.27. -* */ #include <linux/i2c.h>
sound/soc/codecs/tlv320aic32x4-spi.c +2 -3
@@ -1,11 +1,10 @@ -/* SPDX-License-Identifier: GPL-2.0 -* +// SPDX-License-Identifier: GPL-2.0 +/* * Copyright 2011-2019 NW Digital Radio * * Author: Annaliese McDermond <[email protected]> * * Based on sound/soc/codecs/wm8974 and TI driver for kernel 2.6.27. -* */ #include <linux/spi/spi.h>
sound/soc/codecs/tlv320aic32x4.c +125 -145
581 lines not on this page · raw message
sound/soc/codecs/tlv320aic32x4.h +1 -2
@@ -3,7 +3,6 @@* tlv320aic32x4.h */ -#ifndef _TLV320AIC32X4_H#define _TLV320AIC32X4_H
@@ -24,7 +23,7 @@ int aic32x4_register_clocks(struct device *dev, const char *mclk_name);/* tlv320aic32x4 register space (in decimal to match datasheet) */ -#define AIC32X4_REG (page, reg) ((page * 128) + reg) +#define AIC32X4_REG (page, reg) (((page) * 128) + (reg))#define AIC32X4_PSEL AIC32X4_REG(0, 0)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1759/2151 ASoC: tlv320aic32x4: Fix definition of TAS2505 HP Driver Gain Volume control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit f28c09b7e62fb5ead65bdfab93012a86d64b6540 ]
The TAS2505 HP volume is bits 6:0 of page 1 register 22, not of register 16, which holds the HP driver mute (bit 6) and gain (bits 5:0).
--- sound/soc/codecs/tlv320aic32x4.c | 2 +- sound/soc/codecs/tlv320aic32x4.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
sound/soc/codecs/tlv320aic32x4.c +1 -1
@@ -1074,7 +1074,7 @@ static const struct snd_kcontrol_new aic32x4_tas2505_snd_controls[] = {SOC_ENUM ("DAC Playback PowerTune Switch" , l_ptm_enum),SOC_SINGLE_TLV ("HP Driver Gain Volume" , -AIC32X4_HPLGAIN ,0 ,0x74 ,1 , tlv_tas_driver_gain), +TAS2505_HPVOL ,0 ,0x74 ,1 , tlv_tas_driver_gain),SOC_SINGLE ("HP DAC Playback Switch" ,AIC32X4_HPLGAIN ,6 ,1 ,1 ), SOC_SINGLE_TLV("Speaker Driver Playback Volume",
sound/soc/codecs/tlv320aic32x4.h +1 -0
@@ -94,6 +94,7 @@ int aic32x4_register_clocks(struct device *dev, const char *mclk_name);#define AIC32X4_LOLGAIN AIC32X4_REG(1, 18)#define AIC32X4_LORGAIN AIC32X4_REG(1, 19)#define AIC32X4_HEADSTART AIC32X4_REG(1, 20) +#define TAS2505_HPVOL AIC32X4_REG(1, 22)#define TAS2505_SPK AIC32X4_REG(1, 45)#define TAS2505_SPKVOL1 AIC32X4_REG(1, 46)#define TAS2505_SPKVOL2 AIC32X4_REG(1, 48)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1760/2151 RDMA/rxe: Clear pkt->qp before the early drop exits in rxe_rcv()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiwei Zhang <[email protected]>
[ Upstream commit 7d7214b39b14c9763c14445b139f63369063b65e ]
rxe_rcv() puts pkt->qp at its drop label, but leaves pkt->qp uninitialized on the two paths that take an early goto:
if (unlikely(skb->len < RXE_BTH_BYTES)) goto drop; if (rxe_chk_dgid(rxe, skb) < 0) goto drop; pkt->opcode = bth_opcode(pkt); pkt->psn = bth_psn(pkt); pkt->qp = NULL; <- too late for the gotos above ... drop: if (pkt->qp) rxe_put(pkt->qp);
pkt points into skb->cb, which rxe does not own at this point: the network stack has used that space for its own state. For IPv6, ip6_rcv_core() memsets inet6_skb_parm and then writes
IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
at offset 14, so the qword at cb + 8, which is where pkt->qp lives, reads back as 0x0006000000000000 for every IPv6 packet.
Any IPv6 datagram to port 4791 whose payload is shorter than the BTH takes the first goto and reaches the drop label with that value, so rxe_put() runs refcount_dec_and_test() on 0x0006000000000150 and the kernel faults, in softirq, on a non-canonical address:
general protection fault, probably for non-canonical address 0x0006000000000150: 0000 [#1] PREEMPT SMP RIP: 0010:__rxe_put+0x.../... Call Trace: <IRQ> rxe_rcv+0x.../... [rdma_rxe] rxe_udp_encap_recv+0x.../... [rdma_rxe] udp_queue_rcv_one_skb ... Kernel panic - not syncing: Fatal exception in interrupt
The fault happens in softirq, so it panics even with panic_on_oops=0, and with panic=0 the machine hangs until it is power cycled. A remote sender only needs to send an empty UDP datagram to port 4791; no RDMA connection, GID or other state is involved and the rxe socket is bound in init_net.
IPv4 is not affected: ip_rcv_core() memsets the whole inet_skb_parm, so the pkt->qp slot is zero there.
Fix by clearing pkt->qp before the first early exit. pkt->qp is only ever assigned a reference-owning value by hdr_check() and rxe_rcv_mcast_pkt(), both of which run after this point, so the put at the drop label stays balanced.
The ordering has been unsafe since the driver was merged: the two early gotos have preceded pkt->qp = NULL in every version since 8700e3e7c485.
Testing done: the driver was built and run on a 6.2 vendor tree that carries this code, where a single 0-byte IPv6 datagram to port 4791 reproduced the panic above (that tree does not pull the UDP header in rxe_udp_encap_recv(), so payloads of 0..3 bytes reach the first goto there, versus 0..11 on mainline). With this change, the same packets are dropped as intended and tracing the drop label shows pkt->qp is 0 on every path that reaches it. Not done: the mainline tree was not built in the environment used to prepare this, and the reproducer is left out of this message on purpose - both are available on request.
--- drivers/infiniband/sw/rxe/rxe_recv.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_recv.c +8 -1
@@ -319,6 +319,14 @@ void rxe_rcv(struct sk_buff *skb)struct rxe_pkt_info *pkt =SKB_TO_PKT (skb);struct rxe_dev *rxe = pkt->rxe; +/* +* pkt lives in skb->cb, which the network stack has already used +* for its own state: for IPv6 the qword holding pkt->qp holds +* inet6_skb_parm.nhoff. The drop label puts pkt->qp, so clear +* it before the first early exit. +*/ + pkt->qp =NULL ; +if (unlikely (skb->len <RXE_BTH_BYTES )) goto drop;
@@ -327,7 +335,6 @@ void rxe_rcv(struct sk_buff *skb) pkt->opcode =bth_opcode (pkt); pkt->psn =bth_psn (pkt); - pkt->qp =NULL ; pkt->mask |= rxe_opcode[pkt->opcode].mask;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1761/2151 RDMA/usnic: Bound buffer size to sizeof(buf) in flowinfo_read()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 9dd8b9a337af844291edcd9139c927d0f7958dbe ]
In flowinfo_read(), 'left' tracks the remaining space in the 512-byte stack buffer 'buf', but it is initialized to 'count'.
Initialize 'left' to sizeof(buf) instead of 'count'.
--- drivers/infiniband/hw/usnic/usnic_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/usnic/usnic_debugfs.c +1 -1
@@ -76,7 +76,7 @@ static ssize_t flowinfo_read(struct file *f, char __user *data, qp_flow = f->private_data; ptr = buf; - left = count; + left =sizeof (buf);if (*ppos >0 )return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1762/2151 dt-bindings: vendor-prefixes: Add Sensylink
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Troy Mitchell <[email protected]>
[ Upstream commit f4ba4f8cc8e8df45e57c1754955b3a6b9b089a97 ]
Add the vendor prefix for Sensylink Microelectronics.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1425,6 +1425,8 @@ patternProperties: description: Sensirion AG "^sensortek,.*": description: Sensortek Technology Corporation + "^sensylink,.*": + description: Sensylink Microelectronics Technology Co., Ltd. "^sercomm,.*": description: Sercomm (Suzhou) Corporation "^sff,.*":
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1763/2151 selftests/bpf: Use _exit() in uprobe_multi_test clone-ed child
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: KaFai Wan <[email protected]>
[ Upstream commit ce42271dc517baa880352d76548d301850e7385b ]
child_func() terminates with exit(), but spawn_child_flag() also starts it via clone(CLONE_VM), which shares the parent's address space. That exit() then runs atexit handlers and static destructors against globals the parent is still using.
LLVM commit 3c3ed59c6a2a ("[llvm] Add format check for MCSubtargetFeatures") [1], included in the LLVM 23.1 releases, added Target::isValidFeatureListFormat() with a function-local static holding the compiled regex:
static const llvm::Regex pattern("^([+-][^,]+)(,[+-][^,]+)*,?$");
return pattern.match(Features);The child exit destroys that static while its guard variable still marks it as initialized, so the regex is never rebuilt in the parent. From that point on, get_jited_program_text() gets NULL from LLVMCreateDisasmCPUFeatures(), so every jited program text check in the tests running after filter_clone_vm fails, e.g. "verifier_jit_convergence", "verifier_private_stack", "verifier_tailcall_jit" and "verifier_jit_inline".
Use _exit(), which runs neither atexit handlers nor static destructors, as uprobe_syscall.c already does for its own CLONE_VM child.
[1] https://github.com/llvm/llvm-project/pull/180943
--- tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +2 -2
@@ -91,14 +91,14 @@ static int child_func(void *arg)/* wait for parent's kick */ err =read (child->go[0 ], &c,1 );if (err !=1 ) -exit (err); +_exit (err);uprobe_multi_func_1 ();uprobe_multi_func_2 ();uprobe_multi_func_3 ();usdt_trigger (); -exit (errno); +_exit (errno); }static int spawn_child_flag (struct child *child,bool clone_vm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1764/2151 selftests/bpf: Run the cpumask map insert tests only for the test task
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit e2c978ad415ce223e71f6ddaa92778225eca0bef ]
verify_success() attaches each cpumask test program to task_newtask, forks a single child, and expects err to be 0 afterwards. Most programs return right away for other tasks than the test one.
test_insert_leave and test_insert_remove_release don't, and insert a cpumask into the single entry of __cpumask_map for every task created in the system while they are attached. test_insert_leave leaves its cpumask in the map, so a second task created, for instance by a test running in parallel, fails to insert one and sets err to 3. Two tasks created at the same time can do the same to test_insert_remove_release.
Return early for other tasks than the test one in both programs, as the other programs do.
--- tools/testing/selftests/bpf/progs/cpumask_success.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/testing/selftests/bpf/progs/cpumask_success.c +6 -0
@@ -460,6 +460,9 @@ int BPF_PROG(test_insert_leave, struct task_struct *task, u64 clone_flags) {struct bpf_cpumask *cpumask; +if (!is_test_task ()) +return 0 ; + cpumask =create_cpumask ();if (!cpumask)return 0 ;
@@ -476,6 +479,9 @@ int BPF_PROG(test_insert_remove_release, struct task_struct *task, u64 clone_flastruct bpf_cpumask *cpumask;struct __cpumask_map_value *v; +if (!is_test_task ()) +return 0 ; + cpumask =create_cpumask ();if (!cpumask)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1765/2151 gpiolib: fix memory leak in gpiod_set_array_value_complex() EPERM error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kent Gibson <[email protected]>
[ Upstream commit 138d7365c20efe47b4caa92c46f086ec39b81f78 ]
A drive-by review by Sashiko reports that, where the line has not been configured as an output, gpiod_set_array_value_complex() can return without freeing potentially alloced bitmaps, thus leaking memory.
Cleanup the bitmaps before returning.
--- drivers/gpio/gpiolib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib.c +6 -4
@@ -3694,7 +3694,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, unsigned long *value_bitmap) {struct gpio_chip *gc; -int i =0 , ret; +int i =0 , ret =0 ;/* * Validate array_info against desc_array and its size.
@@ -3772,8 +3772,10 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,int hwgpio =gpiod_hwgpio (desc);int value =test_bit (i, value_bitmap); -if (unlikely (!test_bit (GPIOD_FLAG_IS_OUT , &desc->flags))) -return -EPERM ; +if (unlikely (!test_bit (GPIOD_FLAG_IS_OUT , &desc->flags))) { + ret = -EPERM ; + goto cleanup_bitmap; + }/* * Pins applicable for fast input but not for
@@ -3806,10 +3808,10 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, }while ((i < array_size) &&gpio_device_chip_cmp (desc_array[i]->gdev, guard.gc));/* push collected bits to outputs */ - ret =0 ;if (count !=0 ) ret =gpiochip_set_multiple (guard.gc, mask, bits); +cleanup_bitmap:if (mask != fastpath_mask)bitmap_free (mask);if (bits != fastpath_bits)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1766/2151 gpiolib: clear the event clock flags when a line is released
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Ambrozewicz <[email protected]>
[ Upstream commit d35f61581ee67f8d4d58c325bac813cea528b6b9 ]
gpiod_free_commit() clears the flags that a request sets on a line, but not GPIOD_FLAG_EVENT_CLOCK_REALTIME and GPIOD_FLAG_EVENT_CLOCK_HTE, which gpio_v2_line_config_flags_to_desc_flags() sets from the uAPI v2 line config. Once a line requested with GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME or GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE is released, GPIO_V2_GET_LINEINFO_IOCTL and the line info changed events, the "released" one included, keep reporting that event clock for the free line:
GPIO_V2_GET_LINE_IOCTL, line 1, input, event clock realtime: ok close()
GPIO_V2_GET_LINEINFO_IOCTL, line 1: input, event clock realtime
The flags are set before edge detection is set up, so a request that fails in hte_ts_get(), for instance because no HTE provider handles the line, leaves GPIOD_FLAG_EVENT_CLOCK_HTE behind as well. The next uAPI v2 request rewrites both flags, but requests through uAPI v1, sysfs exports and in-kernel consumers do not, and the line info then shows the event clock of an earlier user for them too.
Clear both flags together with the other flags of the request.
Reproduced under QEMU with a test GPIO chip: after a released request with the realtime event clock, and on a kernel with CONFIG_HTE=y but no HTE provider after a failed request with the HTE event clock, the line info of the free line still reports that event clock. With this change it reports none.
--- drivers/gpio/gpiolib.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpiolib.c +2 -0
@@ -2519,6 +2519,8 @@ static void gpiod_free_commit(struct gpio_desc *desc)clear_bit (GPIOD_FLAG_BIAS_DISABLE , &flags);clear_bit (GPIOD_FLAG_EDGE_RISING , &flags);clear_bit (GPIOD_FLAG_EDGE_FALLING , &flags); +clear_bit (GPIOD_FLAG_EVENT_CLOCK_REALTIME , &flags); +clear_bit (GPIOD_FLAG_EVENT_CLOCK_HTE , &flags);clear_bit (GPIOD_FLAG_IS_HOGGED , &flags);#ifdef CONFIG_OF_DYNAMIC WRITE_ONCE (desc->hog,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1767/2151 ALSA: pcm: Protect the unregister notifier traversal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 680be9f82d4977d3410c513d3bfe912d100f64fc ]
snd_pcm_free() traverses snd_pcm_notify_list and calls n_unregister without register_mutex, although snd_pcm_notify() takes that mutex to add and remove notifiers. PCM disconnect releases the mutex before the free callback runs, so it does not protect this later traversal.
With no open OSS file, normal snd-pcm-oss removal can overlap PCM card teardown, for example when unbinding snd-dummy:
PCM card teardown snd-pcm-oss unload
----------------- ------------------
snd_pcm_dev_disconnect()
remove PCM under register_mutex
unlock register_mutex
snd_pcm_free()
fetch notifier
snd_pcm_notify(..., 1)
unlink notifier under mutex
free module storage
read notifier->n_unregister
invoke callback
The free path can then read the notifier from released module storage or call its unloaded code.
Hold register_mutex across the unregister traversal and its callbacks. Notifier removal must wait until both have finished. This also protects the traversal if a callback releases the last module reference: module exit cannot unlink its notifier until the free path releases the mutex. Drop the mutex before private_free and the remaining stream cleanup.
--- sound/core/pcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/core/pcm.c +4 -2
@@ -855,8 +855,10 @@ static int snd_pcm_free(struct snd_pcm *pcm) {if (!pcm)return 0 ; -if (!pcm->internal) -pcm_call_notify (pcm, n_unregister); +if (!pcm->internal) { + scoped_guard(mutex, ®ister_mutex) +pcm_call_notify (pcm, n_unregister); + }if (pcm->private_free) pcm->private_free (pcm);snd_pcm_lib_preallocate_free_for_all (pcm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1768/2151 ALSA: oss: Keep emulation modules loaded until object teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f0780cfa6acf72576464dc3b40431db389f46ee8 ]
OSS proc entries and notifier callbacks can remain in use without an open OSS device file. Normal snd-pcm-oss removal can therefore delete an existing PCM's OSS proc entry while late HDA codec binding repeats snd_card_register() on the same live card:
OSS PCM module unload Card registration
--------------------- -----------------
snd_info_free_entry(entry)
proc_remove(entry->p)
clear entry->p
snd_info_card_register()
republish linked entry
unlink and free entry
The new proc node retains a pointer to freed storage. Mixer OSS removal can likewise release an adapter while a card notification still uses it.
Hold a snd-pcm-oss module reference for each PCM registered with its notifier and a snd-mixer-oss reference for each card adapter. Release them at final unregister or FREE, after proc and adapter cleanup. Normal module unload can no longer initiate removal while these objects exist.
Track PCM OSS registration with a separate bool registered. Unlike oss.reg, this state also covers unmapped PCMs and remains set across DISCONNECT until final unregister. BUILD-state and creation-error cleanup must not drop a reference when registration never acquired one. The PCM notifier's register_mutex serialization keeps the final put ahead of notifier removal and module teardown until dispatch has finished.
For mixer OSS, serialize callback publication, dispatch and withdrawal in the core so module exit waits for callbacks, including one dropping the last reference, to return. Keep card enumeration in the OSS module, with card references released after dispatch drops the mutex. Ignore duplicate REGISTER notifications so a delayed registration cannot replace an adapter retained across DISCONNECT and leak its module pin.
Partial HDA codec teardown can still remove an individual PCM while the card remains registered; its object-lifetime handling is separate.
--- include/sound/core.h | 3 ++- include/sound/pcm_oss.h | 1 + sound/core/init.c | 29 +++++++++++++++++++++-------- sound/core/oss/mixer_oss.c | 36 ++++++++++++++++++++---------------- sound/core/oss/pcm_oss.c | 12 ++++++++++++ 5 files changed, 56 insertions(+), 25 deletions(-)
include/sound/core.h +2 -1
@@ -298,7 +298,8 @@ int snd_card_locked(int card);#define SND_MIXER_OSS_NOTIFY_REGISTER 0#define SND_MIXER_OSS_NOTIFY_DISCONNECT 1#define SND_MIXER_OSS_NOTIFY_FREE 2 -extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card,int cmd); +void snd_mixer_oss_set_notify (int (*callback)(struct snd_card *card,int cmd)); +void snd_mixer_oss_notify (struct snd_card *card,int cmd);#endif int snd_card_new(struct device *parent, int idx, const char *xid,
include/sound/pcm_oss.h +1 -0
@@ -70,6 +70,7 @@ struct snd_pcm_oss_stream {struct snd_pcm_oss {int reg;unsigned int reg_mask; +bool registered; };#endif /* __SOUND_PCM_OSS_H */
sound/core/init.c +21 -8
@@ -82,8 +82,24 @@ static int module_slot_match(struct module *module, int idx) }#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -int (*snd_mixer_oss_notify_callback)(struct snd_card *card,int free_flag); -EXPORT_SYMBOL (snd_mixer_oss_notify_callback); +static DEFINE_MUTEX (mixer_oss_notify_mutex); +static int (*mixer_oss_notify_callback)(struct snd_card *card,int cmd); + +void snd_mixer_oss_notify (struct snd_card *card,int cmd) +{ +guard (mutex)(&mixer_oss_notify_mutex); +if (mixer_oss_notify_callback) +mixer_oss_notify_callback (card, cmd); +} +EXPORT_SYMBOL (snd_mixer_oss_notify); + +void snd_mixer_oss_set_notify (int (*callback)(struct snd_card *,int )) +{ +/* Wait for callbacks, including a final module_put(), to return. */ +guard (mutex)(&mixer_oss_notify_mutex); + mixer_oss_notify_callback = callback; +} +EXPORT_SYMBOL (snd_mixer_oss_set_notify);#endif static int check_empty_slot (struct module *module,int slot)
@@ -525,8 +541,7 @@ void snd_card_disconnect(struct snd_card *card)/* at this point, they cannot respond to any calls except release() */ #if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_DISCONNECT ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_DISCONNECT );#endif /* notify all devices that we are disconnected */
@@ -584,8 +599,7 @@ static int snd_card_do_free(struct snd_card *card) card->releasing = true;#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_FREE ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_FREE );#endif snd_device_free_all (card);if (card->private_free)
@@ -923,8 +937,7 @@ int snd_card_register(struct snd_card *card)return err;#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_REGISTER ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_REGISTER );#endif return 0 ; }
sound/core/oss/mixer_oss.c +20 -16
@@ -1306,13 +1306,22 @@ static int snd_mixer_oss_free1(void *private)static int snd_mixer_oss_notify_handler (struct snd_card *card,int cmd) {struct snd_mixer_oss *mixer; +int err;if (cmd ==SND_MIXER_OSS_NOTIFY_REGISTER ) { -int idx, err; +int idx; + +/* Module loading and card registration can both notify us. */ +if (card->mixer_oss) +return 0 ; mixer =kcalloc (2 ,sizeof (*mixer),GFP_KERNEL );if (mixer ==NULL )return -ENOMEM ; +if (!try_module_get (THIS_MODULE )) { +kfree (mixer); +return -ENODEV ; + }mutex_init (&mixer->reg_mutex); err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, card, 0,
@@ -1322,6 +1331,7 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)"unable to register OSS mixer device %i:%i\n" , card->number, 0);kfree (mixer); +module_put (THIS_MODULE );return err; } mixer->oss_dev_alloc =1 ;
@@ -1355,7 +1365,10 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)if (cmd ==SND_MIXER_OSS_NOTIFY_DISCONNECT )return 0 ;snd_mixer_oss_proc_done (mixer); -return snd_mixer_oss_free1 (mixer); + err =snd_mixer_oss_free1 (mixer); +if (!err) +module_put (THIS_MODULE ); +return err; }return 0 ; }
@@ -1364,12 +1377,12 @@ static int __init alsa_mixer_oss_init(void) {struct snd_card *card;int idx; - - snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler; + +snd_mixer_oss_set_notify (snd_mixer_oss_notify_handler);for (idx =0 ; idx <SNDRV_CARDS ; idx++) { card =snd_card_ref (idx);if (card) { -snd_mixer_oss_notify_handler (card,SND_MIXER_OSS_NOTIFY_REGISTER ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_REGISTER );snd_card_unref (card); } }
@@ -1378,17 +1391,8 @@ static int __init alsa_mixer_oss_init(void) static void __exit alsa_mixer_oss_exit(void) { -struct snd_card *card; -int idx; - - snd_mixer_oss_notify_callback =NULL ; -for (idx =0 ; idx <SNDRV_CARDS ; idx++) { - card =snd_card_ref (idx); -if (card) { -snd_mixer_oss_notify_handler (card,SND_MIXER_OSS_NOTIFY_FREE ); -snd_card_unref (card); - } - } +/* Live adapters hold module references and prevent normal unload. */ +snd_mixer_oss_set_notify (NULL ); }module_init (alsa_mixer_oss_init)
sound/core/oss/pcm_oss.c +12 -0
@@ -3144,6 +3144,12 @@ static void register_oss_dsp(struct snd_pcm *pcm, int index)static int snd_pcm_oss_register_minor (struct snd_pcm *pcm) { +if (pcm->oss.registered) +return 0 ; +if (!try_module_get (THIS_MODULE )) +return -ENODEV ; + pcm->oss.registered = true; + pcm->oss.reg =0 ;if (dsp_map[pcm->card->number] == (int )pcm->device) {char name[128 ];
@@ -3198,8 +3204,14 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)static int snd_pcm_oss_unregister_minor (struct snd_pcm *pcm) { +/* BUILD-state and creation-error cleanup need not have registered us. */ +if (!pcm->oss.registered) +return 0 ; +snd_pcm_oss_disconnect_minor (pcm);snd_pcm_oss_proc_done (pcm); + pcm->oss.registered = false; +module_put (THIS_MODULE );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1769/2151 octeontx2-af: Fix CQ enable state tracking after AQ writes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alok Tiwari <[email protected]>
[ Upstream commit 07bd391eb9572e74f073c49acef327611234f9bb ]
Use the CQ context's ena field when updating the CQ enable bitmap. The current code reads rq.ena, which overlaps bit 0 of the CQ base address and can leave the bitmap out of sync with the hardware context. This can cause enabled CQs to be skipped during teardown.
Use sq.ena for the SQ bitmap update as well, so each queue type reads its own context.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +2 -2
@@ -1224,7 +1224,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,__clear_bit (req->qidx, pfvf->rq_bmap); }if (req->ctype ==NIX_AQ_CTYPE_SQ ) { - ena = (req->rq.ena & req->sq_mask.ena) | + ena = (req->sq.ena & req->sq_mask.ena) | (test_bit (req->qidx, pfvf->sq_bmap) & ~req->sq_mask.ena);if (ena)
@@ -1233,7 +1233,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,__clear_bit (req->qidx, pfvf->sq_bmap); }if (req->ctype ==NIX_AQ_CTYPE_CQ ) { - ena = (req->rq.ena & req->cq_mask.ena) | + ena = (req->cq.ena & req->cq_mask.ena) | (test_bit (req->qidx, pfvf->cq_bmap) & ~req->cq_mask.ena);if (ena)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1770/2151 netfilter: nf_conntrack: avoid truncating IPv6 nexthdr offset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 48d522b65fb0ce2bd54f8f5838d77b48afcf1f3e ]
find_prev_fhdr() returns the offset of the Next Header field before an IPv6 Fragment header through an int pointer, but stores the offset in a u8 local. An extension header chain can put this field beyond byte 255, causing the offset to wrap before it is saved in the fragment queue.
Reassembly later uses the wrapped value to update the preceding Next Header field. This overwrites another byte in the IPv6 header chain and can make conntrack parse a different transport tuple from the one used by IPv6 local delivery. A two-fragment packet can, for example, be recorded as UDP destination port 53 while its payload is delivered to UDP port 9999.
Use int for the working offset, matching the output argument and the other offset variables in this path.
--- net/ipv6/netfilter/nf_conntrack_reasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +1 -1
@@ -401,7 +401,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff) {u8 nexthdr =ipv6_hdr (skb)->nexthdr;const int netoff =skb_network_offset (skb); -u8 prev_nhoff = netoff + offsetof(struct ipv6hdr , nexthdr); +int prev_nhoff = netoff + offsetof(struct ipv6hdr , nexthdr);int start = netoff +sizeof (struct ipv6hdr );int len = skb->len - start;u8 prevhdr =NEXTHDR_IPV6 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1771/2151 ipvs: fix more races around the overload flag
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
[ Upstream commit 3ba20137287f4f34ddbf0afb53c5d1ba03b6a8c2 ]
Sashiko warns that we still have races when the dest overload thresholds are updated. If we narrow the range between thresholds the lockless readers (ip_vs_bind_dest and ip_vs_unbind_dest) may use old threshold values and as result to skip the required flag change.
To solve the problem ip_vs_bind_dest() and ip_vs_unbind_dest() will have the chance as before to change the overload state not only at the exact threshold positions but
at any conn count below the lower and above the upper thresholds. To make it work without entering the locked region for every connection, we introduce l_threshold_val. Together with u_threshold_val we will switch between two states:
1. not overloaded: where l_threshold_val is set to 0 to close the door for more ip_vs_unbind_dest() calls to clear the overload state.
2. overloaded: where u_threshold_val is set to INT_MAX to close the door for more ip_vs_bind_dest() calls to set the overload state.
If a race occurs, multiple CPUs can repeat the state change but this should be for short time window.
With the introduction of l_threshold_val the IP_VS_DEST_F_OVERLOAD flag and the 'flags' field are not needed anymore. We will use the ip_vs_dest_is_overloaded() helper for all places that read the overload state.
Do not check IP_VS_DEST_CF_AVAILABLE in ip_vs_dh.c because we do not hold reference to dest after it is removed and rely on RCU to access the available dests.
To reduce the cacheline accesses while selecting destination, keep the mostly used fields (weight and l_threshold_val) at the first read-mostly cacheline together with the hash nodes.
--- include/net/ip_vs.h | 50 ++++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_conn.c | 8 ++--- net/netfilter/ipvs/ip_vs_ctl.c | 38 ++++++++++++------------ net/netfilter/ipvs/ip_vs_dh.c | 16 ++-------- net/netfilter/ipvs/ip_vs_fo.c | 2 +- net/netfilter/ipvs/ip_vs_lblc.c | 4 +-- net/netfilter/ipvs/ip_vs_lblcr.c | 8 ++--- net/netfilter/ipvs/ip_vs_lc.c | 2 +- net/netfilter/ipvs/ip_vs_mh.c | 2 +- net/netfilter/ipvs/ip_vs_nq.c | 2 +- net/netfilter/ipvs/ip_vs_ovf.c | 2 +- net/netfilter/ipvs/ip_vs_rr.c | 2 +- net/netfilter/ipvs/ip_vs_sed.c | 4 +-- net/netfilter/ipvs/ip_vs_sh.c | 2 +- net/netfilter/ipvs/ip_vs_twos.c | 4 +-- net/netfilter/ipvs/ip_vs_wlc.c | 4 +-- net/netfilter/ipvs/ip_vs_wrr.c | 2 +- 17 files changed, 76 insertions(+), 76 deletions(-)
include/net/ip_vs.h +32 -18
@@ -34,9 +34,6 @@#define IP_VS_HDR_INVERSE 1#define IP_VS_HDR_ICMP 2 -/* Destination Server Flags */ -#define IP_VS_DEST_F_OVERLOAD 0x0002/* server is overloaded */ -/* Destination Server Config Flags */ #define IP_VS_DEST_CF_AVAILABLE 0x0001/* server is available */
@@ -722,32 +719,43 @@ struct ip_vs_dest_dst {* and so on. */ struct ip_vs_dest { +/* Cacheline for hash table nodes - read-mostly */ +struct list_head n_list;/* for the dests in the service */ struct hlist_node d_list;/* for table with all the dests */ -u16 af;/* address family */ -__be16 port;/* port number of the server */ -union nf_inet_addr addr;/* IP address of the server */ -volatile unsigned int flags;/* dest status flags */ -atomic_t conn_flags;/* flags to copy to conn */ atomic_t weight;/* server weight */ -unsigned long cflags;/* config flags */ atomic_t last_weight;/* server latest weight */ + +/* connection thresholds */ +u32 l_threshold_val;/* used lower threshold */ +u32 u_threshold_val;/* used upper threshold */ +/* 32/48 */ +u32 l_threshold;/* lower threshold */ +u32 u_threshold;/* upper threshold */ + +unsigned long cflags;/* config flags */ + +/* 44/64 */ +atomic_t conn_flags;/* flags to copy to conn */ +__u16 tun_type;/* tunnel type */ __be16 tun_port;/* tunnel port */ __u16 tun_flags;/* tunnel flags */ -refcount_t refcnt;/* reference counter */ -struct ip_vs_stats stats;/* statistics */ -unsigned long idle_start;/* start time, jiffies */ +u16 af;/* address family */ +__be16 port;/* port number of the server */ +/* 60/80 */ +union nf_inet_addr addr;/* IP address of the server */ -/* connection counters and thresholds */ -atomic_t activeconns;/* active connections */ +/* connection counters */ atomic_t totalconns;/* total connections */ +atomic_t activeconns;/* active connections */ atomic_t persistconns;/* persistent connections */ -__u32 u_threshold;/* upper threshold */ -__u32 l_threshold;/* lower threshold */ -__u32 l_threshold_val;/* used lower threshold */ + +refcount_t refcnt;/* reference counter */ +struct ip_vs_stats stats;/* statistics */ +unsigned long idle_start;/* start time, jiffies */ /* for destination cache */ spinlock_t dst_lock;/* lock of dst_cache */
@@ -1588,7 +1596,13 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)kfree (dest); } -void ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode); +void ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload); + +/* Check if dest is in overloaded state */ +static inline bool ip_vs_dest_is_overloaded (const struct ip_vs_dest *dest) +{ +return READ_ONCE (dest->l_threshold_val); +}/* IPVS sync daemon data and function prototypes * (from ip_vs_sync.c)
net/netfilter/ipvs/ip_vs_conn.c +4 -4
@@ -633,8 +633,8 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)if (!(flags &IP_VS_CONN_F_INACTIVE ))atomic_inc (&dest->activeconns); tc =atomic_inc_return (&dest->totalconns); -if (tc ==READ_ONCE (dest->u_threshold)) -ip_vs_dest_update_overload (dest,1 ); +if (tc >=READ_ONCE (dest->u_threshold_val)) +ip_vs_dest_update_overload (dest, true); }else {/* It is a persistent connection/template, so increase the persistent connection counter */
@@ -726,8 +726,8 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)if (!(cp->flags &IP_VS_CONN_F_INACTIVE ))atomic_dec (&dest->activeconns); tc =atomic_fetch_dec (&dest->totalconns); -if (tc ==READ_ONCE (dest->l_threshold_val)) -ip_vs_dest_update_overload (dest,-1 ); +if (tc <=READ_ONCE (dest->l_threshold_val)) +ip_vs_dest_update_overload (dest, false); }else {/* It is a persistent connection/template, so decrease the persistent connection counter */
net/netfilter/ipvs/ip_vs_ctl.c +18 -20
@@ -965,32 +965,32 @@ void ip_vs_stats_free(struct ip_vs_stats *stats)* - conns reach u_threshold and exceed it: set the flag * - conns go below l_threshold (or 75% of u_threshold): clear the flag */ -static void __ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode) +static void __ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload) {int conns;u32 l, u;lockdep_assert_held (&dest->dst_lock); u =READ_ONCE (dest->u_threshold); -if (!u) - goto unset; - l =READ_ONCE (dest->l_threshold_val); - conns =atomic_read (&dest->totalconns); -if (conns >= (mode >0 ? l : u)) { - dest->flags |=IP_VS_DEST_F_OVERLOAD ; -return ; +if (u) { +/* Low threshold defaults to 75% of upper threshold */ + l =READ_ONCE (dest->l_threshold) ? : (u - (u >>2 )); + conns =atomic_read (&dest->totalconns); +if (conns >= (overload ? l : u)) { +WRITE_ONCE (dest->u_threshold_val,INT_MAX ); +WRITE_ONCE (dest->l_threshold_val, l); +return ; + } } -if (conns >= (mode <0 ? u : l)) -return ; -unset: - dest->flags &= ~IP_VS_DEST_F_OVERLOAD ; +WRITE_ONCE (dest->u_threshold_val, u ? :INT_MAX ); +WRITE_ONCE (dest->l_threshold_val,0 ); } -void ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode) +void ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload) {spin_lock_bh (&dest->dst_lock); -__ip_vs_dest_update_overload (dest, mode); +__ip_vs_dest_update_overload (dest, overload);spin_unlock_bh (&dest->dst_lock); }
@@ -1062,15 +1062,13 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,if (READ_ONCE (dest->u_threshold) != udest->u_threshold ||READ_ONCE (dest->l_threshold) != udest->l_threshold) { +bool overload; +spin_lock_bh (&dest->dst_lock);WRITE_ONCE (dest->u_threshold, udest->u_threshold);WRITE_ONCE (dest->l_threshold, udest->l_threshold); -/* Low threshold defaults to 75% of upper threshold */ -WRITE_ONCE (dest->l_threshold_val, - udest->l_threshold ? : - (udest->u_threshold - - (udest->u_threshold >>2 ))); -__ip_vs_dest_update_overload (dest,0 ); + overload =ip_vs_dest_is_overloaded (dest); +__ip_vs_dest_update_overload (dest, overload);spin_unlock_bh (&dest->dst_lock); }
net/netfilter/ipvs/ip_vs_dh.c +2 -14
@@ -196,16 +196,6 @@ static int ip_vs_dh_dest_changed(struct ip_vs_service *svc, } -/* -* If the dest flags is set with IP_VS_DEST_F_OVERLOAD, -* consider that the server is overloaded here. -*/ -static inline int is_overloaded (struct ip_vs_dest *dest) -{ -return dest->flags &IP_VS_DEST_F_OVERLOAD ; -} - -/* * Destination hashing scheduling */
@@ -220,10 +210,8 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, s = (struct ip_vs_dh_state *) svc->sched_data; dest =ip_vs_dh_get (svc->af, s, &iph->daddr); -if (!dest || - !(dest->cflags &IP_VS_DEST_CF_AVAILABLE ) - ||atomic_read (&dest->weight) <=0 - ||is_overloaded (dest)) { +if (!dest ||atomic_read (&dest->weight) <=0 || +ip_vs_dest_is_overloaded (dest)) {ip_vs_scheduler_err (svc,"no destination available" );return NULL ; }
net/netfilter/ipvs/ip_vs_fo.c +1 -1
@@ -30,7 +30,7 @@ ip_vs_fo_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,* Find virtual server with highest weight and send it traffic */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) > hw) { hweight = dest; hw =atomic_read (&dest->weight);
net/netfilter/ipvs/ip_vs_lblc.c +2 -2
@@ -419,7 +419,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)* new connection. */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ;if (atomic_read (&dest->weight) >0 ) { least = dest;
@@ -434,7 +434,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_lblcr.c +4 -4
@@ -167,7 +167,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)/* select the first destination server, whose weight > 0 */ list_for_each_entry_rcu (e, &set->list, list) { least = e->dest; -if (least->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (least))continue ; if ((atomic_read(&least->weight) > 0) &&
@@ -182,7 +182,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) nextstage:list_for_each_entry_continue_rcu (e, &set->list, list) { dest = e->dest; -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
@@ -581,7 +581,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)* new connection. */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ;if (atomic_read (&dest->weight) >0 ) {
@@ -597,7 +597,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_lc.c +1 -1
@@ -39,7 +39,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) || +if (ip_vs_dest_is_overloaded (dest) ||atomic_read (&dest->weight) ==0 )continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_mh.c +1 -1
@@ -81,7 +81,7 @@ static inline void generate_hash_secret(hsiphash_key_t *hash1,static inline bool is_unavailable (struct ip_vs_dest *dest) {return atomic_read (&dest->weight) <=0 || - dest->flags &IP_VS_DEST_F_OVERLOAD ; +ip_vs_dest_is_overloaded (dest); }/* Returns hash value for IPVS MH entry */
net/netfilter/ipvs/ip_vs_nq.c +1 -1
@@ -73,7 +73,7 @@ ip_vs_nq_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD || +if (ip_vs_dest_is_overloaded (dest) || !atomic_read (&dest->weight))continue ;
net/netfilter/ipvs/ip_vs_ovf.c +1 -1
@@ -34,7 +34,7 @@ ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { w =atomic_read (&dest->weight); -if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) || +if (ip_vs_dest_is_overloaded (dest) ||atomic_read (&dest->activeconns) > w || w ==0 )continue ;
net/netfilter/ipvs/ip_vs_rr.c +1 -1
@@ -67,7 +67,7 @@ ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out;
net/netfilter/ipvs/ip_vs_sed.c +2 -2
@@ -76,7 +76,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 ) { least = dest; loh =ip_vs_sed_dest_overhead (least);
@@ -91,7 +91,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_sed_dest_overhead (dest); if ((__s64)loh * atomic_read(&dest->weight) >
net/netfilter/ipvs/ip_vs_sh.c +1 -1
@@ -74,7 +74,7 @@ struct ip_vs_sh_state {static inline bool is_unavailable (struct ip_vs_dest *dest) {return atomic_read (&dest->weight) <=0 || - dest->flags &IP_VS_DEST_F_OVERLOAD ; +ip_vs_dest_is_overloaded (dest); }/*
net/netfilter/ipvs/ip_vs_twos.c +2 -2
@@ -53,7 +53,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc,/* Generate a random weight between [0,sum of all weights) */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD )) { +if (!ip_vs_dest_is_overloaded (dest)) { weight =atomic_read (&dest->weight);if (weight >0 ) { total_weight += weight;
@@ -76,7 +76,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc,/* Pick two weighted servers */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; weight =atomic_read (&dest->weight);
net/netfilter/ipvs/ip_vs_wlc.c +2 -2
@@ -48,7 +48,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 ) { least = dest; loh =ip_vs_dest_conn_overhead (least);
@@ -63,7 +63,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest); if ((__s64)loh * atomic_read(&dest->weight) >
net/netfilter/ipvs/ip_vs_wrr.c +1 -1
@@ -177,7 +177,7 @@ ip_vs_wrr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >= mark->cw) goto found;if (dest == stop)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1772/2151 netfilter: flowtable: use the vlan id, not the full tci, in the tuple key
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangfeng He <[email protected]>
[ Upstream commit c203ecf905745d979de5df28fa657121f2e9342d ]
nf_flow_tuple_encap() stores the skb vlan tag in the encap tuple id using skb_vlan_tag_get(), which returns the unmasked TCI including the 3 PCP priority bits. The flowtable entry, however, is programmed by nf_dev_path_info() with vlan_dev_vlan_id(), a plain 12-bit VID.
When a NIC delivers RX vlan offload skbs with a non-zero priority (an RTL9617C EPON ONU was observed handing over vid 818 skbs with tci 0x6332, PCP 3), the runtime lookup key never matches the programmed entry, so every packet misses the flow table and software flow offload is silently defeated.
Mask both parse sites to the 12-bit VID so the lookup key matches for any priority. The in-header variant has the same problem for frames received with PCP != 0 on a non-offload path.
The egress side is unaffected: nf_flow_encap_push() restores tags from the programmed tuple id, which never carried priority bits.
Measured on an RTL9617C ONU (PPPoE over VLAN 818 WAN, NATed 6-flow download over a 1G EPON line), before -> after:
download throughput 377 Mbps -> 936 Mbps
CPU0 %soft at that rate 91.5% -> 70.9%
--- net/netfilter/nf_flow_table_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -150,14 +150,14 @@ static void nf_flow_tuple_encap(struct sk_buff *skb,int i =0 ;if (skb_vlan_tag_present (skb)) { - tuple->encap[i].id =skb_vlan_tag_get (skb); + tuple->encap[i].id =skb_vlan_tag_get_id (skb); tuple->encap[i].proto = skb->vlan_proto; i++; }switch (skb->protocol) {case htons (ETH_P_8021Q ): veth = (struct vlan_ethhdr *)skb_mac_header (skb); - tuple->encap[i].id =ntohs (veth->h_vlan_TCI); + tuple->encap[i].id =ntohs (veth->h_vlan_TCI) &VLAN_VID_MASK ; tuple->encap[i].proto = skb->protocol;break ;case htons (ETH_P_PPP_SES ):
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1773/2151 netfilter: nft_set_rbtree: narrow down range completion to anonymous sets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 86d47d4c84a1b8470ba3fc16df13ea2a220b74ff ]
For anonymous sets, when adjacent ranges are found, the end element is not added to the set to pack the set representation. Use next start element to complete this interval.
Jérémy Jean says:
Consider two ranges in a netfilter verdict map:
* keys 10-19 accept packets, and
* keys 30-39 jump to chain 'victim'.
Now, delete the end marker at 20. The lookup array now uses element 30 as the first range's end, so an INTERVAL_END query for key 15 returns element 30, including its jump verdict and chain pointer. This can make KASAN reports a UAF after the GC releases reference chain for 30 that has expired:
BUG: KASAN: slab-use-after-free in nft_verdict_dump+0xdd/0x110 Read of size 8 at addr ff110000009dfb58 by task repro/50 ... Call Trace: ... nft_verdict_dump+0xdd/0x110 nft_data_dump+0x4d/0x80 nf_tables_fill_setelem+0x30b/0x8a0 ? __asan_memcpy+0x3c/0x60 nf_tables_fill_setelem_info+0x1b0/0x200 nft_get_set_elem+0x3fd/0x4b0 ... Freed by task 24: ... kfree+0x1a5/0x280 nf_tables_trans_destroy_work+0x2cb/0x520
--- net/netfilter/nft_set_rbtree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_set_rbtree.c +2 -1
@@ -1096,7 +1096,8 @@ static void nft_rbtree_commit(struct nft_set *set)* representation. Use next start element to complete this * interval. */ -if (nft_rbtree_interval_start (rbe) && +if (nft_set_is_anonymous (set) && +nft_rbtree_interval_start (rbe) &&nft_rbtree_interval_start (prev_rbe) && priv->array_next->intervals[num_intervals].from) priv->array_next->intervals[num_intervals++].to = &prev_rbe->ext;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1774/2151 netfilter: xt_dccp: handle reserved options as single-byte
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sung Byeongchan <[email protected]>
[ Upstream commit 2edda78aa4eb04cd8f112a81897510ee0cdd7099 ]
The DCCP UAPI defines option numbers 3 through 31 as reserved. Like Padding and Mandatory, these options occupy one byte. dccp_find_option() only treats values below 2 as single-byte and interprets the byte after a reserved option as a TLV length.
This can skip a later option and invert an XT_DCCP_OPTION rule result. A local production-hook fixture installed the same DROP rule for IPv4 and IPv6. In three fresh boots per kernel, a target-only packet was dropped 20/20 times, while adding reserved option 3 before the same target let 20/20 packets reach the protected receiver. The fixed kernel dropped all trigger packets in three fresh boots and preserved the normal controls.
Treat every option up to DCCPO_MAX_RESERVED as single-byte, matching the protocol definition. Triggering requires CONFIG_NETFILTER_XTABLES_LEGACY, CONFIG_NETFILTER_XT_MATCH_DCCP, an option-based rule, and remote protocol-33 reachability. The touched source is unchanged at 0c2669a9f4a1d607e7591ae50ccf3c432a0aff08, where the patch applies and builds cleanly.
--- net/netfilter/xt_dccp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_dccp.c +1 -1
@@ -62,7 +62,7 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 || i == optlen -1 ) +if (op[i] <=DCCPO_MAX_RESERVED || i == optlen -1 ) i++;else i += op[i +1 ] ? :1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1775/2151 tools/power turbostat: pmt: Improve sscanf() hygiene
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Len Brown <[email protected]>
[ Upstream commit e817a533bbc0aef5a9cb6255153941ed968d2fb1 ]
Explicitly check sscanf() return values for number of matches, and handle EOF (-1).
Defensive programming -- not an issue actively seen by users.
--- tools/power/x86/turbostat/turbostat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/power/x86/turbostat/turbostat.c +5 -3
@@ -1880,15 +1880,17 @@ int pmt_telemdir_filter(const struct dirent *e) {unsigned int dummy; -return sscanf (e->d_name,"telem%u" , &dummy); +return (sscanf (e->d_name,"telem%u" , &dummy) ==1 ); }int pmt_telemdir_sort (const struct dirent **a,const struct dirent **b) {unsigned int aidx =0 , bidx =0 ; -sscanf ((*a)->d_name,"telem%u" , &aidx); -sscanf ((*b)->d_name,"telem%u" , &bidx); +if (sscanf ((*a)->d_name,"telem%u" , &aidx) !=1 ) + aidx =0 ; +if (sscanf ((*b)->d_name,"telem%u" , &bidx) !=1 ) + bidx =0 ;return (aidx > bidx) ?1 : (aidx < bidx) ?-1 :0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1776/2151 nios2: ksyms: Declare __mulsi3 export
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 2180d11e06fb56fd13643ae59964f144896870be ]
GCC may emit libcalls to __mulsi3(). As modpost is not aware that this function is provided through the linked in libgcc, it fails:
ERROR: modpost: kernel/locking/test-ww_mutex.ko: symbol '__mulsi3' undefined!
ERROR: modpost: kernel/time/test_udelay.ko: symbol '__mulsi3' undefined!
ERROR: modpost: kernel/resource_kunit.ko: symbol '__mulsi3' undefined!
ERROR: modpost: fs/fuse/virtiofs.ko: symbol '__mulsi3' undefined! etc.
Make sure modpost can see the symbol from libgcc.
--- arch/nios2/kernel/nios2_ksyms.c | 1 + 1 file changed, 1 insertion(+)
arch/nios2/kernel/nios2_ksyms.c +1 -0
@@ -39,6 +39,7 @@ DECLARE_EXPORT(__udivsi3);DECLARE_EXPORT (__umoddi3);DECLARE_EXPORT (__umodsi3);DECLARE_EXPORT (__muldi3); +DECLARE_EXPORT (__mulsi3);DECLARE_EXPORT (__ucmpdi2);DECLARE_EXPORT (__lshrdi3);DECLARE_EXPORT (__ashldi3);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1777/2151 ALSA: pcmtest: Pin the module while pattern files are open
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 069003afab42b5a9394faa6985a3d76bd4700e72 ]
The fill_pattern_fops table must remain alive until the final release of each pattern debugfs file. It has no .owner, so the fops_get() call in full_proxy_open_regular() does not take a PCMTest module reference.
With snd-pcmtest loaded as a module, a user with permission to open a fill_patternN file and unload the module can retain the descriptor across normal unload, provided no PCM file or other module reference prevents it. The following ordering is possible:
Pattern file user Module unload
----------------- -------------
open(fill_patternN)
full_proxy_open_regular()
fops_get(fill_pattern_fops)
owner == NULL: no module pin
keep the descriptor open
mod_exit()
clear_debug_files()
debugfs_remove_recursive()
drain active operations
return from mod_exit()
free_module()
free the module image
close(fd)
full_proxy_release()
read real_fops->release -> UAF
fops_put(real_fops)
read real_fops->owner
access freed module memoryEven though the table has no release callback, reading those fields is a use-after-free and can fault. The retained dentry keeps the proxy's bookkeeping alive, but does not retain the module storage.
Set .owner to THIS_MODULE so the existing fops_get()/fops_put() pair pins PCMTest until final release has finished accessing the table. Normal module unload is then blocked while any pattern file is open.
--- sound/drivers/pcmtest.c | 1 + 1 file changed, 1 insertion(+)
sound/drivers/pcmtest.c +1 -0
@@ -684,6 +684,7 @@ static ssize_t pattern_read(struct file *file, char __user *u_buff, size_t len, }static const struct file_operations fill_pattern_fops = { + .owner =THIS_MODULE , .read = pattern_read, .write = pattern_write, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1778/2151 ALSA: pcm: Remove channel-map controls before freeing substreams
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit d5dd05c1f72a95d8ab06828d7272a185ad2b9185 ]
A late HDA codec bind on an already registered card builds new PCMs before registering them. add_std_chmaps() publishes generic channel-map controls during this BUILD stage. If an earlier chmap succeeds and a later allocation fails, probe cleanup frees the BUILD PCM while the card's control device remains accessible.
These generic controls are added directly by snd_pcm_add_chmap_ctls(); snd_hda_ctls_clear() only removes codec-tracked mixer controls. BUILD devices also skip dev_disconnect. snd_pcm_free_stream() then frees the substreams before free_chmap() withdraws their generic control:
Late HDA codec bind / rollback Control GET on the live card
------------------------------ ----------------------------
hda_codec_driver_probe()
snd_hda_codec_build_pcms()
PCM is BUILD
snd_hda_codec_build_controls()
add_std_chmaps()
publish an earlier chmap
later allocation: -ENOMEM
snd_hda_codec_cleanup_for_unbind()
snd_hda_ctls_clear()
generic chmap remains
codec_release_pcms()
snd_device_free()
BUILD: skip dev_disconnect snd_pcm_free_stream()
kfree(substream)
snd_ctl_elem_read()
down_read(controls_rwsem) pcm_chmap_ctl_get()
walk freed substream
free_chmap()
snd_ctl_remove()
wait for GET
up_read(controls_rwsem)
The control read lock cannot protect a substream already freed before control removal starts. The failure above occurs before snd_card_register(), so the PCM has not transitioned out of BUILD.
Move free_chmap() before the substream free loop. Its snd_ctl_remove() withdraws the control and drains readers under controls_rwsem before any substream is released. Normal registered-device disconnect already removes the control, so the later call remains harmless on that path.
--- sound/core/pcm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/core/pcm.c +3 -1
@@ -821,6 +821,9 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr)/* free all proc files under the stream */ snd_pcm_stream_proc_done (pstr); +/* Drain channel-map callbacks before freeing the substreams. */ +free_chmap (pstr); + substream = pstr->substream;while (substream) { substream_next = substream->next;
@@ -835,7 +838,6 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr) kfree(setup); }#endif -free_chmap (pstr);if (pstr->substream_count)put_device (pstr->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1779/2151 ALSA: jack: Pin the module while debugfs files are open
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8b479b265301e97bfbec0ef25de1c1f7eb4d2f74 ]
With CONFIG_SND=m and CONFIG_SND_JACK_INJECTION_DEBUG enabled, an in-tree HDA jack creates these debugfs files through snd_jack_new() and snd_jack_add_debugfs(). Their file_operations live in snd, but none sets .owner. full_proxy_open_regular() therefore takes no snd module reference when it calls fops_get(real_fops).
A debugfs descriptor can outlive removal of its HDA card. Once the card and dependent modules, including the OSS emulation modules, have been removed, snd can be unloaded while that descriptor is still open:
Descriptor holder Card/module teardown
----------------- --------------------
open jack debugfs file
full_proxy_open_regular()
fops_get(real_fops)
owner == NULL: no snd pin
keep descriptor open
remove HDA card
snd_card_disconnect()
snd_jack_dev_disconnect()
remove debugfs nodes
snd_jack_dev_free()
unload dependent modules
rmmod snd
alsa_sound_exit()
free_module(): unmap snd
close descriptor
full_proxy_release()
read real_fops->release
fops_put(real_fops)
read real_fops->ownerdebugfs_remove() drains active operations, but does not wait for idle open descriptors. Release deliberately bypasses removal protection and reads the real table even when no release callback is installed. The last close can therefore access unloaded snd storage.
Set .owner to THIS_MODULE in all six tables. The existing proxy fops_get()/fops_put() pair then keeps snd loaded through the final table access on close.
--- sound/core/jack.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/core/jack.c +6 -0
@@ -309,6 +309,7 @@ static ssize_t jack_type_read(struct file *file, }static const struct file_operations jack_type_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_type_read, .llseek = default_llseek,
@@ -316,6 +317,7 @@ static const struct file_operations jack_type_fops = {#endif static const struct file_operations sw_inject_enable_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = sw_inject_enable_read, .write = sw_inject_enable_write,
@@ -323,24 +325,28 @@ static const struct file_operations sw_inject_enable_fops = { };static const struct file_operations jackin_inject_fops = { + .owner =THIS_MODULE , .open = simple_open, .write = jackin_inject_write, .llseek = default_llseek, };static const struct file_operations jack_kctl_id_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_kctl_id_read, .llseek = default_llseek, };static const struct file_operations jack_kctl_mask_bits_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_kctl_mask_bits_read, .llseek = default_llseek, };static const struct file_operations jack_kctl_status_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_kctl_status_read, .llseek = default_llseek,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1780/2151 ALSA: pcm: Protect channel-map reads against runtime detach
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit bb4834d5242c4829c0d8467ee68eb25a9bafc38d ]
Channel-map controls remain accessible between PCM opens. In-tree HDA code publishes the generic controls through add_std_chmaps(), so a SNDRV_CTL_IOCTL_ELEM_READ can overlap the final close of the same PCM substream.
pcm_chmap_ctl_get() checks substream->runtime and later reads its channel count. Final close clears and frees that runtime under pcm->open_mutex, while the control callback holds only controls_rwsem:
Control GET Final PCM close
----------- ---------------
snd_ctl_elem_read()
down_read(controls_rwsem)
pcm_chmap_ctl_get()
check substream->runtime
lock(pcm->open_mutex)
snd_pcm_release_substream()
snd_pcm_detach_substream()
substream->runtime = NULL
kfree(runtime)
unlock(pcm->open_mutex)
substream->runtime->channels
NULL or freed-pointer access
up_read(controls_rwsem)Reloading the cleared field can fault through NULL, while retaining the old pointer can access freed storage. controls_rwsem keeps the control alive, but does not serialize the matching PCM close.
Copy the channel count under open_mutex and use that scalar for the map lookup. Use trylock with -EBUSY because snd_pcm_dev_disconnect() takes open_mutex before removing controls under controls_rwsem; blocking in the reverse order from GET could deadlock.
--- sound/core/pcm_lib.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
sound/core/pcm_lib.c +13 -3
@@ -2496,6 +2496,7 @@ static int pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol,unsigned int idx =snd_ctl_get_ioffidx (kcontrol, &ucontrol->id);struct snd_pcm_substream *substream;const struct snd_pcm_chmap_elem *map; +unsigned int channels;if (!info->chmap)return -EINVAL ;
@@ -2504,11 +2505,20 @@ static int pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol,return -ENODEV ;memset (ucontrol->value.integer.value,0 ,sizeof (long ) * info->max_channels); -if (!substream->runtime) -return 0 ;/* no channels set */ +/* +* PCM disconnect takes open_mutex before removing controls. +* Use trylock to avoid a deadlock with controls_rwsem. +*/ +scoped_cond_guard (mutex_try, return -EBUSY , + &info->pcm->open_mutex) { +if (!substream->runtime) +return 0 ;/* no channels set */ + channels = substream->runtime->channels; + }for (map = info->chmap; map->channels; map++) {int i; -if (map->channels == substream->runtime->channels && + +if (map->channels == channels &&valid_chmap_channels (info, map->channels)) {for (i =0 ; i < map->channels; i++) ucontrol->value.integer.value[i] = map->map[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1781/2151 nfsv4/pnfs: use the MDS authflavor for data server connections
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tigran Mkrtchyan <[email protected]>
[ Upstream commit 4b27670ea25b955b710021151471cb252240b1e0 ]
When a pNFS client connects to an NFSv4.1 data server, the EXCHANGE_ID is always attempted with RPCSEC_GSS krb5i first, even if the auth flavor with the MDS is AUTH_SYS. On a host that runs rpc.gssd but has no usable machine credential, every first contact with a data server therefore upcalls to rpc.gssd before falling back to AUTH_SYS.
As nfs4_discover_server_trunking is serialized by nfs_clid_init_mutex such an extra upcall creates a backlog of DS connections when many files accessed in parallel.
Pass the authflavor of the MDS lease to nfs4_alloc_client() and skip the krb5i attempt if the MDS already ended up with AUTH_SYS. Nothing changes for the MDS itself, or for data servers of an MDS whose lease was established with krb5i.
--- fs/nfs/internal.h | 1 + fs/nfs/nfs4client.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
fs/nfs/internal.h +1 -0
@@ -86,6 +86,7 @@ struct nfs_client_initdata {struct xprtsec_parms xprtsec;unsigned long connect_timeout;unsigned long reconnect_timeout; +rpc_authflavor_t authflavor;/* Auth flavor to use for DS connection */ };/*
fs/nfs/nfs4client.c +6 -1
@@ -240,8 +240,12 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init)/* * Set up the connection to the server before we add add to the * global list. +* +* Prefer krb5i unless the caller already knows AUTH_UNIX is required. */ - err =nfs_create_rpc_client (clp, cl_init,RPC_AUTH_GSS_KRB5I ); + err = -EINVAL ; +if (cl_init->authflavor !=RPC_AUTH_UNIX ) + err =nfs_create_rpc_client (clp, cl_init,RPC_AUTH_GSS_KRB5I );if (err == -EINVAL ) err =nfs_create_rpc_client (clp, cl_init,RPC_AUTH_UNIX );if (err <0 )
@@ -990,6 +994,7 @@ struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv, .cert_serial = TLS_NO_CERT, .privkey_serial = TLS_NO_PRIVKEY, }, + .authflavor = mds_clp->cl_rpcclient->cl_auth->au_flavor, };char buf[INET6_ADDRSTRLEN +1 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1782/2151 pNFS/flexfiles: make pg_init retry loops killable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tigran Mkrtchyan <[email protected]>
[ Upstream commit fde27289503beabe7e0856dac164a5ced4be0342 ]
When a task is killed while the pNFS client connects to a data server, nfs4_pnfs_ds_connect() fails with -ERESTARTSYS. If the layout has FF_FLAGS_NO_IO_THRU_MDS set, ff_layout_pg_init_read() cannot fall back to the MDS and retries after an uninterruptible ssleep. As the fatal signal stays pending, every new connect attempt is aborted the same way and the task loops forever without returning to user space:
# grep -E 'SigPnd|ShdPnd' /proc/156021/status SigPnd: 0000000000000100 ShdPnd: 0000000000000100
# cat /proc/156021/stack msleep+0x2e/0x50 ff_layout_pg_init_read+0x267/0x310 [nfs_layout_flexfiles] __nfs_pageio_add_request+0x1c1/0x480 [nfs] nfs_pageio_add_request+0x21d/0x2c0 [nfs] nfs_read_add_folio+0x143/0x200 [nfs] nfs_readahead+0x204/0x290 [nfs] read_pages+0x62/0x230 page_cache_ra_unbounded+0x136/0x180 filemap_get_pages+0xf2/0x350 filemap_read+0xd5/0x320 nfs_file_read+0x6d/0xc0 [nfs] vfs_read+0x24f/0x3a0 __x64_sys_pread64+0x90/0xc0 do_syscall_64+0x5f/0xe0
Previous attempt propagates the error from nfs4_ff_layout_prepare_ds(), but only ff_layout_{read,write}_pagelist() look at it. The pg_init functions test IS_ERR() and retry on any error.
Check for a fatal signal or an exiting task before sleeping in ff_layout_pg_init_read() and ff_layout_pg_init_write() and fail the I/O instead of retrying.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +20 -3
@@ -966,6 +966,20 @@ ff_layout_get_ds_for_read(struct nfs_pageio_descriptor *pgio, offset, dss_id); } +/* +* Wait before retrying pg_init. Returns false, with pgio->pg_error set, +* if the task was killed or is exiting and must not retry. +*/ +static bool ff_layout_pg_retry_wait (struct nfs_pageio_descriptor *pgio) +{ +if (fatal_signal_pending (current) ||nfs_current_task_exiting ()) { + pgio->pg_error = -ERESTARTSYS ; +return false; + } +ssleep (1 ); +return true; +} + static void ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req,
@@ -1066,7 +1080,8 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, goto out_mds;pnfs_generic_pg_cleanup (pgio);/* Sleep for 1 second before retrying */ -ssleep (1 ); +if (!ff_layout_pg_retry_wait (pgio)) +return ; goto retry; }
@@ -1105,7 +1120,8 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, } pgio->pg_error =0 ;/* Sleep for 1 second before retrying */ -ssleep (1 ); +if (!ff_layout_pg_retry_wait (pgio)) +return ; goto retry; out_mds: trace_pnfs_mds_fallback_pg_init_read(pgio->pg_inode,
@@ -1159,7 +1175,8 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, goto out_mds;pnfs_generic_pg_cleanup (pgio);/* Sleep for 1 second before retrying */ -ssleep (1 ); +if (!ff_layout_pg_retry_wait (pgio)) +return ; goto retry; } pgm = &pgio->pg_mirrors[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1783/2151 nfs/localio: pin UUIDs during global invalidation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinpyo Lee <[email protected]>
[ Upstream commit 62e14699c4dfc98c514a44bf780678cf8622fc08 ]
nfs_localio_invalidate_clients() moves UUID nodes embedded in nfs_client objects to a private list, then walks that list without retaining the containing clients. Concurrent client teardown can free an entry that the iterator has already selected, causing a use-after-free.
Take a reference to each selected UUID under the namespace list lock. Keep this reference count in nfs_common, independently of cl_count, and have nfs_free_client() drain temporary UUID users before freeing the client. Releasing a UUID reference wakes waiting probes and signals completion when the last reference is dropped. It neither calls into nfs.ko nor performs final NFS client teardown in the NFSD invalidation context.
Keep the UUID on the namespace list until its files have been closed. When another thread is already disabling it, wait for that thread to finish unlinking it instead of repeatedly selecting the same head entry. The wait releases the UUID spinlock so file cleanup can make progress.
Append registrations in sequence order and capture the last sequence under the namespace list lock at the start of invalidation. Stop at that boundary so new registrations cannot indefinitely extend the sweep, even if its original last entry is removed concurrently.
Publish the LOCALIO association under the UUID and namespace list locks before making the entry visible to invalidation. A temporary UUID reference allows the handshake to drop the global lookup lock before taking the UUID lock in the documented order; recheck the lookup in case the probe was withdrawn. A new probe waits for temporary UUID users to drain, then rechecks the association before reusing the UUID. This keeps a transient invalidation reference from discarding the client's LOCALIO revalidation attempt. Withdraw pending probes before dropping the owner's UUID reference.
A deterministic same-base KASAN reproducer triggered the reported use-after-free on the unpatched tree. With this patch, the same controlled invalidation and teardown race completed without the target KASAN report or another selected kernel diagnostic. A separate all-live run recorded disable events for all 16 unique clients.
Test-only synchronization hooks verified that a second disabler waits for unlink after ->net is cleared and that client teardown waits for a temporary UUID reference to drain. NFSv4.2 and NFSv3 read, write, and unmount smoke tests, export-flush and I/O stress, NFSD restarts, network namespace lifecycle tests, and module unloads passed with KASAN and lockdep enabled.
A full x86_64 kernel and modules build with GCC 13.3, CONFIG_WERROR=y, NFS_FS=m, NFSD=m, and LOCALIO enabled completed without diagnostics. Module metadata showed that nfs_localio.ko depends only on sunrpc, while nfs.ko depends on lockd, nfs_localio, and sunrpc.
A separate NFS_FS=m, NFSD=y build also linked vmlinux successfully.
The vulnerability research and validation were conducted by members of the Tobabz team as part of the Best of the Best 15th program.
--- fs/nfs/client.c | 2 +- fs/nfs_common/nfslocalio.c | 101 +++++++++++++++++++++++++++++++------ include/linux/nfslocalio.h | 12 +++++ 3 files changed, 98 insertions(+), 17 deletions(-)
fs/nfs/client.c +1 -1
@@ -256,7 +256,7 @@ static void pnfs_init_server(struct nfs_server *server)*/ void nfs_free_client (struct nfs_client *clp) { -nfs_localio_disable_client (clp); +nfs_localio_free_client (clp);/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))
fs/nfs_common/nfslocalio.c +85 -16
173 lines not on this page · raw message
include/linux/nfslocalio.h +12 -0
@@ -8,8 +8,10 @@#if IS_ENABLED (CONFIG_NFS_LOCALIO ) +#include <linux/completion.h> #include <linux/module.h> #include <linux/list.h> +#include <linux/refcount.h> #include <linux/uuid.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svcauth.h>
@@ -28,6 +30,11 @@ struct nfs_file_localio; typedef struct { uuid_t uuid; unsigned nfs3_localio_probe_count; + /* Owner reference plus temporary references held by nfs_common */ + refcount_t refs; + struct completion released; + /* Namespace registration order, protected by list_lock */ + u64 seq; /* this struct is over a cacheline, avoid bouncing */ spinlock_t ____cacheline_aligned lock; struct list_head list;
@@ -46,6 +53,7 @@ void nfs_uuid_is_local(const uuid_t *, struct list_head *, spinlock_t *,void nfs_localio_enable_client (struct nfs_client *clp);void nfs_localio_disable_client (struct nfs_client *clp); +void nfs_localio_free_client (struct nfs_client *clp);void nfs_localio_invalidate_clients (struct list_head *nn_local_clients,spinlock_t *nn_local_clients_lock);
@@ -118,6 +126,10 @@ static inline void nfs_localio_disable_client(struct nfs_client *clp) { } +static inline void nfs_localio_free_client (struct nfs_client *clp) +{ +} +#endif /* CONFIG_NFS_LOCALIO */ #endif /* __LINUX_NFSLOCALIO_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1784/2151 PCI: rcar-gen4: Add missing PM ops
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
[ Upstream commit 6b8c12d354dfa9c80d82eea8c0c45d331a28be11 ]
The R-Car Gen4 PCIe controller is part of a power domain. On R-Car S4 and V4H, this is an always-on power domain which is not shut down in suspend. On R-Car V4M, this is a dedicated A2PCIPHY power domain, which is shut down during suspend, and the controller loses state, which prevents the PCIe from working after resume.
Fix this by adding generic suspend/resume noirq ops for the controller, which tear the link down on suspend, and restart it on resume. Use the same PM ops on all of R-Car Gen4 to gracefully suspend and resume the PCIe link on V4H and S4 too.
Test case which demonstrates the problem on R-Car V4M:
$ hexdump -vC /sys/bus/pci/devices/0000:00:00.0/config > /tmp/pre
$ echo s2idle > /sys/power/mem_sleep
$ echo platform > /sys/power/pm_test
$ echo mem > /sys/power/state
$ hexdump -vC /sys/bus/pci/devices/0000:00:00.0/config > /tmp/post
$ diff -Naru /tmp/pre /tmp/post
...
-00000000 12 19 32 00 07 05 10 00 00 00 04 06 00 00 01 00
+00000000 12 19 32 00 07 05 10 00 00 00 00 ff 00 00 80 00
^^^^^
Class 0604->00ff--- drivers/pci/controller/dwc/pcie-rcar-gen4.c | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/pci/controller/dwc/pcie-rcar-gen4.c +27 -0
@@ -416,6 +416,8 @@ static int rcar_gen4_add_dw_pcie_rp(struct rcar_gen4_pcie *rcar)return -ENODEV ; pp->num_vectors =MAX_MSI_IRQS ; +/* Reserve an iATU window for the generic PME_Turn_Off implementation. */ + pp->use_atu_msg = true; pp->ops = &rcar_gen4_pcie_host_ops;return dw_pcie_host_init (pp);
@@ -800,6 +802,26 @@ static int rcar_gen4_pcie_ltssm_control(struct rcar_gen4_pcie *rcar, bool enablereturn 0 ; } +static int rcar_gen4_pcie_suspend_noirq (struct device *dev) +{ +struct rcar_gen4_pcie *rcar =dev_get_drvdata (dev); + +if (rcar->drvdata->mode !=DW_PCIE_RC_TYPE ) +return 0 ; + +return dw_pcie_suspend_noirq (&rcar->dw); +} + +static int rcar_gen4_pcie_resume_noirq (struct device *dev) +{ +struct rcar_gen4_pcie *rcar =dev_get_drvdata (dev); + +if (rcar->drvdata->mode !=DW_PCIE_RC_TYPE ) +return 0 ; + +return dw_pcie_resume_noirq (&rcar->dw); +} +static struct rcar_gen4_pcie_drvdata drvdata_r8a779f0_pcie = { .ltssm_control = r8a779f0_pcie_ltssm_control, .mode =DW_PCIE_RC_TYPE ,
@@ -843,10 +865,15 @@ static const struct of_device_id rcar_gen4_pcie_of_match[] = { };MODULE_DEVICE_TABLE (of, rcar_gen4_pcie_of_match); +static DEFINE_NOIRQ_DEV_PM_OPS(rcar_gen4_pcie_pm_ops, + rcar_gen4_pcie_suspend_noirq, + rcar_gen4_pcie_resume_noirq); +static struct platform_driver rcar_gen4_pcie_driver = { .driver = { .name ="pcie-rcar-gen4" , .of_match_table = rcar_gen4_pcie_of_match, + .pm =pm_sleep_ptr (&rcar_gen4_pcie_pm_ops), .probe_type =PROBE_PREFER_ASYNCHRONOUS , }, .probe = rcar_gen4_pcie_probe,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1785/2151 ALSA: aloop: Use the new helper for stop-count refcount
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit c54888c1171e6a03b8325e03011cedc0a9781161 ]
Replace the open-code for managing the stop-count refcount with the new helpers.
Only a code cleanup, no functional changes.
Stable-dep-of: a7d4d780f34b ("ALSA: aloop: Keep shared timer callbacks alive through close")
--- sound/drivers/aloop.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
sound/drivers/aloop.c +5 -8
@@ -100,8 +100,7 @@ struct loopback_cable {spinlock_t lock;struct loopback_pcm *streams[2 ];/* in-flight peer stops running outside cable->lock */ -atomic_t stop_count; -wait_queue_head_t stop_wait; +struct snd_refcount stop_count;struct snd_pcm_hardware hw;/* flags */ unsigned int valid;
@@ -374,7 +373,7 @@ static int loopback_check_format(struct loopback_cable *cable, int stream)return -EIO ; else if (check && cruntime->state == SNDRV_PCM_STATE_RUNNING) {/* close must not free the peer runtime below */ -atomic_inc (&cable->stop_count); +snd_refcount_get (&cable->stop_count); stop_capture = true; } }
@@ -407,8 +406,7 @@ static int loopback_check_format(struct loopback_cable *cable, int stream)if (stop_capture) {snd_pcm_stop (dpcm_capt->substream,SNDRV_PCM_STATE_DRAINING ); -if (atomic_dec_and_test (&cable->stop_count)) -wake_up (&cable->stop_wait); +snd_refcount_put (&cable->stop_count); }return 0 ;
@@ -1093,7 +1091,7 @@ static void free_cable(struct snd_pcm_substream *substream) }/* Pair with the stop_count increment in loopback_check_format(). */ -wait_event (cable->stop_wait, !atomic_read (&cable->stop_count)); +snd_refcount_sync (&cable->stop_count);if (other_alive)return ;
@@ -1297,8 +1295,7 @@ static int loopback_open(struct snd_pcm_substream *substream) goto unlock; }spin_lock_init (&cable->lock); -atomic_set (&cable->stop_count,0 ); -init_waitqueue_head (&cable->stop_wait); +snd_refcount_init (&cable->stop_count); cable->hw = loopback_pcm_hardware;if (loopback->timer_source) cable->ops = &loopback_snd_timer_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1786/2151 ALSA: aloop: Keep shared timer callbacks alive through close
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit a7d4d780f34b9e43eefab6a7e6c9f4101f2c144e ]
The shared sound-timer callback must finish using the selected PCM runtimes before a close can detach them. loopback_snd_timer_period_elapsed() saves the active substreams under cable->lock, then drops the lock before calling snd_pcm_period_elapsed() or snd_pcm_stop_xrun(). The sound-timer backend has no per-stream close drain, and free_cable() keeps the timer open when the paired endpoint remains attached.
With both directions running on a shared sound timer, playback can be dropped and closed while a notification is pending. Capture keeps the timer alive, allowing this order:
Timer callback Playback owner
-------------- --------------
select playback under cable->lock
unlock; delay notification
DROP; HW_FREE -> OPEN
close: snd_pcm_drop(); unlock
free_cable(); peer stays alive snd_pcm_period_elapsed()
lock stream; cache runtime
snd_pcm_detach_substream()
free runtime and its fasync
read runtime->fasync
The stream lock taken by snd_pcm_drop() cannot protect a notification that starts after it returns, and detach does not take it. The callback can therefore read runtime->fasync after the runtime has been freed, and an escaped notification can also reach a replacement runtime if the same substream slot is reopened before the notification resumes.
Take the existing cable->stop_count reference under cable->lock when selecting the targets and release it after the PCM callbacks finish, including the XRUN path. free_cable() already removes the closing endpoint under that lock and waits for stop_count before returning, so runtime detach and slot reuse cannot overtake the notification.
--- sound/drivers/aloop.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/drivers/aloop.c +8 -3
@@ -99,7 +99,7 @@ struct loopback_ops {struct loopback_cable {spinlock_t lock;struct loopback_pcm *streams[2 ]; -/* in-flight peer stops running outside cable->lock */ +/* in-flight PCM callbacks running outside cable->lock */ struct snd_refcount stop_count;struct snd_pcm_hardware hw;/* flags */
@@ -804,6 +804,8 @@ static void loopback_snd_timer_period_elapsed(struct loopback_cable *cable, valid_runtime = (running & (1 <<SNDRV_PCM_STREAM_PLAYBACK )) ? dpcm_play->substream->runtime : dpcm_capt->substream->runtime; +/* Keep runtimes alive through the PCM callbacks. */ +snd_refcount_get (&cable->stop_count);/* resolution is only valid for SNDRV_TIMER_EVENT_TICK events */ if (event ==SNDRV_TIMER_EVENT_TICK ) {
@@ -839,13 +841,16 @@ static void loopback_snd_timer_period_elapsed(struct loopback_cable *cable,snd_pcm_stop_xrun (substream_play);if (substream_capt)snd_pcm_stop_xrun (substream_capt); -return ; + goto exit; }if (substream_play)snd_pcm_period_elapsed (substream_play);if (substream_capt)snd_pcm_period_elapsed (substream_capt); + +exit: +snd_refcount_put (&cable->stop_count); } static void loopback_snd_timer_function(struct snd_timer_instance *timeri,
@@ -1090,7 +1095,7 @@ static void free_cable(struct snd_pcm_substream *substream) other_alive = cable->streams[!substream->stream]; } -/* Pair with the stop_count increment in loopback_check_format(). */ +/* Wait for PCM callbacks running outside cable->lock. */ snd_refcount_sync (&cable->stop_count);if (other_alive)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1787/2151 ALSA: aloop: Keep the timer source alive until card release
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 762ef425cf0ac9c4b9e9e61e0da0950e16e6fbea ]
The timer_source string must remain valid while PCM opens can select and parse it. loopback_set_timer_source() allocates the string with parent-device devres, which can release it while the card is still registered.
A successful nonempty proc replacement after snd_card_register() adds the string allocation after trigger_card_free. Unbinding the platform device while snd_aloop remains loaded releases devres in reverse order. An open for an unused cable can run after the string is freed and before the card-free action disconnects the card:
Device unbind PCM open
devres_release_all()
free replacement string
snd_pcm_open()
snd_card_file_add()
loopback_open()
loopback_snd_timer_open()
loopback_parse_timer_id()
trigger_card_free()
snd_card_free()
snd_card_disconnect()The parser can then read freed memory. KASAN has reported a one-byte use-after-free read in strchr() from loopback_snd_timer_open(). The cable_lock mutex serializes explicit replacements with opens, but implicit devres release does not take it. The card and module references held by PCM open do not retain this separate devres allocation.
Use kstrdup() and release the current string from card->private_free. PCM admission already retains the card until each file is removed, and card disconnect drains proc callbacks before final card release. This keeps the string alive across admitted PCM opens and preserves the cable_lock serialization of replacements. Install the callback before the initial allocation so probe failures also release the string.
--- sound/drivers/aloop.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
sound/drivers/aloop.c +11 -6
@@ -1786,13 +1786,10 @@ static int loopback_cable_proc_new(struct loopback *loopback, int cidx)static void loopback_set_timer_source (struct loopback *loopback,const char *value) { -if (loopback->timer_source) { -devm_kfree (loopback->card->dev, loopback->timer_source); - loopback->timer_source =NULL ; - } +kfree (loopback->timer_source); + loopback->timer_source =NULL ;if (value && *value) - loopback->timer_source =devm_kstrdup (loopback->card->dev, - value,GFP_KERNEL ); + loopback->timer_source =kstrdup (value,GFP_KERNEL ); } static void print_timer_source_info(struct snd_info_entry *entry,
@@ -1823,6 +1820,13 @@ static int loopback_timer_source_proc_new(struct loopback *loopback) change_timer_source_info); } +static void loopback_private_free (struct snd_card *card) +{ +struct loopback *loopback = card->private_data; + +kfree (loopback->timer_source); +} +static int loopback_probe (struct platform_device *devptr) {struct snd_card *card;
@@ -1848,6 +1852,7 @@ static int loopback_probe(struct platform_device *devptr) pcm_substreams[dev] =MAX_PCM_SUBSTREAMS ; loopback->card = card; + card->private_free = loopback_private_free;loopback_set_timer_source (loopback, timer_source[dev]);mutex_init (&loopback->cable_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1788/2151 block, bfq: initialize active lists for all actuators
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 00c2c34ead7e84d6594e20fa37a3c503823f5756 ]
Commit 2d31c684a053 ("block, bfq: inject I/O to underutilized actuators") extended bfqd->active_list from a single list_head to an array indexed by actuator, but bfq_init_queue() still only initialized the first two entries:
INIT_LIST_HEAD(&bfqd->active_list[0]);
INIT_LIST_HEAD(&bfqd->active_list[1]);For devices with more than two independent access ranges, the remaining list heads stay zeroed by kzalloc() and are never set up as empty lists. When BFQ later adds a bfq_queue to one of those lists, list_add() writes through head->next, which is NULL, corrupting the list or crashing the kernel.
Initialize every actuator's active list using bfqd->num_actuators, which is already set up earlier in bfq_init_queue().
--- block/bfq-iosched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/bfq-iosched.c +2 -2
@@ -7287,8 +7287,8 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_queue *eq) bfqd->num_groups_with_pending_reqs =0 ;#endif -INIT_LIST_HEAD (&bfqd->active_list[0 ]); -INIT_LIST_HEAD (&bfqd->active_list[1 ]); +for (i =0 ; i < bfqd->num_actuators; i++) +INIT_LIST_HEAD (&bfqd->active_list[i]);INIT_LIST_HEAD (&bfqd->idle_list);INIT_HLIST_HEAD (&bfqd->burst_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1789/2151 cgroup/cpuset: use mems_allowed_seq when checking a policy nodemask
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price (Meta) <[email protected]>
[ Upstream commit b0cec62d2867ab3ed27604d5c177b8960c43b17a ]
A cpuset update changes the task's mems_allowed and rebinds its mempolicy in separate steps under mems_allowed_seq, but the check reads both without it. This can cause a spurious numa placement miss under some cpuset/mempolicy combinations.
A reader that loads one mask before the update and the other after it can see a spurious empty intersection and drop the nodemask.
For example, a task with cpuset.mems={0} and MPOL_BIND={0}. If the cpuset moves to mems={1,2}, the policy is rebound to {1}.
The allocator can race and compare the old mems_allowed {0} against the new policy {1} - which will result in a dropped nodemask and a misplaced allocation on node 2.
Simply retry the intersection until mems_allowed_seq is stable.
This covers the task policy, which is rebound under mems_allowed_seq. VMA policies are rebound afterwards by mpol_rebind_mm(), outside mems_allowed_seq, and are not covered by this change.
--- kernel/cgroup/cpuset.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +12 -1
@@ -4367,10 +4367,21 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)* @nodemask: the nodemask to be checked * * Are any of the nodes in the nodemask allowed in current->mems_allowed? +* +* A cpuset update rebinds the task's mempolicy and changes mems_allowed in +* separate steps, so retry if an update raced with the check. */ int cpuset_nodemask_valid_mems_allowed (nodemask_t *nodemask) { -return nodes_intersects (*nodemask, current->mems_allowed); +unsigned int seq; +int ret; + +do { + seq =read_mems_allowed_begin (); + ret =nodes_intersects (*nodemask, current->mems_allowed); + }while (read_mems_allowed_retry (seq)); + +return ret; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1790/2151 ipe: fix invalid sgid value in audit event documentation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manuel Ebner <[email protected]>
[ Upstream commit edf43c031902787117822b23324cf08ccc023bf6 ]
The audit event example in the IPE documentation contains 'sgid=)', which is not a valid Set Group ID value. Fix it to use 'sgid=0'.
--- Documentation/admin-guide/LSM/ipe.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/LSM/ipe.rst +2 -2
@@ -489,11 +489,11 @@ The following table lists the error codes that may appear in the errno field whi Event Examples:: type=1404 audit(1653425689.008:55): enforcing=0 old_enforcing=1 auid=4294967295 ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1 - type=1300 audit(1653425689.008:55): arch=c000003e syscall=1 success=yes exit=2 a0=1 a1=55c1065e5c60 a2=2 a3=0 items=0 ppid=405 pid=441 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=) + type=1300 audit(1653425689.008:55): arch=c000003e syscall=1 success=yes exit=2 a0=1 a1=55c1065e5c60 a2=2 a3=0 items=0 ppid=405 pid=441 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 type=1327 audit(1653425689.008:55): proctitle="-bash" type=1404 audit(1653425689.008:55): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295 enabled=1 old-enabled=1 lsm=ipe res=1 - type=1300 audit(1653425689.008:55): arch=c000003e syscall=1 success=yes exit=2 a0=1 a1=55c1065e5c60 a2=2 a3=0 items=0 ppid=405 pid=441 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=) + type=1300 audit(1653425689.008:55): arch=c000003e syscall=1 success=yes exit=2 a0=1 a1=55c1065e5c60 a2=2 a3=0 items=0 ppid=405 pid=441 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 type=1327 audit(1653425689.008:55): proctitle="-bash" This record will always be emitted in conjunction with a ``AUDITSYSCALL`` record for the ``write`` syscall.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1791/2151 ipe: fix enforcement audit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 0e5f66bf052223aa5c8caeb8554a7577b54c302f ]
ipe_audit_enforce() starts an audit buffer but writes the state change with audit_log(), which logs its own record. Ending the unused buffer then emits an extra empty AUDIT_MAC_STATUS record.
Remove the unused buffer and log the state change with audit_log() alone.
--- security/ipe/audit.c | 8 -------- 1 file changed, 8 deletions(-)
security/ipe/audit.c +0 -8
@@ -261,18 +261,10 @@ void ipe_audit_policy_load(const struct ipe_policy *const p)*/ void ipe_audit_enforce (bool new_enforce,bool old_enforce) { -struct audit_buffer *ab; - - ab =audit_log_start (audit_context (),GFP_KERNEL ,AUDIT_MAC_STATUS ); -if (!ab) -return ; -audit_log (audit_context (),GFP_KERNEL ,AUDIT_MAC_STATUS ,"enforcing=%d old_enforcing=%d auid=%u ses=%u" " enabled=1 old-enabled=1 lsm=ipe res=1" , new_enforce, old_enforce,from_kuid (&init_user_ns,audit_get_loginuid (current)),audit_get_sessionid (current)); - -audit_log_end (ab); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1792/2151 net/sched: act_api: reject duplicate actions in a batch
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit f67b3ed1308d7a282e2d6202d61af052ab0da39e ]
tca_action_gd() builds actions[] with one tcf_action_get_1() per nested TCA_ACT_TAB entry. Each successful lookup takes its own reference to the resolved action, so repeated TCA_ACT_INDEX entries in one request yield the same pointer in multiple slots.
For RTM_DELACTION, tcf_action_delete() then consumes two references per
slot: one in tcf_action_put() and one in tcf_idr_delete_index(). A duplicate therefore drives the refcount to zero mid-walk -- the delete frees the action and removes its IDR slot -- and the next slot calls tcf_action_put() on the freed action:
refcount_t: underflow; use-after-free.
WARNING: lib/refcount.c:87 at refcount_dec_not_one refcount_dec_and_mutex_lock __tcf_action_put tca_action_gd
Three duplicate entries are enough. Reject a repeated action while a delete batch is built, dropping the reference the extra lookup took, and return -EINVAL. RTM_GETACTION balances its own references and keeps accepting duplicate entries.
Conditions to recreate the bug:
tc actions add action gact index 100
tc actions delete action gact index 100 action gact index 100 \
action gact index 100
--- net/sched/act_api.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/sched/act_api.c +20 -1
@@ -2025,7 +2025,7 @@ static int tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, u32 portid, int event, struct netlink_ext_ack *extack) { - int i, ret; + int i, j, ret;struct nlattr *tb[TCA_ACT_MAX_PRIO +1 ];struct tc_action *act;size_t attr_size =0 ;
@@ -2050,6 +2050,25 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, ret =PTR_ERR (act); goto err; } + +/* A delete consumes two references per slot (tcf_action_put() +* and tcf_idr_delete_index()) but each entry takes one, so a +* repeated action would hit zero mid-walk. GET balances its +* own references and keeps accepting duplicates. +*/ +if (event ==RTM_DELACTION ) { +for (j =0 ; j < i -1 ; j++) { +if (actions[j] != act) +continue ; + +tcf_action_put (act); +NL_SET_ERR_MSG (extack, +"Duplicate TC action in a delete batch" ); + ret = -EINVAL ; + goto err; + } + } + attr_size +=tcf_action_fill_size (act); actions[i -1 ] = act; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1793/2151 RDMA/mlx5: Fix CQ resize destination index mask
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 0fe31052d948a3a993bb2f58cd5886f7ec279ea7 ]
In copy_resize_cqes, the destination CQE index is computed as (i + 1) & cq->resize_buf->nent, but resize_buf->nent is produced by roundup_pow_of_two(), so it is a power of two with exactly one bit set. Masking with a single-bit value can only yield 0 or nent itself. The buffer has nent entries, so valid indices are 0 .. nent - 1 and nent is one past the last slot; whenever the masked result is nent the following memcpy writes one entry out of bounds.
Use (nent - 1) as the wrap mask instead. For a power-of-two nent, (i + 1) & (nent - 1) is the correct modulo-nent reduction, keeping the index within [0, nent - 1]. This matches get_sw_cqe(), which addresses the CQ buffer via n & cq->ibcq.cqe, where cq->ibcq.cqe == entries - 1 is exactly the nent - 1 wrap mask.
--- drivers/infiniband/hw/mlx5/cq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/cq.c +1 -1
@@ -1262,7 +1262,7 @@ static int copy_resize_cqes(struct mlx5_ib_cq *cq)while (get_cqe_opcode (scqe64) !=MLX5_CQE_RESIZE_CQ ) { dcqe =mlx5_frag_buf_get_wqe (&cq->resize_buf->fbc, - (i +1 ) & cq->resize_buf->nent); + (i +1 ) & (cq->resize_buf->nent -1 )); dcqe64 = dsize ==64 ? dcqe : dcqe +64 ; sw_own =sw_ownership_bit (i +1 , cq->resize_buf->nent);memcpy (dcqe, scqe, dsize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1794/2151 net: stmmac: xgmac: do not treat TBU as a TX event
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengfei Zhang <[email protected]>
[ Upstream commit 305deb54c6c287e586bed92da2375ae1220e8dde ]
Commit 8d07a7930434 ("net: stmmac: xgmac: Do not enable TBU interrupt") removed TBUE from the default DMA interrupt mask, but did not remove the TBU check from dwxgmac2_dma_interrupt().
TBU is set whenever a TX channel runs out of descriptors. Since TBUE is not enabled and only enabled bits are cleared, the TBU status bit is never cleared. As a result, TBU stays set on every idle TX channel, regardless of whether there is any TX traffic.
With a shared interrupt, stmmac_dma_interrupt() checks all channels, so every interrupt from any source schedules TX NAPI on every idle TX channel.
Only use TI to trigger TX processing.
--- drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +1 -1
@@ -357,7 +357,7 @@ static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv,u64_stats_update_end (&stats->syncp); ret |= handle_rx; } -if (likely (intr_status & (XGMAC_TI |XGMAC_TBU ))) { +if (likely (intr_status &XGMAC_TI )) {u64_stats_update_begin (&stats->syncp);u64_stats_inc (&stats->tx_normal_irq_n[chan]);u64_stats_update_end (&stats->syncp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1795/2151 mptcp: options: mpc: avoid printing uninit data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
[ Upstream commit a234ee8eb9a20d1a272f0d2ceabdb35165071778 ]
When parsing the MP_CAPABLE suboption, this pr_debug() might read and print uninitialised values.
That's mostly harmless, but that's also confusing. Fixing that also avoids some tools to complain about accessing uninit data.
So read these fields only if they have been set.
Note: this was initially reported by Clashiko as an existing issue. The code has been analysed by a human and confirmed. This is a non-urgent fix.
--- net/mptcp/options.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/options.c +5 -2
@@ -126,8 +126,11 @@ static void mptcp_parse_option(const struct sk_buff *skb, ptr +=2 ; }pr_debug ("MP_CAPABLE version=%x, flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d csum=%u\n" , - version, flags, opsize, mp_opt->sndr_key, - mp_opt->rcvr_key, mp_opt->data_len, mp_opt->csum); + version, flags, opsize, + opsize >=TCPOLEN_MPTCP_MPC_SYNACK ? mp_opt->sndr_key :0 , + opsize >=TCPOLEN_MPTCP_MPC_ACK ? mp_opt->rcvr_key :0 , + opsize >=TCPOLEN_MPTCP_MPC_ACK_DATA ? mp_opt->data_len :0 , + opsize ==TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM ? mp_opt->csum :0 );break ;case MPTCPOPT_MP_JOIN :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1796/2151 mptcp: options: dss: avoid printing uninit csum
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
[ Upstream commit 00e2690c9dad0e09cd2a4435b98de6d8efd5fbc2 ]
When parsing the DSS suboption, this pr_debug() might read and print uninitialised checksum value.
That's mostly harmless, but that's also confusing. Fixing that also avoids some tools to complain about accessing uninit data.
So read this csum field only if it has been set.
Note: this was initially reported by Clashiko as an existing issue. The code has been analysed by a human and confirmed. This is a non-urgent fix.
--- net/mptcp/options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/options.c +1 -1
@@ -259,7 +259,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,pr_debug ("data_seq=%llu subflow_seq=%u data_len=%u csum=%d:%u\n" , mp_opt->data_seq, mp_opt->subflow_seq, mp_opt->data_len, !!(mp_opt->suboptions &OPTION_MPTCP_CSUMREQD ), - mp_opt->csum); + (mp_opt->suboptions &OPTION_MPTCP_CSUMREQD ) ? mp_opt->csum :0 ); }break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1797/2151 net: phy: qca83xx: read resolved QCA8337 link status
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongzhao Chen <[email protected]>
[ Upstream commit 42a91cbfc7a3ab99d05cb2ed0de5a24b9652cfed ]
After a QCA8337 SmartSpeed downshift, genphy_read_status() can report 1000 Mbit/s from the advertised modes when the PHY is running at 100 Mbit/s. On a Redmi AX5400 running downstream OpenWrt Linux 6.18.52, this caused qca8k to program the user-port MAC for 1000 Mbit/s and traffic failed. An earlier prototype that read the resolved speed from the PHY restored traffic.
Wrap genphy_read_status() and use at803x_read_specific_status() to replace its speed and duplex result when an autonegotiated link comes up. Resolve pause for the resulting duplex. Until the PHY reports a resolved speed and duplex, report the link as down so that the next poll reads them again, as marvell_read_status_page_an() does. In that case also clear the duplex, master/slave state and link partner modes that genphy_read_status() read for an up link. QCA8337's register layout matches the helper (data sheet 80-Y0619-3 Rev. D, pages 327-328).
Keep the generic master/slave read order and the early return for a steady autonegotiated link. This avoids additional reads of the clear-on-read idle error count in MII_STAT1000. Forced mode continues to use BMCR. Report the MDI-X state read at link-up and invalidate it when the link goes down or autonegotiation is disabled. Clear mdix_ctrl because this driver does not implement MDI-X configuration.
The QCA8327 entries keep genphy_read_status(). The AR8327 data sheet (MKG-15791 Rev. 1.0) lists the QCA8327-A PHY ID and documents the same PHY-specific status layout, with SmartSpeed enabled after a hardware reset, so those PHYs may have the same problem. That is untested on QCA8327 hardware, so limit this change to QCA8337.
--- drivers/net/phy/qcom/qca83xx.c | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
drivers/net/phy/qcom/qca83xx.c +58 -0
@@ -92,6 +92,63 @@ static int qca83xx_probe(struct phy_device *phydev)return 0 ; } +static int qca8337_read_status (struct phy_device *phydev) +{ +struct at803x_ss_mask ss_mask = { + .speed_mask =AT803X_SS_SPEED_MASK , + .speed_shift =__bf_shf (AT803X_SS_SPEED_MASK ), + }; +int ret, old_link = phydev->link; + + ret =genphy_read_status (phydev); +if (ret) +return ret; + +/* Keep the state resolved at link-up while the link stays up */ +if (phydev->autoneg ==AUTONEG_ENABLE && old_link && phydev->link) + goto out; + + phydev->mdix =ETH_TP_MDI_INVALID ; + +/* genphy_read_status() derives speed and duplex from the +* advertisements, which is wrong after a SmartSpeed downshift. +* Use what the PHY resolved instead. +*/ +if (phydev->autoneg ==AUTONEG_ENABLE && phydev->autoneg_complete && + phydev->link) { + phydev->speed =SPEED_UNKNOWN ; + phydev->duplex =DUPLEX_UNKNOWN ; + phydev->pause = false; + phydev->asym_pause = false; + + ret =at803x_read_specific_status (phydev, ss_mask); +if (ret) +return ret; + +/* Report the link down until speed and duplex are resolved, +* so that the next poll reads them again. Also clear what +* genphy_read_status() read for an up link, as the +* PHY_HALTED path of the state machine does. +*/ +if (phydev->speed ==SPEED_UNKNOWN || + phydev->duplex ==DUPLEX_UNKNOWN ) { + phydev->link =0 ; + phydev->duplex =DUPLEX_UNKNOWN ; + phydev->mdix =ETH_TP_MDI_INVALID ; + phydev->master_slave_state =MASTER_SLAVE_STATE_UNKNOWN ; +linkmode_zero (phydev->lp_advertising); + }else { +phy_resolve_aneg_pause (phydev); + } + } + +out: +/* MDI-X configuration is not implemented */ + phydev->mdix_ctrl =ETH_TP_MDI_INVALID ; + +return 0 ; +} +static int qca83xx_config_init (struct phy_device *phydev) {u8 switch_revision;
@@ -220,6 +277,7 @@ static struct phy_driver qca83xx_driver[] = { .flags = PHY_IS_INTERNAL, .config_init = qca83xx_config_init, .soft_reset = genphy_soft_reset, + .read_status = qca8337_read_status, .get_sset_count = qca83xx_get_sset_count, .get_strings = qca83xx_get_strings, .get_stats = qca83xx_get_stats,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1798/2151 RDMA/irdma: Bound in-flight CQP ops across deferred completions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sunny Tiwari <[email protected]>
[ Upstream commit c3e8e9451e6f1b69f685b75e0fbf14f3d0fb2539 ]
On IRDMA_GEN_3+ devices, CQP operations can complete in two stages:
Stage-1 on the CCQ acknowledges receipt and moves an entry from cqp->ooo_avail to cqp->ooo_pnd, while Stage-2 signals final completion via an AEQ event or a subsequent CCQ CQE.
In irdma_sc_ccq_get_cqe_info(), Stage-1 processing advances cqp->sq_ring.tail so the SQ descriptor slot can be reused once consumed by hardware, whereas cqp->completed_ops is only incremented on Stage-2. Because irdma_cqp_ring_full() only checks cqp->sq_ring, a burst of backlogged commands in dev->cqp_cmd_head allows irdma_process_bh() to submit more concurrent in-flight CQP commands than the maximum supported limit (cqp->sq_size - 1) while earlier commands await Stage-2. This causes CQP completions to be lost and synchronous waiters to time out with -ETIMEDOUT (-110).
Fix this by:
- Updating irdma_cqp_ring_full() to bound total in-flight CQP
operations (cqp->requested_ops - cqp->completed_ops) to
(cqp->sq_size - 1). - Calling irdma_process_bh() at the end of irdma_process_ae_def_cmpl() so backlogged commands are drained after Stage-2 AEQ completions increment cqp->completed_ops and free in-flight capacity.
--- drivers/infiniband/hw/irdma/ctrl.c | 6 +++++- drivers/infiniband/hw/irdma/hw.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/infiniband/hw/irdma/ctrl.c +5 -1
@@ -5406,7 +5406,11 @@ int irdma_sc_static_hmc_pages_allocated(struct irdma_sc_cqp *cqp, u64 scratch,*/ static bool irdma_cqp_ring_full (struct irdma_sc_cqp *cqp) { -return IRDMA_RING_FULL_ERR (cqp->sq_ring); +u64 in_flight = cqp->requested_ops - +atomic64_read (&cqp->completed_ops); + +return IRDMA_RING_FULL_ERR (cqp->sq_ring) || + in_flight >= (cqp->sq_size -1 ); }/**
drivers/infiniband/hw/irdma/hw.c +1 -0
@@ -197,6 +197,7 @@ static void irdma_process_ae_def_cmpl(struct irdma_pci_f *rf,irdma_sc_cqp_def_cmpl_ae_handler (&rf->sc_dev, info, false, &scratch, &sw_def_info); } +irdma_process_bh (&rf->sc_dev); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1799/2151 net/mlx5: HWS, fix reformat pool creation race
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandre Cassen <[email protected]>
[ Upstream commit d730ca15cf3e4806e38fa8fc6f2af8d7405ef2a4 ]
mlx5_fs_get_pr_encap_pool() inserts a new pool when the lookup misses. Two callers allocating the first reformat of a size at once both create one and the second fails with -EBUSY. TC serializes these allocations under encap_tbl_lock while RDMA flow actions on the FDB don't.
Sashiko AI review of an earlier series spotted this issue.
Tested for regressions on ConnectX-7 with firmware 28.48.1000.
--- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +7 -6
@@ -1232,7 +1232,7 @@ static struct mlx5_fs_pool * mlx5_fs_get_pr_encap_pool(struct mlx5_core_dev *dev, struct xarray *pr_pools, enum mlx5hws_action_type reformat_type, size_t size) { - struct mlx5_fs_pool *pr_pool; + struct mlx5_fs_pool *pr_pool, *old;unsigned long index = size;int err;
@@ -1246,13 +1246,14 @@ mlx5_fs_get_pr_encap_pool(struct mlx5_core_dev *dev, struct xarray *pr_pools, err =mlx5_fs_hws_pr_pool_init (pr_pool, dev, size, reformat_type);if (err) goto free_pr_pool; - err =xa_insert (pr_pools, index, pr_pool,GFP_KERNEL ); -if (err) - goto cleanup_pr_pool; -return pr_pool; + old =xa_cmpxchg (pr_pools, index,NULL , pr_pool,GFP_KERNEL ); +if (!old) +return pr_pool; -cleanup_pr_pool:mlx5_fs_hws_pr_pool_cleanup (pr_pool); +kfree (pr_pool); +return xa_is_err (old) ?ERR_PTR (xa_err (old)) : old; + free_pr_pool:kfree (pr_pool);return ERR_PTR (err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1800/2151 net/mlx5: HWS, fix modify header pool creation race
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandre Cassen <[email protected]>
[ Upstream commit e4ab8ab27ab1c9f0cd1589bee471d93319e20c95 ]
mlx5_cmd_hws_modify_header_alloc() creates a pool at the index after the last one if no pool matches the pattern. TC and CT allocate modify headers concurrently, meaning two callers can take the same index and the second call fails with -EBUSY.
Its error path also destroys the pool it just created although another caller may already use it. Keep such a pool since cleanup releases it.
Pools now live until cleanup so the lookup needs no lock. A miss looks again under a mutex before creating the pool.
Tested for regressions on ConnectX-7 with firmware 28.48.1000.
--- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 53 +++++++++++-------- .../mellanox/mlx5/core/steering/hws/fs_hws.h | 1 + 2 files changed, 33 insertions(+), 21 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +32 -21
@@ -63,6 +63,7 @@ static int mlx5_fs_init_hws_actions_pool(struct mlx5_core_dev *dev,xa_init (&hws_pool->el2tol3tnl_pools);xa_init (&hws_pool->el2tol2tnl_pools);xa_init (&hws_pool->mh_pools); +mutex_init (&hws_pool->mh_pools_lock);xa_init (&hws_pool->table_dests);xa_init (&hws_pool->vport_dests);xa_init (&hws_pool->vport_vhca_dests);
@@ -111,6 +112,7 @@ static void mlx5_fs_cleanup_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx)xa_for_each (&hws_pool->mh_pools, i, pool)mlx5_fs_destroy_mh_pool (pool, &hws_pool->mh_pools, i);xa_destroy (&hws_pool->mh_pools); +mutex_destroy (&hws_pool->mh_pools_lock);xa_for_each (&hws_pool->el2tol2tnl_pools, i, pool)mlx5_fs_destroy_pr_pool (pool, &hws_pool->el2tol2tnl_pools, i);xa_destroy (&hws_pool->el2tol2tnl_pools);
@@ -1461,6 +1463,23 @@ mlx5_fs_destroy_mh_pool(struct mlx5_fs_pool *pool, struct xarray *mh_pools,kfree (pool); } +static struct mlx5_fs_pool * +mlx5_fs_find_mh_pool (struct xarray *mh_pools, +struct mlx5hws_action_mh_pattern *pattern, +unsigned long *cnt) +{ +struct mlx5_fs_pool *pool; +unsigned long i; + + *cnt =0 ; +xa_for_each (mh_pools, i, pool) { +if (mlx5_fs_hws_mh_pool_match (pool, pattern)) +return pool; + (*cnt)++; + } +return NULL ; +} + static int mlx5_cmd_hws_modify_header_alloc(struct mlx5_flow_root_namespace *ns, u8 namespace, u8 num_actions, void *modify_actions,
@@ -1471,33 +1490,28 @@ static int mlx5_cmd_hws_modify_header_alloc(struct mlx5_flow_root_namespace *ns,struct mlx5_fs_hws_mh *mh_data =NULL ;struct mlx5hws_action *hws_action;struct mlx5_fs_pool *pool; -unsigned long i, cnt =0 ; -bool known_pattern; +unsigned long cnt;int err; pattern.sz =MLX5_UN_SZ_BYTES (set_add_copy_action_in_auto) * num_actions; pattern.data = modify_actions; - known_pattern = false; -xa_for_each (&hws_pool->mh_pools, i, pool) { -if (mlx5_fs_hws_mh_pool_match (pool, &pattern)) { - known_pattern = true; -break ; - } - cnt++; - } - -if (!known_pattern) { - pool =mlx5_fs_create_mh_pool (ns->dev, &pattern, - &hws_pool->mh_pools, cnt); + pool =mlx5_fs_find_mh_pool (&hws_pool->mh_pools, &pattern, &cnt); +if (!pool) { +mutex_lock (&hws_pool->mh_pools_lock); + pool =mlx5_fs_find_mh_pool (&hws_pool->mh_pools, &pattern, + &cnt); +if (!pool) + pool =mlx5_fs_create_mh_pool (ns->dev, &pattern, + &hws_pool->mh_pools, cnt); +mutex_unlock (&hws_pool->mh_pools_lock);if (IS_ERR (pool))return PTR_ERR (pool); } + mh_data =mlx5_fs_hws_mh_pool_acquire_mh (pool); -if (IS_ERR (mh_data)) { - err =PTR_ERR (mh_data); - goto destroy_pool; - } +if (IS_ERR (mh_data)) +return PTR_ERR (mh_data); hws_action = mh_data->bulk->hws_action; mh_data->data =kmemdup (pattern.data, pattern.sz,GFP_KERNEL );if (!mh_data->data) {
@@ -1513,9 +1527,6 @@ static int mlx5_cmd_hws_modify_header_alloc(struct mlx5_flow_root_namespace *ns, release_mh:mlx5_fs_hws_mh_pool_release_mh (pool, mh_data); -destroy_pool: -if (!known_pattern) -mlx5_fs_destroy_mh_pool (pool, &hws_pool->mh_pools, cnt);return err; }
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +1 -0
@@ -19,6 +19,7 @@ struct mlx5_fs_hws_actions_pool {struct xarray el2tol3tnl_pools;struct xarray el2tol2tnl_pools;struct xarray mh_pools; +struct mutex mh_pools_lock;/* serializes pool creation */ struct xarray table_dests;struct xarray vport_vhca_dests;struct xarray vport_dests;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1801/2151 net: stmmac: avoid duplicate XSK TX completions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
[ Upstream commit daac93975b8ff0a0a036a5e3562236c0b40c3e36 ]
stmmac_tx_clean() reports completed AF_XDP TX descriptors through xsk_tx_completed(), but leaves their buffer type as STMMAC_TXBUF_T_XSK_TX. The slots retain that type until they are reused for another buffer type.
On interface close or XDP teardown, dma_free_tx_skbufs() walks the entire TX ring, not just the dirty_tx..cur_tx range. stmmac_free_tx_buffer() counts the stale XSK_TX slots again, causing xsk_tx_completed() to advance the completion-ring producer for buffers that have already been returned. This publishes completion entries without matching outstanding TX reservations and corrupts completion accounting for a socket which stays bound across the teardown.
Reset the XSK buffer type after counting the completion in both stmmac_tx_clean() and stmmac_free_tx_buffer(). XSK TX slots have a NULL skb pointer and no per-slot DMA mapping, so the SKB type represents an empty slot. Pending XSK descriptors keep their type until they are completed or released, and a released slot can no longer be counted again by a later cleanup.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -2
@@ -1545,8 +1545,10 @@ static void stmmac_free_tx_buffer(struct stmmac_priv *priv, tx_q->xdpf[i] =NULL ; } -if (tx_q->tx_skbuff_dma[i].buf_type ==STMMAC_TXBUF_T_XSK_TX ) +if (tx_q->tx_skbuff_dma[i].buf_type ==STMMAC_TXBUF_T_XSK_TX ) { tx_q->xsk_frames_done++; + tx_q->tx_skbuff_dma[i].buf_type =STMMAC_TXBUF_T_SKB ; + }if (tx_q->tx_skbuff[i] && tx_q->tx_skbuff_dma[i].buf_type ==STMMAC_TXBUF_T_SKB ) {
@@ -2755,8 +2757,11 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue, tx_q->xdpf[entry] =NULL ; } -if (tx_q->tx_skbuff_dma[entry].buf_type ==STMMAC_TXBUF_T_XSK_TX ) +if (tx_q->tx_skbuff_dma[entry].buf_type ==STMMAC_TXBUF_T_XSK_TX ) { tx_q->xsk_frames_done++; +/* Teardown must not count this slot again. */ + tx_q->tx_skbuff_dma[entry].buf_type =STMMAC_TXBUF_T_SKB ; + }if (tx_q->tx_skbuff_dma[entry].buf_type ==STMMAC_TXBUF_T_SKB ) {if (likely (skb)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1802/2151 rtc: mpfs: Fix alarm register word order
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baek Kyu, Kim <[email protected]>
[ Upstream commit d691a96370b6cd7e684e4da1c473c09df963611b ]
mpfs_rtc_readalarm() swaps the low and high words of the alarm time. The RTC core reads this value during device registration to initialize its alarm timer. This can populate the cached alarm and timer queue with an incorrect expiry time, or leave an enabled hardware alarm out of the timer queue if the decoded time appears to be in the past.
Read the low 32 bits from ALARM_LOWER_REG and place the masked high 11 bits from ALARM_UPPER_REG in bits 42:32. This matches the layout used by mpfs_rtc_setalarm() and the low/high assembly in mpfs_rtc_readtime(), so the RTC core imports the programmed alarm time correctly during device registration.
--- drivers/rtc/rtc-mpfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-mpfs.c +2 -2
@@ -131,8 +131,8 @@ static int mpfs_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) alrm->enabled = mode &MODE_WAKE_EN ; - time = (u64 )readl (rtcdev->base +ALARM_LOWER_REG ) <<32 ; - time |= (readl (rtcdev->base +ALARM_UPPER_REG ) &ALARM_UPPER_MASK ); + time =readl (rtcdev->base +ALARM_LOWER_REG ); + time |= ((u64 )readl (rtcdev->base +ALARM_UPPER_REG ) &ALARM_UPPER_MASK ) <<32 ;rtc_time64_to_tm (time, &alrm->time);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1803/2151 rtc: class: Make the time32 hctosys limit configurable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit b253c2e96a80aac8e2bc67b425bf007ed78d4d8c ]
The RTC_HCTOSYS feature faces an impossible dilemma on 32-bit systems:
a) systemd requires RTC_HCTOSYS=y with the correct timestamp for its intended operation
b) broken RTC hardware can produce random future timestamps beyond 2038 at boot time
c) time32 userspace immediately hangs if the time is set to a date beyond 2038 and requires timestamps to be clamped
d) time64 userspace is intended to survive the actual 2038 date and requires timestamps to not be clamped
Commit b3a5ac42ab18 ("rtc: hctosys: Ensure system time doesn't overflow time_t") introduced this limit to protect time32 userspace from future RTC dates that can break boot and address constraints a), b) and c), but broke d) in the process by limiting RTC_HCTOSYS to the time32 range and falling back to RTC_HCTOSYS=n behavior when the RTC time overflows that.
Make the behavior configurable with a new RTC_HCTOSYS_TIME32_LIMIT option that chooses between breaking c) or d). On systems with COMPAT_32BIT_TIME=n, only RTC_HCTOSYS_TIME32_LIMIT=n is allowed since userspace can be assumed to be fully built for time64. 64-bit kernels running 32-bit userland never had the cutoff and continue to not offer the option.
Warn on rejection with the RTC date and option name so users can identify the cause and find the setting.
[arnd: reword Kconfig text and patch description,
add COMPAT_32BIT_TIME dependency]
----
I ended up rewriting most of the text but kept Karl's ownership as he did the original patch.
--- drivers/rtc/Kconfig | 21 +++++++++++++++++++++ drivers/rtc/class.c | 8 +++++--- 2 files changed, 26 insertions(+), 3 deletions(-)
drivers/rtc/Kconfig +21 -0
@@ -30,6 +30,27 @@ config RTC_HCTOSYS the value read from a specified RTC device. This is useful to avoid unnecessary fsck runs at boot time, and to network better. +config RTC_HCTOSYS_TIME32_LIMIT + bool "Reject RTC dates after the 2038 cutoff" + depends on RTC_HCTOSYS && COMPAT_32BIT_TIME && !64BIT + default y + help + Reject RTC dates after 03:14:07 UTC on 19 January 2038 when + initializing the system clock in order to work around broken + RTC implementations that produce nondeterministic timestamps + without a working backup battery. + + A rejected date leaves system time unchanged, normally near + the Unix epoch, and the RTC's hctosys sysfs attribute reads + 0. Userspace must supply the time if no other source has + initialized it. + + Say Y here if the kernel may have to run old time32 userspace on + hardware that can produce unpredictable RTC timestamps. If the + kernel is intended to only run time64 compatible userspace and + continue working past 2038, you must pick N here in order to + have a working RTC_HCTOSYS functionality. + config RTC_HCTOSYS_DEVICE string "RTC used to set the system time" depends on RTC_HCTOSYS
drivers/rtc/class.c +5 -3
@@ -72,12 +72,14 @@ static void rtc_hctosys(struct rtc_device *rtc) tv64.tv_sec =rtc_tm_to_time64 (&tm); -#if BITS_PER_LONG ==32 -if (tv64.tv_sec >INT_MAX ) { +if (IS_ENABLED (CONFIG_RTC_HCTOSYS_TIME32_LIMIT ) && + tv64.tv_sec >INT_MAX ) { +dev_warn (rtc->dev.parent, +"hctosys: rejecting %ptR UTC due to CONFIG_RTC_HCTOSYS_TIME32_LIMIT=y\n" , + &tm); err = -ERANGE ; goto err_read; } -#endif err =do_settimeofday64 (&tv64);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1804/2151 timers: Clear pending_map on CPU hotplug
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liang Hao <[email protected]>
[ Upstream commit e7cad586d73276cbd4466de81b2092287d7475c0 ]
CPU hotplug migration leaves pending_map bits set on the outgoing CPU while its wheel vectors are empty. After re-online, a later next_expiry recalc can treat those empty buckets as pending and temporarily pull next_expiry forward until collect drains the bits.
Clear pending_map under the base lock after migration in timers_dead_cpu().
--- kernel/time/timer.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/time/timer.c +2 -0
@@ -44,6 +44,7 @@#include <linux/compat.h> #include <linux/random.h> #include <linux/sysctl.h> +#include <linux/bitmap.h> #include <linux/uaccess.h> #include <asm/unistd.h>
@@ -2540,6 +2541,7 @@ int timers_dead_cpu(unsigned int cpu)for (i =0 ; i <WHEEL_SIZE ; i++)migrate_timer_list (new_base, old_base->vectors + i); +bitmap_zero (old_base->pending_map,WHEEL_SIZE );raw_spin_unlock (&old_base->lock);raw_spin_unlock_irq (&new_base->lock);put_cpu_ptr (&timer_bases);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1805/2151 ASoC: cs42l56: Remove the ADC Mute Switch control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit ff404ef11b975baf38c4472c51a6674c239e8021 ]
The ADC Mute Switch control writes bits 2 and 3 of the Misc ADC Control register. These are the ADCA Invert and ADCB Invert bits, which have their own controls. The ADC mute bits are bits 0 and 1, and the DAI mute callback already sets them.
So the control has never muted the ADCs, and nobody can be relying on it. Remove it rather than point it at the mute bits, so the ADCs are muted in one place only.
--- sound/soc/codecs/cs42l56.c | 1 - 1 file changed, 1 deletion(-)
sound/soc/codecs/cs42l56.c +0 -1
@@ -419,7 +419,6 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = { CS42L56_PGAB_MUX_VOLUME, 0, 0x34, 0x24, pga_tlv),SOC_DOUBLE_R_TLV ("ADC Volume" ,CS42L56_ADCA_ATTENUATOR ,CS42L56_ADCB_ATTENUATOR ,0 ,0x00 ,1 , adc_tlv), -SOC_DOUBLE ("ADC Mute Switch" ,CS42L56_MISC_ADC_CTL ,2 ,3 ,1 ,1 ),SOC_DOUBLE ("ADC Boost Switch" ,CS42L56_GAIN_BIAS_CTL ,3 ,2 ,1 ,1 ), SOC_DOUBLE_R_SX_TLV("Headphone Volume", CS42L56_HPA_VOLUME,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1806/2151 dt-bindings: clock: mediatek: Add MT8516 fallbacks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rob Herring (Arm) <[email protected]>
[ Upstream commit 1d48ecb48e2ab9dd2564e735a1c1b29a5eeeb599 ]
MT8516 topckgen and apmixedsys nodes use the common syscon fallback form. Add the MT8516 compatibles to the branches that allow the syscon fallback.
--- .../devicetree/bindings/clock/mediatek,apmixedsys.yaml | 2 +- Documentation/devicetree/bindings/clock/mediatek,topckgen.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/clock/mediatek,apmixedsys.yaml +1 -1
@@ -26,7 +26,6 @@ properties: - mediatek,mt7988-apmixedsys - mediatek,mt8135-apmixedsys - mediatek,mt8173-apmixedsys - - mediatek,mt8516-apmixedsys - items: - const: mediatek,mt7623-apmixedsys - const: mediatek,mt2701-apmixedsys
@@ -42,6 +41,7 @@ properties: - mediatek,mt7629-apmixedsys - mediatek,mt8167-apmixedsys - mediatek,mt8183-apmixedsys + - mediatek,mt8516-apmixedsys - const: syscon reg:
Documentation/devicetree/bindings/clock/mediatek,topckgen.yaml +1 -1
@@ -23,7 +23,6 @@ properties: - mediatek,mt7622-topckgen - mediatek,mt8135-topckgen - mediatek,mt8173-topckgen - - mediatek,mt8516-topckgen - items: - const: mediatek,mt7623-topckgen - const: mediatek,mt2701-topckgen
@@ -43,6 +42,7 @@ properties: - mediatek,mt7988-topckgen - mediatek,mt8167-topckgen - mediatek,mt8183-topckgen + - mediatek,mt8516-topckgen - const: syscon reg:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1807/2151 vhost: vringh: use get_user()/put_user() for IOTLB 16-bit accesses
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 95a214f31a3b1ef40034f1e1cb3b9d758a374f01 ]
getu16_iotlb() and putu16_iotlb() use __get_user() and __put_user() when the IOTLB maps to user virtual addresses. Nothing nearby checks the translated address: that relies on the mapping having been validated against the user's VMAs when it was set up.
Use get_user() and put_user(), which do the same single, untorn access and also check the address. The only atomic-context use, the vdpa simulators' notification check, now disables page faults around it, so the might_fault() in the checked accessors stays quiet there.
This is part of getting rid of __get_user() and __put_user() entirely.
--- drivers/vhost/vringh.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vringh.c +2 -2
@@ -1214,7 +1214,7 @@ static inline int getu16_iotlb(const struct vringh *vrh,return ret;if (vrh->use_va) { - ret =__get_user (tmp, (__virtio16 __user *)ivec.iov.iovec[0 ].iov_base); + ret =get_user (tmp, (__virtio16 __user *)ivec.iov.iovec[0 ].iov_base);if (ret)return ret; }else {
@@ -1252,7 +1252,7 @@ static inline int putu16_iotlb(const struct vringh *vrh, tmp =cpu_to_vringh16 (vrh, val);if (vrh->use_va) { - ret =__put_user (tmp, (__virtio16 __user *)ivec.iov.iovec[0 ].iov_base); + ret =put_user (tmp, (__virtio16 __user *)ivec.iov.iovec[0 ].iov_base);if (ret)return ret; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1808/2151 net: openvswitch: skip IPv4 later fragments on TCP/UDP set actions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 14c0350142ab0a10ebeefed03b779df23749e16a ]
An IPv4 later fragment carries no L4 header, but key extraction leaves ip.proto set to the real protocol and the flow may wildcard the frag field, so validate_set() accepts such packets. set_tcp() and set_udp() then treat the first bytes of the fragment payload as an L4 header, rewrite them as ports and patch the bytes at the checksum offset, corrupting the packet.
Skip these actions for OVS_FRAG_TYPE_LATER. IPv6 later fragments are not affected, since their ip.proto is NEXTHDR_FRAGMENT and validate_set() rejects L4 set actions for them.
--- net/openvswitch/actions.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/openvswitch/actions.c +6 -0
@@ -594,6 +594,9 @@ static int set_udp(struct sk_buff *skb, struct sw_flow_key *flow_key,__be16 src, dst;int err; +if (flow_key->ip.frag ==OVS_FRAG_TYPE_LATER ) +return 0 ; + err =skb_ensure_writable (skb,skb_transport_offset (skb) +sizeof (struct udphdr ));if (unlikely (err))
@@ -637,6 +640,9 @@ static int set_tcp(struct sk_buff *skb, struct sw_flow_key *flow_key,__be16 src, dst;int err; +if (flow_key->ip.frag ==OVS_FRAG_TYPE_LATER ) +return 0 ; + err =skb_ensure_writable (skb,skb_transport_offset (skb) +sizeof (struct tcphdr ));if (unlikely (err))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1809/2151 net: openvswitch: drop IP fragments on SCTP set action
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 4d0d8f491307f22aea34b22f73351e1cd2ede735 ]
The SCTP checksum is a CRC32c over the whole SCTP packet. set_sctp() updates it as old_csum ^ old_correct_csum ^ new_csum, with the two CRCs computed over the bytes of the current skb only. That is correct only when the skb holds the whole SCTP packet. For a first fragment, and for a later fragment, it holds just a part of it, and the CRC delta of a change at the start of the packet depends on how many bytes follow, so the checksum written is wrong. The receiver drops the reassembled packet.
validate_set() accepts SCTP set action for any flow with ip.proto set to SCTP, regardless of the fragmentation bits, as it only receives the masked key. As the checksum cannot be fixed up without the whole datagram, fail the action for packets that are IP fragments of either family, so the packet is dropped with OVS_DROP_ACTION_ERROR instead of being forwarded with modified ports and an invalid checksum.
--- net/openvswitch/actions.c | 3 +++ 1 file changed, 3 insertions(+)
net/openvswitch/actions.c +3 -0
@@ -673,6 +673,9 @@ static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key,__le32 old_correct_csum, new_csum, old_csum;int err; +if (flow_key->ip.frag !=OVS_FRAG_TYPE_NONE ) +return -EINVAL ; + err =skb_ensure_writable (skb, sctphoff +sizeof (struct sctphdr ));if (unlikely (err))return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1810/2151 tcp: tcp_metrics: use the socket netns, not the dst device netns
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 504bdcb8c1566a6f887f9accebe1aa99b502ae97 ]
tcp_get_metrics(), __tcp_get_metrics_req() and tcpm_new() look up and create metrics entries in the netns of the cached dst device rather than in the netns of the socket.
These usually match, but not after the device has been moved to another netns or unregistered: a socket can keep a stale dst in sk_dst_cache until it is checked again, and tcp_update_metrics() reads it with __sk_dst_get() without any dst_check(). Once dst_dev_put() has run, the dst device is blackhole_netdev and the entry is created in init_net. Before that, for instance for routes through nexthop objects whose cached dsts are released from a nested RCU callback, it is the netns the device has just been moved to.
A TCP socket of netns A that enters TIME_WAIT in that window then creates or updates an entry carrying A's addresses and RTT in another netns, where TCP_METRICS_CMD_GET can dump it and where new connections to the same peer inherit those metrics.
The metrics belong to the netns of the socket, so use sock_net() for full sockets and request sockets, and pass it to tcpm_new().
Kernel sockets that do not hold a netns reference can still reach tcp_time_wait() after tcp_net_metrics_exit_batch() has flushed the entries of their dismantling netns, and an entry created then would never be flushed and would keep a dangling tcpm_net. Make tcpm_new() refuse to create entries when check_net() fails. Its callers are in an RCU read-side section, and cleanup_net() waits for a grace period between the refcount reaching zero and the flush, so an entry added after a successful check is always seen by the flush.
--- net/ipv4/tcp_metrics.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
net/ipv4/tcp_metrics.c +15 -5
@@ -161,16 +161,26 @@ static void tcpm_check_stamp(struct tcp_metrics_block *tm, rcu_dereference_protected(p, lockdep_is_held(&tcp_metrics_lock))static struct tcp_metrics_block *tcpm_new (struct dst_entry *dst, +struct net *net,struct inetpeer_addr *saddr,struct inetpeer_addr *daddr,unsigned int hash) {struct tcp_metrics_block *tm;bool reclaim = false; -struct net *net;spin_lock_bh (&tcp_metrics_lock); - net =dst_dev_net_rcu (dst); + +/* Do not add entries to a dismantling netns: they would not be +* flushed again. Callers are in an RCU read-side section, and +* cleanup_net() waits for a grace period after the netns refcount +* reached zero and before tcp_metrics_flush_all(NULL) runs, so an +* entry added after a successful check_net() is seen by the flush. +*/ +if (unlikely (!check_net (net))) { + tm =NULL ; + goto out_unlock; + }/* While waiting for the spin-lock the cache might have been populated * with this entry and so we have to check again.
@@ -273,7 +283,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,return NULL ; } - net =dst_dev_net_rcu (dst); + net =sock_net (req_to_sk (req)); hash ^=net_hash_mix (net); hash =hash_32 (hash, tcp_metrics_hash_log);
@@ -318,7 +328,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,else return NULL ; - net =dst_dev_net_rcu (dst); + net =sock_net (sk); hash ^=net_hash_mix (net); hash =hash_32 (hash, tcp_metrics_hash_log);
@@ -326,7 +336,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,if (tm ==TCP_METRICS_RECLAIM_PTR ) tm =NULL ;if (!tm && create) - tm =tcpm_new (dst, &saddr, &daddr, hash); + tm =tcpm_new (dst, net, &saddr, &daddr, hash);else tcpm_check_stamp (tm, dst);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1811/2151 tls: device: protect async RX resync state during device-down
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rishikesh Jethwani <[email protected]>
[ Upstream commit f89a228125238f8d4c7e2b8161e2a85fe35307b6 ]
tls_device_rx_resync_new_rec() can run in process context with the socket lock held, but without an RCU read lock: from the strparser work item (tls_strp_work()) and from the receive paths (tls_rx_rec_wait(), tls_rx_rec_done()). The resync_async pointer belongs to the driver RX context, which tls_device_down() tears down from the netdev notifier without taking the socket lock; only the softirq entry to the parser is implicitly inside an RCU section.
If the parser passes the TLS_RX_DEV_DEGRADED check before device-down sets it, tls_device_down() can complete synchronize_net() and delete the driver context before the parser accesses resync_async->req or its record log. In the asynchronous stage the parser also writes the record log, so this is a write to freed memory, not only a stale read. The RCU section in tls_device_resync_rx() starts after those accesses and therefore does not prevent the use-after-free.
Found by code inspection; not reproduced. Hitting the window requires the parser to be preempted between the DEGRADED check and the resync_async access across the device-down grace period and the driver's teardown.
--- net/tls/tls_device.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
net/tls/tls_device.c +15 -6
@@ -782,8 +782,15 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)if (tls_ctx->rx_conf !=TLS_HW )return ; + +/* The parser also runs in process context, without an RCU read lock. +* Protect the driver's resync_async state before checking the flags: +* device-down sets DEGRADED and waits for synchronize_net() before +* freeing it, without taking the socket lock. +*/ +rcu_read_lock ();if (unlikely (test_bit (TLS_RX_DEV_DEGRADED , &tls_ctx->flags))) -return ; + goto out; prot = &tls_ctx->prot_info; rx_ctx =tls_offload_ctx_rx (tls_ctx);
@@ -798,11 +805,11 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)if (likely (!is_req_pending) || req_seq != seq || !atomic64_try_cmpxchg (&rx_ctx->resync_req, &resync_req,0 )) -return ; + goto out;break ;case TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT :if (likely (!rx_ctx->resync_nh_do_now)) -return ; + goto out;/* head of next rec is already in, note that the sock_inq will * include the currently parsed message when called from parser
@@ -811,7 +818,7 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)if (sock_data > rcd_len) {trace_tls_device_rx_resync_nh_delay (sk, sock_data, rcd_len); -return ; + goto out; } rx_ctx->resync_nh_do_now =0 ;
@@ -822,16 +829,18 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) resync_req =atomic64_read (&rx_ctx->resync_async->req); is_req_pending = resync_req;if (likely (!is_req_pending)) -return ; + goto out;if (!tls_device_rx_resync_async (rx_ctx->resync_async, resync_req, &seq, &rcd_delta)) -return ; + goto out;tls_bigint_subtract (rcd_sn, rcd_delta);break ; }tls_device_resync_rx (tls_ctx, sk, seq, rcd_sn); +out: +rcu_read_unlock (); } static void tls_device_core_ctrl_rx_resync(struct tls_context *tls_ctx,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1812/2151 octeontx2: Fix use-after-free of qos node in delete path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Deng <[email protected]>
[ Upstream commit dcaa6219648955f7a8160313f1685321dbd1bf28 ]
hash_del_rcu() only unlinks the node; a reader that already holds the bucket iterator still uses the node. The immediate kfree() has no grace period, so a concurrent transmit on a socket whose skb priority carries the deleted classid reads node->classid / node->qid from freed memory (use-after-free in the softirq transmit path).
Fix this by calling synchronize_net() before the node is freed, as mlx5e does.
Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only.
--- drivers/net/ethernet/marvell/octeontx2/nic/qos.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +2 -0
@@ -331,6 +331,8 @@ static void otx2_qos_sw_node_delete(struct otx2_nic *pfvf,otx2_qos_update_tx_netdev_queues (pfvf); } +synchronize_net (); +list_del (&node->list);kfree (node); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1813/2151 net: qede: initialize extack in qede_flow_spec_to_rule()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anirudh Virdi <[email protected]>
[ Upstream commit 106e562966a02f61917c2e0b83909aa2b088447f ]
qede_flow_spec_to_rule() declares a netlink_ext_ack on the stack without initializing it. qede_parse_flow_attr() and qede_flow_spec_validate() only set extack._msg on error paths via NL_SET_ERR_MSG_MOD(), so on a successful parse the err_out block reads an uninitialized pointer. If that garbage happens to be non-NULL, DP_NOTICE("%s", extack._msg) dereferences it inside vsnprintf, causing a page fault and kernel panic.
This manifests when configuring ethtool ntuple flow rules (ethtool -U flow-type tcp4/udp4) on kernels built with CONFIG_INIT_STACK_NONE=y. With CONFIG_INIT_STACK_ALL_ZERO=y the bug is masked because the compiler zero-initializes extack, making _msg NULL.
Reproduced on RHEL 9.8 (kernel-5.14.0-687.47.1.el9_8) and mainline (v7.3-rc6) with the following reproducer:
IFACE=ens2f0
ip link set $IFACE up
ethtool -K $IFACE ntuple on
for i in $(seq 1 100); do
ethtool -U $IFACE flow-type udp4 src-ip 192.168.2.$i action -1
doneThe loop panics reliably after 10-15 iterations with:
BUG: unable to handle page fault RIP: string+0x49/0xd0 Call Trace: vsnprintf qede_flow_spec_to_rule+0x2b6/0x4b0 [qede] qede_add_cls_rule ethtool_set_rxnfc
Zero-initialize extack so _msg is NULL unless explicitly set by an error path.
--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qlogic/qede/qede_filter.c +1 -1
@@ -1991,8 +1991,8 @@ static int qede_flow_spec_to_rule(struct qede_dev *edev, struct ethtool_rx_flow_spec *fs) {struct ethtool_rx_flow_spec_input input = {}; +struct netlink_ext_ack extack = {};struct ethtool_rx_flow_rule *flow; -struct netlink_ext_ack extack;__be16 proto;int err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1814/2151 net: phy: realtek: restore RTL8211F RGMII delays on resume
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 20c0c677362468b0af23e26e5fdb871ea911bc25 ]
RTL8211F and RTL8211F-VD both use rtl8211f_config_rgmii_delay() during initialization and share rtl821x_resume(). The RTL8211F-VD loses its RGMII TX and RX delay enable bits across a software power-down, but the shared resume path only clears BMCR_PDOWN and waits for the receive clock to stabilize.
On a BeagleV Ahead configured for rgmii-id, carrier and the negotiated speed return after an interface close/open, but the receive path does not work. At 100 Mbit/s no frames were received. At 1000 Mbit/s all 11 observed frames had CRC errors.
Reapply the RGMII delay configuration after the existing resume delay.
Tested on a BeagleV Ahead with an RTL8211F-VD at 100 and 1000 Mbit/s, including close/open without a link partner.
--- drivers/net/phy/realtek/realtek_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/realtek/realtek_main.c +1 -1
@@ -772,7 +772,7 @@ static int rtl821x_resume(struct phy_device *phydev)msleep (20 ); -return 0 ; +return rtl8211f_config_rgmii_delay (phydev); }static int rtl8211f_resume (struct phy_device *phydev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1815/2151 net: hix5hd2: serialize timeout recovery with interface teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 87cce46329a811ea3fe108ac721e0a2400d0a3bb ]
The timeout worker calls the driver's close and open methods without RTNL or a running-state check. A timeout queued before an interface is closed can call close again after ndo_stop has disabled NAPI. The second napi_disable() can then wait indefinitely. The worker can also race with an ongoing close.
Take RTNL and skip recovery when the interface is no longer running. Use the netdev core close and open helpers so a failed reopen leaves the interface down, rather than leaving it marked running with NAPI disabled.
After unregister_netdev() has stopped the watchdog, drain the worker before releasing its MDIO and descriptor resources. This wait is outside RTNL, allowing an already queued worker to take RTNL, observe the down state, and finish.
This issue was identified as part of our ongoing research while reviewing kernel code.
--- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +9 -3
@@ -12,6 +12,7 @@#include <linux/of_net.h> #include <linux/of_mdio.h> #include <linux/reset.h> +#include <linux/rtnetlink.h> #include <linux/clk.h> #include <linux/circ_buf.h>
@@ -890,8 +891,13 @@ static void hix5hd2_tx_timeout_task(struct work_struct *work)struct hix5hd2_priv *priv; priv = container_of(work, struct hix5hd2_priv, tx_timeout_task); -hix5hd2_net_close (priv->netdev); -hix5hd2_net_open (priv->netdev); + +rtnl_lock (); +if (netif_running (priv->netdev)) { +dev_close (priv->netdev); +dev_open (priv->netdev,NULL ); + } +rtnl_unlock (); }static void hix5hd2_net_timeout (struct net_device *dev,unsigned int txqueue)
@@ -1283,6 +1289,7 @@ static void hix5hd2_dev_remove(struct platform_device *pdev)struct hix5hd2_priv *priv =netdev_priv (ndev);unregister_netdev (ndev); +cancel_work_sync (&priv->tx_timeout_task);mdiobus_unregister (priv->bus);mdiobus_free (priv->bus);
@@ -1290,7 +1297,6 @@ static void hix5hd2_dev_remove(struct platform_device *pdev)hix5hd2_destroy_sg_desc_queue (priv);hix5hd2_destroy_hw_desc_queue (priv);of_node_put (priv->phy_node); -cancel_work_sync (&priv->tx_timeout_task);free_netdev (ndev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1816/2151 net: bcmasp: fix mib counters struct alignment with ethtool stats
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit db45c15c98134f5ebd13c4dc5b6be5d1cd3fc706 ]
When EDPKT stats were removed in commit e9f31435ee7d ("net: bcmasp: Add support for asp-v3.0"), the corresponding entries were removed from bcmasp_gstrings_stats in bcmasp_ethtool.c, but the edpkt_* fields were left at the beginning of struct bcmasp_mib_counters in bcmasp.h.
Because bcmasp_update_mib_counters() and bcmasp_get_ethtool_stats() index into struct bcmasp_mib_counters sequentially based on the order of bcmasp_gstrings_stats, this 16-byte offset caused ethtool to read from shifted offsets: the first four software counters read unused fields and reported 0, the next four software counters reported the values of alloc_rx_skb_failed, tx_dma_failed, mc_filters_full_cnt, and uc_filters_full_cnt, while filters_combine_cnt, promisc_filters_cnt, tx_realloc_offload_failed, and tx_timeout_cnt were never reported.
Remove the obsolete edpkt_* fields from struct bcmasp_mib_counters so that it aligns with bcmasp_gstrings_stats.
--- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.h +0 -4
@@ -249,10 +249,6 @@ struct bcmasp_intf_stats64 { };struct bcmasp_mib_counters { -u32 edpkt_ts; -u32 edpkt_rx_pkt_cnt; -u32 edpkt_hdr_ext_cnt; -u32 edpkt_hdr_out_cnt;u32 umac_frm_cnt;u32 fb_frm_cnt;u32 fb_rx_fifo_depth;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1817/2151 net: bcmasp: unmap previous DMA mappings on TX map failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit a3cf9877558ab2c51182af558815dde64fc17cb9 ]
When mapping an skb with fragments for transmission in bcmasp_xmit(), if mapping fails on fragment i > 0, the error handler calls bcmasp_clean_txcb() for previous iterations j < i. However, bcmasp_clean_txcb() only zeroes the control block fields without unmapping the DMA buffers, leaking the DMA mappings allocated for the head and earlier fragments.
Call dma_unmap_single() before calling bcmasp_clean_txcb() in the error cleanup loop.
--- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +5 -0
@@ -317,6 +317,11 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) intf->mib.tx_dma_failed++; spb_index = intf->tx_spb_index;for (j =0 ; j < i; j++) { + txcb = &intf->tx_cbs[spb_index]; +dma_unmap_single (kdev, +dma_unmap_addr (txcb, dma_addr), +dma_unmap_len (txcb, dma_len), +DMA_TO_DEVICE );bcmasp_clean_txcb (intf, spb_index); spb_index =incr_ring (spb_index,DESC_RING_COUNT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1818/2151 net: bcmasp: validate minimum RX packet size in bcmasp_rx_poll()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 07b624d2f5a4517d7d0022fbd4aef17e884b5686 ]
In bcmasp_rx_poll(), the driver removes a 2-byte alignment pad and optionally strips the ETH_FCS_LEN CRC from received packets before passing them to eth_type_trans().
If the hardware reports a descriptor size smaller than the sum of the 2-byte pad, the Ethernet header (ETH_HLEN), and optional CRC (ETH_FCS_LEN), subtracting the pad and CRC lengths underflows u32 len. This adds ~4 GiB to rx_bytes statistics, while the undersized frame reaches eth_type_trans(), which reads past skb->len into stale buffer data.
Check that desc->size is at least (2 + ETH_HLEN + (crc_fwd ? ETH_FCS_LEN : 0)) before proceeding to process the descriptor.
--- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +6 -0
@@ -563,6 +563,12 @@ static int bcmasp_rx_poll(struct napi_struct *napi, int budget) DMA_FROM_DEVICE); len = desc->size; +if (unlikely (len <2 +ETH_HLEN + (intf->crc_fwd ?ETH_FCS_LEN :0 ))) { +u64_stats_update_begin (&stats->syncp); +u64_stats_inc (&stats->rx_dropped); +u64_stats_update_end (&stats->syncp); + goto next; + } skb =napi_alloc_skb (napi, len);if (!skb) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1819/2151 net: bcmasp: fix OF node reference leak for phy_dn
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit a31623d91c6e48b08c74dc95567aeb62f1f35938 ]
In bcmasp_interface_create(), intf->phy_dn is obtained via of_parse_phandle() or assigned ndev_dn. of_parse_phandle() returns a node reference with its refcount incremented, but of_node_put() was never called on intf->phy_dn in bcmasp_interface_destroy() or the error unwind path in bcmasp_interface_create().
Acquire a reference on ndev_dn for the fixed-link case as well so that intf->phy_dn consistently holds a reference, and release it with of_node_put() on teardown and error.
--- drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +3 -1
@@ -1261,7 +1261,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, ndev_dn->name); goto err_free_netdev; } - intf->phy_dn = ndev_dn; + intf->phy_dn =of_node_get (ndev_dn); }/* Map resource */
@@ -1302,6 +1302,7 @@ struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv, err_deregister_fixed_link:if (of_phy_is_fixed_link (ndev_dn))of_phy_deregister_fixed_link (ndev_dn); +of_node_put (intf->phy_dn); err_free_netdev:free_netdev (ndev); err:
@@ -1314,6 +1315,7 @@ void bcmasp_interface_destroy(struct bcmasp_intf *intf)unregister_netdev (intf->ndev);if (of_phy_is_fixed_link (intf->ndev_dn))of_phy_deregister_fixed_link (intf->ndev_dn); +of_node_put (intf->phy_dn);free_netdev (intf->ndev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1820/2151 net: bcmasp: account for offload header in TX short packet padding
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 74667a55122ad2fad88af4fd7672e4c8175c2558 ]
When hardware checksum offload is enabled for an skb, bcmasp_csum_offload() prepends a struct bcmasp_pkt_offload header (20 bytes) to the skb via skb_push(). This increases skb->len and skb_headlen(skb) by sizeof(struct bcmasp_pkt_offload).
Because the hardware descriptor processor strips this offload header before transmitting the packet on the wire, the wire packet length is smaller by sizeof(struct bcmasp_pkt_offload). The padding calculation must account for this extra header; otherwise, short frames are sent on the wire smaller than the minimum Ethernet frame size (ETH_ZLEN + ETH_FCS_LEN).
Furthermore, small frames with payload in page fragments (such as small TCP segments with CHECKSUM_PARTIAL) have nr_frags > 0 and were skipping padding entirely because the padding check was restricted to nr_frags == 0.
Perform the padding check on skb->len before the descriptor loop using skb_put_padto(), adding sizeof(struct bcmasp_pkt_offload) to min_size when checksum offload is enabled, and re-read nr_frags after padding in case the skb was linearized.
--- .../net/ethernet/broadcom/asp2/bcmasp_intf.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +11 -6
@@ -268,7 +268,7 @@ static const struct bcmasp_intf_ops bcmasp_intf_ops = {static netdev_tx_t bcmasp_xmit (struct sk_buff *skb,struct net_device *dev) {struct bcmasp_intf *intf =netdev_priv (dev); -unsigned int total_bytes, size; +unsigned int total_bytes, size, min_size;int spb_index, nr_frags, i, j;struct bcmasp_tx_cb *txcb;dma_addr_t mapping, valid;
@@ -294,16 +294,21 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)if (!skb)return NETDEV_TX_OK ; + min_size =ETH_ZLEN +ETH_FCS_LEN ; +if (csum_hw) + min_size +=sizeof (struct bcmasp_pkt_offload ); + +if (skb->len < min_size) { +if (skb_put_padto (skb, min_size)) +return NETDEV_TX_OK ; + nr_frags =skb_shinfo (skb)->nr_frags; + } + spb_index = intf->tx_spb_index; valid = intf->tx_spb_dma_valid;for (i =0 ; i <= nr_frags; i++) {if (!i) { size =skb_headlen (skb); -if (!nr_frags && size < (ETH_ZLEN +ETH_FCS_LEN )) { -if (skb_put_padto (skb,ETH_ZLEN +ETH_FCS_LEN )) -return NETDEV_TX_OK ; - size = skb->len; - } mapping =dma_map_single (kdev, skb->data, size,DMA_TO_DEVICE ); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1821/2151 net: bcmasp: fix network filter lookup and wake filter pair allocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit fa1459375794f14fb65039cd19c9398d759b491e ]
In bcmasp_netfilt_get_init(), when looking up an existing filter (!init) for a specified location, if the filter at loc was not claimed, the previous loop continued searching higher indices and could return an arbitrary unrelated filter belonging to the port. This caused flow get or delete operations on an empty rule location to return or delete an unintended filter.
Fix this by checking only the requested location on lookup and rejecting RX_CLS_LOC_ANY when !init. In addition, harden wake filter allocation and release by ensuring wake filter pair searches stay on even boundaries where both entries are free, checking that loc + 1 is free for positioned wake filters, and validating parity and bounds on release.
--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 121 +++++++++++--------- 1 file changed, 70 insertions(+), 51 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +70 -51
@@ -511,6 +511,13 @@ static int bcmasp_netfilt_wr_to_hw(struct bcmasp_priv *priv,return 0 ; } +static bool bcmasp_netfilt_is_companion (struct bcmasp_priv *priv,int i) +{ +return i >0 && (i %2 ) && + priv->net_filters[i].wake_filter && + priv->net_filters[i -1 ].wake_filter; +} +void bcmasp_netfilt_suspend (struct bcmasp_intf *intf) {struct bcmasp_priv *priv = intf->parent;
@@ -524,9 +531,7 @@ void bcmasp_netfilt_suspend(struct bcmasp_intf *intf) priv->net_filters[i].port != intf->port)continue ; -if (i >0 && (i %2 ) && - priv->net_filters[i].wake_filter && - priv->net_filters[i -1 ].wake_filter) +if (bcmasp_netfilt_is_companion (priv, i))continue ; ret =bcmasp_netfilt_wr_to_hw (priv, &priv->net_filters[i]);
@@ -556,9 +561,7 @@ int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, priv->net_filters[i].port != intf->port)continue ; -if (i >0 && (i %2 ) && - priv->net_filters[i].wake_filter && - priv->net_filters[i -1 ].wake_filter) +if (bcmasp_netfilt_is_companion (priv, i))continue ;if (j == *rule_cnt)
@@ -583,9 +586,7 @@ int bcmasp_netfilt_get_active(struct bcmasp_intf *intf)continue ;/* Skip over a wake filter pair */ -if (i >0 && (i %2 ) && - priv->net_filters[i].wake_filter && - priv->net_filters[i -1 ].wake_filter) +if (bcmasp_netfilt_is_companion (priv, i))continue ; cnt++;
@@ -607,6 +608,9 @@ bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf, priv->net_filters[i].port != intf->port)continue ; +if (bcmasp_netfilt_is_companion (priv, i)) +continue ; + cur = &priv->net_filters[i].fs; if (cur->flow_type != fs->flow_type ||
@@ -659,7 +663,7 @@ bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf, }/* If no network filter found, return open filter. -* If no more open filters return NULL +* If no more open filters return error. */ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf, u32 loc, bool wake_filter,
@@ -669,45 +673,55 @@ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,struct bcmasp_priv *priv = intf->parent;int i, open_index =-1 ; -/* Check whether we exceed the filter table capacity */ +if (!init) { +if (loc ==RX_CLS_LOC_ANY || loc >= priv->num_net_filters) +return ERR_PTR (-EINVAL ); + +if (priv->net_filters[loc].claimed && + priv->net_filters[loc].port == intf->port && + !bcmasp_netfilt_is_companion (priv, loc)) +return &priv->net_filters[loc]; + +return ERR_PTR (-ENOENT ); + } +if (loc !=RX_CLS_LOC_ANY && loc >= priv->num_net_filters)return ERR_PTR (-EINVAL );/* If the filter location is busy (already claimed) and we are initializing * the filter (insertion), return a busy error code. */ -if (loc !=RX_CLS_LOC_ANY && init && priv->net_filters[loc].claimed) -return ERR_PTR (-EBUSY ); - -/* We need two filters for wake-up, so we cannot use an odd filter */ -if (wake_filter && loc !=RX_CLS_LOC_ANY && (loc %2 )) -return ERR_PTR (-EINVAL ); - -/* Initialize the loop index based on the desired location or from 0 */ - i = loc ==RX_CLS_LOC_ANY ?0 : loc; - -for ( ; i < priv->num_net_filters; i++) { -/* Found matching network filter */ -if (!init && - priv->net_filters[i].claimed && - priv->net_filters[i].hw_index == i && - priv->net_filters[i].port == intf->port) -return &priv->net_filters[i]; - -/* If we don't need a new filter or new filter already found */ -if (!init || open_index >=0 ) -continue ; - -/* Wake filter conslidates two filters to cover more bytes -* Wake filter is open if... -* 1. It is an even filter -* 2. The current and next filter is not claimed -*/ -if (wake_filter && !(i %2 ) && !priv->net_filters[i].claimed && - !priv->net_filters[i +1 ].claimed) - open_index = i; -else if (!priv->net_filters[i].claimed) - open_index = i; +if (loc !=RX_CLS_LOC_ANY ) { +if (priv->net_filters[loc].claimed) +return ERR_PTR (-EBUSY ); + +/* We need two filters for wake-up, so we cannot use an odd filter */ +if (wake_filter) { +if ((loc %2 ) || loc +1 >= priv->num_net_filters) +return ERR_PTR (-EINVAL ); +if (priv->net_filters[loc +1 ].claimed) +return ERR_PTR (-EBUSY ); + } + open_index = loc; + }else { +for (i =0 ; i < priv->num_net_filters; i++) { +/* Wake filter consolidates two filters to cover more bytes. +* Wake filter is open if: +* 1. It is an even filter +* 2. The current and next filter is not claimed +*/ +if (wake_filter) { +if (!(i %2 ) && (i +1 < priv->num_net_filters) && + !priv->net_filters[i].claimed && + !priv->net_filters[i +1 ].claimed) { + open_index = i; +break ; + } + }else if (!priv->net_filters[i].claimed) { + open_index = i; +break ; + } + } }if (open_index >=0 ) {
@@ -716,16 +730,20 @@ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf, nfilter->port = intf->port; nfilter->ch = intf->channel + priv->tx_chan_offset; nfilter->hw_index = open_index; - } -if (wake_filter && open_index >=0 ) { -/* Claim next filter */ - priv->net_filters[open_index +1 ].claimed = true; - priv->net_filters[open_index +1 ].wake_filter = true; - nfilter->wake_filter = true; +if (wake_filter) { +/* Claim next filter */ + priv->net_filters[open_index +1 ].claimed = true; + priv->net_filters[open_index +1 ].wake_filter = true; + priv->net_filters[open_index +1 ].hw_index = open_index +1 ; + priv->net_filters[open_index +1 ].port = intf->port; + priv->net_filters[open_index +1 ].ch = intf->channel + + priv->tx_chan_offset; + nfilter->wake_filter = true; + } } -return nfilter ? nfilter :ERR_PTR (-EINVAL ); +return nfilter ? nfilter :ERR_PTR (-ENOSPC ); } void bcmasp_netfilt_release(struct bcmasp_intf *intf,
@@ -733,7 +751,8 @@ void bcmasp_netfilt_release(struct bcmasp_intf *intf, {struct bcmasp_priv *priv = intf->parent; -if (nfilt->wake_filter) { +if (nfilt->wake_filter && !(nfilt->hw_index %2 ) && + nfilt->hw_index +1 < priv->num_net_filters) {memset (&priv->net_filters[nfilt->hw_index +1 ],0 ,sizeof (struct bcmasp_net_filter )); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1822/2151 bridge: mcast: Delete empty MDB entry when port group creation fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 1d0590f96fa4133578b7370ea9ce1d871f6bfc21 ]
When a port group cannot be created for a new group, the MDB entry that was created for it is left with no ports and is not joined by the host. Its timer is never armed, so the entry is never deleted, but it is counted towards mcast_hash_max. When this maximum is reached, the bridge disables multicast snooping.
Since commit b57e8d870d52 ("net: bridge: Maintain number of MDB entries in net_bridge_mcast_port"), port group creation also fails when the port reached its mcast_max_groups limit. A host behind such a port can therefore disable snooping by sending reports for new groups, which is what the limit is meant to prevent. The RTM_NEWMDB path has the same problem.
Fix by deleting the entry after a failure if it is unused. Delete it immediately rather than arming its timer, so that it stops counting towards the maximum right away.
--- net/bridge/br_mdb.c | 16 +++++++++++++--- net/bridge/br_multicast.c | 9 +++++++++ net/bridge/br_private.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-)
net/bridge/br_mdb.c +13 -3
@@ -819,6 +819,7 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg,struct br_mdb_config sg_cfg;struct br_ip sg_ip;u8 flags =0 ; +int err; sg_ip = cfg->group; sg_ip.src = src_ip->src;
@@ -842,7 +843,11 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg, sg_cfg.filter_mode =MCAST_INCLUDE ; sg_cfg.rt_protocol = cfg->rt_protocol; sg_cfg.nlflags = cfg->nlflags; -return br_mdb_add_group_sg (&sg_cfg, sgmp, brmctx, flags, extack); + err =br_mdb_add_group_sg (&sg_cfg, sgmp, brmctx, flags, extack); +if (err) +br_multicast_del_group (sgmp); + +return err; } static int br_mdb_add_group_src(const struct br_mdb_config *cfg,
@@ -1047,6 +1052,7 @@ static int br_mdb_add_group(const struct br_mdb_config *cfg,struct net_bridge_mcast *brmctx;struct br_ip group = cfg->group;unsigned char flags =0 ; +int err; brmctx =__br_mdb_choose_context (br, entry, extack);if (!brmctx)
@@ -1073,9 +1079,13 @@ static int br_mdb_add_group(const struct br_mdb_config *cfg, flags |=MDB_PG_FLAGS_PERMANENT ;if (br_multicast_is_star_g (&group)) -return br_mdb_add_group_star_g (cfg, mp, brmctx, flags, extack); + err =br_mdb_add_group_star_g (cfg, mp, brmctx, flags, extack);else -return br_mdb_add_group_sg (cfg, mp, brmctx, flags, extack); + err =br_mdb_add_group_sg (cfg, mp, brmctx, flags, extack); +if (err) +br_multicast_del_group (mp); + +return err; } static int __br_mdb_add(const struct br_mdb_config *cfg,
net/bridge/br_multicast.c +9 -0
@@ -647,6 +647,14 @@ static void br_multicast_del_mdb_entry(struct net_bridge_mdb_entry *mp)queue_work (system_long_wq, &br->mcast_gc_work); } +void br_multicast_del_group (struct net_bridge_mdb_entry *mp) +{ +if (mp->ports || mp->host_joined) +return ; + +br_multicast_del_mdb_entry (mp); +} +static void br_multicast_group_expired (struct timer_list *t) {struct net_bridge_mdb_entry *mp =timer_container_of (mp, t, timer);
@@ -1561,6 +1569,7 @@ __br_multicast_add_group(struct net_bridge_mcast *brmctx, p =br_multicast_new_port_group (pmctx->port, group, *pp,0 , src, filter_mode,RTPROT_KERNEL ,NULL );if (unlikely (!p)) { +br_multicast_del_group (mp); p =ERR_PTR (-ENOMEM ); goto out; }
net/bridge/br_private.h +1 -0
@@ -990,6 +990,7 @@ struct net_bridge_mdb_entry * br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);struct net_bridge_mdb_entry *br_multicast_new_group (struct net_bridge *br,struct br_ip *group); +void br_multicast_del_group (struct net_bridge_mdb_entry *mp);struct net_bridge_port_group * br_multicast_new_port_group(struct net_bridge_port *port, const struct br_ip *group,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1823/2151 net: axienet: release every RX buffer in axienet_dma_bd_release()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sagi Maimon <[email protected]>
[ Upstream commit b59787892d04a5647a7e662fbb02cd0abdb1a993 ]
The RX walk in axienet_dma_bd_release() stops at the first descriptor without an skb, assuming that such a slot and all after it were never filled. That holds on the axienet_dma_bd_init() error path, but not once the ring has been running: when axienet_rx_poll() fails to allocate or map a replacement buffer it leaves the slot it emptied with a NULL skb, in the middle of a populated ring, until a later poll refills it. Closing the interface before then leaks the skb and the streaming DMA mapping of every descriptor after that slot, which can be most of the ring, and is most likely under memory pressure.
The walk also frees each skb before unmapping it. With swiotlb, the DMA_FROM_DEVICE unmap copies the bounce buffer back into the skb data that was just freed, and on non-coherent platforms it invalidates cache lines that may already belong to a new owner.
Skip empty slots instead of stopping at the first one. An emptied slot still has a non-zero cntrl but its buffer is already unmapped, so the skip has to cover the unmap too, which it does by coming before it. Then unmap before freeing, as axienet_rx_poll() does.
This was reported by the Sashiko AI review bot.
Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes after each of ten down/up cycles, each running axienet_dma_bd_release(), so the unmap-then-free order is exercised on every buffer. A failed RX refill was not reproduced, so the skip over an empty slot was not exercised.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7 -5
@@ -245,13 +245,13 @@ static void axienet_dma_bd_release(struct net_device *ndev)for (i =0 ; i < lp->rx_bd_num; i++) {dma_addr_t phys; -/* A NULL skb means this descriptor has not been initialised -* at all. +/* A NULL skb means the descriptor holds no buffer: it was +* never filled, or axienet_rx_poll() took its skb and could +* not refill it, having already unmapped the old buffer. +* Such slots can sit anywhere in a ring that has been running. */ if (!lp->rx_bd_v[i].skb) -break ; - -dev_kfree_skb (lp->rx_bd_v[i].skb); +continue ;/* For each descriptor, we programmed cntrl with the (non-zero) * descriptor size, after it had been successfully allocated.
@@ -262,6 +262,8 @@ static void axienet_dma_bd_release(struct net_device *ndev)dma_unmap_single (lp->dev, phys, lp->max_frm_size,DMA_FROM_DEVICE ); } + +dev_kfree_skb (lp->rx_bd_v[i].skb); } dma_free_coherent(lp->dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1824/2151 ipv6: account route exceptions to the netns of their dst
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 8ff017b891e89276c15f06dfd7155981d572af77 ]
rt6_insert_exception() and rt6_remove_exception() update rt6_stats->fib_rt_cache of dev_net(rt6i->dst.dev), but the device of an exception dst can move to another netns while the exception is still in its bucket.
This happens when the bucket is flushed from an RCU callback, for instance from nexthop_free_rcu() for the nh_info of a replaced nexthop, whose exceptions still point to live routes. If the device moves to another netns before that callback runs, the decrement hits the other netns, whose u32 counter underflows in /proc/net/rt6_stats, while the counter of the original netns never goes back down.
Account exceptions to the netns their dst was allocated in, derived from dst->ops as ip6_dst_gc() already does, which does not depend on the device. The dst already relies on that netns' ip6_dst_ops being alive when it is destroyed, which happens after the exception is removed.
--- net/ipv6/route.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
net/ipv6/route.c +11 -2
@@ -1503,6 +1503,15 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,*/ static DEFINE_SPINLOCK (rt6_exception_lock); +/* Exceptions are accounted to the netns their dst was allocated in. +* Unlike dev_net(dst->dev), it does not change when the device moves to +* another netns or when dst_dev_put() points the dst to blackhole_netdev. +*/ +static struct net *rt6_exception_net (const struct rt6_info *rt) +{ + return container_of(rt->dst.ops, struct net, ipv6.ip6_dst_ops); +} +/* Remove rt6_ex from hash table and free the memory * Caller must hold rt6_exception_lock */
@@ -1514,7 +1523,7 @@ static void rt6_remove_exception(struct rt6_exception_bucket *bucket,if (!bucket || !rt6_ex)return ; - net =dev_net (rt6_ex->rt6i->dst.dev); + net =rt6_exception_net (rt6_ex->rt6i); net->ipv6.rt6_stats->fib_rt_cache--;/* purge completely the exception to allow releasing the held resources:
@@ -1779,7 +1788,7 @@ static int rt6_insert_exception(struct rt6_info *nrt, rt6_ex->stamp = jiffies;hlist_add_head_rcu (&rt6_ex->hlist, &bucket->chain); bucket->depth++; - net->ipv6.rt6_stats->fib_rt_cache++; +rt6_exception_net (nrt)->ipv6.rt6_stats->fib_rt_cache++;/* Randomize max depth to avoid some side channels attacks. */ max_depth =FIB6_MAX_DEPTH +get_random_u32_below (FIB6_MAX_DEPTH );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1825/2151 platform/x86: gpd pocket fan: Cancel work before releasing GPIOs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 9962770049c715fc30a7b3274d8f245167c0a410 ]
The fan worker changes the direction of both GPIOs and schedules its next run. Its managed cancellation action is registered before the GPIOs are acquired, so devres releases the GPIOs before cancelling the work. A running worker can therefore change a GPIO after the driver has released it.
Register the work cancellation action after both GPIO acquisitions. This makes devres cancel and drain the worker before releasing either GPIO. No work has been queued yet if GPIO acquisition or action registration fails.
This issue was identified as part of our ongoing research while reviewing kernel code.
--- drivers/platform/x86/gpd-pocket-fan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/platform/x86/gpd-pocket-fan.c +5 -4
@@ -153,10 +153,6 @@ static int gpd_pocket_fan_probe(struct platform_device *pdev)return -ENOMEM ; fan->dev = &pdev->dev; - ret =devm_delayed_work_autocancel (&pdev->dev, &fan->work, - gpd_pocket_fan_worker); -if (ret) -return ret;/* Note this returns a "weak" reference which we don't need to free */ fan->dts0 =thermal_zone_get_zone_by_name ("soc_dts0" );
@@ -175,6 +171,11 @@ static int gpd_pocket_fan_probe(struct platform_device *pdev)if (IS_ERR (fan->gpio1))return PTR_ERR (fan->gpio1); + ret =devm_delayed_work_autocancel (&pdev->dev, &fan->work, + gpd_pocket_fan_worker); +if (ret) +return ret; +gpd_pocket_fan_force_update (fan);platform_set_drvdata (pdev, fan);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1826/2151 net: phy: marvell: keep WOL_EIE across interrupt reconfiguration
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit f434191f93884c9de58c38f18ac7fc7f1fdf9e42 ]
marvell_config_intr() rewrites the whole interrupt enable register, so the config_intr call from phy_init_hw() on resume silently cleared WOL_EIE on the 88E1318S and 88E1510: m88e1318_get_wol() still reported WAKE_MAGIC, but a matched magic packet was no longer routed to INTn and the board did not wake.
Bit 7 of that register is WOL_EIE only on these two PHYs; on others, such as the 88E1111, it enables a FIFO error interrupt. So give the 88E1318S and 88E1510 their own config_intr and handle_interrupt, and leave the shared callbacks unchanged.
m88e1318_set_wol() now records whether WoL is enabled, and both it and the new config_intr derive WOL_EIE from that state under the MDIO bus lock. WOL_EIE stays set across config_intr while WoL is enabled, except when the PHY has an interrupt line and interrupts are being disabled, as in phy_free_interrupt(): INTn is then the PHY IRQ, and nothing would read IEVENT after free_irq() to release it. The bit is set again once interrupts are re-enabled. phy_probe() still clears a WOL_EIE left by a previous boot, since WoL starts out disabled. The new handler also claims WoL events, so they do not go unacknowledged when the PHY IRQ is in use.
Helios4 (Armada 388, 88E1512), 7.2.9. With this patch WOL_EIE stays set over 3 link down/up cycles, "wol d" clears it, and a magic packet on a running board is a handled interrupt. Without it, WOL_EIE is lost on the first down/up, survives "wol d", and the magic packet is an unhandled interrupt.
--- drivers/net/phy/marvell.c | 97 ++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 22 deletions(-)
drivers/net/phy/marvell.c +75 -22
@@ -55,6 +55,8 @@#define MII_M1011_IMASK 0x12#define MII_M1011_IMASK_INIT 0x6400#define MII_M1011_IMASK_CLEAR 0x0000 +/* WOL Event Interrupt Enable, 88E1318S and 88E1510 only */ +#define MII_M1011_IMASK_WOL BIT(7)#define MII_M1011_PHY_SCR 0x10#define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11)
@@ -139,11 +141,6 @@#define MII_88E1318S_PHY_MSCR1_REG 16#define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) -/* Copper Specific Interrupt Enable Register */ -#define MII_88E1318S_PHY_CSIER 0x12 -/* WOL Event Interrupt Enable */ -#define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7) -#define MII_88E1318S_PHY_LED_FUNC 0x10#define MII_88E1318S_PHY_LED_FUNC_OFF (0x8)#define MII_88E1318S_PHY_LED_FUNC_ON (0x9)
@@ -354,6 +351,7 @@ struct marvell_priv {u32 step;s8 pair;u8 vct_phase; +bool wol_enabled; };static int marvell_read_page (struct phy_device *phydev)
@@ -407,7 +405,8 @@ static int marvell_config_intr(struct phy_device *phydev)return err; } -static irqreturn_t marvell_handle_interrupt (struct phy_device *phydev) +static irqreturn_t __marvell_handle_interrupt (struct phy_device *phydev, +u16 mask) {int irq_status;
@@ -417,7 +416,7 @@ static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev)return IRQ_NONE ; } -if (!(irq_status &MII_M1011_IMASK_INIT )) +if (!(irq_status & mask))return IRQ_NONE ;phy_trigger_machine (phydev);
@@ -425,6 +424,57 @@ static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev)return IRQ_HANDLED ; } +static irqreturn_t marvell_handle_interrupt (struct phy_device *phydev) +{ +return __marvell_handle_interrupt (phydev,MII_M1011_IMASK_INIT ); +} + +/* WOL_EIE also routes WoL events to INTn. Keep it set while WoL is enabled, +* unless INTn is the PHY interrupt and that interrupt is being disabled: +* nothing would read IEVENT after free_irq() to release the line. +*/ +static u16 m88e1318_wol_imask (struct phy_device *phydev) +{ +struct marvell_priv *priv = phydev->priv; + +if (priv->wol_enabled && + (phydev->interrupts ==PHY_INTERRUPT_ENABLED || + !phy_interrupt_is_valid (phydev))) +return MII_M1011_IMASK_WOL ; + +return 0 ; +} + +static int m88e1318_config_intr (struct phy_device *phydev) +{ +bool enable = phydev->interrupts ==PHY_INTERRUPT_ENABLED ; +u16 imask; +int err; + +if (enable) { + err =marvell_ack_interrupt (phydev); +if (err) +return err; + } + +/* Serialise against m88e1318_set_wol() updating wol_enabled */ +phy_lock_mdio_bus (phydev); + imask = enable ?MII_M1011_IMASK_INIT :MII_M1011_IMASK_CLEAR ; + imask |=m88e1318_wol_imask (phydev); + err =__phy_write (phydev,MII_M1011_IMASK , imask); +phy_unlock_mdio_bus (phydev); +if (err || enable) +return err; + +return marvell_ack_interrupt (phydev); +} + +static irqreturn_t m88e1318_handle_interrupt (struct phy_device *phydev) +{ +return __marvell_handle_interrupt (phydev,MII_M1011_IMASK_INIT | +MII_M1011_IMASK_WOL ); +} +static int marvell_set_polarity (struct phy_device *phydev,int polarity) {u16 val;
@@ -1969,18 +2019,27 @@ static void m88e1318_get_wol(struct phy_device *phydev,static int m88e1318_set_wol (struct phy_device *phydev,struct ethtool_wolinfo *wol) { +struct marvell_priv *priv = phydev->priv;int err =0 , oldpage; oldpage =phy_save_page (phydev);if (oldpage <0 ) goto error; -if (wol->wolopts & (WAKE_MAGIC |WAKE_PHY )) { -/* Explicitly switch to page 0x00, just to be sure */ - err =marvell_write_page (phydev,MII_MARVELL_COPPER_PAGE ); -if (err <0 ) - goto error; + priv->wol_enabled = !!(wol->wolopts & (WAKE_MAGIC |WAKE_PHY )); + +/* Explicitly switch to page 0x00, just to be sure */ + err =marvell_write_page (phydev,MII_MARVELL_COPPER_PAGE ); +if (err <0 ) + goto error; + +/* Update the WOL interrupt enable */ + err =__phy_modify (phydev,MII_M1011_IMASK ,MII_M1011_IMASK_WOL , +m88e1318_wol_imask (phydev)); +if (err <0 ) + goto error; +if (priv->wol_enabled) {/* If WOL event happened once, the LED[2] interrupt pin * will not be cleared unless we reading the interrupt status * register. If interrupts are in use, the normal interrupt
@@ -1990,12 +2049,6 @@ static int m88e1318_set_wol(struct phy_device *phydev,if (!phy_interrupt_is_valid (phydev))__phy_read (phydev,MII_M1011_IEVENT ); -/* Enable the WOL interrupt */ - err =__phy_set_bits (phydev,MII_88E1318S_PHY_CSIER , -MII_88E1318S_PHY_CSIER_WOL_EIE ); -if (err <0 ) - goto error; - err =marvell_write_page (phydev,MII_MARVELL_LED_PAGE );if (err <0 ) goto error;
@@ -3846,8 +3899,8 @@ static struct phy_driver marvell_drivers[] = { .config_init = m88e1318_config_init, .config_aneg = m88e1318_config_aneg, .read_status = marvell_read_status, - .config_intr = marvell_config_intr, - .handle_interrupt = marvell_handle_interrupt, + .config_intr = m88e1318_config_intr, + .handle_interrupt = m88e1318_handle_interrupt, .get_wol = m88e1318_get_wol, .set_wol = m88e1318_set_wol, .resume = genphy_resume,
@@ -3954,8 +4007,8 @@ static struct phy_driver marvell_drivers[] = { .config_init = m88e1510_config_init, .config_aneg = m88e1510_config_aneg, .read_status = marvell_read_status, - .config_intr = marvell_config_intr, - .handle_interrupt = marvell_handle_interrupt, + .config_intr = m88e1318_config_intr, + .handle_interrupt = m88e1318_handle_interrupt, .get_wol = m88e1318_get_wol, .set_wol = m88e1318_set_wol, .resume = m88e1510_resume,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1827/2151 net/mlx5e: Update netdev features only after a successful ringparam set
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dimitri Daskalakis <[email protected]>
[ Upstream commit 23dd5be7e19ceab8c1c79110ee3552bcabc463ef ]
mlx5 couples HW-GRO with tcp-data-split. If a user sets rx-gro-hw on -> tcp-data-split on -> rx-gro-hw off, the driver will leave HW-GRO on. mlx5e_ethtool_set_tcp_data_split() calls netdev_update_features() when tcp-data-split goes from enabled to disabled in case HW-GRO needs to be released. mlx5e_fix_features() reads the new HDS config from dev->cfg_pending, so HW-GRO is released before all ring parameters are validated.
If the subsequent call to mlx5e_ethtool_set_ringparam() fails, the ethtool core discards the pending change and reports tcp-data-split enabled. The device is no longer splitting, and subsequent ring changes are blocked.
Move the call to netdev_update_features() aftermlx5e_ethtool_set_ringparam() exits successfully.
The issue was discovered by manual code inspection during review of a change that stops mlx5 users from disabling tcp-data-split. It was reproduced on a ConnectX-7 with ethtool alone.
Steps to reproduce:
ethtool -K eth0 rx-gro-hw on
ethtool -G eth0 tcp-data-split on
ethtool -K eth0 rx-gro-hw off # HW-GRO kept on for tcp-data-split
ethtool -G eth0 tcp-data-split off rx 1 # de-sync driver & kernel state
netlink error: mlx5_core: rx (1) < min (16)
netlink error: Invalid argument
ethtool -G eth0 rx 1024 # valid ring changes are now blocked
netlink error: mlx5_core: TCP-data-split is not supported when GRO HW is disabled netlink error: Invalid argument
This is not a terminal state, users can recover by setting rx-gro-hw on. With the fix, the failing ringparam set leaves rx-gro-hw on and later ring changes succeed.
--- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +11 -6
@@ -391,11 +391,6 @@ static bool mlx5e_ethtool_set_tcp_data_split(struct mlx5e_priv *priv,return false; } -/* Might need to disable HW-GRO if it was kept on due to hds. */ -if (tcp_data_split ==ETHTOOL_TCP_DATA_SPLIT_DISABLED && - dev->cfg->hds_config ==ETHTOOL_TCP_DATA_SPLIT_ENABLED ) -netdev_update_features (priv->netdev); -return true; }
@@ -456,13 +451,23 @@ static int mlx5e_set_ringparam(struct net_device *dev, struct netlink_ext_ack *extack) {struct mlx5e_priv *priv =netdev_priv (dev); +int err;if (!mlx5e_ethtool_set_tcp_data_split (priv, kernel_param->tcp_data_split, extack))return -EINVAL ; -return mlx5e_ethtool_set_ringparam (priv, param, extack); + err =mlx5e_ethtool_set_ringparam (priv, param, extack); +if (err) +return err; + +/* Might need to disable HW-GRO if it was kept on due to hds. */ +if (kernel_param->tcp_data_split ==ETHTOOL_TCP_DATA_SPLIT_DISABLED && + dev->cfg->hds_config ==ETHTOOL_TCP_DATA_SPLIT_ENABLED ) +netdev_update_features (priv->netdev); + +return 0 ; } void mlx5e_ethtool_get_channels(struct mlx5e_priv *priv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1828/2151 ipv6: Hold RCU when emitting route hardware flags notification
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 7c9cb1edaf8fd8e1af25e39741e603500986ef66 ]
fib6_info_hw_flags_set() is called by drivers from process context without RTNL or RCU. When the route uses a nexthop object, rt6_nlmsg_size() and rt6_fill_node() access the nexthop's RCU protected nexthop info and group pointers via rcu_dereference_rtnl(), resulting in suspicious RCU usage splats [1].
Fix by holding RCU while sizing and filling the notification, like fib_alias_hw_flags_set() already does. Switch to GFP_ATOMIC for the skb allocation accordingly.
Reproducer:
# echo "10 0" > /sys/bus/netdevsim/new_device # sysctl -wq net.ipv6.fib_notify_on_flag_change=1 # sysctl -wq net.ipv4.nexthop_compat_mode=1 # ip -6 nexthop add id 1 blackhole # ip -6 route add 2001:db8:1::1/128 nhid 1
[1]
WARNING: suspicious RCU usage 7.3.0-rc7-virtme-g191aa41548b2 #38 Not tainted net/ipv4/nexthop.c:1539 suspicious rcu_dereference_check() usage! [...]
Workqueue: events nsim_fib_event_work Call Trace: <TASK> dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120) lockdep_rcu_suspicious.cold (kernel/locking/lockdep.c:6972) nexthop_for_each_fib6_nh (net/ipv4/nexthop.c:1539 (discriminator 16)) rt6_nlmsg_size (net/ipv6/route.c:5728) fib6_info_hw_flags_set (net/ipv6/route.c:6503) nsim_fib6_rt_add (drivers/net/netdevsim/fib.c:671 drivers/net/netdevsim/fib.c:694) nsim_fib6_rt_insert (drivers/net/netdevsim/fib.c:759) nsim_fib_event_work (drivers/net/netdevsim/fib.c:856 drivers/net/netdevsim/fib.c:889 drivers/net/netdevsim/fib.c:1493) process_one_work (kernel/workqueue.c:3396) worker_thread (kernel/workqueue.c:3479 kernel/workqueue.c:3560) kthread (kernel/kthread.c:436) ret_from_fork (arch/x86/kernel/process.c:158) ret_from_fork_asm (arch/x86/entry/entry_64.S:245) </TASK>
--- net/ipv6/route.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/ipv6/route.c +6 -1
@@ -6468,7 +6468,9 @@ void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i,if (!fib_notify_on_flag_change)return ; - skb =nlmsg_new (rt6_nlmsg_size (f6i),GFP_KERNEL ); +rcu_read_lock (); + + skb =nlmsg_new (rt6_nlmsg_size (f6i),GFP_ATOMIC );if (!skb) { err = -ENOBUFS ; goto errout;
@@ -6481,10 +6483,13 @@ void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i, goto errout; } +rcu_read_unlock (); +rtnl_notify (skb, net,0 ,RTNLGRP_IPV6_ROUTE ,NULL ,GFP_KERNEL );return ; errout: +rcu_read_unlock ();rtnl_set_sk_err (net,RTNLGRP_IPV6_ROUTE , err); }EXPORT_SYMBOL (fib6_info_hw_flags_set);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1829/2151 team: reject CAN, IEEE 802.15.4 and 6LoWPAN devices in team_port_add
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 9043be310c6a4c5e57f7bba4b9870554eac7aa96 ]
When the first port has a non-Ethernet type, team_setup_by_port() copies port_dev->type to the team device while netdev_priv() of the team device still holds a struct team. Several L2 stacks identify their devices by dev->type alone and then access type specific data that the team driver never sets up:
- CAN protocols rely on the CAN mid-layer private data (ml_priv)
- IEEE 802.15.4 code dereferences ieee802154_ptr and the mlme ops in ml_priv
- the 6LoWPAN netdev notifier writes through lowpan_dev(dev) on NETDEV_DOWN and reads it on NETDEV_UP/NETDEV_CHANGE
Enslaving such a device (e.g. vxcan, wpan0, lowpan0) therefore leads to NULL pointer dereferences or to writes into struct team.
This is the same problem that syzbot reported for the bonding driver with a vxcan device enslaved to a bond master, which crashed in can_rx_unregister() and was fixed by commit 8ba68464e478 ("bonding:
refuse to enslave CAN devices"). The team driver has the same gap.
Reject ARPHRD_CAN, ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR and ARPHRD_6LOWPAN devices in team_port_add().
--- drivers/net/team/team_core.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/team/team_core.c +11 -0
@@ -1117,6 +1117,17 @@ static int team_port_add(struct team *team, struct net_device *port_dev,return -EINVAL ; } +if (port_dev->type ==ARPHRD_CAN || + port_dev->type ==ARPHRD_IEEE802154 || + port_dev->type ==ARPHRD_IEEE802154_MONITOR || + port_dev->type ==ARPHRD_6LOWPAN ) { +NL_SET_ERR_MSG (extack, +"CAN, IEEE 802.15.4 and 6LoWPAN devices can't be added as a team port" ); +netdev_err (dev,"Device %s is CAN, IEEE 802.15.4 or 6LoWPAN. These device types can't be added as a team port\n" , + portname); +return -EINVAL ; + } +if (netif_is_team_port (port_dev)) {NL_SET_ERR_MSG (extack,"Device is already a port of a team device" ); netdev_err(dev, "Device %s is already a port "
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1830/2151 net: stmmac: Track the TX DMA threshold per queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ovidiu Panait <[email protected]>
[ Upstream commit 9dd53418781900f02897c805eed397555cf98417 ]
Commit 3a6c12a0c6c3 ("net: stmmac: bump tc when get underflow error from DMA descriptor") made dwmac4 raise the DMA threshold of the queues that report TX underflows. This is done by incrementing a module global parameter 'tc' by 64 on each underflow.
This leads to inconsistent TX DMA thresholds between queues and causes issues on platforms with multiple stmmac controllers, as 'tc' is shared by all of them. Once 'tc' goes over 256 the bumping stops, and queues that did not underflow before are left at the initial threshold.
On the Renesas RZ/V2H platform, which has two dwmac4 controllers, we observed sporadic iperf3 TCP TX failures:
iperf3 -c <server> -t5 --bind-dev end1 ... [ 5] 0.00-5.00 sec 1.00 MBytes 1.68 Mbits/sec 87 sender [ 5] 0.00-5.00 sec 768 KBytes 1.26 Mbits/sec receiver
This happens because the TX queues of end1 were underflowing on a large fraction of the packets, but the DMA TX threshold was never raised from the default of 64 bytes. The threshold was not raised because end0 had underflowed first and had already pushed 'tc' past 256. Which controller is affected depends on which one underflows first.
To fix this, make the TX DMA threshold per queue instead of global. Each time an underflow happens on a queue, its TX DMA threshold gets incremented, without affecting other queues or controllers. With this change, 'tc' is only used as the initial value, and the RX threshold is no longer bumped together with the TX one, as TX underflows have nothing to do with the RX side.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
@@ -255,6 +255,7 @@ struct stmmac_priv {bool sph_capable;u32 sarc_type;u32 rx_riwt[MTL_MAX_RX_QUEUES ]; +u32 tx_threshold[MTL_MAX_TX_QUEUES ];int hwts_rx_en;void __iomem *ioaddr;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +20 -13
@@ -2399,7 +2399,6 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) }if (priv->plat->force_thresh_dma_mode) { - txmode = tc; rxmode = tc; }else if (priv->plat->force_sf_dma_mode || priv->plat->tx_coe) {/*
@@ -2413,7 +2412,6 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv) rxmode =SF_DMA_MODE ; priv->xstats.threshold =SF_DMA_MODE ; }else { - txmode = tc; rxmode =SF_DMA_MODE ; }
@@ -2442,8 +2440,11 @@ static void stmmac_dma_operation_mode(struct stmmac_priv *priv)for (chan =0 ; chan < tx_channels_count; chan++) { qmode = priv->plat->tx_queues_cfg[chan].mode_to_use; -stmmac_dma_tx_mode (priv, priv->ioaddr, txmode, chan, - txfifosz, qmode); +if (txmode ==SF_DMA_MODE ) + priv->tx_threshold[chan] =SF_DMA_MODE ; + +stmmac_dma_tx_mode (priv, priv->ioaddr, priv->tx_threshold[chan], + chan, txfifosz, qmode); } }
@@ -2622,17 +2623,20 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)static void stmmac_bump_dma_threshold (struct stmmac_priv *priv,u32 chan) { -if (unlikely (priv->xstats.threshold !=SF_DMA_MODE ) && tc <=256 ) { - tc +=64 ; +u32 thresh = priv->tx_threshold[chan]; -if (priv->plat->force_thresh_dma_mode) -stmmac_set_dma_operation_mode (priv, tc, tc, chan); -else -stmmac_set_dma_operation_mode (priv, tc,SF_DMA_MODE , - chan); +if (unlikely (thresh ==SF_DMA_MODE ) || thresh >256 ) +return ; - priv->xstats.threshold = tc; - } + thresh +=64 ; + +if (priv->plat->force_thresh_dma_mode) +stmmac_set_dma_operation_mode (priv, thresh, tc, chan); +else +stmmac_set_dma_operation_mode (priv, thresh,SF_DMA_MODE , chan); + + priv->tx_threshold[chan] = thresh; + priv->xstats.threshold = thresh; }/**
@@ -7723,6 +7727,9 @@ int stmmac_dvr_probe(struct device *device, priv->xstats.threshold = tc; +for (i =0 ; i <MTL_MAX_TX_QUEUES ; i++) + priv->tx_threshold[i] = tc; +/* Initialize RSS */ rxq = priv->plat->rx_queues_to_use;netdev_rss_key_fill (priv->rss.key,sizeof (priv->rss.key));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1831/2151 ibmveth: fix netpoll races with RX replenish
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit 8d9ecac6b96e61d0e6d126c60644829fd9f66952 ]
ibmveth_poll_controller() runs RX replenish outside NAPI and without a lock, racing NAPI's replenish on another CPU. Both can fill the same slot, so an skb and its DMA mapping leak and PHYP can write into an unmapped buffer. netpoll calls it from netconsole and from netpoll-enabled bonds.
ibmveth_open() also enables NAPI before the RX resources exist. ibmveth_change_mtu(), veth_pool_store(), ibmveth_set_csum_offload() and ibmveth_set_tso() call close() and open() directly, so while open() is still setting up, netpoll and the direct ibmveth_interrupt() calls can replenish NULL pools and read freed memory.
Remove the callback, as Eric Dumazet did for many drivers after commit ac3d9dd034e5 ("netpoll: make ndo_poll_controller() optional"), including ibmvnic in commit 0c3b9d1b37df ("ibmvnic: remove ndo_poll_controller"). netpoll then polls NAPI itself with budget 0. napi->poll_owner serializes that with NAPI, but not with a NAPI poll that was already running when netpoll was set up, so skip RX replenish at budget 0, which netpoll uses for TX only. TX completes synchronously, so ibmveth_poll() has nothing else to do for netpoll.
Enable NAPI just before request_irq(), once everything ibmveth_poll() touches exists.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection of poll_one_napi() and the direct close()/open() callers; neither race was reproduced. Tested on a POWER10 LPAR with netconsole over ibmveth: a ping flood (678,470 packets, no loss) during a printk flood, and MTU changes and buffer pool toggles under traffic, with no warnings. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +13 -15
@@ -628,8 +628,6 @@ static int ibmveth_open(struct net_device *netdev)netdev_dbg (netdev,"open starting\n" ); -napi_enable (&adapter->napi); -for (i =0 ; i <IBMVETH_NUM_BUFF_POOLS ; i++) rxq_entries += adapter->rx_buff_pool[i].size;
@@ -717,10 +715,18 @@ static int ibmveth_open(struct net_device *netdev) } } +/* NAPI can run as soon as it is enabled, from netpoll during the +* direct close()/open() pairs or from a direct ibmveth_interrupt() +* call, so enable it only once everything ibmveth_poll() touches +* exists. +*/ +napi_enable (&adapter->napi); +netdev_dbg (netdev,"registering irq 0x%x\n" , netdev->irq); rc =request_irq (netdev->irq, ibmveth_interrupt,0 , netdev->name, netdev);if (rc !=0 ) { +napi_disable (&adapter->napi);netdev_err (netdev,"unable to request irq 0x%x, rc %d\n" , netdev->irq, rc); goto out_free_buffer_pools;
@@ -765,7 +771,6 @@ static int ibmveth_open(struct net_device *netdev) out_free_buffer_list:free_page ((unsigned long )adapter->buffer_list_addr); out: -napi_disable (&adapter->napi);return rc; }
@@ -1542,7 +1547,11 @@ static int ibmveth_poll(struct napi_struct *napi, int budget) } } -ibmveth_replenish_task (adapter); +/* netpoll polls with budget 0 for TX only, and is not serialized +* with a NAPI poll that was already running when it was set up +*/ +if (budget) +ibmveth_replenish_task (adapter);if (frames_processed == budget) goto out;
@@ -1682,14 +1691,6 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)return -EINVAL ; } -#ifdef CONFIG_NET_POLL_CONTROLLER -static void ibmveth_poll_controller (struct net_device *dev) -{ -ibmveth_replenish_task (netdev_priv (dev)); -ibmveth_interrupt (dev->irq, dev); -} -#endif -/** * ibmveth_get_desired_dma - Calculate IO memory desired by the driver *
@@ -1791,9 +1792,6 @@ static const struct net_device_ops ibmveth_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_set_mac_address = ibmveth_set_mac_addr, .ndo_features_check = ibmveth_features_check, -#ifdef CONFIG_NET_POLL_CONTROLLER - .ndo_poll_controller = ibmveth_poll_controller, -#endif };static int ibmveth_probe (struct vio_dev *dev,const struct vio_device_id *id)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1832/2151 ibmveth: do not close twice after a failed reopen
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit 95811c873d1b97c424a7e6e731730cbf6656ab7e ]
ibmveth_change_mtu(), veth_pool_store(), ibmveth_set_csum_offload() and ibmveth_set_tso() call close() and open() directly. If open() fails, NAPI is left disabled while IFF_UP stays set, so the next close() (ifdown, unregister or another reconfiguration) calls napi_disable() again and waits forever with RTNL held. Networking and shutdown hang; only a reboot recovers. ethtool -L in that state also wakes queues that have no TX buffer and dereferences NULL in ibmveth_start_xmit().
Any open() failure on those paths triggers it, for example an allocation failure on an MTU change to jumbo frames.
Track a successful open in adapter->opened. close() returns early when it is clear, and set_channels() checks it instead of IFF_UP.
The open() error-path leaks were fixed separately in net by commit af0524bf4ce1 ("ibmveth: h_free logical LAN on open-fail after register") and commit 84bec0bf0352 ("ibmveth: fix TX LTB and filter unwind on open-fail"), which are now in net-next too, so a failed open() no longer leaves TX buffers or the logical LAN registration behind for the early return to skip.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection. Tested on a POWER10 LPAR with ibmveth_open() forced to fail by a test-only module parameter (not part of this patch): 'ip link set dev eth1 mtu 9000' fails, then 'ip link set dev eth1 down' returns at once and 'ip link set dev eth1 up' recovers the interface. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 24 +++++++++++++++++------- drivers/net/ethernet/ibm/ibmveth.h | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +17 -7
@@ -739,6 +739,7 @@ static int ibmveth_open(struct net_device *netdev)netif_tx_start_all_queues (netdev); + adapter->opened = true;netdev_dbg (netdev,"open complete\n" );return 0 ;
@@ -781,6 +782,14 @@ static int ibmveth_close(struct net_device *netdev)long lpar_rc;int i; +/* change_mtu, pool sysfs, set_csum and set_tso call close() and +* open() directly. If that open() fails, IFF_UP stays set and +* NAPI is disabled; a second close() would hang in napi_disable(). +*/ +if (!adapter->opened) +return 0 ; + adapter->opened = false; +netdev_dbg (netdev,"close starting\n" );napi_disable (&adapter->napi);
@@ -832,10 +841,10 @@ static int ibmveth_close(struct net_device *netdev)* * @w: pointer to work_struct embedded in adapter structure * -* Context: This routine acquires rtnl_mutex and disables its NAPI through -* ibmveth_close. It can't be called directly in a context that has -* already acquired rtnl_mutex or disabled its NAPI, or directly from -* a poll routine. +* Context: This routine acquires rtnl_mutex and, if the device is open, +* disables its NAPI through ibmveth_close. It can't be called +* directly in a context that has already acquired rtnl_mutex or +* disabled its NAPI, or directly from a poll routine. * * Return: void */
@@ -1129,10 +1138,11 @@ static int ibmveth_set_channels(struct net_device *netdev, goal = channels->tx_count;int rc, i; -/* If ndo_open has not been called yet then don't allocate, just set -* desired netdev_queue's and return +/* If the device is not open (including a failed close/open with +* IFF_UP still set) then don't allocate, just set desired +* netdev_queue's and return */ -if (!(netdev->flags &IFF_UP )) +if (!adapter->opened)return netif_set_real_num_tx_queues (netdev, goal);/* We have IBMVETH_MAX_QUEUES netdev_queue's allocated
drivers/net/ethernet/ibm/ibmveth.h +2 -0
@@ -172,6 +172,8 @@ struct ibmveth_adapter {int rx_csum;int large_send;bool is_active_trunk; +/* Set by a successful ibmveth_open(), cleared by ibmveth_close(). */ +bool opened;unsigned int rx_buffers_per_hcall;u64 fw_ipv6_csum_support;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1833/2151 ibmveth: disable the reset work before unregister in remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit 1412235447869922eb0ee041a31fab6176e60ab0 ]
ibmveth_remove() cancels the reset work before unregister_netdev(), but NAPI keeps running until unregister closes the device and can queue the reset again, on an interrupt enable failure, a bad free_map entry or a bad RX slot. The reset can then run on the adapter after free_netdev(), or reopen the device during unregister.
Use disable_work_sync(), which waits for a running reset and keeps the work from being queued again. A bad RX slot also makes poll spin, which can stall unregister; a later patch in this series fixes that.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; it was not reproduced. Tested on a POWER10 LPAR with unbind and bind cycles under traffic. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ibm/ibmveth.c +1 -1
@@ -1956,7 +1956,7 @@ static void ibmveth_remove(struct vio_dev *dev)struct ibmveth_adapter *adapter =netdev_priv (netdev);int i; -cancel_work_sync (&adapter->work); +disable_work_sync (&adapter->work);for (i =0 ; i <IBMVETH_NUM_BUFF_POOLS ; i++)kobject_put (&adapter->rx_buff_pool[i].kobj);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1834/2151 ibmveth: step past bad RX correlators instead of spinning or oopsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit c9b95adc755f2396307be676ce838161fb011986 ]
ibmveth_poll() mishandles a bad RX correlator from PHYP in two ways.
If harvest fails or ibmveth_rxq_get_buffer() returns NULL, poll breaks out without advancing the ring and restarts on the same slot forever. For an out-of-range correlator it also fires a WARN_ON() and schedules a reset each pass, but the reset is queued on that CPU and never runs, and the CPU stalls RCU, so RTNL holders hang too. This dates from the first commit in Fixes:, which turned the BUG_ON()s here into WARN_ON() plus a reset.
The range check also accepts a correlator naming an inactive buffer pool (pools 2 and 3 by default), whose skbuff array is NULL, so the lookup dereferences NULL in softirq. Pools became inactive with the second commit in Fixes:.
Validate the correlator in one helper that also rejects a pool with no skbuff array. On a bad slot, advance the ring, count the drop in rx_dropped and still schedule the reset, which rebuilds the pools. The slot has moved, so stay in the budget loop and count it in frames_processed. Breaking out would complete NAPI, re-arm, and napi_schedule() with budget left. When the final check finds more work, queue the NAPI and return instead of going back torestart_poll: after napi_complete_done() the NAPI is no longer this call's, and with threaded NAPI and busy polling the kthread can already be polling it on another CPU. frames_processed is below budget there, so busy_poll_stop() does not queue it a second time. Mask the interrupt before queueing, as ibmveth_interrupt() does; masking after napi_schedule() could land after that kthread has finished and unmasked, leaving RX masked with nothing scheduled.
Drop a frame whose offset + length does not fit the pool buffer:
copybreak would read past the RX buffer and skb_put() would BUG(). Also drop one shorter than an Ethernet header, which eth_type_trans() would read past. Read the correlator once per slot and use that value for the lookup, the bound and the harvest.
The base driver never checked frame bounds, and they have not been seen in the field, so they have no Fixes: tag of their own. The tags below are for the correlator hang.
The correlator comes from PHYP, and with the ring advancing a burst of bad slots would WARN once per slot (and panic with panic_on_warn), so use a ratelimited netdev_err() instead. Also free the rx_copybreak skb if harvest fails there.
Add a KUnit case for harvest advancing on errors and extend the existing cases to an inactive pool. Run against the unfixed driver, with the calls changed back to its signatures, the first fails and the others oops.
Found in review of the ibmveth multi-queue RX series (the frame bound by the Sashiko review of v2 of this series) and confirmed by code inspection and the KUnit cases above. Hitting either correlator bug needs PHYP to return a bad correlator, so neither was reproduced on hardware. Tested with KUnit on qemu pseries (ppc64le), and on a POWER10 LPAR with a ping flood and MTU changes under traffic. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 265 +++++++++++++++++++++++------ 1 file changed, 216 insertions(+), 49 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +216 -49
@@ -135,6 +135,13 @@ static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)return be32_to_cpu (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length); } +static u64 ibmveth_rxq_correlator (struct ibmveth_adapter *adapter) +{ +unsigned int idx = adapter->rx_queue.index; + +return READ_ONCE (adapter->rx_queue.queue_addr[idx].correlator); +} +static inline int ibmveth_rxq_csum_good (struct ibmveth_adapter *adapter) {return ibmveth_rxq_flags (adapter) &IBMVETH_RXQ_CSUM_GOOD ;
@@ -443,6 +450,37 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, } } +/* The correlator comes back from PHYP; a bad one schedules a reset. */ +static bool ibmveth_rxq_correlator_valid (struct ibmveth_adapter *adapter, +u64 correlator) +{ +unsigned int index = correlator &0xffffffffUL ; +unsigned int pool = correlator >>32 ; + +/* An inactive pool keeps its size but has no skbuff array. */ +if (pool <IBMVETH_NUM_BUFF_POOLS && + index < adapter->rx_buff_pool[pool].size && + adapter->rx_buff_pool[pool].skbuff) +return true; + +if (net_ratelimit ()) +netdev_err (adapter->netdev, +"invalid RX correlator %llx, resetting\n" , + correlator); +schedule_work (&adapter->work); +return false; +} + +static void ibmveth_rxq_no_skb (struct ibmveth_adapter *adapter, +u64 correlator) +{ +if (net_ratelimit ()) +netdev_err (adapter->netdev, +"no buffer for RX correlator %llx, resetting\n" , + correlator); +schedule_work (&adapter->work); +} +/** * ibmveth_remove_buffer_from_pool - remove a buffer from a pool * @adapter: adapter instance
@@ -451,7 +489,8 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter,* * Return: * * %0 - success -* * %-EINVAL - correlator maps to pool or index out of range +* * %-EINVAL - correlator maps to pool or index out of range, or to an +* inactive pool * * %-EFAULT - pool and index map to null skb */ static int ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter,
@@ -462,15 +501,12 @@ static int ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter,unsigned int free_index;struct sk_buff *skb; -if (WARN_ON (pool >=IBMVETH_NUM_BUFF_POOLS ) || -WARN_ON (index >= adapter->rx_buff_pool[pool].size)) { -schedule_work (&adapter->work); +if (!ibmveth_rxq_correlator_valid (adapter, correlator))return -EINVAL ; - } skb = adapter->rx_buff_pool[pool].skbuff[index]; -if (WARN_ON (!skb)) { -schedule_work (&adapter->work); +if (!skb) { +ibmveth_rxq_no_skb (adapter, correlator);return -EFAULT ; }
@@ -504,51 +540,56 @@ static int ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter,return 0 ; } -/* get the current buffer on the rx queue */ -static inline struct sk_buff *ibmveth_rxq_get_buffer (struct ibmveth_adapter *adapter) +/* get the buffer for @correlator, read once from the current rx queue entry */ +static struct sk_buff *ibmveth_rxq_get_buffer (struct ibmveth_adapter *adapter, +u64 correlator) { -u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;unsigned int pool = correlator >>32 ;unsigned int index = correlator &0xffffffffUL ; +struct sk_buff *skb; -if (WARN_ON (pool >=IBMVETH_NUM_BUFF_POOLS ) || -WARN_ON (index >= adapter->rx_buff_pool[pool].size)) { -schedule_work (&adapter->work); +if (!ibmveth_rxq_correlator_valid (adapter, correlator))return NULL ; - } -return adapter->rx_buff_pool[pool].skbuff[index]; + skb = adapter->rx_buff_pool[pool].skbuff[index]; +if (!skb) +ibmveth_rxq_no_skb (adapter, correlator); +return skb; +} + +static void ibmveth_rxq_advance (struct ibmveth_adapter *adapter) +{ +if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) { + adapter->rx_queue.index =0 ; + adapter->rx_queue.toggle = !adapter->rx_queue.toggle; + } }/** * ibmveth_rxq_harvest_buffer - Harvest buffer from pool * -* @adapter: pointer to adapter -* @reuse: whether to reuse buffer +* @adapter: pointer to adapter +* @correlator: correlator of the current rx queue entry, as read by poll +* @reuse: whether to reuse buffer * * Context: called from ibmveth_poll * +* The ring advances even on error, so poll does not return to a bad +* slot before the scheduled reset can run. +* * Return: * * %0 - success * * other - non-zero return from ibmveth_remove_buffer_from_pool */ static int ibmveth_rxq_harvest_buffer (struct ibmveth_adapter *adapter, -bool reuse) +u64 correlator,bool reuse) { -u64 cor;int rc; - cor = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator; - rc =ibmveth_remove_buffer_from_pool (adapter, cor, reuse); -if (unlikely (rc)) -return rc; + rc =ibmveth_remove_buffer_from_pool (adapter, correlator, reuse); +ibmveth_rxq_advance (adapter); -if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) { - adapter->rx_queue.index =0 ; - adapter->rx_queue.toggle = !adapter->rx_queue.toggle; - } - -return 0 ; +return rc; }static void ibmveth_free_tx_ltb (struct ibmveth_adapter *adapter,int idx)
@@ -1469,31 +1510,60 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)struct net_device *netdev = adapter->netdev;int frames_processed =0 ;unsigned long lpar_rc; +u64 correlator;u16 mss =0 ; +int rc; -restart_poll:while (frames_processed < budget) {if (!ibmveth_rxq_pending_buffer (adapter))break ;smp_rmb (); + correlator =ibmveth_rxq_correlator (adapter);if (!ibmveth_rxq_buffer_valid (adapter)) {wmb ();/* suggested by larson1 */ adapter->rx_invalid_buffer++;netdev_dbg (netdev,"recycling invalid buffer\n" ); -if (unlikely (ibmveth_rxq_harvest_buffer (adapter, true))) -break ; + rc =ibmveth_rxq_harvest_buffer (adapter, correlator, true); +if (unlikely (rc)) { + netdev->stats.rx_dropped++; + frames_processed++; +continue ; + } }else {struct sk_buff *skb, *new_skb;int length =ibmveth_rxq_frame_length (adapter);int offset =ibmveth_rxq_frame_offset (adapter);int csum_good =ibmveth_rxq_csum_good (adapter);int lrg_pkt =ibmveth_rxq_large_packet (adapter); +unsigned int pool, room, off, len;__sum16 iph_check =0 ; - skb =ibmveth_rxq_get_buffer (adapter); -if (unlikely (!skb)) -break ; + skb =ibmveth_rxq_get_buffer (adapter, correlator); +if (unlikely (!skb)) { +ibmveth_rxq_advance (adapter); + netdev->stats.rx_dropped++; + frames_processed++; +continue ; + } + + pool = correlator >>32 ; + room = min_t(unsigned int, skb_tailroom(skb), + adapter->rx_buff_pool[pool].buff_size); + off = offset; + len = length; +if (unlikely (len <ETH_HLEN || off >= room || + len > room - off)) { +if (net_ratelimit ()) +netdev_err (netdev, +"bad RX frame offset %u length %u (buffer %u), dropping\n" , + off, len, room); +ibmveth_rxq_harvest_buffer (adapter, correlator, + true); + netdev->stats.rx_dropped++; + frames_processed++; +continue ; + }/* if the large packet bit is set in the rx queue * descriptor, the mss will be written by PHYP eight
@@ -1517,12 +1587,25 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)if (rx_flush)ibmveth_flush_buffer (skb->data, length + offset); -if (unlikely (ibmveth_rxq_harvest_buffer (adapter, true))) -break ; + rc =ibmveth_rxq_harvest_buffer (adapter, + correlator, + true); +if (unlikely (rc)) { +dev_kfree_skb_any (new_skb); + netdev->stats.rx_dropped++; + frames_processed++; +continue ; + } skb = new_skb; }else { -if (unlikely (ibmveth_rxq_harvest_buffer (adapter, false))) -break ; + rc =ibmveth_rxq_harvest_buffer (adapter, + correlator, + false); +if (unlikely (rc)) { + netdev->stats.rx_dropped++; + frames_processed++; +continue ; + }skb_reserve (skb, offset); }
@@ -1578,10 +1661,13 @@ static int ibmveth_poll(struct napi_struct *napi, int budget) goto out; } -if (ibmveth_rxq_pending_buffer (adapter) &&napi_schedule (napi)) { +/* Mask before queueing, as ibmveth_interrupt() does: a threaded +* NAPI can start polling, and unmask, as soon as it is queued. +*/ +if (ibmveth_rxq_pending_buffer (adapter) &&napi_schedule_prep (napi)) { lpar_rc =h_vio_signal (adapter->vdev->unit_address,VIO_IRQ_DISABLE ); - goto restart_poll; +__napi_schedule (napi); } out:
@@ -2206,8 +2292,7 @@ static void ibmveth_reset_kunit(struct work_struct *w)* @test: pointer to kunit structure * * Tests the error returns from ibmveth_remove_buffer_from_pool. -* ibmveth_remove_buffer_from_pool also calls WARN_ON, so dmesg should be -* checked to see that these warnings happened. +* Each error also logs a ratelimited netdev_err. * * Return: void */
@@ -2216,6 +2301,7 @@ static void ibmveth_remove_buffer_from_pool_test(struct kunit *test)struct ibmveth_adapter *adapter =kunit_kzalloc (test,sizeof (*adapter),GFP_KERNEL );struct ibmveth_buff_pool *pool;u64 correlator; +int ret;KUNIT_ASSERT_NOT_ERR_OR_NULL (test, adapter);
@@ -2239,6 +2325,13 @@ static void ibmveth_remove_buffer_from_pool_test(struct kunit *test)KUNIT_EXPECT_EQ (test, -EINVAL ,ibmveth_remove_buffer_from_pool (adapter, correlator, false));KUNIT_EXPECT_EQ (test, -EINVAL ,ibmveth_remove_buffer_from_pool (adapter, correlator, true)); +/* Pool 2 is in range but has no skbuff array, like an inactive pool. */ + correlator = ((u64 )2 <<32 ) |0 ; + ret =ibmveth_remove_buffer_from_pool (adapter, correlator, false); +KUNIT_EXPECT_EQ (test, -EINVAL , ret); + ret =ibmveth_remove_buffer_from_pool (adapter, correlator, true); +KUNIT_EXPECT_EQ (test, -EINVAL , ret); + correlator = (u64 )0 |0 ; pool->skbuff[0 ] =NULL ;KUNIT_EXPECT_EQ (test, -EFAULT ,ibmveth_remove_buffer_from_pool (adapter, correlator, false));
@@ -2251,9 +2344,8 @@ static void ibmveth_remove_buffer_from_pool_test(struct kunit *test)* ibmveth_rxq_get_buffer_test - unit test for ibmveth_rxq_get_buffer * @test: pointer to kunit structure * -* Tests ibmveth_rxq_get_buffer. ibmveth_rxq_get_buffer also calls WARN_ON for -* the NULL returns, so dmesg should be checked to see that these warnings -* happened. +* Tests ibmveth_rxq_get_buffer. Each NULL return also logs a ratelimited +* netdev_err. * * Return: void */
@@ -2262,6 +2354,7 @@ static void ibmveth_rxq_get_buffer_test(struct kunit *test)struct ibmveth_adapter *adapter =kunit_kzalloc (test,sizeof (*adapter),GFP_KERNEL );struct sk_buff *skb =kunit_kzalloc (test,sizeof (*skb),GFP_KERNEL );struct ibmveth_buff_pool *pool; +u64 cor;KUNIT_ASSERT_NOT_ERR_OR_NULL (test, adapter);KUNIT_ASSERT_NOT_ERR_OR_NULL (test, skb);
@@ -2285,14 +2378,87 @@ static void ibmveth_rxq_get_buffer_test(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, pool->skbuff); adapter->rx_queue.queue_addr[0 ].correlator = (u64 )IBMVETH_NUM_BUFF_POOLS <<32 |0 ; -KUNIT_EXPECT_PTR_EQ (test,NULL ,ibmveth_rxq_get_buffer (adapter)); + cor =ibmveth_rxq_correlator (adapter); +KUNIT_EXPECT_PTR_EQ (test,NULL , +ibmveth_rxq_get_buffer (adapter, cor)); adapter->rx_queue.queue_addr[0 ].correlator = (u64 )0 <<32 | adapter->rx_buff_pool[0 ].size; -KUNIT_EXPECT_PTR_EQ (test,NULL ,ibmveth_rxq_get_buffer (adapter)); + cor =ibmveth_rxq_correlator (adapter); +KUNIT_EXPECT_PTR_EQ (test,NULL , +ibmveth_rxq_get_buffer (adapter, cor)); + +/* Pool 2 is in range but has no skbuff array, like an inactive pool. */ + adapter->rx_queue.queue_addr[0 ].correlator = (u64 )2 <<32 |0 ; + cor =ibmveth_rxq_correlator (adapter); +KUNIT_EXPECT_PTR_EQ (test,NULL , +ibmveth_rxq_get_buffer (adapter, cor)); pool->skbuff[0 ] = skb; adapter->rx_queue.queue_addr[0 ].correlator = (u64 )0 <<32 |0 ; -KUNIT_EXPECT_PTR_EQ (test, skb,ibmveth_rxq_get_buffer (adapter)); + cor =ibmveth_rxq_correlator (adapter); +KUNIT_EXPECT_PTR_EQ (test, skb, +ibmveth_rxq_get_buffer (adapter, cor)); + +flush_work (&adapter->work); +} + +/** +* ibmveth_rxq_harvest_buffer_test - unit test for ibmveth_rxq_harvest_buffer +* @test: pointer to kunit structure +* +* A bad correlator must still advance the RX ring, wrapping and flipping +* the toggle at the end. This covers the harvest path; the advance after +* ibmveth_rxq_get_buffer() fails in ibmveth_poll() is not tested here. +* +* Return: void +*/ +static void ibmveth_rxq_harvest_buffer_test (struct kunit *test) +{ +struct ibmveth_adapter *adapter; +struct ibmveth_buff_pool *pool; +u64 cor; +int ret; + + adapter =kunit_kzalloc (test,sizeof (*adapter),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, adapter); + +INIT_WORK (&adapter->work, ibmveth_reset_kunit); + + adapter->rx_queue.num_slots =2 ; + adapter->rx_queue.index =0 ; + adapter->rx_queue.toggle =1 ; + adapter->rx_queue.queue_addr = +kunit_kcalloc (test,2 ,sizeof (struct ibmveth_rx_q_entry ), +GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, adapter->rx_queue.queue_addr); + +/* Set sane values for buffer pools */ +for (int i =0 ; i <IBMVETH_NUM_BUFF_POOLS ; i++) +ibmveth_init_buffer_pool (&adapter->rx_buff_pool[i], i, + pool_count[i], pool_size[i], + pool_active[i]); + + pool = &adapter->rx_buff_pool[0 ]; + pool->skbuff =kunit_kcalloc (test, pool->size,sizeof (void *), +GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, pool->skbuff); + +/* Slot 0: pool out of range. Slot 1: valid, but no skb. */ + adapter->rx_queue.queue_addr[0 ].correlator = + (u64 )IBMVETH_NUM_BUFF_POOLS <<32 |0 ; + adapter->rx_queue.queue_addr[1 ].correlator = (u64 )0 <<32 |0 ; + + cor =ibmveth_rxq_correlator (adapter); + ret =ibmveth_rxq_harvest_buffer (adapter, cor, true); +KUNIT_EXPECT_EQ (test, -EINVAL , ret); +KUNIT_EXPECT_EQ (test,1ULL , adapter->rx_queue.index); +KUNIT_EXPECT_EQ (test,1ULL , adapter->rx_queue.toggle); + + cor =ibmveth_rxq_correlator (adapter); + ret =ibmveth_rxq_harvest_buffer (adapter, cor, true); +KUNIT_EXPECT_EQ (test, -EFAULT , ret); +KUNIT_EXPECT_EQ (test,0ULL , adapter->rx_queue.index); +KUNIT_EXPECT_EQ (test,0ULL , adapter->rx_queue.toggle);flush_work (&adapter->work); }
@@ -2300,6 +2466,7 @@ static void ibmveth_rxq_get_buffer_test(struct kunit *test)static struct kunit_case ibmveth_test_cases[] = {KUNIT_CASE (ibmveth_remove_buffer_from_pool_test),KUNIT_CASE (ibmveth_rxq_get_buffer_test), +KUNIT_CASE (ibmveth_rxq_harvest_buffer_test), {} };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1835/2151 ibmveth: release the pool kobjects when probe fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit fd052c6823b31eb45f824660567ab3f2da2d5195 ]
If register_netdev() fails in ibmveth_probe(), for example with -EINTR when the binding task is killed, probe frees the netdev but leaves the pool%d kobjects embedded in it registered in sysfs. Reading /sys/devices/vio/<unit>/pool0/num is then a use-after-free, and the next probe cannot add pool0.
Put the kobjects before freeing the netdev, as ibmveth_remove() does, on this path and on the netif_set_real_num_tx_queues() one.
The kobjects also have no release(). With CONFIG_DEBUG_KOBJECT_RELEASE, kobject_put() defers their cleanup, including removing the sysfs files, to a work item, so free_netdev() can free them first, here and in remove(). Add a release() that signals a per-pool completion, and wait for it in both places before free_netdev(). Without that config, release() runs from kobject_put() and the wait returns at once.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; the release() part was raised by the Sashiko review of the first version. Tested on a POWER10 LPAR with register_netdev() forced to fail with -EINTR by a test-only module parameter (not part of this patch): no pool%d directories remain and the device binds again. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 52 +++++++++++++++++++++++++----- drivers/net/ethernet/ibm/ibmveth.h | 3 ++ 2 files changed, 47 insertions(+), 8 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +44 -8
@@ -1890,6 +1890,40 @@ static const struct net_device_ops ibmveth_netdev_ops = { .ndo_features_check = ibmveth_features_check, }; +/** +* ibmveth_pool_kobj_release - Mark a pool kobject finished +* @kobj: kobject embedded in the pool +* +* The pool kobjects live in netdev_priv(), so the last put must wait +* for this before free_netdev(). +*/ +static void ibmveth_pool_kobj_release (struct kobject *kobj) +{ +struct ibmveth_buff_pool *pool =container_of (kobj, + struct ibmveth_buff_pool, + kobj); + +complete (&pool->released); +} + +/** +* ibmveth_put_pool_kobjs - Drop the pool kobjects and wait for release +* @adapter: ibmveth adapter +* +* With CONFIG_DEBUG_KOBJECT_RELEASE the cleanup, including removing the +* sysfs files, runs later from a work item in the kobject; wait for it +* so free_netdev() cannot free the pools first. +*/ +static void ibmveth_put_pool_kobjs (struct ibmveth_adapter *adapter) +{ +int i; + +for (i =0 ; i <IBMVETH_NUM_BUFF_POOLS ; i++) +kobject_put (&adapter->rx_buff_pool[i].kobj); +for (i =0 ; i <IBMVETH_NUM_BUFF_POOLS ; i++) +wait_for_completion (&adapter->rx_buff_pool[i].released); +} +static int ibmveth_probe (struct vio_dev *dev,const struct vio_device_id *id) {int rc, i, mac_len;
@@ -2000,6 +2034,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)ibmveth_init_buffer_pool (&adapter->rx_buff_pool[i], i, pool_count[i], pool_size[i], pool_active[i]); +init_completion (&adapter->rx_buff_pool[i].released); error =kobject_init_and_add (kobj, &ktype_veth_pool, &dev->dev.kobj,"pool%d" , i);if (!error)
@@ -2011,8 +2046,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)if (rc) {netdev_dbg (netdev,"failed to set number of tx queues rc=%d\n" , rc); -free_netdev (netdev); -return rc; + goto err_put_pools; } adapter->tx_ltb_size =PAGE_ALIGN (IBMVETH_MAX_TX_BUF_SIZE );for (i =0 ; i <IBMVETH_MAX_QUEUES ; i++)
@@ -2027,25 +2061,27 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)if (rc) {netdev_dbg (netdev,"failed to register netdev rc=%d\n" , rc); -free_netdev (netdev); -return rc; + goto err_put_pools; }netdev_dbg (netdev,"registered\n" );return 0 ; + +err_put_pools: +ibmveth_put_pool_kobjs (adapter); +free_netdev (netdev); +return rc; }static void ibmveth_remove (struct vio_dev *dev) {struct net_device *netdev =dev_get_drvdata (&dev->dev);struct ibmveth_adapter *adapter =netdev_priv (netdev); -int i;disable_work_sync (&adapter->work); -for (i =0 ; i <IBMVETH_NUM_BUFF_POOLS ; i++) -kobject_put (&adapter->rx_buff_pool[i].kobj); +ibmveth_put_pool_kobjs (adapter);unregister_netdev (netdev);
@@ -2221,7 +2257,7 @@ static const struct sysfs_ops veth_pool_ops = { };static struct kobj_type ktype_veth_pool = { - .release =NULL , + .release = ibmveth_pool_kobj_release, .sysfs_ops = &veth_pool_ops, .default_groups = veth_pool_groups, };
drivers/net/ethernet/ibm/ibmveth.h +3 -0
@@ -14,6 +14,8 @@#ifndef _IBMVETH_H#define _IBMVETH_H +#include <linux/completion.h> +/* constants for H_MULTICAST_CTRL */ #define IbmVethMcastReceptionModifyBit 0x80000UL#define IbmVethMcastReceptionEnableBit 0x20000UL
@@ -143,6 +145,7 @@ struct ibmveth_buff_pool {struct sk_buff **skbuff;int active;struct kobject kobj; +struct completion released; };struct ibmveth_rx_q {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1836/2151 ibmveth: return the error when set_channels cannot add TX queues
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit 16abfa871dc840e55f1726408c5994c66a9773e2 ]
When ibmveth_set_channels() cannot allocate a TX buffer for a new queue, it falls back to the old queue count, and the successful netif_set_real_num_tx_queues() call then overwrites rc. ethtool -L reports success while the queue count is unchanged.
Return the allocation error when the fallback succeeds.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection. Tested on a POWER10 LPAR with the TX buffer allocation forced to fail by a test-only module parameter (not part of this patch):
ethtool -L tx 8 now fails with -ENOMEM and the device keeps its four queues and passes traffic. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/ibm/ibmveth.c +4 -1
@@ -1177,7 +1177,7 @@ static int ibmveth_set_channels(struct net_device *netdev,struct ibmveth_adapter *adapter =netdev_priv (netdev);unsigned int old = netdev->real_num_tx_queues, goal = channels->tx_count; -int rc, i; +int rc, i, alloc_rc =0 ;/* If the device is not open (including a failed close/open with * IFF_UP still set) then don't allocate, just set desired
@@ -1203,6 +1203,7 @@ static int ibmveth_set_channels(struct net_device *netdev,/* if something goes wrong, free everything we just allocated */ netdev_err (netdev,"Failed to allocate more tx queues, returning to %d queues\n" , old); + alloc_rc = rc; goal = old; old = i;break ;
@@ -1213,6 +1214,8 @@ static int ibmveth_set_channels(struct net_device *netdev, old); goal = old; old = i; + }else if (alloc_rc) { + rc = alloc_rc; }/* Free any that are no longer needed */ for (i = old; i > goal; i--) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1837/2151 ibmveth: wait for in-flight transmits in ibmveth_close()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit c807573ea58e615339a9c72675c45c157ffe245c ]
ibmveth_close() frees the TX buffers after netif_tx_stop_all_queues(), which does not wait for an ibmveth_start_xmit() already running on another CPU. That transmit can copy into a freed buffer and hand PHYP a stale DMA address.
MTU, csum/TSO and buffer pool changes call ibmveth_close() directly while traffic flows. ifdown and the reset work go through dev_close(), which waits for running transmits only when the qdisc has an enqueue function, so with noqueue they race the same way.
Use netif_tx_disable(), which waits for running transmits.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; the race was not reproduced. Tested on a POWER10 LPAR with MTU changes during a ping flood, with no warnings. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ibm/ibmveth.c +1 -1
@@ -835,7 +835,7 @@ static int ibmveth_close(struct net_device *netdev)napi_disable (&adapter->napi); -netif_tx_stop_all_queues (netdev); +netif_tx_disable (netdev);h_vio_signal (adapter->vdev->unit_address,VIO_IRQ_DISABLE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1838/2151 ibmveth: wait for the RX poll to return before freeing the RX queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit 3f872b34368c7c1d2a8900950e0fee4cb4dd9a34 ]
napi_disable() returns once ibmveth_poll() has called napi_complete_done(), but the poll is not finished: it then re-enables the interrupt and calls ibmveth_rxq_pending_buffer(), which reads the RX queue. ibmveth_close() can free that queue in the meantime, and the late enable can leave the interrupt unmasked after close() masked it. The request_irq() failure path in ibmveth_open() frees the same memory after napi_disable() too.
Call synchronize_net() after napi_disable() on both paths. Every caller of ibmveth_poll() runs it with bottom halves or interrupts disabled, so this waits for the poll to return.
Found in review of the ibmveth multi-queue RX series and confirmed by code inspection; also raised by the Sashiko review of the first version of this series. The race was not reproduced. Tested on a POWER10 LPAR under an incoming ping flood with 30 rapid link down/up cycles and 30 rapid MTU cycles (1500 <-> 9000); ran cleanly with no warnings or faults. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +6 -0
@@ -768,6 +768,7 @@ static int ibmveth_open(struct net_device *netdev) netdev);if (rc !=0 ) {napi_disable (&adapter->napi); +synchronize_net ();netdev_err (netdev,"unable to request irq 0x%x, rc %d\n" , netdev->irq, rc); goto out_free_buffer_pools;
@@ -834,6 +835,11 @@ static int ibmveth_close(struct net_device *netdev)netdev_dbg (netdev,"close starting\n" );napi_disable (&adapter->napi); +/* napi_disable() returns once ibmveth_poll() has called +* napi_complete_done(), but the poll still re-enables the +* interrupt and reads the RX queue after that. +*/ +synchronize_net ();netif_tx_disable (netdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1839/2151 ibmveth: check headers in the RX large send and checksum helpers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingming Cao <[email protected]>
[ Upstream commit 9486c89a8e157cedecfb561c3d86053e654d32ab ]
ibmveth_rx_mss_helper() and ibmveth_rx_csum_helper() trust the IP and TCP headers of received frames, which come from another partition on the virtual LAN.
The worst case is an IPv4 frame with ihl 0 and iph->check 0xffff: the checksum helper calls ip_fast_csum(iph, 0), and the ppc64 version loops ihl - 1 times on an unsigned count, reading up to 16 GiB in
softirq: a long stall, or an oops once the read leaves mapped memory. Both helpers also read and write header fields past the end of a short frame. The large send helper takes the segment size from the TCP checksum field and gso_segs from a TCP header length it never checks, and treats an IPv4 TCP fragment as a large send, which can zero two of its bytes; the checksum helper can write a checksum into a later fragment's payload.
The ihl problem dates from the first commit in Fixes:, the large send helper from the second, and the checksum helper from the third.
Before using a header, check that it fits the frame, that the IPv4 ihl is at least 5, and that an IPv4 TCP frame is not a fragment. In the large send helper, also require a TCP doff of at least 5, TCP payload within the IP length, and an IP length equal to the frame length:
Ethernet padding or other bytes past the IP length would otherwise stay in a bridged or switched frame, which the stack does not trim, and be segmented but not counted in gso_segs. Compute gso_segs from the IP length, and keep the segment size at or above TCP_MIN_GSO_SIZE, as virtio_net_hdr_to_skb() does since commit c27c449d455a ("virtio-net:
Ensure that TCP packets don't overflow gso_segs"), and below GSO_BY_FRAGS, which virtio rejects. With the headers checked and gso_segs computed, the skb is not marked SKB_GSO_DODGY, which would also keep it from hardware TSO on the egress device.
A frame that fails a check is passed up unchanged, without the GSO fields or CHECKSUM_UNNECESSARY, so nothing downstream trusts its segment count or checksum. The skb is linear, so the checks use skb_headlen(); pskb_may_pull() could reallocate the head under the helpers' header pointers.
Add KUnit cases for both helpers: valid IPv4 and IPv6 large sends, the segment size clamp, and refused frames. With any one of the ihl, doff, IP length, TCP payload, fragment or clamp checks, or the checksum helper's IPv4 options, IPv6 header or TCP header length checks, removed, a case fails; without the checksum helper's ihl check, ip_fast_csum() oopses on qemu.
Found by the Sashiko review of the previous version of this series and confirmed by code inspection and the KUnit cases above. Tested with KUnit on qemu pseries (ppc64le) and on a POWER10 LPAR with iperf3 large sends over IPv4 and IPv6 at MTU 1500 and 9000, threaded NAPI and busy polling, with no new drops or InCsumErrors. No kernel selftests cover ibmveth.
--- drivers/net/ethernet/ibm/ibmveth.c | 286 ++++++++++++++++++++++++++++- 1 file changed, 277 insertions(+), 9 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +277 -9
@@ -1396,8 +1396,12 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, } -static void ibmveth_rx_mss_helper (struct sk_buff *skb,u16 mss,int lrg_pkt) +/* Returns false when the IP or TCP headers fail the checks; the frame is +* then left unchanged and not marked GSO. +*/ +static bool ibmveth_rx_mss_helper (struct sk_buff *skb,u16 mss,int lrg_pkt) { +unsigned int gso_type, ip_len;struct tcphdr *tcph;int offset =0 ;int hdr_len;
@@ -1406,28 +1410,41 @@ static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt)if (skb->protocol ==htons (ETH_P_IP )) {struct iphdr *iph = (struct iphdr *)skb->data; +if (skb_headlen (skb) <sizeof (*iph) || iph->ihl <5 ) +return false;if (iph->protocol ==IPPROTO_TCP ) { +/* only a whole datagram has a TCP header to segment */ +if (ip_is_fragment (iph)) +return false; offset = iph->ihl *4 ; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; + ip_len =ntohs (iph->tot_len); + gso_type =SKB_GSO_TCPV4 ; }else { -return ; +return true; } }else if (skb->protocol ==htons (ETH_P_IPV6 )) {struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data; +if (skb_headlen (skb) <sizeof (*iph6)) +return false;if (iph6->nexthdr ==IPPROTO_TCP ) { offset =sizeof (struct ipv6hdr ); -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV6 ; + ip_len = offset +ntohs (iph6->payload_len); + gso_type =SKB_GSO_TCPV6 ; }else { -return ; +return true; } }else { -return ; +return true; }/* if mss is not set through Large Packet bit/mss in rx buffer, * expect that the mss will be written to the tcp header checksum. */ tcph = (struct tcphdr *)(skb->data + offset); +if (skb_headlen (skb) < offset +sizeof (*tcph) || tcph->doff <5 || + ip_len !=skb_headlen (skb) || ip_len <= offset + tcph->doff *4 ) +return false; +skb_shinfo (skb)->gso_type = gso_type;if (lrg_pkt) {skb_shinfo (skb)->gso_size = mss; }else if (offset) {
@@ -1436,11 +1453,18 @@ static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) }if (skb_shinfo (skb)->gso_size) { +/* chosen by the sending partition: at least the floor +* virtio_net_hdr_to_skb() uses, and never GSO_BY_FRAGS +*/ +skb_shinfo (skb)->gso_size = +clamp_t (u16,skb_shinfo (skb)->gso_size, +TCP_MIN_GSO_SIZE ,GSO_BY_FRAGS -1 ); hdr_len = offset + tcph->doff *4 ;skb_shinfo (skb)->gso_segs = -DIV_ROUND_UP (skb->len - hdr_len, +DIV_ROUND_UP (ip_len - hdr_len,skb_shinfo (skb)->gso_size); } +return true; } static void ibmveth_rx_csum_helper(struct sk_buff *skb,
@@ -1457,6 +1481,10 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb,if (skb_proto ==ETH_P_IP ) { iph = (struct iphdr *)skb->data; +if (skb_headlen (skb) <sizeof (*iph) || iph->ihl <5 || +skb_headlen (skb) < iph->ihl *4 || + (iph->protocol ==IPPROTO_TCP &&ip_is_fragment (iph))) + goto bad_hdr;/* If the IP checksum is not offloaded and if the packet * is large send, the checksum must be rebuilt.
@@ -1471,6 +1499,8 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb, iph_proto = iph->protocol; }else if (skb_proto ==ETH_P_IPV6 ) { iph6 = (struct ipv6hdr *)skb->data; +if (skb_headlen (skb) <sizeof (*iph6)) + goto bad_hdr; iphlen =sizeof (struct ipv6hdr ); iph_proto = iph6->nexthdr; }
@@ -1493,6 +1523,8 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb,if (iph_proto ==IPPROTO_TCP ) {struct tcphdr *tcph = (struct tcphdr *)(skb->data + iphlen); +if (skb_headlen (skb) < iphlen +sizeof (*tcph)) + goto bad_hdr;if (tcph->check ==0x0000 ) {/* Recompute TCP pseudo header checksum */ tcphdrlen = skb->len - iphlen;
@@ -1510,6 +1542,13 @@ static void ibmveth_rx_csum_helper(struct sk_buff *skb,skb_reset_network_header (skb); } } +return ; + +bad_hdr: +/* headers do not fit the frame, or a fragment has no whole TCP +* segment; let the stack check it +*/ + skb->ip_summed =CHECKSUM_NONE ; }static int ibmveth_poll (struct napi_struct *napi,int budget)
@@ -1624,7 +1663,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)/* PHYP without PLSO support places a -1 in the ip * checksum for large send frames. */ -if (skb->protocol ==cpu_to_be16 (ETH_P_IP )) { +if (skb->protocol ==cpu_to_be16 (ETH_P_IP ) && +skb_headlen (skb) >=sizeof (struct iphdr )) {struct iphdr *iph = (struct iphdr *)skb->data; iph_check = iph->check;
@@ -1632,7 +1672,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)if ((length > netdev->mtu +ETH_HLEN ) || lrg_pkt || iph_check ==0xffff ) { -ibmveth_rx_mss_helper (skb, mss, lrg_pkt); +if (!ibmveth_rx_mss_helper (skb, mss, lrg_pkt)) + csum_good =0 ; adapter->rx_large_packets++; }
@@ -2508,10 +2549,237 @@ static void ibmveth_rxq_harvest_buffer_test(struct kunit *test)flush_work (&adapter->work); } +KUNIT_DEFINE_ACTION_WRAPPER(ibmveth_kfree_skb, kfree_skb, struct sk_buff *); + +/* A TCP frame after eth_type_trans(): IP header, 20 byte TCP header and +* payload bytes of data, with the IP length matching the frame. +*/ +static struct sk_buff *ibmveth_test_tcp_skb (struct kunit *test,bool ipv6, +unsigned int payload) +{ +unsigned int iplen = ipv6 ?sizeof (struct ipv6hdr ) : +sizeof (struct iphdr ); +unsigned int len = iplen +sizeof (struct tcphdr ) + payload; +struct sk_buff *skb =alloc_skb (len,GFP_KERNEL ); +struct tcphdr *tcph; + +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, skb); +KUNIT_ASSERT_EQ (test,0 ,kunit_add_action_or_reset (test, + ibmveth_kfree_skb, + skb)); +skb_put_zero (skb, len); +if (ipv6) { +struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data; + + skb->protocol =htons (ETH_P_IPV6 ); + iph6->version =6 ; + iph6->nexthdr =IPPROTO_TCP ; + iph6->payload_len =htons (len - iplen); + }else { +struct iphdr *iph = (struct iphdr *)skb->data; + + skb->protocol =htons (ETH_P_IP ); + iph->version =4 ; + iph->ihl =5 ; + iph->protocol =IPPROTO_TCP ; + iph->tot_len =htons (len); + } + tcph = (struct tcphdr *)(skb->data + iplen); + tcph->doff =5 ; +return skb; +} + +/** +* ibmveth_rx_mss_helper_test - unit test for ibmveth_rx_mss_helper +* @test: pointer to kunit structure +* +* Large send frames get gso_size from the descriptor or the TCP checksum +* field, clamped, and gso_segs from the IP length. Frames whose headers +* do not fit, whose IP length is not the frame length, with no TCP +* payload within the IP length, or that are IPv4 fragments, are refused +* and left without GSO. +* +* Return: void +*/ +static void ibmveth_rx_mss_helper_test (struct kunit *test) +{ +struct sk_buff *skb; +struct tcphdr *tcph; +struct iphdr *iph; + + skb =ibmveth_test_tcp_skb (test, false,2896 ); + tcph = (struct tcphdr *)(skb->data +sizeof (*iph)); + tcph->check = (__force __sum16 )htons (1448 ); +KUNIT_EXPECT_TRUE (test,ibmveth_rx_mss_helper (skb,0 ,0 )); +KUNIT_EXPECT_EQ (test,SKB_GSO_TCPV4 ,skb_shinfo (skb)->gso_type); +KUNIT_EXPECT_EQ (test,1448 ,skb_shinfo (skb)->gso_size); +KUNIT_EXPECT_EQ (test,2 ,skb_shinfo (skb)->gso_segs); +KUNIT_EXPECT_EQ (test,0 , (__force u16 )tcph->check); + + skb =ibmveth_test_tcp_skb (test, false,2896 ); +KUNIT_EXPECT_TRUE (test,ibmveth_rx_mss_helper (skb,1000 ,1 )); +KUNIT_EXPECT_EQ (test,1000 ,skb_shinfo (skb)->gso_size); +KUNIT_EXPECT_EQ (test,3 ,skb_shinfo (skb)->gso_segs); + + skb =ibmveth_test_tcp_skb (test, true,2896 ); + tcph = (struct tcphdr *)(skb->data +sizeof (struct ipv6hdr )); + tcph->check = (__force __sum16 )htons (1448 ); +KUNIT_EXPECT_TRUE (test,ibmveth_rx_mss_helper (skb,0 ,0 )); +KUNIT_EXPECT_EQ (test,SKB_GSO_TCPV6 ,skb_shinfo (skb)->gso_type); +KUNIT_EXPECT_EQ (test,1448 ,skb_shinfo (skb)->gso_size); +KUNIT_EXPECT_EQ (test,2 ,skb_shinfo (skb)->gso_segs); + + skb =ibmveth_test_tcp_skb (test, false,2896 ); +KUNIT_EXPECT_TRUE (test,ibmveth_rx_mss_helper (skb,1 ,1 )); +KUNIT_EXPECT_EQ (test,TCP_MIN_GSO_SIZE ,skb_shinfo (skb)->gso_size); + + skb =ibmveth_test_tcp_skb (test, false,2896 ); +KUNIT_EXPECT_TRUE (test,ibmveth_rx_mss_helper (skb,GSO_BY_FRAGS ,1 )); +KUNIT_EXPECT_EQ (test,GSO_BY_FRAGS -1 ,skb_shinfo (skb)->gso_size); + +/* refused: ihl 0, doff 4, IP length past the frame. With ihl 0 the +* TCP header would overlap the IP header; saddr makes its doff 5. +*/ + skb =ibmveth_test_tcp_skb (test, false,2896 ); + ((struct iphdr *)skb->data)->ihl =0 ; + ((struct iphdr *)skb->data)->saddr =htonl (0x50000000 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); + + skb =ibmveth_test_tcp_skb (test, false,2896 ); + ((struct tcphdr *)(skb->data +sizeof (*iph)))->doff =4 ; +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); + + skb =ibmveth_test_tcp_skb (test, false,2896 ); + ((struct iphdr *)skb->data)->tot_len =htons (skb->len +1 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); + +/* refused: bytes past the IP length, its large send fields left +* alone; gso_segs from the IP length would undercount them +*/ + skb =ibmveth_test_tcp_skb (test, false,2896 ); + ((struct iphdr *)skb->data)->tot_len =htons (skb->len -100 ); + tcph = (struct tcphdr *)(skb->data +sizeof (*iph)); + tcph->check = (__force __sum16 )htons (1448 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,0 ,0 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); +KUNIT_EXPECT_EQ (test,1448 ,ntohs ((__force __be16 )tcph->check)); + +/* refused: a fragment past the first, its payload left alone */ + skb =ibmveth_test_tcp_skb (test, false,2896 ); + ((struct iphdr *)skb->data)->frag_off =htons (185 ); + tcph = (struct tcphdr *)(skb->data +sizeof (*iph)); + tcph->check = (__force __sum16 )htons (1448 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,0 ,0 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); +KUNIT_EXPECT_EQ (test,1448 ,ntohs ((__force __be16 )tcph->check)); + +/* refused: only Ethernet padding past the TCP header */ + skb =ibmveth_test_tcp_skb (test, false,6 ); + ((struct iphdr *)skb->data)->tot_len =htons (40 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); + + skb =ibmveth_test_tcp_skb (test, true,2896 ); + ((struct ipv6hdr *)skb->data)->payload_len =0 ; +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); + +/* refused: no TCP payload, with the IP length matching the frame */ + skb =ibmveth_test_tcp_skb (test, false,0 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); + + skb =ibmveth_test_tcp_skb (test, true,0 ); +KUNIT_EXPECT_FALSE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); + +/* not TCP: accepted and left alone */ + skb =ibmveth_test_tcp_skb (test, false,2896 ); + ((struct iphdr *)skb->data)->protocol =IPPROTO_UDP ; +KUNIT_EXPECT_TRUE (test,ibmveth_rx_mss_helper (skb,1448 ,1 )); +KUNIT_EXPECT_EQ (test,0 ,skb_shinfo (skb)->gso_size); +} + +/** +* ibmveth_rx_csum_helper_test - unit test for ibmveth_rx_csum_helper +* @test: pointer to kunit structure +* +* A large send IPv4 header checksum of 0xffff is rebuilt. Headers that +* do not fit the frame, an IPv4 ihl below 5, or a TCP fragment, clear +* CHECKSUM_UNNECESSARY instead of being read. +* +* Return: void +*/ +static void ibmveth_rx_csum_helper_test (struct kunit *test) +{ +struct sk_buff *skb; +struct tcphdr *tcph; +struct iphdr *iph; + + skb =ibmveth_test_tcp_skb (test, false,100 ); + iph = (struct iphdr *)skb->data; + iph->check = (__force __sum16 )0xffff ; + tcph = (struct tcphdr *)(skb->data +sizeof (*iph)); + tcph->check = (__force __sum16 )htons (1 ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; +ibmveth_rx_csum_helper (skb,NULL ); +KUNIT_EXPECT_EQ (test,0 , (__force u16 )ip_fast_csum (iph, iph->ihl)); +KUNIT_EXPECT_EQ (test,CHECKSUM_UNNECESSARY , (int )skb->ip_summed); + + skb =ibmveth_test_tcp_skb (test, false,100 ); + iph = (struct iphdr *)skb->data; + iph->ihl =0 ; + iph->check = (__force __sum16 )0xffff ; + skb->ip_summed =CHECKSUM_UNNECESSARY ; +ibmveth_rx_csum_helper (skb,NULL ); +KUNIT_EXPECT_EQ (test,CHECKSUM_NONE , (int )skb->ip_summed); +KUNIT_EXPECT_EQ (test,0xffff , (__force u16 )iph->check); + +/* IPv4 options past the frame; UDP, so no TCP check follows */ + skb =ibmveth_test_tcp_skb (test, false,0 ); + iph = (struct iphdr *)skb->data; + iph->protocol =IPPROTO_UDP ; + iph->ihl =15 ; + iph->check = (__force __sum16 )0xffff ; + skb->ip_summed =CHECKSUM_UNNECESSARY ; +ibmveth_rx_csum_helper (skb,NULL ); +KUNIT_EXPECT_EQ (test,CHECKSUM_NONE , (int )skb->ip_summed); + +/* a TCP fragment past the first: header and payload left alone */ + skb =ibmveth_test_tcp_skb (test, false,100 ); + iph = (struct iphdr *)skb->data; + iph->frag_off =htons (185 ); + iph->check = (__force __sum16 )0xffff ; + skb->ip_summed =CHECKSUM_UNNECESSARY ; +ibmveth_rx_csum_helper (skb,NULL ); +KUNIT_EXPECT_EQ (test,CHECKSUM_NONE , (int )skb->ip_summed); +KUNIT_EXPECT_EQ (test,0xffff , (__force u16 )iph->check); +KUNIT_EXPECT_EQ (test,0 , + (__force u16)((struct tcphdr *)(skb->data + +sizeof (*iph)))->check); + +/* TCP header past the frame */ + skb =ibmveth_test_tcp_skb (test, false,0 ); +skb_trim (skb,sizeof (struct iphdr )); + skb->ip_summed =CHECKSUM_UNNECESSARY ; +ibmveth_rx_csum_helper (skb,NULL ); +KUNIT_EXPECT_EQ (test,CHECKSUM_NONE , (int )skb->ip_summed); + +/* IPv6 header past the frame; UDP, so no TCP check follows */ + skb =ibmveth_test_tcp_skb (test, true,0 ); + ((struct ipv6hdr *)skb->data)->nexthdr =IPPROTO_UDP ; +skb_trim (skb,sizeof (struct ipv6hdr ) -1 ); + skb->ip_summed =CHECKSUM_UNNECESSARY ; +ibmveth_rx_csum_helper (skb,NULL ); +KUNIT_EXPECT_EQ (test,CHECKSUM_NONE , (int )skb->ip_summed); +} +static struct kunit_case ibmveth_test_cases[] = {KUNIT_CASE (ibmveth_remove_buffer_from_pool_test),KUNIT_CASE (ibmveth_rxq_get_buffer_test),KUNIT_CASE (ibmveth_rxq_harvest_buffer_test), +KUNIT_CASE (ibmveth_rx_mss_helper_test), +KUNIT_CASE (ibmveth_rx_csum_helper_test), {} };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1840/2151 ksmbd: server: avoid busy polling in accept loop
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingfang Deng <[email protected]>
[ Upstream commit 3316a8fc840d82fad5efcf76ad0ea3f76fdca209 ]
The ksmbd listener thread was using busy waiting on a listening socket by calling kernel_accept() with SOCK_NONBLOCK and retrying every 100ms on -EAGAIN. Since this thread is dedicated to accepting new connections, there is no need for non-blocking mode.
Switch to a blocking accept() call instead, allowing the thread to sleep until a new connection arrives. This avoids unnecessary wakeups and CPU usage. During teardown, call shutdown() on the listening socket so that accept() returns -EINVAL and the thread exits cleanly.
The socket release mutex is redundant because kthread_stop() blocks until the listener thread returns, guaranteeing safe teardown ordering.
Also remove sk_rcvtimeo and sk_sndtimeo assignments, which only caused accept() to return -EAGAIN prematurely.
Stable-dep-of: d34d38ab0c62 ("ksmbd: fix iface_list use-after-free during server reset")
--- fs/smb/server/transport_tcp.c | 41 +++++------------------------------ 1 file changed, 6 insertions(+), 35 deletions(-)
fs/smb/server/transport_tcp.c +6 -35
@@ -22,7 +22,6 @@ struct interface {struct socket *ksmbd_socket;struct list_head entry;char *name; -struct mutex sock_release_lock;int state; };
@@ -57,19 +56,6 @@ static inline void ksmbd_tcp_reuseaddr(struct socket *sock)sock_set_reuseaddr (sock->sk); } -static inline void ksmbd_tcp_rcv_timeout (struct socket *sock,s64 secs) -{ -if (secs && secs <MAX_SCHEDULE_TIMEOUT /HZ -1 ) -WRITE_ONCE (sock->sk->sk_rcvtimeo, secs *HZ ); -else -WRITE_ONCE (sock->sk->sk_rcvtimeo,MAX_SCHEDULE_TIMEOUT ); -} - -static inline void ksmbd_tcp_snd_timeout (struct socket *sock,s64 secs) -{ -sock_set_sndtimeo (sock->sk, secs); -} -static struct tcp_transport *alloc_transport (struct socket *client_sk) {struct tcp_transport *t;
@@ -239,20 +225,14 @@ static int ksmbd_kthread_fn(void *p)unsigned int max_ip_conns;while (!kthread_should_stop ()) { -mutex_lock (&iface->sock_release_lock);if (!iface->ksmbd_socket) { -mutex_unlock (&iface->sock_release_lock);break ; } - ret =kernel_accept (iface->ksmbd_socket, &client_sk, -SOCK_NONBLOCK ); -mutex_unlock (&iface->sock_release_lock); -if (ret) { -if (ret == -EAGAIN ) -/* check for new connections every 100 msecs */ -schedule_timeout_interruptible (HZ /10 ); + ret =kernel_accept (iface->ksmbd_socket, &client_sk,0 ); +if (ret == -EINVAL ) +break ; +if (ret)continue ; - }if (!server_conf.max_ip_connections) goto skip_max_ip_conns_limit;
@@ -472,10 +452,6 @@ static void tcp_destroy_socket(struct socket *ksmbd_socket)if (!ksmbd_socket)return ; -/* set zero to timeout */ -ksmbd_tcp_rcv_timeout (ksmbd_socket,0 ); -ksmbd_tcp_snd_timeout (ksmbd_socket,0 ); - ret =kernel_sock_shutdown (ksmbd_socket,SHUT_RDWR );if (ret)pr_err ("Failed to shutdown socket: %d\n" , ret);
@@ -546,9 +522,6 @@ static int create_socket(struct interface *iface) goto out_error; } - ksmbd_socket->sk->sk_rcvtimeo =KSMBD_TCP_RECV_TIMEOUT ; - ksmbd_socket->sk->sk_sndtimeo =KSMBD_TCP_SEND_TIMEOUT ; - ret =kernel_listen (ksmbd_socket,KSMBD_SOCKET_BACKLOG );if (ret) {pr_err ("Port listen() error: %d\n" , ret);
@@ -627,12 +600,11 @@ static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,if (iface && iface->state ==IFACE_STATE_CONFIGURED ) {ksmbd_debug (CONN ,"netdev-down event: netdev(%s) is going down\n" , iface->name); +kernel_sock_shutdown (iface->ksmbd_socket,SHUT_RDWR );tcp_stop_kthread (iface->ksmbd_kthread); iface->ksmbd_kthread =NULL ; -mutex_lock (&iface->sock_release_lock); -tcp_destroy_socket (iface->ksmbd_socket); +sock_release (iface->ksmbd_socket); iface->ksmbd_socket =NULL ; -mutex_unlock (&iface->sock_release_lock); iface->state =IFACE_STATE_DOWN ;break ;
@@ -695,7 +667,6 @@ static struct interface *alloc_iface(char *ifname) iface->name = ifname; iface->state =IFACE_STATE_DOWN ;list_add (&iface->entry, &iface_list); -mutex_init (&iface->sock_release_lock);return iface; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1841/2151 ksmbd: fix listener task lifetime on netdev events
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit a506290f59e1c6ce9ac0a13158640bb8fee93471 ]
The listener thread exits when its listening socket is shutdown. The netdevice notifier shuts down the socket before calling kthread_stop(), so the task_struct can be freed before kthread_stop() gets its reference.
Create the listener in a stopped state and hold an extra task_struct reference until kthread_stop_put() completes. Also stop and release listeners before freeing their interface records during TCP teardown.
Stable-dep-of: d34d38ab0c62 ("ksmbd: fix iface_list use-after-free during server reset")
--- fs/smb/server/transport_tcp.c | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)
fs/smb/server/transport_tcp.c +27 -9
@@ -39,6 +39,7 @@ struct tcp_transport {static const struct ksmbd_transport_ops ksmbd_tcp_transport_ops;static void tcp_stop_kthread (struct task_struct *kthread); +static void ksmbd_tcp_stop_listener (struct interface *iface);static struct interface *alloc_iface (char *ifname);static void ksmbd_tcp_disconnect (struct ksmbd_transport *t);
@@ -321,13 +322,20 @@ static int ksmbd_tcp_run_kthread(struct interface *iface)int rc;struct task_struct *kthread; - kthread =kthread_run (ksmbd_kthread_fn, (void *)iface,"ksmbd-%s" , - iface->name); + kthread =kthread_create (ksmbd_kthread_fn, (void *)iface,"ksmbd-%s" , + iface->name);if (IS_ERR (kthread)) { rc =PTR_ERR (kthread);return rc; } + +/* +* The listener can exit after its socket is shutdown, so keep the +* task_struct alive until the caller has stopped it. +*/ +get_task_struct (kthread); iface->ksmbd_kthread = kthread; +wake_up_process (kthread);return 0 ; }
@@ -600,12 +608,7 @@ static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,if (iface && iface->state ==IFACE_STATE_CONFIGURED ) {ksmbd_debug (CONN ,"netdev-down event: netdev(%s) is going down\n" , iface->name); -kernel_sock_shutdown (iface->ksmbd_socket,SHUT_RDWR ); -tcp_stop_kthread (iface->ksmbd_kthread); - iface->ksmbd_kthread =NULL ; -sock_release (iface->ksmbd_socket); - iface->ksmbd_socket =NULL ; - +ksmbd_tcp_stop_listener (iface); iface->state =IFACE_STATE_DOWN ;break ; }
@@ -633,11 +636,25 @@ static void tcp_stop_kthread(struct task_struct *kthread)if (!kthread)return ; - ret =kthread_stop (kthread); + ret =kthread_stop_put (kthread);if (ret)pr_err ("failed to stop forker thread\n" ); } +static void ksmbd_tcp_stop_listener (struct interface *iface) +{ +if (iface->ksmbd_socket) +kernel_sock_shutdown (iface->ksmbd_socket,SHUT_RDWR ); + +tcp_stop_kthread (iface->ksmbd_kthread); + iface->ksmbd_kthread =NULL ; + +if (iface->ksmbd_socket) { +sock_release (iface->ksmbd_socket); + iface->ksmbd_socket =NULL ; + } +} +void ksmbd_tcp_destroy (void ) {struct interface *iface, *tmp;
@@ -645,6 +662,7 @@ void ksmbd_tcp_destroy(void)unregister_netdevice_notifier (&ksmbd_netdev_notifier);list_for_each_entry_safe (iface, tmp, &iface_list, entry) { +ksmbd_tcp_stop_listener (iface);list_del (&iface->entry);kfree (iface->name);kfree (iface);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1842/2151 ksmbd: fix iface_list use-after-free during server reset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Hu <[email protected]>
[ Upstream commit d34d38ab0c62fe4eb9e746420c554e6d0e6f54db ]
ksmbd_find_netdev_name_iface_list() walks iface_list for fsctl_query_iface_info_ioctl(), which holds RTNL. But during server reset, ksmbd_tcp_destroy() unlinks and frees the entries without RTNL, and queued SMB requests can still be running at that point. So an FSCTL_QUERY_NETWORK_INTERFACE_INFO request can therefore race with interface destruction and dereference a freed entry. With debug-only instrumentation to make the race deterministic, KASAN reports:
BUG: KASAN: slab-use-after-free in ksmbd_find_netdev_name_iface_list
ksmbd_find_netdev_name_iface_list
fsctl_query_iface_info_ioctl
smb2_ioctl
handle_ksmbd_work
Freed by:
kfree
ksmbd_tcp_destroy
ksmbd_conn_transport_destroy
kill_server_store
The fix is to detach iface_list to a temporary list under RTNL, then drop RTNL before cleanup because the following cleanup may block and hold RTNL for a long time.
--- fs/smb/server/transport_tcp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/transport_tcp.c +6 -1
@@ -658,10 +658,15 @@ static void ksmbd_tcp_stop_listener(struct interface *iface)void ksmbd_tcp_destroy (void ) {struct interface *iface, *tmp; +LIST_HEAD (iface_list_to_free);unregister_netdevice_notifier (&ksmbd_netdev_notifier); -list_for_each_entry_safe (iface, tmp, &iface_list, entry) { +rtnl_lock (); +list_splice_init (&iface_list, &iface_list_to_free); +rtnl_unlock (); + +list_for_each_entry_safe (iface, tmp, &iface_list_to_free, entry) {ksmbd_tcp_stop_listener (iface);list_del (&iface->entry);kfree (iface->name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1843/2151 ksmbd: fix link speed query in fsctl_query_iface_info_ioctl()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Hu <[email protected]>
[ Upstream commit 2bc1d25fc8597fa6cbf6b1ff92653881939a6436 ]
fsctl_query_iface_info_ioctl() used to call netdev->ethtool_ops->get_link_ksettings() directly and never checked the return value. If the callback fails, cmd.base.speed may be left uninitialized. Also, SPEED_UNKNOWN (-1) is treated as a numeric link speed and would be converted into a bogus link speed.
Use __ethtool_get_link_ksettings() to acquire the per-netdev ops lock when needed. Fall back to 1Gbps when the query fails, or when the reported speed is 0 or SPEED_UNKNOWN.
--- fs/smb/server/smb2pdu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +3 -4
@@ -8243,6 +8243,7 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,struct sockaddr_storage_rsp *sockaddr_storage;unsigned int flags;unsigned long long speed; +struct ethtool_link_ksettings cmd;rtnl_lock ();for_each_netdev (&init_net, netdev) {
@@ -8277,10 +8278,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn, nii_rsp->Next =cpu_to_le32 (152 ); nii_rsp->Reserved =0 ; -if (netdev->ethtool_ops->get_link_ksettings) { -struct ethtool_link_ksettings cmd; - - netdev->ethtool_ops->get_link_ksettings (netdev, &cmd); +if (!__ethtool_get_link_ksettings (netdev, &cmd) && + cmd.base.speed && cmd.base.speed !=SPEED_UNKNOWN ) { speed = cmd.base.speed; }else { ksmbd_debug(SMB, "%s %s\n", netdev->name,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1844/2151 ksmbd: fix unlocked IPv6 addr_list walk in fsctl_query_iface_info_ioctl()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Hu <[email protected]>
[ Upstream commit a63bb4d91c784f63ad7c063717dff7920d8445be ]
fsctl_query_iface_info_ioctl() walks idev6->addr_list with a plain list_for_each_entry() while holding only rtnl_lock(). rtnl does not serialize all writers of this list: the DAD-failure path (addrconf_dad_failure -> ipv6_add_addr) can insert addresses without holding RTNL. It updates idev->addr_list with list_add_tail_rcu() under write_lock_bh(&idev->lock), so it can race with the unlocked walk.
addr_list is RCU managed, so walk it with list_for_each_entry_rcu() under rcu_read_lock(), matching the other lockless readers of the list.
--- fs/smb/server/smb2pdu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +3 -1
@@ -8321,13 +8321,15 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,if (!idev6)continue ; -list_for_each_entry (ifa, &idev6->addr_list, if_list) { +rcu_read_lock (); +list_for_each_entry_rcu (ifa, &idev6->addr_list, if_list) {if (ifa->flags & (IFA_F_TENTATIVE |IFA_F_DEPRECATED ))continue ;memcpy (ipv6_addr, ifa->addr.s6_addr,16 );break ; } +rcu_read_unlock (); sockaddr_storage->addr6.ScopeId =0 ; nbytes +=sizeof (struct network_interface_info_ioctl_rsp ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1845/2151 ksmbd: fix invalid Next offset in interface info replies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Hu <[email protected]>
[ Upstream commit 2c50a4a5e75db55880eca43c035649cb51fcb52a ]
fsctl_query_iface_info_ioctl() assigns nii_rsp to the next output slot before checking whether the interface has an in_device or inet6_dev. If either lookup returns NULL, the loop continues without advancing nbytes, leaving nii_rsp pointing at an uncommitted slot. If no later entry is committed, clearing nii_rsp->Next updates that slot instead of the last returned entry, leaving the latter with a nonzero Next offset.
Fix this by using nbytes to locate the last committed entry and clear its Next field, but only when the response contains at least one entry.
--- fs/smb/server/smb2pdu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/smb/server/smb2pdu.c +8 -2
@@ -8336,9 +8336,15 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn, }rtnl_unlock (); -/* zero if this is last one */ -if (nii_rsp) +/* +* nii_rsp may point to an entry not included in nbytes if the IPv4 +* or IPv6 device lookup failed. Clear Next in the last returned entry. +*/ +if (nbytes >0 ) { + nii_rsp = (struct network_interface_info_ioctl_rsp *) + &rsp->Buffer[nbytes -sizeof (*nii_rsp)]; nii_rsp->Next =0 ; + } rsp->PersistentFileId =SMB2_NO_FID ; rsp->VolatileFileId =SMB2_NO_FID ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1846/2151 ksmbd: report IPv4 and IPv6 addresses independently in iface query
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Hu <[email protected]>
[ Upstream commit bb0326a5806015fb7e5a6a721a50ff172c92c6e4 ]
fsctl_query_iface_info_ioctl() appends an entry before checking that a usable address was found, so it advertises unspecified-address
placeholders: an entry containing 0.0.0.0 when an in_device exists but has no primary IPv4 address, and an entry containing :: when an inet6_dev exists but its address list is empty or every address is tentative or deprecated.
The loop also couples IPv6 reporting to IPv4 success: when __in_dev_get_rtnl() returns NULL it continues to the next interface, skipping the IPv6 pass, so an interface without an in_device is dropped even if it has a usable IPv6 address.
Query IPv4 and IPv6 independently and append an entry only when an address is found. Factor out the common entry initialization and query the link speed once per interface instead of once per address family.
--- fs/smb/server/smb2pdu.c | 127 ++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 57 deletions(-)
fs/smb/server/smb2pdu.c +70 -57
@@ -8233,6 +8233,27 @@ static __be32 idev_ipv4_address(struct in_device *idev)return addr; } +static struct network_interface_info_ioctl_rsp * +ksmbd_iface_entry_init (struct smb2_ioctl_rsp *rsp,int nbytes, +struct net_device *netdev,unsigned long long speed) +{ +struct network_interface_info_ioctl_rsp *nii_rsp; + + nii_rsp = (struct network_interface_info_ioctl_rsp *)&rsp->Buffer[nbytes]; + nii_rsp->IfIndex =cpu_to_le32 (netdev->ifindex); + nii_rsp->Capability =0 ; +if (netdev->real_num_tx_queues >1 ) + nii_rsp->Capability |=RSS_CAPABLE ; +if (ksmbd_rdma_capable_netdev (netdev)) + nii_rsp->Capability |=RDMA_CAPABLE ; + nii_rsp->Next =cpu_to_le32 (152 ); + nii_rsp->Reserved =0 ; + nii_rsp->LinkSpeed =cpu_to_le64 (speed); +memset (nii_rsp->SockAddr_Storage,0 ,128 ); + +return nii_rsp; +} +static int fsctl_query_iface_info_ioctl (struct ksmbd_conn *conn,struct smb2_ioctl_rsp *rsp,unsigned int out_buf_len)
@@ -8247,7 +8268,12 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,rtnl_lock ();for_each_netdev (&init_net, netdev) { -bool ipv4_set = false; +struct inet6_ifaddr *ifa; +struct inet6_dev *idev6; +struct in_device *idev; +struct in6_addr ip6 = { }; +bool have_ip6 = false; +__be32 ip4 =0 ;if (netdev->type ==ARPHRD_LOOPBACK )continue ;
@@ -8258,25 +8284,6 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn, flags =netif_get_flags (netdev);if (!(flags &IFF_RUNNING ))continue ; -ipv6_retry: -if (out_buf_len < - nbytes +sizeof (struct network_interface_info_ioctl_rsp )) { -rtnl_unlock (); -return -ENOSPC ; - } - - nii_rsp = (struct network_interface_info_ioctl_rsp *) - &rsp->Buffer[nbytes]; - nii_rsp->IfIndex =cpu_to_le32 (netdev->ifindex); - - nii_rsp->Capability =0 ; -if (netdev->real_num_tx_queues >1 ) - nii_rsp->Capability |=RSS_CAPABLE ; -if (ksmbd_rdma_capable_netdev (netdev)) - nii_rsp->Capability |=RDMA_CAPABLE ; - - nii_rsp->Next =cpu_to_le32 (152 ); - nii_rsp->Reserved =0 ;if (!__ethtool_get_link_ksettings (netdev, &cmd) && cmd.base.speed && cmd.base.speed !=SPEED_UNKNOWN ) {
@@ -8286,60 +8293,66 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn, "speed is unknown, defaulting to 1Gb/sec"); speed =SPEED_1000 ; } - speed *=1000000 ; - nii_rsp->LinkSpeed =cpu_to_le64 (speed); - sockaddr_storage = (struct sockaddr_storage_rsp *) - nii_rsp->SockAddr_Storage; -memset (sockaddr_storage,0 ,128 ); +/* +* Query IPv4 and IPv6 independently; emit an entry only when a +* usable address exists, so an interface missing one family is +* still reported for the other and 0.0.0.0 / :: placeholders are +* never advertised. +*/ + idev =__in_dev_get_rtnl (netdev); +if (idev) + ip4 =idev_ipv4_address (idev); -if (!ipv4_set) { -struct in_device *idev; + idev6 =__in6_dev_get (netdev); +if (idev6) { +rcu_read_lock (); +list_for_each_entry_rcu (ifa, &idev6->addr_list, if_list) { +if (ifa->flags & (IFA_F_TENTATIVE |IFA_F_DEPRECATED )) +continue ; +memcpy (&ip6, ifa->addr.s6_addr,sizeof (ip6)); + have_ip6 = true; +break ; + } +rcu_read_unlock (); + } +if (ip4) { +if (out_buf_len < + nbytes +sizeof (struct network_interface_info_ioctl_rsp )) { +rtnl_unlock (); +return -ENOSPC ; + } + + nii_rsp =ksmbd_iface_entry_init (rsp, nbytes, netdev, speed); + sockaddr_storage = (struct sockaddr_storage_rsp *)nii_rsp->SockAddr_Storage; sockaddr_storage->Family =INTERNETWORK ; sockaddr_storage->addr4.Port =0 ; - - idev =__in_dev_get_rtnl (netdev); -if (!idev) -continue ; - sockaddr_storage->addr4.IPv4Address = -idev_ipv4_address (idev); + sockaddr_storage->addr4.IPv4Address = ip4; nbytes +=sizeof (struct network_interface_info_ioctl_rsp ); - ipv4_set = true; - goto ipv6_retry; - }else { -struct inet6_dev *idev6; -struct inet6_ifaddr *ifa; -__u8 *ipv6_addr = sockaddr_storage->addr6.IPv6Address; + } + +if (have_ip6) { +if (out_buf_len < + nbytes +sizeof (struct network_interface_info_ioctl_rsp )) { +rtnl_unlock (); +return -ENOSPC ; + } + nii_rsp =ksmbd_iface_entry_init (rsp, nbytes, netdev, speed); + sockaddr_storage = (struct sockaddr_storage_rsp *)nii_rsp->SockAddr_Storage; sockaddr_storage->Family =INTERNETWORKV6 ; sockaddr_storage->addr6.Port =0 ; sockaddr_storage->addr6.FlowInfo =0 ; - - idev6 =__in6_dev_get (netdev); -if (!idev6) -continue ; - -rcu_read_lock (); -list_for_each_entry_rcu (ifa, &idev6->addr_list, if_list) { -if (ifa->flags & (IFA_F_TENTATIVE | -IFA_F_DEPRECATED )) -continue ; -memcpy (ipv6_addr, ifa->addr.s6_addr,16 ); -break ; - } -rcu_read_unlock (); +memcpy (sockaddr_storage->addr6.IPv6Address, ip6.s6_addr,16 ); sockaddr_storage->addr6.ScopeId =0 ; nbytes +=sizeof (struct network_interface_info_ioctl_rsp ); } }rtnl_unlock (); -/* -* nii_rsp may point to an entry not included in nbytes if the IPv4 -* or IPv6 device lookup failed. Clear Next in the last returned entry. -*/ +/* Clear Next of the last committed entry to terminate the list. */ if (nbytes >0 ) { nii_rsp = (struct network_interface_info_ioctl_rsp *) &rsp->Buffer[nbytes -sizeof (*nii_rsp)];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1847/2151 smb/server: fix trailing period in generated short names
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: ChenXiaoSong <[email protected]>
[ Upstream commit e8486c5cfbdd07811afa4196060bafbf78ccdae2 ]
Reproducer:
1. touch /mnt/file
2. smbinfo filealternatenameinfo /mnt/file
Alternate Name: FILE~9!.
See MS-FSCC 2.1.5.2.1. The base filename MUST be 1-8 characters in length and MUST NOT contain a "." period character.
--- fs/smb/server/smb_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/smb/server/smb_common.c +1 -3
@@ -494,8 +494,6 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,* @shortname: destination short filename * * Return: shortname length or 0 when source long name is '.' or '..' -* TODO: Though this function conforms the restriction of 8.3 Filename spec, -* but the result is different with Windows 7's one. need to check. */ int ksmbd_extract_shortname (struct ksmbd_conn *conn,const char *longname,char *shortname)
@@ -559,7 +557,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname,if (dot_present)memcpy (out + baselen +4 , extension,4 );else - out[baselen +4 ] ='\0' ; + out[baselen +3 ] ='\0' ;smbConvertToUTF16 ((__le16 *)shortname, out,PATH_MAX , conn->local_nls,0 ); len =strlen (out) *2 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1848/2151 ksmbd: preserve open change time across rename
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 24dcee8305d6ba18c69594ca6fb42eaa32f8e63e ]
inode ctime is updated when a file is renamed. ksmbd returned that ctime directly as SMB2 ChangeTime for handle-based query information. This makes ChangeTime change after a rename through an already-open handle, while Windows keeps the handle's ChangeTime stable for this case.
Store the SMB ChangeTime in struct ksmbd_file when the handle is opened and use that value for create, close, and handle-based query information responses. If a client explicitly sets FILE_BASIC_INFORMATION ChangeTime, update the stored value as well.
This fixes smbtorture smb2.rename.simple_modtime, which expects ChangeTime and LastWriteTime to remain unchanged after renaming an already-open file.
Stable-dep-of: aad7d86a6651 ("ksmbd: round SetAllocation to the advertised allocation unit")
--- fs/smb/server/smb2pdu.c | 23 ++++++++++------------- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 11 insertions(+), 13 deletions(-)
fs/smb/server/smb2pdu.c +10 -13
@@ -3737,6 +3737,7 @@ int smb2_open(struct ksmbd_work *work) fp->create_time =ksmbd_UnixTimeToNT (stat.btime); else fp->create_time = ksmbd_UnixTimeToNT(stat.ctime); + fp->change_time =ksmbd_UnixTimeToNT (stat.ctime);if (req->FileAttributes || fp->f_ci->m_fattr ==0 ) fp->f_ci->m_fattr =cpu_to_le32 (smb2_get_dos_mode (&stat,le32_to_cpu (req->FileAttributes)));
@@ -3786,8 +3787,7 @@ int smb2_open(struct ksmbd_work *work) rsp->LastAccessTime =cpu_to_le64 (time); time =ksmbd_UnixTimeToNT (stat.mtime); rsp->LastWriteTime =cpu_to_le64 (time); - time =ksmbd_UnixTimeToNT (stat.ctime); - rsp->ChangeTime =cpu_to_le64 (time); + rsp->ChangeTime =cpu_to_le64 (fp->change_time); rsp->AllocationSize =S_ISDIR (stat.mode) ?0 :cpu_to_le64 (stat.blocks <<9 ); rsp->EndofFile =S_ISDIR (stat.mode) ?0 :cpu_to_le64 (stat.size);
@@ -5057,8 +5057,7 @@ static int get_file_basic_info(struct smb2_query_info_rsp *rsp, basic_info->LastAccessTime =cpu_to_le64 (time); time =ksmbd_UnixTimeToNT (stat.mtime); basic_info->LastWriteTime =cpu_to_le64 (time); - time =ksmbd_UnixTimeToNT (stat.ctime); - basic_info->ChangeTime =cpu_to_le64 (time); + basic_info->ChangeTime =cpu_to_le64 (fp->change_time); basic_info->Attributes = fp->f_ci->m_fattr; basic_info->Pad1 =0 ; rsp->OutputBufferLength =
@@ -5158,8 +5157,7 @@ static int get_file_all_info(struct ksmbd_work *work, file_info->LastAccessTime =cpu_to_le64 (time); time =ksmbd_UnixTimeToNT (stat.mtime); file_info->LastWriteTime =cpu_to_le64 (time); - time =ksmbd_UnixTimeToNT (stat.ctime); - file_info->ChangeTime =cpu_to_le64 (time); + file_info->ChangeTime =cpu_to_le64 (fp->change_time); file_info->Attributes = fp->f_ci->m_fattr; file_info->Pad1 =0 ;if (ksmbd_stream_fd (fp) == false) {
@@ -5371,8 +5369,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp, file_info->LastAccessTime =cpu_to_le64 (time); time =ksmbd_UnixTimeToNT (stat.mtime); file_info->LastWriteTime =cpu_to_le64 (time); - time =ksmbd_UnixTimeToNT (stat.ctime); - file_info->ChangeTime =cpu_to_le64 (time); + file_info->ChangeTime =cpu_to_le64 (fp->change_time); file_info->Attributes = fp->f_ci->m_fattr;if (ksmbd_stream_fd (fp) == false) { file_info->AllocationSize =cpu_to_le64 (stat.blocks <<9 );
@@ -5498,8 +5495,7 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, file_info->LastAccessTime =cpu_to_le64 (time); time =ksmbd_UnixTimeToNT (stat.mtime); file_info->LastWriteTime =cpu_to_le64 (time); - time =ksmbd_UnixTimeToNT (stat.ctime); - file_info->ChangeTime =cpu_to_le64 (time); + file_info->ChangeTime =cpu_to_le64 (fp->change_time); file_info->DosAttributes = fp->f_ci->m_fattr; file_info->Inode =cpu_to_le64 (stat.ino);if (ksmbd_stream_fd (fp) == false) {
@@ -6254,8 +6250,7 @@ int smb2_close(struct ksmbd_work *work) rsp->LastAccessTime =cpu_to_le64 (time); time =ksmbd_UnixTimeToNT (stat.mtime); rsp->LastWriteTime =cpu_to_le64 (time); - time =ksmbd_UnixTimeToNT (stat.ctime); - rsp->ChangeTime =cpu_to_le64 (time); + rsp->ChangeTime =cpu_to_le64 (fp->change_time);ksmbd_fd_put (work, fp); }else { rsp->Flags =0 ;
@@ -6468,9 +6463,11 @@ static int set_file_basic_info(struct ksmbd_file *fp, attrs.ia_valid |= (ATTR_ATIME |ATTR_ATIME_SET ); } -if (file_info->ChangeTime) +if (file_info->ChangeTime) { + fp->change_time =le64_to_cpu (file_info->ChangeTime);inode_set_ctime_to_ts (inode,ksmbd_NTtimeToUnix (file_info->ChangeTime)); + }if (file_info->LastWriteTime) { attrs.ia_mtime =ksmbd_NTtimeToUnix (file_info->LastWriteTime);
fs/smb/server/vfs_cache.h +1 -0
@@ -101,6 +101,7 @@ struct ksmbd_file {__le32 coption;__le32 cdoption;__u64 create_time; +__u64 change_time;__u64 itime;bool is_nt_open;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1849/2151 ksmbd: return requested create allocation size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 3b41d8b05dc89b1f3c53ca7f1a084c7c93712ebf ]
smb2.create.blob sends an SMB2_CREATE_ALLOCATION_SIZE create context with a 1MiB allocation size and expects the create response AllocationSize field to match the requested size. smb2.create.open additionally compares the AllocationSize returned in the CREATE response with the AllocationSize returned by FILE_ALL_INFORMATION on the same handle.
ksmbd applies the allocation with fallocate(), but then fills both the create response and handle-based information from stat.blocks << 9. On filesystems such as ext4 this can include filesystem allocation rounding and metadata effects, causing a response larger than the SMB2 allocation size context and a disagreement between the two queries.
Remember the requested allocation size while processing the create context, store the reported allocation size in struct ksmbd_file, and use it for both the create response and handle-based allocation size responses. Update the stored value when FILE_ALLOCATION_INFORMATION changes it, and fall back to stat.blocks << 9 when no allocation size context was provided.
Stable-dep-of: aad7d86a6651 ("ksmbd: round SetAllocation to the advertised allocation unit")
--- fs/smb/server/smb2pdu.c | 34 +++++++++++++++++++++++----------- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 24 insertions(+), 11 deletions(-)
fs/smb/server/smb2pdu.c +23 -11
@@ -2999,7 +2999,7 @@ int smb2_open(struct ksmbd_work *work)char *stream_name =NULL ;bool file_present = false, created = false, already_permitted = false;int share_ret, need_truncate =0 ; -u64 time; +u64 time, alloc_size =0 ;umode_t posix_mode =0 ;__le32 daccess, maximal_access =0 ;int iov_len =0 ;
@@ -3679,7 +3679,6 @@ int smb2_open(struct ksmbd_work *work) rc =PTR_ERR (az_req); goto err_out1; }else if (az_req) { -loff_t alloc_size;int err; if (le16_to_cpu(az_req->ccontext.DataOffset) +
@@ -3738,6 +3737,8 @@ int smb2_open(struct ksmbd_work *work)else fp->create_time =ksmbd_UnixTimeToNT (stat.ctime); fp->change_time =ksmbd_UnixTimeToNT (stat.ctime); + fp->allocation_size =S_ISDIR (stat.mode) ?0 : + (alloc_size ?: stat.blocks <<9 );if (req->FileAttributes || fp->f_ci->m_fattr ==0 ) fp->f_ci->m_fattr =cpu_to_le32 (smb2_get_dos_mode (&stat,le32_to_cpu (req->FileAttributes)));
@@ -3788,8 +3789,19 @@ int smb2_open(struct ksmbd_work *work) time =ksmbd_UnixTimeToNT (stat.mtime); rsp->LastWriteTime =cpu_to_le64 (time); rsp->ChangeTime =cpu_to_le64 (fp->change_time); - rsp->AllocationSize =S_ISDIR (stat.mode) ?0 : -cpu_to_le64 (stat.blocks <<9 ); +/* +* The cached allocation size hides filesystem rounding for the +* requested allocation, but it can go stale when the file grows past +* it via writes (e.g. across a durable reconnect). Refresh it once the +* file exceeds the cached value, rounding the end of file up to the +* volume allocation unit (the filesystem block size, matching the +* SectorsPerAllocationUnit/BytesPerSector ksmbd advertises) rather than +* using the raw on-disk block count, which can include filesystem +* preallocation and metadata rounding. +*/ +if (!S_ISDIR (stat.mode) && stat.size > fp->allocation_size) + fp->allocation_size =round_up (stat.size, stat.blksize); + rsp->AllocationSize =cpu_to_le64 (fp->allocation_size); rsp->EndofFile =S_ISDIR (stat.mode) ?0 :cpu_to_le64 (stat.size); rsp->FileAttributes = fp->f_ci->m_fattr;
@@ -5082,7 +5094,7 @@ static int get_file_standard_info(struct smb2_query_info_rsp *rsp, delete_pending =ksmbd_inode_pending_delete (fp);if (ksmbd_stream_fd (fp) == false) { - sinfo->AllocationSize =cpu_to_le64 (stat.blocks <<9 ); + sinfo->AllocationSize =cpu_to_le64 (fp->allocation_size); sinfo->EndOfFile =S_ISDIR (stat.mode) ?0 :cpu_to_le64 (stat.size); }else { sinfo->AllocationSize =cpu_to_le64 (fp->stream.size);
@@ -5161,8 +5173,7 @@ static int get_file_all_info(struct ksmbd_work *work, file_info->Attributes = fp->f_ci->m_fattr; file_info->Pad1 =0 ;if (ksmbd_stream_fd (fp) == false) { - file_info->AllocationSize = -cpu_to_le64 (stat.blocks <<9 ); + file_info->AllocationSize =cpu_to_le64 (fp->allocation_size); file_info->EndOfFile =S_ISDIR (stat.mode) ?0 :cpu_to_le64 (stat.size); }else { file_info->AllocationSize =cpu_to_le64 (fp->stream.size);
@@ -5372,7 +5383,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp, file_info->ChangeTime =cpu_to_le64 (fp->change_time); file_info->Attributes = fp->f_ci->m_fattr;if (ksmbd_stream_fd (fp) == false) { - file_info->AllocationSize =cpu_to_le64 (stat.blocks <<9 ); + file_info->AllocationSize =cpu_to_le64 (fp->allocation_size); file_info->EndOfFile =S_ISDIR (stat.mode) ?0 :cpu_to_le64 (stat.size); }else { file_info->AllocationSize =cpu_to_le64 (fp->stream.size);
@@ -5500,7 +5511,7 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, file_info->Inode =cpu_to_le64 (stat.ino);if (ksmbd_stream_fd (fp) == false) { file_info->EndOfFile =cpu_to_le64 (stat.size); - file_info->AllocationSize =cpu_to_le64 (stat.blocks <<9 ); + file_info->AllocationSize =cpu_to_le64 (fp->allocation_size); }else { file_info->EndOfFile =cpu_to_le64 (fp->stream.size); file_info->AllocationSize =cpu_to_le64 (fp->stream.size);
@@ -6241,8 +6252,7 @@ int smb2_close(struct ksmbd_work *work) } rsp->Flags =SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB ; - rsp->AllocationSize =S_ISDIR (stat.mode) ?0 : -cpu_to_le64 (stat.blocks <<9 ); + rsp->AllocationSize =cpu_to_le64 (fp->allocation_size); rsp->EndOfFile =cpu_to_le64 (stat.size); rsp->Attributes = fp->f_ci->m_fattr; rsp->CreationTime =cpu_to_le64 (fp->create_time);
@@ -6581,6 +6591,8 @@ static int set_file_allocation_info(struct ksmbd_work *work,return rc; } } + + fp->allocation_size =le64_to_cpu (file_alloc_info->AllocationSize);return 0 ; }
fs/smb/server/vfs_cache.h +1 -0
@@ -102,6 +102,7 @@ struct ksmbd_file {__le32 cdoption;__u64 create_time;__u64 change_time; +__u64 allocation_size;__u64 itime;bool is_nt_open;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1850/2151 ksmbd: stabilize allocation size after buffered writes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 84c41b731b019f1e5a97c21ac1a4a4c63b6be38f ]
Ordinary opens initialize their allocation size from stat.blocks. Buffered writes can leave delayed allocation pending, so separate handles can cache different block counts for the same file.
This makes generic/568 fail when a zero write used for fallocate emulation is followed by an overwrite of the same range. The first query can report the pre-writeback block count, while the second query reports the block count after delayed allocation is completed.
Complete writeback and refresh the cached block count before returning allocation information for ordinary opens. Track client-specified allocation sizes separately so CREATE allocation contexts and FILE_ALLOCATION_INFORMATION continue to return the requested value.
Stable-dep-of: aad7d86a6651 ("ksmbd: round SetAllocation to the advertised allocation unit")
--- fs/smb/server/smb2pdu.c | 38 ++++++++++++++++++++++++++++++-------- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 31 insertions(+), 8 deletions(-)
fs/smb/server/smb2pdu.c +30 -8
@@ -3688,6 +3688,7 @@ int smb2_open(struct ksmbd_work *work) goto err_out1; } alloc_size =le64_to_cpu (az_req->AllocationSize); + fp->allocation_size_set = true;ksmbd_debug (SMB ,"request smb2 create allocate size : %llu\n" , alloc_size);
@@ -5077,6 +5078,30 @@ static int get_file_basic_info(struct smb2_query_info_rsp *rsp,return 0 ; } +static int get_file_allocation_stat (struct ksmbd_file *fp,struct kstat *stat) +{ +int ret; + +/* +* Buffered writes can leave delayed allocation in a state where two +* consecutive queries report different block counts even when the +* second write only overwrites the first one. Complete writeback before +* reporting the filesystem allocation for an ordinary open. +*/ +if (!fp->allocation_size_set) { + ret =file_write_and_wait (fp->filp); +if (ret) +return ret; + } + + ret =vfs_getattr (&fp->filp->f_path, stat,STATX_BASIC_STATS , +AT_STATX_SYNC_AS_STAT ); +if (!ret && !fp->allocation_size_set) + fp->allocation_size =S_ISDIR (stat->mode) ?0 : stat->blocks <<9 ; + +return ret; +} +static int get_file_standard_info (struct smb2_query_info_rsp *rsp,struct ksmbd_file *fp,void *rsp_org) {
@@ -5085,8 +5110,7 @@ static int get_file_standard_info(struct smb2_query_info_rsp *rsp,struct kstat stat;int ret; - ret =vfs_getattr (&fp->filp->f_path, &stat,STATX_BASIC_STATS , -AT_STATX_SYNC_AS_STAT ); + ret =get_file_allocation_stat (fp, &stat);if (ret)return ret;
@@ -5153,8 +5177,7 @@ static int get_file_all_info(struct ksmbd_work *work,return -EINVAL ; } - ret =vfs_getattr (&fp->filp->f_path, &stat,STATX_BASIC_STATS , -AT_STATX_SYNC_AS_STAT ); + ret =get_file_allocation_stat (fp, &stat);if (ret) {kfree (filename);return ret;
@@ -5368,8 +5391,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp,return -EACCES ; } - ret =vfs_getattr (&fp->filp->f_path, &stat,STATX_BASIC_STATS , -AT_STATX_SYNC_AS_STAT ); + ret =get_file_allocation_stat (fp, &stat);if (ret)return ret;
@@ -5495,8 +5517,7 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp,return -EACCES ; } - ret =vfs_getattr (&fp->filp->f_path, &stat,STATX_BASIC_STATS , -AT_STATX_SYNC_AS_STAT ); + ret =get_file_allocation_stat (fp, &stat);if (ret)return ret;
@@ -6593,6 +6614,7 @@ static int set_file_allocation_info(struct ksmbd_work *work, } fp->allocation_size =le64_to_cpu (file_alloc_info->AllocationSize); + fp->allocation_size_set = true;return 0 ; }
fs/smb/server/vfs_cache.h +1 -0
@@ -107,6 +107,7 @@ struct ksmbd_file {bool is_nt_open;bool attrib_only; +bool allocation_size_set;char client_guid[16 ];char create_guid[16 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1851/2151 ksmbd: round SetAllocation to the advertised allocation unit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit aad7d86a6651efefb2c0a4f02c86dfeff3c176a2 ]
SetAllocation rounds requests to 512-byte blocks, although FS_SIZE_INFORMATION advertises the filesystem's f_bsize as its allocation unit. For example, on a filesystem with a 4 KiB unit, a 1000-byte request can truncate an 8 KiB file to 1024 bytes instead of 4 KiB.
Round the request to the advertised unit and use the same result for the block-count decision, fallocate, truncate, and the size stored on the open handle. Validate the unit and rounded size before either operation. Use DIV_ROUND_UP_ULL() so the calculation works on 32-bit kernels.
This does not change the existing block-count decision for whether to call fallocate. In particular, success does not yet guarantee reservation of holes within the requested range on a sparse file.
--- fs/smb/server/smb2pdu.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
fs/smb/server/smb2pdu.c +20 -15
@@ -6560,10 +6560,11 @@ static int set_file_allocation_info(struct ksmbd_work *work,* properly with any smb.conf option */ -loff_t alloc_blks; -u64 alloc_size; +u64 alloc_size, target, alloc_blks; +u32 alloc_unit;struct inode *inode;struct kstat stat; +struct kstatfs stfs;int rc;if (!(fp->daccess &FILE_WRITE_DATA_LE ))
@@ -6576,44 +6577,48 @@ static int set_file_allocation_info(struct ksmbd_work *work, AT_STATX_SYNC_AS_STAT);if (rc)return rc; + rc =vfs_statfs (&fp->filp->f_path, &stfs); +if (rc) +return rc;/* -* AllocationSize is fully client-controlled (the caller only -* validates the fixed 8-byte buffer length). Reject values that -* would overflow the "round up to 512-byte blocks" conversion -* below instead of silently wrapping it to a tiny block count, -* which would truncate the file to a size the client never -* asked for. +* Use the allocation unit advertised in FS_SIZE_INFORMATION. +* Reject requests that overflow when rounded to a whole unit. */ alloc_size =le64_to_cpu (file_alloc_info->AllocationSize); -if (alloc_size >MAX_LFS_FILESIZE -511 ) +if (stfs.f_bsize <=0 || (u64 )stfs.f_bsize >U32_MAX ) +return -EINVAL ; + alloc_unit = stfs.f_bsize; +if (alloc_size >MAX_LFS_FILESIZE - (alloc_unit -1 ))return -EINVAL ; - alloc_blks = (alloc_size +511 ) >>9 ; + target =DIV_ROUND_UP_ULL (alloc_size, alloc_unit) * alloc_unit; + alloc_blks =DIV_ROUND_UP_ULL (target,512 ); inode =file_inode (fp->filp); +if (target > inode->i_sb->s_maxbytes) +return -EINVAL ;if (alloc_blks > stat.blocks) {smb_break_all_levII_oplock (work, fp,1 ); - rc =vfs_fallocate (fp->filp,FALLOC_FL_KEEP_SIZE ,0 , - alloc_blks *512 ); + rc =vfs_fallocate (fp->filp,FALLOC_FL_KEEP_SIZE ,0 , target);if (rc && rc != -EOPNOTSUPP ) {pr_err ("vfs_fallocate is failed : %d\n" , rc);return rc; } }else if (alloc_blks < stat.blocks && - alloc_blks *512 <=i_size_read (inode)) { + target <=i_size_read (inode)) {/* * Truncate at or below EOF to discard excess allocation. * Truncating above EOF would extend the file on disk. */ - rc =ksmbd_vfs_truncate (work, fp, alloc_blks *512 ); + rc =ksmbd_vfs_truncate (work, fp, target);if (rc) {pr_err ("truncate failed!, err %d\n" , rc);return rc; } } - fp->allocation_size =le64_to_cpu (file_alloc_info->AllocationSize); + fp->allocation_size = target; fp->allocation_size_set = true;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1852/2151 ksmbd: fix fd_limit accounting across durable reconnects
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit df5c868f6b80ca16c171cfac5e4e6c9be83ba4c2 ]
A disconnected durable handle keeps its ksmbd_file and the fd_limit reservation taken at its initial open. Reconnecting allocates another volatile ID and takes another reservation for the same file. Final close returns only one reservation, so repeated reconnects permanently reduce the server-wide open-file budget.
Move reservation into ksmbd_open_fd() and release it on every creation failure. Keep the reservation until final close, including while a durable handle is disconnected. Make ID allocation independent of fd_limit so reconnects neither consume nor return slots. This also avoids returning an unreserved slot when persistent ID allocation fails.
New opens continue to return -EMFILE when the budget is exhausted, keeping the existing STATUS_INSUFFICIENT_RESOURCES mapping.
--- fs/smb/server/vfs_cache.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
fs/smb/server/vfs_cache.c +8 -7
@@ -721,11 +721,6 @@ static int __open_id(struct ksmbd_file_table *ft, struct ksmbd_file *fp,u64 id =0 ;int ret; -if (type ==OPEN_ID_TYPE_VOLATILE_ID &&fd_limit_depleted ()) { -__open_id_set (fp,KSMBD_NO_FID , type); -return -EMFILE ; - } -idr_preload (KSMBD_DEFAULT_GFP );write_lock (&ft->lock); ret = idr_alloc_cyclic(ft->idr, fp, KSMBD_START_FID, INT_MAX - 1,
@@ -735,7 +730,6 @@ static int __open_id(struct ksmbd_file_table *ft, struct ksmbd_file *fp, ret =0 ; }else { id =KSMBD_NO_FID ; -fd_limit_close (); }__open_id_set (fp, id, type);
@@ -755,10 +749,15 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp)struct ksmbd_file *fp;int ret; +/* Durable reconnects reuse the slot held for the lifetime of fp. */ +if (fd_limit_depleted ()) +return ERR_PTR (-EMFILE ); + fp =kmem_cache_zalloc (filp_cache,KSMBD_DEFAULT_GFP );if (!fp) {pr_err ("Failed to allocate memory\n" ); -return ERR_PTR (-ENOMEM ); + ret = -ENOMEM ; + goto err_fd_limit; }INIT_LIST_HEAD (&fp->blocked_works);
@@ -801,6 +800,8 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp)/* fp->conn was set and refcounted before every branch here. */ ksmbd_conn_put (fp->conn);kmem_cache_free (filp_cache, fp); +err_fd_limit: +fd_limit_close ();return ERR_PTR (ret); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1853/2151 ksmbd: reject foreign RPC pipe handles on IPC$ read and write
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohammed Alquraini <[email protected]>
[ Upstream commit da25995071e5e0f3aa9a41160b00b2f833127b3e ]
RPC pipe handles on IPC$ are allocated from a single server-global IDA, and ksmbd.mountd looks a pipe up by handle alone, with no session information. smb2_read_pipe() and smb2_write_pipe() take the handle straight from the client request (VolatileFileId) and pass it to the daemon without checking that the requesting session opened it. An authenticated user can therefore issue an SMB2 READ or WRITE on IPC$ with another session's handle and receive that session's in-flight DCERPC response, or write attacker-chosen bytes into its pipe stream. A tree connect to IPC$, which every RPC client already has, is the only requirement.
Validate ownership before the transfer, the way the sibling pipe paths already do: under sess->rpc_lock, ksmbd_session_rpc_method() returns 0 for a handle the session did not open. smb2_get_info_file_pipe() and the FSCTL_PIPE_TRANSCEIVE ioctl already reject such handles; read and write were the remaining gap. Reject them with STATUS_FILE_CLOSED, as the ioctl path does.
--- fs/smb/server/smb2pdu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
fs/smb/server/smb2pdu.c +20 -0
@@ -7001,6 +7001,16 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work) id = req->VolatileFileId; +lockdep_assert_not_held (&work->sess->rpc_lock); +down_read (&work->sess->rpc_lock); +if (!ksmbd_session_rpc_method (work->sess, id)) { +up_read (&work->sess->rpc_lock); + rsp->hdr.Status =STATUS_FILE_CLOSED ; +smb2_set_err_rsp (work); +return -ENOENT ; + } +up_read (&work->sess->rpc_lock); + rpc_resp =ksmbd_rpc_read (work->sess, id);if (rpc_resp) {void *aux_payload_buf;
@@ -7317,6 +7327,16 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work) goto out; } +lockdep_assert_not_held (&work->sess->rpc_lock); +down_read (&work->sess->rpc_lock); +if (!ksmbd_session_rpc_method (work->sess, id)) { +up_read (&work->sess->rpc_lock); + rsp->hdr.Status =STATUS_FILE_CLOSED ; +smb2_set_err_rsp (work); +return -ENOENT ; + } +up_read (&work->sess->rpc_lock); + data_buf = (char *)(((char *)&req->hdr.ProtocolId) + data_offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1854/2151 ksmbd: reject FILE_ATTRIBUTE_TEMPORARY on directories
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michail Andreas Michalopoulos <[email protected]>
[ Upstream commit 8323aab48525b83f750e712f66e6e9387b550cf4 ]
Setting FILE_ATTRIBUTE_TEMPORARY on a directory with SMB2 SET_INFO (FileBasicInformation) succeeds: ksmbd keeps the attribute and, with "store dos attributes" enabled, also writes it to the DOS attribute xattr.
MS-FSA (FileBasicInformation) says the request must fail with STATUS_INVALID_PARAMETER when FILE_ATTRIBUTE_TEMPORARY is set on a directory, and Samba rejects it too. smbtorture's smb2.create.dosattr_tmp_dir checks this and fails against ksmbd.
Return -EINVAL, which is sent as STATUS_INVALID_PARAMETER, when a directory is asked to become TEMPORARY. Do the check before any timestamp is changed, so a rejected request leaves the open file and the inode unchanged.
--- fs/smb/server/smb2pdu.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/smb/server/smb2pdu.c +5 -0
@@ -6486,6 +6486,11 @@ static int set_file_basic_info(struct ksmbd_file *fp, inode =file_inode (filp); idmap =file_mnt_idmap (filp); +/* MS-FSA FileBasicInformation: a directory can't be marked TEMPORARY */ +if (S_ISDIR (inode->i_mode) && + (file_info->Attributes &FILE_ATTRIBUTE_TEMPORARY_LE )) +return -EINVAL ; +if (file_info->CreationTime) fp->create_time =le64_to_cpu (file_info->CreationTime);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1855/2151 net: pse-pd: si3474: fix use-after-free in ancillary client error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlo Szelinsky <[email protected]>
[ Upstream commit 70c29b35fd87f87a7b8dad6eb8d55ce54a0d549a ]
If devm_add_action_or_reset() fails, it has already unregistered the ancillary I2C client, and the error message then reads that client's device. It can only fail with -ENOMEM, which is already reported, so drop the message.
Found by code inspection. Not reproduced.
--- drivers/net/pse-pd/si3474.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/pse-pd/si3474.c +1 -3
@@ -516,10 +516,8 @@ static int si3474_i2c_probe(struct i2c_client *client)return PTR_ERR (priv->client[1 ]); ret =devm_add_action_or_reset (dev, si3474_ancillary_i2c_remove, priv->client[1 ]); -if (ret <0 ) { -dev_err (&priv->client[1 ]->dev,"Cannot register remove callback\n" ); +if (ret)return ret; - } ret =i2c_smbus_read_byte_data (priv->client[1 ],VENDOR_IC_ID_REG );if (ret <0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1856/2151 net: skbuff: dont copy alloc_cpu in skb header copies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 78d4bd22ec9df490135303c00e190ac43d5c334a ]
Commit 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") added alloc_cpu to struct sk_buff and placed it in the headers group copied by __copy_skb_header().
This is wrong for newly allocated skbs. For example, skb_segment() allocates a new skb and records the current CPU in alloc_cpu, but __copy_skb_header() overwrites it with the value from the original skb.
If the original skb was allocated on another CPU, the segment may later be treated as remotely allocated and unnecessarily deferred there when it is freed.
Move alloc_cpu out of the headers group so it is preserved across header copies. Copy it explicitly in skb_clone(), which allocates the skb object directly instead of going through __alloc_skb().
This was discovered while investigating a throughput regression with software IPsec. The load used 512 IPsec tunnels carrying traffic over VXLAN, with 512 parallel iperf3 flows and an MTU of 4500.
Before the fix:
16.09% queued_spin_lock_slowpath
|
--15.90%--_raw_spin_lock_irqsave
|
--9.37%--__slab_free
kfree
skb_release_data
napi_consume_skb
mlx5e_poll_tx_cqAfter the fix:
6.84% queued_spin_lock_slowpath
|
--6.57%--_raw_spin_lock_irqsave
|
--5.00%--__slab_free
kfree
skb_release_data
napi_consume_skb
mlx5e_poll_tx_cq--- include/linux/skbuff.h | 4 ++-- net/core/skbuff.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/skbuff.h +2 -2
@@ -1036,8 +1036,6 @@ struct sk_buff {__u16 tc_index;/* traffic control index */ #endif -u16 alloc_cpu; - union { __wsum csum; struct {
@@ -1090,6 +1088,8 @@ struct sk_buff { ); /* end headers group */ +u16 alloc_cpu; +/* These elements must be at the end, see alloc_skb() for details. */ sk_buff_data_t tail;sk_buff_data_t end;
net/core/skbuff.c +1 -1
@@ -1530,7 +1530,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NET_RX_BUSY_POLL CHECK_SKB_FIELD (napi_id);#endif -CHECK_SKB_FIELD (alloc_cpu);#ifdef CONFIG_XPS CHECK_SKB_FIELD (sender_cpu);#endif
@@ -1562,6 +1561,7 @@ static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb)C (pfmemalloc);C (pp_recycle); n->destructor =NULL ; +C (alloc_cpu);C (tail);C (end);C (head);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1857/2151 tcp_bpf: propagate error code in tcp_bpf_sendmsg()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Antipov <[email protected]>
[ Upstream commit 82e31923c0553fdbfcddcd910ca07952880ca9b9 ]
In tcp_bpf_sendmsg(), the value returned by sk_msg_memcopy_from_iter() is checked for error but not propagated to 'out_err' label, so error handling may not work as expected. Fix this by assigning error value to 'err', thus making sure that error won't be silently ignored.
--- net/ipv4/tcp_bpf.c | 1 + 1 file changed, 1 insertion(+)
net/ipv4/tcp_bpf.c +1 -0
@@ -581,6 +581,7 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) copy);if (ret <0 ) {sk_msg_trim (sk, msg_tx, osize); + err = ret; goto out_err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1858/2151 ocfs2: reserve xattr value tree metadata only once
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 5365f1f417b36627f825aacf9844ae24b671b525 ]
ocfs2_calc_xattr_set_need() asks for the new value's extent tree twice when it replaces an inline value smaller than a value root with one large enough to be stored outside. The "stored outside" branch reserves the tree and then falls through to meta_guess instead of going out:
if (!ocfs2_xattr_is_local(xe)) {
...
xv = (struct ocfs2_xattr_value_root *)
(base + name_offset + name_len);
value_size = OCFS2_XATTR_ROOT_SIZE;
} else
xv = &def_xv.xv;
if (old_clusters >= new_clusters) {
...
goto out;
} else {
meta_add += ocfs2_extend_meta_needed(&xv->xr_list);
...
if (value_size >= OCFS2_XATTR_ROOT_SIZE)
goto out;
}On the fall-through xv is def_xv, so what gets added here is the two blocks ocfs2_extend_meta_needed() wants for an empty value root -- and both sides of meta_guess reserve that same tree again. The create side has done so since commit 3ed2be719eb9 ("ocfs2: allow for more than one data extent when creating xattr"), which ported this reservation to the create case without noticing it was already on the way in, and the existing-block side since commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs"). Both were chasing the same RESTART_META failure in ocfs2_xattr_extend_allocation(), for xattr create and then for xattr update.
ocfs2_init_xattr_set_ctxt() hands the total straight to ocfs2_reserve_new_metadata_blocks(), so the surplus is two blocks held for the whole transaction. A setxattr that would otherwise fit can come back -ENOSPC on a filesystem whose metadata allocator is nearly exhausted.
Move the reservation into the branch that stops there, leaving meta_guess as the only place that reserves for a value tree the fall through is about to create. The paths that do go out keep reserving against the value root they already have, which for an external old value is the on-disk one and so can legitimately ask for more than two blocks.
Both sides of meta_guess have to come out even on their own now that the copy covering for them is gone. The existing-block side only started reserving the value tree in the commit this one is tagged against. The create side has reserved the tree since 3ed2be719eb9, but only the tree:
the block ocfs2_create_xattr_block() claims came out of the same two, and on the fall-through it was the duplicate removed here that made up the difference. So "ocfs2: reserve metadata for a new xattr block and its value tree" has to land first -- without it the create side reserves 2 where 3 are needed and the value tree is back to RESTART_META. That one fixes a shortfall of its own on the path that reaches meta_guess directly, where there was never a duplicate to cover it, so it is worth taking alone; this patch is not.
--- fs/ocfs2/xattr.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
fs/ocfs2/xattr.c +15 -2
@@ -3217,12 +3217,21 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, credits +=ocfs2_remove_extent_credits (inode->i_sb); goto out; }else { - meta_add +=ocfs2_extend_meta_needed (&xv->xr_list); clusters_add += new_clusters - old_clusters; credits +=ocfs2_calc_extend_credits (inode->i_sb, &xv->xr_list); -if (value_size >=OCFS2_XATTR_ROOT_SIZE ) +/* +* The old value occupies at least as much room as a +* value root, whether it sat outside or inline, so the +* new root fits where it was and no new xattr block or +* bucket is needed -- only the metadata to extend the +* tree hanging off it. A smaller one is replaced +* outright, which meta_guess below reserves for. +*/ +if (value_size >=OCFS2_XATTR_ROOT_SIZE ) { + meta_add +=ocfs2_extend_meta_needed (&xv->xr_list); goto out; + } } }else {/*
@@ -3274,6 +3283,10 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode,* Reserve metadata for the new xattr's value extent tree. * The not_found path above adds credits for this tree but * omits meta_add, leaving meta_ac NULL for large values. +* +* This is all of meta_ac on this side beyond the xattr tree +* above: no xattr block is allocated here, and a new bucket or +* index block is paid for out of data_ac. */ if (xi->xi_value_len >OCFS2_XATTR_INLINE_SIZE ) meta_add +=ocfs2_extend_meta_needed (&def_xv.xv.xr_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1859/2151 ocfs2: initialize status waiters before publishing them
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f6bfa6c458288d72948af95391b205f3eb775721 ]
o2net_prep_nsw() publishes its stack waiter in nn_status_idr and nn_status_list under nn_lock, then initializes the wait queue and completion status after releasing the lock. A concurrent disconnect can find that waiter through o2net_complete_nodes_nsw() and call wake_up() before the wait queue has a valid lock and list head. The sender can also overwrite a completion status with its initial value.
Initialize the wait queue and status before publishing the waiter. nn_lock then orders publication against completion, and no reader can observe a partially initialized object. Leave the IDR allocation and its failure handling unchanged.
A controlled case-modified test kernel used a synthetic connection to enter the real send path and overlap publication with disconnect. The candidate completion and wake-up code were unchanged. Its Oops includes:
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:__wake_up_common+0xa0/0x1f0 Call Trace: <TASK> __wake_up+0x36/0x60 o2net_complete_nsw_locked+0x222/0x370 o2net_set_nn_state+0x917/0xea0 o2net_disconnect_node+0xd0/0x190 o2net_validate_control_write+0x454/0x500 full_proxy_write+0x11f/0x180 vfs_write+0x25a/0x1010 ksys_write+0x111/0x200 do_syscall_64+0x114/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Modules linked in:
--- fs/ocfs2/cluster/tcp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ocfs2/cluster/tcp.c +5 -3
@@ -301,6 +301,11 @@ static int o2net_prep_nsw(struct o2net_node *nn, struct o2net_status_wait *nsw) {int ret; +/* Initialize all completion-visible state before publishing the waiter. */ +init_waitqueue_head (&nsw->ns_wq); + nsw->ns_sys_status =O2NET_ERR_NONE ; + nsw->ns_status =0 ; +spin_lock (&nn->nn_lock); ret =idr_alloc (&nn->nn_status_idr, nsw,0 ,0 ,GFP_ATOMIC );if (ret >=0 ) {
@@ -311,9 +316,6 @@ static int o2net_prep_nsw(struct o2net_node *nn, struct o2net_status_wait *nsw)if (ret <0 )return ret; -init_waitqueue_head (&nsw->ns_wq); - nsw->ns_sys_status =O2NET_ERR_NONE ; - nsw->ns_status =0 ;return 0 ; }
Signature · 1 line
2.53.0