5.15.203-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 412/570 net/sched: sch_hfsc: fix divide-by-zero in rtsc_min()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 4576100b8cd03118267513cafacde164b498b322 ]
m2sm() converts a u32 slope to a u64 scaled value. For large inputs (e.g. m1=4000000000), the result can reach 2^32. rtsc_min() stores the difference of two such u64 values in a u32 variable dsm and uses it as a divisor. When the difference is exactly 2^32 the truncation yields zero, causing a divide-by-zero oops in the concave-curve intersection path:
Oops: divide error: 0000 RIP: 0010:rtsc_min (net/sched/sch_hfsc.c:601) Call Trace: init_ed (net/sched/sch_hfsc.c:629) hfsc_enqueue (net/sched/sch_hfsc.c:1569) [...]
Widen dsm to u64 and replace do_div() with div64_u64() so the full difference is preserved.
--- net/sched/sch_hfsc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/sched/sch_hfsc.c +2 -2
@@ -556,7 +556,7 @@ static void rtsc_min(struct runtime_sc *rtsc, struct internal_sc *isc, u64 x, u64 y) { u64 y1, y2, dx, dy; -u32 dsm; +u64 dsm;if (isc->sm1 <= isc->sm2) {/* service curve is convex */
@@ -599,7 +599,7 @@ rtsc_min(struct runtime_sc *rtsc, struct internal_sc *isc, u64 x, u64 y)*/ dx = (y1 - y) <<SM_SHIFT ; dsm = isc->sm1 - isc->sm2; -do_div (dx, dsm); + dx =div64_u64 (dx, dsm);/* * check if (x, y1) belongs to the 1st segment of rtsc. * if so, add the offset.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/570 ipv6: prevent possible UaF in addrconf_permanent_addr()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit fd63f185979b047fb22a0dfc6bd94d0cab6a6a70 ]
The mentioned helper try to warn the user about an exceptional condition, but the message is delivered too late, accessing the ipv6 after its possible deletion.
Reorder the statement to avoid the possible UaF; while at it, place the warning outside the idev->lock as it needs no protection.
--- net/ipv6/addrconf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv6/addrconf.c +3 -3
@@ -3547,12 +3547,12 @@ static void addrconf_permanent_addr(struct net *net, struct net_device *dev)if ((ifp->flags &IFA_F_PERMANENT ) &&fixup_permanent_addr (net, idev, ifp) <0 ) {write_unlock_bh (&idev->lock); -in6_ifa_hold (ifp); -ipv6_del_addr (ifp); -write_lock_bh (&idev->lock);net_info_ratelimited ("%s: Failed to add prefix route for address %pI6c; dropping\n" , idev->dev->name, &ifp->addr); +in6_ifa_hold (ifp); +ipv6_del_addr (ifp); +write_lock_bh (&idev->lock); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/570 net: sched: cls_api: fix tc_chain_fill_node to initialize tcm_info to zero to prevent an info-leak
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yochai Eisenrich <[email protected]>
[ Upstream commit e6e3eb5ee89ac4c163d46429391c889a1bb5e404 ]
When building netlink messages, tc_chain_fill_node() never initializes the tcm_info field of struct tcmsg. Since the allocation is not zeroed, kernel heap memory is leaked to userspace through this 4-byte field.
The fix simply zeroes tcm_info alongside the other fields that are already initialized.
--- net/sched/cls_api.c | 1 + 1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
@@ -2672,6 +2672,7 @@ static int tc_chain_fill_node(const struct tcf_proto_ops *tmplt_ops, tcm->tcm__pad1 =0 ; tcm->tcm__pad2 =0 ; tcm->tcm_handle =0 ; + tcm->tcm_info =0 ;if (block->q) { tcm->tcm_ifindex =qdisc_dev (block->q)->ifindex; tcm->tcm_parent = block->q->handle;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/570 NFC: pn533: bound the UART receive buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 30fe3f5f6494f827d812ff179f295a8e532709d6 ]
pn532_receive_buf() appends every incoming byte to dev->recv_skb and only resets the buffer after pn532_uart_rx_is_frame() recognizes a complete frame. A continuous stream of bytes without a valid PN532 frame header therefore keeps growing the skb until skb_put_u8() hits the tail limit.
Drop the accumulated partial frame once the fixed receive buffer is full so malformed UART traffic cannot grow the skb past PN532_UART_SKB_BUFF_LEN.
--- drivers/nfc/pn533/uart.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nfc/pn533/uart.c +3 -0
@@ -211,6 +211,9 @@ static int pn532_receive_buf(struct serdev_device *serdev,del_timer (&dev->cmd_timeout);for (i =0 ; i < count; i++) { +if (unlikely (!skb_tailroom (dev->recv_skb))) +skb_trim (dev->recv_skb,0 ); +skb_put_u8 (dev->recv_skb, *data++);if (!pn532_uart_rx_is_frame (dev->recv_skb))continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/570 net: xilinx: axienet: Correct BD length masks to match AXIDMA IP spec
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suraj Gupta <[email protected]>
[ Upstream commit 393e0b4f178ec7fce1141dacc3304e3607a92ee9 ]
The XAXIDMA_BD_CTRL_LENGTH_MASK and XAXIDMA_BD_STS_ACTUAL_LEN_MASK macros were defined as 0x007FFFFF (23 bits), but the AXI DMA IP product guide (PG021) specifies the buffer length field as bits 25:0 (26 bits). Update both masks to match the IP documentation.
In practice this had no functional impact, since Ethernet frames are far smaller than 2^23 bytes and the extra bits were always zero, but the masks should still reflect the hardware specification.
--- drivers/net/ethernet/xilinx/xilinx_axienet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -2
@@ -103,7 +103,7 @@#define XAXIDMA_BD_HAS_DRE_MASK 0xF00/* Whether has DRE mask */ #define XAXIDMA_BD_WORDLEN_MASK 0xFF/* Whether has DRE mask */ -#define XAXIDMA_BD_CTRL_LENGTH_MASK 0x007FFFFF/* Requested len */ +#define XAXIDMA_BD_CTRL_LENGTH_MASK GENMASK(25, 0)/* Requested len */ #define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000/* First tx packet */ #define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000/* Last tx packet */ #define XAXIDMA_BD_CTRL_ALL_MASK 0x0C000000/* All control bits */
@@ -129,7 +129,7 @@#define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000/* Last tx packet */ #define XAXIDMA_BD_CTRL_ALL_MASK 0x0C000000/* All control bits */ -#define XAXIDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF/* Actual len */ +#define XAXIDMA_BD_STS_ACTUAL_LEN_MASK GENMASK(25, 0)/* Actual len */ #define XAXIDMA_BD_STS_COMPLETE_MASK 0x80000000/* Completed */ #define XAXIDMA_BD_STS_DEC_ERR_MASK 0x40000000/* Decode error */ #define XAXIDMA_BD_STS_SLV_ERR_MASK 0x20000000/* Slave error */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/570 bpf: Fix regsafe() for pointers to packet
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit a8502a79e832b861e99218cbd2d8f4312d62e225 ]
In case rold->reg->range == BEYOND_PKT_END && rcur->reg->range == N regsafe() may return true which may lead to current state with valid packet range not being explored. Fix the bug.
--- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +6 -1
@@ -10599,8 +10599,13 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,* since someone could have accessed through (ptr - k), or * even done ptr -= k in a register, to get a safe access. */ -if (rold->range > rcur->range) +if (rold->range <0 || rcur->range <0 ) { +/* special case for [BEYOND|AT]_PKT_END */ +if (rold->range != rcur->range) +return false; + }else if (rold->range > rcur->range) {return false; + }/* If the offsets don't match, we can't trust our alignment; * nor can we be sure that we won't fall out of range. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/570 net: ipv6: flowlabel: defer exclusive option free until RCU teardown
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhengchuan Liang <[email protected]>
[ Upstream commit 9ca562bb8e66978b53028fa32b1a190708e6a091 ]
ip6fl_seq_show() walks the global flowlabel hash under the seq-file RCU read-side lock and prints fl->opt->opt_nflen when an option block is present.
Exclusive flowlabels currently free fl->opt as soon as fl->users drops to zero in fl_release(). However, the surrounding struct ip6_flowlabel remains visible in the global hash table until later garbage collection removes it and fl_free_rcu() finally tears it down.
A concurrent /proc/net/ip6_flowlabel reader can therefore race that early kfree() and dereference freed option state, triggering a crash in ip6fl_seq_show().
Fix this by keeping fl->opt alive until fl_free_rcu(). That matches the lifetime already required for the enclosing flowlabel while readers can still reach it under RCU.
--- net/ipv6/ip6_flowlabel.c | 5 ----- 1 file changed, 5 deletions(-)
net/ipv6/ip6_flowlabel.c +0 -5
@@ -133,11 +133,6 @@ static void fl_release(struct ip6_flowlabel *fl)if (time_after (ttd, fl->expires)) fl->expires = ttd; ttd = fl->expires; -if (fl->opt && fl->share ==IPV6_FL_S_EXCL ) { -struct ipv6_txoptions *opt = fl->opt; - fl->opt =NULL ; -kfree (opt); - }if (!timer_pending (&ip6_fl_gc_timer) ||time_after (ip6_fl_gc_timer.expires, ttd))mod_timer (&ip6_fl_gc_timer, ttd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/570 netfilter: flowtable: strictly check for maximum number of actions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 76522fcdbc3a02b568f5d957f7e66fc194abb893 ]
The maximum number of flowtable hardware offload actions in IPv6 is:
* ethernet mangling (4 payload actions, 2 for each ethernet address)
* SNAT (4 payload actions)
* DNAT (4 payload actions)
* Double VLAN (4 vlan actions, 2 for popping vlan, and 2 for pushing) for QinQ.
* Redirect (1 action)
Which makes 17, while the maximum is 16. But act_ct supports for tunnels actions too. Note that payload action operates at 32-bit word level, so mangling an IPv6 address takes 4 payload actions.
Update flow_action_entry_next() calls to check for the maximum number of supported actions.
While at it, rise the maximum number of actions per flow from 16 to 24 so this works fine with IPv6 setups.
--- net/netfilter/nf_flow_table_offload.c | 196 +++++++++++++++++--------- 1 file changed, 130 insertions(+), 66 deletions(-)
net/netfilter/nf_flow_table_offload.c +130 -66
@@ -13,6 +13,8 @@#include <net/netfilter/nf_conntrack_core.h> #include <net/netfilter/nf_conntrack_tuple.h> +#define NF_FLOW_RULE_ACTION_MAX 24 +static struct workqueue_struct *nf_flow_offload_add_wq;static struct workqueue_struct *nf_flow_offload_del_wq;static struct workqueue_struct *nf_flow_offload_stats_wq;
@@ -204,7 +206,12 @@ static void flow_offload_mangle(struct flow_action_entry *entry,static inline struct flow_action_entry *flow_action_entry_next (struct nf_flow_rule *flow_rule) { -int i = flow_rule->rule->action.num_entries++; +int i; + +if (unlikely (flow_rule->rule->action.num_entries >=NF_FLOW_RULE_ACTION_MAX )) +return NULL ; + + i = flow_rule->rule->action.num_entries++;return &flow_rule->rule->action.entries[i]; }
@@ -222,6 +229,9 @@ static int flow_offload_eth_src(struct net *net,u32 mask, val;u16 val16; +if (!entry0 || !entry1) +return -E2BIG ; + this_tuple = &flow->tuplehash[dir].tuple;switch (this_tuple->xmit_type) {
@@ -272,6 +282,9 @@ static int flow_offload_eth_dst(struct net *net,u8 nud_state;u16 val16; +if (!entry0 || !entry1) +return -E2BIG ; + this_tuple = &flow->tuplehash[dir].tuple;switch (this_tuple->xmit_type) {
@@ -313,16 +326,19 @@ static int flow_offload_eth_dst(struct net *net,return 0 ; } -static void flow_offload_ipv4_snat (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_ipv4_snat (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {struct flow_action_entry *entry =flow_action_entry_next (flow_rule);u32 mask = ~htonl (0xffffffff );__be32 addr;u32 offset; +if (!entry) +return -E2BIG ; +switch (dir) {case FLOW_OFFLOAD_DIR_ORIGINAL : addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.dst_v4.s_addr;
@@ -333,23 +349,27 @@ static void flow_offload_ipv4_snat(struct net *net, offset = offsetof(struct iphdr , daddr);break ;default : -return ; +return -EOPNOTSUPP ; }flow_offload_mangle (entry,FLOW_ACT_MANGLE_HDR_TYPE_IP4 , offset, &addr, &mask); +return 0 ; } -static void flow_offload_ipv4_dnat (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_ipv4_dnat (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {struct flow_action_entry *entry =flow_action_entry_next (flow_rule);u32 mask = ~htonl (0xffffffff );__be32 addr;u32 offset; +if (!entry) +return -E2BIG ; +switch (dir) {case FLOW_OFFLOAD_DIR_ORIGINAL : addr = flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.src_v4.s_addr;
@@ -360,14 +380,15 @@ static void flow_offload_ipv4_dnat(struct net *net, offset = offsetof(struct iphdr , saddr);break ;default : -return ; +return -EOPNOTSUPP ; }flow_offload_mangle (entry,FLOW_ACT_MANGLE_HDR_TYPE_IP4 , offset, &addr, &mask); +return 0 ; } -static void flow_offload_ipv6_mangle (struct nf_flow_rule *flow_rule, +static int flow_offload_ipv6_mangle (struct nf_flow_rule *flow_rule,unsigned int offset,const __be32 *addr,const __be32 *mask) {
@@ -376,15 +397,20 @@ static void flow_offload_ipv6_mangle(struct nf_flow_rule *flow_rule,for (i =0 ; i <sizeof (struct in6_addr ) /sizeof (u32); i++) { entry =flow_action_entry_next (flow_rule); +if (!entry) +return -E2BIG ; +flow_offload_mangle (entry,FLOW_ACT_MANGLE_HDR_TYPE_IP6 , offset + i *sizeof (u32), &addr[i], mask); } + +return 0 ; } -static void flow_offload_ipv6_snat (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_ipv6_snat (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {u32 mask = ~htonl (0xffffffff );const __be32 *addr;
@@ -400,16 +426,16 @@ static void flow_offload_ipv6_snat(struct net *net, offset = offsetof(struct ipv6hdr , daddr);break ;default : -return ; +return -EOPNOTSUPP ; } -flow_offload_ipv6_mangle (flow_rule, offset, addr, &mask); +return flow_offload_ipv6_mangle (flow_rule, offset, addr, &mask); } -static void flow_offload_ipv6_dnat (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_ipv6_dnat (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {u32 mask = ~htonl (0xffffffff );const __be32 *addr;
@@ -425,10 +451,10 @@ static void flow_offload_ipv6_dnat(struct net *net, offset = offsetof(struct ipv6hdr , saddr);break ;default : -return ; +return -EOPNOTSUPP ; } -flow_offload_ipv6_mangle (flow_rule, offset, addr, &mask); +return flow_offload_ipv6_mangle (flow_rule, offset, addr, &mask); }static int flow_offload_l4proto (const struct flow_offload *flow)
@@ -450,15 +476,18 @@ static int flow_offload_l4proto(const struct flow_offload *flow)return type; } -static void flow_offload_port_snat (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_port_snat (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {struct flow_action_entry *entry =flow_action_entry_next (flow_rule);u32 mask, port;u32 offset; +if (!entry) +return -E2BIG ; +switch (dir) {case FLOW_OFFLOAD_DIR_ORIGINAL : port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.dst_port);
@@ -473,22 +502,26 @@ static void flow_offload_port_snat(struct net *net, mask = ~htonl (0xffff );break ;default : -return ; +return -EOPNOTSUPP ; }flow_offload_mangle (entry,flow_offload_l4proto (flow), offset, &port, &mask); +return 0 ; } -static void flow_offload_port_dnat (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_port_dnat (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {struct flow_action_entry *entry =flow_action_entry_next (flow_rule);u32 mask, port;u32 offset; +if (!entry) +return -E2BIG ; +switch (dir) {case FLOW_OFFLOAD_DIR_ORIGINAL : port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.src_port);
@@ -503,20 +536,24 @@ static void flow_offload_port_dnat(struct net *net, mask = ~htonl (0xffff0000 );break ;default : -return ; +return -EOPNOTSUPP ; }flow_offload_mangle (entry,flow_offload_l4proto (flow), offset, &port, &mask); +return 0 ; } -static void flow_offload_ipv4_checksum (struct net *net, -const struct flow_offload *flow, -struct nf_flow_rule *flow_rule) +static int flow_offload_ipv4_checksum (struct net *net, +const struct flow_offload *flow, +struct nf_flow_rule *flow_rule) {u8 protonum = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.l4proto;struct flow_action_entry *entry =flow_action_entry_next (flow_rule); +if (!entry) +return -E2BIG ; + entry->id =FLOW_ACTION_CSUM ; entry->csum_flags =TCA_CSUM_UPDATE_FLAG_IPV4HDR ;
@@ -528,12 +565,14 @@ static void flow_offload_ipv4_checksum(struct net *net, entry->csum_flags |=TCA_CSUM_UPDATE_FLAG_UDP ;break ; } + +return 0 ; } -static void flow_offload_redirect (struct net *net, -const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_redirect (struct net *net, +const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {const struct flow_offload_tuple *this_tuple, *other_tuple;struct flow_action_entry *entry;
@@ -551,21 +590,28 @@ static void flow_offload_redirect(struct net *net, ifindex = other_tuple->iifidx;break ;default : -return ; +return -EOPNOTSUPP ; } dev =dev_get_by_index (net, ifindex);if (!dev) -return ; +return -ENODEV ; entry =flow_action_entry_next (flow_rule); +if (!entry) { +dev_put (dev); +return -E2BIG ; + } + entry->id =FLOW_ACTION_REDIRECT ; entry->dev = dev; + +return 0 ; } -static void flow_offload_encap_tunnel (const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_encap_tunnel (const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {const struct flow_offload_tuple *this_tuple;struct flow_action_entry *entry;
@@ -573,7 +619,7 @@ static void flow_offload_encap_tunnel(const struct flow_offload *flow, this_tuple = &flow->tuplehash[dir].tuple;if (this_tuple->xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) -return ; +return 0 ; dst = this_tuple->dst_cache;if (dst && dst->lwtstate) {
@@ -582,15 +628,19 @@ static void flow_offload_encap_tunnel(const struct flow_offload *flow, tun_info =lwt_tun_info (dst->lwtstate);if (tun_info && (tun_info->mode &IP_TUNNEL_INFO_TX )) { entry =flow_action_entry_next (flow_rule); +if (!entry) +return -E2BIG ; entry->id =FLOW_ACTION_TUNNEL_ENCAP ; entry->tunnel = tun_info; } } + +return 0 ; } -static void flow_offload_decap_tunnel (const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int flow_offload_decap_tunnel (const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) {const struct flow_offload_tuple *other_tuple;struct flow_action_entry *entry;
@@ -598,7 +648,7 @@ static void flow_offload_decap_tunnel(const struct flow_offload *flow, other_tuple = &flow->tuplehash[!dir].tuple;if (other_tuple->xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) -return ; +return 0 ; dst = other_tuple->dst_cache;if (dst && dst->lwtstate) {
@@ -607,9 +657,13 @@ static void flow_offload_decap_tunnel(const struct flow_offload *flow, tun_info =lwt_tun_info (dst->lwtstate);if (tun_info && (tun_info->mode &IP_TUNNEL_INFO_TX )) { entry =flow_action_entry_next (flow_rule); +if (!entry) +return -E2BIG ; entry->id =FLOW_ACTION_TUNNEL_DECAP ; } } + +return 0 ; } static int
@@ -621,8 +675,9 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow,const struct flow_offload_tuple *tuple;int i; -flow_offload_decap_tunnel (flow, dir, flow_rule); -flow_offload_encap_tunnel (flow, dir, flow_rule); +if (flow_offload_decap_tunnel (flow, dir, flow_rule) <0 || +flow_offload_encap_tunnel (flow, dir, flow_rule) <0 ) +return -1 ;if (flow_offload_eth_src (net, flow, dir, flow_rule) <0 ||flow_offload_eth_dst (net, flow, dir, flow_rule) <0 )
@@ -638,6 +693,8 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow,if (tuple->encap[i].proto ==htons (ETH_P_8021Q )) { entry =flow_action_entry_next (flow_rule); +if (!entry) +return -1 ; entry->id =FLOW_ACTION_VLAN_POP ; } }
@@ -651,6 +708,8 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow,continue ; entry =flow_action_entry_next (flow_rule); +if (!entry) +return -1 ;switch (other_tuple->encap[i].proto) {case htons (ETH_P_PPP_SES ):
@@ -676,18 +735,22 @@ int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,return -1 ;if (test_bit (NF_FLOW_SNAT , &flow->flags)) { -flow_offload_ipv4_snat (net, flow, dir, flow_rule); -flow_offload_port_snat (net, flow, dir, flow_rule); +if (flow_offload_ipv4_snat (net, flow, dir, flow_rule) <0 || +flow_offload_port_snat (net, flow, dir, flow_rule) <0 ) +return -1 ; }if (test_bit (NF_FLOW_DNAT , &flow->flags)) { -flow_offload_ipv4_dnat (net, flow, dir, flow_rule); -flow_offload_port_dnat (net, flow, dir, flow_rule); +if (flow_offload_ipv4_dnat (net, flow, dir, flow_rule) <0 || +flow_offload_port_dnat (net, flow, dir, flow_rule) <0 ) +return -1 ; }if (test_bit (NF_FLOW_SNAT , &flow->flags) ||test_bit (NF_FLOW_DNAT , &flow->flags)) -flow_offload_ipv4_checksum (net, flow, flow_rule); +if (flow_offload_ipv4_checksum (net, flow, flow_rule) <0 ) +return -1 ; -flow_offload_redirect (net, flow, dir, flow_rule); +if (flow_offload_redirect (net, flow, dir, flow_rule) <0 ) +return -1 ;return 0 ; }
@@ -701,22 +764,23 @@ int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,return -1 ;if (test_bit (NF_FLOW_SNAT , &flow->flags)) { -flow_offload_ipv6_snat (net, flow, dir, flow_rule); -flow_offload_port_snat (net, flow, dir, flow_rule); +if (flow_offload_ipv6_snat (net, flow, dir, flow_rule) <0 || +flow_offload_port_snat (net, flow, dir, flow_rule) <0 ) +return -1 ; }if (test_bit (NF_FLOW_DNAT , &flow->flags)) { -flow_offload_ipv6_dnat (net, flow, dir, flow_rule); -flow_offload_port_dnat (net, flow, dir, flow_rule); +if (flow_offload_ipv6_dnat (net, flow, dir, flow_rule) <0 || +flow_offload_port_dnat (net, flow, dir, flow_rule) <0 ) +return -1 ; } -flow_offload_redirect (net, flow, dir, flow_rule); +if (flow_offload_redirect (net, flow, dir, flow_rule) <0 ) +return -1 ;return 0 ; }EXPORT_SYMBOL_GPL (nf_flow_rule_route_ipv6); -#define NF_FLOW_RULE_ACTION_MAX 16 -static struct nf_flow_rule * nf_flow_offload_rule_alloc(struct net *net, const struct flow_offload_work *offload,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/570 netfilter: nfnetlink_log: account for netlink header size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 6d52a4a0520a6696bdde51caa11f2d6821cd0c01 ]
This is a followup to an old bug fix: NLMSG_DONE needs to account for the netlink header size, not just the attribute size.
This can result in a WARN splat + drop of the netlink message, but other than this there are no ill effects.
--- net/netfilter/nfnetlink_log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink_log.c +1 -1
@@ -715,7 +715,7 @@ nfulnl_log_packet(struct net *net, +nla_total_size (plen)/* prefix */ +nla_total_size (sizeof (struct nfulnl_msg_packet_hw )) +nla_total_size (sizeof (struct nfulnl_msg_packet_timestamp )) - +nla_total_size (sizeof (struct nfgenmsg ));/* NLMSG_DONE */ + +nlmsg_total_size (sizeof (struct nfgenmsg ));/* NLMSG_DONE */ if (in &&skb_mac_header_was_set (skb)) { size +=nla_total_size (skb->dev->hard_header_len)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/570 netfilter: x_tables: ensure names are nul-terminated
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit a958a4f90ddd7de0800b33ca9d7b886b7d40f74e ]
Reject names that lack a \0 character before feeding them to functions that expect c-strings.
Fixes tag is the most recent commit that needs this change.
--- net/netfilter/xt_cgroup.c | 6 ++++++ net/netfilter/xt_rateest.c | 5 +++++ 2 files changed, 11 insertions(+)
net/netfilter/xt_cgroup.c +6 -0
@@ -53,6 +53,9 @@ static int cgroup_mt_check_v1(const struct xt_mtchk_param *par) info->priv =NULL ;if (info->has_path) { +if (strnlen (info->path,sizeof (info->path)) >=sizeof (info->path)) +return -ENAMETOOLONG ; + cgrp =cgroup_get_from_path (info->path);if (IS_ERR (cgrp)) { pr_info_ratelimited("invalid path, errno=%ld\n",
@@ -85,6 +88,9 @@ static int cgroup_mt_check_v2(const struct xt_mtchk_param *par) info->priv =NULL ;if (info->has_path) { +if (strnlen (info->path,sizeof (info->path)) >=sizeof (info->path)) +return -ENAMETOOLONG ; + cgrp =cgroup_get_from_path (info->path);if (IS_ERR (cgrp)) { pr_info_ratelimited("invalid path, errno=%ld\n",
net/netfilter/xt_rateest.c +5 -0
@@ -91,6 +91,11 @@ static int xt_rateest_mt_checkentry(const struct xt_mtchk_param *par) goto err1; } +if (strnlen (info->name1,sizeof (info->name1)) >=sizeof (info->name1)) +return -ENAMETOOLONG ; +if (strnlen (info->name2,sizeof (info->name2)) >=sizeof (info->name2)) +return -ENAMETOOLONG ; + ret = -ENOENT ; est1 =xt_rateest_lookup (par->net, info->name1);if (!est1)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/570 netfilter: ipset: use nla_strcmp for IPSET_ATTR_NAME attr
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit b7e8590987aa94c9dc51518fad0e58cb887b1db5 ]
IPSET_ATTR_NAME and IPSET_ATTR_NAMEREF are of NLA_STRING type, they cannot be treated like a c-string.
They either have to be switched to NLA_NUL_STRING, or the compare operations need to use the nla functions.
--- include/linux/netfilter/ipset/ip_set.h | 2 +- net/netfilter/ipset/ip_set_core.c | 4 ++-- net/netfilter/ipset/ip_set_list_set.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
include/linux/netfilter/ipset/ip_set.h +1 -1
@@ -309,7 +309,7 @@ enum {/* register and unregister set references */ extern ip_set_id_t ip_set_get_byname (struct net *net, -const char *name,struct ip_set **set); +const struct nlattr *name,struct ip_set **set);extern void ip_set_put_byindex (struct net *net,ip_set_id_t index);extern void ip_set_name_byindex (struct net *net,ip_set_id_t index,char *name);extern ip_set_id_t ip_set_nfnl_get_byindex (struct net *net,ip_set_id_t index);
net/netfilter/ipset/ip_set_core.c +2 -2
@@ -823,7 +823,7 @@ EXPORT_SYMBOL_GPL(ip_set_del);* */ ip_set_id_t -ip_set_get_byname (struct net *net,const char *name,struct ip_set **set) +ip_set_get_byname (struct net *net,const struct nlattr *name,struct ip_set **set) {ip_set_id_t i, index =IPSET_INVALID_ID ;struct ip_set *s;
@@ -832,7 +832,7 @@ ip_set_get_byname(struct net *net, const char *name, struct ip_set **set)rcu_read_lock ();for (i =0 ; i < inst->ip_set_max; i++) { s =rcu_dereference (inst->ip_set_list)[i]; -if (s &&STRNCMP (s->name, name)) { +if (s &&nla_strcmp (name, s->name) ==0 ) {__ip_set_get (s); index = i; *set = s;
net/netfilter/ipset/ip_set_list_set.c +2 -2
@@ -367,7 +367,7 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], ret =ip_set_get_extensions (set, tb, &ext);if (ret)return ret; - e.id =ip_set_get_byname (map->net,nla_data (tb[IPSET_ATTR_NAME ]), &s); + e.id =ip_set_get_byname (map->net, tb[IPSET_ATTR_NAME ], &s);if (e.id ==IPSET_INVALID_ID )return -IPSET_ERR_NAME ;/* "Loop detection" */
@@ -389,7 +389,7 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[],if (tb[IPSET_ATTR_NAMEREF ]) { e.refid =ip_set_get_byname (map->net, -nla_data (tb[IPSET_ATTR_NAMEREF ]), + tb[IPSET_ATTR_NAMEREF ], &s);if (e.refid ==IPSET_INVALID_ID ) { ret = -IPSET_ERR_NAMEREF ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/570 netfilter: nf_conntrack_helper: pass helper to expect cleanup
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qi Tang <[email protected]>
[ Upstream commit a242a9ae58aa46ff7dae51ce64150a93957abe65 ]
nf_conntrack_helper_unregister() calls nf_ct_expect_iterate_destroy() to remove expectations belonging to the helper being unregistered. However, it passes NULL instead of the helper pointer as the data argument, so expect_iter_me() never matches any expectation and all of them survive the cleanup.
After unregister returns, nfnl_cthelper_del() frees the helper object immediately. Subsequent expectation dumps or packet-driven init_conntrack() calls then dereference the freed exp->helper, causing a use-after-free.
Pass the actual helper pointer so expectations referencing it are properly destroyed before the helper object is freed.
BUG: KASAN: slab-use-after-free in string+0x38f/0x430 Read of size 1 at addr ffff888003b14d20 by task poc/103 Call Trace: string+0x38f/0x430 vsnprintf+0x3cc/0x1170 seq_printf+0x17a/0x240 exp_seq_show+0x2e5/0x560 seq_read_iter+0x419/0x1280 proc_reg_read+0x1ac/0x270 vfs_read+0x179/0x930 ksys_read+0xef/0x1c0 Freed by task 103: The buggy address is located 32 bytes inside of freed 192-byte region [ffff888003b14d00, ffff888003b14dc0)
--- net/netfilter/nf_conntrack_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_helper.c +1 -1
@@ -469,7 +469,7 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)*/ synchronize_rcu (); -nf_ct_expect_iterate_destroy (expect_iter_me,NULL ); +nf_ct_expect_iterate_destroy (expect_iter_me, me);nf_ct_iterate_destroy (unhelp, me);/* Maybe someone has gotten the helper already when unhelp above.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/570 netfilter: ctnetlink: zero expect NAT fields when CTA_EXPECT_NAT absent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qi Tang <[email protected]>
[ Upstream commit 35177c6877134a21315f37d57a5577846225623e ]
ctnetlink_alloc_expect() allocates expectations from a non-zeroing slab cache via nf_ct_expect_alloc(). When CTA_EXPECT_NAT is not present in the netlink message, saved_addr and saved_proto are never initialized. Stale data from a previous slab occupant can then be dumped to userspace by ctnetlink_exp_dump_expect(), which checks these fields to decide whether to emit CTA_EXPECT_NAT.
The safe sibling nf_ct_expect_init(), used by the packet path, explicitly zeroes these fields.
Zero saved_addr, saved_proto and dir in the else branch, guarded by IS_ENABLED(CONFIG_NF_NAT) since these fields only exist when NAT is enabled.
Confirmed by priming the expect slab with NAT-bearing expectations, freeing them, creating a new expectation without CTA_EXPECT_NAT, and observing that the ctnetlink dump emits a spurious CTA_EXPECT_NAT containing stale data from the prior allocation.
--- net/netfilter/nf_conntrack_netlink.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nf_conntrack_netlink.c +6 -0
@@ -3580,6 +3580,12 @@ ctnetlink_alloc_expect(const struct nlattr * const cda[], struct nf_conn *ct, exp, nf_ct_l3num(ct));if (err <0 ) goto err_out; +#if IS_ENABLED (CONFIG_NF_NAT ) + } else { +memset (&exp->saved_addr,0 ,sizeof (exp->saved_addr)); +memset (&exp->saved_proto,0 ,sizeof (exp->saved_proto)); + exp->dir =0 ; +#endif }return exp; err_out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/570 netfilter: x_tables: restrict xt_check_match/xt_check_target extensions for NFPROTO_ARP
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 3d5d488f11776738deab9da336038add95d342d1 ]
Weiming Shi says:
xt_match and xt_target structs registered with NFPROTO_UNSPEC can be loaded by any protocol family through nft_compat. When such a match/target sets .hooks to restrict which hooks it may run on, the bitmask uses NF_INET_* constants. This is only correct for families whose hook layout matches NF_INET_*: IPv4, IPv6, INET, and bridge all share the same five hooks (PRE_ROUTING ... POST_ROUTING).
ARP only has three hooks (IN=0, OUT=1, FORWARD=2) with different semantics. Because NF_ARP_OUT == 1 == NF_INET_LOCAL_IN, the .hooks validation silently passes for the wrong reasons, allowing matches to run on ARP chains where the hook assumptions (e.g. state->in being set on input hooks) do not hold. This leads to NULL pointer dereferences; xt_devgroup is one concrete example:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000044: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000220-0x0000000000000227] RIP: 0010:devgroup_mt+0xff/0x350 Call Trace: <TASK> nft_match_eval (net/netfilter/nft_compat.c:407) nft_do_chain (net/netfilter/nf_tables_core.c:285) nft_do_chain_arp (net/netfilter/nft_chain_filter.c:61) nf_hook_slow (net/netfilter/core.c:623) arp_xmit (net/ipv4/arp.c:666) </TASK> Kernel panic - not syncing: Fatal exception in interrupt
Fix it by restricting arptables to NFPROTO_ARP extensions only. Note that arptables-legacy only supports:
- arpt_CLASSIFY
- arpt_mangle
- arpt_MARK
that provide explicit NFPROTO_ARP match/target declarations.
--- net/netfilter/x_tables.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
net/netfilter/x_tables.c +23 -0
@@ -501,6 +501,17 @@ int xt_check_match(struct xt_mtchk_param *par, par->match->table, par->table);return -EINVAL ; } + +/* NFPROTO_UNSPEC implies NF_INET_* hooks which do not overlap with +* NF_ARP_IN,OUT,FORWARD, allow explicit extensions with NFPROTO_ARP +* support. +*/ +if (par->family ==NFPROTO_ARP && + par->match->family !=NFPROTO_ARP ) { +pr_info_ratelimited ("%s_tables: %s match: not valid for this family\n" , + xt_prefix[par->family], par->match->name); +return -EINVAL ; + }if (par->match->hooks && (par->hook_mask & ~par->match->hooks) !=0 ) {char used[64 ], allow[64 ];
@@ -1016,6 +1027,18 @@ int xt_check_target(struct xt_tgchk_param *par, par->target->table, par->table);return -EINVAL ; } + +/* NFPROTO_UNSPEC implies NF_INET_* hooks which do not overlap with +* NF_ARP_IN,OUT,FORWARD, allow explicit extensions with NFPROTO_ARP +* support. +*/ +if (par->family ==NFPROTO_ARP && + par->target->family !=NFPROTO_ARP ) { +pr_info_ratelimited ("%s_tables: %s target: not valid for this family\n" , + xt_prefix[par->family], par->target->name); +return -EINVAL ; + } +if (par->target->hooks && (par->hook_mask & ~par->target->hooks) !=0 ) {char used[64 ], allow[64 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/570 netfilter: nf_tables: reject immediate NF_QUEUE verdict
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit da107398cbd4bbdb6bffecb2ce86d5c9384f4cec ]
nft_queue is always used from userspace nftables to deliver the NF_QUEUE verdict. Immediately emitting an NF_QUEUE verdict is never used by the userspace nft tools, so reject immediate NF_QUEUE verdicts.
The arp family does not provide queue support, but such an immediate verdict is still reachable. Globally reject NF_QUEUE immediate verdicts to address this issue.
--- net/netfilter/nf_tables_api.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +5 -2
@@ -10232,8 +10232,6 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,switch (data->verdict.code) {case NF_ACCEPT :case NF_DROP : -case NF_QUEUE : -break ;case NFT_CONTINUE :case NFT_BREAK :case NFT_RETURN :
@@ -10268,6 +10266,11 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data, data->verdict.chain = chain;break ; +case NF_QUEUE : +/* The nft_queue expression is used for this purpose, an +* immediate NF_QUEUE verdict should not ever be seen here. +*/ + fallthrough;default :return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/570 Bluetooth: MGMT: validate LTK enc_size on load
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Keenan Dong <[email protected]>
[ Upstream commit b8dbe9648d69059cfe3a28917bfbf7e61efd7f15 ]
Load Long Term Keys stores the user-provided enc_size and later uses it to size fixed-size stack operations when replying to LE LTK requests. An enc_size larger than the 16-byte key buffer can therefore overflow the reply stack buffer.
Reject oversized enc_size values while validating the management LTK record so invalid keys never reach the stored key state.
--- net/bluetooth/mgmt.c | 3 +++ 1 file changed, 3 insertions(+)
net/bluetooth/mgmt.c +3 -0
@@ -6214,6 +6214,9 @@ static bool ltk_is_valid(struct mgmt_ltk_info *key)if (key->initiator !=0x00 && key->initiator !=0x01 )return false; +if (key->enc_size >sizeof (key->val)) +return false; +switch (key->addr.type) {case BDADDR_LE_PUBLIC :return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/570 rds: ib: reject FRMR registration before IB connection is established
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit a54ecccfae62c5c85259ae5ea5d9c20009519049 ]
rds_ib_get_mr() extracts the rds_ib_connection from conn->c_transport_data and passes it to rds_ib_reg_frmr() for FRWR memory registration. On a fresh outgoing connection, ic is allocated in rds_ib_conn_alloc() with i_cm_id = NULL because the connection worker has not yet called rds_ib_conn_path_connect() to create the rdma_cm_id. When sendmsg() with RDS_CMSG_RDMA_MAP is called on such a connection, the sendmsg path parses the control message before any connection establishment, allowing rds_ib_post_reg_frmr() to dereference ic->i_cm_id->qp and crash the kernel.
The existing guard in rds_ib_reg_frmr() only checks for !ic (added in commit 9e630bcb7701), which does not catch this case since ic is allocated early and is always non-NULL once the connection object exists.
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:rds_ib_post_reg_frmr+0x50e/0x920 Call Trace: rds_ib_post_reg_frmr (net/rds/ib_frmr.c:167) rds_ib_map_frmr (net/rds/ib_frmr.c:252) rds_ib_reg_frmr (net/rds/ib_frmr.c:430) rds_ib_get_mr (net/rds/ib_rdma.c:615) __rds_rdma_map (net/rds/rdma.c:295) rds_cmsg_rdma_map (net/rds/rdma.c:860) rds_sendmsg (net/rds/send.c:1363) ____sys_sendmsg do_syscall_64
Add a check in rds_ib_get_mr() that verifies ic, i_cm_id, and qp are all non-NULL before proceeding with FRMR registration, mirroring the guard already present in rds_ib_post_inv(). Return -ENODEV when the connection is not ready, which the existing error handling in rds_cmsg_send() converts to -EAGAIN for userspace retry and triggers rds_conn_connect_if_down() to start the connection worker.
--- net/rds/ib_rdma.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/rds/ib_rdma.c +6 -1
@@ -608,8 +608,13 @@ void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,return ibmr; } -if (conn) +if (conn) { ic = conn->c_transport_data; +if (!ic || !ic->i_cm_id || !ic->i_cm_id->qp) { + ret = -ENODEV ; + goto out; + } + }if (!rds_ibdev->mr_8k_pool || !rds_ibdev->mr_1m_pool) { ret = -ENODEV ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/570 net: macb: fix clk handling on PCI glue driver removal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fedor Pchelkin <[email protected]>
[ Upstream commit ce8fe5287b87e24e225c342f3b0ec04f0b3680fe ]
platform_device_unregister() may still want to use the registered clks during runtime resume callback.
Note that there is a commit d82d5303c4c5 ("net: macb: fix use after free on rmmod") that addressed the similar problem of clk vs platform device unregistration but just moved the bug to another place.
Save the pointers to clks into local variables for reuse after platform device is unregistered.
BUG: KASAN: use-after-free in clk_prepare+0x5a/0x60 Read of size 8 at addr ffff888104f85e00 by task modprobe/597 CPU: 2 PID: 597 Comm: modprobe Not tainted 6.1.164+ #114 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x8d/0xba print_report+0x17f/0x496 kasan_report+0xd9/0x180 clk_prepare+0x5a/0x60 macb_runtime_resume+0x13d/0x410 [macb] pm_generic_runtime_resume+0x97/0xd0 __rpm_callback+0xc8/0x4d0 rpm_callback+0xf6/0x230 rpm_resume+0xeeb/0x1a70 __pm_runtime_resume+0xb4/0x170 bus_remove_device+0x2e3/0x4b0 device_del+0x5b3/0xdc0 platform_device_del+0x4e/0x280 platform_device_unregister+0x11/0x50 pci_device_remove+0xae/0x210 device_remove+0xcb/0x180 device_release_driver_internal+0x529/0x770 driver_detach+0xd4/0x1a0 bus_remove_driver+0x135/0x260 driver_unregister+0x72/0xb0 pci_unregister_driver+0x26/0x220 __do_sys_delete_module+0x32e/0x550 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 </TASK> Allocated by task 519: kasan_save_stack+0x2c/0x50 kasan_set_track+0x21/0x30 __kasan_kmalloc+0x8e/0x90 __clk_register+0x458/0x2890 clk_hw_register+0x1a/0x60 __clk_hw_register_fixed_rate+0x255/0x410 clk_register_fixed_rate+0x3c/0xa0 macb_probe+0x1d8/0x42e [macb_pci] local_pci_probe+0xd7/0x190 pci_device_probe+0x252/0x600 really_probe+0x255/0x7f0 __driver_probe_device+0x1ee/0x330 driver_probe_device+0x4c/0x1f0 __driver_attach+0x1df/0x4e0 bus_for_each_dev+0x15d/0x1f0 bus_add_driver+0x486/0x5e0 driver_register+0x23a/0x3d0 do_one_initcall+0xfd/0x4d0 do_init_module+0x18b/0x5a0 load_module+0x5663/0x7950 __do_sys_finit_module+0x101/0x180 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 Freed by task 597: kasan_save_stack+0x2c/0x50 kasan_set_track+0x21/0x30 kasan_save_free_info+0x2a/0x50 __kasan_slab_free+0x106/0x180 __kmem_cache_free+0xbc/0x320 clk_unregister+0x6de/0x8d0 macb_remove+0x73/0xc0 [macb_pci] pci_device_remove+0xae/0x210 device_remove+0xcb/0x180 device_release_driver_internal+0x529/0x770 driver_detach+0xd4/0x1a0 bus_remove_driver+0x135/0x260 driver_unregister+0x72/0xb0 pci_unregister_driver+0x26/0x220 __do_sys_delete_module+0x32e/0x550 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x6e/0xd8
--- drivers/net/ethernet/cadence/macb_pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb_pci.c +4 -2
@@ -110,10 +110,12 @@ static void macb_remove(struct pci_dev *pdev) {struct platform_device *plat_dev =pci_get_drvdata (pdev);struct macb_platform_data *plat_data =dev_get_platdata (&plat_dev->dev); +struct clk *pclk = plat_data->pclk; +struct clk *hclk = plat_data->hclk; -clk_unregister (plat_data->pclk); -clk_unregister (plat_data->hclk);platform_device_unregister (plat_dev); +clk_unregister (pclk); +clk_unregister (hclk); }static const struct pci_device_id dev_id_table[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/570 net: macb: properly unregister fixed rate clocks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fedor Pchelkin <[email protected]>
[ Upstream commit f0f367a4f459cc8118aadc43c6bba53c60d93f8d ]
The additional resources allocated with clk_register_fixed_rate() need to be released with clk_unregister_fixed_rate(), otherwise they are lost.
--- drivers/net/ethernet/cadence/macb_pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/cadence/macb_pci.c +4 -4
@@ -97,10 +97,10 @@ static int macb_probe(struct pci_dev *pdev, const struct pci_device_id *id)return 0 ; err_plat_dev_register: -clk_unregister (plat_data.hclk); +clk_unregister_fixed_rate (plat_data.hclk); err_hclk_register: -clk_unregister (plat_data.pclk); +clk_unregister_fixed_rate (plat_data.pclk); err_pclk_register:return err;
@@ -114,8 +114,8 @@ static void macb_remove(struct pci_dev *pdev)struct clk *hclk = plat_data->hclk;platform_device_unregister (plat_dev); -clk_unregister (pclk); -clk_unregister (hclk); +clk_unregister_fixed_rate (pclk); +clk_unregister_fixed_rate (hclk); }static const struct pci_device_id dev_id_table[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/570 net/mlx5: Avoid "No data available" when FW version queries fail
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Saeed Mahameed <[email protected]>
[ Upstream commit 10dc35f6a443d488f219d1a1e3fb8f8dac422070 ]
Avoid printing the misleading "kernel answers: No data available" devlink output when querying firmware or pending firmware version fails (e.g. MLX5 fw state errors / flash failures).
FW can fail on loading the pending flash image and get its version due to various reasons, examples:
mlxfw: Firmware flash failed: key not applicable, err (7)mlx5_fw_image_pending: can't read pending fw version while fw state is 1
and the resulting:
$ devlink dev info kernel answers: No data available
Instead, just report 0 or 0xfff.. versions in case of failure to indicate a problem, and let other information be shown.
after the fix:
$ devlink dev info
pci/0000:00:06.0:
driver mlx5_core
serial_number xxx...
board.serial_number MT2225300179
versions:
fixed:
fw.psid MT_0000000436
running:
fw.version 22.41.0188
fw 22.41.0188
stored:
fw.version 255.255.65535
fw 255.255.65535--- .../net/ethernet/mellanox/mlx5/core/devlink.c | 4 +- drivers/net/ethernet/mellanox/mlx5/core/fw.c | 53 ++++++++++++------- .../ethernet/mellanox/mlx5/core/mlx5_core.h | 4 +- 3 files changed, 37 insertions(+), 24 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/devlink.c +1 -3
@@ -54,9 +54,7 @@ mlx5_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,if (err)return err; - err =mlx5_fw_version_query (dev, &running_fw, &stored_fw); -if (err) -return err; +mlx5_fw_version_query (dev, &running_fw, &stored_fw); snprintf(version_str, sizeof(version_str), "%d.%d.%04d", mlx5_fw_ver_major(running_fw), mlx5_fw_ver_minor(running_fw),
drivers/net/ethernet/mellanox/mlx5/core/fw.c +34 -19
82 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h +2 -2
@@ -206,8 +206,8 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev);int mlx5_firmware_flash (struct mlx5_core_dev *dev,const struct firmware *fw,struct netlink_ext_ack *extack); -int mlx5_fw_version_query (struct mlx5_core_dev *dev, -u32 *running_ver,u32 *stored_ver); +void mlx5_fw_version_query (struct mlx5_core_dev *dev,u32 *running_ver, +u32 *stored_ver);#ifdef CONFIG_MLX5_CORE_EN int mlx5e_init (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/570 net/x25: Fix potential double free of skb
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Schiller <[email protected]>
[ Upstream commit d10a26aa4d072320530e6968ef945c8c575edf61 ]
When alloc_skb fails in x25_queue_rx_frame it calls kfree_skb(skb) at line 48 and returns 1 (error).
This error propagates back through the call chain:
x25_queue_rx_frame returns 1
|
v
x25_state3_machine receives the return value 1 and takes the else
branch at line 278, setting queued=0 and returning 0
|
v
x25_process_rx_frame returns queued=0
|
vx25_backlog_rcv at line 452 sees queued=0 and calls kfree_skb(skb) again
This would free the same skb twice. Looking at x25_backlog_rcv:
net/x25/x25_in.c:x25_backlog_rcv() {
...
queued = x25_process_rx_frame(sk, skb);
...
if (!queued)
kfree_skb(skb);
}--- net/x25/x25_in.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/x25/x25_in.c +2 -3
@@ -44,10 +44,9 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)if (!more && x25->fraglen >0 ) {/* End of fragment */ int len = x25->fraglen + skb->len; -if ((skbn =alloc_skb (len,GFP_ATOMIC )) ==NULL ){ -kfree_skb (skb); + skbn =alloc_skb (len,GFP_ATOMIC ); +if (!skbn)return 1 ; - }skb_queue_tail (&x25->fragment_queue, skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/570 net/x25: Fix overflow when accumulating packets
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Schiller <[email protected]>
[ Upstream commit a1822cb524e89b4cd2cf0b82e484a2335496a6d9 ]
Add a check to ensure that x25_sock.fraglen does not overflow.
The fraglen also needs to be resetted when purging fragment_queue in x25_clear_queues().
--- net/x25/x25_in.c | 4 ++++ net/x25/x25_subr.c | 1 + 2 files changed, 5 insertions(+)
net/x25/x25_in.c +4 -0
@@ -34,6 +34,10 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)struct sk_buff *skbo, *skbn = skb;struct x25_sock *x25 =x25_sk (sk); +/* make sure we don't overflow */ +if (x25->fraglen + skb->len >USHRT_MAX ) +return 1 ; +if (more) { x25->fraglen += skb->len;skb_queue_tail (&x25->fragment_queue, skb);
net/x25/x25_subr.c +1 -0
@@ -40,6 +40,7 @@ void x25_clear_queues(struct sock *sk)skb_queue_purge (&x25->interrupt_in_queue);skb_queue_purge (&x25->interrupt_out_queue);skb_queue_purge (&x25->fragment_queue); + x25->fraglen =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/570 net/sched: cls_fw: fix NULL pointer dereference on shared blocks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit faeea8bbf6e958bf3c00cb08263109661975987c ]
The old-method path in fw_classify() calls tcf_block_q() and dereferences q->handle. Shared blocks leave block->q NULL, causing a NULL deref when an empty cls_fw filter is attached to a shared block and a packet with a nonzero major skb mark is classified.
Reject the configuration in fw_change() when the old method (no TCA_OPTIONS) is used on a shared block, since fw_classify()'s old-method path needs block->q which is NULL for shared blocks.
The fixed null-ptr-deref calling stack:
KASAN: null-ptr-deref in range [0x0000000000000038-0x000000000000003f] RIP: 0010:fw_classify (net/sched/cls_fw.c:81) Call Trace: tcf_classify (./include/net/tc_wrapper.h:197 net/sched/cls_api.c:1764 net/sched/cls_api.c:1860) tc_run (net/core/dev.c:4401) __dev_queue_xmit (net/core/dev.c:4535 net/core/dev.c:4790)
--- net/sched/cls_fw.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/sched/cls_fw.c +12 -2
@@ -245,8 +245,18 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,struct nlattr *tb[TCA_FW_MAX +1 ];int err; -if (!opt) -return handle ? -EINVAL :0 ;/* Succeed if it is old method. */ +if (!opt) { +if (handle) +return -EINVAL ; + +if (tcf_block_shared (tp->chain->block)) { +NL_SET_ERR_MSG (extack, +"Must specify mark when attaching fw filter to block" ); +return -EINVAL ; + } + +return 0 ;/* Succeed if it is old method. */ + } err =nla_parse_nested_deprecated (tb,TCA_FW_MAX , opt, fw_policy,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/570 net/sched: cls_flow: fix NULL pointer dereference on shared blocks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 1a280dd4bd1d616a01d6ffe0de284c907b555504 ]
flow_change() calls tcf_block_q() and dereferences q->handle to derive a default baseclass. Shared blocks leave block->q NULL, causing a NULL deref when a flow filter without a fully qualified baseclass is created on a shared block.
Check tcf_block_shared() before accessing block->q and return -EINVAL for shared blocks. This avoids the null-deref shown below:
=======================================================================
KASAN: null-ptr-deref in range [0x0000000000000038-0x000000000000003f] RIP: 0010:flow_change (net/sched/cls_flow.c:508) Call Trace: tc_new_tfilter (net/sched/cls_api.c:2432) rtnetlink_rcv_msg (net/core/rtnetlink.c:6980) [...] =======================================================================
--- net/sched/cls_flow.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/sched/cls_flow.c +9 -1
@@ -501,8 +501,16 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, }if (TC_H_MAJ (baseclass) ==0 ) { -struct Qdisc *q =tcf_block_q (tp->chain->block); +struct tcf_block *block = tp->chain->block; +struct Qdisc *q; +if (tcf_block_shared (block)) { +NL_SET_ERR_MSG (extack, +"Must specify baseclass when attaching flow filter to block" ); + goto err2; + } + + q =tcf_block_q (block); baseclass =TC_H_MAKE (q->handle, baseclass); }if (TC_H_MIN (baseclass) ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/570 net: hsr: fix VLAN add unwind on slave errors
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luka Gejak <[email protected]>
[ Upstream commit 2e3514e63bfb0e972b1f19668547a455d0129e88 ]
When vlan_vid_add() fails for a secondary slave, the error path calls vlan_vid_del() on the failing port instead of the peer slave that had already succeeded. This results in asymmetric VLAN state across the HSR pair.
Fix this by switching to a centralized unwind path that removes the VID from any slave device that was already programmed.
--- net/hsr/hsr_device.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
net/hsr/hsr_device.c +17 -15
@@ -476,8 +476,8 @@ static void hsr_change_rx_flags(struct net_device *dev, int change)static int hsr_ndo_vlan_rx_add_vid (struct net_device *dev,__be16 proto,u16 vid) { -bool is_slave_a_added = false; -bool is_slave_b_added = false; +struct net_device *slave_a_dev =NULL ; +struct net_device *slave_b_dev =NULL ;struct hsr_port *port;struct hsr_priv *hsr;int ret =0 ;
@@ -493,33 +493,35 @@ static int hsr_ndo_vlan_rx_add_vid(struct net_device *dev,switch (port->type) {case HSR_PT_SLAVE_A :if (ret) { -/* clean up Slave-B */ netdev_err (dev,"add vid failed for Slave-A\n" ); -if (is_slave_b_added) -vlan_vid_del (port->dev, proto, vid); -return ret; + goto unwind; } - - is_slave_a_added = true; + slave_a_dev = port->dev;break ; -case HSR_PT_SLAVE_B :if (ret) { -/* clean up Slave-A */ netdev_err (dev,"add vid failed for Slave-B\n" ); -if (is_slave_a_added) -vlan_vid_del (port->dev, proto, vid); -return ret; + goto unwind; } - - is_slave_b_added = true; + slave_b_dev = port->dev;break ;default : +if (ret) + goto unwind;break ; } }return 0 ; + +unwind: +if (slave_a_dev) +vlan_vid_del (slave_a_dev, proto, vid); + +if (slave_b_dev) +vlan_vid_del (slave_b_dev, proto, vid); + +return ret; } static int hsr_ndo_vlan_rx_kill_vid(struct net_device *dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/570 ipv6: avoid overflows in ip6_datagram_send_ctl()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 4e453375561fc60820e6b9d8ebeb6b3ee177d42e ]
Yiming Qian reported :
<quote>
I believe I found a locally triggerable kernel bug in the IPv6 sendmsg ancillary-data path that can panic the kernel via skb_under_panic() (local DoS).
The core issue is a mismatch between:
- a 16-bit length accumulator (struct ipv6_txoptions::opt_flen, type __u16) and
- a pointer to the *last* provided destination-options header (opt->dst1opt)
when multiple IPV6_DSTOPTS control messages (cmsgs) are provided.
- include/net/ipv6.h:
- struct ipv6_txoptions::opt_flen is __u16 (wrap possible).
(lines 291-307, especially 298)
- net/ipv6/datagram.c:ip6_datagram_send_ctl():
- Accepts repeated IPV6_DSTOPTS and accumulates into opt_flen
without rejecting duplicates. (lines 909-933)
- net/ipv6/ip6_output.c:__ip6_append_data():
- Uses opt->opt_flen + opt->opt_nflen to compute header
sizes/headroom decisions. (lines 1448-1466, especially 1463-1465)
- net/ipv6/ip6_output.c:__ip6_make_skb():
- Calls ipv6_push_frag_opts() if opt->opt_flen is non-zero.
(lines 1930-1934)
- net/ipv6/exthdrs.c:ipv6_push_frag_opts() / ipv6_push_exthdr():
- Push size comes from ipv6_optlen(opt->dst1opt) (based on the
pointed-to header). (lines 1179-1185 and 1206-1211)
1. opt_flen is a 16-bit accumulator:
- include/net/ipv6.h:298 defines __u16 opt_flen; /* after fragment hdr */.
2. ip6_datagram_send_ctl() accepts *repeated* IPV6_DSTOPTS cmsgs and increments opt_flen each time:
- In net/ipv6/datagram.c:909-933, for IPV6_DSTOPTS:
- It computes len = ((hdr->hdrlen + 1) << 3);
- It checks CAP_NET_RAW using `ns_capable(net->user_ns,
CAP_NET_RAW)`. (line 922)
- Then it does:
- opt->opt_flen += len; (line 927)
- opt->dst1opt = hdr; (line 928)
There is no duplicate rejection here (unlike the legacy IPV6_2292DSTOPTS path which rejects duplicates at net/ipv6/datagram.c:901-904).
If enough large IPV6_DSTOPTS cmsgs are provided, opt_flen wraps while dst1opt still points to a large (2048-byte) destination-options header.
In the attached PoC (poc.c):
- 32 cmsgs with hdrlen=255 => len = (255+1)*8 = 2048
- 1 cmsg with hdrlen=0 => len = 8
- Total increment: 32*2048 + 8 = 65544, so (__u16)opt_flen == 8
- The last cmsg is 2048 bytes, so dst1opt points to a 2048-byte header.
3. The transmit path sizes headers using the wrapped opt_flen:
- In net/ipv6/ip6_output.c:1463-1465:
- `headersize = sizeof(struct ipv6hdr) + (opt ? opt->opt_flen +
opt->opt_nflen : 0) + ...;`
With wrapped opt_flen, headersize/headroom decisions underestimate what will be pushed later.
4. When building the final skb, the actual push length comes from dst1opt and is not limited by wrapped opt_flen:
- In net/ipv6/ip6_output.c:1930-1934:
- if (opt->opt_flen) proto = ipv6_push_frag_opts(skb, opt, proto);
- In net/ipv6/exthdrs.c:1206-1211, ipv6_push_frag_opts() pushes dst1opt via ipv6_push_exthdr().
- In net/ipv6/exthdrs.c:1179-1184, ipv6_push_exthdr() does:
- skb_push(skb, ipv6_optlen(opt));
- memcpy(h, opt, ipv6_optlen(opt));
With insufficient headroom, skb_push() underflows and triggers skb_under_panic() -> BUG():
- net/core/skbuff.c:2669-2675 (skb_push() calls skb_under_panic())
- net/core/skbuff.c:207-214 (skb_panic() ends in BUG())
- The IPV6_DSTOPTS cmsg path requires CAP_NET_RAW in the target netns user namespace (ns_capable(net->user_ns, CAP_NET_RAW)).
- Root (or any task with CAP_NET_RAW) can trigger this without user namespaces.
- An unprivileged uid=1000 user can trigger this if unprivileged user namespaces are enabled and it can create a userns+netns to obtain namespaced CAP_NET_RAW (the attached PoC does this).
- Local denial of service: kernel BUG/panic (system crash).
- Reproducible with a small userspace PoC.
</quote>
This patch does not reject duplicated options, as this might break some user applications.
Instead, it makes sure to adjust opt_flen and opt_nflen to correctly reflect the size of the current option headers, preventing the overflows and the potential for panics.
This applies to IPV6_DSTOPTS, IPV6_HOPOPTS, and IPV6_RTHDR.
Specifically:
When a new IPV6_DSTOPTS is processed, the length of the old opt->dst1opt is subtracted from opt->opt_flen before adding the new length.
When a new IPV6_HOPOPTS is processed, the length of the old opt->dst0opt is subtracted from opt->opt_nflen.
When a new Routing Header (IPV6_RTHDR or IPV6_2292RTHDR) is processed, the length of the old opt->srcrt is subtracted from opt->opt_nflen.
In the special case within IPV6_2292RTHDR handling where dst1opt is moved to dst0opt, the length of the old opt->dst0opt is subtracted from opt->opt_nflen before the new one is added.
--- net/ipv6/datagram.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/ipv6/datagram.c +10 -0
@@ -756,6 +756,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, {struct in6_pktinfo *src_info;struct cmsghdr *cmsg; +struct ipv6_rt_hdr *orthdr;struct ipv6_rt_hdr *rthdr;struct ipv6_opt_hdr *hdr;struct ipv6_txoptions *opt = ipc6->opt;
@@ -917,9 +918,13 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, goto exit_f; }if (cmsg->cmsg_type ==IPV6_DSTOPTS ) { +if (opt->dst1opt) + opt->opt_flen -=ipv6_optlen (opt->dst1opt); opt->opt_flen += len; opt->dst1opt = hdr; }else { +if (opt->dst0opt) + opt->opt_nflen -=ipv6_optlen (opt->dst0opt); opt->opt_nflen += len; opt->dst0opt = hdr; }
@@ -962,12 +967,17 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, goto exit_f; } + orthdr = opt->srcrt; +if (orthdr) + opt->opt_nflen -= ((orthdr->hdrlen +1 ) <<3 ); opt->opt_nflen += len; opt->srcrt = rthdr;if (cmsg->cmsg_type ==IPV6_2292RTHDR && opt->dst1opt) {int dsthdrlen = ((opt->dst1opt->hdrlen+1 )<<3 ); +if (opt->dst0opt) + opt->opt_nflen -=ipv6_optlen (opt->dst0opt); opt->opt_nflen += dsthdrlen; opt->dst0opt = opt->dst1opt; opt->dst1opt =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/570 bpf: reject direct access to nullable PTR_TO_BUF pointers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qi Tang <[email protected]>
[ Upstream commit b0db1accbc7395657c2b79db59fa9fae0d6656f3 ]
check_mem_access() matches PTR_TO_BUF via base_type() which strips PTR_MAYBE_NULL, allowing direct dereference without a null check.
Map iterator ctx->key and ctx->value are PTR_TO_BUF | PTR_MAYBE_NULL. On stop callbacks these are NULL, causing a kernel NULL dereference.
Add a type_may_be_null() guard to the PTR_TO_BUF branch, matching the existing PTR_TO_BTF_ID pattern.
--- kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
@@ -4572,7 +4572,8 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn }else if (reg->type ==CONST_PTR_TO_MAP ) { err =check_ptr_to_map_access (env, regs, regno, off, size, t, value_regno); - }else if (base_type (reg->type) ==PTR_TO_BUF ) { + }else if (base_type (reg->type) ==PTR_TO_BUF && + !type_may_be_null (reg->type)) {bool rdonly_mem =type_is_rdonly_mem (reg->type);const char *buf_info;u32 *max_access;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/570 hwmon: (pxe1610) Check return value of page-select write in probe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
[ Upstream commit ccf70c41e562b29d1c05d1bbf53391785e09c6fb ]
pxe1610_probe() writes PMBUS_PAGE to select page 0 but does not check the return value. If the write fails, subsequent register reads operate on an indeterminate page, leading to silent misconfiguration.
Check the return value and propagate the error using dev_err_probe(), which also handles -EPROBE_DEFER correctly without log spam.
--- drivers/hwmon/pmbus/pxe1610.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pxe1610.c +4 -1
@@ -104,7 +104,10 @@ static int pxe1610_probe(struct i2c_client *client)* By default this device doesn't boot to page 0, so set page 0 * to access all pmbus registers. */ -i2c_smbus_write_byte_data (client,PMBUS_PAGE ,0 ); + ret =i2c_smbus_write_byte_data (client,PMBUS_PAGE ,0 ); +if (ret <0 ) +return dev_err_probe (&client->dev, ret, +"Failed to set page 0\n" );/* Read Manufacturer id */ ret =i2c_smbus_read_block_data (client,PMBUS_MFR_ID , buf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/570 hwmon: (tps53679) Fix device ID comparison and printing in tps53676_identify()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
[ Upstream commit ca34ee6d0307a0b4e52c870dfc1bb8a3c3eb956e ]
tps53676_identify() uses strncmp() to compare the device ID buffer against a byte sequence containing embedded non-printable bytes (\x53\x67\x60). strncmp() is semantically wrong for binary data comparison; use memcmp() instead.
Additionally, the buffer from i2c_smbus_read_block_data() is not NUL-terminated, so printing it with "%s" in the error path is undefined behavior and may read past the buffer. Use "%*ph" to hex-dump the actual bytes returned.
Per the datasheet, the expected device ID is the 6-byte sequence 54 49 53 67 60 00 ("TI\x53\x67\x60\x00"), so compare all 6 bytes including the trailing NUL.
--- drivers/hwmon/pmbus/tps53679.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/tps53679.c +2 -2
@@ -156,8 +156,8 @@ static int tps53676_identify(struct i2c_client *client, ret =i2c_smbus_read_block_data (client,PMBUS_IC_DEVICE_ID , buf);if (ret <0 )return ret; -if (strncmp ("TI\x53\x67\x60" , buf,5 )) { -dev_err (&client->dev,"Unexpected device ID: %s\n" , buf); +if (ret !=6 ||memcmp (buf,"TI\x53\x67\x60\x00" ,6 )) { +dev_err (&client->dev,"Unexpected device ID: %*ph\n" , ret, buf);return -ENODEV ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/570 hwmon: (occ) Fix missing newline in occ_show_extended()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
[ Upstream commit 09773978879ecf71a7990fe9a28ce4eb92bce645 ]
In occ_show_extended() case 0, when the EXTN_FLAG_SENSOR_ID flag is set, the sysfs_emit format string "%u" is missing the trailing newline that the sysfs ABI expects. The else branch correctly uses "%4phN\n", and all other show functions in this file include the trailing newline.
Add the missing "\n" for consistency and correct sysfs output.
--- drivers/hwmon/occ/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/occ/common.c +1 -1
@@ -724,7 +724,7 @@ static ssize_t occ_show_extended(struct device *dev,switch (sattr->nr) {case 0 :if (extn->flags &EXTN_FLAG_SENSOR_ID ) { - rc =sysfs_emit (buf,"%u" , + rc =sysfs_emit (buf,"%u\n" ,get_unaligned_be32 (&extn->sensor_id)); }else { rc = sysfs_emit(buf, "%02x%02x%02x%02x\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/570 riscv: kgdb: fix several debug register assignment bugs
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Walmsley <[email protected]>
[ Upstream commit 834911eb8eef2501485d819b4eabebadc25c3497 ]
Fix several bugs in the RISC-V kgdb implementation:
- The element of dbg_reg_def[] that is supposed to pertain to the S1 register embeds instead the struct pt_regs offset of the A1 register. Fix this to use the S1 register offset in struct pt_regs.
- The sleeping_thread_to_gdb_regs() function copies the value of the S10 register into the gdb_regs[] array element meant for the S9 register, and copies the value of the S11 register into the array element meant for the S10 register. It also neglects to copy the value of the S11 register. Fix all of these issues.
--- arch/riscv/kernel/kgdb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/riscv/kernel/kgdb.c +4 -3
@@ -194,7 +194,7 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { {DBG_REG_T1, GDB_SIZEOF_REG, offsetof(struct pt_regs, t1)}, {DBG_REG_T2, GDB_SIZEOF_REG, offsetof(struct pt_regs, t2)}, {DBG_REG_FP, GDB_SIZEOF_REG, offsetof(struct pt_regs, s0)}, - {DBG_REG_S1, GDB_SIZEOF_REG, offsetof(struct pt_regs, a1)}, + {DBG_REG_S1, GDB_SIZEOF_REG, offsetof(struct pt_regs, s1)}, {DBG_REG_A0, GDB_SIZEOF_REG, offsetof(struct pt_regs, a0)}, {DBG_REG_A1, GDB_SIZEOF_REG, offsetof(struct pt_regs, a1)}, {DBG_REG_A2, GDB_SIZEOF_REG, offsetof(struct pt_regs, a2)},
@@ -263,8 +263,9 @@ sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task) gdb_regs[DBG_REG_S6_OFF ] = task->thread.s[6 ]; gdb_regs[DBG_REG_S7_OFF ] = task->thread.s[7 ]; gdb_regs[DBG_REG_S8_OFF ] = task->thread.s[8 ]; - gdb_regs[DBG_REG_S9_OFF ] = task->thread.s[10 ]; - gdb_regs[DBG_REG_S10_OFF ] = task->thread.s[11 ]; + gdb_regs[DBG_REG_S9_OFF ] = task->thread.s[9 ]; + gdb_regs[DBG_REG_S10_OFF ] = task->thread.s[10 ]; + gdb_regs[DBG_REG_S11_OFF ] = task->thread.s[11 ]; gdb_regs[DBG_REG_EPC_OFF ] = task->thread.ra; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/570 drm/ioc32: stop speculation on the drm_compat_ioctl path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit f8995c2df519f382525ca4bc90553ad2ec611067 upstream.
The drm compat ioctl path takes a user controlled pointer, and then dereferences it into a table of function pointers, the signature method of spectre problems. Fix this up by calling array_index_nospec() on the index to the function pointer list.
--- drivers/gpu/drm/drm_ioc32.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/drm_ioc32.c +2 -0
@@ -28,6 +28,7 @@* IN THE SOFTWARE. */ #include <linux/compat.h> +#include <linux/nospec.h> #include <linux/ratelimit.h> #include <linux/export.h>
@@ -982,6 +983,7 @@ long drm_compat_ioctl(struct file *filp,if (nr >=ARRAY_SIZE (drm_compat_ioctls))return drm_ioctl (filp, cmd, arg); + nr =array_index_nospec (nr,ARRAY_SIZE (drm_compat_ioctls)); fn = drm_compat_ioctls[nr].fn;if (!fn)return drm_ioctl (filp, cmd, arg);
Greg Kroah-Hartman
maintainerPATCH 444/570 wifi: wilc1000: fix u8 overflow in SSID scan buffer size calculation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yasuaki Torimaru <[email protected]>
commit d049e56b1739101d1c4d81deedb269c52a8dbba0 upstream.
The variable valuesize is declared as u8 but accumulates the total length of all SSIDs to scan. Each SSID contributes up to 33 bytes (IEEE80211_MAX_SSID_LEN + 1), and with WILC_MAX_NUM_PROBED_SSID (10) SSIDs the total can reach 330, which wraps around to 74 when stored in a u8.
This causes kmalloc to allocate only 75 bytes while the subsequent memcpy writes up to 331 bytes into the buffer, resulting in a 256-byte heap buffer overflow.
Widen valuesize from u8 to u32 to accommodate the full range.
--- drivers/net/wireless/microchip/wilc1000/hif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/microchip/wilc1000/hif.c +1 -1
@@ -157,7 +157,7 @@ int wilc_scan(struct wilc_vif *vif, u8 su32 index =0 ;u32 i, scan_timeout;u8 *buffer; -u8 valuesize =0 ; +u32 valuesize =0 ;u8 *search_ssid_vals =NULL ;struct host_if_drv *hif_drv = vif->hif_drv;
Greg Kroah-Hartman
maintainerPATCH 445/570 USB: serial: option: add MeiG Smart SRM825WN
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ernestas Kulik <[email protected]>
commit e8d0ed37bd51da52da6225d278e330c2f18a6198 upstream.
Add support for the SDX62-based MeiG Smart SRM825WN module.
If#= 0: RNDIS
If#= 1: RNDIS
If#= 2: Diag
If#= 3: AT
If#= 4: AT
If#= 5: NMEA
T: Bus=01 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 19 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=2dee ProdID=4d38 Rev= 5.04 S: Manufacturer=MEIG S: Product=LTE-A Module S: SerialNumber=da47a175
C:* #Ifs= 6 Cfg#= 1 Atr=80 MxPwr=500mA
A: FirstIf#= 0 IfCount= 2 Cls=e0(wlcon) Sub=01 Prot=03
I:* If#= 0 Alt= 0 #EPs= 1 Cls=e0(wlcon) Sub=01 Prot=03 Driver=rndis_host
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=32ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=rndis_host
E: Ad=8e(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=0f(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=86(I) Atr=03(Int.) MxPS= 10 Ivl=32ms E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 5 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option E: Ad=88(I) Atr=03(Int.) MxPS= 10 Ivl=32ms E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
--- drivers/usb/serial/option.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/serial/option.c +3 -0
@@ -2441,6 +2441,9 @@ static const struct usb_device_id option { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d22, 0xff, 0xff, 0x30) }, /* MeiG Smart SRM815 and SRM825L */ { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d22, 0xff, 0xff, 0x40) }, /* MeiG Smart SRM825L */ { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d22, 0xff, 0xff, 0x60) }, /* MeiG Smart SRM825L */ + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d38, 0xff, 0xff, 0x30) }, /* MeiG Smart SRM825WN (Diag) */ + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d38, 0xff, 0xff, 0x40) }, /* MeiG Smart SRM825WN (AT) */ + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d38, 0xff, 0xff, 0x60) }, /* MeiG Smart SRM825WN (NMEA) */ { USB_DEVICE_INTERFACE_CLASS(0x2df3, 0x9d03, 0xff) }, /* LongSung M5710 */ { USB_DEVICE_INTERFACE_CLASS(0x305a, 0x1404, 0xff) }, /* GosunCn GM500 RNDIS */ { USB_DEVICE_INTERFACE_CLASS(0x305a, 0x1405, 0xff) }, /* GosunCn GM500 MBIM */
Greg Kroah-Hartman
maintainerPATCH 446/570 ALSA: caiaq: fix stack out-of-bounds read in init_card
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Berk Cem Goksel <[email protected]>
commit 45424e871abf2a152e247a9cff78359f18dd95c0 upstream.
The loop creates a whitespace-stripped copy of the card shortname where len < sizeof(card->id) is used for the bounds check. Since sizeof(card->id) is 16 and the local id buffer is also 16 bytes, writing 16 non-space characters fills the entire buffer, overwriting the terminating nullbyte.
When this non-null-terminated string is later passed to snd_card_set_id() -> copy_valid_id_string(), the function scans forward with while (*nid && ...) and reads past the end of the stack buffer, reading the contents of the stack.
A USB device with a product name containing many non-ASCII, non-space characters (e.g. multibyte UTF-8) will reliably trigger this as follows:
BUG: KASAN: stack-out-of-bounds in copy_valid_id_string
sound/core/init.c:696 [inline]
BUG: KASAN: stack-out-of-bounds in snd_card_set_id_no_lock+0x698/0x74c
sound/core/init.c:718The off-by-one has been present since commit bafeee5b1f8d ("ALSA:snd_usb_caiaq: give better shortname") from June 2009 (v2.6.31-rc1), which first introduced this whitespace-stripping loop. The original code never accounted for the null terminator when bounding the copy.
Fix this by changing the loop bound to sizeof(card->id) - 1, ensuring at least one byte remains as the null terminator.
--- sound/usb/caiaq/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -1
@@ -488,7 +488,7 @@ static int init_card(struct snd_usb_caiamemset (id,0 ,sizeof (id));for (c = card->shortname, len =0 ; - *c && len <sizeof (card->id); c++) + *c && len <sizeof (card->id) -1 ; c++)if (*c !=' ' ) id[len++] = *c;
Greg Kroah-Hartman
maintainerPATCH 447/570 ALSA: ctxfi: Fix missing SPDIFI1 index handling
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit b045ab3dff97edae6d538eeff900a34c098761f8 upstream.
SPDIF1 DAIO type isn't properly handled in daio_device_index() for hw20k2, and it returned -EINVAL, which ended up with the out-of-bounds array access. Follow the hw20k1 pattern and return the proper index for this type, too.
--- sound/pci/ctxfi/ctdaio.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/ctxfi/ctdaio.c +1 -0
@@ -119,6 +119,7 @@ static unsigned int daio_device_index(enswitch (type) {case SPDIFOO :return 0 ;case SPDIFIO :return 0 ; +case SPDIFI1 :return 1 ;case LINEO1 :return 4 ;case LINEO2 :return 7 ;case LINEO3 :return 5 ;
Greg Kroah-Hartman
maintainerPATCH 448/570 Bluetooth: SMP: derive legacy responder STK authentication from MITM state
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleh Konko <[email protected]>
commit 20756fec2f0108cb88e815941f1ffff88dc286fe upstream.
The legacy responder path in smp_random() currently labels the stored STK as authenticated whenever pending_sec_level is BT_SECURITY_HIGH. That reflects what the local service requested, not what the pairing flow actually achieved.
For Just Works/Confirm legacy pairing, SMP_FLAG_MITM_AUTH stays clear and the resulting STK should remain unauthenticated even if the local side requested HIGH security. Use the established MITM state when storing the responder STK so the key metadata matches the pairing result.
This also keeps the legacy path aligned with the Secure Connections code, which already treats JUST_WORKS/JUST_CFM as unauthenticated.
--- net/bluetooth/smp.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/bluetooth/smp.c +1 -4
@@ -1017,10 +1017,7 @@ static u8 smp_random(struct smp_chan *smsmp_s1 (smp->tk, smp->prnd, smp->rrnd, stk); -if (hcon->pending_sec_level ==BT_SECURITY_HIGH ) - auth =1 ; -else - auth =0 ; + auth =test_bit (SMP_FLAG_MITM_AUTH , &smp->flags) ?1 :0 ;/* Even though there's no _RESPONDER suffix this is the * responder STK we're adding for later lookup (the initiator
Greg Kroah-Hartman
maintainerPATCH 449/570 Bluetooth: SMP: force responder MITM requirements before building the pairing response
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleh Konko <[email protected]>
commit d05111bfe37bfd8bd4d2dfe6675d6bdeef43f7c7 upstream.
smp_cmd_pairing_req() currently builds the pairing response from the initiator auth_req before enforcing the local BT_SECURITY_HIGH requirement. If the initiator omits SMP_AUTH_MITM, the response can also omit it even though the local side still requires MITM.
tk_request() then sees an auth value without SMP_AUTH_MITM and may select JUST_CFM, making method selection inconsistent with the pairing policy the responder already enforces.
When the local side requires HIGH security, first verify that MITM can be achieved from the IO capabilities and then force SMP_AUTH_MITM in the response in both rsp.auth_req and auth. This keeps the responder auth bits and later method selection aligned.
--- net/bluetooth/smp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/bluetooth/smp.c +5 -1
@@ -1817,7 +1817,7 @@ static u8 smp_cmd_pairing_req(struct l2cif (sec_level > conn->hcon->pending_sec_level) conn->hcon->pending_sec_level = sec_level; -/* If we need MITM check that it can be achieved */ +/* If we need MITM check that it can be achieved. */ if (conn->hcon->pending_sec_level >=BT_SECURITY_HIGH ) {u8 method;
@@ -1825,6 +1825,10 @@ static u8 smp_cmd_pairing_req(struct l2c req->io_capability);if (method ==JUST_WORKS || method ==JUST_CFM )return SMP_AUTH_REQUIREMENTS ; + +/* Force MITM bit if it isn't set by the initiator. */ + auth |=SMP_AUTH_MITM ; + rsp.auth_req |=SMP_AUTH_MITM ; } key_size =min (req->max_key_size, rsp.max_key_size);
Greg Kroah-Hartman
maintainerPATCH 450/570 MIPS: Fix the GCC version check for `__multi3 workaround
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej W. Rozycki <[email protected]>
commit ec8bf18814915460d9c617b556bf024efef26613 upstream.
It was only GCC 10 that fixed a MIPS64r6 code generation issue with a `__multi3' libcall inefficiently produced to perform 64-bit widening multiplication while suitable machine instructions exist to do such a calculation. The fix went in with GCC commit 48b2123f6336 ("re PR target/82981 (unnecessary __multi3 call for mips64r6 linux kernel)").
Adjust our code accordingly, removing build failures such as:
mips64-linux-ld: lib/math/div64.o: in function `mul_u64_add_u64_div_u64':
div64.c:(.text+0x84): undefined reference to `__multi3'
with the GCC versions affected.
--- arch/mips/lib/multi3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/mips/lib/multi3.c +3 -3
@@ -4,12 +4,12 @@#include "libgcc.h" /* -* GCC 7 & older can suboptimally generate __multi3 calls for mips64r6, so for +* GCC 9 & older can suboptimally generate __multi3 calls for mips64r6, so for * that specific case only we implement that intrinsic here. * * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981 */ -#if defined(CONFIG_64BIT ) && defined(CONFIG_CPU_MIPSR6 ) && (__GNUC__ <8 ) +#if defined(CONFIG_64BIT ) && defined(CONFIG_CPU_MIPSR6 ) && (__GNUC__ <10 )/* multiply 64-bit values, low 64-bits returned */ static inline long long notrace dmulu (long long a,long long b)
@@ -51,4 +51,4 @@ ti_type notrace __multi3(ti_type a, ti_t }EXPORT_SYMBOL (__multi3); -#endif /* 64BIT && CPU_MIPSR6 && GCC7 */ +#endif /* 64BIT && CPU_MIPSR6 && GCC9 */
Greg Kroah-Hartman
maintainerPATCH 451/570 hwmon: (occ) Fix division by zero in occ_show_power_1()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 39e2a5bf970402a8530a319cf06122e216ba57b8 upstream.
In occ_show_power_1() case 1, the accumulator is divided by update_tag without checking for zero. If no samples have been collected yet (e.g. during early boot when the sensor block is included but hasn't been updated), update_tag is zero, causing a kernel divide-by-zero crash.
The 2019 fix in commit 211186cae14d ("hwmon: (occ) Fix division by zero issue") only addressed occ_get_powr_avg() used by occ_show_power_2() and occ_show_power_a0(). This separate code path in occ_show_power_1() was missed.
Fix this by reusing the existing occ_get_powr_avg() helper, which already handles the zero-sample case and uses mul_u64_u32_div() to multiply before dividing for better precision. Move the helper above occ_show_power_1() so it is visible at the call site.
--- drivers/hwmon/occ/common.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/hwmon/occ/common.c +8 -9
@@ -419,6 +419,12 @@ static ssize_t occ_show_freq_2(struct dereturn sysfs_emit (buf,"%u\n" , val); } +static u64 occ_get_powr_avg (u64 accum,u32 samples) +{ +return (samples ==0 ) ?0 : +mul_u64_u32_div (accum,1000000UL , samples); +} +static ssize_t occ_show_power_1 (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -440,9 +446,8 @@ static ssize_t occ_show_power_1(struct d val =get_unaligned_be16 (&power->sensor_id);break ;case 1 : - val =get_unaligned_be32 (&power->accumulator) / -get_unaligned_be32 (&power->update_tag); - val *=1000000ULL ; + val =occ_get_powr_avg (get_unaligned_be32 (&power->accumulator), +get_unaligned_be32 (&power->update_tag));break ;case 2 : val = (u64)get_unaligned_be32(&power->update_tag) *
@@ -458,12 +463,6 @@ static ssize_t occ_show_power_1(struct dreturn sysfs_emit (buf,"%llu\n" , val); } -static u64 occ_get_powr_avg (u64 accum,u32 samples) -{ -return (samples ==0 ) ?0 : -mul_u64_u32_div (accum,1000000UL , samples); -} -static ssize_t occ_show_power_2 (struct device *dev,struct device_attribute *attr,char *buf) {
Greg Kroah-Hartman
maintainerPATCH 452/570 drm/ast: dp501: Fix initialization of SCU2C
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
commit 2f42c1a6161646cbd29b443459fd635d29eda634 upstream.
Ast's DP501 initialization reads the register SCU2C at offset 0x1202c and tries to set it to source data from VGA. But writes the update to offset 0x0, with unknown results. Write the result to SCU instead.
The bug only happens in ast_init_analog(). There's similar code in ast_init_dvo(), which works correctly.
--- drivers/gpu/drm/ast/ast_dp501.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_dp501.c +1 -1
@@ -484,7 +484,7 @@ static void ast_init_analog(struct drm_d/* Finally, clear bits [17:16] of SCU2c */ data =ast_read32 (ast,0x1202c ); data &=0xfffcffff ; -ast_write32 (ast,0 , data); +ast_write32 (ast,0x1202c , data);/* Disable DVO */ ast_set_index_reg_mask (ast,AST_IO_CRTC_PORT ,0xa3 ,0xcf ,0x00 );
Greg Kroah-Hartman
maintainerPATCH 453/570 USB: serial: io_edgeport: add support for Blackbox IC135A
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frej Drejhammar <[email protected]>
commit 0e01c3416eb863ee7f156a9d7e7421ec0a9f68a0 upstream.
The Blackbox 724-746-5500 USB Director USB-RS-232 HUB, part number IC135A, is a rebadged Edgeport/4 with its own USB device id.
--- drivers/usb/serial/io_edgeport.c | 3 +++ drivers/usb/serial/io_usbvend.h | 1 + 2 files changed, 4 insertions(+)
drivers/usb/serial/io_edgeport.c +3 -0
@@ -73,6 +73,7 @@ static const struct usb_device_id edgepo { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_22I) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_412_4) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_COMPATIBLE) }, + { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_BLACKBOX_IC135A) }, { } };
@@ -121,6 +122,7 @@ static const struct usb_device_id id_tab { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8R) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8RR) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_412_8) }, + { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_BLACKBOX_IC135A) }, { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0202) }, { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0203) }, { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0310) },
@@ -470,6 +472,7 @@ static void get_product_info(struct edgecase ION_DEVICE_ID_EDGEPORT_2_DIN :case ION_DEVICE_ID_EDGEPORT_4_DIN :case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU : +case ION_DEVICE_ID_BLACKBOX_IC135A : product_info->IsRS232 =1 ;break ;
drivers/usb/serial/io_usbvend.h +1 -0
@@ -211,6 +211,7 @@// // Definitions for other product IDs +#define ION_DEVICE_ID_BLACKBOX_IC135A 0x0801 // OEM device (rebranded Edgeport/4)#define ION_DEVICE_ID_MT4X56USB 0x1403 // OEM device#define ION_DEVICE_ID_E5805A 0x1A01 // OEM device (rebranded Edgeport/4)
Greg Kroah-Hartman
maintainerPATCH 454/570 USB: serial: option: add support for Rolling Wireless RW135R-GL
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wanquan Zhong <[email protected]>
commit 01e8d0f742222f1e68f48180d5480097adf7ae9f upstream.
Add VID/PID 33f8:1003 for the Rolling Wireless RW135R-GL M.2 module, which is used in laptop debug cards with MBIM interface for Linux/Chrome OS. The device supports mbim, pipe functionalities.
Here are the outputs of usb-devices:
T: Bus=04 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#= 2 Spd=5000 MxCh= 0 D: Ver= 3.20 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 9 #Cfgs= 1 P: Vendor=33f8 ProdID=1003 Rev=05.15 S: Manufacturer=Rolling Wireless S.a.r.l. S: Product=Rolling RW135R-GL Module S: SerialNumber=12345678 C: #Ifs= 3 Cfg#= 1 Atr=a0 MxPwr=896mA I: If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=32ms I: If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim E: Ad=0f(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms E: Ad=8e(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=40 Driver=option E: Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms E: Ad=82(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms E: Ad=83(I) Atr=03(Int.) MxPS= 10 Ivl=32ms
--- drivers/usb/serial/option.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/serial/option.c +1 -0
@@ -2464,6 +2464,7 @@ static const struct usb_device_id option { USB_DEVICE_INTERFACE_CLASS(0x33f8, 0x0302, 0xff) }, /* Rolling RW101R-GL (laptop MBIM) */ { USB_DEVICE_INTERFACE_CLASS(0x33f8, 0x0802, 0xff), /* Rolling RW350-GL (laptop MBIM) */ .driver_info = RSVD(5) }, + { USB_DEVICE_INTERFACE_CLASS(0x33f8, 0x1003, 0xff) }, /* Rolling RW135R-GL (laptop MBIM) */ { USB_DEVICE_AND_INTERFACE_INFO(0x3731, 0x0100, 0xff, 0xff, 0x30) }, /* NetPrisma LCUK54-WWD for Global */ { USB_DEVICE_AND_INTERFACE_INFO(0x3731, 0x0100, 0xff, 0x00, 0x40) }, { USB_DEVICE_AND_INTERFACE_INFO(0x3731, 0x0100, 0xff, 0xff, 0x40) },
Greg Kroah-Hartman
maintainerPATCH 455/570 USB: core: add NO_LPM quirk for Razer Kiyo Pro webcam
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: JP Hein <[email protected]>
commit 8b7a42ecdcdeb55580d9345412f7f8fc5aca3f6c upstream.
The Razer Kiyo Pro (1532:0e05) is a USB 3.0 UVC webcam whose firmware does not handle USB Link Power Management transitions reliably. When LPM is active, the device can enter a state where it fails to respond to control transfers, producing EPIPE (-32) errors on UVC probe control SET_CUR requests. In the worst case, the stalled endpoint triggers an xHCI stop-endpoint command that times out, causing the host controller to be declared dead and every USB device on the bus to be disconnected.
This has been reported as Ubuntu Launchpad Bug #2061177. The failure mode is:
1. UVC probe control SET_CUR returns -32 (EPIPE)
2. xHCI host not responding to stop endpoint command
3. xHCI host controller not responding, assume dead
4. All USB devices on the affected xHCI controller disconnect
Disabling LPM prevents the firmware from entering the problematic low- power states that precede the stall. This is the same approach used for other webcams with similar firmware issues (e.g., Logitech HD Webcam C270).
--- drivers/usb/core/quirks.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/core/quirks.c +2 -0
@@ -476,6 +476,8 @@ static const struct usb_device_id usb_qu/* Razer - Razer Blade Keyboard */ { USB_DEVICE(0x1532, 0x0116), .driver_info = USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, + /* Razer - Razer Kiyo Pro Webcam */ + { USB_DEVICE(0x1532, 0x0e05), .driver_info = USB_QUIRK_NO_LPM }, /* Lenovo ThinkPad OneLink+ Dock twin hub controllers (VIA Labs VL812) */ { USB_DEVICE(0x17ef, 0x1018), .driver_info = USB_QUIRK_RESET_RESUME },
Greg Kroah-Hartman
maintainerPATCH 456/570 Input: synaptics-rmi4 - fix a locking bug in an error path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
commit 7adaaee5edd35a423ae199c41b86bd1ed60ed483 upstream.
Lock f54->data_mutex when entering the function statement since jumping to the 'error' label when checking report_size fails causes that mutex to be unlocked.
This bug has been detected by the Clang thread-safety checker.
--- drivers/input/rmi4/rmi_f54.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/rmi4/rmi_f54.c +2 -2
@@ -540,6 +540,8 @@ static void rmi_f54_work(struct work_strint error;int i; +mutex_lock (&f54->data_mutex); + report_size =rmi_f54_get_report_size (f54);if (report_size ==0 ) { dev_err(&fn->dev, "Bad report size, report type=%d\n",
@@ -548,8 +550,6 @@ static void rmi_f54_work(struct work_str goto error;/* retry won't help */ } -mutex_lock (&f54->data_mutex); -/* * Need to check if command has completed. * If not try again later.
Greg Kroah-Hartman
maintainerPATCH 457/570 Input: i8042 - add TUXEDO InfinityBook Max 16 Gen10 AMD to i8042 quirk table
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoffer Sandberg <[email protected]>
commit 5839419cffc7788a356428d321e3ec18055c0286 upstream.
The device occasionally wakes up from suspend with missing input on the internal keyboard and the following suspend attempt results in an instant wake-up. The quirks fix both issues for this device.
--- drivers/input/serio/i8042-acpipnpio.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/serio/i8042-acpipnpio.h +7 -0
@@ -1181,6 +1181,13 @@ static const struct dmi_system_id i8042_ }, { .matches = { + DMI_MATCH(DMI_BOARD_NAME, "X6KK45xU_X6SP45xU"), + }, + .driver_data = (void *)(SERIO_QUIRK_NOMUX |SERIO_QUIRK_RESET_ALWAYS | +SERIO_QUIRK_NOLOOP |SERIO_QUIRK_NOPNP ) + }, + { + .matches = { DMI_MATCH(DMI_BOARD_NAME, "WUJIE Series-X5SP4NAG"), }, .driver_data = (void *)(SERIO_QUIRK_NOMUX | SERIO_QUIRK_RESET_ALWAYS |
Greg Kroah-Hartman
maintainerPATCH 458/570 Input: xpad - add support for Razer Wolverine V3 Pro
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zoltan Illes <[email protected]>
commit e2b0ae529db4766584e77647cefe3ec15c3d842e upstream.
Add device IDs for the Razer Wolverine V3 Pro controller in both wired (0x0a57) and wireless 2.4 GHz dongle (0x0a59) modes.
The controller uses the Xbox 360 protocol (vendor-specific class, subclass 93, protocol 1) on interface 0 with an identical 20-byte input report layout, so no additional processing is needed.
--- drivers/input/joystick/xpad.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/joystick/xpad.c +2 -0
@@ -271,6 +271,8 @@ static const struct xpad_device { { 0x1532, 0x0a00, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, { 0x1532, 0x0a03, "Razer Wildcat", 0, XTYPE_XBOXONE }, { 0x1532, 0x0a29, "Razer Wolverine V2", 0, XTYPE_XBOXONE }, + { 0x1532, 0x0a57, "Razer Wolverine V3 Pro (Wired)", 0, XTYPE_XBOX360 }, + { 0x1532, 0x0a59, "Razer Wolverine V3 Pro (2.4 GHz Dongle)", 0, XTYPE_XBOX360 }, { 0x15e4, 0x3f00, "Power A Mini Pro Elite", 0, XTYPE_XBOX360 }, { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 }, { 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 },
Greg Kroah-Hartman
maintainerPATCH 459/570 iio: dac: ad5770r: fix error return in ad5770r_read_raw()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit c354521708175d776d896f8bdae44b18711eccb6 upstream.
Return the error code from regmap_bulk_read() instead of 0 so that I/O failures are properly propagated.
--- drivers/iio/dac/ad5770r.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5770r.c +1 -1
@@ -323,7 +323,7 @@ static int ad5770r_read_raw(struct iio_d chan->address, st->transf_buf, 2);if (ret) -return 0 ; +return ret; buf16 = st->transf_buf[0 ] + (st->transf_buf[1 ] <<8 ); *val = buf16 >>2 ;
Greg Kroah-Hartman
maintainerPATCH 460/570 iio: light: vcnl4035: fix scan buffer on big-endian
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lechner <[email protected]>
commit fdc7aa54a5d44c05880a4aad7cfb41aacfd16d7b upstream.
Rework vcnl4035_trigger_consumer_handler() so that we are not passing what should be a u16 value as an int * to regmap_read(). This won't work on bit endian systems.
Instead, add a new unsigned int variable to pass to regmap_read(). Then copy that value into the buffer struct.
The buffer array is replaced with a struct since there is only one value being read. This allows us to use the correct u16 data type and has a side-effect of simplifying the alignment specification.
Also fix the endianness of the scan format from little-endian to CPU endianness. Since we are using regmap to read the value, it will be CPU-endian.
--- drivers/iio/light/vcnl4035.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/iio/light/vcnl4035.c +12 -6
@@ -105,17 +105,23 @@ static irqreturn_t vcnl4035_trigger_consstruct iio_dev *indio_dev = pf->indio_dev;struct vcnl4035_data *data =iio_priv (indio_dev);/* Ensure naturally aligned timestamp */ -u8 buffer[ALIGN (sizeof (u16),sizeof (s64)) +sizeof (s64)]__aligned(8) = { }; +struct { +u16 als_data; +aligned_s64 timestamp; + } buffer = { }; +unsigned int val;int ret; - ret =regmap_read (data->regmap,VCNL4035_ALS_DATA , (int *)buffer); + ret =regmap_read (data->regmap,VCNL4035_ALS_DATA , &val);if (ret <0 ) {dev_err (&data->client->dev,"Trigger consumer can't read from sensor.\n" ); goto fail_read; } -iio_push_to_buffers_with_timestamp (indio_dev, buffer, -iio_get_time_ns (indio_dev)); + + buffer.als_data = val; +iio_push_to_buffers_with_timestamp (indio_dev, &buffer, +iio_get_time_ns (indio_dev)); fail_read:iio_trigger_notify_done (indio_dev->trig);
@@ -378,7 +384,7 @@ static const struct iio_chan_spec vcnl40 .sign = 'u', .realbits = 16, .storagebits = 16, - .endianness = IIO_LE, + .endianness = IIO_CPU, }, }, {
@@ -392,7 +398,7 @@ static const struct iio_chan_spec vcnl40 .sign = 'u', .realbits = 16, .storagebits = 16, - .endianness = IIO_LE, + .endianness = IIO_CPU, }, }, };
Greg Kroah-Hartman
maintainerPATCH 461/570 iio: imu: st_lsm6dsx: Set FIFO ODR for accelerometer and gyroscope only
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Lavra <[email protected]>
commit 630748afa7030b272b7bee5df857e7bcf132ed51 upstream.
The st_lsm6dsx_set_fifo_odr() function, which is called when enabling and disabling the hardware FIFO, checks the contents of the hw->settings->batch array at index sensor->id, and then sets the current ODR value in sensor registers that depend on whether the register address is set in the above array element. This logic is valid for internal sensors only, i.e. the accelerometer and gyroscope; however, since commit c91c1c844ebd ("iio: imu:st_lsm6dsx: add i2c embedded controller support"), this function is called also when configuring the hardware FIFO for external sensors (i.e. sensors accessed through the sensor hub functionality), which can result in unrelated device registers being written.
Add a check to the beginning of st_lsm6dsx_set_fifo_odr() so that it does not touch any registers unless it is called for internal sensors.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +4 -0
@@ -201,6 +201,10 @@ static int st_lsm6dsx_set_fifo_odr(strucconst struct st_lsm6dsx_reg *batch_reg;u8 data; +/* Only internal sensors have a FIFO ODR configuration register. */ +if (sensor->id >=ARRAY_SIZE (hw->settings->batch)) +return 0 ; + batch_reg = &hw->settings->batch[sensor->id];if (batch_reg->addr) {int val;
Greg Kroah-Hartman
maintainerPATCH 462/570 iio: gyro: mpu3050: Fix incorrect free_irq() variable
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Tidmore <[email protected]>
commit edb11a1aef4011a4b7b22cc3c3396c6fe371f4a6 upstream.
The handler for the IRQ part of this driver is mpu3050->trig but, in the teardown free_irq() is called with handler mpu3050.
Use correct IRQ handler when calling free_irq().
--- drivers/iio/gyro/mpu3050-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/gyro/mpu3050-core.c +1 -1
@@ -1282,7 +1282,7 @@ int mpu3050_common_remove(struct devicepm_runtime_disable (dev);iio_triggered_buffer_cleanup (indio_dev);if (mpu3050->irq) -free_irq (mpu3050->irq, mpu3050); +free_irq (mpu3050->irq, mpu3050->trig);iio_device_unregister (indio_dev);mpu3050_power_down (mpu3050);
Greg Kroah-Hartman
maintainerPATCH 463/570 iio: gyro: mpu3050: Fix irq resource leak
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Tidmore <[email protected]>
commit 4216db1043a3be72ef9c2b7b9f393d7fa72496e6 upstream.
The interrupt handler is setup but only a few lines down if iio_trigger_register() fails the function returns without properly releasing the handler.
Add cleanup goto to resolve resource leak.
Detected by Smatch:drivers/iio/gyro/mpu3050-core.c:1128 mpu3050_trigger_probe() warn:
'irq' from request_threaded_irq() not released on lines: 1124.
--- drivers/iio/gyro/mpu3050-core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iio/gyro/mpu3050-core.c +6 -1
@@ -1141,11 +1141,16 @@ static int mpu3050_trigger_probe(struct ret =iio_trigger_register (mpu3050->trig);if (ret) -return ret; + goto err_iio_trigger; indio_dev->trig =iio_trigger_get (mpu3050->trig);return 0 ; + +err_iio_trigger: +free_irq (mpu3050->irq, mpu3050->trig); + +return ret; } int mpu3050_common_probe(struct device *dev,
Greg Kroah-Hartman
maintainerPATCH 464/570 iio: gyro: mpu3050: Move iio_device_register() to correct location
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Tidmore <[email protected]>
commit 4c05799449108fb0e0a6bd30e65fffc71e60db4d upstream.
iio_device_register() should be at the end of the probe function to prevent race conditions.
Place iio_device_register() at the end of the probe function and place iio_device_unregister() accordingly.
--- drivers/iio/gyro/mpu3050-core.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/iio/gyro/mpu3050-core.c +13 -8
@@ -1238,12 +1238,6 @@ int mpu3050_common_probe(struct device * goto err_power_down; } - ret =iio_device_register (indio_dev); -if (ret) { -dev_err (dev,"device register failed\n" ); - goto err_cleanup_buffer; - } -dev_set_drvdata (dev, indio_dev);/* Check if we have an assigned IRQ to use as trigger */
@@ -1266,9 +1260,20 @@ int mpu3050_common_probe(struct device *pm_runtime_use_autosuspend (dev);pm_runtime_put (dev); + ret =iio_device_register (indio_dev); +if (ret) { +dev_err (dev,"device register failed\n" ); + goto err_iio_device_register; + } +return 0 ; -err_cleanup_buffer: +err_iio_device_register: +pm_runtime_get_sync (dev); +pm_runtime_put_noidle (dev); +pm_runtime_disable (dev); +if (irq) +free_irq (mpu3050->irq, mpu3050->trig);iio_triggered_buffer_cleanup (indio_dev); err_power_down:mpu3050_power_down (mpu3050);
@@ -1282,13 +1287,13 @@ int mpu3050_common_remove(struct devicestruct iio_dev *indio_dev =dev_get_drvdata (dev);struct mpu3050 *mpu3050 =iio_priv (indio_dev); +iio_device_unregister (indio_dev);pm_runtime_get_sync (dev);pm_runtime_put_noidle (dev);pm_runtime_disable (dev);iio_triggered_buffer_cleanup (indio_dev);if (mpu3050->irq)free_irq (mpu3050->irq, mpu3050->trig); -iio_device_unregister (indio_dev);mpu3050_power_down (mpu3050);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 465/570 iio: gyro: mpu3050: Fix out-of-sequence free_irq()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Tidmore <[email protected]>
commit d14116f6529fa085b1a1b1f224dc9604e4d2a29c upstream.
The triggered buffer is initialized before the IRQ is requested. The removal path currently calls iio_triggered_buffer_cleanup() before free_irq(). This violates the expected LIFO.
Place free_irq() in the correct location relative to iio_triggered_buffer_cleanup().
--- drivers/iio/gyro/mpu3050-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/gyro/mpu3050-core.c +1 -1
@@ -1291,9 +1291,9 @@ int mpu3050_common_remove(struct devicepm_runtime_get_sync (dev);pm_runtime_put_noidle (dev);pm_runtime_disable (dev); -iio_triggered_buffer_cleanup (indio_dev);if (mpu3050->irq)free_irq (mpu3050->irq, mpu3050->trig); +iio_triggered_buffer_cleanup (indio_dev);mpu3050_power_down (mpu3050);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 466/570 usb: quirks: add DELAY_INIT quirk for another Silicon Motion flash drive
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miao Li <[email protected]>
commit dd36014ec6042f424ef51b923e607772f7502ee7 upstream.
Another Silicon Motion flash drive also randomly work incorrectly (lsusb does not list the device) on Huawei hisi platforms during 500 reboot cycles, and the DELAY_INIT quirk fixes this issue.
--- drivers/usb/core/quirks.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/core/quirks.c +1 -0
@@ -394,6 +394,7 @@ static const struct usb_device_id usb_qu/* Silicon Motion Flash Drive */ { USB_DEVICE(0x090c, 0x1000), .driver_info = USB_QUIRK_DELAY_INIT }, + { USB_DEVICE(0x090c, 0x2000), .driver_info = USB_QUIRK_DELAY_INIT }, /* Sound Devices USBPre2 */ { USB_DEVICE(0x0926, 0x0202), .driver_info =
Greg Kroah-Hartman
maintainerPATCH 467/570 usb: ulpi: fix double free in ulpi_register_interface() error path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 01af542392b5d41fd659d487015a71f627accce3 upstream.
When device_register() fails, ulpi_register() calls put_device() on ulpi->dev.
The device release callback ulpi_dev_release() drops the OF node reference and frees ulpi, but the current error path in ulpi_register_interface() then calls kfree(ulpi) again, causing a double free.
Let put_device() handle the cleanup through ulpi_dev_release() and avoid freeing ulpi again in ulpi_register_interface().
--- drivers/usb/common/ulpi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/common/ulpi.c +2 -3
@@ -286,10 +286,9 @@ struct ulpi *ulpi_register_interface(str ulpi->ops = ops; ret =ulpi_register (dev, ulpi); -if (ret) { -kfree (ulpi); +if (ret)return ERR_PTR (ret); - } +return ulpi; }
Greg Kroah-Hartman
maintainerPATCH 468/570 usb: usbtmc: Flush anchored URBs in usbtmc_release
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Heitor Alves de Siqueira <[email protected]>
commit 8a768552f7a8276fb9e01d49773d2094ace7c8f1 upstream.
When calling usbtmc_release, pending anchored URBs must be flushed or killed to prevent use-after-free errors (e.g. in the HCD giveback path). Call usbtmc_draw_down() to allow anchored URBs to be completed.
--- drivers/usb/class/usbtmc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/class/usbtmc.c +3 -0
@@ -254,6 +254,9 @@ static int usbtmc_release(struct inode *list_del (&file_data->file_elem);spin_unlock_irq (&file_data->data->dev_lock); + +/* flush anchored URBs */ +usbtmc_draw_down (file_data);mutex_unlock (&file_data->data->io_mutex);kref_put (&file_data->data->kref, usbtmc_delete);
Greg Kroah-Hartman
maintainerPATCH 469/570 usb: ehci-brcm: fix sleep during atomic
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Chen <[email protected]>
commit 679b771ea05ad0f8eeae83e14a91b8f4f39510c4 upstream.
echi_brcm_wait_for_sof() gets called after disabling interrupts in ehci_brcm_hub_control(). Use the atomic version of poll_timeout to fix the warning.
--- drivers/usb/host/ehci-brcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-brcm.c +2 -2
@@ -31,8 +31,8 @@ static inline void ehci_brcm_wait_for_soint res;/* Wait for next microframe (every 125 usecs) */ - res =readl_relaxed_poll_timeout (&ehci->regs->frame_index, val, - val != frame_idx,1 ,130 ); + res =readl_relaxed_poll_timeout_atomic (&ehci->regs->frame_index, + val, val != frame_idx,1 ,130 );if (res)ehci_err (ehci,"Error waiting for SOF\n" );udelay (delay);
Greg Kroah-Hartman
maintainerPATCH 470/570 usb: dwc2: gadget: Fix spin_lock/unlock mismatch in dwc2_hsotg_udc_stop()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Juno Choi <[email protected]>
commit 9bb4b5ed7f8c4f95cc556bdf042b0ba2fa13557a upstream.
dwc2_gadget_exit_clock_gating() internally calls call_gadget() macro, which expects hsotg->lock to be held since it does spin_unlock/spin_lock around the gadget driver callback invocation.
However, dwc2_hsotg_udc_stop() calls dwc2_gadget_exit_clock_gating() without holding the lock. This leads to:
- spin_unlock on a lock that is not held (undefined behavior)
- The lock remaining held after dwc2_gadget_exit_clock_gating() returns, causing a deadlock when spin_lock_irqsave() is called later in the same function.
Fix this by acquiring hsotg->lock before calling dwc2_gadget_exit_clock_gating() and releasing it afterwards, which satisfies the locking requirement of the call_gadget() macro.
--- drivers/usb/dwc2/gadget.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc2/gadget.c +2 -0
@@ -4605,7 +4605,9 @@ static int dwc2_hsotg_udc_stop(struct us/* Exit clock gating when driver is stopped. */ if (hsotg->params.power_down ==DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && !hsotg->params.no_clock_gating) { +spin_lock_irqsave (&hsotg->lock, flags);dwc2_gadget_exit_clock_gating (hsotg,0 ); +spin_unlock_irqrestore (&hsotg->lock, flags); }/* all endpoints should be shutdown */
Greg Kroah-Hartman
maintainerPATCH 471/570 usb: cdns3: gadget: fix NULL pointer dereference in ep_queue
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongchao Wu <[email protected]>
commit 7f6f127b9bc34bed35f56faf7ecb1561d6b39000 upstream.
When the gadget endpoint is disabled or not yet configured, the ep->desc pointer can be NULL. This leads to a NULL pointer dereference when __cdns3_gadget_ep_queue() is called, causing a kernel crash.
Add a check to return -ESHUTDOWN if ep->desc is NULL, which is the standard return code for unconfigured endpoints.
This prevents potential crashes when ep_queue is called on endpoints that are not ready.
--- drivers/usb/cdns3/cdns3-gadget.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/cdns3/cdns3-gadget.c +3 -0
@@ -2586,6 +2586,9 @@ static int __cdns3_gadget_ep_queue(strucstruct cdns3_request *priv_req;int ret =0 ; +if (!ep->desc) +return -ESHUTDOWN ; + request->actual =0 ; request->status = -EINPROGRESS ; priv_req =to_cdns3_request (request);
Greg Kroah-Hartman
maintainerPATCH 472/570 usb: cdns3: gadget: fix state inconsistency on gadget init failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongchao Wu <[email protected]>
commit c32f8748d70c8fc77676ad92ed76cede17bf2c48 upstream.
When cdns3_gadget_start() fails, the DRD hardware is left in gadget mode while software state remains INACTIVE, creating hardware/software state inconsistency.
When switching to host mode via sysfs:
echo host > /sys/class/usb_role/13180000.usb-role-switch/role
The role state is not set to CDNS_ROLE_STATE_ACTIVE due to the error, so cdns_role_stop() skips cleanup because state is still INACTIVE. This violates the DRD controller design specification (Figure22), which requires returning to idle state before switching roles.
This leads to a synchronous external abort in xhci_gen_setup() when setting up the host controller:
[ 516.440698] configfs-gadget 13180000.usb: failed to start g1: -19
[ 516.442035] cdns-usb3 13180000.usb: Failed to add gadget
[ 516.443278] cdns-usb3 13180000.usb: set role 2 has failed
...
[ 1301.375722] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 1301.377716] Internal error: synchronous external abort: 96000010 [#1] PREEMPT SMP
[ 1301.382485] pc : xhci_gen_setup+0xa4/0x408
[ 1301.393391] backtrace:
...
xhci_gen_setup+0xa4/0x408 <-- CRASH
xhci_plat_setup+0x44/0x58
usb_add_hcd+0x284/0x678
...
cdns_role_set+0x9c/0xbc <-- Role switchFix by calling cdns_drd_gadget_off() in the error path to properly clean up the DRD gadget state.
--- drivers/usb/cdns3/cdns3-gadget.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/cdns3/cdns3-gadget.c +1 -0
@@ -3427,6 +3427,7 @@ static int __cdns3_gadget_init(struct cd ret =cdns3_gadget_start (cdns);if (ret) {pm_runtime_put_sync (cdns->dev); +cdns_drd_gadget_off (cdns);return ret; }
Greg Kroah-Hartman
maintainerPATCH 473/570 nvmet-tcp: fix use-before-check of sg in bounds validation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cengiz Can <[email protected]>
The stable backport of commit 52a0a9854934 ("nvmet-tcp: add bounds checks in nvmet_tcp_build_pdu_iovec") placed the bounds checks after the iov_len calculation:
while (length) {
u32 iov_len = min_t(u32, length, sg->length - sg_offset);
if (!sg_remaining) { /* too late: sg already dereferenced */In mainline, the checks come first because C99 allows mid-block variable declarations. The stable backport moved the declaration to the top of the loop to satisfy C89 declaration rules, but this ended up placing the sg->length dereference before the sg_remaining and sg->length guards.
If sg_next() returns NULL at the end of the scatterlist, the next iteration dereferences a NULL pointer in the iov_len calculation before the sg_remaining check can prevent it.
Fix this by moving the iov_len declaration to function scope and keeping the assignment after the bounds checks, matching the ordering in mainline.
--- drivers/nvme/target/tcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/target/tcp.c +3 -3
@@ -312,7 +312,7 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd) {struct bio_vec *iov = cmd->iov;struct scatterlist *sg; -u32 length, offset, sg_offset; +u32 length, offset, sg_offset, iov_len;unsigned int sg_remaining;int nr_pages;
@@ -329,8 +329,6 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd) sg_remaining = cmd->req.sg_cnt - cmd->sg_idx;while (length) { -u32 iov_len =min_t (u32, length, sg->length - sg_offset); -if (!sg_remaining) {nvmet_tcp_fatal_error (cmd->queue);return ;
@@ -340,6 +338,8 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd)return ; } + iov_len =min_t (u32, length, sg->length - sg_offset); + iov->bv_page =sg_page (sg); iov->bv_len = iov_len; iov->bv_offset = sg->offset + sg_offset;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 474/570 phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
commit 54c4c58713aaff76c2422ff5750e557ab3b100d7 upstream.
It has been observed on the Renesas RZ/G3S SoC that unbinding and binding the PHY driver leads to role autodetection failures. This issue occurs when PHY 3 is the first initialized PHY. PHY 3 does not have an interrupt associated with the USB2_INT_ENABLE register (as rcar_gen3_int_enable[3] = 0). As a result, rcar_gen3_init_otg() is called to initialize OTG without enabling PHY interrupts.
To resolve this, add rcar_gen3_is_any_otg_rphy_initialized() and call it in role_store(), role_show(), and rcar_gen3_init_otg(). At the same time, rcar_gen3_init_otg() is only called when initialization for a PHY with interrupt bits is in progress. As a result, the
struct rcar_gen3_phy::otg_initialized is no longer needed.
[claudiu.beznea: declare the i iterrator from
rcar_gen3_is_any_otg_rphy_initialized() outside of for loop]
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 32 +++++++++++------------- 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +14 -18
@@ -103,7 +103,6 @@ struct rcar_gen3_phy {struct rcar_gen3_chan *ch;u32 int_enable_bits;bool initialized; -bool otg_initialized;bool powered; };
@@ -311,16 +310,16 @@ static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch)return false; } -static bool rcar_gen3_needs_init_otg (struct rcar_gen3_chan *ch) +static bool rcar_gen3_is_any_otg_rphy_initialized (struct rcar_gen3_chan *ch) { -int i; +enum rcar_gen3_phy_index i; -for (i =0 ; i <NUM_OF_PHYS ; i++) { -if (ch->rphys[i].otg_initialized) -return false; +for (i =PHY_INDEX_BOTH_HC ; i <=PHY_INDEX_EHCI ; i++) { +if (ch->rphys[i].initialized) +return true; } -return true; +return false; }static bool rcar_gen3_are_all_rphys_power_off (struct rcar_gen3_chan *ch)
@@ -342,7 +341,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,bool is_b_device;enum phy_mode cur_mode, new_mode; -if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized (ch)) +if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch))return -EIO ;if (sysfs_streq (buf,"host" ))
@@ -380,7 +379,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, {struct rcar_gen3_chan *ch =dev_get_drvdata (dev); -if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized (ch)) +if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch))return -EIO ; return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
@@ -393,6 +392,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)void __iomem *usb2_base = ch->base;u32 val; +if (!ch->is_otg_channel ||rcar_gen3_is_any_otg_rphy_initialized (ch)) +return ; +/* Should not use functions of read-modify-write a register */ val =readl (usb2_base +USB2_LINECTRL1 ); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -459,12 +461,9 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)writel (USB2_OC_TIMSET_INIT , usb2_base +USB2_OC_TIMSET ); } -/* Initialize otg part */ -if (channel->is_otg_channel) { -if (rcar_gen3_needs_init_otg (channel)) -rcar_gen3_init_otg (channel); - rphy->otg_initialized = true; - } +/* Initialize otg part (only if we initialize a PHY with IRQs). */ +if (rphy->int_enable_bits) +rcar_gen3_init_otg (channel); rphy->initialized = true;
@@ -480,9 +479,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) rphy->initialized = false; -if (channel->is_otg_channel) - rphy->otg_initialized = false; - val =readl (usb2_base +USB2_INT_ENABLE ); val &= ~rphy->int_enable_bits;if (!rcar_gen3_is_any_rphy_initialized (channel))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 475/570 phy: renesas: rcar-gen3-usb2: Move IRQ request in probe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
commit de76809f60cc938d3580bbbd5b04b7d12af6ce3a upstream.
Commit 08b0ad375ca6 ("phy: renesas: rcar-gen3-usb2: move IRQ registration to init") moved the IRQ request operation from probe to
struct phy_ops::phy_init API to avoid triggering interrupts (which lead to register accesses) while the PHY clocks (enabled through runtime PM APIs) are not active. If this happens, it results in a synchronous abort.
One way to reproduce this issue is by enabling CONFIG_DEBUG_SHIRQ, which calls free_irq() on driver removal.
Move the IRQ request and free operations back to probe, and take the runtime PM state into account in IRQ handler. This commit is preparatory for the subsequent fixes in this series.
[claudiu.beznea: fixed conflict in probe b/w IRQ request probe and
platform_set_drvdata() by keeping platform_set_drvdata() code before IRQ request code]
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 46 +++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +26 -20
@@ -115,7 +115,6 @@ struct rcar_gen3_chan {struct work_struct work;struct mutex lock;/* protects rphys[...].powered */ enum usb_dr_mode dr_mode; -int irq;u32 obint_enable_bits;bool extcon_host;bool is_otg_channel;
@@ -420,16 +419,25 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) {struct rcar_gen3_chan *ch = _ch;void __iomem *usb2_base = ch->base; -u32 status =readl (usb2_base +USB2_OBINTSTA ); +struct device *dev = ch->dev;irqreturn_t ret =IRQ_NONE ; +u32 status; +pm_runtime_get_noresume (dev); + +if (pm_runtime_suspended (dev)) + goto rpm_put; + + status =readl (usb2_base +USB2_OBINTSTA );if (status & ch->obint_enable_bits) { -dev_vdbg (ch->dev,"%s: %08x\n" , __func__, status); +dev_vdbg (dev,"%s: %08x\n" , __func__, status);writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA );rcar_gen3_device_recognition (ch); ret =IRQ_HANDLED ; } +rpm_put: +pm_runtime_put_noidle (dev);return ret; }
@@ -439,17 +447,6 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base;u32 val; -int ret; - -if (!rcar_gen3_is_any_rphy_initialized (channel) && channel->irq >=0 ) { -INIT_WORK (&channel->work, rcar_gen3_phy_usb2_work); - ret =request_irq (channel->irq, rcar_gen3_phy_usb2_irq, -IRQF_SHARED ,dev_name (channel->dev), channel); -if (ret <0 ) { -dev_err (channel->dev,"No irq handler (%d)\n" , channel->irq); -return ret; - } - }/* Initialize USB2 part */ val =readl (usb2_base +USB2_INT_ENABLE );
@@ -485,9 +482,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &= ~USB2_INT_ENABLE_UCOM_INTEN ;writel (val, usb2_base +USB2_INT_ENABLE ); -if (channel->irq >=0 && !rcar_gen3_is_any_rphy_initialized (channel)) -free_irq (channel->irq, channel); -return 0 ; }
@@ -654,7 +648,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct rcar_gen3_chan *channel;struct phy_provider *provider; -int ret =0 , i; +int ret =0 , i, irq;if (!dev->of_node) {dev_err (dev,"This driver needs device tree\n" );
@@ -670,8 +664,6 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)return PTR_ERR (channel->base); channel->obint_enable_bits =USB2_OBINT_BITS ; -/* get irq number here and request_irq for OTG in phy_init */ - channel->irq =platform_get_irq_optional (pdev,0 ); channel->dr_mode =rcar_gen3_get_dr_mode (dev->of_node);if (channel->dr_mode !=USB_DR_MODE_UNKNOWN ) { channel->is_otg_channel = true;
@@ -731,6 +723,20 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)platform_set_drvdata (pdev, channel); channel->dev = dev; + irq =platform_get_irq_optional (pdev,0 ); +if (irq <0 && irq != -ENXIO ) { + ret = irq; + goto error; + }else if (irq >0 ) { +INIT_WORK (&channel->work, rcar_gen3_phy_usb2_work); + ret =devm_request_irq (dev, irq, rcar_gen3_phy_usb2_irq, +IRQF_SHARED ,dev_name (dev), channel); +if (ret <0 ) { +dev_err (dev,"Failed to request irq (%d)\n" , irq); + goto error; + } + } + provider =devm_of_phy_provider_register (dev, rcar_gen3_phy_usb2_xlate);if (IS_ERR (provider)) {dev_err (dev,"Failed to register PHY provider\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 476/570 phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
commit 55a387ebb9219cbe4edfa8ba9996ccb0e7ad4932 upstream.
The phy-rcar-gen3-usb2 driver exposes four individual PHYs that are requested and configured by PHY users. The struct phy_ops APIs access the same set of registers to configure all PHYs. Additionally, PHY settings can be modified through sysfs or an IRQ handler. While some struct phy_ops APIs are protected by a driver-wide mutex, others rely on individual PHY-specific mutexes.
This approach can lead to various issues, including:
1/ the IRQ handler may interrupt PHY settings in progress, racing with
hardware configuration protected by a mutex lock
2/ due to msleep(20) in rcar_gen3_init_otg(), while a configuration thread
suspends to wait for the delay, another thread may try to configure another PHY (with phy_init() + phy_power_on()); re-running the phy_init() goes to the exact same configuration code, re-running the same hardware configuration on the same set of registers (and bits) which might impact the result of the msleep for the 1st configuring thread
3/ sysfs can configure the hardware (though role_store()) and it can
still race with the phy_init()/phy_power_on() APIs calling into the drivers struct phy_ops
To address these issues, add a spinlock to protect hardware register access and driver private data structures (e.g., calls to rcar_gen3_is_any_rphy_initialized()). Checking driver-specific data remains necessary as all PHY instances share common settings. With this change, the existing mutex protection is removed and the cleanup.h helpers are used.
While at it, to keep the code simpler, do not skip regulator_enable()/regulator_disable() APIs in rcar_gen3_phy_usb2_power_on()/rcar_gen3_phy_usb2_power_off() as the regulators enable/disable operations are reference counted anyway.
[claudiu.beznea:
- in rcar_gen3_phy_usb2_irq() and rcar_gen3_phy_usb2_power_off() replaced scoped_guard() with spin_lock()/spin_unlock(), since scoped_guard() is not available in v5.15
- in rcar_gen3_phy_usb2_power_on() used spin_lock_irqsave()/ spin_unlock_irqrestore() instead of guard() to avoid compilation warning "ISO C90 forbids mixed declarations and code"]
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 42 +++++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +26 -16
@@ -9,6 +9,7 @@* Copyright (C) 2014 Cogent Embedded, Inc. */ +#include <linux/cleanup.h> #include <linux/extcon-provider.h> #include <linux/interrupt.h> #include <linux/io.h>
@@ -113,7 +114,7 @@ struct rcar_gen3_chan {struct rcar_gen3_phy rphys[NUM_OF_PHYS ];struct regulator *vbus;struct work_struct work; -struct mutex lock;/* protects rphys[...].powered */ +spinlock_t lock;/* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode;u32 obint_enable_bits;bool extcon_host;
@@ -340,6 +341,8 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,bool is_b_device;enum phy_mode cur_mode, new_mode; +guard (spinlock_irqsave)(&ch->lock); +if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch))return -EIO ;
@@ -407,7 +410,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val =readl (usb2_base +USB2_ADPCTRL );writel (val |USB2_ADPCTRL_IDPULLUP , usb2_base +USB2_ADPCTRL ); } -msleep (20 ); +mdelay (20 );writel (0xffffffff , usb2_base +USB2_OBINTSTA );writel (ch->obint_enable_bits, usb2_base +USB2_OBINTEN );
@@ -428,6 +431,8 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)if (pm_runtime_suspended (dev)) goto rpm_put; +spin_lock (&ch->lock); + status =readl (usb2_base +USB2_OBINTSTA );if (status & ch->obint_enable_bits) {dev_vdbg (dev,"%s: %08x\n" , __func__, status);
@@ -436,6 +441,8 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) ret =IRQ_HANDLED ; } +spin_unlock (&ch->lock); + rpm_put:pm_runtime_put_noidle (dev);return ret;
@@ -448,6 +455,8 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)void __iomem *usb2_base = channel->base;u32 val; +guard (spinlock_irqsave)(&channel->lock); +/* Initialize USB2 part */ val =readl (usb2_base +USB2_INT_ENABLE ); val |=USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits;
@@ -474,6 +483,8 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)void __iomem *usb2_base = channel->base;u32 val; +guard (spinlock_irqsave)(&channel->lock); + rphy->initialized = false; val =readl (usb2_base +USB2_INT_ENABLE );
@@ -490,19 +501,21 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +unsigned long flags;u32 val;int ret =0 ; -mutex_lock (&channel->lock); -if (!rcar_gen3_are_all_rphys_power_off (channel)) - goto out; -if (channel->vbus) { ret =regulator_enable (channel->vbus);if (ret) - goto out; +return ret; } +spin_lock_irqsave (&channel->lock, flags); + +if (!rcar_gen3_are_all_rphys_power_off (channel)) + goto out; + val =readl (usb2_base +USB2_USBCTR ); val |=USB2_USBCTR_PLL_RST ;writel (val, usb2_base +USB2_USBCTR );
@@ -512,7 +525,8 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) out:/* The powered flag should be set for any other phys anyway */ rphy->powered = true; -mutex_unlock (&channel->lock); + +spin_unlock_irqrestore (&channel->lock, flags);return 0 ; }
@@ -521,20 +535,16 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch; +unsigned long flags;int ret =0 ; -mutex_lock (&channel->lock); +spin_lock_irqsave (&channel->lock, flags); rphy->powered = false; - -if (!rcar_gen3_are_all_rphys_power_off (channel)) - goto out; +spin_unlock_irqrestore (&channel->lock, flags);if (channel->vbus) ret =regulator_disable (channel->vbus); -out: -mutex_unlock (&channel->lock); -return ret; }
@@ -697,7 +707,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)if (phy_data->no_adp_ctrl) channel->obint_enable_bits =USB2_OBINT_IDCHG_EN ; -mutex_init (&channel->lock); +spin_lock_init (&channel->lock);for (i =0 ; i <NUM_OF_PHYS ; i++) { channel->rphys[i].phy =devm_phy_create (dev,NULL , phy_data->phy_usb2_ops);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 477/570 phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
commit 9ce71e85b29eb63e48e294479742e670513f03a0 upstream.
Assert PLL reset on PHY power off. This saves power.
[claudiu.beznea: fixed conflict in rcar_gen3_phy_usb2_power_off() by
using spin_lock_irqsave()/spin_unlock_irqrestore() instead of scoped_guard()]
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +7 -0
@@ -540,6 +540,13 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p)spin_lock_irqsave (&channel->lock, flags); rphy->powered = false; + +if (rcar_gen3_are_all_rphys_power_off (channel)) { +u32 val =readl (channel->base +USB2_USBCTR ); + + val |=USB2_USBCTR_PLL_RST ; +writel (val, channel->base +USB2_USBCTR ); + }spin_unlock_irqrestore (&channel->lock, flags);if (channel->vbus)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 478/570 bridge: br_nd_send: validate ND option lengths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yang <[email protected]>
commit 850837965af15707fd3142c1cf3c5bfaf022299b upstream.
br_nd_send() walks ND options according to option-provided lengths. A malformed option can make the parser advance beyond the computed option span or use a too-short source LLADDR option payload.
Validate option lengths against the remaining NS option area before advancing, and only read source LLADDR when the option is large enough for an Ethernet address.
--- net/bridge/br_arp_nd_proxy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bridge/br_arp_nd_proxy.c +4 -2
@@ -285,12 +285,14 @@ static void br_nd_send(struct net_bridge ns_olen = request->len - (skb_network_offset (request) +sizeof (struct ipv6hdr )) -sizeof (*ns);for (i =0 ; i < ns_olen -1 ; i += (ns->opt[i +1 ] <<3 )) { -if (!ns->opt[i +1 ]) { +if (!ns->opt[i +1 ] || i + (ns->opt[i +1 ] <<3 ) > ns_olen) {kfree_skb (reply);return ; }if (ns->opt[i] ==ND_OPT_SOURCE_LL_ADDR ) { - daddr = ns->opt + i +sizeof (struct nd_opt_hdr ); +if ((ns->opt[i +1 ] <<3 ) >= +sizeof (struct nd_opt_hdr ) +ETH_ALEN ) + daddr = ns->opt + i +sizeof (struct nd_opt_hdr );break ; } }
Greg Kroah-Hartman
maintainerPATCH 479/570 cdc-acm: new quirk for EPSON HMD
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit f97e96c303d689708f7f713d8f3afcc31f1237e9 upstream.
This device has a union descriptor that is just garbage and needs a custom descriptor.
In principle this could be done with a (conditionally activated) heuristic. That would match more devices without a need for defining a new quirk. However, this always carries the risk that the heuristics does the wrong thing and leads to more breakage. Defining the quirk and telling it exactly what to do is the safe and conservative approach.
--- drivers/usb/class/cdc-acm.c | 9 +++++++++ drivers/usb/class/cdc-acm.h | 1 + 2 files changed, 10 insertions(+)
drivers/usb/class/cdc-acm.c +9 -0
@@ -1205,6 +1205,12 @@ static int acm_probe(struct usb_interfacif (!data_interface || !control_interface)return -ENODEV ; goto skip_normal_probe; + }else if (quirks ==NO_UNION_12 ) { + data_interface =usb_ifnum_to_if (usb_dev,2 ); + control_interface =usb_ifnum_to_if (usb_dev,1 ); +if (!data_interface || !control_interface) +return -ENODEV ; + goto skip_normal_probe; }/* normal probing*/
@@ -1733,6 +1739,9 @@ static const struct usb_device_id acm_id { USB_DEVICE(0x045b, 0x024D), /* Renesas R-Car E3 USB Download mode */ .driver_info =DISABLE_ECHO ,/* Don't echo banner */ }, + { USB_DEVICE(0x04b8, 0x0d12), /* EPSON HMD Com&Sens */ + .driver_info = NO_UNION_12, /* union descriptor is garbage */ + }, { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; [email protected] */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ },
drivers/usb/class/cdc-acm.h +1 -0
@@ -142,3 +142,4 @@ struct acm {#define SEND_ZERO_PACKET BIT(6)#define DISABLE_ECHO BIT(7)#define MISSING_CAP_BRK BIT(8) +#define NO_UNION_12 BIT(9)
Greg Kroah-Hartman
maintainerPATCH 480/570 comedi: dt2815: add hardware detection to prevent crash
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Deepanshu Kartikey <[email protected]>
commit 93853512f565e625df2397f0d8050d6aafd7c3ad upstream.
The dt2815 driver crashes when attached to I/O ports without actual hardware present. This occurs because syzkaller or users can attach the driver to arbitrary I/O addresses via COMEDI_DEVCONFIG ioctl.
When no hardware exists at the specified port, inb() operations return 0xff (floating bus), but outb() operations can trigger page faults due to undefined behavior, especially under race conditions:
BUG: unable to handle page fault for address: 000000007fffff90 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page RIP: 0010:dt2815_attach+0x6e0/0x1110
Add hardware detection by reading the status register before attempting any write operations. If the read returns 0xff, assume no hardware is present and fail the attach with -ENODEV. This prevents crashes from outb() operations on non-existent hardware.
--- drivers/comedi/drivers/dt2815.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/comedi/drivers/dt2815.c +12 -0
@@ -176,6 +176,18 @@ static int dt2815_attach(struct comedi_d ? current_range_type : voltage_range_type; } +/* +* Check if hardware is present before attempting any I/O operations. +* Reading 0xff from status register typically indicates no hardware +* on the bus (floating bus reads as all 1s). +*/ +if (inb (dev->iobase +DT2815_STATUS ) ==0xff ) { +dev_err (dev->class_dev, +"No hardware detected at I/O base 0x%lx\n" , + dev->iobase); +return -ENODEV ; + } +/* Init the 2815 */ outb (0x00 , dev->iobase +DT2815_STATUS );for (i =0 ; i <100 ; i++) {
Greg Kroah-Hartman
maintainerPATCH 481/570 comedi: Reinit dev->spinlock between attachments to low-level drivers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
commit 4b9a9a6d71e3e252032f959fb3895a33acb5865c upstream.
struct comedi_device is the main controlling structure for a COMEDI device created by the COMEDI subsystem. It contains a member spinlock containing a spin-lock that is initialized by the COMEDI subsystem, but is reserved for use by a low-level driver attached to the COMEDI device (at least since commit 25436dc9d84f ("Staging: comedi: remove RT code")).
Some COMEDI devices (those created on initialization of the COMEDI subsystem when the "comedi.comedi_num_legacy_minors" parameter is non-zero) can be attached to different low-level drivers over their lifetime using the COMEDI_DEVCONFIG ioctl command. This can result in inconsistent lock states being reported when there is a mismatch in the spin-lock locking levels used by each low-level driver to which the COMEDI device has been attached. Fix it by reinitializing dev->spinlock before calling the low-level driver's attach function pointer if CONFIG_LOCKDEP is enabled.
--- drivers/comedi/drivers.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/comedi/drivers.c +8 -0
@@ -1001,6 +1001,14 @@ int comedi_device_attach(struct comedi_d ret = -EIO ; goto out; } +if (IS_ENABLED (CONFIG_LOCKDEP )) { +/* +* dev->spinlock is for private use by the attached low-level +* driver. Reinitialize it to stop lock-dependency tracking +* between attachments to different low-level drivers. +*/ +spin_lock_init (&dev->spinlock); + } dev->driver = driv; dev->board_name = dev->board_ptr ? *(const char **)dev->board_ptr : dev->driver->driver_name;
Greg Kroah-Hartman
maintainerPATCH 482/570 comedi: ni_atmio16d: Fix invalid clean-up after failed attach
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
commit 101ab946b79ad83b36d5cfd47de587492a80acf0 upstream.
If the driver's COMEDI "attach" handler function (atmio16d_attach()) returns an error, the COMEDI core will call the driver's "detach" handler function (atmio16d_detach()) to clean up. This calls reset_atmio16d() unconditionally, but depending on where the error occurred in the attach handler, the device may not have been sufficiently initialized to call reset_atmio16d(). It uses dev->iobase as the I/O port base address and dev->private as the pointer to the COMEDI device's private data structure. dev->iobase may still be set to its initial value of 0, which would result in undesired writes to low I/O port addresses. dev->private may still be NULL, which would result in null pointer dereferences.
Fix atmio16d_detach() by checking that dev->private is valid (non-null) before calling reset_atmio16d(). This implies that dev->iobase was set correctly since that is set up before dev->private.
--- drivers/comedi/drivers/ni_atmio16d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/comedi/drivers/ni_atmio16d.c +2 -1
@@ -699,7 +699,8 @@ static int atmio16d_attach(struct comedistatic void atmio16d_detach (struct comedi_device *dev) { -reset_atmio16d (dev); +if (dev->private) +reset_atmio16d (dev);comedi_legacy_detach (dev); }
Greg Kroah-Hartman
maintainerPATCH 483/570 comedi: me_daq: Fix potential overrun of firmware buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
commit cc797d4821c754c701d9714b58bea947e31dbbe0 upstream.
me2600_xilinx_download() loads the firmware that was requested by request_firmware(). It is possible for it to overrun the source buffer because it blindly trusts the file format. It reads a data stream length from the first 4 bytes into variable file_length and reads the data stream contents of length file_length from offset 16 onwards. Although it checks that the supplied firmware is at least 16 bytes long, it does not check that it is long enough to contain the data stream.
Add a test to ensure that the supplied firmware is long enough to contain the header and the data stream. On failure, log an error and return -EINVAL.
--- drivers/comedi/drivers/me_daq.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/comedi/drivers/me_daq.c +19 -16
@@ -345,6 +345,25 @@ static int me2600_xilinx_download(structunsigned int file_length;unsigned int i; +/* +* Format of the firmware +* Build longs from the byte-wise coded header +* Byte 1-3: length of the array +* Byte 4-7: version +* Byte 8-11: date +* Byte 12-15: reserved +*/ +if (size >=4 ) { + file_length = (((unsigned int )data[0 ] &0xff ) <<24 ) + + (((unsigned int )data[1 ] &0xff ) <<16 ) + + (((unsigned int )data[2 ] &0xff ) <<8 ) + + ((unsigned int )data[3 ] &0xff ); + } +if (size <16 || file_length > size -16 ) { +dev_err (dev->class_dev,"Firmware length inconsistency\n" ); +return -EINVAL ; + } +/* disable irq's on PLX */ writel (0x00 , devpriv->plx_regbase +PLX9052_INTCSR );
@@ -359,22 +378,6 @@ static int me2600_xilinx_download(structsleep (1 );/* -* Format of the firmware -* Build longs from the byte-wise coded header -* Byte 1-3: length of the array -* Byte 4-7: version -* Byte 8-11: date -* Byte 12-15: reserved -*/ -if (size <16 ) -return -EINVAL ; - - file_length = (((unsigned int )data[0 ] &0xff ) <<24 ) + - (((unsigned int )data[1 ] &0xff ) <<16 ) + - (((unsigned int )data[2 ] &0xff ) <<8 ) + - ((unsigned int )data[3 ] &0xff ); - -/* * Loop for writing firmware byte by byte to xilinx * Firmware data start at offset 16 */
Greg Kroah-Hartman
maintainerPATCH 484/570 comedi: me4000: Fix potential overrun of firmware buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
commit 3fb43a7a5b44713f892c58ead2e5f3a1bc9f4ee7 upstream.
me4000_xilinx_download() loads the firmware that was requested by request_firmware(). It is possible for it to overrun the source buffer because it blindly trusts the file format. It reads a data stream length from the first 4 bytes into variable file_length and reads the data stream contents of length file_length from offset 16 onwards.
Add a test to ensure that the supplied firmware is long enough to contain the header and the data stream. On failure, log an error and return -EINVAL.
Note: The firmware loading was totally broken before commit ac584af59945 ("staging: comedi: me4000: fix firmware downloading"), but that is the most sensible target for this fix.
--- drivers/comedi/drivers/me4000.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/comedi/drivers/me4000.c +12 -4
@@ -316,6 +316,18 @@ static int me4000_xilinx_download(structunsigned int val;unsigned int i; +/* Get data stream length from header. */ +if (size >=4 ) { + file_length = (((unsigned int )data[0 ] &0xff ) <<24 ) + + (((unsigned int )data[1 ] &0xff ) <<16 ) + + (((unsigned int )data[2 ] &0xff ) <<8 ) + + ((unsigned int )data[3 ] &0xff ); + } +if (size <16 || file_length > size -16 ) { +dev_err (dev->class_dev,"Firmware length inconsistency\n" ); +return -EINVAL ; + } +if (!xilinx_iobase)return -ENODEV ;
@@ -347,10 +359,6 @@ static int me4000_xilinx_download(structoutl (val, devpriv->plx_regbase +PLX9052_CNTRL );/* Download Xilinx firmware */ - file_length = (((unsigned int )data[0 ] &0xff ) <<24 ) + - (((unsigned int )data[1 ] &0xff ) <<16 ) + - (((unsigned int )data[2 ] &0xff ) <<8 ) + - ((unsigned int )data[3 ] &0xff );usleep_range (10 ,1000 );for (i =0 ; i < file_length; i++) {
Greg Kroah-Hartman
maintainerPATCH 485/570 netfilter: ipset: drop logically empty buckets in mtype_del
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifan Wu <[email protected]>
commit 9862ef9ab0a116c6dca98842aab7de13a252ae02 upstream.
mtype_del() counts empty slots below n->pos in k, but it only drops the bucket when both n->pos and k are zero. This misses buckets whose live entries have all been removed while n->pos still points past deleted slots.
Treat a bucket as empty when all positions below n->pos are unused and release it directly instead of shrinking it further.
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -1086,7 +1086,7 @@ mtype_del(struct ip_set *set, void *valuif (!test_bit (i, n->used)) k++; } -if (n->pos ==0 && k ==0 ) { +if (k == n->pos) { t->hregion[r].ext_size -=ext_size (n->size, dsize);rcu_assign_pointer (hbucket (t, key),NULL );kfree_rcu (n, rcu);
Greg Kroah-Hartman
maintainerPATCH 486/570 vxlan: validate ND option lengths in vxlan_na_create
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yang <[email protected]>
commit afa9a05e6c4971bd5586f1b304e14d61fb3d9385 upstream.
vxlan_na_create() walks ND options according to option-provided lengths. A malformed option can make the parser advance beyond the computed option span or use a too-short source LLADDR option payload.
Validate option lengths against the remaining NS option area before advancing, and only read source LLADDR when the option is large enough for an Ethernet address.
--- drivers/net/vxlan/vxlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/vxlan/vxlan_core.c +4 -2
@@ -2099,12 +2099,14 @@ static struct sk_buff *vxlan_na_create(s ns_olen = request->len -skb_network_offset (request) -sizeof (struct ipv6hdr ) -sizeof (*ns);for (i =0 ; i < ns_olen-1 ; i += (ns->opt[i+1 ]<<3 )) { -if (!ns->opt[i +1 ]) { +if (!ns->opt[i +1 ] || i + (ns->opt[i +1 ] <<3 ) > ns_olen) {kfree_skb (reply);return NULL ; }if (ns->opt[i] ==ND_OPT_SOURCE_LL_ADDR ) { - daddr = ns->opt + i +sizeof (struct nd_opt_hdr ); +if ((ns->opt[i +1 ] <<3 ) >= +sizeof (struct nd_opt_hdr ) +ETH_ALEN ) + daddr = ns->opt + i +sizeof (struct nd_opt_hdr );break ; } }
Greg Kroah-Hartman
maintainerPATCH 487/570 net: ftgmac100: fix ring allocation unwind on open failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yufan Chen <[email protected]>
commit c0fd0fe745f5e8c568d898cd1513d0083e46204a upstream.
ftgmac100_alloc_rings() allocates rx_skbs, tx_skbs, rxdes, txdes, and rx_scratch in stages. On intermediate failures it returned -ENOMEM directly, leaking resources allocated earlier in the function.
Rework the failure path to use staged local unwind labels and free allocated resources in reverse order before returning -ENOMEM. This matches common netdev allocation cleanup style.
--- drivers/net/ethernet/faraday/ftgmac100.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/net/ethernet/faraday/ftgmac100.c +24 -4
@@ -931,19 +931,19 @@ static int ftgmac100_alloc_rings(struct priv->tx_skbs =kcalloc (MAX_TX_QUEUE_ENTRIES ,sizeof (void *),GFP_KERNEL );if (!priv->tx_skbs) -return -ENOMEM ; + goto err_free_rx_skbs;/* Allocate descriptors */ priv->rxdes =dma_alloc_coherent (priv->dev,MAX_RX_QUEUE_ENTRIES *sizeof (struct ftgmac100_rxdes ), &priv->rxdes_dma,GFP_KERNEL );if (!priv->rxdes) -return -ENOMEM ; + goto err_free_tx_skbs; priv->txdes =dma_alloc_coherent (priv->dev,MAX_TX_QUEUE_ENTRIES *sizeof (struct ftgmac100_txdes ), &priv->txdes_dma,GFP_KERNEL );if (!priv->txdes) -return -ENOMEM ; + goto err_free_rxdes;/* Allocate scratch packet buffer */ priv->rx_scratch = dma_alloc_coherent(priv->dev,
@@ -951,9 +951,29 @@ static int ftgmac100_alloc_rings(struct &priv->rx_scratch_dma, GFP_KERNEL);if (!priv->rx_scratch) -return -ENOMEM ; + goto err_free_txdes;return 0 ; + +err_free_txdes: +dma_free_coherent (priv->dev, +MAX_TX_QUEUE_ENTRIES * +sizeof (struct ftgmac100_txdes ), + priv->txdes, priv->txdes_dma); + priv->txdes =NULL ; +err_free_rxdes: +dma_free_coherent (priv->dev, +MAX_RX_QUEUE_ENTRIES * +sizeof (struct ftgmac100_rxdes ), + priv->rxdes, priv->rxdes_dma); + priv->rxdes =NULL ; +err_free_tx_skbs: +kfree (priv->tx_skbs); + priv->tx_skbs =NULL ; +err_free_rx_skbs: +kfree (priv->rx_skbs); + priv->rx_skbs =NULL ; +return -ENOMEM ; }static void ftgmac100_init_rings (struct ftgmac100 *priv)
Greg Kroah-Hartman
maintainerPATCH 488/570 thunderbolt: Fix property read in nhi_wake_supported()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konrad Dybcio <[email protected]>
commit 73a505dc48144ec72e25874e2b2a72487b02d3bc upstream.
device_property_read_foo() returns 0 on success and only then modifies 'val'. Currently, val is left uninitialized if the aforementioned function returns non-zero, making nhi_wake_supported() return true almost always (random != 0) if the property is not present in device firmware.
Invert the check to make it make sense.
--- drivers/thunderbolt/nhi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/nhi.c +1 -1
@@ -1002,7 +1002,7 @@ static bool nhi_wake_supported(struct pc* If power rails are sustainable for wakeup from S4 this * property is set by the BIOS. */ -if (device_property_read_u8 (&pdev->dev,"WAKE_SUPPORTED" , &val)) +if (!device_property_read_u8 (&pdev->dev,"WAKE_SUPPORTED" , &val))return !!val;return true;
Greg Kroah-Hartman
maintainerPATCH 489/570 USB: dummy-hcd: Fix locking/synchronization error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 616a63ff495df12863692ab3f9f7b84e3fa7a66d upstream.
Syzbot testing was able to provoke an addressing exception and crash in the usb_gadget_udc_reset() routine in drivers/usb/gadgets/udc/core.c, resulting from the fact that the routine was called with a second ("driver") argument of NULL. The bad caller was set_link_state() in dummy_hcd.c, and the problem arose because of a race between a USB reset and driver unbind.
These sorts of races were not supposed to be possible; commit 7dbd8f4cabd9 ("USB: dummy-hcd: Fix erroneous synchronization change"), along with a few followup commits, was written specifically to prevent them. As it turns out, there are (at least) two errors remaining in the code. Another patch will address the second error; this one is concerned with the first.
The error responsible for the syzbot crash occurred because the stop_activity() routine will sometimes drop and then re-acquire the dum->lock spinlock. A call to stop_activity() occurs in set_link_state() when handling an emulated USB reset, after the test of dum->ints_enabled and before the increment of dum->callback_usage. This allowed another thread (doing a driver unbind) to sneak in and grab the spinlock, and then clear dum->ints_enabled and dum->driver. Normally this other thread would have to wait for dum->callback_usage to go down to 0 before it would clear dum->driver, but in this case it didn't have to wait since dum->callback_usage had not yet been incremented.
The fix is to increment dum->callback_usage _before_ calling stop_activity() instead of after. Then the thread doing the unbind will not clear dum->driver until after the call to usb_gadget_udc_reset() safely returns and dum->callback_usage has been decremented again.
--- drivers/usb/gadget/udc/dummy_hcd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/dummy_hcd.c +6 -1
@@ -458,8 +458,13 @@ static void set_link_state(struct dummy_/* Report reset and disconnect events to the driver */ if (dum->ints_enabled && (disconnect || reset)) { -stop_activity (dum); ++dum->callback_usage; +/* +* stop_activity() can drop dum->lock, so it must +* not come between the dum->ints_enabled test +* and the ++dum->callback_usage. +*/ +stop_activity (dum);spin_unlock (&dum->lock);if (reset)usb_gadget_udc_reset (&dum->gadget, dum->driver);
Greg Kroah-Hartman
maintainerPATCH 490/570 USB: dummy-hcd: Fix interrupt synchronization error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit 2ca9e46f8f1f5a297eb0ac83f79d35d5b3a02541 upstream.
This fixes an error in synchronization in the dummy-hcd driver. The error has a somewhat involved history. The synchronization mechanism was introduced by commit 7dbd8f4cabd9 ("USB: dummy-hcd: Fix erroneous synchronization change"), which added an emulated "interrupts enabled" flag together with code emulating synchronize_irq() (it waits until all current handler callbacks have returned).
But the emulated interrupt-disable occurred too late, after the driver containing the handler callback routines had been told that it was unbound and no more callbacks would occur. Commit 4a5d797a9f9c ("usb:
gadget: dummy_hcd: fix gpf in gadget_setup") tried to fix this by moving the synchronize_irq() emulation code from dummy_stop() to dummy_pullup(), which runs before the unbind callback.
There still were races, though, because the emulated interrupt-disable still occurred too late. It couldn't be moved to dummy_pullup(), because that routine can be called for reasons other than an impending unbind. Therefore commits 7dc0c55e9f30 ("USB: UDC core: Add udc_async_callbacks gadget op") and 04145a03db9d ("USB: UDC: Implement udc_async_callbacks in dummy-hcd") added an API allowing the UDC core to tell dummy-hcd exactly when emulated interrupts and their callbacks should be disabled.
That brings us to the current state of things, which is still wrong because the emulated synchronize_irq() occurs before the emulated interrupt-disable! That's no good, beause it means that more emulated interrupts can occur after the synchronize_irq() emulation has run, leading to the possibility that a callback handler may be running when the gadget driver is unbound.
To fix this, we have to move the synchronize_irq() emulation code yet again, to the dummy_udc_async_callbacks() routine, which takes care of enabling and disabling emulated interrupt requests. The synchronization will now run immediately after emulated interrupts are disabled, which is where it belongs.
--- drivers/usb/gadget/udc/dummy_hcd.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +14 -15
@@ -909,21 +909,6 @@ static int dummy_pullup(struct usb_gadgespin_lock_irqsave (&dum->lock, flags); dum->pullup = (value !=0 );set_link_state (dum_hcd); -if (value ==0 ) { -/* -* Emulate synchronize_irq(): wait for callbacks to finish. -* This seems to be the best place to emulate the call to -* synchronize_irq() that's in usb_gadget_remove_driver(). -* Doing it in dummy_udc_stop() would be too late since it -* is called after the unbind callback and unbind shouldn't -* be invoked until all the other callbacks are finished. -*/ -while (dum->callback_usage >0 ) { -spin_unlock_irqrestore (&dum->lock, flags); -usleep_range (1000 ,2000 ); -spin_lock_irqsave (&dum->lock, flags); - } - }spin_unlock_irqrestore (&dum->lock, flags);usb_hcd_poll_rh_status (dummy_hcd_to_hcd (dum_hcd));
@@ -946,6 +931,20 @@ static void dummy_udc_async_callbacks(stspin_lock_irq (&dum->lock); dum->ints_enabled = enable; +if (!enable) { +/* +* Emulate synchronize_irq(): wait for callbacks to finish. +* This has to happen after emulated interrupts are disabled +* (dum->ints_enabled is clear) and before the unbind callback, +* just like the call to synchronize_irq() in +* gadget/udc/core:gadget_unbind_driver(). +*/ +while (dum->callback_usage >0 ) { +spin_unlock_irq (&dum->lock); +usleep_range (1000 ,2000 ); +spin_lock_irq (&dum->lock); + } + }spin_unlock_irq (&dum->lock); }
Greg Kroah-Hartman
maintainerPATCH 491/570 usb: gadget: dummy_hcd: fix premature URB completion when ZLP follows partial transfer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Urban <[email protected]>
commit f50200dd44125e445a6164e88c217472fa79cdbc upstream.
When a gadget request is only partially transferred in transfer() because the per-frame bandwidth budget is exhausted, the loop advances to the next queued request. If that next request is a zero-length packet (ZLP), len evaluates to zero and the code takes the unlikely(len == 0) path, which sets is_short = 1. This bypasses the bandwidth guard ("limit < ep->ep.maxpacket && limit < len") that lives in the else branch and would otherwise break out of the loop for non-zero requests. The is_short path then completes the URB before all data from the first request has been transferred.
Reproducer (bulk IN, high speed):
Device side (FunctionFS with Linux AIO):
1. Queue a 65024-byte write via io_submit (127 * 512, i.e. a multiple of the HS bulk max packet size).
2. Immediately queue a zero-length write (ZLP) via io_submit.
Host side:
3. Submit a 65536-byte bulk IN URB.
Expected: URB completes with actual_length = 65024.
Actual: URB completes with actual_length = 53248, losing 11776
bytes that leak into subsequent URBs.
At high speed the per-frame budget is 53248 bytes (512 * 13 * 8). The 65024-byte request exhausts this budget after 53248 bytes, leaving the request incomplete (req->req.actual < req->req.length). Neither the request nor the URB is finished, and rescan is 0, so the loop advances to the ZLP. For the ZLP, dev_len = 0, so len = min(12288, 0) = 0, taking the unlikely(len == 0) path and setting is_short = 1. The is_short handler then sets *status = 0, completing the URB with only 53248 of the expected 65024 bytes.
Fix this by breaking out of the loop when the current request has remaining data (req->req.actual < req->req.length). The request resumes on the next timer tick, preserving correct data ordering.
--- drivers/usb/gadget/udc/dummy_hcd.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/gadget/udc/dummy_hcd.c +6 -0
@@ -1531,6 +1531,12 @@ top:/* rescan to continue with any other queued i/o */ if (rescan) goto top; + +/* request not fully transferred; stop iterating to +* preserve data ordering across queued requests. +*/ +if (req->req.actual < req->req.length) +break ; }return sent; }
Greg Kroah-Hartman
maintainerPATCH 492/570 can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit 7352e1d5932a0e777e39fa4b619801191f57e603 ]
In gs_can_open(), the URBs for USB-in transfers are allocated, added to the parent->rx_submitted anchor and submitted. In the complete callback gs_usb_receive_bulk_callback(), the URB is processed and resubmitted. In gs_can_close() the URBs are freed by calling usb_kill_anchored_urbs(parent->rx_submitted).
However, this does not take into account that the USB framework unanchors the URB before the complete function is called. This means that once an in-URB has been completed, it is no longer anchored and is ultimately not released in gs_can_close().
Fix the memory leak by anchoring the URB in the gs_usb_receive_bulk_callback() to the parent->rx_submitted anchor.
[ The variable usbcan was renamed to parent in
commit b6980ad3a90c ("can: gs_usb: uniformly use "parent" as variable name for struct gs_usb") introduced in v6.6. To backport to v5.15, replace parent with usbcan. ]
--- drivers/net/can/usb/gs_usb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/can/usb/gs_usb.c +2 -0
@@ -402,6 +402,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)usbcan ); +usb_anchor_urb (urb, &usbcan->rx_submitted); + rc =usb_submit_urb (urb,GFP_ATOMIC );/* USB failure take down all interfaces */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 493/570 can: gs_usb: gs_usb_receive_bulk_callback(): unanchor URL on usb_submit_urb() error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit 79a6d1bfe1148bc921b8d7f3371a7fbce44e30f7 ]
In commit 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak"), the URB was re-anchored before usb_submit_urb() in gs_usb_receive_bulk_callback() to prevent a leak of this URB during cleanup.
However, this patch did not take into account that usb_submit_urb() could fail. The URB remains anchored and usb_kill_anchored_urbs(&parent->rx_submitted) in gs_can_close() loops infinitely since the anchor list never becomes empty.
To fix the bug, unanchor the URB when an usb_submit_urb() error occurs, also print an info message.
--- drivers/net/can/usb/gs_usb.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/can/usb/gs_usb.c +7 -0
@@ -405,6 +405,10 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)usb_anchor_urb (urb, &usbcan->rx_submitted); rc =usb_submit_urb (urb,GFP_ATOMIC ); +if (!rc) +return ; + +usb_unanchor_urb (urb);/* USB failure take down all interfaces */ if (rc == -ENODEV ) {
@@ -413,6 +417,9 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)if (usbcan->canch[rc])netif_device_detach (usbcan->canch[rc]->netdev); } + }else if (rc != -ESHUTDOWN &&net_ratelimit ()) { +netdev_info (netdev,"failed to re-submit IN URB: %pe\n" , +ERR_PTR (urb->status)); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 494/570 can: gs_usb: gs_usb_receive_bulk_callback(): fix error message
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit 494fc029f662c331e06b7c2031deff3c64200eed ]
Sinc commit 79a6d1bfe114 ("can: gs_usb: gs_usb_receive_bulk_callback():
unanchor URL on usb_submit_urb() error") a failing resubmit URB will print an info message.
In the case of a short read where netdev has not yet been assigned, initialize as NULL to avoid dereferencing an undefined value. Also report the error value of the failed resubmit.
--- drivers/net/can/usb/gs_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/gs_usb.c +2 -2
@@ -297,7 +297,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) {struct gs_usb *usbcan = urb->context;struct gs_can *dev; -struct net_device *netdev; +struct net_device *netdev =NULL ;int rc;struct net_device_stats *stats;struct gs_host_frame *hf = urb->transfer_buffer;
@@ -419,7 +419,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) } }else if (rc != -ESHUTDOWN &&net_ratelimit ()) {netdev_info (netdev,"failed to re-submit IN URB: %pe\n" , -ERR_PTR (urb->status)); +ERR_PTR (rc)); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 495/570 fbcon: Set fb_display[i]->mode to NULL when the mode is released
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quanmin Yan <[email protected]>
[ Upstream commit a1f3058930745d2b938b6b4f5bd9630dc74b26b7 ]
Recently, we discovered the following issue through syzkaller:
BUG: KASAN: slab-use-after-free in fb_mode_is_equal+0x285/0x2f0 Read of size 4 at addr ff11000001b3c69c by task syz.xxx ... Call Trace: <TASK> dump_stack_lvl+0xab/0xe0 print_address_description.constprop.0+0x2c/0x390 print_report+0xb9/0x280 kasan_report+0xb8/0xf0 fb_mode_is_equal+0x285/0x2f0 fbcon_mode_deleted+0x129/0x180 fb_set_var+0xe7f/0x11d0 do_fb_ioctl+0x6a0/0x750 fb_ioctl+0xe0/0x140 __x64_sys_ioctl+0x193/0x210 do_syscall_64+0x5f/0x9c0 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Based on experimentation and analysis, during framebuffer unregistration, only the memory of fb_info->modelist is freed, without setting the corresponding fb_display[i]->mode to NULL for the freed modes. This leads to UAF issues during subsequent accesses. Here's an example of reproduction steps:
1. With /dev/fb0 already registered in the system, load a kernel module to register a new device /dev/fb1;
2. Set fb1's mode to the global fb_display[] array (via FBIOPUT_CON2FBMAP);
3. Switch console from fb to VGA (to allow normal rmmod of the ko);
4. Unload the kernel module, at this point fb1's modelist is freed, leaving a wild pointer in fb_display[];
5. Trigger the bug via system calls through fb0 attempting to delete a mode from fb0.
Add a check in do_unregister_framebuffer(): if the mode to be freed exists in fb_display[], set the corresponding mode pointer to NULL.
[ The context change is due to the commit 2c0c19b681d5 ("fbdev: fbmem: Fix double free of 'fb_info->pixmap.addr'") in v5.16 which is irrelevant to the logic of this patch. ]
--- drivers/video/fbdev/core/fbcon.c | 20 ++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 2 ++ include/linux/fbcon.h | 2 ++ 3 files changed, 24 insertions(+)
drivers/video/fbdev/core/fbcon.c +20 -0
@@ -2797,6 +2797,26 @@ int fbcon_mode_deleted(struct fb_info *info,return found; } +static void fbcon_delete_mode (struct fb_videomode *m) +{ +struct fbcon_display *p; +int i; + +for (i = first_fb_vc; i <= last_fb_vc; i++) { + p = &fb_display[i]; +if (p->mode == m) + p->mode =NULL ; + } +} + +void fbcon_delete_modelist (struct list_head *head) +{ +struct fb_modelist *modelist; + +list_for_each_entry (modelist, head, list) +fbcon_delete_mode (&modelist->mode); +} +#ifdef CONFIG_VT_HW_CONSOLE_BINDING static void fbcon_unbind (void ) {
drivers/video/fbdev/core/fbmem.c +2 -0
@@ -1750,6 +1750,8 @@ static void do_unregister_framebuffer(struct fb_info *fb_info)if (fb_info->pixmap.addr && (fb_info->pixmap.flags &FB_PIXMAP_DEFAULT ))kfree (fb_info->pixmap.addr); + +fbcon_delete_modelist (&fb_info->modelist);fb_destroy_modelist (&fb_info->modelist); registered_fb[fb_info->node] =NULL ; num_registered_fb--;
include/linux/fbcon.h +2 -0
@@ -11,6 +11,7 @@ void fbcon_suspended(struct fb_info *info);void fbcon_resumed (struct fb_info *info);int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode); +void fbcon_delete_modelist (struct list_head *head);void fbcon_new_modelist (struct fb_info *info);void fbcon_get_requirement (struct fb_info *info,struct fb_blit_caps *caps);
@@ -31,6 +32,7 @@ static inline void fbcon_suspended(struct fb_info *info) {}static inline void fbcon_resumed (struct fb_info *info) {}static inline int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode) {return 0 ; } +static inline void fbcon_delete_modelist (struct list_head *head) {}static inline void fbcon_new_modelist (struct fb_info *info) {}static inline void fbcon_get_requirement (struct fb_info *info,struct fb_blit_caps *caps) {}
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 496/570 net: mctp: Dont access ifa_index when missing
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Johnston <[email protected]>
[ Upstream commit f11cf946c0a92c560a890d68e4775723353599e1 ]
In mctp_dump_addrinfo, ifa_index can be used to filter interfaces, but only when the struct ifaddrmsg is provided. Otherwise it will be comparing to uninitialised memory - reproducible in the syzkaller case from dhcpd, or busybox "ip addr show".
The kernel MCTP implementation has always filtered by ifa_index, so existing userspace programs expecting to dump MCTP addresses must already be passing a valid ifa_index value (either 0 or a real index).
BUG: KMSAN: uninit-value in mctp_dump_addrinfo+0x208/0xac0 net/mctp/device.c:128 mctp_dump_addrinfo+0x208/0xac0 net/mctp/device.c:128 rtnl_dump_all+0x3ec/0x5b0 net/core/rtnetlink.c:4380 rtnl_dumpit+0xd5/0x2f0 net/core/rtnetlink.c:6824 netlink_dump+0x97b/0x1690 net/netlink/af_netlink.c:2309
[ The context change is due to the commit 2d45eeb7d5d7 ("mctp: no longer rely on net->dev_index_head[]") in v6.14 which is irrelevant to the logic of this patch. ]
--- net/mctp/device.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
net/mctp/device.c +13 -6
@@ -99,12 +99,19 @@ static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb)struct net_device *dev;struct ifaddrmsg *hdr;struct mctp_dev *mdev; -int ifindex; -int idx, rc; - - hdr =nlmsg_data (cb->nlh); -// filter by ifindex if requested - ifindex = hdr->ifa_index; +int idx; +int ifindex =0 , rc; + +/* Filter by ifindex if a header is provided */ +if (cb->nlh->nlmsg_len >=nlmsg_msg_size (sizeof (*hdr))) { + hdr =nlmsg_data (cb->nlh); + ifindex = hdr->ifa_index; + }else { +if (cb->strict_check) { +NL_SET_ERR_MSG (cb->extack,"mctp: Invalid header for addr dump request" ); +return -EINVAL ; + } + }rcu_read_lock ();for (; mcb->h <NETDEV_HASHENTRIES ; mcb->h++, mcb->idx =0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 497/570 smb: client: Fix refcount leak for cifs_sb_tlink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhao Fu <[email protected]>
[ Upstream commit c2b77f42205ef485a647f62082c442c1cd69d3fc ]
Fix three refcount inconsistency issues related to cifs_sb_tlink.
Comments for cifs_sb_tlink state that cifs_put_tlink() needs to be called after successful calls to cifs_sb_tlink(). Three calls fail to update refcount accordingly, leading to possible resource leaks.
--- fs/cifs/inode.c | 6 ++++-- fs/cifs/smb2ops.c | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-)
fs/cifs/inode.c +4 -2
@@ -2023,8 +2023,10 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, tcon =tlink_tcon (tlink); server = tcon->ses->server; -if (!server->ops->rename) -return -ENOSYS ; +if (!server->ops->rename) { + rc = -ENOSYS ; + goto do_rename_exit; + }/* try path-based rename first */ rc = server->ops->rename (xid, tcon, from_path, to_path, cifs_sb);
fs/cifs/smb2ops.c +4 -4
@@ -3437,8 +3437,7 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, utf16_path =cifs_convert_path_to_utf16 (path, cifs_sb);if (!utf16_path) { rc = -ENOMEM ; -free_xid (xid); -return ERR_PTR (rc); + goto put_tlink; } oparms.tcon = tcon;
@@ -3466,6 +3465,7 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid); } +put_tlink:cifs_put_tlink (tlink);free_xid (xid);
@@ -3506,8 +3506,7 @@ set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen, utf16_path =cifs_convert_path_to_utf16 (path, cifs_sb);if (!utf16_path) { rc = -ENOMEM ; -free_xid (xid); -return rc; + goto put_tlink; } oparms.tcon = tcon;
@@ -3527,6 +3526,7 @@ set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid); } +put_tlink:cifs_put_tlink (tlink);free_xid (xid);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 498/570 staging: rtl8723bs: fix out-of-bounds read in rtw_get_ie() parser
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Navaneeth K <[email protected]>
[ Upstream commit 154828bf9559b9c8421fc2f0d7f7f76b3683aaed ]
The Information Element (IE) parser rtw_get_ie() trusted the length byte of each IE without validating that the IE body (len bytes after the 2-byte header) fits inside the remaining frame buffer. A malformed frame can advertise an IE length larger than the available data, causing the parser to increment its pointer beyond the buffer end. This results in out-of-bounds reads or, depending on the pattern, an infinite loop.
Fix by validating that (offset + 2 + len) does not exceed the limit before accepting the IE or advancing to the next element.
This prevents OOB reads and ensures the parser terminates safely on malformed frames.
[ The context change is due to the commit 4610e57a7d2e ("staging: rtl8723bs: Remove redundant else branches.") in v5.19 which is irrelevant to the logic of this patch. ]
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +7 -6
@@ -141,23 +141,24 @@ u8 *rtw_get_ie(u8 *pbuf, signed int index, signed int *len, signed int limit)signed int tmp, i;u8 *p; -if (limit <1 ) +if (limit <2 )return NULL ; p = pbuf; i =0 ; *len =0 ; -while (1 ) { +while (i +2 <= limit) { + tmp = *(p +1 ); +if (i +2 + tmp > limit) +break ; +if (*p == index) { - *len = *(p +1 ); + *len = tmp;return p; }else { - tmp = *(p +1 ); p += (tmp +2 ); i += (tmp +2 ); } -if (i >= limit) -break ; }return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 499/570 usb: gadget: f_subset: Fix unbalanced refcnt in geth_free
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuen-Han Tsai <[email protected]>
commit caa27923aacd8a5869207842f2ab1657c6c0c7bc upstream.
geth_alloc() increments the reference count, but geth_free() fails to decrement it. This prevents the configuration of attributes via configfs after unlinking the function.
Decrement the reference count in geth_free() to ensure proper cleanup.
--- drivers/usb/gadget/function/f_subset.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/usb/gadget/function/f_subset.c +7 -0
@@ -6,6 +6,7 @@* Copyright (C) 2008 Nokia Corporation */ +#include <linux/cleanup.h> #include <linux/slab.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -451,8 +452,14 @@ static struct usb_function_instance *getstatic void geth_free (struct usb_function *f) {struct f_gether *eth; +struct f_gether_opts *opts; + + opts = container_of(f->fi, struct f_gether_opts, func_inst); eth =func_to_geth (f); +mutex_lock (&opts->lock); + opts->refcnt--; +mutex_unlock (&opts->lock);kfree (eth); }
Greg Kroah-Hartman
maintainerPATCH 500/570 usb: gadget: f_rndis: Protect RNDIS options with mutex
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuen-Han Tsai <[email protected]>
commit 8d8c68b1fc06ece60cf43e1306ff0f4ac121547e upstream.
The class/subclass/protocol options are suspectible to race conditions as they can be accessed concurrently through configfs.
Use existing mutex to protect these options. This issue was identified during code inspection.
--- drivers/usb/gadget/function/f_rndis.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/gadget/function/f_rndis.c +3 -0
@@ -11,6 +11,7 @@/* #define VERBOSE_DEBUG */ +#include <linux/cleanup.h> #include <linux/slab.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -690,9 +691,11 @@ rndis_bind(struct usb_configuration *c, f->os_desc_table[0 ].os_desc = &rndis_opts->rndis_os_desc; } +mutex_lock (&rndis_opts->lock); rndis_iad_descriptor.bFunctionClass = rndis_opts->class; rndis_iad_descriptor.bFunctionSubClass = rndis_opts->subclass; rndis_iad_descriptor.bFunctionProtocol = rndis_opts->protocol; +mutex_unlock (&rndis_opts->lock);/* * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
Greg Kroah-Hartman
maintainerPATCH 501/570 usb: gadget: f_uac1_legacy: validate control request size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Taegu Ha <[email protected]>
commit 6e0e34d85cd46ceb37d16054e97a373a32770f6c upstream.
f_audio_complete() copies req->length bytes into a 4-byte stack variable:
u32 data = 0; memcpy(&data, req->buf, req->length);
req->length is derived from the host-controlled USB request path, which can lead to a stack out-of-bounds write.
Validate req->actual against the expected payload size for the supported control selectors and decode only the expected amount of data.
This avoids copying a host-influenced length into a fixed-size stack object.
--- drivers/usb/gadget/function/f_uac1_legacy.c | 47 ++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-)
drivers/usb/gadget/function/f_uac1_legacy.c +37 -10
@@ -360,19 +360,46 @@ static int f_audio_out_ep_complete(strucstatic void f_audio_complete (struct usb_ep *ep,struct usb_request *req) {struct f_audio *audio = req->context; -int status = req->status; -u32 data =0 ;struct usb_ep *out_ep = audio->out_ep; -switch (status) { - -case 0 :/* normal completion? */ -if (ep == out_ep) +switch (req->status) { +case 0 : +if (ep == out_ep) {f_audio_out_ep_complete (ep, req); -else if (audio->set_con) { -memcpy (&data, req->buf, req->length); - audio->set_con->set (audio->set_con, audio->set_cmd, -le16_to_cpu (data)); + }else if (audio->set_con) { +struct usb_audio_control *con = audio->set_con; +u8 type = con->type; +u32 data; +bool valid_request = false; + +switch (type) { +case UAC_FU_MUTE : { +u8 value; + +if (req->actual ==sizeof (value)) { +memcpy (&value, req->buf,sizeof (value)); + data = value; + valid_request = true; + } +break ; + } +case UAC_FU_VOLUME : { +__le16 value; + +if (req->actual ==sizeof (value)) { +memcpy (&value, req->buf,sizeof (value)); + data =le16_to_cpu (value); + valid_request = true; + } +break ; + } + } + +if (valid_request) + con->set (con, audio->set_cmd, data); +else +usb_ep_set_halt (ep); + audio->set_con =NULL ; }break ;
Greg Kroah-Hartman
maintainerPATCH 502/570 io_uring/tctx: work around xa_store() allocation error issue
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
commit 7eb75ce7527129d7f1fee6951566af409a37a1c4 upstream.
syzbot triggered the following WARN_ON:
WARNING: CPU: 0 PID: 16 at io_uring/tctx.c:51 __io_uring_free+0xfa/0x140 io_uring/tctx.c:51
which is the
WARN_ON_ONCE(!xa_empty(&tctx->xa));
sanity check in __io_uring_free() when a io_uring_task is going through its final put. The syzbot test case includes injecting memory allocation failures, and it very much looks like xa_store() can fail one of its memory allocations and end up with ->head being non-NULL even though no entries exist in the xarray.
Until this issue gets sorted out, work around it by attempting to iterate entries in our xarray, and WARN_ON_ONCE() if one is found.
--- io_uring/io_uring.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
io_uring/io_uring.c +12 -1
@@ -8699,8 +8699,19 @@ static int io_uring_alloc_task_context(svoid __io_uring_free (struct task_struct *tsk) {struct io_uring_task *tctx = tsk->io_uring; +struct io_tctx_node *node; +unsigned long index; -WARN_ON_ONCE (!xa_empty (&tctx->xa)); +/* +* Fault injection forcing allocation errors in the xa_store() path +* can lead to xa_empty() returning false, even though no actual +* node is stored in the xarray. Until that gets sorted out, attempt +* an iteration here and warn if any entries are found. +*/ +xa_for_each (&tctx->xa, index, node) { +WARN_ON_ONCE (1 ); +break ; + }WARN_ON_ONCE (tctx->io_wq);WARN_ON_ONCE (tctx->cached_refs);
Greg Kroah-Hartman
maintainerPATCH 503/570 wifi: virt_wifi: remove SET_NETDEV_DEV to avoid use-after-free
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Popov <[email protected]>
commit 789b06f9f39cdc7e895bdab2c034e39c41c8f8d6 upstream.
Currently we execute SET_NETDEV_DEV(dev, &priv->lowerdev->dev) for the virt_wifi net devices. However, unregistering a virt_wifi device in netdev_run_todo() can happen together with the device referenced by SET_NETDEV_DEV().
It can result in use-after-free during the ethtool operations performed on a virt_wifi device that is currently being unregistered. Such a net device can have the dev.parent field pointing to the freed memory, but ethnl_ops_begin() calls pm_runtime_get_sync(dev->dev.parent).
Let's remove SET_NETDEV_DEV for virt_wifi to avoid bugs like this:
==================================================================
BUG: KASAN: slab-use-after-free in __pm_runtime_resume+0xe2/0xf0 Read of size 2 at addr ffff88810cfc46f8 by task pm/606 Call Trace: <TASK> dump_stack_lvl+0x4d/0x70 print_report+0x170/0x4f3 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 kasan_report+0xda/0x110 ? __pm_runtime_resume+0xe2/0xf0 ? __pm_runtime_resume+0xe2/0xf0 __pm_runtime_resume+0xe2/0xf0 ethnl_ops_begin+0x49/0x270 ethnl_set_features+0x23c/0xab0 ? __pfx_ethnl_set_features+0x10/0x10 ? kvm_sched_clock_read+0x11/0x20 ? local_clock_noinstr+0xf/0xf0 ? local_clock+0x10/0x30 ? kasan_save_track+0x25/0x60 ? __kasan_kmalloc+0x7f/0x90 ? genl_family_rcv_msg_attrs_parse.isra.0+0x150/0x2c0 genl_family_rcv_msg_doit+0x1e7/0x2c0 ? __pfx_genl_family_rcv_msg_doit+0x10/0x10 ? __pfx_cred_has_capability.isra.0+0x10/0x10 ? stack_trace_save+0x8e/0xc0 genl_rcv_msg+0x411/0x660 ? __pfx_genl_rcv_msg+0x10/0x10 ? __pfx_ethnl_set_features+0x10/0x10 netlink_rcv_skb+0x121/0x380 ? __pfx_genl_rcv_msg+0x10/0x10 ? __pfx_netlink_rcv_skb+0x10/0x10 ? __pfx_down_read+0x10/0x10 genl_rcv+0x23/0x30 netlink_unicast+0x60f/0x830 ? __pfx_netlink_unicast+0x10/0x10 ? __pfx___alloc_skb+0x10/0x10 netlink_sendmsg+0x6ea/0xbc0 ? __pfx_netlink_sendmsg+0x10/0x10 ? __futex_queue+0x10b/0x1f0 ____sys_sendmsg+0x7a2/0x950 ? copy_msghdr_from_user+0x26b/0x430 ? __pfx_____sys_sendmsg+0x10/0x10 ? __pfx_copy_msghdr_from_user+0x10/0x10 ___sys_sendmsg+0xf8/0x180 ? __pfx____sys_sendmsg+0x10/0x10 ? __pfx_futex_wait+0x10/0x10 ? fdget+0x2e4/0x4a0 __sys_sendmsg+0x11f/0x1c0 ? __pfx___sys_sendmsg+0x10/0x10 do_syscall_64+0xe2/0x570 ? exc_page_fault+0x66/0xb0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
This fix may be combined with another one in the ethtool subsystem:
https://lore.kernel.org/all/[email protected]/T/#u
--- drivers/net/wireless/virt_wifi.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/wireless/virt_wifi.c +0 -1
@@ -553,7 +553,6 @@ static int virt_wifi_newlink(struct neteth_hw_addr_inherit (dev, priv->lowerdev);netif_stacked_transfer_operstate (priv->lowerdev, dev); -SET_NETDEV_DEV (dev, &priv->lowerdev->dev); dev->ieee80211_ptr =kzalloc (sizeof (*dev->ieee80211_ptr),GFP_KERNEL );if (!dev->ieee80211_ptr) {
Greg Kroah-Hartman
maintainerPATCH 504/570 ACPI: EC: Evaluate orphan _REG under EC device
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
commit 0e6b6dedf16800df0ff73ffe2bb5066514db29c2 upstream.
After starting to install the EC address space handler at the ACPI namespace root, if there is an "orphan" _REG method in the EC device's scope, it will not be evaluated any more. This breaks EC operation regions on some systems, like Asus gu605.
To address this, use a wrapper around an existing ACPICA function to look for an "orphan" _REG method in the EC device scope and evaluate it if present.
--- drivers/acpi/acpica/acevents.h | 4 +++ drivers/acpi/acpica/evregion.c | 6 ---- drivers/acpi/acpica/evxfregn.c | 54 +++++++++++++++++++++++++++++++++++++++++ drivers/acpi/ec.c | 3 ++ include/acpi/acpixf.h | 4 +++ 5 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/acpica/acevents.h +4 -0
@@ -191,6 +191,10 @@ void acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, acpi_adr_space_type space_id, u32 function); +void +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *node, +acpi_adr_space_type space_id); +acpi_status acpi_ev_execute_reg_method (union acpi_operand_object *region_obj,u32 function);
drivers/acpi/acpica/evregion.c +1 -5
@@ -20,10 +20,6 @@ extern u8 acpi_gbl_default_address_space/* Local prototypes */ -static void -acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, -acpi_adr_space_type space_id); -static acpi_status acpi_ev_reg_run (acpi_handle obj_handle,u32 level,void *context,void **return_value);
@@ -799,7 +795,7 @@ acpi_ev_reg_run(acpi_handle obj_handle,* ******************************************************************************/ -static void +void acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node,acpi_adr_space_type space_id) {
drivers/acpi/acpica/evxfregn.c +54 -0
57 lines not on this page · raw message
drivers/acpi/ec.c +3 -0
@@ -1521,6 +1521,9 @@ static int ec_install_handlers(struct acif (call_reg && !test_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags)) {acpi_execute_reg_methods (scope_handle,ACPI_ADR_SPACE_EC ); +if (scope_handle != ec->handle) +acpi_execute_orphan_reg_method (ec->handle,ACPI_ADR_SPACE_EC ); +set_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags); }
include/acpi/acpixf.h +4 -0
@@ -661,6 +661,10 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_adr_space_type space_id)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status + acpi_execute_orphan_reg_method(acpi_handle device, + acpi_adr_space_type + space_id)) +ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_remove_address_space_handler(acpi_handle device, acpi_adr_space_type
Greg Kroah-Hartman
maintainerPATCH 505/570 lib/crypto: chacha: Zeroize permuted_state before it leaves scope
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit e5046823f8fa3677341b541a25af2fcb99a5b1e0 upstream.
Since the ChaCha permutation is invertible, the local variable 'permuted_state' is sufficient to compute the original 'state', and thus the key, even after the permutation has been done.
While the kernel is quite inconsistent about zeroizing secrets on the stack (and some prominent userspace crypto libraries don't bother at all since it's not guaranteed to work anyway), the kernel does try to do it as a best practice, especially in cases involving the RNG.
Thus, explicitly zeroize 'permuted_state' before it goes out of scope.
--- lib/crypto/chacha.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/crypto/chacha.c +4 -0
@@ -86,6 +86,8 @@ void chacha_block_generic(u32 *state, u8put_unaligned_le32 (x[i] + state[i], &stream[i *sizeof (u32)]); state[12 ]++; + +memzero_explicit (x,sizeof (x)); }EXPORT_SYMBOL (chacha_block_generic);
@@ -110,5 +112,7 @@ void hchacha_block_generic(const u32 *stmemcpy (&stream[0 ], &x[0 ],16 );memcpy (&stream[4 ], &x[12 ],16 ); + +memzero_explicit (x,sizeof (x)); }EXPORT_SYMBOL (hchacha_block_generic);
Greg Kroah-Hartman
maintainerPATCH 506/570 wifi: rt2x00usb: fix devres lifetime
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 25369b22223d1c56e42a0cd4ac9137349d5a898e upstream.
USB drivers bind to USB interfaces and any device managed resources should have their lifetime tied to the interface rather than parent USB device. This avoids issues like memory leaks when drivers are unbound without their devices being physically disconnected (e.g. on probe deferral or configuration changes).
Fix the USB anchor lifetime so that it is released on driver unbind.
--- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1 -1
@@ -830,7 +830,7 @@ int rt2x00usb_probe(struct usb_interfaceif (retval) goto exit_free_device; - rt2x00dev->anchor =devm_kmalloc (&usb_dev->dev, + rt2x00dev->anchor =devm_kmalloc (&usb_intf->dev,sizeof (struct usb_anchor ),GFP_KERNEL );if (!rt2x00dev->anchor) {
Greg Kroah-Hartman
maintainerPATCH 507/570 xfrm_user: fix info leak in build_report()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit d10119968d0e1f2b669604baf2a8b5fdb72fa6b4 upstream.
struct xfrm_user_report is a __u8 proto field followed by a struct xfrm_selector which means there is three "empty" bytes of padding, but the padding is never zeroed before copying to userspace. Fix that up by zeroing the structure before setting individual member variables.
--- net/xfrm/xfrm_user.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_user.c +1 -0
@@ -3544,6 +3544,7 @@ static int build_report(struct sk_buff *return -EMSGSIZE ; ur =nlmsg_data (nlh); +memset (ur,0 ,sizeof (*ur)); ur->proto = proto;memcpy (&ur->sel, sel,sizeof (ur->sel));
Greg Kroah-Hartman
maintainerPATCH 508/570 mptcp: fix slab-use-after-free in __inet_lookup_established
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
commit 9b55b253907e7431210483519c5ad711a37dafa1 upstream.
The ehash table lookups are lockless and rely on SLAB_TYPESAFE_BY_RCU to guarantee socket memory stability during RCU read-side critical sections. Both tcp_prot and tcpv6_prot have their slab caches created with this flag via proto_register().
However, MPTCP's mptcp_subflow_init() copies tcpv6_prot into tcpv6_prot_override during inet_init() (fs_initcall, level 5), before inet6_init() (module_init/device_initcall, level 6) has called proto_register(&tcpv6_prot). At that point, tcpv6_prot.slab is still NULL, so tcpv6_prot_override.slab remains NULL permanently.
This causes MPTCP v6 subflow child sockets to be allocated via kmalloc (falling into kmalloc-4k) instead of the TCPv6 slab cache. The kmalloc-4k cache lacks SLAB_TYPESAFE_BY_RCU, so when these sockets are freed without SOCK_RCU_FREE (which is cleared for child sockets by design), the memory can be immediately reused. Concurrent ehash lookups under rcu_read_lock can then access freed memory, triggering a slab-use-after-free in __inet_lookup_established.
Fix this by splitting the IPv6-specific initialization out of mptcp_subflow_init() into a new mptcp_subflow_v6_init(), called from mptcp_proto_v6_init() before protocol registration. This ensures tcpv6_prot_override.slab correctly inherits the SLAB_TYPESAFE_BY_RCU slab cache.
--- net/mptcp/protocol.c | 2 ++ net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 15 +++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +2 -0
@@ -3790,6 +3790,8 @@ int __init mptcp_proto_v6_init(void) {int err; +mptcp_subflow_v6_init (); + mptcp_v6_prot = mptcp_prot;strcpy (mptcp_v6_prot.name,"MPTCPv6" ); mptcp_v6_prot.slab =NULL ;
net/mptcp/protocol.h +1 -0
@@ -646,6 +646,7 @@ static inline bool mptcp_has_another_subvoid __init mptcp_proto_init (void );#if IS_ENABLED (CONFIG_MPTCP_IPV6 )int __init mptcp_proto_v6_init (void ); +void __init mptcp_subflow_v6_init (void );#endif struct sock *mptcp_sk_clone(const struct sock *sk,
net/mptcp/subflow.c +9 -6
@@ -1859,7 +1859,15 @@ void __init mptcp_subflow_init(void) tcp_prot_override.psock_update_sk_prot =NULL ;#endif +mptcp_diag_subflow_init (&subflow_ulp_ops); + +if (tcp_register_ulp (&subflow_ulp_ops) !=0 ) +panic ("MPTCP: failed to register subflows to ULP\n" ); +} +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +void __init mptcp_subflow_v6_init (void ) +{/* In struct mptcp_subflow_request_sock, we assume the TCP request sock * structures for v4 and v6 have the same size. It should not changed in * the future but better to make sure to be warned if it is no longer
@@ -1895,10 +1903,5 @@ void __init mptcp_subflow_init(void)/* Disable sockmap processing for subflows */ tcpv6_prot_override.psock_update_sk_prot =NULL ; #endif -#endif - -mptcp_diag_subflow_init (&subflow_ulp_ops); - -if (tcp_register_ulp (&subflow_ulp_ops) !=0 ) -panic ("MPTCP: failed to register subflows to ULP\n" ); } +#endif
Greg Kroah-Hartman
maintainerPATCH 509/570 Input: uinput - fix circular locking dependency with ff-core
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Gavrilov <[email protected]>
commit 4cda78d6f8bf2b700529f2fbccb994c3e826d7c2 upstream.
A lockdep circular locking dependency warning can be triggered reproducibly when using a force-feedback gamepad with uinput (for example, playing ELDEN RING under Wine with a Flydigi Vader 5 controller):
ff->mutex -> udev->mutex -> input_mutex -> dev->mutex -> ff->mutex
The cycle is caused by four lock acquisition paths:
1. ff upload: input_ff_upload() holds ff->mutex and calls uinput_dev_upload_effect() -> uinput_request_submit() -> uinput_request_send(), which acquires udev->mutex.
2. device create: uinput_ioctl_handler() holds udev->mutex and calls uinput_create_device() -> input_register_device(), which acquires input_mutex.
3. device register: input_register_device() holds input_mutex and calls kbd_connect() -> input_register_handle(), which acquires dev->mutex.
4. evdev release: evdev_release() calls input_flush_device() under dev->mutex, which calls input_ff_flush() acquiring ff->mutex.
Fix this by introducing a new state_lock spinlock to protect udev->state and udev->dev access in uinput_request_send() instead of acquiring udev->mutex. The function only needs to atomically check device state and queue an input event into the ring buffer via uinput_dev_event() -- both operations are safe under a spinlock (ktime_get_ts64() and wake_up_interruptible() do not sleep). This breaks the ff->mutex -> udev->mutex link since a spinlock is a leaf in the lock ordering and cannot form cycles with mutexes.
To keep state transitions visible to uinput_request_send(), protect writes to udev->state in uinput_create_device() and uinput_destroy_device() with the same state_lock spinlock.
Additionally, move init_completion(&request->done) from uinput_request_send() to uinput_request_submit() before uinput_request_reserve_slot(). Once the slot is allocated, uinput_flush_requests() may call complete() on it at any time from the destroy path, so the completion must be initialised before the request becomes visible.
Lock ordering after the fix:
ff->mutex -> state_lock (spinlock, leaf)
udev->mutex -> state_lock (spinlock, leaf)
udev->mutex -> input_mutex -> dev->mutex -> ff->mutex (no back-edge)
--- drivers/input/misc/uinput.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/input/misc/uinput.c +21 -7
@@ -56,6 +56,7 @@ struct uinput_device {struct input_dev *dev;struct mutex mutex;enum uinput_state state; +spinlock_t state_lock;wait_queue_head_t waitq;unsigned char ready;unsigned char head;
@@ -145,19 +146,15 @@ static void uinput_request_release_slot(static int uinput_request_send (struct uinput_device *udev,struct uinput_request *request) { -int retval; +int retval =0 ; - retval =mutex_lock_interruptible (&udev->mutex); -if (retval) -return retval; +spin_lock (&udev->state_lock);if (udev->state !=UIST_CREATED ) { retval = -ENODEV ; goto out; } -init_completion (&request->done); -/* * Tell our userspace application about this new request * by queueing an input event.
@@ -165,7 +162,7 @@ static int uinput_request_send(struct uiuinput_dev_event (udev->dev,EV_UINPUT , request->code, request->id); out: -mutex_unlock (&udev->mutex); +spin_unlock (&udev->state_lock);return retval; }
@@ -174,6 +171,13 @@ static int uinput_request_submit(struct {int retval; +/* +* Initialize completion before allocating the request slot. +* Once the slot is allocated, uinput_flush_requests() may +* complete it at any time, so it must be initialized first. +*/ +init_completion (&request->done); + retval =uinput_request_reserve_slot (udev, request);if (retval)return retval;
@@ -288,7 +292,14 @@ static void uinput_destroy_device(structstruct input_dev *dev = udev->dev;enum uinput_state old_state = udev->state; +/* +* Update state under state_lock so that concurrent +* uinput_request_send() sees the state change before we +* flush pending requests and tear down the device. +*/ +spin_lock (&udev->state_lock); udev->state =UIST_NEW_DEVICE ; +spin_unlock (&udev->state_lock);if (dev) { name = dev->name;
@@ -365,7 +376,9 @@ static int uinput_create_device(struct uif (error) goto fail2; +spin_lock (&udev->state_lock); udev->state =UIST_CREATED ; +spin_unlock (&udev->state_lock);return 0 ;
@@ -383,6 +396,7 @@ static int uinput_open(struct inode *inoreturn -ENOMEM ;mutex_init (&newdev->mutex); +spin_lock_init (&newdev->state_lock);spin_lock_init (&newdev->requests_lock);init_waitqueue_head (&newdev->requests_waitq);init_waitqueue_head (&newdev->waitq);
Greg Kroah-Hartman
maintainerPATCH 510/570 Input: uinput - take event lock when submitting FF request "event"
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit ff14dafde15c11403fac61367a34fea08926e9ee upstream.
To avoid racing with FF playback events and corrupting device's event queue take event_lock spinlock when calling uinput_dev_event() when submitting a FF upload or erase "event".
--- drivers/input/misc/uinput.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/misc/uinput.c +7 -0
@@ -25,8 +25,10 @@#include <linux/module.h> #include <linux/init.h> #include <linux/fs.h> +#include <linux/lockdep.h> #include <linux/miscdevice.h> #include <linux/overflow.h> +#include <linux/spinlock.h> #include <linux/input/mt.h> #include "../input-compat.h"
@@ -75,6 +77,8 @@ static int uinput_dev_event(struct inputstruct uinput_device *udev =input_get_drvdata (dev);struct timespec64 ts; +lockdep_assert_held (&dev->event_lock); +ktime_get_ts64 (&ts); udev->buff[udev->head] = (struct input_event ) {
@@ -146,6 +150,7 @@ static void uinput_request_release_slot(static int uinput_request_send (struct uinput_device *udev,struct uinput_request *request) { +unsigned long flags;int retval =0 ;spin_lock (&udev->state_lock);
@@ -159,7 +164,9 @@ static int uinput_request_send(struct ui* Tell our userspace application about this new request * by queueing an input event. */ +spin_lock_irqsave (&udev->dev->event_lock, flags);uinput_dev_event (udev->dev,EV_UINPUT , request->code, request->id); +spin_unlock_irqrestore (&udev->dev->event_lock, flags); out:spin_unlock (&udev->state_lock);
Greg Kroah-Hartman
maintainerPATCH 511/570 media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thadeu Lima de Souza Cascardo <[email protected]>
[ Upstream commit 0e2ee70291e64a30fe36960c85294726d34a103e ]
Per UVC 1.1+ specification 3.7.2, units and terminals must have a non-zero unique ID.
``` Each Unit and Terminal within the video function is assigned a unique identification number, the Unit ID (UID) or Terminal ID (TID), contained in the bUnitID or bTerminalID field of the descriptor. The value 0x00 is reserved for undefined ID, ```
If we add a new entity with id 0 or a duplicated ID, it will be marked as UVC_INVALID_ENTITY_ID.
In a previous attempt commit 3dd075fe8ebb ("media: uvcvideo: Require entities to have a non-zero unique ID"), we ignored all the invalid units, this broke a lot of non-compatible cameras. Hopefully we are more lucky this time.
This also prevents some syzkaller reproducers from triggering warnings due to a chain of entities referring to themselves. In one particular case, an Output Unit is connected to an Input Unit, both with the same ID of 1. But when looking up for the source ID of the Output Unit, that same entity is found instead of the input entity, which leads to such warnings.
In another case, a backward chain was considered finished as the source ID was 0. Later on, that entity was found, but its pads were not valid.
Here is a sample stack trace for one of those cases.
[ 20.650953] usb 1-1: new high-speed USB device number 2 using dummy_hcd [ 20.830206] usb 1-1: Using ep0 maxpacket: 8 [ 20.833501] usb 1-1: config 0 descriptor?? [ 21.038518] usb 1-1: string descriptor 0 read error: -71 [ 21.038893] usb 1-1: Found UVC 0.00 device <unnamed> (2833:0201) [ 21.039299] uvcvideo 1-1:0.0: Entity type for entity Output 1 was not initialized! [ 21.041583] uvcvideo 1-1:0.0: Entity type for entity Input 1 was not initialized! [ 21.042218] ------------[ cut here ]------------ [ 21.042536] WARNING: CPU: 0 PID: 9 at drivers/media/mc/mc-entity.c:1147 media_create_pad_link+0x2c4/0x2e0 [ 21.043195] Modules linked in: [ 21.043535] CPU: 0 UID: 0 PID: 9 Comm: kworker/0:1 Not tainted 6.11.0-rc7-00030-g3480e43aeccf #444 [ 21.044101] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 21.044639] Workqueue: usb_hub_wq hub_event [ 21.045100] RIP: 0010:media_create_pad_link+0x2c4/0x2e0 [ 21.045508] Code: fe e8 20 01 00 00 b8 f4 ff ff ff 48 83 c4 30 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc 0f 0b eb e9 0f 0b eb 0a 0f 0b eb 06 <0f> 0b eb 02 0f 0b b8 ea ff ff ff eb d4 66 2e 0f 1f 84 00 00 00 00 [ 21.046801] RSP: 0018:ffffc9000004b318 EFLAGS: 00010246 [ 21.047227] RAX: ffff888004e5d458 RBX: 0000000000000000 RCX: ffffffff818fccf1 [ 21.047719] RDX: 000000000000007b RSI: 0000000000000000 RDI: ffff888004313290 [ 21.048241] RBP: ffff888004313290 R08: 0001ffffffffffff R09: 0000000000000000 [ 21.048701] R10: 0000000000000013 R11: 0001888004313290 R12: 0000000000000003 [ 21.049138] R13: ffff888004313080 R14: ffff888004313080 R15: 0000000000000000 [ 21.049648] FS: 0000000000000000(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 [ 21.050271] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.050688] CR2: 0000592cc27635b0 CR3: 000000000431c000 CR4: 0000000000750ef0 [ 21.051136] PKRU: 55555554 [ 21.051331] Call Trace: [ 21.051480] <TASK> [ 21.051611] ? __warn+0xc4/0x210 [ 21.051861] ? media_create_pad_link+0x2c4/0x2e0 [ 21.052252] ? report_bug+0x11b/0x1a0 [ 21.052540] ? trace_hardirqs_on+0x31/0x40 [ 21.052901] ? handle_bug+0x3d/0x70 [ 21.053197] ? exc_invalid_op+0x1a/0x50 [ 21.053511] ? asm_exc_invalid_op+0x1a/0x20 [ 21.053924] ? media_create_pad_link+0x91/0x2e0 [ 21.054364] ? media_create_pad_link+0x2c4/0x2e0 [ 21.054834] ? media_create_pad_link+0x91/0x2e0 [ 21.055131] ? _raw_spin_unlock+0x1e/0x40 [ 21.055441] ? __v4l2_device_register_subdev+0x202/0x210 [ 21.055837] uvc_mc_register_entities+0x358/0x400 [ 21.056144] uvc_register_chains+0x1fd/0x290 [ 21.056413] uvc_probe+0x380e/0x3dc0 [ 21.056676] ? __lock_acquire+0x5aa/0x26e0 [ 21.056946] ? find_held_lock+0x33/0xa0 [ 21.057196] ? kernfs_activate+0x70/0x80 [ 21.057533] ? usb_match_dynamic_id+0x1b/0x70 [ 21.057811] ? find_held_lock+0x33/0xa0 [ 21.058047] ? usb_match_dynamic_id+0x55/0x70 [ 21.058330] ? lock_release+0x124/0x260 [ 21.058657] ? usb_match_one_id_intf+0xa2/0x100 [ 21.058997] usb_probe_interface+0x1ba/0x330 [ 21.059399] really_probe+0x1ba/0x4c0 [ 21.059662] __driver_probe_device+0xb2/0x180 [ 21.059944] driver_probe_device+0x5a/0x100 [ 21.060170] __device_attach_driver+0xe9/0x160 [ 21.060427] ? __pfx___device_attach_driver+0x10/0x10 [ 21.060872] bus_for_each_drv+0xa9/0x100 [ 21.061312] __device_attach+0xed/0x190 [ 21.061812] device_initial_probe+0xe/0x20 [ 21.062229] bus_probe_device+0x4d/0xd0 [ 21.062590] device_add+0x308/0x590 [ 21.062912] usb_set_configuration+0x7b6/0xaf0 [ 21.063403] usb_generic_driver_probe+0x36/0x80 [ 21.063714] usb_probe_device+0x7b/0x130 [ 21.063936] really_probe+0x1ba/0x4c0 [ 21.064111] __driver_probe_device+0xb2/0x180 [ 21.064577] driver_probe_device+0x5a/0x100 [ 21.065019] __device_attach_driver+0xe9/0x160 [ 21.065403] ? __pfx___device_attach_driver+0x10/0x10 [ 21.065820] bus_for_each_drv+0xa9/0x100 [ 21.066094] __device_attach+0xed/0x190 [ 21.066535] device_initial_probe+0xe/0x20 [ 21.066992] bus_probe_device+0x4d/0xd0 [ 21.067250] device_add+0x308/0x590 [ 21.067501] usb_new_device+0x347/0x610 [ 21.067817] hub_event+0x156b/0x1e30 [ 21.068060] ? process_scheduled_works+0x48b/0xaf0 [ 21.068337] process_scheduled_works+0x5a3/0xaf0 [ 21.068668] worker_thread+0x3cf/0x560 [ 21.068932] ? kthread+0x109/0x1b0 [ 21.069133] kthread+0x197/0x1b0 [ 21.069343] ? __pfx_worker_thread+0x10/0x10 [ 21.069598] ? __pfx_kthread+0x10/0x10 [ 21.069908] ret_from_fork+0x32/0x40 [ 21.070169] ? __pfx_kthread+0x10/0x10 [ 21.070424] ret_from_fork_asm+0x1a/0x30 [ 21.070737] </TASK>
--- drivers/media/usb/uvc/uvc_driver.c | 73 +++++++++++++++++++----------- drivers/media/usb/uvc/uvcvideo.h | 2 + 2 files changed, 48 insertions(+), 27 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +46 -27
@@ -413,6 +413,9 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) {struct uvc_entity *entity; +if (id ==UVC_INVALID_ENTITY_ID ) +return NULL ; +list_for_each_entry (entity, &dev->entities, list) {if (entity->id == id)return entity;
@@ -1029,14 +1032,27 @@ static const u8 uvc_media_transport_input_guid[16] =UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ;static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ; -static struct uvc_entity *uvc_alloc_entity (u16 type,u16 id, -unsigned int num_pads,unsigned int extra_size) +static struct uvc_entity *uvc_alloc_new_entity (struct uvc_device *dev,u16 type, +u16 id,unsigned int num_pads, +unsigned int extra_size) {struct uvc_entity *entity;unsigned int num_inputs;unsigned int size;unsigned int i; +/* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */ +if (id ==0 ) { +dev_err (&dev->intf->dev,"Found Unit with invalid ID 0\n" ); + id =UVC_INVALID_ENTITY_ID ; + } + +/* Per UVC 1.1+ spec 3.7.2, the ID is unique. */ +if (uvc_entity_by_id (dev, id)) { +dev_err (&dev->intf->dev,"Found multiple Units with ID %u\n" , id); + id =UVC_INVALID_ENTITY_ID ; + } + extra_size =roundup (extra_size,sizeof (*entity->pads));if (num_pads) num_inputs = type &UVC_TERM_OUTPUT ? num_pads : num_pads -1 ;
@@ -1046,7 +1062,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, + num_inputs; entity =kzalloc (size,GFP_KERNEL );if (entity ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); entity->id = id; entity->type = type;
@@ -1136,10 +1152,10 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,break ; } - unit =uvc_alloc_entity (UVC_VC_EXTENSION_UNIT , buffer[3 ], - p +1 ,2 *n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_VC_EXTENSION_UNIT , + buffer[3 ], p +1 ,2 * n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -1249,10 +1265,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - term =uvc_alloc_entity (type |UVC_TERM_INPUT , buffer[3 ], -1 , n + p); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_INPUT , + buffer[3 ],1 , n + p); +if (IS_ERR (term)) +return PTR_ERR (term);if (UVC_ENTITY_TYPE (term) ==UVC_ITT_CAMERA ) { term->camera.bControlSize = n;
@@ -1308,10 +1324,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return 0 ; } - term =uvc_alloc_entity (type |UVC_TERM_OUTPUT , buffer[3 ], -1 ,0 ); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_OUTPUT , + buffer[3 ],1 ,0 ); +if (IS_ERR (term)) +return PTR_ERR (term);memcpy (term->baSourceID, &buffer[7 ],1 );
@@ -1332,9 +1348,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 ,0 ); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 ,0 ); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[5 ], p);
@@ -1356,9 +1373,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ],2 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ],2 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[4 ],1 ); unit->processing.wMaxMultiplier =
@@ -1387,9 +1404,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -1528,9 +1546,10 @@ static int uvc_gpio_parse(struct uvc_device *dev)return dev_err_probe (&dev->intf->dev, irq,"No IRQ for privacy GPIO\n" ); - unit =uvc_alloc_entity (UVC_EXT_GPIO_UNIT ,UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); -if (!unit) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_EXT_GPIO_UNIT , +UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); +if (IS_ERR (unit)) +return PTR_ERR (unit); unit->gpio.gpio_privacy = gpio_privacy; unit->gpio.irq = irq;
drivers/media/usb/uvc/uvcvideo.h +2 -0
@@ -41,6 +41,8 @@#define UVC_EXT_GPIO_UNIT 0x7ffe#define UVC_EXT_GPIO_UNIT_ID 0x100 +#define UVC_INVALID_ENTITY_ID 0xffff +/* ------------------------------------------------------------------------ * GUIDs */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 512/570 media: uvcvideo: Use heuristic to find stream entity
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 758dbc756aad429da11c569c0d067f7fd032bcf7 ]
Some devices, like the Grandstream GUV3100 webcam, have an invalid UVC descriptor where multiple entities share the same ID, this is invalid and makes it impossible to make a proper entity tree without heuristics.
We have recently introduced a change in the way that we handle invalid entities that has caused a regression on broken devices.
Implement a new heuristic to handle these devices properly.
--- drivers/media/usb/uvc/uvc_driver.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +14 -1
@@ -443,13 +443,26 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,static struct uvc_streaming *uvc_stream_by_id (struct uvc_device *dev,int id) { -struct uvc_streaming *stream; +struct uvc_streaming *stream, *last_stream; +unsigned int count =0 ;list_for_each_entry (stream, &dev->streams, list) { + count +=1 ; + last_stream = stream;if (stream->header.bTerminalLink == id)return stream; } +/* +* If the streaming entity is referenced by an invalid ID, notify the +* user and use heuristics to guess the correct entity. +*/ +if (count ==1 && id ==UVC_INVALID_ENTITY_ID ) { +dev_warn (&dev->intf->dev, +"UVC non compliance: Invalid USB header. The streaming entity has an invalid ID, guessing the correct one." ); +return last_stream; + } +return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 513/570 gpiolib: cdev: fix uninitialised kfifo
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kent Gibson <[email protected]>
[ Upstream commit ee0166b637a5e376118e9659e5b4148080f1d27e ]
If a line is requested with debounce, and that results in debouncing in software, and the line is subsequently reconfigured to enable edge detection then the allocation of the kfifo to contain edge events is overlooked. This results in events being written to and read from an uninitialised kfifo. Read events are returned to userspace.
Initialise the kfifo in the case where the software debounce is already active.
--- drivers/gpio/gpiolib-cdev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpio/gpiolib-cdev.c +13 -0
@@ -896,6 +896,7 @@ static int edge_detector_update(struct line *line,unsigned int line_idx, u64 eflags, bool polarity_change) { + int ret;unsigned int debounce_period_us =gpio_v2_line_config_debounce_period (lc, line_idx);
@@ -907,6 +908,18 @@ static int edge_detector_update(struct line *line,if (debounce_period_us &&READ_ONCE (line->sw_debounced)) {WRITE_ONCE (line->eflags, eflags);WRITE_ONCE (line->desc->debounce_period_us, debounce_period_us); +/* +* ensure event fifo is initialised if edge detection +* is now enabled. +*/ + eflags = eflags &GPIO_V2_LINE_EDGE_FLAGS ; +if (eflags && !kfifo_initialized (&line->req->events)) { + ret =kfifo_alloc (&line->req->events, + line->req->event_buffer_size, +GFP_KERNEL ); +if (ret) +return ret; + }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 514/570 iio: adc: ad7923: Fix buffer overflow for tx_buf and ring_xfer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuno Sa <[email protected]>
[ Upstream commit 3a4187ec454e19903fd15f6e1825a4b84e59a4cd ]
The AD7923 was updated to support devices with 8 channels, but the size of tx_buf and ring_xfer was not increased accordingly, leading to a potential buffer overflow in ad7923_update_scan_mode().
--- drivers/iio/adc/ad7923.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7923.c +2 -2
@@ -47,7 +47,7 @@struct ad7923_state {struct spi_device *spi; -struct spi_transfer ring_xfer[5 ]; +struct spi_transfer ring_xfer[9 ];struct spi_transfer scan_single_xfer[2 ];struct spi_message ring_msg;struct spi_message scan_single_msg;
@@ -63,7 +63,7 @@ struct ad7923_state {* Length = 8 channels + 4 extra for 8 byte timestamp */ __be16 rx_buf[12 ]____cacheline_aligned ; -__be16 tx_buf[4 ]; +__be16 tx_buf[8 ]; };struct ad7923_chip_info {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/570 apparmor: validate DFA start states are in bounds in unpack_pdb
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit 9063d7e2615f4a7ab321de6b520e23d370e58816 upstream.
Backport for conflicts caused by
ad596ea74e74 ("apparmor: group dfa policydb unpacking")
- rearrange and consolidated the unpack.
b11e51dd7094 ("apparmor: test: make static symbols visible during kunit testing")
- rename function and make it visible to kunit tests
Start states are read from untrusted data and used as indexes into the DFA state tables. The aa_dfa_next() function call in unpack_pdb() will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read.
==================================================================
BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ...
Reject policies with out-of-bounds start states during unpacking to prevent the issue.
--- security/apparmor/policy_unpack.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
security/apparmor/policy_unpack.c +19 -2
@@ -841,9 +841,18 @@ static struct aa_profile *unpack_profile error = -EPROTO ; goto fail; } -if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) +if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; + }else { +size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + } +/* setup class index */ for (i =AA_CLASS_FILE ; i <=AA_CLASS_LAST ; i++) { profile->policy.start[i] =
@@ -864,9 +873,17 @@ static struct aa_profile *unpack_profile info ="failed to unpack profile file rules" ; goto fail; }else if (profile->file.dfa) { -if (!unpack_u32 (e, &profile->file.start,"dfa_start" )) +if (!unpack_u32 (e, &profile->file.start,"dfa_start" )) {/* default start state */ profile->file.start =DFA_START ; + }else { +size_t state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->file.start >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + } }else if (profile->policy.dfa && profile->policy.start[AA_CLASS_FILE ]) { profile->file.dfa =aa_get_dfa (profile->policy.dfa);
Greg Kroah-Hartman
maintainerPATCH 516/570 apparmor: fix memory leak in verify_header
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit e38c55d9f834e5b848bfed0f5c586aaf45acb825 upstream.
The function sets *ns = NULL on every call, leaking the namespace string allocated in previous iterations when multiple profiles are unpacked. This also breaks namespace consistency checking since *ns is always NULL when the comparison is made.
Remove the incorrect assignment.
The caller (aa_unpack) initializes *ns to NULL once before the loop, which is sufficient.
--- security/apparmor/policy_unpack.c | 1 - 1 file changed, 1 deletion(-)
security/apparmor/policy_unpack.c +0 -1
@@ -976,7 +976,6 @@ static int verify_header(struct aa_ext * {int error = -EPROTONOSUPPORT ;const char *name =NULL ; - *ns =NULL ;/* get the interface version */ if (!unpack_u32 (e, &e->version,"version" )) {
Greg Kroah-Hartman
maintainerPATCH 517/570 apparmor: replace recursive profile removal with iterative approach
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit ab09264660f9de5d05d1ef4e225aa447c63a8747 upstream.
The profile removal code uses recursion when removing nested profiles, which can lead to kernel stack exhaustion and system crashes.
Reproducer:
$ pf='a'; for ((i=0; i<1024; i++)); do
echo -e "profile $pf { \n }" | apparmor_parser -K -a;
pf="$pf//x";
done
$ echo -n a > /sys/kernel/security/apparmor/.removeReplace the recursive __aa_profile_list_release() approach with an iterative approach in __remove_profile(). The function repeatedly finds and removes leaf profiles until the entire subtree is removed, maintaining the same removal semantic without recursion.
--- security/apparmor/policy.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
security/apparmor/policy.c +27 -3
@@ -146,19 +146,43 @@ static void __list_remove_profile(struct }/** -* __remove_profile - remove old profile, and children -* @profile: profile to be replaced (NOT NULL) +* __remove_profile - remove profile, and children +* @profile: profile to be removed (NOT NULL) * * Requires: namespace list lock be held, or list not be shared */ static void __remove_profile (struct aa_profile *profile) { +struct aa_profile *curr, *to_remove; +AA_BUG (!profile);AA_BUG (!profile->ns);AA_BUG (!mutex_is_locked (&profile->ns->lock));/* release any children lists first */ -__aa_profile_list_release (&profile->base.profiles); +if (!list_empty (&profile->base.profiles)) { + curr = list_first_entry(&profile->base.profiles, struct aa_profile, base.list); + +while (curr != profile) { + +while (!list_empty (&curr->base.profiles)) + curr =list_first_entry (&curr->base.profiles, + struct aa_profile, base.list); + + to_remove = curr; +if (!list_is_last (&to_remove->base.list, + &aa_deref_parent (curr)->base.profiles)) + curr =list_next_entry (to_remove, base.list); +else + curr =aa_deref_parent (curr); + +/* released by free_profile */ +aa_label_remove (&to_remove->label); +__aafs_profile_rmdir (to_remove); +__list_remove_profile (to_remove); + } + } +/* released by free_profile */ aa_label_remove (&profile->label);__aafs_profile_rmdir (profile);
Greg Kroah-Hartman
maintainerPATCH 518/570 apparmor: fix: limit the number of levels of policy namespaces
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 306039414932c80f8420695a24d4fe10c84ccfb2 upstream.
Currently the number of policy namespaces is not bounded relying on the user namespace limit. However policy namespaces aren't strictly tied to user namespaces and it is possible to create them and nest them arbitrarily deep which can be used to exhaust system resource.
Hard cap policy namespaces to the same depth as user namespaces.
--- security/apparmor/include/policy_ns.h | 2 ++ security/apparmor/policy_ns.c | 2 ++ 2 files changed, 4 insertions(+)
security/apparmor/include/policy_ns.h +2 -0
@@ -18,6 +18,8 @@#include "label.h" #include "policy.h" +/* Match max depth of user namespaces */ +#define MAX_NS_DEPTH 32/* struct aa_ns_acct - accounting of profiles in namespace * @max_size: maximum space allowed for all profiles in namespace
security/apparmor/policy_ns.c +2 -0
@@ -249,6 +249,8 @@ static struct aa_ns *__aa_create_ns(struAA_BUG (!name);AA_BUG (!mutex_is_locked (&parent->lock)); +if (parent->level >MAX_NS_DEPTH ) +return ERR_PTR (-ENOSPC ); ns =alloc_ns (parent->base.hname, name);if (!ns)return ERR_PTR (-ENOMEM );
Greg Kroah-Hartman
maintainerPATCH 519/570 apparmor: fix side-effect bug in match_char() macro usage
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit 8756b68edae37ff546c02091989a4ceab3f20abd upstream.
The match_char() macro evaluates its character parameter multiple times when traversing differential encoding chains. When invoked with *str++, the string pointer advances on each iteration of the inner do-while loop, causing the DFA to check different characters at each iteration and therefore skip input characters. This results in out-of-bounds reads when the pointer advances past the input buffer boundary.
[ 94.984676] ================================================================== [ 94.985301] BUG: KASAN: slab-out-of-bounds in aa_dfa_match+0x5ae/0x760 [ 94.985655] Read of size 1 at addr ffff888100342000 by task file/976
[ 94.986319] CPU: 7 UID: 1000 PID: 976 Comm: file Not tainted 6.19.0-rc7-next-20260127 #1 PREEMPT(lazy) [ 94.986322] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 94.986329] Call Trace: [ 94.986341] <TASK> [ 94.986347] dump_stack_lvl+0x5e/0x80 [ 94.986374] print_report+0xc8/0x270 [ 94.986384] ? aa_dfa_match+0x5ae/0x760 [ 94.986388] kasan_report+0x118/0x150 [ 94.986401] ? aa_dfa_match+0x5ae/0x760 [ 94.986405] aa_dfa_match+0x5ae/0x760 [ 94.986408] __aa_path_perm+0x131/0x400 [ 94.986418] aa_path_perm+0x219/0x2f0 [ 94.986424] apparmor_file_open+0x345/0x570 [ 94.986431] security_file_open+0x5c/0x140 [ 94.986442] do_dentry_open+0x2f6/0x1120 [ 94.986450] vfs_open+0x38/0x2b0 [ 94.986453] ? may_open+0x1e2/0x2b0 [ 94.986466] path_openat+0x231b/0x2b30 [ 94.986469] ? __x64_sys_openat+0xf8/0x130 [ 94.986477] do_file_open+0x19d/0x360 [ 94.986487] do_sys_openat2+0x98/0x100 [ 94.986491] __x64_sys_openat+0xf8/0x130 [ 94.986499] do_syscall_64+0x8e/0x660 [ 94.986515] ? count_memcg_events+0x15f/0x3c0 [ 94.986526] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986540] ? handle_mm_fault+0x1639/0x1ef0 [ 94.986551] ? vma_start_read+0xf0/0x320 [ 94.986558] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986561] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986563] ? fpregs_assert_state_consistent+0x50/0xe0 [ 94.986572] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986574] ? arch_exit_to_user_mode_prepare+0x9/0xb0 [ 94.986587] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986588] ? irqentry_exit+0x3c/0x590 [ 94.986595] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 94.986597] RIP: 0033:0x7fda4a79c3ea
Fix by extracting the character value before invoking match_char, ensuring single evaluation per outer loop.
--- security/apparmor/match.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
security/apparmor/match.c +20 -10
@@ -452,13 +452,18 @@ unsigned int aa_dfa_match_len(struct aa_if (dfa->tables[YYTD_ID_EC ]) {/* Equivalence class table defined */ u8 *equiv =EQUIV_TABLE (dfa); -for (; len; len--) -match_char (state, def, base, next, check, - equiv[(u8) *str++]); +for (; len; len--) { +u8 c = equiv[(u8) *str]; + +match_char (state, def, base, next, check, c); + str++; + } }else {/* default is direct to next state */ -for (; len; len--) -match_char (state, def, base, next, check, (u8) *str++); +for (; len; len--) { +match_char (state, def, base, next, check, (u8) *str); + str++; + } }return state;
@@ -493,13 +498,18 @@ unsigned int aa_dfa_match(struct aa_dfa/* Equivalence class table defined */ u8 *equiv =EQUIV_TABLE (dfa);/* default is direct to next state */ -while (*str) -match_char (state, def, base, next, check, - equiv[(u8) *str++]); +while (*str) { +u8 c = equiv[(u8) *str]; + +match_char (state, def, base, next, check, c); + str++; + } }else {/* default is direct to next state */ -while (*str) -match_char (state, def, base, next, check, (u8) *str++); +while (*str) { +match_char (state, def, base, next, check, (u8) *str); + str++; + } }return state;
Greg Kroah-Hartman
maintainerPATCH 520/570 apparmor: fix missing bounds check on DEFAULT table in verify_dfa()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit d352873bbefa7eb39995239d0b44ccdf8aaa79a4 upstream.
The verify_dfa() function only checks DEFAULT_TABLE bounds when the state is not differentially encoded.
When the verification loop traverses the differential encoding chain, it reads k = DEFAULT_TABLE[j] and uses k as an array index without validation. A malformed DFA with DEFAULT_TABLE[j] >= state_count, therefore, causes both out-of-bounds reads and writes.
[ 57.179855] ================================================================== [ 57.180549] BUG: KASAN: slab-out-of-bounds in verify_dfa+0x59a/0x660 [ 57.180904] Read of size 4 at addr ffff888100eadec4 by task su/993
[ 57.181554] CPU: 1 UID: 0 PID: 993 Comm: su Not tainted 6.19.0-rc7-next-20260127 #1 PREEMPT(lazy) [ 57.181558] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 57.181563] Call Trace: [ 57.181572] <TASK> [ 57.181577] dump_stack_lvl+0x5e/0x80 [ 57.181596] print_report+0xc8/0x270 [ 57.181605] ? verify_dfa+0x59a/0x660 [ 57.181608] kasan_report+0x118/0x150 [ 57.181620] ? verify_dfa+0x59a/0x660 [ 57.181623] verify_dfa+0x59a/0x660 [ 57.181627] aa_dfa_unpack+0x1610/0x1740 [ 57.181629] ? __kmalloc_cache_noprof+0x1d0/0x470 [ 57.181640] unpack_pdb+0x86d/0x46b0 [ 57.181647] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181653] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181656] ? aa_unpack_nameX+0x1a8/0x300 [ 57.181659] aa_unpack+0x20b0/0x4c30 [ 57.181662] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181664] ? stack_depot_save_flags+0x33/0x700 [ 57.181681] ? kasan_save_track+0x4f/0x80 [ 57.181683] ? kasan_save_track+0x3e/0x80 [ 57.181686] ? __kasan_kmalloc+0x93/0xb0 [ 57.181688] ? __kvmalloc_node_noprof+0x44a/0x780 [ 57.181693] ? aa_simple_write_to_buffer+0x54/0x130 [ 57.181697] ? policy_update+0x154/0x330 [ 57.181704] aa_replace_profiles+0x15a/0x1dd0 [ 57.181707] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181710] ? __kvmalloc_node_noprof+0x44a/0x780 [ 57.181712] ? aa_loaddata_alloc+0x77/0x140 [ 57.181715] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181717] ? _copy_from_user+0x2a/0x70 [ 57.181730] policy_update+0x17a/0x330 [ 57.181733] profile_replace+0x153/0x1a0 [ 57.181735] ? rw_verify_area+0x93/0x2d0 [ 57.181740] vfs_write+0x235/0xab0 [ 57.181745] ksys_write+0xb0/0x170 [ 57.181748] do_syscall_64+0x8e/0x660 [ 57.181762] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 57.181765] RIP: 0033:0x7f6192792eb2
Remove the MATCH_FLAG_DIFF_ENCODE condition to validate all DEFAULT_TABLE entries unconditionally.
--- security/apparmor/match.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
security/apparmor/match.c +3 -2
@@ -204,9 +204,10 @@ static int verify_dfa(struct aa_dfa *dfaif (state_count ==0 ) goto out;for (i =0 ; i < state_count; i++) { -if (!(BASE_TABLE (dfa)[i] &MATCH_FLAG_DIFF_ENCODE ) && - (DEFAULT_TABLE (dfa)[i] >= state_count)) +if (DEFAULT_TABLE (dfa)[i] >= state_count) { +pr_err ("AppArmor DFA default state out of bounds" ); goto out; + }if (BASE_TABLE (dfa)[i] &MATCH_FLAGS_INVALID ) {pr_err ("AppArmor DFA state with invalid match flags" ); goto out;
Greg Kroah-Hartman
maintainerPATCH 521/570 apparmor: Fix double free of ns_name in aa_replace_profiles()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 5df0c44e8f5f619d3beb871207aded7c78414502 upstream.
if ns_name is NULL after
1071 error = aa_unpack(udata, &lh, &ns_name);
and if ent->ns_name contains an ns_name in
1089 } else if (ent->ns_name) {
then ns_name is assigned the ent->ns_name
1095 ns_name = ent->ns_name;
however ent->ns_name is freed at
1262 aa_load_ent_free(ent);
and then again when freeing ns_name at
1270 kfree(ns_name);
Fix this by NULLing out ent->ns_name after it is transferred to ns_name
")
--- security/apparmor/policy.c | 1 + 1 file changed, 1 insertion(+)
security/apparmor/policy.c +1 -0
@@ -917,6 +917,7 @@ ssize_t aa_replace_profiles(struct aa_ns goto fail; } ns_name = ent->ns_name; + ent->ns_name =NULL ; }else count++; }
Greg Kroah-Hartman
maintainerPATCH 522/570 apparmor: fix unprivileged local user can do privileged policy management
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 6601e13e82841879406bf9f369032656f441a425 upstream.
Backport for api changes introduced in
- 90c436a64a6e ("apparmor: pass cred through to audit info.")
- 92de220a7f33 ("apparmor: update policy capable checks to use a label")
An unprivileged local user can load, replace, and remove profiles by opening the apparmorfs interfaces, via a confused deputy attack, by passing the opened fd to a privileged process, and getting the privileged process to write to the interface.
This does require a privileged target that can be manipulated to do the write for the unprivileged process, but once such access is achieved full policy management is possible and all the possible implications that implies: removing confinement, DoS of system or target applications by denying all execution, by-passing the unprivileged user namespace restriction, to exploiting kernel bugs for a local privilege escalation.
The policy management interface can not have its permissions simply changed from 0666 to 0600 because non-root processes need to be able to load policy to different policy namespaces.
Instead ensure the task writing the interface has privileges that are a subset of the task that opened the interface. This is already done via policy for confined processes, but unconfined can delegate access to the opened fd, by-passing the usual policy check.
--- security/apparmor/apparmorfs.c | 19 +++++++++++------- security/apparmor/include/policy.h | 5 ++-- security/apparmor/policy.c | 39 +++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 11 deletions(-)
security/apparmor/apparmorfs.c +12 -7
@@ -409,7 +409,8 @@ static struct aa_loaddata *aa_simple_wri }static ssize_t policy_update (u32 mask,const char __user *buf,size_t size, -loff_t *pos,struct aa_ns *ns) +loff_t *pos,struct aa_ns *ns, +const struct cred *ocred) {struct aa_loaddata *data;struct aa_label *label;
@@ -420,7 +421,7 @@ static ssize_t policy_update(u32 mask, c/* high level check about policy management - fine grained in * below after unpack */ - error =aa_may_manage_policy (label, ns, mask); + error =aa_may_manage_policy (current_cred (), label, ns, ocred, mask);if (error) goto end_section;
@@ -441,7 +442,8 @@ static ssize_t profile_load(struct file loff_t *pos) {struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); -int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns); +int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns, + f->f_cred);aa_put_ns (ns);
@@ -459,7 +461,7 @@ static ssize_t profile_replace(struct fi {struct aa_ns *ns =aa_get_ns (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY |AA_MAY_REPLACE_POLICY , - buf, size, pos, ns); + buf, size, pos, ns, f->f_cred);aa_put_ns (ns);return error;
@@ -483,7 +485,8 @@ static ssize_t profile_remove(struct fil/* high level check about policy management - fine grained in * below after unpack */ - error =aa_may_manage_policy (label, ns,AA_MAY_REMOVE_POLICY ); + error =aa_may_manage_policy (current_cred (), label, ns, + f->f_cred,AA_MAY_REMOVE_POLICY );if (error) goto out;
@@ -1797,7 +1800,8 @@ static int ns_mkdir_op(struct user_namesint error; label =begin_current_label_crit_section (); - error =aa_may_manage_policy (label,NULL ,AA_MAY_LOAD_POLICY ); + error =aa_may_manage_policy (current_cred (), label,NULL ,NULL , +AA_MAY_LOAD_POLICY );end_current_label_crit_section (label);if (error)return error;
@@ -1846,7 +1850,8 @@ static int ns_rmdir_op(struct inode *dirint error; label =begin_current_label_crit_section (); - error =aa_may_manage_policy (label,NULL ,AA_MAY_LOAD_POLICY ); + error =aa_may_manage_policy (current_cred (), label,NULL ,NULL , +AA_MAY_LOAD_POLICY );end_current_label_crit_section (label);if (error)return error;
security/apparmor/include/policy.h +3 -2
@@ -303,7 +303,8 @@ static inline int AUDIT_MODE(struct aa_pbool policy_view_capable (struct aa_ns *ns);bool policy_admin_capable (struct aa_ns *ns); -int aa_may_manage_policy (struct aa_label *label,struct aa_ns *ns, -u32 mask); +int aa_may_manage_policy (const struct cred *subj_cred, +struct aa_label *label,struct aa_ns *ns, +const struct cred *ocred,u32 mask);#endif /* __AA_POLICY_H */
security/apparmor/policy.c +37 -2
@@ -695,14 +695,44 @@ bool policy_admin_capable(struct aa_ns *return policy_view_capable (ns) && capable && !aa_g_lock_policy; } +static bool is_subset_of_obj_privilege (const struct cred *cred, +struct aa_label *label, +const struct cred *ocred) +{ +if (cred == ocred) +return true; + +if (!aa_label_is_subset (label,cred_label (ocred))) +return false; +/* don't allow crossing userns for now */ +if (cred->user_ns != ocred->user_ns) +return false; +if (!cap_issubset (cred->cap_inheritable, ocred->cap_inheritable)) +return false; +if (!cap_issubset (cred->cap_permitted, ocred->cap_permitted)) +return false; +if (!cap_issubset (cred->cap_effective, ocred->cap_effective)) +return false; +if (!cap_issubset (cred->cap_bset, ocred->cap_bset)) +return false; +if (!cap_issubset (cred->cap_ambient, ocred->cap_ambient)) +return false; +return true; +} + +/** * aa_may_manage_policy - can the current task manage policy +* @subj_cred; subjects cred * @label: label to check if it can manage policy -* @op: the policy manipulation operation being done +* @ns: namespace being managed by @label (may be NULL if @label's ns) +* @ocred: object cred if request is coming from an open object +* @mask: contains the policy manipulation operation being done * * Returns: 0 if the task is allowed to manipulate policy else error */ -int aa_may_manage_policy (struct aa_label *label,struct aa_ns *ns,u32 mask) +int aa_may_manage_policy (const struct cred *subj_cred,struct aa_label *label, +struct aa_ns *ns,const struct cred *ocred,u32 mask) {const char *op;
@@ -718,6 +748,11 @@ int aa_may_manage_policy(struct aa_labelreturn audit_policy (label, op,NULL ,NULL ,"policy_locked" , -EACCES ); +if (ocred && !is_subset_of_obj_privilege (subj_cred, label, ocred)) +return audit_policy (label, op,NULL ,NULL , +"not privileged for target profile" , + -EACCES ); +if (!policy_admin_capable (ns))return audit_policy (label, op,NULL ,NULL ,"not policy admin" , -EACCES );
Greg Kroah-Hartman
maintainerPATCH 523/570 apparmor: fix differential encoding verification
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 39440b137546a3aa383cfdabc605fb73811b6093 upstream.
Differential encoding allows loops to be created if it is abused. To prevent this the unpack should verify that a diff-encode chain terminates.
Unfortunately the differential encode verification had two bugs.
1. it conflated states that had gone through check and already been marked, with states that were currently being checked and marked. This means that loops in the current chain being verified are treated as a chain that has already been verified.
2. the order bailout on already checked states compared current chain check iterators j,k instead of using the outer loop iterator i. Meaning a step backwards in states in the current chain verification was being mistaken for moving to an already verified state.
Move to a double mark scheme where already verified states get a different mark, than the current chain being kept. This enables us to also drop the backwards verification check that was the cause of the second error as any already verified state is already marked.
--- security/apparmor/include/match.h | 1 + security/apparmor/match.c | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
security/apparmor/include/match.h +1 -0
@@ -190,6 +190,7 @@ static inline void aa_put_dfa(struct aa_#define MATCH_FLAG_DIFF_ENCODE 0x80000000#define MARK_DIFF_ENCODE 0x40000000#define MATCH_FLAG_OOB_TRANSITION 0x20000000 +#define MARK_DIFF_ENCODE_VERIFIED 0x10000000#define MATCH_FLAGS_MASK 0xff000000#define MATCH_FLAGS_VALID (MATCH_FLAG_DIFF_ENCODE | MATCH_FLAG_OOB_TRANSITION)#define MATCH_FLAGS_INVALID (MATCH_FLAGS_MASK & ~MATCH_FLAGS_VALID)
security/apparmor/match.c +19 -4
@@ -246,16 +246,31 @@ static int verify_dfa(struct aa_dfa *dfasize_t j, k;for (j = i; - (BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ) && - !(BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE ); + ((BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ) && + !(BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE_VERIFIED )); j = k) { +if (BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE ) +/* loop in current chain */ + goto out; k =DEFAULT_TABLE (dfa)[j];if (j == k) +/* self loop */ goto out; -if (k < j) -break ;/* already verified */ BASE_TABLE (dfa)[j] |=MARK_DIFF_ENCODE ; } +/* move mark to verified */ +for (j = i; + (BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ); + j = k) { + k =DEFAULT_TABLE (dfa)[j]; +if (j < i) +/* jumps to state/chain that has been +* verified +*/ +break ; +BASE_TABLE (dfa)[j] &= ~MARK_DIFF_ENCODE ; +BASE_TABLE (dfa)[j] |=MARK_DIFF_ENCODE_VERIFIED ; + } } error =0 ;
Greg Kroah-Hartman
maintainerPATCH 524/570 apparmor: fix race on rawdata dereference
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit a0b7091c4de45a7325c8780e6934a894f92ac86b upstream.
Backport for conflicts introdued by
d61c57fde819 ("apparmor: make export of raw binary profile to userspace optional") which nests the conflicting code inside an if condition
There is a race condition that leads to a use-after-free situation:
because the rawdata inodes are not refcounted, an attacker can start open()ing one of the rawdata files, and at the same time remove the last reference to this rawdata (by removing the corresponding profile, for example), which frees its struct aa_loaddata; as a result, when seq_rawdata_open() is reached, i_private is a dangling pointer and freed memory is accessed.
The rawdata inodes weren't refcounted to avoid a circular refcount and were supposed to be held by the profile rawdata reference. However during profile removal there is a window where the vfs and profile destruction race, resulting in the use after free.
Fix this by moving to a double refcount scheme. Where the profile refcount on rawdata is used to break the circular dependency. Allowing for freeing of the rawdata once all inode references to the rawdata are put.
--- security/apparmor/apparmorfs.c | 36 +++++++++------ security/apparmor/include/policy_unpack.h | 71 ++++++++++++++++++------------ security/apparmor/policy.c | 12 ++--- security/apparmor/policy_unpack.c | 32 +++++++++---- 4 files changed, 94 insertions(+), 57 deletions(-)
security/apparmor/apparmorfs.c +22 -14
@@ -77,7 +77,7 @@ static void rawdata_f_data_free(struct rif (!private)return ; -aa_put_loaddata (private->loaddata); +aa_put_i_loaddata (private->loaddata);kvfree (private); }
@@ -401,7 +401,9 @@ static struct aa_loaddata *aa_simple_wri data->size = copy_size;if (copy_from_user (data->data, userbuf, copy_size)) { -aa_put_loaddata (data); +/* trigger free - don't need to put pcount */ +aa_put_i_loaddata (data); +return ERR_PTR (-EFAULT ); }
@@ -429,7 +431,10 @@ static ssize_t policy_update(u32 mask, c error =PTR_ERR (data);if (!IS_ERR (data)) { error =aa_replace_profiles (ns, label, mask, data); -aa_put_loaddata (data); +/* put pcount, which will put count and free if no +* profiles referencing it. +*/ +aa_put_profile_loaddata (data); } end_section:end_current_label_crit_section (label);
@@ -500,7 +505,7 @@ static ssize_t profile_remove(struct filif (!IS_ERR (data)) { data->data[size] =0 ; error =aa_remove_profiles (ns, label, data->data, size); -aa_put_loaddata (data); +aa_put_profile_loaddata (data); } out:end_current_label_crit_section (label);
@@ -1225,18 +1230,17 @@ static const struct file_operations seq_static int seq_rawdata_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_loaddata *data =__aa_get_loaddata (inode->i_private); +struct aa_loaddata *data =aa_get_i_loaddata (inode->i_private);int error;if (!data) -/* lost race this ent is being reaped */ return -ENOENT ; error =single_open (file, show, data);if (error) {AA_BUG (file->private_data && ((struct seq_file *)file->private_data)->private); -aa_put_loaddata (data); +aa_put_i_loaddata (data); }return error;
@@ -1247,7 +1251,7 @@ static int seq_rawdata_release(struct instruct seq_file *seq = (struct seq_file *) file->private_data;if (seq) -aa_put_loaddata (seq->private); +aa_put_i_loaddata (seq->private);return single_release (inode, file); }
@@ -1366,9 +1370,8 @@ static int rawdata_open(struct inode *inif (!policy_view_capable (NULL ))return -EACCES ; - loaddata =__aa_get_loaddata (inode->i_private); + loaddata =aa_get_i_loaddata (inode->i_private);if (!loaddata) -/* lost race: this entry is being reaped */ return -ENOENT ; private =rawdata_f_data_alloc (loaddata->size);
@@ -1393,7 +1396,7 @@ fail_decompress:return error; fail_private_alloc: -aa_put_loaddata (loaddata); +aa_put_i_loaddata (loaddata);return error; }
@@ -1410,9 +1413,9 @@ static void remove_rawdata_dents(structfor (i =0 ; i <AAFS_LOADDATA_NDENTS ; i++) {if (!IS_ERR_OR_NULL (rawdata->dents[i])) { -/* no refcounts on i_private */ aafs_remove (rawdata->dents[i]); rawdata->dents[i] =NULL ; +aa_put_i_loaddata (rawdata); } } }
@@ -1451,18 +1454,21 @@ int __aa_fs_create_rawdata(struct aa_nsif (IS_ERR (dir))/* ->name freed when rawdata freed */ return PTR_ERR (dir); +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DIR ] = dir; dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, rawdata, &seq_rawdata_abi_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_ABI ] = dent; dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, rawdata, &seq_rawdata_revision_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_REVISION ] = dent;if (aa_g_hash_policy) {
@@ -1470,6 +1476,7 @@ int __aa_fs_create_rawdata(struct aa_ns rawdata, &seq_rawdata_hash_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_HASH ] = dent; }
@@ -1478,24 +1485,25 @@ int __aa_fs_create_rawdata(struct aa_ns &seq_rawdata_compressed_size_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE ] = dent; dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , dir, rawdata, &rawdata_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DATA ] = dent;d_inode (dent)->i_size = rawdata->size; rawdata->ns =aa_get_ns (ns);list_add (&rawdata->list, &ns->rawdata_list); -/* no refcount on inode rawdata */ return 0 ; fail:remove_rawdata_dents (rawdata); - +aa_put_i_loaddata (rawdata);return PTR_ERR (dent); }
security/apparmor/include/policy_unpack.h +43 -28
110 lines not on this page · raw message
security/apparmor/policy.c +6 -6
@@ -265,7 +265,7 @@ void aa_free_profile(struct aa_profile * }kfree_sensitive (profile->hash); -aa_put_loaddata (profile->rawdata); +aa_put_profile_loaddata (profile->rawdata);aa_label_destroy (&profile->label);kfree_sensitive (profile);
@@ -925,7 +925,7 @@ ssize_t aa_replace_profiles(struct aa_nsLIST_HEAD (lh); op = mask &AA_MAY_REPLACE_POLICY ?OP_PROF_REPL :OP_PROF_LOAD ; -aa_get_loaddata (udata); +aa_get_profile_loaddata (udata);/* released below */ error =aa_unpack (udata, &lh, &ns_name);if (error)
@@ -976,10 +976,10 @@ ssize_t aa_replace_profiles(struct aa_nsif (aa_rawdata_eq (rawdata_ent, udata)) {struct aa_loaddata *tmp; - tmp =__aa_get_loaddata (rawdata_ent); + tmp =aa_get_profile_loaddata (rawdata_ent);/* check we didn't fail the race */ if (tmp) { -aa_put_loaddata (udata); +aa_put_profile_loaddata (udata); udata = tmp;break ; }
@@ -989,7 +989,7 @@ ssize_t aa_replace_profiles(struct aa_nslist_for_each_entry (ent, &lh, list) {struct aa_policy *policy; - ent->new->rawdata =aa_get_loaddata (udata); + ent->new->rawdata =aa_get_profile_loaddata (udata); error =__lookup_replace (ns, ent->new->base.hname, !(mask &AA_MAY_REPLACE_POLICY ), &ent->old, &info);
@@ -1103,7 +1103,7 @@ ssize_t aa_replace_profiles(struct aa_ns out:aa_put_ns (ns); -aa_put_loaddata (udata); +aa_put_profile_loaddata (udata);kfree (ns_name);if (error)
security/apparmor/policy_unpack.c +23 -9
@@ -147,34 +147,47 @@ bool aa_rawdata_eq(struct aa_loaddata *lreturn memcmp (l->data, r->data, r->compressed_size ?: r->size) ==0 ; } +static void do_loaddata_free (struct aa_loaddata *d) +{ +kfree_sensitive (d->hash); +kfree_sensitive (d->name); +kvfree (d->data); +kfree_sensitive (d); +} + +void aa_loaddata_kref (struct kref *kref) +{ + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + +do_loaddata_free (d); +} +/* * need to take the ns mutex lock which is NOT safe most places that * put_loaddata is called, so we have to delay freeing it */ -static void do_loaddata_free (struct work_struct *work) +static void do_ploaddata_rmfs (struct work_struct *work) { struct aa_loaddata *d = container_of(work, struct aa_loaddata, work);struct aa_ns *ns =aa_get_ns (d->ns);if (ns) {mutex_lock_nested (&ns->lock, ns->level); +/* remove fs ref to loaddata */ __aa_fs_remove_rawdata (d);mutex_unlock (&ns->lock);aa_put_ns (ns); } - -kfree_sensitive (d->hash); -kfree_sensitive (d->name); -kvfree (d->data); -kfree_sensitive (d); +/* called by dropping last pcount, so drop its associated icount */ +aa_put_i_loaddata (d); } -void aa_loaddata_kref (struct kref *kref) +void aa_ploaddata_kref (struct kref *kref) { - struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, pcount);if (d) { -INIT_WORK (&d->work, do_loaddata_free); +INIT_WORK (&d->work, do_ploaddata_rmfs);schedule_work (&d->work); } }
@@ -192,6 +205,7 @@ struct aa_loaddata *aa_loaddata_alloc(sireturn ERR_PTR (-ENOMEM ); }kref_init (&d->count); +kref_init (&d->pcount);INIT_LIST_HEAD (&d->list);return d;
Greg Kroah-Hartman
maintainerPATCH 525/570 apparmor: fix race between freeing data and fs accessing it
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 8e135b8aee5a06c52a4347a5a6d51223c6f36ba3 upstream.
Backport for conflicts introdued by
- conversion from sha1 to sha256 introduced in
e44a4dc4b36c ("apparmor: switch SECURITY_APPARMOR_HASH from sha1 to sha256
")
- adding of conditioanl that nests the conflicting code inside an if condition
d61c57fde819 ("apparmor: make export of raw binary profile to userspace optional")
AppArmor was putting the reference to i_private data on its end after removing the original entry from the file system. However the inode can and does live beyond that point and it is possible that some of the fs call back functions will be invoked after the reference has been put, which results in a race between freeing the data and accessing it through the fs.
While the rawdata/loaddata is the most likely candidate to fail the race, as it has the fewest references. If properly crafted it might be possible to trigger a race for the other types stored in i_private.
Fix this by moving the put of i_private referenced data to the correct place which is during inode eviction.
--- security/apparmor/apparmorfs.c | 193 +++++++++++++++++------------- security/apparmor/include/label.h | 16 +- security/apparmor/include/lib.h | 12 + security/apparmor/include/policy.h | 8 - security/apparmor/include/policy_unpack.h | 6 security/apparmor/label.c | 12 + security/apparmor/policy_unpack.c | 6 7 files changed, 152 insertions(+), 101 deletions(-)
security/apparmor/apparmorfs.c +113 -80
@@ -32,6 +32,7 @@#include "include/crypto.h" #include "include/ipc.h" #include "include/label.h" +#include "include/lib.h" #include "include/policy.h" #include "include/policy_ns.h" #include "include/resource.h"
@@ -61,6 +62,7 @@* securityfs and apparmorfs filesystems. */ +#define IREF_POISON 101/* * support fns
@@ -150,6 +152,71 @@ static int aafs_show_path(struct seq_filreturn 0 ; } +static struct aa_ns *get_ns_common_ref (struct aa_common_ref *ref) +{ +if (ref) { + struct aa_label *reflabel = container_of(ref, struct aa_label, + count); +return aa_get_ns (labels_ns (reflabel)); + } + +return NULL ; +} + +static struct aa_proxy *get_proxy_common_ref (struct aa_common_ref *ref) +{ +if (ref) + return aa_get_proxy(container_of(ref, struct aa_proxy, count)); + +return NULL ; +} + +static struct aa_loaddata *get_loaddata_common_ref (struct aa_common_ref *ref) +{ +if (ref) + return aa_get_i_loaddata(container_of(ref, struct aa_loaddata, + count)); +return NULL ; +} + +static void aa_put_common_ref (struct aa_common_ref *ref) +{ +if (!ref) +return ; + +switch (ref->reftype) { +case REF_RAWDATA : +aa_put_i_loaddata (container_of (ref ,struct aa_loaddata , +count )); +break ; +case REF_PROXY : +aa_put_proxy (container_of (ref ,struct aa_proxy , +count )); +break ; +case REF_NS : +/* ns count is held on its unconfined label */ +aa_put_ns (labels_ns (container_of (ref ,struct aa_label ,count ))); +break ; +default : +AA_BUG (true,"unknown refcount type" ); +break ; + } +} + +static void aa_get_common_ref (struct aa_common_ref *ref) +{ +kref_get (&ref->count); +} + +static void aafs_evict (struct inode *inode) +{ +struct aa_common_ref *ref = inode->i_private; + +clear_inode (inode); +aa_put_common_ref (ref); + inode->i_private = (void *)IREF_POISON ; +} +static void aafs_free_inode (struct inode *inode) {if (S_ISLNK (inode->i_mode))
@@ -159,6 +226,7 @@ static void aafs_free_inode(struct inodestatic const struct super_operations aafs_super_ops = { .statfs = simple_statfs, + .evict_inode = aafs_evict, .free_inode = aafs_free_inode, .show_path = aafs_show_path, };
@@ -259,7 +327,8 @@ static int __aafs_setup_d_inode(struct i* aafs_remove(). Will return ERR_PTR on failure. */ static struct dentry *aafs_create (const char *name,umode_t mode, -struct dentry *parent,void *data,void *link, +struct dentry *parent, +struct aa_common_ref *data,void *link,const struct file_operations *fops,const struct inode_operations *iops) {
@@ -296,6 +365,9 @@ static struct dentry *aafs_create(const goto fail_dentry;inode_unlock (dir); +if (data) +aa_get_common_ref (data); +return dentry; fail_dentry:
@@ -320,7 +392,8 @@ fail_lock:* see aafs_create */ static struct dentry *aafs_create_file (const char *name,umode_t mode, -struct dentry *parent,void *data, +struct dentry *parent, +struct aa_common_ref *data,const struct file_operations *fops) {return aafs_create (name, mode, parent, data,NULL , fops,NULL );
@@ -446,7 +519,7 @@ end_section:static ssize_t profile_load (struct file *f,const char __user *buf,size_t size,loff_t *pos) { -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns, f->f_cred);
@@ -464,7 +537,7 @@ static const struct file_operations aa_fstatic ssize_t profile_replace (struct file *f,const char __user *buf,size_t size,loff_t *pos) { -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY |AA_MAY_REPLACE_POLICY , buf, size, pos, ns, f->f_cred);aa_put_ns (ns);
@@ -484,7 +557,7 @@ static ssize_t profile_remove(struct filstruct aa_loaddata *data;struct aa_label *label;ssize_t error; -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private); label =begin_current_label_crit_section ();/* high level check about policy management - fine grained in
@@ -574,7 +647,7 @@ static int ns_revision_open(struct inodeif (!rev)return -ENOMEM ; - rev->ns =aa_get_ns (inode->i_private); + rev->ns =get_ns_common_ref (inode->i_private);if (!rev->ns) rev->ns =aa_get_current_ns (); file->private_data = rev;
@@ -1052,7 +1125,7 @@ static const struct file_operations seq_static int seq_profile_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_proxy *proxy =aa_get_proxy (inode->i_private); +struct aa_proxy *proxy =get_proxy_common_ref (inode->i_private);int error =single_open (file, show, proxy);if (error) {
@@ -1230,7 +1303,7 @@ static const struct file_operations seq_static int seq_rawdata_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_loaddata *data =aa_get_i_loaddata (inode->i_private); +struct aa_loaddata *data =get_loaddata_common_ref (inode->i_private);int error;if (!data)
@@ -1370,7 +1443,7 @@ static int rawdata_open(struct inode *inif (!policy_view_capable (NULL ))return -EACCES ; - loaddata =aa_get_i_loaddata (inode->i_private); + loaddata =get_loaddata_common_ref (inode->i_private);if (!loaddata)return -ENOENT ;
@@ -1415,7 +1488,6 @@ static void remove_rawdata_dents(structif (!IS_ERR_OR_NULL (rawdata->dents[i])) {aafs_remove (rawdata->dents[i]); rawdata->dents[i] =NULL ; -aa_put_i_loaddata (rawdata); } } }
@@ -1454,45 +1526,41 @@ int __aa_fs_create_rawdata(struct aa_nsif (IS_ERR (dir))/* ->name freed when rawdata freed */ return PTR_ERR (dir); -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DIR ] = dir; - dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, rawdata, + dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, &rawdata->count, &seq_rawdata_abi_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_ABI ] = dent; - dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, rawdata, - &seq_rawdata_revision_fops); + dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, + &rawdata->count, + &seq_rawdata_revision_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_REVISION ] = dent;if (aa_g_hash_policy) { dent =aafs_create_file ("sha1" ,S_IFREG |0444 , dir, - rawdata, &seq_rawdata_hash_fops); + &rawdata->count, + &seq_rawdata_hash_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_HASH ] = dent; } dent =aafs_create_file ("compressed_size" ,S_IFREG |0444 , dir, - rawdata, + &rawdata->count, &seq_rawdata_compressed_size_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE ] = dent; - dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , - dir, rawdata, &rawdata_fops); + dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , dir, + &rawdata->count, &rawdata_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DATA ] = dent;d_inode (dent)->i_size = rawdata->size;
@@ -1503,7 +1571,6 @@ int __aa_fs_create_rawdata(struct aa_ns fail:remove_rawdata_dents (rawdata); -aa_put_i_loaddata (rawdata);return PTR_ERR (dent); }
@@ -1525,13 +1592,10 @@ void __aafs_profile_rmdir(struct aa_prof__aafs_profile_rmdir (child);for (i =AAFS_PROF_SIZEOF -1 ; i >=0 ; --i) { -struct aa_proxy *proxy;if (!profile->dents[i])continue ; - proxy =d_inode (profile->dents[i])->i_private;aafs_remove (profile->dents[i]); -aa_put_proxy (proxy); profile->dents[i] =NULL ; } }
@@ -1561,14 +1625,7 @@ static struct dentry *create_profile_filstruct aa_profile *profile, const struct file_operations *fops) { - struct aa_proxy *proxy = aa_get_proxy(profile->label.proxy); -struct dentry *dent; - - dent =aafs_create_file (name,S_IFREG |0444 , dir, proxy, fops); -if (IS_ERR (dent)) -aa_put_proxy (proxy); - -return dent; + return aafs_create_file(name, S_IFREG | 0444, dir, &profile->label.proxy->count, fops); }static int profile_depth (struct aa_profile *profile)
@@ -1618,7 +1675,8 @@ static const char *rawdata_get_link_basestruct delayed_call *done, const char *name) { - struct aa_proxy *proxy = inode->i_private; + struct aa_common_ref *ref = inode->i_private; + struct aa_proxy *proxy = container_of(ref, struct aa_proxy, count);struct aa_label *label;struct aa_profile *profile;char *target;
@@ -1758,27 +1816,23 @@ int __aafs_profile_mkdir(struct aa_profiif (profile->rawdata) { dent =aafs_create ("raw_sha1" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_sha1_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_HASH ] = dent; - dent =aafs_create ("raw_abi" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_abi_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_ABI ] = dent; dent =aafs_create ("raw_data" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_data_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_DATA ] = dent; }
@@ -1814,7 +1868,7 @@ static int ns_mkdir_op(struct user_namesif (error)return error; - parent =aa_get_ns (dir->i_private); + parent =get_ns_common_ref (dir->i_private);AA_BUG (d_inode (ns_subns_dir (parent)) != dir);/* we have to unlock and then relock to get locking order right
@@ -1864,7 +1918,7 @@ static int ns_rmdir_op(struct inode *dirif (error)return error; - parent =aa_get_ns (dir->i_private); + parent =get_ns_common_ref (dir->i_private);/* rmdir calls the generic securityfs functions to remove files * from the apparmor dir. It is up to the apparmor ns locking * to avoid races.
@@ -1934,27 +1988,6 @@ void __aafs_ns_rmdir(struct aa_ns *ns)__aa_fs_list_remove_rawdata (ns); -if (ns_subns_dir (ns)) { - sub =d_inode (ns_subns_dir (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subload (ns)) { - sub =d_inode (ns_subload (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subreplace (ns)) { - sub =d_inode (ns_subreplace (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subremove (ns)) { - sub =d_inode (ns_subremove (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subrevision (ns)) { - sub =d_inode (ns_subrevision (ns))->i_private; -aa_put_ns (sub); - } -for (i =AAFS_NS_SIZEOF -1 ; i >=0 ; --i) {aafs_remove (ns->dents[i]); ns->dents[i] =NULL ;
@@ -1979,40 +2012,40 @@ static int __aafs_ns_mkdir_entries(strucreturn PTR_ERR (dent);ns_subdata_dir (ns) = dent; - dent =aafs_create_file ("revision" ,0444 , dir, ns, + dent =aafs_create_file ("revision" ,0444 , dir, + &ns->unconfined->label.count, &aa_fs_ns_revision_fops);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subrevision (ns) = dent; - dent =aafs_create_file (".load" ,0640 , dir, ns, - &aa_fs_profile_load); + dent =aafs_create_file (".load" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_load);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subload (ns) = dent; - dent =aafs_create_file (".replace" ,0640 , dir, ns, - &aa_fs_profile_replace); + dent =aafs_create_file (".replace" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_replace);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subreplace (ns) = dent; - dent =aafs_create_file (".remove" ,0640 , dir, ns, - &aa_fs_profile_remove); + dent =aafs_create_file (".remove" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_remove);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subremove (ns) = dent;/* use create_dentry so we can supply private data */ - dent =aafs_create ("namespaces" ,S_IFDIR |0755 , dir, ns,NULL ,NULL , - &ns_dir_inode_operations); + dent =aafs_create ("namespaces" ,S_IFDIR |0755 , dir, + &ns->unconfined->label.count, +NULL ,NULL , &ns_dir_inode_operations);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subns_dir (ns) = dent;return 0 ;
security/apparmor/include/label.h +8 -8
@@ -103,7 +103,7 @@ enum label_flags {struct aa_label ;struct aa_proxy { -struct kref count; +struct aa_common_ref count;struct aa_label __rcu *label; };
@@ -123,7 +123,7 @@ struct label_it {* @ent: set of profiles for label, actual size determined by @size */ struct aa_label { -struct kref count; +struct aa_common_ref count;struct rb_node node;struct rcu_head rcu;struct aa_proxy *proxy;
@@ -373,7 +373,7 @@ int aa_label_match(struct aa_profile *pr*/ static inline struct aa_label *__aa_get_label (struct aa_label *l) { -if (l &&kref_get_unless_zero (&l->count)) +if (l &&kref_get_unless_zero (&l->count.count))return l;return NULL ;
@@ -382,7 +382,7 @@ static inline struct aa_label *__aa_get_static inline struct aa_label *aa_get_label (struct aa_label *l) {if (l) -kref_get (&(l->count)); +kref_get (&(l->count.count));return l; }
@@ -402,7 +402,7 @@ static inline struct aa_label *aa_get_larcu_read_lock ();do { c =rcu_dereference (*l); - }while (c && !kref_get_unless_zero (&c->count)); + }while (c && !kref_get_unless_zero (&c->count.count));rcu_read_unlock ();return c;
@@ -442,7 +442,7 @@ static inline struct aa_label *aa_get_nestatic inline void aa_put_label (struct aa_label *l) {if (l) -kref_put (&l->count, aa_label_kref); +kref_put (&l->count.count, aa_label_kref); }
@@ -452,7 +452,7 @@ void aa_proxy_kref(struct kref *kref);static inline struct aa_proxy *aa_get_proxy (struct aa_proxy *proxy) {if (proxy) -kref_get (&(proxy->count)); +kref_get (&(proxy->count.count));return proxy; }
@@ -460,7 +460,7 @@ static inline struct aa_proxy *aa_get_prstatic inline void aa_put_proxy (struct aa_proxy *proxy) {if (proxy) -kref_put (&proxy->count, aa_proxy_kref); +kref_put (&proxy->count.count, aa_proxy_kref); }void __aa_proxy_redirect (struct aa_label *orig,struct aa_label *new);
security/apparmor/include/lib.h +12 -0
@@ -60,6 +60,18 @@ void aa_info_message(const char *str);/* Security blob offsets */ extern struct lsm_blob_sizes apparmor_blob_sizes; +enum reftype { +REF_NS , +REF_PROXY , +REF_RAWDATA , +}; + +/* common reference count used by data the shows up in aafs */ +struct aa_common_ref { +struct kref count; +enum reftype reftype; +}; +/** * aa_strneq - compare null terminated @str to a non null terminated substring * @str: a null terminated string
security/apparmor/include/policy.h +4 -4
@@ -243,7 +243,7 @@ static inline unsigned int PROFILE_MEDIAstatic inline struct aa_profile *aa_get_profile (struct aa_profile *p) {if (p) -kref_get (&(p->label.count)); +kref_get (&(p->label.count.count));return p; }
@@ -257,7 +257,7 @@ static inline struct aa_profile *aa_get_*/ static inline struct aa_profile *aa_get_profile_not0 (struct aa_profile *p) { -if (p &&kref_get_unless_zero (&p->label.count)) +if (p &&kref_get_unless_zero (&p->label.count.count))return p;return NULL ;
@@ -277,7 +277,7 @@ static inline struct aa_profile *aa_get_rcu_read_lock ();do { c =rcu_dereference (*p); - }while (c && !kref_get_unless_zero (&c->label.count)); + }while (c && !kref_get_unless_zero (&c->label.count.count));rcu_read_unlock ();return c;
@@ -290,7 +290,7 @@ static inline struct aa_profile *aa_get_static inline void aa_put_profile (struct aa_profile *p) {if (p) -kref_put (&p->label.count, aa_label_kref); +kref_put (&p->label.count.count, aa_label_kref); }static inline int AUDIT_MODE (struct aa_profile *profile)
security/apparmor/include/policy_unpack.h +3 -3
@@ -67,7 +67,7 @@ enum {* fs entries and drops the associated @count ref. */ struct aa_loaddata { -struct kref count; +struct aa_common_ref count;struct kref pcount;struct list_head list;struct work_struct work;
@@ -102,7 +102,7 @@ aa_get_i_loaddata(struct aa_loaddata *da {if (data) -kref_get (&(data->count)); +kref_get (&(data->count.count));return data; }
@@ -130,7 +130,7 @@ struct aa_loaddata *aa_loaddata_alloc(sistatic inline void aa_put_i_loaddata (struct aa_loaddata *data) {if (data) -kref_put (&data->count, aa_loaddata_kref); +kref_put (&data->count.count, aa_loaddata_kref); }static inline void aa_put_profile_loaddata (struct aa_loaddata *data)
security/apparmor/label.c +8 -4
@@ -52,7 +52,8 @@ static void free_proxy(struct aa_proxy *void aa_proxy_kref (struct kref *kref) { - struct aa_proxy *proxy = container_of(kref, struct aa_proxy, count); + struct aa_proxy *proxy = container_of(kref, struct aa_proxy, + count.count);free_proxy (proxy); }
@@ -63,7 +64,8 @@ struct aa_proxy *aa_alloc_proxy(struct a new =kzalloc (sizeof (struct aa_proxy ), gfp);if (new) { -kref_init (&new->count); +kref_init (&new->count.count); + new->count.reftype =REF_PROXY ;rcu_assign_pointer (new->label,aa_get_label (label)); }return new;
@@ -366,7 +368,8 @@ static void label_free_rcu(struct rcu_hevoid aa_label_kref (struct kref *kref) { - struct aa_label *label = container_of(kref, struct aa_label, count); + struct aa_label *label = container_of(kref, struct aa_label, + count.count);struct aa_ns *ns =labels_ns (label);if (!ns) {
@@ -403,7 +406,8 @@ bool aa_label_init(struct aa_label *labe label->size = size;/* doesn't include null */ label->vec[size] =NULL ;/* null terminate */ -kref_init (&label->count); +kref_init (&label->count.count); + label->count.reftype =REF_NS ;/* for aafs purposes */ RB_CLEAR_NODE (&label->node);return true;
security/apparmor/policy_unpack.c +4 -2
@@ -157,7 +157,8 @@ static void do_loaddata_free(struct aa_lvoid aa_loaddata_kref (struct kref *kref) { - struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, + count.count);do_loaddata_free (d); }
@@ -204,7 +205,8 @@ struct aa_loaddata *aa_loaddata_alloc(sikfree (d);return ERR_PTR (-ENOMEM ); } -kref_init (&d->count); +kref_init (&d->count.count); + d->count.reftype =REF_RAWDATA ;kref_init (&d->pcount);INIT_LIST_HEAD (&d->list);
Greg Kroah-Hartman
maintainerPATCH 526/570 netfilter: nft_ct: fix use-after-free in timeout object destroy
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tuan Do <[email protected]>
commit f8dca15a1b190787bbd03285304b569631160eda upstream.
nft_ct_timeout_obj_destroy() frees the timeout object with kfree() immediately after nf_ct_untimeout(), without waiting for an RCU grace period. Concurrent packet processing on other CPUs may still hold RCU-protected references to the timeout object obtained via rcu_dereference() in nf_ct_timeout_data().
Add an rcu_head to struct nf_ct_timeout and use kfree_rcu() to defer freeing until after an RCU grace period, matching the approach already used in nfnetlink_cttimeout.c.
KASAN report:
BUG: KASAN: slab-use-after-free in nf_conntrack_tcp_packet+0x1381/0x29d0 Read of size 4 at addr ffff8881035fe19c by task exploit/80 Call Trace: nf_conntrack_tcp_packet+0x1381/0x29d0 nf_conntrack_in+0x612/0x8b0 nf_hook_slow+0x70/0x100 __ip_local_out+0x1b2/0x210 tcp_sendmsg_locked+0x722/0x1580 __sys_sendto+0x2d8/0x320 Allocated by task 75: nft_ct_timeout_obj_init+0xf6/0x290 nft_obj_init+0x107/0x1b0 nf_tables_newobj+0x680/0x9c0 nfnetlink_rcv_batch+0xc29/0xe00 Freed by task 26: nft_obj_destroy+0x3f/0xa0 nf_tables_trans_destroy_work+0x51c/0x5c0 process_one_work+0x2c4/0x5a0
--- include/net/netfilter/nf_conntrack_timeout.h | 1 + net/netfilter/nft_ct.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/netfilter/nf_conntrack_timeout.h +1 -0
@@ -14,6 +14,7 @@struct nf_ct_timeout {__u16 l3num;const struct nf_conntrack_l4proto *l4proto; +struct rcu_head rcu;char data[]; };
net/netfilter/nft_ct.c +1 -1
@@ -935,7 +935,7 @@ static void nft_ct_timeout_obj_destroy(cnf_queue_nf_hook_drop (ctx->net);nf_ct_untimeout (ctx->net, timeout);nf_ct_netns_put (ctx->net, ctx->family); -kfree (priv->timeout); +kfree_rcu (priv->timeout, rcu); } static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
Greg Kroah-Hartman
maintainerPATCH 527/570 tipc: fix bc_ackers underflow on duplicate GRP_ACK_MSG
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleh Konko <[email protected]>
commit 48a5fe38772b6f039522469ee6131a67838221a8 upstream.
The GRP_ACK_MSG handler in tipc_group_proto_rcv() currently decrements bc_ackers on every inbound group ACK, even when the same member has already acknowledged the current broadcast round.
Because bc_ackers is a u16, a duplicate ACK received after the last legitimate ACK wraps the counter to 65535. Once wrapped, tipc_group_bc_cong() keeps reporting congestion and later group broadcasts on the affected socket stay blocked until the group is recreated.
Fix this by ignoring duplicate or stale ACKs before touching bc_acked or bc_ackers. This makes repeated GRP_ACK_MSG handling idempotent and prevents the underflow path.
--- net/tipc/group.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/tipc/group.c +5 -1
@@ -746,6 +746,7 @@ void tipc_group_proto_rcv(struct tipc_gru32 port =msg_origport (hdr);struct tipc_member *m, *pm;u16 remitted, in_flight; +u16 acked;if (!grp)return ;
@@ -798,7 +799,10 @@ void tipc_group_proto_rcv(struct tipc_grcase GRP_ACK_MSG :if (!m)return ; - m->bc_acked =msg_grp_bc_acked (hdr); + acked =msg_grp_bc_acked (hdr); +if (less_eq (acked, m->bc_acked)) +return ; + m->bc_acked = acked;if (--grp->bc_ackers)return ;list_del_init (&m->small_win);
Greg Kroah-Hartman
maintainerPATCH 528/570 wifi: brcmsmac: Fix dma_free_coherent() size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
commit 12cd7632757a54ce586e36040210b1a738a0fc53 upstream.
dma_alloc_consistent() may change the size to align it. The new size is saved in alloced.
Change the free size to match the allocation size.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c +1 -1
@@ -483,7 +483,7 @@ static void *dma_ringalloc(struct dma_inif (((desc_strtaddr + size -1 ) & boundary) != (desc_strtaddr & boundary)) { *alignbits =dma_align_sizetobits (size); -dma_free_coherent (di->dmadev, size, va, *descpa); +dma_free_coherent (di->dmadev, *alloced, va, *descpa); va =dma_alloc_consistent (di, size, *alignbits, alloced, descpa); }
Greg Kroah-Hartman
maintainerPATCH 529/570 arm64: dts: hisilicon: poplar: Correct PCIe reset GPIO polarity
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
commit c1f2b0f2b5e37b2c27540a175aea2755a3799433 upstream.
The PCIe reset GPIO on Poplar is actually active low. The active high worked before because kernel driver didn't respect the setting from DT. This is changed since commit 1d26a55fbeb9 ("PCI: histb: Switch to using gpiod API"), and thus PCIe on Poplar got brken since then.
Fix the problem by correcting the polarity.
--- arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dts +1 -1
@@ -179,7 +179,7 @@ }; &pcie { - reset-gpios = <&gpio4 4 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio4 4 GPIO_ACTIVE_LOW>; vpcie-supply = <®_pcie>; status = "okay"; };
Greg Kroah-Hartman
maintainerPATCH 530/570 arm64: dts: hisilicon: hi3798cv200: Add missing dma-ranges
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
commit 1af997cad473d505248df6d9577183bb91f69670 upstream.
Reboot starts failing on Poplar since commit 8424ecdde7df ("arm64: mm:
Set ZONE_DMA size based on devicetree's dma-ranges"), which effectively changes zone_dma_bits from 30 to 32 for arm64 platforms that do not properly define dma-ranges in device tree. It's unclear how Poplar reboot gets broken by this change exactly, but a dma-ranges limiting zone_dma to the first 1 GB fixes the regression.
--- arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi +1 -0
@@ -81,6 +81,7 @@ #address-cells = <1>; #size-cells = <1>; ranges = <0x0 0x0 0xf0000000 0x10000000>; + dma-ranges = <0x0 0x0 0x0 0x40000000>; crg: clock-reset-controller@8a22000 { compatible = "hisilicon,hi3798cv200-crg", "syscon", "simple-mfd";
Greg Kroah-Hartman
maintainerPATCH 531/570 nfc: pn533: allocate rx skb before consuming bytes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit c71ba669b570c7b3f86ec875be222ea11dacb352 upstream.
pn532_receive_buf() reports the number of accepted bytes to the serdev core. The current code consumes bytes into recv_skb and may already hand a complete frame to pn533_recv_frame() before allocating a fresh receive buffer.
If that alloc_skb() fails, the callback returns 0 even though it has already consumed bytes, and it leaves recv_skb as NULL for the next receive callback. That breaks the receive_buf() accounting contract and can also lead to a NULL dereference on the next skb_put_u8().
Allocate the receive skb lazily before consuming the next byte instead. If allocation fails, return the number of bytes already accepted.
--- drivers/nfc/pn533/uart.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nfc/pn533/uart.c +8 -3
@@ -211,6 +211,13 @@ static int pn532_receive_buf(struct serddel_timer (&dev->cmd_timeout);for (i =0 ; i < count; i++) { +if (!dev->recv_skb) { + dev->recv_skb =alloc_skb (PN532_UART_SKB_BUFF_LEN , +GFP_KERNEL ); +if (!dev->recv_skb) +return i; + } +if (unlikely (!skb_tailroom (dev->recv_skb)))skb_trim (dev->recv_skb,0 );
@@ -219,9 +226,7 @@ static int pn532_receive_buf(struct serdcontinue ;pn533_recv_frame (dev->priv, dev->recv_skb,0 ); - dev->recv_skb =alloc_skb (PN532_UART_SKB_BUFF_LEN ,GFP_KERNEL ); -if (!dev->recv_skb) -return 0 ; + dev->recv_skb =NULL ; }return i;
Greg Kroah-Hartman
maintainerPATCH 532/570 batman-adv: reject oversized global TT response buffers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruide Cao <[email protected]>
commit 3a359bf5c61d52e7f09754108309d637532164a6 upstream.
batadv_tt_prepare_tvlv_global_data() builds the allocation length for a global TT response in 16-bit temporaries. When a remote originator advertises a large enough global TT, the TT payload length plus the VLAN header offset can exceed 65535 and wrap before kmalloc().
The full-table response path still uses the original TT payload length when it fills tt_change, so the wrapped allocation is too small and batadv_tt_prepare_tvlv_global_data() writes past the end of the heap object before the later packet-size check runs.
Fix this by rejecting TT responses whose TVLV value length cannot fit in the 16-bit TVLV payload length field.
--- net/batman-adv/translation-table.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/batman-adv/translation-table.c +7 -2
@@ -844,8 +844,8 @@ batadv_tt_prepare_tvlv_global_data(struc {u16 num_vlan =0 ;u16 num_entries =0 ; -u16 change_offset; -u16 tvlv_len; +u16 tvlv_len =0 ; +unsigned int change_offset;struct batadv_tvlv_tt_vlan_data *tt_vlan;struct batadv_orig_node_vlan *vlan;u8 *tt_change_ptr;
@@ -863,6 +863,11 @@ batadv_tt_prepare_tvlv_global_data(strucif (*tt_len <0 ) *tt_len =batadv_tt_len (num_entries); +if (change_offset >U16_MAX || *tt_len >U16_MAX - change_offset) { + *tt_len =0 ; + goto out; + } + tvlv_len = *tt_len; tvlv_len += change_offset;
Greg Kroah-Hartman
maintainerPATCH 533/570 net/tls: fix use-after-free in -EBUSY error path of tls_do_encryption
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Alifa Ramdhan <[email protected]>
commit a9b8b18364fffce4c451e6f6fd218fa4ab646705 upstream.
The -EBUSY handling in tls_do_encryption(), introduced by commit 859054147318 ("net: tls: handle backlogging of crypto requests"), has a use-after-free due to double cleanup of encrypt_pending and the scatterlist entry.
When crypto_aead_encrypt() returns -EBUSY, the request is enqueued to the cryptd backlog and the async callback tls_encrypt_done() will be invoked upon completion. That callback unconditionally restores the scatterlist entry (sge->offset, sge->length) and decrements ctx->encrypt_pending. However, if tls_encrypt_async_wait() returns an error, the synchronous error path in tls_do_encryption() performs the same cleanup again, double-decrementing encrypt_pending and double-restoring the scatterlist.
The double-decrement corrupts the encrypt_pending sentinel (initialized to 1), making tls_encrypt_async_wait() permanently skip the wait for pending async callbacks. A subsequent sendmsg can then free the tls_rec via bpf_exec_tx_verdict() while a cryptd callback is still pending, resulting in a use-after-free when the callback fires on the freed record.
Fix this by skipping the synchronous cleanup when the -EBUSY async wait returns an error, since the callback has already handled encrypt_pending and sge restoration.
--- net/tls/tls_sw.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/tls/tls_sw.c +10 -0
@@ -568,6 +568,16 @@ static int tls_do_encryption(struct sockif (rc == -EBUSY ) { rc =tls_encrypt_async_wait (ctx); rc = rc ?: -EINPROGRESS ; +/* +* The async callback tls_encrypt_done() has already +* decremented encrypt_pending and restored the sge on +* both success and error. Skip the synchronous cleanup +* below on error, just remove the record and return. +*/ +if (rc != -EINPROGRESS ) { +list_del (&rec->list); +return rc; + } }if (!rc || rc != -EINPROGRESS ) {atomic_dec (&ctx->encrypt_pending);
Greg Kroah-Hartman
maintainerPATCH 534/570 net: altera-tse: fix skb leak on DMA mapping error in tse_start_xmit()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit 6dede3967619b5944003227a5d09fdc21ed57d10 upstream.
When dma_map_single() fails in tse_start_xmit(), the function returns NETDEV_TX_OK without freeing the skb. Since NETDEV_TX_OK tells the stack the packet was consumed, the skb is never freed, leaking memory on every DMA mapping failure.
Add dev_kfree_skb_any() before returning to properly free the skb.
--- drivers/net/ethernet/altera/altera_tse_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/altera/altera_tse_main.c +1 -0
@@ -591,6 +591,7 @@ static netdev_tx_t tse_start_xmit(struct DMA_TO_DEVICE);if (dma_mapping_error (priv->device, dma_addr)) {netdev_err (priv->dev,"%s: DMA mapping error\n" , __func__); +dev_kfree_skb_any (skb); ret =NETDEV_TX_OK ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 535/570 drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Brzezinka <[email protected]>
commit 4c71fd099513bfa8acab529b626e1f0097b76061 upstream.
A use-after-free / refcount underflow is possible when the heartbeat worker and intel_engine_park_heartbeat() race to release the same engine->heartbeat.systole request.
The heartbeat worker reads engine->heartbeat.systole and calls i915_request_put() on it when the request is complete, but clears the pointer in a separate, non-atomic step. Concurrently, a request retirement on another CPU can drop the engine wakeref to zero, triggering __engine_park() -> intel_engine_park_heartbeat(). If the heartbeat timer is pending at that point, cancel_delayed_work() returns true and intel_engine_park_heartbeat() reads the stale non-NULL systole pointer and calls i915_request_put() on it again, causing a refcount underflow:
``` <4> [487.221889] Workqueue: i915-unordered engine_retire [i915] <4> [487.222640] RIP: 0010:refcount_warn_saturate+0x68/0xb0 ... <4> [487.222707] Call Trace: <4> [487.222711] <TASK> <4> [487.222716] intel_engine_park_heartbeat.part.0+0x6f/0x80 [i915] <4> [487.223115] intel_engine_park_heartbeat+0x25/0x40 [i915] <4> [487.223566] __engine_park+0xb9/0x650 [i915] <4> [487.223973] ____intel_wakeref_put_last+0x2e/0xb0 [i915] <4> [487.224408] __intel_wakeref_put_last+0x72/0x90 [i915] <4> [487.224797] intel_context_exit_engine+0x7c/0x80 [i915] <4> [487.225238] intel_context_exit+0xf1/0x1b0 [i915] <4> [487.225695] i915_request_retire.part.0+0x1b9/0x530 [i915] <4> [487.226178] i915_request_retire+0x1c/0x40 [i915] <4> [487.226625] engine_retire+0x122/0x180 [i915] <4> [487.227037] process_one_work+0x239/0x760 <4> [487.227060] worker_thread+0x200/0x3f0 <4> [487.227068] ? __pfx_worker_thread+0x10/0x10 <4> [487.227075] kthread+0x10d/0x150 <4> [487.227083] ? __pfx_kthread+0x10/0x10 <4> [487.227092] ret_from_fork+0x3d4/0x480 <4> [487.227099] ? __pfx_kthread+0x10/0x10 <4> [487.227107] ret_from_fork_asm+0x1a/0x30 <4> [487.227141] </TASK> ```
Fix this by replacing the non-atomic pointer read + separate clear with xchg() in both racing paths. xchg() is a single indivisible hardware instruction that atomically reads the old pointer and writes NULL. This guarantees only one of the two concurrent callers obtains the non-NULL pointer and performs the put, the other gets NULL and skips it.
--- drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c | 26 +++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +18 -8
@@ -116,10 +116,12 @@ static void heartbeat(struct work_struct/* Just in case everything has gone horribly wrong, give it a kick */ intel_engine_flush_submission (engine); - rq = engine->heartbeat.systole; -if (rq &&i915_request_completed (rq)) { -i915_request_put (rq); - engine->heartbeat.systole =NULL ; + rq =xchg (&engine->heartbeat.systole,NULL ); +if (rq) { +if (i915_request_completed (rq)) +i915_request_put (rq); +else + engine->heartbeat.systole = rq; }if (!intel_engine_pm_get_if_awake (engine))
@@ -200,8 +202,11 @@ static void heartbeat(struct work_struct unlock:mutex_unlock (&ce->timeline->mutex); out: -if (!engine->i915->params.enable_hangcheck || !next_heartbeat (engine)) -i915_request_put (fetch_and_zero (&engine->heartbeat.systole)); +if (!engine->i915->params.enable_hangcheck || !next_heartbeat (engine)) { + rq =xchg (&engine->heartbeat.systole,NULL ); +if (rq) +i915_request_put (rq); + }intel_engine_pm_put (engine); }
@@ -215,8 +220,13 @@ void intel_engine_unpark_heartbeat(strucvoid intel_engine_park_heartbeat (struct intel_engine_cs *engine) { -if (cancel_delayed_work (&engine->heartbeat.work)) -i915_request_put (fetch_and_zero (&engine->heartbeat.systole)); +if (cancel_delayed_work (&engine->heartbeat.work)) { +struct i915_request *rq; + + rq =xchg (&engine->heartbeat.systole,NULL ); +if (rq) +i915_request_put (rq); + } }void intel_gt_unpark_heartbeats (struct intel_gt *gt)
Greg Kroah-Hartman
maintainerPATCH 536/570 mmc: vub300: fix NULL-deref on disconnect
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit dff34ef879c5e73298443956a8b391311ba78d57 upstream.
Make sure to deregister the controller before dropping the reference to the driver data on disconnect to avoid NULL-pointer dereferences or use-after-free.
--- drivers/mmc/host/vub300.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/vub300.c +1 -1
@@ -2371,8 +2371,8 @@ static void vub300_disconnect(struct usbusb_set_intfdata (interface,NULL );/* prevent more I/O from starting */ vub300->interface =NULL ; -kref_put (&vub300->kref, vub300_delete);mmc_remove_host (mmc); +kref_put (&vub300->kref, vub300_delete);pr_info ("USB vub300 remote SDIO host controller[%d]" " now disconnected" , ifnum);return ;
Greg Kroah-Hartman
maintainerPATCH 537/570 net: qualcomm: qca_uart: report the consumed byte on RX skb allocation failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit b76254c55dc8f23edc089027dd3f8792554c69fb upstream.
qca_tty_receive() consumes each input byte before checking whether a completed frame needs a fresh receive skb. When the current byte completes a frame, the driver delivers that frame and then allocates a new skb for the next one.
If that allocation fails, the current code returns i even though data[i] has already been consumed and may already have completed the delivered frame. Since serdev interprets the return value as the number of accepted bytes, this under-reports progress by one byte and can replay the final byte of the completed frame into a fresh parser state on the next call.
Return i + 1 in that failure path so the accepted-byte count matches the actual receive-state progress.
--- drivers/net/ethernet/qualcomm/qca_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qualcomm/qca_uart.c +1 -1
@@ -115,7 +115,7 @@ qca_tty_receive(struct serdev_device *seif (!qca->rx_skb) {netdev_dbg (netdev,"recv: out of RX resources\n" ); n_stats->rx_errors++; -return i; +return i +1 ; } } }
Greg Kroah-Hartman
maintainerPATCH 538/570 net: stmmac: fix integer underflow in chain mode
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyllis Xu <[email protected]>
commit 51f4e090b9f87b40c21b6daadb5c06e6c0a07b67 upstream.
The jumbo_frm() chain-mode implementation unconditionally computes
len = nopaged_len - bmax;
where nopaged_len = skb_headlen(skb) (linear bytes only) and bmax is BUF_SIZE_8KiB or BUF_SIZE_2KiB. However, the caller stmmac_xmit() decides to invoke jumbo_frm() based on skb->len (total length including page fragments):
is_jumbo = stmmac_is_jumbo_frm(priv, skb->len, enh_desc);
When a packet has a small linear portion (nopaged_len <= bmax) but a large total length due to page fragments (skb->len > bmax), the subtraction wraps as an unsigned integer, producing a huge len value (~0xFFFFxxxx). This causes the while (len != 0) loop to execute hundreds of thousands of iterations, passing skb->data + bmax * i pointers far beyond the skb buffer to dma_map_single(). On IOMMU-less SoCs (the typical deployment for stmmac), this maps arbitrary kernel memory to the DMA engine, constituting a kernel memory disclosure and potential memory corruption from hardware.
Fix this by introducing a buf_len local variable clamped to min(nopaged_len, bmax). Computing len = nopaged_len - buf_len is then always safe: it is zero when the linear portion fits within a single descriptor, causing the while (len != 0) loop to be skipped naturally, and the fragment loop in stmmac_xmit() handles page fragments afterward.
--- drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +6 -5
@@ -20,7 +20,7 @@ static int jumbo_frm(void *p, struct sk_unsigned int nopaged_len =skb_headlen (skb);struct stmmac_priv *priv = tx_q->priv_data;unsigned int entry = tx_q->cur_tx; -unsigned int bmax, des2; +unsigned int bmax, buf_len, des2;unsigned int i =1 , len;struct dma_desc *desc;
@@ -31,17 +31,18 @@ static int jumbo_frm(void *p, struct sk_else bmax = BUF_SIZE_2KiB; - len = nopaged_len - bmax; + buf_len = min_t(unsigned int, nopaged_len, bmax); + len = nopaged_len - buf_len; des2 =dma_map_single (priv->device, skb->data, - bmax,DMA_TO_DEVICE ); + buf_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2);if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; - tx_q->tx_skbuff_dma[entry].len = bmax; + tx_q->tx_skbuff_dma[entry].len = buf_len;/* do not close the descriptor and do not set own bit */ -stmmac_prepare_tx_desc (priv, desc,1 , bmax, csum,STMMAC_CHAIN_MODE , +stmmac_prepare_tx_desc (priv, desc,1 , buf_len, csum,STMMAC_CHAIN_MODE ,0 , false, skb->len);while (len !=0 ) {
Greg Kroah-Hartman
maintainerPATCH 539/570 rxrpc: fix reference count leak in rxrpc_server_keyring()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit f125846ee79fcae537a964ce66494e96fa54a6de upstream.
This patch fixes a reference count leak in rxrpc_server_keyring() by checking if rx->securities is already set.
--- net/rxrpc/server_key.c | 3 +++ 1 file changed, 3 insertions(+)
net/rxrpc/server_key.c +3 -0
@@ -125,6 +125,9 @@ int rxrpc_server_keyring(struct rxrpc_so_enter ("" ); +if (rx->securities) +return -EINVAL ; +if (optlen <=0 || optlen >PAGE_SIZE -1 )return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 540/570 rxrpc: Fix key/keyring checks in setsockopt(RXRPC_SECURITY_KEY/KEYRING)
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
commit 2afd86ccbb2082a3c4258aea8c07e5bb6267bc2f upstream.
An AF_RXRPC socket can be both client and server at the same time. When sending new calls (ie. it's acting as a client), it uses rx->key to set the security, and when accepting incoming calls (ie. it's acting as a server), it uses rx->securities.
setsockopt(RXRPC_SECURITY_KEY) sets rx->key to point to an rxrpc-type key and setsockopt(RXRPC_SECURITY_KEYRING) sets rx->securities to point to a keyring of rxrpc_s-type keys.
Now, it should be possible to use both rx->key and rx->securities on the same socket - but for userspace AF_RXRPC sockets rxrpc_setsockopt() prevents that.
Fix this by:
(1) Remove the incorrect check rxrpc_setsockopt(RXRPC_SECURITY_KEYRING)
makes on rx->key.
(2) Move the check that rxrpc_setsockopt(RXRPC_SECURITY_KEY) makes on
rx->key down into rxrpc_request_key().
(3) Remove rxrpc_request_key()'s check on rx->securities.
This (in combination with a previous patch) pushes the checks down into the functions that set those pointers and removes the cross-checks that prevent both key and keyring being set.
--- net/rxrpc/af_rxrpc.c | 6 ------ net/rxrpc/key.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-)
net/rxrpc/af_rxrpc.c +0 -6
@@ -615,9 +615,6 @@ static int rxrpc_setsockopt(struct socke goto success;case RXRPC_SECURITY_KEY : - ret = -EINVAL ; -if (rx->key) - goto error; ret = -EISCONN ;if (rx->sk.sk_state !=RXRPC_UNBOUND ) goto error;
@@ -625,9 +622,6 @@ static int rxrpc_setsockopt(struct socke goto error;case RXRPC_SECURITY_KEYRING : - ret = -EINVAL ; -if (rx->key) - goto error; ret = -EISCONN ;if (rx->sk.sk_state !=RXRPC_UNBOUND ) goto error;
net/rxrpc/key.c +1 -1
@@ -452,7 +452,7 @@ int rxrpc_request_key(struct rxrpc_sock_enter ("" ); -if (optlen <=0 || optlen >PAGE_SIZE -1 || rx->securities) +if (optlen <=0 || optlen >PAGE_SIZE -1 || rx->key)return -EINVAL ; description =memdup_sockptr_nul (optval, optlen);
Greg Kroah-Hartman
maintainerPATCH 541/570 netlink: add nla be16/32 types to minlen array
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 9a0d18853c280f6a0ee99f91619f2442a17a323a upstream.
BUG: KMSAN: uninit-value in nla_validate_range_unsigned lib/nlattr.c:222 [inline] BUG: KMSAN: uninit-value in nla_validate_int_range lib/nlattr.c:336 [inline] BUG: KMSAN: uninit-value in validate_nla lib/nlattr.c:575 [inline] BUG: KMSAN: uninit-value in __nla_validate_parse+0x2e20/0x45c0 lib/nlattr.c:631 nla_validate_range_unsigned lib/nlattr.c:222 [inline] nla_validate_int_range lib/nlattr.c:336 [inline] validate_nla lib/nlattr.c:575 [inline]
...
The message in question matches this policy:
[NFTA_TARGET_REV] = NLA_POLICY_MAX(NLA_BE32, 255),
but because NLA_BE32 size in minlen array is 0, the validation code will read past the malformed (too small) attribute.
Note: Other attributes, e.g. BITFIELD32, SINT, UINT.. are also missing:
those likely should be added too.
--- lib/nlattr.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/nlattr.c +4 -0
@@ -30,6 +30,8 @@ static const u8 nla_attr_len[NLA_TYPE_MA [NLA_S16] = sizeof(s16), [NLA_S32] = sizeof(s32), [NLA_S64] = sizeof(s64), + [NLA_BE16] = sizeof(__be16), + [NLA_BE32] = sizeof(__be32), };static const u8 nla_attr_minlen[NLA_TYPE_MAX +1 ] = {
@@ -43,6 +45,8 @@ static const u8 nla_attr_minlen[NLA_TYPE [NLA_S16] = sizeof(s16), [NLA_S32] = sizeof(s32), [NLA_S64] = sizeof(s64), + [NLA_BE16] = sizeof(__be16), + [NLA_BE32] = sizeof(__be32), };/*
Greg Kroah-Hartman
maintainerPATCH 542/570 xen/privcmd: unregister xenstore notifier on module exit
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: GuoHan Zhao <[email protected]>
commit cd7e1fef5a1ca1c4fcd232211962ac2395601636 upstream.
Commit 453b8fb68f36 ("xen/privcmd: restrict usage in unprivileged domU") added a xenstore notifier to defer setting the restriction target until Xenstore is ready.
XEN_PRIVCMD can be built as a module, but privcmd_exit() leaves that notifier behind. Balance the notifier lifecycle by unregistering it on module exit.
This is harmless even if xenstore was already ready at registration time and the notifier was never queued on the chain.
Message-ID: <[email protected]>
--- drivers/xen/privcmd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/xen/privcmd.c +3 -0
@@ -1068,6 +1068,9 @@ static int __init privcmd_init(void) static void __exit privcmd_exit(void) { +if (!xen_initial_domain ()) +unregister_xenstore_notifier (&xenstore_notifier); +misc_deregister (&privcmd_dev);misc_deregister (&xen_privcmdbuf_dev); }
Greg Kroah-Hartman
maintainerPATCH 543/570 Revert "mptcp: add needs_id for netlink appending addr"
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 8e2760eaab778494fc1fa257031e0e1799647f46 ]
This commit was originally adding the ability to add MPTCP endpoints with ID 0 by accident. The in-kernel PM, handling MPTCP endpoints at the net namespace level, is not supposed to handle endpoints with such ID, because this ID 0 is reserved to the initial subflow, as mentioned in the MPTCPv1 protocol [1], a per-connection setting.
Note that 'ip mptcp endpoint add id 0' stops early with an error, but other tools might still request the in-kernel PM to create MPTCP endpoints with this restricted ID 0.
In other words, it was wrong to call the mptcp_pm_has_addr_attr_id helper to check whether the address ID attribute is set: if it was set to 0, a new MPTCP endpoint would be created with ID 0, which is not expected, and might cause various issues later.
--- net/mptcp/pm_netlink.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
net/mptcp/pm_netlink.c +5 -19
@@ -972,8 +972,7 @@ static bool address_use_port(struct mptc }static int mptcp_pm_nl_append_new_local_addr (struct pm_nl_pernet *pernet, -struct mptcp_pm_addr_entry *entry, -bool needs_id) +struct mptcp_pm_addr_entry *entry) {struct mptcp_pm_addr_entry *cur;unsigned int addr_max;
@@ -1000,7 +999,7 @@ static int mptcp_pm_nl_append_new_local_ goto out; } -if (!entry->addr.id && needs_id) { +if (!entry->addr.id) { find_next: entry->addr.id = find_next_zero_bit(pernet->id_bitmap, MAX_ADDR_ID + 1,
@@ -1011,7 +1010,7 @@ find_next: } } -if (!entry->addr.id && needs_id) +if (!entry->addr.id) goto out;__set_bit (entry->addr.id, pernet->id_bitmap);
@@ -1152,7 +1151,7 @@ int mptcp_pm_nl_get_local_id(struct mptc entry->ifindex =0 ; entry->flags =0 ; entry->lsk =NULL ; - ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, true); + ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 )kfree (entry);
@@ -1374,18 +1373,6 @@ next:return 0 ; } -static bool mptcp_pm_has_addr_attr_id (const struct nlattr *attr, -struct genl_info *info) -{ -struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX +1 ]; - -if (!nla_parse_nested_deprecated (tb,MPTCP_PM_ADDR_ATTR_MAX , attr, - mptcp_pm_addr_policy, info->extack) && - tb[MPTCP_PM_ADDR_ATTR_ID ]) -return true; -return false; -} -static int mptcp_nl_cmd_add_addr (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];
@@ -1412,8 +1399,7 @@ static int mptcp_nl_cmd_add_addr(structreturn ret; } } - ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, - !mptcp_pm_has_addr_attr_id (attr, info)); + ret =mptcp_pm_nl_append_new_local_addr (pernet, entry);if (ret <0 ) {GENL_SET_ERR_MSG (info,"too many addresses or duplicate one" );if (entry->lsk)
Greg Kroah-Hartman
maintainerPATCH 544/570 seg6: separate dst_cache for input and output paths in seg6 lwtunnel
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Mayer <[email protected]>
[ Upstream commit c3812651b522fe8437ebb7063b75ddb95b571643 ]
The seg6 lwtunnel uses a single dst_cache per encap route, shared between seg6_input_core() and seg6_output_core(). These two paths can perform the post-encap SID lookup in different routing contexts (e.g., ip rules matching on the ingress interface, or VRF table separation). Whichever path runs first populates the cache, and the other reuses it blindly, bypassing its own lookup.
Fix this by splitting the cache into cache_input and cache_output, so each path maintains its own cached dst independently.
--- net/ipv6/seg6_iptunnel.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
net/ipv6/seg6_iptunnel.c +28 -13
@@ -48,7 +48,8 @@ static size_t seg6_lwt_headroom(struct s }struct seg6_lwt { -struct dst_cache cache; +struct dst_cache cache_input; +struct dst_cache cache_output;struct seg6_iptunnel_encap tuninfo[]; };
@@ -486,7 +487,7 @@ static int seg6_input_core(struct net *n slwt =seg6_lwt_lwtunnel (lwtst);local_bh_disable (); - dst =dst_cache_get (&slwt->cache); + dst =dst_cache_get (&slwt->cache_input);local_bh_enable (); err =seg6_do_srh (skb, dst);
@@ -504,7 +505,7 @@ static int seg6_input_core(struct net *n/* cache only if we don't create a dst reference loop */ if (!dst->error && lwtst != dst->lwtstate) {local_bh_disable (); -dst_cache_set_ip6 (&slwt->cache, dst, +dst_cache_set_ip6 (&slwt->cache_input, dst, &ipv6_hdr (skb)->saddr);local_bh_enable (); }
@@ -563,7 +564,7 @@ static int seg6_output_core(struct net * slwt =seg6_lwt_lwtunnel (orig_dst->lwtstate);local_bh_disable (); - dst =dst_cache_get (&slwt->cache); + dst =dst_cache_get (&slwt->cache_output);local_bh_enable (); err =seg6_do_srh (skb, dst);
@@ -587,9 +588,12 @@ static int seg6_output_core(struct net * goto drop; } -local_bh_disable (); -dst_cache_set_ip6 (&slwt->cache, dst, &fl6.saddr); -local_bh_enable (); +/* cache only if we don't create a dst reference loop */ +if (orig_dst->lwtstate != dst->lwtstate) { +local_bh_disable (); +dst_cache_set_ip6 (&slwt->cache_output, dst, &fl6.saddr); +local_bh_enable (); + } err =skb_cow_head (skb,LL_RESERVED_SPACE (dst->dev));if (unlikely (err))
@@ -697,11 +701,13 @@ static int seg6_build_state(struct net * slwt =seg6_lwt_lwtunnel (newts); - err =dst_cache_init (&slwt->cache,GFP_ATOMIC ); -if (err) { -kfree (newts); -return err; - } + err =dst_cache_init (&slwt->cache_input,GFP_ATOMIC ); +if (err) + goto err_free_newts; + + err =dst_cache_init (&slwt->cache_output,GFP_ATOMIC ); +if (err) + goto err_destroy_input;memcpy (&slwt->tuninfo, tuninfo, tuninfo_len);
@@ -716,11 +722,20 @@ static int seg6_build_state(struct net * *ts = newts;return 0 ; + +err_destroy_input: +dst_cache_destroy (&slwt->cache_input); +err_free_newts: +kfree (newts); +return err; }static void seg6_destroy_state (struct lwtunnel_state *lwt) { -dst_cache_destroy (&seg6_lwt_lwtunnel (lwt)->cache); +struct seg6_lwt *slwt =seg6_lwt_lwtunnel (lwt); + +dst_cache_destroy (&slwt->cache_input); +dst_cache_destroy (&slwt->cache_output); } static int seg6_fill_encap_info(struct sk_buff *skb,
Greg Kroah-Hartman
maintainerPATCH 545/570 net: rfkill: prevent unlimited numbers of rfkill events from being created
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit ea245d78dec594372e27d8c79616baf49e98a4a1 ]
Userspace can create an unlimited number of rfkill events if the system is so configured, while not consuming them from the rfkill file descriptor, causing a potential out of memory situation. Prevent this from bounding the number of pending rfkill events at a "large" number (i.e. 1000) to prevent abuses like this.
--- net/rfkill/core.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
net/rfkill/core.c +25 -12
@@ -72,11 +72,14 @@ struct rfkill_int_event {struct rfkill_event_ext ev; }; +/* Max rfkill events that can be "in-flight" for one data source */ +#define MAX_RFKILL_EVENT 1000struct rfkill_data {struct list_head list;struct list_head events;struct mutex mtx;wait_queue_head_t read_wait; +u32 event_count;bool input_handler;u8 max_size; };
@@ -254,10 +257,12 @@ static void rfkill_global_led_trigger_un }#endif /* CONFIG_RFKILL_LEDS */ -static void rfkill_fill_event (struct rfkill_event_ext *ev, -struct rfkill *rfkill, -enum rfkill_operation op) +static int rfkill_fill_event (struct rfkill_int_event *int_ev, +struct rfkill *rfkill, +struct rfkill_data *data, +enum rfkill_operation op) { +struct rfkill_event_ext *ev = &int_ev->ev;unsigned long flags; ev->idx = rfkill->idx;
@@ -270,6 +275,16 @@ static void rfkill_fill_event(struct rfk RFKILL_BLOCK_SW_PREV)); ev->hard_block_reasons = rfkill->hard_block_reasons;spin_unlock_irqrestore (&rfkill->lock, flags); + +mutex_lock (&data->mtx); +if (data->event_count++ >MAX_RFKILL_EVENT ) { + data->event_count--; +mutex_unlock (&data->mtx); +return -ENOSPC ; + } +list_add_tail (&int_ev->list, &data->events); +mutex_unlock (&data->mtx); +return 0 ; }static void rfkill_send_events (struct rfkill *rfkill,enum rfkill_operation op)
@@ -281,10 +296,10 @@ static void rfkill_send_events(struct rf ev =kzalloc (sizeof (*ev),GFP_KERNEL );if (!ev)continue ; -rfkill_fill_event (&ev->ev, rfkill, op); -mutex_lock (&data->mtx); -list_add_tail (&ev->list, &data->events); -mutex_unlock (&data->mtx); +if (rfkill_fill_event (ev, rfkill, data, op)) { +kfree (ev); +continue ; + }wake_up_interruptible (&data->read_wait); } }
@@ -1149,7 +1164,6 @@ static int rfkill_fop_open(struct inodeinit_waitqueue_head (&data->read_wait);mutex_lock (&rfkill_global_mutex); -mutex_lock (&data->mtx);/* * start getting events from elsewhere but hold mtx to get * startup events added first
@@ -1159,11 +1173,10 @@ static int rfkill_fop_open(struct inode ev =kzalloc (sizeof (*ev),GFP_KERNEL );if (!ev) goto free; -rfkill_fill_event (&ev->ev, rfkill,RFKILL_OP_ADD ); -list_add_tail (&ev->list, &data->events); +if (rfkill_fill_event (ev, rfkill, data,RFKILL_OP_ADD )) +kfree (ev); }list_add (&data->list, &rfkill_fds); -mutex_unlock (&data->mtx);mutex_unlock (&rfkill_global_mutex); file->private_data = data;
@@ -1171,7 +1184,6 @@ static int rfkill_fop_open(struct inodereturn stream_open (inode, file); free: -mutex_unlock (&data->mtx);mutex_unlock (&rfkill_global_mutex);mutex_destroy (&data->mtx);list_for_each_entry_safe (ev, tmp, &data->events, list)
@@ -1232,6 +1244,7 @@ static ssize_t rfkill_fop_read(struct fi ret = -EFAULT ;list_del (&ev->list); + data->event_count--;kfree (ev); out:mutex_unlock (&data->mtx);
Greg Kroah-Hartman
maintainerPATCH 546/570 usb: gadget: f_hid: move list and spinlock inits from bind to alloc
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Zimmermann <[email protected]>
[ Upstream commit 4e0a88254ad59f6c53a34bf5fa241884ec09e8b2 ]
There was an issue when you did the following:
- setup and bind an hid gadget
- open /dev/hidg0
- use the resulting fd in EPOLL_CTL_ADD
- unbind the UDC
- bind the UDC
- use the fd in EPOLL_CTL_DEL
When CONFIG_DEBUG_LIST was enabled, a list_del corruption was reported within remove_wait_queue (via ep_remove_wait_queue). After some debugging I found out that the queues, which f_hid registers via poll_wait were the problem. These were initialized using init_waitqueue_head inside hidg_bind. So effectively, the bind function re-initialized the queues while there were still items in them.
The solution is to move the initialization from hidg_bind to hidg_alloc to extend their lifetimes to the lifetime of the function instance.
Additionally, I found many other possibly problematic init calls in the bind function, which I moved as well.
--- drivers/usb/gadget/function/f_hid.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/usb/gadget/function/f_hid.c +6 -5
@@ -996,13 +996,8 @@ static int hidg_bind(struct usb_configurif (status) goto fail; -spin_lock_init (&hidg->write_spinlock); hidg->write_pending =1 ; hidg->req =NULL ; -spin_lock_init (&hidg->read_spinlock); -init_waitqueue_head (&hidg->write_queue); -init_waitqueue_head (&hidg->read_queue); -INIT_LIST_HEAD (&hidg->completed_out_req);/* create char device */ cdev_init (&hidg->cdev, &f_hidg_fops);
@@ -1272,6 +1267,12 @@ static struct usb_function *hidg_alloc(smutex_lock (&opts->lock); ++opts->refcnt; +spin_lock_init (&hidg->write_spinlock); +spin_lock_init (&hidg->read_spinlock); +init_waitqueue_head (&hidg->write_queue); +init_waitqueue_head (&hidg->read_queue); +INIT_LIST_HEAD (&hidg->completed_out_req); +device_initialize (&hidg->dev); hidg->dev.release = hidg_release; hidg->dev.class = hidg_class;
Greg Kroah-Hartman
maintainerPATCH 547/570 usb: gadget: u_ether: Fix race between gether_disconnect and eth_stop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuen-Han Tsai <[email protected]>
[ Upstream commit e1eabb072c75681f78312c484ccfffb7430f206e ]
A race condition between gether_disconnect() and eth_stop() leads to a NULL pointer dereference. Specifically, if eth_stop() is triggered concurrently while gether_disconnect() is tearing down the endpoints, eth_stop() attempts to access the cleared endpoint descriptor, causing the following NPE:
Unable to handle kernel NULL pointer dereference Call trace: __dwc3_gadget_ep_enable+0x60/0x788 dwc3_gadget_ep_enable+0x70/0xe4 usb_ep_enable+0x60/0x15c eth_stop+0xb8/0x108
Because eth_stop() crashes while holding the dev->lock, the thread running gether_disconnect() fails to acquire the same lock and spins forever, resulting in a hardlockup:
Core - Debugging Information for Hardlockup core(7)
Call trace: queued_spin_lock_slowpath+0x94/0x488 _raw_spin_lock+0x64/0x6c gether_disconnect+0x19c/0x1e8 ncm_set_alt+0x68/0x1a0 composite_setup+0x6a0/0xc50
The root cause is that the clearing of dev->port_usb in gether_disconnect() is delayed until the end of the function.
Move the clearing of dev->port_usb to the very beginning of gether_disconnect() while holding dev->lock. This cuts off the link immediately, ensuring eth_stop() will see dev->port_usb as NULL and safely bail out.
--- drivers/usb/gadget/function/u_ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/u_ether.c +4 -4
@@ -1173,6 +1173,10 @@ void gether_disconnect(struct gether *liDBG (dev,"%s\n" , __func__); +spin_lock (&dev->lock); + dev->port_usb =NULL ; +spin_unlock (&dev->lock); +netif_stop_queue (dev->net);netif_carrier_off (dev->net);
@@ -1210,10 +1214,6 @@ void gether_disconnect(struct gether *li dev->header_len =0 ; dev->unwrap =NULL ; dev->wrap =NULL ; - -spin_lock (&dev->lock); - dev->port_usb =NULL ; -spin_unlock (&dev->lock); }EXPORT_SYMBOL_GPL (gether_disconnect);
Greg Kroah-Hartman
maintainerPATCH 548/570 usb: gadget: uvc: fix NULL pointer dereference during unbind race
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jimmy Hu <[email protected]>
[ Upstream commit eba2936bbe6b752a31725a9eb5c674ecbf21ee7d ]
Commit b81ac4395bbe ("usb: gadget: uvc: allow for application to cleanly shutdown") introduced two stages of synchronization waits totaling 1500ms in uvc_function_unbind() to prevent several types of kernel panics. However, this timing-based approach is insufficient during power management (PM) transitions.
When the PM subsystem starts freezing user space processes, the wait_event_interruptible_timeout() is aborted early, which allows the unbind thread to proceed and nullify the gadget pointer (cdev->gadget = NULL):
[ 814.123447][ T947] configfs-gadget.g1 gadget.0: uvc: uvc_function_unbind() [ 814.178583][ T3173] PM: suspend entry (deep) [ 814.192487][ T3173] Freezing user space processes [ 814.197668][ T947] configfs-gadget.g1 gadget.0: uvc: uvc_function_unbind no clean disconnect, wait for release
When the PM subsystem resumes or aborts the suspend and tasks are restarted, the V4L2 release path is executed and attempts to access the already nullified gadget pointer, triggering a kernel panic:
[ 814.292597][ C0] PM: pm_system_irq_wakeup: 479 triggered dhdpcie_host_wake [ 814.386727][ T3173] Restarting tasks ... [ 814.403522][ T4558] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000030 [ 814.404021][ T4558] pc : usb_gadget_deactivate+0x14/0xf4 [ 814.404031][ T4558] lr : usb_function_deactivate+0x54/0x94 [ 814.404078][ T4558] Call trace: [ 814.404080][ T4558] usb_gadget_deactivate+0x14/0xf4 [ 814.404083][ T4558] usb_function_deactivate+0x54/0x94 [ 814.404087][ T4558] uvc_function_disconnect+0x1c/0x5c [ 814.404092][ T4558] uvc_v4l2_release+0x44/0xac [ 814.404095][ T4558] v4l2_release+0xcc/0x130
Address the race condition and NULL pointer dereference by:
1. State Synchronization (flag + mutex)
Introduce a 'func_unbound' flag in struct uvc_device. This allows uvc_function_disconnect() to safely skip accessing the nullified cdev->gadget pointer. As suggested by Alan Stern, this flag is protected by a new mutex (uvc->lock) to ensure proper memory ordering and prevent instruction reordering or speculative loads. This mutex is also used to protect 'func_connected' for consistent state management.
2. Explicit Synchronization (completion)
Use a completion to synchronize uvc_function_unbind() with the uvc_vdev_release() callback. This prevents Use-After-Free (UAF) by ensuring struct uvc_device is freed after all video device resources are released.
--- drivers/usb/gadget/function/f_uvc.c | 46 ++++++++++++++++++++++++++++++--- drivers/usb/gadget/function/uvc.h | 3 ++ drivers/usb/gadget/function/uvc_v4l2.c | 13 +++++++-- 3 files changed, 56 insertions(+), 6 deletions(-)
drivers/usb/gadget/function/f_uvc.c +42 -4
@@ -393,6 +393,14 @@ uvc_function_disconnect(struct uvc_devic {int ret; +mutex_lock (&uvc->lock); +if (uvc->func_unbound) { +dev_dbg (&uvc->vdev.dev,"skipping function deactivate (unbound)\n" ); +mutex_unlock (&uvc->lock); +return ; + } +mutex_unlock (&uvc->lock); +if ((ret =usb_function_deactivate (&uvc->func)) <0 )uvcg_info (&uvc->func,"UVC disconnect failed with %d\n" , ret); }
@@ -411,6 +419,15 @@ static ssize_t function_name_show(structstatic DEVICE_ATTR_RO (function_name); +static void uvc_vdev_release (struct video_device *vdev) +{ +struct uvc_device *uvc =video_get_drvdata (vdev); + +/* Signal uvc_function_unbind() that the video device has been released */ +if (uvc->vdev_release_done) +complete (uvc->vdev_release_done); +} +static int uvc_register_video (struct uvc_device *uvc) {
@@ -422,7 +439,7 @@ uvc_register_video(struct uvc_device *uv uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev; uvc->vdev.fops = &uvc_v4l2_fops; uvc->vdev.ioctl_ops = &uvc_v4l2_ioctl_ops; - uvc->vdev.release = video_device_release_empty; + uvc->vdev.release = uvc_vdev_release; uvc->vdev.vfl_dir =VFL_DIR_TX ; uvc->vdev.lock = &uvc->video.mutex; uvc->vdev.device_caps =V4L2_CAP_VIDEO_OUTPUT |V4L2_CAP_STREAMING ;
@@ -596,6 +613,9 @@ uvc_function_bind(struct usb_configuratiint ret = -EINVAL ;uvcg_info (f,"%s()\n" , __func__); +mutex_lock (&uvc->lock); + uvc->func_unbound = false; +mutex_unlock (&uvc->lock); opts =fi_to_f_uvc_opts (f->fi);/* Sanity check the streaming endpoint module parameters.
@@ -888,18 +908,25 @@ static void uvc_free(struct usb_functionstatic void uvc_function_unbind (struct usb_configuration *c,struct usb_function *f) { +DECLARE_COMPLETION_ONSTACK (vdev_release_done);struct usb_composite_dev *cdev = c->cdev;struct uvc_device *uvc =to_uvc (f);long wait_ret =1 ; +bool connected;uvcg_info (f,"%s()\n" , __func__); +mutex_lock (&uvc->lock); + uvc->func_unbound = true; + uvc->vdev_release_done = &vdev_release_done; + connected = uvc->func_connected; +mutex_unlock (&uvc->lock);/* If we know we're connected via v4l2, then there should be a cleanup * of the device from userspace either via UVC_EVENT_DISCONNECT or * though the video device removal uevent. Allow some time for the * application to close out before things get deleted. */ -if (uvc->func_connected) { +if (connected) {uvcg_dbg (f,"waiting for clean disconnect\n" ); wait_ret =wait_event_interruptible_timeout (uvc->func_connected_queue, uvc->func_connected == false,msecs_to_jiffies (500 ));
@@ -910,8 +937,13 @@ static void uvc_function_unbind(struct uvideo_unregister_device (&uvc->vdev);v4l2_device_unregister (&uvc->v4l2_dev); -if (uvc->func_connected) { -/* Wait for the release to occur to ensure there are no longer any +mutex_lock (&uvc->lock); + connected = uvc->func_connected; +mutex_unlock (&uvc->lock); + +if (connected) { +/* +* Wait for the release to occur to ensure there are no longer any * pending operations that may cause panics when resources are cleaned * up. */
@@ -921,6 +953,10 @@ static void uvc_function_unbind(struct uuvcg_dbg (f,"done waiting for release with ret: %ld\n" , wait_ret); } +/* Wait for the video device to be released */ +wait_for_completion (&vdev_release_done); + uvc->vdev_release_done =NULL ; +usb_ep_free_request (cdev->gadget->ep0, uvc->control_req);kfree (uvc->control_buf);
@@ -938,6 +974,8 @@ static struct usb_function *uvc_alloc(streturn ERR_PTR (-ENOMEM );mutex_init (&uvc->video.mutex); +mutex_init (&uvc->lock); + uvc->func_unbound = true; uvc->state =UVC_STATE_DISCONNECTED ;init_waitqueue_head (&uvc->func_connected_queue); opts =fi_to_f_uvc_opts (fi);
drivers/usb/gadget/function/uvc.h +3 -0
@@ -130,6 +130,9 @@ struct uvc_device {enum uvc_state state;struct usb_function func;struct uvc_video video; +struct completion *vdev_release_done; +struct mutex lock;/* protects func_unbound and func_connected */ +bool func_unbound;bool func_connected;wait_queue_head_t func_connected_queue;
drivers/usb/gadget/function/uvc_v4l2.c +11 -2
@@ -234,12 +234,18 @@ uvc_v4l2_subscribe_event(struct v4l2_fhif (sub->type <UVC_EVENT_FIRST || sub->type >UVC_EVENT_LAST )return -EINVAL ; -if (sub->type ==UVC_EVENT_SETUP && uvc->func_connected) +mutex_lock (&uvc->lock); + +if (sub->type ==UVC_EVENT_SETUP && uvc->func_connected) { +mutex_unlock (&uvc->lock);return -EBUSY ; + } ret =v4l2_event_subscribe (fh, sub,2 ,NULL ); -if (ret <0 ) +if (ret <0 ) { +mutex_unlock (&uvc->lock);return ret; + }if (sub->type ==UVC_EVENT_SETUP ) { uvc->func_connected = true;
@@ -247,6 +253,7 @@ uvc_v4l2_subscribe_event(struct v4l2_fhuvc_function_connect (uvc); } +mutex_unlock (&uvc->lock);return 0 ; }
@@ -255,7 +262,9 @@ static void uvc_v4l2_disable(struct uvc_uvc_function_disconnect (uvc);uvcg_video_enable (&uvc->video,0 );uvcg_free_buffers (&uvc->video.queue); +mutex_lock (&uvc->lock); uvc->func_connected = false; +mutex_unlock (&uvc->lock);wake_up_interruptible (&uvc->func_connected_queue); }
Greg Kroah-Hartman
maintainerPATCH 549/570 ext4: publish jinode after initialization
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Chen <[email protected]>
[ Upstream commit 1aec30021edd410b986c156f195f3d23959a9d11 ]
ext4_inode_attach_jinode() publishes ei->jinode to concurrent users. It used to set ei->jinode before jbd2_journal_init_jbd_inode(), allowing a reader to observe a non-NULL jinode with i_vfs_inode still unset.
The fast commit flush path can then pass this jinode to jbd2_wait_inode_data(), which dereferences i_vfs_inode->i_mapping and may crash.
Below is the crash I observe:
``` BUG: unable to handle page fault for address: 000000010beb47f4 PGD 110e51067 P4D 110e51067 PUD 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 1 UID: 0 PID: 4850 Comm: fc_fsync_bench_ Not tainted 6.18.0-00764-g795a690c06a5 #1 PREEMPT(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.17.0-2-2 04/01/2014 RIP: 0010:xas_find_marked+0x3d/0x2e0 Code: e0 03 48 83 f8 02 0f 84 f0 01 00 00 48 8b 47 08 48 89 c3 48 39 c6 0f 82 fd 01 00 00 48 85 c9 74 3d 48 83 f9 03 77 63 4c 8b 0f <49> 8b 71 08 48 c7 47 18 00 00 00 00 48 89 f1 83 e1 03 48 83 f9 02 RSP: 0018:ffffbbee806e7bf0 EFLAGS: 00010246 RAX: 000000000010beb4 RBX: 000000000010beb4 RCX: 0000000000000003 RDX: 0000000000000001 RSI: 0000002000300000 RDI: ffffbbee806e7c10 RBP: 0000000000000001 R08: 0000002000300000 R09: 000000010beb47ec R10: ffff9ea494590090 R11: 0000000000000000 R12: 0000002000300000 R13: ffffbbee806e7c90 R14: ffff9ea494513788 R15: ffffbbee806e7c88 FS: 00007fc2f9e3e6c0(0000) GS:ffff9ea6b1444000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000010beb47f4 CR3: 0000000119ac5000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: <TASK> filemap_get_folios_tag+0x87/0x2a0 __filemap_fdatawait_range+0x5f/0xd0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __schedule+0x3e7/0x10c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 ? cap_safe_nice+0x37/0x70 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 filemap_fdatawait_range_keep_errors+0x12/0x40 ext4_fc_commit+0x697/0x8b0 ? ext4_file_write_iter+0x64b/0x950 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 ? vfs_write+0x356/0x480 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ext4_sync_file+0xf7/0x370 do_fsync+0x3b/0x80 ? syscall_trace_enter+0x108/0x1d0 __x64_sys_fdatasync+0x16/0x20 do_syscall_64+0x62/0x2c0 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... ```
Fix this by initializing the jbd2_inode first.
Use smp_wmb() and WRITE_ONCE() to publish ei->jinode after initialization. Readers use READ_ONCE() to fetch the pointer.
--- fs/ext4/fast_commit.c | 4 ++-- fs/ext4/inode.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-)
fs/ext4/fast_commit.c +2 -2
@@ -979,7 +979,7 @@ static int ext4_fc_submit_inode_data_allfinish_wait (&ei->i_fc_wait, &wait); }spin_unlock (&sbi->s_fc_lock); - ret =jbd2_submit_inode_data (ei->jinode); + ret =jbd2_submit_inode_data (READ_ONCE (ei->jinode));if (ret)return ret;spin_lock (&sbi->s_fc_lock);
@@ -1004,7 +1004,7 @@ static int ext4_fc_wait_inode_data_all(jcontinue ;spin_unlock (&sbi->s_fc_lock); - ret =jbd2_wait_inode_data (journal, pos->jinode); + ret =jbd2_wait_inode_data (journal,READ_ONCE (pos->jinode));if (ret)return ret;spin_lock (&sbi->s_fc_lock);
fs/ext4/inode.c +11 -4
@@ -122,6 +122,8 @@ void ext4_inode_csum_set(struct inode *istatic inline int ext4_begin_ordered_truncate (struct inode *inode,loff_t new_size) { +struct jbd2_inode *jinode =READ_ONCE (EXT4_I (inode)->jinode); +trace_ext4_begin_ordered_truncate (inode, new_size);/* * If jinode is zero, then we never opened the file for
@@ -129,10 +131,10 @@ static inline int ext4_begin_ordered_tru* jbd2_journal_begin_ordered_truncate() since there's no * outstanding writes we need to flush. */ -if (!EXT4_I (inode)->jinode) +if (!jinode)return 0 ;return jbd2_journal_begin_ordered_truncate (EXT4_JOURNAL (inode), -EXT4_I (inode)->jinode, + jinode, new_size); }
@@ -4145,8 +4147,13 @@ int ext4_inode_attach_jinode(struct inodspin_unlock (&inode->i_lock);return -ENOMEM ; } - ei->jinode = jinode; -jbd2_journal_init_jbd_inode (ei->jinode, inode); +jbd2_journal_init_jbd_inode (jinode, inode); +/* +* Publish ->jinode only after it is fully initialized so that +* readers never observe a partially initialized jbd2_inode. +*/ +smp_wmb (); +WRITE_ONCE (ei->jinode, jinode); jinode =NULL ; }spin_unlock (&inode->i_lock);