6.12.120-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 100/816 bpf, cgroup: Keep the skb network offset signed
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 3f9780d62dd1112ca15b5ae73568d29d42ccc950 ]
cgroup_skb progs see a packet from its network header. While they run, __cgroup_bpf_run_filter_skb() moves skb->data there. It assumes that the network header is not after skb->data. It negates skb_network_offset(skb) and pushes skb->data by this offset. The offset is an unsigned int.
But ip6mr_cache_report() and bpf_lwt_xmit_reroute() can pass an skb that has data before the network header. Then the offset wraps. On a 64-bit kernel skb->data is then far below skb->head.
skb->len has 32 bits and wraps to the correct value, thus only skb->data is wrong. A read of packet data faults or gets other memory.
Keep the offset in an int. Pull skb->data when the network header is after it. Otherwise push it, as today.
--- kernel/bpf/cgroup.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
kernel/bpf/cgroup.c +14 -3
@@ -1577,7 +1577,7 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk,struct sk_buff *skb, enum cgroup_bpf_attach_type atype) { - unsigned int offset = -skb_network_offset(skb); + int offset = skb_network_offset(skb);struct sock *save_sk;void *saved_data_end;struct cgroup *cgrp;
@@ -1589,7 +1589,15 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk, cgrp =sock_cgroup_ptr (&sk->sk_cgrp_data); save_sk = skb->sk; skb->sk = sk; -__skb_push (skb, offset); + +/* +* The program sees the packet from its network header on, on +* whichever side of skb->data that header lies. +*/ +if (offset >0 ) +__skb_pull (skb, offset); +else +__skb_push (skb, -offset);/* compute pointers for the bpf prog */ bpf_compute_and_save_data_end (skb, &saved_data_end);
@@ -1631,7 +1639,10 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk, ret = -EFAULT ; }bpf_restore_data_end (skb, saved_data_end); -__skb_pull (skb, offset); +if (offset >0 ) +__skb_push (skb, offset); +else +__skb_pull (skb, -offset); skb->sk = save_sk;return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 101/816 bpf: Dont let bpf_skb_adjust_room() raise gso_size to GSO_BY_FRAGS
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 6d8118937ba477e03fa2e94e9bd9abac7291a2a2 ]
When bpf_skb_adjust_room() shrinks a TCP GSO skb, it adds the number of removed bytes to gso_size. gso_size has 16 bits, and nothing checks the sum. Thus gso_size can wrap to 0 or to a small size, or it can be GSO_BY_FRAGS. GSO_BY_FRAGS is not a size. It tells skb_segment() to read the length of each segment from the frag_list. If the TCP GSO skb has no frag_list, skb_segment() dereferences a NULL pointer.
Return -ENOTSUPP and do not change the skb if the sum is GSO_BY_FRAGS or larger. With BPF_F_ADJ_ROOM_FIXED_GSO the helper does not change gso_size, so it shrinks the skb as before.
--- net/core/filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/filter.c +8 -0
@@ -3691,6 +3691,14 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,return -ENOTSUPP ; } +/* +* The MSS is raised by len_diff. It has 16 bits, and GSO_BY_FRAGS is +* not a size. +*/ +if (skb_is_gso (skb) && !(flags &BPF_F_ADJ_ROOM_FIXED_GSO ) && +skb_shinfo (skb)->gso_size + len_diff >=GSO_BY_FRAGS ) +return -ENOTSUPP ; + ret =skb_unclone (skb,GFP_ATOMIC );if (unlikely (ret <0 ))return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 102/816 bpf: Reject non-IPv6 packets in BPF_LWT_ENCAP_SEG6
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 58e39f8d58b141b96c030008a20dde9d625ec997 ]
The mode BPF_LWT_ENCAP_SEG6 of bpf_lwt_push_encap() pushes an IPv6 header and an SRH, and it replaces the dst. The SRH says that IPv6 follows, and skb->protocol does not change. Thus the mode assumes an IPv6 packet, but an lwt_in prog also runs for IPv4 packets. After the prog, bpf_input() calls orig_input() of the old dst. This IPv4 handler reads the pushed headers as IPv4. It can write after the packet data, and the kernel crashes.
after the push orig_input() expects
--------------------- --------------------
skb->protocol ETH_P_IP ETH_P_IP
dst rt6_info rtable
packet | IPv6 | SRH | IPv4 | | IPv4 |The mode BPF_LWT_ENCAP_SEG6_INLINE returns -EBADMSG for non-IPv6 packets. Apply this check to both modes. End.BPF does not change, because seg6_local_input() drops non-IPv6 packets.
--- net/core/filter.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/core/filter.c +7 -3
@@ -6524,11 +6524,15 @@ static int bpf_push_seg6_encap(struct sk_buff *skb, u32 type, void *hdr, u32 lenif (!seg6_validate_srh (srh, len, false))return -EINVAL ; +/* +* The encap mode names IPv6 as the inner protocol, and neither mode +* updates skb->protocol. +*/ +if (skb->protocol !=htons (ETH_P_IPV6 )) +return -EBADMSG ; +switch (type) {case BPF_LWT_ENCAP_SEG6_INLINE : -if (skb->protocol !=htons (ETH_P_IPV6 )) -return -EBADMSG ; - err =seg6_do_srh_inline (skb, srh);break ;case BPF_LWT_ENCAP_SEG6 :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 103/816 bpf: Limit the SRH length in bpf_lwt_seg6_adjust_srh()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit ac159f39b252971141c49b68a27de0b637debfad ]
bpf_lwt_seg6_adjust_srh() lets an End.BPF prog change the size of the TLVs in the SRH. The helper keeps the SRH length in srh_state->hdrlen, in bytes and without the first 8 bytes. Later seg6_bpf_has_valid_srh() writes it to srh->hdrlen, an 8-bit field in units of 8 bytes. But srh_state->hdrlen has no upper limit, and the cast to u8 can truncate it. After that, seg6_validate_srh() gets the SRH length from srh->hdrlen, and thus it can accept the SRH. Then srh->hdrlen is too small, and a parser reads TLVs as the subsequent header.
Return -EFAULT when the new srh_state->hdrlen is larger than 2040, the largest length that srh->hdrlen can hold. To replace a TLV in the largest SRH, a prog can no longer add bytes first. It must remove bytes first.
--- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/filter.c +3 -0
@@ -6776,6 +6776,9 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset,return -EFAULT ;if (unlikely (len <0 && (void *)((char *)ptr - len) > srh_end))return -EFAULT ; +/* The length field of the SRH has 8 bits, in units of 8 bytes. */ +if (unlikely (len > (U8_MAX <<3 ) - srh_state->hdrlen)) +return -EFAULT ;if (len >0 ) { ret =skb_cow_head (skb, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 104/816 bpf: Dont look for the SRH again in the End.BPF helpers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 45bcc58d576705d2c001332766e10313f1c55bad ]
A packet can have two SRHs. Thus input_action_end_bpf() uses IP6_FH_F_SKIP_RH to skip routing headers with segments_left 0. The helpers bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_adjust_srh() can reallocate the head of the skb. Thus they look for the SRH again, but without this flag.
+------------------------+ <- the helpers: srh_state->srh | SRH 1, segments_left 0 | +------------------------+ <- input_action_end_bpf(): srh_state->srh | SRH 2 | and srh_state->hdrlen +------------------------+
Then the helpers check offset against the wrong limits. If a helper changes TLVs, seg6_bpf_has_valid_srh() writes the length of SRH 2 to SRH 1.
Neither helper changes the offset of the SRH from skb->data. Calculate the new address from this offset. To add IP6_FH_F_SKIP_RH is not sufficient, because advance_nextseg() can set segments_left of SRH 2 to 0. The helper bpf_lwt_seg6_action() can change the headers and still looks for the SRH.
--- net/core/filter.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/core/filter.c +6 -6
@@ -6621,12 +6621,13 @@ BPF_CALL_4(bpf_lwt_seg6_store_bytes, struct sk_buff *, skb, u32, offset,this_cpu_ptr (&seg6_bpf_srh_states);struct ipv6_sr_hdr *srh = srh_state->srh;void *srh_tlvs, *srh_end, *ptr; -int srhoff =0 ; +int srhoff;lockdep_assert_held (&srh_state->bh_lock);if (srh ==NULL )return -EINVAL ; + srhoff = (unsigned char *)srh - skb->data; srh_tlvs = (void *)((char *)srh + ((srh->first_segment +1 ) <<4 )); srh_end = (void *)((char *)srh +sizeof (*srh) + srh_state->hdrlen);
@@ -6639,8 +6640,7 @@ BPF_CALL_4(bpf_lwt_seg6_store_bytes, struct sk_buff *, skb, u32, offset,if (unlikely (bpf_try_make_writable (skb, offset + len)))return -EFAULT ; -if (ipv6_find_hdr (skb, &srhoff,IPPROTO_ROUTING ,NULL ,NULL ) <0 ) -return -EINVAL ; +/* The head may have moved. */ srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);memcpy (skb->data + offset, from, len);
@@ -6759,13 +6759,14 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset,struct ipv6_sr_hdr *srh = srh_state->srh;void *srh_end, *srh_tlvs, *ptr;struct ipv6hdr *hdr; -int srhoff =0 ; +int srhoff;int ret;lockdep_assert_held (&srh_state->bh_lock);if (unlikely (srh ==NULL ))return -EINVAL ; + srhoff = (unsigned char *)srh - skb->data; srh_tlvs = (void *)((unsigned char *)srh +sizeof (*srh) + ((srh->first_segment +1 ) <<4 )); srh_end = (void *)((unsigned char *)srh + sizeof(*srh) +
@@ -6797,8 +6798,7 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, hdr = (struct ipv6hdr *)skb->data; hdr->payload_len =htons (skb->len -sizeof (struct ipv6hdr )); -if (ipv6_find_hdr (skb, &srhoff,IPPROTO_ROUTING ,NULL ,NULL ) <0 ) -return -EINVAL ; +/* The bytes in front of offset have moved together with skb->data. */ srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); srh_state->hdrlen += len; srh_state->valid = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 105/816 bpf: Move the MAC header in bpf_lwt_seg6_adjust_srh()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 0fcb3f11a93d740e7f9ae1aeb48fe4d25838be18 ]
bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() change skb->data and skb->mac_header by len. That is correct in a tc prog, where skb->data is the MAC header. But bpf_lwt_seg6_adjust_srh() calls them in an End.BPF prog, where skb->data is the network header. The MAC header does not move:
before push | free | MAC header | IPv6 | SRH | payload
^ head ^ mac_header ^ data
today | free | MAC h| IPv6 | SRH + len | payload
^ head ^ mac_header ^ data
this patch | free | MAC header | IPv6 | SRH + len | payload
^ head ^ mac_header ^ dataUsers of skb_mac_header() get incorrect bytes until __dev_queue_xmit() sets skb->mac_header again. skb_cow_head() reserves only len bytes. Thus the 16-bit offset skb->mac_header can wrap. A push also changes the "not set" value. In both cases skb_mac_header() points after the skb.
Move the MAC header too. Pass len + skb->mac_len to skb_cow_head(). Keep the "not set" value. The second Fixes tag is for this case. Since that commit an End.BPF prog can get an skb with skb->mac_header not set.
--- net/core/filter.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/core/filter.c +20 -1
@@ -6756,6 +6756,7 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, {struct seg6_bpf_srh_state *srh_state =this_cpu_ptr (&seg6_bpf_srh_states); +bool mac_set =skb_mac_header_was_set (skb);struct ipv6_sr_hdr *srh = srh_state->srh;void *srh_end, *srh_tlvs, *ptr;struct ipv6hdr *hdr;
@@ -6781,20 +6782,38 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset,if (unlikely (len > (U8_MAX <<3 ) - srh_state->hdrlen))return -EFAULT ; +/* +* skb->data is the network header here. The MAC header is in front of +* it, so bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() do not move +* it with the other headers. +*/ if (len >0 ) { - ret =skb_cow_head (skb, len); + ret =skb_cow_head (skb, len + skb->mac_len);if (unlikely (ret <0 ))return ret; +/* The push can write over the MAC header, so move it first. */ +if (mac_set) +memmove (skb->data - len - skb->mac_len, +skb_mac_header (skb), skb->mac_len); ret =bpf_skb_net_hdr_push (skb, offset, len); }else { ret =bpf_skb_net_hdr_pop (skb, offset,-1 * len); +/* The pop has added -len to skb->mac_header. */ +if (likely (!ret) && mac_set) +memmove (skb->data - skb->mac_len, +skb_mac_header (skb) + len, skb->mac_len); }bpf_compute_data_pointers (skb);if (unlikely (ret <0 ))return ret; +if (mac_set) +skb_set_mac_header (skb, -skb->mac_len); +else +skb_unset_mac_header (skb); + hdr = (struct ipv6hdr *)skb->data; hdr->payload_len =htons (skb->len -sizeof (struct ipv6hdr ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 106/816 bpf: Dont leave a stale MAC header in bpf_lwt_push_ip_encap()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 701ffd202b9e32942c8cfc065c9fe76ceaccc302 ]
With BPF_LWT_ENCAP_IP, bpf_lwt_push_encap() pushes a new IP header. The new header overwrites the MAC header of a received skb. But skb->mac_header continues to point to the same bytes. Code that reads the MAC header after the push, for example netfilter, gets bytes of the new header.
before the push | MAC header | old IP | payload
^ mac_header ^ network_header
today | new header | old IP | payload
network_header ^ ^ mac_header
this patch, lwt_in | MAC header | new header | old IP | payload
^ mac_header ^ network_header
this patch, lwt_xmit | new header | old IP | payload network_header ^ mac_header is not set
For lwt_in, move the MAC header in front of the new header before the memcpy(), as __seg6_do_srh_encap() does. skb_cow_head() already reserves len + skb->mac_len bytes.
For lwt_xmit, the output path makes a new MAC header. Thus mark skb->mac_header as not set. This is the state of a locally generated skb.
--- net/core/lwt_bpf.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/lwt_bpf.c +8 -0
@@ -642,6 +642,14 @@ int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress)if (ingress)skb_postpush_rcsum (skb, iph, len);skb_reset_network_header (skb); +/* +* The new header goes over the MAC header. On ingress move it first. +* On egress the packet gets a new one, so forget the old one. +*/ +if (ingress) +skb_mac_header_rebuild (skb); +else +skb_unset_mac_header (skb);if (is_udp_tunnel) {size_t iph_sz = ipv4 ? iph->ihl *4 :sizeof (struct ipv6hdr );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 107/816 ipv4: Convert ip_route_input_noref() to dscp_t.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
[ Upstream commit 66fb6386d358a04edd5c640e38b4a02b323b89d8 ]
Pass a dscp_t variable to ip_route_input_noref(), instead of a plain u8, to prevent accidental setting of ECN bits in ->flowi4_tos.
Callers of ip_route_input_noref() to consider are:
* arp_process() in net/ipv4/arp.c. This function sets the tos parameter to 0, which is already a valid dscp_t value, so it doesn't need to be adjusted for the new prototype.
* ip_route_input(), which already has a dscp_t variable to pass as parameter. We just need to remove the inet_dscp_to_dsfield() conversion.
* ipvlan_l3_rcv(), bpf_lwt_input_reroute(), ip_expire(), ip_rcv_finish_core(), xfrm4_rcv_encap_finish() and xfrm4_rcv_encap(), which get the DSCP directly from IPv4 headers and can simply use the ip4h_dscp() helper.
While there, declare the IPv4 header pointers as const in ipvlan_l3_rcv() and bpf_lwt_input_reroute().
Also, modify the declaration of ip_route_input_noref() in include/net/route.h so that it matches the prototype of its implementation in net/ipv4/route.c.
Stable-dep-of: b3ad42f61832 ("bpf: Reset skb->cb after an lwt prog pushes an IP header")
--- drivers/net/ipvlan/ipvlan_l3s.c | 6 ++++-- include/net/route.h | 7 +++---- net/core/lwt_bpf.c | 5 +++-- net/ipv4/ip_fragment.c | 4 ++-- net/ipv4/ip_input.c | 2 +- net/ipv4/route.c | 6 +++--- net/ipv4/xfrm4_input.c | 2 +- net/ipv4/xfrm4_protocol.c | 2 +- 8 files changed, 18 insertions(+), 16 deletions(-)
drivers/net/ipvlan/ipvlan_l3s.c +4 -2
@@ -2,6 +2,8 @@/* Copyright (c) 2014 Mahesh Bandewar <[email protected]> */ +#include <net/ip.h> +#include "ipvlan.h" static unsigned int ipvlan_netid__read_mostly ;
@@ -48,11 +50,11 @@ static struct sk_buff *ipvlan_l3_rcv(struct net_device *dev,switch (proto) {case AF_INET : { -struct iphdr *ip4h =ip_hdr (skb); +const struct iphdr *ip4h =ip_hdr (skb);int err; err =ip_route_input_noref (skb, ip4h->daddr, ip4h->saddr, - ip4h->tos, sdev); +ip4h_dscp (ip4h), sdev);if (unlikely (err)) goto out;break ;
include/net/route.h +3 -4
@@ -201,8 +201,8 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4int ip_mc_validate_source (struct sk_buff *skb,__be32 daddr,__be32 saddr,u8 tos,struct net_device *dev,struct in_device *in_dev,u32 *itag); -int ip_route_input_noref (struct sk_buff *skb,__be32 dst,__be32 src, -u8 tos,struct net_device *devin); +int ip_route_input_noref (struct sk_buff *skb,__be32 daddr,__be32 saddr, +dscp_t dscp,struct net_device *dev);int ip_route_use_hint (struct sk_buff *skb,__be32 dst,__be32 src,u8 tos,struct net_device *devin,const struct sk_buff *hint);
@@ -213,8 +213,7 @@ static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,int err;rcu_read_lock (); - err =ip_route_input_noref (skb, dst, src,inet_dscp_to_dsfield (dscp), - devin); + err =ip_route_input_noref (skb, dst, src, dscp, devin);if (!err) {skb_dst_force (skb);if (!skb_dst (skb))
net/core/lwt_bpf.c +3 -2
@@ -10,6 +10,7 @@#include <linux/bpf.h> #include <net/lwtunnel.h> #include <net/gre.h> +#include <net/ip.h> #include <net/ip6_route.h> #include <net/ipv6_stubs.h> #include <net/inet_dscp.h>
@@ -91,12 +92,12 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb)if (skb->protocol ==htons (ETH_P_IP )) {struct net_device *dev =skb_dst (skb)->dev; -struct iphdr *iph =ip_hdr (skb); +const struct iphdr *iph =ip_hdr (skb);dev_hold (dev);skb_dst_drop (skb); err =ip_route_input_noref (skb, iph->daddr, iph->saddr, - iph->tos, dev); +ip4h_dscp (iph), dev);dev_put (dev); }else if (skb->protocol ==htons (ETH_P_IPV6 )) {skb_dst_drop (skb);
net/ipv4/ip_fragment.c +2 -2
@@ -168,8 +168,8 @@ static void ip_expire(struct timer_list *t)/* skb has no dst, perform route lookup again */ iph =ip_hdr (head); - err =ip_route_input_noref (head, iph->daddr, iph->saddr, - iph->tos, head->dev); + err =ip_route_input_noref (head, iph->daddr, iph->saddr,ip4h_dscp (iph), + head->dev);if (err) goto out;
net/ipv4/ip_input.c +1 -1
@@ -363,7 +363,7 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,*/ if (!skb_valid_dst (skb)) { err =ip_route_input_noref (skb, iph->daddr, iph->saddr, - iph->tos, dev); +ip4h_dscp (iph), dev);if (unlikely (err)) goto drop_error; }else {
net/ipv4/route.c +3 -3
@@ -2529,14 +2529,14 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr, }int ip_route_input_noref (struct sk_buff *skb,__be32 daddr,__be32 saddr, -u8 tos,struct net_device *dev) +dscp_t dscp,struct net_device *dev) {struct fib_result res;int err; - tos &=INET_DSCP_MASK ;rcu_read_lock (); - err =ip_route_input_rcu (skb, daddr, saddr, tos, dev, &res); + err =ip_route_input_rcu (skb, daddr, saddr,inet_dscp_to_dsfield (dscp), + dev, &res);rcu_read_unlock ();return err;
net/ipv4/xfrm4_input.c +1 -1
@@ -33,7 +33,7 @@ static inline int xfrm4_rcv_encap_finish(struct net *net, struct sock *sk,const struct iphdr *iph =ip_hdr (skb);if (ip_route_input_noref (skb, iph->daddr, iph->saddr, - iph->tos, skb->dev)) +ip4h_dscp (iph), skb->dev)) goto drop; }
net/ipv4/xfrm4_protocol.c +1 -1
@@ -76,7 +76,7 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,const struct iphdr *iph =ip_hdr (skb);if (ip_route_input_noref (skb, iph->daddr, iph->saddr, - iph->tos, skb->dev)) +ip4h_dscp (iph), skb->dev)) goto drop; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 108/816 bpf: Reset skb->cb after an lwt prog pushes an IP header
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit b3ad42f6183286ab376389a5d26edf7ee3bdba27 ]
IPCB(skb)->opt holds the offsets from the network header to the IPv4 options. But bpf_lwt_push_ip_encap() moves the network header and does not change IPCB(skb). Then ip_forward_options() and __ip_options_echo() use the old offsets on the pushed header. Thus the kernel corrupts the skb and the stack. If the family changes, the kernel also reads IP6CB(skb) as IPCB(skb), or the reverse. With CONFIG_IPV6_MIP6, it reads IPSKB_FORWARDED as frag_max_size and adds a needless fragment header.
Reset skb->cb after the prog. bpf_lwt_push_ip_encap() cannot do it, because bpf_prog_run_save_cb() can restore skb->cb. For IPv4 in IPv4, clear IPCB(skb)->opt as ip_tunnel_xmit() does. If the family changes, clear the cb of the new family but keep iif, because ip6_forward() gets the input device from it. Behind a VRF, skb->skb_iif is the VRF device and cannot replace iif. Do nothing for IPv6 in IPv6, as in seg6_do_srh_encap().
Do the reset in bpf_input() only after a push. Without a push, ip_forward_options() needs the offsets. Do it in bpf_xmit() before each reroute, because an lwt_xmit prog can also change the options. Thus after a reroute without a push, ip_options_fragment() leaves the options in all fragments, and ICMP errors echo none. After BPF_OK or BPF_REDIRECT the skb goes to a device, thus bpf_xmit() does no reset. The inner IPv4 checksum can still be wrong after ip_rcv_options() changes an option.
--- net/core/lwt_bpf.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
net/core/lwt_bpf.c +33 -0
@@ -86,6 +86,32 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_lwt_prog *lwt,return ret; } +/* +* skb->cb still describes the IP header that was the first one before the +* prog ran. The option offsets in IPCB(skb)->opt are wrong for a pushed +* header, and a header of the other family needs the other layout. iif +* stays: behind a VRF skb->skb_iif is the L3 master and not the port. +* bpf_lwt_push_encap() cannot do this, because bpf_prog_run_save_cb() can +* restore skb->cb after the prog. +*/ +static void bpf_lwt_reset_cb (struct sk_buff *skb,__be16 proto) +{ +int iif; + +if (skb->protocol == proto) { +if (proto ==htons (ETH_P_IP )) +memset (&IPCB (skb)->opt,0 ,sizeof (IPCB (skb)->opt)); + }else if (skb->protocol ==htons (ETH_P_IP )) { + iif =IP6CB (skb)->iif; +memset (IPCB (skb),0 ,sizeof (*IPCB (skb))); +IPCB (skb)->iif = iif; + }else { + iif =IPCB (skb)->iif; +memset (IP6CB (skb),0 ,sizeof (*IP6CB (skb))); +IP6CB (skb)->iif = iif; + } +} +static int bpf_lwt_input_reroute (struct sk_buff *skb) {int err = -EINVAL ;
@@ -118,6 +144,8 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb)static int bpf_input (struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb); +__be16 proto = skb->protocol; +unsigned int len = skb->len;struct bpf_lwt *bpf;int ret;
@@ -126,6 +154,9 @@ static int bpf_input(struct sk_buff *skb) ret =run_lwt_bpf (skb, &bpf->in, dst,NO_REDIRECT );if (ret <0 )return ret; +/* An lwt_in prog can change the length only with a push. */ +if (skb->len != len) +bpf_lwt_reset_cb (skb, proto);if (ret ==BPF_LWT_REROUTE )return bpf_lwt_input_reroute (skb); }
@@ -305,6 +336,8 @@ static int bpf_xmit(struct sk_buff *skb)case BPF_REDIRECT :return LWTUNNEL_XMIT_DONE ;case BPF_LWT_REROUTE : +/* An lwt_xmit prog can also write to the options. */ +bpf_lwt_reset_cb (skb, proto);return bpf_lwt_xmit_reroute (skb);default :return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 109/816 bpf: Require BPF_LWT_REROUTE when an lwt_in prog changes the protocol
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit d9618a6196953718f7470de5d2e84121bed063f7 ]
When an lwt_in prog returns BPF_OK, bpf_input() calls orig_input(), the input handler of the route. This handler is for one IP version and needs a dst of the same family. But BPF_LWT_ENCAP_IP lets the prog push a header of the other IP version and thus change skb->protocol. Then the handler reads and changes a header of the other IP version. The push of an SRH also replaces the dst, because seg6_lookup_nexthop() puts an rt6_info into the skb. Then ip_forward() uses the rt6_info as a struct rtable.
Drop the skb with -EINVAL when skb->protocol changes, as bpf_xmit() does. Drop it also when the family of the dst changes, because skb->protocol does not always show this change. Today no such skb leaves as the prog made it. A prog works as before if it returns BPF_LWT_REROUTE, or if it pushes an SRH on an IPv6 route.
The commit in the first Fixes tag lets a prog change skb->protocol. The commit in the second tag adds the check to bpf_xmit() only.
--- net/core/lwt_bpf.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/core/lwt_bpf.c +10 -0
@@ -159,6 +159,16 @@ static int bpf_input(struct sk_buff *skb)bpf_lwt_reset_cb (skb, proto);if (ret ==BPF_LWT_REROUTE )return bpf_lwt_input_reroute (skb); +/* +* orig_input() is for the old protocol only, see bpf_xmit(). +* It also needs a dst of the old family. BPF_LWT_ENCAP_SEG6 +* puts an IPv6 dst into the skb. +*/ +if (skb->protocol != proto || +skb_dst (skb)->ops->family != dst->ops->family) { +kfree_skb (skb); +return -EINVAL ; + } }if (unlikely (!dst->lwtstate->orig_input)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 110/816 bpf: Move the transport header with the moved headers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit a9d08fe60fa728ce0e3a99085241e8e790fb14c6 ]
bpf_skb_net_hdr_pop() removes len bytes at offset off. bpf_skb_net_hdr_push() does the opposite.
skb->data off
before | A | removed | B |
after | A | B |
skb->data offmac_header and network_header move with A. transport_header moves only when it is equal to network_header. inner_transport_header never moves. This is correct only for a header in B. In bpf_lwt_seg6_adjust_srh() transport_header is in A. bpf_skb_adjust_room() can remove both transport headers. With an incorrect header offset, the stack can drop the skb or read outside of it.
Also move transport_header with A when it is in A. Set it to offset off when it is in the removed bytes. In BPF_ADJ_ROOM_MAC mode it is then equal to network_header. Do not unset it, because skb_gso_validate_mac_len() uses it without a check. After a removal, set inner_transport_header to off when it is not in B and skb->encapsulation is set. A has only outer headers.
--- net/core/filter.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
net/core/filter.c +31 -6
@@ -3353,9 +3353,25 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len)return 0 ; } +/* +* bpf_skb_net_hdr_push() inserts bytes at @off, bpf_skb_net_hdr_pop() removes +* bytes at @off. Both move the bytes in front of @off together with skb->data, +* and leave the rest of the packet where it is. Return true if the transport +* header is in the part that moves. A transport header that is equal to the +* network header stays equal to it. +*/ +static bool bpf_skb_trans_hdr_moves (const struct sk_buff *skb,u32 off) +{ +if (skb->transport_header == skb->network_header) +return true; + +return skb_transport_header_was_set (skb) && + (u32 )skb_transport_offset (skb) < off; +} +static int bpf_skb_net_hdr_push (struct sk_buff *skb,u32 off,u32 len) { -bool trans_same = skb->transport_header == skb->network_header; +bool trans_moves =bpf_skb_trans_hdr_moves (skb, off);int ret;/* There's no need for __skb_push()/__skb_pull() pair to
@@ -3366,8 +3382,8 @@ static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len)if (likely (!ret)) { skb->mac_header -= len; skb->network_header -= len; -if (trans_same) - skb->transport_header = skb->network_header; +if (trans_moves) + skb->transport_header -= len; }return ret;
@@ -3375,7 +3391,7 @@ static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len)static int bpf_skb_net_hdr_pop (struct sk_buff *skb,u32 off,u32 len) { -bool trans_same = skb->transport_header == skb->network_header; +bool trans_moves =bpf_skb_trans_hdr_moves (skb, off);int ret;/* Same here, __skb_push()/__skb_pull() pair not needed. */
@@ -3383,8 +3399,17 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len)if (likely (!ret)) { skb->mac_header += len; skb->network_header += len; -if (trans_same) - skb->transport_header = skb->network_header; +if (trans_moves) { + skb->transport_header += len; + }else if (skb_transport_header_was_set (skb) && +skb_transport_offset (skb) < (int )off) { +/* It was in the removed bytes or before skb->data. */ +skb_set_transport_header (skb, off); + } +/* Do not leave the inner transport header in front of @off. */ +if (skb->encapsulation && +skb_inner_transport_offset (skb) < (int )off) +skb_set_inner_transport_header (skb, off); }return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 111/816 bpf: Check the offset in bpf_skb_generic_{push,pop}()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit ee36c9aa44ef300cd651074bd97552b229337f85 ]
To make room for len bytes at offset off, bpf_skb_generic_push() moves the first off bytes and clears len bytes after them. It assumes that the first off bytes are in the linear part. But in bpf_skb_adjust_room() off can be the end of the IP header, and this header can be in a frag. Then the function reads and writes after skb->tail, and can damage skb_shared_info.
bpf_skb_generic_pop() checks off + len, but this u32 sum can wrap to a small value. bpf_skb_adjust_room() and bpf_skb_change_proto() calculate off from skb_mac_header_len(). This length is a very large u32 when network_header < mac_header. Then the check can pass, and memmove() reads and writes far outside the skb.
Return -ENOMEM from both functions, like the present check, when off > skb->len. Thus the sum cannot wrap. In bpf_skb_generic_push() also pull the first off bytes into the linear part. Now bpf_skb_adjust_room() fails when a prog grows an skb that ends before off. network_header stays wrong.
--- net/core/filter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/core/filter.c +7 -2
@@ -3320,6 +3320,10 @@ static void bpf_skb_change_protocol(struct sk_buff *skb, u16 proto)static int bpf_skb_generic_push (struct sk_buff *skb,u32 off,u32 len) { +/* The bytes in front of @off are moved with skb->data. */ +if (unlikely (off > skb->len || !pskb_may_pull (skb, off))) +return -ENOMEM ; +/* Caller already did skb_cow() with meta_len+len as headroom, * so no need to do it here. */
@@ -3340,9 +3344,10 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len)void *old_data;/* skb_ensure_writable() is not needed here, as we're -* already working on an uncloned skb. +* already working on an uncloned skb. The first test +* keeps off + len from wrapping. */ -if (unlikely (!pskb_may_pull (skb, off + len))) +if (unlikely (off > skb->len || !pskb_may_pull (skb, off + len)))return -ENOMEM ; old_data = skb->data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 112/816 spi: Fix ACPI SPI resources using relative path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alban Bedel <[email protected]>
[ Upstream commit 4825287f6d2346e9273f35a928d1ef40e68bc58b ]
ACPI resources can use relative path when pointing to other resources. This didn't work with SPISerialBus resources because the device defining the resource was not passed to acpi_get_handle().
Pass the ACPI device handle through the lookup context to also allow for relative paths.
Stable-dep-of: 2d0953ab69d3 ("spi: acpi: only look up the IRQ of confirmed SPI devices")
--- drivers/spi/spi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi.c +3 -1
@@ -2628,6 +2628,7 @@ EXPORT_SYMBOL_GPL(spi_new_ancillary_device); #ifdef CONFIG_ACPI struct acpi_spi_lookup { struct spi_controller *ctlr; + acpi_handle device_handle; u32 max_speed_hz; u32 mode; int irq;
@@ -2722,7 +2723,7 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)if (lookup->index !=-1 && lookup->n++ != lookup->index)return 1 ; - status =acpi_get_handle (NULL , + status =acpi_get_handle (lookup->device_handle, sb->resource_source.string_ptr, &parent_handle);
@@ -2814,6 +2815,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,return ERR_PTR (-EINVAL ); lookup.ctlr = ctlr; + lookup.device_handle =acpi_device_handle (adev); lookup.irq =-1 ; lookup.index = index; lookup.n =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 113/816 spi: acpi: only look up the IRQ of confirmed SPI devices
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 2d0953ab69d316589624b0517fdce01f8e630bf0 ]
When an SPI controller is registered, acpi_register_spi_device() is called for every present ACPI device in the namespace and acpi_spi_device_alloc() walks each device's _CRS. While doing so, acpi_spi_add_resource() converts the first interrupt resource it finds, even for devices that have no SpiSerialBus resource at all and are discarded right afterwards. Converting an interrupt resource registers its GSI, so this maps IRQs for arbitrary unrelated ACPI devices.
On a Dell Precision M4800 (Lynx Point, 24-pin IOAPIC) the DSDT reports Haswell-ULT LPSS child devices (\_SB.PCI0.I2C0.ACD0 and \_SB.PCI0.SDHC.WI01) as present with interrupts on GSI 37 and 38. Registering the intel-spi controller then results in:
ERROR: Unable to locate IOAPIC for GSI 37
ERROR: Unable to locate IOAPIC for GSI 38
Do what the I2C core does and only parse the interrupt resource once the device has been identified as an SPI device on this controller.
--- drivers/spi/spi.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)
drivers/spi/spi.c +28 -8
@@ -2631,7 +2631,6 @@ struct acpi_spi_lookup {acpi_handle device_handle;u32 max_speed_hz;u32 mode; -int irq;u8 bits_per_word;u8 chip_select;int n;
@@ -2774,17 +2773,25 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)if (sb->device_polarity ==ACPI_SPI_ACTIVE_HIGH ) lookup->mode |=SPI_CS_HIGH ; } - }else if (lookup->irq <0 ) { -struct resource r; - -if (acpi_dev_resource_interrupt (ares,0 , &r)) - lookup->irq = r.start; }/* Always tell the ACPI core to skip this resource */ return 1 ; } +static int acpi_spi_add_irq_resource (struct acpi_resource *ares,void *data) +{ +int *irq = data; +struct resource r; + +if (*irq <0 && ares->type !=ACPI_RESOURCE_TYPE_SERIAL_BUS && +acpi_dev_resource_interrupt (ares,0 , &r)) + *irq = r.start; + +/* Always tell the ACPI core to skip this resource */ +return 1 ; +} +/** * acpi_spi_device_alloc - Allocate a spi device, and fill it in with ACPI information * @ctlr: controller to which the spi device belongs
@@ -2809,6 +2816,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,struct list_head resource_list;struct acpi_spi_lookup lookup = {};struct spi_device *spi; +int irq =-1 ;int ret;if (!ctlr && index ==-1 )
@@ -2816,7 +2824,6 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, lookup.ctlr = ctlr; lookup.device_handle =acpi_device_handle (adev); - lookup.irq =-1 ; lookup.index = index; lookup.n =0 ;
@@ -2839,6 +2846,19 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,if (!lookup.max_speed_hz)return ERR_PTR (-ENODEV ); +/* +* Only look up the IRQ once we know this is an SPI device for us. +* Parsing an interrupt resource maps its GSI, which must not be done +* for every unrelated ACPI device walked during enumeration. +*/ +INIT_LIST_HEAD (&resource_list); + ret =acpi_dev_get_resources (adev, &resource_list, + acpi_spi_add_irq_resource, &irq); +if (ret <0 ) +return ERR_PTR (ret); + +acpi_dev_free_resource_list (&resource_list); + spi =spi_alloc_device (lookup.ctlr);if (!spi) { dev_err(&lookup.ctlr->dev, "failed to allocate SPI device for %s\n",
@@ -2852,7 +2872,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,ACPI_COMPANION_SET (&spi->dev, adev); spi->max_speed_hz = lookup.max_speed_hz; spi->mode |= lookup.mode; - spi->irq = lookup.irq; + spi->irq = irq; spi->bits_per_word = lookup.bits_per_word;/* * By default spi->chip_select[0] will hold the physical CS number,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 114/816 bpf: lwt: Free the skb when bpf_xmit() fails to expand the headroom
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuqiang Sun <[email protected]>
[ Upstream commit 5e96760b25fdedbbf9312827f1f237d6b18b03e8 ]
When an LWT xmit program returns BPF_OK, bpf_xmit() makes sure that the skb still has room for the link layer header. If pskb_expand_head() fails there, bpf_xmit() returns -ENOMEM without freeing the skb. Its callers, lwtunnel_xmit() and then ip_finish_output2() or ip6_finish_output2(), take any return value other than LWTUNNEL_XMIT_CONTINUE to mean that the skb has been consumed, so nothing frees it.
Each such failure leaks the skb, together with what it holds: its dst and its charge to the sending socket, so the socket is never freed either. The other error paths of bpf_xmit() (BPF_DROP, an illegal return code, a changed protocol, a failed reroute) all free the skb.
Free it here too.
The leak was found with kbound, a static analysis prototype for ownership mismatches at kernel interfaces, on v7.2.12; it is present in mainline.
Build-tested with x86_64 and arm64 allmodconfig (W=1, sparse): no new warnings. Run-tested on QEMU (x86_64, KVM) with KASAN: a route through a dummy device with an LWT xmit program that pushes one byte with bpf_skb_change_head(), so the headroom check has to expand the head, and failslab limited to allocations under bpf_xmit(). Each of 10 pings then fails with ENOMEM. Without this patch each leaves a raw socket behind (RAW slab objects 6 -> 16); with it none does (6 -> 6), and nothing else is reported. Without injection both kernels go from 6 to 6.
--- net/core/lwt_bpf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/lwt_bpf.c +3 -1
@@ -339,8 +339,10 @@ static int bpf_xmit(struct sk_buff *skb)* made before LWT xmit. */ ret =xmit_check_headroom (skb, hroom); -if (unlikely (ret)) +if (unlikely (ret)) { +kfree_skb (skb);return ret; + }return LWTUNNEL_XMIT_CONTINUE ;case BPF_REDIRECT :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 115/816 net/mlx5: macsec: free struct mlx5_fs_id after an RCU grace period
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit 902407bc588575af0ceae5de4f635fe1e024f258 ]
macsec_fs_id_del() removes a struct mlx5_fs_id from its rhashtable with rhashtable_remove_fast() and then frees it with kfree() right away.
The TX (SCI) table is read locklessly from the transmit path:mlx5e_macsec_handle_tx_skb() and mlx5e_macsec_tx_build_eseg() call mlx5_macsec_fs_get_fs_id_from_hashtable(), which does rhashtable_lookup() under rcu_read_lock() and then reads mlx5_fs_id->id. A transmit that looked the entry up just before it was removed reads freed memory.
Before commit d4ece08f4b1d ("net/mlx5: Maintain fs_id xarray per MACsec device inside macsec steering") the SCI table held struct mlx5e_macsec_sa directly, and mlx5e_macsec_del_txsa() freed it with kfree_rcu_mightsleep(). That commit moved the table into macsec_fs.c with the new struct mlx5_fs_id, but frees it with a plain kfree().
Add an rcu_head to struct mlx5_fs_id and free it with kfree_rcu().
The same issue was flagged by the Sashiko AI review as a pre-existing problem while reviewing the HW-GRO for PSP series.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c +2 -1
@@ -98,6 +98,7 @@ struct mlx5_fs_id {refcount_t refcnt;sci_t sci;struct rhash_head hash; +struct rcu_head rcu; };struct mlx5_macsec_device {
@@ -688,7 +689,7 @@ static void macsec_fs_id_del(struct list_head *macsec_devices_list, u32 fs_id,xa_erase (fs_id_xa, fs_id); -kfree (fs_id_found); +kfree_rcu (fs_id_found, rcu);if (macsec_fs_is_macsec_device_empty (macsec_device)) {list_del (&macsec_device->macsec_devices_list_entry);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 116/816 bnxt_en: Dont keep MSI-X vectors added before FW reserves them
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Poenaru <[email protected]>
[ Upstream commit af449230bd8de936d6e4f759240e787b9aad7cc0 ]
When dynamic MSI-X is supported, bnxt_check_rings() grows the MSI-X vectors with bnxt_change_msix() once FW says the new rings would fit, and keeps them. FW only reserves the extra IRQs later, when bnxt_reserve_rings() calls __bnxt_reserve_rings(). The MSI-X table entries beyond the function's reserved IRQs are not backed until then:
the MSI message written when the new vectors are activated is lost, and the entries read back as zero. After FW reserves them they are live but still zero, so the NQ rings bound to them signal address 0 and every completion on those rings is lost. The next ring change (for example ethtool -G) then times out freeing each of those rings and the TX watchdog fires:
bnxt_en 0002:01:00.0 eth0: Resp cmpl intr err msg: 0x51
bnxt_en 0002:01:00.0 eth0: hwrm_ring_free type 1 failed. rc:fffffff0 err:0
...
bnxt_en 0002:01:00.0 eth0: NETDEV WATCHDOG: CPU: 17: transmit queue 18 timed out 5716 ms
On x86 this is hidden: GENERIC_IRQ_RESERVATION_MODE makes the PCI MSI domains MSI_FLAG_MUST_REACTIVATE, so the message is composed and written again when the IRQ is requested, after FW has reserved the vector. Since commit 0d6a7c417983 ("irqchip/gic-v3-its: Enable dynamic MSI-X allocation"), arm64 GICv3 systems take the dynamic path as well, but write the message only once, at allocation. On an NVIDIA Grace system with a BCM57508, raising the channel count from 18 to 32 left MSI-X entries 18-31 all zero, and the 14 rings using them lost their interrupts.
Keep the allocation in bnxt_check_rings() as a check that enough vectors are available, but free the new vectors again right away when FW manages IRQ reservations (BNXT_NEW_RM). bnxt_reserve_rings() then allocates them after __bnxt_reserve_rings() has reserved them. Without BNXT_NEW_RM there is no IRQ reservation and bnxt_reserve_rings() does not grow the vectors, so keep the current behaviour there.
In bnxt_reserve_rings(), size that allocation from the rings FW actually reserved (bnxt_get_num_msix()) instead of the count computed before the reservation, so that a partial grant does not activate unreserved entries either, at least while no RoCE driver is registered.
The allocation can now fail after FW has committed the reservation. A later open would then find nothing to reserve and return before growing the vectors, and bnxt_request_irq() would use irq_tbl[] entries past bp->total_irqs, which still hold the freed virqs. Grow the vectors in that case as well, and clear irq_tbl[].vector when trimming.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +33 -1
@@ -10947,6 +10947,7 @@ static int bnxt_change_msix(struct bnxt *bp, int total) map.index = i -1 ; map.virq = bp->irq_tbl[i -1 ].vector;pci_msix_free_irq (bp->pdev, map); + bp->irq_tbl[i -1 ].vector =0 ; bp->total_irqs--; }return bp->total_irqs;
@@ -11124,8 +11125,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)int irqs_required;int rc; -if (!bnxt_need_reserve_rings (bp)) +if (!bnxt_need_reserve_rings (bp)) { +/* FW may already hold the reservation from an earlier +* reservation that was not followed by growing the dynamic +* MSI-X vectors, e.g. because the allocation failed. +*/ +if (irq_re_init &&BNXT_NEW_RM (bp) && bp->irq_tbl && +pci_msix_can_alloc_dyn (bp->pdev)) { + irqs_required =bnxt_get_num_msix (bp); +if (irqs_required > bp->total_irqs && +bnxt_change_msix (bp, irqs_required) != irqs_required) { +netdev_err (bp->dev,"Unable to allocate %d MSIX vectors, maximum available %d\n" , + irqs_required, bp->total_irqs); +return -ENOSPC ; + } + }return 0 ; + }if (BNXT_NEW_RM (bp) && !bnxt_ulp_registered (edev)) {int ulp_msix =bnxt_get_avail_msix (bp, bp->ulp_num_msix_want);
@@ -11151,6 +11167,10 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) rc =bnxt_init_int_mode (bp);bnxt_ulp_irq_restart (bp, rc); }else if (irq_change && !rc) { +/* Size the vectors from what FW actually reserved, which +* can be less than what was requested. +*/ + irqs_required =bnxt_get_num_msix (bp);if (bnxt_change_msix (bp, irqs_required) != irqs_required) rc = -ENOSPC ; }
@@ -14181,6 +14201,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, hwr.cp =min_t (int, hwr.cp,bnxt_get_max_func_irqs (bp)); }if (hwr.cp > bp->total_irqs) { +int old_total = bp->total_irqs;int total_msix =bnxt_change_msix (bp, hwr.cp);if (total_msix < hwr.cp) {
@@ -14188,6 +14209,17 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, hwr.cp, total_msix); rc = -ENOSPC ; } +/* FW has not reserved the new vectors yet, and writes to +* MSI-X table entries beyond the reserved IRQs don't +* stick (seen on BCM57508). Free them again; +* bnxt_reserve_rings() allocates them after +* __bnxt_reserve_rings(). Without the new resource +* manager there is no IRQ reservation and +* bnxt_reserve_rings() does not grow the vectors, so +* keep them. +*/ +if (BNXT_NEW_RM (bp)) +bnxt_change_msix (bp, old_total); } }return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 117/816 ipv6: fix fib6 walker UAF on NLM_F_REPLACE
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit 23fec4bd76904e9df7a8cc0a81ceb14c36971da4 ]
fib6_walker uses w->leaf to remember the next fib6_info to dump, so an RTM_GETROUTE dump can continue there on the next recvmsg(). This assumes that whoever removes a route from the tree also updates the walkers pointing at it. fib6_del_route() does: it moves w->leaf to the next route. The NLM_F_REPLACE branch of fib6_add_rt2node() does
not: it removes the old route, fib6_add() frees it, and w->leaf keeps pointing at the freed object.
The fn_sernum version check in fib6_dump_table() normally protects against resuming on a stale w->leaf, but it can be bypassed:ip6_link_failure() resets fn_sernum to -1 when the default route fails, which an unprivileged user in a user+net namespace can cause:
1) link failure fn_sernum = -1
2) dump pauses on route R
3) replace R fn_sernum changed, R freed 4) link failure fn_sernum = -1 5) dump resumes -1 == -1, reads freed R <- UAF
BUG: KASAN: slab-use-after-free in rt6_fill_node+0x1c22/0x2cd0 Read of size 4 at addr ff11000011fa0064 by task poc/101 rt6_fill_node <- rt6_dump_route
Fix by adjusting walkers separately for replacement and deletion. For replacement, add fib6_walkers_replace_leaf() points w->leaf at the new route. For deletion and ECMP sibling removal, fib6_walkers_skip_rt() calls fib6_walkers_replace_leaf() with the next route. Reset w->skip_in_node when updating w->leaf, and set w->state to FWS_U when no next route remains.
--- net/ipv6/ip6_fib.c | 50 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-)
net/ipv6/ip6_fib.c +37 -13
@@ -89,6 +89,40 @@ static void fib6_walker_unlink(struct net *net, struct fib6_walker *w)write_unlock_bh (&net->ipv6.fib6_walker_lock); } +/* @old is leaving the tree. Walkers resting on it continue from @new, or +* climb to the parent node when there is no @new. Called with tb6_lock +* held. +*/ +static void fib6_walkers_replace_leaf (struct net *net,struct fib6_info *old, +struct fib6_info *new) +{ +struct fib6_walker *w; + +read_lock (&net->ipv6.fib6_walker_lock); + FOR_WALKERS(net, w) { +if (w->state ==FWS_C && w->leaf == old) { +pr_debug ("walker %p adjusted by unlink of %p\n" , w, old); + w->leaf = new; + w->skip_in_node =0 ; +if (!new) + w->state =FWS_U ; + } + } +read_unlock (&net->ipv6.fib6_walker_lock); +} + +/* @rt is removed from its node: walkers resting on it continue from the +* next route of the node. +*/ +static void fib6_walkers_skip_rt (struct net *net,struct fib6_info *rt) +{ +struct fib6_info *next; + + next =rcu_dereference_protected (rt->fib6_next, +lockdep_is_held (&rt->fib6_table->tb6_lock)); +fib6_walkers_replace_leaf (net, rt, next); +} +static int fib6_new_sernum (struct net *net) {int new, old =atomic_read (&net->ipv6.fib6_sernum);
@@ -1302,6 +1336,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,rcu_assign_pointer (rt->fib6_node, fn); rt->fib6_next = iter->fib6_next;rcu_assign_pointer (*ins, rt); +fib6_walkers_replace_leaf (info->nl_net, iter, rt);if (!info->skip_notify)inet6_rt_notify (RTM_NEWROUTE , rt, info,NLM_F_REPLACE );if (!(fn->fn_flags &RTN_RTINFO )) {
@@ -1324,6 +1359,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,if (iter->fib6_metric > rt->fib6_metric)break ;if (rt6_qualify_for_ecmp (iter)) { +fib6_walkers_skip_rt (info->nl_net, iter); *ins = iter->fib6_next; iter->fib6_node =NULL ;fib6_purge_rt (iter, fn, info->nl_net);
@@ -1933,7 +1969,6 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn, struct fib6_info __rcu **rtp, struct nl_info *info) { struct fib6_info *leaf, *replace_rt = NULL; -struct fib6_walker *w;struct fib6_info *rt =rcu_dereference_protected (*rtp,lockdep_is_held (&table->tb6_lock));struct net *net = info->nl_net;
@@ -1984,18 +2019,7 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,rt6_multipath_rebalance (next_sibling); } -/* Adjust walkers */ -read_lock (&net->ipv6.fib6_walker_lock); - FOR_WALKERS(net, w) { -if (w->state ==FWS_C && w->leaf == rt) { -pr_debug ("walker %p adjusted by delroute\n" , w); - w->leaf =rcu_dereference_protected (rt->fib6_next, -lockdep_is_held (&table->tb6_lock)); -if (!w->leaf) - w->state =FWS_U ; - } - } -read_unlock (&net->ipv6.fib6_walker_lock); +fib6_walkers_skip_rt (net, rt);/* If it was last route, call fib6_repair_tree() to: * 1. For root node, put back null_entry as how the table was created.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 118/816 tcp: do not let tcp_collapse() drive sk_forward_alloc negative
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 031c403d13e5046750e2abebd4e770631e7c4627 ]
tcp_collapse() charges each newly allocated skb with skb_set_owner_r() before the skbs it replaces are freed, without scheduling memory first.
Since sk_mem_uncharge() reclaims eagerly, sk->sk_forward_alloc has no cushion and can become negative. This can be durable when the collapsed skbs had a high payload/truesize ratio or were partially read, because the new skbs can have a bigger total truesize than the old ones.
A negative sk_forward_alloc then confuses tcp_wmem_schedule(), which can return a negative length to tcp_sendmsg_locked(), triggering a WARN_ON_ONCE(bytes > INT_MAX) in check_copy_size().
Call sk_forced_mem_schedule() before charging nskb.
--- net/ipv4/tcp_input.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/tcp_input.c +4 -0
@@ -5534,6 +5534,10 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,__skb_queue_before (list, skb, nskb); else __skb_queue_tail(&tmp, nskb); /* defer rbtree insertion */ +/* nskb is charged before the skbs it replaces are freed. +* Make sure sk->sk_forward_alloc can not become negative. +*/ +sk_forced_mem_schedule (sk, nskb->truesize);skb_set_owner_r (nskb, sk);mptcp_skb_ext_move (nskb, skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 119/816 ata: libata-sata: allow re-enabling NCQ with the same queue_depth
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Pylypiv <[email protected]>
[ Upstream commit d7c5cc8cc21c1264cce07feb4a51be158688280e ]
When ata_eh_speed_down() disables NCQ due to excessive errors, it sets ATA_DFLAG_NCQ_OFF without changing sdev->queue_depth. Userspace can re-enable NCQ by writing a queue depth > 1 to the sysfs queue_depth attribute, which invokes ata_change_queue_depth() to clear ATA_DFLAG_NCQ_OFF.
However, ata_change_queue_depth() returns early if the requested queue_depth is equal to sdev->queue_depth before clearing ATA_DFLAG_NCQ_OFF. As a result, writing a different queue depth > 1 re-enables NCQ, whereas writing the current sdev->queue_depth value leaves ATA_DFLAG_NCQ_OFF set.
Since ata_change_queue_depth() already checks whether queue_depth equals sdev->queue_depth before calling scsi_change_queue_depth(), remove the early check so that writing the current queue_depth > 1 clears ATA_DFLAG_NCQ_OFF and re-enables NCQ.
--- drivers/ata/libata-sata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libata-sata.c +1 -1
@@ -1287,7 +1287,7 @@ int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,spin_lock_irqsave (ap->lock, flags); dev =ata_scsi_find_dev (ap, sdev); -if (!dev || queue_depth <1 || queue_depth == sdev->queue_depth) { +if (!dev || queue_depth <1 ) {spin_unlock_irqrestore (ap->lock, flags);return sdev->queue_depth; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 120/816 ata: libata-eh: Retry non-NCQ commands when their sense data asks for it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 597be4104c4045d73979c05307fa5fc778d1dbde ]
When a failed command has valid sense data, ata_eh_analyze_tf() asks scsi_check_sense() whether the command should be retried, and sets ATA_QCFLAG_RETRY if it should. ata_eh_link_autopsy() then clears AC_ERR_DEV and AC_ERR_OTHER from qc->err_mask, relying on that decision.
For an NCQ command, qc->err_mask still has AC_ERR_NCQ, so ata_eh_finish() honors ATA_QCFLAG_RETRY. For a non-NCQ command, whose sense data comes from REQUEST SENSE DATA EXT, qc->err_mask is now zero, and ata_eh_finish() completes the command with scmd->retries set to scmd->allowed, without looking at ATA_QCFLAG_RETRY. Such a command is thus never retried, even when its sense data asks for a retry, e.g. a transient error reported as ABORTED COMMAND.
Make ata_eh_finish() honor ATA_QCFLAG_RETRY for commands with valid sense data. ata_eh_qc_retry() cannot be used for this: as qc->err_mask is zero, it increments scmd->allowed, so every retry would allow one more, and a persistent error would be retried forever. Instead, complete the command without touching scmd->allowed or scmd->retries, so that the SCSI midlayer retries it at most scmd->allowed times, like any other failed command.
--- drivers/ata/libata-eh.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/ata/libata-eh.c +14 -2
@@ -4014,8 +4014,20 @@ void ata_eh_finish(struct ata_port *ap)ata_eh_qc_complete (qc); } }else { -if (qc->flags &ATA_QCFLAG_SENSE_VALID || - qc->flags &ATA_QCFLAG_EH_SUCCESS_CMD ) { +if (qc->flags &ATA_QCFLAG_SENSE_VALID && + qc->flags &ATA_QCFLAG_RETRY ) { +/* +* The sense data asks for a retry, see +* ata_eh_analyze_tf(). ata_eh_link_autopsy() +* cleared qc->err_mask, so ata_eh_qc_retry() +* would increment scmd->allowed. Leave +* scmd->allowed alone, so that upper layer +* only retries the command if it has not +* already been retried too many times. +*/ +__ata_eh_qc_complete (qc); + }else if (qc->flags &ATA_QCFLAG_SENSE_VALID || + qc->flags &ATA_QCFLAG_EH_SUCCESS_CMD ) {ata_eh_qc_complete (qc); }else {/* feed zero TF to sense generation */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 121/816 net: stmmac: Set dma_sync_size to zero for discarded frames
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Furong Xu <[email protected]>
[ Upstream commit 51cfbed198ca4aa140babde816387db0e71f09e7 ]
If a frame is going to be discarded by driver, this frame is never touched by driver and the cache lines never become dirty obviously, page_pool_recycle_direct() wastes CPU cycles on unnecessary calling of page_pool_dma_sync_for_device() to sync entire frame. page_pool_put_page() with sync_size setting to 0 is the proper method.
Stable-dep-of: 834ec9530832 ("net: stmmac: drop split frames on AF_XDP zero-copy RX")
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -5586,7 +5586,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) status); }if (unlikely (status == discard_frame)) { -page_pool_recycle_direct (rx_q->page_pool, buf->page); +page_pool_put_page (rx_q->page_pool, buf->page,0 , true); buf->page =NULL ; error =1 ;if (!priv->hwts_rx_en)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 122/816 net: stmmac: drop split frames on AF_XDP zero-copy RX
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit 834ec95308320cbd8c162d86788ab95cc3fd6bf8 ]
stmmac_rx_zc() assumes a 1:1 mapping between a received frame and an XSK pool buffer and drops any frame that spans more than one RX descriptor:
/* XSK pool expects RX frame 1:1 mapped to XSK buffer */
if (likely(status & rx_not_ls)) {
xsk_buff_free(buf->xdp);
buf->xdp = NULL;
dirty++;
count++;
goto read_again;
}The non-last descriptors are freed and dropped, but the frame is not marked as errored. When the poll reaches the last descriptor of the same frame, error is still 0, so the fragment is handled as a complete
frame: it is passed to the XDP program, copied into an skb on XDP_PASS, or converted for XDP_TX. The tail starts in the middle of the original payload at a predictable offset and, parsed as a fresh frame (len == 0), stmmac_rx_buf1_len() reports the full dma_buf_sz length for it even though the DMA engine only wrote the tail remainder into that buffer, so the reads extend past the received bytes and can reach beyond the end of the XSK pool buffer. GMAC4 always enables jumbo frames (GMAC_CONFIG_JE in GMAC_CORE_INIT), so an on-link peer can trigger such a split even when the interface MTU is left at 1500.
Set error when the 1:1 mapping check drops a descriptor, so the remaining descriptors of the frame - including the last one - are drained and released with xsk_buff_free() instead of being processed as a new frame. Account every freed buffer with dirty and count the dropped frame once in the poll budget / rx_pkt_n. The direct 1:1 mapping drop also increments rx_dropped.
Use a bit test instead of an equality test for discard_frame. Commit 644b8437ccef9e ("net: stmmac: dwmac4: report Rx checksum errors in status") made dwmac4_wrback_get_rx_status() set discard_frame on RDES3_ERROR_SUMMARY and OR in csum_none on RDES1_IP_HDR_ERROR or RDES1_IP_PAYLOAD_ERROR, so it can return discard_frame | csum_none. The old "status == discard_frame" test missed that value and delivered frames with CRC, overflow, watchdog or giant errors to the stack in stmmac_rx() - or to XDP/XSK in stmmac_rx_zc() - when they also failed the IP checksum. The change therefore affects the regular RX path, not only zero-copy. The bit test is also required for the discard_frame | rx_not_ls value returned for non-last legacy descriptors below.
Normalize the legacy normal and enhanced descriptor callbacks to report rx_not_ls together with discard_frame for non-last descriptors. This allows both stmmac_rx_zc() and stmmac_rx() to drain split frames on dwmac100 and dwmac1000 instead of reparsing the final fragment as a new packet.
--- .../net/ethernet/stmicro/stmmac/enh_desc.c | 2 +- .../net/ethernet/stmicro/stmmac/norm_desc.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 21 ++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/enh_desc.c +1 -1
@@ -210,7 +210,7 @@ static int enh_desc_get_rx_status(struct stmmac_extra_stats *x,if (unlikely (!(rdes0 &RDES0_LAST_DESCRIPTOR ))) { x->rx_length++; -return discard_frame; +return discard_frame | rx_not_ls; }if (unlikely (rdes0 &RDES0_ERROR_SUMMARY )) {
drivers/net/ethernet/stmicro/stmmac/norm_desc.c +1 -1
@@ -77,7 +77,7 @@ static int ndesc_get_rx_status(struct stmmac_extra_stats *x,if (unlikely (!(rdes0 &RDES0_LAST_DESCRIPTOR ))) { x->rx_length++; -return discard_frame; +return discard_frame | rx_not_ls; }if (unlikely (rdes0 &RDES0_ERROR_SUMMARY )) {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +13 -8
@@ -5387,18 +5387,21 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) &rx_q->dma_erx[entry], status); } -if (unlikely (status == discard_frame)) { -xsk_buff_free (buf->xdp); - buf->xdp =NULL ; - dirty++; + +if (unlikely (!error && (status & discard_frame))) { error =1 ;if (!priv->hwts_rx_en) rx_errors++; } -if (unlikely (error && (status & rx_not_ls))) - goto read_again;if (unlikely (error)) { +xsk_buff_free (buf->xdp); + buf->xdp =NULL ; + dirty++; + +if (status & rx_not_ls) + goto read_again; + count++;continue ; }
@@ -5407,8 +5410,9 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)if (likely (status & rx_not_ls)) {xsk_buff_free (buf->xdp); buf->xdp =NULL ; + rx_dropped++; + error =1 ; dirty++; - count++; goto read_again; }
@@ -5585,7 +5589,8 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) &rx_q->dma_erx[entry], status); } -if (unlikely (status == discard_frame)) { + +if (unlikely (status & discard_frame)) {page_pool_put_page (rx_q->page_pool, buf->page,0 , true); buf->page =NULL ; error =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 123/816 net: stmmac: copy XDP metadata in AF_XDP zero-copy RX
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit 41d78e9ac0984f0e9577e5312e62400b5a6760c8 ]
stmmac_construct_skb_zc() reserves headroom for the XDP metadata and records the length reported by the XDP program, but only copies the packet data starting at xdp->data. The bytes in [xdp->data_meta, xdp->data) are never copied into the new skb, so the skb advertises metadata that is not there: after eth_type_trans() anchors mac_header, data_meta points at uninitialized headroom instead of what the program wrote.
Copy the metadata together with the packet data starting at xdp->data_meta, leaving skb->data at the start of the frame and the metadata immediately before it, and record its length. This keeps data_meta valid for the stack and TC BPF after eth_type_trans() anchors mac_header.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
@@ -5171,7 +5171,8 @@ static struct sk_buff *stmmac_construct_skb_zc(struct stmmac_channel *ch,return NULL ;skb_reserve (skb, xdp->data - xdp->data_hard_start); -memcpy (__skb_put (skb, datasize), xdp->data, datasize); +__skb_put (skb, datasize); +memcpy (skb->data - metasize, xdp->data_meta, datasize + metasize);if (metasize)skb_metadata_set (skb, metasize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 124/816 ata: libata-core: Check device support before querying power state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giuseppe Piscitelli <[email protected]>
[ Upstream commit ec585ac78742527f80495dd8f451dcda7e9e7f59 ]
The standby path queries the power state before checking whether the device accepts ATA power-management commands. This sends CHECK POWER MODE to ATAPI devices, including the QEMU DVD-ROM, which rejects it.
Run the existing taskfile initialization and device-class check first, as the active-power path already does.
--- drivers/ata/libata-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/ata/libata-core.c +4 -4
@@ -2045,6 +2045,10 @@ void ata_dev_power_set_standby(struct ata_device *dev)struct ata_taskfile tf;unsigned int err_mask; +/* Issue STANDBY IMMEDIATE command only if supported by the device */ +if (!ata_dev_power_init_tf (dev, &tf, false)) +return ; +/* If the device is already sleeping or in standby, do nothing. */ if ((dev->flags &ATA_DFLAG_SLEEPING ) || !ata_dev_power_is_active (dev))
@@ -2063,10 +2067,6 @@ void ata_dev_power_set_standby(struct ata_device *dev) system_entering_hibernation())return ; -/* Issue STANDBY IMMEDIATE command only if supported by the device */ -if (!ata_dev_power_init_tf (dev, &tf, false)) -return ; -ata_dev_notice (dev,"Entering standby power mode\n" ); err_mask =ata_exec_internal (dev, &tf,NULL ,DMA_NONE ,NULL ,0 ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 125/816 net: lan966x: dont free XDP buffers in fdma tx clear with budget 0
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit 263a5514cb9535380734b5e300b298f82570eb57 ]
lan966x_fdma_tx_clear_buf() runs from the NAPI poll and frees the buffers of completed tx DCBs with napi_consume_skb(), page_pool_recycle_direct() and xdp_return_frame_bulk().
netpoll calls the NAPI poll with a budget of 0 and hardirqs disabled. With a budget of 0, a driver cannot call any XDP or page pool API.
Before this patch, the XDP_TX pages and ndo_xdp_xmit frames are freed regardless of the budget. With netconsole on the port that owns the FDMA NAPI, such a buffer is freed with hardirqs disabled, and __page_pool_put_page() warns via lockdep_assert_no_hardirq().
Leave the XDP buffers of completed DCBs in place when the budget is 0, and free them in the next NAPI poll. napi_consume_skb() already handles a budget of 0, so skbs are still freed.
Found by an AI code review agent. Reproduced on a lan9668 board with a modified kernel that runs the NAPI poll with a budget of 0 and hardirqs disabled. With the fix the warning is gone.
--- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +6 -0
@@ -354,6 +354,12 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight)if (!fdma_db_is_done (db))continue ; +/* XDP and page pool APIs can't be used with a budget of 0. +* Leave these buffers for the next NAPI poll. +*/ +if (!weight && !dcb_buf->use_skb) +continue ; + dcb_buf->dev->stats.tx_packets++; dcb_buf->dev->stats.tx_bytes += dcb_buf->len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 126/816 drm/panel: visionox-r66451: Send the brightness value MSB first
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 00fe6be187ffde738fdb71ea7deb671fc939e583 ]
The panel expects to get two bytes of the DCS Set Display Brightness command with the most significant byte first, and it uses the lower 12 bits of the value, use mipi_dsi_dcs_set_display_brightness_large() to correct the programmed brightness values.
Tested on the SM8350-HDK display card, the display brightness increases gradually with:
for v in $(seq 16 16 4095); do sleep 0.1; \
echo $v > /sys/class/backlight/ae94000.dsi.0/brightness; \
donewhile without the change the display is dark during all writes.
--- drivers/gpu/drm/panel/panel-visionox-r66451.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panel/panel-visionox-r66451.c +1 -1
@@ -254,7 +254,7 @@ static int visionox_r66451_bl_update_status(struct backlight_device *bl)struct mipi_dsi_device *dsi =bl_get_data (bl);u16 brightness =backlight_get_brightness (bl); -return mipi_dsi_dcs_set_display_brightness (dsi, brightness); +return mipi_dsi_dcs_set_display_brightness_large (dsi, brightness); }static const struct backlight_ops visionox_r66451_bl_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 127/816 drm/panel: visionox-r66451: Wait longer after the panel reset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit b4b2778d5e175b166e4a27e5df5d61da468ad004 ]
The initialization sequence is sent 10ms after the panel reset is deasserted, however on the SM8350-HDK display card the panel does not answer a DCS read at that time, as a result the panel initialization commands are lost, and the panel does not exit sleep mode and the display stays black. With the first command sent about 15ms after the reset the panel comes up reliably, so wait 20ms after deasserting the reset.
--- drivers/gpu/drm/panel/panel-visionox-r66451.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panel/panel-visionox-r66451.c +1 -1
@@ -36,7 +36,7 @@ static void visionox_r66451_reset(struct visionox_r66451 *ctx)gpiod_set_value_cansleep (ctx->reset_gpio,1 );usleep_range (10000 ,10100 );gpiod_set_value_cansleep (ctx->reset_gpio,0 ); -usleep_range (10000 ,10100 ); +usleep_range (20000 ,21000 ); }static int visionox_r66451_on (struct visionox_r66451 *ctx)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 128/816 sfc: ptp: drop the stale frequency reset in efx_ptp_start()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Austin <[email protected]>
[ Upstream commit 21d4917cfc8b6837c44d8aa186941a6a16ec17a0 ]
FW does not touch the clock frequency state on MC_CMD_PTP_OP_DISABLE or MC_CMD_PTP_OP_ENABLE, so the driver doesn't need to either. Doing so just desyncs the driver's cached current_adjfreq from what FW still has programmed.
Resetting current_adjfreq to 0 here means the first efx_phc_adjtime() call after efx_ptp_start() reprograms the NIC's clock frequency to 0, since efx_phc_adjtime() always sends current_adjfreq to FW alongside the time step. efx_ptp_start() runs on every SIOCSHWTSTAMP mode change, on ifup, and on the reset_required path in efx_ptp_worker(), so each of those silently drops any frequency correction the PTP servo had already applied.
efx_ptp_start() is also reached from reset recovery, but that is fine:
on an FLR or PCIe reset FW does not touch the NIC clock, and on a full MC reboot the clock is reset to 1970, so a stale current_adjfreq from before the reset is hardly consequential - especially as it is bound to MAX_PPB, 1000000 ppb.
--- drivers/net/ethernet/sfc/ptp.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/sfc/ptp.c +0 -1
@@ -1446,7 +1446,6 @@ static int efx_ptp_start(struct efx_nic *efx) goto fail; ptp->evt_frag_idx =0 ; - ptp->current_adjfreq =0 ;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 129/816 sfc: ptp: serialize host and MC synchronization transactions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Austin <[email protected]>
[ Upstream commit f707347b33feebdd67633bccea52f96807c18d6e ]
efx_ptp_synchronize() clears the MC-ready DMA flag before efx_mcdi_rpc_start() acquires the MCDI interface, and processes results into ptp->timeset[] after efx_mcdi_rpc_finish() has released it. The PPS worker and the hwtstamp enable path can therefore clobber each other's handshake flag and timesets.
Hold a PHC mutex across the whole transaction and over the clock operations, so efx_phc_settime() reads and adjusts atomically and current_adjfreq is consistently read and written under one lock. Also bail out when efx_mcdi_rpc_start() fails rather than finishing an RPC that was never acquired.
--- drivers/net/ethernet/sfc/ptp.c | 81 +++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 26 deletions(-)
drivers/net/ethernet/sfc/ptp.c +55 -26
@@ -36,6 +36,7 @@#include <linux/errno.h> #include <linux/ktime.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/pps_kernel.h> #include <linux/ptp_clock_kernel.h> #include "net_driver.h"
@@ -272,6 +273,8 @@ struct efx_ptp_rxfilter {* frequency adjustment into a fixed point fractional nanosecond format. * @current_adjfreq: Current ppb adjustment. * @phc_clock: Pointer to registered phc device (if primary function) +* @phc_lock: Serializes PHC commands and synchronization, and protects +* @current_adjfreq * @phc_clock_info: Registration structure for phc device * @pps_work: pps work task for handling pps events * @pps_workwq: pps work queue
@@ -331,6 +334,7 @@ struct efx_ptp_data {unsigned int adjfreq_ppb_shift;s64 current_adjfreq;struct ptp_clock *phc_clock; +struct mutex phc_lock;struct ptp_clock_info phc_clock_info;struct work_struct pps_work;struct workqueue_struct *pps_workwq;
@@ -1008,7 +1012,14 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),return 0 ; } -/* Synchronize times between the host and the MC */ +/* Synchronize times between the host and the MC. +* +* The MC serializes PTP requests, so MC_CMD_PTP_OP_ADJUST cannot be applied +* while MC_CMD_PTP_OP_SYNCHRONIZE is collecting timesets. This holds across +* functions of a controller, which share the clock but adjust it only through +* the function that registered it, so a secondary function can capture here +* without serializing against the primary. +*/ static int efx_ptp_synchronize (struct efx_nic *efx,unsigned int num_readings) {struct efx_ptp_data *ptp = efx->ptp_data;
@@ -1027,11 +1038,14 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)MCDI_SET_QWORD (synch_buf,PTP_IN_SYNCHRONIZE_START_ADDR , ptp->start.dma_addr); +mutex_lock (&ptp->phc_lock); +/* Clear flag that signals MC ready */ WRITE_ONCE (*start,0 ); rc =efx_mcdi_rpc_start (efx,MC_CMD_PTP , synch_buf,MC_CMD_PTP_IN_SYNCHRONIZE_LEN ); -EFX_WARN_ON_ONCE_PARANOID (rc); +if (rc) + goto out;/* Wait for start from MCDI (or timeout) */ timeout = jiffies +msecs_to_jiffies (MAX_SYNCHRONISE_WAIT_MS );
@@ -1062,11 +1076,13 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings) ++ptp->no_time_syncs; } +out:/* Increment the bad syncs counter if the synchronize fails, whatever * the reason. */ if (rc !=0 ) ++ptp->bad_syncs; +mutex_unlock (&ptp->phc_lock);return rc; }
@@ -1569,6 +1585,7 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)if (!efx->ptp_data)return -ENOMEM ; +mutex_init (&ptp->phc_lock); ptp->efx = efx; ptp->channel = channel;
@@ -1640,6 +1657,7 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)efx_nic_free_buffer (efx, &ptp->start); fail1: +mutex_destroy (&ptp->phc_lock);kfree (efx->ptp_data); efx->ptp_data =NULL ;
@@ -1694,6 +1712,7 @@ void efx_ptp_remove(struct efx_nic *efx)destroy_workqueue (efx->ptp_data->workwq);efx_nic_free_buffer (efx, &efx->ptp_data->start); +mutex_destroy (&efx->ptp_data->phc_lock);kfree (efx->ptp_data); efx->ptp_data =NULL ; }
@@ -2110,23 +2129,23 @@ static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)MCDI_SET_QWORD (inadj,PTP_IN_ADJUST_FREQ , adjustment_ns);MCDI_SET_DWORD (inadj,PTP_IN_ADJUST_SECONDS ,0 );MCDI_SET_DWORD (inadj,PTP_IN_ADJUST_NANOSECONDS ,0 ); +mutex_lock (&ptp_data->phc_lock); rc =efx_mcdi_rpc (efx,MC_CMD_PTP , inadj,sizeof (inadj),NULL ,0 ,NULL ); -if (rc !=0 ) -return rc; - - ptp_data->current_adjfreq = adjustment_ns; -return 0 ; +if (!rc) + ptp_data->current_adjfreq = adjustment_ns; +mutex_unlock (&ptp_data->phc_lock); +return rc; } -static int efx_phc_adjtime (struct ptp_clock_info *ptp,s64 delta) +static int _efx_phc_adjtime (struct efx_ptp_data *ptp_data,s64 delta) + __must_hold(&ptp_data->phc_lock) { -u32 nic_major, nic_minor; -struct efx_ptp_data *ptp_data =container_of (ptp, - struct efx_ptp_data, - phc_clock_info); -struct efx_nic *efx = ptp_data->efx;MCDI_DECLARE_BUF (inbuf,MC_CMD_PTP_IN_ADJUST_LEN ); +struct efx_nic *efx = ptp_data->efx; +u32 nic_major, nic_minor; + +lockdep_assert_held (&ptp_data->phc_lock); efx->ptp_data->ns_to_nic_time (delta, &nic_major, &nic_minor);
@@ -2139,6 +2158,18 @@ static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) NULL, 0, NULL); } +static int efx_phc_adjtime (struct ptp_clock_info *ptp,s64 delta) +{ + struct efx_ptp_data *ptp_data = container_of(ptp, struct efx_ptp_data, + phc_clock_info); +int rc; + +mutex_lock (&ptp_data->phc_lock); + rc =_efx_phc_adjtime (ptp_data, delta); +mutex_unlock (&ptp_data->phc_lock); +return rc; +} +static int efx_phc_gettime (struct ptp_clock_info *ptp,struct timespec64 *ts) { struct efx_ptp_data *ptp_data = container_of(ptp,
@@ -2170,23 +2201,21 @@ static int efx_phc_settime(struct ptp_clock_info *ptp, {/* Get the current NIC time, efx_phc_gettime. * Subtract from the desired time to get the offset -* call efx_phc_adjtime with the offset +* call _efx_phc_adjtime with the offset */ + struct efx_ptp_data *ptp_data = container_of(ptp, struct efx_ptp_data, + phc_clock_info); +struct timespec64 time_now, delta;int rc; -struct timespec64 time_now; -struct timespec64 delta; +mutex_lock (&ptp_data->phc_lock); rc =efx_phc_gettime (ptp, &time_now); -if (rc !=0 ) -return rc; - - delta =timespec64_sub (*e_ts, time_now); - - rc =efx_phc_adjtime (ptp,timespec64_to_ns (&delta)); -if (rc !=0 ) -return rc; - -return 0 ; +if (!rc) { + delta =timespec64_sub (*e_ts, time_now); + rc =_efx_phc_adjtime (ptp_data,timespec64_to_ns (&delta)); + } +mutex_unlock (&ptp_data->phc_lock); +return rc; } static int efx_phc_enable(struct ptp_clock_info *ptp,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 130/816 sfc: ptp: avoid racing PPS timestamp updates
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Austin <[email protected]>
[ Upstream commit 23d23e6c6517d0fea4f64340a23e33c89f82c03c ]
efx_ptp_pps_worker() can race with SIOCHWTSTAMP via efx_ptp_change_mode(). After the worker completes synchronization, the ioctl can start another synchronization and update host_time_pps while the worker copies it into the PPS event. This can report a partially updated timestamp. Serializing synchronization transactions alone does not protect this copy, which happens after phc_lock is released.
Return the timestamp through the caller's own pps_event_time rather than the shared field in efx_ptp_data, so the worker reads storage no one else can write.
--- drivers/net/ethernet/sfc/ptp.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/sfc/ptp.c +16 -10
@@ -268,7 +268,6 @@ struct efx_ptp_rxfilter {* @evt_frag_idx: Current fragment number * @evt_code: Last event code * @start: Address at which MC indicates ready for synchronisation -* @host_time_pps: Host time at last PPS * @adjfreq_ppb_shift: Shift required to convert scaled parts-per-billion * frequency adjustment into a fixed point fractional nanosecond format. * @current_adjfreq: Current ppb adjustment.
@@ -330,7 +329,6 @@ struct efx_ptp_data {int evt_frag_idx;int evt_code;struct efx_buffer start; -struct pps_event_time host_time_pps;unsigned int adjfreq_ppb_shift;s64 current_adjfreq;struct ptp_clock *phc_clock;
@@ -912,7 +910,8 @@ static void efx_ptp_read_timeset(MCDI_DECLARE_STRUCT_PTR(data),static int efx_ptp_process_times (struct efx_nic *efx,MCDI_DECLARE_STRUCT_PTR (synch_buf ),size_t response_length, -const struct pps_event_time *last_time) +const struct pps_event_time *last_time, +struct pps_event_time *host_time_pps) {unsigned number_readings = MCDI_VAR_ARRAY_LEN(response_length,
@@ -990,6 +989,10 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), "PTP bad synchronisation seconds\n");return -EAGAIN ; } + +if (!host_time_pps) +return 0 ; + delta.tv_sec = (last_sec - start_sec) &1 ; delta.tv_nsec = last_time->ts_real.tv_nsec -
@@ -1006,8 +1009,8 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), delta.tv_nsec +=ktime_to_timespec64 (mc_time).tv_nsec;/* Set PPS timestamp to match NIC top of second */ - ptp->host_time_pps = *last_time; -pps_sub_ts (&ptp->host_time_pps, delta); + *host_time_pps = *last_time; +pps_sub_ts (host_time_pps, delta);return 0 ; }
@@ -1020,7 +1023,8 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),* the function that registered it, so a secondary function can capture here * without serializing against the primary. */ -static int efx_ptp_synchronize (struct efx_nic *efx,unsigned int num_readings) +static int efx_ptp_synchronize (struct efx_nic *efx,unsigned int num_readings, +struct pps_event_time *host_time_pps) {struct efx_ptp_data *ptp = efx->ptp_data;MCDI_DECLARE_BUF (synch_buf,MC_CMD_PTP_OUT_SYNCHRONIZE_LENMAX );
@@ -1069,7 +1073,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings) &response_length);if (rc ==0 ) { rc =efx_ptp_process_times (efx, synch_buf, response_length, - &last_time); + &last_time, host_time_pps);if (rc ==0 ) ++ptp->good_syncs;else
@@ -1501,14 +1505,15 @@ static void efx_ptp_pps_worker(struct work_struct *work) {struct efx_ptp_data *ptp = container_of(work, struct efx_ptp_data, pps_work); +struct pps_event_time host_time_pps = {};struct efx_nic *efx = ptp->efx;struct ptp_clock_event ptp_evt; -if (efx_ptp_synchronize (efx,PTP_SYNC_ATTEMPTS )) +if (efx_ptp_synchronize (efx,PTP_SYNC_ATTEMPTS , &host_time_pps))return ; ptp_evt.type =PTP_CLOCK_PPSUSR ; - ptp_evt.pps_times = ptp->host_time_pps; + ptp_evt.pps_times = host_time_pps;ptp_clock_event (ptp->phc_clock, &ptp_evt); }
@@ -1849,7 +1854,8 @@ int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted, rc =efx_ptp_start (efx);if (rc ==0 ) { rc =efx_ptp_synchronize (efx, -PTP_SYNC_ATTEMPTS *2 ); +PTP_SYNC_ATTEMPTS *2 , +NULL );if (rc !=0 )efx_ptp_stop (efx); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 131/816 vdpa_sim: serialize IOTLB updates with dataplane access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit 8517ed4429a2eefd002dce00ea46e23e6714350b ]
The simulator translates IOTLB entries into iovecs or bvecs under iommu_lock, then drops the lock before copying data. A concurrent DMA unmap can delete the mapping and release its pinned backing pages while the copy is still in progress, leading to a UAF in _copy_from_iter().
Use the existing simulator mutex to serialize DMA map changes with the full backend work function. Also make vhost-vdpa stop device access before unpinning the backing pages. Otherwise, waiting in the simulator DMA unmap callback happens after the pages have already been released and cannot protect their lifetime.
Keep iommu_lock for the IOTLB table itself and avoid adding a second long-lived lock to the simulator.
I found this bug myself, though the patch was written with AI assistance.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 ++++ drivers/vhost/vdpa.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +4 -0
@@ -714,6 +714,7 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid,if (asid >= vdpasim->dev_attr.nas)return -EINVAL ; +mutex_lock (&vdpasim->mutex);spin_lock (&vdpasim->iommu_lock);if (vdpasim->iommu_pt[asid]) {vhost_iotlb_reset (&vdpasim->iommu[asid]);
@@ -722,6 +723,7 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, ret =vhost_iotlb_add_range_ctx (&vdpasim->iommu[asid], iova, iova + size -1 , pa, perm, opaque);spin_unlock (&vdpasim->iommu_lock); +mutex_unlock (&vdpasim->mutex);return ret; }
@@ -734,6 +736,7 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid,if (asid >= vdpasim->dev_attr.nas)return -EINVAL ; +mutex_lock (&vdpasim->mutex);spin_lock (&vdpasim->iommu_lock);if (vdpasim->iommu_pt[asid]) {vhost_iotlb_reset (&vdpasim->iommu[asid]);
@@ -741,6 +744,7 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, }vhost_iotlb_del_range (&vdpasim->iommu[asid], iova, iova + size -1 );spin_unlock (&vdpasim->iommu_lock); +mutex_unlock (&vdpasim->mutex);return 0 ; }
drivers/vhost/vdpa.c +2 -1
@@ -976,6 +976,8 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,unsigned long pfn, pinned;while ((map =vhost_iotlb_itree_first (iotlb, start, last)) !=NULL ) { +/* Stop device access before releasing the pinned pages. */ +vhost_vdpa_general_unmap (v, map, asid); pinned =PFN_DOWN (map->size);for (pfn =PFN_DOWN (map->addr); pinned >0 ; pfn++, pinned--) {
@@ -985,7 +987,6 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,unpin_user_page (page); }atomic64_sub (PFN_DOWN (map->size), &dev->mm->pinned_vm); -vhost_vdpa_general_unmap (v, map, asid);vhost_iotlb_map_free (iotlb, map); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 132/816 vdpa: invalidate DMA mappings before releasing memory
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit acbf36deb53d9e14e4768bf58883795a8232aa5b ]
vdpa can release pinned pages and file references before the device stops using the corresponding mappings, allowing stale DMA to corrupt memory.
Invalidate mappings before dropping their backing references. For set_map backends, publish an IOTLB without the invalidated range and keep the old references if that fails. Do this immediately even within a batch.
Serialize vdpa_sim set_map updates with its worker so publishing a new map cannot race an active transfer. Abort mlx5 map replacement when resumable virtqueues cannot be suspended, since changing the memory region while those queues remain active would preserve the same stale DMA window. Reject zero-sized and wrapping invalidations before calculating their inclusive range end.
I found this bug myself, though the patch was written with AI assistance.
Message-ID: <[email protected]>
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 10 +++++++- drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 +++ drivers/vhost/vdpa.c | 40 ++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 10 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +9 -1
@@ -3048,7 +3048,15 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,bool teardown = !is_resumable (ndev);int err; -suspend_vqs (ndev,0 , ndev->cur_num_vqs); +if ((mvdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) && !mvdev->suspended) { + err =suspend_vqs (ndev,0 , ndev->cur_num_vqs); +if (err && !teardown) { +for (int i =0 ; i < ndev->cur_num_vqs; i++) +resume_vqs (ndev, i,1 ); +mlx5_vdpa_put_mr (mvdev, new_mr); +return err; + } + }if (teardown) { err =save_channels_info (ndev);if (err) {
drivers/vdpa/vdpa_sim/vdpa_sim.c +3 -0
@@ -639,6 +639,7 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid,if (asid >= vdpasim->dev_attr.nas)return -EINVAL ; +mutex_lock (&vdpasim->mutex);spin_lock (&vdpasim->iommu_lock); iommu = &vdpasim->iommu[asid];
@@ -653,11 +654,13 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, goto err; }spin_unlock (&vdpasim->iommu_lock); +mutex_unlock (&vdpasim->mutex);return 0 ; err:vhost_iotlb_reset (iommu);spin_unlock (&vdpasim->iommu_lock); +mutex_unlock (&vdpasim->mutex);return ret; }
drivers/vhost/vdpa.c +31 -9
@@ -998,10 +998,10 @@ static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,struct vdpa_map_file *map_file;while ((map =vhost_iotlb_itree_first (iotlb, start, last)) !=NULL ) { +vhost_vdpa_general_unmap (v, map, asid); map_file = (struct vdpa_map_file *)map->opaque;fput (map_file->file);kfree (map_file); -vhost_vdpa_general_unmap (v, map, asid);vhost_iotlb_map_free (iotlb, map); } }
@@ -1075,21 +1075,39 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,return 0 ; } -static void vhost_vdpa_unmap (struct vhost_vdpa *v, -struct vhost_iotlb *iotlb, -u64 iova,u64 size) +static int vhost_vdpa_unmap (struct vhost_vdpa *v, +struct vhost_iotlb *iotlb, +u64 iova,u64 size) {struct vdpa_device *vdpa = v->vdpa;const struct vdpa_config_ops *ops = vdpa->config; +struct vhost_iotlb_map *map; +struct vhost_iotlb new_iotlb;u32 asid =iotlb_to_asid (iotlb); +u64 last = iova + size -1 ; +int ret; -vhost_vdpa_iotlb_unmap (v, iotlb, iova, iova + size -1 , asid); +if (ops->set_map && !ops->dma_map) { +vhost_iotlb_init (&new_iotlb, iotlb->limit, iotlb->flags); +list_for_each_entry (map, &iotlb->list, link) { +if (map->start <= last && map->last >= iova) +continue ; + ret =vhost_iotlb_add_range_ctx (&new_iotlb, map->start, + map->last, map->addr, + map->perm, map->opaque); +if (ret) + goto reset; + } -if (ops->set_map) { -if (!v->in_batch) - ops->set_map (vdpa, asid, iotlb); + ret = ops->set_map (vdpa, asid, &new_iotlb); +reset: +vhost_iotlb_reset (&new_iotlb); +if (ret) +return ret; } +vhost_vdpa_iotlb_unmap (v, iotlb, iova, last, asid); +return 0 ; } static int vhost_vdpa_va_map(struct vhost_vdpa *v,
@@ -1339,7 +1357,11 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid, r =vhost_vdpa_process_iotlb_update (v, iotlb, msg);break ;case VHOST_IOTLB_INVALIDATE : -vhost_vdpa_unmap (v, iotlb, msg->iova, msg->size); +if (!msg->size || msg->iova >U64_MAX - msg->size +1 ) { + r = -EINVAL ; +break ; + } + r =vhost_vdpa_unmap (v, iotlb, msg->iova, msg->size);break ;case VHOST_IOTLB_BATCH_BEGIN : v->batch_asid = asid;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 133/816 vhost-scsi: preserve event ordering
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit a9a428115b7d8aa45e12e41899f90f60551bfa82 ]
vhost_scsi_send_evt() uses llist_add(), so pending events are LIFO. vhost_scsi_complete_events() walks the detached list directly. This can deliver a later hotplug or hotunplug event before an earlier one.
Reverse the detached list before processing it.
This keeps delivery in enqueue order.
Message-ID: <[email protected]>
--- drivers/vhost/scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +1 -1
@@ -515,7 +515,7 @@ static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop)struct llist_node *llnode;mutex_lock (&vq->mutex); - llnode =llist_del_all (&vs->vs_event_list); + llnode =llist_reverse_order (llist_del_all (&vs->vs_event_list));llist_for_each_entry_safe (evt, t, llnode, list) {if (!drop)vhost_scsi_do_evt_work (vs, evt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 134/816 vhost-scsi: do not relock event vq mutex on send_evt fallback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit a016d03a9cfe29aeeba438f32f8e8f63291e3275 ]
vhost_scsi_send_evt() is called with the event virtqueue mutex held. If the worker is gone, the fallback currently calls vhost_scsi_complete_events(), which tries to acquire the same mutex again and deadlocks the caller.
Split event completion into a helper for callers that already hold the mutex and a locking wrapper for the event worker. Use the helper on the fallback path.
Message-ID: <[email protected]>
--- drivers/vhost/scsi.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/vhost/scsi.c +11 -4
@@ -508,19 +508,26 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)vq_err (vq,"Faulted on vhost_scsi_send_event\n" ); } -static void vhost_scsi_complete_events (struct vhost_scsi *vs,bool drop) +/* Caller must hold the event virtqueue mutex. */ +static void __vhost_scsi_complete_events (struct vhost_scsi *vs,bool drop) { -struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT ].vq;struct vhost_scsi_evt *evt, *t;struct llist_node *llnode; -mutex_lock (&vq->mutex); llnode =llist_reverse_order (llist_del_all (&vs->vs_event_list));llist_for_each_entry_safe (evt, t, llnode, list) {if (!drop)vhost_scsi_do_evt_work (vs, evt);vhost_scsi_free_evt (vs, evt); } +} + +static void vhost_scsi_complete_events (struct vhost_scsi *vs,bool drop) +{ +struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT ].vq; + +mutex_lock (&vq->mutex); +__vhost_scsi_complete_events (vs, drop);mutex_unlock (&vq->mutex); }
@@ -1595,7 +1602,7 @@ vhost_scsi_send_evt(struct vhost_scsi *vs, struct vhost_virtqueue *vq,llist_add (&evt->list, &vs->vs_event_list);if (!vhost_vq_work_queue (vq, &vs->vs_event_work)) -vhost_scsi_complete_events (vs, true); +__vhost_scsi_complete_events (vs, true); }static void vhost_scsi_evt_handle_kick (struct vhost_work *work)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 135/816 virtio_pci: add missing newline to the pmcsr error message
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoxia <[email protected]>
[ Upstream commit 104d58a6d2592898fbb6989732600b07d543a8e5 ]
The error message emitted when the PCI power management control register cannot be read is not newline-terminated, so the next kernel message is appended to it on the same line.
Add the missing '\n'.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_pci_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.c +1 -1
@@ -636,7 +636,7 @@ static bool vp_supports_pm_no_reset(struct device *dev)pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr);if (PCI_POSSIBLE_ERROR (pmcsr)) { -dev_err (dev,"Unable to query pmcsr" ); +dev_err (dev,"Unable to query pmcsr\n" );return false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 136/816 vdpa: fix double free of the reply skb in vdpa_nl_cmd_dev_config_get_doit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 1f8824fe7f6eaaf2355404db08d3cd05a28aa576 ]
genlmsg_reply() consumes the reply skb on every outcome: netlink_unicast() frees it whether it queues it, drops it, or bails out early. vdpa_nl_cmd_dev_config_get_doit() lets its return value fall through to the shared error label, which calls nlmsg_free(msg) again and double-frees the sk_buff on any reply failure. The failure is reachable unprivileged:VDPA_CMD_DEV_CONFIG_GET carries no GENL_ADMIN_PERM, so batching several requests into one sendto() on a socket with a shrunken SO_RCVBUF fills the receive queue, and netlink_attachskb() then takes its MSG_DONTWAIT path, freeing the skb and returning -EAGAIN.
Set msg to NULL once genlmsg_reply() has consumed it so the shared exit path frees the skb only on the early error gotos that still own it; nlmsg_free(NULL) is a no-op.
BUG: KASAN: slab-use-after-free in sk_skb_reason_drop (net/core/skbuff.c:1220) Read of size 4 at addr ffff88800d99d49c by task exploit/147 Call Trace: sk_skb_reason_drop (net/core/skbuff.c:1220) vdpa_nl_cmd_dev_config_get_doit (drivers/vdpa/vdpa.c:1324) genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114) genl_rcv_msg (net/netlink/genetlink.c:1194) netlink_rcv_skb (net/netlink/af_netlink.c:2556) genl_rcv (net/netlink/genetlink.c:1218) netlink_unicast (net/netlink/af_netlink.c:1345) netlink_sendmsg (net/netlink/af_netlink.c:1900) __sys_sendto (net/socket.c:2281) __x64_sys_sendto (net/socket.c:2284) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) The buggy address belongs to the object at ffff88800d99d3c0 which belongs to the cache skbuff_head_cache of size 232 The buggy address is located 220 bytes inside of freed 232-byte region [ffff88800d99d3c0, ffff88800d99d4a8)
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/vdpa/vdpa.c +4 -3
@@ -1311,15 +1311,16 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info } err =vdpa_dev_config_fill (vdev, msg, info->snd_portid, info->snd_seq,0 , info->extack); -if (!err) +if (!err) { err =genlmsg_reply (msg, info); + msg =NULL ; + } mdev_err:put_device (dev); dev_err:up_read (&vdpa_dev_lock); -if (err) -nlmsg_free (msg); +nlmsg_free (msg);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 137/816 vhost: reject invalid IOTLB update permissions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit b179f21d2d8a60ede29a00472bffdefb0284ef39 ]
vhost_chr_write_iter() validates the type and size of an IOTLB update, but does not validate its permission field. An invalid permission can therefore reach perm_to_iommu_flags() and trigger its warning in vhost_vdpa_map().
Reject IOTLB UPDATE messages whose permission field is empty or contains bits outside VHOST_ACCESS_RW before dispatching them to a backend.
Message-ID: <[email protected]>
--- drivers/vhost/vhost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.c +2 -1
@@ -1728,7 +1728,8 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, goto done; } -if (msg.type ==VHOST_IOTLB_UPDATE && msg.size ==0 ) { +if (msg.type ==VHOST_IOTLB_UPDATE && + (!msg.size || !msg.perm || (msg.perm & ~VHOST_ACCESS_RW ))) { ret = -EINVAL ; goto done; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 138/816 irqbypass: Take ownership of producer/consumer token tracking
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 2b521d86ee80a436a92445b8206d38d75aeb39ea ]
Move ownership of IRQ bypass token tracking into irqbypass.ko, and explicitly require callers to pass an eventfd_ctx structure instead of a completely opaque token. Relying on producers and consumers to set the token appropriately is error prone, and hiding the fact that the token must be an eventfd_ctx pointer (for all intents and purposes) unnecessarily obfuscates the code and makes it more brittle.
Stable-dep-of: c9c1c1b7b31f ("vhost-vdpa: drop the parent's vq callback before the call fd is released")
--- arch/x86/kvm/x86.c | 4 +-- drivers/vfio/pci/vfio_pci_intrs.c | 9 +++---- drivers/vhost/vdpa.c | 8 +++--- include/linux/irqbypass.h | 35 +++++++++++++----------- virt/kvm/eventfd.c | 7 +++-- virt/lib/irqbypass.c | 44 ++++++++++++++++++++----------- 6 files changed, 58 insertions(+), 49 deletions(-)
arch/x86/kvm/x86.c +2 -2
@@ -12850,8 +12850,8 @@ void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons, ret =kvm_x86_call (pi_update_irte)(irqfd->kvm, prod->irq, irqfd->gsi,0 );if (ret) -printk (KERN_INFO "irq bypass consumer (token %p) unregistration" -" fails: %d\n" , irqfd->consumer.token, ret); +printk (KERN_INFO "irq bypass consumer (eventfd %p) unregistration" +" fails: %d\n" , irqfd->consumer.eventfd, ret);spin_unlock_irq (&kvm->irqfds.lock);
drivers/vfio/pci/vfio_pci_intrs.c +3 -6
@@ -512,15 +512,12 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev,if (ret) goto out_put_eventfd_ctx; - ctx->producer.token = trigger; ctx->producer.irq = irq; - ret =irq_bypass_register_producer (&ctx->producer); + ret =irq_bypass_register_producer (&ctx->producer, trigger);if (unlikely (ret)) {dev_info (&pdev->dev, -"irq bypass producer (token %p) registration fails: %d\n" , - ctx->producer.token, ret); - - ctx->producer.token =NULL ; +"irq bypass producer (eventfd %p) registration fails: %d\n" , + trigger, ret); } ctx->trigger = trigger;
drivers/vhost/vdpa.c +3 -5
@@ -225,10 +225,10 @@ static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid)return ; vq->call_ctx.producer.irq = irq; - ret =irq_bypass_register_producer (&vq->call_ctx.producer); + ret =irq_bypass_register_producer (&vq->call_ctx.producer, vq->call_ctx.ctx);if (unlikely (ret)) -dev_info (&v->dev,"vq %u, irq bypass producer (token %p) registration fails, ret = %d\n" , - qid, vq->call_ctx.producer.token, ret); +dev_info (&v->dev,"vq %u, irq bypass producer (eventfd %p) registration fails, ret = %d\n" , + qid, vq->call_ctx.ctx, ret); }static void vhost_vdpa_unsetup_vq_irq (struct vhost_vdpa *v,u16 qid)
@@ -765,7 +765,6 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,if (ops->get_status (vdpa) &VIRTIO_CONFIG_S_DRIVER_OK )vhost_vdpa_unsetup_vq_irq (v, idx); - vq->call_ctx.producer.token =NULL ; }break ; }
@@ -806,7 +805,6 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, cb.callback = vhost_vdpa_virtqueue_cb; cb.private = vq; cb.trigger = vq->call_ctx.ctx; - vq->call_ctx.producer.token = vq->call_ctx.ctx;if (ops->get_status (vdpa) &VIRTIO_CONFIG_S_DRIVER_OK )vhost_vdpa_setup_vq_irq (v, idx);
include/linux/irqbypass.h +19 -16
@@ -10,6 +10,7 @@#include <linux/list.h> +struct eventfd_ctx ;struct irq_bypass_consumer ;/*
@@ -18,20 +19,20 @@ struct irq_bypass_consumer;* The IRQ bypass manager is a simple set of lists and callbacks that allows * IRQ producers (ex. physical interrupt sources) to be matched to IRQ * consumers (ex. virtualization hardware that allows IRQ bypass or offload) -* via a shared token (ex. eventfd_ctx). Producers and consumers register -* independently. When a token match is found, the optional @stop callback -* will be called for each participant. The pair will then be connected via -* the @add_* callbacks, and finally the optional @start callback will allow -* any final coordination. When either participant is unregistered, the -* process is repeated using the @del_* callbacks in place of the @add_* -* callbacks. Match tokens must be unique per producer/consumer, 1:N pairings -* are not supported. +* via a shared eventfd_ctx. Producers and consumers register independently. +* When a producer and consumer are paired, i.e. an eventfd match is found, the +* optional @stop callback will be called for each participant. The pair will +* then be connected via the @add_* callbacks, and finally the optional @start +* callback will allow any final coordination. When either participant is +* unregistered, the process is repeated using the @del_* callbacks in place of +* the @add_* callbacks. eventfds must be unique per producer/consumer, 1:N +* pairings are not supported. */ /** * struct irq_bypass_producer - IRQ bypass producer definition * @node: IRQ bypass manager private list management -* @token: opaque token to match between producer and consumer (non-NULL) +* @eventfd: eventfd context used to match producers and consumers * @irq: Linux IRQ number for the producer device * @add_consumer: Connect the IRQ producer to an IRQ consumer (optional) * @del_consumer: Disconnect the IRQ producer from an IRQ consumer (optional)
@@ -44,7 +45,7 @@ struct irq_bypass_consumer;*/ struct irq_bypass_producer {struct list_head node; -void *token; +struct eventfd_ctx *eventfd;int irq;int (*add_consumer)(struct irq_bypass_producer *,struct irq_bypass_consumer *);
@@ -57,7 +58,7 @@ struct irq_bypass_producer {/** * struct irq_bypass_consumer - IRQ bypass consumer definition * @node: IRQ bypass manager private list management -* @token: opaque token to match between producer and consumer (non-NULL) +* @eventfd: eventfd context used to match producers and consumers * @add_producer: Connect the IRQ consumer to an IRQ producer * @del_producer: Disconnect the IRQ consumer from an IRQ producer * @stop: Perform any quiesce operations necessary prior to add/del (optional)
@@ -70,7 +71,7 @@ struct irq_bypass_producer {*/ struct irq_bypass_consumer {struct list_head node; -void *token; +struct eventfd_ctx *eventfd;int (*add_producer)(struct irq_bypass_consumer *,struct irq_bypass_producer *); void (*del_producer)(struct irq_bypass_consumer *,
@@ -79,9 +80,11 @@ struct irq_bypass_consumer { void (*start)(struct irq_bypass_consumer *); }; -int irq_bypass_register_producer (struct irq_bypass_producer *); -void irq_bypass_unregister_producer (struct irq_bypass_producer *); -int irq_bypass_register_consumer (struct irq_bypass_consumer *); -void irq_bypass_unregister_consumer (struct irq_bypass_consumer *); +int irq_bypass_register_producer (struct irq_bypass_producer *producer, +struct eventfd_ctx *eventfd); +void irq_bypass_unregister_producer (struct irq_bypass_producer *producer); +int irq_bypass_register_consumer (struct irq_bypass_consumer *consumer, +struct eventfd_ctx *eventfd); +void irq_bypass_unregister_consumer (struct irq_bypass_consumer *consumer);#endif /* IRQBYPASS_H */
virt/kvm/eventfd.c +3 -4
@@ -442,15 +442,14 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)#if IS_ENABLED (CONFIG_HAVE_KVM_IRQ_BYPASS )if (kvm_arch_has_irq_bypass ()) { - irqfd->consumer.token = (void *)irqfd->eventfd; irqfd->consumer.add_producer = kvm_arch_irq_bypass_add_producer; irqfd->consumer.del_producer = kvm_arch_irq_bypass_del_producer; irqfd->consumer.stop = kvm_arch_irq_bypass_stop; irqfd->consumer.start = kvm_arch_irq_bypass_start; - ret =irq_bypass_register_consumer (&irqfd->consumer); + ret =irq_bypass_register_consumer (&irqfd->consumer, irqfd->eventfd);if (ret) -pr_info ("irq bypass consumer (token %p) registration fails: %d\n" , - irqfd->consumer.token, ret); +pr_info ("irq bypass consumer (eventfd %p) registration fails: %d\n" , + irqfd->eventfd, ret); }#endif
virt/lib/irqbypass.c +28 -16
155 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 139/816 vhost-vdpa: drop the parents vq callback before the call fd is released
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Zhang <[email protected]>
[ Upstream commit c9c1c1b7b31fc8b9a5d6c04f5f0ae647d081a39d ]
VHOST_SET_VRING_CALL releases the previous call eventfd inside vhost_vring_ioctl() -- it swaps the new context into vq->call_ctx.ctx and then eventfd_ctx_put()s the old one, which is a synchronous kfree(). The parent vdpa device is only told about the change afterwards, when vhost_vdpa_vring_ioctl() reaches ops->set_vq_cb().
Parent drivers cache the pointer handed to them in vdpa_callback::trigger and do not take a reference on it, so throughout that window the parent holds a dangling eventfd_ctx and may signal it. The documentation added with the field describes what signalling it means but says nothing about how long it stays valid.
This is the same hazard that "vhost_vdpa: assign irq bypass producer token correctly" addressed for the irq bypass producer token, by moving vhost_vdpa_unsetup_vq_irq() ahead of the vhost_vring_ioctl() call. The producer token was only one of the two consumers of that pointer; the one the parent keeps via ->set_vq_cb() was left behind the free.
With VDUSE the window is directly reachable from userspace, because the device emulation daemon can inject an interrupt at any time from a different fd, and neither side shares a lock with the other: VDUSE takes vq->irq_lock, vhost takes vhost_dev.mutex + vq->mutex.
BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x76/0xe0 Write of size 4 at addr ffff8881084e8788 by task vduse_uaf/2987 _raw_spin_lock_irqsave+0x76/0xe0 eventfd_signal_mask+0x69/0x120 vduse_dev_ioctl+0x337/0x1a60 <- vduse_vq_signal_irqfd(), inlined __x64_sys_ioctl+0x120/0x170 <- VDUSE_VQ_INJECT_IRQ Allocated by task 2986: do_eventfd+0x50/0x200 __x64_sys_eventfd2+0x2e/0x40
kmalloc-64, freed 64-byte region [ffff8881084e8780, ffff8881084e87c0)
One thread loops VHOST_SET_VRING_CALL on /dev/vhost-vdpa-N with a fresh eventfd and then unbinds it, while another loops VDUSE_VQ_INJECT_IRQ on /dev/vduse/<name>. This reproduces in 5 out of 5 ten-second runs on v7.1.6 and 3 out of 3 on v7.2-rc6. With the patch there are no reports in 3 out of 3 runs on either, while the same workload still gets ~30000 interrupts per run delivered into live eventfds, so the path is still being exercised.
Tell the parent to drop the callback before vhost_vring_ioctl() can free the eventfd, mirroring what is already done for the bypass producer, and restore it if the ioctl fails -- on failure the swap never happened, the old context is still installed, and leaving the parent without a callback would silently drop that vq's interrupts.
Clearing the callback only stops a parent from starting to use the context; a handler that already loaded it can still be running. For parents with a real interrupt, wait for it with synchronize_irq() on the vq's irq. VDUSE does not implement get_vq_irq, so that case stays covered by the teardown above.
Message-ID: <[email protected]>
--- drivers/vhost/vdpa.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/vhost/vdpa.c +34 -1
@@ -765,13 +765,46 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,if (ops->get_status (vdpa) &VIRTIO_CONFIG_S_DRIVER_OK )vhost_vdpa_unsetup_vq_irq (v, idx); +/* +* The parent caches call_ctx.ctx in cb.trigger without +* holding a reference, so it has to stop using it +* before vhost_vring_ioctl() drops the last one. +*/ + cb.callback =NULL ; + cb.private =NULL ; + cb.trigger =NULL ; + ops->set_vq_cb (vdpa, idx, &cb); + +/* +* A parent interrupt handler that loaded the callback +* before that store can still be running, so wait for +* it to finish with the context too. +*/ +if (ops->get_vq_irq) { +int irq = ops->get_vq_irq (vdpa, idx); + +if (irq >=0 ) +synchronize_irq (irq); + } }break ; } r =vhost_vring_ioctl (&v->vdev, cmd, argp); -if (r) +if (r) { +/* +* A failure here means the swap never happened and the old +* context is still installed, so give the parent back the +* callback that was torn down above. +*/ +if (cmd ==VHOST_SET_VRING_CALL && vq->call_ctx.ctx) { + cb.callback = vhost_vdpa_virtqueue_cb; + cb.private = vq; + cb.trigger = vq->call_ctx.ctx; + ops->set_vq_cb (vdpa, idx, &cb); + }return r; + }switch (cmd) {case VHOST_SET_VRING_ADDR :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 140/816 virtio-blk: clamp max_segments to virtqueue ring size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergii Ushakov <[email protected]>
[ Upstream commit 434d2bc41bd0c0ac576d4d259bd9f2ab49071174 ]
In virtblk_add_req(), each request consumes 2 extra descriptors (out_hdr and in_hdr) in addition to the data scatter-gather segments.
When a hypervisor (e.g. QNX Hypervisor) advertises VIRTIO_BLK_F_SEG_MAX with seg_max = 1024 alongside a 1024-entry split ring (vring.num = 1024) and VIRTIO_RING_F_INDIRECT_DESC disabled, lim->max_segments is set to 1024. When the block layer submits requests with 1023 or 1024 data segments, total_sg reaches 1025 or 1026. This exceeds vring.num (1024), causing virtqueue_add_split() to return -ENOSPC and permanently wedge the blk-mq queue.
Furthermore, the Virtio specification (2.7.5.3.1) requires that a descriptor chain never exceed the Queue Size, and virtqueue_add_split() falls back to direct descriptors if indirect table allocation fails.
Fix this by:
1. Rejecting queues with ring_size < 3 at probe, or ring_size < (queue_max_segments + 2) during resume/reset recovery in init_vq().
2. Unconditionally clamping sg_elems to (ring_size - 2) across all virtqueues in virtblk_read_limits().
Message-ID: <[email protected]>
--- drivers/block/virtio_blk.c | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +43 -1
@@ -1021,6 +1021,30 @@ static int init_vq(struct virtio_blk *vblk) goto out;for (i =0 ; i < num_vqs; i++) { +unsigned int ring_size =virtqueue_get_vring_size (vqs[i]); +/* +* Each request consumes 2 extra descriptors (out_hdr and +* in_hdr) in addition to the data segments. +* +* At initial probe (!vblk->disk), each virtqueue must fit at +* least 1 data segment + 2 header descriptors (3). +* On resume/recovery (vblk->disk), each virtqueue must fit the +* existing queue_max_segments() + 2 header descriptors. +*/ +unsigned int min_ring_size =3 ; + +if (vblk->disk) + min_ring_size =queue_max_segments (vblk->disk->queue) +2 ; + +if (ring_size < min_ring_size) { +dev_err (&vdev->dev, +"virtqueue %u ring size %u is smaller than minimum %u\n" , + i, ring_size, min_ring_size); + vdev->config->del_vqs (vdev); + err = -EINVAL ; + goto out; + } +spin_lock_init (&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; }
@@ -1247,7 +1271,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,u16 min_io_size;u8 physical_block_exp, alignment_offset;size_t max_dma_size; -int err; +int err, i;/* We need to know how many segments before we allocate. */ err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SEG_MAX,
@@ -1261,6 +1285,23 @@ static int virtblk_read_limits(struct virtio_blk *vblk,/* Prevent integer overflows and honor max vq size */ sg_elems =min_t (u32, sg_elems,VIRTIO_BLK_MAX_SG_ELEMS -2 ); +/* +* virtblk_add_req() uses separate outgoing and incoming header +* descriptors (out_hdr and in_hdr), consuming 2 extra descriptors +* per request in addition to the data segments. +* +* Per virtio specification (2.7.5.3.1), a driver MUST NOT create a +* descriptor chain longer than the Queue Size of the device. +* +* Clamp max_segments to (ring_size - 2) across all virtqueues so +* that a request never exceeds the ring size of any queue. +*/ +for (i =0 ; i < vblk->num_vqs; i++) { +u32 ring_size =virtqueue_get_vring_size (vblk->vqs[i].vq); + + sg_elems =min_t (u32, sg_elems, ring_size -2 ); + } +/* We can handle whatever the host told us to handle. */ lim->max_segments = sg_elems;
@@ -1460,6 +1501,7 @@ static int virtblk_probe(struct virtio_device *vdev)mutex_init (&vblk->vdev_mutex); vblk->vdev = vdev; + vblk->disk =NULL ;INIT_WORK (&vblk->config_work, virtblk_config_changed_work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 141/816 virtio_blk: Reset device on probe error paths after DRIVER_OK
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit f4f6e9a9cb349003d333f0776de94f12ac95b8d2 ]
virtblk_probe() marks the device ready before revalidating zones and adding the disk, and either of those can fail. The out_cleanup_disk path they take goes on to delete the virtqueues, but nothing tells the device to stop first, so it is still live when the rings are freed.
Reset the device at out_cleanup_disk, which is only reachable after virtio_device_ready(). virtblk_remove() and virtblk_freeze_priv() both reset before deleting the virtqueues for the same reason.
Message-ID: <[email protected]>
--- drivers/block/virtio_blk.c | 1 + 1 file changed, 1 insertion(+)
drivers/block/virtio_blk.c +1 -0
@@ -1584,6 +1584,7 @@ static int virtblk_probe(struct virtio_device *vdev)return 0 ; out_cleanup_disk: +virtio_reset_device (vdev);put_disk (vblk->disk); out_free_tags:blk_mq_free_tag_set (&vblk->tag_set);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 142/816 regulator: qcom_spmi: dont take a sleeping lock in the SAW IPI
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Baryshkov <[email protected]>
[ Upstream commit 053c50a7052549aab0d310ad505947db3e211592 ]
The SAW voltage change runs on CPU 0 from an IPI, but it reaches the SAW registers through the syscon regmap, which is protected by a spinlock_t. That is a sleeping lock on PREEMPT_RT, and lockdep complains as soon as VDD_APCC actually changes voltage:
BUG: Invalid wait context ... regmap_lock_spinlock+0x18/0x30 regmap_read+0x3c/0x78 spmi_saw_set_vdd+0x50/0x1ac __flush_smp_call_function_queue+0x1ac/0x334
Map the SAW with a regmap of our own that uses a raw spinlock, and fail the probe when that cannot be done instead of carrying an error pointer around as the SAW regmap.
--- drivers/regulator/Kconfig | 1 + drivers/regulator/qcom_spmi-regulator.c | 35 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-)
drivers/regulator/Kconfig +1 -0
@@ -1101,6 +1101,7 @@ config REGULATOR_QCOM_SMD_RPM config REGULATOR_QCOM_SPMI tristate "Qualcomm SPMI regulator driver" depends on SPMI || COMPILE_TEST + select REGMAP_MMIO help If you say yes to this option, support will be included for the regulators found in Qualcomm SPMI PMICs.
drivers/regulator/qcom_spmi-regulator.c +27 -8
@@ -12,13 +12,13 @@#include <linux/bitops.h> #include <linux/slab.h> #include <linux/of.h> +#include <linux/of_address.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/ktime.h> #include <linux/regulator/driver.h> #include <linux/regmap.h> #include <linux/list.h> -#include <linux/mfd/syscon.h> #include <linux/io.h> /* Pin control enable input pins. */
@@ -1332,6 +1332,14 @@ static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data)static struct regmap *saw_regmap; +static const struct regmap_config saw_regmap_config = { + .name ="saw" , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .use_raw_spinlock = true, +}; +static void spmi_saw_set_vdd (void *data) {u32 vctl, data3, avs_ctl, pmic_sts;
@@ -2509,7 +2517,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)const char *name;struct device *dev = &pdev->dev;struct device_node *node = pdev->dev.of_node; -struct device_node *syscon, *reg_node; +struct device_node *saw, *reg_node; +void __iomem *saw_base;struct property *reg_prop;int ret, lenp;struct list_head *vreg_list;
@@ -2528,12 +2537,22 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)if (!reg)return -ENODEV ; - syscon =of_parse_phandle (node,"qcom,saw-reg" ,0 ); -if (syscon) { - saw_regmap =syscon_node_to_regmap (syscon); -of_node_put (syscon); -if (IS_ERR (saw_regmap)) -dev_err (dev,"ERROR reading SAW regmap\n" ); + saw =of_parse_phandle (node,"qcom,saw-reg" ,0 ); +if (saw) { + saw_base =devm_of_iomap (dev, saw,0 ,NULL ); +of_node_put (saw); +if (IS_ERR (saw_base)) +return dev_err_probe (dev,PTR_ERR (saw_base), +"failed to map the SAW\n" ); + + saw_regmap =devm_regmap_init_mmio (dev, saw_base, + &saw_regmap_config); +if (IS_ERR (saw_regmap)) { + ret =PTR_ERR (saw_regmap); + saw_regmap =NULL ; +return dev_err_probe (dev, ret, +"failed to set the SAW regmap up\n" ); + } }for (; reg->name; reg++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 143/816 net: sparx5/lan969x: release the in-flight slot of a stale TX skb
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit 873363ac591a1774aa3ced84f7ea3d93a3eb9b07 ]
sparx5_ptp_txtstamp_request() counts every two step TX skb waiting for its timestamp in sparx5->ptp_skbs, and refuses new ones once SPARX5_MAX_PTP_ID are in flight. sparx5_ptp_txtstamp_old_release() frees the skbs that have waited longer than SPARX5_PTP_TIMEOUT.
Before this patch, old_release() does not decrement ptp_skbs, so every skb whose timestamp never arrives, for example because the switch discarded the frame, keeps its slot forever. Once SPARX5_MAX_PTP_ID slots are lost, two step frames fail to transmit on every port of the switch.
Return the number of released skbs from old_release() and subtract it from ptp_skbs in txtstamp_request(), under the ptp_ts_id_lock it already takes.
This fixes the accounting only. A port's stale skbs are still aged out only when that port sends a two step frame, so a port that stops sending them keeps its stale skbs, and their slots, until it sends one again. That behaviour is unchanged by this patch.
Found by an AI code review agent. Reproduced on a lan9696 board with a modified kernel that drops the TX timestamps of two step frames, after which two step timestamping stopped working on the port. With the fix, timestamping keeps working on that board and on a sparx5 PCB135 board.
--- drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +8 -2
@@ -200,9 +200,10 @@ static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb, *rew_op =IFH_REW_OP_TWO_STEP_PTP ; } -static void sparx5_ptp_txtstamp_old_release (struct sparx5_port *port) +static unsigned int sparx5_ptp_txtstamp_old_release (struct sparx5_port *port) {struct sk_buff *skb, *skb_tmp; +unsigned int purged =0 ;unsigned long flags;spin_lock_irqsave (&port->tx_skbs.lock, flags);
@@ -213,8 +214,11 @@ static void sparx5_ptp_txtstamp_old_release(struct sparx5_port *port)__skb_unlink (skb, &port->tx_skbs);dev_kfree_skb_any (skb); + purged++; }spin_unlock_irqrestore (&port->tx_skbs.lock, flags); + +return purged; } int sparx5_ptp_txtstamp_request(struct sparx5_port *port,
@@ -222,6 +226,7 @@ int sparx5_ptp_txtstamp_request(struct sparx5_port *port, {struct sparx5 *sparx5 = port->sparx5;u8 rew_op, pdu_type, pdu_w16_offset; +unsigned int purged;unsigned long flags;sparx5_ptp_classify (port, skb, &rew_op, &pdu_type, &pdu_w16_offset);
@@ -232,9 +237,10 @@ int sparx5_ptp_txtstamp_request(struct sparx5_port *port,if (rew_op !=IFH_REW_OP_TWO_STEP_PTP )return 0 ; -sparx5_ptp_txtstamp_old_release (port); + purged =sparx5_ptp_txtstamp_old_release (port);spin_lock_irqsave (&sparx5->ptp_ts_id_lock, flags); + sparx5->ptp_skbs -= purged;if (sparx5->ptp_skbs ==SPARX5_MAX_PTP_ID ) {spin_unlock_irqrestore (&sparx5->ptp_ts_id_lock, flags);return -EBUSY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 144/816 gpio: mpc8xxx: use a helper variable to store the address of pdev->dev
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 2707a028c9b9c54a6dff22c9dcfebf3083ea095e ]
Instead of repeatedly dereferencing pdev, just store the address of the embedded struct device in a local variable and use it instead for improved readability.
While at it: rearrange variable declarations.
Stable-dep-of: 9e4b35c95fed ("gpio: mpc8xxx: Fix potential use-after-free of IRQ domain")
--- drivers/gpio/gpio-mpc8xxx.c | 48 +++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 26 deletions(-)
drivers/gpio/gpio-mpc8xxx.c +22 -26
@@ -300,14 +300,15 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {static int mpc8xxx_probe (struct platform_device *pdev) { +const struct mpc8xxx_gpio_devtype *devtype =NULL ;struct device_node *np = pdev->dev.of_node;struct mpc8xxx_gpio_chip *mpc8xxx_gc; -struct gpio_chip *gc; -const struct mpc8xxx_gpio_devtype *devtype =NULL ; +struct device *dev = &pdev->dev;struct fwnode_handle *fwnode; +struct gpio_chip *gc;int ret; - mpc8xxx_gc =devm_kzalloc (&pdev->dev,sizeof (*mpc8xxx_gc),GFP_KERNEL ); + mpc8xxx_gc =devm_kzalloc (dev,sizeof (*mpc8xxx_gc),GFP_KERNEL );if (!mpc8xxx_gc)return -ENOMEM ;
@@ -320,32 +321,28 @@ static int mpc8xxx_probe(struct platform_device *pdev)return PTR_ERR (mpc8xxx_gc->regs); gc = &mpc8xxx_gc->gc; - gc->parent = &pdev->dev; - -if (device_property_read_bool (&pdev->dev,"little-endian" )) { - ret =bgpio_init (gc, &pdev->dev,4 , - mpc8xxx_gc->regs +GPIO_DAT , -NULL ,NULL , - mpc8xxx_gc->regs +GPIO_DIR ,NULL , -BGPIOF_BIG_ENDIAN ); + gc->parent = dev; + +if (device_property_read_bool (dev,"little-endian" )) { + ret =bgpio_init (gc, dev,4 , mpc8xxx_gc->regs +GPIO_DAT , +NULL ,NULL , mpc8xxx_gc->regs +GPIO_DIR , +NULL ,BGPIOF_BIG_ENDIAN );if (ret)return ret; -dev_dbg (&pdev->dev,"GPIO registers are LITTLE endian\n" ); +dev_dbg (dev,"GPIO registers are LITTLE endian\n" ); }else { - ret =bgpio_init (gc, &pdev->dev,4 , - mpc8xxx_gc->regs +GPIO_DAT , -NULL ,NULL , - mpc8xxx_gc->regs +GPIO_DIR ,NULL , -BGPIOF_BIG_ENDIAN + ret =bgpio_init (gc, dev,4 , mpc8xxx_gc->regs +GPIO_DAT , +NULL ,NULL , mpc8xxx_gc->regs +GPIO_DIR , +NULL ,BGPIOF_BIG_ENDIAN |BGPIOF_BIG_ENDIAN_BYTE_ORDER );if (ret)return ret; -dev_dbg (&pdev->dev,"GPIO registers are BIG endian\n" ); +dev_dbg (dev,"GPIO registers are BIG endian\n" ); } mpc8xxx_gc->direction_output = gc->direction_output; - devtype =device_get_match_data (&pdev->dev); + devtype =device_get_match_data (dev);if (!devtype) devtype = &mpc8xxx_gpio_devtype_default;
@@ -370,7 +367,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)* associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate * the port value to the GPIO Data Register. */ - fwnode =dev_fwnode (&pdev->dev); + fwnode =dev_fwnode (dev); if (of_device_is_compatible(np, "fsl,qoriq-gpio") || of_device_is_compatible(np, "fsl,ls1028a-gpio") || of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
@@ -381,9 +378,9 @@ static int mpc8xxx_probe(struct platform_device *pdev) gc->read_reg (mpc8xxx_gc->regs +GPIO_DIR ); } - ret =devm_gpiochip_add_data (&pdev->dev, gc, mpc8xxx_gc); + ret =devm_gpiochip_add_data (dev, gc, mpc8xxx_gc);if (ret) { -dev_err (&pdev->dev, +dev_err (dev,"GPIO chip registration failed with status %d\n" , ret);return ret; }
@@ -404,18 +401,17 @@ static int mpc8xxx_probe(struct platform_device *pdev) gc->write_reg (mpc8xxx_gc->regs +GPIO_IER ,0xffffffff ); gc->write_reg (mpc8xxx_gc->regs +GPIO_IMR ,0 ); - ret =devm_request_irq (&pdev->dev, mpc8xxx_gc->irqn, + ret =devm_request_irq (dev, mpc8xxx_gc->irqn, mpc8xxx_gpio_irq_cascade,IRQF_NO_THREAD |IRQF_SHARED ,"gpio-cascade" , mpc8xxx_gc);if (ret) { -dev_err (&pdev->dev, -"failed to devm_request_irq(%d), ret = %d\n" , +dev_err (dev,"failed to devm_request_irq(%d), ret = %d\n" , mpc8xxx_gc->irqn, ret); goto err; } -device_init_wakeup (&pdev->dev, true); +device_init_wakeup (dev, true);return 0 ; err:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 145/816 gpio: mpc8xxx: Fix potential use-after-free of IRQ domain
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 9e4b35c95fede87bad36f68b7ff1eae94ea6b910 ]
GPIO chip cleanup can call the to_irq callback while releasing requested GPIOs. Removing the IRQ domain first leaves that callback using a freed domain, both on removal and after an IRQ request failure.
Register domain cleanup before GPIO chip registration so devres removes the chip before freeing the domain.
This issue was found by our static analysis tool under development.
--- drivers/gpio/gpio-mpc8xxx.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mpc8xxx.c +15 -7
@@ -298,6 +298,14 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = { {} }; +static void mpc8xxx_irq_domain_remove (void *data) +{ +struct mpc8xxx_gpio_chip *mpc8xxx_gc = data; + +if (mpc8xxx_gc->irq) +irq_domain_remove (mpc8xxx_gc->irq); +} +static int mpc8xxx_probe (struct platform_device *pdev) {const struct mpc8xxx_gpio_devtype *devtype =NULL ;
@@ -378,6 +386,11 @@ static int mpc8xxx_probe(struct platform_device *pdev) gc->read_reg (mpc8xxx_gc->regs +GPIO_DIR ); } +/* GPIO chip cleanup still needs the IRQ domain. */ + ret =devm_add_action_or_reset (dev, mpc8xxx_irq_domain_remove, mpc8xxx_gc); +if (ret) +return ret; + ret =devm_gpiochip_add_data (dev, gc, mpc8xxx_gc);if (ret) { dev_err(dev,
@@ -408,25 +421,20 @@ static int mpc8xxx_probe(struct platform_device *pdev)if (ret) {dev_err (dev,"failed to devm_request_irq(%d), ret = %d\n" , mpc8xxx_gc->irqn, ret); - goto err; +return ret; }device_init_wakeup (dev, true);return 0 ; -err: -irq_domain_remove (mpc8xxx_gc->irq); -return ret; }static void mpc8xxx_remove (struct platform_device *pdev) {struct mpc8xxx_gpio_chip *mpc8xxx_gc =platform_get_drvdata (pdev); -if (mpc8xxx_gc->irq) { +if (mpc8xxx_gc->irq)irq_set_chained_handler_and_data (mpc8xxx_gc->irqn,NULL ,NULL ); -irq_domain_remove (mpc8xxx_gc->irq); - } }static int mpc8xxx_suspend (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 146/816 net/iucv: take a private, writable frame before rewriting it in place
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit f38bce9af9e2a3cced7d303a1476f21c1f42bcb7 ]
afiucv_hs_rcv() rewrites the frame in place -- EBCASC() on four name fields, then afiucv_swap_src_dest() swaps them and pushes an Ethernet header -- and can hand the same skb to dev_queue_xmit(), without making it private first, so a packet socket that also gets the frame reads the rewritten names. An ETH_P_ALL tap runs first and leaves af_iucv a cloned skb; a socket opened for ETH_P_AF_IUCV sits on a ptype_specific list, walked after ptype_base[], so deliver_skb() takes a reference and af_iucv runs on an skb that is shared but not cloned.
Unshare, then cow, in that order: skb_cow() can reach pskb_expand_head(), which has BUG_ON(skb_shared()). skb_cow() tests skb_cloned(), which is what a rewrite of the data needs; skb_cow_head() tests only the header. Asking for ETH_HLEN also covers the unchecked push in afiucv_swap_src_dest(); on the ordinary path eth_type_trans() has already pulled that much, so it only compares.
--- net/iucv/af_iucv.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/iucv/af_iucv.c +9 -0
@@ -2071,11 +2071,20 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,int err =NET_RX_SUCCESS ;char nullstring[8 ]; + skb =skb_share_check (skb,GFP_ATOMIC ); +if (!skb) +return NET_RX_SUCCESS ; +if (!pskb_may_pull (skb,sizeof (*trans_hdr))) {kfree_skb (skb);return NET_RX_SUCCESS ; } +if (skb_cow (skb,ETH_HLEN )) { +kfree_skb (skb); +return NET_RX_SUCCESS ; + } + trans_hdr =iucv_trans_hdr (skb);EBCASC (trans_hdr->destAppName,sizeof (trans_hdr->destAppName));EBCASC (trans_hdr->destUserID,sizeof (trans_hdr->destUserID));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 147/816 ASoC: meson: axg-fifo: request the irq with the clock enabled
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jerome Brunet <[email protected]>
[ Upstream commit 82fa7bfab6b961a03d6575348334e0ec15fdc712 ]
The fifo irq handler accesses registers which need pclk, but the irq is requested before pclk is enabled on open and freed after it is disabled on close.
Request the irq after enabling pclk and masking the fifo irqs. Free it before disabling pclk.
--- sound/soc/meson/axg-fifo.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
sound/soc/meson/axg-fifo.c +14 -14
@@ -244,17 +244,10 @@ int axg_fifo_pcm_open(struct snd_soc_component *component,if (ret)return ret; -/* Use the threaded irq handler only with non-atomic links */ - ret =request_threaded_irq (fifo->irq,NULL , - axg_fifo_pcm_irq_block, -IRQF_ONESHOT ,dev_name (dev), ss); -if (ret) -return ret; -/* Enable pclk to access registers and clock the fifo ip */ ret =clk_prepare_enable (fifo->pclk);if (ret) - goto free_irq; +return ret;/* Setup status2 so it reports the memory pointer */ regmap_update_bits(fifo->map, FIFO_CTRL1,
@@ -271,17 +264,24 @@ int axg_fifo_pcm_open(struct snd_soc_component *component,/* Clear any pending interrupt */ axg_fifo_ack_irq (fifo,FIFO_INT_MASK ); +/* Use the threaded irq handler only with non-atomic links */ + ret =request_threaded_irq (fifo->irq,NULL , + axg_fifo_pcm_irq_block, +IRQF_ONESHOT ,dev_name (dev), ss); +if (ret) + goto free_clk; +/* Take memory arbitror out of reset */ ret =reset_control_deassert (fifo->arb);if (ret) - goto free_clk; + goto free_irq;return 0 ; -free_clk: -clk_disable_unprepare (fifo->pclk); free_irq:free_irq (fifo->irq, ss); +free_clk: +clk_disable_unprepare (fifo->pclk);return ret; }EXPORT_SYMBOL_GPL (axg_fifo_pcm_open);
@@ -295,12 +295,12 @@ int axg_fifo_pcm_close(struct snd_soc_component *component,/* Put the memory arbitror back in reset */ ret =reset_control_assert (fifo->arb); -/* Disable fifo ip and register access */ -clk_disable_unprepare (fifo->pclk); -/* remove IRQ */ free_irq (fifo->irq, ss); +/* Disable fifo ip and register access */ +clk_disable_unprepare (fifo->pclk); +return ret; }EXPORT_SYMBOL_GPL (axg_fifo_pcm_close);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 148/816 Bluetooth: hci_core: Initialize IRK before publication
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Deng <[email protected]>
[ Upstream commit f0cf5a24cefeb629876bd15d668ff062c8655e28 ]
hci_add_irk() initializes the identity address and address type of a newly allocated IRK, publishes it on hdev->identity_resolving_keys, and only then initializes its value and RPA. RCU readers such as hci_find_irk_by_rpa() and the debugfs identity_resolving_keys_show() can traverse the new entry during that window and see a zero or partially initialized IRK.
The race is reachable by racing an IRK addition with another CPU resolving or dumping IRKs. In particular, userspace can issue MGMT_OP_LOAD_IRKS while another process reads the corresponding debugfs file or triggers RPA resolution.
Initialize the IRK value and RPA before publishing a newly allocated IRK. Existing IRKs remain published and continue to be updated in place.
Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only.
--- net/bluetooth/hci_core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/bluetooth/hci_core.c +6 -3
@@ -1353,9 +1353,10 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,struct smp_irk *hci_add_irk (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 addr_type,u8 val[16 ],bdaddr_t *rpa) { -struct smp_irk *irk; +struct smp_irk *irk, *old_irk; - irk =hci_find_irk_by_addr (hdev, bdaddr, addr_type); + old_irk =hci_find_irk_by_addr (hdev, bdaddr, addr_type); + irk = old_irk;if (!irk) { irk =kzalloc (sizeof (*irk),GFP_KERNEL );if (!irk)
@@ -1364,12 +1365,14 @@ struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,bacpy (&irk->bdaddr, bdaddr); irk->addr_type = addr_type; -list_add_rcu (&irk->list, &hdev->identity_resolving_keys); }memcpy (irk->val, val,16 );bacpy (&irk->rpa, rpa); +if (!old_irk) +list_add_rcu (&irk->list, &hdev->identity_resolving_keys); +return irk; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 149/816 Bluetooth: hci_core: Initialize link key before publication
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Deng <[email protected]>
[ Upstream commit ae9c8df1ffb84560ac01cbdc26cfb19027f4d25f ]
hci_add_link_key() allocates a new link key with kzalloc(), inserts it into hdev->link_keys with list_add_rcu(), and only then initializes its address, value, type, and PIN length. RCU readers such as hci_find_link_key() and the debugfs link_keys_show() do not take hci_dev_lock, so they can traverse the new entry during that initialization window and observe a zero or partially initialized key.
This can be triggered by racing a link-key update with another CPU looking up or dumping keys. In particular, userspace can issue MGMT_OP_LOAD_LINK_KEYS while another process reads the corresponding debugfs file.
Complete all fields of a newly allocated key before publishing it with list_add_rcu(). Existing keys remain visible and keep their current in-place update behavior.
Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only.
--- net/bluetooth/hci_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_core.c +3 -1
@@ -1290,7 +1290,6 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, key =kzalloc (sizeof (*key),GFP_KERNEL );if (!key)return NULL ; -list_add_rcu (&key->list, &hdev->link_keys); }BT_DBG ("%s key for %pMR type %u" , hdev->name, bdaddr, type);
@@ -1314,6 +1313,9 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,else key->type = type; +if (!old_key) +list_add_rcu (&key->list, &hdev->link_keys); +if (persistent) *persistent =hci_persistent_key (hdev, conn, type, old_key_type);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 150/816 Bluetooth: hci_core: Initialize LTK before publication
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Deng <[email protected]>
[ Upstream commit 4335849380aa1081ee9a1c2b934cbdda0961fa57 ]
hci_add_ltk() publishes a newly allocated LTK on hdev->long_term_keys before initializing its address, type, value, authentication state, encryption size, EDIV, and random value. hci_find_ltk() and the debugfs long_term_keys_show() traverse this list under RCU and can therefore see a zero or partially initialized key before those stores complete.
The race is reachable by racing an LTK addition with another CPU looking up or dumping long-term keys. For example, userspace can issue MGMT_OP_LOAD_LONG_TERM_KEYS while another process reads the corresponding debugfs file.
Initialize all fields of a new LTK before list_add_rcu() makes it visible to RCU readers. Existing LTKs remain published and continue to be updated in place.
Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only.
--- net/bluetooth/hci_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_core.c +3 -1
@@ -1337,7 +1337,6 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, key =kzalloc (sizeof (*key),GFP_KERNEL );if (!key)return NULL ; -list_add_rcu (&key->list, &hdev->long_term_keys); }bacpy (&key->bdaddr, bdaddr);
@@ -1349,6 +1348,9 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, key->enc_size = enc_size; key->type = type; +if (!old_key) +list_add_rcu (&key->list, &hdev->long_term_keys); +return key; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 151/816 Bluetooth: hci_core: Fix queuing rx_work while workqueue is drained
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akhil Arul <[email protected]>
[ Upstream commit 19b4e5701712f74d005cc66a36374559e8dfd281 ]
hci_recv_frame() drops a frame unless HCI_UP or HCI_INIT is set, but the check is not synchronized with hci_dev_close_sync(). A driver can pass the check, then close clears HCI_UP, flushes rx_work and starts drain_workqueue(), and the late queue_work() of rx_work hits the draining workqueue:
workqueue: cannot queue hci_rx_work on wq hci0
WARNING: kernel/workqueue.c:2352 at __queue_work+0x2c0/0x780 Call Trace: queue_work_on+0xb2/0xc0 hci_recv_frame+0x18f/0x330 vhci_write+0x174/0x240 vfs_write+0x271/0x680 ksys_write+0x7c/0x110
Skipping the queue_work() while HCI_CMD_DRAIN_WORKQUEUE is set, as done for tx_work, does not work for rx_work: the flag covers the whole close, and events still have to be received in that window, for the commands sent by hdev->shutdown() and for the reset done with HCI_QUIRK_RESET_ON_CLOSE.
Run hci_recv_frame() under rcu_read_lock() and wait with synchronize_rcu() once HCI_UP has been cleared, so that every caller which still saw HCI_UP has queued its work before the workqueue is drained, and later callers drop the frame.
HCI_INIT does not reopen that window. Apart from the HCI_QUIRK_RESET_ON_CLOSE reset, which runs after drain_workqueue() has returned, it is only set by hci_dev_init_sync() during open, and open and close are serialized by hci_req_sync_lock. So once the grace period has ended, nothing can pass the check and queue rx_work until the drain is over.
Tested in qemu with the syzbot C reproducer, one run per boot: the warning showed up on 12 of 30 boots before and on none of 42 boots after. Bringing a vhci controller up and down 50 times behaves the same with and without this change.
--- net/bluetooth/hci_core.c | 9 +++++++++ net/bluetooth/hci_sync.c | 5 +++++ 2 files changed, 14 insertions(+)
net/bluetooth/hci_core.c +9 -0
@@ -2962,8 +2962,14 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) {u8 dev_pkt_type; +/* Pairs with synchronize_rcu() in hci_dev_close_sync(), so rx_work is +* not queued once the workqueue is being drained. +*/ +rcu_read_lock (); +if (!hdev || (!test_bit (HCI_UP , &hdev->flags) && !test_bit (HCI_INIT , &hdev->flags))) { +rcu_read_unlock ();kfree_skb (skb);return -ENXIO ; }
@@ -2996,6 +3002,7 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)case HCI_ISODATA_PKT :break ;default : +rcu_read_unlock ();kfree_skb (skb);return -EINVAL ; }
@@ -3009,6 +3016,8 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)skb_queue_tail (&hdev->rx_q, skb);queue_work (hdev->workqueue, &hdev->rx_work); +rcu_read_unlock (); +return 0 ; }EXPORT_SYMBOL (hci_recv_frame);
net/bluetooth/hci_sync.c +5 -0
@@ -5508,6 +5508,11 @@ int hci_dev_close_sync(struct hci_dev *hdev)return err; } +/* Wait for hci_recv_frame() callers that still saw HCI_UP, so that +* none of them queues rx_work while the workqueue is drained below. +*/ +synchronize_rcu (); +hci_leds_update_powered (hdev, false);/* Flush RX and TX works */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 152/816 Bluetooth: btintel: fix buffer over-read in fw payload
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catherine L <[email protected]>
[ Upstream commit f92b7bca985205082c86140d0bd7c86c5be00efc ]
The firmware decoder cast fw_ptr + frag_len to struct hci_command_hdr and read cmd->plen before confirming the header and payload still fit in the remaining firmware buffer.
Add explicit bounds checks before each dereference:
1. Reject if the command header is not fully contained in remain.
2. Reject if the full command including payload exceeds remain.
3. Log the offending fragment length and remaining size before returning -EINVAL.
--- drivers/bluetooth/btintel.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/bluetooth/btintel.c +23 -1
@@ -1081,7 +1081,29 @@ static int btintel_download_firmware_payload(struct hci_dev *hdev, err = -EINVAL ;while (fw_ptr - fw->data < fw->size) { -struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len); +struct hci_command_hdr *cmd; +size_t remain = fw->size - (fw_ptr - fw->data); + +/* Ensure the header fits before dereferencing */ +if (frag_len +sizeof (*cmd) > remain) { +bt_dev_err (hdev, +"Firmware buffer overrun at header (frag_len %u, need %zu, remain %zu)" , + frag_len, frag_len +sizeof (*cmd), remain); + err = -EINVAL ; + goto done; + } + + cmd = (void *)(fw_ptr + frag_len); + +/* Ensure the full command (header + payload) fits before use */ +if (frag_len +sizeof (*cmd) + cmd->plen > remain) { +bt_dev_err (hdev, +"Firmware buffer overrun at payload (frag_len %u, plen %u, need %zu, remain %zu)" , + frag_len, cmd->plen, + frag_len +sizeof (*cmd) + cmd->plen, remain); + err = -EINVAL ; + goto done; + } frag_len +=sizeof (*cmd) + cmd->plen;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 153/816 Bluetooth: hci_event: Clear explicit connect state on LE connection
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Dewald <[email protected]>
[ Upstream commit f5cd268af1c6f87fb3847e98274e22b8c6324aa4 ]
Since commit 6cd29ec6ae5e ("Bluetooth: hci_sync: Wait for proper events when connecting LE"), create_le_conn_complete() only runs once the LE Connection Complete event has been handled, and le_conn_complete_evt() has already removed the connection parameters from pend_le_conns by then. hci_connect_le_scan_cleanup() looks the parameters up in pend_le_conns, so after a successful connection it no longer clears explicit_connect, nor deletes the parameters that were only created for the explicit connect.
The parameters of every device connected through an explicit connect, such as an L2CAP or ATT connect or MGMT Pair Device, are thus left with explicit_connect set. MGMT Remove Device for all devices then keeps them as HCI_AUTO_CONN_EXPLICIT instead of freeing them, and if the device was set to auto-connect and is disconnected, they also stay onpend_le_conns: the kernel keeps scanning for the device and connects to it as soon as it advertises, although no one asked for it any more.
Do the cleanup in le_conn_complete_evt() instead, where the explicit connect request is fulfilled: clear explicit_connect, delete the parameters if they only existed for it, and put report parameters back on pend_le_reports. Auto-connect parameters are added back to pend_le_conns on disconnection, as before. Update the comment in hci_explicit_conn_params_set() that names hci_connect_le_scan_cleanup() as the only place deleting them.
--- net/bluetooth/hci_conn.c | 5 +++-- net/bluetooth/hci_event.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-)
net/bluetooth/hci_conn.c +3 -2
@@ -1450,8 +1450,9 @@ static int hci_explicit_conn_params_set(struct hci_dev *hdev,if (!params)return -ENOMEM ; -/* If we created new params, mark them to be deleted in -* hci_connect_le_scan_cleanup. It's different case than +/* If we created new params, mark them to be deleted once the +* explicit connect is done, see le_conn_complete_evt() and +* hci_connect_le_scan_cleanup(). It's different case than * existing disabled params, those will stay after cleanup. */ params->auto_connect =HCI_AUTO_CONN_EXPLICIT ;
net/bluetooth/hci_event.c +22 -0
@@ -5862,6 +5862,28 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,hci_conn_put (params->conn); params->conn =NULL ; } + +/* An explicit connect request is complete once connected, so +* clean it up here: hci_connect_le_scan_cleanup() no longer +* finds the params since they have just been removed from +* pend_le_conns. +*/ +if (params->explicit_connect) { + params->explicit_connect = false; + +switch (params->auto_connect) { +case HCI_AUTO_CONN_EXPLICIT : +hci_conn_params_del (hdev, &conn->dst, + conn->dst_type); +break ; +case HCI_AUTO_CONN_REPORT : +hci_pend_le_list_add (params, + &hdev->pend_le_reports); +break ; +default : +break ; + } + } } unlock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 154/816 Bluetooth: btmtk: drop zero-length ISO packets from endpoint padding
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Lu <[email protected]>
[ Upstream commit 8524c3588fbb9d5c1b876e6f908c42926845650d ]
The ISO interrupt IN endpoint delivers a fixed-size transfer that holds one HCI ISO packet and zero-fills the remainder. That padding belongs to the transfer rather than to the stream, so it has to be dropped instead of reported to the host.
btmtk_recv_isopkt() keeps parsing it: the zero bytes read as an ISO header with handle 0 and a Data_Total_Length of zero, and each one is passed to hci_recv_frame() as a complete frame. A single transfer yields a long run of them, which is what fills the HCI log with malformed ISO packets, and iso_recv() drops the SDU it is reassembling whenever handle 0 belongs to a live CIS/BIS.
A zero Data_Total_Length carries no ISO Data Load, so such a packet is never part of the stream. Check for the zero-filled remainder before starting to parse the next frame, rather than after assembling a 4-byte
header: a remainder shorter than HCI_ISO_HDR_SIZE would otherwise be held across calls as a partial header, corrupting the next transfer's framing. This also means a fully zero-filled remainder no longer costs an skb allocation that gets immediately freed. Reaching a zero Data_Total_Length any other way is then a genuine error, not padding.
This was observed on MT7925, but btmtk_recv_isopkt() is shared by every MediaTek USB controller that supports ISO data.
--- drivers/bluetooth/btmtk.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/bluetooth/btmtk.c +20 -0
@@ -7,6 +7,7 @@#include <linux/usb.h> #include <linux/iopoll.h> #include <linux/overflow.h> +#include <linux/string.h> #include <linux/unaligned.h> #include <net/bluetooth/bluetooth.h>
@@ -1176,6 +1177,14 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count)int len;if (!skb) { +/* Drop the endpoint's zero-filled padding before +* allocating an skb for it; a zero Data_Total_Length +* check below would miss a padding remainder +* shorter than an ISO header. +*/ +if (mem_is_zero (buffer, count)) +break ; + skb =bt_skb_alloc (HCI_MAX_ISO_SIZE ,GFP_ATOMIC );if (!skb) { err = -ENOMEM ;
@@ -1199,6 +1208,17 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count)/* Complete ISO header */ hci_skb_expect (skb) =__le16_to_cpu (dlen); +if (!hci_skb_expect (skb)) { +/* Zero padding was ruled out above, so a +* zero Data_Total_Length here is invalid. +*/ +kfree_skb (skb); + skb =NULL ; + + err = -EILSEQ ; +break ; + } +if (skb_tailroom (skb) <hci_skb_expect (skb)) {kfree_skb (skb); skb =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 155/816 Bluetooth: btmtk: bound the ISO payload length by the controllers MTU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Lu <[email protected]>
[ Upstream commit d015faf684129a276f2137ad2e11c6c985294648 ]
btmtk_recv_isopkt() bounds the Data_Total_Length reported by the controller with skb_tailroom(skb) < hci_skb_expect(skb). That keeps the reassembly inside the skb, but it enforces no protocol limit: the head allocation is rounded up to the next kmalloc bucket and skb_tailroom() reports what the bucket can hold rather than what was requested, which is several hundred bytes more. An oversized length therefore passes, and the parser keeps pulling bytes out of the following transfers to fill it, swallowing the real ISO packets they carry until the frame is handed to hci_recv_frame().
The controller reports the largest ISO_Data_Packet_Length it will send in LE Read Buffer Size [v2], which hci_cc_le_read_buffer_size_v2() keeps in hdev->iso_mtu. Once that is available, bound the length by it and size the receive skb to hold that much plus the 4-byte header. HCI_MAX_ISO_SIZE is kept only as a fallback for the window before the command completes.
Keep the skb_tailroom() test as well, because a fragment started before hdev->iso_mtu was populated sits in an skb sized for the fallback.
--- drivers/bluetooth/btmtk.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/bluetooth/btmtk.c +16 -2
@@ -1168,8 +1168,15 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count)struct btmtk_data *btmtk_data =hci_get_priv (hdev);struct sk_buff *skb;unsigned long flags; +unsigned int iso_mtu;int err =0 ; +/* The controller reports the largest Data_Total_Length it will send in +* LE Read Buffer Size [v2]. Fall back to HCI_MAX_ISO_SIZE while that +* command has not completed yet. +*/ + iso_mtu = hdev->iso_mtu ? hdev->iso_mtu :HCI_MAX_ISO_SIZE ; +spin_lock_irqsave (&btmtk_data->isorxlock, flags); skb = btmtk_data->isopkt_skb;
@@ -1185,7 +1192,8 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count)if (mem_is_zero (buffer, count))break ; - skb =bt_skb_alloc (HCI_MAX_ISO_SIZE ,GFP_ATOMIC ); + skb =bt_skb_alloc (HCI_ISO_HDR_SIZE + iso_mtu, +GFP_ATOMIC );if (!skb) { err = -ENOMEM ;break ;
@@ -1219,7 +1227,13 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count)break ; } -if (skb_tailroom (skb) <hci_skb_expect (skb)) { +/* Reject a length the controller said it would never +* send. The skb_tailroom() test is kept because a +* fragment started before hdev->iso_mtu was populated +* sits in a smaller skb than iso_mtu now allows. +*/ +if (hci_skb_expect (skb) > iso_mtu || +skb_tailroom (skb) <hci_skb_expect (skb)) {kfree_skb (skb); skb =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 156/816 Bluetooth: btmtk: derive the firmware ISO setting from MTK_ISO_THRESHOLD
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Lu <[email protected]>
[ Upstream commit 855c9a54608f1e94f4c52afe3790def30534155a ]
The ISO data transfer size is spelled out twice: as a raw byte pair in the vendor command sent by btmtk_usb_isointf_init(), and as MTK_ISO_THRESHOLD for the padding in btmtk_isopkt_pad(). Build the command payload from the macro so the size is stated once, and update the setting for current MediaTek controllers.
--- drivers/bluetooth/btmtk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/bluetooth/btmtk.c +3 -3
@@ -25,7 +25,7 @@#define MTK_SEC_MAP_NEED_SEND_SIZE 52/* It is for mt79xx iso data transmission setting */ -#define MTK_ISO_THRESHOLD 264 +#define MTK_ISO_THRESHOLD 342struct btmtk_patch_header {u8 datetime[16 ];
@@ -1352,7 +1352,7 @@ static int btmtk_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)static int btmtk_usb_isointf_init (struct hci_dev *hdev) {struct btmtk_data *btmtk_data =hci_get_priv (hdev); -u8 iso_param[2 ] = {0x08 ,0x01 }; +__le16 iso_param =cpu_to_le16 (MTK_ISO_THRESHOLD );struct sk_buff *skb;int err;
@@ -1367,7 +1367,7 @@ static int btmtk_usb_isointf_init(struct hci_dev *hdev)return err; } - skb =__hci_cmd_sync (hdev,0xfd98 ,sizeof (iso_param), iso_param, + skb =__hci_cmd_sync (hdev,0xfd98 ,sizeof (iso_param), &iso_param,HCI_INIT_TIMEOUT );if (IS_ERR (skb)) {bt_dev_err (hdev,"Failed to apply iso setting (%ld)" ,PTR_ERR (skb));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 157/816 Bluetooth: hci_sync: Copy the LE accept list under hdev->lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 674006912777747170ad70d7727804ad4f2d047f ]
The LE accept-list mirror consists of bdaddr_list entries that are added, removed and freed under hdev->lock. The ordinary branch of hci_update_accept_list_sync() traverses this list without that lock. The request worker's req_lock does not serialize raw HCI completions, and the RCU sections protect connection and pending-action lookups, not the accept-list nodes.
Changing connectability can reach this iterator through set_connectable_sync(), hci_update_connectable_sync(), hci_update_passive_scan_sync() and hci_passive_scan_sync(). With a populated mirror, a privileged raw HCI sender can issue HCI_OP_LE_CLEAR_ACCEPT_LIST while request work is reconciling it:
Request work HCI event work
select b and successor t
hci_cc_le_clear_accept_list()
hci_dev_lock(hdev) hci_bdaddr_list_clear()
unlink nodes and kfree(b)
hci_dev_unlock(hdev)
read b->bdaddr_type
The clear completion can therefore free the selected node before its field read, or the saved successor before the iterator advances. KASAN reported a one-byte read of bdaddr_type from the freed node.
Copy each entry's address and type under hdev->lock and reconcile the private array instead. Release the mutex before issuing synchronous commands, since their completion handlers also acquire it. Free the copy after iteration and use the existing error path to disable accept-list filtering if allocation fails.
This change has not been runtime-tested.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in hci_passive_scan_sync+0x1cc4/0x1f80
Read of size 1 at addr ffff888105ee6c56 by task kworker/u17:1/499
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? hci_passive_scan_sync+0x1cc4/0x1f80
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? hci_passive_scan_sync+0x1cc4/0x1f80
kasan_report+0xe0/0x110
? hci_passive_scan_sync+0x1cc4/0x1f80
hci_passive_scan_sync+0x1cc4/0x1f80
? pmbd_gate_site_armed+0x31/0x1c0
? __pfx_hci_passive_scan_sync+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? pmbd_probe_hit_cookie+0x10/0x1c0
? __pfx_pmbd_probe_hit_cookie+0x10/0x10
? hci_update_passive_scan_sync+0x43f/0x9e0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
hci_update_passive_scan_sync+0x473/0x9e0
hci_update_connectable_sync+0x13c/0x250
set_connectable_sync+0x39/0xb0
hci_cmd_sync_work+0x1b3/0x450
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 511:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
hci_bdaddr_list_add+0x179/0x390
hci_cc_le_add_to_accept_list+0x189/0x2d0
hci_cmd_complete_evt+0x373/0xab0
hci_event_packet+0x4e8/0xc70
hci_rx_work+0x367/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
Freed by task 511:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
hci_bdaddr_list_clear+0x134/0x230
hci_cc_le_clear_accept_list+0x80/0x1f0
hci_cmd_complete_evt+0x373/0xab0
hci_event_packet+0x4e8/0xc70
hci_rx_work+0x367/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
The buggy address belongs to the object at ffff888105ee6c40
which
belongs to the cache kmalloc-32 of size 32
The buggy address is located 22 bytes inside of
freed
32-byte region [ffff888105ee6c40,
ffff888105ee6c60)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000
index:0xffff888105ee69c0 pfn:0x105ee6
flags: 0x200000000000200(workingset|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000200 ffff888100042780 ffffea0004187150
ffffea00042534d0
raw: ffff888105ee69c0 000000000040003f 00000000f5000000
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888105ee6b00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
ffff888105ee6b80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
>ffff888105ee6c00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
^
ffff888105ee6c80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
ffff888105ee6d00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================--- net/bluetooth/hci_sync.c | 53 ++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-)
net/bluetooth/hci_sync.c +43 -10
@@ -2923,6 +2923,31 @@ static struct conn_params *conn_params_copy(struct list_head *list, size_t *n)return p; } +static struct conn_params *le_accept_list_copy (struct hci_dev *hdev, +size_t *n) +{ +struct bdaddr_list *entry; +struct conn_params *params; +size_t i =0 ; + +hci_dev_lock (hdev); + + *n =list_count_nodes (&hdev->le_accept_list); + params = kvzalloc_objs(struct conn_params, *n); +if (!params) + goto unlock; + +list_for_each_entry (entry, &hdev->le_accept_list, list) { +bacpy (¶ms[i].addr, &entry->bdaddr); + params[i].addr_type = entry->bdaddr_type; + i++; + } + +unlock: +hci_dev_unlock (hdev); +return params; +} +/* Clear LE Accept List */ static int hci_le_clear_accept_list_sync (struct hci_dev *hdev) {
@@ -2953,7 +2978,6 @@ static int hci_le_clear_accept_list_sync(struct hci_dev *hdev)static u8 hci_update_accept_list_sync (struct hci_dev *hdev) {struct conn_params *params; -struct bdaddr_list *b, *t;u8 num_entries =0 ;bool pend_conn, pend_report;u8 filter_policy;
@@ -3018,20 +3042,27 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)* report. If not present in either list, then remove it from * the controller. */ -list_for_each_entry_safe (b, t, &hdev->le_accept_list, list) { + params =le_accept_list_copy (hdev, &n); +if (!params) { + err = -ENOMEM ; + goto done; + } + +for (i =0 ; i < n; i++) {rcu_read_lock (); -if (hci_conn_hash_lookup_le (hdev, &b->bdaddr, b->bdaddr_type)) { +if (hci_conn_hash_lookup_le (hdev, ¶ms[i].addr, + params[i].addr_type)) {rcu_read_unlock ();continue ; } pend_conn =hci_pend_le_action_lookup (&hdev->pend_le_conns, - &b->bdaddr, - b->bdaddr_type); - pend_report =hci_pend_le_action_lookup (&hdev->pend_le_reports, - &b->bdaddr, - b->bdaddr_type); + ¶ms[i].addr, + params[i].addr_type); + pend_report =hci_pend_le_action_lookup ( + &hdev->pend_le_reports, ¶ms[i].addr, + params[i].addr_type);rcu_read_unlock ();
@@ -3039,14 +3070,16 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)* remove it from the acceptlist. */ if (!pend_conn && !pend_report) { -hci_le_del_accept_list_sync (hdev, &b->bdaddr, - b->bdaddr_type); +hci_le_del_accept_list_sync (hdev, ¶ms[i].addr, + params[i].addr_type);continue ; } num_entries++; } +kvfree (params); +/* Since all no longer valid accept list entries have been * removed, walk through the list of pending connections * and ensure that any new device gets programmed into
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 158/816 Bluetooth: hci_sync: Protect resolving-list lookups
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f05bd61a3213613de7848c8df2865492d5225023 ]
The host resolving list is updated under hdev->lock, and each bdaddr_list_with_irk entry must remain alive throughout a lookup. hci_le_del_resolve_list_sync() and hci_le_add_resolve_list_sync() traverse that list without taking the lock.
On an LE privacy-capable controller with a programmed entry, passive scan reconciliation can reach hci_le_del_resolve_list_sync() while a privileged HCI_RAW client sends LE Clear Resolving List. The raw command does not take req_lock, and its successful completion runs on the controller workqueue independently of request work:
Request work Raw HCI / event work
hci_le_del_resolve_list_sync()
lookup loads a list node
hci_sock_sendmsg()
queue LE Clear Resolving List
hci_cc_le_clear_resolv_list()
take hdev->lock unlink and free the node release hdev->lock
read the node's address/type
The clear can free the node after the lookup loads it and before its address/type read, causing a use-after-free. The report below shows this access with the delete helper on the faulting stack. The add helper uses the same unprotected lookup.
Take hdev->lock around each resolving-list membership lookup and retain only a boolean result. This serializes traversal with clear completion and keeps entry pointers inside the protected section. Release the lock before issuing a synchronous HCI command, whose completion also needs the lock.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in
hci_bdaddr_list_lookup_with_irk+0x106/0x120
Read of size 1 at addr ffff88810b036e16 by task kworker/u17:0/495
CPU: 2 UID: 0 PID: 495 Comm: kworker/u17:0 Not tainted
7.2.0-rc6-pmb-bt-functional-v1+ #3 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix,
1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? hci_bdaddr_list_lookup_with_irk+0x106/0x120
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? hci_bdaddr_list_lookup_with_irk+0x106/0x120
kasan_report+0xe0/0x110
? hci_bdaddr_list_lookup_with_irk+0x106/0x120
hci_bdaddr_list_lookup_with_irk+0x106/0x120
hci_le_del_resolve_list_sync.isra.0+0xd6/0x3f0
? __pfx_hci_le_del_resolve_list_sync.isra.0+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
hci_le_del_accept_list_sync.isra.0+0x11c/0x290
? __pfx_hci_le_del_accept_list_sync.isra.0+0x10/0x10
? hci_passive_scan_sync+0x551/0x1e80
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
hci_passive_scan_sync+0x71c/0x1e80
? __pfx_hci_passive_scan_sync+0x10/0x10
? find_held_lock+0x2b/0x80
? hci_lookup_le_connect+0xe1/0x3c0
? srso_alias_return_thunk+0x5/0xfbef5
? find_held_lock+0x2b/0x80
? hci_update_passive_scan_sync+0x437/0x950
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
hci_update_passive_scan_sync+0x461/0x950
hci_cmd_sync_work+0x1b3/0x450
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 495:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
hci_bdaddr_list_add_with_irk+0x183/0x3e0
hci_cc_le_add_to_resolv_list+0x18c/0x240
hci_cmd_complete_evt+0x373/0xab0
hci_event_packet+0x4e8/0xc70
hci_rx_work+0x367/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
Freed by task 497:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
hci_bdaddr_list_clear+0x134/0x230
hci_cc_le_clear_resolv_list+0x13d/0x240
hci_cmd_complete_evt+0x373/0xab0
hci_event_packet+0x4e8/0xc70
hci_rx_work+0x367/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
The buggy address belongs to the object at ffff88810b036e00
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 22 bytes inside of
freed 64-byte region [ffff88810b036e00, ffff88810b036e40)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0
pfn:0x10b036
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000428c0 dead000000000100
dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88810b036d00: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff88810b036d80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff88810b036e00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff88810b036e80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810b036f00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================
Disabling lock debugging due to kernel taint--- net/bluetooth/hci_sync.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
net/bluetooth/hci_sync.c +12 -9
@@ -2491,15 +2491,17 @@ static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) {struct hci_cp_le_del_from_resolv_list cp; -struct bdaddr_list_with_irk *entry; +bool exists;if (!use_ll_privacy (hdev))return 0 ;/* Check if the IRK has been programmed */ - entry =hci_bdaddr_list_lookup_with_irk (&hdev->le_resolv_list, bdaddr, - bdaddr_type); -if (!entry) +hci_dev_lock (hdev); + exists =hci_bdaddr_list_lookup_with_irk (&hdev->le_resolv_list, + bdaddr, bdaddr_type); +hci_dev_unlock (hdev); +if (!exists)return 0 ; cp.bdaddr_type = bdaddr_type;
@@ -2555,8 +2557,8 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, {struct hci_cp_le_add_to_resolv_list cp;struct smp_irk *irk; -struct bdaddr_list_with_irk *entry;struct hci_conn_params *p; +bool exists;if (!use_ll_privacy (hdev))return 0 ;
@@ -2578,10 +2580,11 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev,return 0 ;/* Check if the IK has _not_ been programmed yet. */ - entry =hci_bdaddr_list_lookup_with_irk (&hdev->le_resolv_list, - ¶ms->addr, - params->addr_type); -if (entry) +hci_dev_lock (hdev); + exists =hci_bdaddr_list_lookup_with_irk ( + &hdev->le_resolv_list, ¶ms->addr, params->addr_type); +hci_dev_unlock (hdev); +if (exists)return 0 ; cp.bdaddr_type = params->addr_type;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 159/816 Bluetooth: mgmt: reply to cancelled mgmt commands instead of silently dropping
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuai Zhang <[email protected]>
[ Upstream commit c0bb764fc082672678d371c375597a6a9f614cf9 ]
The kernel sets HCI_AUTO_OFF when a controller is first registered and starts a 2-second timer. On slower boots bluetoothd and the HCI_AUTO_OFF timer can race: hci_power_off() is already queued while bluetoothd is still in the middle of its adapter setup sequence. hci_cmd_sync_clear() then cancels any pending mgmt commands with -ECANCELED, including the MGMT_OP_REMOVE_ADV_MONITOR sent by reset_adv_monitors() early in the setup sequence.
When auto_off=1, hci_dev_close_sync() skips __mgmt_power_off() entirely, so there is no fallback path to reply to the cancelled commands. mgmt_remove_adv_monitor_complete() silently returns on -ECANCELED, leaving the command with no reply. Since bluez's mgmt queue is strictly serialised, this stalls all subsequent commands indefinitely, leaving bluetoothd unable to register the adapter.
Fix by mapping -ECANCELED to MGMT_STATUS_CANCELLED in mgmt_errno_status() and replying to the cancelled command in mgmt_remove_adv_monitor_complete() instead of returning early.
Stable-dep-of: 7eac80614300 ("Bluetooth: MGMT: Return RFKILLED for Set Powered on a blocked controller")
--- net/bluetooth/mgmt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
net/bluetooth/mgmt.c +13 -1
@@ -303,6 +303,8 @@ static u8 mgmt_errno_status(int err)return MGMT_STATUS_ALREADY_CONNECTED ;case -ENOTCONN :return MGMT_STATUS_DISCONNECTED ; +case -ECANCELED : +return MGMT_STATUS_CANCELLED ; }return MGMT_STATUS_FAILED ;
@@ -5652,8 +5654,18 @@ static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev,struct mgmt_pending_cmd *cmd = data;struct mgmt_cp_remove_adv_monitor *cp; -if (status == -ECANCELED ) +/* Reply to a cancelled command so bluetoothd's serialised mgmt queue +* is not blocked. +*/ +if (status == -ECANCELED ) { + cp = cmd->param; + rp.monitor_handle = cp->monitor_handle; + +mgmt_cmd_complete (cmd->sk, cmd->hdev->id, cmd->opcode, +mgmt_status (status), &rp,sizeof (rp)); +mgmt_pending_free (cmd);return ; + }hci_dev_lock (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 160/816 Bluetooth: MGMT: Return RFKILLED for Set Powered on a blocked controller
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tobias Wilken <[email protected]>
[ Upstream commit 7eac80614300563470cffabf4df2b63616787ee7 ]
Since MGMT_OP_SET_POWERED runs through hci_cmd_sync, powering on a controller that is blocked by rfkill fails with -ERFKILL from hci_dev_open_sync(), and mgmt_set_powered_complete() reports it with mgmt_status(err). mgmt_errno_status() has no case for -ERFKILL, so userspace gets MGMT_STATUS_FAILED instead of MGMT_STATUS_RFKILLED.
Before that conversion, power on went through hci_power_on(), whose error path mgmt_set_powered_failed() still maps -ERFKILL to MGMT_STATUS_RFKILLED. bluetoothd relies on that status: for RFKILLED it sets the adapter PowerState to "off-blocked" and returns org.bluez.Error.Blocked for the Powered property, for any other status it returns org.bluez.Error.Failed.
With the controller soft blocked, "bluetoothctl power on" printed "Failed to set power on: org.bluez.Error.Failed" and btmon showed "Set Powered (0x0005) Status: Failed (0x03)". With this change it prints org.bluez.Error.Blocked and btmon shows "Status: RFKilled (0x12)".
Map -ERFKILL to MGMT_STATUS_RFKILLED in mgmt_errno_status().
--- net/bluetooth/mgmt.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/mgmt.c +2 -0
@@ -305,6 +305,8 @@ static u8 mgmt_errno_status(int err)return MGMT_STATUS_DISCONNECTED ;case -ECANCELED :return MGMT_STATUS_CANCELLED ; +case -ERFKILL : +return MGMT_STATUS_RFKILLED ; }return MGMT_STATUS_FAILED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 161/816 Bluetooth: btmtk: fix error handling in btmtk_usb_isointf_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ismail Tarim <[email protected]>
[ Upstream commit 3b70dd827b27bfadd89e7b1a2d422b04da38797c ]
btmtk_usb_isointf_init() submits the ISO interrupt IN URB and then sends the vendor command 0xfd98. If that command fails, the function returns an error without killing the URB it has just submitted. The caller then leaves BTMTK_ISOPKT_RUNNING clear, so the driver treats the ISO path as inactive while its RX URB is still in flight, and btmtk_usb_suspend() skips killing it. Kill the anchored URBs on this path, as the URB submission failure path already does.
The return value of __set_mtk_intr_interface() is also ignored: a failure to select the ISO alternate setting or to find its endpoints is logged, but the function goes on to submit the URB. Return the error instead.
--- drivers/bluetooth/btmtk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/bluetooth/btmtk.c +4 -1
@@ -1358,7 +1358,9 @@ static int btmtk_usb_isointf_init(struct hci_dev *hdev)spin_lock_init (&btmtk_data->isorxlock); -__set_mtk_intr_interface (hdev); + err =__set_mtk_intr_interface (hdev); +if (err <0 ) +return err; err =btmtk_submit_intr_urb (hdev,GFP_KERNEL );if (err <0 ) {
@@ -1370,6 +1372,7 @@ static int btmtk_usb_isointf_init(struct hci_dev *hdev) skb =__hci_cmd_sync (hdev,0xfd98 ,sizeof (iso_param), &iso_param,HCI_INIT_TIMEOUT );if (IS_ERR (skb)) { +usb_kill_anchored_urbs (&btmtk_data->isopkt_anchor);bt_dev_err (hdev,"Failed to apply iso setting (%ld)" ,PTR_ERR (skb));return PTR_ERR (skb); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 162/816 Bluetooth: hci_core: Keep link-key filtering inside RCU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 281ddc4e01ab54cab07995f2a1b72cf81bf90eb5 ]
hci_find_link_key() must keep the matching link key allocated while it checks the key against the blocked-key list. It currently leaves the key-list RCU read-side section before passing k->val to hci_is_blocked_key(). That helper's own RCU section protects the blocked-key list, but it cannot keep an unlinked link key from being reclaimed.
The SMP receive path calls the finder without hdev->lock: Secure Connections key distribution over BR/EDR reaches it through smp_distribute_keys() and sc_generate_ltk(). With a stored peer link key and a link-key entry in the blocked-key list, MGMT_OP_LOAD_LINK_KEYS can free the selected key before the comparison:
HCI RX worker (SMP) Management / RCU reclamation
hci_find_link_key()
rcu_read_lock()
select k
rcu_read_unlock()
load_link_keys()
hci_dev_lock(hdev)
hci_link_keys_clear(hdev)
list_del_rcu(), kfree_rcu()
hci_dev_unlock(hdev)
grace period ends, k is freed
hci_is_blocked_key(hdev, ..., k->val)
memcmp() reads the freed keyKeep the RCU read-side section active through the blocked-key comparison and the warning that prints k->bdaddr, and release it before returning on both matched-key paths. hci_find_ltk() already handles its blocked-key check this way.
KASAN reported this on a test kernel whose scheduling hook paused the receive worker after the lookup until the key had been freed.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in hci_is_blocked_key+0x2db/0x300
Read of size 1 at addr ffff88810b5f89a7 by task kworker/u17:0/502
CPU: 1 UID: 0 PID: 502 Comm: kworker/u17:0 Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #5 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: hci1 hci_rx_work
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? hci_is_blocked_key+0x2db/0x300
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? hci_is_blocked_key+0x2db/0x300
kasan_report+0xe0/0x110
? hci_is_blocked_key+0x2db/0x300
hci_is_blocked_key+0x2db/0x300
hci_find_link_key+0x12e/0x400
smp_distribute_keys+0x1830/0x2950
? trace_hardirqs_on+0x18/0x160
? srso_alias_return_thunk+0x5/0xfbef5
? queue_delayed_work_on+0xb3/0xf0
? __pfx_smp_distribute_keys+0x10/0x10
? __pfx_smp_send_cmd.isra.0+0x10/0x10
? __cancel_work+0x1b0/0x290
? __entry_text_end+0x1020f7/0x1020f9
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? __asan_memset+0x23/0x50
? smp_recv_cb+0x12c7/0x8d80
? srso_alias_return_thunk+0x5/0xfbef5
smp_recv_cb+0x12c7/0x8d80
? __pfx_smp_recv_cb+0x10/0x10
? __pfx___might_resched+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? stack_depot_save_flags+0x29/0x9a0
? srso_alias_return_thunk+0x5/0xfbef5
? __mutex_lock+0x182c/0x2590
? kasan_save_stack+0x42/0x60
? l2cap_recv_frame+0x9ef/0x8830
? __kasan_slab_free+0x5f/0x80
? kmem_cache_free+0x242/0x580
? kfree_skbmem+0x15e/0x1d0
? sk_skb_reason_drop+0x12f/0x490
? hci_event_packet+0x556/0xc70
? hci_rx_work+0x367/0xf00
? process_one_work+0x908/0x19c0
? worker_thread+0x65c/0xe40
? __pfx___mutex_lock+0x10/0x10
? __lock_acquire+0x466/0x2260
? __pfx_l2cap_chan_hold_unless_zero+0x10/0x10
? l2cap_recv_frame+0x13cc/0x8830
? __pfx_smp_recv_cb+0x10/0x10
l2cap_recv_frame+0x13cc/0x8830
? srso_alias_return_thunk+0x5/0xfbef5
? __mutex_lock+0x182c/0x2590
? __pfx_l2cap_recv_frame+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? find_held_lock+0x2b/0x80
? l2cap_recv_acldata+0x1eb/0x10e0
? __pfx___mutex_lock+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __mutex_unlock_slowpath+0x147/0x920
? __pfx_l2cap_conn_hold_unless_zero+0x10/0x10
? __pfx_hci_conn_enter_active_mode+0x10/0x10
? l2cap_recv_acldata+0x13d/0x10e0
? srso_alias_return_thunk+0x5/0xfbef5
l2cap_recv_acldata+0xe9f/0x10e0
? srso_alias_return_thunk+0x5/0xfbef5
hci_rx_work+0x5a6/0xf00
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 504:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
hci_add_link_key+0x474/0x840
hci_link_key_notify_evt+0x492/0xce0
hci_event_packet+0x894/0xc70
hci_rx_work+0x367/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
Freed by task 29:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
__rcu_free_sheaf_prepare+0x65/0x2a0
rcu_free_sheaf_nobarn+0x1d/0x50
rcu_core+0x661/0x1d10
handle_softirqs+0x201/0x930
run_ksoftirqd+0x33/0x60
smpboot_thread_fn+0x3bd/0x9a0
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
The buggy address belongs to the object at ffff88810b5f8980
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 39 bytes inside of
freed 64-byte region [ffff88810b5f8980, ffff88810b5f89c0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10b5f8
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000428c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88810b5f8880: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810b5f8900: 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc
>ffff88810b5f8980: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff88810b5f8a00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810b5f8a80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================--- net/bluetooth/hci_core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/bluetooth/hci_core.c +2 -3
@@ -1111,17 +1111,16 @@ struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)rcu_read_lock ();list_for_each_entry_rcu (k, &hdev->link_keys, list) {if (bacmp (bdaddr, &k->bdaddr) ==0 ) { -rcu_read_unlock (); -if (hci_is_blocked_key (hdev,HCI_BLOCKED_KEY_TYPE_LINKKEY , k->val)) {bt_dev_warn_ratelimited (hdev,"Link key blocked for %pMR" , &k->bdaddr); -return NULL ; + k =NULL ; } +rcu_read_unlock ();return k; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 163/816 Bluetooth: hci_sync: Copy the resolving-list IRK under RCU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 9ff737119177a6c1ce6083ef8c0fc06355f11869 ]
hci_le_add_resolve_list_sync() copies the peer IRK into the LE Add Device To Resolving List command after hci_find_irk_by_addr() has returned. The finder ends its RCU read-side section before returning the borrowed entry, and neither the request worker nor interleave_scan_work() holds hdev->lock here. The resolving-list membership check between the lookup and the copy takes hdev->lock and may sleep on it, which widens the window.
When LL privacy programs a peer with address resolution enabled, MGMT_OP_LOAD_IRKS can free its IRK before the copy:
Request worker Management / RCU reclamation
hci_le_add_resolve_list_sync()
irk = hci_find_irk_by_addr()
load_irks()
hci_dev_lock(hdev) hci_smp_irks_clear(hdev)
list_del_rcu(), kfree_rcu()
hci_dev_unlock(hdev)
grace period ends, irk is freed
resolving-list membership check
memcpy(cp.peer_irk, irk->val, 16)
Copy the IRK value in an RCU read-side section right after the lookup, as hci_le_set_privacy_mode_sync() does for the identity address. The section ends before hdev->lock is taken and before the synchronous HCI command is sent.
KASAN reported this on a test kernel with scheduling hooks, whose frames appear in the trace. The report predates the hdev->lock taken by the membership check.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in hci_le_add_resolve_list_sync+0x8d9/0x910
Read of size 16 at addr ffff88810d21452d by task kworker/u17:0/504
CPU: 2 UID: 0 PID: 504 Comm: kworker/u17:0 Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #2 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: hci0 interleave_scan_work
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? hci_le_add_resolve_list_sync+0x8d9/0x910
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? hci_le_add_resolve_list_sync+0x8d9/0x910
kasan_report+0xe0/0x110
? hci_le_add_resolve_list_sync+0x8d9/0x910
hci_le_add_resolve_list_sync+0x8d9/0x910
? __pfx_hci_le_add_resolve_list_sync+0x10/0x10
? pmbd_probe_hit_cookie+0xe7/0x1c0
? srso_alias_return_thunk+0x5/0xfbef5
? pmbd_probe_hit_cookie+0xee/0x1c0
? __pfx_pmbd_probe_hit_cookie+0x10/0x10
hci_le_add_accept_list_sync+0x18e/0x820
? conn_params_copy+0x36e/0x650
? __pfx_hci_le_add_accept_list_sync+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? conn_params_copy+0x3a0/0x650
hci_passive_scan_sync+0x95f/0x1f10
? __pfx_hci_passive_scan_sync+0x10/0x10
? debug_object_deactivate+0x2f8/0x3c0
? pwq_dec_nr_in_flight+0x880/0xdf0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_acquire+0x17b/0x2f0
? process_one_work+0x895/0x19c0
interleave_scan_work+0x11b/0x470
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 535:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
hci_add_irk+0xb6/0x220
load_irks+0x5f9/0x840
hci_sock_sendmsg+0x128b/0x22e0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 0:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
__rcu_free_sheaf_prepare+0x65/0x2a0
rcu_free_sheaf+0x1f/0xe0
rcu_core+0x661/0x1d10
handle_softirqs+0x201/0x930
__irq_exit_rcu+0x110/0x1e0
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x6c/0x80
asm_sysvec_apic_timer_interrupt+0x1a/0x20
The buggy address belongs to the object at ffff88810d214500
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 45 bytes inside of
freed 64-byte region [ffff88810d214500, ffff88810d214540)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10d214
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000428c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88810d214400: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810d214480: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff88810d214500: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff88810d214580: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810d214600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================--- net/bluetooth/hci_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/bluetooth/hci_sync.c +9 -2
@@ -2575,9 +2575,17 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, goto done; } +rcu_read_lock (); + irk =hci_find_irk_by_addr (hdev, ¶ms->addr, params->addr_type); -if (!irk) +if (!irk) { +rcu_read_unlock ();return 0 ; + } + +memcpy (cp.peer_irk, irk->val,16 ); + +rcu_read_unlock ();/* Check if the IK has _not_ been programmed yet. */ hci_dev_lock (hdev);
@@ -2589,7 +2597,6 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, cp.bdaddr_type = params->addr_type;bacpy (&cp.bdaddr, ¶ms->addr); -memcpy (cp.peer_irk, irk->val,16 );/* Default privacy mode is always Network */ params->privacy_mode =HCI_NETWORK_PRIVACY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 164/816 Bluetooth: MGMT: Clear disabled connection parameters when loading none
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Dewald <[email protected]>
[ Upstream commit d90f24dc389b9a7524aaac109021d1530fa180f0 ]
Load Connection Parameters only clears the disabled connection parameters when it loads more than one entry, so that loading a single entry can update the parameters of one device without dropping the others. Loading no entries does not clear them either, though, which is what bluetoothd does when it starts without stored connection parameters.
Pair Device adds disabled connection parameters for the device it pairs with, so these now survive bluetoothd restarts, and new connections to the device keep using the parameters they were created with instead of the defaults set since, e.g. the connection interval from main.conf.
Clear the disabled connection parameters unless a single entry is loaded, as was done for any number of entries before.
--- net/bluetooth/mgmt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/bluetooth/mgmt.c +5 -1
@@ -8243,7 +8243,11 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,hci_dev_lock (hdev); -if (param_count >1 ) +/* A single entry may be an update for one device, so keep the other +* disabled parameters then, but clear them otherwise, including when +* no entries are loaded. +*/ +if (param_count !=1 )hci_conn_params_clear_disabled (hdev);for (i =0 ; i < param_count; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 165/816 Bluetooth: hci_core: Initialize advertising RPA work only once
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit a7c5c18b7cc30dcd2a9ae5a0fb38378d3998417e ]
hci_add_adv_instance() also updates existing instances and calls INIT_DELAYED_WORK() on their rpa_expired_cb every time, even when the work is pending or running. cancel_delayed_work_sync() then no longer finds the work, so hci_remove_adv_instance() can free the instance under it:
hdev->workqueue MGMT_OP_ADD_EXT_ADV_PARAMS
adv_instance_rpa_expired()
hci_dev_lock(hdev) hci_add_adv_instance()
INIT_DELAYED_WORK()
mgmt_pending_new() fails hci_remove_adv_instance()
cancel_delayed_work_sync()
returns without waiting
kfree(adv)
hci_dev_unlock(hdev)
adv->rpa_expired = true
The work has been initialized on every update since it was added. Initialize it only when the instance is allocated.
KASAN report as below:
BUG: KASAN: slab-use-after-free in adv_instance_rpa_expired+0x139/0x160
Write of size 1 at addr ffff888108d84b2e by task kworker/u17:0/504
Workqueue: hci0 adv_instance_rpa_expired
Call Trace:
adv_instance_rpa_expired+0x139/0x160
Allocated by task 560:
hci_add_adv_instance+0x68d/0x9d0
add_ext_adv_params+0x4d4/0xb60
hci_sock_sendmsg+0x128b/0x22e0
Freed by task 594:
kfree+0x307/0x580
hci_remove_adv_instance+0x230/0x540
add_ext_adv_params+0xa43/0xb60
hci_sock_sendmsg+0x128b/0x22e0
Last potentially related work creation:
insert_work+0x37/0x210
__queue_work+0xaba/0x1270
call_timer_fn+0x171/0x500
The buggy address belongs to the object at ffff888108d84800
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 814 bytes inside of
freed 1024-byte region [ffff888108d84800, ffff888108d84c00)--- net/bluetooth/hci_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/bluetooth/hci_core.c +3 -2
@@ -1738,6 +1738,9 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,if (!adv)return ERR_PTR (-ENOMEM ); +INIT_DELAYED_WORK (&adv->rpa_expired_cb, + adv_instance_rpa_expired); + adv->pending = true; adv->instance = instance;
@@ -1774,8 +1777,6 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,else adv->duration = duration; -INIT_DELAYED_WORK (&adv->rpa_expired_cb, adv_instance_rpa_expired); -BT_DBG ("%s for %dMR" , hdev->name, instance);return adv;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 166/816 Bluetooth: validate retained LE Create CIS command length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifan Zhang <[email protected]>
[ Upstream commit 1eb52f35fc8fb06ab7f2973fff29cba81f96b947 ]
hci_cs_le_create_cis() retrieves the parameters of the previously sent command without their length. It then trusts num_cis and walks the flexible cis[] array when a controller reports a failed command.
A five-byte HCI command containing only num_cis can therefore make the handler read beyond the command skb. KASAN reports:
BUG: KASAN: slab-out-of-bounds in hci_cs_le_create_cis Read of size 2 hci_cs_le_create_cis hci_cmd_status_evt hci_event_packet
Add a length-returning saved-command helper and require the fixed header and complete CIS array before walking it.
The reproducer no longer triggers a KASAN report with this change.
--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 18 ++++++++++++++---- net/bluetooth/hci_event.c | 7 ++++++- 3 files changed, 22 insertions(+), 5 deletions(-)
include/net/bluetooth/hci_core.h +2 -0
@@ -2292,6 +2292,8 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);void hci_send_iso (struct hci_conn *conn,struct sk_buff *skb);void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode); +void *hci_sent_cmd_data_len (struct hci_dev *hdev,__u16 opcode, +size_t *len);void *hci_recv_event_data (struct hci_dev *hdev,__u8 event);u32 hci_conn_get_phy (struct hci_conn *conn);
net/bluetooth/hci_core.c +14 -4
@@ -3179,7 +3179,8 @@ int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen,EXPORT_SYMBOL (__hci_cmd_send);/* Get data from the previously sent command */ -static void *hci_cmd_data (struct sk_buff *skb,__u16 opcode) +static void *hci_cmd_data (struct sk_buff *skb,__u16 opcode, +size_t *len) {struct hci_command_hdr *hdr;
@@ -3191,23 +3192,32 @@ static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode)if (hdr->opcode !=cpu_to_le16 (opcode))return NULL ; +if (len) + *len = skb->len -HCI_COMMAND_HDR_SIZE ; +return skb->data +HCI_COMMAND_HDR_SIZE ; }/* Get data from the previously sent command */ -void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode) +void *hci_sent_cmd_data_len (struct hci_dev *hdev,__u16 opcode,size_t *len) {void *data;/* Check if opcode matches last sent command */ - data =hci_cmd_data (hdev->sent_cmd, opcode); + data =hci_cmd_data (hdev->sent_cmd, opcode, len);if (!data)/* Check if opcode matches last request */ - data =hci_cmd_data (hdev->req_skb, opcode); + data =hci_cmd_data (hdev->req_skb, opcode, len);return data; } +/* Get data from the previously sent command */ +void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode) +{ +return hci_sent_cmd_data_len (hdev, opcode,NULL ); +} +/* Get data from last received event */ void *hci_recv_event_data (struct hci_dev *hdev,__u8 event) {
net/bluetooth/hci_event.c +6 -1
@@ -4293,6 +4293,7 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status) {struct hci_cp_le_create_cis *cp;bool pending = false; +size_t len;int i;bt_dev_dbg (hdev,"status 0x%2.2x" , status);
@@ -4300,10 +4301,14 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status)if (!status)return ; - cp =hci_sent_cmd_data (hdev,HCI_OP_LE_CREATE_CIS ); + cp =hci_sent_cmd_data_len (hdev,HCI_OP_LE_CREATE_CIS , &len);if (!cp)return ; +if (len <sizeof (*cp) || + len <struct_size (cp, cis, cp->num_cis)) +return ; +hci_dev_lock (hdev);/* Remove connection if command failed */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 167/816 Bluetooth: validate retained LE Set CIG Parameters command length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifan Zhang <[email protected]>
[ Upstream commit ed4d302af778b9e2ead28134a2196c09a4ad248a ]
hci_cc_le_set_cig_params() validates the controller response but not the parameters of the previously sent command. A short command can claim a large num_cis without containing the corresponding cis[] array. A complete successful response then makes the handler read beyond the command skb while looking up each CIS ID.
KASAN reports:
BUG: KASAN: slab-out-of-bounds in hci_cc_le_set_cig_params Read of size 1 hci_cc_le_set_cig_params hci_cmd_complete_evt hci_event_packet
Obtain the retained parameter length and require both the fixed header and the complete CIS array before using the command data.
The reproducer no longer triggers a KASAN report with this change.
--- net/bluetooth/hci_event.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/bluetooth/hci_event.c +5 -2
@@ -3843,13 +3843,16 @@ static u8 hci_cc_le_set_cig_params(struct hci_dev *hdev, void *data,struct hci_conn *conn;u8 status = rp->status;bool pending = false; +size_t len;int i;bt_dev_dbg (hdev,"status 0x%2.2x" , rp->status); - cp =hci_sent_cmd_data (hdev,HCI_OP_LE_SET_CIG_PARAMS ); + cp =hci_sent_cmd_data_len (hdev,HCI_OP_LE_SET_CIG_PARAMS , &len);if (!rp->status && - (!cp || rp->num_handles != cp->num_cis || + (!cp || len <sizeof (*cp) || + len <struct_size (cp, cis, cp->num_cis) || + rp->num_handles != cp->num_cis || rp->cig_id != cp->cig_id || skb->len <array_size (rp->num_handles,sizeof (*rp->handle)))) {bt_dev_err (hdev,"unexpected Set CIG Parameters response data" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 168/816 Bluetooth: MGMT: Fix discovery stuck after a failed Stop Discovery
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Dewald <[email protected]>
[ Upstream commit 60b10121db602a43ada3dbc39792bbf93d25991b ]
Stop Discovery moves the discovery to DISCOVERY_STOPPING, and stop_discovery_complete() only moves it on to DISCOVERY_STOPPED when stopping succeeded. When it fails, for example because LE Set Scan Enable times out, nothing moves the discovery out ofDISCOVERY_STOPPING: Stop Discovery is rejected, as the discovery is not active anymore, and the LE scan timeout was cancelled before the scan was disabled. Until the controller is powered off, every Start Discovery then fails with Busy, and hci_update_passive_scan_sync() skips background scanning, so devices set to auto-connect are not connected anymore.
Move the discovery back to DISCOVERY_FINDING when stopping it failed while its inquiry or active LE scan is still running, so that it can be stopped again. Only change the state while the discovery is still stopping, as Inquiry Cancel may already have stopped it, for example when only the passive scan could not be disabled, and a new Start Discovery may have followed. Do this under hci_dev_lock(), like the command completions that change these flags, and before replying, so that a client acting on the reply sees the new state. Only cancel the LE scan timeout once the scan is disabled, so that the discovery still ends on its own, except when suspending, where it is still cancelled first.
A timed out LE Set Scan Enable can still complete afterwards, which cancels the timeout as well, so also stop the discovery when its scan is disabled while the timeout is pending, or while the timeout work waits for the lock.
--- net/bluetooth/hci_event.c | 12 +++++++++++- net/bluetooth/hci_sync.c | 26 +++++++++++++++++++++++--- net/bluetooth/mgmt.c | 23 ++++++++++++++++++++--- 3 files changed, 54 insertions(+), 7 deletions(-)
net/bluetooth/hci_event.c +11 -1
@@ -1759,6 +1759,8 @@ static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr,static void le_set_scan_enable_complete (struct hci_dev *hdev,u8 enable) { +bool timeout_pending; +hci_dev_lock (hdev);switch (enable) {
@@ -1788,10 +1790,18 @@ static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable)/* Cancel this timer so that we don't try to disable scanning * when it's already disabled. */ -cancel_delayed_work (&hdev->le_scan_disable); + timeout_pending =cancel_delayed_work (&hdev->le_scan_disable);hci_dev_clear_flag (hdev,HCI_LE_SCAN ); +/* The scan of a discovery was disabled before its timeout, +* for example by a Stop Discovery that timed out and still +* completed, so nothing else would end the discovery. +*/ +if (timeout_pending && + hdev->discovery.state ==DISCOVERY_FINDING ) +hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); + if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED && test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks) && !test_bit(HCI_INQUIRY, &hdev->flags) &&
net/bluetooth/hci_sync.c +23 -3
@@ -376,8 +376,18 @@ static void le_scan_disable(struct work_struct *work)bt_dev_dbg (hdev,"" );hci_dev_lock (hdev); -if (!hci_dev_test_flag (hdev,HCI_LE_SCAN )) +if (!hci_dev_test_flag (hdev,HCI_LE_SCAN )) { +/* The scan of a discovery can be disabled while this work +* waits for the lock, for example by a Stop Discovery that +* timed out and still completed, so end the discovery as +* le_set_scan_enable_complete() does when it cancels this +* work. +*/ +if (hdev->discovery.state ==DISCOVERY_FINDING ) + goto discov_stopped; + goto _return; + } status =hci_cmd_sync_queue (hdev, scan_disable_sync,NULL ,NULL );if (status) {
@@ -5763,11 +5773,15 @@ int hci_stop_discovery_sync(struct hci_dev *hdev) }if (hci_dev_test_flag (hdev,HCI_LE_SCAN )) { -cancel_delayed_work (&hdev->le_scan_disable); - err =hci_scan_disable_sync (hdev);if (err)return err; + +/* Only cancel the LE scan timeout once the scan is +* disabled, so that the discovery still ends if +* stopping it failed. +*/ +cancel_delayed_work (&hdev->le_scan_disable); } }else {
@@ -6403,6 +6417,12 @@ static int hci_pause_discovery_sync(struct hci_dev *hdev)return 0 ;hci_discovery_set_state (hdev,DISCOVERY_STOPPING ); + +/* Cancel the LE scan timeout first, so that it does not run while +* suspended if the scan cannot be disabled. +*/ +cancel_delayed_work (&hdev->le_scan_disable); + err =hci_stop_discovery_sync (hdev);if (err)return err;
net/bluetooth/mgmt.c +20 -3
@@ -6320,12 +6320,29 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err)bt_dev_dbg (hdev,"err %d" , err); +hci_dev_lock (hdev); + +/* Change the state before replying, so that a client acting on the +* reply sees it, and only while the discovery is still stopping, as +* Inquiry Cancel may already have stopped it and a new Start Discovery +* may have followed. Go back to DISCOVERY_FINDING when stopping failed +* while the inquiry or the active LE scan of the discovery is still +* running, so that it can be stopped again. +*/ +if (hdev->discovery.state ==DISCOVERY_STOPPING ) { +if (err && (test_bit (HCI_INQUIRY , &hdev->flags) || + (hci_dev_test_flag (hdev,HCI_LE_SCAN ) && + hdev->le_scan_type ==LE_SCAN_ACTIVE ))) +hci_discovery_set_state (hdev,DISCOVERY_FINDING ); +else +hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); + } + +hci_dev_unlock (hdev); +mgmt_cmd_complete (cmd->sk, cmd->hdev->id, cmd->opcode,mgmt_status (err), cmd->param,1 );mgmt_pending_free (cmd); - -if (!err) -hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); }static int stop_discovery_sync (struct hci_dev *hdev,void *data)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 169/816 mctp i3c: Fix locking in an error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 750eb5ab457e62e221a9c8521e2274f14c85b387 ]
If netdev_alloc_skb() fails, mctp_i3c_read() jumps to a label that unlocks mi->lock although that mutex has not been locked yet. Fix this by returning -ENOMEM directly. This bug has been detected by the Clang thread-safety analyzer.
--- drivers/net/mctp/mctp-i3c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/mctp/mctp-i3c.c +1 -2
@@ -111,8 +111,7 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi) mi->mrl + sizeof(struct mctp_i3c_internal_hdr));if (!skb) { stats->rx_dropped++; - rc = -ENOMEM ; - goto err; +return -ENOMEM ; } skb->protocol =htons (ETH_P_MCTP );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 170/816 ksmbd: implement error handling for STATUS_INFO_LENGTH_MISMATCH in smb server
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aaditya Kansal <[email protected]>
[ Upstream commit e4442b2e95baf0901830c924d0a197b100aca970 ]
Add STATUS_INFO_LENGTH_MISMATCH mapping to EMSGSIZE. Currently, STATUS_INFO_LENGTH_MISMATCH has no mapping to any error code, making it difficult to distinguish between invalid parameters and length mismatch.
Map STATUS_INFO_LENGTH_MISMATCH to EMSGSIZE while keeping the EINVAL for invalid parameters. Although the buf_len check only checks for buf_size being less than required, there was no error code for lower buf_size. Hence, EMSGSIZE is used.
Stable-dep-of: e49296d51ccb ("ksmbd: require NUL-terminated EA names")
--- fs/smb/server/smb2pdu.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
fs/smb/server/smb2pdu.c +11 -10
@@ -6714,7 +6714,6 @@ static int set_file_mode_info(struct ksmbd_file *fp,* @share: ksmbd_share_config pointer * * Return: 0 on success, otherwise error -* TODO: need to implement an error handling for STATUS_INFO_LENGTH_MISMATCH */ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp, struct smb2_set_info_req *req,
@@ -6727,14 +6726,14 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,case FILE_BASIC_INFORMATION : {if (buf_len <sizeof (struct smb2_file_basic_info )) -return -EINVAL ; +return -EMSGSIZE ;return set_file_basic_info (fp, (struct smb2_file_basic_info *)buffer, share); }case FILE_ALLOCATION_INFORMATION : {if (buf_len <sizeof (struct smb2_file_alloc_info )) -return -EINVAL ; +return -EMSGSIZE ;return set_file_allocation_info (work, fp, (struct smb2_file_alloc_info *)buffer);
@@ -6742,7 +6741,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,case FILE_END_OF_FILE_INFORMATION : {if (buf_len <sizeof (struct smb2_file_eof_info )) -return -EINVAL ; +return -EMSGSIZE ;return set_end_of_file_info (work, fp, (struct smb2_file_eof_info *)buffer);
@@ -6750,7 +6749,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,case FILE_RENAME_INFORMATION : {if (buf_len <sizeof (struct smb2_file_rename_info )) -return -EINVAL ; +return -EMSGSIZE ; return set_rename_info(work, fp, (struct smb2_file_rename_info *)buffer,
@@ -6761,7 +6760,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,struct smb2_file_link_info *file_info;if (buf_len <sizeof (struct smb2_file_link_info )) -return -EINVAL ; +return -EMSGSIZE ; file_info = (struct smb2_file_link_info *)buffer;if (file_info->ReplaceIfExists && !(fp->daccess &FILE_DELETE_LE )) {
@@ -6776,7 +6775,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,case FILE_DISPOSITION_INFORMATION : {if (buf_len <sizeof (struct smb2_file_disposition_info )) -return -EINVAL ; +return -EMSGSIZE ;return set_file_disposition_info (work, fp, (struct smb2_file_disposition_info *)buffer);
@@ -6790,7 +6789,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp, }if (buf_len <sizeof (struct smb2_ea_info )) -return -EINVAL ; +return -EMSGSIZE ;return smb2_set_ea ((struct smb2_ea_info *)buffer, buf_len, &fp->filp->f_path, true);
@@ -6798,14 +6797,14 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,case FILE_POSITION_INFORMATION : {if (buf_len <sizeof (struct smb2_file_pos_info )) -return -EINVAL ; +return -EMSGSIZE ;return set_file_position_info (fp, (struct smb2_file_pos_info *)buffer); }case FILE_MODE_INFORMATION : {if (buf_len <sizeof (struct smb2_file_mode_info )) -return -EINVAL ; +return -EMSGSIZE ;return set_file_mode_info (fp, (struct smb2_file_mode_info *)buffer); }
@@ -6913,6 +6912,8 @@ int smb2_set_info(struct ksmbd_work *work) rsp->hdr.Status =STATUS_ACCESS_DENIED ; else if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EMSGSIZE) + rsp->hdr.Status = STATUS_INFO_LENGTH_MISMATCH; else if (rc == -ESHARE) rsp->hdr.Status = STATUS_SHARING_VIOLATION; else if (rc == -ENOENT)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 171/816 ksmbd: require NUL-terminated EA names
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifan Zhang <[email protected]>
[ Upstream commit e49296d51ccbf2ad0ed0484db1382f1d7217bd6e ]
smb2_set_ea() verifies that the byte reserved for the declared EA-name terminator lies inside the request, but it does not verify that the byte is zero. With SMB debug logging enabled, the name is passed to %s and the diagnostic reads beyond the request allocation.
KASAN reports:
BUG: KASAN: slab-out-of-bounds in string Read of size 1 string vsnprintf _printk smb2_set_ea smb2_set_info
Reject an EA entry whose declared terminator byte is nonzero. Return -EBADMSG for the malformed buffer, and map that error to STATUS_EA_LIST_INCONSISTENT for both SET_INFO and CREATE.
--- fs/smb/server/smb2pdu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/smb/server/smb2pdu.c +9 -0
@@ -2460,6 +2460,11 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len,if (!eabuf->EaNameLength) goto next; +if (eabuf->name[eabuf->EaNameLength]) { + rc = -EBADMSG ; +break ; + } + ksmbd_debug(SMB, "name : <%s>, name_len : %u, value_len : %u, next : %u\n", eabuf->name, eabuf->EaNameLength,
@@ -3924,6 +3929,8 @@ int smb2_open(struct ksmbd_work *work)if (rc) {if (rc == -EINVAL ) rsp->hdr.Status =STATUS_INVALID_PARAMETER ; +else if (rc == -EBADMSG ) + rsp->hdr.Status =STATUS_EA_LIST_INCONSISTENT ;else if (rc == -EOPNOTSUPP ) rsp->hdr.Status =STATUS_NOT_SUPPORTED ;else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV ) {
@@ -6912,6 +6919,8 @@ int smb2_set_info(struct ksmbd_work *work) rsp->hdr.Status =STATUS_ACCESS_DENIED ; else if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EMSGSIZE) rsp->hdr.Status = STATUS_INFO_LENGTH_MISMATCH; else if (rc == -ESHARE)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 172/816 soreuseport: annotate data-races around reuse->socks[] and num_socks
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 213d491308b99d026514c93980cf8dd572226b1b ]
reuseport_select_sock() and reuseport_migrate_sock() read reuse->num_socks and reuse->socks[] locklessly under RCU, while writers holding reuseport_lock can change them.
Readers snapshot num_socks once, then index socks[] with it. Meanwhile, writers can perform several operations, storing into slots below the reader's stale count:
- __reuseport_detach_sock() moves the last socket into slot i.
- __reuseport_add_sock() then writes the new socket at the (now smaller) num_socks index.
- reuseport_stop_listen_sock() calls __reuseport_detach_sock() then __reuseport_add_closed_sock(), which writes slot max_socks - num_closed_socks - 1. This can be the slot a reader still considers part of the listener region when the array is full.
- __reuseport_detach_closed_sock() can then rewrite that slot.
All pointers stored in socks[] remain valid for the RCU grace period, but without annotations the compiler is allowed to tear or reload these accesses. For instance, reuseport_select_sock_by_hash() could reload reuse->socks[i] between the sk_state/sk_incoming_cpu checks and the return, returning a socket that did not pass them.
Use WRITE_ONCE() for all socks[] stores done while the array is visible to readers, and for num_socks updates (readers already use READ_ONCE()). Use READ_ONCE() in the two lockless readers.
--- net/core/sock_reuseport.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
net/core/sock_reuseport.c +9 -8
@@ -124,10 +124,10 @@ static int reuseport_sock_index(struct sock *sk,static void __reuseport_add_sock (struct sock *sk,struct sock_reuseport *reuse) { - reuse->socks[reuse->num_socks] = sk; +WRITE_ONCE (reuse->socks[reuse->num_socks], sk);/* paired with smp_rmb() in reuseport_(select|migrate)_sock() */ smp_wmb (); - reuse->num_socks++; +WRITE_ONCE (reuse->num_socks, reuse->num_socks +1 );reuseport_get_incoming_cpu (sk, reuse); }
@@ -139,8 +139,8 @@ static bool __reuseport_detach_sock(struct sock *sk,if (i ==-1 )return false; - reuse->socks[i] = reuse->socks[reuse->num_socks -1 ]; - reuse->num_socks--; +WRITE_ONCE (reuse->socks[i], reuse->socks[reuse->num_socks -1 ]); +WRITE_ONCE (reuse->num_socks, reuse->num_socks -1 );reuseport_put_incoming_cpu (sk, reuse);return true;
@@ -149,7 +149,7 @@ static bool __reuseport_detach_sock(struct sock *sk,static void __reuseport_add_closed_sock (struct sock *sk,struct sock_reuseport *reuse) { - reuse->socks[reuse->max_socks - reuse->num_closed_socks -1 ] = sk; +WRITE_ONCE (reuse->socks[reuse->max_socks - reuse->num_closed_socks -1 ], sk);/* paired with READ_ONCE() in inet_csk_bind_conflict() */ WRITE_ONCE (reuse->num_closed_socks, reuse->num_closed_socks +1 );reuseport_get_incoming_cpu (sk, reuse);
@@ -163,7 +163,8 @@ static bool __reuseport_detach_closed_sock(struct sock *sk,if (i ==-1 )return false; - reuse->socks[i] = reuse->socks[reuse->max_socks - reuse->num_closed_socks]; +WRITE_ONCE (reuse->socks[i], + reuse->socks[reuse->max_socks - reuse->num_closed_socks]);/* paired with READ_ONCE() in inet_csk_bind_conflict() */ WRITE_ONCE (reuse->num_closed_socks, reuse->num_closed_socks -1 );reuseport_put_incoming_cpu (sk, reuse);
@@ -521,7 +522,7 @@ static struct sock *run_bpf_filter(struct sock_reuseport *reuse, u16 socks,if (index >= socks)return NULL ; -return reuse->socks[index]; +return READ_ONCE (reuse->socks[index]); } static struct sock *reuseport_select_sock_by_hash(struct sock_reuseport *reuse,
@@ -532,7 +533,7 @@ static struct sock *reuseport_select_sock_by_hash(struct sock_reuseport *reuse, i = j =reciprocal_scale (hash, num_socks); do { - struct sock *sk = reuse->socks[i]; + struct sock *sk = READ_ONCE(reuse->socks[i]); if (sk->sk_state != TCP_ESTABLISHED) { /* Paired with WRITE_ONCE() in __reuseport_(get|put)_incoming_cpu(). */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 173/816 power: sequencing: qcom-wcn: improve support for wcn6855
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit bd4c8bafcf50b6bd415c8bf04e98ebfba78071f9 ]
WCN6855 (also known as QCA6490) is similar to the already supported QCA6390 but takes in two more supplies so add a new vregs list for it.
On sm8450-hdk it also requires a short assert of the xo-clk pin so add handling for it in a dedicated unit.
As we now have a separate set of targets for this variant, store the pointer to the targets struct associated with a model in the device match data.
Stable-dep-of: bd60a639b621 ("power: sequencing: qcom-wcn: increase WCN7850 power-up delay")
--- drivers/power/sequencing/pwrseq-qcom-wcn.c | 101 ++++++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-)
drivers/power/sequencing/pwrseq-qcom-wcn.c +98 -3
@@ -22,6 +22,7 @@ struct pwrseq_qcom_wcn_pdata {size_t num_vregs;unsigned int pwup_delay_ms;unsigned int gpio_enable_delay_ms; +const struct pwrseq_target_data **targets; };struct pwrseq_qcom_wcn_ctx {
@@ -31,6 +32,7 @@ struct pwrseq_qcom_wcn_ctx {struct regulator_bulk_data *regs;struct gpio_desc *bt_gpio;struct gpio_desc *wlan_gpio; +struct gpio_desc *xo_clk_gpio;struct clk *clk;unsigned long last_gpio_enable_jf; };
@@ -98,6 +100,33 @@ static const struct pwrseq_unit_data *pwrseq_qcom_wcn_unit_deps[] = { NULL }; +static int pwrseq_qcom_wcn6855_clk_assert (struct pwrseq_device *pwrseq) +{ +struct pwrseq_qcom_wcn_ctx *ctx =pwrseq_device_get_drvdata (pwrseq); + +if (!ctx->xo_clk_gpio) +return 0 ; + +msleep (1 ); + +gpiod_set_value_cansleep (ctx->xo_clk_gpio,1 ); +usleep_range (100 ,200 ); + +return 0 ; +} + +static const struct pwrseq_unit_data pwrseq_qcom_wcn6855_xo_clk_assert = { + .name ="xo-clk-assert" , + .enable = pwrseq_qcom_wcn6855_clk_assert, +}; + +static const struct pwrseq_unit_data *pwrseq_qcom_wcn6855_unit_deps[] = { + &pwrseq_qcom_wcn_vregs_unit_data, + &pwrseq_qcom_wcn_clk_unit_data, + &pwrseq_qcom_wcn6855_xo_clk_assert, +NULL +}; +static int pwrseq_qcom_wcn_bt_enable (struct pwrseq_device *pwrseq) {struct pwrseq_qcom_wcn_ctx *ctx =pwrseq_device_get_drvdata (pwrseq);
@@ -125,6 +154,13 @@ static const struct pwrseq_unit_data pwrseq_qcom_wcn_bt_unit_data = { .disable = pwrseq_qcom_wcn_bt_disable, }; +static const struct pwrseq_unit_data pwrseq_qcom_wcn6855_bt_unit_data = { + .name ="wlan-enable" , + .deps = pwrseq_qcom_wcn6855_unit_deps, + .enable = pwrseq_qcom_wcn_bt_enable, + .disable = pwrseq_qcom_wcn_bt_disable, +}; +static int pwrseq_qcom_wcn_wlan_enable (struct pwrseq_device *pwrseq) {struct pwrseq_qcom_wcn_ctx *ctx =pwrseq_device_get_drvdata (pwrseq);
@@ -152,6 +188,13 @@ static const struct pwrseq_unit_data pwrseq_qcom_wcn_wlan_unit_data = { .disable = pwrseq_qcom_wcn_wlan_disable, }; +static const struct pwrseq_unit_data pwrseq_qcom_wcn6855_wlan_unit_data = { + .name ="wlan-enable" , + .deps = pwrseq_qcom_wcn6855_unit_deps, + .enable = pwrseq_qcom_wcn_wlan_enable, + .disable = pwrseq_qcom_wcn_wlan_disable, +}; +static int pwrseq_qcom_wcn_pwup_delay (struct pwrseq_device *pwrseq) {struct pwrseq_qcom_wcn_ctx *ctx =pwrseq_device_get_drvdata (pwrseq);
@@ -162,6 +205,18 @@ static int pwrseq_qcom_wcn_pwup_delay(struct pwrseq_device *pwrseq)return 0 ; } +static int pwrseq_qcom_wcn6855_xo_clk_deassert (struct pwrseq_device *pwrseq) +{ +struct pwrseq_qcom_wcn_ctx *ctx =pwrseq_device_get_drvdata (pwrseq); + +if (ctx->xo_clk_gpio) { +usleep_range (2000 ,5000 ); +gpiod_set_value_cansleep (ctx->xo_clk_gpio,0 ); + } + +return pwrseq_qcom_wcn_pwup_delay (pwrseq); +} +static const struct pwrseq_target_data pwrseq_qcom_wcn_bt_target_data = { .name ="bluetooth" , .unit = &pwrseq_qcom_wcn_bt_unit_data,
@@ -174,12 +229,30 @@ static const struct pwrseq_target_data pwrseq_qcom_wcn_wlan_target_data = { .post_enable = pwrseq_qcom_wcn_pwup_delay, }; +static const struct pwrseq_target_data pwrseq_qcom_wcn6855_bt_target_data = { + .name ="bluetooth" , + .unit = &pwrseq_qcom_wcn6855_bt_unit_data, + .post_enable = pwrseq_qcom_wcn6855_xo_clk_deassert, +}; + +static const struct pwrseq_target_data pwrseq_qcom_wcn6855_wlan_target_data = { + .name ="wlan" , + .unit = &pwrseq_qcom_wcn6855_wlan_unit_data, + .post_enable = pwrseq_qcom_wcn6855_xo_clk_deassert, +}; +static const struct pwrseq_target_data *pwrseq_qcom_wcn_targets[] = { &pwrseq_qcom_wcn_bt_target_data, &pwrseq_qcom_wcn_wlan_target_data,NULL }; +static const struct pwrseq_target_data *pwrseq_qcom_wcn6855_targets[] = { + &pwrseq_qcom_wcn6855_bt_target_data, + &pwrseq_qcom_wcn6855_wlan_target_data, +NULL +}; +static const char *const pwrseq_qca6390_vregs[] = {"vddio" ,"vddaon" ,
@@ -196,13 +269,28 @@ static const struct pwrseq_qcom_wcn_pdata pwrseq_qca6390_of_data = { .num_vregs = ARRAY_SIZE(pwrseq_qca6390_vregs), .pwup_delay_ms = 60, .gpio_enable_delay_ms = 100, + .targets = pwrseq_qcom_wcn_targets, +}; + +static const char *const pwrseq_wcn6855_vregs[] = { +"vddio" , +"vddaon" , +"vddpmu" , +"vddpmumx" , +"vddpmucx" , +"vddrfa0p95" , +"vddrfa1p3" , +"vddrfa1p9" , +"vddpcie1p3" , +"vddpcie1p9" , };static const struct pwrseq_qcom_wcn_pdata pwrseq_wcn6855_of_data = { - .vregs = pwrseq_qca6390_vregs, - .num_vregs =ARRAY_SIZE (pwrseq_qca6390_vregs), + .vregs = pwrseq_wcn6855_vregs, + .num_vregs =ARRAY_SIZE (pwrseq_wcn6855_vregs), .pwup_delay_ms =50 , .gpio_enable_delay_ms =5 , + .targets = pwrseq_qcom_wcn6855_targets, };static const char *const pwrseq_wcn7850_vregs[] = {
@@ -219,6 +307,7 @@ static const struct pwrseq_qcom_wcn_pdata pwrseq_wcn7850_of_data = { .vregs = pwrseq_wcn7850_vregs, .num_vregs = ARRAY_SIZE(pwrseq_wcn7850_vregs), .pwup_delay_ms = 50, + .targets = pwrseq_qcom_wcn_targets, }; static int pwrseq_qcom_wcn_match(struct pwrseq_device *pwrseq,
@@ -295,6 +384,12 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (ctx->wlan_gpio),"Failed to get the WLAN enable GPIO\n" ); + ctx->xo_clk_gpio =devm_gpiod_get_optional (dev,"xo-clk" , +GPIOD_OUT_LOW ); +if (IS_ERR (ctx->xo_clk_gpio)) +return dev_err_probe (dev,PTR_ERR (ctx->xo_clk_gpio), +"Failed to get the XO_CLK GPIO\n" ); +/* * Set direction to output but keep the current value in order to not * disable the WLAN module accidentally if it's already powered on.
@@ -313,7 +408,7 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev) config.owner =THIS_MODULE ; config.drvdata = ctx; config.match = pwrseq_qcom_wcn_match; - config.targets = pwrseq_qcom_wcn_targets; + config.targets = ctx->pdata->targets; ctx->pwrseq =devm_pwrseq_device_register (dev, &config);if (IS_ERR (ctx->pwrseq))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 174/816 power: sequencing: qcom-wcn: increase WCN7850 power-up delay
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuai Zhang <[email protected]>
[ Upstream commit bd60a639b621453fe37b780df4b6d3a13f981f13 ]
When the WCN7850 is powered up from the Bluetooth side first, i.e. BT_EN is asserted while WLAN_EN is still low, the chip starts from a cold state and is not ready to accept the first HCI command 50 ms after BT_EN goes high. The first command (0xfc00, read QCA version) is lost, hci_qca does not resend it and fails after the 2 s command timeout:
Bluetooth: hci0: Reading QCA version information failed (-110)
When WLAN is powered first, 50 ms is sufficient, so the failure only shows up in the BT-first ordering. Measured on the affected board by which enable pin rose first:
pwup_delay_ms BT-first boots with -110 50 9 9 75 23 0 100 21 0 300 20 0
Raise the power-up delay of WCN7850 to 100 ms. The delay is shared by the Bluetooth and WLAN targets, so WLAN power-up also waits 50 ms longer.
--- drivers/power/sequencing/pwrseq-qcom-wcn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/sequencing/pwrseq-qcom-wcn.c +1 -1
@@ -306,7 +306,7 @@ static const char *const pwrseq_wcn7850_vregs[] = {static const struct pwrseq_qcom_wcn_pdata pwrseq_wcn7850_of_data = { .vregs = pwrseq_wcn7850_vregs, .num_vregs =ARRAY_SIZE (pwrseq_wcn7850_vregs), - .pwup_delay_ms =50 , + .pwup_delay_ms =100 , .targets = pwrseq_qcom_wcn_targets, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 175/816 vhost-scsi: validate event queue descriptor direction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit 3d8c5b714c186d08c8fe8c8cfd1f9b89525ab067 ]
vhost_get_vq_desc() returns the number of device readable (output) and device writable (input) iovec segments. A guest can submit an eventq descriptor chain that fills vq->iov with output segments, setting out to ARRAY_SIZE(vq->iov) and in to zero.
When the host later queues a vhost-scsi event, vhost_scsi_do_evt_work() uses out as the index of the first input segment. This accesses one element beyond vq->iov and triggers an array-index-out-of-bounds report. With panic_on_warn enabled, the report panics the host.
The event queue accepts device writable buffers only. Reject chains that contain output segments or lack an input segment before using out as an index. The input check prevents the out-of-bounds access, while the output check validates the eventq descriptor direction.
I found the descriptor direction issue myself, though the patch was written with AI assistance. The out-of-bounds read with an output-only chain was separately reported by Jia Jia.
Message-ID: <20261009-fix-arrary-index-out-of-bounds-in-vhost_scsi_complete_events-v2-1-1f7689a54735@gmail.com>
--- drivers/vhost/scsi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/vhost/scsi.c +10 -0
@@ -488,6 +488,16 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)return ; } +/* +* Eventq buffers are device-writable only. A nonzero in count +* guarantees that out is within the bounds of vq->iov. +*/ +if (unlikely (out || !in)) { +vq_err (vq,"Invalid event buffer: out %u, in %u\n" , out, in); + vs->vs_events_missed = true; +return ; + } +if ((vq->iov[out].iov_len !=sizeof (struct virtio_scsi_event ))) {vq_err (vq,"Expecting virtio_scsi_event, got %zu bytes\n" , vq->iov[out].iov_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 176/816 vhost-scsi: reject delayed virtqueue setup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit a543346b96a174fcee6812ac2764acc8dc993358 ]
vhost_scsi_set_endpoint() allocates command pools only for I/O virtqueues that are already set up, but publishes the backend for every virtqueue. Userspace can complete a skipped queue after attaching the endpoint, then kick it with scsi_tags uninitialized and trigger the alloc_hint warning in sbitmap_get().
Delayed virtqueue setup is not supported. Leave skipped I/O virtqueues inactive and reject changes to the vring size or addresses while an endpoint is attached. Userspace must clear the endpoint before changing the vring configuration.
I found this bug myself, though the patch was written with AI assistance.
Message-ID: <[email protected]>
--- drivers/vhost/scsi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/vhost/scsi.c +12 -3
@@ -1845,6 +1845,9 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,for (i =0 ; i < vs->dev.nvqs; i++) { vq = &vs->vqs[i].vq; +if (i >=VHOST_SCSI_VQ_IO && !vs->vqs[i].scsi_cmds) +continue ; +mutex_lock (&vq->mutex);vhost_vq_set_backend (vq, vs_tpg);vhost_vq_init_access (vq);
@@ -2176,10 +2179,16 @@ vhost_scsi_ioctl(struct file *f,default :mutex_lock (&vs->dev.mutex); r =vhost_dev_ioctl (&vs->dev, ioctl, argp); -if (r == -ENOIOCTLCMD ) - r =vhost_vring_ioctl (&vs->dev, ioctl, argp); -else +if (r == -ENOIOCTLCMD ) { +if (vs->vs_tpg && + (ioctl ==VHOST_SET_VRING_NUM || + ioctl ==VHOST_SET_VRING_ADDR )) + r = -EBUSY ; +else + r =vhost_vring_ioctl (&vs->dev, ioctl, argp); + }else {vhost_scsi_flush (vs); + }mutex_unlock (&vs->dev.mutex);return r; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 177/816 vhost: reject backend enable without a kick file
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit 509f6bd229e94fc39506e01be692c4aa22338b49 ]
Enabling a backend without VHOST_SET_VRING_KICK dereferences a NULL vq->kick in vhost_poll_start(). Reject the request with -EINVAL.
Message-ID: <20261011-fix-null-pointer-in-vhost_test_set_backend-v1-1-60b2f12d64c6@gmail.com>
--- drivers/vhost/test.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/vhost/test.c +4 -0
@@ -281,6 +281,10 @@ static long vhost_test_set_backend(struct vhost_test *n, unsigned index, int fd) r = -EFAULT ; goto err_vq; } +if (enable && !vq->kick) { + r = -EINVAL ; + goto err_vq; + }if (!enable) {vhost_poll_stop (&vq->poll); backend =vhost_vq_get_backend (vq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 178/816 vhost-vdpa: initialize state before publishing cdev
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit 4b03d1e7f13613af708441a061556de99891a516 ]
Initialize the completion and as hash buckets before cdev_device_add() makes the device accessible.
Message-ID: <20261011-fix-null-pointer-in-vhost_vdpa_release-v2-1-66ba929971ce@gmail.com>
--- drivers/vhost/vdpa.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/vhost/vdpa.c +5 -4
@@ -1703,7 +1703,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)return minor; } -atomic_set (&v->opened,0 ); +atomic_set (&v->opened,1 );spin_lock_init (&v->config_lock); v->minor = minor; v->vdpa = vdpa;
@@ -1727,16 +1727,17 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)cdev_init (&v->cdev, &vhost_vdpa_fops); v->cdev.owner =THIS_MODULE ; +init_completion (&v->completion); +for (i =0 ; i <VHOST_VDPA_IOTLB_BUCKETS ; i++) +INIT_HLIST_HEAD (&v->as[i]); r =cdev_device_add (&v->cdev, &v->dev);if (r) goto err; -init_completion (&v->completion);vdpa_set_drvdata (vdpa, v); -for (i =0 ; i <VHOST_VDPA_IOTLB_BUCKETS ; i++) -INIT_HLIST_HEAD (&v->as[i]); +atomic_set_release (&v->opened,0 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 179/816 virtio_balloon: initialize wakeup_lock before virtqueues are set up
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingbing Zhai <[email protected]>
[ Upstream commit 161aa708b02cc997a51701c342f3cebade0b5164 ]
Since c578123e63da ("virtio_balloon: Treat stats requests as wakeup events") the stats_request() virtqueue callback takes vb->wakeup_lock via start_wakeup_event(). init_vqs() registers that callback and even primes and kicks the stats queue, so the lock is reachable from irq context as soon as init_vqs() returns, long before the driver setsDRIVER_OK: vring_interrupt() dispatches to the callback without any DRIVER_OK check unless CONFIG_VIRTIO_HARDEN_NOTIFICATION is set, and that option depends on BROKEN. syzbot hit it from a threaded irq:
INFO: trying to register non-static key in stats_request
...
assign_lock_key
register_lock_class
lock_acquire
rt_spin_lock
start_wakeup_event drivers/virtio/virtio_balloon.c:150 [inline] stats_request drivers/virtio/virtio_balloon.c:435
The lock is only initialized near the end of virtballoon_probe(), after init_vqs() and several steps that can still fail and unwind through del_vqs(), where a racing interrupt still finds the callback registered. Until then it is whatever kzalloc() left in vb: lockdep complains about the unregistered lock class, and wakeup_signal_mask and processing_wakeup_event get updated from irq context while probe is still running.
The rt_spin_lock() in the report is just spin_lock() on PREEMPT_RT; any PROVE_LOCKING build takes the same path.
stop_update_lock(), which the same callback also acquires, is already initialized before init_vqs(); do the same for wakeup_lock.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_balloon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/virtio/virtio_balloon.c +1 -2
@@ -965,6 +965,7 @@ static int virtballoon_probe(struct virtio_device *vdev)INIT_WORK (&vb->update_balloon_stats_work, update_balloon_stats_func);INIT_WORK (&vb->update_balloon_size_work, update_balloon_size_func);spin_lock_init (&vb->stop_update_lock); +spin_lock_init (&vb->wakeup_lock);mutex_init (&vb->balloon_lock);init_waitqueue_head (&vb->acked); vb->vdev = vdev;
@@ -1070,8 +1071,6 @@ static int virtballoon_probe(struct virtio_device *vdev) goto out_unregister_oom; } -spin_lock_init (&vb->wakeup_lock); -/* * The virtio balloon itself can't wake up the device, but it is * responsible for processing wakeup events passed up from the transport
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 180/816 ext2: only flush DIRSYNC directories on every change
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3f57fc2c49ed05ccfc56e4dc9eda41be95925bbd ]
Every change of an ext2 directory is written to disk before the system call returns, whether the directory is DIRSYNC or not: its pages with filemap_write_and_wait() and its inode with sync_inode_metadata().
Writes which reach the device for 2000 files, and 200 directories, in a directory without DIRSYNC, with the flusher turned off:
create rename unlink mkdir
before 4000 8000 4000 800
after 0 0 0 0
In a directory with chattr +D the numbers are those of "before", before and after.
commit bc943f4872a7 ("ext2: Don't flush page immediately for DIRSYNC directories") moved the flush from ext2_commit_chunk() to the new ext2_handle_dirsync(). The IS_DIRSYNC() check which was around it didn't move along.
Fix by putting the check into ext2_handle_dirsync().
--- fs/ext2/dir.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext2/dir.c +3 -0
@@ -441,6 +441,9 @@ static int ext2_handle_dirsync(struct inode *dir) {int err; +if (!IS_DIRSYNC (dir)) +return 0 ; + err =filemap_write_and_wait (dir->i_mapping);if (!err) err =sync_inode_metadata (dir,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 181/816 printk: Allow to use the printk kthread immediately even for 1st nbcon
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Mladek <[email protected]>
[ Upstream commit cf5543870186d6f99b631faaeca27beaa996d52f ]
The kthreads for nbcon consoles are created by nbcon_alloc() at the beginning of the console registration. But it currently works only for the 2nd or later nbcon console because the code checks @printk_kthreads_running.
The kthread for the 1st registered nbcon console is created at the very end of register_console() by printk_kthreads_check_locked(). As a result, the entire log is replayed synchronously when the "enabled" message gets printed. It might block the boot for a long time with a slow serial console.
Prevent the synchronous flush by creating the kthread even for the 1st nbcon console when it is safe (kthreads ready and no boot consoles).
Also inform printk() to use the kthread by setting @printk_kthreads_running. Note that the kthreads already must be running when it is safe and this is not the 1st nbcon console.
Symmetrically, clear @printk_kthreads_running when the last nbcon console was unregistered by nbcon_free(). This requires updating @have_nbcon_console before nbcon_free() gets called.
Note that there is _no_ problem when the 1st nbcon console replaces boot consoles. In this case, the kthread will be started at the end of registration after the boot consoles are removed. But the console does not reply the entire log buffer in this case. Note that the flag CON_PRINTBUFFER is always cleared when the boot consoles are removed and vice versa.
Stable-dep-of: 8a7f26aa072a ("printk: Avoid multiple unregistration in unregister_console_locked()")
--- kernel/printk/internal.h | 2 ++ kernel/printk/nbcon.c | 26 ++++++++++++++++++++++++-- kernel/printk/printk.c | 20 +++++++++++--------- 3 files changed, 37 insertions(+), 11 deletions(-)
kernel/printk/internal.h +2 -0
@@ -62,6 +62,7 @@ struct dev_printk_info;extern struct printk_ringbuffer *prb;extern bool printk_kthreads_running; +extern bool printk_kthreads_ready;extern bool debug_non_panic_cpus;__printf (4 ,0 )
@@ -177,6 +178,7 @@ static inline void nbcon_kthread_wake(struct console *con)#define PRINTKRB_RECORD_MAX 0#define printk_kthreads_running (false) +#define printk_kthreads_ready (false)/* * In !PRINTK builds we still export console_sem
kernel/printk/nbcon.c +24 -2
@@ -1690,6 +1690,9 @@ bool nbcon_alloc(struct console *con) {struct nbcon_state state = { }; +/* Synchronize the kthread start. */ +lockdep_assert_console_list_lock_held (); +/* The write_thread() callback is mandatory. */ if (WARN_ON (!con->write_thread))return false;
@@ -1720,12 +1723,15 @@ bool nbcon_alloc(struct console *con)return false; } -if (printk_kthreads_running) { +if (printk_kthreads_ready && !have_boot_console) {if (!nbcon_kthread_create (con)) {kfree (con->pbufs); con->pbufs =NULL ;return false; } + +/* Might be the first kthread. */ + printk_kthreads_running = true; } }
@@ -1735,14 +1741,30 @@ bool nbcon_alloc(struct console *con)/** * nbcon_free - Free and cleanup the nbcon console specific data * @con: Console to free/cleanup nbcon data +* +* Important: @have_nbcon_console must be updated before calling +* this function. In particular, it can be set only when there +* is still another nbcon console registered. */ void nbcon_free (struct console *con) {struct nbcon_state state = { }; -if (printk_kthreads_running) +/* Synchronize the kthread stop. */ +lockdep_assert_console_list_lock_held (); + +if (printk_kthreads_running) {nbcon_kthread_stop (con); +/* Might be the last nbcon console. +* +* Do not rely on printk_kthreads_check_locked(). It is not +* called in some code paths, see nbcon_free() callers. +*/ +if (!have_nbcon_console) + printk_kthreads_running = false; + } +nbcon_state_set (con, &state);/* Boot consoles share global printk buffers. */
kernel/printk/printk.c +11 -9
@@ -3564,7 +3564,7 @@ EXPORT_SYMBOL(console_start);static int unregister_console_locked (struct console *console);/* True when system boot is far enough to create printer threads. */ -static bool printk_kthreads_ready__ro_after_init ; +bool printk_kthreads_ready__ro_after_init ;static struct task_struct *printk_legacy_kthread;
@@ -3708,6 +3708,7 @@ static void printk_kthreads_check_locked(void)if (!printk_kthreads_ready)return ; +/* Start or stop the legacy kthread when needed. */ if (have_legacy_console || have_boot_console) { if (!printk_legacy_kthread && force_legacy_kthread() &&
@@ -4199,14 +4200,6 @@ static int unregister_console_locked(struct console *console)*/ synchronize_srcu (&console_srcu); -if (console->flags &CON_NBCON ) -nbcon_free (console); - -console_sysfs_notify (); - -if (console->exit) - res = console->exit (console); -/* * With this console gone, the global flags tracking registered * console types may have changed. Update them.
@@ -4227,6 +4220,15 @@ static int unregister_console_locked(struct console *console)if (!found_nbcon_con) have_nbcon_console = found_nbcon_con; +/* @have_nbcon_console must be updated before calling nbcon_free(). */ +if (console->flags &CON_NBCON ) +nbcon_free (console); + +console_sysfs_notify (); + +if (console->exit) + res = console->exit (console); +/* Changed console list, may require printer threads to start/stop. */ printk_kthreads_check_locked ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 182/816 printk: Avoid multiple unregistration in unregister_console_locked()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Ogness <[email protected]>
[ Upstream commit 8a7f26aa072a4e63bc3b1adfe649546709db722e ]
unregister_console_locked() is called from within hlist_for_each_entry_safe(console_list) loops. This would be safe if unregister_console_locked() only unregistered the specified console. After all, that is what the _safe variant is for.
However, unregister_console_locked() calls printk_kthreads_check_locked(), which can unregister _multiple_ consoles if kthreads fail to start. This could lead to hlist_for_each_entry_safe() use-after-free scenarios because not only was the list entry removed, but possibly the following entry as well (the @n temporary storage of the next entry).
Move the call to printk_kthreads_check_locked() outside of unregister_console_locked(). Add comments to both functions to clarify if they are safe to be used in hlist_for_each_entry_safe(console_list) loops.
--- kernel/printk/printk.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
kernel/printk/printk.c +30 -4
@@ -3696,6 +3696,13 @@ static struct syscore printk_syscore = {* If appropriate, start nbcon kthreads and set @printk_kthreads_running. * If any kthreads fail to start, those consoles are unregistered. * +* Called after consoles are registered or unregistered. +* +* This MUST NOT be called within an hlist_for_each_entry_safe(console_list) +* loop because it can unregister multiple consoles if any kthreads fail to +* start. That would lead to use-after-free scenarios within the +* hlist_for_each_entry_safe(console_list) loop of the caller. +* * Must be called under console_list_lock(). */ static void printk_kthreads_check_locked (void )
@@ -4137,7 +4144,20 @@ void register_console(struct console *newcon) }EXPORT_SYMBOL (register_console); -/* Must be called under console_list_lock(). */ +/* +* Unregister the specified console. +* +* This can be called safely from within an +* hlist_for_each_entry_safe(console_list) loop because it unregisters +* _only_ the specified console. +* +* Afterwards the caller should call printk_kthreads_check_locked() since +* unregistering a console may require printer threads to start/stop. Note +* that printk_kthreads_check_locked() cannot be called safely from within +* an hlist_for_each_entry_safe(console_list) loop. +* +* Must be called under console_list_lock(). +*/ static int unregister_console_locked (struct console *console) {bool use_device_lock = (console->flags &CON_NBCON ) && console->write_atomic;
@@ -4229,9 +4249,6 @@ static int unregister_console_locked(struct console *console)if (console->exit) res = console->exit (console); -/* Changed console list, may require printer threads to start/stop. */ -printk_kthreads_check_locked (); -return res; }
@@ -4240,7 +4257,12 @@ int unregister_console(struct console *console)int res;console_list_lock (); + res =unregister_console_locked (console); + +/* Changed console list, may require printer threads to start/stop. */ +printk_kthreads_check_locked (); +console_list_unlock ();return res; }
@@ -4359,6 +4381,10 @@ static int __init printk_late_init(void)unregister_console_locked (con); } } + +/* Changed console list, may require printer threads to start/stop. */ +printk_kthreads_check_locked (); +console_list_unlock (); ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 183/816 virtio-blk: Fix zone append sector reporting in batched completion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shao Mingyin <[email protected]>
[ Upstream commit 08a6572441a4e646c96c2b8d8ead9eea0e458332 ]
For zone append, the block layer copies req->__sector back into the bio in blk_zone_append_update_request_bio(), so the driver must update req->__sector with the sector reported by the device. virtblk_request_done() does that, but the batched completion path used by virtblk_poll() only unmaps and cleans up the requests before calling blk_mq_end_request_batch().
A zone append completed through polling therefore keeps the sector that was assigned at submission time, and the file system or application sees the wrong LBA for the written data.
Move the sector update into a helper and call it from both completion paths.
--- drivers/block/virtio_blk.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/block/virtio_blk.c +15 -5
@@ -332,18 +332,25 @@ static inline u8 virtblk_vbr_status(struct virtblk_req *vbr)return *((u8 *)&vbr->in_hdr + vbr->in_hdr_len -1 ); } +static inline void virtblk_update_zone_append_sector (struct request *req, +struct virtblk_req *vbr) +{ +struct virtio_blk *vblk = req->mq_hctx->queue->queuedata; + +if (req_op (req) ==REQ_OP_ZONE_APPEND ) + req->__sector =virtio64_to_cpu (vblk->vdev, + vbr->in_hdr.zone_append.sector); +} +static inline void virtblk_request_done (struct request *req) {struct virtblk_req *vbr =blk_mq_rq_to_pdu (req);blk_status_t status =virtblk_result (virtblk_vbr_status (vbr)); -struct virtio_blk *vblk = req->mq_hctx->queue->queuedata;virtblk_unmap_data (req, vbr);virtblk_cleanup_cmd (req); -if (req_op (req) ==REQ_OP_ZONE_APPEND ) - req->__sector =virtio64_to_cpu (vblk->vdev, - vbr->in_hdr.zone_append.sector); +virtblk_update_zone_append_sector (req, vbr);blk_mq_end_request (req, status); }
@@ -1213,8 +1220,11 @@ static void virtblk_complete_batch(struct io_comp_batch *iob)struct request *req;rq_list_for_each (&iob->req_list, req) { -virtblk_unmap_data (req,blk_mq_rq_to_pdu (req)); +struct virtblk_req *vbr =blk_mq_rq_to_pdu (req); + +virtblk_unmap_data (req, vbr);virtblk_cleanup_cmd (req); +virtblk_update_zone_append_sector (req, vbr); }blk_mq_end_request_batch (iob); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 184/816 block: partitions: reject GPT entries with starting_lba > ending_lba
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zizhi Wo <[email protected]>
[ Upstream commit 7e3801d12ebabaa3db6e2685ccc80b6e6f6d1ff7 ]
A GPT entry whose starting_lba is greater than its ending_lba is accepted, and the kernel creates a partition with a bogus size. The bogus sector count defeats the end-of-device check, so I/O through that partition is not confined to it and can access sectors outside the partition on the same disk.
is_pte_valid() only rejects an entry when its type is NULL or when starting_lba or ending_lba is greater than lastlba; it never checks that starting_lba <= ending_lba. For a reversed entry both field checks still pass, but efi_partition() computes size = ending_lba - starting_lba + 1 in u64, which underflows to a huge value. That value also wraps in the end-of-device check in blk_add_partition() (from + size) and does not fit the signed i_size, which turns negative.
Reject entries with starting_lba > ending_lba in is_pte_valid(), matching the head-level check against last_usable_lba < first_usable_lba.
--- block/partitions/efi.c | 1 + 1 file changed, 1 insertion(+)
block/partitions/efi.c +1 -0
@@ -461,6 +461,7 @@ static inline int is_pte_valid(const gpt_entry *pte, const u64 lastlba) {if ((!efi_guidcmp (pte->partition_type_guid,NULL_GUID )) || +le64_to_cpu (pte->starting_lba) >le64_to_cpu (pte->ending_lba) ||le64_to_cpu (pte->starting_lba) > lastlba ||le64_to_cpu (pte->ending_lba) > lastlba)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 185/816 block: Replace sprintf() with sysfs_emit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: zhangguopeng <[email protected]>
[ Upstream commit 8e71afb94d6ed59055b67dadbc423c70104f21a9 ]
Per Documentation/filesystems/sysfs.rst, show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.
No functional change intended.
Stable-dep-of: 2516f0413f87 ("block: report the correct discard alignment in sysfs")
--- block/blk-sysfs.c | 24 ++++++++++++------------ block/genhd.c | 30 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-)
block/blk-sysfs.c +12 -12
@@ -32,7 +32,7 @@ struct queue_sysfs_entry {static ssize_t queue_var_show (unsigned long var,char *page) { -return sprintf (page,"%lu\n" , var); +return sysfs_emit (page,"%lu\n" , var); } static ssize_t
@@ -123,7 +123,7 @@ QUEUE_SYSFS_LIMIT_SHOW(atomic_write_unit_max)#define QUEUE_SYSFS_LIMIT_SHOW_SECTORS_TO_BYTES (_field) \ static ssize_t queue_##_field##_show(struct gendisk *disk, char *page) \ { \ - return sprintf(page, "%llu\n", \ + return sysfs_emit(page, "%llu\n", \ (unsigned long long)disk->queue->limits._field << \ SECTOR_SHIFT); \ }
@@ -146,7 +146,7 @@ QUEUE_SYSFS_LIMIT_SHOW_SECTORS_TO_KB(max_hw_sectors)#define QUEUE_SYSFS_SHOW_CONST (_name, _val) \ static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \ { \ - return sprintf(page, "%d\n", _val); \ + return sysfs_emit(page, "%d\n", _val); \ }/* deprecated fields */
@@ -221,7 +221,7 @@ static ssize_t queue_feature_store(struct gendisk *disk, const char *page,#define QUEUE_SYSFS_FEATURE (_name, _feature) \ static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \ { \ - return sprintf(page, "%u\n", \ + return sysfs_emit(page, "%u\n", \ !!(disk->queue->limits.features & _feature)); \ } \ static int queue_##_name##_store(struct gendisk *disk, \
@@ -238,7 +238,7 @@ QUEUE_SYSFS_FEATURE(stable_writes, BLK_FEAT_STABLE_WRITES);#define QUEUE_SYSFS_FEATURE_SHOW (_name, _feature) \ static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \ { \ - return sprintf(page, "%u\n", \ + return sysfs_emit(page, "%u\n", \ !!(disk->queue->limits.features & _feature)); \ }
@@ -256,8 +256,8 @@ static ssize_t queue_poll_show(struct gendisk *disk, char *page)static ssize_t queue_zoned_show (struct gendisk *disk,char *page) {if (blk_queue_is_zoned (disk->queue)) -return sprintf (page,"host-managed\n" ); -return sprintf (page,"none\n" ); +return sysfs_emit (page,"host-managed\n" ); +return sysfs_emit (page,"none\n" ); }static ssize_t queue_nr_zones_show (struct gendisk *disk,char *page)
@@ -342,7 +342,7 @@ static ssize_t queue_poll_store(struct gendisk *disk, const char *page,static ssize_t queue_io_timeout_show (struct gendisk *disk,char *page) { -return sprintf (page,"%u\n" ,jiffies_to_msecs (disk->queue->rq_timeout)); +return sysfs_emit (page,"%u\n" ,jiffies_to_msecs (disk->queue->rq_timeout)); } static ssize_t queue_io_timeout_store(struct gendisk *disk, const char *page,
@@ -363,8 +363,8 @@ static ssize_t queue_io_timeout_store(struct gendisk *disk, const char *page,static ssize_t queue_wc_show (struct gendisk *disk,char *page) {if (blk_queue_write_cache (disk->queue)) -return sprintf (page,"write back\n" ); -return sprintf (page,"write through\n" ); +return sysfs_emit (page,"write back\n" ); +return sysfs_emit (page,"write through\n" ); } static int queue_wc_store(struct gendisk *disk, const char *page,
@@ -495,9 +495,9 @@ static ssize_t queue_wb_lat_show(struct gendisk *disk, char *page)return -EINVAL ;if (wbt_disabled (disk->queue)) -return sprintf (page,"0\n" ); +return sysfs_emit (page,"0\n" ); -return sprintf (page,"%llu\n" , +return sysfs_emit (page,"%llu\n" ,div_u64 (wbt_get_min_lat (disk->queue),1000 )); }
block/genhd.c +15 -15
@@ -772,7 +772,7 @@ static ssize_t disk_badblocks_show(struct device *dev,struct gendisk *disk =dev_to_disk (dev);if (!disk->bb) -return sprintf (page,"\n" ); +return sysfs_emit (page,"\n" );return badblocks_show (disk->bb, page,0 ); }
@@ -932,7 +932,7 @@ static ssize_t disk_range_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" , disk->minors); +return sysfs_emit (buf,"%d\n" , disk->minors); } static ssize_t disk_ext_range_show(struct device *dev,
@@ -940,7 +940,7 @@ static ssize_t disk_ext_range_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" , +return sysfs_emit (buf,"%d\n" , (disk->flags &GENHD_FL_NO_PART ) ?1 :DISK_MAX_PARTS ); }
@@ -949,7 +949,7 @@ static ssize_t disk_removable_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" , +return sysfs_emit (buf,"%d\n" , (disk->flags &GENHD_FL_REMOVABLE ?1 :0 )); }
@@ -958,7 +958,7 @@ static ssize_t disk_hidden_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" , +return sysfs_emit (buf,"%d\n" , (disk->flags &GENHD_FL_HIDDEN ?1 :0 )); }
@@ -967,13 +967,13 @@ static ssize_t disk_ro_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" ,get_disk_ro (disk) ?1 :0 ); +return sysfs_emit (buf,"%d\n" ,get_disk_ro (disk) ?1 :0 ); }ssize_t part_size_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%llu\n" ,bdev_nr_sectors (dev_to_bdev (dev))); +return sysfs_emit (buf,"%llu\n" ,bdev_nr_sectors (dev_to_bdev (dev))); } ssize_t part_stat_show(struct device *dev,
@@ -990,7 +990,7 @@ ssize_t part_stat_show(struct device *dev,part_stat_unlock (); }part_stat_read_all (bdev, &stat); -return sprintf (buf, +return sysfs_emit (buf,"%8lu %8lu %8llu %8u " "%8lu %8lu %8llu %8u " "%8u %8u %8u "
@@ -1032,14 +1032,14 @@ ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,else part_in_flight_rw (bdev, inflight); -return sprintf (buf,"%8u %8u\n" , inflight[0 ], inflight[1 ]); +return sysfs_emit (buf,"%8u %8u\n" , inflight[0 ], inflight[1 ]); }static ssize_t disk_capability_show (struct device *dev,struct device_attribute *attr,char *buf) {dev_warn_once (dev,"the capability attribute has been deprecated.\n" ); -return sprintf (buf,"0\n" ); +return sysfs_emit (buf,"0\n" ); } static ssize_t disk_alignment_offset_show(struct device *dev,
@@ -1048,7 +1048,7 @@ static ssize_t disk_alignment_offset_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" ,bdev_alignment_offset (disk->part0)); +return sysfs_emit (buf,"%d\n" ,bdev_alignment_offset (disk->part0)); } static ssize_t disk_discard_alignment_show(struct device *dev,
@@ -1057,7 +1057,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%d\n" ,bdev_alignment_offset (disk->part0)); +return sysfs_emit (buf,"%d\n" ,bdev_alignment_offset (disk->part0)); } static ssize_t diskseq_show(struct device *dev,
@@ -1065,13 +1065,13 @@ static ssize_t diskseq_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sprintf (buf,"%llu\n" , disk->diskseq); +return sysfs_emit (buf,"%llu\n" , disk->diskseq); }static ssize_t partscan_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%u\n" ,disk_has_partscan (dev_to_disk (dev))); +return sysfs_emit (buf,"%u\n" ,disk_has_partscan (dev_to_disk (dev))); } static DEVICE_ATTR(range, 0444, disk_range_show, NULL);
@@ -1093,7 +1093,7 @@ static DEVICE_ATTR(partscan, 0444, partscan_show, NULL);ssize_t part_fail_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%d\n" , +return sysfs_emit (buf,"%d\n" ,bdev_test_flag (dev_to_bdev (dev),BD_MAKE_IT_FAIL )); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 186/816 block: report the correct discard alignment in sysfs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 2516f0413f8704a7370ef8a2eeae26c9bc438978 ]
disk_discard_alignment_show() reports the physical I/O alignment offset instead of the discard alignment. Devices can specify these offsets independently, so the discard_alignment sysfs attribute can report the wrong value.
Use bdev_discard_alignment() for the whole-disk attribute, as is already done for partitions.
--- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/genhd.c +1 -1
@@ -1057,7 +1057,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev, {struct gendisk *disk =dev_to_disk (dev); -return sysfs_emit (buf,"%d\n" ,bdev_alignment_offset (disk->part0)); +return sysfs_emit (buf,"%u\n" ,bdev_discard_alignment (disk->part0)); } static ssize_t diskseq_show(struct device *dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 187/816 vsock: reject negative tv_usec in SO_VM_SOCKETS_CONNECT_TIMEOUT
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Dinh Phi <[email protected]>
[ Upstream commit c0ef6144b4d60afb90bc6d8db3ffdac043cd6ffc ]
The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.
--- net/vmw_vsock/af_vsock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +2 -1
@@ -1941,7 +1941,8 @@ static int vsock_connectible_setsockopt(struct socket *sock, optname == SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD);if (err)break ; -if (tv.tv_sec >=0 && tv.tv_usec <USEC_PER_SEC && +if (tv.tv_sec >=0 && tv.tv_usec >=0 && + tv.tv_usec <USEC_PER_SEC && tv.tv_sec < (MAX_SCHEDULE_TIMEOUT /HZ -1 )) { vsk->connect_timeout = tv.tv_sec *HZ +DIV_ROUND_UP ((unsigned long )tv.tv_usec, (USEC_PER_SEC /HZ ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 188/816 null_blk: fix opening closed zones at the active zone limit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 6f2b59737bf9cf3623719857ac149f0d431db109 ]
When the open zone limit is reached, null_check_open() closes an implicitly open zone only if the active zone limit is not reached.
Closing an implicitly open zone does not change the number of active zones, so this check is wrong. For an empty zone, the active zone limit was already checked by null_check_zone_resources(). For a closed zone, the check makes writing to, opening or finishing the zone fail with BLK_STS_ZONE_OPEN_RESOURCE at the active zone limit, whereas ZBC-3 (4.5.3.2.7.2) and NVMe ZNS (2.1.1.4.1) require closing an implicitly open zone instead.
Remove the check, and update the comment abovenull_check_zone_resources() accordingly.
--- drivers/block/null_blk/zoned.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/block/null_blk/zoned.c +7 -6
@@ -311,10 +311,8 @@ static blk_status_t null_check_open(struct nullb_device *dev)return BLK_STS_OK ;if (dev->nr_zones_imp_open) { -if (null_check_active (dev) ==BLK_STS_OK ) { -null_close_imp_open_zone (dev); -return BLK_STS_OK ; - } +null_close_imp_open_zone (dev); +return BLK_STS_OK ; }return BLK_STS_ZONE_OPEN_RESOURCE ;
@@ -330,8 +328,11 @@ static blk_status_t null_check_open(struct nullb_device *dev)* * ZBC states that an implicit open zone shall be closed only if there is not * room within the open limit. However, with the addition of an active limit, -* it is not certain that closing an implicit open zone will allow a new zone -* to be opened, since we might already be at the active limit capacity. +* it is not certain that closing an implicit open zone will allow an empty +* zone to be opened, since we might already be at the active limit capacity. +* Therefore, the active limit is checked first for an empty zone. A closed +* zone already holds an active zone resource, so only the open limit has to +* be checked for a closed zone. */ static blk_status_t null_check_zone_resources (struct nullb_device *dev,struct nullb_zone *zone)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 189/816 null_blk: dont finish zones to set them read-only or offline
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 973bf587d79f061beffdd392e77012a07f25fcd6 ]
null_set_zone_cond() calls null_finish_zone() to release the zone resources held by a zone before setting it read-only or offline.
For an empty or closed zone, null_finish_zone() first runs the zone resource checks, which can close an unrelated implicitly open zone, or fail. As the error is ignored, a failure for a closed zone leaks nr_zones_closed, permanently lowering the effective active zone limit.
Setting a zone read-only or offline requires no zone resources, so release the zone resources held by the zone directly instead, using a new helper, null_release_zone_resources().
--- drivers/block/null_blk/zoned.c | 35 +++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)
drivers/block/null_blk/zoned.c +30 -5
@@ -731,6 +731,33 @@ blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_op op, } } +/* +* Release the zone resources held by a zone, before changing the condition of +* the zone to a condition that does not hold any zone resources. +*/ +static void null_release_zone_resources (struct nullb_device *dev, +struct nullb_zone *zone) +{ +if (!dev->need_zone_res_mgmt) +return ; + +spin_lock (&dev->zone_res_lock); +switch (zone->cond) { +case BLK_ZONE_COND_IMP_OPEN : + dev->nr_zones_imp_open--; +break ; +case BLK_ZONE_COND_EXP_OPEN : + dev->nr_zones_exp_open--; +break ; +case BLK_ZONE_COND_CLOSED : + dev->nr_zones_closed--; +break ; +default : +break ; + } +spin_unlock (&dev->zone_res_lock); +} +/* * Set a zone in the read-only or offline condition. */
@@ -747,8 +774,8 @@ static void null_set_zone_cond(struct nullb_device *dev,* If the read-only condition is requested again to zones already in * read-only condition, restore back normal empty condition. Do the same * if the offline condition is requested for offline zones. Otherwise, -* set the specified zone condition to the zones. Finish the zones -* beforehand to free up zone resources. +* set the specified zone condition to the zones. Release the zone +* resources held by the zones beforehand. */ if (zone->cond == cond) { zone->cond =BLK_ZONE_COND_EMPTY ;
@@ -756,9 +783,7 @@ static void null_set_zone_cond(struct nullb_device *dev,if (dev->memory_backed)null_handle_discard (dev, zone->start, zone->len); }else { -if (zone->cond !=BLK_ZONE_COND_READONLY && - zone->cond !=BLK_ZONE_COND_OFFLINE ) -null_finish_zone (dev, zone); +null_release_zone_resources (dev, zone); zone->cond = cond; zone->wp =NULL_ZONE_INVALID_WP ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 190/816 tcp: wait for TIME_WAIT teardown before freeing per-netns ehash
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 647b81ddefc6364290e67bf33c89d54971f8995e ]
inet_twsk_kill() removes a TIME_WAIT socket from the established hash before it finishes using the ehash lock, hashinfo and bind tables, and before it drops the death-row reference. A running timer can therefore unhash its socket before inet_twsk_purge() reaches it. The purge cannot synchronize with that timer, and tcp_sk_exit_batch() can free the private ehash and hashinfo while inet_twsk_kill() is still using them.
An unprivileged reproducer using user and network namespaces, a private TCP ehash and a FIN_WAIT2 timer triggers a KASAN slab-use-after-free in inet_twsk_kill(). The allocation and free stacks point to inet_pernet_hashinfo_alloc() and inet_pernet_hashinfo_free().
Wait for an RCU grace period after purging the whole batch, if one netns in the batch uses a private ehash. TIME_WAIT removal runs with bottom halves disabled, so this also waits for removers that were already invisible to the purge. Keep the wait under tcp_exit_batch_mutex, before freeing any private hashinfo.
The same window exists with the shared tcp_hashinfo. There, the hashinfo memory stays valid, but tcp_sk_exit_batch() can decrement tcp_death_row.tw_refcount from 2 to 1 before inet_twsk_kill() drops its own reference. This triggers the WARN_ON_ONCE() in tcp_sk_exit_batch(), then a refcount_t "decrement hit 0" warning from inet_twsk_kill().
Adding a grace period for the shared case would be costly on busy hosts. It is not needed: struct net is freed by a later cleanup_net(), after the synchronize_rcu() in ops_undo_list(), so inet_twsk_kill() can safely drop the last tw_refcount reference itself.
Use refcount_dec_if_one() and only warn if tw_refcount is not 1 after a grace period.
[edumazet: only call synchronize_net() if one netns in the batch uses a private ehash,
use refcount_dec_if_one() to avoid a false WARN with the shared ehash]
--- net/ipv4/tcp_ipv4.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/ipv4/tcp_ipv4.c +20 -1
@@ -3681,6 +3681,7 @@ static int __net_init tcp_sk_init(struct net *net) static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) { +bool synced = false;struct net *net;/* make sure concurrent calls to tcp_sk_exit_batch from net_cleanup_work
@@ -3695,9 +3696,27 @@ static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list)tcp_twsk_purge (net_exit_list); +/* inet_twsk_kill() unhashes a twsk before it is done with ehash +* and bhash, and before it drops its tw_refcount reference, +* so tcp_twsk_purge() can miss it. Such callers run with BH +* disabled: wait for them before freeing a private ehash. +*/ +list_for_each_entry (net, net_exit_list, exit_list) { +if (net->ipv4.tcp_death_row.hashinfo->pernet) { +synchronize_net (); + synced = true; +break ; + } + } +list_for_each_entry (net, net_exit_list, exit_list) {inet_pernet_hashinfo_free (net->ipv4.tcp_death_row.hashinfo); -WARN_ON_ONCE (!refcount_dec_and_test (&net->ipv4.tcp_death_row.tw_refcount)); +/* Without a grace period, a concurrent inet_twsk_kill() might +* still hold a tw_refcount reference. Let it drop it: struct net +* is freed by a later cleanup_net(), after an RCU grace period. +*/ +if (!refcount_dec_if_one (&net->ipv4.tcp_death_row.tw_refcount)) +WARN_ON_ONCE (synced);tcp_fastopen_ctx_destroy (net); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 191/816 net: dsa: b53: Enable IGMP and MLD control packet CPU copies
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 3362cb822ea750399a15b741713181fd8560bd17 ]
IGMPv2 reports and MLDv1 reports are addressed to the multicast group itself. Once the first listener is installed in the ARL table, subsequent reports can follow that entry without reaching the CPU. The bridge then fails to learn additional listeners, although static MDB forwarding works.
Enable the high-level protocol classifiers so that IGMP and MLD control packets are copied to the CPU independently of the multicast ARL lookup. Retain normal L2 forwarding by clearing the CPU-only forwarding modes, and preserve unrelated protocol-control fields.
Handle the BCM5395's 16-bit register and different classifier fields separately from the 32-bit layout on the BCM531xx, BCM5301x and newer integrated RoboSwitch families, including BCM7445, BCM7278 and BCM4908. Export the helper and call it from bcm_sf2_sw_setup() as well, since SF2 uses its own setup operation instead of b53_setup(). This also restores the classifiers after the switch reset on resume. Leave older devices with different IGMP controls untouched, and propagate register access failures during setup.
The SF2 setup integration and BCM4908 chip gate were updated with assistance from OpenAI Codex in response to review feedback.
--- drivers/net/dsa/b53/b53_common.c | 57 ++++++++++++++++++++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 1 + drivers/net/dsa/b53/b53_regs.h | 17 ++++++++++ drivers/net/dsa/bcm_sf2.c | 5 +++ 4 files changed, 80 insertions(+)
drivers/net/dsa/b53/b53_common.c +57 -0
@@ -770,6 +770,59 @@ void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) }EXPORT_SYMBOL (b53_brcm_hdr_setup); +int b53_enable_mcast_snooping (struct b53_device *dev) +{ +u16 val16; +u32 val; +int ret; + +/* Older switches use different IGMP controls, not HL_PRTC_CTRL. */ +if (is5325 (dev) ||is5365 (dev) || dev->chip_id ==BCM5389_DEVICE_ID || +is5397_98 (dev) ||is63xx (dev)) +return 0 ; + +/* IGMPv2 and MLDv1 reports use the group's destination MAC. Once +* the first listener is offloaded, ordinary multicast forwarding +* can keep subsequent reports from reaching the bridge CPU. +*/ + +/* BCM5395 has a narrower register and a single IGMP classifier. +* Its ICMPv6 classifier also covers MLD. +*/ +if (dev->chip_id ==BCM5395_DEVICE_ID ) { + ret =b53_read16 (dev,B53_MGMT_PAGE ,B53_HL_PRTC_CTRL , &val16); +if (ret) +return ret; + + val16 |=HL_PRTC_IGMP_IP_EN_5395 |HL_PRTC_ICMPV6_EN ; +/* Zero forwarding modes copy control traffic to the CPU +* independently of the ARL lookup, retaining L2 forwarding. +*/ + val16 &= ~(HL_PRTC_IGMP_FWD_MODE_5395 | +HL_PRTC_ICMPV6_FWD_MODE ); + +return b53_write16 (dev,B53_MGMT_PAGE ,B53_HL_PRTC_CTRL , + val16); + } + + ret =b53_read32 (dev,B53_MGMT_PAGE ,B53_HL_PRTC_CTRL , &val); +if (ret) +return ret; + + val |=HL_PRTC_IGMP_RPTLVE_EN |HL_PRTC_IGMP_QRY_EN | +HL_PRTC_IGMP_UKN_EN |HL_PRTC_MLD_RPTDONE_EN | +HL_PRTC_MLD_QRY_EN ; +/* Zero forwarding modes copy control traffic to the CPU +* independently of the ARL lookup, retaining L2 forwarding. +*/ + val &= ~(HL_PRTC_IGMP_RPTLVE_FWD_MODE |HL_PRTC_IGMP_QRY_FWD_MODE | +HL_PRTC_IGMP_UKN_FWD_MODE |HL_PRTC_MLD_RPTDONE_FWD_MODE | +HL_PRTC_MLD_QRY_FWD_MODE ); + +return b53_write32 (dev,B53_MGMT_PAGE ,B53_HL_PRTC_CTRL , val); +} +EXPORT_SYMBOL (b53_enable_mcast_snooping); +static void b53_enable_cpu_port (struct b53_device *dev,int port) {u8 port_ctrl;
@@ -1261,6 +1314,10 @@ static int b53_setup(struct dsa_switch *ds)b53_disable_port (ds, port); } + ret =b53_enable_mcast_snooping (dev); +if (ret) +return ret; +return b53_setup_devlink_resources (ds); }
drivers/net/dsa/b53/b53_priv.h +1 -0
@@ -336,6 +336,7 @@ static inline int b53_switch_get_reset_gpio(struct b53_device *dev)/* Exported functions towards other drivers */ void b53_imp_vlan_setup (struct dsa_switch *ds,int cpu_port);int b53_configure_vlan (struct dsa_switch *ds); +int b53_enable_mcast_snooping (struct b53_device *dev);void b53_get_strings (struct dsa_switch *ds,int port,u32 stringset,uint8_t *data);void b53_get_ethtool_stats (struct dsa_switch *ds,int port,uint64_t *data);
drivers/net/dsa/b53/b53_regs.h +17 -0
@@ -262,6 +262,23 @@/* Revision ID register (8 bit) */ #define B53_REV_ID 0x40 +/* High-level protocol control (16 bit on BCM5395, otherwise 32 bit) */ +#define B53_HL_PRTC_CTRL 0x50 +#define HL_PRTC_ICMPV6_EN BIT(4) +#define HL_PRTC_ICMPV6_FWD_MODE BIT(5) +#define HL_PRTC_IGMP_IP_EN_5395 BIT(6) +#define HL_PRTC_IGMP_FWD_MODE_5395 BIT(8) +#define HL_PRTC_IGMP_RPTLVE_EN BIT(9) +#define HL_PRTC_IGMP_RPTLVE_FWD_MODE BIT(10) +#define HL_PRTC_IGMP_QRY_EN BIT(11) +#define HL_PRTC_IGMP_QRY_FWD_MODE BIT(12) +#define HL_PRTC_IGMP_UKN_EN BIT(13) +#define HL_PRTC_IGMP_UKN_FWD_MODE BIT(14) +#define HL_PRTC_MLD_RPTDONE_EN BIT(15) +#define HL_PRTC_MLD_RPTDONE_FWD_MODE BIT(16) +#define HL_PRTC_MLD_QRY_EN BIT(17) +#define HL_PRTC_MLD_QRY_FWD_MODE BIT(18) +/* Broadcom header RX control (16 bit) */ #define B53_BRCM_HDR_RX_DIS 0x60
drivers/net/dsa/bcm_sf2.c +5 -0
@@ -1059,6 +1059,7 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds) {struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds);unsigned int port; +int ret;/* Enable all valid ports and disable those unused */ for (port =0 ; port < priv->hw_params.num_ports; port++) {
@@ -1074,6 +1075,10 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)b53_configure_vlan (ds);bcm_sf2_enable_acb (ds); + ret =b53_enable_mcast_snooping (priv->dev); +if (ret) +return ret; +return b53_setup_devlink_resources (ds); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 192/816 net: ethernet: mediatek: preserve sibling PPE bindings
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Goodkind <[email protected]>
[ Upstream commit 34cc22a9ce6ae0228dcd09a57df23aea62e22b04 ]
__mtk_ppe_check_skb() clears entry->hash for flows bound to other hardware slots in the same software hash bucket. mtk_flow_offload_stats() then skips their hardware counter updates. L2 cleanup also frees sibling subflows without invalidating their hardware rules.
Restrict both cleanup paths to entries assigned to the inspected slot.
Two UDP trials reproduced the counter failure on a GL-MT3000/MT7981 running unmodified OpenWrt 25.12.5 with Linux 6.12.94:
1. Start a UDP connection.
2. Add a control connection in a different hash bucket.
3. Add a connection in the first connection's hash bucket.
AI code review of the original patch identified the cleanup problem in L2 subflows.
Full ARM64 builds with allmodconfig and allyesconfig passed before and after the patch using GCC 14.2.0 and W=1, without new warnings. The builds used CONFIG_WERROR=n because the unmodified ARM64 kernel already emits warnings. Hardware testing has not run for this revision.
--- drivers/net/ethernet/mediatek/mtk_ppe.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +2 -3
@@ -754,8 +754,7 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)hlist_for_each_entry_safe (entry, n, head, list) {if (entry->type ==MTK_FLOW_TYPE_L2_SUBFLOW ) { -if (unlikely (FIELD_GET (MTK_FOE_IB1_STATE , hwe->ib1) == -MTK_FOE_STATE_BIND )) +if (entry->hash != hash)continue ; entry->hash =0xffff ;
@@ -764,7 +763,7 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash) }if (found || !mtk_flow_entry_match (ppe->eth, entry, hwe)) { -if (entry->hash !=0xffff ) +if (entry->hash == hash) entry->hash =0xffff ;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 193/816 nvmet-tcp: ask for the TLS record type on every receive
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 77f72de389e3774dc95d7cd03a98a73e47013abd ]
nvmet_tcp_alloc_cmd() points recv_msg.msg_control at recv_cbuf once. The first receive that stores a record type there advances msg_control and leaves msg_controllen at 0 for the lifetime of the command. From then on nvmet_tcp_try_recv_data() sees the record type of that first
receive: if it was an alert, all later data is dropped as alerts and the queue stalls, if it was data, a later alert can't be reported and tls_sw_recvmsg() fails with -EIO.
Set up the control buffer before each receive, like the other receive paths do.
--- drivers/nvme/target/tcp.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/nvme/target/tcp.c +5 -0
@@ -1346,6 +1346,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)int len, ret;while (msg_data_left (&cmd->recv_msg)) { +if (queue->tls_pskid) { +/* The last receive has used it up */ + cmd->recv_msg.msg_control = cmd->recv_cbuf; + cmd->recv_msg.msg_controllen =sizeof (cmd->recv_cbuf); + } len =sock_recvmsg (cmd->queue->sock, &cmd->recv_msg, cmd->recv_msg.msg_flags);if (len <=0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 194/816 nvmet-rdma: disconnect only established queues
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 000a9f4492abad6008682b55571ddc31941963e3 ]
Over iWARP, rdma_disconnect() sleeps in iw_cm_disconnect() until the ESTABLISHED event of the connection has been handled, and iw_cm handles all events of all connections one at a time on iw_cm_wq. nvmet_rdma_destroy_port_queues(), nvmet_rdma_remove_one() and nvmet_rdma_delete_ctrl() walk the queue list with nvmet_rdma_queue_mutex held and call rdma_disconnect() for each, while nvmet_rdma_cm_handler() takes the same mutex. If the walk sleeps on a queue whose ESTABLISHED is queued behind another queue's event, both are stuck and iWARP connection handling is dead until reboot. A peer sets that up by connecting in a loop, or over siw by asking for MPA peer-to-peer mode and then staying silent, which delays ESTABLISHED indefinitely.
Only call rdma_disconnect() for a queue in NVMET_RDMA_Q_LIVE, which the handler sets when it gets ESTABLISHED. A queue that never got there is left to the release work: ib_drain_qp() moves the QP to the error state, which ends the connection, and rdma_destroy_id() tells the peer. Over IB and RoCE the skipped call did nothing more than that.
--- drivers/nvme/target/rdma.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/nvme/target/rdma.c +13 -2
@@ -1689,7 +1689,7 @@ static void nvmet_rdma_queue_established(struct nvmet_rdma_queue *queue)static void __nvmet_rdma_queue_disconnect (struct nvmet_rdma_queue *queue) { -bool disconnect = false; +bool disconnect = false, live = false;unsigned long flags;pr_debug ("cm_id= %p queue->state= %d\n" , queue->cm_id, queue->state);
@@ -1708,6 +1708,7 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) } fallthrough;case NVMET_RDMA_Q_LIVE : + live = queue->state ==NVMET_RDMA_Q_LIVE ; queue->state =NVMET_RDMA_Q_DISCONNECTING ; disconnect = true;break ;
@@ -1717,7 +1718,17 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue)spin_unlock_irqrestore (&queue->state_lock, flags);if (disconnect) { -rdma_disconnect (queue->cm_id); +/* +* Over iWARP rdma_disconnect() sleeps until the CM has handled +* the ESTABLISHED event of this connection. The CM handles the +* events of all connections one at a time, and our handler +* takes nvmet_rdma_queue_mutex, which callers of this function +* hold. So a queue that has not seen the event is left to the +* release work: ib_drain_qp() moves the queue pair to the error +* state, which ends the connection. +*/ +if (live) +rdma_disconnect (queue->cm_id);queue_work (nvmet_wq, &queue->release_work); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 195/816 nvmet-tcp: limit the connections accepted per work run
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit a029f1b2fb13e6ac6e1c2f27fba1d80b6e7cac51 ]
nvmet_tcp_accept_work() loops until there's nothing left to accept, and anyone opening and closing connections fast enough keeps it running indefinitely, since tearing down a dead connection takes long enough for more to arrive. Whoever flushes nvmet_wq waits for it: removing any other port of the target does in nvmet_port_release(), and so does unloading the rdma and fc modules.
Accept a bounded number of connections per run and requeue the work. A flush doesn't wait for work queued behind it.
--- drivers/nvme/target/tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nvme/target/tcp.c +6 -2
@@ -86,6 +86,7 @@ MODULE_PARM_DESC(tls_handshake_timeout,#define NVMET_TCP_RECV_BUDGET 8#define NVMET_TCP_SEND_BUDGET 8#define NVMET_TCP_IO_WORK_BUDGET 64 +#define NVMET_TCP_ACCEPT_BUDGET 16enum nvmet_tcp_send_state {NVMET_TCP_SEND_DATA_PDU ,
@@ -2090,9 +2091,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w)struct nvmet_tcp_port *port = container_of(w, struct nvmet_tcp_port, accept_work);struct socket *newsock; -int ret; +int ret, i; -while (true) { +for (i =0 ; i <NVMET_TCP_ACCEPT_BUDGET ; i++) { ret =kernel_accept (port->sock, &newsock,O_NONBLOCK );if (ret <0 ) {if (ret != -EAGAIN )
@@ -2101,6 +2102,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w) }nvmet_tcp_alloc_queue (port, newsock); } + +/* There may be more. Come to an end for those who flush nvmet_wq. */ +queue_work (nvmet_wq, &port->accept_work); }static void nvmet_tcp_listen_data_ready (struct sock *sk)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 196/816 nvmet-rdma: take a device off the list last
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 86ae3841aea4e29d7ac08d5614ca3823dc8dfbc9 ]
nvmet_rdma_remove_one() disconnects the queues of a device and flushes nvmet-wq, but since commit a3dd7d0022c3 it returns right away if the device isn't on device_list. nvmet_rdma_free_dev(), run by the release work of the last queue, takes the device off that list first and frees the SRQs and the PD afterwards. A device removal in between finds nothing on the list, returns, and the RDMA core frees the device under ib_dealloc_pd().
Free the SRQs and the PD first and unlist the device last, so the remove callback finds it and its flush waits for the release work.
--- drivers/nvme/target/rdma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nvme/target/rdma.c +8 -3
@@ -1198,13 +1198,18 @@ static void nvmet_rdma_free_dev(struct kref *ref)struct nvmet_rdma_device *ndev = container_of(ref, struct nvmet_rdma_device, ref); +nvmet_rdma_destroy_srqs (ndev); +ib_dealloc_pd (ndev->pd); + +/* +* Only delete from the device list once all RDMA resources are torn +* down because nvmet_rdma_remove_one waits for the release work only +* if the device still is on the list. +*/ mutex_lock (&device_list_mutex);list_del (&ndev->entry);mutex_unlock (&device_list_mutex); -nvmet_rdma_destroy_srqs (ndev); -ib_dealloc_pd (ndev->pd); -kfree (ndev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 197/816 nvmet-rdma: queue the release work under the mutex
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 80095787f776967361cca76357f19e5445e0cd75 ]
nvmet_rdma_remove_one() takes the queue mutex, unlists each queue of the device and queues its release work, then flushes nvmet-wq. So a queue that still holds objects on the device must either be on the list or have its release work queued. nvmet_rdma_queue_disconnect() breaks that: it unlists the queue under the mutex, drops it, and only then calls __nvmet_rdma_queue_disconnect() to queue the work. A device removal in that window finds nothing to wait for, and the release work then destroys the QP and CQ share on a freed device.
Queue the work before dropping the mutex, as nvmet_rdma_remove_one() itself does. That's safe now that rdma_disconnect() no longer sleeps on an iWARP event that needs the same mutex.
--- drivers/nvme/target/rdma.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/nvme/target/rdma.c +6 -6
@@ -1740,17 +1740,17 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue)static void nvmet_rdma_queue_disconnect (struct nvmet_rdma_queue *queue) { -bool disconnect = false; - +/* +* Queue the release work with &nvmet_rdma_queue_mutex held, so that +* nvmet_rdma_remove_one() either finds the queue on the list or the +* work has already been queued. +*/ mutex_lock (&nvmet_rdma_queue_mutex);if (!list_empty (&queue->queue_list)) {list_del_init (&queue->queue_list); - disconnect = true; +__nvmet_rdma_queue_disconnect (queue); }mutex_unlock (&nvmet_rdma_queue_mutex); - -if (disconnect) -__nvmet_rdma_queue_disconnect (queue); } static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 198/816 nvme: fix various comment typos
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Helgaas <[email protected]>
[ Upstream commit 367c240b0a99c7ada700a44345dd3144a02b6164 ]
Fix typos in comments.
Stable-dep-of: a4387799d422 ("nvmet-rdma: disconnect a queue on device removal")
--- drivers/nvme/host/fc.c | 4 ++-- drivers/nvme/host/tcp.c | 2 +- drivers/nvme/target/fc.c | 6 +++--- drivers/nvme/target/rdma.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)
drivers/nvme/host/fc.c +2 -2
@@ -1364,7 +1364,7 @@ nvme_fc_disconnect_assoc_done(struct nvmefc_ls_req *lsreq, int status)* down, and the related FC-NVME Association ID and Connection IDs * become invalid. * -* The behavior of the fc-nvme initiator is such that it's +* The behavior of the fc-nvme initiator is such that its * understanding of the association and connections will implicitly * be torn down. The action is implicit as it may be due to a loss of * connectivity with the fc-nvme target, so you may never get a
@@ -2779,7 +2779,7 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,* as WRITE ZEROES will return a non-zero rq payload_bytes yet * there is no actual payload to be transferred. * To get it right, key data transmission on there being 1 or -* more physical segments in the sg list. If there is no +* more physical segments in the sg list. If there are no * physical segments, there is no payload. */ if (blk_rq_nr_phys_segments (rq)) {
drivers/nvme/host/tcp.c +1 -1
@@ -2438,7 +2438,7 @@ static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new)/* * Only start IO queues for which we have allocated the tagset -* and limitted it to the available queues. On reconnects, the +* and limited it to the available queues. On reconnects, the * queue number might have changed. */ nr_queues =min (ctrl->tagset->nr_hw_queues +1 , ctrl->queue_count);
drivers/nvme/target/fc.c +3 -3
@@ -459,7 +459,7 @@ nvmet_fc_disconnect_assoc_done(struct nvmefc_ls_req *lsreq, int status)* down, and the related FC-NVME Association ID and Connection IDs * become invalid. * -* The behavior of the fc-nvme target is such that it's +* The behavior of the fc-nvme target is such that its * understanding of the association and connections will implicitly * be torn down. The action is implicit as it may be due to a loss of * connectivity with the fc-nvme host, so the target may never get a
@@ -2294,7 +2294,7 @@ nvmet_fc_transfer_fcp_data(struct nvmet_fc_tgtport *tgtport, ret = tgtport->ops->fcp_op (&tgtport->fc_target_port, fod->fcpreq);if (ret) {/* -* should be ok to set w/o lock as its in the thread of +* should be ok to set w/o lock as it's in the thread of * execution (not an async timer routine) and doesn't * contend with any clearing action */
@@ -2612,7 +2612,7 @@ nvmet_fc_handle_fcp_rqst(struct nvmet_fc_tgtport *tgtport,* and the api of the FC LLDD which may issue a hw command to send the * response, but the LLDD may not get the hw completion for that command * and upcall the nvmet_fc layer before a new command may be -* asynchronously received - its possible for a command to be received +* asynchronously received - it's possible for a command to be received * before the LLDD and nvmet_fc have recycled the job structure. It gives * the appearance of more commands received than fits in the sq. * To alleviate this scenario, a temporary queue is maintained in the
drivers/nvme/target/rdma.c +3 -3
@@ -1780,7 +1780,7 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,* We registered an ib_client to handle device removal for queues, * so we only need to handle the listening port cm_ids. In this case * we nullify the priv to prevent double cm_id destruction and destroying -* the cm_id implicitely by returning a non-zero rc to the callout. +* the cm_id implicitly by returning a non-zero rc to the callout. */ static int nvmet_rdma_device_removal (struct rdma_cm_id *cm_id,struct nvmet_rdma_queue *queue)
@@ -1791,7 +1791,7 @@ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id,/* * This is a queue cm_id. we have registered * an ib_client to handle queues removal -* so don't interfear and just return. +* so don't interfere and just return. */ return 0 ; }
@@ -1809,7 +1809,7 @@ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id,/* * We need to return 1 so that the core will destroy -* it's own ID. What a great API design.. +* its own ID. What a great API design.. */ return 1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 199/816 nvmet-rdma: disconnect a queue on device removal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit a4387799d4228866dc1746b466cd17e1c638d050 ]
cma_remove_one() sends DEVICE_REMOVAL to the owner of every cm_id on the device and then waits, without timeout, until they're all destroyed. nvmet_rdma_device_removal() does nothing for a queue cm_id and leaves the queues to nvmet_rdma_remove_one(), which only works if that runs first. As a module it does, nvmet-rdma registers after rdma_cm. Built in, both register at the same initcall level and drivers/Makefile lists nvme/ ahead of infiniband/, so cma_remove_one() runs first and waits for cm_ids that only the later callback would destroy. Since the RDMA CM drops all later events for a cm_id once it has sent DEVICE_REMOVAL, a peer closing its connection doesn't help either. One connection from anyone who can reach the port hangs "rdma link delete" until something else ends the queue.
Call nvmet_rdma_queue_disconnect() for the queue. It unlists the queue and queues the release work, which destroys the cm_id. Don't wait for it, rdma_destroy_id() waits for the handler to return, which was the deadlock before commit f1d4ef7d8883.
--- drivers/nvme/target/rdma.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/nvme/target/rdma.c +8 -9
@@ -1777,10 +1777,13 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,* queue cm_id and/or a device bound listener cm_id (where in this * case queue will be null). * -* We registered an ib_client to handle device removal for queues, -* so we only need to handle the listening port cm_ids. In this case -* we nullify the priv to prevent double cm_id destruction and destroying -* the cm_id implicitly by returning a non-zero rc to the callout. +* The RDMA CM waits until each cm_id of the device is destroyed, so a queue +* has to go now. Our ib_client also removes the queues, but it cannot be +* relied on here: built in, it is called after the RDMA CM's client. +* +* For a listening port cm_id we nullify the priv to prevent double cm_id +* destruction and destroying the cm_id implicitly by returning a non-zero +* rc to the callout. */ static int nvmet_rdma_device_removal (struct rdma_cm_id *cm_id,struct nvmet_rdma_queue *queue)
@@ -1788,11 +1791,7 @@ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id,struct nvmet_rdma_port *port;if (queue) { -/* -* This is a queue cm_id. we have registered -* an ib_client to handle queues removal -* so don't interfere and just return. -*/ +nvmet_rdma_queue_disconnect (queue);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 200/816 net: ethernet: ti: am65-cpts: adjust perout genf following ptp changes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 3f1054a0cb09552dd54db024694f74747f9f1d49 ]
A periodic output requested by PTP_PEROUT_REQUEST2 drifts away from the PHC as soon as the PHC frequency is adjusted, for example by ptp4l or ts2phc: at +10 ppm each edge is 10 us later than the one before.
The GenF that generates the output counts its period in ref_clk cycles, which the PPM correction of the CPTS clock does not reach; each GenF has its own PPM registers. am65_cpts_ptp_adjfine() programs them only for the GenF used for PPS, and am65_cpts_perout_enable_hw() starts every GenF with them cleared, so a GenF used for a periodic output is never corrected.
Commit eb9233ce6751 ("net: ethernet: ti: am65-cpts: adjust pps following ptp changes") added the correction for the PPS GenF, and commit 7849c42da2ca ("net: ethernet: ti: am65-cpts: adjust estf following ptp changes") passed the same values to the ESTFs.
In am65_cpts_ptp_adjfine(), update every enabled GenF the way the PPS GenF was updated: read its control register, set or clear the PPM direction bit and write it back with the PPM value. The PPS GenF and the ESTFs get exactly the values they got before. In am65_cpts_perout_enable_hw(), start a GenF with the current correction instead of none; this applies to the PPS GenF too.
Tested on a BeagleY-AI (J722S) with the GENF0 output looped back to the HW1_TS_PUSH input (EXTTS 0). With the PHC frequency adjusted by +10 ppm before the periodic output is started, the edges drift 10 us per second against the PHC without this patch (290 us after 29 s); with it, they stay 20 to 23 ns after the PHC second. This also works if the frequency is adjusted after the periodic output has started.
--- drivers/net/ethernet/ti/am65-cpts.c | 67 +++++++++++++++++++---------- 1 file changed, 45 insertions(+), 22 deletions(-)
drivers/net/ethernet/ti/am65-cpts.c +45 -22
@@ -176,6 +176,9 @@ struct am65_cpts {struct mutex ptp_clk_lock;/* PHC access sync */ u64 timestamp;u32 genf_enable; +bool genf_neg_adj; +u32 genf_ppm_hi; +u32 genf_ppm_low;u32 hw_ts_enable;u32 estf_enable;struct sk_buff_head txq;
@@ -436,9 +439,11 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) { struct am65_cpts *cpts = container_of(ptp, struct am65_cpts, ptp_info);u32 estf_ctrl_val =0 , estf_ppm_hi =0 , estf_ppm_low =0 ; +u32 genf_ctrl_val[AM65_CPTS_GENF_MAX_NUM ]; +u32 genf_ppm_hi, genf_ppm_low;s32 ppb =scaled_ppm_to_ppb (scaled_ppm);int pps_index = cpts->pps_genf_idx; -u64 adj_period, pps_adj_period; +u64 adj_period, genf_adj_period;u32 ctrl_val, ppm_hi, ppm_low;unsigned long flags;int neg_adj =0 , i;
@@ -470,20 +475,33 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) ppm_hi =upper_32_bits (adj_period) &0x3FF ; ppm_low =lower_32_bits (adj_period); +/* GenF PPM will do correction using cpts refclk tick which is +* (cpts->ts_add_val + 1) ns, so GenF length PPM adj period +* need to be corrected. +*/ + genf_adj_period = adj_period * (cpts->ts_add_val +1 ); + genf_ppm_hi =upper_32_bits (genf_adj_period) &0x3FF ; + genf_ppm_low =lower_32_bits (genf_adj_period); + cpts->genf_neg_adj = neg_adj; + cpts->genf_ppm_hi = genf_ppm_hi; + cpts->genf_ppm_low = genf_ppm_low; + +for (i =0 ; i <AM65_CPTS_GENF_MAX_NUM ; i++) { +if (cpts->genf_enable &BIT (i)) { + genf_ctrl_val[i] =am65_cpts_read32 (cpts, + genf[i].control); +if (neg_adj) + genf_ctrl_val[i] &= ~BIT (1 ); +else + genf_ctrl_val[i] |=BIT (1 ); + } + } +if (cpts->pps_enabled) { - estf_ctrl_val =am65_cpts_read32 (cpts, genf[pps_index].control); -if (neg_adj) - estf_ctrl_val &= ~BIT (1 ); -else - estf_ctrl_val |=BIT (1 ); - -/* GenF PPM will do correction using cpts refclk tick which is -* (cpts->ts_add_val + 1) ns, so GenF length PPM adj period -* need to be corrected. -*/ - pps_adj_period = adj_period * (cpts->ts_add_val +1 ); - estf_ppm_hi =upper_32_bits (pps_adj_period) &0x3FF ; - estf_ppm_low =lower_32_bits (pps_adj_period); +/* am65_cpts_perout_enable_hw() sets pps_index in genf_enable */ + estf_ctrl_val = genf_ctrl_val[pps_index]; + estf_ppm_hi = genf_ppm_hi; + estf_ppm_low = genf_ppm_low; }spin_lock_irqsave (&cpts->lock, flags);
@@ -500,10 +518,13 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)am65_cpts_write32 (cpts, ppm_hi, ts_ppm_hi);am65_cpts_write32 (cpts, ppm_low, ts_ppm_low); -if (cpts->pps_enabled) { -am65_cpts_write32 (cpts, estf_ctrl_val, genf[pps_index].control); -am65_cpts_write32 (cpts, estf_ppm_hi, genf[pps_index].ppm_hi); -am65_cpts_write32 (cpts, estf_ppm_low, genf[pps_index].ppm_low); +for (i =0 ; i <AM65_CPTS_GENF_MAX_NUM ; i++) { +if (cpts->genf_enable &BIT (i)) { +am65_cpts_write32 (cpts, genf_ctrl_val[i], + genf[i].control); +am65_cpts_write32 (cpts, genf_ppm_hi, genf[i].ppm_hi); +am65_cpts_write32 (cpts, genf_ppm_low, genf[i].ppm_low); + } }for (i =0 ; i <AM65_CPTS_ESTF_MAX_NUM ; i++) {
@@ -513,7 +534,6 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)am65_cpts_write32 (cpts, estf_ppm_low, estf[i].ppm_low); } } -/* All GenF/EstF can be updated here the same way */ spin_unlock_irqrestore (&cpts->lock, flags);mutex_unlock (&cpts->ptp_clk_lock);
@@ -679,9 +699,12 @@ static void am65_cpts_perout_enable_hw(struct am65_cpts *cpts, val =lower_32_bits (cycles);am65_cpts_write32 (cpts, val, genf[req->index].length); -am65_cpts_write32 (cpts,0 , genf[req->index].control); -am65_cpts_write32 (cpts,0 , genf[req->index].ppm_hi); -am65_cpts_write32 (cpts,0 , genf[req->index].ppm_low); +am65_cpts_write32 (cpts, cpts->genf_neg_adj ?0 :BIT (1 ), + genf[req->index].control); +am65_cpts_write32 (cpts, cpts->genf_ppm_hi, + genf[req->index].ppm_hi); +am65_cpts_write32 (cpts, cpts->genf_ppm_low, + genf[req->index].ppm_low); cpts->genf_enable |=BIT (req->index); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 201/816 isofs: handle Rock Ridge long-form dates before 1900
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 0cbfc16fe49629f5c1fc3628405661c2b938ec61 ]
iso_date() stores the year relative to 1900 and rejects negative values. Rock Ridge LONG_FORM timestamps encode calendar years from 1 to 9999, so valid years before 1900 are returned as seconds since the Unix epoch equal to zero instead of their recorded dates. For example, an 1899 timestamp on an image produced by xorriso is reported as 1970 by stat, and cp -p preserves that incorrect time.
Use the calendar year for both timestamp formats and pass it directly to mktime64(). Keep the epoch fallback for year zero, while allowing valid long-form years before 1900. Short-form dates are unchanged.
--- fs/isofs/util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/isofs/util.c +4 -4
@@ -25,7 +25,7 @@ struct timespec64 iso_date(u8 *p, int flags) year = (p[0 ] -'0' ) *1000 + (p[1 ] -'0' ) *100 + (p[2 ] -'0' ) *10 + - (p[3 ] -'0' ) -1900 ; + (p[3 ] -'0' ); month = ((p[4 ] -'0' ) *10 + (p[5 ] -'0' )); day = ((p[6 ] -'0' ) *10 + (p[7 ] -'0' )); hour = ((p[8 ] -'0' ) *10 + (p[9 ] -'0' ));
@@ -34,7 +34,7 @@ struct timespec64 iso_date(u8 *p, int flags) ts.tv_nsec = ((p[14 ] -'0' ) *10 + (p[15 ] -'0' )) *10000000 ; tz = p[16 ]; }else { - year = p[0 ]; + year = p[0 ] +1900 ; month = p[1 ]; day = p[2 ]; hour = p[3 ];
@@ -45,10 +45,10 @@ struct timespec64 iso_date(u8 *p, int flags) tz = flags &ISO_DATE_HIGH_SIERRA ?0 : p[6 ]; } -if (year <0 ) { +if (year <1 ) { ts.tv_sec =0 ; }else { - ts.tv_sec =mktime64 (year+1900 , month, day, hour, minute, second); + ts.tv_sec =mktime64 (year, month, day, hour, minute, second);/* sign extend */ if (tz &0x80 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 202/816 tcp: Fix dup-ack detection on non-SACK bidirectional data transfer.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
[ Upstream commit 11140c51df12e594d6bf2c8d2af5dec63b0219ac ]
When receiving a pure ack from a peer that also sends data, we can have SEG.SEQ > SND.WL1, even though the segment contains no data. This makes tcp_may_update_window() return true (because of the "after(ack_seq, tp->snd_wl1)" condition), and tcp_ack_update_window() then adds FLAG_WIN_UPDATE to the segment set of flags, even when there's no window update.
Since FLAG_WIN_UPDATE prevents the segment from being considered as dup-ack (as it's part of FLAG_NOT_DUP), this can inhibit fast retransmit on non-SACK connections, making recovery very slow as it now entirely relies on RTO.
The "DUPLICATE ACKNOWLEDGMENT" definition of RFC 5681, section 2, says that lack of window update is a necessary condition for a dup ack:
"(e) the advertised window in the incoming acknowledgment equals the advertised window in the last incoming acknowledgment.". Spurious window updates can thus prevent dup ack detection and, in the end, fast retransmit.
Avoid this scenario by setting FLAG_WIN_UPDATE only when a window update actually occurs. Pure acks with SEG.SEQ > SND.WL1 can now be detected as dup-ack and trigger fast retransmission.
Also, stop setting FLAG_WIN_UPDATE in tcp_ack()'s header prediction path. One of the conditions for header prediction to happen is that received segments don't trigger a window update. This flag update was thus wrong to begin with. Now that tcp_ack_update_window() sets FLAG_WIN_UPDATE only if a window update actually occurred, we need the header prediction path to stop reporting spurious window updates too. Otherwise BPF programs would get inconsistent window update information (CA_ACK_WIN_UPDATE) between fast an slow paths.
Finally, add FLAG_SND_UNA_ADVANCED to the definition of FLAG_NOT_DUP. This is necessary for the case where an incoming segment acknowledges less than a full segment of the retransmit queue. Such segments were not considered dubious by tcp_ack_is_dubious() because of the spurious FLAG_WIN_UPDATE flag, which prevented the segment from being seen as a duplicate ack. Now that FLAG_WIN_UPDATE doesn't cover this scenario anymore, we need another way to mark these acks as non-duplicate. Adding FLAG_SND_UNA_ADVANCED to FLAG_NOT_DUP is the natural way of doing this, since, by definition, a segment advancing SND.UNA, even by a small amount, cannot be a duplicate ack.
A side effect of this patch is that repeated zero window acks received from peer can now be considered duplicate acks (because of the the "|| !win" condition in tcp_may_update_window()). Therefore, they can now trigger fast retransmission and fast recovery, including congestion window reduction, when the peer is stalled. This is RFC compliant and shouldn't have any negative effect.
Add packetdrill selftest. Before this patch, the 1001:2001 segment was retransmitted upon RTO, now it's sent right after reception of the third duplicate ack.
Thanks to Tom Williams for the investigation help and initial reproducer.
--- net/ipv4/tcp_input.c | 6 +-- .../tcp_bidir_fast_retransmit_nosack.pkt | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_bidir_fast_retransmit_nosack.pkt
net/ipv4/tcp_input.c +3 -3
@@ -104,7 +104,8 @@ int sysctl_tcp_max_orphans __read_mostly = NR_FILE;#define FLAG_DSACK_TLP 0x20000/* DSACK for tail loss probe */ #define FLAG_ACKED (FLAG_DATA_ACKED|FLAG_SYN_ACKED) -#define FLAG_NOT_DUP (FLAG_DATA|FLAG_WIN_UPDATE|FLAG_ACKED) +#define FLAG_NOT_DUP (FLAG_DATA|FLAG_WIN_UPDATE|FLAG_ACKED| \ + FLAG_SND_UNA_ADVANCED)#define FLAG_CA_ALERT (FLAG_DATA_SACKED|FLAG_ECE|FLAG_DSACKING_ACK)#define FLAG_FORWARD_PROGRESS (FLAG_ACKED|FLAG_DATA_SACKED)
@@ -3717,11 +3718,11 @@ static int tcp_ack_update_window(struct sock *sk, const struct sk_buff *skb, u32 nwin <<= tp->rx_opt.snd_wscale;if (tcp_may_update_window (tp, ack, ack_seq, nwin)) { - flag |=FLAG_WIN_UPDATE ;tcp_update_wl (tp, ack_seq);if (tp->snd_wnd != nwin) { tp->snd_wnd = nwin; + flag |=FLAG_WIN_UPDATE ;/* Note, it is the only place, where * fast path is recovered for sending TCP.
@@ -4036,7 +4037,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)*/ tcp_update_wl (tp, ack_seq);tcp_snd_una_update (tp, ack); - flag |=FLAG_WIN_UPDATE ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPHPACKS ); }else {
tools/testing/selftests/net/packetdrill/tcp_bidir_fast_retransmit_nosack.pkt new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 203/816 net: skbuff: reject zero MPLS TTL before decrementing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 24614e72df484ad50ecba98aaa88c7df2448c122 ]
skb_mpls_dec_ttl() decrements the u8 TTL before checking whether it expired. An incoming TTL of zero wraps to 255, causing the TC MPLS dec_ttl action to pass an expired packet instead of dropping it.
Reject a zero TTL before the decrement while preserving the existing behavior for TTL one and valid TTL values.
--- net/core/skbuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
@@ -6643,7 +6643,7 @@ int skb_mpls_dec_ttl(struct sk_buff *skb) lse =be32_to_cpu (mpls_hdr (skb)->label_stack_entry); ttl = (lse &MPLS_LS_TTL_MASK ) >>MPLS_LS_TTL_SHIFT ; -if (!--ttl) +if (!ttl || !--ttl)return -EINVAL ; lse &= ~MPLS_LS_TTL_MASK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 204/816 PM: runtime: Fix check_flush_dependency warning from pm_runtime_remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhou Minqiang <[email protected]>
[ Upstream commit 1f65b45f0f16e1c80a68a5757c9556f78bb39f19 ]
When a WQ_MEM_RECLAIM workqueue (e.g. iscsi_ctrl) triggers device removal via device_del -> pm_runtime_remove, the unconditional flush_work inside pm_runtime_remove can trigger a check_flush_dependency warning:
CPU1: pm_wq worker CPU2: iscsi_ctrl wq
-------- --------
pm_runtime_work(starget) pm_runtime_remove(starget)
spin_lock_irq(&starget->lock) __pm_runtime_disable(starget, false)
request_pending = false spin_lock_irq(&starget->lock)
(blocked, CPU1 holds the lock)
rpm_suspend(starget, RPM_NOWAIT)
status = RPM_SUSPENDING
rpm_callback(cb, starget)
spin_unlock_irq(&starget->lock)
(acquires lock)
disable_depth 0→1
__pm_runtime_barrier():
request_pending == false
→ skip cancel_work_sync
status == RPM_SUSPENDING
→ enter wait_queue, sleep
spin_unlock_irq(&starget->lock)
cb(starget) → 0
spin_lock_irq(&starget->lock)
status = RPM_SUSPENDED
wake_up_all(&wait_queue)
(woken up, waiting for lock)
spin_unlock(&starget->lock) spin_lock_irq(&starget->lock)
status == RPM_SUSPENDED
spin_lock(&parent->lock) → exit wait_queue
rpm_idle(parent, RPM_ASYNC) barrier returns
spin_unlock(&parent->lock) flush_work(&starget->work)
spin_lock(&starget->lock) __flush_work(from_cancel=false)
spin_unlock_irq(&starget->lock) check_flush_dependency()
← WARNING!Replace flush_work with cancel_work_sync in pm_runtime_remove. cancel_work_sync internally calls __flush_work with from_cancel=true, which causes check_flush_dependency to return early before the warning. This preserves the use-after-free fix from commit 29ab76827761 ("PM: runtime: Fix a race condition related to device removal") without the warning.
--- drivers/base/power/runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/runtime.c +1 -1
@@ -1887,7 +1887,7 @@ void pm_runtime_reinit(struct device *dev)void pm_runtime_remove (struct device *dev) {__pm_runtime_disable (dev, false); -flush_work (&dev->power.work); +cancel_work_sync (&dev->power.work);pm_runtime_reinit (dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 205/816 ipv6: Flush exception route while replacing nexthop.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 9401b428b5d4dfe1fd5752973fd02b4e9cd05536 ]
The following creates a cyclic reference between IPv6 route and nexthop:
1. create a nexthop A
2. create a nexthop group w/ A
3. create an IPv6 route with the nexthop group
4. create an exception route w/ A
5. replace A with a new nexthop B in the nexthop group
6. remove the IPv6 route
7. replace B with A in the nexthop group
8. remove the nexthop group
Then, removing a device tied to the route gets stuck and triggers the splat below. [0]
At 5., fib6_nh_release_dsts() is called, but it does not flush exception routes, so the nexthop A continues to grab the IPv6 route reference.
nh_A->rt6i_exception_bucket[] -> rt6_ex->rt6i->from
At 6., fib6_purge_rt() calls rt6_flush_exceptions(), but it only purges exceptions tied to nexthop B. Also, the route is unlinked from the nexthop group by list_del_init(&rt->nh_list).
-> f6i->nh -> nhg->nh_entries[]
At 8., __remove_nexthop_fib() cannot find the IPv6 route, and remove_nexthop_group() calls list_del_init(&nhge->nh_list) to unlink the group from the nexthop A's nhe->grp_list.
nhg->nh_entries[] -> nh_A -> ... -> f6i
Here, the nexthop A is reachable from net->nexthop.devhash[], but remove_nexthop_from_groups() cannot find the nexthop group, leaking the whole chain.
Let's call fib6_nh_flush_exceptions() in fib6_nh_release_dsts().
[0]:unregister_netdevice: waiting for gre6 to become free. Usage count = 4ref_tracker: netdev@000000009652f190 has 1/3 users at
dst_alloc+0x14b/0x490
ip6_rt_cache_alloc+0x27b/0x670
__ip6_rt_update_pmtu+0x572/0x850
ip6_tnl_xmit+0x8c5/0x1b70
__gre6_xmit+0x7af/0xaa0
ip6gre_tunnel_xmit+0x685/0xdc0
dev_hard_start_xmit+0x204/0x5a0
__dev_queue_xmit+0xe8a/0x2550
ip6_finish_output+0x232/0x570
ip6_output+0x226/0x3b0
ip6_send_skb+0x133/0x250
rawv6_push_pending_frames+0x503/0x6f0
rawv6_sendmsg+0xdf0/0x1310
sock_sendmsg_nosec+0xde/0x130
__sys_sendto+0x27f/0x320
__x64_sys_sendto+0xd9/0xf0--- net/ipv6/route.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv6/route.c +4 -2
@@ -3721,9 +3721,10 @@ void fib6_nh_release(struct fib6_nh *fib6_nh) {struct rt6_exception_bucket *bucket; +fib6_nh_release_dsts (fib6_nh); +rcu_read_lock (); -fib6_nh_flush_exceptions (fib6_nh,NULL ); bucket =fib6_nh_get_excptn_bucket (fib6_nh,NULL );if (bucket) {rcu_assign_pointer (fib6_nh->rt6i_exception_bucket,NULL );
@@ -3732,7 +3733,6 @@ void fib6_nh_release(struct fib6_nh *fib6_nh)rcu_read_unlock (); -fib6_nh_release_dsts (fib6_nh);free_percpu (fib6_nh->rt6i_pcpu);fib_nh_common_release (&fib6_nh->nh_common);
@@ -3742,6 +3742,8 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh) {int cpu; +fib6_nh_flush_exceptions (fib6_nh,NULL ); +if (!fib6_nh->rt6i_pcpu)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 206/816 ipv4: Call rt_add_uncached_list() if !do_cache in ip_route_input_slow().
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 4019af3afd72864ec6abbfde2d76e416a64456c2 ]
Since the cited commit, ip_route_input_slow() could call rt_dst_alloc() with vrf in the local_input: path.
If res->fi != NULL and one of the following is true,
- a non-zero itag from fib_validate_source_reason() (realms/classid)
- RTN_BROADCAST with BC_FORWARDING enabled
do_cache is set to false.
Then, the route is not added to rt_uncached_list, so the route cannot be removed from rt_flush_dev().
If the route is cached in sk->sk_rx_dst, removing the vrf device gets stuck. [0]
Let's call rt_add_uncached_list() if !do_cache inip_route_input_slow().
[0]:unregister_netdevice: waiting for vrf0 to become free. Usage count = 2ref_tracker: netdev@000000008b304ac4 has 1/1 users at
dst_alloc+0x14b/0x490
ip_route_input_rcu+0x1540/0x2530
ip_route_input_noref+0x5a/0x90
ip_rcv_finish_core+0x4b0/0x1140
ip_rcv_finish+0xe6/0x190
ip_rcv+0x6c/0x130
__netif_receive_skb+0x121/0x300
process_backlog+0x2df/0x5e0
__napi_poll+0x8c/0x380
net_rx_action+0x43c/0xab0
handle_softirqs+0x19f/0x520
do_softirq+0x46/0x60
__local_bh_enable_ip+0x79/0x80
__dev_queue_xmit+0x1b0e/0x24c0
ip_finish_output2+0x8b2/0xcd0
ip_output+0xf2/0x1e0--- net/ipv4/route.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/route.c +2 -0
@@ -2441,6 +2441,8 @@ out: return err;if (unlikely (!rt_cache_route (nhc, rth)))rt_add_uncached_list (rth); + }else { +rt_add_uncached_list (rth); }skb_dst_set (skb, &rth->dst); err =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 207/816 inet: reduce inet_csk_clone_lock() indent level
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 55250b83b02aa5ffe602987adb2c05178c87ac63 ]
Return early from inet_csk_clone_lock() if the socket allocation failed, to reduce the indentation level.
Stable-dep-of: 8e069fd3fd39 ("tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()")
--- net/ipv4/inet_connection_sock.c | 50 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 23 deletions(-)
net/ipv4/inet_connection_sock.c +27 -23
@@ -1257,39 +1257,43 @@ struct sock *inet_csk_clone_lock(const struct sock *sk, const gfp_t priority) {struct sock *newsk =sk_clone_lock (sk, priority); +struct inet_connection_sock *newicsk; -if (newsk) { -struct inet_connection_sock *newicsk =inet_csk (newsk); +if (!newsk) +return NULL ; -inet_sk_set_state (newsk,TCP_SYN_RECV ); - newicsk->icsk_bind_hash =NULL ; - newicsk->icsk_bind2_hash =NULL ; + newicsk =inet_csk (newsk); -inet_sk (newsk)->inet_dport =inet_rsk (req)->ir_rmt_port; -inet_sk (newsk)->inet_num =inet_rsk (req)->ir_num; -inet_sk (newsk)->inet_sport =htons (inet_rsk (req)->ir_num); +inet_sk_set_state (newsk,TCP_SYN_RECV ); + newicsk->icsk_bind_hash =NULL ; + newicsk->icsk_bind2_hash =NULL ; -/* listeners have SOCK_RCU_FREE, not the children */ -sock_reset_flag (newsk,SOCK_RCU_FREE ); +inet_sk (newsk)->inet_dport =inet_rsk (req)->ir_rmt_port; +inet_sk (newsk)->inet_num =inet_rsk (req)->ir_num; +inet_sk (newsk)->inet_sport =htons (inet_rsk (req)->ir_num); -inet_sk (newsk)->mc_list =NULL ; +/* listeners have SOCK_RCU_FREE, not the children */ +sock_reset_flag (newsk,SOCK_RCU_FREE ); - newsk->sk_mark =inet_rsk (req)->ir_mark; -atomic64_set (&newsk->sk_cookie, -atomic64_read (&inet_rsk (req)->ir_cookie)); +inet_sk (newsk)->mc_list =NULL ; - newicsk->icsk_retransmits =0 ; - newicsk->icsk_backoff =0 ; - newicsk->icsk_probes_out =0 ; - newicsk->icsk_probes_tstamp =0 ; + newsk->sk_mark =inet_rsk (req)->ir_mark; +atomic64_set (&newsk->sk_cookie, +atomic64_read (&inet_rsk (req)->ir_cookie)); -/* Deinitialize accept_queue to trap illegal accesses. */ -memset (&newicsk->icsk_accept_queue,0 ,sizeof (newicsk->icsk_accept_queue)); + newicsk->icsk_retransmits =0 ; + newicsk->icsk_backoff =0 ; + newicsk->icsk_probes_out =0 ; + newicsk->icsk_probes_tstamp =0 ; -inet_clone_ulp (req, newsk, priority); +/* Deinitialize accept_queue to trap illegal accesses. */ +memset (&newicsk->icsk_accept_queue,0 , +sizeof (newicsk->icsk_accept_queue)); + +inet_clone_ulp (req, newsk, priority); + +security_inet_csk_clone (newsk, req); -security_inet_csk_clone (newsk, req); - }return newsk; }EXPORT_SYMBOL_GPL (inet_csk_clone_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 208/816 inet: consolidate inet_csk_clone_lock()
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 a3a128f611a965fddf8a02dd45716f96e0738e00 ]
Current inet_sock_set_state trace from inet_csk_clone_lock() is missing many details :
... sock:inet_sock_set_state: family=AF_INET6 protocol=IPPROTO_TCP \
sport=4901 dport=0 \
saddr=127.0.0.6 daddr=0.0.0.0 \
saddrv6=:: daddrv6=:: \
oldstate=TCP_LISTEN newstate=TCP_SYN_RECVOnly the sport gives the listener port, no other parts of the n-tuple are correct.
In this patch, I initialize relevant fields of the new socket before calling inet_sk_set_state(newsk, TCP_SYN_RECV).
We now have a trace including all the source/destination bits.
... sock:inet_sock_set_state: family=AF_INET6 protocol=IPPROTO_TCP \
sport=4901 dport=47648 \
saddr=127.0.0.6 daddr=127.0.0.6 \
saddrv6=2002:a05:6830:1f85:: daddrv6=2001:4860:f803:65::3 \
oldstate=TCP_LISTEN newstate=TCP_SYN_RECVStable-dep-of: 8e069fd3fd39 ("tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()")
--- net/dccp/ipv4.c | 3 --- net/dccp/ipv6.c | 9 +++------ net/ipv4/inet_connection_sock.c | 24 ++++++++++++++++++++---- net/ipv4/tcp_ipv4.c | 4 ---- net/ipv6/tcp_ipv6.c | 8 ++------ 5 files changed, 25 insertions(+), 23 deletions(-)
net/dccp/ipv4.c +0 -3
@@ -427,9 +427,6 @@ struct sock *dccp_v4_request_recv_sock(const struct sock *sk, newinet =inet_sk (newsk); ireq =inet_rsk (req); -sk_daddr_set (newsk, ireq->ir_rmt_addr); -sk_rcv_saddr_set (newsk, ireq->ir_loc_addr); - newinet->inet_saddr = ireq->ir_loc_addr;RCU_INIT_POINTER (newinet->inet_opt,rcu_dereference (ireq->ireq_opt)); newinet->mc_index =inet_iif (skb); newinet->mc_ttl =ip_hdr (skb)->ttl;
net/dccp/ipv6.c +3 -6
@@ -365,6 +365,9 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb) ireq =inet_rsk (req); ireq->ir_v6_rmt_addr =ipv6_hdr (skb)->saddr; ireq->ir_v6_loc_addr =ipv6_hdr (skb)->daddr; + ireq->ir_rmt_addr =LOOPBACK4_IPV6 ; + ireq->ir_loc_addr =LOOPBACK4_IPV6 ; + ireq->ireq_family =AF_INET6 ; ireq->ir_mark =inet_request_mark (sk, skb);
@@ -507,10 +510,7 @@ static struct sock *dccp_v6_request_recv_sock(const struct sock *sk,memcpy (newnp, np,sizeof (struct ipv6_pinfo )); - newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr; newnp->saddr = ireq->ir_v6_loc_addr; - newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr; - newsk->sk_bound_dev_if = ireq->ir_iif;/* Now IPv6 options...
@@ -549,9 +549,6 @@ static struct sock *dccp_v6_request_recv_sock(const struct sock *sk,dccp_sync_mss (newsk,dst_mtu (dst)); - newinet->inet_daddr = newinet->inet_saddr =LOOPBACK4_IPV6 ; - newinet->inet_rcv_saddr =LOOPBACK4_IPV6 ; -if (__inet_inherit_port (sk, newsk) <0 ) {inet_csk_prepare_forced_close (newsk);dccp_done (newsk);
net/ipv4/inet_connection_sock.c +20 -4
@@ -1258,19 +1258,33 @@ struct sock *inet_csk_clone_lock(const struct sock *sk, {struct sock *newsk =sk_clone_lock (sk, priority);struct inet_connection_sock *newicsk; +struct inet_request_sock *ireq; +struct inet_sock *newinet;if (!newsk)return NULL ; newicsk =inet_csk (newsk); + newinet =inet_sk (newsk); + ireq =inet_rsk (req); -inet_sk_set_state (newsk,TCP_SYN_RECV ); newicsk->icsk_bind_hash =NULL ; newicsk->icsk_bind2_hash =NULL ; -inet_sk (newsk)->inet_dport =inet_rsk (req)->ir_rmt_port; -inet_sk (newsk)->inet_num =inet_rsk (req)->ir_num; -inet_sk (newsk)->inet_sport =htons (inet_rsk (req)->ir_num); + newinet->inet_dport = ireq->ir_rmt_port; + newinet->inet_num = ireq->ir_num; + newinet->inet_sport =htons (ireq->ir_num); + + newsk->sk_bound_dev_if = ireq->ir_iif; + + newsk->sk_daddr = ireq->ir_rmt_addr; + newsk->sk_rcv_saddr = ireq->ir_loc_addr; + newinet->inet_saddr = ireq->ir_loc_addr; + +#if IS_ENABLED (CONFIG_IPV6 ) + newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr; + newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr; +#endif /* listeners have SOCK_RCU_FREE, not the children */ sock_reset_flag (newsk,SOCK_RCU_FREE );
@@ -1290,6 +1304,8 @@ struct sock *inet_csk_clone_lock(const struct sock *sk,memset (&newicsk->icsk_accept_queue,0 ,sizeof (newicsk->icsk_accept_queue)); +inet_sk_set_state (newsk,TCP_SYN_RECV ); +inet_clone_ulp (req, newsk, priority);security_inet_csk_clone (newsk, req);
net/ipv4/tcp_ipv4.c +0 -4
@@ -1770,10 +1770,6 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, newtp =tcp_sk (newsk); newinet =inet_sk (newsk); ireq =inet_rsk (req); -sk_daddr_set (newsk, ireq->ir_rmt_addr); -sk_rcv_saddr_set (newsk, ireq->ir_loc_addr); - newsk->sk_bound_dev_if = ireq->ir_iif; - newinet->inet_saddr = ireq->ir_loc_addr; inet_opt =rcu_dereference (ireq->ireq_opt);RCU_INIT_POINTER (newinet->inet_opt, inet_opt); newinet->mc_index =inet_iif (skb);
net/ipv6/tcp_ipv6.c +2 -6
@@ -798,6 +798,8 @@ static void tcp_v6_init_req(struct request_sock *req, ireq->ir_v6_rmt_addr =ipv6_hdr (skb)->saddr; ireq->ir_v6_loc_addr =ipv6_hdr (skb)->daddr; + ireq->ir_rmt_addr =LOOPBACK4_IPV6 ; + ireq->ir_loc_addr =LOOPBACK4_IPV6 ;/* So that link locals have meaning */ if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
@@ -1439,10 +1441,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *ip6_dst_store (newsk, dst,NULL , false); - newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr; newnp->saddr = ireq->ir_v6_loc_addr; - newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr; - newsk->sk_bound_dev_if = ireq->ir_iif;/* Now IPv6 options...
@@ -1493,9 +1492,6 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *tcp_initialize_rcv_mss (newsk); - newinet->inet_daddr = newinet->inet_saddr =LOOPBACK4_IPV6 ; - newinet->inet_rcv_saddr =LOOPBACK4_IPV6 ; -#ifdef CONFIG_TCP_MD5SIG l3index =l3mdev_master_ifindex_by_index (sock_net (sk), ireq->ir_iif);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 209/816 tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()
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 8e069fd3fd396b89af417e50b359bc9892dd41cd ]
When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.
Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:
BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582) Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076 Call Trace: <IRQ> tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582) tcp_rtx_synack (net/ipv4/tcp_output.c:4719) tcp_check_req (net/ipv4/tcp_minisocks.c:762) tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826) ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479) ip6_input_finish (net/ipv6/ip6_input.c:534) ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545) ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351) Freed by task 5074 on cpu 0 at 15.412249s: kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757) tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528) tcp_check_req (net/ipv4/tcp_minisocks.c:934) tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826) ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479) ip6_input_finish (net/ipv6/ip6_input.c:534)
Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.
The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().
Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.
As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.
--- include/linux/tcp.h | 3 +++ net/ipv6/tcp_ipv6.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/tcp.h +3 -0
@@ -171,6 +171,9 @@ struct tcp_request_sock {u8 ao_rcv_next;bool used_tcp_ao;#endif +#if IS_ENABLED (CONFIG_IPV6 ) +__be32 syn_flowlabel; +#endif };static inline struct tcp_request_sock *tcp_rsk (const struct request_sock *req)
net/ipv6/tcp_ipv6.c +3 -2
@@ -546,8 +546,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst, &ireq->ir_v6_rmt_addr); fl6->daddr = ireq->ir_v6_rmt_addr; -if (inet6_test_bit (REPFLOW , sk) && ireq->pktopts) - fl6->flowlabel =ip6_flowlabel (ipv6_hdr (ireq->pktopts)); +if (inet6_test_bit (REPFLOW , sk)) + fl6->flowlabel =tcp_rsk (req)->syn_flowlabel; tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ? (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
@@ -800,6 +800,7 @@ static void tcp_v6_init_req(struct request_sock *req, ireq->ir_v6_loc_addr =ipv6_hdr (skb)->daddr; ireq->ir_rmt_addr =LOOPBACK4_IPV6 ; ireq->ir_loc_addr =LOOPBACK4_IPV6 ; +tcp_rsk (req)->syn_flowlabel =ip6_flowlabel (ipv6_hdr (skb));/* So that link locals have meaning */ if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 210/816 drm/amd/pm: track BACO state in the SMU v11 ArmD3 sequence
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit a26ec190925733dd205507493e936e59dbcd2b19 ]
On Navi1x/Sienna Cichlid with runtime PM, when the audio function is enabled, BACO entry and exit are delegated to PMFW by sending SMU_MSG_ArmD3 instead of going through smu_v11_0_baco_set_state(). Unlike the v13/v14/v15 helpers, smu_v11_0_baco_set_armd3_sequence() does not update smu_baco->state, so the driver keeps reporting SMU_BACO_STATE_EXIT while the ASIC is armed for / sitting in BACO.
At runtime resume amdgpu_device_baco_exit() checks amdgpu_device_supports_baco(), which ends up in smu_v11_0_get_bamaco_support(). Since the state never reads ENTER, the "already in BACO" shortcut is skipped and the live BACO feature bit is consulted instead. PMFW clears that bit once ArmD3(BACO) is armed, so the check reports "supported but not enabled", the exit fails with -ENOTSUPP and the ULPS ArmD3 message is never sent. The runtime resume caller ignores the error, and a later secondary bus reset leaves the device unreachable. This shows up on a Navi 23 being handed from amdgpu to vfio-pci:
baco_enter: in_runpm=1 audio_enabled=1 armd3=1 baco_state=1 ret=0
bamaco: state=1 ... feat supported=1 enabled=0 in_runpm=1
baco_exit: supports=0 ...
runtime resume: baco_exit ret=-524
Update smu_baco->state in the helper, mirroring the v13 implementation, so the capability check short-circuits while in BACO.
--- .../gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +19 -1
@@ -1549,7 +1549,25 @@ int smu_v11_0_set_azalia_d3_pme(struct smu_context *smu)int smu_v11_0_baco_set_armd3_sequence (struct smu_context *smu,enum smu_baco_seq baco_seq) { -return smu_cmn_send_smc_msg_with_param (smu, SMU_MSG_ArmD3, baco_seq,NULL ); +struct smu_baco_context *smu_baco = &smu->smu_baco; +int ret; + + ret =smu_cmn_send_smc_msg_with_param (smu, SMU_MSG_ArmD3, baco_seq,NULL ); +if (ret) +return ret; + +/* +* PMFW owns the BACO transition once armed, so keep the driver's view +* in sync. Otherwise smu_v11_0_get_bamaco_support() falls back to the +* live BACO feature bit, which PMFW clears when armed, and the runtime +* resume wrongly concludes BACO is unsupported and skips the exit. +*/ +if (baco_seq ==BACO_SEQ_BAMACO || baco_seq ==BACO_SEQ_BACO ) + smu_baco->state =SMU_BACO_STATE_ENTER ; +else + smu_baco->state =SMU_BACO_STATE_EXIT ; + +return 0 ; }int smu_v11_0_get_bamaco_support (struct smu_context *smu)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 211/816 firmware: cs_dsp: Fix memory leak on cs_dsp_power_up() error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Richard Fitzgerald <[email protected]>
[ Upstream commit 39d31f76ad1b12f1b5e6ef4c15f89e6b3c3f603a ]
If cs_dsp_power_up() fails on or after cs_dsp_load() mark the controls disabled and free the alg regions.
--- drivers/firmware/cirrus/cs_dsp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/firmware/cirrus/cs_dsp.c +6 -0
@@ -2706,6 +2706,7 @@ int cs_dsp_power_up(struct cs_dsp *dsp, const struct firmware *coeff_firmware, const char *coeff_filename, const char *fw_name) { + struct cs_dsp_coeff_ctl *ctl;int ret;mutex_lock (&dsp->pwr_lock);
@@ -2750,6 +2751,11 @@ int cs_dsp_power_up(struct cs_dsp *dsp,return 0 ; err_ena: +list_for_each_entry (ctl, &dsp->ctl_list, list) + ctl->enabled =0 ; + +cs_dsp_free_alg_regions (dsp); +if (dsp->ops->disable_core) dsp->ops->disable_core (dsp); err_mem:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 212/816 ACPI: scan: Print the offline failure message in acpi_bus_offline()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit b9ea1e921c2721546f53270cffdc6866e20576dd ]
When a physical node of an ACPI device being hot-removed cannot be offlined, acpi_bus_offline() passes the physical device back to acpi_scan_try_to_offline() through ret_p and the latter prints "Offline failed." for it after the namespace walk. By then physical_node_lock is not held anymore, so the device may have been unbound from its ACPI companion and freed in the meantime.
Print the message in acpi_bus_offline() when device_offline() fails in the second pass, while physical_node_lock keeps the device bound to its ACPI companion and so the reference taken by acpi_bind_one() is still held. acpi_scan_try_to_offline() only needs to know that something could not be offlined, so pass the ACPI device back through ret_p instead, like in the "Offline disabled." case.
--- drivers/acpi/scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/scan.c +2 -2
@@ -164,8 +164,9 @@ static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,if (ret >=0 ) { pn->put_online = !ret; }else { - *ret_p = pn->dev; + *ret_p = &device->dev;if (second_pass) { +dev_warn (pn->dev,"Offline failed.\n" ); status =AE_ERROR ;break ; }
@@ -234,7 +235,6 @@ static int acpi_scan_try_to_offline(struct acpi_device *device) (void **)&errdev);if (errdev) { -dev_warn (errdev,"Offline failed.\n" );acpi_bus_online (handle,0 ,NULL ,NULL ); acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, acpi_bus_online,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 213/816 ACPI: scan: Do not hold physical_node_lock across device_offline() and device_online()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 17654aa629cba9a70e31cc1b7226a4fc1a1c801a ]
acpi_bus_offline() and acpi_bus_online() hold the physical_node_lock of the ACPI device being hot-removed while they call device_offline() and device_online() for its physical nodes. Offlining a CPU this way takes cpu_add_remove_lock and the CPU hotplug lock under physical_node_lock, and lockdep connects that to the uevent attribute of platform devices, whose store method takes physical_node_lock in acpi_primary_dev_companion():
physical_node_lock (acpi_bus_offline())
-> cpu_add_remove_lock -> cpu_hotplug_lock
-> cpuhp_state-down (mce_cpu_pre_down() unregistering a device)
-> device_links_lock (device_links_purge())
-> kn->active of a uevent attribute (device link unregistration)
-> physical_node_lock (uevent_store() -> acpi_companion_match())syzbot has reported this cycle twice. The uevent attribute waited for in the link unregistration is the device link's, not a platform device's, and the physical_node_lock taken at the end is that of the platform device's ACPI companion, not of the processor being ejected, so lockdep only connects them because they share lock classes and this is unlikely to deadlock. However, lockdep turns itself off after reporting it.
It can be reproduced in a QEMU guest by writing to the uevent attribute of an ACPI-enumerated platform device, reading the uevent attribute of a device link while the link is removed, offlining a CPU and ejecting one through sysfs.
physical_node_lock protects the list of physical nodes. Since acpi_unbind_one() blocks on it, holding it also keeps device_offline() and device_online() from running in parallel with whatever happens to a device after it has been unbound from its ACPI companion, but that is not
necessary: a reference to each device is held while the lock is dropped, and the removal of the devices that can actually be taken offline here (CPUs, memory blocks and containers) is serialized by the device hotplug lock or acpi_scan_lock, both of which acpi_device_hotplug() holds throughout.
So drop physical_node_lock around device_offline() and device_online(). Mark the nodes to offline with a new offline_pending flag, hold a reference to each device while the lock is dropped, and look its node up again afterwards to record whether it needs to be put back online, because it may have been unbound in the meantime. Physical nodes added while the lock is not held are not offlined by the current pass, which is no different from adding them right after it.
Since acpi_container_offline() no longer runs under the container's physical_node_lock, the nesting annotation added to acpi_scan_is_offline() by commit 4c533c801d1c ("ACPI / scan: Annotate physical_node_lock in acpi_scan_is_offline()") is not needed anymore, so drop it.
--- drivers/acpi/scan.c | 106 +++++++++++++++++++++++++++++++++------- include/acpi/acpi_bus.h | 1 + 2 files changed, 88 insertions(+), 19 deletions(-)
drivers/acpi/scan.c +87 -19
@@ -113,11 +113,7 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)bool offline = true;char *envp[] = {"EVENT=offline" ,NULL }; -/* -* acpi_container_offline() calls this for all of the container's -* children under the container's physical_node_lock lock. -*/ -mutex_lock_nested (&adev->physical_node_lock,SINGLE_DEPTH_NESTING ); +mutex_lock (&adev->physical_node_lock);list_for_each_entry (pn, &adev->physical_node_list, node)if (device_supports_offline (pn->dev) && !pn->dev->offline) {
@@ -132,6 +128,59 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent)return offline; } +static struct acpi_device_physical_node * +acpi_find_physical_node (struct acpi_device *adev,struct device *dev) +{ +struct acpi_device_physical_node *pn; + +lockdep_assert_held (&adev->physical_node_lock); + +list_for_each_entry (pn, &adev->physical_node_list, node) +if (pn->dev == dev) +return pn; + +return NULL ; +} + +static struct device *acpi_next_offline_pending (struct acpi_device *adev) +{ +struct acpi_device_physical_node *pn; + +lockdep_assert_held (&adev->physical_node_lock); + +/* +* Find the first physical node that is still to be offlined, clear its +* offline_pending flag and return its device with a reference held. +*/ +list_for_each_entry (pn, &adev->physical_node_list, node) +if (pn->offline_pending) { + pn->offline_pending = false; +return get_device (pn->dev); + } + +return NULL ; +} + +static struct device *acpi_next_put_online (struct acpi_device *adev) +{ +struct acpi_device_physical_node *pn; + +lockdep_assert_held (&adev->physical_node_lock); + +/* +* Find the first physical node that has been offlined by +* acpi_bus_offline(), clear its put_online flag and return its device +* with a reference held. +*/ +list_for_each_entry (pn, &adev->physical_node_list, node) +if (pn->put_online) { + pn->put_online = false; +return get_device (pn->dev); + } + +return NULL ; +} +static acpi_status acpi_bus_offline (acpi_handle handle,u32 lvl,void *data,void **ret_p) {
@@ -139,6 +188,7 @@ static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,struct acpi_device_physical_node *pn;bool second_pass = (bool )data;acpi_status status =AE_OK ; +struct device *dev;if (!device)return AE_OK ;
@@ -151,26 +201,43 @@ static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,mutex_lock (&device->physical_node_lock);list_for_each_entry (pn, &device->physical_node_list, node) { -int ret; -if (second_pass) {/* Skip devices offlined by the first pass. */ -if (pn->put_online) -continue ; + pn->offline_pending = !pn->put_online; }else { + pn->offline_pending = true; pn->put_online = false; } - ret =device_offline (pn->dev); + } + +/* +* Drop physical_node_lock around device_offline(), because the latter +* acquires locks, like the CPU hotplug ones, that must not nest under +* it. +*/ +while ((dev =acpi_next_offline_pending (device))) { +int ret; + +mutex_unlock (&device->physical_node_lock); + ret =device_offline (dev); +mutex_lock (&device->physical_node_lock); +if (ret >=0 ) { - pn->put_online = !ret; +/* The device may have been unbound in the meantime. */ + pn =acpi_find_physical_node (device, dev); +if (pn) + pn->put_online = !ret; }else { *ret_p = &device->dev;if (second_pass) { -dev_warn (pn->dev,"Offline failed.\n" ); +dev_warn (dev,"Offline failed.\n" ); status =AE_ERROR ; -break ; } } + +put_device (dev); +if (ACPI_FAILURE (status)) +break ; }mutex_unlock (&device->physical_node_lock);
@@ -182,18 +249,19 @@ static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data, void **ret_p) {struct acpi_device *device =acpi_fetch_acpi_dev (handle); -struct acpi_device_physical_node *pn; +struct device *dev;if (!device)return AE_OK ;mutex_lock (&device->physical_node_lock); -list_for_each_entry (pn, &device->physical_node_list, node) -if (pn->put_online) { -device_online (pn->dev); - pn->put_online = false; - } +while ((dev =acpi_next_put_online (device))) { +mutex_unlock (&device->physical_node_lock); +device_online (dev); +mutex_lock (&device->physical_node_lock); +put_device (dev); + }mutex_unlock (&device->physical_node_lock);
include/acpi/acpi_bus.h +1 -0
@@ -363,6 +363,7 @@ struct acpi_device_physical_node {struct device *dev;unsigned int node_id; bool put_online:1; + bool offline_pending:1; };struct acpi_device_properties {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 214/816 ASoC: wm_adsp: Prevent negative string length in wm_adsp_control_add()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Richard Fitzgerald <[email protected]>
[ Upstream commit 4d07af76ca41cc1a03240cd3b5f44dc428856214 ]
Check that avail does not become < 1 in wm_adsp_control_add(). This prevents overflows during subsequent operations.
The main aim is to trap a negative value in avail, but a zero length would mean that the control ends up without a name, so 1 is the smallest valid value.
--- sound/soc/codecs/wm_adsp.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/soc/codecs/wm_adsp.c +10 -0
@@ -43,6 +43,9 @@#define adsp_dbg (_dsp, fmt, ...) \ dev_dbg(_dsp->cs_dsp.dev, "%s: " fmt, _dsp->cs_dsp.name, ##__VA_ARGS__) +#define adsp_warn_once (_dsp, fmt, ...) \ + dev_warn_once(_dsp->cs_dsp.dev, "%s: " fmt, _dsp->cs_dsp.name, ##__VA_ARGS__) +#define compr_err (_obj, fmt, ...) \ adsp_err(_obj->dsp, "%s: " fmt, _obj->name ? _obj->name : "legacy", \ ##__VA_ARGS__)
@@ -627,6 +630,13 @@ int wm_adsp_control_add(struct cs_dsp_coeff_ctl *cs_ctl)if (dsp->component->name_prefix) avail -=strlen (dsp->component->name_prefix) +1 ; +if (avail <1 ) { +adsp_warn_once (dsp, +"%.*s: ALSA prefix too long: control not created\n" , + cs_ctl->subname_len, cs_ctl->subname); +return -EINVAL ; + } +/* Truncate the subname from the start if it is too long */ if (cs_ctl->subname_len > avail) skip = cs_ctl->subname_len - avail;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 215/816 Bluetooth: hci_conn: Fix SCO/eSCO Transport_Unit_Size for HCI data path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijun Hu <[email protected]>
[ Upstream commit 3efdadae3a252b14ca1f62b16e31a9aa7c5d30cf ]
Correct (Input|Output)_Transport_Unit_Size based on Core spec v6.3, Vol 4, Part E, 7.1.45:
"The Host shall set the Input_Transport_Unit_Size and
Output_Transport_Unit_Size to be equal. For HCI Host transport the Host shall set them to 0."
--- net/bluetooth/hci_conn.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/bluetooth/hci_conn.c +12 -6
@@ -331,8 +331,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data) cp.out_pcm_sample_payload_msb_pos =0 ; cp.in_data_path = conn->codec.data_path; cp.out_data_path = conn->codec.data_path; - cp.in_transport_unit_size =1 ; - cp.out_transport_unit_size =1 ; +if (conn->codec.data_path) { + cp.in_transport_unit_size =1 ; + cp.out_transport_unit_size =1 ; + }break ;case BT_CODEC_TRANSPARENT :
@@ -357,8 +359,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data) cp.out_pcm_sample_payload_msb_pos =0 ; cp.in_data_path = conn->codec.data_path; cp.out_data_path = conn->codec.data_path; - cp.in_transport_unit_size =1 ; - cp.out_transport_unit_size =1 ; +if (conn->codec.data_path) { + cp.in_transport_unit_size =1 ; + cp.out_transport_unit_size =1 ; + }break ;case BT_CODEC_CVSD :
@@ -388,8 +392,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data) cp.out_pcm_sample_payload_msb_pos =0 ; cp.in_data_path = conn->codec.data_path; cp.out_data_path = conn->codec.data_path; - cp.in_transport_unit_size =16 ; - cp.out_transport_unit_size =16 ; +if (conn->codec.data_path) { + cp.in_transport_unit_size =16 ; + cp.out_transport_unit_size =16 ; + }break ;default : goto unlock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 216/816 Bluetooth: L2CAP: Clear request identifiers on incoming LE connections
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
[ Upstream commit 15a80cc8263abd50132a05d1b06824de8e28abcb ]
Incoming LE and ECRED channels retain the peer's request identifier after an immediate response. The deferred LE response also leaves the identifier set, unlike the deferred ECRED response.
A later ECRED request can reuse that identifier and include an unrelated channel in its shared-response handling. That walk matches on the identifier alone, so an LE channel is selected too. If the old channel is closing, the checks can refuse the new connection. The check at request receipt rejects it with L2CAP_CR_LE_INVALID_PARAMS; the check before a deferred response returns L2CAP_CR_LE_AUTHORIZATION.
Store the identifier only when deferring the response, and clear it after sending the deferred LE response. Keep deferred ECRED identifiers until the shared response is sent, since a partially accepted group still needs them.
AI assistance was used.
--- net/bluetooth/l2cap_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +3 -2
@@ -3882,6 +3882,7 @@ void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan)l2cap_send_cmd (conn, chan->ident,L2CAP_LE_CONN_RSP ,sizeof (rsp), &rsp); + chan->ident =0 ; }static void l2cap_ecred_list_defer (struct l2cap_chan *chan,void *data)
@@ -5137,10 +5138,10 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,__set_chan_timer (chan, chan->ops->get_sndtimeo (chan)); - chan->ident = cmd->ident; chan->mode =L2CAP_MODE_LE_FLOWCTL ;if (test_bit (FLAG_DEFER_SETUP , &chan->flags)) { + chan->ident = cmd->ident;l2cap_state_change (chan,BT_CONNECT2 );/* The following result value is actually not defined * for LE CoC but we use it to let the function know
@@ -5370,10 +5371,10 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn,__set_chan_timer (chan, chan->ops->get_sndtimeo (chan)); - chan->ident = cmd->ident; chan->mode =L2CAP_MODE_EXT_FLOWCTL ;if (test_bit (FLAG_DEFER_SETUP , &chan->flags)) { + chan->ident = cmd->ident;l2cap_state_change (chan,BT_CONNECT2 ); defer = true; chan->ops->defer (chan);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 217/816 net: ethernet: bgmac: preserve forced 2.5 Gbps link speed
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit d4f3d2c04624854d27aa948cd7bfc9d946faaac5 ]
Northstar and Northstar Plus use a 2.5 Gbps internal link between the AMAC and the switch. BGMAC_FEAT_FORCE_SPEED_2500 makes bgmac_miiconfig() configure that speed, but bgmac_adjust_link() subsequently replaces it with the synthetic fixed PHY's 1 Gbps speed.
Use the forced speed when processing link changes so the MAC remains at 2.5 Gbps. Together with configuring the switch IMP port for its 2 Gbps mode, this eliminates the output queue discards that caused approximately 1000 TCP retransmissions per second during an iperf3 transmit test.
Restrict the platform forced-speed flag to Northstar Plus using the SoC compatible, since Hurricane2 shares the AMAC compatible. Other platform AMACs without a phy-handle must continue following the fixed PHY speed. The BCMA path already selects the flag only for the Northstar family.
--- drivers/net/ethernet/broadcom/bgmac-platform.c | 3 ++- drivers/net/ethernet/broadcom/bgmac.c | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +2 -1
@@ -243,7 +243,8 @@ static int bgmac_probe(struct platform_device *pdev) bgmac->phy_connect = platform_phy_connect; }else { bgmac->phy_connect = bgmac_phy_connect_direct; - bgmac->feature_flags |=BGMAC_FEAT_FORCE_SPEED_2500 ; +if (of_machine_is_compatible ("brcm,nsp" )) + bgmac->feature_flags |=BGMAC_FEAT_FORCE_SPEED_2500 ; }return bgmac_enet_probe (bgmac);
drivers/net/ethernet/broadcom/bgmac.c +6 -2
@@ -1429,11 +1429,15 @@ void bgmac_adjust_link(struct net_device *net_dev) {struct bgmac *bgmac =netdev_priv (net_dev);struct phy_device *phy_dev = net_dev->phydev; +int speed = phy_dev->speed;bool update = false; +if (bgmac->feature_flags &BGMAC_FEAT_FORCE_SPEED_2500 ) + speed =SPEED_2500 ; +if (phy_dev->link) { -if (phy_dev->speed != bgmac->mac_speed) { - bgmac->mac_speed = phy_dev->speed; +if (speed != bgmac->mac_speed) { + bgmac->mac_speed = speed; update = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 218/816 net: dsa: b53: restore the NSP IMP port 2 Gbps mode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 41af38324341df9d769641d6485abb67fd5209ed ]
The Northstar Plus IMP port uses the switch's proprietary 2 Gbps mode for its internal link to the AMAC. Its fixed-link description reports 1 Gbps, so applying that speed clears PORT_OVERRIDE_SPEED_2000M and leaves the two ends of the internal link configured at different speeds.
Force the 2 Gbps mode and flow control for BCM5301x and NSP CPU ports. The mismatch caused switch output queue discards on both copper and SerDes ports, with one discard for every TCP retransmission. With both ends restored to their high-speed modes, iperf3 reports no retransmissions.
--- drivers/net/dsa/b53/b53_common.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/dsa/b53/b53_common.c +9 -3
@@ -1654,9 +1654,15 @@ static void b53_phylink_mac_link_up(struct phylink_config *config, }if (mode ==MLO_AN_FIXED ) { -/* Force flow control on BCM5301x's CPU port */ -if (is5301x (dev) &&dsa_is_cpu_port (ds, port)) - tx_pause = rx_pause = true; +/* Force flow control and 2Gbits/sec on BCM5301x and NSP CPU +* ports +*/ +if ((is5301x (dev) || dev->chip_id ==BCM58XX_DEVICE_ID ) && +dsa_is_cpu_port (ds, port)) { + tx_pause = true; + rx_pause = true; + speed =2000 ; + }b53_force_port_config (dev, port, speed, duplex, tx_pause, rx_pause);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 219/816 Bluetooth: Fix not updating of hdev->commands[] after reset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit e00aa1a33f81a5e25b510f569ab9cb9f97eb41b9 ]
Read Local Supported Commands was only read once during the INIT/SETUP flow, but the supported commands bits may change at runtime, for example after a firmware change applied with vendor commands, so update hdev->commands[] every time the response is received.
--- net/bluetooth/hci_event.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/bluetooth/hci_event.c +1 -3
@@ -781,9 +781,7 @@ static u8 hci_cc_read_local_commands(struct hci_dev *hdev, void *data,if (rp->status)return rp->status; -if (hci_dev_test_flag (hdev,HCI_SETUP ) || -hci_dev_test_flag (hdev,HCI_CONFIG )) -memcpy (hdev->commands, rp->commands,sizeof (hdev->commands)); +memcpy (hdev->commands, rp->commands,sizeof (hdev->commands));return rp->status; }
Signature · 1 line
2.53.0