6.18.35-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 62/307 tunnels: do not assume transport header in iptunnel_pmtud_check_icmp()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 509323077ef79a26ba0c60bb556e45c12c398b2d ]
In some cases, iptunnel_pmtud_check_icmp() can be called while skb transport header is not set.
This triggers an out-of-bound access, because
(typeof(skb->transport_header))~0U is 65535.
Access the icmp header based on IPv4 network header, after making sure icmp->type is present in skb linear part.
Note that iptunnel_pmtud_check_icmpv6()) is fine.
--- net/ipv4/ip_tunnel_core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
net/ipv4/ip_tunnel_core.c +10 -3
@@ -278,7 +278,6 @@ static int iptunnel_pmtud_build_icmp(struct sk_buff *skb, int mtu)*/ static int iptunnel_pmtud_check_icmp (struct sk_buff *skb,int mtu) { -const struct icmphdr *icmph =icmp_hdr (skb);const struct iphdr *iph =ip_hdr (skb);if (mtu <576 || iph->frag_off !=htons (IP_DF ))
@@ -289,9 +288,17 @@ static int iptunnel_pmtud_check_icmp(struct sk_buff *skb, int mtu) ipv4_is_lbcast(iph->saddr) || ipv4_is_multicast(iph->saddr))return 0 ; -if (iph->protocol ==IPPROTO_ICMP &&icmp_is_err (icmph->type)) -return 0 ; +if (iph->protocol ==IPPROTO_ICMP ) { +const struct icmphdr *icmph; +if (!pskb_network_may_pull (skb, iph->ihl *4 + + offsetofend(struct icmphdr, type))) +return 0 ; + iph =ip_hdr (skb); + icmph = (void *)iph + iph->ihl *4 ; +if (icmp_is_err (icmph->type)) +return 0 ; + }return iptunnel_pmtud_build_icmp (skb, mtu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 63/307 ASoC: codecs: simple-mux: Fix enum control bounds check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
[ Upstream commit f63ad68e18d774a5d15cd7e405ead63f6b322679 ]
simple_mux_control_put() rejects values greater than e->items, but enum control values are zero based. For the two-entry mux used by this driver, valid values are 0 and 1, so value 2 must be rejected as well.
Accepting e->items can store an invalid mux state, pass it to the GPIO setter, and pass it on to the DAPM mux update path where it is used as an index into the enum text array.
Use the same >= e->items check used by the ASoC enum helpers.
--- sound/soc/codecs/simple-mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/simple-mux.c +1 -1
@@ -49,7 +49,7 @@ static int simple_mux_control_put(struct snd_kcontrol *kcontrol,struct snd_soc_component *c =snd_soc_dapm_to_component (dapm);struct simple_mux *priv =snd_soc_component_get_drvdata (c); -if (ucontrol->value.enumerated.item[0 ] > e->items) +if (ucontrol->value.enumerated.item[0 ] >= e->items)return -EINVAL ;if (priv->mux == ucontrol->value.enumerated.item[0 ])
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 64/307 Bluetooth: 6lowpan: check skb_clone() return value in send_mcast_pkt()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Dongdong <[email protected]>
[ Upstream commit 3c40d381ce04f9575a5d8b542898183c3b4b38dc ]
The skb_clone() function can return NULL if memory allocation fails. send_mcast_pkt() calls skb_clone() without checking the return value, which can lead to a NULL pointer dereference in send_pkt() when it dereferences skb->data.
Add a NULL check after skb_clone() and skip the peer if the clone fails.
--- net/bluetooth/6lowpan.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/6lowpan.c +2 -0
@@ -485,6 +485,8 @@ static int send_mcast_pkt(struct sk_buff *skb, struct net_device *netdev)int ret; local_skb =skb_clone (skb,GFP_ATOMIC ); +if (!local_skb) +continue ; BT_DBG("xmit %s to %pMR type %u IP %pI6c chan %p", netdev->name,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 65/307 bonding: refuse to enslave CAN devices
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
[ Upstream commit 8ba68464e4787b6a7ec938826e16124df20fd23d ]
syzbot reported a kernel paging request crash in can_rx_unregister() inside net/can/af_can.c. The crash occurs because a virtual CAN device (vxcan) is being enslaved to a bonding master.
During the enslavement process, the bonding driver mutates and modifies the network device states to fit an Ethernet-like aggregation model. However, CAN devices operate on a completely different Layer 2 architecture, relying on the CAN mid-layer private data structure (can_ml_priv) instead of standard Ethernet structures. Since bonding does not initialize or maintain these CAN structures, subsequent operations on the half-enslaved interface (such as closing associated sockets via isotp_release) lead to a null-pointer dereference when accessing the CAN receiver lists.
Bonding CAN interfaces is architecturally invalid as CAN lacks MAC addresses, ARP capabilities, and standard Ethernet link-layer mechanisms. While generic loopback devices are blocked globally in net/core/dev.c, virtual CAN devices bypass this check because they do not carry the IFF_LOOPBACK flag, despite acting as local software-loopbacks.
Fix this by explicitly blocking network devices of type ARPHRD_CAN from being enslaved at the very beginning of bond_enslave(). This prevents illegal state mutations, eliminates the resulting KASAN crashes, and avoids potential memory leaks from incomplete socket cleanups.
As the CAN support has been added a long time after bonding the Fixes-tag points to the introduction of ARPHRD_CAN that would have needed a specific handling in bonding_main.c.
--- drivers/net/bonding/bond_main.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/bonding/bond_main.c +6 -0
@@ -1927,6 +1927,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,int link_reporting;int res =0 , i; +if (slave_dev->type ==ARPHRD_CAN ) { +BOND_NL_ERR (bond_dev, extack, +"CAN devices cannot be enslaved" ); +return -EPERM ; + } +if (slave_dev->flags &IFF_MASTER && !netif_is_bond_master (slave_dev)) { BOND_NL_ERR(bond_dev, extack,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 66/307 ethtool: coalesce: cap profile updates at NET_DIM_PARAMS_NUM_PROFILES
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 7281b096b072f6c6e30420e3467d738f2e4c4b57 ]
ethnl_update_profile() walks the ETHTOOL_A_PROFILE_IRQ_MODERATION nest list with an index 'i' and writes new_profile[i++] without bounding i. The destination is kmemdup()'d at NET_DIM_PARAMS_NUM_PROFILES entries (5), but the Netlink nest count is entirely user-controlled. Netlink policies do not have support for constraining the number of nested entries (or number of multi-attr entries).
--- net/ethtool/coalesce.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ethtool/coalesce.c +6 -0
@@ -463,6 +463,12 @@ static int ethnl_update_profile(struct net_device *dev,nla_for_each_nested_type (nest,ETHTOOL_A_PROFILE_IRQ_MODERATION , nests, rem) { +if (i >=NET_DIM_PARAMS_NUM_PROFILES ) { +NL_SET_BAD_ATTR (extack, nest); + ret = -E2BIG ; + goto err_out; + } + ret =nla_parse_nested (tb, len_irq_moder -1 , nest, coalesce_irq_moderation_policy, extack);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 67/307 ethtool: linkstate: fix unbalanced ethnl_ops_complete() on PHY lookup error
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 596c51ed9e125b12c4d85b4530dfd4c7847634b7 ]
linkstate_prepare_data() calls ethnl_req_get_phydev() before ethnl_ops_begin(), but routes its error path through "goto out" which calls ethnl_ops_complete().
--- net/ethtool/linkstate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/ethtool/linkstate.c +2 -4
@@ -105,10 +105,8 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base, phydev =ethnl_req_get_phydev (req_base, tb,ETHTOOL_A_LINKSTATE_HEADER , info->extack); -if (IS_ERR (phydev)) { - ret =PTR_ERR (phydev); - goto out; - } +if (IS_ERR (phydev)) +return PTR_ERR (phydev); ret =ethnl_ops_begin (dev);if (ret <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 68/307 ethtool: pse-pd: fix missing ethnl_ops_complete()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit ab5bf428fb6bd361163c7247b92750d1d24ca2ed ]
pse_prepare_data() is missing ethnl_ops_complete() if ethnl_req_get_phydev() returned an error. Move getting phydev up so that we don't have to worry about this (similar order to linkstate_prepare_data()).
Note that phydev may still be NULL (this is checked in pse_get_pse_attributes()), the goal isn't really to avoid the _begin() / _complete() calls, only to simplify the error handling.
While at it propagate the original error. Why this code overrides the error with -ENODEV but !phydev generates -EOPNOTSUPP is unclear to me...
--- net/ethtool/pse-pd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/ethtool/pse-pd.c +5 -5
@@ -60,14 +60,14 @@ static int pse_prepare_data(const struct ethnl_req_info *req_base,struct phy_device *phydev;int ret; - ret =ethnl_ops_begin (dev); -if (ret <0 ) -return ret; - phydev =ethnl_req_get_phydev (req_base, tb,ETHTOOL_A_PSE_HEADER , info->extack);if (IS_ERR (phydev)) -return -ENODEV ; +return PTR_ERR (phydev); + + ret =ethnl_ops_begin (dev); +if (ret <0 ) +return ret; ret =pse_get_pse_attributes (phydev, info->extack, data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 69/307 ethtool: strset: fix header attribute index in ethnl_req_get_phydev()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit a8d8bef6b45bf7cc0b1f6110c5cd8d0160a9bad7 ]
strset_prepare_data() passes ETHTOOL_A_HEADER_FLAGS (3) as the header attribute to ethnl_req_get_phydev(). This is incorrect, in the main attr space 3 is ETHTOOL_A_STRSET_COUNTS_ONLY, not the request header attr. The correct constant is ETHTOOL_A_STRSET_HEADER (1).
ethnl_req_get_phydev() only uses this value for the extack, so this is not a "functionally visible"(?) bug.
--- net/ethtool/strset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ethtool/strset.c +1 -1
@@ -299,7 +299,7 @@ static int strset_prepare_data(const struct ethnl_req_info *req_base,return 0 ; } - phydev =ethnl_req_get_phydev (req_base, tb,ETHTOOL_A_HEADER_FLAGS , + phydev =ethnl_req_get_phydev (req_base, tb,ETHTOOL_A_STRSET_HEADER , info->extack);/* phydev can be NULL, check for errors only */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 70/307 ethtool: eeprom: add missing ethnl_ops_begin() / _complete() during fallback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 2376586f85f972fefe701f095bb37dcfe7405d21 ]
All ethtool driver op calls should be sandwiched between ethnl_ops_begin() / ethnl_ops_complete(). In Netlink eeprom code, if the paged access failed we fall back to old API, but we first call _complete() and the fallback never does its own ethnl_ops_begin(). Move the fallback into the _begin() / _complete() section.
--- net/ethtool/eeprom.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/ethtool/eeprom.c +2 -3
@@ -140,12 +140,11 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,return 0 ; err_ops: +if (ret == -EOPNOTSUPP ) + ret =eeprom_fallback (request, reply);ethnl_ops_complete (dev); err_free:kfree (page_data.data); - -if (ret == -EOPNOTSUPP ) -return eeprom_fallback (request, reply);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 71/307 ethtool: eeprom: add more safeties to EEPROM Netlink fallback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 67cfdd9210b99f260b3e0afeb9525e0acc7be31e ]
The Netlink fallback path for reading module EEPROM (fallback_set_params()) validates that offset < eeprom_len, but does not check that offset + length stays within eeprom_len. The ioctl equivalent (ethtool_get_any_eeprom() in ioctl.c) has always enforced both bounds:
if (eeprom.offset + eeprom.len > total_len)
return -EINVAL;
This could lead to surprises in both drivers and device FW. Add the missing offset + length validation to fallback_set_params(), mirroring the ioctl.
Similarly - ethtool core in general, and ethtool_get_any_eeprom() in particular tries to zero-init all buffers passed to the drivers to avoid any extra work of zeroing things out. eeprom_fallback() uses a plain kmalloc(), change it to zalloc.
--- net/ethtool/eeprom.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ethtool/eeprom.c +4 -1
@@ -43,6 +43,9 @@ static int fallback_set_params(struct eeprom_req_info *request,if (offset >= modinfo->eeprom_len)return -EINVAL ; +if (length > modinfo->eeprom_len - offset) +return -EINVAL ; + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; eeprom->len = length; eeprom->offset = offset;
@@ -68,7 +71,7 @@ static int eeprom_fallback(struct eeprom_req_info *request,if (err <0 )return err; - data =kmalloc (eeprom.len,GFP_KERNEL ); + data =kzalloc (eeprom.len,GFP_KERNEL );if (!data)return -ENOMEM ; err =ethtool_get_module_eeprom_call (dev, &eeprom, data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 72/307 ipv6: rpl: fix hdrlen overflow in ipv6_rpl_srh_decompress()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rahul Chandelkar <[email protected]>
[ Upstream commit 9d5e7a46a9f6d8f503b41bfefef70659845f1679 ]
ipv6_rpl_srh_decompress() computes:
outhdr->hdrlen = (((n + 1) * sizeof(struct in6_addr)) >> 3);
hdrlen is __u8. For n >= 127 the result exceeds 255 and silently truncates. With n=127 (cmpri=15, cmpre=15, pad=0, hdrlen=16):
(128 * 16) >> 3 = 256, truncated to 0 as __u8
The caller in ipv6_rpl_srh_rcv() then places the compressed header at buf + ((ohdr->hdrlen + 1) << 3). With hdrlen=0 this is buf + 8, but the decompressed region occupies buf[0..2055] (8-byte header plus 128 full addresses). The compressed header overlaps the decompressed data, and ipv6_rpl_srh_compress() writes into this overlap, corrupting the routing header of the forwarded packet.
The existing guard at exthdrs.c:546 checks (n + 1) > 255, which prevents n+1 from overflowing unsigned char (the segments_left field), but does not prevent the computed hdrlen from overflowing __u8. n=127 passes because 128 <= 255, yet hdrlen=256 does not fit.
Tighten the bound to (n + 1) > 127. This caps n at 126, giving hdrlen = (127 * 16) >> 3 = 254, which fits in __u8. The compressed header then lands at buf + ((254 + 1) << 3) = buf + 2040, exactly past the decompressed region (buf[0..2039]). No overlap. 127 segments is well beyond any realistic RPL deployment.
--- net/ipv6/exthdrs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/exthdrs.c +1 -1
@@ -546,7 +546,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)* unsigned char which is segments_left field. Should not be * higher than that. */ -if (r || (n +1 ) >255 ) { +if (r || (n +1 ) >127 ) {kfree_skb (skb);return -1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 74/307 net/sched: fix packet loop on netem when duplicate is on
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 9552b11e3edabc97cfcd9f29103d5afbce7ae183 ]
When netem duplicates a packet it re-enqueues the copy at the root qdisc. If another netem sits in the tree the copy can be duplicated again, recursing until the stack or memory is exhausted.
The original duplication guard temporarily zeroed q->duplicate around the re-enqueue, but that does not cover all cases because it is per-qdisc state shared across all concurrent enqueue paths and is not safe without additional locking.
Use the skb tc_depth field introduced in an earlier patch:
- increment it on the duplicate before re-enqueue
- skip duplication for any skb whose tc_depth is already non-zero.
This marks the packet itself rather than mutating qdisc state, therefore it is safe regardless of tree topology or concurrency.
--- net/sched/sch_netem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/sched/sch_netem.c +3 -4
@@ -459,7 +459,8 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, skb->prev =NULL ;/* Random duplication */ -if (q->duplicate && q->duplicate >=get_crandom (&q->dup_cor, &q->prng)) +if (q->duplicate && skb->tc_depth ==0 && + q->duplicate >=get_crandom (&q->dup_cor, &q->prng)) ++count;/* Drop packet? */
@@ -538,11 +539,9 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,*/ if (skb2) {struct Qdisc *rootq =qdisc_root_bh (sch); -u32 dupsave = q->duplicate;/* prevent duplicating a dup... */ - q->duplicate =0 ; + skb2->tc_depth++;/* prevent duplicating a dup... */ rootq->enqueue (skb2, rootq, to_free); - q->duplicate = dupsave; skb2 =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 75/307 net/sched: act_mirred: Move the recursion counter struct netdev_xmit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 7fe70c06a182a140be9996b02256d907e114479a ]
mirred_nest_level is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking.
Move mirred_nest_level to struct netdev_xmit as u8, provide wrappers.
Stable-dep-of: e80ad525fc7e ("net/sched: act_mirred: Fix return code in early mirred redirect error paths")
--- include/linux/netdevice_xmit.h | 3 +++ net/sched/act_mirred.c | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-)
include/linux/netdevice_xmit.h +3 -0
@@ -8,6 +8,9 @@ struct netdev_xmit {#ifdef CONFIG_NET_EGRESS u8 skip_txqueue;#endif +#if IS_ENABLED (CONFIG_NET_ACT_MIRRED ) +u8 sched_mirred_nest; +#endif };#endif
net/sched/act_mirred.c +25 -3
@@ -30,7 +30,29 @@ static LIST_HEAD(mirred_list);static DEFINE_SPINLOCK (mirred_list_lock);#define MIRRED_NEST_LIMIT 4 -static DEFINE_PER_CPU(unsigned int, mirred_nest_level); + +#ifndef CONFIG_PREEMPT_RT +static u8 tcf_mirred_nest_level_inc_return (void ) +{ +return __this_cpu_inc_return (softnet_data.xmit.sched_mirred_nest); +} + +static void tcf_mirred_nest_level_dec (void ) +{ +__this_cpu_dec (softnet_data.xmit.sched_mirred_nest); +} + +#else +static u8 tcf_mirred_nest_level_inc_return (void ) +{ +return current->net_xmit.sched_mirred_nest++; +} + +static void tcf_mirred_nest_level_dec (void ) +{ + current->net_xmit.sched_mirred_nest--; +} +#endif static bool tcf_mirred_is_act_redirect (int action) {
@@ -423,7 +445,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,int m_eaction;u32 blockid; - nest_level =__this_cpu_inc_return (mirred_nest_level); + nest_level =tcf_mirred_nest_level_inc_return ();if (unlikely (nest_level >MIRRED_NEST_LIMIT )) {net_warn_ratelimited ("Packet exceeded mirred recursion limit on dev %s\n" ,netdev_name (skb->dev));
@@ -454,7 +476,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, retval); dec_nest_level: -__this_cpu_dec (mirred_nest_level); +tcf_mirred_nest_level_dec ();return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 76/307 net/sched: act_mirred: add loop detection
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit fe946a751d9b52b7c45ca34899723b314b79b249 ]
Commit 0f022d32c3ec ("net/sched: Fix mirred deadlock on device recursion") added code in the fast path, even when act_mirred is not used.
Prepare its revert by implementing loop detection in act_mirred.
Adds an array of device pointers in struct netdev_xmit.
tcf_mirred_is_act_redirect() can detect if the array already contains the target device.
Stable-dep-of: e80ad525fc7e ("net/sched: act_mirred: Fix return code in early mirred redirect error paths")
--- include/linux/netdevice_xmit.h | 9 ++++- net/sched/act_mirred.c | 62 +++++++++++++--------------------- 2 files changed, 31 insertions(+), 40 deletions(-)
include/linux/netdevice_xmit.h +8 -1
@@ -2,6 +2,12 @@ #ifndef _LINUX_NETDEVICE_XMIT_H #define _LINUX_NETDEVICE_XMIT_H +#if IS_ENABLED(CONFIG_NET_ACT_MIRRED) +#define MIRRED_NEST_LIMIT 4 +#endif + +struct net_device; + struct netdev_xmit { u16 recursion; u8 more;
@@ -9,7 +15,8 @@ struct netdev_xmit {u8 skip_txqueue;#endif #if IS_ENABLED (CONFIG_NET_ACT_MIRRED ) -u8 sched_mirred_nest; +u8 sched_mirred_nest; +struct net_device *sched_mirred_dev[MIRRED_NEST_LIMIT ];#endif };
net/sched/act_mirred.c +23 -39
98 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 77/307 net: Introduce skb tc depth field to track packet loops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 98b34f3e8c3492cfc89ff943c9d92b4d52863d1d ]
Add a 2-bit per-skb tc depth field to track packet loops across the stack.
The previous per-CPU loop counters like MIRRED_NEST_LIMIT assume a single call stack and lose state in two cases:
1) When a packet is queued and reprocessed later (e.g., egress->ingress via backlog), the per-cpu state is gone by the time it is dequeued.
2) With XPS/RPS a packet may arrive on one CPU and be processed on another.
A per-skb field solves both by travelling with the packet itself.
The field fits in existing padding, using 2 bits that were previously a hole:
pahole before(-) and after (+) diff looks like:
__u8 slow_gro:1; /* 132: 3 1 */ __u8 csum_not_inet:1; /* 132: 4 1 */ __u8 unreadable:1; /* 132: 5 1 */ + __u8 tc_depth:2; /* 132: 6 1 */
- /* XXX 2 bits hole, try to pack */
/* XXX 1 byte hole, try to pack */
__u16 tc_index; /* 134 2 */
There used to be a ttl field which was removed as part of tc_verd in commit aec745e2c520 ("net-tc: remove unused tc_verd fields"). It was already unused by that time, due to remove earlier in commit c19ae86a510c ("tc: remove unused redirect ttl").
The first user of this field is netem, which increments tc_depth on duplicated packets before re-enqueueing them at the root qdisc. On re-entry, netem skips duplication for any skb with tc_depth already set, bounding recursion to a single level regardless of tree topology.
The other user is mirred which increments it on each pass and limits to depth to MIRRED_DEFER_LIMIT (3).
The new field was called ttl in earlier versions of this patch but renamed to tc_depth to avoid confusion with IP ttl.
Note (looking at you Sashiko! Dont ignore me and continue bringing this up):
1. Since both mirred and netem utilize the same 2-bit tc_depth field it is possible when netem and mirred are used together that netem qdisc to skip the duplication step. This is a known trade-off, as a 2-bit field cannot independently track both features' recursion depths and it is not considered sane to have a setup that addresses both features on at the same time.
2. skb_scrub_packet does not clear tc_depth. This means a packet's loop history is preserved even across namespaces. While this might be restrictive for some topologies, it is also design intent to provide robustness against loops across namespaces.
Stable-dep-of: e80ad525fc7e ("net/sched: act_mirred: Fix return code in early mirred redirect error paths")
--- include/linux/skbuff.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/skbuff.h +2 -0
@@ -802,6 +802,7 @@ enum skb_tstamp_type {* @_sk_redir: socket redirection information for skmsg * @_nfct: Associated connection, if any (with nfctinfo bits) * @skb_iif: ifindex of device we arrived on +* @tc_depth: counter for packet duplication * @tc_index: Traffic control index * @hash: the packet hash * @queue_mapping: Queue mapping for multiqueue devices
@@ -1011,6 +1012,7 @@ struct sk_buff { __u8 csum_not_inet:1;#endif __u8 unreadable:1; + __u8 tc_depth:2;#if defined(CONFIG_NET_SCHED ) || defined(CONFIG_NET_XGRESS )__u16 tc_index;/* traffic control index */ #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 78/307 net/sched: Fix ethx:ingress -> ethy:egress -> ethx:ingress mirred loop
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit db875221ab08d213a83bf30196ae8b64d55a3403 ]
When mirred redirects to ingress (from either ingress or egress) the loop state from sched_mirred_dev array dev is lost because of 1) the packet deferral into the backlog and 2) the fact the sched_mirred_dev array is cleared. In such cases, if there was a loop we won't discover it.
Here's a simple test to reproduce:
ip a add dev port0 10.10.10.11/24
tc qdisc add dev port0 clsact
tc filter add dev port0 egress protocol ip \
prio 10 matchall action mirred ingress redirect dev port1
tc qdisc add dev port1 clsact
tc filter add dev port1 ingress protocol ip \
prio 10 matchall action mirred egress redirect dev port0
ping -c 1 -W0.01 10.10.10.10
Stable-dep-of: e80ad525fc7e ("net/sched: act_mirred: Fix return code in early mirred redirect error paths")
--- net/sched/act_mirred.c | 47 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-)
net/sched/act_mirred.c +30 -17
@@ -26,6 +26,10 @@#include <net/tc_act/tc_mirred.h> #include <net/tc_wrapper.h> +#define MIRRED_DEFER_LIMIT 3 +_Static_assert (MIRRED_DEFER_LIMIT <=3 , +"MIRRED_DEFER_LIMIT exceeds tc_depth bitfield width" ); +static LIST_HEAD (mirred_list);static DEFINE_SPINLOCK (mirred_list_lock);
@@ -234,12 +238,15 @@ tcf_mirred_forward(bool at_ingress, bool want_ingress, struct sk_buff *skb) {int err; -if (!want_ingress) +if (!want_ingress) { err =tcf_dev_queue_xmit (skb, dev_queue_xmit); -else if (!at_ingress) - err =netif_rx (skb); -else - err =netif_receive_skb (skb); + }else { + skb->tc_depth++; +if (!at_ingress) + err =netif_rx (skb); +else + err =netif_receive_skb (skb); + }return err; }
@@ -417,6 +424,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,struct netdev_xmit *xmit;bool m_mac_header_xmit;struct net_device *dev; +bool want_ingress;int i, m_eaction;u32 blockid;
@@ -425,7 +433,8 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,#else xmit =this_cpu_ptr (&softnet_data.xmit);#endif -if (unlikely (xmit->sched_mirred_nest >=MIRRED_NEST_LIMIT )) { +if (unlikely (xmit->sched_mirred_nest >=MIRRED_NEST_LIMIT || + skb->tc_depth >=MIRRED_DEFER_LIMIT )) {net_warn_ratelimited ("Packet exceeded mirred recursion limit on dev %s\n" ,netdev_name (skb->dev));return TC_ACT_SHOT ;
@@ -444,23 +453,27 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,tcf_action_inc_overlimit_qstats (&m->common);return retval; } -for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) -continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); -tcf_action_inc_overlimit_qstats (&m->common); -return retval; - } - xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + m_eaction =READ_ONCE (m->tcfm_eaction); + want_ingress =tcf_mirred_act_wants_ingress (m_eaction); +if (!want_ingress) { +for (i =0 ; i < xmit->sched_mirred_nest; i++) { +if (xmit->sched_mirred_dev[i] != dev) +continue ; +pr_notice_once ("tc mirred: loop on device %s\n" , +netdev_name (dev)); +tcf_action_inc_overlimit_qstats (&m->common); +return retval; + } + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + } m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); - m_eaction =READ_ONCE (m->tcfm_eaction); retval =tcf_mirred_to_dev (skb, m, dev, m_mac_header_xmit, m_eaction, retval); - xmit->sched_mirred_nest--; +if (!want_ingress) + xmit->sched_mirred_nest--;return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 79/307 net/sched: act_mirred: Fix return code in early mirred redirect error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit e80ad525fc7e8c933ad78478c5dda286cfd55c60 ]
Since retval is set as TC_ACT_STOLEN in the mirred redirect case, returning retval in cases where redirect failed will make the callers not register the skb as being dropped.
Fix this by returning TC_ACT_SHOT instead in such scenarios.
--- net/sched/act_mirred.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
net/sched/act_mirred.c +13 -5
@@ -363,7 +363,8 @@ static int tcf_blockcast_redir(struct sk_buff *skb, struct tcf_mirred *m,dev_is_mac_header_xmit (dev_prev), m_eaction, retval); -return retval; +/* If the packet wasn't redirected, we have to register as a drop */ +return TC_ACT_SHOT ; } static int tcf_blockcast_mirror(struct sk_buff *skb, struct tcf_mirred *m,
@@ -403,7 +404,7 @@ static int tcf_blockcast(struct sk_buff *skb, struct tcf_mirred *m, block =tcf_block_lookup (dev_net (skb->dev), blockid);if (!block ||xa_empty (&block->ports)) {tcf_action_inc_overlimit_qstats (&m->common); -return retval; +return is_redirect ?TC_ACT_SHOT : retval; }if (is_redirect)
@@ -421,8 +422,8 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, {struct tcf_mirred *m =to_mirred (a);int retval =READ_ONCE (m->tcf_action); +bool m_mac_header_xmit, is_redirect;struct netdev_xmit *xmit; -bool m_mac_header_xmit;struct net_device *dev;bool want_ingress;int i, m_eaction;
@@ -447,11 +448,13 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,if (blockid)return tcf_blockcast (skb, m, blockid, res, retval); + is_redirect =tcf_mirred_is_act_redirect (m_eaction); + dev =rcu_dereference_bh (m->tcfm_dev);if (unlikely (!dev)) {pr_notice_once ("tc mirred: target device is gone\n" );tcf_action_inc_overlimit_qstats (&m->common); -return retval; + goto err_out; } m_eaction =READ_ONCE (m->tcfm_eaction);
@@ -463,7 +466,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,pr_notice_once ("tc mirred: loop on device %s\n" ,netdev_name (dev));tcf_action_inc_overlimit_qstats (&m->common); -return retval; + goto err_out; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; }
@@ -476,6 +479,11 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, xmit->sched_mirred_nest--;return retval; + +err_out: +if (is_redirect) + retval =TC_ACT_SHOT ; +return retval; } static void tcf_stats_update(struct tc_action *a, u64 bytes, u64 packets,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 80/307 net/handshake: Use spin_lock_bh for hn_lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit cc993e0927ec8bd98ea33377ada03295fcda0f24 ]
nvmet_tcp_state_change(), a socket callback that runs in BH context, can reach handshake_req_cancel() via nvmet_tcp_schedule_release_queue() and tls_handshake_cancel(). handshake_req_cancel() acquires hn->hn_lock with plain spin_lock(). If a process-context thread on the same CPU holds hn->hn_lock when a softirq invokes the cancel path, the lock attempt deadlocks. This is the only caller that invokes tls_handshake_cancel() from BH context; every other consumer calls it from process context.
Deferring the cancel to process context in the NVMe target is not
straightforward: nvmet_tcp_schedule_release_queue() must call tls_handshake_cancel() atomically with its state transition to DISCONNECTING. If the cancel were deferred, the handshake completion callback could fire in the window before the cancel runs, observe the unexpected state, and return without dropping its kref on the queue. Reworking that interlock is considerably more invasive than hardening the handshake lock. Convert all hn->hn_lock acquisitions from spin_lock/spin_unlock to spin_lock_bh/spin_unlock_bh so the lock is never taken with softirqs enabled.
--- net/handshake/netlink.c | 4 ++-- net/handshake/request.c | 14 +++++++------- net/handshake/tlshd.c | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-)
net/handshake/netlink.c +2 -2
@@ -203,10 +203,10 @@ static void __net_exit handshake_net_exit(struct net *net)* accepted and are in progress will be destroyed when * the socket is closed. */ -spin_lock (&hn->hn_lock); +spin_lock_bh (&hn->hn_lock);set_bit (HANDSHAKE_F_NET_DRAINING , &hn->hn_flags);list_splice_init (&requests, &hn->hn_requests); -spin_unlock (&hn->hn_lock); +spin_unlock_bh (&hn->hn_lock);while (!list_empty (&requests)) { req = list_first_entry(&requests, struct handshake_req, hr_list);
net/handshake/request.c +7 -7
@@ -168,12 +168,12 @@ static bool remove_pending(struct handshake_net *hn, struct handshake_req *req) {bool ret = false; -spin_lock (&hn->hn_lock); +spin_lock_bh (&hn->hn_lock);if (!list_empty (&req->hr_list)) {__remove_pending_locked (hn, req); ret = true; } -spin_unlock (&hn->hn_lock); +spin_unlock_bh (&hn->hn_lock);return ret; }
@@ -183,7 +183,7 @@ struct handshake_req *handshake_req_next(struct handshake_net *hn, int class)struct handshake_req *req, *pos; req =NULL ; -spin_lock (&hn->hn_lock); +spin_lock_bh (&hn->hn_lock);list_for_each_entry (pos, &hn->hn_requests, hr_list) {if (pos->hr_proto->hp_handler_class != class)continue ;
@@ -191,7 +191,7 @@ struct handshake_req *handshake_req_next(struct handshake_net *hn, int class) req = pos;break ; } -spin_unlock (&hn->hn_lock); +spin_unlock_bh (&hn->hn_lock);return req; }
@@ -250,7 +250,7 @@ int handshake_req_submit(struct socket *sock, struct handshake_req *req,if (READ_ONCE (hn->hn_pending) >= hn->hn_pending_max) goto out_err; -spin_lock (&hn->hn_lock); +spin_lock_bh (&hn->hn_lock); ret = -EOPNOTSUPP ;if (test_bit (HANDSHAKE_F_NET_DRAINING , &hn->hn_flags)) goto out_unlock;
@@ -259,7 +259,7 @@ int handshake_req_submit(struct socket *sock, struct handshake_req *req, goto out_unlock;if (!__add_pending_locked (hn, req)) goto out_unlock; -spin_unlock (&hn->hn_lock); +spin_unlock_bh (&hn->hn_lock); ret =handshake_genl_notify (net, req->hr_proto, flags);if (ret) {
@@ -275,7 +275,7 @@ int handshake_req_submit(struct socket *sock, struct handshake_req *req,return 0 ; out_unlock: -spin_unlock (&hn->hn_lock); +spin_unlock_bh (&hn->hn_lock); out_err:/* Restore original destructor so socket teardown still runs on failure */ req->hr_sk->sk_destruct = req->hr_odestruct;
net/handshake/tlshd.c +2 -0
@@ -419,6 +419,8 @@ EXPORT_SYMBOL(tls_server_hello_psk);* Request cancellation races with request completion. To determine * who won, callers examine the return value from this function. * +* Context: May be called from process or softirq context. +* * Return values: * %true - Uncompleted handshake request was canceled * %false - Handshake request already completed or not found
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 81/307 nvme-tcp: store negative errno in queue->tls_err
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 9015985b5eb1a90eb86caf5bce1dfcf1aa38f8ad ]
nvme_tcp_tls_done() assigns queue->tls_err in three branches. The ENOKEY lookup failure and the EOPNOTSUPP initializer both store negative errnos. The third branch, reached when the handshake layer reports a non-zero status, stores -status.
The handshake layer delivers status to the consumer callback as a negative errno; the other in-tree consumers -- xs_tls_handshake_done() and the nvmet target callback -- treat their status argument that way. The extra negation in nvme_tcp_tls_done() flips the sign, leaving tls_err as a positive value (for instance, +EIO), which nvme_tcp_start_tls() then returns to its caller.
Drop the extra negation so queue->tls_err uniformly carries a negative errno on failure.
--- drivers/nvme/host/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/tcp.c +1 -1
@@ -1719,7 +1719,7 @@ static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid) qid, pskid, status);if (status) { - queue->tls_err = -status; + queue->tls_err = status; goto out_complete; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 82/307 net/handshake: Pass negative errno through handshake_complete()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 6b22d433aa13f68e3cd9534ca9a5f4277bfa01c2 ]
handshake_complete() declares status as unsigned int and tls_handshake_done() negates that value (-status) before handing it to the TLS consumer. Consumers match on negative errno constants -- xs_tls_handshake_done() has
switch (status) {
case 0:
case -EACCES:
case -ETIMEDOUT:
lower_transport->xprt_err = status;
break;
default:
lower_transport->xprt_err = -EACCES;
}so the API as designed expects callers to pass positive errno values that the tlshd shim then negates.
Three internal callers in handshake_nl_accept_doit(), the net-exit drain, and a kunit test follow kernel convention and pass negative errnos -- -EIO, -ETIMEDOUT, -ETIMEDOUT. The implicit conversion to unsigned int turns -ETIMEDOUT into 0xFFFFFF92; the subsequent -status in tls_handshake_done() wraps back to 110, the consumer's switch falls through, and the xprt reports -EACCES on what should be -ETIMEDOUT or -EIO.
Fix the API rather than the call sites. The natural kernel convention is negative errno in, negative errno out. Change handshake_complete() and hp_done to take int status, drop the negation in tls_handshake_done(), and negate once in handshake_nl_done_doit() where status arrives from the wire as an unsigned netlink attribute. The three internal callers were already correct under that convention and need no change.
At the same wire boundary, declare MAX_ERRNO as the netlink policy upper bound for HANDSHAKE_A_DONE_STATUS. Attribute validation rejects out-of-range values before handshake_nl_done_doit() runs, and negating a bounded u32 there stays within int range -- closing the UBSAN-visible signed- integer overflow that an unconstrained u32 would invoke.
--- Documentation/netlink/specs/handshake.yaml | 8 ++++++++ net/handshake/genl.c | 3 ++- net/handshake/genl.h | 1 + net/handshake/handshake-test.c | 2 +- net/handshake/handshake.h | 4 ++-- net/handshake/netlink.c | 2 +- net/handshake/request.c | 2 +- net/handshake/tlshd.c | 4 ++-- 8 files changed, 18 insertions(+), 8 deletions(-)
Documentation/netlink/specs/handshake.yaml +8 -0
@@ -12,6 +12,12 @@ protocol: genetlink doc: Netlink protocol to request a transport layer security handshake. definitions: + - + type: const + name: max-errno + value: 4095 + header: linux/err.h + scope: kernel - type: enum name: handler-class
@@ -77,6 +83,8 @@ attribute-sets: - name: status type: u32 + checks: + max: max-errno - name: sockfd type: s32
net/handshake/genl.c +2 -1
@@ -9,6 +9,7 @@#include "genl.h" #include <uapi/linux/handshake.h> +#include <linux/err.h> /* HANDSHAKE_CMD_ACCEPT - do */ static const struct nla_policy handshake_accept_nl_policy[HANDSHAKE_A_ACCEPT_HANDLER_CLASS +1 ] = {
@@ -17,7 +18,7 @@ static const struct nla_policy handshake_accept_nl_policy[HANDSHAKE_A_ACCEPT_HAN/* HANDSHAKE_CMD_DONE - do */ static const struct nla_policy handshake_done_nl_policy[HANDSHAKE_A_DONE_REMOTE_AUTH +1 ] = { - [HANDSHAKE_A_DONE_STATUS ] = { .type =NLA_U32 , }, + [HANDSHAKE_A_DONE_STATUS ] =NLA_POLICY_MAX (NLA_U32 ,MAX_ERRNO ), [HANDSHAKE_A_DONE_SOCKFD ] = { .type =NLA_S32 , }, [HANDSHAKE_A_DONE_REMOTE_AUTH ] = { .type =NLA_U32 , }, };
net/handshake/genl.h +1 -0
@@ -10,6 +10,7 @@#include <net/genetlink.h> #include <uapi/linux/handshake.h> +#include <linux/err.h> int handshake_nl_accept_doit (struct sk_buff *skb,struct genl_info *info);int handshake_nl_done_doit (struct sk_buff *skb,struct genl_info *info);
net/handshake/handshake-test.c +1 -1
@@ -25,7 +25,7 @@ static int test_accept_func(struct handshake_req *req, struct genl_info *info,return 0 ; } -static void test_done_func (struct handshake_req *req,unsigned int status, +static void test_done_func (struct handshake_req *req,int status,struct genl_info *info) { }
net/handshake/handshake.h +2 -2
@@ -57,7 +57,7 @@ struct handshake_proto {int (*hp_accept)(struct handshake_req *req,struct genl_info *info,int fd);void (*hp_done)(struct handshake_req *req, -unsigned int status, +int status,struct genl_info *info);void (*hp_destroy)(struct handshake_req *req); };
@@ -86,7 +86,7 @@ struct handshake_req *handshake_req_hash_lookup(struct sock *sk);struct handshake_req *handshake_req_next (struct handshake_net *hn,int class);int handshake_req_submit (struct socket *sock,struct handshake_req *req,gfp_t flags); -void handshake_complete (struct handshake_req *req,unsigned int status, +void handshake_complete (struct handshake_req *req,int status,struct genl_info *info);bool handshake_req_cancel (struct sock *sk);
net/handshake/netlink.c +1 -1
@@ -161,7 +161,7 @@ int handshake_nl_done_doit(struct sk_buff *skb, struct genl_info *info) status = -EIO ;if (info->attrs[HANDSHAKE_A_DONE_STATUS ]) - status =nla_get_u32 (info->attrs[HANDSHAKE_A_DONE_STATUS ]); + status = -(int )nla_get_u32 (info->attrs[HANDSHAKE_A_DONE_STATUS ]);handshake_complete (req, status, info);sockfd_put (sock);
net/handshake/request.c +1 -1
@@ -285,7 +285,7 @@ int handshake_req_submit(struct socket *sock, struct handshake_req *req, }EXPORT_SYMBOL (handshake_req_submit); -void handshake_complete (struct handshake_req *req,unsigned int status, +void handshake_complete (struct handshake_req *req,int status,struct genl_info *info) {struct sock *sk = req->hr_sk;
net/handshake/tlshd.c +2 -2
@@ -93,7 +93,7 @@ static void tls_handshake_remote_peerids(struct tls_handshake_req *treq,* */ static void tls_handshake_done (struct handshake_req *req, -unsigned int status,struct genl_info *info) +int status,struct genl_info *info) {struct tls_handshake_req *treq =handshake_req_private (req);
@@ -104,7 +104,7 @@ static void tls_handshake_done(struct handshake_req *req,if (!status)set_bit (HANDSHAKE_F_REQ_SESSION , &req->hr_flags); - treq->th_consumer_done (treq->th_consumer_data, -status, + treq->th_consumer_done (treq->th_consumer_data, status, treq->th_peerid[0 ]); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 83/307 remove pointless includes of <linux/fdtable.h>
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit be5498cac2ddb112c5bd7433d5e834a1a2493427 ]
some of those used to be needed, some had been cargo-culted for no reason...
Stable-dep-of: ea5fe6a73ca5 ("net/handshake: Drain pending requests at net namespace exit")
--- fs/fcntl.c | 1 - fs/file_table.c | 1 - fs/notify/fanotify/fanotify.c | 1 - fs/notify/fanotify/fanotify_user.c | 1 - fs/overlayfs/copy_up.c | 1 - fs/proc/base.c | 1 - io_uring/io_uring.c | 1 - kernel/bpf/bpf_inode_storage.c | 1 - kernel/bpf/bpf_task_storage.c | 1 - kernel/bpf/token.c | 1 - kernel/exit.c | 1 - kernel/module/dups.c | 1 - kernel/module/kmod.c | 1 - kernel/umh.c | 1 - net/handshake/request.c | 1 - security/apparmor/domain.c | 1 - 16 files changed, 16 deletions(-)
fs/fcntl.c +0 -1
@@ -12,7 +12,6 @@#include <linux/fs.h> #include <linux/filelock.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/capability.h> #include <linux/dnotify.h> #include <linux/slab.h>
fs/file_table.c +0 -1
@@ -9,7 +9,6 @@#include <linux/string.h> #include <linux/slab.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h>
fs/notify/fanotify/fanotify.c +0 -1
@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/fanotify.h> -#include <linux/fdtable.h> #include <linux/fsnotify_backend.h> #include <linux/init.h> #include <linux/jiffies.h>
fs/notify/fanotify/fanotify_user.c +0 -1
@@ -1,7 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/fanotify.h> #include <linux/fcntl.h> -#include <linux/fdtable.h> #include <linux/file.h> #include <linux/fs.h> #include <linux/anon_inodes.h>
fs/overlayfs/copy_up.c +0 -1
@@ -16,7 +16,6 @@#include <linux/sched/signal.h> #include <linux/cred.h> #include <linux/namei.h> -#include <linux/fdtable.h> #include <linux/ratelimit.h> #include <linux/exportfs.h> #include "overlayfs.h"
fs/proc/base.c +0 -1
@@ -58,7 +58,6 @@#include <linux/init.h> #include <linux/capability.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/generic-radix-tree.h> #include <linux/string.h> #include <linux/seq_file.h>
io_uring/io_uring.c +0 -1
@@ -51,7 +51,6 @@#include <linux/sched/signal.h> #include <linux/fs.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/mm.h> #include <linux/mman.h> #include <linux/percpu.h>
kernel/bpf/bpf_inode_storage.c +0 -1
@@ -16,7 +16,6 @@#include <uapi/linux/btf.h> #include <linux/bpf_lsm.h> #include <linux/btf_ids.h> -#include <linux/fdtable.h> #include <linux/rcupdate_trace.h> DEFINE_BPF_STORAGE_CACHE (inode_cache);
kernel/bpf/bpf_task_storage.c +0 -1
@@ -16,7 +16,6 @@#include <linux/filter.h> #include <uapi/linux/btf.h> #include <linux/btf_ids.h> -#include <linux/fdtable.h> #include <linux/rcupdate_trace.h> DEFINE_BPF_STORAGE_CACHE (task_cache);
kernel/bpf/token.c +0 -1
@@ -1,6 +1,5 @@#include <linux/bpf.h> #include <linux/vmalloc.h> -#include <linux/fdtable.h> #include <linux/file.h> #include <linux/fs.h> #include <linux/kernel.h>
kernel/exit.c +0 -1
@@ -25,7 +25,6 @@#include <linux/acct.h> #include <linux/tsacct_kern.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/freezer.h> #include <linux/binfmts.h> #include <linux/nsproxy.h>
kernel/module/dups.c +0 -1
@@ -18,7 +18,6 @@#include <linux/completion.h> #include <linux/cred.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/workqueue.h> #include <linux/security.h> #include <linux/mount.h>
kernel/module/kmod.c +0 -1
@@ -15,7 +15,6 @@#include <linux/completion.h> #include <linux/cred.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/workqueue.h> #include <linux/security.h> #include <linux/mount.h>
kernel/umh.c +0 -1
@@ -13,7 +13,6 @@#include <linux/completion.h> #include <linux/cred.h> #include <linux/file.h> -#include <linux/fdtable.h> #include <linux/fs_struct.h> #include <linux/workqueue.h> #include <linux/security.h>
net/handshake/request.c +0 -1
@@ -13,7 +13,6 @@#include <linux/module.h> #include <linux/skbuff.h> #include <linux/inet.h> -#include <linux/fdtable.h> #include <linux/rhashtable.h> #include <net/sock.h>
security/apparmor/domain.c +0 -1
@@ -9,7 +9,6 @@*/ #include <linux/errno.h> -#include <linux/fdtable.h> #include <linux/fs.h> #include <linux/file.h> #include <linux/mount.h>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 84/307 net/handshake: Take a long-lived file reference at submit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 09dba37eee70d0596e26645015f1aa95a9848e9d ]
handshake_nl_accept_doit() needs the file pointer backing req->hr_sk->sk_socket to survive the window between handshake_req_next() and the subsequent FD_PREPARE() and get_file(). The submit-side sock_hold() does not provide that. sk_refcnt keeps struct sock alive, but struct socket is owned by sock->file: when the consumer fputs the last file reference, sock_release() tears the socket down regardless of any sock_hold.
Add an hr_file pointer to struct handshake_req and acquire an explicit reference on sock->file during handshake_req_submit(). handshake_complete() and handshake_req_cancel() release the reference on the completion-bit-winning path.
The submit error path must also release the file reference, but after rhashtable insertion a concurrent handshake_req_cancel() can discover the request and race the error path. Gate the error-path cleanup -- sk_destruct restoration, fput, and request destruction -- with test_and_set_bit(HANDSHAKE_F_REQ_COMPLETED), the same serialization handshake_complete() and handshake_req_cancel() already use. When cancel has already claimed ownership, the submit error path returns without touching the request; socket teardown handles final destruction.
The accept-side dereferences are not yet retargeted; that change comes in the next patch.
Stable-dep-of: ea5fe6a73ca5 ("net/handshake: Drain pending requests at net namespace exit")
--- net/handshake/handshake.h | 2 ++ net/handshake/netlink.c | 6 ------ net/handshake/request.c | 42 ++++++++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 13 deletions(-)
net/handshake/handshake.h +2 -0
@@ -24,6 +24,7 @@ enum hn_flags_bits { HANDSHAKE_F_NET_DRAINING, }; +struct file ;struct handshake_proto ;/* One handshake request */
@@ -32,6 +33,7 @@ struct handshake_req {struct rhash_head hr_rhash;unsigned long hr_flags;const struct handshake_proto *hr_proto; +struct file *hr_file;struct sock *hr_sk;void (*hr_odestruct)(struct sock *sk);
net/handshake/netlink.c +0 -6
@@ -211,12 +211,6 @@ static void __net_exit handshake_net_exit(struct net *net)while (!list_empty (&requests)) { req = list_first_entry(&requests, struct handshake_req, hr_list);list_del (&req->hr_list); - -/* -* Requests on this list have not yet been -* accepted, so they do not have an fd to put. -*/ -handshake_complete (req, -ETIMEDOUT ,NULL ); } }
net/handshake/request.c +35 -7
90 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 85/307 net/handshake: Drain pending requests at net namespace exit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit ea5fe6a73ca57e5150b8a38b341aef2636eb72f0 ]
The arguments to list_splice_init() in handshake_net_exit() are reversed. The call moves the local empty "requests" list onto hn->hn_requests, leaving the local list empty, so the subsequent drain loop runs zero iterations. Pending handshake requests that had not yet been accepted are not torn down when the net namespace is destroyed; each one keeps a reference on a socket file and on the handshake_req allocation.
Pass the source and destination in the documented order (list_splice_init(list, head) moves list onto head) so the pending list is transferred to the local scratch list and drained through handshake_complete().
Fixing the splice direction exposes a list-corruption race. After the splice each req->hr_list still has non-empty link pointers, threading the stack-local scratch list rather than hn_requests. A concurrent handshake_req_cancel() -- for example, from sunrpc's TLS timeout on a kernel socket whose netns reference was not taken -- finds the request through the rhashtable, calls remove_pending(), and sees !list_empty(&req->hr_list). __remove_pending_locked() then list_del_init()s an entry off the scratch list while the drain iterates, corrupting it. The same call arriving after the drain loop has run list_del() on an entry hits LIST_POISON instead.
Have remove_pending() check HANDSHAKE_F_NET_DRAINING under hn_lock and report not-found when drain is in progress. The drain has already taken ownership; handshake_complete()'s existing test_and_set on HANDSHAKE_F_REQ_COMPLETED still arbitrates between drain and cancel for who calls the consumer's hp_done. Use list_del_init() rather than list_del() in the drain so req->hr_list does not carry LIST_POISON after drain releases the entry.
The DRAINING guard in remove_pending() makes cancel return false, but cancel still falls through to test_and_set_bit on HANDSHAKE_F_REQ_COMPLETED and drops the request's hr_file reference. Without another pin, if that is the last reference, sk_destruct frees the request while it is still linked on the drain loop's local list. Pin each request's hr_file under hn_lock before releasing the list, and drop that drain pin after the loop finishes with the request.
--- net/handshake/netlink.c | 10 ++++++++-- net/handshake/request.c | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-)
net/handshake/netlink.c +8 -2
@@ -205,13 +205,19 @@ static void __net_exit handshake_net_exit(struct net *net)*/ spin_lock_bh (&hn->hn_lock);set_bit (HANDSHAKE_F_NET_DRAINING , &hn->hn_flags); -list_splice_init (&requests, &hn->hn_requests); +list_splice_init (&hn->hn_requests, &requests); +list_for_each_entry (req, &requests, hr_list) +get_file (req->hr_file);spin_unlock_bh (&hn->hn_lock);while (!list_empty (&requests)) { +struct file *file; + req = list_first_entry(&requests, struct handshake_req, hr_list); -list_del (&req->hr_list); + file = req->hr_file; +list_del_init (&req->hr_list);handshake_complete (req, -ETIMEDOUT ,NULL ); +fput (file); } }
net/handshake/request.c +4 -1
@@ -163,13 +163,16 @@ static void __remove_pending_locked(struct handshake_net *hn,* otherwise %false. * * If @req was on a pending list, it has not yet been accepted. +* Returns %false when the net namespace is draining; the drain +* loop has taken ownership of the pending list. */ static bool remove_pending (struct handshake_net *hn,struct handshake_req *req) {bool ret = false;spin_lock_bh (&hn->hn_lock); -if (!list_empty (&req->hr_list)) { +if (!test_bit (HANDSHAKE_F_NET_DRAINING , &hn->hn_flags) && + !list_empty (&req->hr_list)) {__remove_pending_locked (hn, req); ret = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 86/307 Bluetooth: l2cap: clear chan->ident on ECRED reconfiguration success
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenghang Xiao <[email protected]>
[ Upstream commit 00e1950716c6ed67d74777b2db286b0fa23b4be9 ]
l2cap_ecred_reconf_rsp() returns early on success without clearing chan->ident. Every other L2CAP response handler (l2cap_ecred_conn_rsp, l2cap_le_connect_rsp, l2cap_config_rsp) clears chan->ident after a successful transaction to prevent the channel from matching subsequent responses with the recycled ident value.
A remote attacker that completed a reconfiguration as the peer can replay a failure response with the stale ident, causing the kernel to match and destroy the already-established channel via l2cap_chan_del(chan, ECONNRESET).
Clear chan->ident for all matching channels on success, and harden the failure path by using l2cap_chan_hold_unless_zero() consistent with other L2CAP handlers (l2cap_le_command_rej, __l2cap_get_chan_by_ident).
--- net/bluetooth/l2cap_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +8 -2
@@ -5392,14 +5392,20 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn,BT_DBG ("result 0x%4.4x" , result); -if (!result) +if (!result) { +list_for_each_entry (chan, &conn->chan_l, list) { +if (chan->ident == cmd->ident) + chan->ident =0 ; + }return 0 ; + }list_for_each_entry_safe (chan, tmp, &conn->chan_l, list) {if (chan->ident != cmd->ident)continue ; -l2cap_chan_hold (chan); +if (!l2cap_chan_hold_unless_zero (chan)) +continue ;l2cap_chan_lock (chan);l2cap_chan_del (chan,ECONNRESET );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 88/307 Bluetooth: hci_sync: Set HCI_CMD_DRAIN_WORKQUEUE during device close
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Heitor Alves de Siqueira <[email protected]>
[ Upstream commit 525daaea459fc215f432de1b8debbd9144bf97b0 ]
Since hci_dev_close_sync() can now be called during the reset path, we should also set HCI_CMD_DRAIN_WORKQUEUE. This avoids queuing timeouts while the hdev workqueue is being drained.
--- net/bluetooth/hci_sync.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/bluetooth/hci_sync.c +8 -0
@@ -5223,6 +5223,12 @@ int hci_dev_close_sync(struct hci_dev *hdev)bt_dev_dbg (hdev,"" ); +/* Set HCI_DRAIN_WORKQUEUE flag to prevent queuing work during +* reset/close. See hci_cmd_work() and handle_cmd_cnt_and_timer(). +*/ +hci_dev_set_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE ); +synchronize_rcu (); +if (hci_dev_test_flag (hdev,HCI_UNREGISTER )) {disable_delayed_work (&hdev->power_off);disable_delayed_work (&hdev->ncmd_timer);
@@ -5246,6 +5252,7 @@ int hci_dev_close_sync(struct hci_dev *hdev)if (!test_and_clear_bit (HCI_UP , &hdev->flags)) {cancel_delayed_work_sync (&hdev->cmd_timer); +hci_dev_clear_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE );return err; }
@@ -5345,6 +5352,7 @@ int hci_dev_close_sync(struct hci_dev *hdev)/* Clear flags */ hdev->flags &=BIT (HCI_RAW );hci_dev_clear_volatile_flags (hdev); +hci_dev_clear_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE );memset (hdev->eir,0 ,sizeof (hdev->eir));memset (hdev->dev_class,0 ,sizeof (hdev->dev_class));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 89/307 gpio: virtuser: Fix uninitialized data bug in gpio_virtuser_direction_do_write()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 8a122b5e72cc0043705f0d524bcd15f0c0b3ec15 ]
If *ppos is non-zero (user-space write split over multiple calls to write()) then simple_write_to_buffer() won't initialize the start of the buffer. Really, non-zero values for *ppos aren't going to work at all. Check for that and return -EINVAL at the start of the function.
--- drivers/gpio/gpio-virtuser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-virtuser.c +2 -2
@@ -400,7 +400,7 @@ static ssize_t gpio_virtuser_direction_do_write(struct file *file,char buf[32 ], *trimmed;int ret, dir, val =0 ; -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -EINVAL ; ret =simple_write_to_buffer (buf,sizeof (buf) -1 , ppos, user_buf, count);
@@ -627,7 +627,7 @@ static ssize_t gpio_virtuser_consumer_write(struct file *file,char buf[GPIO_VIRTUSER_NAME_BUF_LEN +2 ];int ret; -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -EINVAL ; ret = simple_write_to_buffer(buf, GPIO_VIRTUSER_NAME_BUF_LEN, ppos,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 90/307 gpio: rockchip: convert bank->clk to devm_clk_get_enabled()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Scardovi <[email protected]>
[ Upstream commit 3e46c18d5d87f063a93ae0fe7662fbf6660459d5 ]
The bank->clk was previously obtained via of_clk_get() and manually prepared/enabled. However, it was missing a corresponding clk_put() in both the error paths and the remove function, leading to a reference leak.
Convert the allocation to devm_clk_get_enabled(), which also properly propagates failures from clk_prepare_enable() that were previously ignored.
The GPIO bank device uses the same OF node as the previous of_clk_get() call, so devm_clk_get_enabled(dev, NULL) correctly resolves the same clock provider entry.
Fix the reference leak and simplify the code by removing the manual clk_disable_unprepare() calls in the probe error paths and in the remove function.
--- drivers/gpio/gpio-rockchip.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpio/gpio-rockchip.c +1 -5
@@ -647,11 +647,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)if (!bank->irq)return -EINVAL ; - bank->clk =of_clk_get (bank->of_node,0 ); + bank->clk =devm_clk_get_enabled (bank->dev,NULL );if (IS_ERR (bank->clk))return PTR_ERR (bank->clk); -clk_prepare_enable (bank->clk); id =readl (bank->reg_base + gpio_regs_v2.version_id);/* If not gpio v2, that is default to v1. */
@@ -661,7 +660,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) bank->db_clk =of_clk_get (bank->of_node,1 );if (IS_ERR (bank->db_clk)) {dev_err (bank->dev,"cannot find debounce clk\n" ); -clk_disable_unprepare (bank->clk);return -EINVAL ; } }else {
@@ -735,7 +733,6 @@ static int rockchip_gpio_probe(struct platform_device *pdev) ret =rockchip_gpiolib_register (bank);if (ret) { -clk_disable_unprepare (bank->clk);mutex_unlock (&bank->deferred_lock);return ret; }
@@ -776,7 +773,6 @@ static void rockchip_gpio_remove(struct platform_device *pdev) {struct rockchip_pin_bank *bank =platform_get_drvdata (pdev); -clk_disable_unprepare (bank->clk);gpiochip_remove (&bank->gpio_chip); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 91/307 net: mana: Add NULL guards in teardown path to prevent panic on attach failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dipayaan Roy <[email protected]>
[ Upstream commit 17bfe0a8c014ee1d542ad352cd6a0a505361664a ]
When queue allocation fails partway through, the error cleanup frees and NULLs apc->tx_qp and apc->rxqs. Multiple teardown paths such as mana_remove(), mana_change_mtu() recovery, and internal error handling in mana_alloc_queues() can subsequently call into functions that dereference these pointers without NULL checks:
- mana_chn_setxdp() dereferences apc->rxqs[0], causing a NULL pointer dereference panic (CR2: 0000000000000000 at mana_chn_setxdp+0x26).
- mana_destroy_vport() iterates apc->rxqs without a NULL check.
- mana_fence_rqs() iterates apc->rxqs without a NULL check.
- mana_dealloc_queues() iterates apc->tx_qp without a NULL check.
Add NULL guards for apc->rxqs in mana_fence_rqs(), mana_destroy_vport(), and before the mana_chn_setxdp() call. Add a NULL guard for apc->tx_qp in mana_dealloc_queues() to skip TX queue draining when TX queues were never allocated or already freed.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +41 -29
@@ -1304,6 +1304,9 @@ static void mana_fence_rqs(struct mana_port_context *apc)struct mana_rxq *rxq;int err; +if (!apc->rxqs) +return ; +for (rxq_idx =0 ; rxq_idx < apc->num_queues; rxq_idx++) { rxq = apc->rxqs[rxq_idx]; err =mana_fence_rq (apc, rxq);
@@ -2324,13 +2327,16 @@ static void mana_destroy_vport(struct mana_port_context *apc)struct mana_rxq *rxq;u32 rxq_idx; -for (rxq_idx =0 ; rxq_idx < apc->num_queues; rxq_idx++) { - rxq = apc->rxqs[rxq_idx]; -if (!rxq) -continue ; +if (apc->rxqs) { -mana_destroy_rxq (apc, rxq, true); - apc->rxqs[rxq_idx] =NULL ; +for (rxq_idx =0 ; rxq_idx < apc->num_queues; rxq_idx++) { + rxq = apc->rxqs[rxq_idx]; +if (!rxq) +continue ; + +mana_destroy_rxq (apc, rxq, true); + apc->rxqs[rxq_idx] =NULL ; + } }mana_destroy_txq (apc);
@@ -2633,7 +2639,8 @@ static int mana_dealloc_queues(struct net_device *ndev)if (apc->port_is_up)return -EINVAL ; -mana_chn_setxdp (apc,NULL ); +if (apc->rxqs) +mana_chn_setxdp (apc,NULL );if (gd->gdma_context->is_pf)mana_pf_deregister_filter (apc);
@@ -2651,33 +2658,38 @@ static int mana_dealloc_queues(struct net_device *ndev)* number of queues. */ -for (i =0 ; i < apc->num_queues; i++) { - txq = &apc->tx_qp[i].txq; - tsleep =1000 ; -while (atomic_read (&txq->pending_sends) >0 && -time_before (jiffies, timeout)) { -usleep_range (tsleep, tsleep +1000 ); - tsleep <<=1 ; - } -if (atomic_read (&txq->pending_sends)) { - err =pcie_flr (to_pci_dev (gd->gdma_context->dev)); -if (err) { -netdev_err (ndev,"flr failed %d with %d pkts pending in txq %u\n" , - err,atomic_read (&txq->pending_sends), - txq->gdma_txq_id); +if (apc->tx_qp) { +for (i =0 ; i < apc->num_queues; i++) { + txq = &apc->tx_qp[i].txq; + tsleep =1000 ; +while (atomic_read (&txq->pending_sends) >0 && +time_before (jiffies, timeout)) { +usleep_range (tsleep, tsleep +1000 ); + tsleep <<=1 ; + } +if (atomic_read (&txq->pending_sends)) { + err = +pcie_flr (to_pci_dev (gd->gdma_context->dev)); +if (err) { +netdev_err (ndev,"flr failed %d with %d pkts pending in txq %u\n" , + err, +atomic_read (&txq->pending_sends), + txq->gdma_txq_id); + } +break ; } -break ; } - } -for (i =0 ; i < apc->num_queues; i++) { - txq = &apc->tx_qp[i].txq; -while ((skb =skb_dequeue (&txq->pending_skbs))) { -mana_unmap_skb (skb, apc); -dev_kfree_skb_any (skb); +for (i =0 ; i < apc->num_queues; i++) { + txq = &apc->tx_qp[i].txq; +while ((skb =skb_dequeue (&txq->pending_skbs))) { +mana_unmap_skb (skb, apc); +dev_kfree_skb_any (skb); + } +atomic_set (&txq->pending_sends,0 ); } -atomic_set (&txq->pending_sends,0 ); } +/* We're 100% sure the queues can no longer be woken up, because * we're sure now mana_poll_tx_cq() can't be running. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 92/307 sctp: fix race between sctp_wait_for_connect and peeloff
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenghang Xiao <[email protected]>
[ Upstream commit f14fe6395a8b3d961a61e138ad7b36ba3626dd4e ]
sctp_wait_for_connect() drops and re-acquires the socket lock while waiting for the association to reach ESTABLISHED state. During this window, another thread can peeloff the association to a new socket via getsockopt(SCTP_SOCKOPT_PEELOFF), changing asoc->base.sk. After re-acquiring the old socket lock, sctp_wait_for_connect() returns success without noticing the migration — the caller then accesses the association under the wrong lock in sctp_datamsg_from_user().
Add the same sk != asoc->base.sk check that sctp_wait_for_sndbuf() already has, returning an error if the association was migrated while we slept.
--- net/sctp/socket.c | 2 ++ 1 file changed, 2 insertions(+)
net/sctp/socket.c +2 -0
@@ -9377,6 +9377,8 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)release_sock (sk); current_timeo =schedule_timeout (current_timeo);lock_sock (sk); +if (sk != asoc->base.sk) + goto do_error; *timeo_p = current_timeo; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 93/307 ipv6: fix possible infinite loop in rt6_fill_node()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 9f72412bcf60144f252b0d6205106abf14344abc ]
Sashiko reported this issue [1]. Apply the same fix as
commit f8d8ce1b515a ("ipv6: fix possible infinite loop in fib6_info_uses_dev()").
Writers holding tb6_lock can list_del_rcu(&rt->fib6_siblings) without waiting for RCU readers; rt->fib6_siblings.next then still points into the old ring and this softirq-side walker never reaches &rt->fib6_siblings, causing a CPU stall. fib6_del_route() always WRITE_ONCE()s rt->fib6_nsiblings to 0 before list_del_rcu(), so an inside-loop check is a reliable detach signal.
[1] https://sashiko.dev/#/patchset/20260526020227.4857-1-jiayuan.chen%40linux.dev
--- net/ipv6/route.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/route.c +2 -0
@@ -5812,6 +5812,8 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, goto nla_put_failure; } +if (!READ_ONCE (rt->fib6_nsiblings)) +break ; }rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 94/307 ipv6: fix possible infinite loop in fib6_select_path()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 9c7da87c2dc860bb17ca1ece942495d28b1ce3b9 ]
Found while auditing the same pattern Sashiko reported in rt6_fill_node() [1]. Apply the same fix as
commit f8d8ce1b515a ("ipv6: fix possible infinite loop in fib6_info_uses_dev()").
Writers holding tb6_lock can list_del_rcu(&first->fib6_siblings) without waiting for RCU readers; first->fib6_siblings.next then still points into the old ring and this softirq-side walker never reaches &first->fib6_siblings as its terminator. fib6_purge_rt() always WRITE_ONCE()s first->fib6_nsiblings to 0 before list_del_rcu(), so an inside-loop check is a reliable detach signal.
[1] https://sashiko.dev/#/patchset/20260526020227.4857-1-jiayuan.chen%40linux.dev
--- net/ipv6/route.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/route.c +3 -0
@@ -482,6 +482,9 @@ void fib6_select_path(const struct net *net, struct fib6_result *res,const struct fib6_nh *nh = sibling->fib6_nh;int nh_upper_bound; +if (!READ_ONCE (first->fib6_nsiblings)) +break ; + nh_upper_bound =atomic_read (&nh->fib_nh_upper_bound);if (hash > nh_upper_bound)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 95/307 net: skbuff: fix pskb_carve leaking zcopy pages
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Begunkov <[email protected]>
[ Upstream commit ff6e798c2eac3ebd0501ad7e796f583fab928de8 ]
When SKBFL_MANAGED_FRAG_REFS is set, frag pages are not refcounted but their lifetime is controlled by the attached ubuf_info. To make a copy of the skb_shared_info, we either should clear the flag and reference the frags, or keep the flag and have frags unreferenced.
pskb_carve_inside_header() and pskb_carve_inside_nonlinear() don't follow the rule and thus can leak page references. Let's clear SKBFL_MANAGED_FRAG_REFS from the original skb to fix it. It's the simplest way to address it, but there are more performant ways to do that if it ever becomes a problem.
--- net/core/skbuff.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/core/skbuff.c +10 -0
@@ -6689,6 +6689,11 @@ static int pskb_carve_inside_header(struct sk_buff *skb, const u32 off,skb_copy_from_linear_data_offset (skb, off, data, new_hlen); skb->len -= off; +/* Remove SKBFL_MANAGED_FRAG_REFS instead of trying to honour it +* while refcounting frags below. +*/ +skb_zcopy_downgrade_managed (skb); + memcpy((struct skb_shared_info *)(data + size), skb_shinfo(skb), offsetof(struct skb_shared_info,
@@ -6801,6 +6806,11 @@ static int pskb_carve_inside_nonlinear(struct sk_buff *skb, const u32 off,return -ENOMEM ; size =SKB_WITH_OVERHEAD (size); +/* Remove SKBFL_MANAGED_FRAG_REFS instead of trying to honour it +* while refcounting frags below. +*/ +skb_zcopy_downgrade_managed (skb); +memcpy ((struct skb_shared_info *)(data + size), skb_shinfo(skb), offsetof(struct skb_shared_info, frags[0]));if (skb_orphan_frags (skb, gfp_mask)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 96/307 perf: Fix dangling cgroup pointer in cpuctx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 3b7a34aebbdf2a4b7295205bf0c654294283ec82 ]
Commit a3c3c6667("perf/core: Fix child_total_time_enabled accounting bug at task exit") moves the event->state update to before list_del_event(). This makes the event->state test in list_del_event() always false; never calling perf_cgroup_event_disable().
As a result, cpuctx->cgrp won't be cleared properly; causing havoc.
--- kernel/events/core.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
kernel/events/core.c +4 -12
@@ -2096,18 +2096,6 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)if (event->group_leader == event)del_event_from_groups (event, ctx); -/* -* If event was in error state, then keep it -* that way, otherwise bogus counts will be -* returned on read(). The only way to get out -* of error state is by explicit re-enabling -* of the event -*/ -if (event->state >PERF_EVENT_STATE_OFF ) { -perf_cgroup_event_disable (event, ctx); -perf_event_set_state (event,PERF_EVENT_STATE_OFF ); - } - ctx->generation++; event->pmu_ctx->nr_events--; }
@@ -2457,6 +2445,10 @@ __perf_remove_from_context(struct perf_event *event, state =PERF_EVENT_STATE_DEAD ; }event_sched_out (event, ctx); + +if (event->state >PERF_EVENT_STATE_OFF ) +perf_cgroup_event_disable (event, ctx); +perf_event_set_state (event,min (event->state, state));if (flags &DETACH_GROUP )perf_group_detach (event);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 97/307 batman-adv: v: stop OGMv2 on disabled interface
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit f8ce8b8331a1bc44ad4905886a482214d428b253 upstream.
When a batadv_hard_iface is disabled, its mesh_iface pointer is set to NULL. However, batadv_v_ogm_send_meshif() may still dispatch OGMs via batadv_v_ogm_queue_on_if() for interfaces that have since lost their mesh_iface association. This results in a NULL pointer dereference when batadv_v_ogm_queue_on_if() unconditionally calls netdev_priv() on the now NULL hard_iface->mesh_iface to retrieve the batadv_priv.
It is necessary to ensure that the batadv_v_ogm_queue_on_if() checks that it is using the same mesh_iface for which batadv_v_ogm_send_meshif() was called.
--- net/batman-adv/bat_v_ogm.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
net/batman-adv/bat_v_ogm.c +21 -12
@@ -115,14 +115,14 @@ static void batadv_v_ogm_start_timer(struct batadv_priv *bat_priv)/** * batadv_v_ogm_send_to_if() - send a batman ogm using a given interface +* @bat_priv: the bat priv with all the mesh interface information * @skb: the OGM to send * @hard_iface: the interface to use to send the OGM */ -static void batadv_v_ogm_send_to_if (struct sk_buff *skb, +static void batadv_v_ogm_send_to_if (struct batadv_priv *bat_priv, +struct sk_buff *skb,struct batadv_hard_iface *hard_iface) { -struct batadv_priv *bat_priv =netdev_priv (hard_iface->soft_iface); -if (hard_iface->if_status !=BATADV_IF_ACTIVE ) {kfree_skb (skb);return ;
@@ -189,6 +189,7 @@ static void batadv_v_ogm_aggr_list_free(struct batadv_hard_iface *hard_iface)/** * batadv_v_ogm_aggr_send() - flush & send aggregation queue +* @bat_priv: the bat priv with all the mesh interface information * @hard_iface: the interface with the aggregation queue to flush * * Aggregates all OGMv2 packets currently in the aggregation queue into a
@@ -198,7 +199,8 @@ static void batadv_v_ogm_aggr_list_free(struct batadv_hard_iface *hard_iface)* * Caller needs to hold the hard_iface->bat_v.aggr_list.lock. */ -static void batadv_v_ogm_aggr_send (struct batadv_hard_iface *hard_iface) +static void batadv_v_ogm_aggr_send (struct batadv_priv *bat_priv, +struct batadv_hard_iface *hard_iface) {unsigned int aggr_len = hard_iface->bat_v.aggr_len;struct sk_buff *skb_aggr;
@@ -228,27 +230,32 @@ static void batadv_v_ogm_aggr_send(struct batadv_hard_iface *hard_iface)consume_skb (skb); } -batadv_v_ogm_send_to_if (skb_aggr, hard_iface); +batadv_v_ogm_send_to_if (bat_priv, skb_aggr, hard_iface); }/** * batadv_v_ogm_queue_on_if() - queue a batman ogm on a given interface +* @bat_priv: the bat priv with all the mesh interface information * @skb: the OGM to queue * @hard_iface: the interface to queue the OGM on */ -static void batadv_v_ogm_queue_on_if (struct sk_buff *skb, +static void batadv_v_ogm_queue_on_if (struct batadv_priv *bat_priv, +struct sk_buff *skb,struct batadv_hard_iface *hard_iface) { -struct batadv_priv *bat_priv =netdev_priv (hard_iface->soft_iface); +if (hard_iface->soft_iface != bat_priv->soft_iface) { +kfree_skb (skb); +return ; + }if (!atomic_read (&bat_priv->aggregated_ogms)) { -batadv_v_ogm_send_to_if (skb, hard_iface); +batadv_v_ogm_send_to_if (bat_priv, skb, hard_iface);return ; }spin_lock_bh (&hard_iface->bat_v.aggr_list.lock);if (!batadv_v_ogm_queue_left (skb, hard_iface)) -batadv_v_ogm_aggr_send (hard_iface); +batadv_v_ogm_aggr_send (bat_priv, hard_iface); hard_iface->bat_v.aggr_len +=batadv_v_ogm_len (skb);__skb_queue_tail (&hard_iface->bat_v.aggr_list, skb);
@@ -347,7 +354,7 @@ static void batadv_v_ogm_send_softif(struct batadv_priv *bat_priv)break ; } -batadv_v_ogm_queue_on_if (skb_tmp, hard_iface); +batadv_v_ogm_queue_on_if (bat_priv, skb_tmp, hard_iface);batadv_hardif_put (hard_iface); }rcu_read_unlock ();
@@ -387,12 +394,14 @@ void batadv_v_ogm_aggr_work(struct work_struct *work) {struct batadv_hard_iface_bat_v *batv;struct batadv_hard_iface *hard_iface; +struct batadv_priv *bat_priv; batv = container_of(work, struct batadv_hard_iface_bat_v, aggr_wq.work); hard_iface = container_of(batv, struct batadv_hard_iface, bat_v); + bat_priv =netdev_priv (hard_iface->soft_iface);spin_lock_bh (&hard_iface->bat_v.aggr_list.lock); -batadv_v_ogm_aggr_send (hard_iface); +batadv_v_ogm_aggr_send (bat_priv, hard_iface);spin_unlock_bh (&hard_iface->bat_v.aggr_list.lock);batadv_v_ogm_start_queue_timer (hard_iface);
@@ -582,7 +591,7 @@ static void batadv_v_ogm_forward(struct batadv_priv *bat_priv, if_outgoing->net_dev->name,ntohl (ogm_forward->throughput), ogm_forward->ttl, if_incoming->net_dev->name); -batadv_v_ogm_queue_on_if (skb, if_outgoing); +batadv_v_ogm_queue_on_if (bat_priv, skb, if_outgoing); out:batadv_orig_ifinfo_put (orig_ifinfo);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 98/307 batman-adv: tvlv: abort OGM send on tvlv append failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 501368506563e151b322c8c3f228b796e615b90d upstream.
batadv_tvlv_container_ogm_append() could fail in two ways: a memory allocation failure when resizing the packet buffer, or the tvlv data exceeding U16_MAX bytes. In both cases the function previously returned the old (now stale) tvlv_value_len rather than signalling an error, causing the OGM/OGM2 send path to transmit a packet whose TVLV length field no longer matched the actual buffer contents. And because it also didn't fill in the new TVLV data, sending either uninitialized or corrupted data on the wire.
All errors in batadv_tvlv_container_ogm_append() must be forwarded to the caller. And the caller must abort the send of the OGM2. For B.A.T.M.A.N. IV, it is currently not allowed to abort the send. The non-TVLV part of the OGM must be queued up instead.
--- net/batman-adv/bat_iv_ogm.c | 16 +++++++++++++--- net/batman-adv/bat_v_ogm.c | 26 ++++++++++++++------------ net/batman-adv/tvlv.c | 17 ++++++++++++----- net/batman-adv/tvlv.h | 2 +- 4 files changed, 40 insertions(+), 21 deletions(-)
net/batman-adv/bat_iv_ogm.c +13 -3
@@ -781,6 +781,7 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)u32 seqno;u16 tvlv_len =0 ;unsigned long send_time; +int ret;lockdep_assert_held (&hard_iface->bat_iv.ogm_buff_mutex);
@@ -804,9 +805,18 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)* appended as it may alter the tt tvlv container */ batadv_tt_local_commit_changes (bat_priv); - tvlv_len =batadv_tvlv_container_ogm_append (bat_priv, ogm_buff, - ogm_buff_len, -BATADV_OGM_HLEN ); + ret =batadv_tvlv_container_ogm_append (bat_priv, ogm_buff, + ogm_buff_len, +BATADV_OGM_HLEN ); +if (ret <0 ) { +/* OGMs must be queued even when the buffer allocation for +* TVLVs failed. just fall back to the non-TVLV version +*/ + ret =0 ; + *ogm_buff_len =BATADV_OGM_HLEN ; + } + + tvlv_len = ret; } batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
net/batman-adv/bat_v_ogm.c +14 -12
@@ -271,9 +271,9 @@ static void batadv_v_ogm_send_softif(struct batadv_priv *bat_priv)struct batadv_hard_iface *hard_iface;struct batadv_ogm2_packet *ogm_packet;struct sk_buff *skb, *skb_tmp; -unsigned char *ogm_buff; -int ogm_buff_len; -u16 tvlv_len =0 ; +unsigned char **ogm_buff; +int *ogm_buff_len; +u16 tvlv_len;int ret;lockdep_assert_held (&bat_priv->bat_v.ogm_buff_mutex);
@@ -281,25 +281,27 @@ static void batadv_v_ogm_send_softif(struct batadv_priv *bat_priv)if (atomic_read (&bat_priv->mesh_state) ==BATADV_MESH_DEACTIVATING ) goto out; - ogm_buff = bat_priv->bat_v.ogm_buff; - ogm_buff_len = bat_priv->bat_v.ogm_buff_len; + ogm_buff = &bat_priv->bat_v.ogm_buff; + ogm_buff_len = &bat_priv->bat_v.ogm_buff_len; +/* tt changes have to be committed before the tvlv data is * appended as it may alter the tt tvlv container */ batadv_tt_local_commit_changes (bat_priv); - tvlv_len =batadv_tvlv_container_ogm_append (bat_priv, &ogm_buff, - &ogm_buff_len, -BATADV_OGM2_HLEN ); + ret =batadv_tvlv_container_ogm_append (bat_priv, ogm_buff, + ogm_buff_len, +BATADV_OGM2_HLEN ); +if (ret <0 ) + goto reschedule; - bat_priv->bat_v.ogm_buff = ogm_buff; - bat_priv->bat_v.ogm_buff_len = ogm_buff_len; + tvlv_len = ret; - skb =netdev_alloc_skb_ip_align (NULL ,ETH_HLEN + ogm_buff_len); + skb =netdev_alloc_skb_ip_align (NULL ,ETH_HLEN + *ogm_buff_len);if (!skb) goto reschedule;skb_reserve (skb,ETH_HLEN ); -skb_put_data (skb, ogm_buff, ogm_buff_len); +skb_put_data (skb, *ogm_buff, *ogm_buff_len); ogm_packet = (struct batadv_ogm2_packet *)skb->data; ogm_packet->seqno =htonl (atomic_read (&bat_priv->bat_v.ogm_seqno));
net/batman-adv/tvlv.c +12 -5
@@ -8,6 +8,7 @@#include <linux/byteorder/generic.h> #include <linux/container_of.h> +#include <linux/errno.h> #include <linux/etherdevice.h> #include <linux/gfp.h> #include <linux/if_ether.h>
@@ -306,9 +307,10 @@ static bool batadv_tvlv_realloc_packet_buff(unsigned char **packet_buff,* The ogm packet might be enlarged or shrunk depending on the current size * and the size of the to-be-appended tvlv containers. * -* Return: size of all appended tvlv containers in bytes. +* Return: size of all appended tvlv containers in bytes (max U16_MAX), negative +* if operation failed */ -u16 batadv_tvlv_container_ogm_append (struct batadv_priv *bat_priv, +int batadv_tvlv_container_ogm_append (struct batadv_priv *bat_priv,unsigned char **packet_buff,int *packet_buff_len,int packet_min_len) {
@@ -316,6 +318,7 @@ u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,struct batadv_tvlv_hdr *tvlv_hdr;u16 tvlv_value_len;void *tvlv_value; +int tvlv_len_ret;bool ret;spin_lock_bh (&bat_priv->tvlv.container_list_lock);
@@ -323,9 +326,12 @@ u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, ret =batadv_tvlv_realloc_packet_buff (packet_buff, packet_buff_len, packet_min_len, tvlv_value_len); - -if (!ret) +if (!ret) { + tvlv_len_ret = -ENOMEM ; goto end; + } + + tvlv_len_ret = tvlv_value_len;if (!tvlv_value_len) goto end;
@@ -344,7 +350,8 @@ u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, end:spin_unlock_bh (&bat_priv->tvlv.container_list_lock); -return tvlv_value_len; + +return tvlv_len_ret; }/**
net/batman-adv/tvlv.h +1 -1
@@ -16,7 +16,7 @@void batadv_tvlv_container_register (struct batadv_priv *bat_priv,u8 type,u8 version,void *tvlv_value,u16 tvlv_value_len); -u16 batadv_tvlv_container_ogm_append (struct batadv_priv *bat_priv, +int batadv_tvlv_container_ogm_append (struct batadv_priv *bat_priv,unsigned char **packet_buff,int *packet_buff_len,int packet_min_len); void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 99/307 batman-adv: tt: reject oversized local TVLV buffers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 1e9fab756f8395096d5bba7be0c373c4c8f5d165 upstream.
The commit 3a359bf5c61d ("batman-adv: reject oversized global TT response buffers") added a check to ensure that a global return buffer size can be stored in an u16. The same buffer handling also exists for the local data buffer but was not touched.
A similar check should be also be in place for the local TVLV buffer. It doesn't have the similar attack surface because it is only generated from locally discovered MAC addresses but the dynamic nature could still cause temporarily to large buffers.
--- net/batman-adv/translation-table.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +5 -3
@@ -924,12 +924,12 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, {struct batadv_tvlv_tt_vlan_data *tt_vlan;struct batadv_softif_vlan *vlan; +size_t change_offset;u16 num_vlan =0 ;u16 vlan_entries =0 ;u16 total_entries =0 ;u16 tvlv_len;u8 *tt_change_ptr; -int change_offset;spin_lock_bh (&bat_priv->softif_vlan_list_lock);hlist_for_each_entry (vlan, &bat_priv->softif_vlan_list, list) {
@@ -948,8 +948,10 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,if (*tt_len <0 ) *tt_len =batadv_tt_len (total_entries); - tvlv_len = *tt_len; - tvlv_len += change_offset; +if (check_add_overflow (*tt_len, change_offset, &tvlv_len)) { + tvlv_len =0 ; + goto out; + } *tt_data =kmalloc (tvlv_len,GFP_ATOMIC );if (!*tt_data) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 100/307 batman-adv: bla: avoid NULL-ptr deref for claim via dropped interface
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit f80d3d98d2ff78d9e2fe5d68b1f45948c4f7bd24 upstream.
Without rtnl_lock held, a hardif might be retrieved as primary interface of a meshif, but then (while operating on this interface) getting decoupled from the mesh interface. In this case, the meshif still exists but the pointer from the primary hardif to the meshif is set to NULL.
The mesh_iface must be checked first to be non-NULL before continuing to send an ARP request using meshif.
--- net/batman-adv/bridge_loop_avoidance.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +4 -2
@@ -356,12 +356,14 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, const u8 *mac, sizeof(local_claim_dest)); local_claim_dest.type = claimtype; - soft_iface = primary_if->soft_iface; + soft_iface =READ_ONCE (primary_if->soft_iface); +if (!soft_iface) + goto out; skb = arp_create(ARPOP_REPLY, ETH_P_ARP, /* IP DST: 0.0.0.0 */ zeroip, - primary_if->soft_iface, + soft_iface, /* IP SRC: 0.0.0.0 */ zeroip,/* Ethernet DST: Broadcast */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 101/307 batman-adv: tvlv: reject oversized TVLV packets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit f50487e3566358b2b982b7801945e858c78ad9ab upstream.
batadv_tvlv_container_ogm_append() builds a TVLV packet section from the tvlv.container_list. The total size of this section is computed by batadv_tvlv_container_list_size(), which sums the sizes of all registered containers.
The return type and accumulator in batadv_tvlv_container_list_size() were u16. If the accumulated size exceeds U16_MAX, the value wraps around, causing the subsequent allocation in batadv_tvlv_container_ogm_append() to be undersized. The memcpy-style copy that follows would then write beyond the end of the allocated buffer, corrupting kernel memory.
Fix this by widening the return type of batadv_tvlv_container_list_size() to size_t. In batadv_tvlv_container_ogm_append(), check the computed length against U16_MAX before proceeding, and bail out as if the allocation had failed when the limit is exceeded.
--- net/batman-adv/tvlv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
net/batman-adv/tvlv.c +8 -3
@@ -13,6 +13,7 @@#include <linux/gfp.h> #include <linux/if_ether.h> #include <linux/kref.h> +#include <linux/limits.h> #include <linux/list.h> #include <linux/lockdep.h> #include <linux/netdevice.h>
@@ -160,10 +161,10 @@ batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version)* * Return: size of all currently registered tvlv containers in bytes. */ -static u16 batadv_tvlv_container_list_size (struct batadv_priv *bat_priv) +static size_t batadv_tvlv_container_list_size (struct batadv_priv *bat_priv) {struct batadv_tvlv_container *tvlv; -u16 tvlv_len =0 ; +size_t tvlv_len =0 ;lockdep_assert_held (&bat_priv->tvlv.container_list_lock);
@@ -316,13 +317,17 @@ int batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, {struct batadv_tvlv_container *tvlv;struct batadv_tvlv_hdr *tvlv_hdr; -u16 tvlv_value_len; +size_t tvlv_value_len;void *tvlv_value;int tvlv_len_ret;bool ret;spin_lock_bh (&bat_priv->tvlv.container_list_lock); tvlv_value_len =batadv_tvlv_container_list_size (bat_priv); +if (tvlv_value_len >U16_MAX ) { + tvlv_len_ret = -E2BIG ; + goto end; + } ret =batadv_tvlv_realloc_packet_buff (packet_buff, packet_buff_len, packet_min_len, tvlv_value_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 102/307 batman-adv: iv: recover OGM scheduling after forward packet error
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit aa3153bd139a6c48667dcd02608d3b2c80bff02c upstream.
When batadv_iv_ogm_schedule_buff() fails to allocate and queue a forward packet for OGM transmission, the work item that drives periodic OGM scheduling is never re-armed. This silently halts transmission of the node's own OGMs on the affected interface — only OGMs from other peers continue to be aggregated and forwarded.
Fix this by tracking whether batadv_iv_ogm_queue_add() (and transitively batadv_iv_ogm_aggregate_new()) successfully scheduled a forward packet. When scheduling fails, batadv_iv_ogm_schedule_buff() falls back to queuing a dedicated recovery work item (reschedule_work) that fires after one originator interval and calls batadv_iv_ogm_schedule() again.
--- net/batman-adv/bat_iv_ogm.c | 76 +++++++++++++++++++++++++++---------- net/batman-adv/types.h | 3 ++ 2 files changed, 60 insertions(+), 19 deletions(-)
net/batman-adv/bat_iv_ogm.c +57 -19
@@ -223,6 +223,8 @@ static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface) hard_iface->bat_iv.ogm_buff =NULL ;mutex_unlock (&hard_iface->bat_iv.ogm_buff_mutex); + +cancel_delayed_work_sync (&hard_iface->bat_iv.reschedule_work); }static void batadv_iv_ogm_iface_update_mac (struct batadv_hard_iface *hard_iface)
@@ -527,8 +529,10 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,* @if_incoming: interface where the packet was received * @if_outgoing: interface for which the retransmission should be considered * @own_packet: true if it is a self-generated ogm +* +* Return: whether forward packet was scheduled */ -static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, +static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, int packet_len, unsigned long send_time, bool direct_link, struct batadv_hard_iface *if_incoming,
@@ -552,13 +556,13 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, skb =netdev_alloc_skb_ip_align (NULL , skb_size);if (!skb) -return ; +return false; forw_packet_aggr =batadv_forw_packet_alloc (if_incoming, if_outgoing, queue_left, bat_priv, skb);if (!forw_packet_aggr) {kfree_skb (skb); -return ; +return false; } forw_packet_aggr->skb->priority =TC_PRIO_CONTROL ;
@@ -580,6 +584,8 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, batadv_iv_send_outstanding_bat_ogm_packet);batadv_forw_packet_ogmv1_queue (bat_priv, forw_packet_aggr, send_time); + +return true; }/* aggregate a new packet into the existing ogm packet */
@@ -609,8 +615,10 @@ static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,* @if_outgoing: interface for which the retransmission should be considered * @own_packet: true if it is a self-generated ogm * @send_time: timestamp (jiffies) when the packet is to be sent +* +* Return: whether forward packet was scheduled */ -static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv, +static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv, unsigned char *packet_buff, int packet_len, struct batadv_hard_iface *if_incoming,
@@ -662,14 +670,16 @@ static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,if (!own_packet &&atomic_read (&bat_priv->aggregated_ogms)) send_time += max_aggregation_jiffies; -batadv_iv_ogm_aggregate_new (packet_buff, packet_len, - send_time, direct_link, - if_incoming, if_outgoing, - own_packet); +return batadv_iv_ogm_aggregate_new (packet_buff, packet_len, + send_time, direct_link, + if_incoming, if_outgoing, + own_packet); }else {batadv_iv_ogm_aggregate (forw_packet_aggr, packet_buff, packet_len, direct_link);spin_unlock_bh (&bat_priv->forw_bat_list_lock); + +return true; } }
@@ -781,6 +791,8 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)u32 seqno;u16 tvlv_len =0 ;unsigned long send_time; +bool reschedule = false; +bool scheduled;int ret;lockdep_assert_held (&hard_iface->bat_iv.ogm_buff_mutex);
@@ -809,11 +821,8 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface) ogm_buff_len, BATADV_OGM_HLEN);if (ret <0 ) { -/* OGMs must be queued even when the buffer allocation for -* TVLVs failed. just fall back to the non-TVLV version -*/ - ret =0 ; - *ogm_buff_len =BATADV_OGM_HLEN ; + reschedule = true; + goto out; } tvlv_len = ret;
@@ -835,8 +844,11 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)/* OGMs from secondary interfaces are only scheduled on their * respective interfaces. */ -batadv_iv_ogm_queue_add (bat_priv, *ogm_buff, *ogm_buff_len, - hard_iface, hard_iface,1 , send_time); + scheduled =batadv_iv_ogm_queue_add (bat_priv, *ogm_buff, *ogm_buff_len, + hard_iface, hard_iface,1 , send_time); +if (!scheduled) + reschedule = true; + goto out; }
@@ -851,15 +863,28 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)if (!kref_get_unless_zero (&tmp_hard_iface->refcount))continue ; -batadv_iv_ogm_queue_add (bat_priv, *ogm_buff, - *ogm_buff_len, hard_iface, - tmp_hard_iface,1 , send_time); - + scheduled =batadv_iv_ogm_queue_add (bat_priv, *ogm_buff, + *ogm_buff_len, hard_iface, + tmp_hard_iface,1 , send_time);batadv_hardif_put (tmp_hard_iface); + +if (!scheduled && tmp_hard_iface == hard_iface) + reschedule = true; }rcu_read_unlock (); out: +if (reschedule) { +/* there was a failure scheduling the own forward packet. +* as result, the batadv_iv_send_outstanding_bat_ogm_packet() +* work item is no longer scheduled. it is therefore necessary +* to reschedule it manually +*/ +queue_delayed_work (batadv_event_workqueue, + &hard_iface->bat_iv.reschedule_work, +msecs_to_jiffies (atomic_read (&bat_priv->orig_interval))); + } +batadv_hardif_put (primary_if); }
@@ -874,6 +899,17 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)mutex_unlock (&hard_iface->bat_iv.ogm_buff_mutex); } +static void batadv_iv_ogm_reschedule (struct work_struct *work) +{ +struct delayed_work *delayed_work =to_delayed_work (work); +struct batadv_hard_iface *hard_iface; + + hard_iface =container_of (delayed_work, + struct batadv_hard_iface, + bat_iv.reschedule_work); +batadv_iv_ogm_schedule (hard_iface); +} +/** * batadv_iv_orig_ifinfo_sum() - Get bcast_own sum for originator over interface * @orig_node: originator which reproadcasted the OGMs directly
@@ -2277,6 +2313,8 @@ batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,static void batadv_iv_iface_enabled (struct batadv_hard_iface *hard_iface) { +INIT_DELAYED_WORK (&hard_iface->bat_iv.reschedule_work, batadv_iv_ogm_reschedule); +/* begin scheduling originator messages on that interface */ batadv_iv_ogm_schedule (hard_iface); }
net/batman-adv/types.h +3 -0
@@ -83,6 +83,9 @@ struct batadv_hard_iface_bat_iv {/** @ogm_seqno: OGM sequence number - used to identify each OGM */ atomic_t ogm_seqno; +/** @reschedule_work: recover OGM schedule after schedule error */ +struct delayed_work reschedule_work; +/** @ogm_buff_mutex: lock protecting ogm_buff and ogm_buff_len */ struct mutex ogm_buff_mutex; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 103/307 batman-adv: tp_meter: avoid role confusion in tp_list
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit ff24f2ecfd94c07a2b89bac497433e3b23271cac upstream.
Session lookups in tp_list matched only on destination address (and optionally session ID), leaving role validation to the caller. If two sessions with the same other_end coexisted (one as sender, one as receiver) a lookup could silently return the wrong one, causing the caller's role to bail out early, potentially skipping necessary cleanup.
Move the role check into the lookup functions themselves so the correct entry is always returned, or none at all. Since batadv_tp_start() legitimately needs to detect any active session to a destination regardless of role, introduce a dedicated helper for that case rather than bending the existing lookup semantics.
--- net/batman-adv/tp_meter.c | 59 ++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 23 deletions(-)
net/batman-adv/tp_meter.c +36 -23
@@ -255,6 +255,7 @@ static void batadv_tp_batctl_error_notify(enum batadv_tp_meter_reason reason,* batadv_tp_list_find() - find a tp_vars object in the global list * @bat_priv: the bat priv with all the soft interface information * @dst: the other endpoint MAC address to look for +* @role: role of the session * * Look for a tp_vars object matching dst as end_point and return it after * having increment the refcounter. Return NULL is not found
@@ -262,7 +263,8 @@ static void batadv_tp_batctl_error_notify(enum batadv_tp_meter_reason reason,* Return: matching tp_vars or NULL when no tp_vars with @dst was found */ static struct batadv_tp_vars *batadv_tp_list_find (struct batadv_priv *bat_priv, -const u8 *dst) +const u8 *dst, +enum batadv_tp_meter_role role) {struct batadv_tp_vars *pos, *tp_vars =NULL ;
@@ -271,6 +273,9 @@ static struct batadv_tp_vars *batadv_tp_list_find(struct batadv_priv *bat_priv,if (!batadv_compare_eth (pos->other_end, dst))continue ; +if (pos->role != role) +continue ; +/* most of the time this function is invoked during the normal * process..it makes sens to pay more when the session is * finished and to speed the process up during the measurement
@@ -286,12 +291,33 @@ static struct batadv_tp_vars *batadv_tp_list_find(struct batadv_priv *bat_priv,return tp_vars; } +/** +* batadv_tp_list_active() - check if session from/to destination is ongoing +* @bat_priv: the bat priv with all the mesh interface information +* @dst: the other endpoint MAC address to look for +* +* Return: if matching session with @dst was found +*/ +static bool batadv_tp_list_active (struct batadv_priv *bat_priv,const u8 *dst) + __must_hold(&bat_priv->tp_list_lock) +{ +struct batadv_tp_vars *tp_vars; + +hlist_for_each_entry_rcu (tp_vars, &bat_priv->tp_list, list) { +if (batadv_compare_eth (tp_vars->other_end, dst)) +return true; + } + +return false; +} +/** * batadv_tp_list_find_session() - find tp_vars session object in the global * list * @bat_priv: the bat priv with all the soft interface information * @dst: the other endpoint MAC address to look for * @session: session identifier +* @role: role of the session * * Look for a tp_vars object matching dst as end_point, session as tp meter * session and return it after having increment the refcounter. Return NULL
@@ -301,7 +327,7 @@ static struct batadv_tp_vars *batadv_tp_list_find(struct batadv_priv *bat_priv,*/ static struct batadv_tp_vars *batadv_tp_list_find_session (struct batadv_priv *bat_priv,const u8 *dst, -const u8 *session) +const u8 *session,enum batadv_tp_meter_role role) {struct batadv_tp_vars *pos, *tp_vars =NULL ;
@@ -313,6 +339,9 @@ batadv_tp_list_find_session(struct batadv_priv *bat_priv, const u8 *dst,if (memcmp (pos->session, session,sizeof (pos->session)) !=0 )continue ; +if (pos->role != role) +continue ; +/* most of the time this function is invoked during the normal * process..it makes sense to pay more when the session is * finished and to speed the process up during the measurement
@@ -671,13 +700,10 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,/* find the tp_vars */ tp_vars =batadv_tp_list_find_session (bat_priv, icmp->orig, - icmp->session); + icmp->session,BATADV_TP_SENDER );if (unlikely (!tp_vars))return ; -if (unlikely (tp_vars->role !=BATADV_TP_SENDER )) - goto out; -if (unlikely (batadv_tp_sender_stopped (tp_vars))) goto out;
@@ -986,10 +1012,8 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,return ; } - tp_vars =batadv_tp_list_find (bat_priv, dst); -if (tp_vars) { +if (batadv_tp_list_active (bat_priv, dst)) {spin_unlock_bh (&bat_priv->tp_list_lock); -batadv_tp_vars_put (tp_vars);batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Meter: test to or from the same node already ongoing, aborting\n" ); batadv_tp_batctl_error_notify(BATADV_TP_REASON_ALREADY_ONGOING,
@@ -1110,18 +1134,14 @@ void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst,if (!orig_node)return ; - tp_vars =batadv_tp_list_find (bat_priv, orig_node->orig); + tp_vars =batadv_tp_list_find (bat_priv, orig_node->orig,BATADV_TP_SENDER );if (!tp_vars) {batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Meter: trying to interrupt an already over connection\n" ); goto out_put_orig_node; } -if (unlikely (tp_vars->role !=BATADV_TP_SENDER )) - goto out_put_tp_vars; -batadv_tp_sender_shutdown (tp_vars, return_value); -out_put_tp_vars:batadv_tp_vars_put (tp_vars); out_put_orig_node:batadv_orig_node_put (orig_node);
@@ -1377,7 +1397,7 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv, goto out_unlock; tp_vars =batadv_tp_list_find_session (bat_priv, icmp->orig, - icmp->session); + icmp->session,BATADV_TP_RECEIVER );if (tp_vars) goto out_unlock;
@@ -1448,7 +1468,7 @@ static void batadv_tp_recv_msg(struct batadv_priv *bat_priv, } }else { tp_vars =batadv_tp_list_find_session (bat_priv, icmp->orig, - icmp->session); + icmp->session,BATADV_TP_RECEIVER );if (!tp_vars) { batadv_dbg(BATADV_DBG_TP_METER, bat_priv, "Unexpected packet from %pM!\n",
@@ -1457,13 +1477,6 @@ static void batadv_tp_recv_msg(struct batadv_priv *bat_priv, } } -if (unlikely (tp_vars->role !=BATADV_TP_RECEIVER )) { -batadv_dbg (BATADV_DBG_TP_METER , bat_priv, -"Meter: dropping packet: not expected (role=%u)\n" , - tp_vars->role); - goto out; - } - tp_vars->last_recv_time = jiffies;/* if the packet is a duplicate, it may be the case that an ACK has been
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 104/307 s390/cio: Restore GFP_DMA for CHSC allocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Oberparleiter <[email protected]>
[ Upstream commit ea34567db0a6b3a7ce78ba421592344315c8f90e ]
Re-add GFP_DMA when allocating memory for CHSC control blocks. On some supported machines, CHSC cannot access memory outside the DMA zone, causing CHSC command failures.
--- drivers/s390/cio/chsc.c | 4 ++-- drivers/s390/cio/chsc_sch.c | 20 ++++++++++---------- drivers/s390/cio/scm.c | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/s390/cio/chsc.c +2 -2
@@ -1153,8 +1153,8 @@ int __init chsc_init(void) {int ret; - sei_page = (void *)get_zeroed_page (GFP_KERNEL ); - chsc_page = (void *)get_zeroed_page (GFP_KERNEL ); + sei_page = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA ); + chsc_page = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!sei_page || !chsc_page) { ret = -ENOMEM ; goto out_err;
drivers/s390/cio/chsc_sch.c +10 -10
@@ -293,7 +293,7 @@ static int chsc_ioctl_start(void __user *user_area)if (!css_general_characteristics.dynio)/* It makes no sense to try. */ return -EOPNOTSUPP ; - chsc_area = (void *)get_zeroed_page (GFP_KERNEL ); + chsc_area = (void *)get_zeroed_page (GFP_DMA |GFP_KERNEL );if (!chsc_area)return -ENOMEM ; request =kzalloc (sizeof (*request),GFP_KERNEL );
@@ -341,7 +341,7 @@ static int chsc_ioctl_on_close_set(void __user *user_area) ret = -ENOMEM ; goto out_unlock; } - on_close_chsc_area = (void *)get_zeroed_page (GFP_KERNEL ); + on_close_chsc_area = (void *)get_zeroed_page (GFP_DMA |GFP_KERNEL );if (!on_close_chsc_area) { ret = -ENOMEM ; goto out_free_request;
@@ -393,7 +393,7 @@ static int chsc_ioctl_start_sync(void __user *user_area)struct chsc_sync_area *chsc_area;int ret, ccode; - chsc_area = (void *)get_zeroed_page (GFP_KERNEL ); + chsc_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!chsc_area)return -ENOMEM ;if (copy_from_user (chsc_area, user_area,PAGE_SIZE )) {
@@ -439,7 +439,7 @@ static int chsc_ioctl_info_channel_path(void __user *user_cd)u8 data[PAGE_SIZE -20 ]; } __attribute__ ((packed)) *scpcd_area; - scpcd_area = (void *)get_zeroed_page (GFP_KERNEL ); + scpcd_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!scpcd_area)return -ENOMEM ; cd =kzalloc (sizeof (*cd),GFP_KERNEL );
@@ -501,7 +501,7 @@ static int chsc_ioctl_info_cu(void __user *user_cd)u8 data[PAGE_SIZE -20 ]; } __attribute__ ((packed)) *scucd_area; - scucd_area = (void *)get_zeroed_page (GFP_KERNEL ); + scucd_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!scucd_area)return -ENOMEM ; cd =kzalloc (sizeof (*cd),GFP_KERNEL );
@@ -564,7 +564,7 @@ static int chsc_ioctl_info_sch_cu(void __user *user_cud)u8 data[PAGE_SIZE -20 ]; } __attribute__ ((packed)) *sscud_area; - sscud_area = (void *)get_zeroed_page (GFP_KERNEL ); + sscud_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!sscud_area)return -ENOMEM ; cud =kzalloc (sizeof (*cud),GFP_KERNEL );
@@ -626,7 +626,7 @@ static int chsc_ioctl_conf_info(void __user *user_ci)u8 data[PAGE_SIZE -20 ]; } __attribute__ ((packed)) *sci_area; - sci_area = (void *)get_zeroed_page (GFP_KERNEL ); + sci_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!sci_area)return -ENOMEM ; ci =kzalloc (sizeof (*ci),GFP_KERNEL );
@@ -697,7 +697,7 @@ static int chsc_ioctl_conf_comp_list(void __user *user_ccl)u32 res; } __attribute__ ((packed)) *cssids_parm; - sccl_area = (void *)get_zeroed_page (GFP_KERNEL ); + sccl_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!sccl_area)return -ENOMEM ; ccl =kzalloc (sizeof (*ccl),GFP_KERNEL );
@@ -757,7 +757,7 @@ static int chsc_ioctl_chpd(void __user *user_chpd)int ret; chpd =kzalloc (sizeof (*chpd),GFP_KERNEL ); - scpd_area = (void *)get_zeroed_page (GFP_KERNEL ); + scpd_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!scpd_area || !chpd) { ret = -ENOMEM ; goto out_free;
@@ -797,7 +797,7 @@ static int chsc_ioctl_dcal(void __user *user_dcal)u8 data[PAGE_SIZE -36 ]; } __attribute__ ((packed)) *sdcal_area; - sdcal_area = (void *)get_zeroed_page (GFP_KERNEL ); + sdcal_area = (void *)get_zeroed_page (GFP_KERNEL |GFP_DMA );if (!sdcal_area)return -ENOMEM ; dcal =kzalloc (sizeof (*dcal),GFP_KERNEL );
drivers/s390/cio/scm.c +1 -1
@@ -228,7 +228,7 @@ int scm_update_information(void)size_t num;int ret; - scm_info = (void *)__get_free_page (GFP_KERNEL ); + scm_info = (void *)__get_free_page (GFP_KERNEL |GFP_DMA );if (!scm_info)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 105/307 batman-adv: tp_meter: directly shut down timer on cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit d5487249a81ea658717614009c8f46acc5b7101a upstream.
batadv_tp_sender_cleanup() was calling timer_delete_sync() followed by timer_delete() to guard against the timer handler re-arming itself between the two calls. This double-deletion hack relied on the sending status being set to 0 to suppress re-arming.
Replace both calls with a single timer_shutdown_sync(). This function both waits for any running timer callback to complete (like timer_delete_sync()) and permanently disarms the timer so it cannot be re-armed afterwards, making re-arming prevention unconditional and self-documenting.
The re-arming property is also required because otherwise:
1. context 0 (batadv_tp_recv_ack()) checks in batadv_tp_reset_sender_timer() if sending is still 1 -> it is
2. context 1 changes in batadv_tp_sender_shutdown() sending to 0 and in this process forces the kthread to stop timer in batadv_tp_sender_cleanup()
3. context 0 continues in batadv_tp_reset_sender_timer() and rearms the timer -> but the reference for it is already gone
--- net/batman-adv/tp_meter.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
net/batman-adv/tp_meter.c +1 -7
@@ -430,13 +430,7 @@ static void batadv_tp_sender_cleanup(struct batadv_tp_vars *tp_vars)batadv_tp_list_detach (tp_vars);/* kill the timer and remove its reference */ -del_timer_sync (&tp_vars->timer); -/* the worker might have rearmed itself therefore we kill it again. Note -* that if the worker should run again before invoking the following -* del_timer(), it would not re-arm itself once again because the status -* is OFF now -*/ -del_timer (&tp_vars->timer); +timer_shutdown_sync (&tp_vars->timer);batadv_tp_vars_put (tp_vars); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 106/307 batman-adv: tt: fix TOCTOU race for reported vlans
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 94d27005016be15ffc638b2ecbc4d58805ad7b48 upstream.
The local TT based TVLV is generated by first checking the number of VLANs which have at least one TT entry. A new buffer with the correct size for the VLANs is then allocated. Only then, the list of VLANs s used to fill the VLAN entries in the buffer. During this time, the meshif_vlan_list_lock is held. But the actual number of TT entries of each VLAN can still increase during this time - just not the number of VLANs in the list.
But the prefilter used in the buffer size calculation might still cause an increase of the number of VLANs which need to be stored. Simply because a VLAN might now suddenly have at least one entry when it had none in the pre-alloc check - and then needs to occupy space which was not allocated.
It is better to overestimate the buffer size at the beginning and then fill the buffer only with the VLANs which are not empty.
--- net/batman-adv/translation-table.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
net/batman-adv/translation-table.c +10 -4
@@ -934,11 +934,8 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,spin_lock_bh (&bat_priv->softif_vlan_list_lock);hlist_for_each_entry (vlan, &bat_priv->softif_vlan_list, list) { vlan_entries =atomic_read (&vlan->tt.num_entries); -if (vlan_entries <1 ) -continue ; - - num_vlan++; total_entries += vlan_entries; + num_vlan++; } change_offset =sizeof (**tt_data);
@@ -964,6 +961,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, (*tt_data)->num_vlan =htons (num_vlan); tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data +1 ); + num_vlan =0 ;hlist_for_each_entry (vlan, &bat_priv->softif_vlan_list, list) { vlan_entries =atomic_read (&vlan->tt.num_entries);if (vlan_entries <1 )
@@ -974,8 +972,16 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, tt_vlan->reserved =0 ; tt_vlan++; + num_vlan++; } +/* recalculate in case number of VLANs reduced */ + change_offset =sizeof (**tt_data); + change_offset += num_vlan *sizeof (*tt_vlan); + tvlv_len = *tt_len + change_offset; + + (*tt_data)->num_vlan =htons (num_vlan); + tt_change_ptr = (u8 *)*tt_data + change_offset; *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 107/307 batman-adv: tt: avoid empty VLAN responses
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit fa1bd704940b5bcbc32c0b28db9167405c8ee5e0 upstream.
The commit 16116dac2339 ("batman-adv: prevent TT request storms by not sending inconsistent TT TLVLs") added checks to the local (direct) TT response code. But the response can also be done indirectly by another node using the global TT state. To avoid such inconsistency states reported in the original fix, also avoid sending empty VLANs for replies from the global TT state.
--- net/batman-adv/translation-table.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +18 -3
@@ -843,17 +843,19 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node, s32 *tt_len) {u16 num_vlan =0 ; -u16 num_entries =0 ;u16 tvlv_len =0 ;unsigned int change_offset;struct batadv_tvlv_tt_vlan_data *tt_vlan;struct batadv_orig_node_vlan *vlan; +u16 total_entries =0 ;u8 *tt_change_ptr; +int vlan_entries;spin_lock_bh (&orig_node->vlan_list_lock);hlist_for_each_entry (vlan, &orig_node->vlan_list, list) { + vlan_entries =atomic_read (&vlan->tt.num_entries); + total_entries += vlan_entries; num_vlan++; - num_entries +=atomic_read (&vlan->tt.num_entries); } change_offset =sizeof (**tt_data);
@@ -861,7 +863,7 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,/* if tt_len is negative, allocate the space needed by the full table */ if (*tt_len <0 ) - *tt_len =batadv_tt_len (num_entries); + *tt_len =batadv_tt_len (total_entries);if (change_offset >U16_MAX || *tt_len >U16_MAX - change_offset) { *tt_len =0 ;
@@ -882,14 +884,27 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node, (*tt_data)->num_vlan =htons (num_vlan); tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data +1 ); + num_vlan =0 ;hlist_for_each_entry (vlan, &orig_node->vlan_list, list) { + vlan_entries =atomic_read (&vlan->tt.num_entries); +if (vlan_entries <1 ) +continue ; + tt_vlan->vid =htons (vlan->vid); tt_vlan->crc =htonl (vlan->tt.crc); tt_vlan->reserved =0 ; tt_vlan++; + num_vlan++; } +/* recalculate in case number of VLANs reduced */ + change_offset =sizeof (**tt_data); + change_offset += num_vlan *sizeof (*tt_vlan); + tvlv_len = *tt_len + change_offset; + + (*tt_data)->num_vlan =htons (num_vlan); + tt_change_ptr = (u8 *)*tt_data + change_offset; *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 108/307 batman-adv: bla: avoid double decrement of bla.num_requests
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 83ab69bd12b80f6ea169c8bea6977701b53a043d upstream.
The bla.num_requests is increased when no request_sent was in progress. And it is decremented in various places (announcement was received, backbone is purged, periodic work). But the check if the request_sent is actually set to a specific state and the atomic_dec/_inc are not safe because they are not atomic (TOCTOU) and multiple such code portions can run concurrently.
At the same time, it is necessary to modify request_sent (state) and bla.num_requests atomically. Otherwise batadv_bla_send_request() might set request_sent to 1 and is interrupted. batadv_handle_announce() can then set request_sent back to 0 and decrement num_requests before batadv_bla_send_request() incremented it.
The two operations must therefore be locked. And since state (request_sent) and wait_periods are only accessed inside this lock, they can be converted to simpler datatypes. And to avoid that the bla.num_requests is touched by a parallel running context with a valid backbone_gw reference after batadv_bla_purge_backbone_gw() ran, a third state "stopped" is required to correctly signal that a backbone_gw is in the state of being cleaned up.
--- net/batman-adv/bridge_loop_avoidance.c | 51 ++++++++++++++++++-------- net/batman-adv/soft-interface.c | 1 + net/batman-adv/types.h | 39 ++++++++++++++++---- 3 files changed, 67 insertions(+), 24 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +35 -16
@@ -516,8 +516,8 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, const u8 *orig, entry->crc =BATADV_BLA_CRC_INIT ; entry->bat_priv = bat_priv;spin_lock_init (&entry->crc_lock); -atomic_set (&entry->request_sent,0 ); -atomic_set (&entry->wait_periods,0 ); + entry->state =BATADV_BLA_BACKBONE_GW_SYNCED ; + entry->wait_periods =0 ;ether_addr_copy (entry->orig, orig);INIT_WORK (&entry->report_work, batadv_bla_loopdetect_report);kref_init (&entry->refcount);
@@ -546,9 +546,13 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, const u8 *orig,batadv_bla_send_announce (bat_priv, entry);/* this will be decreased in the worker thread */ -atomic_inc (&entry->request_sent); -atomic_set (&entry->wait_periods,BATADV_BLA_WAIT_PERIODS ); -atomic_inc (&bat_priv->bla.num_requests); +spin_lock_bh (&bat_priv->bla.num_requests_lock); +if (entry->state ==BATADV_BLA_BACKBONE_GW_SYNCED ) { + entry->state =BATADV_BLA_BACKBONE_GW_UNSYNCED ; + entry->wait_periods =BATADV_BLA_WAIT_PERIODS ; +atomic_inc (&bat_priv->bla.num_requests); + } +spin_unlock_bh (&bat_priv->bla.num_requests_lock); }return entry;
@@ -651,10 +655,12 @@ static void batadv_bla_send_request(struct batadv_bla_backbone_gw *backbone_gw) backbone_gw->vid, BATADV_CLAIM_TYPE_REQUEST);/* no local broadcasts should be sent or received, for now. */ -if (!atomic_read (&backbone_gw->request_sent)) { +spin_lock_bh (&backbone_gw->bat_priv->bla.num_requests_lock); +if (backbone_gw->state ==BATADV_BLA_BACKBONE_GW_SYNCED ) { + backbone_gw->state =BATADV_BLA_BACKBONE_GW_UNSYNCED ;atomic_inc (&backbone_gw->bat_priv->bla.num_requests); -atomic_set (&backbone_gw->request_sent,1 ); } +spin_unlock_bh (&backbone_gw->bat_priv->bla.num_requests_lock); }/**
@@ -875,10 +881,12 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,/* if we have sent a request and the crc was OK, * we can allow traffic again. */ -if (atomic_read (&backbone_gw->request_sent)) { +spin_lock_bh (&bat_priv->bla.num_requests_lock); +if (backbone_gw->state ==BATADV_BLA_BACKBONE_GW_UNSYNCED ) { + backbone_gw->state =BATADV_BLA_BACKBONE_GW_SYNCED ;atomic_dec (&backbone_gw->bat_priv->bla.num_requests); -atomic_set (&backbone_gw->request_sent,0 ); } +spin_unlock_bh (&bat_priv->bla.num_requests_lock); }batadv_backbone_gw_put (backbone_gw);
@@ -1257,9 +1265,13 @@ static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now) purged = true;/* don't wait for the pending request anymore */ -if (atomic_read (&backbone_gw->request_sent)) +spin_lock_bh (&bat_priv->bla.num_requests_lock); +if (backbone_gw->state ==BATADV_BLA_BACKBONE_GW_UNSYNCED )atomic_dec (&bat_priv->bla.num_requests); + backbone_gw->state =BATADV_BLA_BACKBONE_GW_STOPPED ; +spin_unlock_bh (&bat_priv->bla.num_requests_lock); +batadv_bla_del_backbone_claims (backbone_gw);hlist_del_rcu (&backbone_gw->hash_entry);
@@ -1510,7 +1522,7 @@ static void batadv_bla_periodic_work(struct work_struct *work)batadv_bla_send_loopdetect (bat_priv, backbone_gw); -/* request_sent is only set after creation to avoid +/* state is only set to unsynced after creation to avoid * problems when we are not yet known as backbone gw * in the backbone. *
@@ -1519,14 +1531,21 @@ static void batadv_bla_periodic_work(struct work_struct *work)* some grace time. */ -if (atomic_read (&backbone_gw->request_sent) ==0 ) -continue ; +spin_lock_bh (&bat_priv->bla.num_requests_lock); +if (backbone_gw->state !=BATADV_BLA_BACKBONE_GW_UNSYNCED ) + goto unlock_next; -if (!atomic_dec_and_test (&backbone_gw->wait_periods)) -continue ; +if (backbone_gw->wait_periods >0 ) + backbone_gw->wait_periods--; + +if (backbone_gw->wait_periods >0 ) + goto unlock_next; + backbone_gw->state =BATADV_BLA_BACKBONE_GW_SYNCED ;atomic_dec (&backbone_gw->bat_priv->bla.num_requests); -atomic_set (&backbone_gw->request_sent,0 ); + +unlock_next: +spin_unlock_bh (&bat_priv->bla.num_requests_lock); }rcu_read_unlock (); }
net/batman-adv/soft-interface.c +1 -0
@@ -787,6 +787,7 @@ static int batadv_softif_init_late(struct net_device *dev)atomic_set (&bat_priv->tt.ogm_append_cnt,0 );#ifdef CONFIG_BATMAN_ADV_BLA atomic_set (&bat_priv->bla.num_requests,0 ); +spin_lock_init (&bat_priv->bla.num_requests_lock);#endif atomic_set (&bat_priv->tp_num,0 );
net/batman-adv/types.h +31 -8
@@ -1091,6 +1091,12 @@ struct batadv_priv_bla {/** @num_requests: number of bla requests in flight */ atomic_t num_requests; +/** +* @num_requests_lock: locks update num_requests + +* batadv_backbone_gw::state + batadv_backbone_gw::wait_periods update +*/ +spinlock_t num_requests_lock; +/** * @claim_hash: hash table containing mesh nodes this host has claimed */
@@ -1825,6 +1831,27 @@ struct batadv_priv {#ifdef CONFIG_BATMAN_ADV_BLA +enum batadv_bla_backbone_gw_state { +/** +* @BATADV_BLA_BACKBONE_GW_STOPPED: backbone gw is being removed +* and it must not longer work on requests +*/ +BATADV_BLA_BACKBONE_GW_STOPPED , + +/** +* @BATADV_BLA_BACKBONE_GW_UNSYNCED: backbone was detected out +* of sync and a request was send. No traffic is forwarded until the +* situation is resolved +*/ +BATADV_BLA_BACKBONE_GW_UNSYNCED , + +/** +* @BATADV_BLA_BACKBONE_GW_SYNCED: backbone is consider to be in +* sync. traffic can be forwarded +*/ +BATADV_BLA_BACKBONE_GW_SYNCED , +}; +/** * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN */
@@ -1850,16 +1877,12 @@ struct batadv_bla_backbone_gw {/** * @wait_periods: grace time for bridge forward delays and bla group * forming at bootup phase - no bcast traffic is formwared until it has -* elapsed +* elapsed. Must only be access with num_requests_lock. */ -atomic_t wait_periods; +u8 wait_periods; -/** -* @request_sent: if this bool is set to true we are out of sync with -* this backbone gateway - no bcast traffic is formwared until the -* situation was resolved -*/ -atomic_t request_sent; +/** @state: sync state. Must only be access with num_requests_lock. */ +enum batadv_bla_backbone_gw_state state;/** @crc: crc16 checksum over all claims */ u16 crc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 109/307 mm/page_alloc: clear page->private in free_pages_prepare()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Gavrilov <[email protected]>
[ Upstream commit ac1ea219590c09572ed5992dc233bbf7bb70fef9 ]
Several subsystems (slub, shmem, ttm, etc.) use page->private but don't clear it before freeing pages. When these pages are later allocated as high-order pages and split via split_page(), tail pages retain stale page->private values.
This causes a use-after-free in the swap subsystem. The swap code uses page->private to track swap count continuations, assuming freshly allocated pages have page->private == 0. When stale values are present, swap_count_continued() incorrectly assumes the continuation list is valid and iterates over uninitialized page->lru containing LIST_POISON values, causing a crash:
KASAN: maybe wild-memory-access in range [0xdead000000000100-0xdead000000000107] RIP: 0010:__do_sys_swapoff+0x1151/0x1860
Fix this by clearing page->private in free_pages_prepare(), ensuring all freed pages have clean state regardless of previous use.
--- mm/page_alloc.c | 1 + 1 file changed, 1 insertion(+)
mm/page_alloc.c +1 -0
@@ -1158,6 +1158,7 @@ __always_inline bool free_pages_prepare(struct page *page,page_cpupid_reset_last (page); page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP ; + page->private =0 ;reset_page_owner (page, order);page_table_check_free (page, order);pgalloc_tag_sub (page,1 << order);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 110/307 media: rc: fix race between unregister and urb/irq callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit dccc0c3ddf8f16071736f98a7d6dd46a2d43e037 ]
Some rc device drivers have a race condition between rc_unregister_device() and irq or urb callbacks. This is because rc_unregister_device() does two things, it marks the device as unregistered so no new commands can be issued and then it calls rc_free_device(). This means the driver has no chance to cancel any pending urb callbacks or interrupts after the device has been marked as unregistered. Those callbacks may access struct rc_dev or its members (e.g. struct ir_raw_event_ctrl), which have been freed by rc_free_device().
This change removes the implicit call to rc_free_device() from rc_unregister_device(). This means that device drivers can call rc_unregister_device() in their remove or disconnect function, then cancel all the urbs and interrupts before explicitly calling rc_free_device().
Note this is an alternative fix for an issue found by Haotian Zhang, see the Closes: tags.
Stable-dep-of: 646ebdd31058 ("media: rc: ttusbir: fix inverted error logic")
--- drivers/gpu/drm/bridge/sil-sii8620.c | 1 + drivers/hid/hid-picolcd_cir.c | 1 + drivers/media/cec/core/cec-core.c | 2 +- drivers/media/common/siano/smsir.c | 1 + drivers/media/i2c/ir-kbd-i2c.c | 2 ++ drivers/media/pci/bt8xx/bttv-input.c | 3 ++- drivers/media/pci/cx23885/cx23885-input.c | 1 + drivers/media/pci/cx88/cx88-input.c | 3 ++- drivers/media/pci/dm1105/dm1105.c | 1 + drivers/media/pci/mantis/mantis_input.c | 1 + drivers/media/pci/saa7134/saa7134-input.c | 1 + drivers/media/pci/smipcie/smipcie-ir.c | 1 + drivers/media/pci/ttpci/budget-ci.c | 1 + drivers/media/rc/ati_remote.c | 6 +++--- drivers/media/rc/ene_ir.c | 2 +- drivers/media/rc/fintek-cir.c | 3 ++- drivers/media/rc/igorplugusb.c | 1 + drivers/media/rc/iguanair.c | 1 + drivers/media/rc/img-ir/img-ir-hw.c | 3 ++- drivers/media/rc/img-ir/img-ir-raw.c | 3 ++- drivers/media/rc/imon.c | 3 ++- drivers/media/rc/ir-hix5hd2.c | 2 +- drivers/media/rc/ir_toy.c | 1 + drivers/media/rc/ite-cir.c | 2 +- drivers/media/rc/mceusb.c | 1 + drivers/media/rc/rc-ir-raw.c | 5 ----- drivers/media/rc/rc-loopback.c | 1 + drivers/media/rc/rc-main.c | 6 +----- drivers/media/rc/redrat3.c | 4 +++- drivers/media/rc/st_rc.c | 2 +- drivers/media/rc/streamzap.c | 7 ++++--- drivers/media/rc/sunxi-cir.c | 1 + drivers/media/rc/ttusbir.c | 2 +- drivers/media/rc/winbond-cir.c | 2 +- drivers/media/rc/xbox_remote.c | 5 +++-- drivers/media/usb/au0828/au0828-input.c | 1 + drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 1 + drivers/media/usb/dvb-usb/dvb-usb-remote.c | 6 ++++-- drivers/media/usb/em28xx/em28xx-input.c | 1 + drivers/staging/media/av7110/av7110_ir.c | 1 + include/media/rc-core.h | 2 -- 41 files changed, 58 insertions(+), 36 deletions(-)
drivers/gpu/drm/bridge/sil-sii8620.c +1 -0
@@ -2220,6 +2220,7 @@ static void sii8620_detach(struct drm_bridge *bridge)return ;rc_unregister_device (ctx->rc_dev); +rc_free_device (ctx->rc_dev); } static int sii8620_is_packing_required(struct sii8620 *ctx,
drivers/hid/hid-picolcd_cir.c +1 -0
@@ -134,5 +134,6 @@ void picolcd_exit_cir(struct picolcd_data *data) data->rc_dev =NULL ;rc_unregister_device (rdev); +rc_free_device (rdev); }
drivers/media/cec/core/cec-core.c +1 -1
@@ -337,8 +337,8 @@ int cec_register_adapter(struct cec_adapter *adap, res =cec_devnode_register (&adap->devnode, adap->owner);if (res) {#ifdef CONFIG_MEDIA_CEC_RC -/* Note: rc_unregister also calls rc_free */ rc_unregister_device (adap->rc); +rc_free_device (adap->rc); adap->rc =NULL ;#endif return res;
drivers/media/common/siano/smsir.c +1 -0
@@ -92,6 +92,7 @@ int sms_ir_init(struct smscore_device_t *coredev)void sms_ir_exit (struct smscore_device_t *coredev) {rc_unregister_device (coredev->ir.dev); +rc_free_device (coredev->ir.dev);pr_debug ("\n" ); }
drivers/media/i2c/ir-kbd-i2c.c +2 -0
@@ -355,6 +355,7 @@ static void ir_work(struct work_struct *work)mutex_unlock (&ir->lock);if (rc == -ENODEV ) {rc_unregister_device (ir->rc); +rc_free_device (ir->rc); ir->rc =NULL ;return ; }
@@ -972,6 +973,7 @@ static void ir_remove(struct i2c_client *client)i2c_unregister_device (ir->tx_c);rc_unregister_device (ir->rc); +rc_free_device (ir->rc); }static const struct i2c_device_id ir_kbd_id[] = {
drivers/media/pci/bt8xx/bttv-input.c +2 -1
@@ -572,8 +572,9 @@ void bttv_input_fini(struct bttv *btv)if (btv->remote ==NULL )return ; -bttv_ir_stop (btv);rc_unregister_device (btv->remote->dev); +bttv_ir_stop (btv); +rc_free_device (btv->remote->dev);kfree (btv->remote); btv->remote =NULL ; }
drivers/media/pci/cx23885/cx23885-input.c +1 -0
@@ -402,6 +402,7 @@ void cx23885_input_fini(struct cx23885_dev *dev)if (dev->kernel_ir ==NULL )return ;rc_unregister_device (dev->kernel_ir->rc); +rc_free_device (dev->kernel_ir->rc);kfree (dev->kernel_ir->phys);kfree (dev->kernel_ir->name);kfree (dev->kernel_ir);
drivers/media/pci/cx88/cx88-input.c +2 -1
@@ -510,8 +510,9 @@ int cx88_ir_fini(struct cx88_core *core)if (!ir)return 0 ; -cx88_ir_stop (core);rc_unregister_device (ir->dev); +cx88_ir_stop (core); +rc_free_device (ir->dev);kfree (ir);/* done */
drivers/media/pci/dm1105/dm1105.c +1 -0
@@ -763,6 +763,7 @@ static int dm1105_ir_init(struct dm1105_dev *dm1105)static void dm1105_ir_exit (struct dm1105_dev *dm1105) {rc_unregister_device (dm1105->ir.dev); +rc_free_device (dm1105->ir.dev); }static int dm1105_hw_init (struct dm1105_dev *dev)
drivers/media/pci/mantis/mantis_input.c +1 -0
@@ -72,5 +72,6 @@ EXPORT_SYMBOL_GPL(mantis_input_init);void mantis_input_exit (struct mantis_pci *mantis) {rc_unregister_device (mantis->rc); +rc_free_device (mantis->rc); }EXPORT_SYMBOL_GPL (mantis_input_exit);
drivers/media/pci/saa7134/saa7134-input.c +1 -0
@@ -834,6 +834,7 @@ void saa7134_input_fini(struct saa7134_dev *dev)return ;rc_unregister_device (dev->remote->dev); +rc_free_device (dev->remote->dev);kfree (dev->remote); dev->remote =NULL ; }
drivers/media/pci/smipcie/smipcie-ir.c +1 -0
@@ -181,5 +181,6 @@ void smi_ir_exit(struct smi_dev *dev)rc_unregister_device (rc_dev);smi_ir_stop (ir); +rc_free_device (rc_dev); ir->rc_dev =NULL ; }
drivers/media/pci/ttpci/budget-ci.c +1 -0
@@ -249,6 +249,7 @@ static void msp430_ir_deinit(struct budget_ci *budget_ci)cancel_work_sync (&budget_ci->ir.msp430_irq_bh_work);rc_unregister_device (budget_ci->ir.dev); +rc_free_device (budget_ci->ir.dev); }static int ciintf_read_attribute_mem (struct dvb_ca_en50221 *ca,int slot,int address)
drivers/media/rc/ati_remote.c +3 -3
@@ -921,7 +921,6 @@ static int ati_remote_probe(struct usb_interface *interface,input_free_device (input_dev); exit_unregister_device:rc_unregister_device (rc_dev); - rc_dev =NULL ; exit_kill_urbs:usb_kill_urb (ati_remote->irq_urb);usb_kill_urb (ati_remote->out_urb);
@@ -941,18 +940,19 @@ static void ati_remote_disconnect(struct usb_interface *interface)struct ati_remote *ati_remote; ati_remote =usb_get_intfdata (interface); -usb_set_intfdata (interface,NULL );if (!ati_remote) {dev_warn (&interface->dev,"%s - null device?\n" , __func__);return ; } +rc_unregister_device (ati_remote->rdev); +usb_set_intfdata (interface,NULL );usb_kill_urb (ati_remote->irq_urb);usb_kill_urb (ati_remote->out_urb);if (ati_remote->idev)input_unregister_device (ati_remote->idev); -rc_unregister_device (ati_remote->rdev);ati_remote_free_buffers (ati_remote); +rc_free_device (ati_remote->rdev);kfree (ati_remote); }
drivers/media/rc/ene_ir.c +1 -1
@@ -1090,7 +1090,6 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)release_region (dev->hw_io,ENE_IO_SIZE ); exit_unregister_device:rc_unregister_device (rdev); - rdev =NULL ; exit_free_dev_rdev:rc_free_device (rdev);kfree (dev);
@@ -1110,6 +1109,7 @@ static void ene_remove(struct pnp_dev *pnp_dev)ene_rx_restore_hw_buffer (dev);spin_unlock_irqrestore (&dev->hw_lock, flags); +rc_free_device (dev->rdev);free_irq (dev->irq, dev);release_region (dev->hw_io,ENE_IO_SIZE );kfree (dev);
drivers/media/rc/fintek-cir.c +2 -1
@@ -568,6 +568,7 @@ static void fintek_remove(struct pnp_dev *pdev)struct fintek_dev *fintek =pnp_get_drvdata (pdev);unsigned long flags; +rc_unregister_device (fintek->rdev);spin_lock_irqsave (&fintek->fintek_lock, flags);/* disable CIR */ fintek_disable_cir (fintek);
@@ -580,7 +581,7 @@ static void fintek_remove(struct pnp_dev *pdev)free_irq (fintek->cir_irq, fintek);release_region (fintek->cir_addr, fintek->cir_port_len); -rc_unregister_device (fintek->rdev); +rc_free_device (fintek->rdev);kfree (fintek); }
drivers/media/rc/igorplugusb.c +1 -0
@@ -247,6 +247,7 @@ static void igorplugusb_disconnect(struct usb_interface *intf)usb_set_intfdata (intf,NULL );usb_unpoison_urb (ir->urb);usb_free_urb (ir->urb); +rc_free_device (ir->rc);kfree (ir->buf_in);kfree (ir->request); }
drivers/media/rc/iguanair.c +1 -0
@@ -500,6 +500,7 @@ static void iguanair_disconnect(struct usb_interface *intf)usb_set_intfdata (intf,NULL );usb_kill_urb (ir->urb_in);usb_kill_urb (ir->urb_out); +rc_free_device (ir->rc);usb_free_urb (ir->urb_in);usb_free_urb (ir->urb_out);usb_free_coherent (ir->udev,MAX_IN_PACKET , ir->buf_in, ir->dma_in);
drivers/media/rc/img-ir/img-ir-hw.c +2 -1
@@ -1117,9 +1117,10 @@ void img_ir_remove_hw(struct img_ir_priv *priv)struct rc_dev *rdev = hw->rdev;if (!rdev)return ; +rc_unregister_device (rdev);img_ir_set_decoder (priv,NULL ,0 ); hw->rdev =NULL ; -rc_unregister_device (rdev); +rc_free_device (rdev);#ifdef CONFIG_COMMON_CLK if (!IS_ERR (priv->clk))clk_notifier_unregister (priv->clk, &hw->clk_nb);
drivers/media/rc/img-ir/img-ir-raw.c +2 -1
@@ -136,6 +136,7 @@ void img_ir_remove_raw(struct img_ir_priv *priv)if (!rdev)return ; +rc_unregister_device (rdev);/* switch off and disable raw (edge) interrupts */ spin_lock_irq (&priv->lock); raw->rdev =NULL ;
@@ -145,7 +146,7 @@ void img_ir_remove_raw(struct img_ir_priv *priv)img_ir_write (priv,IMG_IR_IRQ_CLEAR ,IMG_IR_IRQ_EDGE );spin_unlock_irq (&priv->lock); -rc_unregister_device (rdev); +rc_free_device (rdev);del_timer_sync (&raw->timer); }
drivers/media/rc/imon.c +2 -1
@@ -2546,9 +2546,10 @@ static void imon_disconnect(struct usb_interface *interface)if (ifnum ==0 ) { ictx->dev_present_intf0 = false; +rc_unregister_device (ictx->rdev);usb_kill_urb (ictx->rx_urb_intf0);input_unregister_device (ictx->idev); -rc_unregister_device (ictx->rdev); +rc_free_device (ictx->rdev);if (ictx->display_supported) {if (ictx->display_type ==IMON_DISPLAY_TYPE_LCD )usb_deregister_dev (interface, &imon_lcd_class);
drivers/media/rc/ir-hix5hd2.c +1 -1
@@ -331,7 +331,6 @@ static int hix5hd2_ir_probe(struct platform_device *pdev) regerr:rc_unregister_device (rdev); - rdev =NULL ; clkerr:clk_disable_unprepare (priv->clock); err:
@@ -346,6 +345,7 @@ static void hix5hd2_ir_remove(struct platform_device *pdev)clk_disable_unprepare (priv->clock);rc_unregister_device (priv->rdev); +rc_free_device (priv->rdev); }#ifdef CONFIG_PM_SLEEP
drivers/media/rc/ir_toy.c +1 -0
@@ -536,6 +536,7 @@ static void irtoy_disconnect(struct usb_interface *intf)usb_free_urb (ir->urb_out);usb_kill_urb (ir->urb_in);usb_free_urb (ir->urb_in); +rc_free_device (ir->rc);kfree (ir->in);kfree (ir->out);kfree (ir);
drivers/media/rc/ite-cir.c +1 -1
@@ -1414,7 +1414,6 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_idrelease_region (itdev->cir_addr, itdev->params->io_region_size); exit_unregister_device:rc_unregister_device (rdev); - rdev =NULL ; exit_free_dev_rdev:rc_free_device (rdev);kfree (itdev);
@@ -1439,6 +1438,7 @@ static void ite_remove(struct pnp_dev *pdev)release_region (dev->cir_addr, dev->params->io_region_size);rc_unregister_device (dev->rdev); +rc_free_device (dev->rdev);kfree (dev); }
drivers/media/rc/mceusb.c +1 -0
@@ -1851,6 +1851,7 @@ static void mceusb_dev_disconnect(struct usb_interface *intf)usb_free_urb (ir->urb_in);usb_free_coherent (dev, ir->len_in, ir->buf_in, ir->dma_in);usb_put_dev (dev); +rc_free_device (ir->rc);kfree (ir); }
drivers/media/rc/rc-ir-raw.c +0 -5
@@ -647,9 +647,6 @@ int ir_raw_event_register(struct rc_dev *dev)void ir_raw_event_free (struct rc_dev *dev) { -if (!dev) -return ; -kfree (dev->raw); dev->raw =NULL ; }
@@ -673,8 +670,6 @@ void ir_raw_event_unregister(struct rc_dev *dev)lirc_bpf_free (dev); -ir_raw_event_free (dev); -/* * A user can be calling bpf(BPF_PROG_{QUERY|ATTACH|DETACH}), so * ensure that the raw member is null on unlock; this is how
drivers/media/rc/rc-loopback.c +1 -0
@@ -263,6 +263,7 @@ static int __init loop_init(void) static void __exit loop_exit(void) {rc_unregister_device (loopdev.dev); +rc_free_device (loopdev.dev); }module_init (loop_init);
drivers/media/rc/rc-main.c +1 -5
@@ -1611,6 +1611,7 @@ static void rc_dev_release(struct device *device) {struct rc_dev *dev =to_rc_dev (device); +ir_raw_event_free (dev);kfree (dev); }
@@ -1773,7 +1774,6 @@ struct rc_dev *devm_rc_allocate_device(struct device *dev, } rc->dev.parent = dev; - rc->managed_alloc = true; *dr = rc;devres_add (dev, dr);
@@ -2042,11 +2042,7 @@ void rc_unregister_device(struct rc_dev *dev)device_del (&dev->dev);ida_free (&rc_ida, dev->minor); - -if (!dev->managed_alloc) -rc_free_device (dev); } -EXPORT_SYMBOL_GPL (rc_unregister_device);/*
drivers/media/rc/redrat3.c +3 -1
@@ -1133,11 +1133,13 @@ static void redrat3_dev_disconnect(struct usb_interface *intf) {struct usb_device *udev =interface_to_usbdev (intf);struct redrat3_dev *rr3 =usb_get_intfdata (intf); +struct rc_dev *rc = rr3->rc;usb_set_intfdata (intf,NULL ); -rc_unregister_device (rr3->rc); +rc_unregister_device (rc);led_classdev_unregister (&rr3->led);redrat3_delete (rr3, udev); +rc_free_device (rc); }static int redrat3_dev_suspend (struct usb_interface *intf,pm_message_t message)
drivers/media/rc/st_rc.c +1 -1
@@ -203,6 +203,7 @@ static void st_rc_remove(struct platform_device *pdev)device_init_wakeup (&pdev->dev, false);clk_disable_unprepare (rc_dev->sys_clock);rc_unregister_device (rc_dev->rdev); +rc_free_device (rc_dev->rdev); }static int st_rc_open (struct rc_dev *rdev)
@@ -334,7 +335,6 @@ static int st_rc_probe(struct platform_device *pdev)return ret; rcerr:rc_unregister_device (rdev); - rdev =NULL ; clkerr:clk_disable_unprepare (rc_dev->sys_clock); err:
drivers/media/rc/streamzap.c +4 -3
@@ -392,15 +392,16 @@ static void streamzap_disconnect(struct usb_interface *interface)struct streamzap_ir *sz =usb_get_intfdata (interface);struct usb_device *usbdev =interface_to_usbdev (interface); -usb_set_intfdata (interface,NULL ); -if (!sz)return ; -usb_kill_urb (sz->urb_in);rc_unregister_device (sz->rdev); +usb_set_intfdata (interface,NULL ); + +usb_kill_urb (sz->urb_in);usb_free_urb (sz->urb_in);usb_free_coherent (usbdev, sz->buf_in_len, sz->buf_in, sz->dma_in); +rc_free_device (sz->rdev);kfree (sz); }
drivers/media/rc/sunxi-cir.c +1 -0
@@ -371,6 +371,7 @@ static void sunxi_ir_remove(struct platform_device *pdev)struct sunxi_ir *ir =platform_get_drvdata (pdev);rc_unregister_device (ir->rc); +rc_free_device (ir->rc);sunxi_ir_hw_exit (&pdev->dev); }
drivers/media/rc/ttusbir.c +1 -1
@@ -336,7 +336,6 @@ static int ttusbir_probe(struct usb_interface *intf,return 0 ; out3:rc_unregister_device (rc); - rc =NULL ; out2:led_classdev_unregister (&tt->led); out:
@@ -378,6 +377,7 @@ static void ttusbir_disconnect(struct usb_interface *intf)usb_kill_urb (tt->bulk_urb);usb_free_urb (tt->bulk_urb);kfree (tt->bulk_buffer); +rc_free_device (tt->rc);usb_set_intfdata (intf,NULL );kfree (tt); }
drivers/media/rc/winbond-cir.c +1 -1
@@ -1132,7 +1132,6 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)release_region (data->wbase,WAKEUP_IOMEM_LEN ); exit_unregister_device:rc_unregister_device (data->dev); - data->dev =NULL ; exit_free_rc:rc_free_device (data->dev); exit_unregister_led:
@@ -1163,6 +1162,7 @@ wbcir_remove(struct pnp_dev *device)wbcir_set_bits (data->wbase +WBCIR_REG_WCEIR_EV_EN ,0x00 ,0x07 );rc_unregister_device (data->dev); +rc_free_device (data->dev);led_classdev_unregister (&data->led);
drivers/media/rc/xbox_remote.c +3 -2
@@ -283,14 +283,15 @@ static void xbox_remote_disconnect(struct usb_interface *interface)struct xbox_remote *xbox_remote; xbox_remote =usb_get_intfdata (interface); -usb_set_intfdata (interface,NULL );if (!xbox_remote) {dev_warn (&interface->dev,"%s - null device?\n" , __func__);return ; } -usb_kill_urb (xbox_remote->irq_urb);rc_unregister_device (xbox_remote->rdev); +usb_set_intfdata (interface,NULL ); +usb_kill_urb (xbox_remote->irq_urb); +rc_free_device (xbox_remote->rdev);usb_free_urb (xbox_remote->irq_urb);kfree (xbox_remote->inbuf);kfree (xbox_remote);
drivers/media/usb/au0828/au0828-input.c +1 -0
@@ -357,6 +357,7 @@ void au0828_rc_unregister(struct au0828_dev *dev)return ;rc_unregister_device (ir->rc); +rc_free_device (ir->rc);/* done */ kfree (ir);
drivers/media/usb/dvb-usb-v2/dvb_usb_core.c +1 -0
@@ -187,6 +187,7 @@ static int dvb_usbv2_remote_exit(struct dvb_usb_device *d)if (d->rc_dev) {cancel_delayed_work_sync (&d->rc_query_work);rc_unregister_device (d->rc_dev); +rc_free_device (d->rc_dev); d->rc_dev =NULL ; }
drivers/media/usb/dvb-usb/dvb-usb-remote.c +4 -2
@@ -347,10 +347,12 @@ int dvb_usb_remote_exit(struct dvb_usb_device *d) {if (d->state &DVB_USB_STATE_REMOTE ) {cancel_delayed_work_sync (&d->rc_query_work); -if (d->props.rc.mode ==DVB_RC_LEGACY ) +if (d->props.rc.mode ==DVB_RC_LEGACY ) {input_unregister_device (d->input_dev); -else + }else {rc_unregister_device (d->rc_dev); +rc_free_device (d->rc_dev); + } } d->state &= ~DVB_USB_STATE_REMOTE ;return 0 ;
drivers/media/usb/em28xx/em28xx-input.c +1 -0
@@ -853,6 +853,7 @@ static int em28xx_ir_fini(struct em28xx *dev) goto ref_put;rc_unregister_device (ir->rc); +rc_free_device (ir->rc);kfree (ir->i2c_client);
drivers/staging/media/av7110/av7110_ir.c +1 -0
@@ -151,6 +151,7 @@ int av7110_ir_init(struct av7110 *av7110)void av7110_ir_exit (struct av7110 *av7110) {rc_unregister_device (av7110->ir.rcdev); +rc_free_device (av7110->ir.rcdev); }//MODULE_AUTHOR("Holger Waechtler <[email protected]>, Oliver Endriss <[email protected]>");
include/media/rc-core.h +0 -2
@@ -81,7 +81,6 @@ struct lirc_fh {/** * struct rc_dev - represents a remote control device * @dev: driver model's view of this device -* @managed_alloc: devm_rc_allocate_device was used to create rc_dev * @sysfs_groups: sysfs attribute groups * @device_name: name of the rc child device * @input_phys: physical path to the input child device
@@ -156,7 +155,6 @@ struct lirc_fh {*/ struct rc_dev {struct device dev; -bool managed_alloc;const struct attribute_group *sysfs_groups[5 ];const char *device_name;const char *input_phys;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 111/307 media: rc: ttusbir: fix inverted error logic
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
[ Upstream commit 646ebdd3105809d84ed04aa9e92e47e89cc44502 ]
We have to report ENOMEM if no buffer is allocated. Typo dropped a "!". Restore it.
--- drivers/media/rc/ttusbir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/ttusbir.c +1 -1
@@ -191,7 +191,7 @@ static int ttusbir_probe(struct usb_interface *intf, tt =kzalloc (sizeof (*tt),GFP_KERNEL ); buffer =kzalloc (5 ,GFP_KERNEL ); rc =rc_allocate_device (RC_DRIVER_IR_RAW ); -if (!tt || !rc || buffer) { +if (!tt || !rc || !buffer) { ret = -ENOMEM ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 112/307 inet: frags: add inet_frag_queue_flush()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 1231eec6994be29d6bb5c303dfa54731ed9fc0e6 ]
Instead of exporting inet_frag_rbtree_purge() which requires that caller takes care of memory accounting, add a new helper. We will need to call it from a few places in the next patch.
--- include/net/inet_frag.h | 5 ++--- net/ipv4/inet_fragment.c | 15 ++++++++++++--- net/ipv4/ip_fragment.c | 6 +----- 3 files changed, 15 insertions(+), 11 deletions(-)
include/net/inet_frag.h +2 -3
@@ -141,9 +141,8 @@ void inet_frag_kill(struct inet_frag_queue *q);void inet_frag_destroy (struct inet_frag_queue *q);struct inet_frag_queue *inet_frag_find (struct fqdir *fqdir,void *key); -/* Free all skbs in the queue; return the sum of their truesizes. */ -unsigned int inet_frag_rbtree_purge (struct rb_root *root, -enum skb_drop_reason reason); +void inet_frag_queue_flush (struct inet_frag_queue *q, +enum skb_drop_reason reason);static inline void inet_frag_put (struct inet_frag_queue *q) {
net/ipv4/inet_fragment.c +12 -3
@@ -264,8 +264,8 @@ static void inet_frag_destroy_rcu(struct rcu_head *head)kmem_cache_free (f->frags_cachep, q); } -unsigned int inet_frag_rbtree_purge (struct rb_root *root, -enum skb_drop_reason reason) +static unsigned int +inet_frag_rbtree_purge (struct rb_root *root,enum skb_drop_reason reason) {struct rb_node *p =rb_first (root);unsigned int sum =0 ;
@@ -285,7 +285,16 @@ unsigned int inet_frag_rbtree_purge(struct rb_root *root, }return sum; } -EXPORT_SYMBOL (inet_frag_rbtree_purge); + +void inet_frag_queue_flush (struct inet_frag_queue *q, +enum skb_drop_reason reason) +{ +unsigned int sum; + + sum =inet_frag_rbtree_purge (&q->rb_fragments, reason); +sub_frag_mem_limit (q->fqdir, sum); +} +EXPORT_SYMBOL (inet_frag_queue_flush);void inet_frag_destroy (struct inet_frag_queue *q) {
net/ipv4/ip_fragment.c +1 -5
@@ -253,16 +253,12 @@ static int ip_frag_too_far(struct ipq *qp)static int ip_frag_reinit (struct ipq *qp) { -unsigned int sum_truesize =0 ; -if (!mod_timer (&qp->q.timer, jiffies + qp->q.fqdir->timeout)) {refcount_inc (&qp->q.refcnt);return -ETIMEDOUT ; } - sum_truesize =inet_frag_rbtree_purge (&qp->q.rb_fragments, -SKB_DROP_REASON_FRAG_TOO_FAR ); -sub_frag_mem_limit (qp->q.fqdir, sum_truesize); +inet_frag_queue_flush (&qp->q,SKB_DROP_REASON_FRAG_TOO_FAR ); qp->q.flags =0 ; qp->q.len =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 113/307 inet: frags: flush pending skbs in fqdir_pre_exit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 006a5035b495dec008805df249f92c22c89c3d2e ]
We have been seeing occasional deadlocks on pernet_ops_rwsem since September in NIPA. The stuck task was usually modprobe (often loading a driver like ipvlan), trying to take the lock as a Writer. lockdep does not track readers for rwsems so the read wasn't obvious from the reports.
On closer inspection the Reader holding the lock was conntrack looping forever in nf_conntrack_cleanup_net_list(). Based on past experience with occasional NIPA crashes I looked thru the tests which run before the crash and noticed that the crash follows ip_defrag.sh. An immediate red flag. Scouring thru (de)fragmentation queues reveals skbs sitting around, holding conntrack references.
The problem is that since conntrack depends on nf_defrag_ipv6, nf_defrag_ipv6 will load first. Since nf_defrag_ipv6 loads first its netns exit hooks run _after_ conntrack's netns exit hook.
Flush all fragment queue SKBs during fqdir_pre_exit() to release conntrack references before conntrack cleanup runs. Also flush the queues in timer expiry handlers when they discover fqdir->dead is set, in case packet sneaks in while we're running the pre_exit flush.
The commit under Fixes is not exactly the culprit, but I think previously the timer firing would eventually unblock the spinning conntrack.
--- include/net/inet_frag.h | 13 +------------ include/net/ipv6_frag.h | 9 ++++++--- net/ipv4/inet_fragment.c | 36 ++++++++++++++++++++++++++++++++++++ net/ipv4/ip_fragment.c | 12 +++++++----- 4 files changed, 50 insertions(+), 20 deletions(-)
include/net/inet_frag.h +1 -12
@@ -123,18 +123,7 @@ void inet_frags_fini(struct inet_frags *);int fqdir_init (struct fqdir **fqdirp,struct inet_frags *f,struct net *net); -static inline void fqdir_pre_exit (struct fqdir *fqdir) -{ -/* Prevent creation of new frags. -* Pairs with READ_ONCE() in inet_frag_find(). -*/ -WRITE_ONCE (fqdir->high_thresh,0 ); - -/* Pairs with READ_ONCE() in inet_frag_kill(), ip_expire() -* and ip6frag_expire_frag_queue(). -*/ -WRITE_ONCE (fqdir->dead, true); -} +void fqdir_pre_exit (struct fqdir *fqdir);void fqdir_exit (struct fqdir *fqdir);void inet_frag_kill (struct inet_frag_queue *q);
include/net/ipv6_frag.h +6 -3
@@ -68,9 +68,6 @@ ip6frag_expire_frag_queue(struct net *net, struct frag_queue *fq)struct sk_buff *head;rcu_read_lock (); -/* Paired with the WRITE_ONCE() in fqdir_pre_exit(). */ -if (READ_ONCE (fq->q.fqdir->dead)) - goto out_rcu_unlock;spin_lock (&fq->q.lock);if (fq->q.flags &INET_FRAG_COMPLETE )
@@ -79,6 +76,12 @@ ip6frag_expire_frag_queue(struct net *net, struct frag_queue *fq) fq->q.flags |=INET_FRAG_DROP ;inet_frag_kill (&fq->q); +/* Paired with the WRITE_ONCE() in fqdir_pre_exit(). */ +if (READ_ONCE (fq->q.fqdir->dead)) { +inet_frag_queue_flush (&fq->q,0 ); + goto out; + } + dev =dev_get_by_index_rcu (net, fq->iif);if (!dev) goto out;
net/ipv4/inet_fragment.c +36 -0
@@ -219,6 +219,41 @@ static int __init inet_frag_wq_init(void)pure_initcall (inet_frag_wq_init); +void fqdir_pre_exit (struct fqdir *fqdir) +{ +struct inet_frag_queue *fq; +struct rhashtable_iter hti; + +/* Prevent creation of new frags. +* Pairs with READ_ONCE() in inet_frag_find(). +*/ +WRITE_ONCE (fqdir->high_thresh,0 ); + +/* Pairs with READ_ONCE() in inet_frag_kill(), ip_expire() +* and ip6frag_expire_frag_queue(). +*/ +WRITE_ONCE (fqdir->dead, true); + +rhashtable_walk_enter (&fqdir->rhashtable, &hti); +rhashtable_walk_start (&hti); + +while ((fq =rhashtable_walk_next (&hti))) { +if (IS_ERR (fq)) { +if (PTR_ERR (fq) != -EAGAIN ) +break ; +continue ; + } +spin_lock_bh (&fq->lock); +if (!(fq->flags &INET_FRAG_COMPLETE )) +inet_frag_queue_flush (fq,0 ); +spin_unlock_bh (&fq->lock); + } + +rhashtable_walk_stop (&hti); +rhashtable_walk_exit (&hti); +} +EXPORT_SYMBOL (fqdir_pre_exit); +void fqdir_exit (struct fqdir *fqdir) {INIT_WORK (&fqdir->destroy_work, fqdir_work_fn);
@@ -291,6 +326,7 @@ void inet_frag_queue_flush(struct inet_frag_queue *q, {unsigned int sum; + reason = reason ?:SKB_DROP_REASON_FRAG_REASM_TIMEOUT ; sum =inet_frag_rbtree_purge (&q->rb_fragments, reason);sub_frag_mem_limit (q->fqdir, sum); }
net/ipv4/ip_fragment.c +7 -5
@@ -148,11 +148,6 @@ static void ip_expire(struct timer_list *t) net = qp->q.fqdir->net;rcu_read_lock (); - -/* Paired with WRITE_ONCE() in fqdir_pre_exit(). */ -if (READ_ONCE (qp->q.fqdir->dead)) - goto out_rcu_unlock; -spin_lock (&qp->q.lock);if (qp->q.flags &INET_FRAG_COMPLETE )
@@ -160,6 +155,13 @@ static void ip_expire(struct timer_list *t) qp->q.flags |=INET_FRAG_DROP ;ipq_kill (qp); + +/* Paired with WRITE_ONCE() in fqdir_pre_exit(). */ +if (READ_ONCE (qp->q.fqdir->dead)) { +inet_frag_queue_flush (&qp->q,0 ); + goto out; + } +__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS );__IP_INC_STATS (net,IPSTATS_MIB_REASMTIMEOUT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 114/307 HID: core: Add printk_ratelimited variants to hid_warn() etc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vicki Pfau <[email protected]>
[ Upstream commit 1d64624243af8329b4b219d8c39e28ea448f9929 ]
hid_warn_ratelimited() is needed. Add the others as part of the block.
--- include/linux/hid.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/linux/hid.h +11 -0
@@ -1245,4 +1245,15 @@ void hid_quirks_exit(__u16 bus);#define hid_dbg_once (hid, fmt, ...) \ dev_dbg_once(&(hid)->dev, fmt, ##__VA_ARGS__) +#define hid_err_ratelimited (hid, fmt, ...) \ + dev_err_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__) +#define hid_notice_ratelimited (hid, fmt, ...) \ + dev_notice_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__) +#define hid_warn_ratelimited (hid, fmt, ...) \ + dev_warn_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__) +#define hid_info_ratelimited (hid, fmt, ...) \ + dev_info_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__) +#define hid_dbg_ratelimited (hid, fmt, ...) \ + dev_dbg_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__) +#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 115/307 HID: pass the buffer size to hid_report_raw_event
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Tissoires <[email protected]>
[ Upstream commit 2c85c61d1332e1e16f020d76951baf167dcb6f7a ]
commit 0a3fe972a7cb ("HID: core: Mitigate potential OOB by removing bogus memset()") enforced the provided data to be at least the size of the declared buffer in the report descriptor to prevent a buffer overflow. However, we can try to be smarter by providing both the buffer size and the data size, meaning that hid_report_raw_event() can make better decision whether we should plaining reject the buffer (buffer overflow attempt) or if we can safely memset it to 0 and pass it to the rest of the stack.
Stable-dep-of: 206342541fc8 ("HID: core: introduce hid_safe_input_report()")
--- drivers/hid/bpf/hid_bpf_dispatch.c | 6 +++-- drivers/hid/hid-core.c | 37 +++++++++++++++++++++--------- drivers/hid/hid-gfrm.c | 4 ++-- drivers/hid/hid-logitech-hidpp.c | 2 +- drivers/hid/hid-multitouch.c | 2 +- drivers/hid/hid-primax.c | 2 +- drivers/hid/hid-vivaldi-common.c | 2 +- drivers/hid/wacom_sys.c | 6 ++--- drivers/staging/greybus/hid.c | 2 +- include/linux/hid.h | 4 ++-- include/linux/hid_bpf.h | 14 +++++++---- 11 files changed, 51 insertions(+), 30 deletions(-)
drivers/hid/bpf/hid_bpf_dispatch.c +4 -2
@@ -24,7 +24,8 @@ EXPORT_SYMBOL(hid_ops);u8 *dispatch_hid_bpf_device_event (struct hid_device *hdev,enum hid_report_type type,u8 *data, -u32 *size,int interrupt,u64 source,bool from_bpf) +size_t *buf_size,u32 *size,int interrupt,u64 source, +bool from_bpf) {struct hid_bpf_ctx_kern ctx_kern = { .ctx = {
@@ -74,6 +75,7 @@ dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type *size = ret; } + *buf_size = ctx_kern.ctx.allocated_size;return ctx_kern.data; }EXPORT_SYMBOL_GPL (dispatch_hid_bpf_device_event);
@@ -514,7 +516,7 @@ __hid_bpf_input_report(struct hid_bpf_ctx *ctx, enum hid_report_type type, u8 *bif (ret)return ret; -return hid_ops->hid_input_report (ctx->hid, type, buf, size,0 , (u64 )(long )ctx, true, +return hid_ops->hid_input_report (ctx->hid, type, buf, size, size,0 , (u64 )(long )ctx, true, lock_already_taken); }
drivers/hid/hid-core.c +26 -11
@@ -1998,24 +1998,32 @@ int __hid_request(struct hid_device *hid, struct hid_report *report, }EXPORT_SYMBOL_GPL (__hid_request); -int hid_report_raw_event (struct hid_device *hid,enum hid_report_type type,u8 *data,u32 size, -int interrupt) +int hid_report_raw_event (struct hid_device *hid,enum hid_report_type type,u8 *data, +size_t bufsize,u32 size,int interrupt) {struct hid_report_enum *report_enum = hid->report_enum + type;struct hid_report *report;struct hid_driver *hdrv;int max_buffer_size =HID_MAX_BUFFER_SIZE ;u32 rsize, csize = size; +size_t bsize = bufsize;u8 *cdata = data;int ret =0 ; report =hid_get_report (report_enum, data);if (!report) - goto out; +return 0 ; + +if (unlikely (bsize < csize)) { +hid_warn_ratelimited (hid,"Event data for report %d is incorrect (%d vs %ld)\n" , + report->id, csize, bsize); +return -EINVAL ; + }if (report_enum->numbered) { cdata++; csize--; + bsize--; } rsize =hid_compute_report_size (report);
@@ -2028,9 +2036,15 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *else if (rsize > max_buffer_size) rsize = max_buffer_size; +if (bsize < rsize) { +hid_warn_ratelimited (hid,"Event data for report %d was too short (%d vs %ld)\n" , + report->id, rsize, bsize); +return -EINVAL ; + } +if (csize < rsize) {dbg_hid ("report %d is too short, (%d < %d)\n" , report->id, - csize, rsize); + csize, rsize);memset (cdata + csize,0 , rsize - csize); }
@@ -2039,7 +2053,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *if (hid->claimed &HID_CLAIMED_HIDRAW ) { ret =hidraw_report_event (hid, data, size);if (ret) - goto out; +return ret; }if (hid->claimed !=HID_CLAIMED_HIDRAW && report->maxfield) {
@@ -2051,15 +2065,15 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *if (hid->claimed &HID_CLAIMED_INPUT )hidinput_report_event (hid, report); -out: +return ret; }EXPORT_SYMBOL_GPL (hid_report_raw_event);static int __hid_input_report (struct hid_device *hid,enum hid_report_type type, -u8 *data,u32 size,int interrupt,u64 source,bool from_bpf, -bool lock_already_taken) +u8 *data,size_t bufsize,u32 size,int interrupt,u64 source, +bool from_bpf,bool lock_already_taken) {struct hid_report_enum *report_enum;struct hid_driver *hdrv;
@@ -2084,7 +2098,8 @@ static int __hid_input_report(struct hid_device *hid, enum hid_report_type type, report_enum = hid->report_enum + type; hdrv = hid->driver; - data =dispatch_hid_bpf_device_event (hid, type, data, &size, interrupt, source, from_bpf); + data =dispatch_hid_bpf_device_event (hid, type, data, &bufsize, &size, interrupt, + source, from_bpf);if (IS_ERR (data)) { ret =PTR_ERR (data); goto unlock;
@@ -2113,7 +2128,7 @@ static int __hid_input_report(struct hid_device *hid, enum hid_report_type type, goto unlock; } - ret =hid_report_raw_event (hid, type, data, size, interrupt); + ret =hid_report_raw_event (hid, type, data, bufsize, size, interrupt); unlock:if (!lock_already_taken)
@@ -2135,7 +2150,7 @@ static int __hid_input_report(struct hid_device *hid, enum hid_report_type type,int hid_input_report (struct hid_device *hid,enum hid_report_type type,u8 *data,u32 size,int interrupt) { -return __hid_input_report (hid, type, data, size, interrupt,0 , +return __hid_input_report (hid, type, data, size, size, interrupt,0 , false,/* from_bpf */ false/* lock_already_taken */ ); }
drivers/hid/hid-gfrm.c +2 -2
@@ -66,7 +66,7 @@ static int gfrm_raw_event(struct hid_device *hdev, struct hid_report *report,switch (data[1 ]) {case GFRM100_SEARCH_KEY_DOWN : ret =hid_report_raw_event (hdev,HID_INPUT_REPORT , search_key_dn, -sizeof (search_key_dn),1 ); +sizeof (search_key_dn),sizeof (search_key_dn),1 );break ;case GFRM100_SEARCH_KEY_AUDIO_DATA :
@@ -74,7 +74,7 @@ static int gfrm_raw_event(struct hid_device *hdev, struct hid_report *report,case GFRM100_SEARCH_KEY_UP : ret =hid_report_raw_event (hdev,HID_INPUT_REPORT , search_key_up, -sizeof (search_key_up),1 ); +sizeof (search_key_up),sizeof (search_key_up),1 );break ;default :
drivers/hid/hid-logitech-hidpp.c +1 -1
@@ -3691,7 +3691,7 @@ static int hidpp10_consumer_keys_raw_event(struct hidpp_device *hidpp,memcpy (&consumer_report[1 ], &data[3 ],4 );/* We are called from atomic context */ hid_report_raw_event (hidpp->hid_dev,HID_INPUT_REPORT , - consumer_report,5 ,1 ); + consumer_report,sizeof (consumer_report),5 ,1 );return 1 ; }
drivers/hid/hid-multitouch.c +1 -1
@@ -500,7 +500,7 @@ static void mt_get_feature(struct hid_device *hdev, struct hid_report *report) } ret =hid_report_raw_event (hdev,HID_FEATURE_REPORT , buf, - size,0 ); + size, size,0 );if (ret)dev_warn (&hdev->dev,"failed to report feature\n" ); }
drivers/hid/hid-primax.c +1 -1
@@ -44,7 +44,7 @@ static int px_raw_event(struct hid_device *hid, struct hid_report *report, data[0 ] |= (1 << (data[idx] -0xE0 )); data[idx] =0 ; } -hid_report_raw_event (hid,HID_INPUT_REPORT , data, size,0 ); +hid_report_raw_event (hid,HID_INPUT_REPORT , data, size, size,0 );return 1 ;default :/* unknown report */
drivers/hid/hid-vivaldi-common.c +1 -1
@@ -85,7 +85,7 @@ void vivaldi_feature_mapping(struct hid_device *hdev, } ret =hid_report_raw_event (hdev,HID_FEATURE_REPORT , report_data, - report_len,0 ); + report_len, report_len,0 );if (ret) {dev_warn (&hdev->dev,"failed to report feature %d\n" , field->report->id);
drivers/hid/wacom_sys.c +3 -3
@@ -74,7 +74,7 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,int err; size =kfifo_out (fifo, buf,sizeof (buf)); - err =hid_report_raw_event (hdev,HID_INPUT_REPORT , buf, size, false); + err =hid_report_raw_event (hdev,HID_INPUT_REPORT , buf, size, size, false);if (err) {hid_warn (hdev,"%s: unable to flush event due to error %d\n" , __func__, err);
@@ -319,7 +319,7 @@ static void wacom_feature_mapping(struct hid_device *hdev, data, n, WAC_CMD_RETRIES);if (ret == n && features->type ==HID_GENERIC ) { ret =hid_report_raw_event (hdev, -HID_FEATURE_REPORT , data, n,0 ); +HID_FEATURE_REPORT , data, n, n,0 ); }else if (ret ==2 && features->type !=HID_GENERIC ) { features->touch_max = data[1 ]; }else {
@@ -380,7 +380,7 @@ static void wacom_feature_mapping(struct hid_device *hdev, data, n, WAC_CMD_RETRIES);if (ret == n) { ret =hid_report_raw_event (hdev,HID_FEATURE_REPORT , - data, n,0 ); + data, n, n,0 ); }else {hid_warn (hdev,"%s: could not retrieve sensor offsets\n" , __func__);
drivers/staging/greybus/hid.c +1 -1
@@ -201,7 +201,7 @@ static void gb_hid_init_report(struct gb_hid *ghid, struct hid_report *report)* we just need to setup the input fields, so using * hid_report_raw_event is safe. */ -hid_report_raw_event (ghid->hid, report->type, ghid->inbuf, size,1 ); +hid_report_raw_event (ghid->hid, report->type, ghid->inbuf, ghid->bufsize, size,1 ); }static void gb_hid_init_reports (struct gb_hid *ghid)
include/linux/hid.h +2 -2
@@ -1213,8 +1213,8 @@ static inline u32 hid_report_len(struct hid_report *report)return DIV_ROUND_UP (report->size,8 ) + (report->id >0 ); } -int hid_report_raw_event (struct hid_device *hid,enum hid_report_type type,u8 *data,u32 size, -int interrupt); +int hid_report_raw_event (struct hid_device *hid,enum hid_report_type type,u8 *data, +size_t bufsize,u32 size,int interrupt);/* HID quirks API */ unsigned long hid_lookup_quirk (const struct hid_device *hdev);
include/linux/hid_bpf.h +9 -5
@@ -72,8 +72,8 @@ struct hid_ops {int (*hid_hw_output_report)(struct hid_device *hdev,__u8 *buf,size_t len,u64 source,bool from_bpf);int (*hid_input_report)(struct hid_device *hid,enum hid_report_type type, -u8 *data,u32 size,int interrupt,u64 source,bool from_bpf, -bool lock_already_taken); +u8 *data,size_t bufsize,u32 size,int interrupt,u64 source, +bool from_bpf,bool lock_already_taken);struct module *owner;const struct bus_type *bus_type; };
@@ -200,7 +200,8 @@ struct hid_bpf {#ifdef CONFIG_HID_BPF u8 *dispatch_hid_bpf_device_event (struct hid_device *hid,enum hid_report_type type,u8 *data, -u32 *size,int interrupt,u64 source,bool from_bpf); +size_t *buf_size,u32 *size,int interrupt,u64 source, +bool from_bpf); int dispatch_hid_bpf_raw_requests(struct hid_device *hdev, unsigned char reportnum, __u8 *buf, u32 size, enum hid_report_type rtype,
@@ -215,8 +216,11 @@ int hid_bpf_device_init(struct hid_device *hid);u8 *call_hid_bpf_rdesc_fixup (struct hid_device *hdev,const u8 *rdesc,unsigned int *size);#else /* CONFIG_HID_BPF */ static inline u8 *dispatch_hid_bpf_device_event (struct hid_device *hid,enum hid_report_type type, -u8 *data,u32 *size,int interrupt, -u64 source,bool from_bpf) {return data; } +u8 *data,size_t *buf_size,u32 *size, +int interrupt,u64 source,bool from_bpf) +{ +return data; +} static inline int dispatch_hid_bpf_raw_requests(struct hid_device *hdev, unsigned char reportnum, u8 *buf, u32 size, enum hid_report_type rtype,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 116/307 HID: core: introduce hid_safe_input_report()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Tissoires <[email protected]>
[ Upstream commit 206342541fc887ae919774a43942dc883161fece ]
hid_input_report() is used in too many places to have a commit that doesn't cross subsystem borders. Instead of changing the API, introduce a new one when things matters in the transport layers:
- usbhid
- i2chid
This effectively revert to the old behavior for those two transport layers.
--- drivers/hid/hid-core.c | 25 +++++++++++++++++++++++++ drivers/hid/i2c-hid/i2c-hid-core.c | 7 ++++--- drivers/hid/usbhid/hid-core.c | 11 ++++++----- include/linux/hid.h | 2 ++ 4 files changed, 37 insertions(+), 8 deletions(-)
drivers/hid/hid-core.c +25 -0
@@ -2146,6 +2146,7 @@ static int __hid_input_report(struct hid_device *hid, enum hid_report_type type,* @interrupt: distinguish between interrupt and control transfers * * This is data entry for lower layers. +* Legacy, please use hid_safe_input_report() instead. */ int hid_input_report (struct hid_device *hid,enum hid_report_type type,u8 *data,u32 size,int interrupt)
@@ -2156,6 +2157,30 @@ int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data }EXPORT_SYMBOL_GPL (hid_input_report); +/** +* hid_safe_input_report - report data from lower layer (usb, bt...) +* +* @hid: hid device +* @type: HID report type (HID_*_REPORT) +* @data: report contents +* @bufsize: allocated size of the data buffer +* @size: useful size of data parameter +* @interrupt: distinguish between interrupt and control transfers +* +* This is data entry for lower layers. +* Please use this function instead of the non safe version because we provide +* here the size of the buffer, allowing hid-core to make smarter decisions +* regarding the incoming buffer. +*/ +int hid_safe_input_report (struct hid_device *hid,enum hid_report_type type,u8 *data, +size_t bufsize,u32 size,int interrupt) +{ +return __hid_input_report (hid, type, data, bufsize, size, interrupt,0 , + false,/* from_bpf */ + false/* lock_already_taken */ ); +} +EXPORT_SYMBOL_GPL (hid_safe_input_report); +bool hid_match_one_id (const struct hid_device *hdev,const struct hid_device_id *id) {
drivers/hid/i2c-hid/i2c-hid-core.c +4 -3
@@ -568,9 +568,10 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)if (ihid->hid->group !=HID_GROUP_RMI )pm_wakeup_event (&ihid->client->dev,0 ); -hid_input_report (ihid->hid,HID_INPUT_REPORT , - ihid->inbuf +sizeof (__le16), - ret_size -sizeof (__le16),1 ); +hid_safe_input_report (ihid->hid,HID_INPUT_REPORT , + ihid->inbuf +sizeof (__le16), + ihid->bufsize -sizeof (__le16), + ret_size -sizeof (__le16),1 ); }return ;
drivers/hid/usbhid/hid-core.c +6 -5
@@ -283,9 +283,9 @@ static void hid_irq_in(struct urb *urb)break ;usbhid_mark_busy (usbhid);if (!test_bit (HID_RESUME_RUNNING , &usbhid->iofl)) { -hid_input_report (urb->context,HID_INPUT_REPORT , - urb->transfer_buffer, - urb->actual_length,1 ); +hid_safe_input_report (urb->context,HID_INPUT_REPORT , + urb->transfer_buffer, urb->transfer_buffer_length, + urb->actual_length,1 );/* * autosuspend refused while keys are pressed * because most keyboards don't wake up when
@@ -482,9 +482,10 @@ static void hid_ctrl(struct urb *urb)switch (status) {case 0 :/* success */ if (usbhid->ctrl[usbhid->ctrltail].dir ==USB_DIR_IN ) -hid_input_report (urb->context, +hid_safe_input_report (urb->context, usbhid->ctrl[usbhid->ctrltail].report->type, - urb->transfer_buffer, urb->actual_length,0 ); + urb->transfer_buffer, urb->transfer_buffer_length, + urb->actual_length,0 );break ;case -ESHUTDOWN :/* unplug */ unplug =1 ;
include/linux/hid.h +2 -0
@@ -949,6 +949,8 @@ struct hid_field *hid_find_field(struct hid_device *hdev, unsigned int report_tyint hid_set_field (struct hid_field *,unsigned ,__s32 );int hid_input_report (struct hid_device *hid,enum hid_report_type type,u8 *data,u32 size,int interrupt); +int hid_safe_input_report (struct hid_device *hid,enum hid_report_type type,u8 *data, +size_t bufsize,u32 size,int interrupt);struct hid_field *hidinput_get_led_field (struct hid_device *hid);unsigned int hidinput_count_leds (struct hid_device *hid);__s32 hidinput_calc_abs_res (const struct hid_field *field,__u16 code);
Signature · 11 lines
2.53.0 pu, ZCR_EL2, p->regval); - vq = SYS_FIELD_GET(ZCR_ELx, LEN, p->regval) + 1; - vq = min(vq, vcpu_sve_max_vq(vcpu)); - __vcpu_assign_sys_reg(vcpu, ZCR_EL2, vq - 1); return true; }
Greg Kroah-Hartman
maintainerPATCH 117/307 HID: core: Fix size_t specifier in hid_report_raw_event()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
[ Upstream commit 4d3a2a466b8d68d852a1f3bbf11204b718428dc4 ]
When building for 32-bit platforms, for which 'size_t' is 'unsigned int', there are warnings around using the incorrect format specifier to print bsize in hid_report_raw_event():
drivers/hid/hid-core.c:2054:29: error: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
2053 | hid_warn_ratelimited(hid, "Event data for report %d is incorrect (%d vs %ld)\n",
| ~~~
| %zu
2054 | report->id, csize, bsize);
| ^~~~~
drivers/hid/hid-core.c:2076:29: error: format specifies type 'long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
2075 | hid_warn_ratelimited(hid, "Event data for report %d was too short (%d vs %ld)\n",
| ~~~
| %zu
2076 | report->id, rsize, bsize);
| ^~~~~Use the proper 'size_t' format specifier, '%zu', to clear up the warnings.
--- drivers/hid/hid-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +2 -2
@@ -2015,7 +2015,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *return 0 ;if (unlikely (bsize < csize)) { -hid_warn_ratelimited (hid,"Event data for report %d is incorrect (%d vs %ld)\n" , +hid_warn_ratelimited (hid,"Event data for report %d is incorrect (%d vs %zu)\n" , report->id, csize, bsize);return -EINVAL ; }
@@ -2037,7 +2037,7 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 * rsize = max_buffer_size;if (bsize < rsize) { -hid_warn_ratelimited (hid,"Event data for report %d was too short (%d vs %ld)\n" , +hid_warn_ratelimited (hid,"Event data for report %d was too short (%d vs %zu)\n" , report->id, rsize, bsize);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 118/307 drm/i915/psr: Add defininitions for INTEL_WA_REGISTER_CAPS DPCD register
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Högander <[email protected]>
commit fbceb39b536e40c2f7cc47ab42037bb7c2b7ced9 upstream.
EDP specification says:
"If either VSC SDP is unable to be transmitted 100 ns before the SU region, the Source device may optionally transmit the VSC SDP during the prior video scan line’s HBlank period There is a Intel specific drm dp register currently containing bits related how TCON can support PSR2 with SDP on prior line."
Unfortunately many panels are having problems in implementing this. So there is a custom Intel specific DPCD register (INTEL_WA_REGISTER_CAPS) to figure out if this is properly implemented on a panel or if panel doesn't require that 100 ns delay before the SU region. Here are the definitions in this custom DPCD address:
0 = Panel doesn't support SDP on prior line
1 = Panel supports SDP on prior line
2 = Panel doesn't have 100ns requirement
3 = Reserved
Add definitions for this new register and it's values into new header intel_dpcd.h.
v2: add INTEL_DPCD_ prefix to definitions
Bspec: 74741
--- drivers/gpu/drm/i915/display/intel_dpcd.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 drivers/gpu/drm/i915/display/intel_dpcd.h
drivers/gpu/drm/i915/display/intel_dpcd.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ + +#ifndef __INTEL_DPCD_H__ +#define __INTEL_DPCD_H__ + +#define INTEL_DPCD_INTEL_WA_REGISTER_CAPS 0x3f0 +# define INTEL_DPCD_INTEL_WA_REGISTER_CAPS_PSR2_EARLYSCANLINE_SDP_SUPPORT_MASK REG_GENMASK(1, 0) +# define INTEL_DPCD_INTEL_WA_REGISTER_CAPS_FALL_BACK_TO_PSR1 0 +# define INTEL_DPCD_INTEL_WA_REGISTER_CAPS_PSR2_WITH_EARLY_SCANLINE 1 +# define INTEL_DPCD_INTEL_WA_REGISTER_CAPS_PSR2_WITHOUT_EARLY_SCANLINE 2 + +#endif /* __INTEL_DPCD_H__ */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 119/307 drm/i915/psr: Read Intel DPCD workaround register
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Högander <[email protected]>
commit f30bece421a4ae34359254e1dc2a187a42b6af9b upstream.
Read Intel DPCD workaround register and store it into intel_connector->dp.psr_caps. psr_caps was chosen as currently it contains only PSR workaround for PSR2 SDP on prior scanline implementation.
--- drivers/gpu/drm/i915/display/intel_display_types.h | 1 + drivers/gpu/drm/i915/display/intel_psr.c | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/gpu/drm/i915/display/intel_display_types.h +1 -0
@@ -1773,6 +1773,7 @@ struct intel_dp {u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE ];u8 lttpr_phy_caps[DP_MAX_LTTPR_COUNT ][DP_LTTPR_PHY_CAP_SIZE ];u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE ]; +u8 intel_wa_dpcd;/* source rates */ int num_source_rates;const int *source_rates;
drivers/gpu/drm/i915/display/intel_psr.c +7 -0
@@ -35,6 +35,7 @@#include "intel_de.h" #include "intel_display_types.h" #include "intel_dp.h" +#include "intel_dpcd.h" #include "intel_dp_aux.h" #include "intel_frontbuffer.h" #include "intel_hdmi.h"
@@ -665,6 +666,12 @@ static void _psr_init_dpcd(struct intel_dp *intel_dp)drm_dbg_kms (display->drm,"PSR2 %ssupported\n" , intel_dp->psr.sink_psr2_support ?"" :"not " ); } + +if (intel_dp->psr.sink_psr2_support) +drm_dp_dpcd_read (&intel_dp->aux, +INTEL_DPCD_INTEL_WA_REGISTER_CAPS , + &intel_dp->intel_wa_dpcd, +sizeof (intel_dp->intel_wa_dpcd)); }void intel_psr_init_dpcd (struct intel_dp *intel_dp)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 120/307 drm/dp: Add eDP 1.5 bit definition
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suraj Kandpal <[email protected]>
commit 5dfc37a6b77bf6beedbd30d70184b54e1a08ccac upstream.
Add the eDP revision bit value for 1.5.
Spec: eDPv1.5 Table 16-5
--- include/drm/display/drm_dp.h | 1 + 1 file changed, 1 insertion(+)
include/drm/display/drm_dp.h +1 -0
@@ -997,6 +997,7 @@# define DP_EDP_14 0x03# define DP_EDP_14a 0x04/* eDP 1.4a */ # define DP_EDP_14b 0x05/* eDP 1.4b */ +# define DP_EDP_15 0x06/* eDP 1.5 */ #define DP_EDP_GENERAL_CAP_1 0x701# define DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP (1 << 0)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 121/307 drm/i915/psr: Apply Intel DPCD workaround when SDP on prior line used
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Högander <[email protected]>
commit 4703049f768fc1c1caac754134118bee1a3af189 upstream.
There is Intel specific workaround DPCD address containing workaround for case where SDP is on prior line. Apply this workaround according to values in the offset.
--- drivers/gpu/drm/i915/display/intel_psr.c | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_psr.c +26 -1
@@ -1303,6 +1303,30 @@ static bool psr2_granularity_check(struct intel_dp *intel_dp,return true; } +static bool apply_scanline_indication_wa (struct intel_dp *intel_dp, +struct intel_crtc_state *crtc_state) +{ +u8 early_scanline_support = intel_dp->intel_wa_dpcd & +INTEL_DPCD_INTEL_WA_REGISTER_CAPS_PSR2_EARLYSCANLINE_SDP_SUPPORT_MASK ; + +if (intel_dp->edp_dpcd[0 ] >=DP_EDP_15 ) +return true; + +switch (early_scanline_support) { +case INTEL_DPCD_INTEL_WA_REGISTER_CAPS_FALL_BACK_TO_PSR1 : + crtc_state->req_psr2_sdp_prior_scanline = false; +return false; +case INTEL_DPCD_INTEL_WA_REGISTER_CAPS_PSR2_WITH_EARLY_SCANLINE : +return true; +case INTEL_DPCD_INTEL_WA_REGISTER_CAPS_PSR2_WITHOUT_EARLY_SCANLINE : + crtc_state->req_psr2_sdp_prior_scanline = false; +return true; +default : +MISSING_CASE (early_scanline_support); +return false; + } +} +static bool _compute_psr2_sdp_prior_scanline_indication (struct intel_dp *intel_dp,struct intel_crtc_state *crtc_state) {
@@ -1324,7 +1348,8 @@ static bool _compute_psr2_sdp_prior_scanline_indication(struct intel_dp *intel_dreturn false; crtc_state->req_psr2_sdp_prior_scanline = true; -return true; + +return apply_scanline_indication_wa (intel_dp, crtc_state); } static int intel_psr_entry_setup_frames(struct intel_dp *intel_dp,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 122/307 arm64: io: Rename ioremap_prot() to __ioremap_prot()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
commit f6bf47ab32e0863df50f5501d207dcdddb7fc507 upstream.
Rename our ioremap_prot() implementation to __ioremap_prot() and convert all arch-internal callers over to the new function.
ioremap_prot() remains as a #define to __ioremap_prot() for generic_access_phys() and will be subsequently extended to handle user permissions in 'prot'.
--- arch/arm64/include/asm/io.h | 7 ++++--- arch/arm64/kernel/acpi.c | 2 +- arch/arm64/mm/ioremap.c | 7 +++---- 3 files changed, 8 insertions(+), 8 deletions(-)
arch/arm64/include/asm/io.h +4 -3
@@ -274,15 +274,16 @@ __iowrite64_copy(void __iomem *to, const void *from, size_t count)typedef int (*ioremap_prot_hook_t )(phys_addr_t phys_addr,size_t size,pgprot_t *prot);int arm64_ioremap_prot_hook_register (const ioremap_prot_hook_t hook); +void __iomem *__ioremap_prot (phys_addr_t phys,size_t size,pgprot_t prot);#define ioremap_prot ioremap_prot#define _PAGE_IOREMAP PROT_DEVICE_nGnRE#define ioremap_wc (addr, size) \ - ioremap_prot((addr), (size), PROT_NORMAL_NC) + __ioremap_prot((addr), (size), __pgprot(PROT_NORMAL_NC))#define ioremap_np (addr, size) \ - ioremap_prot((addr), (size), PROT_DEVICE_nGnRnE) + __ioremap_prot((addr), (size), __pgprot(PROT_DEVICE_nGnRnE))/* * io{read,write}{16,32,64}be() macros
@@ -303,7 +304,7 @@ static inline void __iomem *ioremap_cache(phys_addr_t addr, size_t size)if (pfn_is_map_memory (__phys_to_pfn (addr)))return (void __iomem *)__phys_to_virt (addr); -return ioremap_prot (addr, size,PROT_NORMAL ); +return __ioremap_prot (addr, size,__pgprot (PROT_NORMAL )); }/*
arch/arm64/kernel/acpi.c +1 -1
@@ -379,7 +379,7 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) prot =__acpi_get_writethrough_mem_attribute (); } } -return ioremap_prot (phys, size,pgprot_val (prot)); +return __ioremap_prot (phys, size, prot); }/*
arch/arm64/mm/ioremap.c +3 -4
@@ -14,11 +14,10 @@ int arm64_ioremap_prot_hook_register(ioremap_prot_hook_t hook)return 0 ; } -void __iomem *ioremap_prot (phys_addr_t phys_addr,size_t size, -unsigned long prot) +void __iomem *__ioremap_prot (phys_addr_t phys_addr,size_t size, +pgprot_t pgprot) {unsigned long last_addr = phys_addr + size -1 ; -pgprot_t pgprot =__pgprot (prot);/* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK )
@@ -39,7 +38,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,return generic_ioremap_prot (phys_addr, size, pgprot); } -EXPORT_SYMBOL (ioremap_prot); +EXPORT_SYMBOL (__ioremap_prot);/* * Must be called after early_fixmap_init
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 123/307 arm64: io: Extract user memory type in ioremap_prot()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
[ Upstream commit 8f098037139b294050053123ab2bc0f819d08932 ]
The only caller of ioremap_prot() outside of the generic ioremap() implementation is generic_access_phys(), which passes a 'pgprot_t' value determined from the user mapping of the target 'pfn' being accessed by the kernel. On arm64, the 'pgprot_t' contains all of the non-address bits from the pte, including the permission controls, and so we end up returning a new user mapping from ioremap_prot() which faults when accessed from the kernel on systems with PAN:
| Unable to handle kernel read from unreadable memory at virtual address ffff80008ea89000 | ... | Call trace: | __memcpy_fromio+0x80/0xf8 | generic_access_phys+0x20c/0x2b8 | __access_remote_vm+0x46c/0x5b8 | access_remote_vm+0x18/0x30 | environ_read+0x238/0x3e8 | vfs_read+0xe4/0x2b0 | ksys_read+0xcc/0x178 | __arm64_sys_read+0x4c/0x68
Extract only the memory type from the user 'pgprot_t' in ioremap_prot() and assert that we're being passed a user mapping, to protect us against any changes in future that may require additional handling. To avoid falsely flagging users of ioremap(), provide our own ioremap() macro which simply wraps __ioremap_prot().
[ Modified ioremap_prot() parameter, using "unsigned long user_prot" instead of "pgprot_t user_prot" to fix conflict with generic header ]
--- arch/arm64/include/asm/io.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
arch/arm64/include/asm/io.h +15 -2
@@ -276,10 +276,23 @@ typedef int (*ioremap_prot_hook_t)(phys_addr_t phys_addr, size_t size,int arm64_ioremap_prot_hook_register (const ioremap_prot_hook_t hook);void __iomem *__ioremap_prot (phys_addr_t phys,size_t size,pgprot_t prot); -#define ioremap_prot ioremap_prot +static inline void __iomem *ioremap_prot (phys_addr_t phys,size_t size, +unsigned long user_prot) +{ +pgprot_t prot; +pteval_t user_prot_val =pgprot_val (__pgprot (user_prot)); + +if (WARN_ON_ONCE (!(user_prot_val &PTE_USER ))) +return NULL ; -#define _PAGE_IOREMAP PROT_DEVICE_nGnRE + prot =__pgprot_modify (PAGE_KERNEL ,PTE_ATTRINDX_MASK , + user_prot_val &PTE_ATTRINDX_MASK ); +return __ioremap_prot (phys, size, prot); +} +#define ioremap_prot ioremap_prot +#define ioremap (addr, size) \ + __ioremap_prot((addr), (size), __pgprot(PROT_DEVICE_nGnRE))#define ioremap_wc (addr, size) \ __ioremap_prot((addr), (size), __pgprot(PROT_NORMAL_NC))#define ioremap_np (addr, size) \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 124/307 phy: mscc: Use PHY_ID_MATCH_EXACT for VSC8584, VSC8582, VSC8575, VSC856X
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Horatiu Vultur <[email protected]>
[ Upstream commit 1bc80d673087e5704adbb3ee8e4b785c14899cce ]
As the PHYs VSC8584, VSC8582, VSC8575 and VSC856X exists only as rev B, we can use PHY_ID_MATCH_EXACT to match exactly on revision B of the PHY. Because of this change then there is not need the check if it is a different revision than rev B in the function vsc8584_probe() as we already know that this will never happen.
These changes are a preparation for the next patch because in that patch we will make the PHYs VSC8574 and VSC8572 to use vsc8584_probe() and these PHYs have multiple revision.
--- drivers/net/phy/mscc/mscc.h | 8 ++++---- drivers/net/phy/mscc/mscc_main.c | 23 ++++------------------- 2 files changed, 8 insertions(+), 23 deletions(-)
drivers/net/phy/mscc/mscc.h +4 -4
@@ -286,12 +286,12 @@ enum rgmii_clock_delay {#define PHY_ID_VSC8540 0x00070760#define PHY_ID_VSC8541 0x00070770#define PHY_ID_VSC8552 0x000704e0 -#define PHY_ID_VSC856X 0x000707e0 +#define PHY_ID_VSC856X 0x000707e1#define PHY_ID_VSC8572 0x000704d0#define PHY_ID_VSC8574 0x000704a0 -#define PHY_ID_VSC8575 0x000707d0 -#define PHY_ID_VSC8582 0x000707b0 -#define PHY_ID_VSC8584 0x000707c0 +#define PHY_ID_VSC8575 0x000707d1 +#define PHY_ID_VSC8582 0x000707b1 +#define PHY_ID_VSC8584 0x000707c1#define PHY_VENDOR_MSCC 0x00070400#define MSCC_VDDMAC_1500 1500
drivers/net/phy/mscc/mscc_main.c +4 -19
@@ -1724,12 +1724,6 @@ static int vsc8584_config_init(struct phy_device *phydev)* in this pre-init function. */ if (phy_package_init_once (phydev)) { -/* The following switch statement assumes that the lowest -* nibble of the phy_id_mask is always 0. This works because -* the lowest nibble of the PHY_ID's below are also 0. -*/ -WARN_ON (phydev->drv->phy_id_mask &0xf ); -switch (phydev->phy_id & phydev->drv->phy_id_mask) {case PHY_ID_VSC8504 :case PHY_ID_VSC8552 :
@@ -2268,11 +2262,6 @@ static int vsc8584_probe(struct phy_device *phydev) VSC8531_DUPLEX_COLLISION};int ret; -if ((phydev->phy_id &MSCC_DEV_REV_MASK ) !=VSC8584_REVB ) { -dev_err (&phydev->mdio.dev,"Only VSC8584 revB is supported.\n" ); -return -ENOTSUPP ; - } - vsc8531 =devm_kzalloc (&phydev->mdio.dev,sizeof (*vsc8531),GFP_KERNEL );if (!vsc8531)return -ENOMEM ;
@@ -2559,9 +2548,8 @@ static struct phy_driver vsc85xx_driver[] = { .get_stats = &vsc85xx_get_stats, }, { - .phy_id = PHY_ID_VSC856X, + PHY_ID_MATCH_EXACT(PHY_ID_VSC856X), .name = "Microsemi GE VSC856X SyncE", - .phy_id_mask = 0xfffffff0,/* PHY_GBIT_FEATURES */ .soft_reset = &genphy_soft_reset, .config_init = &vsc8584_config_init,
@@ -2633,9 +2621,8 @@ static struct phy_driver vsc85xx_driver[] = { .get_stats = &vsc85xx_get_stats, }, { - .phy_id = PHY_ID_VSC8575, + PHY_ID_MATCH_EXACT(PHY_ID_VSC8575), .name = "Microsemi GE VSC8575 SyncE", - .phy_id_mask = 0xfffffff0,/* PHY_GBIT_FEATURES */ .soft_reset = &genphy_soft_reset, .config_init = &vsc8584_config_init,
@@ -2657,9 +2644,8 @@ static struct phy_driver vsc85xx_driver[] = { .get_stats = &vsc85xx_get_stats, }, { - .phy_id = PHY_ID_VSC8582, + PHY_ID_MATCH_EXACT(PHY_ID_VSC8582), .name = "Microsemi GE VSC8582 SyncE", - .phy_id_mask = 0xfffffff0,/* PHY_GBIT_FEATURES */ .soft_reset = &genphy_soft_reset, .config_init = &vsc8584_config_init,
@@ -2681,9 +2667,8 @@ static struct phy_driver vsc85xx_driver[] = { .get_stats = &vsc85xx_get_stats, }, { - .phy_id = PHY_ID_VSC8584, + PHY_ID_MATCH_EXACT(PHY_ID_VSC8584), .name = "Microsemi GE VSC8584 SyncE", - .phy_id_mask = 0xfffffff0,/* PHY_GBIT_FEATURES */ .soft_reset = &genphy_soft_reset, .config_init = &vsc8584_config_init,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 125/307 batman-adv: tt: prevent TVLV entry number overflow
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 99d9958fa10fb684b2a8e2c48a8d704122721420 upstream.
The helpers to prepare the buffers for the local and global TT based replies are trying to sum up all TT entries which can be found for each VLAN. In theory, this sum can be too big for an u16 and therefore overflow. A too small buffer would then be allocated for the TVLV.
The too small buffer will be handled gracefully by batadv_tt_tvlv_generate() and is not causing a buffer overflow - just a truncated reply. But this overflow shouldn't have happened in the first and the too small buffer should never have been allocated when an overflow was detected.
--- net/batman-adv/translation-table.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +17 -3
@@ -850,11 +850,18 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,u16 total_entries =0 ;u8 *tt_change_ptr;int vlan_entries; +u16 sum_entries;spin_lock_bh (&orig_node->vlan_list_lock);hlist_for_each_entry (vlan, &orig_node->vlan_list, list) { vlan_entries =atomic_read (&vlan->tt.num_entries); - total_entries += vlan_entries; + +if (check_add_overflow (vlan_entries, total_entries, &sum_entries)) { + *tt_len =0 ; + goto out; + } + + total_entries = sum_entries; num_vlan++; }
@@ -941,15 +948,22 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,struct batadv_softif_vlan *vlan;size_t change_offset;u16 num_vlan =0 ; -u16 vlan_entries =0 ;u16 total_entries =0 ;u16 tvlv_len;u8 *tt_change_ptr; +int vlan_entries; +u16 sum_entries;spin_lock_bh (&bat_priv->softif_vlan_list_lock);hlist_for_each_entry (vlan, &bat_priv->softif_vlan_list, list) { vlan_entries =atomic_read (&vlan->tt.num_entries); - total_entries += vlan_entries; + +if (check_add_overflow (vlan_entries, total_entries, &sum_entries)) { + tvlv_len =0 ; + goto out; + } + + total_entries = sum_entries; num_vlan++; }
Signature · 1 line
2.53.0
Re: [PATCH 6.12 125/307] batman-adv: tt: prevent TVLV entry number overflow
Quoted 1 line · On Sunday, 7 June 2026 11:58:42 CEST Greg Kroah-Hartman wrote:
6.12-stable review patch. If anyone has any objections, please let me know.
No real objection for 6.12. But it was missed in
* 6.6: https://lore.kernel.org/all/[email protected]/
- applied when using the correct order - no actual change in the patch
* 6.1: https://lore.kernel.org/all/[email protected]/
- applied when using the correct order - no actual change in the patch
* 5.15:
- it depends on the also missed patch (with context conflicts):
https://lore.kernel.org/all/[email protected]/ - applied when using the correct order - no actual change in the patch: https://lore.kernel.org/all/[email protected]/
* 5.10:
- it depends on the also missed patch (with context conflicts):
https://lore.kernel.org/all/[email protected]/ - applied when using the correct order - no actual change in the patch: https://lore.kernel.org/all/[email protected]/
In case of questions regarding the order of patches, you can refer to:
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/7.1
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/7.0
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/6.18
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/6.12
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/6.6
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/6.1
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/5.15
* https://git.open-mesh.org/batadv.git/log/?h=batadv/lts/5.10
Regards,
Sven
Sasha Levin
maintainerRe: [PATCH 6.12 125/307] batman-adv: tt: prevent TVLV entry number overflow
Quoted 9 lines · Sven Eckelmann
No real objection for 6.12. But it was missed in
* 6.6: ...
* 6.1: ...
- applied when using the correct order - no actual change in the patch
* 5.15:
- it depends on the also missed patch (with context conflicts): ...
* 5.10:
- it depends on the also missed patch (with context conflicts): ...
Thanks Sven. Queued the missed backports for all four trees:
- 6.6 and 6.1: applied the single main fix directly.
- 5.15 and 5.10: applied the prerequisite 1e9fab756f83 ("batman-adv:
tt: reject oversized local TVLV buffers") first, then the main fix, per the ordering you pointed to.
All four built cleanly.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 126/307 iio: imu: st_lsm6dsx: fix stack leak in tagged FIFO buffer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit c9d8e9adaa63150ef7e833480b799d0bab83a276 upstream.
The tagged FIFO path declares iio_buff on the stack with __aligned(8) but no initializer, but there is a hole in the structure, which will then leak to userspace as ST_LSM6DSX_SAMPLE_SIZE bytes (6) will be copied, but the space between that and the timestamp are not initialized.
Commit c14edb4d0bdc ("iio:imu:st_lsm6dsx Fix alignment and data leak issues") moved the untagged FIFO path to a kzalloc'd buffer in hw->scan, but for the tagged path it only added the alignment qualifier and not the initializer :(
Fix this by just zero-initializing the structure on the stack.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +1 -1
@@ -608,7 +608,7 @@ int st_lsm6dsx_read_tagged_fifo(struct s* must be passed a buffer that is aligned to 8 bytes so * as to allow insertion of a naturally aligned timestamp. */ -u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE ]__aligned(8) ; +u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE ]__aligned(8) = { };u8 tag;bool reset_ts = false;int i, err, read_len;
Greg Kroah-Hartman
maintainerPATCH 127/307 usb: typec: ucsi: ccg: reject firmware images without a : record header
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit d7486952bf74e546ee3748fb14b2d07881fa6273 upstream.
do_flash() locates the first .cyacd record with
p = strnchr(fw->data, fw->size, ':');
while (p < eof) {
s = strnchr(p + 1, eof - p - 1, ':');
...
}If the firmware image contains no ':' byte, strnchr() returns NULL. NULL compares less than the valid kernel pointer eof, so the loop body runs and strnchr() is called with p + 1 == (void *)1 and a length of roughly (unsigned long)eof, causing a wonderful crash.
The not_signed_fw fallthrough earlier in do_flash() and the chip-state branches in ccg_fw_update_needed() allow an unsigned blob to reach this loop, so a root user who can place a crafted file under /lib/firmware and write the do_flash sysfs attribute can trigger the oops.
Bail out with -EINVAL when the initial strnchr() returns NULL.
--- drivers/usb/typec/ucsi/ucsi_ccg.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/typec/ucsi/ucsi_ccg.c +5 -0
@@ -1241,6 +1241,11 @@ not_signed_fw:*****************************************************************/ p =strnchr (fw->data, fw->size,':' ); +if (!p) { +dev_err (dev,"Bad FW format: no ':' record header found\n" ); + err = -EINVAL ; + goto release_mem; + }while (p < eof) { s =strnchr (p +1 , eof - p -1 ,':' );
Greg Kroah-Hartman
maintainerPATCH 128/307 usb: typec: tcpm: validate VDO count in Discover Identity ACK handlers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 8fbc349e8383125dd2d8de1c1e926279d398ab17 upstream.
Properly validate the count passed from a device when calling svdm_consume_identity() or svdm_consume_identity_sop_prime() as the device-controlled value could index off of the static arrays, which could leak data.
--- drivers/usb/typec/tcpm/tcpm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/usb/typec/tcpm/tcpm.c +7 -1
@@ -1639,6 +1639,9 @@ static void svdm_consume_identity(structu32 vdo = p[VDO_INDEX_IDH ];u32 product = p[VDO_INDEX_PRODUCT ]; +if (cnt <=VDO_INDEX_PRODUCT ) +return ; +memset (&port->mode_data,0 ,sizeof (port->mode_data)); port->partner_ident.id_header = vdo;
@@ -1659,6 +1662,9 @@ static void svdm_consume_identity_sop_pru32 product = p[VDO_INDEX_PRODUCT ];int svdm_version; +if (cnt <=VDO_INDEX_CABLE_1 ) +return ; +/* * Attempt to consume identity only if cable currently is not set */
@@ -1682,7 +1688,7 @@ static void svdm_consume_identity_sop_prswitch (port->negotiated_rev_prime) {case PD_REV30 : port->cable_desc.pd_revision =0x0300 ; -if (port->cable_desc.active) +if (port->cable_desc.active && cnt >VDO_INDEX_CABLE_2 ) port->cable_ident.vdo[1 ] = p[VDO_INDEX_CABLE_2 ];break ;case PD_REV20 :
Greg Kroah-Hartman
maintainerPATCH 129/307 usb: typec: tcpm: bound altmode_desc[] per iteration in svdm_consume_modes()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 3389c149c68c3fea61910ad5d34f7bf3bff44e32 upstream.
svdm_consume_modes() checks pmdata->altmodes against the array size once before the loop over the count, but forgot to check the bound at every point in the loop.
In the well-behaved SVDM discovery flow this is harmless because each of at most SVID_DISCOVERY_MAX SVIDs contributes at most MODE_DISCOVERY_MAX modes, exactly filling altmode_desc[ALTMODE_DISCOVERY_MAX]. But the CMDT_RSP_ACK handler in tcpm_pd_svdm() does not correlate an incoming ACK with any request the port actually sent. Once port->partner is set, an unsolicited Discover Modes ACK is consumed unconditionally. A broken or malicious port partner can therefore drive altmodes to ALTMODE_DISCOVERY_MAX - 1 via the normal flow, and then send one extra Discover Modes ACK with seven VDOs. Because the pre-loop check passes, the loop could then writes up to five entries past altmode_desc[]. For mode_data_prime the next field in struct tcpm_port is the partner_altmode[] pointer array, which then receives partner-chosen SVID/VDO bytes.
Move the bound check inside the loop so the array can never be indexed past ALTMODE_DISCOVERY_MAX regardless of how many VDOs the partner supplies or how the function was reached.
--- drivers/usb/typec/tcpm/tcpm.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +4 -8
@@ -1776,23 +1776,19 @@ static void svdm_consume_modes(struct tcswitch (rx_sop_type) {case TCPC_TX_SOP_PRIME : pmdata = &port->mode_data_prime; -if (pmdata->altmodes >=ARRAY_SIZE (port->plug_prime_altmode)) { -/* Already logged in svdm_consume_svids() */ -return ; - }break ;case TCPC_TX_SOP : pmdata = &port->mode_data; -if (pmdata->altmodes >=ARRAY_SIZE (port->partner_altmode)) { -/* Already logged in svdm_consume_svids() */ -return ; - }break ;default :return ; }for (i =1 ; i < cnt; i++) { +if (pmdata->altmodes >=ALTMODE_DISCOVERY_MAX ) { +/* Already logged in svdm_consume_svids() */ +return ; + } paltmode = &pmdata->altmode_desc[pmdata->altmodes];memset (paltmode,0 ,sizeof (*paltmode));
Greg Kroah-Hartman
maintainerPATCH 130/307 usb: typec: ucsi: displayport: NAK DP_CMD_CONFIGURE without a payload VDO
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 167dd8d12226587ee554f520aed0256b7769cd5d upstream.
ucsi_displayport_vdm() handles a DP_CMD_CONFIGURE by copying the first payload VDO from data[], but unlike the equivalent handler in altmodes/displayport.c it does not check that count covers a VDO beyond the header. A header-only Configure VDM (count == 1) would read one u32 past the caller's array.
In the normal UCSI path the caller controls count, so this is hardening for non-standard delivery paths. NAK and bail when no configuration VDO is present, matching the generic DP altmode driver's existing guard.
--- drivers/usb/typec/ucsi/displayport.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/typec/ucsi/displayport.c +4 -0
@@ -240,6 +240,10 @@ static int ucsi_displayport_vdm(struct t dp->header |=VDO_CMDT (CMDT_RSP_ACK );break ;case DP_CMD_CONFIGURE : +if (count <2 ) { + dp->header |=VDO_CMDT (CMDT_RSP_NAK ); +break ; + } dp->data.conf = *data;if (ucsi_displayport_configure (dp)) { dp->header |=VDO_CMDT (CMDT_RSP_NAK );
Greg Kroah-Hartman
maintainerPATCH 131/307 usb: typec: altmodes/displayport: validate count before reading Status Update VDO
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 8a18f896e667df491331371b55d4ad644dc51d60 upstream.
A broken/malicious device can send the incorrect count for a status update VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the update object.
--- drivers/usb/typec/altmodes/displayport.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/altmodes/displayport.c +2 -0
@@ -386,6 +386,8 @@ static int dp_altmode_vdm(struct typec_a dp->state =DP_STATE_EXIT_PRIME ;break ;case DP_CMD_STATUS_UPDATE : +if (count <2 ) +break ; dp->data.status = *vdo; ret =dp_altmode_status_update (dp);break ;
Greg Kroah-Hartman
maintainerPATCH 132/307 usb: typec: wcove: dont write past struct pd_message in wcove_read_rx_buffer()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 4af7ad0e6d7aa4403dbb1dac7b9659b0421efcaa upstream.
wcove_read_rx_buffer() copies the PD RX FIFO into the caller's struct pd_message with
for (i = 0; i < USBC_RXINFO_RXBYTES(info); i++) regmap_read(wcove->regmap, USBC_RX_DATA + i, msg + i);
which has two problems:
USBC_RXINFO_RXBYTES() is a 5-bit field (max 31) while struct pd_message is 30 bytes (__le16 header + __le32 payload[PD_MAX_PAYLOAD], packed). The byte count latched in RXINFO is the number of bytes the port partner put on the wire, so a malicious partner that transmits a 31-byte frame can drive the loop one byte past the destination if the WCOVE BMC receiver does not enforce the PD object-count limit in hardware. The existing FIXME flagged this as unverified.
Independently, regmap_read() takes an unsigned int * and stores a full unsigned int at the destination. Passing the byte pointer msg + i means each iteration writes four bytes; the high three are zero (val_bits is
8) and are normally overwritten by the next iteration, but the final iteration's high bytes are not. With RXBYTES == 30 the i == 29 iteration already writes three zero bytes past msg, which sits on the IRQ thread's stack in wcove_typec_irq().
Clamp the loop to sizeof(struct pd_message) and read each register into a local before storing only its low byte, so the copy can never exceed the destination regardless of what RXINFO reports.
--- drivers/usb/typec/tcpm/wcove.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/typec/tcpm/wcove.c +8 -5
@@ -444,9 +444,11 @@ static int wcove_start_toggling(struct treturn regmap_write (wcove->regmap,USBC_CONTROL1 , usbc_ctrl); } -static int wcove_read_rx_buffer (struct wcove_typec *wcove,void *msg) +static int wcove_read_rx_buffer (struct wcove_typec *wcove, +struct pd_message *msg) { -unsigned int info; +unsigned int info, val, len; +u8 *buf = (u8 *)msg;int ret;int i;
@@ -454,12 +456,13 @@ static int wcove_read_rx_buffer(struct wif (ret)return ret; -/* FIXME: Check that USBC_RXINFO_RXBYTES(info) matches the header */ + len =min (USBC_RXINFO_RXBYTES (info),sizeof (*msg)); -for (i =0 ; i <USBC_RXINFO_RXBYTES (info); i++) { - ret =regmap_read (wcove->regmap,USBC_RX_DATA + i, msg + i); +for (i =0 ; i < len; i++) { + ret =regmap_read (wcove->regmap,USBC_RX_DATA + i, &val);if (ret)return ret; + buf[i] = val; } return regmap_write(wcove->regmap, USBC_RXSTATUS,
Greg Kroah-Hartman
maintainerPATCH 133/307 usb: typec: tcpm/tcpci_maxim: validate header NDO against RX_BYTE_CNT
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit aa2f716327be1818e1cb156da8a2844804aaec2f upstream.
A broken/malicious port can transmit a CRC-valid frame whose header advertises up to seven data objects but whose body carries fewer than that. Check for this, and rightfully reject the message, instead of reading from uninitialized stack memory.
--- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/usb/typec/tcpm/tcpci_maxim_core.c +9 -0
@@ -186,6 +186,15 @@ static void process_rx(struct max_tcpci_ rx_buf_ptr = rx_buf +TCPC_RECEIVE_BUFFER_RX_BYTE_BUF_OFFSET ; msg.header =cpu_to_le16 (*(u16 *)rx_buf_ptr); rx_buf_ptr = rx_buf_ptr +sizeof (msg.header); + +if (count <TCPC_RECEIVE_BUFFER_RX_BYTE_BUF_OFFSET +sizeof (msg.header) + +pd_header_cnt_le (msg.header) *sizeof (msg.payload[0 ])) { +max_tcpci_write16 (chip,TCPC_ALERT ,TCPC_ALERT_RX_STATUS ); +dev_err (chip->dev,"Invalid TCPC_RX_BYTE_CNT %d for header cnt %d\n" , + count,pd_header_cnt_le (msg.header)); +return ; + } +for (payload_index =0 ; payload_index <pd_header_cnt_le (msg.header); payload_index++, rx_buf_ptr +=sizeof (msg.payload[0 ])) msg.payload[payload_index] =cpu_to_le32 (*(u32 *)rx_buf_ptr);
Greg Kroah-Hartman
maintainerPATCH 134/307 usb: typec: ucsi: validate connector number in ucsi_connector_change()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 288a81a8507052bcfbf884d39a463c44c42c5fd9 upstream.
The connector number in a UCSI CCI notification is a 7-bit field supplied by the PPM. ucsi_connector_change() uses it to index the ucsi->connector[] array without checking it against the number of connectors the PPM reported at init time, so a buggy or malicious PPM (EC firmware, or an I2C-attached UCSI controller on the ccg / stm32g0 / glink transports) can drive schedule_work() on memory past the end of the array.
Reject connector numbers that are zero or exceed cap.num_connectors before dereferencing the array.
--- drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi.c +10 -1
@@ -1290,13 +1290,22 @@ out_unlock:*/ void ucsi_connector_change (struct ucsi *ucsi,u8 num) { -struct ucsi_connector *con = &ucsi->connector[num -1 ]; +struct ucsi_connector *con;if (!(ucsi->ntfy &UCSI_ENABLE_NTFY_CONNECTOR_CHANGE )) {dev_dbg (ucsi->dev,"Early connector change event\n" );return ; } +if (!num || num > ucsi->cap.num_connectors) { +dev_warn_ratelimited (ucsi->dev, +"Bogus connector change on %u (max %u)\n" , + num, ucsi->cap.num_connectors); +return ; + } + + con = &ucsi->connector[num -1 ]; +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags))schedule_work (&con->work); }
Greg Kroah-Hartman
maintainerPATCH 135/307 USB: serial: safe_serial: fix memory corruption with small endpoint
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 438061ed1ad85e6743e2dce826671772d81089ec upstream.
Make sure that the bulk-out buffer size is at least eight bytes to avoid user-controlled slab corruption in "safe" mode should a malicious device report a smaller size.
--- drivers/usb/serial/safe_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/usb/serial/safe_serial.c +11 -0
@@ -259,6 +259,7 @@ static int safe_prepare_write_buffer(strstatic int safe_startup (struct usb_serial *serial) {struct usb_interface_descriptor *desc; +int bulk_out_size;if (serial->dev->descriptor.bDeviceClass !=CDC_DEVICE_CLASS )return -ENODEV ;
@@ -279,6 +280,16 @@ static int safe_startup(struct usb_seriadefault :return -EINVAL ; } + +/* +* The bulk-out buffer needs to be large enough for the two-byte +* trailer in safe mode, but assume anything smaller than eight bytes +* is broken. +*/ + bulk_out_size = serial->port[0 ]->bulk_out_size; +if (bulk_out_size >0 && bulk_out_size <8 ) +return -EINVAL ; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 136/307 media: rc: igorplugusb: fix control request setup packet
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henri A <[email protected]>
commit 171022c7d594c133a45f92357a2a91475edabe20 upstream.
Commit eac69475b01f ("media: rc: igorplugusb: heed coherency rules") changed the control request storage from an embedded struct to an allocated pointer so it can obey DMA coherency rules.
However, the driver still passes &ir->request to usb_fill_control_urb(). That points the URB setup packet at the pointer field itself rather than at the allocated struct usb_ctrlrequest.
USB core then interprets pointer bytes as the setup packet. This can produce an invalid bRequestType and trigger the control direction warning reported by syzbot:
usb 2-1: BOGUS control dir, pipe 80003580 doesn't match bRequestType 0
Pass ir->request itself as the setup packet.
--- drivers/media/rc/igorplugusb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/igorplugusb.c +1 -1
@@ -184,7 +184,7 @@ static int igorplugusb_probe(struct usb_if (!ir->buf_in) goto fail;usb_fill_control_urb (ir->urb, udev, -usb_rcvctrlpipe (udev,0 ), (uint8_t *)&ir->request, +usb_rcvctrlpipe (udev,0 ), (uint8_t *)ir->request, ir->buf_in,MAX_PACKET , igorplugusb_callback, ir);usb_make_path (udev, ir->phys,sizeof (ir->phys));
Greg Kroah-Hartman
maintainerPATCH 137/307 Input: ims-pcu - fix usb_free_coherent() size in ims_pcu_buffers_free()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
commit dab48a7e74e6a394f3aa0461a2b1fb0c7b38fcb8 upstream.
The input buffer size is pcu->max_in_size, but pcu->max_out_size is passed to usb_free_coherent().
Change size to match the allocation size.
--- drivers/input/misc/ims-pcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/ims-pcu.c +1 -1
@@ -1604,7 +1604,7 @@ static void ims_pcu_buffers_free(structusb_kill_urb (pcu->urb_in);usb_free_urb (pcu->urb_in); -usb_free_coherent (pcu->udev, pcu->max_out_size, +usb_free_coherent (pcu->udev, pcu->max_in_size, pcu->urb_in_buf, pcu->read_dma);kfree (pcu->urb_out_buf);
Greg Kroah-Hartman
maintainerPATCH 138/307 HID: quirks: Add ALWAYS_POLL quirk for SIGMACHIP USB mouse
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: hlleng <[email protected]>
commit 07466fc91c55532edcfb5c6a7ccd2ea52728d6bd upstream.
The SIGMACHIP USB mouse with VID/PID 1c4f:0034 can disconnect and re-enumerate repeatedly after it has been enumerated if its interrupt endpoint is not continuously polled.
This was observed with the device reporting itself as "SIGMACHIP Usb Mouse". Keeping the input event device open avoids the disconnects.
Add HID_QUIRK_ALWAYS_POLL for this device so the HID core keeps polling it even when there is no userspace input consumer.
--- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-quirks.c | 1 + 2 files changed, 2 insertions(+)
drivers/hid/hid-ids.h +1 -0
@@ -1230,6 +1230,7 @@#define USB_VENDOR_ID_SIGMA_MICRO 0x1c4f#define USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD 0x0002 +#define USB_DEVICE_ID_SIGMA_MICRO_USB_MOUSE 0x0034#define USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD2 0x0059#define USB_VENDOR_ID_SIGMATEL 0x066F
drivers/hid/hid-quirks.c +1 -0
@@ -186,6 +186,7 @@ static const struct hid_device_id hid_qu { HID_USB_DEVICE(USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD), HID_QUIRK_NO_INIT_REPORTS }, { HID_USB_DEVICE(USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB), HID_QUIRK_NOGET }, { HID_USB_DEVICE(USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD), HID_QUIRK_NO_INIT_REPORTS }, + { HID_USB_DEVICE(USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_USB_MOUSE), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_SIGMATEL, USB_DEVICE_ID_SIGMATEL_STMP3780), HID_QUIRK_NOGET }, { HID_USB_DEVICE(USB_VENDOR_ID_SIS_TOUCH, USB_DEVICE_ID_SIS1030_TOUCH), HID_QUIRK_NOGET }, { HID_USB_DEVICE(USB_VENDOR_ID_SIS_TOUCH, USB_DEVICE_ID_SIS817_TOUCH), HID_QUIRK_NOGET },
Greg Kroah-Hartman
maintainerPATCH 139/307 Bluetooth: btusb: Allow firmware re-download when version matches
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuai Zhang <[email protected]>
commit 82855073c1081732656734b74d7d1d5e4cfd0da7 upstream.
The Bluetooth host decides whether to download firmware by reading the controller firmware download completion flag and firmware version information.
If a USB error occurs during the firmware download process (for example due to a USB disconnect), the download is aborted immediately. An incomplete firmware transfer does not cause the controller to set the download completion flag, but the firmware version information may be updated at an early stage of the download process.
In this case, after USB reconnection, the host attempts to re-download the firmware because the download completion flag is not set. However, since the controller reports the same firmware version as the target firmware, the download is skipped. This ultimately results in the firmware not being properly updated on the controller.
This change removes the restriction that skips firmware download when the versions are equal. It covers scenarios where the USB connection can be disconnected at any time and ensures that firmware download can be retriggered after USB reconnection, allowing the Bluetooth firmware to be correctly and completely updated.
--- drivers/bluetooth/btusb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/bluetooth/btusb.c +7 -1
@@ -3430,7 +3430,13 @@ static int btusb_setup_qca_load_rampatch"firmware rome 0x%x build 0x%x" , rver_rom, rver_patch, ver_rom, ver_patch); -if (rver_rom != ver_rom || rver_patch <= ver_patch) { +/* Allow rampatch when the patch version equals the firmware version. +* A firmware download may be aborted by a transient USB error (e.g. +* disconnect) after the controller updates version info but before +* completion. +* Allowing equal versions enables re-flashing during recovery. +*/ +if (rver_rom != ver_rom || rver_patch < ver_patch) {bt_dev_err (hdev,"rampatch file version did not match with firmware" ); err = -EINVAL ; goto done;
Greg Kroah-Hartman
maintainerPATCH 140/307 hpfs: fix a crash if hpfs_map_dnode_bitmap fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 974820a59efde7c1a7e1260bcfe9bb81f833cc9f upstream.
If hpfs_map_dnode_bitmap fails, the code would call hpfs_brelse4 on uninitialized quad buffer head, causing a crash.
--- fs/hpfs/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hpfs/alloc.c +1 -1
@@ -372,8 +372,8 @@ int hpfs_check_free_dnodes(struct super_return 0 ; } } +hpfs_brelse4 (&qbh); } -hpfs_brelse4 (&qbh); i =0 ;if (hpfs_sb (s)->sb_c_bitmap !=-1 ) { bmp =hpfs_map_bitmap (s, b, &qbh,"chkdn1" );
Greg Kroah-Hartman
maintainerPATCH 141/307 ipc: limit next_id allocation to the valid ID range
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linpu Yu <[email protected]>
commit fa0b9b2b7ae3539908d69c2b9ac0d144d9bc5139 upstream.
The checkpoint/restore sysctl path can request the next SysV IPC id through ids->next_id. ipc_idr_alloc() currently forwards that request to idr_alloc() with an open-ended upper bound.
If the valid tail of the SysV IPC id space is full, the allocation can spill beyond ipc_mni. The returned SysV IPC id still uses the normal index encoding, so later lookup and removal can target the wrong slot. This leaves the real IDR entry behind and breaks the IDR state for the object.
The bug is in ipc_idr_alloc() in the checkpoint/restore path.
1. ids->next_id is passed to:
idr_alloc(&ids->ipcs_idr, new, ipcid_to_idx(next_id), 0, ...)
2. The zero upper bound makes the allocation effectively open-ended. Once the valid SysV IPC tail is occupied, idr_alloc() can spill past ipc_mni and allocate an entry beyond the valid IPC id range.
3. The new object id is still encoded with the narrower SysV IPC index width:
new->id = (new->seq << ipcmni_seq_shift()) + idx
4. Later removal goes through ipc_rmid(), which uses:
ipcid_to_idx(ipcp->id)
That truncates the real IDR index. An object actually stored at a high index can then be removed as if it lived at a low in-range index.
5. For shared memory, shm_destroy() frees the current object anyway, but the real high IDR slot is left behind as a dangling pointer.
6. A subsequent walk of /proc/sysvipc/shm reaches the stale IDR entry and dereferences freed memory.
Prevent this by bounding the requested allocation to ipc_mni so the checkpoint/restore path fails once the valid range is exhausted.
--- ipc/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ipc/util.c +1 -1
@@ -253,7 +253,7 @@ static inline int ipc_idr_alloc(struct i }else { new->seq =ipcid_to_seqx (next_id); idx =idr_alloc (&ids->ipcs_idr, new,ipcid_to_idx (next_id), -0 ,GFP_NOWAIT ); + ipc_mni,GFP_NOWAIT ); }if (idx >=0 ) new->id = (new->seq <<ipcmni_seq_shift ()) + idx;
Greg Kroah-Hartman
maintainerPATCH 142/307 auxdisplay: line-display: fix OOB read on zero-length message_store()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stepan Ionichev <[email protected]>
commit a7511dcd9dd4bc55d123f9b800c8a4ed2662e5c6 upstream.
linedisp_display() unconditionally reads msg[count - 1] before checking whether count is zero, so a write of zero bytes to the message sysfs attribute hits msg[-1]:
write(fd, "", 0); -> message_store(..., buf, count=0) -> linedisp_display(linedisp, buf, count=0) -> msg[count - 1] == '\n' ; OOB read
The kernfs write buffer for that store is a 1-byte allocation (kernfs_fop_write_iter() does kmalloc(len + 1) with len == 0), so msg[-1] is a 1-byte read before the slab object. On a KASAN-enabled kernel this trips an out-of-bounds report and panics; on stock kernels it silently reads adjacent slab data and, if that byte happens to be '\n', the following count-- wraps ssize_t 0 to -1 and is then passed to kmemdup_nul().
linedisp_display() is reached from the message_store() sysfs callback (drivers/auxdisplay/line-display.c message attribute, mode 0644) and from the in-tree initial-message setup with count == -1, so the OOB path is only userspace-triggerable via zero-byte writes; vfs_write() does not short-circuit on count == 0 and kernfs_fop_write_iter() dispatches the store callback regardless.
Guard the trailing-newline trim with a count check. The existing if (!count) block then takes the clear-display path unchanged.
Affects every auxdisplay driver that registers via linedisp_register() / linedisp_attach(): ht16k33, max6959, img-ascii-lcd, seg-led-gpio.
--- drivers/auxdisplay/line-display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/line-display.c +1 -1
@@ -90,7 +90,7 @@ static int linedisp_display(struct lined count =strlen (msg);/* if the string ends with a newline, trim it */ -if (msg[count -1 ] =='\n' ) +if (count && msg[count -1 ] =='\n' ) count--;if (!count) {
Greg Kroah-Hartman
maintainerPATCH 143/307 Bluetooth: L2CAP: use chan timer to close channels in cleanup_listen()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
commit 8c8e620467a7b51562dbcefbd1f09f288d7d710d upstream.
l2cap_chan_close() removes the channel from conn->chan_l, which must be done under conn->lock. cleanup_listen() runs under the parent sk_lock, so acquiring conn->lock would invert the established conn->lock -> chan->lock -> sk_lock order.
Instead of calling l2cap_chan_close() directly, schedule l2cap_chan_timeout with delay 0 to close the channel asynchronously. The timeout handler already acquires conn->lock and chan->lock in the correct order.
The timer is only armed when chan->conn is still set: if it is already NULL, l2cap_conn_del() has already processed this channel (l2cap_chan_del + l2cap_sock_teardown_cb + l2cap_sock_close_cb), so there is nothing left to do. If l2cap_conn_del() races in after the timer is armed, __clear_chan_timer() inside l2cap_chan_del() cancels it; if the timer has already fired, the handler returns harmlessly because chan->conn was cleared.
--- net/bluetooth/l2cap_sock.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/bluetooth/l2cap_sock.c +9 -7
@@ -1468,6 +1468,10 @@ static void l2cap_sock_cleanup_listen(st* pin it (hold_unless_zero() additionally skips a chan already past * its last reference). We then drop the sk lock before taking * chan->lock, so sk and chan locks are never held together. +* +* Since we cannot call l2cap_chan_close() without conn->lock, +* schedule l2cap_chan_timeout to close the channel; it already +* acquires conn->lock -> chan->lock in the correct order. */ while ((sk =bt_accept_dequeue (parent,NULL ))) {struct l2cap_chan *chan;
@@ -1485,14 +1489,12 @@ static void l2cap_sock_cleanup_listen(st state_to_string(chan->state));l2cap_chan_lock (chan); -__clear_chan_timer (chan); -l2cap_chan_close (chan,ECONNRESET ); -/* l2cap_conn_del() may already have killed this socket -* (it sets SOCK_DEAD); skip the duplicate to avoid a -* double sock_put()/l2cap_chan_put(). +/* Since we cannot call l2cap_chan_close() without +* conn->lock, schedule its timer to trigger the close +* and cleanup of this channel. */ -if (!sock_flag (sk,SOCK_DEAD )) -l2cap_sock_kill (sk); +if (chan->conn) +__set_chan_timer (chan,0 );l2cap_chan_unlock (chan);l2cap_chan_put (chan);
Greg Kroah-Hartman
maintainerPATCH 144/307 Bluetooth: L2CAP: fix chan ref leak in l2cap_chan_timeout() on !conn
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
commit 9dbd84990394c51f5cee1e8871bb5ff8af5ed939 upstream.
__set_chan_timer() takes a l2cap_chan reference via l2cap_chan_hold() before scheduling the delayed work. The normal path in l2cap_chan_timeout() drops this reference with l2cap_chan_put() at the end, but the early return when chan->conn is NULL skips the put, leaking the reference.
Add the missing l2cap_chan_put() before the early return.
--- net/bluetooth/l2cap_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +3 -1
@@ -411,8 +411,10 @@ static void l2cap_chan_timeout(struct woBT_DBG ("chan %p state %s" , chan,state_to_string (chan->state)); -if (!conn) +if (!conn) { +l2cap_chan_put (chan);return ; + }mutex_lock (&conn->lock);/* __set_chan_timer() calls l2cap_chan_hold(chan) while scheduling
Greg Kroah-Hartman
maintainerPATCH 145/307 Bluetooth: HIDP: fix missing length checks in hidp_input_report()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 2a3ac9ee11dbb9845f3947cef4a79dba658cf6f6 upstream.
hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.
hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data. The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.
Replace the open-coded length tracking and pointer arithmetic with skb_pull_data() calls. skb_pull_data() returns NULL if the requested bytes are not present, eliminating the need for a manual size variable and the separate skb->len guard.
--- net/bluetooth/hidp/core.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
net/bluetooth/hidp/core.c +18 -5
@@ -179,12 +179,21 @@ static void hidp_input_report(struct hid {struct input_dev *dev = session->input;unsigned char *keys = session->keys; -unsigned char *udata = skb->data +1 ; -signed char *sdata = skb->data +1 ; -int i, size = skb->len -1 ; +unsigned char *udata; +signed char *sdata; +u8 *hdr; +int i; + + hdr =skb_pull_data (skb,1 ); +if (!hdr) +return ; -switch (skb->data[0 ]) { +switch (*hdr) {case 0x01 :/* Keyboard report */ + udata =skb_pull_data (skb,8 ); +if (!udata) +break ; +for (i =0 ; i <8 ; i++)input_report_key (dev, hidp_keycode[i +224 ], (udata[0 ] >> i) &1 );
@@ -213,6 +222,10 @@ static void hidp_input_report(struct hidbreak ;case 0x02 :/* Mouse report */ + sdata =skb_pull_data (skb,3 ); +if (!sdata) +break ; +input_report_key (dev,BTN_LEFT , sdata[0 ] &0x01 );input_report_key (dev,BTN_RIGHT , sdata[0 ] &0x02 );input_report_key (dev,BTN_MIDDLE , sdata[0 ] &0x04 );
@@ -222,7 +235,7 @@ static void hidp_input_report(struct hidinput_report_rel (dev,REL_X , sdata[1 ]);input_report_rel (dev,REL_Y , sdata[2 ]); -if (size >3 ) +if (skb->len >0 )input_report_rel (dev,REL_WHEEL , sdata[3 ]);break ; }
Greg Kroah-Hartman
maintainerPATCH 146/307 Bluetooth: ISO: fix UAF in iso_recv_frame
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 47f23a259517abbdb8032c057a1e8a6bf3734878 upstream.
iso_recv_frame reads conn->sk under iso_conn_lock but releases the lock before using sk, with no reference held. A concurrent iso_sock_kill() can free sk in that window, causing use-after-free on sk->sk_state and sock_queue_rcv_skb().
Fix by replacing the bare pointer read with iso_sock_hold(conn), which calls sock_hold() while the spinlock is held, atomically elevating the refcount before the lock drops. Add a drop_put label so sock_put() is called on all exit paths where the hold succeeded.
--- net/bluetooth/iso.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/bluetooth/iso.c +7 -3
@@ -553,7 +553,7 @@ static void iso_recv_frame(struct iso_costruct sock *sk;iso_conn_lock (conn); - sk = conn->sk; + sk =iso_sock_hold (conn);iso_conn_unlock (conn);if (!sk)
@@ -562,11 +562,15 @@ static void iso_recv_frame(struct iso_coBT_DBG ("sk %p len %d" , sk, skb->len);if (sk->sk_state !=BT_CONNECTED ) - goto drop; + goto drop_put; -if (!sock_queue_rcv_skb (sk, skb)) +if (!sock_queue_rcv_skb (sk, skb)) { +sock_put (sk);return ; + } +drop_put: +sock_put (sk); drop:kfree_skb (skb); }
Greg Kroah-Hartman
maintainerPATCH 147/307 Bluetooth: ISO: serialize iso_sock_clear_timer with socket lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 4b5f8e608749b7e8fa386c6e4301cf9272595859 upstream.
iso_sock_close() calls iso_sock_clear_timer() before acquiring lock_sock(sk).
iso_sock_clear_timer() reads iso_pi(sk)->conn twice without the socket lock held:
if (!iso_pi(sk)->conn)
return;
cancel_delayed_work(&iso_pi(sk)->conn->timeout_work);Concurrently, iso_conn_del() executes under lock_sock(sk) and calls iso_chan_del(), which sets iso_pi(sk)->conn to NULL and may result in the final reference to the connection being dropped:
CPU0 CPU1
---- ----
iso_sock_clear_timer()
if (conn != NULL) ... lock_sock(sk)
iso_chan_del()
iso_pi(sk)->conn = NULL
cancel_delayed_work(conn) /* NULL deref or UAF */iso_pi(sk)->conn is not stable across the unlock window, causing a NULL pointer dereference or use-after-free.
Serialize iso_sock_clear_timer() with the socket lock by moving it inside lock_sock()/release_sock(), matching the pattern used in iso_conn_del() and all other call sites.
--- net/bluetooth/iso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/iso.c +1 -1
@@ -835,8 +835,8 @@ static void __iso_sock_close(struct sock/* Must be called on unlocked socket. */ static void iso_sock_close (struct sock *sk) { -iso_sock_clear_timer (sk);lock_sock (sk); +iso_sock_clear_timer (sk);__iso_sock_close (sk);release_sock (sk);iso_sock_kill (sk);
Greg Kroah-Hartman
maintainerPATCH 148/307 Bluetooth: hci_sync: fix UAF in hci_le_create_cis_sync
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit bfea6091e0fffb270c20e74384b660910277eb6c upstream.
hci_le_create_cis_sync() dereferences conn->conn_timeout after releasing both rcu_read_lock() and hci_dev_lock(hdev). The conn pointer was obtained from an RCU-protected iteration over hdev->conn_hash.list and is not valid once these locks are dropped. A concurrent disconnect can free the hci_conn between the unlock and the dereference, causing a use-after-free read.
The cancellation mechanism in hci_conn_del() cannot prevent this because hci_le_create_cis_pending() queues hci_create_cis_sync with data=NULL:
hci_cmd_sync_queue(hdev, hci_create_cis_sync, NULL, NULL);
While hci_conn_del() dequeues with data=conn:
hci_cmd_sync_dequeue(hdev, NULL, conn, NULL);
Since NULL != conn, the lookup in _hci_cmd_sync_lookup_entry() never matches, and the pending work item is not cancelled.
Fix this by saving conn->conn_timeout into a local variable while the locks are still held, so the stale conn pointer is never dereferenced after unlock.
This is the same class of bug as the one fixed by commit 035c25007c9e ("Bluetooth: hci_sync: Fix UAF on le_read_features_complete") which addressed the identical pattern in a different function.
This vulnerability was identified using 0sec.ai, an open-source automated security auditing platform (https://github.com/0sec-labs).
--- net/bluetooth/hci_sync.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_sync.c +3 -1
@@ -6626,6 +6626,7 @@ int hci_le_create_cis_sync(struct hci_de DEFINE_FLEX(struct hci_cp_le_create_cis, cmd, cis, num_cis, 0x1f);size_t aux_num_cis =0 ;struct hci_conn *conn; +u16 timeout =0 ;u8 cig =BT_ISO_QOS_CIG_UNSET ;/* The spec allows only one pending LE Create CIS command at a time. If
@@ -6696,6 +6697,7 @@ int hci_le_create_cis_sync(struct hci_deset_bit (HCI_CONN_CREATE_CIS , &conn->flags); cis->acl_handle =cpu_to_le16 (conn->parent->handle); cis->cis_handle =cpu_to_le16 (conn->handle); + timeout = conn->conn_timeout; aux_num_cis++;if (aux_num_cis >= cmd->num_cis)
@@ -6715,7 +6717,7 @@ done:return __hci_cmd_sync_status_sk (hdev,HCI_OP_LE_CREATE_CIS ,struct_size (cmd, cis, cmd->num_cis), cmd,HCI_EVT_LE_CIS_ESTABLISHED , - conn->conn_timeout,NULL ); + timeout,NULL ); }int hci_le_remove_cig_sync (struct hci_dev *hdev,u8 handle)
Greg Kroah-Hartman
maintainerPATCH 149/307 Input: xpad - fix out-of-bounds access for Share button
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 6cdc46b38cf146ce81d4831b6472dbf7731849a2 upstream.
xpadone_process_packet() receives len directly from urb->actual_length and uses it to index the share-button byte at data[len - 18] or data[len - 26]. Since both len and data[0] are under the device's control, a broken controller can send a GIP_CMD_INPUT packet with actual_length < 18 (e.g. 5 bytes) and reach this code path, causing accesses beyond the actual array.
Fix this by calculating the offset and checking bounds against the packet length.
--- drivers/input/joystick/xpad.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/input/joystick/xpad.c +4 -4
@@ -1081,10 +1081,10 @@ static void xpadone_process_packet(strucinput_report_key (dev,BTN_START , data[4 ] &BIT (2 ));input_report_key (dev,BTN_SELECT , data[4 ] &BIT (3 ));if (xpad->mapping &MAP_SHARE_BUTTON ) { -if (xpad->mapping &MAP_SHARE_OFFSET ) -input_report_key (dev,KEY_RECORD , data[len -26 ] &BIT (0 )); -else -input_report_key (dev,KEY_RECORD , data[len -18 ] &BIT (0 )); +u32 offset = (xpad->mapping &MAP_SHARE_OFFSET ) ?26 :18 ; + +if (len >= offset) +input_report_key (dev,KEY_RECORD , data[len - offset] &BIT (0 )); }/* buttons A,B,X,Y */
Greg Kroah-Hartman
maintainerPATCH 150/307 parport: Fix race between port and client registration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ben Hutchings <[email protected]>
commit ef15ccbb3e8640a723c42ad90eaf81d66ae02017 upstream.
The parport subsystem registers port devices before they are fully initialised, resulting in a race condition where client drivers such as lp can attach to ports that are not completely initialised or even being torn down.
When the port and client drivers are built as modules and loaded around the same time during boot, this occasionally results in a crash. I was able to make this happen reliably in a VM with a PC-style parallel port by patching parport_pc to fail probing:
drivers/parport/parport_pc.c static struct parport *__parport_pc_probe_port(unsigned long int base, · line 2075
Quoted 11 lines
drivers/parport/parport_pc.c +1
-1@@ -2069,7 +2069,7 @@ static struct parport *__parport_pc_probe_port(unsigned long int base,if (!p) goto out3; - base_res =request_region (base,3 , p->name); + base_res =NULL ;if (!base_res) goto out4;
and then running:
while true; do
modprobe lp & modprobe parport_pc
wait
rmmod lp parport_pc
done
for a few seconds.
In the long term I think port registration should be changed to put the call to device_add() inside parport_announce_port(), but since the latter currently cannot fail this will require changing all port drivers.
For now, add a flag to indicate whether a port has been "announced" and only try to attach client drivers to ports when the flag is set.
--- drivers/parport/share.c | 11 +++++++++-- include/linux/parport.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/parport/share.c +9 -2
@@ -214,10 +214,14 @@ static void get_lowlevel_driver(void)static int port_check (struct device *dev,void *dev_drv) {struct parport_driver *drv = dev_drv; +struct parport *port;/* only send ports, do not send other devices connected to bus */ -if (is_parport (dev)) - drv->match_port (to_parport_dev (dev)); +if (is_parport (dev)) { + port =to_parport_dev (dev); +if (test_bit (PARPORT_ANNOUNCED , &port->devflags)) + drv->match_port (port); + }return 0 ; }
@@ -532,6 +536,7 @@ void parport_announce_port(struct parporif (slave)attach_driver_chain (slave); } +set_bit (PARPORT_ANNOUNCED , &port->devflags);mutex_unlock (®istration_lock); }EXPORT_SYMBOL (parport_announce_port);
@@ -561,6 +566,8 @@ void parport_remove_port(struct parportmutex_lock (®istration_lock); +clear_bit (PARPORT_ANNOUNCED , &port->devflags); +/* Spread the word. */ detach_driver_chain (port);
include/linux/parport.h +1 -0
@@ -240,6 +240,7 @@ struct parport {unsigned long devflags;#define PARPORT_DEVPROC_REGISTERED 0 +#define PARPORT_ANNOUNCED 1struct pardevice *proc_device;/* Currently register proc device */ struct list_head full_list;
Greg Kroah-Hartman
maintainerPATCH 151/307 USB: cdc-acm: Fix bit overlap and move quirk definitions to header
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Guan <[email protected]>
commit 5eb070769ea5e18405535609d1d3f6886f3755bd upstream.
The VENDOR_CLASS_DATA_IFACE and ALWAYS_POLL_CTRL quirk flags added in commit f58752ebcb35 ("USB: cdc-acm: Add quirks for Yoga Book 9 14IAH10 INGENIC touchscreen") were placed inside the acm_ctrl_msg() function rather than in the header with the other quirk flags. Then, their values (BIT(9) and BIT(10)) collided with NO_UNION_12 which is already BIT(9).
Move the definitions to drivers/usb/class/cdc-acm.h where they belong and shift them to BIT(10) and BIT(11) to avoid the overlap.
--- drivers/usb/class/cdc-acm.c | 2 -- drivers/usb/class/cdc-acm.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/usb/class/cdc-acm.c +0 -2
@@ -114,8 +114,6 @@ static int acm_ctrl_msg(struct acm *acm,int retval; retval =usb_autopm_get_interface (acm->control); -#define VENDOR_CLASS_DATA_IFACE BIT(9)/* data interface uses vendor-specific class */ -#define ALWAYS_POLL_CTRL BIT(10)/* keep ctrl URB active even without an open TTY */ if (retval)return retval;
drivers/usb/class/cdc-acm.h +2 -0
@@ -115,3 +115,5 @@ struct acm {#define DISABLE_ECHO BIT(7)#define MISSING_CAP_BRK BIT(8)#define NO_UNION_12 BIT(9) +#define VENDOR_CLASS_DATA_IFACE BIT(10)/* data interface uses vendor-specific class */ +#define ALWAYS_POLL_CTRL BIT(11)/* keep ctrl URB active even without an open TTY */
Greg Kroah-Hartman
maintainerPATCH 152/307 KVM: arm64: PMU: Preserve AArch32 counter low bits
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiang Ma <[email protected]>
commit 1750ad1388e03fb27068cd1f22c9c8b4590fe936 upstream.
AArch32 writes to PMU event counters cannot update the top 32 bits, even when PMUv3p5 makes the counters 64-bit. KVM therefore needs to preserve the existing high half and only update the low half written by the guest, unless the caller explicitly forces a full reset through PMCR.P.
The current code masks @val down to the old high half before taking lower_32_bits(val), which means the low half is always zero. As a result, AArch32 writes to event counters discard the guest-provided low 32 bits instead of storing them.
Build the new value from the old high 32 bits and the low 32 bits of the value supplied by the guest.
--- arch/arm64/kvm/pmu-emul.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/pmu-emul.c +2 -2
@@ -163,8 +163,8 @@ static void kvm_pmu_set_pmc_value(struct* action is to use PMCR.P, which will reset them to * 0 (the only use of the 'force' parameter). */ - val =__vcpu_sys_reg (vcpu, reg) &GENMASK (63 ,32 ); - val |=lower_32_bits (val); + val = (__vcpu_sys_reg (vcpu, reg) &GENMASK (63 ,32 )) | +lower_32_bits (val); }__vcpu_sys_reg (vcpu, reg) = val;
Greg Kroah-Hartman
maintainerPATCH 153/307 KVM: SVM: Flush the current TLB when transitioning from xAVIC => x2AVIC
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit a9e18aa3263f356edae305e29830e5fe63d8597a upstream.
Flush the current TLB when xAVIC *or* x2AVIC is activated, as KVM is (apparently) responsible for purging TLB entries when transitioning from xAVIC to x2AVIC. The APM says a whole lot of nothing about TLB flushing with respect to (x2)AVIC, but empirical data strongly suggests hardware also does a whole lot of nothing.
Failure to flush the TLB when enabling x2AVIC can lead to guest accesses to the APIC base address getting incorrectly redirected to the virtual APIC page. The flaw most visibly manifests as failures in KVM-Unit-Test's verify_disabled_apic_mmio() testcase when x2APIC is enabled (though for reasons unknown, the test only reliably fails with EFI builds).
--- arch/x86/kvm/svm/avic.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
arch/x86/kvm/svm/avic.c +29 -6
@@ -111,6 +111,35 @@ static void avic_activate_vmcb(struct vcsvm_clr_intercept (svm,INTERCEPT_CR8_WRITE );/* +* Flush the TLB when enabling (x2)AVIC and when transitioning between +* xAVIC and x2AVIC, as the CPU may have inserted a TLB entry for the +* "wrong" mapping. +* +* KVM uses a per-VM "scratch" page to back the APIC memslot, because +* KVM also uses per-VM page tables *and* maintains the page table (NPT +* or shadow page) mappings for said memslot even if one or more vCPUs +* have their local APIC hardware-disabled or are in x2APIC mode, i.e. +* even if one or more vCPUs' APIC MMIO BAR is effectively disabled. +* +* If xAVIC is fully enabled, hardware ignores the physical address in +* KVM's page tables, i.e. in the leaf SPTE for the APIC memslot, and +* instead redirects the access to the AVIC backing page, i.e. to the +* vCPU's virtual APIC page. If xAVIC is not enabled (APIC is either +* hardware-disabled or in x2APIC mode), then guest accesses will use +* the page table mapping verbatim, i.e. will access the per-VM scratch +* page, as normal memory. +* +* In both cases, the CPU is allowed to cache TLB entries for the APIC +* base GPA. So, KVM needs to flush the TLB when enabling xAVIC, as +* accesses need to be redirected to the virtual APIC page, but the TLB +* may contain entries pointing at the scratch page. KVM also needs to +* flush the TLB when enabling x2AVIC, as accesses need to go to the +* scratch page, but the TLB may contain entries tagged as xAVIC, i.e. +* entries pointing to the vCPU's virtual APIC page. +*/ +kvm_make_request (KVM_REQ_TLB_FLUSH_CURRENT , &svm->vcpu); + +/* * Note: KVM supports hybrid-AVIC mode, where KVM emulates x2APIC MSR * accesses, while interrupt injection to a running vCPU can be * achieved using AVIC doorbell. KVM disables the APIC access page
@@ -123,12 +152,6 @@ static void avic_activate_vmcb(struct vc/* Disabling MSR intercept for x2APIC registers */ svm_set_x2apic_msr_interception (svm, false); }else { -/* -* Flush the TLB, the guest may have inserted a non-APIC -* mapping into the TLB while AVIC was disabled. -*/ -kvm_make_request (KVM_REQ_TLB_FLUSH_CURRENT , &svm->vcpu); -/* Enabling MSR intercept for x2APIC registers */ svm_set_x2apic_msr_interception (svm, true); }
Greg Kroah-Hartman
maintainerPATCH 154/307 KVM: SEV: Require in-GHCB scratch area if GHCB v2+ is in use
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Roth <[email protected]>
commit db3f2195d29344a3cf1e9dd9ab7f21ced7308cf7 upstream.
As per the GHCB spec, when using GHCB v2+ require the software scratch area to reside in the GHCB's shared buffer. Note, things like Page State Change (PSC) requests _rely_ on this behavior, as the guest can't provide a length when making the request, i.e. the size of the guest payload is bounded by the size of the shared buffer.
Failure to force usage of the GHCB, and a slew of other flaws, lets a malicious SNP guest corrupt host kernel heap memory, and leak host heap layout information.
setup_vmgexit_scratch() allocates a buffer via kvzalloc(exit_info_2), where exit_info_2 is guest-controlled. With exit_info_2=24, this yields a 24-byte allocation in kmalloc-cg-32 (32-byte slab objects). The buffer holds an 8-byte psc_hdr followed by 8-byte psc_entry structs, so only entries[0] and entries[1] are in-bounds.
snp_begin_psc() validates end_entry against VMGEXIT_PSC_MAX_COUNT (253) but NOT against the actual buffer size:
idx_end = hdr->end_entry;
if (idx_end >= VMGEXIT_PSC_MAX_COUNT) { // checks 253, not buffer
snp_complete_psc(svm, ...);
return 1;
}
for (idx = idx_start; idx <= idx_end; idx++) {
entry_start = entries[idx]; // OOB when idx >= 2The guest sets end_entry=10+, causing the host to iterate entries[2+] which are OOB into adjacent slab objects. For each OOB entry:
- The host reads 8 bytes (OOB READ / info leak oracle)
- If the data passes PSC validation, __snp_complete_one_psc() writes
cur_page = 1 or 512 into the entry (OOB WRITE, sev.c:3806)
- If validation fails, the error response reveals whether adjacent memory is zero vs non-zero (information disclosure to guest)
The guest controls allocation size (exit_info_2), entry range (cur_entry/end_entry), and can fire unlimited VMGEXITs to repeatedly hit different slab positions.
By exploiting the variety of bugs, a malicious SEV-SNP guest can:
- OOB read adjacent kmalloc-cg-32 objects (heap layout disclosure)
- OOB write cur_page bits into adjacent objects (heap corruption)
- Trigger use-after-free conditions across VMGEXITs
E.g. with KASAN enabled, a single insmod of the PoC guest module produces 73 KASAN reports:
BUG: KASAN: slab-out-of-bounds in snp_begin_psc+0x126/0x890
Read of size 8 at addr ffff888219ffb5e0 by task qemu-system-x86/2199
BUG: KASAN: slab-out-of-bounds in snp_begin_psc+0x468/0x890
Write of size 8 at addr ffff888351566648 by task qemu-system-x86/2199
The buggy address belongs to the object at ffff888XXXXXXXXX
which belongs to the cache kmalloc-cg-32 of size 32
The buggy address is located N bytes to the right of
allocated 32-byte region [ffff888XXXXXXXXX, ffff888XXXXXXXXX) Breakdown:
62 slab-out-of-bounds (reads + writes past allocation)
7 slab-use-after-free
4 use-after-free
All credit to Stan for the wonderful description and reproducer!
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kvm/svm/sev.c +4 -0
@@ -3543,6 +3543,10 @@ static int setup_vmgexit_scratch(struct scratch_va = (void *)svm->sev_es.ghcb; scratch_va += (scratch_gpa_beg - control->ghcb_gpa); }else { +/* GHCB v2 requires the scratch area to be within the GHCB. */ +if (to_kvm_sev_info (svm->vcpu.kvm)->ghcb_version >=2 ) + goto e_scratch; +/* * The guest memory must be read into a kernel buffer, so * limit the size
Greg Kroah-Hartman
maintainerPATCH 155/307 KVM: SEV: Use the size of the PSC header as the minimum size for PSC requests
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit 2be54670bdc017004c4a4b8bddb6ff02ebe7dbe2 upstream.
When handling a Page State Change (PSC) #VMGEXIT use the size of the PSC header as the minimum size for the scratch area. Per the GHCB spec, PSC requests do NOT provide the length, i.e. using control->exit_info_2 for the length is completely made up behavior. The existing code "works", e.g. even though Linux-as-a-guest always passes '0', because KVM doesn't do anything with the length when the request is in the GHCB's shared buffer.
Use the header as the min length. Once the header is retrieved, KVM can use the specified indices to compute the full size of the request.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +1 -1
@@ -4393,7 +4393,7 @@ int sev_handle_vmgexit(struct kvm_vcpu * vcpu->run->system_event.data[0 ] = control->ghcb_gpa;break ;case SVM_VMGEXIT_PSC : - ret =setup_vmgexit_scratch (svm, true, control->exit_info_2); + ret =setup_vmgexit_scratch (svm, true,sizeof (struct psc_hdr ));if (ret)break ;
Greg Kroah-Hartman
maintainerPATCH 156/307 KVM: SEV: WARN if KVM attempts to setup scratch area with min_len==0
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit f185e05dce6f170f83c4ba602e969b1c3c7a22e6 upstream.
Now that all paths in KVM properly validate the length needed for the scratch area, and are guaranteed to pass in a non-zero length, WARN if KVM attempts to configured the scratch area with min_len==0 to guard against future bugs.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kvm/svm/sev.c +3 -0
@@ -3509,6 +3509,9 @@ static int setup_vmgexit_scratch(structu64 scratch_gpa_beg, scratch_gpa_end;void *scratch_va; +if (WARN_ON_ONCE (!min_len)) + goto e_scratch; + scratch_gpa_beg = svm->sev_es.sw_scratch;if (!scratch_gpa_beg) {pr_err ("vmgexit: scratch gpa not provided\n" );
Greg Kroah-Hartman
maintainerPATCH 157/307 KVM: SEV: Compute the correct max length of the in-GHCB scratch area
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit 5867d7e202e09f037cefe77f7af4413c7c0fa088 upstream.
When setting the length of the GHCB scratch area, and the area is in the GHCB shared buffer, set the effective length of the scratch area to the max possible size given the start of the guest-provided pointer, and the end of the shared buffer.
The code was "fine" when first introduced, as KVM doesn't consult the length of the buffer when emulating MMIO, because the passed in @len always specifies the *max* size required. But for PSC requests, the incoming @len is just the minimum length (to process the header), and KVM needs to know the full size of the scratch area to avoid buffer overflows (spoiler alert).
Opportunistically rename @len => @min_len to better reflect its role.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
arch/x86/kvm/svm/sev.c +10 -9
@@ -3502,7 +3502,7 @@ void pre_sev_run(struct vcpu_svm *svm, i }#define GHCB_SCRATCH_AREA_LIMIT (16ULL * PAGE_SIZE) -static int setup_vmgexit_scratch (struct vcpu_svm *svm,bool sync,u64 len) +static int setup_vmgexit_scratch (struct vcpu_svm *svm,bool sync,u64 min_len) {struct vmcb_control_area *control = &svm->vmcb->control;u64 ghcb_scratch_beg, ghcb_scratch_end;
@@ -3518,10 +3518,10 @@ static int setup_vmgexit_scratch(struct goto e_scratch; } - scratch_gpa_end = scratch_gpa_beg + len; + scratch_gpa_end = scratch_gpa_beg + min_len;if (scratch_gpa_end < scratch_gpa_beg) {pr_err ("vmgexit: scratch length (%#llx) not valid for scratch address (%#llx)\n" , - len, scratch_gpa_beg); + min_len, scratch_gpa_beg); goto e_scratch; }
@@ -3545,6 +3545,8 @@ static int setup_vmgexit_scratch(struct scratch_va = (void *)svm->sev_es.ghcb; scratch_va += (scratch_gpa_beg - control->ghcb_gpa); + + svm->sev_es.ghcb_sa_len = ghcb_scratch_end - scratch_gpa_beg; }else {/* GHCB v2 requires the scratch area to be within the GHCB. */ if (to_kvm_sev_info (svm->vcpu.kvm)->ghcb_version >=2 )
@@ -3554,16 +3556,16 @@ static int setup_vmgexit_scratch(struct* The guest memory must be read into a kernel buffer, so * limit the size */ -if (len >GHCB_SCRATCH_AREA_LIMIT ) { +if (min_len >GHCB_SCRATCH_AREA_LIMIT ) {pr_err ("vmgexit: scratch area exceeds KVM limits (%#llx requested, %#llx limit)\n" , - len,GHCB_SCRATCH_AREA_LIMIT ); + min_len,GHCB_SCRATCH_AREA_LIMIT ); goto e_scratch; } - scratch_va =kvzalloc (len,GFP_KERNEL_ACCOUNT ); + scratch_va =kvzalloc (min_len,GFP_KERNEL_ACCOUNT );if (!scratch_va)return -ENOMEM ; -if (kvm_read_guest (svm->vcpu.kvm, scratch_gpa_beg, scratch_va, len)) { +if (kvm_read_guest (svm->vcpu.kvm, scratch_gpa_beg, scratch_va, min_len)) {/* Unable to copy scratch area from guest */ pr_err ("vmgexit: kvm_read_guest for scratch area failed\n" );
@@ -3579,11 +3581,10 @@ static int setup_vmgexit_scratch(struct*/ svm->sev_es.ghcb_sa_sync = sync; svm->sev_es.ghcb_sa_free = true; + svm->sev_es.ghcb_sa_len = min_len; } svm->sev_es.ghcb_sa = scratch_va; - svm->sev_es.ghcb_sa_len = len; -return 0 ; e_scratch:
Greg Kroah-Hartman
maintainerPATCH 158/307 KVM: SEV: Check PSC request indices against the actual size of the buffer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit 121d88de56bc5c0ba0ce2f6381af67f948a7e7c1 upstream.
When processing Page State Change (PSC) requests, validate the PSC buffer against the effective size of the scratch area, which could be less than the maximum size if the guest provided a pointer that isn't exactly at the start of the GHCB shared buffer.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/sev.c +15 -2
@@ -3729,7 +3729,7 @@ static int snp_begin_psc(struct vcpu_svmstruct kvm_vcpu *vcpu = &svm->vcpu;struct psc_hdr *hdr = &psc->hdr;struct psc_entry entry_start; -u16 idx, idx_start, idx_end; +u16 idx, idx_start, idx_end, max_nr_entries;int npages;bool huge;u64 gfn;
@@ -3739,6 +3739,19 @@ static int snp_begin_psc(struct vcpu_svmreturn 1 ; } +/* +* GHCB v2 requires the scratch area to reside within the GHCB itself, +* and PSC requests are only supported for GHCB v2+. Thus it should be +* impossible to exceed the max PSC entry count (which is derived from +* the size of the shared GHCB buffer). +*/ + max_nr_entries = (sev_es->ghcb_sa_len -sizeof (struct psc_hdr )) / +sizeof (struct psc_entry ); +if (WARN_ON_ONCE (max_nr_entries >VMGEXIT_PSC_MAX_COUNT )) { +snp_complete_psc (svm,VMGEXIT_PSC_ERROR_GENERIC ); +return 1 ; + } + next_range:/* There should be no other PSCs in-flight at this point. */ if (WARN_ON_ONCE (svm->sev_es.psc_inflight)) {
@@ -3754,7 +3767,7 @@ next_range: idx_start = hdr->cur_entry; idx_end = hdr->end_entry; -if (idx_end >=VMGEXIT_PSC_MAX_COUNT ) { +if (idx_end >= max_nr_entries) {snp_complete_psc (svm,VMGEXIT_PSC_ERROR_INVALID_HDR );return 1 ; }
Greg Kroah-Hartman
maintainerPATCH 159/307 KVM: SEV: Use READ_ONCE() when reading entries/indices from PSC buffer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit c8cc238093ca6c99267032f6cfe78f59389f3157 upstream.
Use READ_ONCE() when reading entries/indices from the guest-accessible Page State Change buffer to defend against TOCTOU bugs.
Don't bother with READ_ONCE()/WRITE_ONCE() for cases where KVM is writing (and not consuming the result!), as the guest isn't supposed to touch the buffer while it's being processed. I.e. using READ_ONCE() is all about protecting against misbehaving guests.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/kvm/svm/sev.c +6 -6
@@ -3699,9 +3699,9 @@ static void __snp_complete_one_psc(struc*/ for (idx = svm->sev_es.psc_idx; svm->sev_es.psc_inflight; svm->sev_es.psc_inflight--, idx++) { -struct psc_entry *entry = &entries[idx]; +struct psc_entry entry =READ_ONCE (entries[idx]); - entry->cur_page = entry->pagesize ?512 :1 ; + entries[idx].cur_page = entry.pagesize ?512 :1 ; } hdr->cur_entry = idx;
@@ -3764,8 +3764,8 @@ next_range:* validation, so take care to only use validated copies of values used * for things like array indexing. */ - idx_start = hdr->cur_entry; - idx_end = hdr->end_entry; + idx_start =READ_ONCE (hdr->cur_entry); + idx_end =READ_ONCE (hdr->end_entry);if (idx_end >= max_nr_entries) {snp_complete_psc (svm,VMGEXIT_PSC_ERROR_INVALID_HDR );
@@ -3774,7 +3774,7 @@ next_range:/* Find the start of the next range which needs processing. */ for (idx = idx_start; idx <= idx_end; idx++, hdr->cur_entry++) { - entry_start = entries[idx]; + entry_start =READ_ONCE (entries[idx]); gfn = entry_start.gfn; huge = entry_start.pagesize;
@@ -3818,7 +3818,7 @@ next_range:* KVM_HC_MAP_GPA_RANGE exit. */ while (++idx <= idx_end) { -struct psc_entry entry = entries[idx]; +struct psc_entry entry =READ_ONCE (entries[idx]); if (entry.operation != entry_start.operation || entry.gfn != entry_start.gfn + npages ||
Greg Kroah-Hartman
maintainerPATCH 160/307 KVM: SEV: Dont explicitly pass PSC buffer to snp_begin_psc()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit ebe4b2dc9cfbfb2d8f665667c4d08f4c6c9bec05 upstream.
Stop explicitly passing the PSC buffer to snp_begin_psc(): it *must* be the scratch area. This will allow fixing a variety of bugs without further complicating the code.
No functional change intended.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/x86/kvm/svm/sev.c +6 -5
@@ -3675,7 +3675,7 @@ struct psc_buffer {struct psc_entry entries[]; } __packed; -static int snp_begin_psc (struct vcpu_svm *svm,struct psc_buffer *psc); +static int snp_begin_psc (struct vcpu_svm *svm);static void snp_complete_psc (struct vcpu_svm *svm,u64 psc_ret) {
@@ -3710,7 +3710,6 @@ static void __snp_complete_one_psc(strucstatic int snp_complete_one_psc (struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu); -struct psc_buffer *psc = svm->sev_es.ghcb_sa;if (vcpu->run->hypercall.ret) {snp_complete_psc (svm,VMGEXIT_PSC_ERROR_GENERIC );
@@ -3720,11 +3719,13 @@ static int snp_complete_one_psc(struct k__snp_complete_one_psc (svm);/* Handle the next range (if any). */ -return snp_begin_psc (svm, psc); +return snp_begin_psc (svm); } -static int snp_begin_psc (struct vcpu_svm *svm,struct psc_buffer *psc) +static int snp_begin_psc (struct vcpu_svm *svm) { +struct vcpu_sev_es_state *sev_es = &svm->sev_es; +struct psc_buffer *psc = sev_es->ghcb_sa;struct psc_entry *entries = psc->entries;struct kvm_vcpu *vcpu = &svm->vcpu;struct psc_hdr *hdr = &psc->hdr;
@@ -4414,7 +4415,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *if (ret)break ; - ret =snp_begin_psc (svm, svm->sev_es.ghcb_sa); + ret =snp_begin_psc (svm);break ;case SVM_VMGEXIT_AP_CREATION : ret =sev_snp_ap_creation (svm);
Greg Kroah-Hartman
maintainerPATCH 161/307 Disable -Wattribute-alias for clang-23 and newer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 175db11786bde9061db526bf1ac5107d915f5163 upstream.
Clang recently added support for -Wattribute-alias [1], which results in the same warnings that necessitated commit bee20031772a ("disable -Wattribute-alias warning for SYSCALL_DEFINEx()") for GCC.
kernel/time/itimer.c:325:1: error: alias and aliasee have different types 'long (unsigned int)' and 'long (typeof (__builtin_choose_expr((__builtin_types_compatible_p(typeof ((unsigned int)0), typeof (0LL)) || __builtin_types_compatible_p(typeof ((unsigned int)0), typeof (0ULL))), 0LL, 0L)))' (aka 'long (long)') [-Werror,-Wattribute-alias]
325 | SYSCALL_DEFINE1(alarm, unsigned int, seconds)
| ^
include/linux/syscalls.h:225:36: note: expanded from macro 'SYSCALL_DEFINE1'
225 | #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
| ^
include/linux/syscalls.h:236:2: note: expanded from macro 'SYSCALL_DEFINEx'
236 | __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
| ^
include/linux/syscalls.h:251:18: note: expanded from macro '__SYSCALL_DEFINEx'
251 | __attribute__((alias(__stringify(__se_sys##name)))); \
| ^
kernel/time/itimer.c:325:1: note: aliasee is declared here
include/linux/syscalls.h:225:36: note: expanded from macro 'SYSCALL_DEFINE1'
225 | #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
| ^
include/linux/syscalls.h:236:2: note: expanded from macro 'SYSCALL_DEFINEx'
236 | __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
| ^
include/linux/syscalls.h:255:18: note: expanded from macro '__SYSCALL_DEFINEx'
255 | asmlinkage long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
| ^
<scratch space>:16:1: note: expanded from here
16 | __se_sys_alarm
| ^Disable the warnings in the same way for clang-23 and newer. Disable the warning about unknown warning options to avoid breaking the build for versions of clang-23 that do not have -Wattribute-alias, such as ones deployed by vendors like Android or CI systems or when bisecting LLVM between llvmorg-23-init and release/23.x.
--- arch/riscv/include/asm/syscall_wrapper.h | 4 ++++ include/linux/compat.h | 4 ++++ include/linux/compiler-clang.h | 6 ++++++ include/linux/compiler_types.h | 4 ++++ include/linux/syscalls.h | 4 ++++ 5 files changed, 22 insertions(+)
arch/riscv/include/asm/syscall_wrapper.h +4 -0
@@ -32,6 +32,10 @@ asmlinkage long __riscv_sys_ni_syscall(c__diag_push (); \__diag_ignore (GCC ,8 ,"-Wattribute-alias" , \"Type aliasing is used to sanitize syscall arguments" ); \ +__diag_ignore (clang,23 ,"-Wunknown-warning-option" , \ +"Avoid breaking versions without -Wattribute-alias" ); \ +__diag_ignore (clang,23 ,"-Wattribute-alias" , \ +"Type aliasing is used to sanitize syscall arguments" ); \ static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \ ulong) \ __attribute__((alias(__stringify(___se_##prefix##name)))); \
include/linux/compat.h +4 -0
@@ -72,6 +72,10 @@__diag_push (); \__diag_ignore (GCC ,8 ,"-Wattribute-alias" , \"Type aliasing is used to sanitize syscall arguments" );\ +__diag_ignore (clang,23 ,"-Wunknown-warning-option" , \ +"Avoid breaking versions without -Wattribute-alias" ); \ +__diag_ignore (clang,23 ,"-Wattribute-alias" , \ +"Type aliasing is used to sanitize syscall arguments" ); \ asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ __attribute__((alias(__stringify(__se_compat_sys##name)))); \ ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
include/linux/compiler-clang.h +6 -0
@@ -133,6 +133,12 @@#define __diag_str (s) __diag_str1(s)#define __diag (s) _Pragma(__diag_str(clang diagnostic s)) +#if CONFIG_CLANG_VERSION >=230000 +#define __diag_clang_23 (s) __diag(s) +#else +#define __diag_clang_23 (s) +#endif +#define __diag_clang_13 (s) __diag(s)#define __diag_ignore_all (option, comment) \
include/linux/compiler_types.h +4 -0
@@ -569,6 +569,10 @@ struct ftrace_likely_data {#define __diag_GCC (version, severity, string)#endif +#ifndef __diag_clang +#define __diag_clang (version, severity, string) +#endif +#define __diag_push () __diag(push)#define __diag_pop () __diag(pop)
include/linux/syscalls.h +4 -0
@@ -245,6 +245,10 @@ static inline int is_syscall_trace_event__diag_push (); \__diag_ignore (GCC ,8 ,"-Wattribute-alias" , \"Type aliasing is used to sanitize syscall arguments" );\ +__diag_ignore (clang,23 ,"-Wunknown-warning-option" , \ +"Avoid breaking versions without -Wattribute-alias" );\ +__diag_ignore (clang,23 ,"-Wattribute-alias" , \ +"Type aliasing is used to sanitize syscall arguments" );\ asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ __attribute__((alias(__stringify(__se_sys##name)))); \ ALLOW_ERROR_INJECTION(sys##name, ERRNO); \
Greg Kroah-Hartman
maintainerPATCH 162/307 iio: adc: xilinx-xadc: Fix sequencer mode in postdisable for dual mux
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christofer Jonason <[email protected]>
commit 852534744c2d35626a604f128ff0b8ec12805591 upstream.
xadc_postdisable() unconditionally sets the sequencer to continuous mode. For dual external multiplexer configurations this is incorrect:
simultaneous sampling mode is required so that ADC-A samples through the mux on VAUX[0-7] while ADC-B simultaneously samples through the mux on VAUX[8-15]. In continuous mode only ADC-A is active, so VAUX[8-15] channels return incorrect data.
Since postdisable is also called from xadc_probe() to set the initial idle state, the wrong sequencer mode is active from the moment the driver loads.
The preenable path already uses xadc_get_seq_mode() which returns SIMULTANEOUS for dual mux. Fix postdisable to do the same.
--- drivers/iio/adc/xilinx-xadc-core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/iio/adc/xilinx-xadc-core.c +9 -2
@@ -817,6 +817,7 @@ static int xadc_postdisable(struct iio_d {struct xadc *xadc =iio_priv (indio_dev);unsigned long scan_mask; +int seq_mode;int ret;int i;
@@ -824,6 +825,12 @@ static int xadc_postdisable(struct iio_dfor (i =0 ; i < indio_dev->num_channels; i++) scan_mask |=BIT (indio_dev->channels[i].scan_index); +/* +* Use the correct sequencer mode for the idle state: simultaneous +* mode for dual external mux configurations, continuous otherwise. +*/ + seq_mode =xadc_get_seq_mode (xadc, scan_mask); +/* Enable all channels and calibration */ ret =xadc_write_adc_reg (xadc,XADC_REG_SEQ (0 ), scan_mask &0xffff );if (ret)
@@ -834,11 +841,11 @@ static int xadc_postdisable(struct iio_dreturn ret; ret =xadc_update_adc_reg (xadc,XADC_REG_CONF1 ,XADC_CONF1_SEQ_MASK , -XADC_CONF1_SEQ_CONTINUOUS ); + seq_mode);if (ret)return ret; -return xadc_power_adc_b (xadc,XADC_CONF1_SEQ_CONTINUOUS ); +return xadc_power_adc_b (xadc, seq_mode); }static int xadc_preenable (struct iio_dev *indio_dev)
Greg Kroah-Hartman
maintainerPATCH 163/307 iio: adc: npcm: fix unbalanced clk_disable_unprepare()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit 0d42e2c0bd6ceb89e44c6e065f9bdf9b1df3ef0c upstream.
The driver acquired the ADC clock with devm_clk_get() and read its rate, but never called clk_prepare_enable(). The probe error path and npcm_adc_remove() both called clk_disable_unprepare() unconditionally, causing the clk framework's enable/prepare counts to underflow on probe failure or module unbind.
The issue went unnoticed because NPCM BMC firmware leaves the ADC clock enabled at boot, so the driver happened to work in practice.
Switch to devm_clk_get_enabled() so the clock is properly enabled during probe and automatically released by the device-managed cleanup, and drop the now-redundant clk_disable_unprepare() from both the probe error path and remove().
While at it, drop the duplicate error message on devm_request_irq() failure since the IRQ core already logs it.
--- drivers/iio/adc/npcm_adc.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/iio/adc/npcm_adc.c +8 -17
@@ -231,7 +231,7 @@ static int npcm_adc_probe(struct platforif (IS_ERR (info->reset))return PTR_ERR (info->reset); - info->adc_clk =devm_clk_get (&pdev->dev,NULL ); + info->adc_clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (info->adc_clk)) {dev_warn (&pdev->dev,"ADC clock failed: can't read clk\n" );return PTR_ERR (info->adc_clk);
@@ -244,17 +244,13 @@ static int npcm_adc_probe(struct platfor info->adc_sample_hz =clk_get_rate (info->adc_clk) / ((div +1 ) *2 ); irq =platform_get_irq (pdev,0 ); -if (irq <0 ) { - ret = irq; - goto err_disable_clk; - } +if (irq <0 ) +return irq; ret =devm_request_irq (&pdev->dev, irq, npcm_adc_isr,0 ,"NPCM_ADC" , indio_dev); -if (ret <0 ) { -dev_err (dev,"failed requesting interrupt\n" ); - goto err_disable_clk; - } +if (ret <0 ) +return ret; reg_con =ioread32 (info->regs +NPCM_ADCCON ); info->vref =devm_regulator_get_optional (&pdev->dev,"vref" );
@@ -262,7 +258,7 @@ static int npcm_adc_probe(struct platfor ret =regulator_enable (info->vref);if (ret) {dev_err (&pdev->dev,"Can't enable ADC reference voltage\n" ); - goto err_disable_clk; +return ret; } iowrite32(reg_con & ~NPCM_ADCCON_REFSEL,
@@ -272,10 +268,8 @@ static int npcm_adc_probe(struct platfor* Any error which is not ENODEV indicates the regulator * has been specified and so is a failure case. */ -if (PTR_ERR (info->vref) != -ENODEV ) { - ret =PTR_ERR (info->vref); - goto err_disable_clk; - } +if (PTR_ERR (info->vref) != -ENODEV ) +return PTR_ERR (info->vref);/* Use internal reference */ iowrite32(reg_con | NPCM_ADCCON_REFSEL,
@@ -314,8 +308,6 @@ err_iio_register:iowrite32 (reg_con & ~NPCM_ADCCON_ADC_EN , info->regs +NPCM_ADCCON );if (!IS_ERR (info->vref))regulator_disable (info->vref); -err_disable_clk: -clk_disable_unprepare (info->adc_clk);return ret; }
@@ -332,7 +324,6 @@ static void npcm_adc_remove(struct platfiowrite32 (regtemp & ~NPCM_ADCCON_ADC_EN , info->regs +NPCM_ADCCON );if (!IS_ERR (info->vref))regulator_disable (info->vref); -clk_disable_unprepare (info->adc_clk); }static struct platform_driver npcm_adc_driver = {
Greg Kroah-Hartman
maintainerPATCH 164/307 iio: dac: max5821: fix return value check in powerdown sync
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
commit d0a228d903425e653f18a4341e60c0538afb6d41 upstream.
The function max5821_sync_powerdown_mode() returned the result of i2c_master_send() directly. If a partial transfer occurred, it would be incorrectly treated as a success by the caller.
While the caller currently handles the positive return value of 2 as success, this patch refactors the function to return 0 on full success and -EIO on short writes. This ensures robust error handling for incomplete transfers and improves code maintainability by using sizeof(outbuf).
--- drivers/iio/dac/max5821.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/iio/dac/max5821.c +8 -1
@@ -91,6 +91,7 @@ static int max5821_sync_powerdown_mode(s const struct iio_chan_spec *chan) {u8 outbuf[2 ]; +int ret; outbuf[0 ] =MAX5821_EXTENDED_COMMAND_MODE ;
@@ -104,7 +105,13 @@ static int max5821_sync_powerdown_mode(selse outbuf[1 ] |=MAX5821_EXTENDED_POWER_UP ; -return i2c_master_send (data->client, outbuf,2 ); + ret =i2c_master_send (data->client, outbuf,sizeof (outbuf)); +if (ret <0 ) +return ret; +if (ret !=sizeof (outbuf)) +return -EIO ; + +return 0 ; } static ssize_t max5821_write_dac_powerdown(struct iio_dev *indio_dev,
Greg Kroah-Hartman
maintainerPATCH 165/307 iio: dac: ad5686: fix input raw value check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Alencar <[email protected]>
commit d01220ee5e43c65a206df827b39bf5cf5f7b9dce upstream.
Fix range check for input raw value, which is off by one, i.e., for a 10-bit DAC the max valid value is 1023, but 1 << 10 equals 1024, which passes the previous check, allowing an out-of-range write. The issue exists since the ad5686 driver was first introduced.
--- drivers/iio/dac/ad5686.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5686.c +1 -1
@@ -154,7 +154,7 @@ static int ad5686_write_raw(struct iio_dswitch (mask) {case IIO_CHAN_INFO_RAW : -if (val > (1 << chan->scan_type.realbits) || val <0 ) +if (val >= (1 << chan->scan_type.realbits) || val <0 )return -EINVAL ;mutex_lock (&st->lock);
Greg Kroah-Hartman
maintainerPATCH 166/307 iio: dac: ad5686: acquire lock when doing powerdown control
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Alencar <[email protected]>
commit 5237c3175cae5ab05f18878cec3301a04403859e upstream.
Protect access of pwr_down_mode and pwr_down_mask fields with existing mutex lock. Each channel exposes their own attributes for controlling powerdown modes and powerdown state. This fixes potential race conditions as those the write functions perform non-atomic read-modify-write operations to those pwr_down_* fields. This issue exists since the ad5686 driver was first introduced.
--- drivers/iio/dac/ad5686.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/dac/ad5686.c +8 -0
@@ -30,6 +30,8 @@ static int ad5686_get_powerdown_mode(str {struct ad5686_state *st =iio_priv (indio_dev); +guard (mutex)(&st->lock); +return ((st->pwr_down_mode >> (chan->channel *2 )) &0x3 ) -1 ; }
@@ -39,6 +41,8 @@ static int ad5686_set_powerdown_mode(str {struct ad5686_state *st =iio_priv (indio_dev); +guard (mutex)(&st->lock); + st->pwr_down_mode &= ~(0x3 << (chan->channel *2 )); st->pwr_down_mode |= ((mode +1 ) << (chan->channel *2 ));
@@ -57,6 +61,8 @@ static ssize_t ad5686_read_dac_powerdown {struct ad5686_state *st =iio_priv (indio_dev); +guard (mutex)(&st->lock); +return sysfs_emit (buf,"%d\n" , !!(st->pwr_down_mask & (0x3 << (chan->channel *2 )))); }
@@ -77,6 +83,8 @@ static ssize_t ad5686_write_dac_powerdowif (ret)return ret; +guard (mutex)(&st->lock); +if (readin) st->pwr_down_mask |= (0x3 << (chan->channel *2 ));else
Greg Kroah-Hartman
maintainerPATCH 167/307 iio: adc: mt6359: fix unchecked return value in mt6358_read_imp
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
commit f9bbd943c34a9ad60e593a4b99ce2394e4e2381b upstream.
In mt6358_read_imp(), the variable val_v is passed to regmap_read() but the return value is not checked. If the read fails, val_v remains uninitialized and its random stack content is subsequently reported as a measurement result.
Initialize val_v to zero to ensure a predictable value is reported in case of bus failure and to prevent potential stack data leakage. This also satisfies static analyzers that might otherwise flag the variable as used uninitialized.
--- drivers/iio/adc/mt6359-auxadc.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/adc/mt6359-auxadc.c +1 -0
@@ -347,6 +347,7 @@ static int mt6358_read_imp(struct mt6359return ret;/* Read the params before stopping */ + val_v =0 ;regmap_read (regmap, reg_adc0 + (cinfo->imp_adc_num <<1 ), &val_v);mt6358_stop_imp_conv (adc_dev);
Greg Kroah-Hartman
maintainerPATCH 168/307 iio: adc: viperboard: Fix error handling in vprbrd_iio_read_raw
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
commit 422b5bbf333f75fb486855ad0eedc23cf21f3277 upstream.
The driver proceeds to the reception phase even if the preceding transmission fails.
This uses a goto error label for an early bail out and ensures the mutex is properly unlocked in case of failure.
--- drivers/iio/adc/viperboard_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/viperboard_adc.c +3 -1
@@ -70,8 +70,10 @@ static int vprbrd_iio_read_raw(struct iiVPRBRD_USB_TYPE_OUT ,0x0000 ,0x0000 , admsg, sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS);if (ret !=sizeof (struct vprbrd_adc_msg )) { -dev_err (&iio_dev->dev,"usb send error on adc read\n" ); +mutex_unlock (&vb->lock); error = -EREMOTEIO ; +dev_err (&iio_dev->dev,"usb send error on adc read\n" ); + goto error; } ret = usb_control_msg(vb->usb_dev,
Greg Kroah-Hartman
maintainerPATCH 169/307 iio: gyro: itg3200: fix i2c read into the wrong stack location
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit 6bdc3023d62ed5c7d591f0eb27a5adb37fb892ae upstream.
itg3200_read_all_channels() takes __be16 *buf' as a parameter and fills the i2c_msg destination as (char *)&buf'. Since buf' is the parameter (a pointer), &buf' is the address of the local pointer slot on the stack of itg3200_read_all_channels(), not the address of the caller's scan buffer. The (char *) cast hides the type mismatch.
i2c_transfer() therefore writes ITG3200_SCAN_ELEMENTS * sizeof(s16) = 8 bytes into the parameter's stack slot, which is discarded when the function returns. The caller's scan buffer in itg3200_trigger_handler() is never written to, so iio_push_to_buffers_with_timestamp() pushes uninitialised stack contents to userspace via /dev/iio:deviceX every scan -- both a functional bug (no actual gyroscope or temperature data is delivered through the triggered buffer) and an information leak.
The non-buffered read_raw() path is unaffected: it goes through itg3200_read_reg_s16() which uses `&out' on a local s16 value, where that is correct.
Drop the spurious `&' so the i2c read writes into the caller's buffer.
--- drivers/iio/gyro/itg3200_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/gyro/itg3200_buffer.c +1 -1
@@ -34,7 +34,7 @@ static int itg3200_read_all_channels(str .addr = i2c->addr, .flags = i2c->flags | I2C_M_RD, .len = ITG3200_SCAN_ELEMENTS * sizeof(s16), - .buf = (char *)&buf, + .buf = (char *)buf, }, };
Greg Kroah-Hartman
maintainerPATCH 170/307 iio: gyro: adis16260: fix division by zero in write_raw
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit 761e8b489e6cf166c574034b70637f8a7eadd0ee upstream.
Add a validation check for the sampling frequency value before using it as a divisor. A user writing zero to the sampling_frequency sysfs attribute triggers a division by zero in the kernel.
--- drivers/iio/gyro/adis16260.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/gyro/adis16260.c +3 -0
@@ -287,6 +287,9 @@ static int adis16260_write_raw(struct ii addr = adis16260_addresses[chan->scan_index][1 ];return adis_write_reg_16 (adis, addr, val);case IIO_CHAN_INFO_SAMP_FREQ : +if (val <=0 ) +return -EINVAL ; +if (spi_get_device_id (adis->spi)->driver_data) t =256 / val;else
Greg Kroah-Hartman
maintainerPATCH 171/307 iio: ssp_sensors: cancel delayed work_refresh on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanjay Chitroda <[email protected]>
commit eedf7602fbd929e97e0c480da501dc7a34beb2a8 upstream.
The work_refresh may still be pending or running when the device is removed, cancel the delayed work_refresh in remove path.
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/common/ssp_sensors/ssp_dev.c +1 -0
@@ -590,6 +590,7 @@ static void ssp_remove(struct spi_devicessp_clean_pending_list (data);free_irq (data->spi->irq, data); +cancel_delayed_work_sync (&data->work_refresh);del_timer_sync (&data->wdt_timer);cancel_work_sync (&data->work_wdt);
Greg Kroah-Hartman
maintainerPATCH 172/307 iio: temperature: tsys01: fix broken PROM checksum validation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
commit 4701e471c16866e7aa8f5e6a3a6b0d31e097e2c9 upstream.
The current implementation of tsys01_crc_valid() incorrectly sums the first word (n_prom[0]) repeatedly instead of iterating over the 8 words retrieved from the PROM. This leads to a checksum mismatch and probe failure on hardware.
According to the TSYS01 datasheet, the PROM consists of 8 words. A valid check must iterate through all 8 words to verify the integrity of the calibration data. The current driver only checks the first word 8 times.
Note: This fix was identified during a code audit and is based on datasheet specifications. It has not been tested on real hardware.
--- drivers/iio/temperature/tsys01.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/temperature/tsys01.c +1 -1
@@ -119,7 +119,7 @@ static bool tsys01_crc_valid(u16 *n_promu8 sum =0 ;for (cnt =0 ; cnt <TSYS01_PROM_WORDS_NB ; cnt++) - sum += ((n_prom[0 ] >>8 ) + (n_prom[0 ] &0xFF )); + sum += ((n_prom[cnt] >>8 ) + (n_prom[cnt] &0xFF ));return (sum ==0 ); }
Greg Kroah-Hartman
maintainerPATCH 173/307 iio: magnetometer: st_magn: fix default DRDY pin selection for LIS2MDL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Advait Dhamorikar <[email protected]>
commit 49f79cd28f1e3333cbe0d616ce59ead0b24bf34e upstream.
The device tree binding for st,lis2mdl does not support st,drdy-int-pin property. However, when no platform data is provided and the property is absent, the driver falls back to default_magn_pdata which hardcodes drdy_int_pin = 2. This causes st_sensors_set_drdy_int_pin to fail with -EINVAL because the LIS2MDL sensor settings have no INT2 DRDY mask defined.
Fix this by checking the sensor's INT2 DRDY mask availability at probe time and selecting the appropriate default pin. Sensors that do not support INT2 DRDY will default to INT1, while all others retain the existing default of INT2.
--- drivers/iio/magnetometer/st_magn_core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/st_magn_core.c +11 -2
@@ -506,6 +506,11 @@ static const struct st_sensors_platform_ .drdy_int_pin = 2, }; +/* LIS2MDL only supports DRDY on INT1 */ +static const struct st_sensors_platform_data alt_magn_pdata = { + .drdy_int_pin =1 , +}; +static int st_magn_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *ch,int *val,int *val2,long mask)
@@ -628,8 +633,12 @@ int st_magn_common_probe(struct iio_dev mdata->current_fullscale = &mdata->sensor_settings->fs.fs_avl[0 ]; mdata->odr = mdata->sensor_settings->odr.odr_avl[0 ].hz; -if (!pdata) - pdata = (struct st_sensors_platform_data *)&default_magn_pdata; +if (!pdata) { +if (mdata->sensor_settings->drdy_irq.int2.mask) + pdata = (struct st_sensors_platform_data *)&default_magn_pdata; +else + pdata = (struct st_sensors_platform_data *)&alt_magn_pdata; + } err =st_sensors_init_sensor (indio_dev, pdata);if (err <0 )
Greg Kroah-Hartman
maintainerPATCH 174/307 iio: light: cm3323: fix reg_conf not being initialized correctly
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Conte <[email protected]>
commit 1f4f0bcc5255dec5c4c3a1551bf49d8c33b69b20 upstream.
The code stores the return value of i2c_smbus_write_word_data() in data->reg_conf; however, this value represents the result of the write operation and not the value actually written to the configuration register. This meant that the contents of data->reg_conf did not truly reflect the contents
of the hardware register.
Instead, save the value of the register before the write and use this value in the I2C write.
The bug was found by code inspection: i2c_smbus_write_word_data() returns 0 on success, not the value written to the register.
Tested using i2c-stub on a Raspberry Pi 3B running a custom 6.19.10 kernel. Before loading the driver, the configuration register 0x00 CM3323_CMD_CONF was populated with 0x0030 usingi2cset -y 11 0x10 0x00 0x0030 w, encoding an integration time of 320ms in bits[6:4].
Due to incorrect initialization of data->reg_conf in cm3323_init(), the print of integration_time returns 0.040000 instead of the expected 0.320000. This happens because the read of the integration_time depends on cm3323_get_it_bits() that is based on the value of data->reg_conf, which is erroneously set to 0.
With this fix applied, data->reg_conf correctly saves 0x0030 after init and the successive integration_time reports 0.320000 as expected.
--- drivers/iio/light/cm3323.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/light/cm3323.c +2 -3
@@ -89,15 +89,14 @@ static int cm3323_init(struct iio_dev *i/* enable sensor and set auto force mode */ ret &= ~(CM3323_CONF_SD_BIT |CM3323_CONF_AF_BIT ); + data->reg_conf = ret; - ret =i2c_smbus_write_word_data (data->client,CM3323_CMD_CONF , ret); + ret =i2c_smbus_write_word_data (data->client,CM3323_CMD_CONF , data->reg_conf);if (ret <0 ) {dev_err (&data->client->dev,"Error writing reg_conf\n" );return ret; } - data->reg_conf = ret; -return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 175/307 iio: buffer: hw-consumer: fix use-after-free in error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
commit 6f5ed4f2c7c83f33344e0ba179f72a12e5dad4a4 upstream.
In the err_put_buffers cleanup path of iio_hw_consumer_alloc(), the code was using list_for_each_entry() to iterate through buffers while calling iio_buffer_put() which can free the current buffer if refcount drops to 0. The list_for_each_entry() loop macro then evaluates buf->head.next to continue iteration, accessing the freed buffer.
Fix this by using list_for_each_entry_safe().
--- drivers/iio/buffer/industrialio-hw-consumer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/buffer/industrialio-hw-consumer.c +2 -2
@@ -82,7 +82,7 @@ static struct hw_consumer_buffer *iio_hw*/ struct iio_hw_consumer *iio_hw_consumer_alloc (struct device *dev) { -struct hw_consumer_buffer *buf; +struct hw_consumer_buffer *buf, *tmp;struct iio_hw_consumer *hwc;struct iio_channel *chan;int ret;
@@ -113,7 +113,7 @@ struct iio_hw_consumer *iio_hw_consumer_return hwc; err_put_buffers: -list_for_each_entry (buf, &hwc->buffers, head) +list_for_each_entry_safe (buf, tmp, &hwc->buffers, head)iio_buffer_put (&buf->buffer);iio_channel_release_all (hwc->channels); err_free_hwc:
Greg Kroah-Hartman
maintainerPATCH 176/307 iio: buffer: Fix DMA fence leak in iio_buffer_enqueue_dmabuf()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benoît Monin <[email protected]>
commit a093999355084bdbfe6e97f1dd232e58a1525f0b upstream.
iio_buffer_enqueue_dmabuf() allocates a struct iio_dma_fence (104 bytes, kmalloc-128) via kmalloc_obj()+dma_fence_init(), which sets the initial kref to 1. It then calls dma_resv_add_fence() which takes a second reference (kref=2), and stores a raw pointer in block->fence.
On the success path the function returns without calling dma_fence_put() to release the initial reference, so every buffer enqueue permanently leaks one kmalloc-128 allocation.
The iio_buffer_cleanup() work item only releases the temporary reference taken during completion signalling by iio_buffer_signal_dmabuf_done(); the initial reference from dma_fence_init() is never released.
With four iio_rwdev instances at 240kHz and 512 samples per buffer, this produces ~1875 kmalloc-128 allocations per second matching the observed slab growth exactly. A test with ftrace confirmed that the dma_fence_destroy event was never triggered.
Fix by calling dma_fence_put() after dma_resv_add_fence(), transferring ownership of the fence to the DMA reservation object. The DMA fence then gets properly discarded after being signalled.
--- drivers/iio/industrialio-buffer.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/industrialio-buffer.c +1 -0
@@ -1911,6 +1911,7 @@ static int iio_buffer_enqueue_dmabuf(strdma_resv_add_fence (dmabuf->resv, &fence->base, dma_to_ram ?DMA_RESV_USAGE_WRITE :DMA_RESV_USAGE_READ ); +dma_fence_put (&fence->base);dma_resv_unlock (dmabuf->resv); cookie =dma_fence_begin_signalling ();
Greg Kroah-Hartman
maintainerPATCH 177/307 USB: serial: omninet: fix memory corruption with small endpoint
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 60df93d30f9bdd27db17c4d80ed80ef718d7226b upstream.
Make sure that the bulk-out buffers are at least as large as the hardcoded transfer size to avoid user-controlled slab corruption should a malicious device report a smaller endpoint max packet size than expected.
--- drivers/usb/serial/omninet.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/usb/serial/omninet.c +5 -4
@@ -30,6 +30,10 @@/* This one seems to be a re-branded ZyXEL device */ #define BT_IGNITIONPRO_ID 0x2000 +#define OMNINET_HEADERLEN 4 +#define OMNINET_BULKOUTSIZE 64 +#define OMNINET_PAYLOADSIZE (OMNINET_BULKOUTSIZE - OMNINET_HEADERLEN) +/* function prototypes */ static void omninet_process_read_urb (struct urb *urb); static int omninet_prepare_write_buffer(struct usb_serial_port *port,
@@ -54,6 +58,7 @@ static struct usb_serial_driver zyxel_om .description = "ZyXEL - omni.net usb", .id_table = id_table, .num_bulk_out = 2, + .bulk_out_size = OMNINET_BULKOUTSIZE, .calc_num_ports = omninet_calc_num_ports, .port_probe = omninet_port_probe, .port_remove = omninet_port_remove,
@@ -130,10 +135,6 @@ static void omninet_port_remove(struct ukfree (od); } -#define OMNINET_HEADERLEN 4 -#define OMNINET_BULKOUTSIZE 64 -#define OMNINET_PAYLOADSIZE (OMNINET_BULKOUTSIZE - OMNINET_HEADERLEN) -static void omninet_process_read_urb (struct urb *urb) {struct usb_serial_port *port = urb->context;
Greg Kroah-Hartman
maintainerPATCH 178/307 usb: cdns3: gadget: fix request skipping after clearing halt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongchao Wu <[email protected]>
commit c8778ff817a7047d6848fefba99dcb27b1bf01fe upstream.
According to the cdns3 datasheet, the EPRST (Endpoint Reset) command causes the DMA engine to reposition its internal pointer to the next Transfer Descriptor (TD) if it was already processing one.
This issue is consistently observed during the ADB identification process on macOS hosts, where the host issues a Clear_Halt. Although commit 4bf2dd65135a ("usb: cdns3: gadget: toggle cycle bit before reset endpoint") attempted to avoid DMA advance by toggling the cycle bit, trace logs show that on certain hosts like macOS, the DMA pointer (EP_TRADDR) still shifts after EPRST:
cdns3_ctrl_req: Clear Endpoint Feature(Halt ep1out)
cdns3_doorbell_epx: ep1out, ep_trbaddr f9c04030 <-- Should be f9c04000
cdns3_gadget_giveback: ep1out: req: ... length: 16384/16384
As shown above, the DMA pointer jumped to the next TD, causing the controller to skip the initial TRBs of the request. This leads to data misalignment and ADB protocol hangs on macOS.
Fix this by manually restoring the EP_TRADDR register to the starting physical address of the current request after the EPRST operation is complete.
--- drivers/usb/cdns3/cdns3-gadget.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/usb/cdns3/cdns3-gadget.c +11 -1
@@ -2817,9 +2817,19 @@ int __cdns3_gadget_ep_clear_halt(struct priv_ep->flags &= ~(EP_STALLED |EP_STALL_PENDING );if (request) { -if (trb) +if (trb) { *trb = trb_tmp; +/* +* Per datasheet, EPRST causes DMA to reposition to the next TD. +* Manually reset EP_TRADDR to the current TRB to prevent +* the hardware from skipping the interrupted request. +*/ +writel (EP_TRADDR_TRADDR (priv_ep->trb_pool_dma + + priv_req->start_trb *TRB_SIZE ), + &priv_dev->regs->ep_traddr); + } +cdns3_rearm_transfer (priv_ep,1 ); }
Greg Kroah-Hartman
maintainerPATCH 179/307 usb: cdns3: plat: fix leaked usb2_phy initialization on usb3_phy acquisition failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Chen <[email protected]>
commit e6970cda63fd4b4546aeed9d0e2f53a7c95cd09c upstream.
Move usb2_phy initialization after usb3_phy acquisition.
--- drivers/usb/cdns3/cdns3-plat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/cdns3/cdns3-plat.c +4 -4
@@ -126,15 +126,15 @@ static int cdns3_plat_probe(struct platfreturn dev_err_probe (dev,PTR_ERR (cdns->usb2_phy),"Failed to get cdn3,usb2-phy\n" ); - ret =phy_init (cdns->usb2_phy); -if (ret) -return ret; - cdns->usb3_phy =devm_phy_optional_get (dev,"cdns3,usb3-phy" );if (IS_ERR (cdns->usb3_phy))return dev_err_probe (dev,PTR_ERR (cdns->usb3_phy),"Failed to get cdn3,usb3-phy\n" ); + ret =phy_init (cdns->usb2_phy); +if (ret) +return ret; + ret =phy_init (cdns->usb3_phy);if (ret) goto err_phy3_init;
Greg Kroah-Hartman
maintainerPATCH 180/307 usb: cdns3: plat: fix unbalanced pm_runtime_forbid() call permanently leaks the runtime PM usage counter across bind/unbind cycles
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Chen <[email protected]>
commit ae6f3b82324e4f39ad8443c9020787e6fc889637 upstream.
Call pm_runtime_allow(dev) conditionally at cdns3_plat_remove.
--- drivers/usb/cdns3/cdns3-plat.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/cdns3/cdns3-plat.c +3 -0
@@ -188,6 +188,9 @@ static void cdns3_plat_remove(struct plastruct device *dev = cdns->dev;pm_runtime_get_sync (dev); +if (!(cdns->pdata && (cdns->pdata->quirks &CDNS3_DEFAULT_PM_RUNTIME_ALLOW ))) +pm_runtime_allow (dev); +pm_runtime_disable (dev);pm_runtime_put_noidle (dev);cdns_remove (cdns);
Greg Kroah-Hartman
maintainerPATCH 181/307 usb: dwc2: Fix use after free in debug code
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit 9ea06a3fbf9f16e0d98c52cb3b99642be15ec281 upstream.
We're not allowed to dereference "urb" after calling usb_hcd_giveback_urb() so save the urb->status ahead of time.
--- drivers/usb/dwc2/hcd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/dwc2/hcd.c +3 -1
@@ -4804,6 +4804,7 @@ static int _dwc2_hcd_urb_dequeue(structstruct dwc2_hsotg *hsotg =dwc2_hcd_to_hsotg (hcd);int rc;unsigned long flags; +int urb_status;dev_dbg (hsotg->dev,"DWC OTG HCD URB Dequeue\n" );dwc2_dump_urb_info (hcd, urb,"urb_dequeue" );
@@ -4828,11 +4829,12 @@ static int _dwc2_hcd_urb_dequeue(struct/* Higher layer software sets URB status */ spin_unlock (&hsotg->lock); + urb_status = urb->status;usb_hcd_giveback_urb (hcd, urb, status);spin_lock (&hsotg->lock);dev_dbg (hsotg->dev,"Called usb_hcd_giveback_urb()\n" ); -dev_dbg (hsotg->dev," urb->status = %d\n" , urb->status); +dev_dbg (hsotg->dev," urb->status = %d\n" , urb_status); out:spin_unlock_irqrestore (&hsotg->lock, flags);
Greg Kroah-Hartman
maintainerPATCH 182/307 Input: elan_i2c - validate firmware size before use
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 76b0d0baa9ae9c60e726bbe1b6ff0bec2c993634 upstream.
Ensure that the firmware file is large enough to contain the expected number of pages and the signature (which resides at the end of the firmware blob) before accessing them to prevent potential out-of-bounds reads.
--- drivers/input/mouse/elan_i2c_core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/input/mouse/elan_i2c_core.c +5 -0
@@ -645,6 +645,11 @@ static ssize_t elan_sysfs_update_fw(strureturn error; } +if (fw->size < data->fw_signature_address +sizeof (signature)) { +dev_err (dev,"firmware file too small\n" ); +return -EBADF ; + } +/* Firmware file must match signature data */ fw_signature = &fw->data[data->fw_signature_address];if (memcmp (fw_signature, signature,sizeof (signature)) !=0 ) {
Greg Kroah-Hartman
maintainerPATCH 183/307 wireguard: send: append trailer after expanding head
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason A. Donenfeld <[email protected]>
commit f75e3eb08fe31d30a9af6ed80cdd22e6772837e2 upstream.
With how this is currently written, we add the trailer, zero it out, and then add the header space on. If that header space requires a reallocation + copy, the zeros in the trailer aren't copied, because the skb len hasn't actually been yet expanded to cover that. Instead add the padding at the end of the process rather than at the beginning.
--- drivers/net/wireguard/send.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/net/wireguard/send.c +10 -10
@@ -177,16 +177,6 @@ static bool encrypt_packet(struct sk_buf trailer_len = padding_len +noise_encrypted_len (0 ); plaintext_len = skb->len + padding_len; -/* Expand data section to have room for padding and auth tag. */ - num_frags =skb_cow_data (skb, trailer_len, &trailer); -if (unlikely (num_frags <0 || num_frags >ARRAY_SIZE (sg))) -return false; - -/* Set the padding to zeros, and make sure it and the auth tag are part -* of the skb. -*/ -memset (skb_tail_pointer (trailer),0 , padding_len); -/* Expand head section to have room for our header and the network * stack's headers. */
@@ -198,6 +188,16 @@ static bool encrypt_packet(struct sk_buf skb_checksum_help(skb)))return false; +/* Expand data section to have room for padding and auth tag. */ + num_frags =skb_cow_data (skb, trailer_len, &trailer); +if (unlikely (num_frags <0 || num_frags >ARRAY_SIZE (sg))) +return false; + +/* Set the padding to zeros, and make sure it and the auth tag are part +* of the skb. +*/ +memset (skb_tail_pointer (trailer),0 , padding_len); +/* Only after checksumming can we safely add on the padding at the end * and the header. */
Greg Kroah-Hartman
maintainerPATCH 184/307 bpf: sockmap: fix tail fragment offset in bpf_msg_push_data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuqi Xu <[email protected]>
commit f72eed9b84fb771019a955908132410a9ba9ea3f upstream.
When bpf_msg_push_data() inserts data in the middle of a scatterlist entry, it splits the original entry into a left fragment and a right fragment.
The right fragment offset is page-local, but the code advances it with start, which is the message-global insertion point. For inserts into a non-first SG entry, this over-advances the offset and leaves the split layout inconsistent.
Advance the right fragment offset by the fragment-local delta, start - offset, which matches the length removed from the front of the original entry.
--- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
@@ -2867,7 +2867,7 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_ psge->length = start - offset; rsge.length -= psge->length; - rsge.offset += start; + rsge.offset += start - offset;sk_msg_iter_var_next (i);sg_unmark_end (psge);
Greg Kroah-Hartman
maintainerPATCH 185/307 macsec: fix replay protection at XPN lower-PN wrap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
commit e68842b3356471ba56c882209f324613dac47f64 upstream.
In macsec_post_decrypt(), when pn is U32_MAX, pn + 1 overflows u32 to 0 and the first branch never fires. If next_pn_halves.lower is also in the upper half, pn_same_half(pn, lower) is true and the XPN else-if does not fire either, leaving next_pn_halves unchanged. An attacker that captures the legitimate frame carrying pn == 0xFFFFFFFF on an XPN association can then replay it indefinitely, since lowest_pn never rises above the captured pn and macsec_decrypt() reconstructs the same IV.
Extend the XPN else-if to also fire when pn + 1 wraps to 0, so receipt of pn == U32_MAX advances next_pn_halves to (upper + 1, 0).
--- drivers/net/macsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/macsec.c +2 -1
@@ -803,7 +803,8 @@ static bool macsec_post_decrypt(struct sif (pn +1 > rx_sa->next_pn_halves.lower) { rx_sa->next_pn_halves.lower = pn +1 ; }else if (secy->xpn && - !pn_same_half (pn, rx_sa->next_pn_halves.lower)) { + (pn +1 ==0 || + !pn_same_half (pn, rx_sa->next_pn_halves.lower))) { rx_sa->next_pn_halves.upper++; rx_sa->next_pn_halves.lower = pn +1 ; }
Greg Kroah-Hartman
maintainerPATCH 186/307 ipv6: exthdrs: refresh nh pointer after ipv6_hop_jumbo()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Iurman <[email protected]>
commit d47548a36639095939f4747d4c43f2271366f565 upstream.
ipv6_hop_jumbo() calls pskb_trim_rcsum(), which can change skb pointers. Let's recompute nh pointer to make sure any change won't mess things up.
--- net/ipv6/exthdrs.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/exthdrs.c +2 -0
@@ -184,6 +184,8 @@ static bool ip6_parse_tlv(bool hopbyhop,case IPV6_TLV_JUMBO :if (!ipv6_hop_jumbo (skb, off))return false; + + nh =skb_network_header (skb);break ;case IPV6_TLV_CALIPSO :if (!ipv6_hop_calipso (skb, off))
Greg Kroah-Hartman
maintainerPATCH 187/307 ASoC: qcom: q6asm-dai: fix error handling in prepare and set_params
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
commit 4b4db09f283df65d780bc7cee66cb4a7e9bf4770 upstream.
Fix error handling in q6asm_dai_compr_set_params() and q6asm_dai_prepare() for both CMD_CLOSE and q6asm_unmap_memory_regions().
In both the functions, we are doing q6asm_audio_client_free in failure cases, which means if prepare or set_params fail, we can never recover. Now open and close are done in respective dai_open/close functions.
--- sound/soc/qcom/qdsp6/q6asm-dai.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
sound/soc/qcom/qdsp6/q6asm-dai.c +16 -8
@@ -234,9 +234,19 @@ static int q6asm_dai_prepare(struct snd_/* rate and channels are sent to audio driver */ if (prtd->state ==Q6ASM_STREAM_RUNNING ) {/* clear the previous setup if any */ -q6asm_cmd (prtd->audio_client, prtd->stream_id,CMD_CLOSE ); -q6asm_unmap_memory_regions (substream->stream, - prtd->audio_client); + ret =q6asm_cmd (prtd->audio_client, prtd->stream_id,CMD_CLOSE ); +if (ret <0 ) { +dev_err (dev,"Failed to close q6asm stream %d\n" , prtd->stream_id); +return ret; + } + + ret =q6asm_unmap_memory_regions (substream->stream, prtd->audio_client); +if (ret <0 ) { +dev_err (dev,"Failed to unmap memory regions for q6asm stream %d\n" , + prtd->stream_id); +return ret; + } +q6routing_stream_close (soc_prtd->dai_link->id, substream->stream); prtd->state =Q6ASM_STREAM_STOPPED ;
@@ -304,8 +314,6 @@ routing_err:q6asm_cmd (prtd->audio_client, prtd->stream_id,CMD_CLOSE ); open_err:q6asm_unmap_memory_regions (substream->stream, prtd->audio_client); -q6asm_audio_client_free (prtd->audio_client); - prtd->audio_client =NULL ;return ret; }
@@ -902,7 +910,7 @@ static int q6asm_dai_compr_set_params(st prtd->session_id, dir);if (ret) {dev_err (dev,"Stream reg failed ret:%d\n" , ret); - goto q6_err; + goto routing_err; } ret = __q6asm_dai_compr_set_codec_params(component, stream,
@@ -928,11 +936,11 @@ static int q6asm_dai_compr_set_params(streturn 0 ; q6_err: +q6routing_stream_close (rtd->dai_link->id, dir); +routing_err:q6asm_cmd (prtd->audio_client, prtd->stream_id,CMD_CLOSE ); open_err: -q6asm_audio_client_free (prtd->audio_client); - prtd->audio_client =NULL ;return ret; }
Greg Kroah-Hartman
maintainerPATCH 188/307 ipv6: exthdrs: refresh nh after handling HAO option
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhengchuan Liang <[email protected]>
commit f7b52afe3592eae66e160586b45a3f2242972c63 upstream.
ip6_parse_tlv() caches skb_network_header(skb) in nh while walking IPv6 TLVs.
ipv6_dest_hao() may call pskb_expand_head() for a cloned skb, which can move the skb head and invalidate the cached network header pointer. Refresh nh after ipv6_dest_hao() returns so any trailing padding or TLVs are parsed from the current skb head.
This matches the existing pattern used in ip6_parse_tlv() after helpers that can modify skb header storage.
--- net/ipv6/exthdrs.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/exthdrs.c +2 -0
@@ -203,6 +203,8 @@ static bool ip6_parse_tlv(bool hopbyhop,case IPV6_TLV_HAO :if (!ipv6_dest_hao (skb, off))return false; + + nh =skb_network_header (skb);break ;#endif default :
Greg Kroah-Hartman
maintainerPATCH 189/307 ip6: vti: Use ip6_tnl.net in vti6_siocdevprivate().
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 8b484efd5cb4eeef9021a661e198edc5349dacf6 upstream.
After patch 1/2 in this series, vti6_update() unlinks and relinks the tunnel through t->net. vti6_siocdevprivate() still uses dev_net(dev) for the collision lookup. For a tunnel moved through IFLA_NET_NS_FD, dev_net(dev) is the new netns, not t->net.
SIOCCHGTUNNEL on a migrated tunnel then runs:
net = dev_net(dev) /* migrated netns */
t = vti6_locate(net, &p1, false) /* misses target in t->net */
...
t = netdev_priv(dev)
vti6_update(t, &p1, false) /* mutates t->net's hash */
A caller in the migrated netns picks params that match a tunnel in the creation netns. The lookup in dev_net(dev) finds nothing. vti6_update() prepends the migrated tunnel at the head of the creation netns hash bucket for those params. Later lookups in the creation netns resolve to the migrated device. xfrm receive delivers the matched packets through a device the caller controls.
Reachable from an unprivileged user namespace (unshare --user --map-root-user --net). Cross tenant scope on container hosts.
Switch the SIOCCHGTUNNEL path on a non fallback device to use t->net for the lookup. The lookup now matches the netns vti6_update() operates on.
Also add ns_capable(self->net->user_ns, CAP_NET_ADMIN) before the lookup. The check at the top of the case is against dev_net(dev)->user_ns, which after migration is the attacker's netns. A caller there can pick params absent from self->net, the lookup returns NULL, t becomes self, and vti6_update() inserts the device into the creation netns hash. The new check requires CAP_NET_ADMIN in the creation netns user_ns too.
SIOCADDTUNNEL and SIOCCHGTUNNEL on the fallback device keep dev_net(dev), which equals init_net there.
--- net/ipv6/ip6_vti.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/ipv6/ip6_vti.c +9 -2
@@ -834,17 +834,24 @@ vti6_siocdevprivate(struct net_device *dif (p.proto !=IPPROTO_IPV6 && p.proto !=0 )break ;vti6_parm_from_user (&p1, &p); - t =vti6_locate (net, &p1, cmd ==SIOCADDTUNNEL );if (dev != ip6n->fb_tnl_dev && cmd ==SIOCCHGTUNNEL ) { +struct ip6_tnl *self =netdev_priv (dev); + + err = -EPERM ; +if (!ns_capable (self->net->user_ns,CAP_NET_ADMIN )) +break ; + t =vti6_locate (self->net, &p1, false);if (t) {if (t->dev != dev) { err = -EEXIST ;break ; } }else - t =netdev_priv (dev); + t = self; err =vti6_update (t, &p1, false); + }else { + t =vti6_locate (net, &p1, cmd ==SIOCADDTUNNEL ); }if (t) { err =0 ;
Greg Kroah-Hartman
maintainerPATCH 190/307 ipv6: validate extension header length before copying to cmsg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qi Tang <[email protected]>
commit dd433671fef381fdaf7b530c631e6b782d66e224 upstream.
ip6_datagram_recv_specific_ctl() builds IPV6_{HOPOPTS,DSTOPTS,RTHDR} cmsgs (and their IPV6_2292* legacy counterparts) by trusting the on-wire hdrlen byte (ptr[1]) when computing the put_cmsg() length. The length was validated only at parse time (ipv6_parse_hopopts(), etc.). An nftables payload-write expression can rewrite hdrlen after parsing and before the skb reaches recvmsg; the write itself is in-bounds but put_cmsg() then reads up to ((hdrlen+1) << 3) = 2040 bytes from an 8-byte header. nftables is reachable from an unprivileged user namespace, so this is an unprivileged slab-out-of-bounds read:
BUG: KASAN: slab-out-of-bounds in put_cmsg+0x3ac/0x540 put_cmsg+0x3ac/0x540 udpv6_recvmsg+0xca0/0x1250 sock_recvmsg+0xdf/0x190 ____sys_recvmsg+0x1b1/0x620
Add ipv6_get_exthdr_len() which validates that at least two bytes are accessible before reading the hdrlen field, then checks the computed length against skb_tail_pointer(skb), returning 0 on failure. Extension headers are kept in the linear skb area by pskb_may_pull() during input, so skb_tail_pointer() is the correct bound.
Use ipv6_get_exthdr_len() at all non-AH call sites: the five standalone cmsg blocks (HbH, 2292HbH, 2292DSTOPTS x2, 2292RTHDR) and the three standard cases in the extension-header walk loop (DSTOPTS, ROUTING, default). AH retains an inline bounds check because its length formula differs ((ptr[1]+2)<<2).
The walk loop also gets a pre-read bounds check at the top to validate ptr before any case accesses ptr[0] or ptr[1].
When the walk loop detects a corrupted header, return from the function instead of continuing to process later socket options.
--- net/ipv6/datagram.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-)
net/ipv6/datagram.c +46 -8
@@ -617,6 +617,18 @@ void ip6_datagram_recv_common_ctl(struct } } +static u16 ipv6_get_exthdr_len (const struct sk_buff *skb,const u8 *ptr) +{ +u16 len; + +if (ptr +2 >skb_tail_pointer (skb)) +return 0 ; + + len = (ptr[1 ] +1 ) <<3 ; + +return (len <=skb_tail_pointer (skb) - ptr) ? len :0 ; +} +void ip6_datagram_recv_specific_ctl (struct sock *sk,struct msghdr *msg,struct sk_buff *skb) {
@@ -643,7 +655,10 @@ void ip6_datagram_recv_specific_ctl(stru/* HbH is allowed only once */ if (np->rxopt.bits.hopopts && (opt->flags &IP6SKB_HOPBYHOP )) {u8 *ptr = nh +sizeof (struct ipv6hdr ); -put_cmsg (msg,SOL_IPV6 ,IPV6_HOPOPTS , (ptr[1 ]+1 )<<3 , ptr); +u16 len =ipv6_get_exthdr_len (skb, ptr); + +if (len) +put_cmsg (msg,SOL_IPV6 ,IPV6_HOPOPTS , len, ptr); } if (opt->lastopt &&
@@ -664,26 +679,37 @@ void ip6_datagram_recv_specific_ctl(struunsigned int len;u8 *ptr = nh + off; +if (ptr +2 >skb_tail_pointer (skb)) +return ; +switch (nexthdr) {case IPPROTO_DSTOPTS : nexthdr = ptr[0 ]; - len = (ptr[1 ] +1 ) <<3 ; + len =ipv6_get_exthdr_len (skb, ptr); +if (!len) +return ;if (np->rxopt.bits.dstopts)put_cmsg (msg,SOL_IPV6 ,IPV6_DSTOPTS , len, ptr);break ;case IPPROTO_ROUTING : nexthdr = ptr[0 ]; - len = (ptr[1 ] +1 ) <<3 ; + len =ipv6_get_exthdr_len (skb, ptr); +if (!len) +return ;if (np->rxopt.bits.srcrt)put_cmsg (msg,SOL_IPV6 ,IPV6_RTHDR , len, ptr);break ;case IPPROTO_AH : nexthdr = ptr[0 ]; len = (ptr[1 ] +2 ) <<2 ; +if (ptr + len >skb_tail_pointer (skb)) +return ;break ;default : nexthdr = ptr[0 ]; - len = (ptr[1 ] +1 ) <<3 ; + len =ipv6_get_exthdr_len (skb, ptr); +if (!len) +return ;break ; }
@@ -705,19 +731,31 @@ void ip6_datagram_recv_specific_ctl(stru }if (np->rxopt.bits.ohopopts && (opt->flags &IP6SKB_HOPBYHOP )) {u8 *ptr = nh +sizeof (struct ipv6hdr ); -put_cmsg (msg,SOL_IPV6 ,IPV6_2292HOPOPTS , (ptr[1 ]+1 )<<3 , ptr); +u16 len =ipv6_get_exthdr_len (skb, ptr); + +if (len) +put_cmsg (msg,SOL_IPV6 ,IPV6_2292HOPOPTS , len, ptr); }if (np->rxopt.bits.odstopts && opt->dst0) {u8 *ptr = nh + opt->dst0; -put_cmsg (msg,SOL_IPV6 ,IPV6_2292DSTOPTS , (ptr[1 ]+1 )<<3 , ptr); +u16 len =ipv6_get_exthdr_len (skb, ptr); + +if (len) +put_cmsg (msg,SOL_IPV6 ,IPV6_2292DSTOPTS , len, ptr); }if (np->rxopt.bits.osrcrt && opt->srcrt) {struct ipv6_rt_hdr *rthdr = (struct ipv6_rt_hdr *)(nh + opt->srcrt); -put_cmsg (msg,SOL_IPV6 ,IPV6_2292RTHDR , (rthdr->hdrlen+1 ) <<3 , rthdr); +u16 len =ipv6_get_exthdr_len (skb, (u8 *)rthdr); + +if (len) +put_cmsg (msg,SOL_IPV6 ,IPV6_2292RTHDR , len, rthdr); }if (np->rxopt.bits.odstopts && opt->dst1) {u8 *ptr = nh + opt->dst1; -put_cmsg (msg,SOL_IPV6 ,IPV6_2292DSTOPTS , (ptr[1 ]+1 )<<3 , ptr); +u16 len =ipv6_get_exthdr_len (skb, ptr); + +if (len) +put_cmsg (msg,SOL_IPV6 ,IPV6_2292DSTOPTS , len, ptr); }if (np->rxopt.bits.rxorigdstaddr) {struct sockaddr_in6 sin6;
Greg Kroah-Hartman
maintainerPATCH 191/307 xfrm: input: hold netns during deferred transport reinjection
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhengchuan Liang <[email protected]>
commit c16f74dc1d75d0e2e7670076d5375deda110ebeb upstream.
Transport-mode reinjection stores a struct net pointer in skb->cb and uses it later from xfrm_trans_reinject(). That pointer must stay valid until the deferred callback runs.
Take a netns reference when queueing deferred reinjection work and drop it after the callback completes. Use maybe_get_net() so the queueing path does not revive a namespace that is already being torn down.
This keeps the existing workqueue design and fixes the netns lifetime handling in one place for all users of xfrm_trans_queue_net().
--- net/xfrm/xfrm_input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
net/xfrm/xfrm_input.c +12 -4
@@ -769,9 +769,12 @@ static void xfrm_trans_reinject(struct wspin_unlock_bh (&trans->queue_lock);local_bh_disable (); -while ((skb =__skb_dequeue (&queue))) -XFRM_TRANS_SKB_CB (skb)->finish (XFRM_TRANS_SKB_CB (skb)->net, -NULL , skb); +while ((skb =__skb_dequeue (&queue))) { +struct net *net =XFRM_TRANS_SKB_CB (skb)->net; + +XFRM_TRANS_SKB_CB (skb)->finish (net,NULL , skb); +put_net (net); + }local_bh_enable (); }
@@ -780,6 +783,7 @@ int xfrm_trans_queue_net(struct net *net struct sk_buff *)) {struct xfrm_trans_tasklet *trans; +struct net *hold_net; trans =this_cpu_ptr (&xfrm_trans_tasklet);
@@ -788,8 +792,12 @@ int xfrm_trans_queue_net(struct net *netBUILD_BUG_ON (sizeof (struct xfrm_trans_cb ) >sizeof (skb->cb)); + hold_net =maybe_get_net (net); +if (!hold_net) +return -ENODEV ; +XFRM_TRANS_SKB_CB (skb)->finish = finish; -XFRM_TRANS_SKB_CB (skb)->net = net; +XFRM_TRANS_SKB_CB (skb)->net = hold_net;spin_lock_bh (&trans->queue_lock);__skb_queue_tail (&trans->queue, skb);spin_unlock_bh (&trans->queue_lock);
Greg Kroah-Hartman
maintainerPATCH 192/307 l2tp: use refcount_inc_not_zero in l2tp_session_get_by_ifname
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 05f95729ca844704d15e49ce14868af4b403b32b upstream.
A reader in l2tp_session_get_by_ifname() can return a pointer to a session whose refcount has reached zero. The getter takes its reference with plain refcount_inc(), but every other session getter in the same file (l2tp_v2_session_get, l2tp_v3_session_get, and the corresponding _get_next variants) uses refcount_inc_not_zero() because the IDR/RCU lookup can race with refcount_dec_and_test() -> l2tp_session_free() -> kfree_rcu(). The ifname getter is the only outlier; the inconsistency was raised on-list after 979c017803c4 ("l2tp: use list_del_rcu in l2tp_session_unhash").
A reader inside rcu_read_lock_bh() that matches session->ifname can be preempted between the strcmp() and the refcount_inc(). If the last reference drops on another CPU in that window, the reader's refcount_inc() runs on a counter that has reached zero. refcount_t catches the addition-on-zero, prints "refcount_t: addition on 0; use-after-free", saturates the counter, and returns the saturated pointer to the caller. Session memory is held live by the in-flight RCU read section, but the kfree_rcu() callback queued from l2tp_session_free() will free it once the grace period closes; a caller that dereferences the returned session past that point hits a slab-use-after-free. On PREEMPT_RT local_bh_disable() is a per-CPU sleeping lock and the preemption window is real; on stock PREEMPT kernels local_bh_disable() is a preempt_count increment that closes the cross-CPU race in practice (see below).
Use refcount_inc_not_zero() and continue the list walk on failure, matching the other session getters in the file. The ifname getter is the only session getter in net/l2tp/ that still uses the bare refcount_inc() pattern; this change restores file-internal consistency. The success path is unchanged.
--- net/l2tp/l2tp_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/l2tp/l2tp_core.c +6 -5
@@ -441,12 +441,13 @@ struct l2tp_session *l2tp_session_get_byidr_for_each_entry_ul (&pn->l2tp_tunnel_idr, tunnel, tmp, tunnel_id) {if (tunnel) {list_for_each_entry_rcu (session, &tunnel->session_list, list) { -if (!strcmp (session->ifname, ifname)) { -refcount_inc (&session->ref_count); -rcu_read_unlock_bh (); +if (strcmp (session->ifname, ifname)) +continue ; +if (!refcount_inc_not_zero (&session->ref_count)) +continue ; +rcu_read_unlock_bh (); -return session; - } +return session; } } }