7.1.5-rc1 review
Subsystems (15)
Greg Kroah-Hartman
maintainerPATCH 1348/2077 tracing/eprobes: Allow use of BTF names to dereference pointers
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit 69efd863a78584b9416ed6be0e1e7349124b4a00 ]
Add syntax to the parsing of eprobes to be able to typecast a trace event field that is a pointer to a structure.
Currently, a dereference must be a number, where the user has to figure out manually the offset of a member of a structure that they want to dereference.
But for event probes that records a field that happens to be a pointer to a structure, it cannot dereference these values with BTF naming, but must use numerical offsets.
For example, to find out what device a sk_buff is pointing to in the net_dev_xmit trace event, one must first use gdb to find the offsets of the members of the structures:
(gdb) p &((struct sk_buff *)0)->dev
$1 = (struct net_device **) 0x10
(gdb) p &((struct net_device *)0)->name
$2 = (char (*)[16]) 0x118
And then use the raw numbers to dereference:
# echo 'e:xmit net.net_dev_xmit +0x118(+0x10($skbaddr)):string' >> dynamic_events
If BTF is in the kernel, then instead, the skbaddr can be typecast to sk_buff and use the normal dereference logic.
# echo 'e:xmit net.net_dev_xmit (sk_buff)skbaddr->dev->name:string' >> dynamic_events
# echo 1 > events/eprobes/xmit/enable
# cat trace
[..]
sshd-session-1022 [000] b..2. 860.249343: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.250061: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.250142: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.263553: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.283820: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.302716: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.322905: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.342828: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.362268: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.382335: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.400856: xmit: (net.net_dev_xmit) arg1="enp7s0"
sshd-session-1022 [000] b..2. 860.419893: xmit: (net.net_dev_xmit) arg1="enp7s0"The syntax is simply: (STRUCT)(FIELD)->MEMBER[->MEMBER..]
Also add comments around the #else and #endif of #ifdef CONFIG_PROBE_EVENTS_BTF_ARGS to know what they are for.
Stable-dep-of: 251a8fe1b9ae ("tracing/probes: Remove WARN_ON_ONCE from parse_btf_arg")
--- Documentation/trace/eprobetrace.rst | 4 + kernel/trace/trace_probe.c | 173 +++++++++++++++++++++++----- kernel/trace/trace_probe.h | 5 +- 3 files changed, 154 insertions(+), 28 deletions(-)
Documentation/trace/eprobetrace.rst +4 -0
@@ -46,6 +46,10 @@ Synopsis of eprobe_events (x8/x16/x32/x64), VFS layer common type(%pd/%pD), "char", "string", "ustring", "symbol", "symstr" and "bitfield" are supported. + (STRUCT)FIELD->MEMBER[->MEMBER] : If BTF is supported, typecast FIELD to + a pointer to STRUCT and then derference the pointer defined by + ->MEMBER. Note that when this is used, the FIELD name does not + need to be prefixed with a '$'. Types -----
kernel/trace/trace_probe.c +146 -27
273 lines not on this page · raw message
kernel/trace/trace_probe.h +4 -1
@@ -422,7 +422,9 @@ struct traceprobe_parse_context {const struct btf_param *params;/* Parameter of the function */ s32 nr_params;/* The number of the parameters */ struct btf *btf;/* The BTF to be used */ +struct btf *struct_btf;/* The BTF to be used for structs */ const struct btf_type *last_type;/* Saved type */ +const struct btf_type *last_struct;/* Saved structure */ u32 last_bitoffs;/* Saved bitoffs */ u32 last_bitsize;/* Saved bitsize */ struct trace_probe *tp;
@@ -563,7 +565,8 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,C (NEED_STRING_TYPE ,"$comm and immediate-string only accepts string type" ),\C (TOO_MANY_ARGS ,"Too many arguments are specified" ), \C (TOO_MANY_EARGS ,"Too many entry arguments specified" ), \ -C (EVENT_TOO_BIG ,"Event too big (too many fields?)" ), +C (EVENT_TOO_BIG ,"Event too big (too many fields?)" ), \ +C (TYPECAST_NOT_EVENT ,"Typecasts are only for eprobe fields" ), #undef C #define C(a, b) TP_ERR_##a
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1349/2077 tracing/probes: Remove WARN_ON_ONCE from parse_btf_arg
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 251a8fe1b9aedccd298b77bc28426d564c5a923f ]
Sashiko found that user can cause this WARN_ON_ONCE() easily with adding a kprobe event based on a raw address with BTF parameter.
Since this is not an unexpected condition, remove the WARN_ON_ONCE().
--- kernel/trace/trace_probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_probe.c +1 -1
@@ -678,7 +678,7 @@ static int parse_btf_arg(char *varname,int i, is_ptr, ret;u32 tid; -if (WARN_ON_ONCE (!ctx->funcname && !(ctx->flags &TPARG_FL_TEVENT ))) +if (!ctx->funcname && !(ctx->flags &TPARG_FL_TEVENT ))return -EINVAL ; is_ptr =split_next_field (varname, &field, ctx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1350/2077 tracing/events: Fix to check the simple_tsk_fn creation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit cda1fbfc5313bb90daa271d45eea4a8d317a8544 ]
Sashiko pointed that this sample code does not correctly handle the failure of thread creation because kthread_run() can return -errno.
Check the simple_tsk_fn is correctly initialized (created) or not.
--- samples/trace_events/trace-events-sample.c | 4 ++++ 1 file changed, 4 insertions(+)
samples/trace_events/trace-events-sample.c +4 -0
@@ -107,6 +107,10 @@ int foo_bar_reg(void)* for consistency sake, we still take the thread_mutex. */ simple_tsk_fn =kthread_run (simple_thread_fn,NULL ,"event-sample-fn" ); +if (IS_ERR_OR_NULL (simple_tsk_fn)) { +pr_err ("Failed to create simple_thread_fn\n" ); + simple_tsk_fn =NULL ; + } out:mutex_unlock (&thread_mutex);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1351/2077 tracing: eprobe: read the complete FILTER_PTR_STRING pointer
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Kaiser <[email protected]>
[ Upstream commit 206b25c09080cc20fd4c2bea12d59df4b7ba2121 ]
For a char * element in an event, the FILTER_PTR_STRING filter type is used. When the event occurs, a pointer is stored in the ringbuffer.
If an eprobe references such a char * element of a "base event", the stored pointer is truncated when it's read from the ringbuffer.
$ cd /sys/kernel/tracing $ echo 'e rcu.rcu_utilization $s:x64 $s:string' > dynamic_events $ echo 1 > tracing_on $ echo 1 > events/eprobes/enable $ sleep 1 $ echo 0 > events/eprobes/enable $ cat trace <idle>-0 ...: (rcu.rcu_utilization) arg1=0x4f arg2=(fault) <idle>-0 ...: (rcu.rcu_utilization) arg1=0x2 arg2=(fault)
The problem is in get_event_field
val = (unsigned long)(*(char *)addr);
addr points to the position in the ringbuffer where the pointer was stored. The assignment reads only the lowest byte of the pointer.
Fix the cast to read the whole pointer. The output of the test above is now
<idle>-0 ... arg1=0xffffffff81c7d3f3 arg2="Start scheduler-tick" <idle>-0 ... arg1=0xffffffff81c57340 arg2="End scheduler-tick"
--- kernel/trace/trace_eprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_eprobe.c +1 -1
@@ -315,7 +315,7 @@ get_event_field(struct fetch_insn *code, void *rec) val = (unsigned long )addr;break ;case FILTER_PTR_STRING : - val = (unsigned long )(*(char *)addr); + val = *(unsigned long *)addr;break ;default :WARN_ON_ONCE (1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1352/2077 tracing/fprobe: Fix NULL pointer dereference in fprobe_fgraph_entry()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sechang Lim <[email protected]>
[ Upstream commit 367c49d6e283c17b56a31e7a8d964a079244264c ]
fprobe_fgraph_entry() sizes a shadow-stack reservation in one walk of the per-ip fprobe list and fills it in a second walk, both under rcu_read_lock() only. A fprobe registered on an already-live ip can become visible between the two walks, so the fill walk processes an exit_handler the sizing walk did not count and used runs past reserved_words. If the sizing walk counted nothing, fgraph_data is NULL and the first write_fprobe_header() faults:
Oops: general protection fault, probably for non-canonical address ... KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:fprobe_fgraph_entry+0xa38/0xf10 kernel/trace/fprobe.c:167 Call Trace: <TASK> function_graph_enter_regs+0x44c/0xa10 kernel/trace/fgraph.c:677 ftrace_graph_func+0xc5/0x140 arch/x86/kernel/ftrace.c:671 __kernel_text_address+0x9/0x40 kernel/extable.c:78 arch_stack_walk+0x117/0x170 arch/x86/kernel/stacktrace.c:26 kmem_cache_free+0x188/0x580 mm/slub.c:6378 tcp_data_queue+0x18d/0x6550 net/ipv4/tcp_input.c:5590 [...] </TASK>
The list cannot be frozen across the two walks, so skip a node that does not fit the reservation and count it as missed.
--- kernel/trace/fprobe.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/trace/fprobe.c +10 -0
@@ -613,6 +613,16 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_opscontinue ; data_size = fp->entry_data_size; +/* +* The list may have grown since it was sized, so this node +* may not fit. Skip it as missed rather than overrun the +* reservation. +*/ +if (fp->exit_handler && + used +FPROBE_HEADER_SIZE_IN_LONG +SIZE_IN_LONG (data_size) > reserved_words) { + fp->nmissed++; +continue ; + }if (data_size && fp->exit_handler) data = fgraph_data + used +FPROBE_HEADER_SIZE_IN_LONG ;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1353/2077 tracing/probes: Make the $ prefix mandatory for comm access
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit a369299c3f785cf556bbef2de2db0aa2d294c4c9 ]
Since $comm or $COMM are not event field but special fetcharg variables to access current->comm, It should not be accessed without '$' prefix even with typecast.
--- kernel/trace/trace_probe.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
kernel/trace/trace_probe.c +7 -5
@@ -342,10 +342,6 @@ static int parse_trace_event(char *arg, struct fetch_insn *code, ret =parse_trace_event_arg (arg, code, ctx);if (!ret)return 0 ; -if (strcmp (arg,"comm" ) ==0 ||strcmp (arg,"COMM" ) ==0 ) { - code->op =FETCH_OP_COMM ; -return 0 ; - }return -EINVAL ; }
@@ -1073,8 +1069,14 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t,int len;if (ctx->flags &TPARG_FL_TEVENT ) { -if (parse_trace_event (arg, code, ctx) <0 ) +if (parse_trace_event (arg, code, ctx) <0 ) { +/* 'comm' should be checked after field parsing. */ +if (strcmp (arg,"comm" ) ==0 ||strcmp (arg,"COMM" ) ==0 ) { + code->op =FETCH_OP_COMM ; +return 0 ; + } goto inval; + }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1354/2077 irqchip/gic-v3-its: Fix OF node reference leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 2e1368a9d61bdf5502ddade004f223a5831c5b8c ]
of_get_cpu_node() returns a referenced device node. In its_cpu_init_collection(), the Cavium 23144 workaround only uses the node to compare the CPU NUMA node, but the reference is never dropped.
Use the device_node cleanup helper for the CPU node reference so it is released when leaving the workaround block, including the NUMA mismatch return path.
--- drivers/irqchip/irq-gic-v3-its.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +2 -4
@@ -3290,11 +3290,9 @@ static void its_cpu_init_collection(struct its_node *its)/* avoid cross node collections and its mapping */ if (its->flags &ITS_FLAGS_WORKAROUND_CAVIUM_23144 ) { -struct device_node *cpu_node; + struct device_node *cpu_node __free(device_node) = of_get_cpu_node(cpu, NULL); - cpu_node =of_get_cpu_node (cpu,NULL ); -if (its->numa_node !=NUMA_NO_NODE && - its->numa_node !=of_node_to_nid (cpu_node)) +if (its->numa_node !=NUMA_NO_NODE && its->numa_node !=of_node_to_nid (cpu_node))return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1355/2077 irqchip/ts4800: Fix missing chained handler cleanup on remove
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingshuang Fu <[email protected]>
[ Upstream commit 98bf7e54cec07d514b3575c11896a8b12d50ecc4 ]
The driver installs a chained handler for the parent interrupt during probe using irq_set_chained_handler_and_data(), but the remove function does not clear this handler. This leaves a dangling handler that may be called when the parent interrupt fires after the driver has been removed, potentially accessing freed memory and causing a kernel crash.
Additionally, the parent_irq obtained via irq_of_parse_and_map() is not stored, making it inaccessible in the remove function. Moreover, interrupt mappings created during probe are not properly disposed.
Fix this by:
- Saving parent_irq in probe
- Clearing the chained handler with NULL in ts4800_ic_remove()
- Disposing all IRQ mappings before domain removal to prevent resource leaks
--- drivers/irqchip/irq-ts4800.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/irqchip/irq-ts4800.c +10 -0
@@ -28,6 +28,7 @@ struct ts4800_irq_data {void __iomem *base;struct platform_device *pdev;struct irq_domain *domain; +unsigned int parent_irq; };static void ts4800_irq_mask (struct irq_data *d)
@@ -134,6 +135,7 @@ static int ts4800_ic_probe(struct platform_device *pdev)irq_set_chained_handler_and_data (parent_irq, ts4800_ic_chained_handle_irq, data); + data->parent_irq = parent_irq;platform_set_drvdata (pdev, data);return 0 ;
@@ -142,6 +144,14 @@ static int ts4800_ic_probe(struct platform_device *pdev)static void ts4800_ic_remove (struct platform_device *pdev) {struct ts4800_irq_data *data =platform_get_drvdata (pdev); +unsigned int hwirq; + +irq_set_chained_handler_and_data (data->parent_irq,NULL ,NULL ); + +for (hwirq =0 ; hwirq <8 ; hwirq++) +irq_dispose_mapping (irq_find_mapping (data->domain, hwirq)); + +irq_dispose_mapping (data->parent_irq);irq_domain_remove (data->domain); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1356/2077 spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit 7fc2c3dcae28347a30ccd76c8817e5719005f1c3 ]
wait_event_interruptible_timeout() can return a negative error code when interrupted by a signal. The original code treated all non-zero return values as success, which would incorrectly synchronize DMA channels and return 0 instead of propagating the interruption error.
--- drivers/spi/spi-rzv2h-rspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +2 -2
@@ -366,14 +366,14 @@ static int rzv2h_rspi_transfer_dma(struct rzv2h_rspi_priv *rspi,rzv2h_rspi_clear_all_irqs (rspi); ret =wait_event_interruptible_timeout (rspi->wait, rspi->dma_callbacked,HZ ); -if (ret) { +if (ret >0 ) {dmaengine_synchronize (rspi->controller->dma_tx);dmaengine_synchronize (rspi->controller->dma_rx); ret =0 ; }else {dmaengine_terminate_sync (rspi->controller->dma_tx);dmaengine_terminate_sync (rspi->controller->dma_rx); - ret = -ETIMEDOUT ; + ret = ret ?: -ETIMEDOUT ; }enable_irq (rspi->irq_rx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1357/2077 sctp: fix addr_wq_timer race in sctp_free_addr_wq()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit 976c19de0f22a857ba0112f39635f8fd7a257568 ]
sctp_free_addr_wq() previously removed addr_wq_timer using timer_delete() while holding addr_wq_lock. However, timer_delete() does not guarantee that a currently running timer handler has completed.
This allows a race with sctp_addr_wq_timeout_handler(), where the handler may still run after addr_waitq has been freed, acquire addr_wq_lock, and access freed memory, leading to a use-after-free.
Fix this by calling timer_shutdown_sync() before taking addr_wq_lock. This guarantees that any in-flight timer handler has finished and prevents the timer from being re-armed during teardown, making subsequent cleanup safe.
--- net/sctp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sctp/protocol.c +2 -1
@@ -663,8 +663,9 @@ static void sctp_free_addr_wq(struct net *net)struct sctp_sockaddr_entry *addrw;struct sctp_sockaddr_entry *temp; +timer_shutdown_sync (&net->sctp.addr_wq_timer); +spin_lock_bh (&net->sctp.addr_wq_lock); -timer_delete (&net->sctp.addr_wq_timer);list_for_each_entry_safe (addrw, temp, &net->sctp.addr_waitq, list) {list_del (&addrw->list);kfree (addrw);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1358/2077 virtio_net: disable cb when NAPI is busy-polled
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longjun Tang <[email protected]>
[ Upstream commit 1eb8fc67ca41db71c90866ff76c990d85247daef ]
When busy-poll is active, napi_schedule_prep() returns false in virtqueue_napi_schedule(), so virtqueue_disable_cb() is skipped. The device may keep firing irqs until reaches virtqueue_napi_complete(). Under load (received == budget), it will lead to a large number of spurious interrupts.
Fix it by disabling the callback at the virtnet_poll() entry. This keeps the callback off while we poll and it is re-enabled by virtqueue_napi_complete() when going idle.
--- drivers/net/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/virtio_net.c +3 -0
@@ -3011,6 +3011,9 @@ static int virtnet_poll(struct napi_struct *napi, int budget)unsigned int xdp_xmit =0 ;bool napi_complete; +if (budget) +virtqueue_disable_cb (rq->vq); +virtnet_poll_cleantx (rq, budget); received =virtnet_receive (rq, budget, &xdp_xmit);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1359/2077 cxgb4: Fix decode strings dump for T6 adapters
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gleb Markov <[email protected]>
[ Upstream commit 5d6dc22d62682d93f5f55f145ad792f2891de911 ]
Depending on the value of chip_version, the correct decode set is selected. However, the subsequent matching with the t4 encoding type in the if-else block results in a reassignment, which leads to the loss of support for t6_decode as well as reinitializing of values t4_decode and t5_decode.
The component history shows that the if-else block previously used for this purpose, as well as the execution order, was not affected by the change.
Furthermore, it is suggested by the execution order that the scenario with overwriting and loss of support will be implemented.
Delete the if-else block.
--- drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +0 -8
@@ -6737,14 +6737,6 @@ void t4_sge_decode_idma_state(struct adapter *adapter, int state)return ; } -if (is_t4 (adapter->params.chip)) { - sge_idma_decode = (const char **)t4_decode; - sge_idma_decode_nstates =ARRAY_SIZE (t4_decode); - }else { - sge_idma_decode = (const char **)t5_decode; - sge_idma_decode_nstates =ARRAY_SIZE (t5_decode); - } -if (state < sge_idma_decode_nstates)CH_WARN (adapter,"idma state %s\n" , sge_idma_decode[state]);else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1360/2077 selftests: drv-net: tso: dont touch dangerous feature bits
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 2f7f2e311106cb838d3f3fb6ef25effdb3f8e366 ]
query_nic_features() detects which offloads depend on tx-gso-partial by enabling everything, turning tx-gso-partial off, and seeing which active features drop out. Enabling all hw features is dangerous:
we may end up enabling rx-fcs and loopback for example. For the ice driver we end up getting into problems with feature dependencies so the cleanup isn't successful either, and the test exits with rx-fcs and loopback enabled.
Scope the feature probing just to segmentation bits.
--- tools/testing/selftests/drivers/net/hw/tso.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
tools/testing/selftests/drivers/net/hw/tso.py +6 -10
@@ -187,28 +187,24 @@ def query_nic_features(cfg) -> None: cfg.wanted_features.add(f["name"]) cfg.hw_features = set() - hw_all_features_cmd = "" for f in features["hw"]["bits"]["bit"]: if f.get("value", False): - feature = f["name"] - cfg.hw_features.add(feature) - hw_all_features_cmd += f" {feature} on" - try: - ethtool(f"-K {cfg.ifname} {hw_all_features_cmd}") - except Exception as e: - ksft_pr(f"WARNING: failure enabling all hw features: {e}") - ksft_pr("partial gso feature detection may be impacted") + cfg.hw_features.add(f["name"]) # Check which features are supported via GSO partial cfg.partial_features = set() if 'tx-gso-partial' in cfg.hw_features: + seg_features = {f for f in cfg.hw_features if "segmentation" in f} + ethtool(f"-K {cfg.ifname} " + + " ".join(f"{f} on" for f in seg_features)) + ethtool(f"-K {cfg.ifname} tx-gso-partial off") no_partial = set() features = cfg.ethnl.features_get({"header": {"dev-index": cfg.ifindex}}) for f in features["active"]["bits"]["bit"]: no_partial.add(f["name"]) - cfg.partial_features = cfg.hw_features - no_partial + cfg.partial_features = seg_features - no_partial ethtool(f"-K {cfg.ifname} tx-gso-partial on") restore_wanted_features(cfg)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1361/2077 net/sched: act_bpf: use rcu_dereference_bh() to read the filter
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sechang Lim <[email protected]>
[ Upstream commit adc49c7ba690c9b33b8392ec27397456b65d0893 ]
tcf_bpf_act() can run from the tc egress path, which holds only rcu_read_lock_bh(), but reads prog->filter with rcu_dereference() and trips lockdep:
WARNING: suspicious RCU usage
net/sched/act_bpf.c:47 suspicious rcu_dereference_check() usage! 1 lock held by syz.2.1588/12756:
#0: (rcu_read_lock_bh){....}-{1:3}, at: __dev_queue_xmit net/core/dev.c:4792
tcf_bpf_act+0x6ae/0x940 net/sched/act_bpf.c:47 tcf_classify+0x6e4/0x1080 net/sched/cls_api.c:1860 sch_handle_egress net/core/dev.c:4545 [inline] __dev_queue_xmit+0x2185/0x2c00 net/core/dev.c:4808 packet_sendmsg+0x3dfa/0x5120 net/packet/af_packet.c:3114
The other tc actions and cls_bpf already use rcu_dereference_bh() here. Do the same.
--- net/sched/act_bpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/act_bpf.c +1 -1
@@ -44,7 +44,7 @@ TC_INDIRECT_SCOPE int tcf_bpf_act(struct sk_buff *skb,tcf_lastuse_update (&prog->tcf_tm);bstats_update (this_cpu_ptr (prog->common.cpu_bstats), skb); - filter =rcu_dereference (prog->filter); + filter =rcu_dereference_bh (prog->filter);if (at_ingress) {__skb_push (skb, skb->mac_len); filter_res =bpf_prog_run_data_pointers (filter, skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1362/2077 ksmbd: reject undersized DACLs before parsing ACEs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haofeng Li <[email protected]>
[ Upstream commit 60908f7ebcd9b6cde74ad5711fab0f49c7970949 ]
parse_dacl() limits the attacker-controlled ACE count by comparing it with the number of minimal ACEs that fit in the DACL size. The DACL size field is 16 bits, but the expression subtracts sizeof(struct smb_acl). Because sizeof() is unsigned, a DACL size smaller than the ACL header underflows to a large size_t.
A malicious client can reach this with:
SMB2_SET_INFO (InfoType=SMB2_O_INFO_SECURITY)
-> smb2_set_info_sec()
-> set_info_sec()
-> parse_sec_desc()
-> parse_dacl()
-> init_acl_state(..., 0xffff)
-> init_acl_state(..., 0xffff)
-> kmalloc_objs(..., 0xffff)Thus a malformed security descriptor can make num_aces pass the guard and drive large temporary ACL state and pointer-array allocations.
Reject DACLs smaller than struct smb_acl before doing the subtraction, so the ACE count check cannot be bypassed by the underflow.
--- fs/smb/server/smbacl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/smbacl.c +6 -1
@@ -374,6 +374,7 @@ static void parse_dacl(struct mnt_idmap *idmap, {int i, ret;u16 num_aces =0 ; +u16 dacl_size;unsigned int acl_size;char *acl_base;struct smb_ace **ppace;
@@ -403,7 +404,11 @@ static void parse_dacl(struct mnt_idmap *idmap,if (num_aces <=0 )return ; -if (num_aces > (le16_to_cpu (pdacl->size) -sizeof (struct smb_acl )) / + dacl_size =le16_to_cpu (pdacl->size); +if (dacl_size <sizeof (struct smb_acl )) +return ; + +if (num_aces > (dacl_size -sizeof (struct smb_acl )) / (offsetof(struct smb_ace , sid) + offsetof(struct smb_sid , sub_auth) +sizeof (__le16)))return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1363/2077 ksmbd: fix use-after-free of fp->owner.name in durable handle owner check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
[ Upstream commit 38637163501fd9e2f684b8cd275d0db5d79f37c6 ]
Two concurrent SMB2 durable reconnects (DH2C/DHnC) on the same persistent_id race the fp->owner.name compare-read in ksmbd_vfs_compare_durable_owner() against the kfree() in ksmbd_reopen_durable_fd()'s reopen-success path. fp->owner.name is a standalone kstrdup() buffer whose lifetime is independent of the fp refcount, and the two sites share no lock: the compare reads the buffer while the reopen frees it, so the strcmp() can dereference freed memory.
Commit 7ce4fc40018d ("ksmbd: fix durable reconnect double-bind race in ksmbd_reopen_durable_fd") made the fp->conn claim atomic under global_ft.lock (closing the owner.name double-free and the ksmbd_file write-UAF), but the compare-read versus reopen-free pair was left unserialized.
BUG: KASAN: slab-use-after-free in strcmp+0x2c/0x80
Read of size 1 by task kworker
strcmp
ksmbd_vfs_compare_durable_owner
smb2_check_durable_oplock
smb2_open
Freed by task kworker:
kfree
ksmbd_reopen_durable_fd
smb2_open
Allocated by task kworker:
kstrdup
session_fd_check
smb2_session_logoff
The buggy address belongs to the cache kmalloc-8Serialize both sides of the race with fp->f_lock. The global durable file-table lock still protects the durable reconnect claim, but fp->owner.name is per-open state and does not need to block unrelated durable table lookups or reconnects. The teardown is left at its existing location after the reopen-success point so that an __open_id() rollback still retains owner.name for a later legitimate reconnect to verify.
--- fs/smb/server/vfs_cache.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
fs/smb/server/vfs_cache.c +21 -8
@@ -1229,16 +1229,21 @@ void ksmbd_stop_durable_scavenger(void)static int ksmbd_vfs_copy_durable_owner (struct ksmbd_file *fp,struct ksmbd_user *user) { +char *name; +if (!user)return -EINVAL ;/* Duplicate the user name to ensure identity persistence */ - fp->owner.name =kstrdup (user->name,GFP_KERNEL ); -if (!fp->owner.name) + name =kstrdup (user->name,GFP_KERNEL ); +if (!name)return -ENOMEM ; +spin_lock (&fp->f_lock); fp->owner.uid = user->uid; fp->owner.gid = user->gid; + fp->owner.name = name; +spin_unlock (&fp->f_lock);return 0 ; }
@@ -1256,18 +1261,24 @@ static int ksmbd_vfs_copy_durable_owner(struct ksmbd_file *fp,bool ksmbd_vfs_compare_durable_owner (struct ksmbd_file *fp,struct ksmbd_user *user) { -if (!user || !fp->owner.name) +bool ret = false; + +if (!user)return false; +spin_lock (&fp->f_lock); +if (!fp->owner.name) + goto out; +/* Check if the UID and GID match first (fast path) */ if (fp->owner.uid != user->uid || fp->owner.gid != user->gid) -return false; + goto out;/* Validate the account name to ensure the same SecurityContext */ -if (strcmp (fp->owner.name, user->name)) -return false; - -return true; + ret = (strcmp (fp->owner.name, user->name) ==0 ); +out: +spin_unlock (&fp->f_lock); +return ret; } static bool session_fd_check(struct ksmbd_tree_connect *tcon,
@@ -1460,9 +1471,11 @@ int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp) }up_write (&ci->m_lock); +spin_lock (&fp->f_lock); fp->owner.uid = fp->owner.gid =0 ;kfree (fp->owner.name); fp->owner.name =NULL ; +spin_unlock (&fp->f_lock);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1364/2077 gpio: timberdale: Return -ENOMEM on dynamic memory allocation in probe
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 8d7e62d5e9b2d2ff146f472a9215d7e29c7e2307 ]
Out of memory situation on driver's probe is expected to be reported to the driver's framework with a proper -ENOMEM error code.
--- drivers/gpio/gpio-timberdale.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-timberdale.c +1 -1
@@ -235,7 +235,7 @@ static int timbgpio_probe(struct platform_device *pdev) tgpio =devm_kzalloc (dev,sizeof (*tgpio),GFP_KERNEL );if (!tgpio) -return -EINVAL ; +return -ENOMEM ; tgpio->irq_base = pdata->irq_base;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1365/2077 pinctrl: meson: restore non-sleeping GPIO access
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viacheslav Bocharov <[email protected]>
[ Upstream commit 9777530157e7b82fd994327ff878c4245dadc931 ]
Commit 28f240683871 ("pinctrl: meson: mark the GPIO controller as sleeping") set gpio_chip.can_sleep = true to work around gpio-shared-proxy holding a spinlock across a sleeping pinctrl config path. That locking bug is now fixed in the shared-proxy itself ("gpio:
shared-proxy: always serialize with a sleeping mutex"), so the controller-wide workaround is no longer needed; the meson GPIO controller does not sleep.
meson_gpio_get/set/direction_* access MMIO through regmap. The regmap_mmio bus uses fast I/O (spinlock) locking, so these value callbacks do not contain sleeping operations. Since gpio_chip.can_sleep describes the get/set value path, restore can_sleep = false.
Marking the controller sleeping also broke atomic value consumers such as w1-gpio (1-Wire bitbang): w1_io.c runs its read time slot under local_irq_save() and uses the non-cansleep gpiod_set_value() / gpiod_get_value(), which with can_sleep=true trigger WARN_ON(can_sleep) in gpiolib on every transferred bit (from w1_gpio_write_bit() / w1_gpio_read_bit() via w1_reset_bus() and w1_search()). The printk and stack dump inside the IRQs-off, microsecond-scale time slot destroy the bit timing, so reset/presence detection and ROM search fail: the bus master registers but w1_master_slave_count stays at 0 and no devices are found. Verified on an Amlogic A113X board (DS18B20 on GPIOA_14):
with can_sleep restored to false the warnings are gone and the sensor is detected and read again.
This must not be applied or backported without the shared-proxy locking fix above; otherwise the original Khadas VIM3 splat returns on boards that genuinely share a meson GPIO.
--- drivers/pinctrl/meson/pinctrl-meson.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/meson/pinctrl-meson.c +1 -1
@@ -619,7 +619,7 @@ static int meson_gpiolib_register(struct meson_pinctrl *pc) pc->chip.set = meson_gpio_set; pc->chip.base =-1 ; pc->chip.ngpio = pc->data->num_pins; - pc->chip.can_sleep = true; + pc->chip.can_sleep = false; ret =gpiochip_add_data (&pc->chip, pc);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1366/2077 xen/pvcalls: bound backend response req_id before indexing rsp[]
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit d33846c8dcc06b83b7acdeac1e8bfbb5c0c26cb2 ]
pvcalls_front_event_handler() takes req_id directly from the backend-supplied ring response and uses it to index the fixed-size bedata->rsp[] array for a memcpy() and a store, with no range check. A malicious or buggy backend can set req_id past PVCALLS_NR_RSP_PER_RING and drive an out-of-bounds write past the bedata allocation.
req_id was also declared int while the wire field rsp->req_id is u32, so a range check on the signed value alone is insufficient: a backend req_id of 0xffffffff becomes -1, passes a >= PVCALLS_NR_RSP_PER_RING test and indexes bedata->rsp[-1]. Declare req_id as u32 so a single bound covers both ends.
A backend that sends an out-of-range req_id has violated the wire protocol, so rather than silently dropping the response, log once and stop trusting the backend: set bedata->disabled. The event handler then ignores further responses, and the request paths that wait for a response return -EIO instead of blocking forever. This mirrors the fatal-error handling xen-netback uses (xenvif_fatal_tx_err()).
The pvcalls frontend currently trusts its backend, so this is not a classic-Xen security issue, but it matters for hardening PV frontends against malicious backends (confidential and disaggregated deployments).
Message-ID: <[email protected]>
--- drivers/xen/pvcalls-front.c | 88 ++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 12 deletions(-)
drivers/xen/pvcalls-front.c +76 -12
@@ -32,6 +32,7 @@ struct pvcalls_bedata {struct xen_pvcalls_front_ring ring;grant_ref_t ref;int irq; +bool disabled;struct list_head socket_mappings;spinlock_t socket_lock;
@@ -131,6 +132,20 @@ static inline int get_request(struct pvcalls_bedata *bedata, int *req_id)return 0 ; } +/* +* Wait for the backend's response to req_id, or for the frontend to be +* disabled because the backend violated the wire protocol. Returns 0 once +* the response has arrived, or -EIO if the frontend was disabled. +*/ +static int pvcalls_front_wait_rsp (struct pvcalls_bedata *bedata,u32 req_id) +{ +wait_event (bedata->inflight_req, +READ_ONCE (bedata->rsp[req_id].req_id) == req_id || +READ_ONCE (bedata->disabled)); + +return READ_ONCE (bedata->disabled) ? -EIO :0 ; +} +static bool pvcalls_front_write_todo (struct sock_mapping *map) {struct pvcalls_data_intf *intf = map->active.ring;
@@ -168,7 +183,8 @@ static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)struct pvcalls_bedata *bedata;struct xen_pvcalls_response *rsp;uint8_t *src, *dst; -int req_id =0 , more =0 , done =0 ; +u32 req_id =0 ; +int more =0 , done =0 ;if (dev ==NULL )return IRQ_HANDLED ;
@@ -179,12 +195,31 @@ static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)pvcalls_exit ();return IRQ_HANDLED ; } +if (READ_ONCE (bedata->disabled)) { +pvcalls_exit (); +return IRQ_HANDLED ; + } again:while (RING_HAS_UNCONSUMED_RESPONSES (&bedata->ring)) { rsp =RING_GET_RESPONSE (&bedata->ring, bedata->ring.rsp_cons); req_id = rsp->req_id; +if (req_id >=PVCALLS_NR_RSP_PER_RING ) { +/* +* The backend supplied a req_id that would index +* bedata->rsp[] out of bounds: a protocol violation +* from a malicious or buggy backend. Log once, stop +* trusting this backend and disable the frontend rather +* than silently dropping the response and continuing. +*/ +pr_err_once ("pvcalls: backend sent out-of-range req_id %u, disabling frontend\n" , + req_id); +WRITE_ONCE (bedata->disabled, true); + bedata->ring.rsp_cons++; + done =1 ; +break ; + }if (rsp->cmd ==PVCALLS_POLL ) {struct sock_mapping *map = (struct sock_mapping *)(uintptr_t ) rsp->u.poll.id;
@@ -217,7 +252,7 @@ static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id) }RING_FINAL_CHECK_FOR_RESPONSES (&bedata->ring, more); -if (more) +if (more && !READ_ONCE (bedata->disabled)) goto again;if (done)wake_up (&bedata->inflight_req);
@@ -330,8 +365,11 @@ int pvcalls_front_socket(struct socket *sock)if (notify)notify_remote_via_irq (bedata->irq); -wait_event (bedata->inflight_req, -READ_ONCE (bedata->rsp[req_id].req_id) == req_id); + ret =pvcalls_front_wait_rsp (bedata, req_id); +if (ret) { +pvcalls_exit (); +return ret; + }/* read req_id, then the content */ smp_rmb ();
@@ -477,8 +515,11 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,if (notify)notify_remote_via_irq (bedata->irq); -wait_event (bedata->inflight_req, -READ_ONCE (bedata->rsp[req_id].req_id) == req_id); + ret =pvcalls_front_wait_rsp (bedata, req_id); +if (ret) { +pvcalls_exit_sock (sock); +return ret; + }/* read req_id, then the content */ smp_rmb ();
@@ -711,8 +752,11 @@ int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int addr_len)if (notify)notify_remote_via_irq (bedata->irq); -wait_event (bedata->inflight_req, -READ_ONCE (bedata->rsp[req_id].req_id) == req_id); + ret =pvcalls_front_wait_rsp (bedata, req_id); +if (ret) { +pvcalls_exit_sock (sock); +return ret; + }/* read req_id, then the content */ smp_rmb ();
@@ -761,8 +805,11 @@ int pvcalls_front_listen(struct socket *sock, int backlog)if (notify)notify_remote_via_irq (bedata->irq); -wait_event (bedata->inflight_req, -READ_ONCE (bedata->rsp[req_id].req_id) == req_id); + ret =pvcalls_front_wait_rsp (bedata, req_id); +if (ret) { +pvcalls_exit_sock (sock); +return ret; + }/* read req_id, then the content */ smp_rmb ();
@@ -820,6 +867,14 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, } } +if (READ_ONCE (bedata->disabled)) { +clear_bit (PVCALLS_FLAG_ACCEPT_INFLIGHT , + (void *)&map->passive.flags); +wake_up (&map->passive.inflight_accept_req); +pvcalls_exit_sock (sock); +return -EIO ; + } + map2 =kzalloc_obj (*map2);if (map2 ==NULL ) { clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
@@ -880,10 +935,18 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, }if (wait_event_interruptible (bedata->inflight_req, -READ_ONCE (bedata->rsp[req_id].req_id) == req_id)) { +READ_ONCE (bedata->rsp[req_id].req_id) == req_id || +READ_ONCE (bedata->disabled))) {pvcalls_exit_sock (sock);return -EINTR ; } +if (READ_ONCE (bedata->disabled)) { +clear_bit (PVCALLS_FLAG_ACCEPT_INFLIGHT , + (void *)&map->passive.flags); +wake_up (&map->passive.inflight_accept_req); +pvcalls_exit_sock (sock); +return -EIO ; + }/* read req_id, then the content */ smp_rmb ();
@@ -1054,7 +1117,8 @@ int pvcalls_front_release(struct socket *sock)notify_remote_via_irq (bedata->irq);wait_event (bedata->inflight_req, -READ_ONCE (bedata->rsp[req_id].req_id) == req_id); +READ_ONCE (bedata->rsp[req_id].req_id) == req_id || +READ_ONCE (bedata->disabled));if (map->active_socket) {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1367/2077 net/sched: dualpi2: clear stale classification on filter miss
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Moelius <[email protected]>
[ Upstream commit bf83ee45874e9f071478bed39f9cf40cc741629f ]
DualPI2 leaves previous classification state attached to an skb when filter classification returns no match. The enqueue path can then act on stale state from an earlier classification attempt.
A filter miss should fall back to the default class without reusing old per-packet classification data.
Initialize the classification result to CLASSIC before running the classifier. Explicit L4S, priority, and successful filter classification can still override that default.
--- net/sched/sch_dualpi2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/sched/sch_dualpi2.c +3 -3
@@ -346,6 +346,8 @@ static int dualpi2_skb_classify(struct dualpi2_sched_data *q,struct tcf_proto *fl;int result; + cb->classified =DUALPI2_C_CLASSIC ; +dualpi2_read_ect (skb);if (cb->ect & q->ecn_mask) { cb->classified =DUALPI2_C_L4S ;
@@ -359,10 +361,8 @@ static int dualpi2_skb_classify(struct dualpi2_sched_data *q, } fl =rcu_dereference_bh (q->tcf_filters); -if (!fl) { - cb->classified =DUALPI2_C_CLASSIC ; +if (!fl)return NET_XMIT_SUCCESS ; - } result =tcf_classify (skb,NULL , fl, &res, false);if (result >=0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1368/2077 net/sched: hhf: clear heavy-hitter state on reset
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Moelius <[email protected]>
[ Upstream commit a225f8c20712713406ae47024b8df42deacddd4a ]
HHF reset does not clear the classifier state used to identify heavy hitters. Packets after reset can therefore be scheduled using flow history from before the reset.
The reset operation should return the qdisc to an empty state.
Clear the heavy-hitter classifier tables when HHF is reset.
--- net/sched/sch_hhf.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
net/sched/sch_hhf.c +27 -0
@@ -462,12 +462,39 @@ static struct sk_buff *hhf_dequeue(struct Qdisc *sch)return skb; } +static void hhf_reset_classifier (struct hhf_sched_data *q) +{ +int i; + +if (!q->hh_flows) +return ; + +for (i =0 ; i <HH_FLOWS_CNT ; i++) { +struct hh_flow_state *flow, *next; +struct list_head *head = &q->hh_flows[i]; + +list_for_each_entry_safe (flow, next, head, flowchain) { +list_del (&flow->flowchain); +kfree (flow); + } + } +WRITE_ONCE (q->hh_flows_current_cnt,0 ); + +for (i =0 ; i <HHF_ARRAYS_CNT ; i++) { +if (q->hhf_valid_bits[i]) +bitmap_zero (q->hhf_valid_bits[i],HHF_ARRAYS_LEN ); + } + q->hhf_arrays_reset_timestamp =hhf_time_stamp (); +} +static void hhf_reset (struct Qdisc *sch) { +struct hhf_sched_data *q =qdisc_priv (sch);struct sk_buff *skb;while ((skb =hhf_dequeue (sch)) !=NULL )rtnl_kfree_skbs (skb, skb); +hhf_reset_classifier (q); }static void hhf_destroy (struct Qdisc *sch)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1369/2077 fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgid
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 539dce1144651f7976fa418e618b0b574bf15eeb ]
vfs_tmpfile() never checked that the caller's fsuid and fsgid map into the filesystem. On an idmapped mount whose idmapping does not cover the caller's fs{u,g}id, the ->tmpfile() instance initializes the new inode through inode_init_owner(), where mapped_fsuid()/mapped_fsgid() return INVALID_UID/INVALID_GID, and the tmpfile ends up owned by (uid_t)-1.
Every other creation path already refuses this: may_o_create() (O_CREAT) and may_create_dentry() (mkdir, mknod, symlink, link) bail out with -EOVERFLOW via fsuidgid_has_mapping() precisely so that an object cannot be created with an owner the filesystem cannot represent. An O_TMPFILE is no exception: it is created I_LINKABLE and linkat(2) can splice it into the namespace afterwards, so the same guarantee must hold.
Add the missing fsuidgid_has_mapping() check to vfs_tmpfile(). On a non-idmapped mount the caller's fs{u,g}id always map in the superblock's user namespace, so this is a no-op there and only takes effect on an idmapped mount that does not map the caller. It applies to every filesystem that sets FS_ALLOW_IDMAP and implements ->tmpfile() (tmpfs, ext4, btrfs, xfs, f2fs, ...), and to overlayfs, whose upper-layer tmpfile creation funnels through vfs_tmpfile() via backing_tmpfile_open().
--- fs/namei.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/namei.c +4 -0
@@ -4735,6 +4735,10 @@ int vfs_tmpfile(struct mnt_idmap *idmap,int error;int open_flag = file->f_flags; +/* A tmpfile is I_LINKABLE, so guard its owner like may_o_create(). */ +if (!fsuidgid_has_mapping (dir->i_sb, idmap)) +return -EOVERFLOW ; +/* we want directory to be writable */ error =inode_permission (idmap, dir,MAY_WRITE |MAY_EXEC );if (error)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1370/2077 afs: Fix error code in afs_extract_vl_addrs()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 4897cb71d4ab1f7e1a214adb1e4b80176702368d ]
The error codes on these paths are only set on the first iteration through the loop. Set the correct error code on every iteration.
--- fs/afs/vl_list.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/afs/vl_list.c +3 -1
@@ -92,7 +92,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net, {struct afs_addr_list *alist;const u8 *b = *_b; -int ret = -EINVAL ; +int ret; alist =afs_alloc_addrlist (nr_addrs);if (!alist)
@@ -110,6 +110,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net,case DNS_ADDRESS_IS_IPV4 :if (end - b <4 ) {_leave (" = -EINVAL [short inet]" ); + ret = -EINVAL ; goto error; }memcpy (x, b,4 );
@@ -122,6 +123,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net,case DNS_ADDRESS_IS_IPV6 :if (end - b <16 ) {_leave (" = -EINVAL [short inet6]" ); + ret = -EINVAL ; goto error; }memcpy (x, b,16 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1371/2077 afs: Fix double netfs initialisation in afs_root_iget()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 733a984a4ee7345325e47efb505eebfe67b299bc ]
Fix afs_root_iget() to leave initialisation of the netfs_inode part of the afs_vnode to afs_inode_init_from_status().
--- fs/afs/inode.c | 1 - 1 file changed, 1 deletion(-)
fs/afs/inode.c +0 -1
@@ -566,7 +566,6 @@ struct inode *afs_root_iget(struct super_block *sb, struct key *key) vnode =AFS_FS_I (inode); vnode->cb_v_check =atomic_read (&as->volume->cb_v_break); -afs_set_netfs_context (vnode); op =afs_alloc_operation (key, as->volume);if (IS_ERR (op)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1372/2077 afs: Remove setting of AS_RELEASE_ALWAYS for symlinks and mountpoints
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 81e985b4c3a6cbcc443fcdcd3ebda7fcc845d459 ]
Regular AFS files correctly use afs_file_aops which have release_folio set as netfs_release_folio, so AS_RELEASE_ALWAYS is valid for them when fscache is enabled (set via afs_vnode_set_cache()). Symlinks and mountpoints in AFS use afs_dir_aops, which does not provide a release_folio callback. However, afs_apply_status() unconditionally calls mapping_set_release_always() for these.
In such case when memory management code attempts to release folios, filemap_release_folio() checks folio_needs_release() which returns true due to AS_RELEASE_ALWAYS being set. Since there is no release_folio callback, it falls through to try_to_free_buffers(), which at present expects buffer_heads to be not null. For symlinks and mountpoints without buffer_heads, this causes pointer dereference.
[dh: Added more bits that were missed]
--- fs/afs/inode.c | 7 +++---- fs/afs/internal.h | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-)
fs/afs/inode.c +3 -4
@@ -52,9 +52,9 @@ static noinline void dump_vnode(struct afs_vnode *vnode, struct afs_vnode *paren/* * Set parameters for the netfs library */ -static void afs_set_netfs_context (struct afs_vnode *vnode) +static void afs_set_netfs_context (struct afs_vnode *vnode,bool is_file) { -netfs_inode_init (&vnode->netfs, &afs_req_ops, true); +netfs_inode_init (&vnode->netfs, &afs_req_ops, is_file); }/*
@@ -126,7 +126,6 @@ static int afs_inode_init_from_status(struct afs_operation *op, } inode->i_mapping->a_ops = &afs_symlink_aops;inode_nohighmem (inode); -mapping_set_release_always (inode->i_mapping);break ;default :dump_vnode (vnode, op->file[0 ].vnode != vnode ? op->file[0 ].vnode :NULL );
@@ -136,7 +135,7 @@ static int afs_inode_init_from_status(struct afs_operation *op,i_size_write (inode, status->size);inode_set_bytes (inode, status->size); -afs_set_netfs_context (vnode); +afs_set_netfs_context (vnode, status->type ==AFS_FTYPE_FILE ); vnode->invalid_before = status->data_version;trace_afs_set_dv (vnode, status->data_version);
fs/afs/internal.h +0 -2
@@ -750,8 +750,6 @@ static inline void afs_vnode_set_cache(struct afs_vnode *vnode, {#ifdef CONFIG_AFS_FSCACHE vnode->netfs.cache = cookie; -if (cookie) -mapping_set_release_always (vnode->netfs.inode.i_mapping);#endif }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1373/2077 afs: Fix directory inode initialisation order
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 35b177ef541ae8eefbfbf679c3476bc3fb1eb83c ]
Fix afs_inode_init_from_status() to call afs_set_netfs_context() before the switch to do file type-specific initialisation because local directory changes don't get uploaded to the server, only stored in the cache.
This requires that the file size be set before, so move that up too.
Without this, NETFS_ICTX_SINGLE_NO_UPLOAD as set on directories gets clobbered.
--- fs/afs/inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/afs/inode.c +4 -4
@@ -93,6 +93,10 @@ static int afs_inode_init_from_status(struct afs_operation *op, inode->i_gid =make_kgid (&init_user_ns, status->group);set_nlink (&vnode->netfs.inode, status->nlink); +i_size_write (inode, status->size); +inode_set_bytes (inode, status->size); +afs_set_netfs_context (vnode, status->type ==AFS_FTYPE_FILE ); +switch (status->type) {case AFS_FTYPE_FILE : inode->i_mode =S_IFREG | (status->mode &S_IALLUGO );
@@ -133,10 +137,6 @@ static int afs_inode_init_from_status(struct afs_operation *op,return afs_protocol_error (NULL , afs_eproto_file_type); } -i_size_write (inode, status->size); -inode_set_bytes (inode, status->size); -afs_set_netfs_context (vnode, status->type ==AFS_FTYPE_FILE ); - vnode->invalid_before = status->data_version;trace_afs_set_dv (vnode, status->data_version);inode_set_iversion_raw (&vnode->netfs.inode, status->data_version);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1374/2077 afs: use kvfree() to free memory allocated by kvcalloc()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zilin Guan <[email protected]>
[ Upstream commit cb39654926f8e7a08ecc1dcb3941628855275940 ]
op->more_files is allocated with kvcalloc() but released via afs_put_operation(), which uses kfree() internally. This mismach prevents the resource from being released properly and may lead to undefined behavior.
Fix this by using kvfree() to free op->more_files to match its allocation method.
--- fs/afs/fs_operation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/fs_operation.c +1 -1
@@ -348,7 +348,7 @@ int afs_put_operation(struct afs_operation *op)for (i =0 ; i < op->nr_files -2 ; i++)if (op->more_files[i].put_vnode)iput (&op->more_files[i].vnode->netfs.inode); -kfree (op->more_files); +kvfree (op->more_files); }if (op->estate) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1375/2077 afs: Remove erroneous seq |= 1 in volume lookup loop
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit a58edda50a3ec08e6adac1d04dc3e488494e412d ]
The seq |= 1 operation in the volume lookup loop is incorrect because:
seq is already incremented at start, making it odd in next iteration which triggers lock, but The |= 1 operation causes seq to be even and unintended lockless operation
Remove this erroneous operation to maintain proper lock sequencing.
--- fs/afs/callback.c | 1 - 1 file changed, 1 deletion(-)
fs/afs/callback.c +0 -1
@@ -140,7 +140,6 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,break ;if (!need_seqretry (&cell->volume_lock, seq))break ; - seq |=1 ;/* Want a lock next time */ }done_seqretry (&cell->volume_lock, seq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1376/2077 afs: Fix bulk lookup malfunction due to change in dir_emit() API
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 2f79d1b93c62470fe02dbdc24770f1ae5a9e1be6 ]
afs_do_lookup() and afs_do_lookup_one() use the same directory parsing code as afs_readdir() and were supplying alternative dir_context actors to retrieve dirents, but because lookup needs the vnode's uniquifier as part of the reference, but not the DT flags, the uniquifier was being passed in the dt flags argument to the lookup actors.
Unfortunately, commit c644bce62b9c, added to fix overlayfs with fuse, broke this by masking off part of the uniquifier. This doesn't matter enough to be directly noticeable, instead causing bulk advance inode lookups to fail (which are retried later) and may cause dir revalidation to malfunction if the uniquifier is changed by masking.
Fix this by making the afs directory parsing code take special ->actor values of AFS_LOOKUP or AFS_LOOKUP_ONE instead that tell it to call afs_lookup_filldir() or afs_lookup_one_filldir() directly rather than going through dir_emit(). dir_emit() is still used for readdir.
--- fs/afs/dir.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)
fs/afs/dir.c +25 -15
@@ -28,9 +28,11 @@ static int afs_d_revalidate(struct inode *dir, const struct qstr *name,static int afs_d_delete (const struct dentry *dentry);static void afs_d_iput (struct dentry *dentry,struct inode *inode);static bool afs_lookup_one_filldir (struct dir_context *ctx,const char *name,int nlen, -loff_t fpos,u64 ino,unsigned dtype); +u64 ino,u32 uniquifier); +#define AFS_LOOKUP_ONE ((filldir_t)0x123UL)static bool afs_lookup_filldir (struct dir_context *ctx,const char *name,int nlen, -loff_t fpos,u64 ino,unsigned dtype); +u64 ino,u32 uniquifier); +#define AFS_LOOKUP ((filldir_t)0x137UL)static int afs_create (struct mnt_idmap *idmap,struct inode *dir,struct dentry *dentry,umode_t mode,bool excl); static struct dentry *afs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
@@ -421,11 +423,18 @@ static int afs_dir_iterate_block(struct afs_vnode *dvnode, }/* found the next entry */ -if (!dir_emit (ctx, dire->u.name, nlen, -ntohl (dire->u.vnode), - (ctx->actor == afs_lookup_filldir || - ctx->actor == afs_lookup_one_filldir)? -ntohl (dire->u.unique) :DT_UNKNOWN )) { +if (ctx->actor ==AFS_LOOKUP ) { +if (!afs_lookup_filldir (ctx, dire->u.name, nlen, +ntohl (dire->u.vnode), +ntohl (dire->u.unique))) +return 0 ; + }else if (ctx->actor ==AFS_LOOKUP_ONE ) { +if (!afs_lookup_one_filldir (ctx, dire->u.name, nlen, +ntohl (dire->u.vnode), +ntohl (dire->u.unique))) +return 0 ; + }else if (!dir_emit (ctx, dire->u.name, nlen, +ntohl (dire->u.vnode),DT_UNKNOWN )) {_leave (" = 0 [full]" );return 0 ; }
@@ -545,6 +554,7 @@ static int afs_readdir(struct file *file, struct dir_context *ctx) {afs_dataversion_t dir_version; + ctx->dt_flags_mask =UINT_MAX ;return afs_dir_iterate (file_inode (file), ctx, file, &dir_version); }
@@ -554,14 +564,14 @@ static int afs_readdir(struct file *file, struct dir_context *ctx)* uniquifier through dtype */ static bool afs_lookup_one_filldir (struct dir_context *ctx,const char *name, -int nlen,loff_t fpos,u64 ino,unsigned dtype) +int nlen,u64 ino,u32 uniquifier) {struct afs_lookup_one_cookie *cookie = container_of(ctx, struct afs_lookup_one_cookie, ctx);_enter ("{%s,%u},%s,%u,,%llu,%u" , cookie->name.name, cookie->name.len, name, nlen, - (unsigned long long ) ino, dtype); + (unsigned long long ) ino, uniquifier);/* insanity checks first */ BUILD_BUG_ON (sizeof (union afs_xdr_dir_block ) !=2048 );
@@ -574,7 +584,7 @@ static bool afs_lookup_one_filldir(struct dir_context *ctx, const char *name, } cookie->fid.vnode = ino; - cookie->fid.unique = dtype; + cookie->fid.unique = uniquifier; cookie->found =1 ;_leave (" = false [found]" );
@@ -591,7 +601,7 @@ static int afs_do_lookup_one(struct inode *dir, const struct qstr *name, {struct afs_super_info *as = dir->i_sb->s_fs_info;struct afs_lookup_one_cookie cookie = { - .ctx.actor = afs_lookup_one_filldir, + .ctx.actor =AFS_LOOKUP_ONE , .name = *name, .fid.vid = as->volume->vid };
@@ -622,14 +632,14 @@ static int afs_do_lookup_one(struct inode *dir, const struct qstr *name,* uniquifier through dtype */ static bool afs_lookup_filldir (struct dir_context *ctx,const char *name, -int nlen,loff_t fpos,u64 ino,unsigned dtype) +int nlen,u64 ino,u32 uniquifier) {struct afs_lookup_cookie *cookie = container_of(ctx, struct afs_lookup_cookie, ctx);_enter ("{%s,%u},%s,%u,,%llu,%u" , cookie->name.name, cookie->name.len, name, nlen, - (unsigned long long ) ino, dtype); + (unsigned long long ) ino, uniquifier);/* insanity checks first */ BUILD_BUG_ON (sizeof (union afs_xdr_dir_block ) !=2048 );
@@ -637,7 +647,7 @@ static bool afs_lookup_filldir(struct dir_context *ctx, const char *name,if (cookie->nr_fids <50 ) { cookie->fids[cookie->nr_fids].vnode = ino; - cookie->fids[cookie->nr_fids].unique = dtype; + cookie->fids[cookie->nr_fids].unique = uniquifier; cookie->nr_fids++; }
@@ -778,7 +788,7 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry)for (i =0 ; i <ARRAY_SIZE (cookie->fids); i++) cookie->fids[i].vid = dvnode->fid.vid; - cookie->ctx.actor = afs_lookup_filldir; + cookie->ctx.actor =AFS_LOOKUP ; cookie->name = dentry->d_name; cookie->nr_fids =2 ;/* slot 1 is saved for the fid we actually want * and slot 0 for the directory */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1377/2077 afs: Fix misplaced inc of net->cells_outstanding
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit c9c3b615a462a4023bd148f02c564e175ed10502 ]
Fix net->cells_outstanding being incremented before the check for failure of idr_alloc_cyclic(), leaving the count incremented on error.
--- fs/afs/cell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/cell.c +1 -1
@@ -205,11 +205,11 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_source = vllist->source; cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ -atomic_inc (&net->cells_outstanding); ret =idr_alloc_cyclic (&net->cells_dyn_ino, cell,2 ,INT_MAX /2 ,GFP_KERNEL );if (ret <0 ) goto error; +atomic_inc (&net->cells_outstanding); cell->dynroot_ino = ret; cell->debug_id =atomic_inc_return (&cell_debug_id);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1378/2077 afs: Fix reinitialisation of the inode, in particular ->lock_work
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 5597fbd1e7c161914f20315a726e54025b0fdadb ]
It seems that initalising afs_vnode::lock_work a single time in the slab's init function isn't sufficient for work_structs. This results in the DEBUG_OBJECTS debugging stuff producing a warning occasionally when running the generic/131 xfstest:
ODEBUG: activate not available (active state 0) object: 0000000016d8760f object type: work_struct hint: afs_lock_work+0x0/0x220
WARNING: lib/debugobjects.c:629 at debug_print_object+0x4b/0x90, CPU#3: locktest/7695 ... CPU: 3 UID: 0 PID: 7695 Comm: locktest Tainted: G S 7.1.0-build3+ #2771 PREEMPT ... RIP: 0010:debug_print_object+0x65/0x90 ... Call Trace: <TASK> ? __pfx_afs_lock_work+0x10/0x10 debug_object_activate+0x122/0x170 insert_work+0x25/0x60 __queue_work+0x2e0/0x340 queue_delayed_work_on+0x48/0x70 afs_fl_release_private+0x57/0x70 locks_release_private+0x5c/0xa0 locks_free_lock+0xe/0x20 posix_lock_inode+0x55f/0x5b0 locks_lock_inode_wait+0x81/0x140 ? file_write_and_wait_range+0x50/0x70 afs_lock+0xcd/0x110 fcntl_setlk+0x10d/0x260 do_fcntl+0x24e/0x5b0 __do_sys_fcntl+0x6a/0x90 do_syscall_64+0x11e/0x310 entry_SYSCALL_64_after_hwframe+0x71/0x79
Fix this by reinitialising ->lock_work after allocating an inode.
Also, flush ->lock_work when the inode is being evicted to make sure it's not still running.
--- fs/afs/inode.c | 1 + fs/afs/super.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
fs/afs/inode.c +1 -0
@@ -680,6 +680,7 @@ void afs_evict_inode(struct inode *inode inode->i_mapping->a_ops->writepages (inode->i_mapping, &wbc); } +flush_delayed_work (&vnode->lock_work);netfs_wait_for_outstanding_io (inode);truncate_inode_pages_final (&inode->i_data);netfs_free_folioq_buffer (vnode->directory);
fs/afs/super.c +1 -1
@@ -660,7 +660,6 @@ static void afs_i_init_once(void *_vnodeINIT_LIST_HEAD (&vnode->wb_keys);INIT_LIST_HEAD (&vnode->pending_locks);INIT_LIST_HEAD (&vnode->granted_locks); -INIT_DELAYED_WORK (&vnode->lock_work, afs_lock_work);INIT_LIST_HEAD (&vnode->cb_mmap_link);seqlock_init (&vnode->cb_lock); }
@@ -694,6 +693,7 @@ static struct inode *afs_alloc_inode(strinit_rwsem (&vnode->rmdir_lock);INIT_WORK (&vnode->cb_work, afs_invalidate_mmap_work); +INIT_DELAYED_WORK (&vnode->lock_work, afs_lock_work);_leave (" = %p" , &vnode->netfs.inode);return &vnode->netfs.inode;
Greg Kroah-Hartman
maintainerPATCH 1379/2077 afs: Fix callback service message parsers to pass through -EAGAIN
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 0f36469d7ce98b362934113c550d08bb0c784231 ]
The AFS filesystem client uses an rxrpc server to listen for callback notifications. Each callback call type handler has a delivery function that parses the incoming request stream, and this should return -EAGAIN the last packet hasn't yet been seen, but all currently queued received data is consumed. afs_extract_data() does this, but the -EAGAIN return is switched to 0 inadvertantly
Fix callback service message parsers to pass through -EAGAIN
--- fs/afs/cmservice.c | 2 -- 1 file changed, 2 deletions(-)
fs/afs/cmservice.c +0 -2
@@ -334,7 +334,6 @@ static int afs_deliver_cb_init_call_back ret =afs_extract_data (call, false);switch (ret) {case 0 :break ; -case -EAGAIN :return 0 ;default :return ret; }
@@ -456,7 +455,6 @@ static int afs_deliver_cb_probe_uuid(str ret =afs_extract_data (call, false);switch (ret) {case 0 :break ; -case -EAGAIN :return 0 ;default :return ret; }
Greg Kroah-Hartman
maintainerPATCH 1380/2077 afs: Fix missing NULL pointer check in afs_break_some_callbacks()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 794a01110390c1b76f59ece773fb0fbfd89c6f5c ]
Fix afs_break_some_callbacks() to check to see if afs_lookup_volume_rcu() returned NULL (e.g. the specified volume is unknown).
--- fs/afs/callback.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/callback.c +5 -1
@@ -220,7 +220,11 @@ static void afs_break_some_callbacks(struct afs_server *server,rcu_read_lock (); volume =afs_lookup_volume_rcu (server->cell, vid); -if (cbb->fid.vnode ==0 && cbb->fid.unique ==0 ) { +if (!volume) { +/* Ignore breaks on unknown volumes. */ +rcu_read_unlock (); + *_count =0 ; + }else if (cbb->fid.vnode ==0 && cbb->fid.unique ==0 ) {afs_break_volume_callback (server, volume); *_count -=1 ;if (*_count)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1381/2077 afs: Use scoped_seqlock_read() rather than manually doing seqlock stuff
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 3b1601471a88f86082fc1f1c2475645cdf59f7d8 ]
This is an addendum to the patch to remove the erroneous seq |= 1 in volume lookup loop.
Switch to using scoped_seqlock_read() as suggested by Oleg Nesterov[1].
Stable-dep-of: d672c276f685 ("afs: Fix leak of ungot volume")
--- fs/afs/callback.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
fs/afs/callback.c +1 -8
@@ -113,16 +113,12 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell, {struct afs_volume *volume =NULL ;struct rb_node *p; -int seq =1 ; -for (;;) { + scoped_seqlock_read(&cell->volume_lock, ss_lock) {/* Unfortunately, rbtree walking doesn't give reliable results * under just the RCU read lock, so we have to check for * changes. */ - seq++;/* 2 on the 1st/lockless path, otherwise odd */ -read_seqbegin_or_lock (&cell->volume_lock, &seq); - p =rcu_dereference_raw (cell->volumes.rb_node);while (p) { volume = rb_entry(p, struct afs_volume, cell_node);
@@ -138,11 +134,8 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,if (volume &&afs_try_get_volume (volume, afs_volume_trace_get_callback))break ; -if (!need_seqretry (&cell->volume_lock, seq)) -break ; } -done_seqretry (&cell->volume_lock, seq);return volume; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1382/2077 afs: Fix leak of ungot volume
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit d672c276f685a540ed2b2a8bafaed4650a89022c ]
Fix afs_lookup_volume_rcu() so that it doesn't leak a dying volume if afs_try_get_volume() fails.
--- fs/afs/callback.c | 1 + 1 file changed, 1 insertion(+)
fs/afs/callback.c +1 -0
@@ -134,6 +134,7 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,if (volume &&afs_try_get_volume (volume, afs_volume_trace_get_callback))break ; + volume =NULL ; }return volume;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1383/2077 afs: Fix vllist leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit fc10c0ecf06f2981af5d04357612b00051e03e9e ]
Fix a leak of the new vllist in afs_update_cell() in the event that it is an empty list (nr_servers == 0), in which case the old list isn't displaced unless the old list is also empty.
--- fs/afs/cell.c | 2 ++ 1 file changed, 2 insertions(+)
fs/afs/cell.c +2 -0
@@ -547,6 +547,8 @@ static int afs_update_cell(struct afs_cell *cell)rcu_assign_pointer (cell->vl_servers, vllist); cell->dns_source = vllist->source; old = p; + }else { + old = vllist; }write_unlock (&cell->vl_servers_lock);afs_put_vlserverlist (cell->net, old);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1384/2077 afs: Fix lack of locking around modifications of net->cells_dyn_ino
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 55e841836c6f4646490f7b0347192b7a92d431ba ]
Fix the lack of locking around modifications of net->cells_dyn_ino by taking net->cells_lock exclusively. This also requires to cell to be removed from net->cells_dyn_ino in afs_destroy_cell_work() rather than in afs_cell_destroy() as the latter runs in RCU cleanup context and sleeping locks cannot be taken there.
--- fs/afs/cell.c | 8 +++++++- fs/afs/dynroot.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-)
fs/afs/cell.c +7 -1
@@ -205,8 +205,10 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_source = vllist->source; cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ +down_write (&net->cells_lock); ret =idr_alloc_cyclic (&net->cells_dyn_ino, cell,2 ,INT_MAX /2 ,GFP_KERNEL ); +up_write (&net->cells_lock);if (ret <0 ) goto error;atomic_inc (&net->cells_outstanding);
@@ -579,7 +581,6 @@ static void afs_cell_destroy(struct rcu_head *rcu)afs_put_vlserverlist (net,rcu_access_pointer (cell->vl_servers));afs_unuse_cell (cell->alias_of, afs_cell_trace_unuse_alias);key_put (cell->anonymous_key); -idr_remove (&net->cells_dyn_ino, cell->dynroot_ino);kfree (cell->name -1 );kfree (cell);
@@ -594,6 +595,11 @@ static void afs_destroy_cell_work(struct work_struct *work)afs_see_cell (cell, afs_cell_trace_destroy);timer_delete_sync (&cell->management_timer);cancel_work_sync (&cell->manager); + +down_write (&cell->net->cells_lock); +idr_remove (&cell->net->cells_dyn_ino, cell->dynroot_ino); +up_write (&cell->net->cells_lock); +call_rcu (&cell->rcu, afs_cell_destroy); }
fs/afs/dynroot.c +1 -1
@@ -278,7 +278,7 @@ static struct dentry *afs_lookup_atcell(struct inode *dir, struct dentry *dentry }/* -* Transcribe the cell database into readdir content under the RCU read lock. +* Transcribe the cell database into readdir content under net->cells_lock. * Each cell produces two entries, one prefixed with a dot and one not. */ static int afs_dynroot_readdir_cells (struct afs_net *net,struct dir_context *ctx)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1385/2077 afs: Fix premature cell exposure through /afs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 26f17ce6fa3f05cb5965790499c1839094260de4 ]
AFS cell records are prematurely exposured through the /afs dynamic root by virtue of adding them immediately to the net->cells_dyn_ino IDR when the cell is allocated rather than when it is added to the lookup tree. This allows a candidate record to be accessed, even if it's actually a duplicate or not published yet.
Fix this by not adding the cell to cells_dyn_ino until it's confirmed non-duplicate and is being published. A flag is then used to record whether it is added to the IDR to make removal from the IDR conditional.
--- fs/afs/cell.c | 27 +++++++++++++++++---------- fs/afs/internal.h | 1 + 2 files changed, 18 insertions(+), 10 deletions(-)
fs/afs/cell.c +17 -10
@@ -205,14 +205,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_source = vllist->source; cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ -down_write (&net->cells_lock); - ret =idr_alloc_cyclic (&net->cells_dyn_ino, cell, -2 ,INT_MAX /2 ,GFP_KERNEL ); -up_write (&net->cells_lock); -if (ret <0 ) - goto error;atomic_inc (&net->cells_outstanding); - cell->dynroot_ino = ret; cell->debug_id =atomic_inc_return (&cell_debug_id);trace_afs_cell (cell->debug_id,1 ,0 , afs_cell_trace_alloc);
@@ -306,6 +299,13 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net, goto cell_already_exists; } + ret =idr_alloc_cyclic (&net->cells_dyn_ino, candidate, +2 ,INT_MAX /2 ,GFP_KERNEL ); +if (ret <0 ) + goto cant_alloc_ino; + candidate->dynroot_ino = ret; +set_bit (AFS_CELL_FL_HAVE_INO , &candidate->flags); + cell = candidate; candidate =NULL ;afs_use_cell (cell, trace);
@@ -380,6 +380,11 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net,_leave (" = %p [cell]" , cell);return cell; +cant_alloc_ino: +up_write (&net->cells_lock); +afs_put_cell (candidate, afs_cell_trace_put_candidate); + goto error_noput; + cell_already_exists:_debug ("cell exists" ); cell = cursor;
@@ -596,9 +601,11 @@ static void afs_destroy_cell_work(struct work_struct *work)timer_delete_sync (&cell->management_timer);cancel_work_sync (&cell->manager); -down_write (&cell->net->cells_lock); -idr_remove (&cell->net->cells_dyn_ino, cell->dynroot_ino); -up_write (&cell->net->cells_lock); +if (test_bit (AFS_CELL_FL_HAVE_INO , &cell->flags)) { +down_write (&cell->net->cells_lock); +idr_remove (&cell->net->cells_dyn_ino, cell->dynroot_ino); +up_write (&cell->net->cells_lock); + }call_rcu (&cell->rcu, afs_cell_destroy); }
fs/afs/internal.h +1 -0
@@ -388,6 +388,7 @@ struct afs_cell {#define AFS_CELL_FL_NO_GC 0/* The cell was added manually, don't auto-gc */ #define AFS_CELL_FL_DO_LOOKUP 1/* DNS lookup requested */ #define AFS_CELL_FL_CHECK_ALIAS 2/* Need to check for aliases */ +#define AFS_CELL_FL_HAVE_INO 3/* Have dynroot_ino */ enum afs_cell_state state;short error; enum dns_record_source dns_source:8; /* Latest source of data from lookup */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1386/2077 afs: Fix the volume AFS_VOLUME_RM_TREE is set on
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 56b4e4b26f84411d880f968a539207b0a8889c8c ]
Fix afs_insert_volume_into_cell() to set AFS_VOLUME_RM_TREE on the volume replaced, not the new volume, as it's now removed from the cell's volume tree. This will cause the old volume to be removed from the tree twice and the new volume never to be removed.
--- fs/afs/volume.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/volume.c +1 -1
@@ -40,7 +40,7 @@ static struct afs_volume *afs_insert_volume_into_cell(struct afs_cell *cell, goto found; } -set_bit (AFS_VOLUME_RM_TREE , &volume->flags); +set_bit (AFS_VOLUME_RM_TREE , &p->flags);rb_replace_node_rcu (&p->cell_node, &volume->cell_node, &cell->volumes); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1387/2077 afs: Fix unchecked-length string display in debug statement
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 903d37c97228258da71e092f8b4ab260ce81497d ]
Fix afs_extract_vlserver_list() to limit the length of the displayed string in a debug statement().
--- fs/afs/vl_list.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/vl_list.c +5 -1
@@ -200,6 +200,8 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell, b +=sizeof (*hdr);while (end - b >=sizeof (bs)) { +int nlen; + bs.name_len =afs_extract_le16 (&b); bs.priority =afs_extract_le16 (&b); bs.weight =afs_extract_le16 (&b);
@@ -209,10 +211,12 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell, bs.protocol = *b++; bs.nr_addrs = *b++; + nlen =min3 (bs.name_len, end - b,255 ); +_debug ("extract %u %u %u %u %u %u %*.*s" , bs.name_len, bs.priority, bs.weight, bs.port, bs.protocol, bs.nr_addrs, - bs.name_len, bs.name_len, b); + bs.name_len, nlen, b);if (end - b < bs.name_len)break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1388/2077 iomap: release pages on atomic dio size mismatch
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fengnan Chang <[email protected]>
[ Upstream commit 681e452683b69a8e1a571cba0f238f8ceacf55d2 ]
If bio_iov_iter_get_pages() or the bounce helper succeeds but builds a short bio, the REQ_ATOMIC size check rejects it before submission. The old error path only dropped the bio reference, leaving any pages already attached to the bio unreleased.
Release or unbounce the pages before falling through to out_put_bio on this error path.
This bug was reported by sashiko:
https://sashiko.dev/#/patchset/20260608073134.95964-1-changfengnan%40bytedance.com
--- fs/iomap/direct-io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/iomap/direct-io.c +6 -1
@@ -369,7 +369,7 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,*/ if ((op &REQ_ATOMIC ) &&WARN_ON_ONCE (ret !=iomap_length (iter))) { ret = -EINVAL ; - goto out_put_bio; + goto out_bio_release_pages; }if (iter->iomap.flags &IOMAP_F_INTEGRITY ) {
@@ -393,6 +393,11 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,iomap_dio_submit_bio (iter, dio, bio, pos);return ret; +out_bio_release_pages: +if (dio->flags &IOMAP_DIO_BOUNCE ) +bio_iov_iter_unbounce (bio, true, false); +else +bio_release_pages (bio, false); out_put_bio:bio_put (bio);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1389/2077 minix: avoid overflow in bitmap block count calculation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit fb3e566cafc38fe3ba35e6843a2d529a3748870c ]
minix_check_superblock() uses minix_blocks_needed() to verify that the on-disk imap and zmap block counts are large enough for the advertised inode and zone counts.
The helper currently performs DIV_ROUND_UP() in unsigned int arithmetic. A Minix v3 image can set s_ninodes or s_zones near UINT_MAX so the addition inside DIV_ROUND_UP() wraps to zero. That makes a zero imap/zmap block count look valid, after which minix_fill_super() can dereference s_imap[0] or s_zmap[0] even though no bitmap buffers were allocated.
Impact: mounting a crafted Minix v3 image whose s_ninodes or s_zones is near UINT_MAX makes minix_check_superblock() accept a zero bitmap-block count and minix_fill_super() dereference s_imap[0]/s_zmap[0], panicking the kernel.
The divisor is the bitmap capacity in bits, blocksize * 8, which is always a power of two: minix_fill_super() obtains the block size through sb_set_blocksize(), and blk_validate_block_size() rejects any size that is not a power of two. Use DIV_ROUND_UP_POW2(), which divides before adding the round-up term and so cannot overflow for a power-of-two divisor.
--- fs/minix/minix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/minix/minix.h +1 -1
@@ -97,7 +97,7 @@ static inline struct minix_inode_info *minix_i(struct inode *inode)static inline unsigned minix_blocks_needed (unsigned bits,unsigned blocksize) { -return DIV_ROUND_UP (bits, blocksize *8 ); +return DIV_ROUND_UP_POW2 (bits, blocksize *8 ); } #if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1390/2077 cachefiles: Fix double unlock in nomem_d_alloc error path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit 8c256fba2b46020004201c500b2a1fbc707a33ef ]
When start_creating() fails and returns -ENOMEM, it has already released the parent directory lock in __start_dirop():
static struct dentry *__start_dirop(...)
{
...
inode_lock_nested(dir, I_MUTEX_PARENT);
dentry = lookup_one_qstr_excl(name, parent, lookup_flags);
if (IS_ERR(dentry))
inode_unlock(dir); <-- Lock released on error
return dentry;
}However, the nomem_d_alloc error path in cachefiles_get_directory() unconditionally calls inode_unlock(d_inode(dir)) again, causing a double unlock that corrupts the rwsem state.
This is a leftover from commit 7ab96df840e60 which replaced manual locking with start_creating() but failed to update the nomem_d_alloc path (while correctly updating mkdir_error and lookup_error paths).
--- fs/cachefiles/namei.c | 1 - 1 file changed, 1 deletion(-)
fs/cachefiles/namei.c +0 -1
@@ -209,7 +209,6 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,return ERR_PTR (ret); nomem_d_alloc: -inode_unlock (d_inode (dir));_leave (" = -ENOMEM" );return ERR_PTR (-ENOMEM ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1391/2077 ovl: fix comment about locking order
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit fd5637a2fe6dd4448392738691d63e5559fafb12 ]
Forgot to update the comment when we changed the locking order.
--- fs/overlayfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/overlayfs/inode.c +2 -2
@@ -783,8 +783,8 @@ static const struct address_space_operations ovl_aops = {* * This chain is valid: * - inode->i_rwsem (inode_lock[2]) -* - upper_mnt->mnt_sb->s_writers (ovl_want_write[0]) * - OVL_I(inode)->lock (ovl_inode_lock[2]) +* - upper_mnt->mnt_sb->s_writers (ovl_want_write[0]) * - OVL_I(lowerinode)->lock (ovl_inode_lock[1]) * * And this chain is valid:
@@ -797,8 +797,8 @@ static const struct address_space_operations ovl_aops = {* held, because it is in reverse order of the non-nested case using the same * upper fs: * - inode->i_rwsem (inode_lock[1]) -* - upper_mnt->mnt_sb->s_writers (ovl_want_write[0]) * - OVL_I(inode)->lock (ovl_inode_lock[1]) +* - upper_mnt->mnt_sb->s_writers (ovl_want_write[0]) */ #define OVL_MAX_NESTING FILESYSTEM_MAX_STACK_DEPTH
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1392/2077 iomap: guard io_size EOF trim against concurrent truncate underflow
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Morduan Zang <[email protected]>
[ Upstream commit 55ec50d046c03b3724741957f7b007856e36dbe7 ]
iomap: fix zero padding data issue in concurrent append writes changed ioend accounting so that io_size tracks only valid data within EOF. This trims io_size when a writeback range extends past end_pos:
ioend->io_size += map_len;
if (ioend->io_offset + ioend->io_size > end_pos)
ioend->io_size = end_pos - ioend->io_offset;However, if end_pos ends up below ioend->io_offset, the subtraction becomes negative and is stored in size_t io_size, causing an unsigned wrap to a huge value. This can happen when writeback continues past byte-level EOF up to a block-aligned range, or when a concurrent truncate shrinks the file after end_pos was sampled in iomap_writeback_handle_eof().
A wrapped io_size can mislead append detection and corrupt completion-time size handling, since filesystem end_io paths consume io_size for decisions such as on-disk EOF updates and unwritten/COW completion ranges.
Fix this by clamping io_size to zero when EOF has moved to or before the ioend start offset. This preserves the original intent of trimming io_size to valid in-EOF data while avoiding the underflow.
--- fs/iomap/ioend.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/iomap/ioend.c +6 -2
@@ -297,8 +297,12 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,* appending writes. */ ioend->io_size += map_len; -if (ioend->io_offset + ioend->io_size > end_pos) - ioend->io_size = end_pos - ioend->io_offset; +if (ioend->io_offset + ioend->io_size > end_pos) { +if (ioend->io_offset >= end_pos) + ioend->io_size =0 ; +else + ioend->io_size = end_pos - ioend->io_offset; + }wbc_account_cgroup_owner (wpc->wbc, folio, map_len);return map_len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1393/2077 netfs: Fix netfs_create_write_req() to handle async cache object creation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit dbd6f56d975b23241b7bbb11bb8f562af548a0aa ]
netfs_create_write_req() will skip caching if the fscache cookie is disabled, but this is a problem because async cache object creation might not have got far enough yet that has been enabled - thereby causing the call to fscache_begin_write_operation() to be skipped.
Fix this by removing the checks on the cookie and delegating this to fscache_begin_write_operation().
--- fs/netfs/write_issue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/netfs/write_issue.c +1 -1
@@ -106,7 +106,7 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,_enter ("R=%x" , wreq->debug_id); ictx =netfs_inode (wreq->inode); -if (is_cacheable &&netfs_is_cache_enabled (ictx)) +if (is_cacheable)fscache_begin_write_operation (&wreq->cache_resources,netfs_i_cookie (ictx));if (rolling_buffer_init (&wreq->buffer, wreq->debug_id,ITER_SOURCE ) <0 ) goto nomem;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1394/2077 cachefiles: Fix file burial to take lock when unsetting S_KERNEL_FILE
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 511a018ed2afd8d415edd307ce7ad2048506f6a1 ]
Fix cachefiles_bury_object() to lock the inode of the file being buried whilst it unsets the S_KERNEL_FILE flag.
--- fs/cachefiles/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cachefiles/namei.c +1 -1
@@ -374,7 +374,7 @@ int cachefiles_bury_object(struct cachefiles_cache *cache, "Rename failed with error %d", ret); } -__cachefiles_unmark_inode_in_use (object,d_inode (rep)); +cachefiles_do_unmark_inode_in_use (object,d_inode (rep));end_renaming (&rd);_leave (" = 0" );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1395/2077 netfs: Fix writethrough to use collection offload
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit ba6a9f6533c77c628eef0c0c5c19cd316e2be1b4 ]
Fix writethrough write to set NETFS_RREQ_OFFLOAD_COLLECTION on the request so that collection is processed asynchronously rather than only right at the end - and also so that asynchronous O_SYNC writes get collected at all.
--- fs/netfs/write_issue.c | 1 + 1 file changed, 1 insertion(+)
fs/netfs/write_issue.c +1 -0
@@ -628,6 +628,7 @@ struct netfs_io_request *netfs_begin_writethrough(struct kiocb *iocb, size_t len } wreq->io_streams[0 ].avail = true; +__set_bit (NETFS_RREQ_OFFLOAD_COLLECTION , &wreq->flags);trace_netfs_write (wreq, netfs_write_trace_writethrough);return wreq; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1396/2077 netfs: Fix writeback error handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit ac5f95ac5d6d0f4c567b8b642825705a2bf0d79e ]
Fix the error handling in writeback_iter() loop. If an error occurs, writeback_iter() needs to be called again with *error set to the error so that it can clean up iteration state. Further, the current folio needs unlocking and redirtying.
--- fs/netfs/write_issue.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/netfs/write_issue.c +8 -3
@@ -588,8 +588,6 @@ int netfs_writepages(struct address_space *mapping, } error =netfs_write_folio (wreq, wbc, folio); -if (error <0 ) -break ; }while ((folio =writeback_iter (mapping, wbc, folio, &error)));netfs_end_issue_write (wreq);
@@ -602,7 +600,14 @@ int netfs_writepages(struct address_space *mapping,return error; couldnt_start: -netfs_kill_dirty_pages (mapping, wbc, folio); +if (error == -ENOMEM ) { +folio_redirty_for_writepage (wbc, folio); +folio_unlock (folio); + folio =writeback_iter (mapping, wbc, folio, &error); +WARN_ON_ONCE (folio !=NULL ); + }else { +netfs_kill_dirty_pages (mapping, wbc, folio); + } out:mutex_unlock (&ictx->wb_lock);_leave (" = %d" , error);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1397/2077 netfs: Fix folio state after ENOMEM whilst under writeback iteration
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit b6a713fd34b9498ee2164d5d3e8460732a392efc ]
Fix the state of the current folio when ENOMEM occurs during writeback iteration. The folio needs to be redirtied and unlocked before the terminal writeback_iter() is invoked.
--- fs/netfs/write_issue.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/netfs/write_issue.c +4 -0
@@ -588,6 +588,10 @@ int netfs_writepages(struct address_space *mapping, } error =netfs_write_folio (wreq, wbc, folio); +if (error == -ENOMEM ) { +folio_redirty_for_writepage (wbc, folio); +folio_unlock (folio); + } }while ((folio =writeback_iter (mapping, wbc, folio, &error)));netfs_end_issue_write (wreq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1398/2077 drm/xe/pt: Fix NULL pointer dereference in xe_pt_zap_ptes_entry()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francois Dugast <[email protected]>
[ Upstream commit 3feeb667197bd58a17f4edfdbcad249ffcb3c864 ]
The page-table walk framework may pass a NULL *child pointer for unpopulated entries. xe_pt_zap_ptes_entry() called container_of(*child) before checking for NULL, then dereferenced the result, causing a crash.
Move the container_of() call after a NULL guard, so the function returns early instead of proceeding with an invalid pointer. XE_WARN_ON is kept to help root cause the issue, but we now bail instead of crashing the driver.
v2: Comment that triggering XE_WARN_ON is unexpected behavior (Matt Brost)
--- drivers/gpu/drm/xe/xe_pt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +10 -2
@@ -884,12 +884,20 @@ static int xe_pt_zap_ptes_entry(struct xe_ptw *parent, pgoff_t offset, {struct xe_pt_zap_ptes_walk *xe_walk =container_of (walk,typeof (*xe_walk), base); -struct xe_pt *xe_child =container_of (*child,typeof (*xe_child), base); +struct xe_pt *xe_child;pgoff_t end_offset; -XE_WARN_ON (!*child);XE_WARN_ON (!level); +/* +* Below would be unexpected behavior that needs to be root caused +* but better warn and bail than crash the driver. +*/ +if (XE_WARN_ON (!*child)) +return 0 ; + + xe_child =container_of (*child,typeof (*xe_child), base); +/* * Note that we're called from an entry callback, and we're dealing * with the child of that entry rather than the parent, so need to
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1399/2077 drm/imagination: Fix returned size for DRM_IOCTL_PVR_DEV_QUERY
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brajesh Gupta <[email protected]>
[ Upstream commit d431b4012fd22920523dbd2806da663c1048e386 ]
For a few subtypes of DRM_IOCTL_PVR_DEV_QUERY, driver was overriding the returned size unconditionally. This would have resulted in increase of reported size beyond the amount of data returned to userspace when args->size < size of query structure.
Updated behaviour matches with the description of drm_pvr_ioctl_dev_query_args.size and written byte length. None of the structures of DRM_IOCTL_PVR_DEV_QUERY changed after addition, so change will not break any compatibility with earlier version.
--- drivers/gpu/drm/imagination/pvr_drv.c | 6 ++++-- drivers/gpu/drm/imagination/pvr_vm.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/imagination/pvr_drv.c +4 -2
@@ -514,7 +514,8 @@ pvr_dev_query_quirks_get(struct pvr_device *pvr_dev,if (err <0 )return err; - args->size =sizeof (query); +if (args->size >sizeof (query)) + args->size =sizeof (query);return 0 ; }
@@ -595,7 +596,8 @@ pvr_dev_query_enhancements_get(struct pvr_device *pvr_dev,if (err <0 )return err; - args->size =sizeof (query); +if (args->size >sizeof (query)) + args->size =sizeof (query);return 0 ; }
drivers/gpu/drm/imagination/pvr_vm.c +4 -2
@@ -1019,7 +1019,8 @@ pvr_static_data_areas_get(const struct pvr_device *pvr_dev,if (err <0 )return err; - args->size =sizeof (query); +if (args->size >sizeof (query)) + args->size =sizeof (query);return 0 ; }
@@ -1069,7 +1070,8 @@ pvr_heap_info_get(const struct pvr_device *pvr_dev,if (err <0 )return err; - args->size =sizeof (query); +if (args->size >sizeof (query)) + args->size =sizeof (query);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1400/2077 drm/xe/userptr: Hold notifier_lock for write on inject test path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuicheng Lin <[email protected]>
[ Upstream commit dca6e08c923a44d2d66b955e03dd57a3a38c2b94 ]
When CONFIG_DRM_XE_USERPTR_INVAL_INJECT=y, xe_pt_svm_userptr_pre_commit() runs vma_check_userptr() with the svm notifier_lock taken for read. The test injection causes vma_check_userptr() to call xe_vma_userptr_force_invalidate(), which feeds into xe_vma_userptr_do_inval() with drm_gpusvm_ctx.in_notifier=true. That flag tells drm_gpusvm_unmap_pages() the caller already holds notifier_lock for write and only asserts the mode. Because the caller actually holds it for read, the assertion fires:
WARNING: drivers/gpu/drm/drm_gpusvm.c:1669 at \
drm_gpusvm_unmap_pages+0xd4/0x130 [drm_gpusvm_helper]
Call Trace:
xe_vma_userptr_do_inval+0x40d/0xfd0 [xe]
xe_vma_userptr_invalidate_pass1+0x3e6/0x8d0 [xe]
xe_vma_userptr_force_invalidate+0xde/0x290 [xe]
vma_check_userptr.constprop.0+0x1c6/0x220 [xe]
xe_pt_svm_userptr_pre_commit+0x6a3/0xc60 [xe]
...
xe_vm_bind_ioctl+0x3a0a/0x4480 [xe]Acquire notifier_lock for write in pre-commit when the inject Kconfig is enabled, via new helpers xe_pt_svm_userptr_notifier_lock()/_unlock(). Rename xe_svm_assert_held_read() to xe_svm_assert_held_read_or_inject_write() so it asserts the correct mode under each build configuration. Production builds (CONFIG_DRM_XE_USERPTR_INVAL_INJECT=n) keep the existing read-mode behavior bit-for-bit.
--- drivers/gpu/drm/xe/xe_pt.c | 43 ++++++++++++++++++++++++++++++------- drivers/gpu/drm/xe/xe_svm.h | 15 +++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +35 -8
@@ -1085,7 +1085,7 @@ static void xe_pt_commit_locks_assert(struct xe_vma *vma)xe_pt_commit_prepare_locks_assert (vma);if (xe_vma_is_userptr (vma)) -xe_svm_assert_held_read (vm); +xe_svm_assert_held_read_or_inject_write (vm); } static void xe_pt_commit(struct xe_vma *vma,
@@ -1405,6 +1405,33 @@ static int xe_pt_pre_commit(struct xe_migrate_pt_update *pt_update) pt_update_ops, rftree); } +/* +* Acquire/release the svm notifier_lock around xe_pt_svm_userptr_pre_commit() +* and the matching late release in xe_pt_update_ops_run(). Read mode by +* default; write mode when CONFIG_DRM_XE_USERPTR_INVAL_INJECT is on, +* because a userptr op in this critical section may invoke the injected +* xe_vma_userptr_force_invalidate() path that calls +* drm_gpusvm_unmap_pages() with ctx->in_notifier=true, which requires the +* lock held for write. +*/ +static void xe_pt_svm_userptr_notifier_lock (struct xe_vm *vm) +{ +#if IS_ENABLED (CONFIG_DRM_XE_USERPTR_INVAL_INJECT ) +down_write (&vm->svm.gpusvm.notifier_lock); +#else +xe_svm_notifier_lock (vm); +#endif +} + +static void xe_pt_svm_userptr_notifier_unlock (struct xe_vm *vm) +{ +#if IS_ENABLED (CONFIG_DRM_XE_USERPTR_INVAL_INJECT ) +up_write (&vm->svm.gpusvm.notifier_lock); +#else +xe_svm_notifier_unlock (vm); +#endif +} +#if IS_ENABLED (CONFIG_DRM_GPUSVM )#ifdef CONFIG_DRM_XE_USERPTR_INVAL_INJECT
@@ -1436,7 +1463,7 @@ static int vma_check_userptr(struct xe_vm *vm, struct xe_vma *vma,struct xe_userptr_vma *uvma;unsigned long notifier_seq; -xe_svm_assert_held_read (vm); +xe_svm_assert_held_read_or_inject_write (vm);if (!xe_vma_is_userptr (vma))return 0 ;
@@ -1466,7 +1493,7 @@ static int op_check_svm_userptr(struct xe_vm *vm, struct xe_vma_op *op, {int err =0 ; -xe_svm_assert_held_read (vm); +xe_svm_assert_held_read_or_inject_write (vm);switch (op->base.op) {case DRM_GPUVA_OP_MAP :
@@ -1538,12 +1565,12 @@ static int xe_pt_svm_userptr_pre_commit(struct xe_migrate_pt_update *pt_update)if (err)return err; -xe_svm_notifier_lock (vm); +xe_pt_svm_userptr_notifier_lock (vm);list_for_each_entry (op, &vops->list, link) { err =op_check_svm_userptr (vm, op, pt_update_ops);if (err) { -xe_svm_notifier_unlock (vm); +xe_pt_svm_userptr_notifier_unlock (vm);break ; } }
@@ -2379,7 +2406,7 @@ static void bind_op_commit(struct xe_vm *vm, struct xe_tile *tile, vma->tile_invalidated & ~BIT(tile->id)); vma->tile_staged &= ~BIT (tile->id);if (xe_vma_is_userptr (vma)) { -xe_svm_assert_held_read (vm); +xe_svm_assert_held_read_or_inject_write (vm);to_userptr_vma (vma)->userptr.initial_bind = true; }
@@ -2415,7 +2442,7 @@ static void unbind_op_commit(struct xe_vm *vm, struct xe_tile *tile,if (!vma->tile_present) {list_del_init (&vma->combined_links.rebind);if (xe_vma_is_userptr (vma)) { -xe_svm_assert_held_read (vm); +xe_svm_assert_held_read_or_inject_write (vm);spin_lock (&vm->userptr.invalidated_lock);list_del_init (&to_userptr_vma (vma)->userptr.invalidate_link);
@@ -2691,7 +2718,7 @@ xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops) }if (pt_update_ops->needs_svm_lock) -xe_svm_notifier_unlock (vm); +xe_pt_svm_userptr_notifier_unlock (vm);/* * The last fence is only used for zero bind queue idling; migrate
drivers/gpu/drm/xe/xe_svm.h +13 -2
@@ -394,8 +394,19 @@ static inline struct drm_pagemap *xe_drm_pagemap_from_fd(int fd, u32 region_inst#define xe_svm_assert_in_notifier (vm__) \ lockdep_assert_held_write(&(vm__)->svm.gpusvm.notifier_lock) -#define xe_svm_assert_held_read (vm__) \ +/* +* Assert the svm notifier_lock is held. Read mode by default; write mode +* when CONFIG_DRM_XE_USERPTR_INVAL_INJECT is on, because that path forces +* a userptr invalidation that ends in drm_gpusvm_unmap_pages() with +* ctx->in_notifier=true, which requires the lock held for write. +*/ +#if IS_ENABLED (CONFIG_DRM_XE_USERPTR_INVAL_INJECT ) +#define xe_svm_assert_held_read_or_inject_write (vm__) \ + lockdep_assert_held_write(&(vm__)->svm.gpusvm.notifier_lock) +#else +#define xe_svm_assert_held_read_or_inject_write (vm__) \ lockdep_assert_held_read(&(vm__)->svm.gpusvm.notifier_lock) +#endif #define xe_svm_notifier_lock (vm__) \ drm_gpusvm_notifier_lock(&(vm__)->svm.gpusvm)
@@ -409,7 +420,7 @@ static inline struct drm_pagemap *xe_drm_pagemap_from_fd(int fd, u32 region_inst#else #define xe_svm_assert_in_notifier (...) do {} while (0) -static inline void xe_svm_assert_held_read (struct xe_vm *vm) +static inline void xe_svm_assert_held_read_or_inject_write (struct xe_vm *vm) { }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1401/2077 drm/xe/userptr: Drop bogus static from finish in force_invalidate
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuicheng Lin <[email protected]>
[ Upstream commit 0c56ea482aab1470b96a525ef53fa3eb8704f9a6 ]
The local "finish" pointer in xe_vma_userptr_force_invalidate() is unconditionally written before each read, so the static storage class serves no purpose. Worse, it makes the variable a process-wide shared
slot: the function's per-VM asserts do not exclude concurrent callers on different VMs, so two such callers can race on the slot and take the wrong if (finish) branch.
The function is gated by CONFIG_DRM_XE_USERPTR_INVAL_INJECT (developer/test option, default n), so production builds are unaffected.
Drop the static.
--- drivers/gpu/drm/xe/xe_userptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_userptr.c +1 -1
@@ -269,7 +269,7 @@ static const struct mmu_interval_notifier_ops vma_userptr_notifier_ops = {*/ void xe_vma_userptr_force_invalidate (struct xe_userptr_vma *uvma) { -static struct mmu_interval_notifier_finish *finish; +struct mmu_interval_notifier_finish *finish;struct xe_vm *vm =xe_vma_vm (&uvma->vma);/* Protect against concurrent userptr pinning */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1402/2077 drm/xe/hw_engine: Fix double-free of managed BO in error path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuicheng Lin <[email protected]>
[ Upstream commit 7ac3cae7a251d28e9079de07a991bd4eb2bb7fd8 ]
The error path in hw_engine_init() explicitly frees a BO allocated with xe_managed_bo_create_pin_map() via xe_bo_unpin_map_no_vm(). Since the managed BO already has a devm cleanup action registered, this causes a double-free when devm unwinds during probe failure.
Remove the explicit free and let devm handle it, consistent with all other xe_managed_bo_create_pin_map() callers.
--- drivers/gpu/drm/xe/xe_hw_engine.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_hw_engine.c +1 -3
@@ -629,7 +629,7 @@ static int hw_engine_init(struct xe_gt *gt, struct xe_hw_engine *hwe, hwe->exl_port =xe_execlist_port_create (xe, hwe);if (IS_ERR (hwe->exl_port)) { err =PTR_ERR (hwe->exl_port); - goto err_hwsp; + goto err_name; } }else {/* GSCCS has a special interrupt for reset */
@@ -649,8 +649,6 @@ static int hw_engine_init(struct xe_gt *gt, struct xe_hw_engine *hwe,return devm_add_action_or_reset (xe->drm.dev, hw_engine_fini, hwe); -err_hwsp: -xe_bo_unpin_map_no_vm (hwe->hwsp); err_name: hwe->name =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1403/2077 drm/xe/pf: Dont attempt to process FAST_REQ or EVENT relays
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Wajdeczko <[email protected]>
[ Upstream commit ed8b0d731892c68b41ecbd27c952af284816dec1 ]
Currently defined VF/PF relay actions use regular REQUEST messages only and the PF shouldn't attempt to handle FAST_REQUEST nor EVENT messages as this would result in breaking the VFPF ABI protocol and also might trigger an assert on the PF side.
--- drivers/gpu/drm/xe/xe_guc_relay.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_guc_relay.c +9 -4
@@ -689,12 +689,17 @@ static int relay_action_handler(struct xe_guc_relay *relay, u32 origin,return relay_testloop_action_handler (relay, origin, msg, len, response, size); type =FIELD_GET (GUC_HXG_MSG_0_TYPE , msg[0 ]); +relay_assert (relay,guc_hxg_type_is_action (type)); -if (IS_SRIOV_PF (relay_to_xe (relay))) - ret =xe_gt_sriov_pf_service_process_request (gt, origin, msg, len, response, size); -else +if (IS_SRIOV_PF (relay_to_xe (relay))) { +if (type ==GUC_HXG_TYPE_REQUEST ) + ret =xe_gt_sriov_pf_service_process_request (gt, origin, msg, len, + response, size); +else + ret = -EOPNOTSUPP ; + }else { ret = -EOPNOTSUPP ; - + }if (type ==GUC_HXG_TYPE_EVENT )relay_assert (relay, ret <=0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1404/2077 drm/xe: fix NPD in bo_meminfo()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Auld <[email protected]>
[ Upstream commit b5c55015d4164a0f206bcdcf2985da948b3c7837 ]
When a buffer object is purged, its ttm.resource is set to NULL via the TTM pipeline gutting flow. However, the BO remains in the client's object list until userspace explicitly closes the GEM handle. If memory stats are queried during this time, accessing bo->ttm.resource->mem_type will result in a NULL pointer dereference.
Fix this by safely skipping purged BOs in bo_meminfo, as they no longer consume any memory.
User is getting NPD on device resume, and possible theory is that in bo_move(), if we need to evict something to SYSTEM to save the CCS state, but the BO is marked as dontneed, this won't trigger a move but will nuke the pages, leaving us with a NULL bo resource. And the meminfo() doesn't look ready to handle a NULL resource.
v2 (Sashiko):
- There could potentially be other cases where we might end up with a NULL resource, so make this a general NULL check for now.
--- drivers/gpu/drm/xe/xe_drm_client.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_drm_client.c +11 -1
@@ -168,10 +168,20 @@ static void bo_meminfo(struct xe_bo *bo, struct drm_memory_stats stats[TTM_NUM_MEM_TYPES]) {u64 sz =xe_bo_size (bo); -u32 mem_type = bo->ttm.resource->mem_type; +u32 mem_type;xe_bo_assert_held (bo); +/* +* The resource can be NULL if the BO has been purged, plus maybe some +* other cases. Either way there shouldn't be any memory to account for, +* or a current resource to account this against, so skip for now. +*/ +if (!bo->ttm.resource) +return ; + + mem_type = bo->ttm.resource->mem_type; +if (drm_gem_object_is_shared_for_memory_stats (&bo->ttm.base)) stats[mem_type].shared += sz;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1405/2077 drm/xe/pt: prevent invalid cursor access for purged BOs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Auld <[email protected]>
[ Upstream commit 8a0fb57675be578c4db19deb4298ed08a70f0f1a ]
During a page table walk for binding, xe_pt_stage_bind() explicitly skips initializing the xe_res_cursor for purged BOs, treating them similarly to NULL VMAs by only setting the cursor size.
However, xe_pt_hugepte_possible() and xe_pt_scan_64K() did not check if the BO was purged before attempting to walk the cursor using xe_res_dma() and xe_res_next(). Because the cursor was left uninitialized for purged BOs, this falls through and triggers warnings like:
WARNING: drivers/gpu/drm/xe/xe_res_cursor.h:274 at xe_res_next
Fix this by explicitly checking if the BO is purged in both xe_pt_hugepte_possible() and xe_pt_scan_64K(), returning early just as we do for NULL VMAs, avoiding the invalid cursor accesses entirely.
As a precaution, also zero-initialize the cursor in xe_pt_stage_bind() to ensure we don't pass garbage data into the page table walkers if we ever hit a similar edge case in the future.
--- drivers/gpu/drm/xe/xe_pt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +7 -5
@@ -432,6 +432,7 @@ xe_pt_insert_entry(struct xe_pt_stage_bind_walk *xe_walk, struct xe_pt *parent,static bool xe_pt_hugepte_possible (u64 addr,u64 next,unsigned int level,struct xe_pt_stage_bind_walk *xe_walk) { +struct xe_bo *bo =xe_vma_bo (xe_walk->vma);u64 size, dma;if (level >MAX_HUGEPTE_LEVEL )
@@ -445,8 +446,8 @@ static bool xe_pt_hugepte_possible(u64 addr, u64 next, unsigned int level,if (next - xe_walk->va_curs_start > xe_walk->curs->size)return false; -/* null VMA's do not have dma addresses */ -if (xe_vma_is_null (xe_walk->vma)) +/* null VMA's and purged BO's do not have dma addresses */ +if (xe_vma_is_null (xe_walk->vma) || (bo &&xe_bo_is_purged (bo)))return true;/* if we are clearing page table, no dma addresses*/
@@ -467,6 +468,7 @@ static bool xe_pt_hugepte_possible(u64 addr, u64 next, unsigned int level,static bool xe_pt_scan_64K (u64 addr,u64 next,struct xe_pt_stage_bind_walk *xe_walk) { +struct xe_bo *bo =xe_vma_bo (xe_walk->vma);struct xe_res_cursor curs = *xe_walk->curs;if (!IS_ALIGNED (addr,SZ_64K ))
@@ -475,8 +477,8 @@ xe_pt_scan_64K(u64 addr, u64 next, struct xe_pt_stage_bind_walk *xe_walk)if (next > xe_walk->l0_end_addr)return false; -/* null VMA's do not have dma addresses */ -if (xe_vma_is_null (xe_walk->vma)) +/* null VMA's and purged BO's do not have dma addresses */ +if (xe_vma_is_null (xe_walk->vma) || (bo &&xe_bo_is_purged (bo)))return true;xe_res_next (&curs, addr - xe_walk->va_curs_start);
@@ -707,7 +709,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, {struct xe_device *xe =tile_to_xe (tile);struct xe_bo *bo =xe_vma_bo (vma); -struct xe_res_cursor curs; +struct xe_res_cursor curs = {};struct xe_vm *vm =xe_vma_vm (vma);struct xe_pt_stage_bind_walk xe_walk = { .base = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1406/2077 x86/uprobes: Keep shadow stack in sync for emulated CALLs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Windsor <[email protected]>
[ Upstream commit abf08854d224085e2ebb3ba660e7995909f47d6a ]
Uprobe CALL emulation updates the normal user stack, but not the CET user shadow stack. The subsequent RET then sees a stale shadow stack entry and raises #CP.
Update the relative CALL emulation and XOL CALL fixup paths to keep the shadow stack in sync.
--- arch/x86/kernel/uprobes.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/x86/kernel/uprobes.c +11 -1
@@ -1246,9 +1246,15 @@ static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regslong correction = utask->vaddr - utask->xol_vaddr; regs->ip += correction; }else if (auprobe->defparam.fixups &UPROBE_FIX_CALL ) { +unsigned long retaddr = utask->vaddr + auprobe->defparam.ilen; +int err; + regs->sp +=sizeof_long (regs);/* Pop incorrect return address */ -if (emulate_push_stack (regs, utask->vaddr + auprobe->defparam.ilen)) +if (emulate_push_stack (regs, retaddr))return -ERESTART ; + err =shstk_update_last_frame (retaddr); +if (err) +return err; }/* popf; tell the caller to not touch TF */ if (auprobe->defparam.fixups &UPROBE_FIX_SETF )
@@ -1338,6 +1344,10 @@ static bool branch_emulate_op(struct arch_uprobe *auprobe, struct pt_regs *regs)*/ if (emulate_push_stack (regs, new_ip))return false; +if (shstk_push (new_ip) == -EFAULT ) { + regs->sp +=sizeof_long (regs); +return false; + } }else if (!check_jmp_cond (auprobe, regs)) { offs =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1407/2077 uprobes/x86: Use proper mm_struct in __in_uprobe_trampoline
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Olsa <[email protected]>
[ Upstream commit 169328645663bae30e9abad4012d52441e085a71 ]
In the unregister path we use __in_uprobe_trampoline check with current->mm for the VMA lookup, which is wrong, because we are in the tracer context, not the traced process.
Add mm_struct pointer argument to __in_uprobe_trampoline and changing related callers to pass proper mm_struct pointer.
--- arch/x86/kernel/uprobes.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/x86/kernel/uprobes.c +7 -7
@@ -761,9 +761,9 @@ void arch_uprobe_clear_state(struct mm_struct *mm)destroy_uprobe_trampoline (tramp); } -static bool __in_uprobe_trampoline (unsigned long ip) +static bool __in_uprobe_trampoline (struct mm_struct *mm,unsigned long ip) { -struct vm_area_struct *vma =vma_lookup (current->mm, ip); +struct vm_area_struct *vma =vma_lookup (mm, ip);return vma &&vma_is_special_mapping (vma, &tramp_mapping); }
@@ -776,14 +776,14 @@ static bool in_uprobe_trampoline(unsigned long ip)rcu_read_lock ();if (mmap_lock_speculate_try_begin (mm, &seq)) { - found =__in_uprobe_trampoline (ip); + found =__in_uprobe_trampoline (mm, ip); retry =mmap_lock_speculate_retry (mm, seq); }rcu_read_unlock ();if (retry) {mmap_read_lock (mm); - found =__in_uprobe_trampoline (ip); + found =__in_uprobe_trampoline (mm, ip);mmap_read_unlock (mm); }return found;
@@ -1044,7 +1044,7 @@ static int copy_from_vaddr(struct mm_struct *mm, unsigned long vaddr, void *dst,return 0 ; } -static bool __is_optimized (uprobe_opcode_t *insn,unsigned long vaddr) +static bool __is_optimized (struct mm_struct *mm,uprobe_opcode_t *insn,unsigned long vaddr) {struct __packed __arch_relative_insn {u8 op;
@@ -1053,7 +1053,7 @@ static bool __is_optimized(uprobe_opcode_t *insn, unsigned long vaddr)if (!is_call_insn (insn))return false; -return __in_uprobe_trampoline (vaddr +5 + call->raddr); +return __in_uprobe_trampoline (mm, vaddr +5 + call->raddr); }static int is_optimized (struct mm_struct *mm,unsigned long vaddr)
@@ -1064,7 +1064,7 @@ static int is_optimized(struct mm_struct *mm, unsigned long vaddr) err =copy_from_vaddr (mm, vaddr, &insn,5 );if (err)return err; -return __is_optimized ((uprobe_opcode_t *)&insn, vaddr); +return __is_optimized (mm, (uprobe_opcode_t *)&insn, vaddr); }static bool should_optimize (struct arch_uprobe *auprobe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1408/2077 cifs: Fix missing credit release on failure in cifs_issue_read()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit c16b8c4cfb4fe2244cc33e469a93c1ab8684146b ]
Fix missing release of credits in the failure path in cifs_issue_read() lest retrying the subreq just overwrites the credits value.
--- fs/smb/client/file.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/file.c +1 -0
@@ -241,6 +241,7 @@ static void cifs_issue_read(struct netfs_io_subrequest *subreq)return ; failed: +add_credits_and_wake_if (rdata->server, &rdata->credits,0 ); subreq->error = rc;netfs_read_subreq_terminated (subreq); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1409/2077 ata: sata_gemini: unwind clocks on IDE pinctrl errors
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit c0ace4130e813acbabdfaa28d4e94a849c2ffdd7 ]
gemini_sata_bridge_init() prepares and enables both SATA PCLKs, then disables them again while keeping the clocks prepared for later bridge start and stop operations. If gemini_setup_ide_pins() fails after that, gemini_sata_probe() returns directly and skips the existing out_unprep_clk unwind path.
Route the IDE pinctrl failure through out_unprep_clk so the clocks prepared by gemini_sata_bridge_init() are unprepared before probe fails.
--- drivers/ata/sata_gemini.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/sata_gemini.c +1 -1
@@ -353,7 +353,7 @@ static int gemini_sata_probe(struct platform_device *pdev)if (sg->ide_pins) { ret =gemini_setup_ide_pins (dev);if (ret) -return ret; + goto out_unprep_clk; }dev_info (dev,"set up the Gemini IDE/SATA nexus\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1410/2077 ata: libata-scsi: limit simulated SCSI command copy to response length
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karuna Ramkumar <[email protected]>
[ Upstream commit cd64be0ecd399fa2b1ab60b3aaf2b2b744243467 ]
The function ata_scsi_rbuf_fill() is used to copy the response of emulated SCSI commands from ata_scsi_rbuf to the SCSI command's scatterlist.
Currently, sg_copy_from_buffer() is called with the size argument set to ATA_SCSI_RBUF_SIZE (2048 bytes). Since ata_scsi_rbuf is zeroed out before the simulation actor is invoked, copying the full buffer size causes the remainder of the SCSI command's transfer buffer (beyond the actual response length 'len') to be overwritten with zeroes. This clobbers any pre-existing sentinel values or data in the caller's buffer tail, even though the correct residual count is reported via scsi_set_resid().
Fix this by passing the actual response length 'len' as the copy size to sg_copy_from_buffer(), ensuring that the tail of the caller's buffer remains untouched. Also, add a defensive check to ensure that the actor does not return a length exceeding the static buffer capacity. If this occurs, trigger a WARN_ON(), fail the command with an aborted command error, and return immediately without copying any data.
The fix was tested by invoking an SCSI SG_IO INQUIRY on an ATA disk on vanilla build, and build with the fix. Confirmed that the input buffer's tail end remains unmodified with the fix.
--- drivers/ata/libata-scsi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/ata/libata-scsi.c +6 -1
@@ -1931,8 +1931,13 @@ static void ata_scsi_rbuf_fill(struct ata_device *dev, struct scsi_cmnd *cmd,memset (ata_scsi_rbuf,0 ,ATA_SCSI_RBUF_SIZE ); len =actor (dev, cmd, ata_scsi_rbuf);if (len) { +if (WARN_ON (len >ATA_SCSI_RBUF_SIZE )) { +ata_scsi_set_sense (dev, cmd,ABORTED_COMMAND ,0 ,0 ); +spin_unlock_irqrestore (&ata_scsi_rbuf_lock, flags); +return ; + }sg_copy_from_buffer (scsi_sglist (cmd),scsi_sg_count (cmd), - ata_scsi_rbuf,ATA_SCSI_RBUF_SIZE ); + ata_scsi_rbuf, len); cmd->result =SAM_STAT_GOOD ;if (scsi_bufflen (cmd) > len)scsi_set_resid (cmd,scsi_bufflen (cmd) - len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1411/2077 netfs: Fix barriering when walking subrequest list
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 5c6ce05e406520290c1d89da97fb3cd70c09137d ]
Fix the barriering used when walking the subrequest list in retry as there's a possibility of seeing a subreq that's just been added by the application thread.
--- fs/netfs/read_retry.c | 7 ++++++- fs/netfs/write_retry.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-)
fs/netfs/read_retry.c +6 -1
@@ -98,7 +98,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) goto abandon; } -list_for_each_continue (next, &stream->subrequests) { +for (;;) { +/* Read pointer to subreq before reading subreq state. */ + next =smp_load_acquire (&next->next); +if (next == &stream->subrequests) +break ; + subreq = list_entry(next, struct netfs_io_subrequest, rreq_link); if (subreq->start + subreq->transferred != start + len || test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
fs/netfs/write_retry.c +6 -1
@@ -72,7 +72,12 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq, !test_bit(NETFS_SREQ_NEED_RETRY, &from->flags)) return; -list_for_each_continue (next, &stream->subrequests) { +for (;;) { +/* Read pointer to subreq before reading subreq state. */ + next =smp_load_acquire (&next->next); +if (next == &stream->subrequests) +break ; + subreq = list_entry(next, struct netfs_io_subrequest, rreq_link); if (subreq->start + subreq->transferred != start + len || test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1412/2077 ntfs: avoid stale runlist element dereference in MFT writeback
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 81fe702ff1760da32bcd3ef4494b2a33dbeced72 ]
ntfs_write_mft_block() maps each $MFT record through the $MFT data runlist. For sub-folio clusters it looks up a struct runlist_element under ni->runlist.lock, drops the lock, and later uses rl->length and rl->vcn when choosing folio_sz.
That pointer is only borrowed from ni->runlist.rl. Concurrent $MFT allocation extension can merge a replacement runlist under the same lock, and ntfs_rl_realloc() can free the old backing array. If that happens between the lookup and the later folio_sz decision, writeback can dereference freed runlist storage.
The buggy scenario involves two paths, with each column showing the order within that path:
MFT writeback path: $MFT allocation extension: 1. Look up rl under 1. Extend the $MFT data allocation. ni->runlist.lock. 2. Publish a replacement runlist. 2. Drop ni->runlist.lock. 3. Free the old runlist array.
3. Read rl->length and rl->vcn
to choose folio_sz.
Compute the remaining run length while ni->runlist.lock is still held, and use that scalar after unlock. This preserves the existing folio sizing decision without carrying a borrowed runlist_element across the lock boundary.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in ntfs_mft_writepages+0x1c8d/0x1fb0 Call Trace: <TASK> dump_stack_lvl+0x66/0xa0 print_report+0xce/0x630 ? ntfs_mft_writepages+0x1c8d/0x1fb0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? ntfs_mft_writepages+0x1c8d/0x1fb0 kasan_report+0xe0/0x110 ? ntfs_mft_writepages+0x1c8d/0x1fb0 ntfs_mft_writepages+0x1c8d/0x1fb0 ? __pfx_ntfs_mft_writepages+0x10/0x10 ? __pfx___mutex_unlock_slowpath+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? iput+0x92/0xa80 do_writepages+0x219/0x530 ? __pfx_do_writepages+0x10/0x10 __writeback_single_inode+0x117/0xf50 ? do_raw_spin_lock+0x130/0x270 ? __pfx_do_raw_spin_lock+0x10/0x10 ? __pfx___writeback_single_inode+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 writeback_sb_inodes+0x65b/0x1810 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_acquire+0x2b8/0x2f0 ? __pfx_writeback_sb_inodes+0x10/0x10 ? lock_release+0x1e0/0x280 ? _raw_spin_unlock+0x23/0x40 ? move_expired_inodes+0x2b8/0x850 __writeback_inodes_wb+0xf4/0x270 ? __pfx___writeback_inodes_wb+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? queue_io+0x2e4/0x410 wb_writeback+0x666/0x880 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_wb_writeback+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? get_nr_dirty_inodes+0x1c/0x170 wb_workfn+0x75e/0xbb0 ? srso_alias_return_thunk+0x5/0xfbef5 ? _raw_spin_unlock_irqrestore+0x27/0x60 ? __pfx_wb_workfn+0x10/0x10 ? __pfx_debug_object_deactivate+0x10/0x10 ? lock_acquire+0x2b8/0x2f0 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0x1e0/0x280 process_one_work+0x8d0/0x1870 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x575/0xf80 ? __pfx_worker_thread+0x10/0x10 kthread+0x2e7/0x3c0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x576/0x810 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x57e/0xe10 ? __switch_to_asm+0x33/0x70 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 970: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kvmalloc_node_noprof+0x353/0x920 ntfs_rl_realloc+0x3c/0x80 ntfs_runlists_merge+0x1212/0x3010 ntfs_mft_data_extend_allocation_nolock+0x3e0/0x1f40 ntfs_mft_record_alloc+0x1ab4/0x4f10 __ntfs_create+0x680/0x2e50 ntfs_create+0x1e6/0x3a0 path_openat+0x2b55/0x3c10 do_file_open+0x1f4/0x460 do_sys_openat2+0xde/0x170 __x64_sys_openat+0x122/0x1e0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 1294: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 ntfs_rl_realloc+0x66/0x80 ntfs_runlists_merge+0x1212/0x3010 ntfs_mft_data_extend_allocation_nolock+0x3e0/0x1f40 ntfs_mft_record_alloc+0x1ab4/0x4f10 __ntfs_create+0x680/0x2e50 ntfs_create+0x1e6/0x3a0 path_openat+0x2b55/0x3c10 do_file_open+0x1f4/0x460 do_sys_openat2+0xde/0x170 __x64_sys_openat+0x122/0x1e0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
--- fs/ntfs/mft.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/ntfs/mft.c +6 -2
@@ -2745,7 +2745,6 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *ws64 vcn =ntfs_pidx_to_cluster (vol, folio->index);s64 end_vcn =ntfs_bytes_to_cluster (vol, ni->allocated_size);unsigned int folio_sz; -struct runlist_element *rl =NULL ;loff_t i_size =i_size_read (vi); ntfs_debug("Entering for inode 0x%llx, attribute type 0x%x, folio index 0x%lx.",
@@ -2790,6 +2789,7 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w &tni, &ref_inos[nr_ref_inos])) {unsigned int mft_record_off =0 ;s64 vcn_off = vcn; +s64 rl_len =0 ;/* * Skip $MFT extent mft records and let them being written
@@ -2822,8 +2822,12 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w }if (vol->cluster_size <folio_size (folio)) { +struct runlist_element *rl; +down_write (&ni->runlist.lock); rl =ntfs_attr_vcn_to_rl (ni, vcn_off, &lcn); +if (!IS_ERR (rl)) + rl_len = rl->length - (vcn_off - rl->vcn);up_write (&ni->runlist.lock);if (IS_ERR (rl) || lcn <0 ) { err = -EIO ;
@@ -2854,7 +2858,7 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *wif (vol->cluster_size ==NTFS_BLOCK_SIZE && (mft_record_off || - (rl && rl->length - (vcn_off - rl->vcn) ==1 ) || + rl_len ==1 || mft_ofs +NTFS_BLOCK_SIZE >=PAGE_SIZE )) folio_sz =NTFS_BLOCK_SIZE ;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1413/2077 HID: picolcd: prevent NULL pointer dereference in picolcd_send_and_wait()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgiy Osokin <[email protected]>
[ Upstream commit 0021eb09041f021c079be1022934a280f7f176c0 ]
In picolcd_send_and_wait(), an integer overflow of the signed loop counter 'k' can theoretically lead to a NULL pointer dereference of 'raw_data'. If the loop executes more than INT_MAX times, 'k' becomes negative, making the condition 'k < size' true even when 'size' is 0.
Change the type of 'k' to 'unsigned int' to prevent the overflow and eliminate the out-of-bounds access.
Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.
--- drivers/hid/hid-picolcd_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-picolcd_core.c +2 -1
@@ -72,7 +72,8 @@ struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,struct picolcd_pending *work;struct hid_report *report =picolcd_out_report (report_id, hdev);unsigned long flags; -int i, j, k; +int i, j; +unsigned int k;if (!report || !data)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1414/2077 HID: core: Fix OOB read in hid_get_report for numbered reports
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit af1a9b65ebe8a948eda805c14b78d4d0767cb1b5 ]
When a caller passes a size of 0 to hid_report_raw_event() for a numbered report, the function originally called hid_get_report() before performing any size validation.
Inside hid_get_report(), if the report is numbered (report_enum->numbered is true), it unconditionally dereferences data[0] to extract the report ID. With a size of 0, this results in an out-of-bounds read or kernel panic.
Fix this by moving the numbered report size validation check before the call to hid_get_report(), ensuring that size is at least 1 before dereferencing the data pointer.
--- drivers/hid/hid-core.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hid/hid-core.c +7 -0
@@ -2045,6 +2045,13 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *u8 *cdata = data;int ret =0 ; +if (report_enum->numbered && (size <1 || bufsize <1 )) { +hid_warn_ratelimited (hid, +"Event data for numbered report is too short (%d vs %zu)\n" , + size, bufsize); +return -EINVAL ; + } + report =hid_get_report (report_enum, data);if (!report)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1415/2077 arm64: Avoid eager DVMSync reclaim batches with C1-Pro SME erratum
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
[ Upstream commit 534eb6940a89ff7ca3f2ab6582f3548ca97674c3 ]
The C1-Pro SME DVMSync workaround currently samples mm_cpumask() from arch_tlbbatch_add_pending(). It requires a DSB after every batched TLBI so that the mask read is ordered after the hardware DVMSync, defeating much of the reclaim batching benefit.
Introduce the sme_active_cpus mask tracking which CPUs run in user-space with SME enabled and use it for batch flushing instead of accumulating the mm_cpumask() of the unmapped pages.
--- arch/arm64/include/asm/tlbbatch.h | 10 ++----- arch/arm64/include/asm/tlbflush.h | 49 +++++-------------------------- arch/arm64/kernel/fpsimd.c | 10 +++++-- arch/arm64/kernel/process.c | 35 ---------------------- 4 files changed, 17 insertions(+), 87 deletions(-)
arch/arm64/include/asm/tlbbatch.h +2 -8
@@ -2,17 +2,11 @@#ifndef _ARCH_ARM64_TLBBATCH_H#define _ARCH_ARM64_TLBBATCH_H -#include <linux/cpumask.h> -struct arch_tlbflush_unmap_batch { -#ifdef CONFIG_ARM64_ERRATUM_4193714 /* -* Track CPUs that need SME DVMSync on completion of this batch. -* Otherwise, the arm64 HW can do tlb shootdown, so we don't need to -* record cpumask for sending IPI +* For arm64, HW can do TLB shootdown, so we don't need to record a +* cpumask for sending IPIs. */ -cpumask_var_t cpumask; -#endif };#endif /* _ARCH_ARM64_TLBBATCH_H */
arch/arm64/include/asm/tlbflush.h +8 -41
92 lines not on this page · raw message
arch/arm64/kernel/fpsimd.c +7 -3
@@ -1366,6 +1366,7 @@ void do_sve_acc(unsigned long esr, struct pt_regs *regs)* SME/CME erratum handling. */ static cpumask_t sme_dvmsync_cpus; +cpumask_t sme_active_cpus;/* * These helpers are only called from non-preemptible contexts, so
@@ -1379,13 +1380,15 @@ void sme_set_active(void)return ;cpumask_set_cpu (cpu,mm_cpumask (current->mm)); +cpumask_set_cpu (cpu, &sme_active_cpus);/* * A subsequent (post ERET) SME access may use a stale address * translation. On C1-Pro, a TLBI+DSB on a different CPU will wait for -* the completion of cpumask_set_cpu() above as it appears in program -* order before the SME access. The post-TLBI+DSB read of mm_cpumask() -* will lead to the IPI being issued. +* the completion of the cpumask_set_cpu() operations above as they +* appear in program order before the SME access. The post-TLBI+DSB +* read of mm_cpumask() or sme_active_cpus will lead to the IPI being +* issued. * * https://lore.kernel.org/r/ablEXwhfKyJW1i7l@J2N7QTR9R3 */
@@ -1403,6 +1406,7 @@ void sme_clear_active(void)* completed on entering EL1. */ cpumask_clear_cpu (cpu,mm_cpumask (current->mm)); +cpumask_clear_cpu (cpu, &sme_active_cpus); }static void sme_dvmsync_ipi (void *unused)
arch/arm64/kernel/process.c +0 -35
@@ -341,41 +341,8 @@ void flush_thread(void)flush_gcs (); } -#ifdef CONFIG_ARM64_ERRATUM_4193714 - -static void arch_dup_tlbbatch_mask (struct task_struct *dst) -{ -/* -* Clear the inherited cpumask with memset() to cover both cases where -* cpumask_var_t is a pointer or an array. It will be allocated lazily -* in sme_dvmsync_add_pending() if CPUMASK_OFFSTACK=y. -*/ -if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) -memset (&dst->tlb_ubc.arch.cpumask,0 , -sizeof (dst->tlb_ubc.arch.cpumask)); -} - -static void arch_release_tlbbatch_mask (struct task_struct *tsk) -{ -if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) -free_cpumask_var (tsk->tlb_ubc.arch.cpumask); -} - -#else - -static void arch_dup_tlbbatch_mask (struct task_struct *dst) -{ -} - -static void arch_release_tlbbatch_mask (struct task_struct *tsk) -{ -} - -#endif /* CONFIG_ARM64_ERRATUM_4193714 */ -void arch_release_task_struct (struct task_struct *tsk) { -arch_release_tlbbatch_mask (tsk);fpsimd_release_task (tsk); }
@@ -391,8 +358,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) *dst = *src; -arch_dup_tlbbatch_mask (dst); -/* * Drop stale reference to src's sve_state and convert dst to * non-streaming FPSIMD mode.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1416/2077 arm64/mm: Optimize TLB flush in unmap_hotplug_[pmd|pud]_range()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anshuman Khandual <[email protected]>
[ Upstream commit ff4c5a0de1f2ef7737a8688a86e19301e567020d ]
Commit 48478b9f7913 ("arm64/mm: Enable batched TLB flush in unmap_hotplug_range") inadvertently introduced redundant TLB invalidation when clearing a block entry, resulting in unnecessary broadcast invalidation on CPUs without support for range-based invalidation.
Re-introduce the old behaviour, along with some expanded comments to help people working in this area next time around.
--- arch/arm64/mm/mmu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arm64/mm/mmu.c +9 -2
@@ -1509,7 +1509,13 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,if (free_mapped) {/* CONT blocks are not supported in the vmemmap */ WARN_ON (pmd_cont (pmd)); -flush_tlb_kernel_range (addr, addr +PMD_SIZE ); +/* +* Invalidating a block entry requires just +* a single overlapping TLB invalidation, +* so limit the range of the flush to a single +* page. +*/ +flush_tlb_kernel_range (addr, addr +PAGE_SIZE );free_hotplug_page_range (pmd_page (pmd),PMD_SIZE , altmap); }
@@ -1539,7 +1545,8 @@ static void unmap_hotplug_pud_range(p4d_t *p4dp, unsigned long addr,if (pud_leaf (pud)) {pud_clear (pudp);if (free_mapped) { -flush_tlb_kernel_range (addr, addr +PUD_SIZE ); +/* See comment in unmap_hotplug_pmd_range(). */ +flush_tlb_kernel_range (addr, addr +PAGE_SIZE );free_hotplug_page_range (pud_page (pud),PUD_SIZE , altmap); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1417/2077 iio: dac: mcp47feb02: Fix passing uninitialized vref1_uV for no Vref1 case
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ariana Lazar <[email protected]>
[ Upstream commit e74c0d0eef7e1fa9fd387b81b2787b4581e0b11c ]
Ensure that if a device has Vref1 but reading the regulator returns an error, mcp47feb02_init_ctrl_regs() is not called with an uninitialized vref1_uV value. Also add a device_property_present() check for the Vref1 supply before reading the regulator.
--- drivers/iio/dac/mcp47feb02.c | 37 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
drivers/iio/dac/mcp47feb02.c +22 -15
@@ -1136,26 +1136,33 @@ static int mcp47feb02_probe(struct i2c_client *client) vdd_uV = ret; - ret =devm_regulator_get_enable_read_voltage (dev,"vref" ); -if (ret >0 ) { - vref_uV = ret; +if (device_property_present (dev,"vref-supply" )) { + vref_uV =devm_regulator_get_enable_read_voltage (dev,"vref" ); +if (vref_uV <0 ) +return vref_uV; + +if (vref_uV ==0 ) +return dev_err_probe (dev, -EINVAL ,"Vref is 0 uV.\n" ); + data->use_vref = true; }else { vref_uV =0 ; -dev_dbg (dev,"using internal band gap as voltage reference.\n" ); -dev_dbg (dev,"Vref is unavailable.\n" ); +dev_dbg (dev,"Using internal band gap as voltage reference.\n" ); } -if (chip_features->have_ext_vref1) { - ret =devm_regulator_get_enable_read_voltage (dev,"vref1" ); -if (ret >0 ) { - vref1_uV = ret; - data->use_vref1 = true; - }else { - vref1_uV =0 ; -dev_dbg (dev,"using internal band gap as voltage reference 1.\n" ); -dev_dbg (dev,"Vref1 is unavailable.\n" ); - } +if (chip_features->have_ext_vref1 && +device_property_present (dev,"vref1-supply" )) { + vref1_uV =devm_regulator_get_enable_read_voltage (dev,"vref1" ); +if (vref1_uV <0 ) +return vref1_uV; + +if (vref1_uV ==0 ) +return dev_err_probe (dev, -EINVAL ,"Vref1 is 0 uV.\n" ); + + data->use_vref1 = true; + }else { + vref1_uV =0 ; +dev_dbg (dev,"Using internal band gap as voltage reference 1.\n" ); } ret =mcp47feb02_init_ctrl_regs (data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1418/2077 ntfs: avoid stale runlist element dereference in fallocate
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 88496c4ac5a6ade75619f4b1015706a8b924d50a ]
ntfs_attr_fallocate() allocates holes and delayed allocations inside initialized size by looking up the current runlist element under ni->runlist.lock. The returned struct runlist_element is only a borrowed pointer into ni->runlist.rl. A writer can replace and free that array after the read lock is dropped, so later reads of rl->lcn, rl->length and rl->vcn can touch freed memory.
The buggy scenario involves two paths, with each column showing the order within that path:
ntfs_attr_fallocate():
1. Take ni->runlist.lock for read.
2. Get rl from ntfs_attr_find_vcn_nolock().
3. Drop ni->runlist.lock.
4. Read rl->lcn, rl->length and rl->vcn.
mmap page_mkwrite:
1. Enter ntfs_filemap_page_mkwrite().
2. Reach __ntfs_write_iomap_begin() and ntfs_attr_map_cluster().
3. Merge allocation state with ntfs_runlists_merge().
4. Reallocate ni->runlist.rl in ntfs_rl_realloc(), freeing the old array.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in ntfs_attr_fallocate+0xbb8/0xd00 Call Trace: <TASK> dump_stack_lvl+0x66/0xa0 print_report+0xce/0x630 ? ntfs_attr_fallocate+0xbb8/0xd00 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? ntfs_attr_fallocate+0xbb8/0xd00 kasan_report+0xe0/0x110 ? ntfs_attr_fallocate+0xbb8/0xd00 ntfs_attr_fallocate+0xbb8/0xd00 ? lock_acquire+0x2b8/0x2f0 ? __pfx_ntfs_attr_fallocate+0x10/0x10 ? 0xffffffffc0000095 ? down_write+0x10d/0x1e0 ntfs_fallocate+0x5c9/0x1d00 ? __pfx_ntfs_fallocate+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_acquire+0x2b8/0x2f0 ? srso_alias_return_thunk+0x5/0xfbef5 ? selinux_file_permission+0x3a7/0x510 vfs_fallocate+0x29d/0xd30 __x64_sys_fallocate+0xc7/0x150 ? do_syscall_64+0x81/0x6a0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task 410: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kvmalloc_node_noprof+0x353/0x920 ntfs_rl_realloc+0x3f/0x110 ntfs_runlists_merge+0xaa3/0x3010 ntfs_attr_map_cluster+0x4e5/0xf80 ntfs_attr_fallocate+0x53f/0xd00 ntfs_fallocate+0x5c9/0x1d00 vfs_fallocate+0x29d/0xd30 __x64_sys_fallocate+0xc7/0x150 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 424: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 ntfs_rl_realloc+0x6f/0x110 ntfs_runlists_merge+0x7b1/0x3010 ntfs_attr_map_cluster+0x4e5/0xf80 __ntfs_write_iomap_begin+0x8cd/0x2280 iomap_iter+0x6de/0x11e0 iomap_page_mkwrite+0x391/0x650 ntfs_filemap_page_mkwrite+0x1ac/0x400 do_page_mkwrite+0x15c/0x280 __handle_mm_fault+0xd6d/0x1ca0 handle_mm_fault+0x19c/0x470 do_user_addr_fault+0x23b/0x9c0 exc_page_fault+0x5c/0xc0 asm_exc_page_fault+0x26/0x30
Fix this by copying the needed runlist fields while the read lock is still held and using only those scalar snapshots after unlocking.
After the snapshot, ntfs_attr_map_cluster() can also find that the range is already mapped and return balloc=false. Only call ntfs_dio_zero_range() when new clusters were allocated, matching the write iomap path and preserving the zero-newly-allocated-holes behavior.
--- fs/ntfs/attrib.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
fs/ntfs/attrib.c +19 -11
@@ -5435,6 +5435,7 @@ int ntfs_attr_fallocate(struct ntfs_inode *ni, loff_t start, loff_t byte_len, bos64 old_data_size;s64 vcn_start, vcn_end, vcn_uninit, vcn, try_alloc_cnt;s64 lcn, alloc_cnt; +s64 rl_lcn, rl_length, rl_vcn;int err =0 ;struct runlist_element *rl;bool balloc;
@@ -5514,19 +5515,23 @@ int ntfs_attr_fallocate(struct ntfs_inode *ni, loff_t start, loff_t byte_len, bowhile (vcn < vcn_uninit) {down_read (&ni->runlist.lock); rl =ntfs_attr_find_vcn_nolock (ni, vcn,NULL ); -up_read (&ni->runlist.lock);if (IS_ERR (rl)) { +up_read (&ni->runlist.lock); err =PTR_ERR (rl); goto out; } + rl_lcn = rl->lcn; + rl_length = rl->length; + rl_vcn = rl->vcn; +up_read (&ni->runlist.lock); -if (rl->lcn >0 ) { - vcn += rl->length - (vcn - rl->vcn); - }else if (rl->lcn ==LCN_DELALLOC || rl->lcn ==LCN_HOLE ) { - try_alloc_cnt =min (rl->length - (vcn - rl->vcn), +if (rl_lcn >0 ) { + vcn += rl_length - (vcn - rl_vcn); + }else if (rl_lcn ==LCN_DELALLOC || rl_lcn ==LCN_HOLE ) { + try_alloc_cnt =min (rl_length - (vcn - rl_vcn), vcn_uninit - vcn); -if (rl->lcn ==LCN_DELALLOC ) { +if (rl_lcn ==LCN_DELALLOC ) { vcn += try_alloc_cnt;continue ; }
@@ -5541,11 +5546,14 @@ int ntfs_attr_fallocate(struct ntfs_inode *ni, loff_t start, loff_t byte_len, boif (err) goto out; - err =ntfs_dio_zero_range (VFS_I (ni), - lcn << vol->cluster_size_bits, - alloc_cnt << vol->cluster_size_bits); -if (err >0 ) - goto out; +if (balloc) { + err =ntfs_dio_zero_range (VFS_I (ni), + lcn << vol->cluster_size_bits, + alloc_cnt << + vol->cluster_size_bits); +if (err >0 ) + goto out; + }if (signal_pending (current)) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1419/2077 HID: bpf: Fix hid_bpf_get_data() range check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 2d044049421dd48212b28646a850749d4a2d57fa ]
hid_bpf_get_data() returns a pointer into the HID-BPF context data when the caller-provided offset and size fit inside ctx->allocated_size.
The current check adds rdwr_buf_size and offset before comparing the result against ctx->allocated_size. Since both values are unsigned, a very large size can wrap the sum below ctx->allocated_size and make the helper return a pointer even though the requested range is not contained in the backing buffer.
Use check_add_overflow() to reject wrapped range ends before comparing the requested range end against ctx->allocated_size.
--- drivers/hid/bpf/hid_bpf_dispatch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hid/bpf/hid_bpf_dispatch.c +4 -1
@@ -17,6 +17,7 @@#include <linux/kfifo.h> #include <linux/minmax.h> #include <linux/module.h> +#include <linux/overflow.h> #include "hid_bpf_dispatch.h" const struct hid_ops *hid_ops;
@@ -296,10 +297,12 @@ __bpf_kfunc __u8 * hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t rdwr_buf_size) { struct hid_bpf_ctx_kern *ctx_kern; +size_t end; ctx_kern = container_of(ctx, struct hid_bpf_ctx_kern, ctx); -if (rdwr_buf_size + offset > ctx->allocated_size) +if (check_add_overflow (rdwr_buf_size, offset, &end) || + end > ctx->allocated_size)return NULL ;return ctx_kern->data + offset;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1420/2077 selftests/hid: Load only requested struct_ops maps
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 5aad55011a37d999cf99d14bafb6a093a1a70466 ]
The HID selftest skeleton contains several struct_ops maps, but each test usually wants to load only the programs named by that test.
load_programs() disabled auto-attach for all maps, but left struct_ops autocreate enabled. libbpf can enable autoload for programs referenced by autocreated struct_ops maps, so an unrelated program can be loaded and fail even when the current test does not use it.
Disable autocreate for all struct_ops maps by default, then re-enable it only for the maps selected by the test before loading the skeleton.
--- tools/testing/selftests/hid/hid_bpf.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
tools/testing/selftests/hid/hid_bpf.c +18 -7
@@ -86,6 +86,20 @@ static void load_programs(const struct test_program programs[], self->skel =hid__open (); ASSERT_OK_PTR(self->skel) TEARDOWN_LOG("Error while calling hid__open"); +/* +* Disable all struct_ops maps by default so libbpf does not autoload +* programs referenced by maps that are unrelated to the current test. +*/ +bpf_object__for_each_map (iter_map, *self->skel->skeleton->obj) { +if (bpf_map__type (iter_map) ==BPF_MAP_TYPE_STRUCT_OPS ) { + err =bpf_map__set_autocreate (iter_map, false); + ASSERT_OK(err) TH_LOG("can not disable struct_ops map '%s'", + bpf_map__name(iter_map)); + } + +bpf_map__set_autoattach (iter_map, false); + } +for (int i =0 ; i < progs_count; i++) {struct bpf_program *prog;struct bpf_map *map;
@@ -102,6 +116,10 @@ static void load_programs(const struct test_program programs[], ASSERT_OK_PTR(map) TH_LOG("can not find struct_ops by name '%s'", programs[i].name + 4); + err =bpf_map__set_autocreate (map, true); + ASSERT_OK(err) TH_LOG("can not enable struct_ops map '%s'", + programs[i].name + 4); +/* hid_id is the first field of struct hid_bpf_ops */ ops_hid_id =bpf_map__initial_value (map,NULL ); ASSERT_OK_PTR(ops_hid_id) TH_LOG("unable to retrieve struct_ops data");
@@ -109,13 +127,6 @@ static void load_programs(const struct test_program programs[], *ops_hid_id = self->hid.hid_id; } -/* we disable the auto-attach feature of all maps because we -* only want the tested one to be manually attached in the next -* call to bpf_map__attach_struct_ops() -*/ -bpf_object__for_each_map (iter_map, *self->skel->skeleton->obj) -bpf_map__set_autoattach (iter_map, false); - err =hid__load (self->skel); ASSERT_OK(err) TH_LOG("hid_skel_load failed: %d", err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1421/2077 selftests/hid: Cover hid_bpf_get_data() size overflow
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit eebbef7c468a5cb58c4772849ee5066441166cf0 ]
Add a HID-BPF regression check for hid_bpf_get_data() requests whose size would overflow when added to the offset.
The new rdesc fixup callback asks for offset 2 and size ~0ULL, then records whether the helper returns NULL. A vulnerable kernel returns a non-NULL pointer because the runtime check wraps the addition. A fixed kernel rejects the request. The callback records the helper result without dereferencing any returned pointer.
The callback reports the helper result through BSS and returns 0 intentionally. hid_rdesc_fixup return values are consumed as report descriptor fixup results, so a positive test-result value would be interpreted as a replacement report descriptor size.
Also add KHDR_INCLUDES to the HID selftest build so hid_bpf.c sees the current kernel UAPI HID definitions on systems whose installed headers do not provide enum hid_report_type.
--- tools/testing/selftests/hid/Makefile | 2 +- tools/testing/selftests/hid/hid_bpf.c | 11 +++++++++++ tools/testing/selftests/hid/progs/hid.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-)
tools/testing/selftests/hid/Makefile +1 -1
@@ -24,7 +24,7 @@ CXX ?= $(CROSS_COMPILE)g++ HOSTPKG_CONFIG := pkg-config -CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT) +CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT) $(KHDR_INCLUDES) CFLAGS += -I$(OUTPUT)/tools/include LDLIBS += -lelf -lz -lrt -lpthread
tools/testing/selftests/hid/hid_bpf.c +11 -0
@@ -898,6 +898,17 @@ TEST_F(hid_bpf, test_rdesc_fixup)ASSERT_EQ (rpt_desc.value[4 ],0x42 ); } +TEST_F(hid_bpf, test_rdesc_fixup_get_data_overflow) +{ +const struct test_program progs[] = { + { .name ="hid_rdesc_fixup_get_data_overflow" }, + }; + +LOAD_PROGRAMS (progs); + +ASSERT_EQ (self->skel->bss->get_data_overflow_check,1 ); +} +static int libbpf_print_fn (enum libbpf_print_level level,const char *format,va_list args) {
tools/testing/selftests/hid/progs/hid.c +15 -0
@@ -13,6 +13,7 @@ struct attach_prog_args {__u64 callback_check =52 ;__u64 callback2_check =52 ; +__u64 get_data_overflow_check; SEC("?struct_ops/hid_device_event")int BPF_PROG (hid_first_event ,struct hid_bpf_ctx *hid_ctx,enum hid_report_type type)
@@ -240,6 +241,20 @@ struct hid_bpf_ops rdesc_fixup = { .hid_rdesc_fixup = (void *)hid_rdesc_fixup, }; +SEC("?struct_ops.s/hid_rdesc_fixup") +int BPF_PROG (hid_rdesc_fixup_get_data_overflow ,struct hid_bpf_ctx *hid_ctx) +{ +if (!hid_bpf_get_data (hid_ctx,2 /* offset */ , ~0ULL /* size */ )) + get_data_overflow_check =1 ; + +return 0 ; +} + +SEC(".struct_ops.link") +struct hid_bpf_ops rdesc_fixup_get_data_overflow = { + .hid_rdesc_fixup = (void *)hid_rdesc_fixup_get_data_overflow, +}; + SEC("?struct_ops/hid_device_event")int BPF_PROG (hid_test_insert1 ,struct hid_bpf_ctx *hid_ctx,enum hid_report_type type) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1422/2077 arm64/sysreg: Fix BWE field encoding in ID_AA64DFR2_EL1
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia He <[email protected]>
[ Upstream commit 6666336d8fe5f3f0cd3f8da2865ca78110a6e170 ]
Commit 93d7356e4b30 ("arm64: sysreg: Describe ID_AA64DFR2_EL1 fields") encodes the FEAT_BWE2 value of the BWE field as '0b0002'. Binary literals only accept the digits 0 and 1, so the intended value is 2, i.e. 0b0010.
The macro generated by gen-sysreg.awk currently expands to
#define ID_AA64DFR2_EL1_BWE_FEAT_BWE2 UL(0b0002)
is not legal C and would fail to compile if any in-tree code referenced it. At present no caller uses this enum value, so the kernel still builds cleanly, but the bug is latent.
Fix the typo by using the correct binary literal 0b0010.
--- arch/arm64/tools/sysreg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/tools/sysreg +1 -1
@@ -1806,7 +1806,7 @@ Res0 15:8 UnsignedEnum 7:4 BWE 0b0000 NI 0b0001 FEAT_BWE - 0b0002 FEAT_BWE2 + 0b0010 FEAT_BWE2 EndEnum UnsignedEnum 3:0 STEP 0b0000 NI
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1423/2077 net: usb: net1080: validate packet_len before pad-byte access in rx_fixup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 03f384bc0cb8d4a1301d4f5b0baef2d980258383 ]
For an even packet_len, net1080_rx_fixup() reads the pad byte at skb->data[packet_len] before the skb->len != packet_len check further down, and packet_len is only bounded against NC_MAX_PACKET. A malicious NetChip 1080 device can send a short frame advertising a large even packet_len (e.g. 0x4000), so the pad-byte read lands past the end of the skb:
BUG: KASAN: slab-out-of-bounds in net1080_rx_fixup Read of size 1 at addr ffff8880106c83c6 by task ksoftirqd/0/14 ... net1080_rx_fixup (drivers/net/usb/net1080.c:384) usbnet_bh (drivers/net/usb/usbnet.c:1589) process_one_work (kernel/workqueue.c:3322) bh_worker (kernel/workqueue.c:3708) tasklet_action (kernel/softirq.c:965) handle_softirqs (kernel/softirq.c:622) ...
Reject the frame when packet_len >= skb->len before reading.
--- drivers/net/usb/net1080.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/usb/net1080.c +1 -1
@@ -381,7 +381,7 @@ static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)skb_trim (skb, skb->len -sizeof *trailer);if ((packet_len &0x01 ) ==0 ) { -if (skb->data [packet_len] !=PAD_BYTE ) { +if (packet_len >= skb->len || skb->data[packet_len] !=PAD_BYTE ) { dev->net->stats.rx_frame_errors++;netdev_dbg (dev->net,"bad pad\n" );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1424/2077 gue: validate REMCSUM private option length
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qihang <[email protected]>
[ Upstream commit d335dcc6f521571d57117b8deeebc940836e5450 ]
GUE private flags can indicate that remote checksum offload metadata is present. The private flags field itself is accounted for by guehdr_flags_len(), but guehdr_priv_flags_len() currently returns 0 even when GUE_PFLAG_REMCSUM is set.
This lets a packet with only the private flags field pass validate_gue_flags(), after which gue_remcsum() and gue_gro_remcsum() read the missing REMCSUM start/offset fields from the following bytes.
Account for GUE_PLEN_REMCSUM when GUE_PFLAG_REMCSUM is present so that malformed packets are rejected during option validation.
--- include/net/gue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/gue.h +1 -1
@@ -80,7 +80,7 @@ static inline size_t guehdr_flags_len(__be16 flags)static inline size_t guehdr_priv_flags_len (__be32 flags) { -return 0 ; +return (flags &GUE_PFLAG_REMCSUM ) ?GUE_PLEN_REMCSUM :0 ; }/* Validate standard and private flags. Returns non-zero (meaning invalid)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1425/2077 netfilter: xt_u32: reject invalid shift counts
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wyatt Feng <[email protected]>
[ Upstream commit 64cdf7d30ac18e43df6c48004435febb965809a8 ]
u32_match_it() executes rule-supplied shift operands on a 32-bit value. A malformed u32 rule can provide a shift count of 32 or more, triggering an undefined shift out-of-bounds during packet evaluation.
Validate XT_U32_LEFTSH and XT_U32_RIGHTSH operands in u32_mt_checkentry() and reject malformed rules before they reach the packet path.
--- net/netfilter/xt_u32.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/netfilter/xt_u32.c +11 -1
@@ -106,7 +106,7 @@ static int u32_mt_checkentry(const struct xt_mtchk_param *par) {const struct xt_u32 *data = par->matchinfo;const struct xt_u32_test *ct; -unsigned int i; +unsigned int i, j;if (data->ntests >ARRAY_SIZE (data->tests))return -EINVAL ;
@@ -117,6 +117,16 @@ static int u32_mt_checkentry(const struct xt_mtchk_param *par)if (ct->nnums >ARRAY_SIZE (ct->location) || ct->nvalues >ARRAY_SIZE (ct->value))return -EINVAL ; + +for (j =1 ; j < ct->nnums; ++j) { +switch (ct->location[j].nextop) { +case XT_U32_LEFTSH : +case XT_U32_RIGHTSH : +if (ct->location[j].number >=32 ) +return -EINVAL ; +break ; + } + } }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1426/2077 netfilter: xt_rateest: fix u64 truncation in xt_rateest_mt()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Wu <[email protected]>
[ Upstream commit 444853cd438201007da5359821adcc2995655ab1 ]
On links faster than ~34 Gbps, where byte rate may exceed 2^32-1 (~ 4.3 GBps), the comparison result becomes incorrect because the truncated value no longer reflects the actual estimator rate.
Fix by changing the local variables to u64.
--- net/netfilter/xt_rateest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_rateest.c +1 -1
@@ -16,7 +16,7 @@ xt_rateest_mt(const struct sk_buff *skb, struct xt_action_param *par) {const struct xt_rateest_match_info *info = par->matchinfo;struct gnet_stats_rate_est64 sample = {0 }; -u_int32_t bps1, bps2, pps1, pps2; +u64 bps1, bps2, pps1, pps2;bool ret = true;gen_estimator_read (&info->est1->rate_est, &sample);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1427/2077 netfilter: ip6tables: mark malformed IPv6 extension headers for hotdrop
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhixing Chen <[email protected]>
[ Upstream commit 43ccc20b5a733226417832cf16ef45322e594990 ]
The ah, hbh and rt matches check that the fixed extension header is present, then use the header length field to derive the advertised extension header length for matching.
For the ah match, add the missing advertised-length check. For hbh and rt, update the existing advertised-length checks. In all three cases, set hotdrop to true before returning false when the advertised extension header length exceeds the available skb data.
Returning false treats the packet as a rule mismatch. Set hotdrop to true and drop malformed packets so they cannot bypass rules intended to drop packets with these IPv6 extension headers.
--- net/ipv6/netfilter/ip6t_ah.c | 5 +++++ net/ipv6/netfilter/ip6t_hbh.c | 1 + net/ipv6/netfilter/ip6t_rt.c | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-)
net/ipv6/netfilter/ip6t_ah.c +5 -0
@@ -56,6 +56,11 @@ static bool ah_mt6(const struct sk_buff *skb, struct xt_action_param *par) } hdrlen =ipv6_authlen (ah); +if (skb->len - ptr < hdrlen) { +/* Packet smaller than its length field */ + par->hotdrop = true; +return false; + }pr_debug ("IPv6 AH LEN %u %u " , hdrlen, ah->hdrlen);pr_debug ("RES %04X " , ah->reserved);
net/ipv6/netfilter/ip6t_hbh.c +1 -0
@@ -75,6 +75,7 @@ hbh_mt6(const struct sk_buff *skb, struct xt_action_param *par) hdrlen =ipv6_optlen (oh);if (skb->len - ptr < hdrlen) {/* Packet smaller than it's length field */ + par->hotdrop = true;return false; }
net/ipv6/netfilter/ip6t_rt.c +2 -1
@@ -56,7 +56,8 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par) hdrlen =ipv6_optlen (rh);if (skb->len - ptr < hdrlen) { -/* Pcket smaller than its length field */ +/* Packet smaller than its length field */ + par->hotdrop = true;return false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1428/2077 netfilter: nft_set_rbtree: get command skips end element with open interval
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit d63611cbe8af99dd61b118ee6e5b5e3e518250b2 ]
The get command on intervals provide partial matches such as subranges for usability reasons. However, an open interval has no closing end element. If the closing element matches within the range of the open internal, ie. its closest match is the start element of the open range, then, return 0 but offer no matching element to userspace through netlink as a special case. Userspace provides at least a matching start element in this case and the closing end element matching the open interal is ignored.
Another possibility is to report the matching start element of the open interval for this end interval. However, this results in duplicated matching being listed in userspace because userspace does not expect a start element as response to a end element.
--- net/netfilter/nf_tables_api.c | 3 +++ net/netfilter/nft_set_rbtree.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +3 -0
@@ -6559,6 +6559,9 @@ static int nft_get_set_elem(struct nft_ctx *ctx, const struct nft_set *set,if (err <0 )return err; +if (!elem.priv) +return 0 ; + err = -ENOMEM ; skb =nlmsg_new (NLMSG_GOODSIZE ,GFP_ATOMIC );if (skb ==NULL )
net/netfilter/nft_set_rbtree.c +6 -2
@@ -184,10 +184,14 @@ nft_rbtree_get(const struct net *net, const struct nft_set *set,if (!interval ||nft_set_elem_expired (interval->from))return ERR_PTR (-ENOENT ); -if (flags &NFT_SET_ELEM_INTERVAL_END ) +if (flags &NFT_SET_ELEM_INTERVAL_END ) { +if (!interval->to) +return NULL ; + rbe = container_of(interval->to, struct nft_rbtree_elem, ext); -else + }else { rbe = container_of(interval->from, struct nft_rbtree_elem, ext); + }return &rbe->priv; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1429/2077 netfilter: xt_connmark: reject invalid shift parameters
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wyatt Feng <[email protected]>
[ Upstream commit 1b47026fb4b35bac850ad6e8a4ad7fc018e09ebc ]
Revision 2 of the CONNMARK target accepts user-controlled shift parameters and applies them to 32-bit mark values in connmark_tg_shift().
A shift_bits value of 32 or more triggers an undefined-shift bug when the rule is evaluated. Invalid shift_dir values are also accepted and silently fall back to the left-shift path.
Reject invalid revision-2 shift parameters in connmark_tg_check() so malformed rules fail at installation time, before they can reach the packet path.
--- net/netfilter/xt_connmark.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/netfilter/xt_connmark.c +12 -2
@@ -112,6 +112,16 @@ static int connmark_tg_check(const struct xt_tgchk_param *par)return ret; } +static int connmark_tg_check_v2 (const struct xt_tgchk_param *par) +{ +const struct xt_connmark_tginfo2 *info = par->targinfo; + +if (info->shift_dir >D_SHIFT_RIGHT || info->shift_bits >=32 ) +return -EINVAL ; + +return connmark_tg_check (par); +} +static void connmark_tg_destroy (const struct xt_tgdtor_param *par) {nf_ct_netns_put (par->net, par->family);
@@ -162,7 +172,7 @@ static struct xt_target connmark_tg_reg[] __read_mostly = { .name = "CONNMARK", .revision = 2, .family = NFPROTO_IPV4, - .checkentry = connmark_tg_check, + .checkentry = connmark_tg_check_v2, .target = connmark_tg_v2, .targetsize = sizeof(struct xt_connmark_tginfo2), .destroy = connmark_tg_destroy,
@@ -183,7 +193,7 @@ static struct xt_target connmark_tg_reg[] __read_mostly = { .name = "CONNMARK", .revision = 2, .family = NFPROTO_IPV6, - .checkentry = connmark_tg_check, + .checkentry = connmark_tg_check_v2, .target = connmark_tg_v2, .targetsize = sizeof(struct xt_connmark_tginfo2), .destroy = connmark_tg_destroy,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1430/2077 platform/x86: bitland-mifs-wmi: Fix NULL pointer dereference during suspend/resume
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mingyou Chen <[email protected]>
[ Upstream commit d3666875c75eb1bc8090343fa0d6fc8fb7924356 ]
The driver registers two distinct WMI devices: a control device (BITLAND_WMI_CONTROL) and an event device (BITLAND_WMI_EVENT). During the probe phase, the event device handling path returns early before initializing the platform profile device (data->pp_dev), leaving it NULL.
However, the PM sleep operations are registered globally for the WMI driver and are triggered for both devices. When entering suspend, the event device invokes bitland_mifs_wmi_suspend(), which passes the uninitialized data->pp_dev (NULL) into laptop_profile_get(). This leads to a NULL pointer dereference inside dev_get_drvdata(), causing a kernel Oops and halting the suspend sequence.
Fix this by adding a validity check for data->pp_dev in both the suspend and resume callbacks, safely skipping profile operations for the event device.
--- drivers/platform/x86/bitland-mifs-wmi.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/platform/x86/bitland-mifs-wmi.c +8 -0
@@ -300,6 +300,10 @@ static int bitland_mifs_wmi_suspend(struct device *dev)enum platform_profile_option profile;int ret; +/* Skip event device */ +if (!data->pp_dev) +return 0 ; + ret =laptop_profile_get (data->pp_dev, &profile);if (ret ==0 ) data->saved_profile = profile;
@@ -311,6 +315,10 @@ static int bitland_mifs_wmi_resume(struct device *dev) {struct bitland_mifs_wmi_data *data =dev_get_drvdata (dev); +/* Skip event device */ +if (!data->pp_dev) +return 0 ; +dev_dbg (dev,"Resuming, restoring profile %d\n" , data->saved_profile);return laptop_profile_set (dev, data->saved_profile); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1431/2077 net/mlx5: Lag: refactor representor reload handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Bloch <[email protected]>
[ Upstream commit b501400fa66d9b8045f282ae8de80ceb6e02fe85 ]
Representor reload during LAG/MPESW transitions has to be repeated in several flows, and each open-coded loop was easy to get out of sync when adding new flags or tweaking error handling. Move the sequencing into a single helper so that all call sites share the same ordering and checks.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 45 +++++++++++-------- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 2 + .../ethernet/mellanox/mlx5/core/lag/mpesw.c | 12 ++--- 3 files changed, 33 insertions(+), 26 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +27 -18
@@ -1093,6 +1093,27 @@ void mlx5_lag_remove_devices(struct mlx5_lag *ldev) } } +int mlx5_lag_reload_ib_reps (struct mlx5_lag *ldev,u32 flags,bool cont_on_fail) +{ +struct lag_func *pf; +int ret; +int i; + +mlx5_ldev_for_each (i,0 , ldev) { + pf =mlx5_lag_pf (ldev, i); +if (!(pf->dev->priv.flags & flags)) { +struct mlx5_eswitch *esw; + + esw = pf->dev->priv.eswitch; + ret =mlx5_eswitch_reload_ib_reps (esw); +if (ret && !cont_on_fail) +return ret; + } + } + +return 0 ; +} +void mlx5_disable_lag (struct mlx5_lag *ldev) {bool shared_fdb =test_bit (MLX5_LAG_MODE_FLAG_SHARED_FDB , &ldev->mode_flags);
@@ -1130,9 +1151,8 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)mlx5_lag_add_devices (ldev);if (shared_fdb) -mlx5_ldev_for_each (i,0 , ldev) -if (!(mlx5_lag_pf (ldev, i)->dev->priv.flags &MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV )) -mlx5_eswitch_reload_ib_reps (mlx5_lag_pf (ldev, i)->dev->priv.eswitch); +mlx5_lag_reload_ib_reps (ldev,MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV , + true); }bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev)
@@ -1393,10 +1413,8 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)if (err) {if (shared_fdb || roce_lag)mlx5_lag_add_devices (ldev); -if (shared_fdb) { -mlx5_ldev_for_each (i,0 , ldev) -mlx5_eswitch_reload_ib_reps (mlx5_lag_pf (ldev, i)->dev->priv.eswitch); - } +if (shared_fdb) +mlx5_lag_reload_ib_reps (ldev,0 , true);return ; }
@@ -1414,24 +1432,15 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)mlx5_nic_vport_enable_roce (dev); } }else if (shared_fdb) { -int i; - dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ;mlx5_rescan_drivers_locked (dev0); - -mlx5_ldev_for_each (i,0 , ldev) { - err =mlx5_eswitch_reload_ib_reps (mlx5_lag_pf (ldev, i)->dev->priv.eswitch); -if (err) -break ; - } - + err =mlx5_lag_reload_ib_reps (ldev,0 , false);if (err) { dev0->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ;mlx5_rescan_drivers_locked (dev0);mlx5_deactivate_lag (ldev);mlx5_lag_add_devices (ldev); -mlx5_ldev_for_each (i,0 , ldev) -mlx5_eswitch_reload_ib_reps (mlx5_lag_pf (ldev, i)->dev->priv.eswitch); +mlx5_lag_reload_ib_reps (ldev,0 , true);mlx5_core_err (dev0,"Failed to enable lag\n" );return ; }
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +2 -0
@@ -199,4 +199,6 @@ int mlx5_get_next_ldev_func(struct mlx5_lag *ldev, int start_idx);int mlx5_lag_get_dev_index_by_seq (struct mlx5_lag *ldev,int seq);int mlx5_lag_num_devs (struct mlx5_lag *ldev);int mlx5_lag_num_netdevs (struct mlx5_lag *ldev); +int mlx5_lag_reload_ib_reps (struct mlx5_lag *ldev,u32 flags, +bool cont_on_fail);#endif /* __MLX5_LAG_H__ */
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +4 -8
@@ -70,7 +70,6 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)int idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 );struct mlx5_core_dev *dev0;int err; -int i;if (ldev->mode ==MLX5_LAG_MODE_MPESW )return 0 ;
@@ -103,11 +102,9 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev) dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ;mlx5_rescan_drivers_locked (dev0); -mlx5_ldev_for_each (i,0 , ldev) { - err =mlx5_eswitch_reload_ib_reps (mlx5_lag_pf (ldev, i)->dev->priv.eswitch); -if (err) - goto err_rescan_drivers; - } + err =mlx5_lag_reload_ib_reps (ldev,0 , false); +if (err) + goto err_rescan_drivers;mlx5_lag_set_vports_agg_speed (ldev);
@@ -119,8 +116,7 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)mlx5_deactivate_lag (ldev); err_add_devices:mlx5_lag_add_devices (ldev); -mlx5_ldev_for_each (i,0 , ldev) -mlx5_eswitch_reload_ib_reps (mlx5_lag_pf (ldev, i)->dev->priv.eswitch); +mlx5_lag_reload_ib_reps (ldev,0 , true);mlx5_mpesw_metadata_cleanup (ldev);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1432/2077 net/mlx5: E-Switch, add representor lifecycle lock
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Bloch <[email protected]>
[ Upstream commit 9b8468f001e46c4ffcbbeb2050aabf80e1ed7960 ]
Add a per-E-Switch mutex for serializing representor lifecycle work and provide small helpers for taking and dropping it. Initialize and destroy the mutex with the E-Switch offloads state.
Add the lock and helper API first. Follow-up patches will take the lock in the individual representor lifecycle components. This keeps the functional changes split by component and leaves this patch without intended behavior change, making the series easier to review and bisectable.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 6 ++++++ .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 12 ++++++++++++ 2 files changed, 18 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +6 -0
@@ -316,6 +316,7 @@ struct mlx5_esw_offload {DECLARE_HASHTABLE (termtbl_tbl,8 );struct mutex termtbl_mutex;/* protects termtbl hash */ struct xarray vhca_map; +struct mutex reps_lock;/* protects representor load/unload/register */ const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES ];u8 inline_mode;atomic64_t num_flows;
@@ -949,6 +950,8 @@ mlx5_esw_lag_demux_fg_create(struct mlx5_eswitch *esw,struct mlx5_flow_handle *mlx5_esw_lag_demux_rule_create (struct mlx5_eswitch *esw,u16 vport_num,struct mlx5_flow_table *lag_ft); +void mlx5_esw_reps_block (struct mlx5_eswitch *esw); +void mlx5_esw_reps_unblock (struct mlx5_eswitch *esw);#else /* CONFIG_MLX5_ESWITCH */ /* eswitch API stubs */ static inline int mlx5_eswitch_init (struct mlx5_core_dev *dev) {return 0 ; }
@@ -1026,6 +1029,9 @@ mlx5_esw_host_functions_enabled(const struct mlx5_core_dev *dev)return true; } +static inline void mlx5_esw_reps_block (struct mlx5_eswitch *esw) {} +static inline void mlx5_esw_reps_unblock (struct mlx5_eswitch *esw) {} +static inline bool mlx5_esw_vport_vhca_id (struct mlx5_eswitch *esw,u16 vportn,u16 *vhca_id) {
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +12 -0
@@ -2410,6 +2410,16 @@ static int esw_create_restore_table(struct mlx5_eswitch *esw)return err; } +void mlx5_esw_reps_block (struct mlx5_eswitch *esw) +{ +mutex_lock (&esw->offloads.reps_lock); +} + +void mlx5_esw_reps_unblock (struct mlx5_eswitch *esw) +{ +mutex_unlock (&esw->offloads.reps_lock); +} +static void esw_mode_change (struct mlx5_eswitch *esw,u16 mode) {mlx5_devcom_comp_lock (esw->dev->priv.hca_devcom_comp);
@@ -2642,6 +2652,7 @@ static void esw_offloads_cleanup_reps(struct mlx5_eswitch *esw)mlx5_esw_for_each_rep (esw, i, rep)mlx5_esw_offloads_rep_cleanup (esw, rep);xa_destroy (&esw->offloads.vport_reps); +mutex_destroy (&esw->offloads.reps_lock); }static int esw_offloads_init_reps (struct mlx5_eswitch *esw)
@@ -2651,6 +2662,7 @@ static int esw_offloads_init_reps(struct mlx5_eswitch *esw)int err;xa_init (&esw->offloads.vport_reps); +mutex_init (&esw->offloads.reps_lock);mlx5_esw_for_each_vport (esw, i, vport) { err =mlx5_esw_offloads_rep_add (esw, vport);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1433/2077 net/mlx5: Lag, avoid LAG and representor lock cycles
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Bloch <[email protected]>
[ Upstream commit 63ec6c69e6134ce4cf5dc9acc61b49bac4916979 ]
The LAG shared-FDB and multiport E-Switch transitions rescan auxiliary devices and reload IB representors while holding ldev->lock. Driver bind/unbind paths may register or unregister E-Switch representor ops, and representor load paths may enter LAG code, so holding ldev->lock across those calls creates lock-order cycles with the E-Switch representor lock.
Keep the devcom component locked for the transition, but drop ldev->lock before rescanning auxiliary devices or reloading IB representors. Mark the LAG transition as in progress while the lock is dropped and assert the devcom lock where the helper relies on it. This preserves LAG serialization while avoiding ldev->lock nesting under E-Switch representor registration.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 142 ++++++++++++++---- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 7 +- .../ethernet/mellanox/mlx5/core/lag/mpesw.c | 10 +- .../ethernet/mellanox/mlx5/core/lib/devcom.c | 8 + .../ethernet/mellanox/mlx5/core/lib/devcom.h | 1 + 5 files changed, 134 insertions(+), 34 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +116 -26
@@ -1063,37 +1063,99 @@ bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)return true; } -void mlx5_lag_add_devices (struct mlx5_lag *ldev) +static void mlx5_lag_assert_locked_transition (struct mlx5_lag *ldev) { +struct mlx5_devcom_comp_dev *devcom =NULL ;struct lag_func *pf;int i; -mlx5_ldev_for_each (i,0 , ldev) { - pf =mlx5_lag_pf (ldev, i); -if (pf->dev->priv.flags &MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV ) -continue ; +lockdep_assert_held (&ldev->lock); - pf->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (pf->dev); + i =mlx5_get_next_ldev_func (ldev,0 ); +if (i <MLX5_MAX_PORTS ) { + pf =mlx5_lag_pf (ldev, i); + devcom = pf->dev->priv.hca_devcom_comp; } +mlx5_devcom_comp_assert_locked (devcom); } -void mlx5_lag_remove_devices (struct mlx5_lag *ldev) +static void mlx5_lag_drop_lock_for_reps (struct mlx5_lag *ldev) +{ +mlx5_lag_assert_locked_transition (ldev); + +/* Keep PF membership stable while ldev->lock is dropped. Device add +* and remove paths observe mode_changes_in_progress and retry. +*/ + ldev->mode_changes_in_progress++; +mutex_unlock (&ldev->lock); +} + +static void mlx5_lag_retake_lock_after_reps (struct mlx5_lag *ldev) { +mutex_lock (&ldev->lock); + ldev->mode_changes_in_progress--; +} + +void mlx5_lag_rescan_dev_locked (struct mlx5_lag *ldev, +struct mlx5_core_dev *dev, +bool enable) +{ +if (dev->priv.flags &MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV ) +return ; + +if (enable) + dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; +else + dev->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; + +/* Auxiliary bus probe/remove can register or unregister representor +* callbacks and take reps_lock. Drop ldev->lock so the only ordering +* remains reps_lock -> ldev->lock from representor callbacks. +*/ +mlx5_lag_drop_lock_for_reps (ldev); +mlx5_rescan_drivers_locked (dev); +mlx5_lag_retake_lock_after_reps (ldev); +} + +static void mlx5_lag_rescan_devices_locked (struct mlx5_lag *ldev,bool enable) +{ +struct mlx5_core_dev *devs[MLX5_MAX_PORTS ];struct lag_func *pf; +int num_devs =0 ;int i; +mlx5_lag_assert_locked_transition (ldev); +mlx5_ldev_for_each (i,0 , ldev) { pf =mlx5_lag_pf (ldev, i);if (pf->dev->priv.flags &MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV )continue ; - pf->dev->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (pf->dev); +if (enable) + pf->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; +else + pf->dev->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; + devs[num_devs++] = pf->dev; } + +mlx5_lag_drop_lock_for_reps (ldev); +for (i =0 ; i < num_devs; i++) +mlx5_rescan_drivers_locked (devs[i]); +mlx5_lag_retake_lock_after_reps (ldev); } -int mlx5_lag_reload_ib_reps (struct mlx5_lag *ldev,u32 flags,bool cont_on_fail) +void mlx5_lag_add_devices (struct mlx5_lag *ldev) +{ +mlx5_lag_rescan_devices_locked (ldev, true); +} + +void mlx5_lag_remove_devices (struct mlx5_lag *ldev) +{ +mlx5_lag_rescan_devices_locked (ldev, false); +} + +static int mlx5_lag_reload_ib_reps_unlocked (struct mlx5_lag *ldev,u32 flags, +bool cont_on_fail) {struct lag_func *pf;int ret;
@@ -1105,7 +1167,9 @@ int mlx5_lag_reload_ib_reps(struct mlx5_lag *ldev, u32 flags, bool cont_on_fail)struct mlx5_eswitch *esw; esw = pf->dev->priv.eswitch; +mlx5_esw_reps_block (esw); ret =mlx5_eswitch_reload_ib_reps (esw); +mlx5_esw_reps_unblock (esw);if (ret && !cont_on_fail)return ret; }
@@ -1114,6 +1178,34 @@ int mlx5_lag_reload_ib_reps(struct mlx5_lag *ldev, u32 flags, bool cont_on_fail)return 0 ; } +static int mlx5_lag_reload_ib_reps (struct mlx5_lag *ldev,u32 flags, +bool cont_on_fail) +{ +int ret; + +/* The HCA devcom component lock serializes LAG mode transitions while +* ldev->lock is dropped here. Dropping ldev->lock is required because +* the reload takes the per-E-Switch reps_lock, and representor +* load/unload callbacks can re-enter LAG netdev add/remove and take +* ldev->lock. Keep the ordering reps_lock -> ldev->lock. +*/ +mlx5_lag_drop_lock_for_reps (ldev); + ret =mlx5_lag_reload_ib_reps_unlocked (ldev, flags, cont_on_fail); +mlx5_lag_retake_lock_after_reps (ldev); + +return ret; +} + +int mlx5_lag_reload_ib_reps_from_locked (struct mlx5_lag *ldev,u32 flags, +bool cont_on_fail) +{ +int ret; + + ret =mlx5_lag_reload_ib_reps (ldev, flags, cont_on_fail); + +return ret; +} +void mlx5_disable_lag (struct mlx5_lag *ldev) {bool shared_fdb =test_bit (MLX5_LAG_MODE_FLAG_SHARED_FDB , &ldev->mode_flags);
@@ -1132,10 +1224,7 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)if (shared_fdb) {mlx5_lag_remove_devices (ldev); }else if (roce_lag) { -if (!(dev0->priv.flags &MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV )) { - dev0->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (dev0); - } +mlx5_lag_rescan_dev_locked (ldev, dev0, false);mlx5_ldev_for_each (i,0 , ldev) {if (i == idx)continue ;
@@ -1151,8 +1240,9 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)mlx5_lag_add_devices (ldev);if (shared_fdb) -mlx5_lag_reload_ib_reps (ldev,MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV , - true); +mlx5_lag_reload_ib_reps_from_locked (ldev, +MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV , + true); }bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev)
@@ -1414,7 +1504,8 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)if (shared_fdb || roce_lag)mlx5_lag_add_devices (ldev);if (shared_fdb) -mlx5_lag_reload_ib_reps (ldev,0 , true); +mlx5_lag_reload_ib_reps_from_locked (ldev,0 , + true);return ; }
@@ -1422,8 +1513,7 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)if (roce_lag) {struct mlx5_core_dev *dev; - dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (dev0); +mlx5_lag_rescan_dev_locked (ldev, dev0, true);mlx5_ldev_for_each (i,0 , ldev) {if (i == idx)continue ;
@@ -1432,15 +1522,15 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)mlx5_nic_vport_enable_roce (dev); } }else if (shared_fdb) { - dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (dev0); - err =mlx5_lag_reload_ib_reps (ldev,0 , false); +mlx5_lag_rescan_dev_locked (ldev, dev0, true); + err =mlx5_lag_reload_ib_reps_from_locked (ldev,0 , + false);if (err) { - dev0->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (dev0); +mlx5_lag_rescan_dev_locked (ldev, dev0, false);mlx5_deactivate_lag (ldev);mlx5_lag_add_devices (ldev); -mlx5_lag_reload_ib_reps (ldev,0 , true); +mlx5_lag_reload_ib_reps_from_locked (ldev,0 , + true);mlx5_core_err (dev0,"Failed to enable lag\n" );return ; }
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +5 -2
@@ -164,6 +164,9 @@ void mlx5_disable_lag(struct mlx5_lag *ldev);void mlx5_lag_remove_devices (struct mlx5_lag *ldev);int mlx5_deactivate_lag (struct mlx5_lag *ldev);void mlx5_lag_add_devices (struct mlx5_lag *ldev); +void mlx5_lag_rescan_dev_locked (struct mlx5_lag *ldev, +struct mlx5_core_dev *dev, +bool enable);struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp (struct mlx5_lag *ldev);#ifdef CONFIG_MLX5_ESWITCH
@@ -199,6 +202,6 @@ int mlx5_get_next_ldev_func(struct mlx5_lag *ldev, int start_idx);int mlx5_lag_get_dev_index_by_seq (struct mlx5_lag *ldev,int seq);int mlx5_lag_num_devs (struct mlx5_lag *ldev);int mlx5_lag_num_netdevs (struct mlx5_lag *ldev); -int mlx5_lag_reload_ib_reps (struct mlx5_lag *ldev,u32 flags, -bool cont_on_fail); +int mlx5_lag_reload_ib_reps_from_locked (struct mlx5_lag *ldev,u32 flags, +bool cont_on_fail);#endif /* __MLX5_LAG_H__ */
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +4 -6
@@ -100,9 +100,8 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev) goto err_add_devices; } - dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (dev0); - err =mlx5_lag_reload_ib_reps (ldev,0 , false); +mlx5_lag_rescan_dev_locked (ldev, dev0, true); + err =mlx5_lag_reload_ib_reps_from_locked (ldev,0 , false);if (err) goto err_rescan_drivers;
@@ -111,12 +110,11 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)return 0 ; err_rescan_drivers: - dev0->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_IB_ADEV ; -mlx5_rescan_drivers_locked (dev0); +mlx5_lag_rescan_dev_locked (ldev, dev0, false);mlx5_deactivate_lag (ldev); err_add_devices:mlx5_lag_add_devices (ldev); -mlx5_lag_reload_ib_reps (ldev,0 , true); +mlx5_lag_reload_ib_reps_from_locked (ldev,0 , true);mlx5_mpesw_metadata_cleanup (ldev);return err; }
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c +8 -0
@@ -3,6 +3,7 @@#include <linux/mlx5/vport.h> #include <linux/list.h> +#include <linux/lockdep.h> #include "lib/devcom.h" #include "lib/mlx5.h" #include "mlx5_core.h"
@@ -438,3 +439,10 @@ int mlx5_devcom_comp_trylock(struct mlx5_devcom_comp_dev *devcom)return 0 ;return down_write_trylock (&devcom->comp->sem); } + +void mlx5_devcom_comp_assert_locked (struct mlx5_devcom_comp_dev *devcom) +{ +if (!devcom) +return ; +lockdep_assert_held_write (&devcom->comp->sem); +}
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h +1 -0
@@ -75,5 +75,6 @@ void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom_comp_dev *devcom,void mlx5_devcom_comp_lock (struct mlx5_devcom_comp_dev *devcom);void mlx5_devcom_comp_unlock (struct mlx5_devcom_comp_dev *devcom);int mlx5_devcom_comp_trylock (struct mlx5_devcom_comp_dev *devcom); +void mlx5_devcom_comp_assert_locked (struct mlx5_devcom_comp_dev *devcom);#endif /* __LIB_MLX5_DEVCOM_H__ */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1434/2077 net/mlx5: LAG, factor out shared FDB code into dedicated file
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit cf6c4c0508a9a3858203b726bd3a3f9557449f67 ]
Refactor shared FDB LAG logic into a new lag/shared_fdb.c file to improve code organization and enable reuse. Move shared FDB specific functions from lag.c and introduce consolidated APIs:
- mlx5_lag_shared_fdb_create() handles LAG activation with shared FDB
- mlx5_lag_shared_fdb_destroy() handles LAG deactivation with shared FDB
Update mlx5_do_bond(), mlx5_disable_lag() and mpesw.c to use the new APIs, which simplifies the shared FDB code paths.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 156 ++++-------------- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 26 +++ .../ethernet/mellanox/mlx5/core/lag/mpesw.c | 25 +-- .../mellanox/mlx5/core/lag/shared_fdb.c | 143 ++++++++++++++++ 5 files changed, 210 insertions(+), 142 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -41,7 +41,7 @@ mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o en/port_buffer.o mlx5_core-$(CONFIG_PCI_HYPERV_INTERFACE) += en/hv_vhca_stats.o mlx5_core-$(CONFIG_MLX5_ESWITCH) += lag/mp.o lag/port_sel.o lib/geneve.o lib/port_tun.o \ en_rep.o en/rep/bond.o en/mod_hdr.o \ - en/mapping.o lag/mpesw.o + en/mapping.o lag/mpesw.o lag/shared_fdb.o mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en_tc.o en/rep/tc.o en/rep/neigh.o \ lib/fs_chains.o en/tc_tun.o \ esw/indir_table.o en/tc_tun_encap.o \
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +36 -120
194 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +26 -0
@@ -137,7 +137,33 @@ mlx5_lag_is_ready(struct mlx5_lag *ldev)return test_bit (MLX5_LAG_FLAG_NDEVS_READY , &ldev->state_flags); } +#ifdef CONFIG_MLX5_ESWITCH +int mlx5_lag_shared_fdb_create (struct mlx5_lag *ldev, +struct lag_tracker *tracker, +enum mlx5_lag_mode mode); +void mlx5_lag_shared_fdb_destroy (struct mlx5_lag *ldev); +int mlx5_lag_create_single_fdb (struct mlx5_lag *ldev);bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev); +#else +static inline int mlx5_lag_shared_fdb_create (struct mlx5_lag *ldev, +struct lag_tracker *tracker, +enum mlx5_lag_mode mode) +{ +return -EOPNOTSUPP ; +} + +static inline void mlx5_lag_shared_fdb_destroy (struct mlx5_lag *ldev) {} + +static inline int mlx5_lag_create_single_fdb (struct mlx5_lag *ldev) +{ +return -EOPNOTSUPP ; +} + +static inline bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev) +{ +return false; +} +#endif bool mlx5_lag_check_prereq (struct mlx5_lag *ldev);int mlx5_lag_demux_init (struct mlx5_core_dev *dev,struct mlx5_flow_table_attr *ft_attr);
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +4 -21
@@ -92,38 +92,21 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)if (err)return err; -mlx5_lag_remove_devices (ldev); - - err =mlx5_activate_lag (ldev,NULL ,MLX5_LAG_MODE_MPESW , true); + err =mlx5_lag_shared_fdb_create (ldev,NULL ,MLX5_LAG_MODE_MPESW );if (err) {mlx5_core_warn (dev0,"Failed to create LAG in MPESW mode (%d)\n" , err); - goto err_add_devices; +mlx5_mpesw_metadata_cleanup (ldev); +return err; } -mlx5_lag_rescan_dev_locked (ldev, dev0, true); - err =mlx5_lag_reload_ib_reps_from_locked (ldev,0 , false); -if (err) - goto err_rescan_drivers; - -mlx5_lag_set_vports_agg_speed (ldev); -return 0 ; - -err_rescan_drivers: -mlx5_lag_rescan_dev_locked (ldev, dev0, false); -mlx5_deactivate_lag (ldev); -err_add_devices: -mlx5_lag_add_devices (ldev); -mlx5_lag_reload_ib_reps_from_locked (ldev,0 , true); -mlx5_mpesw_metadata_cleanup (ldev); -return err; }void mlx5_lag_disable_mpesw (struct mlx5_lag *ldev) {if (ldev->mode ==MLX5_LAG_MODE_MPESW ) {mlx5_mpesw_metadata_cleanup (ldev); -mlx5_disable_lag (ldev); +mlx5_lag_shared_fdb_destroy (ldev); } }
drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1435/2077 net/mlx5: LAG, replace peer count check with direct peer lookup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit 2ca494dad9676301ecde1c9e214bfbf83d4c6326 ]
Replace mlx5_eswitch_get_npeers() count-based check with a new mlx5_eswitch_is_peer() function that directly verifies the peer relationship between two eswitches.
This change prepares for SD LAG support, which is a virtual LAG that does not have num_lag_ports capability and cannot use the count-based peer validation.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 11 ++--------- .../mellanox/mlx5/core/eswitch_offloads.c | 12 ++++++++++++ .../mellanox/mlx5/core/lag/shared_fdb.c | 17 +++++++---------- 3 files changed, 21 insertions(+), 19 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +2 -9
@@ -899,6 +899,8 @@ int mlx5_eswitch_offloads_single_fdb_add_one(struct mlx5_eswitch *master_esw,void mlx5_eswitch_offloads_single_fdb_del_one (struct mlx5_eswitch *master_esw,struct mlx5_eswitch *slave_esw);int mlx5_eswitch_reload_ib_reps (struct mlx5_eswitch *esw); +bool mlx5_eswitch_is_peer (struct mlx5_eswitch *esw, +struct mlx5_eswitch *peer_esw);bool mlx5_eswitch_block_encap (struct mlx5_core_dev *dev,bool from_fdb);void mlx5_eswitch_unblock_encap (struct mlx5_core_dev *dev);
@@ -914,13 +916,6 @@ static inline int mlx5_eswitch_num_vfs(struct mlx5_eswitch *esw)return 0 ; } -static inline int mlx5_eswitch_get_npeers (struct mlx5_eswitch *esw) -{ -if (mlx5_esw_allowed (esw)) -return esw->num_peers; -return 0 ; -} -static inline struct mlx5_flow_table *mlx5_eswitch_get_slow_fdb (struct mlx5_eswitch *esw) {
@@ -996,8 +991,6 @@ static inline void mlx5_eswitch_offloads_single_fdb_del_one(struct mlx5_eswitch *master_esw, struct mlx5_eswitch *slave_esw) {} -static inline int mlx5_eswitch_get_npeers (struct mlx5_eswitch *esw) {return 0 ; } -static inline int mlx5_eswitch_reload_ib_reps (struct mlx5_eswitch *esw) {
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +12 -0
@@ -3237,6 +3237,18 @@ static int mlx5_esw_offloads_set_ns_peer(struct mlx5_eswitch *esw,return 0 ; } +bool mlx5_eswitch_is_peer (struct mlx5_eswitch *esw, +struct mlx5_eswitch *peer_esw) +{ +u16 peer_esw_i; + +if (!mlx5_esw_allowed (esw) || !mlx5_esw_allowed (peer_esw)) +return false; + + peer_esw_i =MLX5_CAP_GEN (peer_esw->dev, vhca_id); +return !!xa_load (&esw->paired, peer_esw_i); +} +static int mlx5_esw_offloads_devcom_event (int event,void *my_data,void *event_data)
drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c +7 -10
@@ -10,7 +10,7 @@bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev) { -struct mlx5_core_dev *dev; +struct mlx5_core_dev *dev0, *dev;bool ret = false;int idx;int i;
@@ -19,6 +19,7 @@ bool mlx5_lag_shared_fdb_supported(struct mlx5_lag *ldev)if (idx <0 )return false; + dev0 =mlx5_lag_pf (ldev, idx)->dev;mlx5_ldev_for_each (i,0 , ldev) {if (i == idx)continue ;
@@ -27,19 +28,15 @@ bool mlx5_lag_shared_fdb_supported(struct mlx5_lag *ldev)mlx5_eswitch_vport_match_metadata_enabled (dev->priv.eswitch) &&MLX5_CAP_GEN (dev, lag_native_fdb_selection) &&MLX5_CAP_ESW (dev, root_ft_on_other_esw) && -mlx5_eswitch_get_npeers (dev->priv.eswitch) == - MLX5_CAP_GEN(dev, num_lag_ports) - 1) + mlx5_eswitch_is_peer(dev0->priv.eswitch, dev->priv.eswitch)) continue;return false; } - dev =mlx5_lag_pf (ldev, idx)->dev; -if (is_mdev_switchdev_mode (dev) && -mlx5_eswitch_vport_match_metadata_enabled (dev->priv.eswitch) && -mlx5_esw_offloads_devcom_is_ready (dev->priv.eswitch) && -MLX5_CAP_ESW (dev, esw_shared_ingress_acl) && -mlx5_eswitch_get_npeers (dev->priv.eswitch) == -MLX5_CAP_GEN (dev, num_lag_ports) -1 ) +if (is_mdev_switchdev_mode (dev0) && +mlx5_eswitch_vport_match_metadata_enabled (dev0->priv.eswitch) && +mlx5_esw_offloads_devcom_is_ready (dev0->priv.eswitch) && +MLX5_CAP_ESW (dev0, esw_shared_ingress_acl)) ret = true;return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1436/2077 net/mlx5: LAG, prepare for SD device integration
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit 14a47f55c8def9d677a4307bdce88b40255e8505 ]
Socket Direct (SD) secondaries devices will participate in LAG, even though they are silent. SD secondary devices share the same physical port as their primary but are separate PCI functions that need to be tracked alongside regular LAG ports.
Extend lag_func with a group_id field to identify SD group membership and introduce a unified iterator that can filter by group. Add APIs for registering SD secondary devices in an existing LAG.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 59 ++++++++++++++----- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 53 +++++++++++++++-- 2 files changed, 90 insertions(+), 22 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +43 -16
@@ -242,7 +242,7 @@ static void mlx5_ldev_free(struct kref *ref)unregister_netdevice_notifier_net (net, &ldev->nb); } -mlx5_ldev_for_each (i,0 , ldev) { +mlx5_lag_for_each (i,0 , ldev,MLX5_LAG_FILTER_ALL ) { pf =mlx5_lag_pf (ldev, i);if (pf->port_change_nb.nb.notifier_call) {struct mlx5_nb *nb = &pf->port_change_nb;
@@ -391,7 +391,7 @@ int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev)if (pf && pf->dev == dev)return 0 ; -mlx5_ldev_for_each (i,0 , ldev) { +mlx5_lag_for_each (i,0 , ldev,MLX5_LAG_FILTER_ALL ) {if (i == master_idx)continue ; pf =mlx5_lag_pf (ldev, i);
@@ -1034,7 +1034,7 @@ static void mlx5_lag_assert_locked_transition(struct mlx5_lag *ldev)lockdep_assert_held (&ldev->lock); - i =mlx5_get_next_ldev_func (ldev,0 ); + i =mlx5_get_next_lag_func (ldev,0 ,MLX5_LAG_FILTER_PORTS );if (i <MLX5_MAX_PORTS ) { pf =mlx5_lag_pf (ldev, i); devcom = pf->dev->priv.hca_devcom_comp;
@@ -1482,7 +1482,7 @@ struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp(struct mlx5_lag *ldev)int i;mutex_lock (&ldev->lock); - i =mlx5_get_next_ldev_func (ldev,0 ); + i =mlx5_get_next_lag_func (ldev,0 ,MLX5_LAG_FILTER_PORTS );if (i <MLX5_MAX_PORTS ) { pf =mlx5_lag_pf (ldev, i); devcom = pf->dev->priv.hca_devcom_comp;
@@ -1965,8 +1965,9 @@ static void mlx5_ldev_remove_netdev(struct mlx5_lag *ldev,spin_unlock_irqrestore (&lag_lock, flags); } -static int mlx5_ldev_add_mdev (struct mlx5_lag *ldev, -struct mlx5_core_dev *dev) +int mlx5_ldev_add_mdev (struct mlx5_lag *ldev, +struct mlx5_core_dev *dev, +u32 group_id) {struct lag_func *pf;u32 idx;
@@ -1985,8 +1986,14 @@ static int mlx5_ldev_add_mdev(struct mlx5_lag *ldev, pf->idx = idx; pf->dev = dev; + pf->group_id = group_id; dev->priv.lag = ldev; +if (group_id) +return 0 ; + +xa_set_mark (&ldev->pfs, idx,MLX5_LAG_XA_MARK_PORT ); +MLX5_NB_INIT (&pf->port_change_nb, mlx5_lag_mpesw_port_change_event,PORT_CHANGE );mlx5_eq_notifier_register (dev, &pf->port_change_nb);
@@ -1994,13 +2001,13 @@ static int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,return 0 ; } -static void mlx5_ldev_remove_mdev (struct mlx5_lag *ldev, -struct mlx5_core_dev *dev) +void mlx5_ldev_remove_mdev (struct mlx5_lag *ldev, +struct mlx5_core_dev *dev) {struct lag_func *pf;int i; -mlx5_ldev_for_each (i,0 , ldev) { +mlx5_lag_for_each (i,0 , ldev,MLX5_LAG_FILTER_ALL ) { pf =mlx5_lag_pf (ldev, i);if (pf->dev == dev)break ;
@@ -2035,7 +2042,7 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)mlx5_core_err (dev,"Failed to alloc lag dev\n" );return 0 ; } - err =mlx5_ldev_add_mdev (ldev, dev); + err =mlx5_ldev_add_mdev (ldev, dev,0 );if (err) {mlx5_core_err (dev,"Failed to add mdev to lag dev\n" );mlx5_ldev_put (ldev);
@@ -2050,7 +2057,7 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)return -EAGAIN ; }mlx5_ldev_get (ldev); - err =mlx5_ldev_add_mdev (ldev, dev); + err =mlx5_ldev_add_mdev (ldev, dev,0 );if (err) {mlx5_ldev_put (ldev);mutex_unlock (&ldev->lock);
@@ -2187,27 +2194,47 @@ void mlx5_lag_add_netdev(struct mlx5_core_dev *dev,mlx5_queue_bond_work (ldev,0 ); } -int mlx5_get_pre_ldev_func (struct mlx5_lag *ldev,int start_idx,int end_idx) +int mlx5_get_pre_lag_func (struct mlx5_lag *ldev,int start_idx,int end_idx, +u32 filter) {struct lag_func *pf;int i;for (i = start_idx; i >= end_idx; i--) { pf =xa_load (&ldev->pfs, i); -if (pf && pf->dev) +if (!pf || !pf->dev) +continue ; +if (filter ==MLX5_LAG_FILTER_PORTS ) { +if (xa_get_mark (&ldev->pfs, i,MLX5_LAG_XA_MARK_PORT )) +return i; + }else if (filter ==MLX5_LAG_FILTER_ALL || + filter == pf->group_id) {return i; + } }return -1 ; } -int mlx5_get_next_ldev_func (struct mlx5_lag *ldev,int start_idx) +int mlx5_get_next_lag_func (struct mlx5_lag *ldev,int start_idx,u32 filter) {struct lag_func *pf;unsigned long idx; -xa_for_each_start (&ldev->pfs, idx, pf, start_idx) -if (pf->dev) +if (filter ==MLX5_LAG_FILTER_PORTS ) { +xa_for_each_marked_start (&ldev->pfs, idx, pf, +MLX5_LAG_XA_MARK_PORT , start_idx) +if (pf->dev) +return idx; +return MLX5_MAX_PORTS ; + } + +xa_for_each_start (&ldev->pfs, idx, pf, start_idx) { +if (!pf->dev) +continue ; +if (filter ==MLX5_LAG_FILTER_ALL || + filter == pf->group_id)return idx; + }return MLX5_MAX_PORTS ; }
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +47 -6
85 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1437/2077 net/mlx5: LAG, extend shared FDB API with group_id filter
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit 3cbce590b7f2e9f056ed803a05f9ee09ac4a49a7 ]
Add a group_id parameter to mlx5_lag_shared_fdb_create() and mlx5_lag_shared_fdb_destroy() to scope shared FDB operations to a specific SD group.
When group_id is U32_MAX, the functions operate on all LAG devices. When group_id is non-zero, they operate only on devices in that SD group without issuing FW LAG commands, since SD LAG is a pure software construct.
Stable-dep-of: 0f0e4ae6975c ("net/mlx5: LAG, Fix off-by-one in single-FDB error rollback")
--- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 195 ++++++++++++++---- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 32 ++- .../ethernet/mellanox/mlx5/core/lag/mpesw.c | 7 +- .../mellanox/mlx5/core/lag/shared_fdb.c | 153 +++++++++++--- .../net/ethernet/mellanox/mlx5/core/lib/sd.c | 10 + .../net/ethernet/mellanox/mlx5/core/lib/sd.h | 10 + 6 files changed, 324 insertions(+), 83 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +151 -44
@@ -370,6 +370,22 @@ int mlx5_lag_get_dev_index_by_seq(struct mlx5_lag *ldev, int seq)return -ENOENT ; } +/* Return the appropriate iterator filter for a device in LAG: +* - SD shared FDB active: iterate only the device's SD group +* - SD group exists but shared FDB not active: iterate all devices +* - No SD: iterate ports only +*/ +static u32 mlx5_lag_get_filter (struct mlx5_lag *ldev,struct mlx5_core_dev *dev) +{ +struct lag_func *pf =mlx5_lag_pf_by_dev (ldev, dev); + +if (pf && pf->sd_fdb_active) +return pf->group_id; +if (pf && pf->group_id) +return MLX5_LAG_FILTER_ALL ; +return MLX5_LAG_FILTER_PORTS ; +} +/* Reverse of mlx5_lag_get_dev_index_by_seq: given a device, return its * sequence number in the LAG. Master is always 0, others numbered * sequentially starting from 1.
@@ -379,11 +395,13 @@ int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev)struct mlx5_lag *ldev =mlx5_lag_dev (dev);int master_idx, i, num =1 ;struct lag_func *pf; +u32 filter;if (!ldev)return -ENOENT ; - master_idx =mlx5_lag_get_master_idx (ldev); + filter =mlx5_lag_get_filter (ldev, dev); + master_idx =mlx5_lag_get_dev_index_by_seq_filter (ldev,0 , filter);if (master_idx <0 )return -ENOENT ;
@@ -391,7 +409,7 @@ int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev)if (pf && pf->dev == dev)return 0 ; -mlx5_lag_for_each (i,0 , ldev,MLX5_LAG_FILTER_ALL ) { +mlx5_lag_for_each (i,0 , ldev, filter) {if (i == master_idx)continue ; pf =mlx5_lag_pf (ldev, i);
@@ -403,6 +421,69 @@ int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev) }EXPORT_SYMBOL (mlx5_lag_get_dev_seq); +/* seq 0 = master, then all remaining devices */ +static int mlx5_lag_get_dev_index_by_seq_all (struct mlx5_lag *ldev,int seq) +{ +int master_idx, i, num =0 ; + + master_idx =mlx5_lag_get_master_idx (ldev); + +if (master_idx >=0 ) { +if (seq ==0 ) +return master_idx; + num++; + } + +mlx5_lag_for_each (i,0 , ldev,MLX5_LAG_FILTER_ALL ) { +if (i == master_idx) +continue ; +if (num == seq) +return i; + num++; + } +return -ENOENT ; +} + +/* From group POV, port-marked entry is the lag master */ +static int mlx5_lag_get_dev_index_by_seq_group (struct mlx5_lag *ldev,int seq, +u32 group_id) +{ +int i, num =0 ; + +mlx5_lag_for_each (i,0 , ldev, group_id) { +if (xa_get_mark (&ldev->pfs, i,MLX5_LAG_XA_MARK_PORT )) { +if (seq ==0 ) +return i; + num++; +break ; + } + } + +mlx5_lag_for_each (i,0 , ldev, group_id) { +if (xa_get_mark (&ldev->pfs, i,MLX5_LAG_XA_MARK_PORT )) +continue ; +if (num == seq) +return i; + num++; + } +return -ENOENT ; +} + +int mlx5_lag_get_dev_index_by_seq_filter (struct mlx5_lag *ldev,int seq, +u32 filter) +{ +if (!ldev) +return -ENOENT ; + +if (!filter || filter ==MLX5_LAG_FILTER_PORTS ) +return mlx5_lag_get_dev_index_by_seq (ldev, seq); + +if (filter ==MLX5_LAG_FILTER_ALL ) +return mlx5_lag_get_dev_index_by_seq_all (ldev, seq); + +return mlx5_lag_get_dev_index_by_seq_group (ldev, seq, filter); +} +/* Devcom events for LAG master marking */ #define LAG_DEVCOM_PAIR (0)#define LAG_DEVCOM_UNPAIR (1)
@@ -512,6 +593,14 @@ static bool __mlx5_lag_is_sriov(struct mlx5_lag *ldev)return ldev->mode ==MLX5_LAG_MODE_SRIOV ; } +static bool __mlx5_lag_is_sd_active (struct mlx5_lag *ldev, +struct mlx5_core_dev *dev) +{ +struct lag_func *pf =mlx5_lag_pf_by_dev (ldev, dev); + +return pf && pf->sd_fdb_active; +} +/* Create a mapping between steering slots and active ports. * As we have ldev->buckets slots per port first assume the native * mapping should be used.
@@ -927,27 +1016,19 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev)u32 in[MLX5_ST_SZ_DW (destroy_lag_in)] = {};bool roce_lag =__mlx5_lag_is_roce (ldev);unsigned long flags = ldev->mode_flags; -struct mlx5_eswitch *master_esw;struct mlx5_core_dev *dev0;int err; -int i;if (master_idx <0 )return -EINVAL ; dev0 =mlx5_lag_pf (ldev, master_idx)->dev; - master_esw = dev0->priv.eswitch; ldev->mode =MLX5_LAG_MODE_NONE ; ldev->mode_flags =0 ;mlx5_lag_mp_reset (ldev);if (test_bit (MLX5_LAG_MODE_FLAG_SHARED_FDB , &flags)) { -mlx5_ldev_for_each (i,0 , ldev) { -if (i == master_idx) -continue ; -mlx5_eswitch_offloads_single_fdb_del_one (master_esw, -mlx5_lag_pf (ldev, i)->dev->priv.eswitch); - } +mlx5_lag_destroy_single_fdb (ldev);clear_bit (MLX5_LAG_MODE_FLAG_SHARED_FDB , &flags); }
@@ -1026,7 +1107,7 @@ bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)return true; } -static void mlx5_lag_assert_locked_transition (struct mlx5_lag *ldev) +static void mlx5_lag_assert_locked_transition (struct mlx5_lag *ldev,u32 filter) {struct mlx5_devcom_comp_dev *devcom =NULL ;struct lag_func *pf;
@@ -1034,17 +1115,21 @@ static void mlx5_lag_assert_locked_transition(struct mlx5_lag *ldev)lockdep_assert_held (&ldev->lock); - i =mlx5_get_next_lag_func (ldev,0 ,MLX5_LAG_FILTER_PORTS ); + i =mlx5_get_next_lag_func (ldev,0 , filter);if (i <MLX5_MAX_PORTS ) { pf =mlx5_lag_pf (ldev, i); - devcom = pf->dev->priv.hca_devcom_comp; +if (filter ==MLX5_LAG_FILTER_PORTS || + filter ==MLX5_LAG_FILTER_ALL ) + devcom = pf->dev->priv.hca_devcom_comp; +else + devcom =mlx5_sd_get_devcom (pf->dev); }mlx5_devcom_comp_assert_locked (devcom); } -static void mlx5_lag_drop_lock_for_reps (struct mlx5_lag *ldev) +static void mlx5_lag_drop_lock_for_reps (struct mlx5_lag *ldev,u32 filter) { -mlx5_lag_assert_locked_transition (ldev); +mlx5_lag_assert_locked_transition (ldev, filter);/* Keep PF membership stable while ldev->lock is dropped. Device add * and remove paths observe mode_changes_in_progress and retry.
@@ -1075,21 +1160,22 @@ void mlx5_lag_rescan_dev_locked(struct mlx5_lag *ldev,* callbacks and take reps_lock. Drop ldev->lock so the only ordering * remains reps_lock -> ldev->lock from representor callbacks. */ -mlx5_lag_drop_lock_for_reps (ldev); +mlx5_lag_drop_lock_for_reps (ldev,mlx5_lag_get_filter (ldev, dev));mlx5_rescan_drivers_locked (dev);mlx5_lag_retake_lock_after_reps (ldev); } -static void mlx5_lag_rescan_devices_locked (struct mlx5_lag *ldev,bool enable) +static void mlx5_lag_rescan_devices_locked_filter (struct mlx5_lag *ldev, +bool enable,u32 filter) {struct mlx5_core_dev *devs[MLX5_MAX_PORTS ];struct lag_func *pf;int num_devs =0 ;int i; -mlx5_lag_assert_locked_transition (ldev); +mlx5_lag_assert_locked_transition (ldev, filter); -mlx5_ldev_for_each (i,0 , ldev) { +mlx5_lag_for_each (i,0 , ldev, filter) { pf =mlx5_lag_pf (ldev, i);if (pf->dev->priv.flags &MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV )continue ;
@@ -1101,30 +1187,40 @@ static void mlx5_lag_rescan_devices_locked(struct mlx5_lag *ldev, bool enable) devs[num_devs++] = pf->dev; } -mlx5_lag_drop_lock_for_reps (ldev); +mlx5_lag_drop_lock_for_reps (ldev, filter);for (i =0 ; i < num_devs; i++)mlx5_rescan_drivers_locked (devs[i]);mlx5_lag_retake_lock_after_reps (ldev); } +void mlx5_lag_add_devices_filter (struct mlx5_lag *ldev,u32 filter) +{ +mlx5_lag_rescan_devices_locked_filter (ldev, true, filter); +} +void mlx5_lag_add_devices (struct mlx5_lag *ldev) { -mlx5_lag_rescan_devices_locked (ldev, true); +mlx5_lag_add_devices_filter (ldev,MLX5_LAG_FILTER_PORTS ); +} + +void mlx5_lag_remove_devices_filter (struct mlx5_lag *ldev,u32 filter) +{ +mlx5_lag_rescan_devices_locked_filter (ldev, false, filter); }void mlx5_lag_remove_devices (struct mlx5_lag *ldev) { -mlx5_lag_rescan_devices_locked (ldev, false); +mlx5_lag_remove_devices_filter (ldev,MLX5_LAG_FILTER_PORTS ); }static int mlx5_lag_reload_ib_reps_unlocked (struct mlx5_lag *ldev,u32 flags, -bool cont_on_fail) +u32 filter,bool cont_on_fail) {struct lag_func *pf;int ret;int i; -mlx5_ldev_for_each (i,0 , ldev) { +mlx5_lag_for_each (i,0 , ldev, filter) { pf =mlx5_lag_pf (ldev, i);if (!(pf->dev->priv.flags & flags)) {struct mlx5_eswitch *esw;
@@ -1142,7 +1238,7 @@ static int mlx5_lag_reload_ib_reps_unlocked(struct mlx5_lag *ldev, u32 flags, }static int mlx5_lag_reload_ib_reps (struct mlx5_lag *ldev,u32 flags, -bool cont_on_fail) +u32 filter,bool cont_on_fail) {int ret;
@@ -1152,21 +1248,18 @@ static int mlx5_lag_reload_ib_reps(struct mlx5_lag *ldev, u32 flags,* load/unload callbacks can re-enter LAG netdev add/remove and take * ldev->lock. Keep the ordering reps_lock -> ldev->lock. */ -mlx5_lag_drop_lock_for_reps (ldev); - ret =mlx5_lag_reload_ib_reps_unlocked (ldev, flags, cont_on_fail); +mlx5_lag_drop_lock_for_reps (ldev, filter); + ret =mlx5_lag_reload_ib_reps_unlocked (ldev, flags, filter, + cont_on_fail);mlx5_lag_retake_lock_after_reps (ldev);return ret; }int mlx5_lag_reload_ib_reps_from_locked (struct mlx5_lag *ldev,u32 flags, -bool cont_on_fail) +u32 filter,bool cont_on_fail) { -int ret; - - ret =mlx5_lag_reload_ib_reps (ldev, flags, cont_on_fail); - -return ret; +return mlx5_lag_reload_ib_reps (ldev, flags, filter, cont_on_fail); }void mlx5_disable_lag (struct mlx5_lag *ldev)
@@ -1182,7 +1275,7 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)return ;if (shared_fdb) { -mlx5_lag_shared_fdb_destroy (ldev); +mlx5_lag_shared_fdb_destroy (ldev,0 );return ; }
@@ -1420,7 +1513,8 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)if (shared_fdb) { err =mlx5_lag_shared_fdb_create (ldev, &tracker, -MLX5_LAG_MODE_SRIOV ); +MLX5_LAG_MODE_SRIOV , +0 );if (err)return ; }else {
@@ -2261,7 +2355,8 @@ bool mlx5_lag_is_active(struct mlx5_core_dev *dev)spin_lock_irqsave (&lag_lock, flags); ldev =mlx5_lag_dev (dev); - res = ldev &&__mlx5_lag_is_active (ldev); + res = ldev && (__mlx5_lag_is_active (ldev) || +__mlx5_lag_is_sd_active (ldev, dev));spin_unlock_irqrestore (&lag_lock, flags);return res;
@@ -2294,10 +2389,17 @@ bool mlx5_lag_is_master(struct mlx5_core_dev *dev)spin_lock_irqsave (&lag_lock, flags); ldev =mlx5_lag_dev (dev); - idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 ); -if (ldev &&__mlx5_lag_is_active (ldev) && idx >=0 ) { - pf =mlx5_lag_pf (ldev, idx); - res = pf && dev == pf->dev; +if (ldev) { +u32 filter; + + filter =mlx5_lag_get_filter (ldev, dev); + idx =mlx5_lag_get_dev_index_by_seq_filter (ldev,MLX5_LAG_P1 , + filter); +if ((__mlx5_lag_is_active (ldev) || +__mlx5_lag_is_sd_active (ldev, dev)) && idx >=0 ) { + pf =mlx5_lag_pf (ldev, idx); + res = pf && dev == pf->dev; + } }spin_unlock_irqrestore (&lag_lock, flags);
@@ -2324,11 +2426,16 @@ bool mlx5_lag_is_shared_fdb(struct mlx5_core_dev *dev) {struct mlx5_lag *ldev;unsigned long flags; -bool res; +bool res = false;spin_lock_irqsave (&lag_lock, flags); ldev =mlx5_lag_dev (dev); - res = ldev &&test_bit (MLX5_LAG_MODE_FLAG_SHARED_FDB , &ldev->mode_flags); +if (ldev) { + res =test_bit (MLX5_LAG_MODE_FLAG_SHARED_FDB , + &ldev->mode_flags); +if (__mlx5_lag_is_sd (ldev, dev) && !__mlx5_lag_is_active (ldev)) + res =__mlx5_lag_is_sd_active (ldev, dev); + }spin_unlock_irqrestore (&lag_lock, flags);return res;
@@ -2429,7 +2536,7 @@ struct mlx5_core_dev *mlx5_lag_get_next_peer_mdev(struct mlx5_core_dev *dev, intif (*i ==MLX5_MAX_PORTS ) goto unlock; -mlx5_ldev_for_each (idx, *i, ldev) { +mlx5_lag_for_each (idx, *i, ldev,mlx5_lag_get_filter (ldev, dev)) { pf =mlx5_lag_pf (ldev, idx);if (pf->dev != dev)break ;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +25 -7
@@ -148,6 +148,14 @@ mlx5_lag_pf_by_dev(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)return NULL ; } +static inline bool +__mlx5_lag_is_sd (struct mlx5_lag *ldev,struct mlx5_core_dev *dev) +{ +struct lag_func *pf =mlx5_lag_pf_by_dev (ldev, dev); + +return pf && pf->group_id !=0 ; +} +static inline bool __mlx5_lag_is_active (struct mlx5_lag *ldev) {
@@ -163,25 +171,31 @@ mlx5_lag_is_ready(struct mlx5_lag *ldev)#ifdef CONFIG_MLX5_ESWITCH int mlx5_lag_shared_fdb_create (struct mlx5_lag *ldev,struct lag_tracker *tracker, -enum mlx5_lag_mode mode); -void mlx5_lag_shared_fdb_destroy (struct mlx5_lag *ldev); +enum mlx5_lag_mode mode, +u32 group_id); +void mlx5_lag_shared_fdb_destroy (struct mlx5_lag *ldev,u32 group_id);int mlx5_lag_create_single_fdb (struct mlx5_lag *ldev); +void mlx5_lag_destroy_single_fdb (struct mlx5_lag *ldev);bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev); +bool mlx5_lag_shared_fdb_supported_filter (struct mlx5_lag *ldev,u32 filter);#else static inline int mlx5_lag_shared_fdb_create (struct mlx5_lag *ldev,struct lag_tracker *tracker, -enum mlx5_lag_mode mode) +enum mlx5_lag_mode mode, +u32 group_id) {return -EOPNOTSUPP ; } -static inline void mlx5_lag_shared_fdb_destroy (struct mlx5_lag *ldev) {} +static inline void mlx5_lag_shared_fdb_destroy (struct mlx5_lag *ldev, +u32 group_id) {}static inline int mlx5_lag_create_single_fdb (struct mlx5_lag *ldev) {return -EOPNOTSUPP ; } +static inline void mlx5_lag_destroy_single_fdb (struct mlx5_lag *ldev) {}static inline bool mlx5_lag_shared_fdb_supported (struct mlx5_lag *ldev) {return false;
@@ -211,11 +225,13 @@ void mlx5_ldev_add_debugfs(struct mlx5_core_dev *dev);void mlx5_ldev_remove_debugfs (struct dentry *dbg);void mlx5_disable_lag (struct mlx5_lag *ldev);void mlx5_lag_remove_devices (struct mlx5_lag *ldev); +void mlx5_lag_remove_devices_filter (struct mlx5_lag *ldev,u32 filter);int mlx5_deactivate_lag (struct mlx5_lag *ldev);void mlx5_lag_add_devices (struct mlx5_lag *ldev);void mlx5_lag_rescan_dev_locked (struct mlx5_lag *ldev,struct mlx5_core_dev *dev,bool enable); +void mlx5_lag_add_devices_filter (struct mlx5_lag *ldev,u32 filter);struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp (struct mlx5_lag *ldev);#ifdef CONFIG_MLX5_ESWITCH
@@ -238,8 +254,8 @@ static inline bool mlx5_lag_is_supported(struct mlx5_core_dev *dev) }/* Iterator filter constants for mlx5_lag_for_each() */ -#define MLX5_LAG_FILTER_ALL 0/* iterate ALL devices */ -#define MLX5_LAG_FILTER_PORTS U32_MAX/* iterate ports only (XA_MARK_PORT) */ +#define MLX5_LAG_FILTER_PORTS 0/* iterate ports only (XA_MARK_PORT) */ +#define MLX5_LAG_FILTER_ALL U32_MAX/* iterate ALL devices */ /* any other value = iterate devices with that specific group_id */ #define mlx5_lag_for_each (i, start_index, ldev, filter) \
@@ -264,10 +280,12 @@ int mlx5_get_pre_lag_func(struct mlx5_lag *ldev, int start_idx, int end_idx, u32 filter);int mlx5_get_next_lag_func (struct mlx5_lag *ldev,int start_idx,u32 filter);int mlx5_lag_get_dev_index_by_seq (struct mlx5_lag *ldev,int seq); +int mlx5_lag_get_dev_index_by_seq_filter (struct mlx5_lag *ldev,int seq, +u32 filter);int mlx5_lag_num_devs (struct mlx5_lag *ldev);int mlx5_lag_num_netdevs (struct mlx5_lag *ldev);int mlx5_lag_reload_ib_reps_from_locked (struct mlx5_lag *ldev,u32 flags, -bool cont_on_fail); +u32 filter,bool cont_on_fail);int mlx5_ldev_add_mdev (struct mlx5_lag *ldev,struct mlx5_core_dev *dev,u32 group_id);void mlx5_ldev_remove_mdev (struct mlx5_lag *ldev,struct mlx5_core_dev *dev);
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +4 -3
@@ -85,14 +85,15 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev) !MLX5_CAP_PORT_SELECTION (dev0, port_select_flow_table) || !MLX5_CAP_GEN (dev0, create_lag_when_not_master_up) || !mlx5_lag_check_prereq (ldev) || - !mlx5_lag_shared_fdb_supported(ldev)) + !mlx5_lag_shared_fdb_supported_filter(ldev, MLX5_LAG_FILTER_ALL)) return -EOPNOTSUPP; err =mlx5_mpesw_metadata_set (ldev);if (err)return err; - err =mlx5_lag_shared_fdb_create (ldev,NULL ,MLX5_LAG_MODE_MPESW ); + err =mlx5_lag_shared_fdb_create (ldev,NULL ,MLX5_LAG_MODE_MPESW , +MLX5_LAG_FILTER_ALL );if (err) {mlx5_core_warn (dev0,"Failed to create LAG in MPESW mode (%d)\n" , err);mlx5_mpesw_metadata_cleanup (ldev);
@@ -106,7 +107,7 @@ void mlx5_lag_disable_mpesw(struct mlx5_lag *ldev) {if (ldev->mode ==MLX5_LAG_MODE_MPESW ) {mlx5_mpesw_metadata_cleanup (ldev); -mlx5_lag_shared_fdb_destroy (ldev); +mlx5_lag_shared_fdb_destroy (ldev,MLX5_LAG_FILTER_ALL ); } }
drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c +124 -29
225 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c +10 -0
@@ -57,6 +57,16 @@ static struct mlx5_core_dev *mlx5_sd_get_primary(struct mlx5_core_dev *dev)return sd->primary ? dev : sd->primary_dev; } +struct mlx5_devcom_comp_dev *mlx5_sd_get_devcom (struct mlx5_core_dev *dev) +{ +struct mlx5_sd *sd =mlx5_get_sd (dev); + +if (!sd) +return NULL ; + +return sd->devcom; +} +struct mlx5_core_dev *mlx5_sd_primary_get_peer (struct mlx5_core_dev *primary,int idx) {
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.h +10 -0
@@ -21,6 +21,16 @@ void mlx5_sd_put_adev(struct auxiliary_device *actual_adev,int mlx5_sd_init (struct mlx5_core_dev *dev);void mlx5_sd_cleanup (struct mlx5_core_dev *dev); +#ifdef CONFIG_MLX5_CORE_EN +struct mlx5_devcom_comp_dev *mlx5_sd_get_devcom (struct mlx5_core_dev *dev); +#else +static inline struct mlx5_devcom_comp_dev * +mlx5_sd_get_devcom (struct mlx5_core_dev *dev) +{ +return NULL ; +} +#endif +#define mlx5_sd_for_each_dev_from_to (i, primary, ix_from, to, pos) \ for (i = ix_from; \ (pos = mlx5_sd_primary_get_peer(primary, i)) && pos != (to); i++)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1438/2077 net/mlx5: LAG, Fix off-by-one in single-FDB error rollback
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit 0f0e4ae6975c773f7854fc48932a267f6c79088f ]
On failure at index i, the reverse cleanup loop in mlx5_lag_create_single_fdb() starts from i, so the failed index itself is rolled back. That can operate on uninitialized state or double-tear-down a rule the add_one path already self-rolled-back.
Start the rollback from i - 1 so only successfully-installed entries are undone.
--- drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c +1 -1
@@ -78,7 +78,7 @@ static int mlx5_lag_create_single_fdb_filter(struct mlx5_lag *ldev, u32 filter) }return 0 ; err: -mlx5_lag_for_each_reverse (j, i,0 , ldev, filter) { +mlx5_lag_for_each_reverse (j, i -1 ,0 , ldev, filter) {struct mlx5_eswitch *slave_esw;if (j == master_idx)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1439/2077 net/mlx5: LAG, MPESW, Fix missing complete() on devcom error
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit d4b85f9a668b9c44216bb78daf4ec1a915cc92d1 ]
mlx5_mpesw_work() returned without calling complete() when mlx5_lag_get_devcom_comp() returned NULL. A caller that queued the work and waited on mpesww->comp would block indefinitely.
Funnel the early-return path through a new "complete" label so the waiter is always woken.
--- drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +5 -2
@@ -118,8 +118,10 @@ static void mlx5_mpesw_work(struct work_struct *work)struct mlx5_lag *ldev = mpesww->lag; devcom =mlx5_lag_get_devcom_comp (ldev); -if (!devcom) -return ; +if (!devcom) { + mpesww->result = -ENODEV ; + goto complete; + }mlx5_devcom_comp_lock (devcom);mutex_lock (&ldev->lock);
@@ -135,6 +137,7 @@ static void mlx5_mpesw_work(struct work_struct *work) unlock:mutex_unlock (&ldev->lock);mlx5_devcom_comp_unlock (devcom); +complete:complete (&mpesww->comp); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1440/2077 net/mlx5e: TC, skip peer flow cleanup when LAG seq is unavailable
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shay Drory <[email protected]>
[ Upstream commit 7bed4af0ced82948d660205efecd551ef8bc3912 ]
mlx5_lag_get_dev_seq() will return error when the peer isn't in the LAG or when no device is marked as master. Result bad memory access and kernel crash[1].
Hence, skip the peer when lookup fails.
Note: In case there are peer flows, they are cleaned before LAG cleared the master mark.
[1]
RIP: 0010:mlx5e_tc_del_fdb_peers_flow+0x3d/0x350 [mlx5_core] Call Trace: <TASK> mlx5e_tc_clean_fdb_peer_flows+0xc1/0x130 [mlx5_core] mlx5_esw_offloads_unpair+0x3a/0x400 [mlx5_core] mlx5_esw_offloads_devcom_event+0xee/0x360 [mlx5_core] mlx5_devcom_send_event+0x7a/0x140 [mlx5_core] mlx5_esw_offloads_devcom_cleanup+0x2f/0x90 [mlx5_core] mlx5e_tc_esw_cleanup+0x28/0xf0 [mlx5_core] mlx5e_rep_tc_cleanup+0x19/0x30 [mlx5_core] mlx5e_cleanup_uplink_rep_tx+0x36/0x40 [mlx5_core] mlx5e_cleanup_rep_tx+0x55/0x60 [mlx5_core] mlx5e_detach_netdev+0x96/0xf0 [mlx5_core] mlx5e_netdev_change_profile+0x5b/0x120 [mlx5_core] mlx5e_netdev_attach_nic_profile+0x1b/0x30 [mlx5_core] mlx5e_vport_rep_unload+0xdd/0x110 [mlx5_core] __esw_offloads_unload_rep+0x81/0xb0 [mlx5_core] mlx5_eswitch_unregister_vport_reps+0x1d7/0x220 [mlx5_core] mlx5e_rep_remove+0x22/0x30 [mlx5_core] device_release_driver_internal+0x194/0x1f0 bus_remove_device+0xe8/0x1b0 device_del+0x159/0x3c0 mlx5_rescan_drivers_locked+0xbc/0x2d0 [mlx5_core] mlx5_unregister_device+0x54/0x80 [mlx5_core] mlx5_uninit_one+0x73/0x130 [mlx5_core] remove_one+0x78/0xe0 [mlx5_core] pci_device_remove+0x39/0xa0
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +3 -0
@@ -5526,6 +5526,9 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw)mlx5_devcom_for_each_peer_entry (devcom, peer_esw, pos) { i =mlx5_lag_get_dev_seq (peer_esw->dev); +if (i <0 ) +continue ; +list_for_each_entry_safe (flow, tmp, &esw->offloads.peer_flows[i], peer[i])mlx5e_tc_del_fdb_peers_flow (flow); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1441/2077 drm/bridge: analogix_dp: Fix PE/VS value shift mismatch during link training
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damon Ding <[email protected]>
[ Upstream commit 6bb8898f702385d363dc2c513a1efa62807f8068 ]
VS/PE values returned by drm_dp_get_adjust_request_voltage() and drm_dp_get_adjust_request_pre_emphasis() are already encoded to their native DPCD register bit positions. However, DPCD_VOLTAGE_SWING_SET / DPCD_PRE_EMPHASIS_SET macros perform an extra internal shift. Feeding the raw offset-bearing values directly leads to overlapping bitfields and invalid lane training configuration, causing link training failures and black screen.
Add right shift using DP_TRAIN_*_SHIFT constants to strip the DPCD bit offsets before passing values to the SET macros and subsequent checks. Apply this fix for both clock recovery and adjust training code paths.
--- drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +4 -0
@@ -306,7 +306,9 @@ static void analogix_dp_get_adjust_training_lane(struct analogix_dp_device *dp, lane_count = dp->link_train.lane_count;for (lane =0 ; lane < lane_count; lane++) { voltage_swing =drm_dp_get_adjust_request_voltage (link_status, lane); + voltage_swing >>=DP_TRAIN_VOLTAGE_SWING_SHIFT ; pre_emphasis =drm_dp_get_adjust_request_pre_emphasis (link_status, lane); + pre_emphasis >>=DP_TRAIN_PRE_EMPHASIS_SHIFT ; training_lane =DPCD_VOLTAGE_SWING_SET (voltage_swing) |DPCD_PRE_EMPHASIS_SET (pre_emphasis);
@@ -352,7 +354,9 @@ static int analogix_dp_process_clock_recovery(struct analogix_dp_device *dp)for (lane =0 ; lane < lane_count; lane++) { training_lane =analogix_dp_get_lane_link_training (dp, lane); voltage_swing =drm_dp_get_adjust_request_voltage (link_status, lane); + voltage_swing >>=DP_TRAIN_VOLTAGE_SWING_SHIFT ; pre_emphasis =drm_dp_get_adjust_request_pre_emphasis (link_status, lane); + pre_emphasis >>=DP_TRAIN_PRE_EMPHASIS_SHIFT ;if (DPCD_VOLTAGE_SWING_GET (training_lane) == voltage_swing &&DPCD_PRE_EMPHASIS_GET (training_lane) == pre_emphasis)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1442/2077 net/mlx5e: Fix HV VHCA stats zero-sized buffer allocation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Liu <[email protected]>
[ Upstream commit 25f6b929c7e379cbea7cb8caa67b49b2d1efae17 ]
mlx5e_hv_vhca_stats_create() is called from mlx5e_nic_enable(), before mlx5e_open(). At that point priv->stats_nch is still zero, because it is only ever incremented in mlx5e_channel_stats_alloc(), which is reached only from mlx5e_open_channel().
mlx5e_hv_vhca_stats_buf_size() therefore returns 0, and kvzalloc(0, GFP_KERNEL) returns ZERO_SIZE_PTR ((void *)16) rather than NULL. The "if (!buf)" guard does not catch this, and mlx5e_hv_vhca_stats_create() completes "successfully" with priv->stats_agent.buf set to ZERO_SIZE_PTR.
Once channels are opened (priv->stats_nch > 0) and the hypervisor enables stats reporting, mlx5e_hv_vhca_stats_work() recomputes buf_len using the new non-zero stats_nch and calls memset(buf, 0, buf_len) on ZERO_SIZE_PTR, faulting at address 0x10.
Allocate the buffer based on priv->max_nch, which is set in mlx5e_priv_init() and is the upper bound on stats_nch:
- Add a separate helper mlx5e_hv_vhca_stats_buf_max_size() that returns sizeof(per_ring_stats) * max(max_nch, stats_nch), and use it for the kvzalloc() in mlx5e_hv_vhca_stats_create().
- Keep mlx5e_hv_vhca_stats_buf_size() (which returns based on stats_nch) for the worker's active payload size, so the wire format (block->rings = stats_nch) and the amount of data filled by mlx5e_hv_vhca_fill_stats() are unchanged.
The max(max_nch, stats_nch) guard handles the rare case where mlx5e_attach_netdev() recomputes max_nch downward across a detach/resume cycle while priv->stats_nch persists (mlx5e_detach_netdev does not call mlx5e_priv_cleanup, so stats_nch is only reset when the netdev is destroyed). Without the guard, the worker could compute buf_len from stats_nch and overrun the smaller buffer allocated based on the reduced max_nch.
Allocating a non-zero buffer also makes the kvzalloc() failure path in mlx5e_hv_vhca_stats_create() reachable for the first time: it returns early without (re)creating the agent. Clear priv->stats_agent.{agent,buf} in mlx5e_hv_vhca_stats_destroy() after freeing them, so that if a later create() bails out on this path, a subsequent teardown does not double-free the stale agent/buffer left from a previous enable/disable cycle.
This mirrors the existing mlx5e pattern of preallocating arrays of size max_nch (e.g. priv->channel_stats) and lazily populating entries up to stats_nch on demand.
--- .../net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c +9 -1
@@ -54,6 +54,12 @@ static int mlx5e_hv_vhca_stats_buf_size(struct mlx5e_priv *priv) priv->stats_nch); } +static int mlx5e_hv_vhca_stats_buf_max_size (struct mlx5e_priv *priv) +{ +return (sizeof (struct mlx5e_hv_vhca_per_ring_stats ) * +max (priv->max_nch, priv->stats_nch)); +} +static void mlx5e_hv_vhca_stats_work (struct work_struct *work) {struct mlx5e_hv_vhca_stats_agent *sagent;
@@ -122,7 +128,7 @@ static void mlx5e_hv_vhca_stats_cleanup(struct mlx5_hv_vhca_agent *agent)void mlx5e_hv_vhca_stats_create (struct mlx5e_priv *priv) { -int buf_len =mlx5e_hv_vhca_stats_buf_size (priv); +int buf_len =mlx5e_hv_vhca_stats_buf_max_size (priv);struct mlx5_hv_vhca_agent *agent; priv->stats_agent.buf =kvzalloc (buf_len,GFP_KERNEL );
@@ -155,5 +161,7 @@ void mlx5e_hv_vhca_stats_destroy(struct mlx5e_priv *priv)return ;mlx5_hv_vhca_agent_destroy (priv->stats_agent.agent); + priv->stats_agent.agent =NULL ;kvfree (priv->stats_agent.buf); + priv->stats_agent.buf =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1443/2077 net/mlx5e: Fix HV VHCA stats agent registration race
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Liu <[email protected]>
[ Upstream commit 89b25b5f46f488ea3b29b3444864c76944c9075b ]
mlx5e_hv_vhca_stats_create() registers the stats agent through mlx5_hv_vhca_agent_create(). The helper publishes the agent in hv_vhca->agents[type] under agents_lock and immediately schedules an asynchronous control invalidation on the HV VHCA workqueue before returning to mlx5e.
The asynchronous invalidation invokes the control agent's invalidate callback, which reads the hypervisor control block and forwards the command to mlx5e_hv_vhca_stats_control(). That callback may either:
- call cancel_delayed_work_sync(&priv->stats_agent.work), or
- call queue_delayed_work(priv->wq, &sagent->work, sagent->delay).
However, the delayed_work and priv->stats_agent.agent are only initialized after mlx5_hv_vhca_agent_create() returns to mlx5e:
agent = mlx5_hv_vhca_agent_create(...); /* publish + invalidate */
...
priv->stats_agent.agent = agent; /* too late */
INIT_DELAYED_WORK(&priv->stats_agent.work, ...); /* too late */If the asynchronous control path runs before the two assignments above, it can:
- Operate on an uninitialized delayed_work whose timer.function is NULL. queue_delayed_work() calls add_timer() unconditionally, so when the timer expires the timer softirq invokes a NULL function pointer.
- Re-initialize the timer later through INIT_DELAYED_WORK() while the timer is already enqueued in the timer wheel, corrupting the hlist (entry.pprev cleared while the previous bucket node still points at this entry).
- When the worker eventually runs, mlx5e_hv_vhca_stats_work() reads
sagent->agent (NULL) and dereferences it inside
mlx5_hv_vhca_agent_write().Fix this by:
- Initializing priv->stats_agent.work before invoking mlx5_hv_vhca_agent_create(), so the work is always in a valid state when the control callback observes it.
- Adding a struct mlx5_hv_vhca_agent **ctx_update out-parameter to mlx5_hv_vhca_agent_create(). The helper writes the agent pointer to *ctx_update before publishing into hv_vhca->agents[] and triggering the agents_update flow, so any callback subsequently invoked from that flow already sees a valid priv->stats_agent.agent. This avoids having the control callback participate in agent initialization.
While at it, access priv->stats_agent.agent with READ_ONCE()/WRITE_ONCE() for the cross-CPU access with the worker, and clear priv->stats_agent.buf on the agent_create() failure path.
--- .../mellanox/mlx5/core/en/hv_vhca_stats.c | 21 +++++++++++-------- .../ethernet/mellanox/mlx5/core/lib/hv_vhca.c | 8 +++++-- .../ethernet/mellanox/mlx5/core/lib/hv_vhca.h | 6 ++++-- 3 files changed, 22 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c +12 -9
@@ -73,7 +73,7 @@ static void mlx5e_hv_vhca_stats_work(struct work_struct *work) sagent = container_of(dwork, struct mlx5e_hv_vhca_stats_agent, work); priv = container_of(sagent, struct mlx5e_priv, stats_agent); buf_len =mlx5e_hv_vhca_stats_buf_size (priv); - agent = sagent->agent; + agent =READ_ONCE (sagent->agent); buf = sagent->buf;memset (buf,0 , buf_len);
@@ -135,11 +135,14 @@ void mlx5e_hv_vhca_stats_create(struct mlx5e_priv *priv)if (!priv->stats_agent.buf)return ; +INIT_DELAYED_WORK (&priv->stats_agent.work, mlx5e_hv_vhca_stats_work); + agent =mlx5_hv_vhca_agent_create (priv->mdev->hv_vhca,MLX5_HV_VHCA_AGENT_STATS , mlx5e_hv_vhca_stats_control,NULL , mlx5e_hv_vhca_stats_cleanup, - priv); + priv, + &priv->stats_agent.agent);if (IS_ERR_OR_NULL (agent)) {if (IS_ERR (agent))
@@ -148,20 +151,20 @@ void mlx5e_hv_vhca_stats_create(struct mlx5e_priv *priv) agent);kvfree (priv->stats_agent.buf); -return ; + priv->stats_agent.buf =NULL ; } - - priv->stats_agent.agent = agent; -INIT_DELAYED_WORK (&priv->stats_agent.work, mlx5e_hv_vhca_stats_work); }void mlx5e_hv_vhca_stats_destroy (struct mlx5e_priv *priv) { -if (IS_ERR_OR_NULL (priv->stats_agent.agent)) +struct mlx5_hv_vhca_agent *agent; + + agent =READ_ONCE (priv->stats_agent.agent); +if (IS_ERR_OR_NULL (agent))return ; -mlx5_hv_vhca_agent_destroy (priv->stats_agent.agent); - priv->stats_agent.agent =NULL ; +mlx5_hv_vhca_agent_destroy (agent); +WRITE_ONCE (priv->stats_agent.agent,NULL );kvfree (priv->stats_agent.buf); priv->stats_agent.buf =NULL ; }
drivers/net/ethernet/mellanox/mlx5/core/lib/hv_vhca.c +6 -2
@@ -190,7 +190,7 @@ mlx5_hv_vhca_control_agent_create(struct mlx5_hv_vhca *hv_vhca)return mlx5_hv_vhca_agent_create (hv_vhca,MLX5_HV_VHCA_AGENT_CONTROL ,NULL , mlx5_hv_vhca_control_agent_invalidate, -NULL ,NULL ); +NULL ,NULL ,NULL ); }static void mlx5_hv_vhca_control_agent_destroy (struct mlx5_hv_vhca_agent *agent)
@@ -256,7 +256,8 @@ mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca *hv_vhca,void (*invalidate)(struct mlx5_hv_vhca_agent *,u64 block_mask), void (*cleaup)(struct mlx5_hv_vhca_agent *agent), - void *priv) + void *priv, + struct mlx5_hv_vhca_agent **ctx_update) { struct mlx5_hv_vhca_agent *agent;
@@ -284,6 +285,9 @@ mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca *hv_vhca, agent->invalidate = invalidate; agent->cleanup = cleaup; +if (ctx_update) +WRITE_ONCE (*ctx_update, agent); +mutex_lock (&hv_vhca->agents_lock); hv_vhca->agents[type] = agent;mutex_unlock (&hv_vhca->agents_lock);
drivers/net/ethernet/mellanox/mlx5/core/lib/hv_vhca.h +4 -2
@@ -43,7 +43,8 @@ mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca *hv_vhca,void (*invalidate)(struct mlx5_hv_vhca_agent *,u64 block_mask), void (*cleanup)(struct mlx5_hv_vhca_agent *agent), - void *context); + void *context, + struct mlx5_hv_vhca_agent **ctx_update);void mlx5_hv_vhca_agent_destroy (struct mlx5_hv_vhca_agent *agent); int mlx5_hv_vhca_agent_write(struct mlx5_hv_vhca_agent *agent,
@@ -84,7 +85,8 @@ mlx5_hv_vhca_agent_create(struct mlx5_hv_vhca *hv_vhca,void (*invalidate)(struct mlx5_hv_vhca_agent *,u64 block_mask), void (*cleanup)(struct mlx5_hv_vhca_agent *agent), - void *context) + void *context, + struct mlx5_hv_vhca_agent **ctx_update) { return NULL; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1444/2077 net/mlx5e: Fix publication race for priv->channel_stats[]
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Liu <[email protected]>
[ Upstream commit 5a799714e8ca0bce9ea40694f49914cf1adbbaa9 ]
mlx5e_channel_stats_alloc() publishes a new entry to priv->channel_stats[] and then increments priv->stats_nch as a publication token, but neither store carries any memory barrier:
priv->channel_stats[ix] = kvzalloc_node(...); if (!priv->channel_stats[ix]) return -ENOMEM; priv->stats_nch++;
Concurrent readers compute the loop bound from priv->stats_nch and then dereference priv->channel_stats[i] using plain accesses, e.g.
for (i = 0; i < priv->stats_nch; i++) {
struct mlx5e_channel_stats *cs = priv->channel_stats[i];
... cs->rq.packets ...
}On weakly-ordered architectures (ARM, PowerPC, RISC-V) the writes to channel_stats[ix] and stats_nch may become visible to other CPUs out of program order. A reader can observe stats_nch == N while still seeing channel_stats[N-1] == NULL, leading to a NULL pointer dereference in the channel_stats loop.
This has been observed in production on BlueField-3 DPUs (arm64), where ovs-vswitchd queries netdev statistics over netlink during NIC bringup, racing mlx5e_open_channel() -> mlx5e_channel_stats_alloc() on another CPU:
Unable to handle kernel NULL pointer dereference at virtual address 0x840 Hardware name: BlueField-3 DPU pc : mlx5e_fold_sw_stats64+0x30/0x180 [mlx5_core] Call trace: mlx5e_fold_sw_stats64+0x30/0x180 [mlx5_core] dev_get_stats+0x50/0xc0 ovs_vport_get_stats+0x38/0xac [openvswitch] ovs_vport_cmd_fill_info+0x194/0x290 [openvswitch] ovs_vport_cmd_get+0xbc/0x10c [openvswitch] genl_family_rcv_msg_doit+0xd0/0x160 genl_rcv_msg+0xec/0x1f0 netlink_rcv_skb+0x64/0x130 genl_rcv+0x40/0x60 netlink_unicast+0x2fc/0x370 netlink_sendmsg+0x1dc/0x454 ... __arm64_sys_sendmsg+0x2c/0x40
Add mlx5e_stats_nch_write() and mlx5e_stats_nch_read() helpers in en.h that wrap the smp_store_release()/smp_load_acquire() pair on stats_nch. The release/acquire pair establishes the contract:
stats_nch == N => channel_stats[0..N-1] are visible and non-NULL.
Publish the stats_nch increment via mlx5e_stats_nch_write() in the writer (mlx5e_channel_stats_alloc()), and read stats_nch via mlx5e_stats_nch_read() in all readers: mlx5e RX/TX queue stats, mlx5e_get_base_stats(), ethtool channels stats, IPoIB stats, the sw_stats fold and the HV VHCA stats agent.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 12 ++++++++++++ .../ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c | 10 ++++++---- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 14 ++++++++------ drivers/net/ethernet/mellanox/mlx5/core/en_stats.c | 9 +++++---- .../net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c | 3 ++- 5 files changed, 33 insertions(+), 15 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +12 -0
@@ -987,6 +987,18 @@ struct mlx5e_priv {struct ethtool_fec_hist_range *fec_ranges; }; +static inline u16 mlx5e_stats_nch_read (const struct mlx5e_priv *priv) +{ +/* Pairs with smp_store_release in mlx5e_stats_nch_write(). */ +return smp_load_acquire (&priv->stats_nch); +} + +static inline void mlx5e_stats_nch_write (struct mlx5e_priv *priv,u16 n) +{ +/* Pairs with smp_load_acquire in mlx5e_stats_nch_read(). */ +smp_store_release (&priv->stats_nch, n); +} +struct mlx5e_dev {struct net_device *netdev;struct devlink_port dl_port;
drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c +6 -4
@@ -33,9 +33,10 @@ mlx5e_hv_vhca_fill_ring_stats(struct mlx5e_priv *priv, int ch,static void mlx5e_hv_vhca_fill_stats (struct mlx5e_priv *priv,void *data,int buf_len) { +u16 nch =mlx5e_stats_nch_read (priv);int ch, i =0 ; -for (ch =0 ; ch < priv->stats_nch; ch++) { +for (ch =0 ; ch < nch; ch++) {void *buf = data + i; if (WARN_ON_ONCE(buf +
@@ -50,8 +51,9 @@ static void mlx5e_hv_vhca_fill_stats(struct mlx5e_priv *priv, void *data,static int mlx5e_hv_vhca_stats_buf_size (struct mlx5e_priv *priv) { -return (sizeof (struct mlx5e_hv_vhca_per_ring_stats ) * - priv->stats_nch); +u16 nch =mlx5e_stats_nch_read (priv); + +return sizeof (struct mlx5e_hv_vhca_per_ring_stats ) * nch; }static int mlx5e_hv_vhca_stats_buf_max_size (struct mlx5e_priv *priv)
@@ -106,7 +108,7 @@ static void mlx5e_hv_vhca_stats_control(struct mlx5_hv_vhca_agent *agent, sagent = &priv->stats_agent; block->version =MLX5_HV_VHCA_STATS_VERSION ; - block->rings = priv->stats_nch; + block->rings =mlx5e_stats_nch_read (priv);if (!block->command) {cancel_delayed_work_sync (&priv->stats_agent.work);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +8 -6
@@ -2773,7 +2773,7 @@ static int mlx5e_channel_stats_alloc(struct mlx5e_priv *priv, int ix, int cpu) GFP_KERNEL, cpu_to_node(cpu));if (!priv->channel_stats[ix])return -ENOMEM ; - priv->stats_nch++; +mlx5e_stats_nch_write (priv, priv->stats_nch +1 );return 0 ; }
@@ -4043,9 +4043,10 @@ static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,void mlx5e_fold_sw_stats64 (struct mlx5e_priv *priv,struct rtnl_link_stats64 *s) { +u16 nch =mlx5e_stats_nch_read (priv);int i; -for (i =0 ; i < priv->stats_nch; i++) { +for (i =0 ; i < nch; i++) {struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i];struct mlx5e_rq_stats *xskrq_stats = &channel_stats->xskrq;struct mlx5e_rq_stats *rq_stats = &channel_stats->rq;
@@ -5489,7 +5490,7 @@ static void mlx5e_get_queue_stats_rx(struct net_device *dev, int i,struct mlx5e_rq_stats *xskrq_stats;struct mlx5e_rq_stats *rq_stats; -if (mlx5e_is_uplink_rep (priv) || !priv->stats_nch) +if (mlx5e_is_uplink_rep (priv) || !mlx5e_stats_nch_read (priv))return ; channel_stats = priv->channel_stats[i];
@@ -5508,7 +5509,7 @@ static void mlx5e_get_queue_stats_tx(struct net_device *dev, int i,struct mlx5e_priv *priv =netdev_priv (dev);struct mlx5e_sq_stats *sq_stats; -if (!priv->stats_nch) +if (!mlx5e_stats_nch_read (priv))return ;/* no special case needed for ptp htb etc since txq2sq_stats is kept up
@@ -5525,6 +5526,7 @@ static void mlx5e_get_base_stats(struct net_device *dev, struct netdev_queue_stats_tx *tx) {struct mlx5e_priv *priv =netdev_priv (dev); +u16 nch =mlx5e_stats_nch_read (priv);struct mlx5e_ptp *ptp_channel;int i, tc;
@@ -5533,7 +5535,7 @@ static void mlx5e_get_base_stats(struct net_device *dev, rx->bytes =0 ; rx->alloc_fail =0 ; -for (i = priv->channels.params.num_channels; i < priv->stats_nch; i++) { +for (i = priv->channels.params.num_channels; i < nch; i++) {struct netdev_queue_stats_rx rx_i = {0 };mlx5e_get_queue_stats_rx (dev, i, &rx_i);
@@ -5558,7 +5560,7 @@ static void mlx5e_get_base_stats(struct net_device *dev, tx->packets =0 ; tx->bytes =0 ; -for (i =0 ; i < priv->stats_nch; i++) { +for (i =0 ; i < nch; i++) {struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i];/* handle two cases:
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c +5 -4
@@ -516,6 +516,7 @@ static void mlx5e_stats_update_stats_rq_page_pool(struct mlx5e_channel *c)static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS (sw) {struct mlx5e_sw_stats *s = &priv->stats.sw; +u16 nch =mlx5e_stats_nch_read (priv);int i;memset (s,0 ,sizeof (*s));
@@ -523,7 +524,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(sw)for (i =0 ; i < priv->channels.num; i++)/* for active channels only */ mlx5e_stats_update_stats_rq_page_pool (priv->channels.c[i]); -for (i =0 ; i < priv->stats_nch; i++) { +for (i =0 ; i < nch; i++) {struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i];
@@ -2615,7 +2616,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(ptp) { return; }static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS (channels) { -int max_nch = priv->stats_nch; +int max_nch =mlx5e_stats_nch_read (priv);return (NUM_RQ_STATS * max_nch) + (NUM_CH_STATS * max_nch) +
@@ -2628,8 +2629,8 @@ static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(channels)static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS (channels) { +int max_nch =mlx5e_stats_nch_read (priv);bool is_xsk = priv->xsk.ever_used; -int max_nch = priv->stats_nch;int i, j, tc;for (i =0 ; i < max_nch; i++)
@@ -2661,8 +2662,8 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(channels)static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS (channels) { +int max_nch =mlx5e_stats_nch_read (priv);bool is_xsk = priv->xsk.ever_used; -int max_nch = priv->stats_nch;int i, j, tc;for (i =0 ; i < max_nch; i++)
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c +2 -1
@@ -135,10 +135,11 @@ void mlx5i_cleanup(struct mlx5e_priv *priv)static void mlx5i_grp_sw_update_stats (struct mlx5e_priv *priv) { +u16 nch =mlx5e_stats_nch_read (priv);struct rtnl_link_stats64 s = {};int i, j; -for (i =0 ; i < priv->stats_nch; i++) { +for (i =0 ; i < nch; i++) {struct mlx5e_channel_stats *channel_stats;struct mlx5e_rq_stats *rq_stats;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1445/2077 net: microchip: vcap: fix races on the shared Super VCAP block
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Emil Schulz Østergaard <[email protected]>
[ Upstream commit d7a8d500d7e42837bd8dce40cb52c97c6e8706a9 ]
The VCAP instances on a chip are not independent, yet they are locked independently. On sparx5 and lan969x the IS0 and IS2 instances are backed by the same Super VCAP hardware block and share its cache and command registers: every access drives the shared VCAP_SUPER_CTRL register and moves data through the shared cache registers.
Accessing one instance therefore races with accessing another. The per-instance admin->lock cannot prevent this, as each instance takes a different lock.
The locking issue is mostly disguised by the fact that the core usage of the vcap api runs under rtnl. However, the full rule dump in debugfs decodes rules straight from hardware (a READ command followed by a cache read) and runs outside rtnl, so it races a concurrent tc-flower rule write to another Super VCAP instance.
Besides corrupting the dump, the read repopulates the shared cache between the writers cache fill and its write command, so the writer commits the wrong data and corrupts the hardware entry.
Introduce vcap_lock() and vcap_unlock() helpers and route every rule lock site in the VCAP API and its debugfs code through them. Replace the per-instance admin->lock with a single mutex in struct vcap_control that serializes access to all instances. The helpers reach it through a new admin->vctrl back-pointer, and the clients initialise and destroy the control lock instead of a per-instance one.
No path holds more than one instance lock, so collapsing them onto a single mutex cannot self-deadlock.
--- .../microchip/lan966x/lan966x_vcap_impl.c | 5 +- .../microchip/sparx5/sparx5_vcap_impl.c | 5 +- .../net/ethernet/microchip/vcap/vcap_api.c | 72 +++++++++++-------- .../net/ethernet/microchip/vcap/vcap_api.h | 3 +- .../microchip/vcap/vcap_api_debugfs.c | 8 +-- .../microchip/vcap/vcap_api_debugfs_kunit.c | 3 +- .../ethernet/microchip/vcap/vcap_api_kunit.c | 3 +- .../microchip/vcap/vcap_api_private.h | 3 + 8 files changed, 60 insertions(+), 42 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c +3 -2
@@ -601,7 +601,6 @@ static void lan966x_vcap_admin_free(struct vcap_admin *admin)kfree (admin->cache.keystream);kfree (admin->cache.maskstream);kfree (admin->cache.actionstream); -mutex_destroy (&admin->lock);kfree (admin); }
@@ -615,7 +614,7 @@ lan966x_vcap_admin_alloc(struct lan966x *lan966x, struct vcap_control *ctrl,if (!admin)return ERR_PTR (-ENOMEM ); -mutex_init (&admin->lock); + admin->vctrl = ctrl;INIT_LIST_HEAD (&admin->list);INIT_LIST_HEAD (&admin->rules);INIT_LIST_HEAD (&admin->enabled);
@@ -721,6 +720,7 @@ int lan966x_vcap_init(struct lan966x *lan966x) ctrl->ops = &lan966x_vcap_ops;INIT_LIST_HEAD (&ctrl->list); +mutex_init (&ctrl->lock);for (int i =0 ; i <ARRAY_SIZE (lan966x_vcap_inst_cfg); ++i) { cfg = &lan966x_vcap_inst_cfg[i];
@@ -780,5 +780,6 @@ void lan966x_vcap_deinit(struct lan966x *lan966x)lan966x_vcap_admin_free (admin); } +mutex_destroy (&ctrl->lock);kfree (ctrl); }
drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c +3 -2
@@ -1930,7 +1930,6 @@ static void sparx5_vcap_admin_free(struct vcap_admin *admin) {if (!admin)return ; -mutex_destroy (&admin->lock);kfree (admin->cache.keystream);kfree (admin->cache.maskstream);kfree (admin->cache.actionstream);
@@ -1950,7 +1949,7 @@ sparx5_vcap_admin_alloc(struct sparx5 *sparx5, struct vcap_control *ctrl,INIT_LIST_HEAD (&admin->list);INIT_LIST_HEAD (&admin->rules);INIT_LIST_HEAD (&admin->enabled); -mutex_init (&admin->lock); + admin->vctrl = ctrl; admin->vtype = cfg->vtype; admin->vinst = cfg->vinst; admin->ingress = cfg->ingress;
@@ -2059,6 +2058,7 @@ int sparx5_vcap_init(struct sparx5 *sparx5) ctrl->ops = &sparx5_vcap_ops;INIT_LIST_HEAD (&ctrl->list); +mutex_init (&ctrl->lock);for (idx =0 ; idx <ARRAY_SIZE (sparx5_vcap_inst_cfg); ++idx) { cfg = &consts->vcaps_cfg[idx]; admin =sparx5_vcap_admin_alloc (sparx5, ctrl, cfg);
@@ -2097,5 +2097,6 @@ void sparx5_vcap_deinit(struct sparx5 *sparx5)list_del (&admin->list);sparx5_vcap_admin_free (admin); } +mutex_destroy (&ctrl->lock);kfree (ctrl); }
drivers/net/ethernet/microchip/vcap/vcap_api.c +41 -31
235 lines not on this page · raw message
drivers/net/ethernet/microchip/vcap/vcap_api.h +2 -1
@@ -164,7 +164,7 @@ struct vcap_admin {struct list_head list;/* for insertion in vcap_control */ struct list_head rules;/* list of rules */ struct list_head enabled;/* list of enabled ports */ -struct mutex lock;/* control access to rules */ +struct vcap_control *vctrl;/* the control instance owning this vcap */ enum vcap_type vtype;/* type of vcap */ int vinst;/* instance number within the same type */ int first_cid;/* first chain id in this vcap */
@@ -275,6 +275,7 @@ struct vcap_control {const struct vcap_info *vcaps;/* client supplied vcap models */ const struct vcap_statistics *stats;/* client supplied vcap stats */ struct list_head list;/* list of vcap instances */ + struct mutex lock; /* serialize access to all vcap instances */ };#endif /* __VCAP_API__ */
drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +4 -4
@@ -410,9 +410,9 @@ static int vcap_debugfs_show(struct seq_file *m, void *unused) };int ret; -mutex_lock (&info->admin->lock); +vcap_lock (info->admin); ret =vcap_show_admin (info->vctrl, info->admin, &out); -mutex_unlock (&info->admin->lock); +vcap_unlock (info->admin);return ret; }DEFINE_SHOW_ATTRIBUTE (vcap_debugfs);
@@ -427,9 +427,9 @@ static int vcap_raw_debugfs_show(struct seq_file *m, void *unused) };int ret; -mutex_lock (&info->admin->lock); +vcap_lock (info->admin); ret =vcap_show_admin_raw (info->vctrl, info->admin, &out); -mutex_unlock (&info->admin->lock); +vcap_unlock (info->admin);return ret; }DEFINE_SHOW_ATTRIBUTE (vcap_raw_debugfs);
drivers/net/ethernet/microchip/vcap/vcap_api_debugfs_kunit.c +2 -1
@@ -243,10 +243,11 @@ static void vcap_test_api_init(struct vcap_admin *admin) {/* Initialize the shared objects */ INIT_LIST_HEAD (&test_vctrl.list); +mutex_init (&test_vctrl.lock);INIT_LIST_HEAD (&admin->list);INIT_LIST_HEAD (&admin->rules);INIT_LIST_HEAD (&admin->enabled); -mutex_init (&admin->lock); + admin->vctrl = &test_vctrl;list_add_tail (&admin->list, &test_vctrl.list);memset (test_updateaddr,0 ,sizeof (test_updateaddr)); test_updateaddridx =0 ;
drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c +2 -1
@@ -233,10 +233,11 @@ static void vcap_test_api_init(struct vcap_admin *admin) {/* Initialize the shared objects */ INIT_LIST_HEAD (&test_vctrl.list); +mutex_init (&test_vctrl.lock);INIT_LIST_HEAD (&admin->list);INIT_LIST_HEAD (&admin->rules);INIT_LIST_HEAD (&admin->enabled); -mutex_init (&admin->lock); + admin->vctrl = &test_vctrl;list_add_tail (&admin->list, &test_vctrl.list);memset (test_updateaddr,0 ,sizeof (test_updateaddr)); test_updateaddridx =0 ;
drivers/net/ethernet/microchip/vcap/vcap_api_private.h +3 -0
@@ -50,6 +50,9 @@ struct vcap_stream_iter {/* Check that the control has a valid set of callbacks */ int vcap_api_check (struct vcap_control *ctrl); +/* Serialize access to the vcap instances of a control */ +void vcap_lock (struct vcap_admin *admin); +void vcap_unlock (struct vcap_admin *admin);/* Erase the VCAP cache area used or encoding and decoding */ void vcap_erase_cache (struct vcap_rule_internal *ri);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1446/2077 qede: fix off-by-one in BD ring consumption on build_skb failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shigeru Yoshida <[email protected]>
[ Upstream commit a0a558ca7e75b49e71f8c545c30e8c005e6e4e2f ]
qede_rx_build_skb() and qede_tpa_rx_build_skb() do not check for a NULL return from qede_build_skb(). When it returns NULL under memory pressure, the functions still consume a BD from the ring before returning NULL. The callers then recycle additional BDs, resulting in one extra BD being consumed (off-by-one). This desynchronizes the BD ring, which can corrupt DMA page reference counts and lead to SLUB freelist corruption.
Commit 4e910dbe3650 ("qede: confirm skb is allocated before using") added a NULL check inside qede_build_skb() to prevent a NULL pointer dereference, but did not address the missing NULL checks in the callers, making this off-by-one reachable.
Fix this by adding NULL checks for the return value of qede_build_skb() in both qede_rx_build_skb() and qede_tpa_rx_build_skb(), returning NULL immediately before any BD ring manipulation.
--- drivers/net/ethernet/qlogic/qede/qede_fp.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/qlogic/qede/qede_fp.c +5 -0
@@ -765,6 +765,9 @@ qede_tpa_rx_build_skb(struct qede_dev *edev,struct sk_buff *skb; skb =qede_build_skb (rxq, bd, len, pad); +if (unlikely (!skb)) +return NULL ; + bd->page_offset += rxq->rx_buf_seg_size;if (bd->page_offset ==PAGE_SIZE ) {
@@ -812,6 +815,8 @@ qede_rx_build_skb(struct qede_dev *edev, } skb =qede_build_skb (rxq, bd, len, pad); +if (unlikely (!skb)) +return NULL ;if (unlikely (qede_realloc_rx_buffer (rxq, bd))) {/* Incr page ref count to reuse on allocation failure so
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1447/2077 net: qualcomm: rmnet: validate MAP frame length before ingress parsing
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit f0f1887a9e30712a1df03e152dce6fb91344b1f3 ]
When ingress deaggregation is disabled, rmnet_map_ingress_handler() passes the skb straight to __rmnet_map_ingress_handler(), skipping the length validation that rmnet_map_deaggregate() performs on the aggregated path. The parser then dereferences the MAP header and csum header/trailer based on the on-wire pkt_len without checking skb->len, so a short frame is read out of bounds:
BUG: KASAN: slab-out-of-bounds in rmnet_map_checksum_downlink_packet Read of size 1 at addr ffff88801118ed00 by task exploit/147 Call Trace: ... rmnet_map_checksum_downlink_packet (drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c:413) __rmnet_map_ingress_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:96) rmnet_rx_handler (drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c:129) __netif_receive_skb_core.constprop.0 (net/core/dev.c:6089) netif_receive_skb (net/core/dev.c:6460) tun_get_user (drivers/net/tun.c:1955) tun_chr_write_iter (drivers/net/tun.c:2001) vfs_write (fs/read_write.c:688) ksys_write (fs/read_write.c:740) do_syscall_64 (arch/x86/entry/syscall_64.c:94) ...
Factor that validation out of rmnet_map_deaggregate() into rmnet_map_validate_packet_len() and run it on the no-aggregation path too. The MAP header is bounds-checked first, since this path can receive a frame shorter than the header.
--- .../ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +- .../net/ethernet/qualcomm/rmnet/rmnet_map.h | 1 + .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 72 ++++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-)
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +4 -1
@@ -126,7 +126,10 @@ rmnet_map_ingress_handler(struct sk_buff *skb,consume_skb (skb); }else { -__rmnet_map_ingress_handler (skb, port); +if (rmnet_map_validate_packet_len (skb, port)) +__rmnet_map_ingress_handler (skb, port); +else +kfree_skb (skb); } }
drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +1 -0
@@ -59,5 +59,6 @@ void rmnet_map_tx_aggregate_init(struct rmnet_port *port);void rmnet_map_tx_aggregate_exit (struct rmnet_port *port);void rmnet_map_update_ul_agg_config (struct rmnet_port *port,u32 size,u32 count,u32 time); +u32 rmnet_map_validate_packet_len (struct sk_buff *skb,struct rmnet_port *port);#endif /* _RMNET_MAP_H_ */
drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +40 -32
94 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1448/2077 net/sched: act_pedit: fix TOCTOU heap OOB write in tc offload
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 8b519cbcabe836a441369fbec1a8a6518a709251 ]
There is a TOCTOU race condition in flower lockless approach between sizing a flow_rule buffer and filling it. [email protected] reports:
The cls_flower classifier operates with TCF_PROTO_OPS_DOIT_UNLOCKED (fl_change runs without RTNL), while RTM_NEWACTION holds RTNL, so the independent locking domains make the race reachable in practice. KASAN confirms:
BUG: KASAN: slab-out-of-bounds in tcf_pedit_offload_act_setup+0x81b/0x930 Write of size 4 at addr ffff888001f27520 by task poc-toctou/312 The buggy address is located 0 bytes to the right of allocated 288-byte region [ffff888001f27400, ffff888001f27520) (cache kmalloc-512)
Note: The result is a heap OOB write attacker-controlled content into the adjacent slab object (requires CAP_NET_ADMIN).
The fix introduces reading tcfp_nkeys under act->tcfa_lock in all places using a new tcf_pedit_nkeys_locked() which replaces the old tcf_pedit_nkeys(). Additionally we close the remaining TOCTOU window between the sizing read and the fill reads by more careful accounting.
Rather than silently truncating the key count, which leads to incorrect action semantics offloaded to hardware and secondary OOB writes if the remaining capacity is zero or consumed by prior actions, we enforce remaining capacity checks and return -ENOSPC if the required space exceeds the remaining capacity.
--- include/net/tc_act/tc_pedit.h | 18 ++++++++---------- net/sched/act_api.c | 13 +++++++++---- net/sched/act_pedit.c | 13 +++++++++++-- net/sched/cls_api.c | 22 +++++++++++++++++----- 4 files changed, 45 insertions(+), 21 deletions(-)
include/net/tc_act/tc_pedit.h +8 -10
@@ -37,17 +37,15 @@ static inline bool is_tcf_pedit(const struct tc_action *a)return false; } -static inline int tcf_pedit_nkeys (const struct tc_action *a) +/* Must be called with act->tcfa_lock held to ensure consistency of parallel +* reads of the same action's pedit keys (e.g. flow_offload count vs fill). +* Note, this is only used for pedit offload. +*/ +static inline int tcf_pedit_nkeys_locked (const struct tc_action *a) { -struct tcf_pedit_parms *parms; -int nkeys; - -rcu_read_lock (); - parms =to_pedit_parms (a); - nkeys = parms->tcfp_nkeys; -rcu_read_unlock (); - -return nkeys; +lockdep_assert_held (&a->tcfa_lock); +return rcu_dereference_protected (to_pedit (a)->parms, +lockdep_is_held (&a->tcfa_lock))->tcfp_nkeys; }static inline u32 tcf_pedit_htype (const struct tc_action *a,int index)
net/sched/act_api.c +9 -4
@@ -148,10 +148,15 @@ static void offload_action_hw_count_dec(struct tc_action *act,static unsigned int tcf_offload_act_num_actions_single (struct tc_action *act) { -if (is_tcf_pedit (act)) -return tcf_pedit_nkeys (act); -else -return 1 ; +unsigned int count; + +if (is_tcf_pedit (act)) { +spin_lock_bh (&act->tcfa_lock); + count =tcf_pedit_nkeys_locked (act); +spin_unlock_bh (&act->tcfa_lock); +return count; + } +return 1 ; }static bool tc_act_skip_hw (u32 flags)
net/sched/act_pedit.c +11 -2
@@ -563,9 +563,18 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data, {if (bind) {struct flow_action_entry *entry = entry_data; +int nkeys =tcf_pedit_nkeys_locked (act);int k; -for (k =0 ; k <tcf_pedit_nkeys (act); k++) { +/* If the required keys exceed the remaining capacity return +* -ENOSPC to abort the offload and fallback to software. +*/ +if (nkeys > *index_inc) { +NL_SET_ERR_MSG_MOD (extack,"Not enough space to offload all pedit keys" ); +return -ENOSPC ; + } + +for (k =0 ; k < nkeys; k++) {switch (tcf_pedit_cmd (act, k)) {case TCA_PEDIT_KEY_EX_CMD_SET : entry->id =FLOW_ACTION_MANGLE ;
@@ -602,7 +611,7 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,return -EOPNOTSUPP ; } -for (k =1 ; k <tcf_pedit_nkeys (act); k++) { +for (k =1 ; k <tcf_pedit_nkeys_locked (act); k++) {if (cmd !=tcf_pedit_cmd (act, k)) {NL_SET_ERR_MSG_MOD (extack,"Unsupported pedit command offload" );return -EOPNOTSUPP ;
net/sched/cls_api.c +17 -5
@@ -3886,12 +3886,21 @@ int tc_setup_action(struct flow_action *flow_action, entry = &flow_action->entries[j];spin_lock_bh (&act->tcfa_lock); + +/* Abort the offload if we have exhausted the allocated capacity */ +if (j >= flow_action->num_entries) { +NL_SET_ERR_MSG_MOD (extack,"Flow action buffer overflow" ); + err = -ENOSPC ; + goto err_out_locked; + } + err =tcf_act_get_user_cookie (entry, act);if (err) goto err_out_locked; - index =0 ; - err =tc_setup_offload_act (act, entry, &index, extack); + index = flow_action->num_entries - j; + err =tc_setup_offload_act (act, entry, &index, + extack);if (err) goto err_out_locked;
@@ -3945,10 +3954,13 @@ unsigned int tcf_exts_num_actions(struct tcf_exts *exts)int i;tcf_exts_for_each_action (i, act, exts) { -if (is_tcf_pedit (act)) - num_acts +=tcf_pedit_nkeys (act); -else +if (is_tcf_pedit (act)) { +spin_lock_bh (&act->tcfa_lock); + num_acts +=tcf_pedit_nkeys_locked (act); +spin_unlock_bh (&act->tcfa_lock); + }else { num_acts++; + } }return num_acts; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1449/2077 net/smc: fix UAF in smc_cdc_rx_handler() by pinning the socket
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 9d160b35cc34a2ba8229d07651468a7848325135 ]
smc_cdc_rx_handler() looks up the connection by token under the link group's conns_lock, drops the lock, and then dereferences conn and the smc_sock derived from it, ending in sock_hold(&smc->sk) inside smc_cdc_msg_recv(). No reference is held across the lock release.
The only reference pinning the socket while the connection is discoverable in the link group is taken in smc_lgr_register_conn() (sock_hold) and dropped in __smc_lgr_unregister_conn() (sock_put), both under conns_lock. Once the handler drops conns_lock, a concurrent close() -> smc_release() -> smc_conn_free() -> smc_lgr_unregister_conn() can drop that reference and free the smc_sock, so the handler's later sock_hold() runs on freed memory:
WARNING: lib/refcount.c:25 at refcount_warn_saturate Workqueue: rxe_wq do_work refcount_warn_saturate (lib/refcount.c:25) smc_cdc_msg_recv (net/smc/smc_cdc.c:430) smc_cdc_rx_handler (net/smc/smc_cdc.c:502) smc_wr_rx_tasklet_fn (net/smc/smc_wr.c:445) tasklet_action_common (kernel/softirq.c:938) handle_softirqs (kernel/softirq.c:622) Kernel panic - not syncing: panic_on_warn set
Only SMC-R is affected. The SMC-D receive tasklet is stopped by tasklet_kill(&conn->rx_tsklet) in smc_conn_free() before the connection is unregistered, so it cannot run concurrently with the free.
Take the socket reference while still holding conns_lock, so the registration reference can no longer be the last one, and drop it once the handler is done.
--- net/smc/smc_cdc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
net/smc/smc_cdc.c +10 -5
@@ -470,9 +470,9 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf) {struct smc_link *link = (struct smc_link *)wc->qp->qp_context;struct smc_cdc_msg *cdc = buf; +struct smc_sock *smc =NULL ;struct smc_connection *conn;struct smc_link_group *lgr; -struct smc_sock *smc;if (wc->byte_len < offsetof(struct smc_cdc_msg , reserved))return ;/* short message */
@@ -483,21 +483,26 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf) lgr =smc_get_lgr (link);read_lock_bh (&lgr->conns_lock); conn =smc_lgr_find_conn (ntohl (cdc->token), lgr); -read_unlock_bh (&lgr->conns_lock); -if (!conn || conn->out_of_sync) +if (!conn || conn->out_of_sync) { +read_unlock_bh (&lgr->conns_lock);return ; + } smc = container_of(conn, struct smc_sock, conn); +sock_hold (&smc->sk); +read_unlock_bh (&lgr->conns_lock);if (cdc->prod_flags.failover_validation) {smc_cdc_msg_validate (smc, cdc, link); -return ; + goto out; }if (smc_cdc_before (ntohs (cdc->seqno), conn->local_rx_ctrl.seqno))/* received seqno is old */ -return ; + goto out;smc_cdc_msg_recv (smc, cdc); +out: +sock_put (&smc->sk); }static struct smc_wr_rx_handler smc_cdc_rx_handlers[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1450/2077 amt: fix size calculation in amt_get_size()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 9e05e91a9a847ed57926414bd7c2c5e54d6c56c6 ]
amt_get_size() incorrectly used sizeof(struct iphdr) for the sizes of IFLA_AMT_DISCOVERY_IP, IFLA_AMT_REMOTE_IP, and IFLA_AMT_LOCAL_IP. These attributes contain IPv4 addresses (__be32), not full IP headers.
Replace sizeof(struct iphdr) with sizeof(__be32) to avoid over-allocating netlink message space.
--- drivers/net/amt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/amt.c +3 -3
@@ -3301,9 +3301,9 @@ static size_t amt_get_size(const struct net_device *dev)nla_total_size (sizeof (__u16)) +/* IFLA_AMT_GATEWAY_PORT */ nla_total_size (sizeof (__u32)) +/* IFLA_AMT_LINK */ nla_total_size (sizeof (__u32)) +/* IFLA_MAX_TUNNELS */ -nla_total_size (sizeof (struct iphdr )) +/* IFLA_AMT_DISCOVERY_IP */ -nla_total_size (sizeof (struct iphdr )) +/* IFLA_AMT_REMOTE_IP */ -nla_total_size (sizeof (struct iphdr ));/* IFLA_AMT_LOCAL_IP */ +nla_total_size (sizeof (__be32)) +/* IFLA_AMT_DISCOVERY_IP */ +nla_total_size (sizeof (__be32)) +/* IFLA_AMT_REMOTE_IP */ +nla_total_size (sizeof (__be32));/* IFLA_AMT_LOCAL_IP */ }static int amt_fill_info (struct sk_buff *skb,const struct net_device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1451/2077 ksmbd: fix multichannel binding and enforce channel limit
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 4b706360ffb7e459cb3d3edae30b06a584f6eddd ]
A signed multichannel SESSION_SETUP binding request can require multiple authentication rounds. ksmbd excludes SESSION_SETUP from the signed request check and tries to sign every binding response with the channel signing key. The channel does not exist for STATUS_MORE_PROCESSING_REQUIRED, so that response is sent unsigned. Clients reject it with STATUS_ACCESS_DENIED.
The final channel signing key also needs the key exported by the binding authentication context. Keep that key in the channel instead of overwriting the established session key, and use the session signing key for intermediate and failed binding responses. Retain the binding session reference until an error response has been signed and sent.
Limit a session to 32 channels while holding the channel lock. Return STATUS_INSUFFICIENT_RESOURCES for an additional binding, matching the server limit expected by clients.
This fixes smb2.multichannel.generic.num_channels, which previously failed the first binding with STATUS_ACCESS_DENIED and returned the same status instead of STATUS_INSUFFICIENT_RESOURCES for channel 33.
--- fs/smb/server/auth.c | 47 +++++----- fs/smb/server/auth.h | 7 +- fs/smb/server/mgmt/user_session.c | 4 +- fs/smb/server/mgmt/user_session.h | 1 + fs/smb/server/smb2pdu.c | 142 +++++++++++++++++++----------- 5 files changed, 126 insertions(+), 75 deletions(-)
fs/smb/server/auth.c +27 -20
@@ -133,16 +133,17 @@ static int calc_ntlmv2_hash(struct ksmbd_conn *conn, struct ksmbd_session *sess,* @blen: NTLMv2 blob length * @domain_name: domain name * @cryptkey: session crypto key +* @sess_key: derived session key output buffer * * Return: 0 on success, error number on error */ int ksmbd_auth_ntlmv2 (struct ksmbd_conn *conn,struct ksmbd_session *sess,struct ntlmv2_resp *ntlmv2,int blen,char *domain_name, -char *cryptkey) +char *cryptkey,char *sess_key) {char ntlmv2_hash[CIFS_ENCPWD_SIZE ];char ntlmv2_rsp[CIFS_HMAC_MD5_HASH_SIZE ]; -char sess_key[SMB2_NTLMV2_SESSKEY_SIZE ]; +char base_key[SMB2_NTLMV2_SESSKEY_SIZE ];struct hmac_md5_ctx ctx;int rc;
@@ -165,7 +166,7 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,/* Generate the session key */ hmac_md5_usingrawkey (ntlmv2_hash,CIFS_HMAC_MD5_HASH_SIZE , ntlmv2_rsp,CIFS_HMAC_MD5_HASH_SIZE , - sess_key); + base_key);if (crypto_memneq (ntlmv2->ntlmv2_hash, ntlmv2_rsp,CIFS_HMAC_MD5_HASH_SIZE )) {
@@ -173,12 +174,12 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess, goto out; } -memcpy (sess->sess_key, sess_key,sizeof (sess_key)); +memcpy (sess_key, base_key,sizeof (base_key)); rc =0 ; out:memzero_explicit (ntlmv2_hash,sizeof (ntlmv2_hash));memzero_explicit (ntlmv2_rsp,sizeof (ntlmv2_rsp)); -memzero_explicit (sess_key,sizeof (sess_key)); +memzero_explicit (base_key,sizeof (base_key));return rc; }
@@ -189,12 +190,13 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,* @blob_len: length of the @authblob message * @conn: connection * @sess: session of connection +* @sess_key: derived session key output buffer * * Return: 0 on success, error number on error */ int ksmbd_decode_ntlmssp_auth_blob (struct authenticate_message *authblob,int blob_len,struct ksmbd_conn *conn, -struct ksmbd_session *sess) +struct ksmbd_session *sess,char *sess_key) {char *domain_name;unsigned int nt_off, dn_off;
@@ -234,7 +236,7 @@ int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob, ret =ksmbd_auth_ntlmv2 (conn, sess, (struct ntlmv2_resp *)((char *)authblob + nt_off), nt_len -CIFS_ENCPWD_SIZE , - domain_name, conn->ntlmssp.cryptkey); + domain_name, conn->ntlmssp.cryptkey, sess_key);kfree (domain_name);if (ret)return ret;
@@ -257,8 +259,8 @@ int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob,if (!ctx_arc4)return -ENOMEM ; -arc4_setkey (ctx_arc4, sess->sess_key,SMB2_NTLMV2_SESSKEY_SIZE ); -arc4_crypt (ctx_arc4, sess->sess_key, +arc4_setkey (ctx_arc4, sess_key,SMB2_NTLMV2_SESSKEY_SIZE ); +arc4_crypt (ctx_arc4, sess_key, (char *)authblob + sess_key_off, sess_key_len);kfree_sensitive (ctx_arc4); }
@@ -400,7 +402,8 @@ ksmbd_build_ntlmssp_challenge_blob(struct challenge_message *chgblob,#ifdef CONFIG_SMB_SERVER_KERBEROS5 int ksmbd_krb5_authenticate (struct ksmbd_session *sess,char *in_blob, -int in_len,char *out_blob,int *out_len) +int in_len,char *out_blob,int *out_len, +char *sess_key) {struct ksmbd_spnego_authen_response *resp;struct ksmbd_login_response_ext *resp_ext =NULL ;
@@ -455,7 +458,7 @@ int ksmbd_krb5_authenticate(struct ksmbd_session *sess, char *in_blob,ksmbd_free_user (user); } -memcpy (sess->sess_key, resp->payload, resp->session_key_len); +memcpy (sess_key, resp->payload, resp->session_key_len);memcpy (out_blob, resp->payload + resp->session_key_len, resp->spnego_blob_len); *out_len = resp->spnego_blob_len;
@@ -466,7 +469,8 @@ int ksmbd_krb5_authenticate(struct ksmbd_session *sess, char *in_blob, }#else int ksmbd_krb5_authenticate (struct ksmbd_session *sess,char *in_blob, -int in_len,char *out_blob,int *out_len) +int in_len,char *out_blob,int *out_len, +char *sess_key) {return -EOPNOTSUPP ; }
@@ -525,7 +529,7 @@ struct derivation {bool binding; }; -static void generate_key (struct ksmbd_conn *conn,struct ksmbd_session *sess, +static void generate_key (struct ksmbd_conn *conn,const char *sess_key,struct kvec label,struct kvec context,__u8 *key,unsigned int key_size) {
@@ -536,7 +540,7 @@ static void generate_key(struct ksmbd_conn *conn, struct ksmbd_session *sess,unsigned char prfhash[SMB2_HMACSHA256_SIZE ];struct hmac_sha256_ctx ctx; -hmac_sha256_init_usingrawkey (&ctx, sess->sess_key, +hmac_sha256_init_usingrawkey (&ctx, sess_key,SMB2_NTLMV2_SESSKEY_SIZE );hmac_sha256_update (&ctx, i,4 );hmac_sha256_update (&ctx, label.iov_base, label.iov_len);
@@ -559,18 +563,21 @@ static int generate_smb3signingkey(struct ksmbd_session *sess, const struct derivation *signing) {struct channel *chann; -char *key; +char *key, *sess_key; chann =lookup_chann_list (sess, conn);if (!chann)return 0 ; -if (conn->dialect >=SMB30_PROT_ID && signing->binding) +if (conn->dialect >=SMB30_PROT_ID && signing->binding) { key = chann->smb3signingkey; -else + sess_key = chann->sess_key; + }else { key = sess->smb3signingkey; + sess_key = sess->sess_key; + } -generate_key (conn, sess, signing->label, signing->context, key, +generate_key (conn, sess_key, signing->label, signing->context, key,SMB3_SIGN_KEY_SIZE );if (!(conn->dialect >=SMB30_PROT_ID && signing->binding))
@@ -627,11 +634,11 @@ static void generate_smb3encryptionkey(struct ksmbd_conn *conn,struct ksmbd_session *sess, const struct derivation_twin *ptwin) { - generate_key(conn, sess, ptwin->encryption.label, + generate_key(conn, sess->sess_key, ptwin->encryption.label, ptwin->encryption.context, sess->smb3encryptionkey,SMB3_ENC_DEC_KEY_SIZE ); -generate_key (conn, sess, ptwin->decryption.label, +generate_key (conn, sess->sess_key, ptwin->decryption.label, ptwin->decryption.context, sess->smb3decryptionkey,SMB3_ENC_DEC_KEY_SIZE );
fs/smb/server/auth.h +4 -3
@@ -41,17 +41,18 @@ int ksmbd_crypt_message(struct ksmbd_work *work, struct kvec *iov,void ksmbd_copy_gss_neg_header (void *buf);int ksmbd_auth_ntlmv2 (struct ksmbd_conn *conn,struct ksmbd_session *sess,struct ntlmv2_resp *ntlmv2,int blen,char *domain_name, -char *cryptkey); +char *cryptkey,char *sess_key);int ksmbd_decode_ntlmssp_auth_blob (struct authenticate_message *authblob,int blob_len,struct ksmbd_conn *conn, -struct ksmbd_session *sess); +struct ksmbd_session *sess,char *sess_key);int ksmbd_decode_ntlmssp_neg_blob (struct negotiate_message *negblob,int blob_len,struct ksmbd_conn *conn);unsigned int ksmbd_build_ntlmssp_challenge_blob (struct challenge_message *chgblob,struct ksmbd_conn *conn);int ksmbd_krb5_authenticate (struct ksmbd_session *sess,char *in_blob, -int in_len,char *out_blob,int *out_len); +int in_len,char *out_blob,int *out_len, +char *sess_key);void ksmbd_sign_smb2_pdu (struct ksmbd_conn *conn,char *key,struct kvec *iov,int n_vec,char *sig); void ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov,
fs/smb/server/mgmt/user_session.c +2 -2
@@ -255,7 +255,7 @@ static void free_channel_list(struct ksmbd_session *sess)down_write (&sess->chann_lock);xa_for_each (&sess->ksmbd_chann_list, index, chann) {xa_erase (&sess->ksmbd_chann_list, index); -kfree (chann); +kfree_sensitive (chann); }xa_destroy (&sess->ksmbd_chann_list);
@@ -449,7 +449,7 @@ static int ksmbd_chann_del(struct ksmbd_conn *conn, struct ksmbd_session *sess)if (!chann)return -ENOENT ; -kfree (chann); +kfree_sensitive (chann);return 0 ; }
fs/smb/server/mgmt/user_session.h +1 -0
@@ -19,6 +19,7 @@struct ksmbd_file_table ;struct channel { +char sess_key[SMB2_NTLMV2_SESSKEY_SIZE ];__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE ];struct ksmbd_conn *conn; };
fs/smb/server/smb2pdu.c +92 -50
245 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1452/2077 smb: client: preserve leading slash for POSIX absolute symlink targets
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steve French <[email protected]>
[ Upstream commit dce002f685e04e0c94e088cb66cb4021311cc6b5 ]
When creating a native SMB symbolic link (CIFS_SYMLINK_TYPE_NATIVE) whose target is an absolute path on a mount that uses POSIX paths, the leading path separator was silently dropped from the stored symlink target.
create_native_symlink() converted the target to UTF-16 with cifs_convert_path_to_utf16(). That helper was intended for share-relative SMB paths and therefore unconditionally strips a leading path separator. For an absolute POSIX symlink target the leading '/' is significant, so a target of "/foo/bar" was stored and read back as "foo/bar", even though the reparse point was still flagged as absolute (SYMLINK_FLAG_RELATIVE cleared).
On a POSIX paths mount the symlink target is stored verbatim, so convert it directly with cifs_strndup_to_utf16() instead. This preserves the leading separator, avoids the leading-backslash stripping that cifs_convert_path_to_utf16() also performs (a backslash is a valid POSIX filename character), and uses NO_MAP_UNI_RSVD to match the readback path in smb2_parse_native_symlink(), which always converts the target with cifs_strndup_from_utf16() / NO_MAP_UNI_RSVD. This mirrors how the NFS and WSL reparse symlink creators convert their targets.
The NT-style absolute symlink handling, which needs the "\??\" prefix and drive-letter colon preserved, continues to use cifs_convert_path_to_utf16() together with the existing masking of those bytes.
--- fs/smb/client/reparse.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/smb/client/reparse.c +16 -1
@@ -67,6 +67,7 @@ static int create_native_symlink(const unsigned int xid, struct inode *inode,char *sym =NULL ;struct kvec iov;bool directory; +int path_len;int rc =0 ;if (strlen (symname) >REPARSE_SYM_PATH_MAX )
@@ -168,7 +169,21 @@ static int create_native_symlink(const unsigned int xid, struct inode *inode,if (!(sbflags &CIFS_MOUNT_POSIX_PATHS ) && symname[0 ] =='/' ) sym[0 ] = sym[1 ] = sym[2 ] = sym[5 ] ='_' ; - path =cifs_convert_path_to_utf16 (sym, cifs_sb); +/* +* On a POSIX paths mount the symlink target is stored verbatim, so +* convert it with cifs_strndup_to_utf16(). cifs_convert_path_to_utf16() +* must not be used here: it strips a leading path separator (it is +* meant for share-relative SMB paths), which would corrupt an absolute +* POSIX symlink target such as "/foo/bar". Using NO_MAP_UNI_RSVD also +* matches the readback path in smb2_parse_native_symlink(). +*/ +if (sbflags &CIFS_MOUNT_POSIX_PATHS ) + path =cifs_strndup_to_utf16 (sym,strlen (sym), &path_len, + cifs_sb->local_nls, +NO_MAP_UNI_RSVD ); +else + path =cifs_convert_path_to_utf16 (sym, cifs_sb); +if (!path) { rc = -ENOMEM ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1453/2077 gpio: shared: make the voting mechanism adaptable
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit b30973e8c3920ddfa9255a959b19057515b4e5e8 ]
The current voting mechanism in GPIO shared proxy assumes that "low" is always the default value and users can only vote for driving the GPIO "high" in which case it will remain high as long as there's at least one user voting.
This makes it impossible to use the automatic sharing management for certain use-cases such as the write-protect GPIOs of EEPROMs which are requested "high" and driven "low" to enable writing. In this case, if the WP GPIO is shared by multiple EEPROMs, and at least one of them wants to enable writing, the pin must be set to "low".
Modify the voting heuristic to assume the value set by the first user on request to be the "default" and subseqent calls to gpiod_set_value() will constitute votes for a change of the value to the opposite. In the wp-gpios case it will mean that the nvmem core requests the GPIO as "out-high" for all EEPROMs sharing the pin, and when one of them wants to write, the pin will be driven low, enabling it.
--- drivers/gpio/gpio-shared-proxy.c | 66 ++++++++++++++++---------------- drivers/gpio/gpiolib-shared.h | 3 +- 2 files changed, 34 insertions(+), 35 deletions(-)
drivers/gpio/gpio-shared-proxy.c +32 -34
@@ -22,7 +22,7 @@ struct gpio_shared_proxy_data {struct gpio_chip gc;struct gpio_shared_desc *shared_desc;struct device *dev; -bool voted_high; +bool voted_change; }; static int
@@ -34,52 +34,54 @@ gpio_shared_proxy_set_unlocked(struct gpio_shared_proxy_data *proxy, int value)lockdep_assert_held (&shared_desc->mutex); -if (value) { -/* User wants to set value to high. */ -if (proxy->voted_high) -/* Already voted for high, nothing to do. */ +if (value != shared_desc->def_val) { +/* User wants to vote for a value change. */ +if (proxy->voted_change) +/* Already voted for a change, nothing to do. */ goto out; -/* Haven't voted for high yet. */ -if (!shared_desc->highcnt) { +/* Haven't voted for a value change yet. */ +if (!shared_desc->votecnt) {/* -* Current value is low, need to actually set value -* to high. +* Current value is default, need to actually set value +* to the opposite. */ - ret =gpiod_set_value_cansleep (desc,1 ); + ret =gpiod_set_value_cansleep (desc, value);if (ret) goto out; } - shared_desc->highcnt++; - proxy->voted_high = true; + shared_desc->votecnt++; + proxy->voted_change = true; goto out; } -/* Desired value is low. */ -if (!proxy->voted_high) -/* We didn't vote for high, nothing to do. */ +/* Desired value is the default. */ +if (!proxy->voted_change) +/* We didn't vote for change previously, nothing to do. */ goto out; -/* We previously voted for high. */ -if (shared_desc->highcnt ==1 ) { -/* This is the last remaining vote for high, set value to low. */ - ret =gpiod_set_value_cansleep (desc,0 ); +/* We previously voted for change. */ +if (shared_desc->votecnt ==1 ) { +/* This is the last remaining vote for change, set value to default. */ + ret =gpiod_set_value_cansleep (desc, shared_desc->def_val);if (ret) goto out; } - shared_desc->highcnt--; - proxy->voted_high = false; + shared_desc->votecnt--; + proxy->voted_change = false; out: -if (shared_desc->highcnt) +if (shared_desc->votecnt)dev_dbg (proxy->dev, -"Voted for value '%s', effective value is 'high', number of votes for 'high': %u\n" , -str_high_low (value), shared_desc->highcnt); +"Voted for value '%s', effective value is '%s', number of votes: %u\n" , +str_high_low (value),str_high_low (!shared_desc->def_val), + shared_desc->votecnt);else -dev_dbg (proxy->dev,"Voted for value 'low', effective value is 'low'\n" ); +dev_dbg (proxy->dev,"Voted for value '%s', effective value is '%s'\n" , +str_high_low (value),str_high_low (shared_desc->def_val));return ret; }
@@ -107,8 +109,8 @@ static void gpio_shared_proxy_free(struct gpio_chip *gc, unsigned int offset)guard (mutex)(&shared_desc->mutex); -if (proxy->voted_high) { - ret =gpio_shared_proxy_set_unlocked (proxy,0 ); +if (proxy->voted_change) { + ret =gpio_shared_proxy_set_unlocked (proxy, shared_desc->def_val);if (ret)dev_err (proxy->dev,"Failed to unset the shared GPIO value on release: %d\n" , ret);
@@ -197,13 +199,9 @@ static int gpio_shared_proxy_direction_output(struct gpio_chip *gc,if (ret)return ret; -if (value) { - proxy->voted_high = true; - shared_desc->highcnt =1 ; - }else { - proxy->voted_high = false; - shared_desc->highcnt =0 ; - } + shared_desc->def_val = value; + shared_desc->votecnt =0 ; + proxy->voted_change = false;return 0 ; }
drivers/gpio/gpiolib-shared.h +2 -1
@@ -41,7 +41,8 @@ struct gpio_shared_desc {struct gpio_desc *desc;unsigned long cfg;unsigned int usecnt; -unsigned int highcnt; +unsigned int votecnt; +int def_val;struct mutex mutex;/* serializes all proxy operations on this descriptor */ };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1454/2077 drm/i915/ltphy: Fix SSC Enablement bit in PORT_CLOCK_CTL
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suraj Kandpal <[email protected]>
[ Upstream commit e91da9053006da622b865e672a4a37439a3bb88b ]
According to Bspec we only need to write SSC Enable PLL A bit and leave PLL B bit alone in PORT_CLOCK_CTL register.
Bspec: 74667, 74492
--- drivers/gpu/drm/i915/display/intel_lt_phy.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/i915/display/intel_lt_phy.c +1 -5
@@ -1223,11 +1223,7 @@ intel_lt_phy_program_port_clock_ctl(struct intel_encoder *encoder,else val |=XELPDP_DDI_CLOCK_SELECT_PREP (display,XELPDP_DDI_CLOCK_SELECT_MAXPCLK ); -/* DP2.0 10G and 20G rates enable MPLLA*/ -if (port_clock ==1000000 || port_clock ==2000000 ) - val |=XELPDP_SSC_ENABLE_PLLA ; -else - val |= ltpll->ssc_enabled ?XELPDP_SSC_ENABLE_PLLB :0 ; + val |= ltpll->ssc_enabled ?XELPDP_SSC_ENABLE_PLLA :0 ; intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port), XELPDP_LANE1_PHY_CLOCK_SELECT | XELPDP_FORWARD_CLOCK_UNGATE |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1455/2077 Bluetooth: 6lowpan: avoid untracked enable work
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 352a59dc1f4a41314b6f827c17e16af7ca88271a ]
lowpan_enable_set() allocates a temporary work item and schedules do_enable_set() on system_wq, then returns to debugfs. The debugfs active operation has ended at that point, but the worker still executes module text and manipulates enable_6lowpan and listen_chan.
bt_6lowpan_exit() removes the debugfs files and immediately closes and puts listen_chan. It has no pointer to the queued work item, so it cannot cancel or flush it before tearing down the state that the worker uses.
The buggy scenario involves two paths, with each column showing the order within that path:
debugfs enable write module exit
1. lowpan_enable_set() allocates 1. bt_6lowpan_exit() removes
set_enable work the debugfs file
2. schedule_work() queues 2. bt_6lowpan_exit() closes
do_enable_set() and puts listen_chan
3. the write operation returns 3. module teardown can continue
4. do_enable_set() later runs
against stale state
Run the enable state transition synchronously in lowpan_enable_set() instead. The simple debugfs setter can sleep, and this file already handles the 6LoWPAN control write synchronously under the same set_lock. Once the setter returns, debugfs removal covers the whole operation and exit can no longer race with an untracked work item.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in do_enable_set+0x113/0x2e0 Workqueue: events do_enable_set [bluetooth_6lowpan] The buggy address belongs to the object at ffff888109cb8000
--- net/bluetooth/6lowpan.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-)
net/bluetooth/6lowpan.c +4 -23
@@ -1061,23 +1061,15 @@ static void disconnect_all_peers(void) }while (nchans); } -struct set_enable { -struct work_struct work; -bool flag; -}; - -static void do_enable_set (struct work_struct *work) +static void do_enable_set (bool flag) { -struct set_enable *set_enable =container_of (work, - struct set_enable, work); - -if (!set_enable->flag || enable_6lowpan != set_enable->flag) +if (!flag || enable_6lowpan != flag)/* Disconnect existing connections if 6lowpan is * disabled */ disconnect_all_peers (); - enable_6lowpan = set_enable->flag; + enable_6lowpan = flag;mutex_lock (&set_lock);if (listen_chan) {
@@ -1089,22 +1081,11 @@ static void do_enable_set(struct work_struct *work) listen_chan =bt_6lowpan_listen ();mutex_unlock (&set_lock); - -kfree (set_enable); }static int lowpan_enable_set (void *data,u64 val) { -struct set_enable *set_enable; - - set_enable =kzalloc_obj (*set_enable); -if (!set_enable) -return -ENOMEM ; - - set_enable->flag = !!val; -INIT_WORK (&set_enable->work, do_enable_set); - -schedule_work (&set_enable->work); +do_enable_set (!!val);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1456/2077 Bluetooth: 6lowpan: hold L2CAP conn across debugfs control
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 518aa9505fa10ea5662349e5d2efd8c9e32a820b ]
get_l2cap_conn() looks up an LE hci_conn under hdev protection, but then drops that protection before reading hcon->l2cap_data and before lowpan_control_write() later dereferences conn->hcon. A disconnect or device close can tear down the same L2CAP connection in that window.
The buggy scenario involves two paths, with each column showing the order within that path:
6LoWPAN control write: HCI disconnect/device close:
1. get_l2cap_conn() finds hcon 1. hci_disconn_cfm() dispatches
and hcon->l2cap_data. the L2CAP disconnect callback.
2. get_l2cap_conn() drops hdev 2. l2cap_conn_del() clears
protection and returns conn. hcon->l2cap_data and drops the
L2CAP connection reference.
3. lowpan_control_write() reads 3. hci_conn_del() removes and drops
conn->hcon. the HCI connection.Take a reference to the L2CAP connection with l2cap_conn_hold_unless_zero() while hdev is still locked, and drop that reference after the debugfs command's last use of conn. This mirrors the existing L2CAP ACL receive-side handoff and keeps the connection dereferenceable after leaving hdev protection. Export the existing helper so the bluetooth_6lowpan module can use the same lifetime primitive.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in lowpan_control_write+0x374/0x520 The buggy address belongs to the object at ffff888111b9d000 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 0 bytes inside of freed 1024-byte region [ffff888111b9d000, ffff888111b9d400) Read of size 8 Call trace: dump_stack_lvl+0x66/0xa0 print_report+0xce/0x5f0 lowpan_control_write+0x374/0x520 (net/bluetooth/6lowpan.c:1131) srso_alias_return_thunk+0x5/0xfbef5 __virt_addr_valid+0x19f/0x330 kasan_report+0xe0/0x110 __debugfs_file_get+0xf7/0x400 full_proxy_write+0x9e/0xd0 vfs_write+0x1b0/0x810 ksys_write+0xd2/0x170 dnotify_flush+0x32/0x220 do_syscall_64+0x115/0x6a0 (arch/x86/entry/syscall_64.c:87) entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task stack: kasan_save_stack+0x33/0x60 kasan_save_track+0x17/0x60 __kasan_kmalloc+0xaa/0xb0 l2cap_conn_add+0x45/0x520 l2cap_chan_connect+0xac6/0xd90 l2cap_sock_connect+0x216/0x350 __sys_connect+0x101/0x130 __x64_sys_connect+0x40/0x50 do_syscall_64+0x115/0x6a0 (arch/x86/entry/syscall_64.c:87) entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task stack: kasan_save_stack+0x33/0x60 kasan_save_track+0x17/0x60 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x313/0x590 hci_conn_hash_flush+0xc0/0x140 hci_dev_close_sync+0x41a/0xb00 hci_dev_close+0x12f/0x160 hci_sock_ioctl+0x157/0x570 sock_do_ioctl+0xf7/0x210 sock_ioctl+0x32f/0x490 __x64_sys_ioctl+0xc7/0x110 do_syscall_64+0x115/0x6a0 (arch/x86/entry/syscall_64.c:87) entry_SYSCALL_64_after_hwframe+0x77/0x7f kasan_record_aux_stack+0xa7/0xc0 insert_work+0x32/0x100 __queue_work+0x262/0xa60 queue_work_on+0xad/0xb0 l2cap_connect_cfm+0x4ef/0x670 hci_le_remote_feat_complete_evt+0x247/0x430 hci_event_packet+0x360/0x6f0 hci_rx_work+0x2ae/0x7a0 process_one_work+0x4fd/0xbc0 worker_thread+0x2d8/0x570 kthread+0x1ad/0x1f0 ret_from_fork+0x3c9/0x540 ret_from_fork_asm+0x1a/0x30
--- net/bluetooth/6lowpan.c | 21 +++++++++++++++------ net/bluetooth/l2cap_core.c | 1 + 2 files changed, 16 insertions(+), 6 deletions(-)
net/bluetooth/6lowpan.c +15 -6
@@ -997,16 +997,19 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,hci_dev_lock (hdev); hcon =hci_conn_hash_lookup_le (hdev, addr, le_addr_type); -hci_dev_unlock (hdev); -hci_dev_put (hdev); - -if (!hcon) +if (!hcon) { +hci_dev_unlock (hdev); +hci_dev_put (hdev);return -ENOENT ; + } - *conn = (struct l2cap_conn *)hcon->l2cap_data; + *conn =l2cap_conn_hold_unless_zero (hcon->l2cap_data);BT_DBG ("conn %p dst %pMR type %u" , *conn, &hcon->dst, hcon->dst_type); +hci_dev_unlock (hdev); +hci_dev_put (hdev); +return 0 ; }
@@ -1134,18 +1137,22 @@ static ssize_t lowpan_control_write(struct file *fp,if (conn) {struct lowpan_peer *peer; -if (!is_bt_6lowpan (conn->hcon)) +if (!is_bt_6lowpan (conn->hcon)) { +l2cap_conn_put (conn);return -EINVAL ; + } peer =lookup_peer (conn);if (peer) {BT_DBG ("6LoWPAN connection already exists" ); +l2cap_conn_put (conn);return -EALREADY ; }BT_DBG ("conn %p dst %pMR type %d user %u" , conn, &conn->hcon->dst, conn->hcon->dst_type, addr_type); +l2cap_conn_put (conn); } ret =bt_6lowpan_connect (&addr, addr_type);
@@ -1161,6 +1168,8 @@ static ssize_t lowpan_control_write(struct file *fp,return ret; ret =bt_6lowpan_disconnect (conn, addr_type); +if (conn) +l2cap_conn_put (conn);if (ret <0 )return ret;
net/bluetooth/l2cap_core.c +1 -0
@@ -7714,6 +7714,7 @@ struct l2cap_conn *l2cap_conn_hold_unless_zero(struct l2cap_conn *c)return c; } +EXPORT_SYMBOL (l2cap_conn_hold_unless_zero);int l2cap_recv_acldata (struct hci_dev *hdev,u16 handle,struct sk_buff *skb,u16 flags)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1457/2077 Bluetooth: MGMT: Fix adv monitor add failure cleanup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 384a4b2fef9ffe5e270ee5558975c0504881c5fb ]
hci_add_adv_monitor() publishes a new adv_monitor in hdev->adv_monitors_idr before the powered MSFT setup step. The MSFT offload add path can then fail either locally before the controller add command completes, or in the MSFT add callback. In the current queued management add flow, hci_cmd_sync_work() still invokes mgmt_add_adv_patterns_monitor_complete() with the original pending command after msft_add_monitor_pattern() returns.
The buggy scenario involves two paths, with each column showing the order within that path:
MSFT add handling MGMT completion 1. insert monitor and handle 1. receive sync error 2. send MSFT add command 2. call add-monitor completion 3. callback sees bad response 3. load cmd->user_data 4. callback frees monitor 4. read monitor->handle
Local MSFT setup failures have the other half of the same ownership bug:
they return an error after the IDR insertion, but no later code removes the failed monitor from the IDR.
Keep ownership with the pending management command until its completion. For normal management adds, the MSFT add callback now records successful controller state and returns errors to its caller. The management completion frees the monitor on non-success after copying the response handle, while resume/reregister callback-error cleanup remains in the MSFT callback. The success path keeps the existing bookkeeping.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in mgmt_add_adv_patterns_monitor_complete+0xfb/0x260 [bluetooth] Call Trace: <TASK> dump_stack_lvl+0x66/0xa0 print_report+0xce/0x5f0 ? mgmt_add_adv_patterns_monitor_complete+0xfb/0x260 [bluetooth] ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x19f/0x330 ? mgmt_add_adv_patterns_monitor_complete+0xfb/0x260 [bluetooth] kasan_report+0xe0/0x110 ? mgmt_add_adv_patterns_monitor_complete+0xfb/0x260 [bluetooth] mgmt_add_adv_patterns_monitor_complete+0xfb/0x260 [bluetooth] ? srso_alias_return_thunk+0x5/0xfbef5 ? 0xffffffffc00d00da ? __pfx_mgmt_add_adv_patterns_monitor_complete+0x10/0x10 [bluetooth] ? __pfx_mgmt_add_adv_patterns_monitor_complete+0x10/0x10 [bluetooth] ? hci_cmd_sync_work+0x1ab/0x210 [bluetooth] hci_cmd_sync_work+0x1c0/0x210 [bluetooth] ? __pfx_mgmt_add_adv_patterns_monitor_complete+0x10/0x10 [bluetooth] process_one_work+0x4fd/0xbc0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? __list_add_valid_or_report+0x37/0xf0 ? __pfx_hci_cmd_sync_work+0x10/0x10 [bluetooth] ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x2d8/0x570 ? __pfx_worker_thread+0x10/0x10 kthread+0x1ad/0x1f0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x3c9/0x540 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x2e9/0x730 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 471 on cpu 3 at 285.205389s: kasan_save_stack+0x33/0x60 kasan_save_track+0x17/0x60 __kasan_kmalloc+0xaa/0xb0 add_adv_patterns_monitor_rssi+0xd5/0x230 [bluetooth] hci_sock_sendmsg+0x96b/0xf80 [bluetooth] __sys_sendto+0x2bc/0x2d0 __x64_sys_sendto+0x76/0x90 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 454 on cpu 2 at 285.217112s: kasan_save_stack+0x33/0x60 kasan_save_track+0x17/0x60 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x313/0x590 msft_add_monitor_sync+0x54a/0x570 [bluetooth] hci_add_adv_monitor+0x133/0x180 [bluetooth] hci_cmd_sync_work+0x187/0x210 [bluetooth] process_one_work+0x4fd/0xbc0 worker_thread+0x2d8/0x570 kthread+0x1ad/0x1f0 ret_from_fork+0x3c9/0x540 ret_from_fork_asm+0x1a/0x30
--- net/bluetooth/mgmt.c | 2 ++ net/bluetooth/msft.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/mgmt.c +2 -0
@@ -5378,6 +5378,8 @@ static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev,if (monitor->state ==ADV_MONITOR_STATE_NOT_REGISTERED ) monitor->state =ADV_MONITOR_STATE_REGISTERED ;hci_update_passive_scan (hdev); + }else { +hci_free_adv_monitor (hdev, monitor); } mgmt_cmd_complete(cmd->sk, cmd->hdev->id, cmd->opcode,
net/bluetooth/msft.c +1 -1
@@ -291,7 +291,7 @@ static int msft_le_monitor_advertisement_cb(struct hci_dev *hdev, u16 opcode, monitor->state =ADV_MONITOR_STATE_OFFLOADED ; unlock: -if (status) +if (status && msft->resuming)hci_free_adv_monitor (hdev, monitor);hci_dev_unlock (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1458/2077 Bluetooth: sco: Fix a race condition in sco_sock_timeout()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sungwoo Kim <[email protected]>
[ Upstream commit 0f8a5dcc66648b6e1458a9f3ba4c5a0463a228fc ]
sco_sock_timeout() runs asynchronously and lock_sock(sk). If the socket is closing while the timer is running, it holds the same lock (lock_sock(sk)) twice, leading to a deadlock.
CPU 0 CPU 1
==================== ======================sco_sock_close()
sco_sock_timeout()lock_sock(sk) // <-- LOCK
__sco_sock_close()
sco_chan_del()
sco_conn_put()
sco_conn_free()
disable_delayed_work_sync()
lock(sk) // <-- SAME LOCKFix this by moving disable_delayed_work_sync() outside of lock_sock(sk), ensuring that no lock_sock(sk) is held before sco_sock_timeout().
Lockdep splat:
WARNING: possible circular locking dependency detected 6.13.0-rc4 #7 Not tainted
syz-executor292/9514 is trying to acquire lock:ffff8881115d5070 ((work_completion)(&(&conn->timeout_work)->work)){+.+.}-{0:0}, at: rcu_lock_acquire sect/v6.13-rc4/./include/linux/rcupdate.h:337 [inline] ffff8881115d5070 ((work_completion)(&(&conn->timeout_work)->work)){+.+.}-{0:0}, at: rcu_read_lock sect/v6.13-rc4/./include/linux/rcupdate.h:849 [inline] ffff8881115d5070 ((work_completion)(&(&conn->timeout_work)->work)){+.+.}-{0:0}, at: start_flush_work sect/v6.13-rc4/kernel/workqueue.c:4137 [inline] ffff8881115d5070 ((work_completion)(&(&conn->timeout_work)->work)){+.+.}-{0:0}, at: __flush_work+0xd1/0xc40 sect/v6.13-rc4/kernel/workqueue.c:4195
but task is already holding lock:ffff88807db3a258 (sk_lock-AF_BLUETOOTH-BTPROTO_SCO){+.+.}-{0:0}, at: lock_sock sect/v6.13-rc4/./include/net/sock.h:1623 [inline] ffff88807db3a258 (sk_lock-AF_BLUETOOTH-BTPROTO_SCO){+.+.}-{0:0}, at: sco_sock_close+0x25/0x100 sect/v6.13-rc4/net/bluetooth/sco.c:524
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (sk_lock-AF_BLUETOOTH-BTPROTO_SCO){+.+.}-{0:0}:
lock_acquire+0x1c4/0x520 sect/v6.13-rc4/kernel/locking/lockdep.c:5849
lock_sock_nested+0x48/0x130 sect/v6.13-rc4/net/core/sock.c:3622
lock_sock sect/v6.13-rc4/./include/net/sock.h:1623 [inline]
sco_sock_timeout+0xbe/0x270 sect/v6.13-rc4/net/bluetooth/sco.c:158
process_one_work sect/v6.13-rc4/kernel/workqueue.c:3229 [inline]
process_scheduled_works+0xa99/0x18f0 sect/v6.13-rc4/kernel/workqueue.c:3310
worker_thread+0x8a9/0xd80 sect/v6.13-rc4/kernel/workqueue.c:3391
kthread+0x2c6/0x360 sect/v6.13-rc4/kernel/kthread.c:389
ret_from_fork+0x4e/0x80 sect/v6.13-rc4/arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 sect/v6.13-rc4/arch/x86/entry/entry_64.S:244-> #0 ((work_completion)(&(&conn->timeout_work)->work)){+.+.}-{0:0}:
check_prev_add sect/v6.13-rc4/kernel/locking/lockdep.c:3161 [inline]
check_prevs_add sect/v6.13-rc4/kernel/locking/lockdep.c:3280 [inline]
validate_chain+0x1888/0x5760 sect/v6.13-rc4/kernel/locking/lockdep.c:3904
__lock_acquire+0x13b4/0x2120 sect/v6.13-rc4/kernel/locking/lockdep.c:5226
lock_acquire+0x1c4/0x520 sect/v6.13-rc4/kernel/locking/lockdep.c:5849
touch_work_lockdep_map sect/v6.13-rc4/kernel/workqueue.c:3909 [inline]
start_flush_work sect/v6.13-rc4/kernel/workqueue.c:4163 [inline]
__flush_work+0x70f/0xc40 sect/v6.13-rc4/kernel/workqueue.c:4195
__cancel_work_sync sect/v6.13-rc4/kernel/workqueue.c:4351 [inline]
disable_delayed_work_sync+0xbb/0xf0 sect/v6.13-rc4/kernel/workqueue.c:4514
sco_conn_free sect/v6.13-rc4/net/bluetooth/sco.c:95 [inline]
kref_put sect/v6.13-rc4/./include/linux/kref.h:65 [inline]
sco_conn_put+0x18f/0x270 sect/v6.13-rc4/net/bluetooth/sco.c:107
sco_chan_del+0xe2/0x210 sect/v6.13-rc4/net/bluetooth/sco.c:236
sco_sock_close+0x8f/0x100 sect/v6.13-rc4/net/bluetooth/sco.c:526
sco_sock_release+0x62/0x2d0 sect/v6.13-rc4/net/bluetooth/sco.c:1300
__sock_release+0xe1/0x2d0 sect/v6.13-rc4/net/socket.c:640
sock_close+0x1c/0x30 sect/v6.13-rc4/net/socket.c:1408
__fput+0x2bd/0xa80 sect/v6.13-rc4/fs/file_table.c:450
__fput_sync+0x15e/0x1c0 sect/v6.13-rc4/fs/file_table.c:535
__do_sys_close sect/v6.13-rc4/fs/open.c:1554 [inline]
__se_sys_close sect/v6.13-rc4/fs/open.c:1539 [inline]
__x64_sys_close+0x93/0x120 sect/v6.13-rc4/fs/open.c:1539
do_syscall_x64 sect/v6.13-rc4/arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xee/0x210 sect/v6.13-rc4/arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f--- net/bluetooth/sco.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
net/bluetooth/sco.c +14 -1
@@ -572,10 +572,23 @@ static void __sco_sock_close(struct sock *sk)/* Must be called on unlocked socket. */ static void sco_sock_close (struct sock *sk) { +struct sco_conn *conn; + +lock_sock (sk); + conn =sco_pi (sk)->conn; +if (conn) +sco_conn_hold (conn); +release_sock (sk); + +if (conn) +disable_delayed_work_sync (&conn->timeout_work); +lock_sock (sk); -sco_sock_clear_timer (sk);__sco_sock_close (sk);release_sock (sk); + +if (conn) +sco_conn_put (conn); }static void sco_sock_init (struct sock *sk,struct sock *parent)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1459/2077 Bluetooth: btintel_pcie: Support Product level reset
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chandrashekar Devegowda <[email protected]>
[ Upstream commit 2d00975c841fa2e52921353392ce9780843bfee7 ]
When driver encounters a TOP exception, ACPI methods will be called for Product level reset since Wifi and BT share the same TOP. BT driver will first reprobe the wifi driver and then reprobe BT.
Stable-dep-of: 9c36951474d8 ("Bluetooth: btintel_pcie: Refactor FLR to use device_reprobe()")
--- drivers/bluetooth/Kconfig | 2 +- drivers/bluetooth/btintel.c | 10 +- drivers/bluetooth/btintel.h | 7 ++ drivers/bluetooth/btintel_pcie.c | 205 ++++++++++++++++++++++++++----- drivers/bluetooth/btintel_pcie.h | 7 ++ 5 files changed, 195 insertions(+), 36 deletions(-)
drivers/bluetooth/Kconfig +1 -1
@@ -502,7 +502,7 @@ config BT_NXPUART config BT_INTEL_PCIE tristate "Intel HCI PCIe driver" - depends on PCI + depends on PCI && ACPI select BT_INTEL select FW_LOADER help
drivers/bluetooth/btintel.c +6 -4
@@ -67,9 +67,10 @@ static struct {u32 fw_build_num; } coredump_info; -static const guid_t btintel_guid_dsm = +const guid_t btintel_guid_dsm =GUID_INIT (0xaa10f4e0 ,0x81ac ,0x4233 ,0xab ,0xf6 ,0x3b ,0x2a ,0xc5 ,0x0e ,0x28 ,0xd9 ); +EXPORT_SYMBOL_GPL (btintel_guid_dsm);int btintel_check_bdaddr (struct hci_dev *hdev) {
@@ -2624,7 +2625,7 @@ static void btintel_set_ppag(struct hci_dev *hdev, struct intel_version_tlv *verkfree_skb (skb); } -static int btintel_acpi_reset_method (struct hci_dev *hdev) +int btintel_acpi_reset_method (struct hci_dev *hdev) {int ret =0 ;acpi_status status;
@@ -2632,14 +2633,14 @@ static int btintel_acpi_reset_method(struct hci_dev *hdev)struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; status =acpi_evaluate_object (ACPI_HANDLE (GET_HCIDEV_DEV (hdev)),"_PRR" ,NULL , &buffer); -if (ACPI_FAILURE (status)) { +if (ACPI_FAILURE (status) || !buffer.pointer) {bt_dev_err (hdev,"Failed to run _PRR method" ); ret = -ENODEV ;return ret; } p = buffer.pointer; -if (p->package.count !=1 || p->type !=ACPI_TYPE_PACKAGE ) { +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=1 ) {bt_dev_err (hdev,"Invalid arguments" ); ret = -EINVAL ; goto exit_on_error;
@@ -2663,6 +2664,7 @@ static int btintel_acpi_reset_method(struct hci_dev *hdev)kfree (buffer.pointer);return ret; } +EXPORT_SYMBOL_GPL (btintel_acpi_reset_method);static void btintel_set_dsm_reset_method (struct hci_dev *hdev,struct intel_version_tlv *ver_tlv)
drivers/bluetooth/btintel.h +7 -0
@@ -80,6 +80,8 @@ struct intel_tlv {#define BTINTEL_HWID_SCP2F 0x21/* Scorpius Peak2-F - Nova Lake */ #define BTINTEL_HWID_BZRIW 0x22/* BlazarIW - Wildcat Lake */ +extern const guid_t btintel_guid_dsm; +struct intel_version_tlv {u32 cnvi_top;u32 cnvr_top;
@@ -290,6 +292,7 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev,int btintel_shutdown_combined (struct hci_dev *hdev);void btintel_hw_error (struct hci_dev *hdev,u8 code);void btintel_print_fseq_info (struct hci_dev *hdev); +int btintel_acpi_reset_method (struct hci_dev *hdev);#else static inline int btintel_check_bdaddr (struct hci_dev *hdev)
@@ -423,4 +426,8 @@ static inline void btintel_hw_error(struct hci_dev *hdev, u8 code)static inline void btintel_print_fseq_info (struct hci_dev *hdev) { } +static inline int btintel_acpi_reset_method (struct hci_dev *hdev) +{ +return -ENODEV ; +}#endif
drivers/bluetooth/btintel_pcie.c +174 -31
305 lines not on this page · raw message
drivers/bluetooth/btintel_pcie.h +7 -0
@@ -145,6 +145,11 @@ enum msix_mbox_int_causes { BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX4 = BIT(3), /* cause MBOX4 */ }; +enum btintel_pcie_reset_type { +BTINTEL_PCIE_IOSF_PRR_FLR =0 , +BTINTEL_PCIE_IOSF_PRR_PLDR =1 , +}; +#define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE BIT(7)/* Minimum and Maximum number of MSI-X Vector
@@ -501,6 +506,7 @@ struct btintel_pcie_data {struct workqueue_struct *workqueue;struct sk_buff_head rx_skb_q;struct work_struct rx_work; +struct work_struct reset_work;struct dma_pool *dma_pool;dma_addr_t dma_p_addr;
@@ -512,6 +518,7 @@ struct btintel_pcie_data {struct txq txq;struct rxq rxq;u32 alive_intr_ctxt; +enum btintel_pcie_reset_type reset_type;struct btintel_pcie_dbgc dbgc;struct btintel_pcie_dump_header dmp_hdr;u8 pm_sx_event;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1460/2077 Bluetooth: btintel_pcie: Add support for smart trigger dump
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiran K <[email protected]>
[ Upstream commit 975a70ff0aec8a2be0d633113f781b301db4a816 ]
Based on the debug configuration, firmware can raise MSI-X interrupt with firmware trigger cause bit set on specific events like Disconnection, Connection Timeout, Page Timeout etc.
Upon receiving an MSI-X interrupt with the firmware trigger cause bit set, the driver performs the following actions:
1. Reads Device Memory: Retrieves data from the device memory, constructs an HCI diagnostic event, and sends it to the monitor. This event includes details about the trigger, such as connection timeout or page timeout.
2. Dumps Device Coredump: Generates a coredump containing firmware traces for further analysis.
The coredump can be retrieved using:
$ cat /sys/class/devcoredump/devcd*/data > /tmp/btintel_coredump.bin
HCI traces:
= Vendor Diagnostic (len 12)
a5 a5 a5 a5 01 03 00 23 00 01 00 00
Stable-dep-of: 9c36951474d8 ("Bluetooth: btintel_pcie: Refactor FLR to use device_reprobe()")
--- drivers/bluetooth/btintel.h | 1 + drivers/bluetooth/btintel_pcie.c | 164 +++++++++++++++++++++++++++++++ drivers/bluetooth/btintel_pcie.h | 10 +- 3 files changed, 174 insertions(+), 1 deletion(-)
drivers/bluetooth/btintel.h +1 -0
@@ -53,6 +53,7 @@ struct intel_tlv { } __packed;#define BTINTEL_HCI_OP_RESET 0xfc01 +#define BTINTEL_HCI_OP_DEBUG 0xfcd9#define BTINTEL_CNVI_BLAZARI 0x900/* BlazarI - Lunar Lake */ #define BTINTEL_CNVI_BLAZARIW 0x901/* BlazarIW - Wildcat Lake */
drivers/bluetooth/btintel_pcie.c +164 -0
218 lines not on this page · raw message
drivers/bluetooth/btintel_pcie.h +9 -1
@@ -102,6 +102,7 @@ enum msix_hw_int_causes {BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0 =BIT (0 ),/* cause 32 */ BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP1 =BIT (1 ),/* cause 33 */ BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP =BIT (3 ),/* cause 35 */ + BTINTEL_PCIE_MSIX_HW_INT_CAUSES_FWTRIG = BIT(5), /* cause 37 */ };/* PCIe device states
@@ -119,6 +120,7 @@ enum {BTINTEL_PCIE_CORE_HALTED ,BTINTEL_PCIE_HWEXP_INPROGRESS ,BTINTEL_PCIE_COREDUMP_INPROGRESS , +BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS ,BTINTEL_PCIE_RECOVERY_IN_PROGRESS , BTINTEL_PCIE_SETUP_DONE };
@@ -134,7 +136,9 @@ enum btintel_pcie_tlv_type {BTINTEL_DUMP_TIME ,BTINTEL_FW_BUILD ,BTINTEL_VENDOR , - BTINTEL_DRIVER +BTINTEL_DRIVER , +BTINTEL_EVENT_TYPE , + BTINTEL_EVENT_ID };/* causes for the MBOX interrupts */
@@ -434,6 +438,8 @@ struct btintel_pcie_dump_header {u32 wrap_ctr;u16 trigger_reason;int state; +u8 event_type; +u16 event_id; };/* struct btintel_pcie_data
@@ -522,6 +528,8 @@ struct btintel_pcie_data {struct btintel_pcie_dbgc dbgc;struct btintel_pcie_dump_header dmp_hdr;u8 pm_sx_event; +u32 debug_evt_addr; +u32 debug_evt_size; }; static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1461/2077 Bluetooth: btintel_pcie: Separate coredump work from RX work
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravindra <[email protected]>
[ Upstream commit f70f7f2512c6b9113dc78f6a25361166afd1412e ]
Sharing a single workqueue between coredump processing and RX delays evacuation of RX events while a coredump is in progress. The firmware's RX buffers can overflow during that window, leading to dropped events. The issue was observed in HID use cases where HID reports arrive in bursts and quickly fill the RX path while a coredump is being collected.
Move coredump processing to a dedicated ordered coredump_workqueue with its own coredump_work, so coredumps run independently of RX. All four coredump trigger sources (FW assert, HW exception, user sysfs trigger, and resume-error detection) are switched to this new workqueue. Ordering serialises concurrent triggers without blocking RX.
Stable-dep-of: 9c36951474d8 ("Bluetooth: btintel_pcie: Refactor FLR to use device_reprobe()")
--- drivers/bluetooth/btintel_pcie.c | 102 +++++++++++++++++++++++++------ drivers/bluetooth/btintel_pcie.h | 5 ++ 2 files changed, 87 insertions(+), 20 deletions(-)
drivers/bluetooth/btintel_pcie.c +82 -20
@@ -1444,7 +1444,7 @@ static void btintel_pcie_msix_fw_trigger_handler(struct btintel_pcie_data *data)if (!test_and_set_bit (BTINTEL_PCIE_COREDUMP_INPROGRESS , &data->flags)) data->dmp_hdr.trigger_reason =BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT ; -queue_work (data->workqueue, &data->rx_work); +queue_work (data->coredump_workqueue, &data->coredump_work); }static void btintel_pcie_msix_hw_exp_handler (struct btintel_pcie_data *data)
@@ -1461,16 +1461,21 @@ static void btintel_pcie_msix_hw_exp_handler(struct btintel_pcie_data *data)if (!test_and_set_bit (BTINTEL_PCIE_COREDUMP_INPROGRESS , &data->flags)) data->dmp_hdr.trigger_reason =BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT ; -queue_work (data->workqueue, &data->rx_work); +queue_work (data->coredump_workqueue, &data->coredump_work); } -static void btintel_pcie_rx_work (struct work_struct *work) +static void btintel_pcie_coredump_worker (struct work_struct *work) {struct btintel_pcie_data *data =container_of (work, - struct btintel_pcie_data, rx_work); -struct sk_buff *skb; + struct btintel_pcie_data, coredump_work);int err; +/* hdev is NULL until setup_hdev() succeeds, and is cleared on +* teardown after disable_work_sync() drains us; bail in that case. +*/ +if (!data->hdev) +return ; +if (test_bit (BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS , &data->flags)) { err =btintel_pcie_dump_fwtrigger_event (data);if (err)
@@ -1494,6 +1499,13 @@ static void btintel_pcie_rx_work(struct work_struct *work)btintel_pcie_read_hwexp (data);clear_bit (BTINTEL_PCIE_HWEXP_INPROGRESS , &data->flags); } +} + +static void btintel_pcie_rx_work (struct work_struct *work) +{ +struct btintel_pcie_data *data =container_of (work, + struct btintel_pcie_data, rx_work); +struct sk_buff *skb;/* Process the sk_buf in queue and send to the HCI layer */ while ((skb =skb_dequeue (&data->rx_skb_q))) {
@@ -2168,9 +2180,11 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,static void btintel_pcie_release_hdev (struct btintel_pcie_data *data) { -struct hci_dev *hdev; +struct hci_dev *hdev = data->hdev; + +if (!hdev) +return ; - hdev = data->hdev;hci_unregister_dev (hdev);hci_free_dev (hdev); data->hdev =NULL ;
@@ -2588,6 +2602,10 @@ static void btintel_pcie_reset_work(struct work_struct *wk)btintel_pcie_synchronize_irqs (data);flush_work (&data->rx_work); +/* Drain any in-flight coredump and block new ones across reset. +* Safe from self-deadlock: coredump_work runs on a separate wq. +*/ +disable_work_sync (&data->coredump_work);bt_dev_dbg (data->hdev,"Release bluetooth interface" );if (data->reset_type ==BTINTEL_PCIE_IOSF_PRR_PLDR ) {
@@ -2595,16 +2613,27 @@ static void btintel_pcie_reset_work(struct work_struct *wk)* pci_rescan_remove_lock. This mutex serializes against PCI device * addition/removal (hotplug), so no device can be added to or * removed from the bus list while this code runs. +* +* device_reprobe() inside btintel_pcie_perform_pldr() destroys +* 'data' via .remove(); a fresh probe re-INIT_WORKs the +* coredump_work with disable count 0, so we must not call +* enable_work() on this path. */ btintel_pcie_perform_pldr (data); goto out; }btintel_pcie_release_hdev (data); - err =pci_reset_function (pdev); +/* Use pci_try_reset_function() rather than pci_reset_function() to +* avoid an ABBA deadlock against btintel_pcie_remove(): the PCI core +* calls .remove() with device_lock held, and remove() then waits for +* this work via cancel_work_sync(); pci_reset_function() would in +* turn try to acquire the same device_lock, deadlocking both paths. +*/ + err =pci_try_reset_function (pdev);if (err) {BT_ERR ("Failed resetting the pcie device (%d)" , err); - goto out; + goto out_enable; }btintel_pcie_enable_interrupts (data);
@@ -2614,7 +2643,7 @@ static void btintel_pcie_reset_work(struct work_struct *wk)if (err) {BT_ERR ("Failed to enable bluetooth hardware after reset (%d)" , err); - goto out; + goto out_enable; }btintel_pcie_reset_ia (data);
@@ -2624,8 +2653,15 @@ static void btintel_pcie_reset_work(struct work_struct *wk) err =btintel_pcie_setup_hdev (data);if (err) {BT_ERR ("Failed registering hdev (%d)" , err); - goto out; + goto out_enable; } + +out_enable: +/* Balance disable_work_sync() above on every exit. Leaving the +* counter incremented on a failed reset would permanently disable +* coredump_work even after a later successful reset. +*/ +enable_work (&data->coredump_work); out:pci_dev_put (pdev);pci_unlock_rescan_remove ();
@@ -2759,7 +2795,6 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data) hdev->bus =HCI_PCI ;hci_set_drvdata (hdev, data); - data->hdev = hdev;SET_HCIDEV_DEV (hdev, &data->pdev->dev); hdev->manufacturer =2 ;
@@ -2778,15 +2813,17 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data) err =hci_register_dev (hdev);if (err <0 ) {BT_ERR ("Failed to register to hdev (%d)" , err); - goto exit_error; +hci_free_dev (hdev); +return err; } +/* Publish hdev only after successful registration; the coredump +* worker bails on !data->hdev, so it never observes a half-set-up +* device. +*/ + data->hdev = hdev; data->dmp_hdr.driver_name =KBUILD_MODNAME ;return 0 ; - -exit_error: -hci_free_dev (hdev); -return err; } static int btintel_pcie_probe(struct pci_dev *pdev,
@@ -2817,9 +2854,16 @@ static int btintel_pcie_probe(struct pci_dev *pdev,if (!data->workqueue)return -ENOMEM ; + data->coredump_workqueue =alloc_ordered_workqueue (KBUILD_MODNAME "_cd" ,0 ); +if (!data->coredump_workqueue) { +destroy_workqueue (data->workqueue); +return -ENOMEM ; + } +skb_queue_head_init (&data->rx_skb_q);INIT_WORK (&data->rx_work, btintel_pcie_rx_work);INIT_WORK (&data->reset_work, btintel_pcie_reset_work); +INIT_WORK (&data->coredump_work, btintel_pcie_coredump_worker); data->boot_stage_cache =0x00 ; data->img_resp_cache =0x00 ;
@@ -2862,6 +2906,8 @@ static int btintel_pcie_probe(struct pci_dev *pdev,/* reset device before exit */ btintel_pcie_reset_bt (data); +destroy_workqueue (data->coredump_workqueue); +pci_clear_master (pdev);pci_set_drvdata (pdev,NULL );
@@ -2879,13 +2925,20 @@ static void btintel_pcie_remove(struct pci_dev *pdev)return ; } +/* Permanently block coredump triggers and drain the worker before +* tearing down. Must run before cancel_work_sync(&reset_work) so +* the disable counter stays >= 1 even after reset_work()'s +* balanced enable_work() (counter 2 -> 1, never reaching 0). +*/ +disable_work_sync (&data->coredump_work); +/* Cancel pending reset work. Skip only when remove() is called from * within the reset work itself (PLDR device_reprobe path) to avoid * deadlock. current_work() returns the work_struct of the caller if * we are in a workqueue context. */ if (current_work () != &data->reset_work) -cancel_work_sync (&data->reset_work); +disable_work_sync (&data->reset_work);btintel_pcie_disable_interrupts (data);
@@ -2905,6 +2958,7 @@ static void btintel_pcie_remove(struct pci_dev *pdev)btintel_pcie_release_hdev (data); +destroy_workqueue (data->coredump_workqueue);destroy_workqueue (data->workqueue);btintel_pcie_free (data);
@@ -2920,11 +2974,19 @@ static void btintel_pcie_coredump(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct btintel_pcie_data *data =pci_get_drvdata (pdev); +if (!data) +return ; +if (test_and_set_bit (BTINTEL_PCIE_COREDUMP_INPROGRESS , &data->flags))return ; data->dmp_hdr.trigger_reason =BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER ; - queue_work(data->workqueue, &data->rx_work); +/* queue_work() returns false if the work is disabled (reset or +* remove in progress); clear the in-progress bit so a later +* trigger can succeed once the work is re-enabled. +*/ +if (!queue_work (data->coredump_workqueue, &data->coredump_work)) + clear_bit(BTINTEL_PCIE_COREDUMP_INPROGRESS, &data->flags); }#endif
@@ -3065,7 +3127,7 @@ static int btintel_pcie_resume(struct device *dev) &data->flags)) { data->dmp_hdr.trigger_reason =BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT ; -queue_work (data->workqueue, &data->rx_work); +queue_work (data->coredump_workqueue, &data->coredump_work); }set_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags);btintel_pcie_reset (data->hdev);
drivers/bluetooth/btintel_pcie.h +5 -0
@@ -466,6 +466,8 @@ struct btintel_pcie_dump_header {* @workqueue: workqueue for RX work * @rx_skb_q: SKB queue for RX packet * @rx_work: RX work struct to process the RX packet in @rx_skb_q +* @coredump_workqueue: dedicated workqueue for coredump collection +* @coredump_work: work struct for coredump trace collection * @dma_pool: DMA pool for descriptors, index array and ci * @dma_p_addr: DMA address for pool * @dma_v_addr: address of pool
@@ -514,6 +516,9 @@ struct btintel_pcie_data {struct work_struct rx_work;struct work_struct reset_work; +struct workqueue_struct *coredump_workqueue; +struct work_struct coredump_work; +struct dma_pool *dma_pool;dma_addr_t dma_p_addr;void *dma_v_addr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1462/2077 Bluetooth: btintel_pcie: Refactor FLR to use device_reprobe()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiran K <[email protected]>
[ Upstream commit 9c36951474d8e1127f4946f39cb874a200f34e9f ]
The FLR branch in btintel_pcie_reset_work() open-coded the entire re-init sequence: btintel_pcie_release_hdev() (hci_unregister_dev + hci_free_dev), pci_try_reset_function(), enable_interrupts / config_msix / enable_bt / reset_ia / start_rx, then btintel_pcie_setup_hdev() (hci_alloc_dev_priv + hci_register_dev). Every probe() init step had to be kept in sync with this second copy in the reset path, and any failure mid-sequence left state to unwind by hand.
The PLDR path already delegates teardown and re-init to the PCI core via device_reprobe(): .remove() destroys data through devres and unregisters hdev, then .probe() rebuilds everything from scratch. Apply the same model to FLR.
Introduce btintel_pcie_perform_flr() mirroring perform_pldr(). It runs pci_try_reset_function() (required to avoid the device_lock ABBA against btintel_pcie_remove(), which calls disable_work_sync(&reset_work) while holding device_lock) followed by device_reprobe(). On success, data is destroyed and a fresh probe re-INIT_WORKs coredump_work with disable count 0, so enable_work() must not be called; on failure, data is still alive and the caller balances the earlier disable_work_sync(). The contract is documented on the helper and reiterated at the reset_work() call site.
reset_work() shrinks to interrupt/worker drain, dispatch on reset_type, and the single asymmetry between the two paths. The out_enable label, the manual unregister/register pair, and the forward declaration of btintel_pcie_setup_hdev() are dropped.
No intended functional change; FLR and PLDR now share one teardown contract.
--- drivers/bluetooth/btintel_pcie.c | 102 ++++++++++++++++--------------- 1 file changed, 52 insertions(+), 50 deletions(-)
drivers/bluetooth/btintel_pcie.c +52 -50
@@ -2114,6 +2114,9 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,if (test_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags))return -ENODEV ; +if (test_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags)) +return -ENODEV ; +/* Due to the fw limitation, the type header of the packet should be * 4 bytes unlike 1 byte for UART. In UART, the firmware can read * the first byte to get the packet type and redirect the rest of data
@@ -2472,7 +2475,6 @@ static void btintel_pcie_inc_recovery_count(struct pci_dev *pdev, } } -static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data);static void btintel_pcie_reset (struct hci_dev *hdev);static int btintel_pcie_acpi_reset_method (struct btintel_pcie_data *data)
@@ -2583,12 +2585,45 @@ static void btintel_pcie_perform_pldr(struct btintel_pcie_data *data) } } +/* +* Issue a Function Level Reset and hand teardown/re-init off to the PCI +* core via device_reprobe(), mirroring the PLDR path's contract. +* +* Caller must hold pci_lock_rescan_remove() and must have already +* disabled interrupts and drained both rx_work and coredump_work. +*/ +static int btintel_pcie_perform_flr (struct btintel_pcie_data *data) +{ +struct pci_dev *pdev = data->pdev; +int err; + +/* pci_try_reset_function() avoids the device_lock ABBA against +* btintel_pcie_remove(): .remove() runs with device_lock held and +* then waits for this work via disable_work_sync(); the blocking +* pci_reset_function() would deadlock by trying to re-acquire +* device_lock here. +*/ + err =pci_try_reset_function (pdev); +if (err) { +BT_ERR ("Failed resetting the pcie device (%d)" , err); +return err; + } + +/* device_reprobe() always detaches the driver first (running +* .remove(), which frees 'data'); any re-probe failure leaves the +* device unbound but 'data' is already gone, so just log it. +*/ +if (device_reprobe (&pdev->dev)) +BT_ERR ("BT reprobe failed for BDF:%s" ,pci_name (pdev)); + +return 0 ; +} +static void btintel_pcie_reset_work (struct work_struct *wk) {struct btintel_pcie_data *data = container_of(wk, struct btintel_pcie_data, reset_work);struct pci_dev *pdev = data->pdev; -int err;pci_lock_rescan_remove ();
@@ -2608,60 +2643,27 @@ static void btintel_pcie_reset_work(struct work_struct *wk)disable_work_sync (&data->coredump_work);bt_dev_dbg (data->hdev,"Release bluetooth interface" ); + +/* Both reset paths follow the same contract: on success they +* destroy 'data' via device_reprobe() (a fresh probe re-INIT_WORKs +* the coredump_work with disable count 0), so enable_work() must +* NOT be called on the success path. Only the FLR path can fail +* with 'data' still alive, in which case we balance the +* disable_work_sync() above so a later successful reset is not +* permanently blocked. +* +* pci_lock_rescan_remove() (held above) serializes against PCI +* device addition/removal (hotplug), so no device can be added to +* or removed from the bus list while this code runs. +*/ if (data->reset_type ==BTINTEL_PCIE_IOSF_PRR_PLDR ) { -/* This function holds pci_lock_rescan_remove(), which acquires -* pci_rescan_remove_lock. This mutex serializes against PCI device -* addition/removal (hotplug), so no device can be added to or -* removed from the bus list while this code runs. -* -* device_reprobe() inside btintel_pcie_perform_pldr() destroys -* 'data' via .remove(); a fresh probe re-INIT_WORKs the -* coredump_work with disable count 0, so we must not call -* enable_work() on this path. -*/ btintel_pcie_perform_pldr (data); goto out; } -btintel_pcie_release_hdev (data); - -/* Use pci_try_reset_function() rather than pci_reset_function() to -* avoid an ABBA deadlock against btintel_pcie_remove(): the PCI core -* calls .remove() with device_lock held, and remove() then waits for -* this work via cancel_work_sync(); pci_reset_function() would in -* turn try to acquire the same device_lock, deadlocking both paths. -*/ - err =pci_try_reset_function (pdev); -if (err) { -BT_ERR ("Failed resetting the pcie device (%d)" , err); - goto out_enable; - } -btintel_pcie_enable_interrupts (data); -btintel_pcie_config_msix (data); - - err =btintel_pcie_enable_bt (data); -if (err) { -BT_ERR ("Failed to enable bluetooth hardware after reset (%d)" , - err); - goto out_enable; - } - -btintel_pcie_reset_ia (data); -btintel_pcie_start_rx (data); - data->flags =0 ; +if (btintel_pcie_perform_flr (data)) +enable_work (&data->coredump_work); - err =btintel_pcie_setup_hdev (data); -if (err) { -BT_ERR ("Failed registering hdev (%d)" , err); - goto out_enable; - } - -out_enable: -/* Balance disable_work_sync() above on every exit. Leaving the -* counter incremented on a failed reset would permanently disable -* coredump_work even after a later successful reset. -*/ -enable_work (&data->coredump_work); out:pci_dev_put (pdev);pci_unlock_rescan_remove ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1463/2077 Bluetooth: ISO: fix malformed ISO_END/CONT handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit e054c1a6ae7310d2815778fddb87da616e11c255 ]
Core specification (Part C vol 4 sec 5.4.5) does not exclude empty ISO_CONT, ISO_END packets. We currently reject them if they are last.
If controller sends malformed sequence
ISO_START -> rx_len = 4, ISO_CONT skb->len 4, ISO_START
that ends payload in ISO_CONT, we leak conn->rx_skb. If controller sends too long ISO_END, we panic on skb_put. If controller sends too short ISO_END we accept it.
Fix by marking unfinished ISO_START via conn->rx_skb != NULL. Check skb->len properly before skb_put. Combine the ISO_CONT/END code paths as they require the same initial checks. Reject too short ISO_END packets.
--- net/bluetooth/iso.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
net/bluetooth/iso.c +16 -15
@@ -2539,7 +2539,7 @@ int iso_recv(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, u16 flags)switch (pb) {case ISO_START :case ISO_SINGLE : -if (conn->rx_len) { +if (conn->rx_skb || conn->rx_len) {BT_ERR ("Unexpected start frame (len %d)" , skb->len);kfree_skb (conn->rx_skb); conn->rx_skb =NULL ;
@@ -2620,12 +2620,14 @@ int iso_recv(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, u16 flags)break ;case ISO_CONT : -BT_DBG ("Cont: frag len %d (expecting %d)" , skb->len, +case ISO_END : +BT_DBG ("%s: frag len %d (expecting %d)" , + (pb ==ISO_END ) ?"End" :"Cont" , skb->len, conn->rx_len); -if (!conn->rx_len) { -BT_ERR ("Unexpected continuation frame (len %d)" , - skb->len); +if (!conn->rx_skb) { +BT_ERR ("Unexpected ISO %s frame (len %d)" , + (pb ==ISO_END ) ?"End" :"Cont" , skb->len); goto drop; }
@@ -2641,17 +2643,9 @@ int iso_recv(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, u16 flags)skb_copy_from_linear_data (skb,skb_put (conn->rx_skb, skb->len), skb->len); conn->rx_len -= skb->len; -break ; -case ISO_END : -if (!conn->rx_len) { -BT_ERR ("Unexpected end frame (len %d)" , skb->len); - goto drop; - } - -skb_copy_from_linear_data (skb,skb_put (conn->rx_skb, skb->len), - skb->len); - conn->rx_len -= skb->len; +if (pb ==ISO_CONT ) +break ;if (!conn->rx_len) {struct sk_buff *rx_skb = conn->rx_skb;
@@ -2662,6 +2656,13 @@ int iso_recv(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, u16 flags)*/ conn->rx_skb =NULL ;iso_recv_frame (conn, rx_skb); + }else { +BT_ERR ("ISO fragment incomplete (len %d, expected %d)" , + skb->len, conn->rx_len); +kfree_skb (conn->rx_skb); + conn->rx_skb =NULL ; + conn->rx_len =0 ; + goto drop; }break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1464/2077 Bluetooth: ISO: exclude RFU bits from ISO_SDU_Length
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit fd076d8deeab6f9f18ef13400f89e1f550df665b ]
slen contains ISO_SDU_Length (12 bits), RFU (2 bits), Packet_Status_Flags (2 bits).
Exclude the RFU bits from hci_iso_data_len. Also add masks to the pack macro.
--- include/net/bluetooth/hci.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/net/bluetooth/hci.h +3 -2
@@ -3410,8 +3410,9 @@ static inline struct hci_iso_hdr *hci_iso_hdr(const struct sk_buff *skb)#define hci_iso_flags_pack (pb, ts) ((pb & 0x03) | ((ts & 0x01) << 2))/* ISO data length and flags pack/unpack */ -#define hci_iso_data_len_pack (h, f) ((__u16) ((h) | ((f) << 14))) -#define hci_iso_data_len (h) ((h) & 0x3fff) +#define hci_iso_data_len_pack (h, f) ((__u16) (((h) & 0x0fff) | \ + (((f) & 0x3) << 14))) +#define hci_iso_data_len (h) ((h) & 0x0fff)#define hci_iso_data_flags (h) ((h) >> 14)/* codec transport types */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1465/2077 Bluetooth: bpa10x: avoid OOB read of revision string in bpa10x_setup()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit dd068ef044128db655f48323a4acfd5907e04903 ]
bpa10x_setup() sends the vendor command 0xfc0e and passes the response to bt_dev_info() and hci_set_fw_info() as a "%s" string starting at skb->data + 1, without checking the length:
bt_dev_info(hdev, "%s", (char *)(skb->data + 1)); hci_set_fw_info(hdev, "%s", skb->data + 1);
A device that returns a one-byte response (status only) leaves skb->data + 1 past the end of the data, and the %s walk reads adjacent slab memory until it meets a NUL. The same happens when the payload is not NUL-terminated within skb->len. The out-of-bounds bytes end up in the kernel log and the firmware-info debugfs file.
Print the revision string with a bounded "%.*s" limited to skb->len - 1 instead. This keeps the string readable for well-behaved devices while never reading past the received data, and does not fail setup, so a device returning a short or unterminated response keeps working.
--- drivers/bluetooth/bpa10x.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/bluetooth/bpa10x.c +6 -2
@@ -255,9 +255,13 @@ static int bpa10x_setup(struct hci_dev *hdev)if (IS_ERR (skb))return PTR_ERR (skb); -bt_dev_info (hdev,"%s" , (char *)(skb->data +1 )); +/* Bounded print: the device controls skb->len. */ +if (skb->len >1 ) { +int len = skb->len -1 ; -hci_set_fw_info (hdev,"%s" , skb->data +1 ); +bt_dev_info (hdev,"%.*s" , len, (char *)(skb->data +1 )); +hci_set_fw_info (hdev,"%.*s" , len, skb->data +1 ); + }kfree_skb (skb);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1466/2077 Bluetooth: L2CAP: fix tx ident leak for commands without a response
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stig Hornang <[email protected]>
[ Upstream commit 6e1930ece855a4c256f1c7e6632d634cfb9888b5 ]
Commit 6c3ea155e5ee ("Bluetooth: L2CAP: Fix not tracking outstanding TX ident") changed ident allocation to use an IDA, releasing idents in l2cap_put_ident() when the matching response command is received.
But identifiers allocated for commands that have no response defined are never released. In particular L2CAP_LE_CREDITS is sent repeatedly for the lifetime of an LE CoC channel, so a peer streaming data to the host exhausts the 1-255 ident range after 254 credit packets. From then on l2cap_get_ident() fails:
kernel: Bluetooth: Unable to allocate ident: -28
and every subsequent L2CAP_LE_CREDITS packet is sent with ident 0, which is invalid (Core Spec, Vol 3, Part A, Section 4: "Signaling identifier 0x00 is an invalid identifier and shall never be used in any command"). Remote stacks that validate the ident drop these commands, never receive new credits, and the channel stalls permanently. With default socket buffers this happens after roughly 0.5 MB of received data (the exact amount depends on the socket receive buffer):
< ACL Data TX: Handle 2048 flags 0x00 dlen 12
LE L2CAP: LE Flow Control Credit (0x16) ident 0 len 4
Source CID: 64
Credits: 1
Release the ident immediately after sending L2CAP_LE_CREDITS since no response will ever release it. Use a local variable instead of chan->ident so that an ident that an EXT_FLOWCTL channel may be waiting on (e.g. a pending reconfigure) is not overwritten by a credit packet.
Also add the missing L2CAP_LE_CONN_RSP case to l2cap_put_ident() so idents allocated for outgoing L2CAP_LE_CONN_REQ commands are released when the response arrives.
--- net/bluetooth/l2cap_core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +13 -2
@@ -4824,6 +4824,7 @@ static void l2cap_put_ident(struct l2cap_conn *conn, u8 code, u8 id)case L2CAP_ECHO_RSP :case L2CAP_INFO_RSP :case L2CAP_CONN_PARAM_UPDATE_RSP : +case L2CAP_LE_CONN_RSP :case L2CAP_ECRED_CONN_RSP :case L2CAP_ECRED_RECONF_RSP :/* First do a lookup since the remote may send bogus ids that
@@ -6721,6 +6722,7 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan)struct l2cap_conn *conn = chan->conn;struct l2cap_le_credits pkt;u16 return_credits =l2cap_le_rx_credits (chan); +int ident;if (chan->mode !=L2CAP_MODE_LE_FLOWCTL && chan->mode !=L2CAP_MODE_EXT_FLOWCTL )
@@ -6738,9 +6740,18 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan) pkt.cid =cpu_to_le16 (chan->scid); pkt.credits =cpu_to_le16 (return_credits); - chan->ident =l2cap_get_ident (conn); + ident =l2cap_get_ident (conn); -l2cap_send_cmd (conn, chan->ident,L2CAP_LE_CREDITS ,sizeof (pkt), &pkt); +l2cap_send_cmd (conn, ident,L2CAP_LE_CREDITS ,sizeof (pkt), &pkt); + +/* L2CAP_LE_CREDITS has no response so the ident is never released by +* l2cap_put_ident() - release it right away, otherwise the tx_ida +* range is exhausted after 254 packets and from then on credits are +* sent with the invalid ident 0, which some remote stacks ignore, +* stalling the channel. +*/ +if (ident >0 ) +ida_free (&conn->tx_ida, ident); }void l2cap_chan_rx_avail (struct l2cap_chan *chan,ssize_t rx_avail)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1467/2077 ring-buffer: Fix event length with forced 8-byte alignment
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Wang <[email protected]>
[ Upstream commit c37e0a4b79a6bbb96ce5ffe279d7c001e20529e0 ]
When RB_FORCE_8BYTE_ALIGNMENT is true, rb_calculate_event_length() reserves the space of event->array[0] for placing the data length and rb_update_event() stores the data length in event->array[0] accordingly. As a result the whole event length will add extra 4 bytes for sizeof(event.array[0]) unconditionally.
But ring_buffer_event_length() only subtracts the sizeof(event->array[0]) for events larger than RB_MAX_SMALL_DATA + sizeof(event->array[0]). As a result, small events on architectures with RB_FORCE_8BYTE_ALIGNMENT=true report a data length that is 4 bytes larger than expected.
To fix it, add the RB_FORCE_8BYTE_ALIGNMENT as a condition to subtract the size of that length field whenever RB_FORCE_8BYTE_ALIGNMENT is true.
This issue is observed in a riscv64 kernel with CONFIG_HAVE_64BIT_ALIGNED_ACCESS set to y, when we run ftrace selftest trace_marker_raw.tc, we get the weird log: for cases where the id is 1..100, the number of data field is 8*N, but once id exceeds 100, the number of data field becomes 8*N+4:
# 1 buf: 58 00 00 00 80 5e d1 63 (number of data field is 8*1)
...
# a buf: 58 ... (number of data field is 8*2) ... # 64 buf: 58 ... (number of data field is 8*13) # 65 buf: 58 ... (number of data field is 8*13+4)
After applying this change, the number of data field keeps being 8*N+4 consistently.
--- kernel/trace/ring_buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/ring_buffer.c +2 -1
@@ -266,7 +266,8 @@ unsigned ring_buffer_event_length(struct ring_buffer_event *event)if (event->type_len >RINGBUF_TYPE_DATA_TYPE_LEN_MAX )return length; length -=RB_EVNT_HDR_SIZE ; -if (length >RB_MAX_SMALL_DATA +sizeof (event->array[0 ])) +if (length >RB_MAX_SMALL_DATA +sizeof (event->array[0 ]) || +RB_FORCE_8BYTE_ALIGNMENT ) length -=sizeof (event->array[0 ]);return length; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1468/2077 accel/amdxdna: Prevent PM resume deadlock in hwctx_sync_debug_bo()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhi Hou <[email protected]>
[ Upstream commit e35c9cf5512814fb04f369f2eada64f0a7164609 ]
amdxdna_hwctx_sync_debug_bo() invokes the hardware hwctx_sync_debug_bo() callback while holding xdna->dev_lock.
The callback may call amdxdna_cmd_submit(), which in turn calls amdxdna_pm_resume_get(). If the device is suspended, amdxdna_pm_resume_get() may synchronously execute amdxdna_pm_resume(), which also acquires xdna->dev_lock, resulting in a deadlock.
Avoid the deadlock by calling amdxdna_pm_resume_get() before holding xdna->dev_lock in both amdxdna_hwctx_sync_debug_bo() and amdxdna_drm_config_hwctx_ioctl()
--- drivers/accel/amdxdna/aie2_ctx.c | 2 +- drivers/accel/amdxdna/amdxdna_ctx.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/accel/amdxdna/aie2_ctx.c +1 -1
@@ -815,7 +815,7 @@ static int aie2_hwctx_cu_config(struct amdxdna_hwctx *hwctx, void *buf, u32 sizeif (!hwctx->cus)return -ENOMEM ; - ret =amdxdna_pm_resume_get_locked (xdna); + ret =amdxdna_pm_resume_get (xdna);if (ret) goto free_cus;
drivers/accel/amdxdna/amdxdna_ctx.c +22 -4
@@ -356,16 +356,25 @@ int amdxdna_drm_config_hwctx_ioctl(struct drm_device *dev, void *data, struct drreturn -EINVAL ; } -guard (mutex)(&xdna->dev_lock); + ret =amdxdna_pm_resume_get (xdna); +if (ret) { +XDNA_ERR (xdna,"Resume failed, ret %d" , ret); + goto free_buf; + } + +mutex_lock (&xdna->dev_lock); hwctx =xa_load (&client->hwctx_xa, args->handle);if (!hwctx) {XDNA_DBG (xdna,"PID %d failed to get hwctx %d" , client->pid, args->handle); ret = -EINVAL ; - goto free_buf; + goto unlock; } ret = xdna->dev_info->ops->hwctx_config (hwctx, args->param_type, val, buf, buf_size); +unlock: +mutex_unlock (&xdna->dev_lock); +amdxdna_pm_suspend_put (xdna); free_buf:kfree (buf);return ret;
@@ -386,16 +395,25 @@ int amdxdna_hwctx_sync_debug_bo(struct amdxdna_client *client, u32 debug_bo_hdl)if (!gobj)return -EINVAL ; + ret =amdxdna_pm_resume_get (xdna); +if (ret) { +XDNA_ERR (xdna,"Resume failed, ret %d" , ret); + goto put_obj; + } + abo =to_xdna_obj (gobj); -guard (mutex)(&xdna->dev_lock); +mutex_lock (&xdna->dev_lock); hwctx =xa_load (&client->hwctx_xa, abo->assigned_hwctx);if (!hwctx) { ret = -EINVAL ; - goto put_obj; + goto unlock; } ret = xdna->dev_info->ops->hwctx_sync_debug_bo (hwctx, debug_bo_hdl); +unlock: +mutex_unlock (&xdna->dev_lock); +amdxdna_pm_suspend_put (xdna); put_obj:drm_gem_object_put (gobj);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1469/2077 accel/amdxdna: Use unsigned long for nr_pages in amdxdna_hmm_register()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhi Hou <[email protected]>
[ Upstream commit 18aaebdf43366954345a6721ed2bff3ac3c9fa61 ]
nr_pages is declared as u32 in amdxdna_hmm_register(), which may not be large enough to represent the number of pages for large mappings.
Use unsigned long for nr_pages to avoid potential overflow.
--- drivers/accel/amdxdna/amdxdna_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_gem.c +1 -1
@@ -291,7 +291,7 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,unsigned long len = vma->vm_end - vma->vm_start;unsigned long addr = vma->vm_start;struct amdxdna_umap *mapp; -u32 nr_pages; +unsigned long nr_pages;int ret;if (!xdna->dev_info->ops->hmm_invalidate)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1470/2077 accel/amdxdna: Fix VMA access race
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhi Hou <[email protected]>
[ Upstream commit 1ba02717e821cf14ece642273958647e79698d3d ]
aie2_populate_range() and amdxdna_umap_release() access a saved VMA pointer that may have already been freed, leading to a potential use-after-free.
Remove the VMA accesses from these functions to avoid the race.
--- drivers/accel/amdxdna/aie2_ctx.c | 2 -- drivers/accel/amdxdna/amdxdna_gem.c | 31 +++++++++++++++++++---------- drivers/accel/amdxdna/amdxdna_gem.h | 1 - 3 files changed, 21 insertions(+), 13 deletions(-)
drivers/accel/amdxdna/aie2_ctx.c +0 -2
@@ -977,8 +977,6 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo)kref_get (&mapp->refcnt);up_write (&xdna->notifier_lock); -XDNA_DBG (xdna,"populate memory range %lx %lx" , - mapp->vma->vm_start, mapp->vma->vm_end); mm = mapp->notifier.mm;if (!mmget_not_zero (mm)) {amdxdna_umap_put (mapp);
drivers/accel/amdxdna/amdxdna_gem.c +21 -10
@@ -200,7 +200,7 @@ static bool amdxdna_hmm_invalidate(struct mmu_interval_notifier *mni, xdna =to_xdna_dev (to_gobj (abo)->dev);XDNA_DBG (xdna,"Invalidating range 0x%lx, 0x%lx, type %d" , - mapp->vma->vm_start, mapp->vma->vm_end, abo->type); + mapp->range.start, mapp->range.end, abo->type);if (!mmu_notifier_range_blockable (range))return false;
@@ -229,15 +229,23 @@ static const struct mmu_interval_notifier_ops amdxdna_hmm_ops = { .invalidate = amdxdna_hmm_invalidate, }; +static inline bool compare_range (struct amdxdna_umap *mapp, +struct mm_struct *mm, +unsigned long start,unsigned long end) +{ +return (!mapp->unmapped && mapp->notifier.mm == mm && + mapp->range.start == start && mapp->range.end == end); +} +static void amdxdna_hmm_unregister (struct amdxdna_gem_obj *abo,struct vm_area_struct *vma) {struct amdxdna_dev *xdna =to_xdna_dev (to_gobj (abo)->dev);struct amdxdna_umap *mapp; -down_read (&xdna->notifier_lock); +down_write (&xdna->notifier_lock);list_for_each_entry (mapp, &abo->mem.umap_list, node) { -if (!vma || mapp->vma == vma) { +if (!vma ||compare_range (mapp, vma->vm_mm, vma->vm_start, vma->vm_end)) {if (!mapp->unmapped) {queue_work (xdna->notifier_wq, &mapp->hmm_unreg_work); mapp->unmapped = true;
@@ -246,19 +254,16 @@ static void amdxdna_hmm_unregister(struct amdxdna_gem_obj *abo,break ; } } -up_read (&xdna->notifier_lock); +up_write (&xdna->notifier_lock); }static void amdxdna_umap_release (struct kref *ref) { struct amdxdna_umap *mapp = container_of(ref, struct amdxdna_umap, refcnt);struct amdxdna_gem_obj *abo = mapp->abo; -struct vm_area_struct *vma = mapp->vma;struct amdxdna_dev *xdna;mmu_interval_notifier_remove (&mapp->notifier); -if (is_import_bo (abo) && vma->vm_file && vma->vm_file->f_mapping) -mapping_clear_unevictable (vma->vm_file->f_mapping); xdna =to_xdna_dev (to_gobj (mapp->abo)->dev);down_write (&xdna->notifier_lock);
@@ -297,6 +302,15 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,if (!xdna->dev_info->ops->hmm_invalidate)return 0 ; +down_read (&xdna->notifier_lock); +list_for_each_entry (mapp, &abo->mem.umap_list, node) { +if (compare_range (mapp, current->mm, addr, addr + len)) { +up_read (&xdna->notifier_lock); +return 0 ; + } + } +up_read (&xdna->notifier_lock); + mapp =kzalloc_obj (*mapp);if (!mapp)return -ENOMEM ;
@@ -322,13 +336,10 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo, mapp->range.start = vma->vm_start; mapp->range.end = vma->vm_end; mapp->range.default_flags =HMM_PFN_REQ_FAULT ; - mapp->vma = vma; mapp->abo = abo;kref_init (&mapp->refcnt);INIT_WORK (&mapp->hmm_unreg_work, amdxdna_hmm_unreg_work); -if (is_import_bo (abo) && vma->vm_file && vma->vm_file->f_mapping) -mapping_set_unevictable (vma->vm_file->f_mapping);down_write (&xdna->notifier_lock);if (list_empty (&abo->mem.umap_list))
drivers/accel/amdxdna/amdxdna_gem.h +0 -1
@@ -12,7 +12,6 @@#include "amdxdna_pci_drv.h" struct amdxdna_umap { -struct vm_area_struct *vma;struct mmu_interval_notifier notifier;struct hmm_range range;struct work_struct hmm_unreg_work;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1471/2077 net/tls: Consume empty data records in tls_sw_read_sock()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 3be28e2c9cd0230cb51fd4967df095273afd3848 ]
A peer may send a zero-length TLS application_data record; TLS 1.3 explicitly permits these as a traffic-analysis countermeasure (RFC 8446, Section 5.1). After decryption such a record has full_len ==
0. tls_sw_read_sock() hands it to the read_actor, which has no payload to consume and returns zero. The loop treats a zero return as backpressure (used <= 0), requeues the skb at the head of rx_list, and stops. rx_list is serviced head-first on the next call, so the empty record is dequeued, fails the same way, and is requeued again; every later record on the connection is blocked behind it.
tls_sw_recvmsg() does not stall on this: a zero-length data record copies nothing and falls through to consume_skb(). Mirror that in the read_sock() path by recognizing an empty data record before the actor runs, consuming it, and continuing.
--- net/tls/tls_sw.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/tls/tls_sw.c +11 -0
@@ -2424,6 +2424,17 @@ int tls_sw_read_sock(struct sock *sk, read_descriptor_t *desc, goto read_sock_requeue; } +/* An empty data record (legal in TLS 1.3) gives a zero +* read_actor return, indistinguishable from the consumer +* stalling; the used <= 0 path would requeue it at the +* head of rx_list and block all later records. Consume it +* here instead. +*/ +if (rxm->full_len ==0 ) { +consume_skb (skb); +continue ; + } + used =read_actor (desc, skb, rxm->offset, rxm->full_len);if (used <=0 ) {if (!copied)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1472/2077 net: rnpgbe: fix mailbox endianness and remove pointer casts
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dong Yibo <[email protected]>
[ Upstream commit d9d6d67f4c0877fde783c9d5beee013bcf1b1e85 ]
The rnpgbe mailbox exchanges data through 32-bit MMIO registers in little-endian wire format. The original code had two problems:
1. FW structs (with __le16/__le32 fields) were cast to (u32 *) before reaching the mailbox transport, hiding the endian annotations from sparse.
2. No cpu_to_le32()/le32_to_cpu() conversion was done between CPU-endian MMIO values and the little-endian payload, causing data corruption on big-endian systems.
Fix by adding the missing byte-order conversions in the transport layer and introducing union wrappers (mbx_fw_cmd_req_u, mbx_fw_cmd_reply_u) that overlay each FW struct with a __le32 dwords[] array. Callers fill named fields using cpu_to_le16/32(), then pass dwords[] to the transport, which now takes explicit __le32 * instead of u32 *. This eliminates all pointer casts on the mailbox data path and lets sparse verify the conversions.
--- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c | 26 ++++-- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h | 5 +- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 82 ++++++++++--------- .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 14 ++++ 4 files changed, 80 insertions(+), 47 deletions(-)
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.c +18 -8
@@ -166,18 +166,23 @@ static void mucse_mbx_inc_pf_ack(struct mucse_hw *hw)* * Return: 0 on success, negative errno on failure **/ -static int mucse_read_mbx_pf (struct mucse_hw *hw,u32 *msg,u16 size) +static int mucse_read_mbx_pf (struct mucse_hw *hw,__le32 *msg,u16 size) { -const int size_in_words = size /sizeof (u32); +const int size_in_words = size /sizeof (__le32);struct mucse_mbx_info *mbx = &hw->mbx; +int off =MUCSE_MBX_FWPF_SHM ;int err; err =mucse_obtain_mbx_lock_pf (hw);if (err)return err; +/* memcpy_fromio() is unsuitable: the mailbox uses 32-bit MMIO +* registers, not byte-addressable RAM. readl() guarantees +* the required 32-bit access width. +*/ for (int i =0 ; i < size_in_words; i++) - msg[i] =mbx_data_rd32 (mbx,MUCSE_MBX_FWPF_SHM +4 * i); + msg[i] =cpu_to_le32 (mbx_data_rd32 (mbx, off +4 * i));/* Hw needs write data_reg at last */ mbx_data_wr32 (mbx,MUCSE_MBX_FWPF_SHM ,0 );/* flush reqs as we have read this request data */
@@ -236,7 +241,7 @@ static int mucse_poll_for_msg(struct mucse_hw *hw)* Return: 0 if it successfully received a message notification and * copied it into the receive buffer, negative errno on failure **/ -int mucse_poll_and_read_mbx (struct mucse_hw *hw,u32 *msg,u16 size) +int mucse_poll_and_read_mbx (struct mucse_hw *hw,__le32 *msg,u16 size) {int err;
@@ -290,9 +295,9 @@ static void mucse_mbx_inc_pf_req(struct mucse_hw *hw)* Return: 0 if it successfully copied message into the buffer, * negative errno on failure **/ -static int mucse_write_mbx_pf (struct mucse_hw *hw,u32 *msg,u16 size) +static int mucse_write_mbx_pf (struct mucse_hw *hw,const __le32 *msg,u16 size) { -const int size_in_words = size /sizeof (u32); +const int size_in_words = size /sizeof (__le32);struct mucse_mbx_info *mbx = &hw->mbx;int err;
@@ -300,8 +305,12 @@ static int mucse_write_mbx_pf(struct mucse_hw *hw, u32 *msg, u16 size)if (err)return err; +/* memcpy_toio() would decompose into arbitrary-width accesses; +* the mailbox requires 32-bit MMIO writes via writel(). +*/ for (int i =0 ; i < size_in_words; i++) -mbx_data_wr32 (mbx,MUCSE_MBX_FWPF_SHM + i *4 , msg[i]); +mbx_data_wr32 (mbx,MUCSE_MBX_FWPF_SHM + i *4 , +le32_to_cpu (msg[i]));/* flush acks as we are overwriting the message buffer */ hw->mbx.fw_ack =mucse_mbx_get_fwack (mbx);
@@ -360,7 +369,8 @@ static int mucse_poll_for_ack(struct mucse_hw *hw)* Return: 0 if it successfully copied message into the buffer and * received an ack to that message within delay * timeout_cnt period **/ -int mucse_write_and_wait_ack_mbx (struct mucse_hw *hw,u32 *msg,u16 size) +int mucse_write_and_wait_ack_mbx (struct mucse_hw *hw,const __le32 *msg, +u16 size) {int err;
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx.h +3 -2
@@ -14,7 +14,8 @@#define MUCSE_MBX_REQ BIT(0)/* Request a req to mailbox */ #define MUCSE_MBX_PFU BIT(3)/* PF owns the mailbox buffer */ -int mucse_write_and_wait_ack_mbx (struct mucse_hw *hw,u32 *msg,u16 size); +int mucse_write_and_wait_ack_mbx (struct mucse_hw *hw, +const __le32 *msg,u16 size);void mucse_init_mbx_params_pf (struct mucse_hw *hw); -int mucse_poll_and_read_mbx (struct mucse_hw *hw,u32 *msg,u16 size); +int mucse_poll_and_read_mbx (struct mucse_hw *hw,__le32 *msg,u16 size);#endif /* _RNPGBE_MBX_H */
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c +45 -37
150 lines not on this page · raw message
drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h +14 -0
@@ -80,6 +80,20 @@ struct mbx_fw_cmd_reply { }; } __packed; +/* Union wrappers to expose struct as __le32 dword array for mailbox +* transport, eliminating the need for pointer casts. The __packed +* structs have no padding, so dwords[] overlays the fields exactly. +*/ +union mbx_fw_cmd_req_u { +struct mbx_fw_cmd_req r; +__le32 dwords[sizeof (struct mbx_fw_cmd_req ) /sizeof (__le32)]; +}; + +union mbx_fw_cmd_reply_u { +struct mbx_fw_cmd_reply r; +__le32 dwords[sizeof (struct mbx_fw_cmd_reply ) /sizeof (__le32)]; +}; +int mucse_mbx_sync_fw (struct mucse_hw *hw);int mucse_mbx_powerup (struct mucse_hw *hw,bool is_powerup);int mucse_mbx_reset_hw (struct mucse_hw *hw);
Signature · 1 line
2.53.0