6.6.158-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 620/1193 cpufreq: zero-initialize policy cpumask before sysfs publication
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhongqiu Han <[email protected]>
commit 54d37bcf2f497140b9207968557ddb484058e749 upstream.
cpufreq_policy_alloc() allocates policy->cpus with alloc_cpumask_var(), i.e. without __GFP_ZERO, unlike the sibling related_cpus and real_cpus masks. With CONFIG_CPUMASK_OFFSTACK=y the mask is a separate kmalloc_node() allocation, so its bitmap holds whatever the slab allocator left behind:
cpufreq_online()
cpufreq_policy_alloc()
alloc_cpumask_var(&policy->cpus) /* bitmap is uninitialized */
kobject_init_and_add() /* policy%u/ appears in sysfs */
cpufreq_policy_online()
cpumask_copy(policy->cpus, cpumask_of(cpu)) /* first valid value */This leaves a window in which the sysfs attributes are already reachable while policy->cpus is still garbage. show()/store() gate on policy_is_inactive(), i.e. cpumask_empty(policy->cpus), so a non-zero bitmap makes them run the attribute callbacks on a policy that is not initialized yet.
Fix this by using zalloc_cpumask_var() for policy->cpus.
--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
@@ -1264,7 +1264,7 @@ static struct cpufreq_policy *cpufreq_poif (!policy)return NULL ; -if (!alloc_cpumask_var (&policy->cpus,GFP_KERNEL )) +if (!zalloc_cpumask_var (&policy->cpus,GFP_KERNEL )) goto err_free_policy;if (!zalloc_cpumask_var (&policy->related_cpus,GFP_KERNEL ))
Greg Kroah-Hartman
maintainerPATCH 621/1193 cpufreq: initialize policy rwsem before sysfs publication
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 3e5d1bf4bd687beb2cb4e32a07af695455925588 upstream.
cpufreq_policy_alloc() initializes policy->rwsem after kobject_init_and_add() has created the policy sysfs directory and its default attributes. A sysfs access can therefore reach a policy callback before the semaphore has been initialized.
Initialize policy->rwsem before publishing the policy kobject so sysfs callbacks always see an initialized semaphore.
--- drivers/cpufreq/cpufreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/cpufreq.c +2 -2
@@ -1273,6 +1273,8 @@ static struct cpufreq_policy *cpufreq_poif (!zalloc_cpumask_var (&policy->real_cpus,GFP_KERNEL )) goto err_free_rcpumask; +init_rwsem (&policy->rwsem); +init_completion (&policy->kobj_unregister); ret =kobject_init_and_add (&policy->kobj, &ktype_cpufreq, cpufreq_global_kobject,"policy%u" , cpu);
@@ -1287,8 +1289,6 @@ static struct cpufreq_policy *cpufreq_po goto err_free_real_cpus; } -init_rwsem (&policy->rwsem); -freq_constraints_init (&policy->constraints); policy->nb_min.notifier_call = cpufreq_notifier_min;
Greg Kroah-Hartman
maintainerPATCH 622/1193 exec: do_close_on_exec() before taking exec_update_lock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit e780259b54e618ceb4763fbc21314acf3565e813 upstream.
do_close_on_exec() currently happens while holding the exec_update_lock, which is used in a lot of places that access process state to synchronize access checks.
I recently added another such use of exec_update_lock, causing a regression.
do_close_on_exec() can block waiting for a reply from a filesystem. That means a hung filesystem can block codepaths that use exec_update_lock; and it also means that a FUSE filesystem which attempts to inspect the calling process can deadlock.
To avoid such problems, move do_close_on_exec() before the exec_update_lock is taken, but after the FD table has been copied if necessary.
I have looked through all the calls between the old and new position of the do_close_on_exec() call; there seems to be no file descriptor table access in between.
--- fs/exec.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
fs/exec.c +14 -8
@@ -1274,6 +1274,20 @@ int begin_new_exec(struct linux_binprm * goto out;/* +* We have to apply CLOEXEC before we change whether the process is +* dumpable (in setup_new_exec) to avoid a race with a process in userspace +* trying to access the should-be-closed file descriptors of a process +* undergoing exec(2). +* +* This can block on filesystem ->flush() handlers, including waiting +* for FUSE daemons, so do it before exec_mmap takes the +* exec_update_lock. +* This must happen after the point of no return, and after unsharing +* the FD table. +*/ +do_close_on_exec (me->files); + +/* * Must be called _before_ exec_mmap() as bprm->mm is * not visible until then. Doing it here also ensures * we don't race against replace_mm_exe_file().
@@ -1323,14 +1337,6 @@ int begin_new_exec(struct linux_binprm *clear_syscall_work_syscall_user_dispatch (me); -/* -* We have to apply CLOEXEC before we change whether the process is -* dumpable (in setup_new_exec) to avoid a race with a process in userspace -* trying to access the should-be-closed file descriptors of a process -* undergoing exec(2). -*/ -do_close_on_exec (me->files); -if (bprm->secureexec) {/* Make sure parent cannot signal privileged process. */ me->pdeath_signal =0 ;
Greg Kroah-Hartman
maintainerPATCH 623/1193 drm/drm_exec: fix up contended obj when num_objects is 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sunil Khatri <[email protected]>
commit 159720704d9d652b64390c11fb971e15b0a78d23 upstream.
drm_exec_prepare_array() silently returns success without calling drm_exec_lock_contended() when num_objects is zero. This breaks the invariant upheld by drm_exec_lock_obj(), where every entry point into the locking sequence must first attempt to lock any previously contended object before proceeding.
Drivers that chain multiple drm_exec_prepare_array() calls per drm_exec_until_all_locked() iteration (e.g. amdgpu's userq signal/wait ioctls, which prepare separate read and write BO arrays) can pass an empty array for one of the two calls. If contention is hit while preparing the non-empty array, exec->contended is set and the loop retries; on retry, the empty-array call preceding it is a no-op that never clears exec->contended, so drm_exec_retry_on_contention() immediately jumps back to the top of the loop without ever reaching the call that would resolve the contention. This spins forever.
Fix it by having drm_exec_prepare_array() call drm_exec_lock_contended() directly when num_objects is zero, so a pending contended object dont loop infinitely.
--- drivers/gpu/drm/drm_exec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/drm_exec.c +13 -0
@@ -319,6 +319,19 @@ int drm_exec_prepare_array(struct drm_ex {int ret; +/* +* Make sure to lock a contended object even when no objects are +* given, otherwise drm_exec_retry_on_contention() would loop +* forever on patterns like: +* +* ret = drm_exec_prepare_array(exec, objs, num_objects, ...); +* drm_exec_retry_on_contention(exec); +* +* with num_objects == 0. +*/ +if (!num_objects) +return drm_exec_lock_contended (exec); +for (unsigned int i =0 ; i < num_objects; ++i) { ret =drm_exec_prepare_obj (exec, objects[i], num_fences);if (unlikely (ret))
Greg Kroah-Hartman
maintainerPATCH 624/1193 drm/i915: Fix memory leak in query_perf_config_list()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit cbd3dafc2003db679ccd2f6c6a2551db79657049 upstream.
When krealloc() fails, free the original oa_config_ids before returning to avoid a memory leak.
--- drivers/gpu/drm/i915/i915_query.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_query.c +3 -1
@@ -401,8 +401,10 @@ static int query_perf_config_list(struct ids =krealloc (oa_config_ids, n_configs *sizeof (*oa_config_ids),GFP_KERNEL ); -if (!ids) +if (!ids) { +kfree (oa_config_ids);return -ENOMEM ; + } alloc =fetch_and_zero (&n_configs);
Greg Kroah-Hartman
maintainerPATCH 625/1193 ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
commit 815e07c8fe885a87751c2496a30ae0dcd4118210 upstream.
rb_wake_up_waiters() is a irq_work callback which is initialized with init_irq_work(). As such it will be invoked in thread context on PREEMPT_RT. Invoking the callback in IRQ context on PREEMPT_RT is not an option due its usage of wake_up_all(). Since this callback may run in thread context, it needs to acquire ring_buffer_per_cpu::reader_lock with disabling interrupts and may not assume that they are disabled.
Use raw_spinlock_irqsave() to acquire ring_buffer_per_cpu::reader_lock.
--- kernel/trace/ring_buffer.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
kernel/trace/ring_buffer.c +6 -7
@@ -907,14 +907,13 @@ static void rb_wake_up_waiters(struct irstruct ring_buffer_per_cpu *cpu_buffer = container_of(rbwork, struct ring_buffer_per_cpu, irq_work); -/* Called from interrupt context */ -raw_spin_lock (&cpu_buffer->reader_lock); - rbwork->wakeup_full = false; - rbwork->full_waiters_pending = false; + scoped_guard(raw_spinlock_irqsave, &cpu_buffer->reader_lock) { + rbwork->wakeup_full = false; + rbwork->full_waiters_pending = false; -/* Waking up all waiters, they will reset the shortest full */ - cpu_buffer->shortest_full =0 ; -raw_spin_unlock (&cpu_buffer->reader_lock); +/* Waking up all waiters, they will reset the shortest full */ + cpu_buffer->shortest_full =0 ; + }wake_up_all (&rbwork->full_waiters); }
Greg Kroah-Hartman
maintainerPATCH 626/1193 net: hso: fix TIOCMIWAIT race
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 00f9fbc12320253bfc576fb7539d860029c82d0f upstream.
The task state must be updated before checking the wakeup condition to avoid missing a racing modem status update.
--- drivers/net/usb/hso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/usb/hso.c +1 -1
@@ -1550,10 +1550,10 @@ hso_wait_modem_status(struct hso_serialspin_unlock_irq (&serial->serial_lock);add_wait_queue (&tiocmget->waitq, &wait);for (;;) { +set_current_state (TASK_INTERRUPTIBLE );spin_lock_irq (&serial->serial_lock);memcpy (&cnow, &tiocmget->icount,sizeof (struct uart_icount ));spin_unlock_irq (&serial->serial_lock); -set_current_state (TASK_INTERRUPTIBLE );if (((arg &TIOCM_RNG ) && (cnow.rng != cprev.rng)) || ((arg &TIOCM_DSR ) && (cnow.dsr != cprev.dsr)) || ((arg &TIOCM_CD ) && (cnow.dcd != cprev.dcd))) {
Greg Kroah-Hartman
maintainerPATCH 627/1193 net: mana: Reserve extra CQ slot for the fence completion CQE
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sahil Chandna <[email protected]>
commit 80dd7e754b3aa9637a0758ad93fa209f9650ec48 upstream.
The RX completion queue is sized to hold exactly one CQE per posted RX WQE. MANA_FENCE_RQ makes hardware post an additional CQE_RX_OBJECT_FENCE after the packet CQEs. The current sizing reserves no extra slot for it and in rare cases, CQ has no guaranteed slot for the fence CQE when it is full of packet CQEs. This can lead to dropping the fence completion while the driver waits holding RTNL lock throughout the timeout duration. Reserve one extra CQE slot for CQE_RX_OBJECT_FENCE. mana_gd_alloc_memory() requires queue_size to be a power-of-two and at least MANA_PAGE_SIZE; the reservation pushes cq_size past a power-of-two, so round up the CQ size in mana_create_rxq().
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +5 -1
@@ -2152,6 +2152,10 @@ static int mana_alloc_rx_wqe(struct mana *cq_size +=COMP_ENTRY_SIZE ; } +/* Reserve an extra slot for Fence completion +* event (CQE_RX_OBJECT_FENCE) in case RX CQ is full. +*/ + *cq_size +=COMP_ENTRY_SIZE ;return 0 ; }
@@ -2234,7 +2238,7 @@ static struct mana_rxq *mana_create_rxq( goto out; rq_size =MANA_PAGE_ALIGN (rq_size); - cq_size =MANA_PAGE_ALIGN (cq_size); + cq_size =MANA_PAGE_ALIGN (roundup_pow_of_two (cq_size));/* Create RQ */ memset (&spec,0 ,sizeof (spec));
Greg Kroah-Hartman
maintainerPATCH 628/1193 net: mpls: clear inner_protocol when the last label is popped
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fourie Zhang <[email protected]>
commit 78a86d75a70e1e227711c72865c59b1422d0a5ae upstream.
skb_mpls_push() records the pre-encapsulation network header once, gated on !skb->inner_protocol. skb_mpls_pop() never clears that record, so it outlives the encapsulation it describes.
Open vSwitch can then re-push MPLS onto a packet whose inner_network_header still points at the older, deeper offset: push a label, pop every label, recirculate (ovs_flow_key_update() re-derives key->eth.type and resets network_header, but leaves inner_*), then push again. ovs_fragment() trusts the record:
skb->network_header = skb->inner_network_header;
so skb_network_offset() goes negative. The bound check is signed:
if (skb_network_offset(skb) > MAX_L2_LEN)
a negative offset passes it, and prepare_frag() widens the value:
unsigned int hlen = skb_network_offset(skb); memcpy(&data->l2_data, skb->data, hlen);
which is a ~4GiB memcpy out of a 30-byte per-CPU buffer.
Reproduced on v7.3-rc1. RDX is the truncated length, (unsigned int)(-8):
BUG: unable to handle page fault for address: ffffe8ffffc16000 #PF: supervisor write access in kernel mode Oops: 0002 [#1] SMP KASAN NOPTI RIP: 0010:memcpy+0x8/0x20 RDX: 00000000fffffff8 RSI: ffff888105d732db RDI: ffffe8ffffc16000 prepare_frag+0x3df/0x4e0 ovs_fragment+0x589/0x7e0 do_output+0x4ce/0x5e0 do_execute_actions+0x55d2/0x7b30 ovs_execute_actions+0xea/0x450
Same root-cause shape as commit 975b5b067f52 ("ipv6: sr: restore network header before routing and forwarding"): a stale network header offset reaching a consumer that widens it. Here it originates in the MPLS push/pop path.
Clear inner_protocol once the packet is no longer MPLS, so a later push re-records the current header. net/sched/act_mpls.c is the only other skb_mpls_pop() caller and gets the same fix; sch_frag.c saves and restores inner_protocol around fragmentation in the same way OVS does.
--- net/core/skbuff.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/skbuff.c +7 -0
@@ -6256,6 +6256,13 @@ int skb_mpls_pop(struct sk_buff *skb, __ } skb->protocol = next_proto; +/* The last label is gone, so the inner header recorded by +* skb_mpls_push() no longer describes this packet. Drop it, or a +* later push keeps the stale offset. +*/ +if (!eth_p_mpls (next_proto)) + skb->inner_protocol =0 ; +return 0 ; }EXPORT_SYMBOL_GPL (skb_mpls_pop);
Greg Kroah-Hartman
maintainerPATCH 629/1193 net: openvswitch: fix use-after-free of the flow table mask array
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Szetei <[email protected]>
commit ba4ba11ed6eb8972c69070417fc27b48deb002e8 upstream.
tbl_mask_array_realloc() retires the old mask_array before it stops being reachable:
old = ovsl_dereference(tbl->mask_array);
if (old) {
...
call_rcu(&old->rcu, mask_array_rcu_cb);
}
rcu_assign_pointer(tbl->mask_array, new);call_rcu() only waits for read-side critical sections already in flight. tbl->mask_array still points at old between the call_rcu() and the rcu_assign_pointer(), so a reader entering ovs_flow_tbl_lookup_stats() in that window picks up old in a fresh critical section that the pending grace period does not cover.
tbl_mask_array_realloc() runs in process context under ovs_mutex, so the window is preemptible and can outlast the grace period. Then mask_array_rcu_cb() frees old before the swap runs:
BUG: KASAN: slab-use-after-free in flow_lookup.constprop.0+0x2bf/0x2f0 Read of size 8 at addr ffff888020b3e018 by task poc/741 flow_lookup.constprop.0+0x2bf/0x2f0 ovs_flow_tbl_lookup_stats+0x4a3/0x5c0 ovs_dp_process_packet+0x19c/0x710 ovs_vport_receive+0x243/0x390 internal_dev_xmit+0x81/0x170 Freed by task 728: kfree+0x16a/0x4e0 rcu_core+0x853/0x1030
Publish the new array before retiring the old one. The kfree_rcu() that call_rcu() replaced ran after the swap.
--- net/openvswitch/flow_table.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/openvswitch/flow_table.c +3 -1
@@ -262,11 +262,13 @@ static int tbl_mask_array_realloc(structif (ovsl_dereference (old->masks[i])) new->masks[new->count++] = old->masks[i]; } -call_rcu (&old->rcu, mask_array_rcu_cb); }rcu_assign_pointer (tbl->mask_array, new); +if (old) +call_rcu (&old->rcu, mask_array_rcu_cb); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 630/1193 netfilter: nf_log: unregister loggers before per-net teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 2c018cc4842c33f0c732962e2ab58635e8ae5823 upstream.
nf_log_syslog and nfnetlink_log unregister their per-network namespace operations before unregistering their global logger backends. This leaves a window where a sysctl or netlink writer can rebind the still- registered logger after the per-net pre-exit callback cleared the old selection.
The race looks like this:
CPU 0 CPU 1
---- ----
unregister_pernet_subsys()
nf_log_unset(net, logger)
net->nf.nf_loggers[pf] = NULL
lock nf_log_mutex
find logger in loggers[][]
net->nf.nf_loggers[pf] = logger
unlock nf_log_mutex nf_log_unregister(logger)
lock nf_log_mutex
loggers[pf][type] = NULL
unlock nf_log_mutex
synchronize_rcu()
module exit returns
module core frees backend memory
Later, a sysctl read or packet logging operation can dereference the stale per-net logger pointer.
Fix this by unregistering the global logger backends before tearing down per-net state. Once the global registrations are gone, later writers can no longer rebind the logger. unregister_pernet_subsys() already waits for an RCU grace period after the pre-exit callback clears the per-net selection, while nf_log_unregister() continues to cover readers of the global logger table.
Apply this ordering fix to both nf_log backends that combine per-net teardown with global logger registration.
--- net/netfilter/nf_log_syslog.c | 2 +- net/netfilter/nfnetlink_log.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_log_syslog.c +1 -1
@@ -1063,12 +1063,12 @@ err1: static void __exit nf_log_syslog_exit(void) { -unregister_pernet_subsys (&nf_log_syslog_net_ops);nf_log_unregister (&nf_ip_logger);nf_log_unregister (&nf_arp_logger);nf_log_unregister (&nf_ip6_logger);nf_log_unregister (&nf_netdev_logger);nf_log_unregister (&nf_bridge_logger); +unregister_pernet_subsys (&nf_log_syslog_net_ops); }module_init (nf_log_syslog_init);
net/netfilter/nfnetlink_log.c +1 -1
@@ -1205,8 +1205,8 @@ static void __exit nfnetlink_log_fini(vo {nfnetlink_subsys_unregister (&nfulnl_subsys);netlink_unregister_notifier (&nfulnl_rtnl_notifier); -unregister_pernet_subsys (&nfnl_log_net_ops);nf_log_unregister (&nfulnl_logger); +unregister_pernet_subsys (&nfnl_log_net_ops); }MODULE_DESCRIPTION ("netfilter userspace logging" );
Greg Kroah-Hartman
maintainerPATCH 631/1193 netfilter: report NLM_F_DUMP_FILTERED when all is filtered out
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
commit 7a099b347fef536a84068076e2d384f044e5cfc5 upstream.
NLM_F_DUMP_FILTERED is only set on data elements in the conntrack dump. But when everything is filtered out it is confusing for the user space, since the flag is not reported anymore and it looks like the table was empty, which may or may not be the case.
'answer_flags' were introduced precisely for this use case, and the conntrack dump should set the flag in there in case the filtering was applied.
This is important, for example, to be able to tell if the filters are supported or not by the kernel without modifying the kernel state.
With the proper reporting of NLM_F_DUMP_FILTERED on NLMSG_DONE, an application in user space can just try and dump with an arbitrary filter without worrying that there could be no matching entry. The reported flag will signal that the filtering was applied and therefore supported.
--- net/netfilter/nf_conntrack_netlink.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_netlink.c +2 -0
@@ -1048,6 +1048,8 @@ static int ctnetlink_start(struct netlin } cb->data = filter; +if (filter) + cb->answer_flags =NLM_F_DUMP_FILTERED ;return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 632/1193 vdpa: ifcvf: Put device on unsupported feature error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiong Weimin <[email protected]>
commit 4d470be71196ca0ce302e6623454533dc31b465b upstream.
Route unsupported provisioned features through the common error path after vdpa_alloc_device() so the allocated device and adapter pointer are released consistently.
Message-ID: <[email protected]>
--- drivers/vdpa/ifcvf/ifcvf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vdpa/ifcvf/ifcvf_main.c +2 -1
@@ -708,7 +708,8 @@ static int ifcvf_vdpa_dev_add(struct vdpif (config->device_features & ~device_features) {IFCVF_ERR (pdev,"The provisioned features 0x%llx are not supported by this device with features 0x%llx\n" , config->device_features, device_features); -return -EINVAL ; + ret = -EINVAL ; + goto err; } device_features &= config->device_features; }
Greg Kroah-Hartman
maintainerPATCH 633/1193 vdpa: solidrun: Free IRQs after request failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiong Weimin <[email protected]>
commit e847542ab0545c73354849126150206c29d83929 upstream.
Unwind IRQs already requested by snet_request_irqs() before returning a VQ IRQ request error so a later DRIVER_OK retry starts from a clean state. The IRQs are requested and freed while the PCI device remains bound, so the driver cannot wait for devres cleanup at detach time.
Message-ID: <[email protected]>
--- drivers/vdpa/solidrun/snet_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/vdpa/solidrun/snet_main.c +5 -1
@@ -418,11 +418,15 @@ static int snet_request_irqs(struct pci_ snet->vqs[i]->irq_name, snet->vqs[i]);if (ret) {SNET_ERR (pdev,"Failed to request IRQ\n" ); -return ret; + goto err_free_irqs; } snet->vqs[i]->irq = irq; }return 0 ; + +err_free_irqs: +snet_free_irqs (snet); +return ret; }static void snet_set_status (struct vdpa_device *vdev,u8 status)
Greg Kroah-Hartman
maintainerPATCH 634/1193 scripts/sorttable: Mark long_size as __maybe_unused
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 4f73462856576797b8f3c55564a9be99f76dc67b upstream.
When building in a kernel tree prior to commit b055f4c431e3 ("sorttable:
Move ELF parsing into scripts/elf-parse.[ch]") with clang-23 or newer, which implements a new warning under -Wunused-but-set-variable for static global variable, there is a warning from sorttable because long_size is unused when MCOUNT_SORT_ENABLED is not set:
scripts/sorttable.c:452:12: error: variable 'long_size' set but not used [-Werror,-Wunused-but-set-global]
452 | static int long_size;
| ^Mark long_size as __maybe_unused to avoid inserting more ugly #ifdef directives while insuring the warning does not reappear, as the aforementioned change does not alter the uses of long_size, so it appears to be coincidence that the warning disappears after this refactoring.
--- scripts/sorttable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/sorttable.c +1 -1
@@ -449,7 +449,7 @@ static inline void *get_index(void *star }static int extable_ent_size; -static int long_size; +static int long_size__maybe_unused ;#define ERRSTR_MAXSZ 256
Greg Kroah-Hartman
maintainerPATCH 635/1193 fbdev: vfb: defer cleanup until the last reference
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit a0a34a40ed299c9c7cff6af163a5b883ee9d6d73 upstream.
FBIOGETCMAP takes a shallow snapshot of info->cmap and performs the usercopy after dropping info->lock. vfb_remove() frees the colormap immediately after unregistering the framebuffer, even when an open file still holds a reference to fb_info. A concurrent driver unbind can therefore free the colormap while the ioctl copies it to userspace.
KASAN reports:
BUG: KASAN: slab-use-after-free in _copy_to_user Read of size 512 by task poc/125 _copy_to_user (./include/linux/instrumented.h:129 ./include/linux/uaccess.h:201 lib/usercopy.c:24) fb_cmap_to_user (./include/linux/uaccess.h:230 drivers/video/fbdev/core/fbcmap.c:211) do_fb_ioctl (drivers/video/fbdev/core/fb_chrdev.c:114) Allocated by task 1: fb_alloc_cmap_gfp (./include/linux/slab.h:973 ./include/linux/slab.h:1290 drivers/video/fbdev/core/fbcmap.c:108) vfb_probe (drivers/video/fbdev/vfb.c:459) Freed by task 124: fb_dealloc_cmap (drivers/video/fbdev/core/fbcmap.c:151) vfb_remove (drivers/video/fbdev/vfb.c:489)
unregister_framebuffer() drops the registration reference, and fbdev calls fb_destroy after the last put_fb_info(). Move the registered framebuffer's cleanup into an fb_destroy callback so its colormap and screen buffer stay alive until all file references have been released.
--- drivers/video/fbdev/vfb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/video/fbdev/vfb.c +8 -3
@@ -78,6 +78,13 @@ static int vfb_pan_display(struct fb_varstatic int vfb_mmap (struct fb_info *info,struct vm_area_struct *vma); +static void vfb_destroy (struct fb_info *info) +{ +vfree (info->screen_buffer); +fb_dealloc_cmap (&info->cmap); +framebuffer_release (info); +} +static const struct fb_ops vfb_ops = { .owner =THIS_MODULE , .fb_read = fb_sys_read,
@@ -90,6 +97,7 @@ static const struct fb_ops vfb_ops = { .fb_copyarea = sys_copyarea, .fb_imageblit = sys_imageblit, .fb_mmap = vfb_mmap, + .fb_destroy = vfb_destroy, };/*
@@ -485,9 +493,6 @@ static void vfb_remove(struct platform_dif (info) {unregister_framebuffer (info); -vfree (videomemory); -fb_dealloc_cmap (&info->cmap); -framebuffer_release (info); } }
Greg Kroah-Hartman
maintainerPATCH 636/1193 inet: frags: invalidate queues before flushing them
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yilin Zhang <[email protected]>
commit b824476c56a153934c67c9e0f873e1fd967743d6 upstream.
fqdir_pre_exit() flushes the skbs from incomplete queues without changing their completion state. A fragment which found a queue before high_thresh was cleared can then acquire the queue lock and reuse stale reassembly metadata. A queue concurrently killed after fqdir->dead is set can instead become INET_FRAG_COMPLETE|INET_FRAG_HASH_DEAD while still holding its old skbs; skipping it because it is complete leaves those references behind until asynchronous fqdir teardown.
For IPv6, stale metadata can make ip6_frag_reasm() use the old nhoffset with a new skb and access memory out of bounds. The resulting heap corruption can be leveraged for local privilege escalation when unprivileged network namespaces are available. Unflushed fragments can also keep conntrack references alive after the conntrack per-net cleanup point.
Kill each incomplete queue, then flush every queue still owned by the dying rhashtable. HASH_DEAD identifies that ownership, while complete queues without it are already owned by another destroy path and must be left alone. Releasing a timer reference removed by inet_frag_kill() is deferred to inet_frag_putn(), after the queue lock is dropped.
KASAN report:
BUG: KASAN: slab-out-of-bounds in ipv6_frag_rcv (net/ipv6/reassembly.c:289 (discriminator 2) net/ipv6/reassembly.c:229 (discriminator 2) net/ipv6/reassembly.c:391 (discriminator 2)) Write of size 1 at addr ff110001039c6e00 by task poc/771 Call Trace: ? ipv6_frag_rcv (net/ipv6/reassembly.c:289 (discriminator 2) net/ipv6/reassembly.c:229 (discriminator 2) net/ipv6/reassembly.c:391 (discriminator 2)) ipv6_frag_rcv (net/ipv6/reassembly.c:289 (discriminator 2) net/ipv6/reassembly.c:229 (discriminator 2) net/ipv6/reassembly.c:391 (discriminator 2)) ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479 (discriminator 5)) ip6_input_finish (net/ipv6/ip6_input.c:534) ipv6_rcv (include/net/dst.h:480 (discriminator 3) net/ipv6/ip6_input.c:119 (discriminator 3) net/ipv6/ip6_input.c:109 (discriminator 3) include/linux/netfilter.h:325 (discriminator 3) include/linux/netfilter.h:319 (discriminator 3) net/ipv6/ip6_input.c:351 (discriminator 3)) packet_sendmsg (net/packet/af_packet.c:3110 net/packet/af_packet.c:3142) __x64_sys_sendmmsg (net/socket.c:2883 net/socket.c:2880 net/socket.c:2880) The buggy address belongs to the object at ff110001039c6b40 which belongs to the cache skbuff_small_head of size 704 The buggy address is located 0 bytes to the right of allocated 704-byte region [ff110001039c6b40, ff110001039c6e00) BUG: KASAN: slab-out-of-bounds in ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:423 (discriminator 1)) Read of size 1 at addr ff110001039c6e08 by task poc/771 Call Trace: ? ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:423 (discriminator 1)) ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:423 (discriminator 1)) ip6_input_finish (net/ipv6/ip6_input.c:534) ipv6_rcv (include/net/dst.h:480 (discriminator 3) net/ipv6/ip6_input.c:119 (discriminator 3) net/ipv6/ip6_input.c:109 (discriminator 3) include/linux/netfilter.h:325 (discriminator 3) include/linux/netfilter.h:319 (discriminator 3) net/ipv6/ip6_input.c:351 (discriminator 3)) packet_sendmsg (net/packet/af_packet.c:3110 net/packet/af_packet.c:3142) __x64_sys_sendmmsg (net/socket.c:2883 net/socket.c:2880 net/socket.c:2880) packet_sendmsg (net/packet/af_packet.c:2959 net/packet/af_packet.c:3053 net/packet/af_packet.c:3142) __x64_sys_sendmmsg (net/socket.c:2883 net/socket.c:2880 net/socket.c:2880) The buggy address belongs to the object at ff110001039c6b40 which belongs to the cache skbuff_small_head of size 704 The buggy address is located 8 bytes to the right of allocated 704-byte region [ff110001039c6b40, ff110001039c6e00)
--- net/ipv4/inet_fragment.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ipv4/inet_fragment.c +6 -0
@@ -237,6 +237,8 @@ void fqdir_pre_exit(struct fqdir *fqdir)rhashtable_walk_start (&hti);while ((fq =rhashtable_walk_next (&hti))) { +int refs =0 ; +if (IS_ERR (fq)) {if (PTR_ERR (fq) != -EAGAIN )break ;
@@ -244,8 +246,12 @@ void fqdir_pre_exit(struct fqdir *fqdir) }spin_lock_bh (&fq->lock);if (!(fq->flags &INET_FRAG_COMPLETE )) +inet_frag_kill (fq, &refs); + +if (fq->flags &INET_FRAG_HASH_DEAD )inet_frag_queue_flush (fq,0 );spin_unlock_bh (&fq->lock); +inet_frag_putn (fq, refs); }rhashtable_walk_stop (&hti);
Greg Kroah-Hartman
maintainerPATCH 637/1193 ieee802154: 6lowpan: fix NULL dereference in lowpan_newlink
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
commit bf79662bc85e820ac3b846e2f347da29fbf6ac95 upstream.
TUNSETLINK allows a TUN device to change its link-layer type to ARPHRD_IEEE802154 without initializing ieee802154_ptr. lowpan_newlink() checks only the device type before dereferencing the pointer, so an RTM_NEWLINK request can trigger a NULL pointer dereference.
Reject devices without ieee802154_ptr along with devices of the wrong type.
--- net/ieee802154/6lowpan/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ieee802154/6lowpan/core.c +1 -1
@@ -146,7 +146,7 @@ static int lowpan_newlink(struct net *sr wdev =dev_get_by_index (dev_net (ldev),nla_get_u32 (tb[IFLA_LINK ]));if (!wdev)return -ENODEV ; -if (wdev->type !=ARPHRD_IEEE802154 ) { +if (wdev->type !=ARPHRD_IEEE802154 || !wdev->ieee802154_ptr) {dev_put (wdev);return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 638/1193 ieee802154: hwsim: serialize pib updates to fix double-free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit 979d5b8de8ed4e1f997aef12da5694b99be7b871 upstream.
hwsim_update_pib() does an unserialized read-swap-free of phy->pib:
pib_old = rtnl_dereference(phy->pib); ... rcu_assign_pointer(phy->pib, pib); kfree_rcu(pib_old, rcu);
It assumes the RTNL is held, but ->set_channel is not always called under it: the mac802154 scan worker changes channels via drv_set_channel() without the RTNL. Such an update can race an RTNL-held one on the same phy; both read the same pib_old and both kfree_rcu() it, double-freeing the object. With SLUB percpu sheaves batching kfree_rcu(), this surfaces as a KASAN invalid-free in rcu_free_sheaf().
struct hwsim_phy has no lock for pib. Add one and make the swap atomic with rcu_replace_pointer() under it, dropping the misleading rtnl_dereference().
--- drivers/net/ieee802154/mac802154_hwsim.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ieee802154/mac802154_hwsim.c +7 -3
@@ -72,6 +72,8 @@ struct hwsim_phy {struct ieee802154_hw *hw;u32 idx; +/* Serializes phy->pib_updates. */ +spinlock_t pib_lock;struct hwsim_pib __rcu *pib;bool suspended;
@@ -102,8 +104,6 @@ static int hwsim_update_pib(struct ieee8if (!pib)return -ENOMEM ; - pib_old =rtnl_dereference (phy->pib); - pib->page = page; pib->channel = channel; pib->filt.short_addr = filt->short_addr;
@@ -112,7 +112,10 @@ static int hwsim_update_pib(struct ieee8 pib->filt.pan_coord = filt->pan_coord; pib->filt_level = filt_level; -rcu_assign_pointer (phy->pib, pib); +spin_lock_bh (&phy->pib_lock); + pib_old =rcu_replace_pointer (phy->pib, pib, +lockdep_is_held (&phy->pib_lock)); +spin_unlock_bh (&phy->pib_lock);kfree_rcu (pib_old, rcu);return 0 ; }
@@ -952,6 +955,7 @@ static int hwsim_add_one(struct genl_inf goto err_pib; } +spin_lock_init (&phy->pib_lock); pib->channel =13 ; pib->filt.short_addr =cpu_to_le16 (IEEE802154_ADDR_BROADCAST ); pib->filt.pan_id =cpu_to_le16 (IEEE802154_PANID_BROADCAST );
Greg Kroah-Hartman
maintainerPATCH 639/1193 ipv4: fib: bound automatic table ID allocation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit efdfb1e27a3328085b79540dfe781d537b576ea1 upstream.
fib_empty_table() probes every table ID from 1 until it finds a free one. IPv4 tables are stored in a 256-bucket hash table, so a dense set of IDs makes each probe walk a growing hash chain while RTNL is held.
Automatic table assignment ("ip rule ... table 0") is an IPv4-only legacy path. Bound the automatically allocated ID to 4096 so the RTNL hold stays bounded, without changing lookups of explicitly specified table IDs.
This changes user-visible behavior. A table-0 rule previously received the lowest free ID in 1..RT_TABLE_MAX (0xFFFFFFFF). After this patch the search stops at 4096 and the rule add fails with ENOBUFS if that range is fully occupied. Explicit table IDs above 4096 remain usable.
The automatic path is unused in practice: it is IPv4-only, not documented by ip-rule, uncovered by kernel selftests, and both NetworkManager and systemd refuse table 0.
--- net/ipv4/fib_rules.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv4/fib_rules.c +3 -1
@@ -203,6 +203,8 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_mareturn 1 ; } +#define FIB_MAX_AUTO_TABLE_ID 4096 +static struct fib_table *fib_empty_table (struct net *net) {u32 id =1 ;
@@ -211,7 +213,7 @@ static struct fib_table *fib_empty_tableif (!fib_get_table (net, id))return fib_new_table (net, id); -if (id++ ==RT_TABLE_MAX ) +if (id++ ==FIB_MAX_AUTO_TABLE_ID )break ; }return NULL ;
Greg Kroah-Hartman
maintainerPATCH 640/1193 ipvs: reject invalid states in connection template sync records
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
commit 74cb39735b6cd0aff4b5584158f09376fd97aadf upstream.
IPVS sync receivers validate protocol states before creating or updating a connection. For connection templates, however, they only log states outside the template state range and still store the value in the connection.
A template can be returned by ordinary connection lookup. TCP and SCTP then use the invalid state as an index into their transition tables.
Reject invalid template states in both sync protocol versions before looking up or modifying a connection. The version 1 path handles both IPv4 and IPv6 records.
--- net/netfilter/ipvs/ip_vs_sync.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +8 -8
@@ -1000,10 +1000,10 @@ static void ip_vs_process_message_v0(str pp->name, state);continue ; } - }else { -if (state >=IP_VS_CTPL_S_LAST ) -IP_VS_DBG (7 ,"BACKUP v0, Invalid tpl state %u\n" , - state); + }else if (state >=IP_VS_CTPL_S_LAST ) { +IP_VS_DBG (7 ,"BACKUP v0, Invalid tpl state %u\n" , + state); +continue ; } ip_vs_conn_fill_param(ipvs, AF_INET, s->protocol,
@@ -1160,10 +1160,10 @@ static inline int ip_vs_proc_sync_conn(s retc =40 ; goto out; } - }else { -if (state >=IP_VS_CTPL_S_LAST ) -IP_VS_DBG (7 ,"BACKUP, Invalid tpl state %u\n" , - state); + }else if (state >=IP_VS_CTPL_S_LAST ) { +IP_VS_DBG (7 ,"BACKUP, Invalid tpl state %u\n" , state); + retc =40 ; + goto out; }if (ip_vs_conn_fill_param_sync (ipvs, af, s, ¶m, pe_data, pe_data_len, pe_name, pe_name_len)) {
Greg Kroah-Hartman
maintainerPATCH 641/1193 mac802154: fix use-after-free of sdata via queued RX frames
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
commit 2f37fba846c9fdff5fc15b6d93656057ccd13031 upstream.
The RX softirq producer ieee802154_subif_frame() queues received beacon and MAC-command frames onto local->rx_beacon_list / rx_mac_cmd_list and schedules a process-context worker, storing a raw mac_pkt->sdata (and skb->dev == sdata->dev) with neither a reference nor any locking:
- the lists have no lock: the softirq producer list_add_tail()s while the mac_wq worker list_del()s, so sibling interfaces on the same phy corrupt the list;
- the workers dereference the interface after it may have been freed. mac802154_rx_mac_cmd_worker() touches mac_pkt->sdata directly, and mac802154_rx_beacon_worker() -> mac802154_process_beacon() dereferences skb->dev (== sdata->dev). Removing an interface frees its sdata (netdev_priv) while a queued frame still points at it, so a later worker run is a use-after-free.
Reproduced under KASAN by flooding a victim interface with MAC command frames and removing it (the beacon path is the same class via skb->dev):
BUG: KASAN: slab-use-after-free in mac802154_rx_mac_cmd_worker+0x463/0x630 [mac802154] Read of size 4 at addr ffff888002f9ea18 by task kworker/u8:1/31 Workqueue: phy0-mac-cmds mac802154_rx_mac_cmd_worker [mac802154] Call Trace: mac802154_rx_mac_cmd_worker+0x463/0x630 [mac802154] process_one_work+0x611/0xe80 worker_thread+0x52e/0xdc0 kthread+0x30c/0x630 ret_from_fork+0x2fd/0x3e0
Fix both lists together:
- add local->rx_lock and take it around every list access: the softirq producer (plain spin_lock, softirq context) and the workers and flush (spin_lock_bh, process context);
- pin the interface for the lifetime of a queued frame with netdev_hold()/netdev_put(), so the worker can safely dereference sdata / skb->dev even while the interface is being removed;
- dequeue under the lock at the head and loop-drain the whole list in the workers (they previously processed one frame per run and relied on a later enqueue to drain the rest);
- drop not-yet-started frames of an interface before it is unregistered, from ieee802154_if_remove() (after the RCU grace period) and from the ieee802154_remove_interfaces() loop -- the latter is the whole-phy teardown path, which does not go through ieee802154_if_remove().
An in-flight worker that already dequeued a frame keeps its own netdev reference; unregister_netdevice() then waits it out in netdev_run_todo(), which runs at rtnl_unlock() (rtnl released) and after the interface has been closed, so it does not pin rtnl. A worker blocked in an association TX only delays that one interface's unregister (the usual "waiting for %s to become free"), it does not hold rtnl. netdev_hold() is used for this reason instead of a cancel_work_sync() under rtnl, which would block on the worker's unbounded MLME TX wait via ieee802154_sync_queue().
The mac-command worker additionally skips processing for a stopped interface (ieee802154_sdata_running()), avoiding a needless association response during teardown.
--- include/net/cfg802154.h | 1 net/mac802154/ieee802154_i.h | 8 ++ net/mac802154/iface.c | 6 ++ net/mac802154/main.c | 1 net/mac802154/rx.c | 120 +++++++++++++++++++++++++++++++++++-------- net/mac802154/scan.c | 10 +-- 6 files changed, 117 insertions(+), 29 deletions(-)
include/net/cfg802154.h +1 -0
@@ -353,6 +353,7 @@ struct cfg802154_mac_pkt {struct list_head node;struct sk_buff *skb;struct ieee802154_sub_if_data *sdata; +netdevice_tracker dev_tracker;u8 page;u8 channel; };
net/mac802154/ieee802154_i.h +8 -0
@@ -73,6 +73,10 @@ struct ieee802154_local {struct work_struct rx_beacon_work;struct list_head rx_mac_cmd_list;struct work_struct rx_mac_cmd_work; +/* Serializes rx_beacon_list and rx_mac_cmd_list against the RX +* softirq producer, the mac_wq workers and the teardown flush. +*/ +spinlock_t rx_lock;bool started;bool suspended;
@@ -295,6 +299,10 @@ static inline bool mac802154_is_beaconin }void mac802154_rx_mac_cmd_worker (struct work_struct *work); +void mac802154_flush_list (struct list_head *list, +struct ieee802154_sub_if_data *sdata); +void mac802154_flush_queued_pkts (struct ieee802154_local *local, +struct ieee802154_sub_if_data *sdata);/* interface handling */ int ieee802154_iface_init (void );
net/mac802154/iface.c +6 -0
@@ -694,6 +694,7 @@ void ieee802154_if_remove(struct ieee802mutex_unlock (&sdata->local->iflist_mtx);synchronize_rcu (); +mac802154_flush_queued_pkts (sdata->local, sdata);unregister_netdevice (sdata->dev); }
@@ -705,6 +706,11 @@ void ieee802154_remove_interfaces(structlist_for_each_entry_safe (sdata, tmp, &local->interfaces, list) {list_del_rcu (&sdata->list); +/* Best-effort: a frame the RX softirq queues for this sdata +* after the flush still pins the netdev, so the +* unregister_netdevice() below waits it out. +*/ +mac802154_flush_queued_pkts (local, sdata);unregister_netdevice (sdata->dev); }mutex_unlock (&local->iflist_mtx);
net/mac802154/main.c +1 -0
@@ -91,6 +91,7 @@ ieee802154_alloc_hw(size_t priv_data_lenINIT_LIST_HEAD (&local->interfaces);INIT_LIST_HEAD (&local->rx_beacon_list);INIT_LIST_HEAD (&local->rx_mac_cmd_list); +spin_lock_init (&local->rx_lock);mutex_init (&local->iflist_mtx);tasklet_setup (&local->tasklet, ieee802154_tasklet_handler);
net/mac802154/rx.c +98 -22
161 lines not on this page · raw message
net/mac802154/scan.c +3 -7
@@ -104,13 +104,9 @@ static unsigned int mac802154_scan_get_cstatic void mac802154_flush_queued_beacons (struct ieee802154_local *local) { -struct cfg802154_mac_pkt *mac_pkt, *tmp; - -list_for_each_entry_safe (mac_pkt, tmp, &local->rx_beacon_list, node) { -list_del (&mac_pkt->node); -kfree_skb (mac_pkt->skb); -kfree (mac_pkt); - } +spin_lock_bh (&local->rx_lock); +mac802154_flush_list (&local->rx_beacon_list,NULL ); +spin_unlock_bh (&local->rx_lock); } static void
Greg Kroah-Hartman
maintainerPATCH 642/1193 KVM: PPC: Book3S HV: Set irqfd->producer only on success
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: leixiang <[email protected]>
commit 1144454ea22290d7c6998a2af6239e5995476afc upstream.
Set irqfd->producer only after kvmppc_set_passthru_irq() succeeds to avoid leaving a dangling pointer on failure. The bypass manager does not register a failed producer, so the pointer is never cleared.
--- arch/powerpc/kvm/book3s_hv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_hv.c +2 -2
@@ -5790,12 +5790,12 @@ static int kvmppc_irq_bypass_add_producestruct kvm_kernel_irqfd *irqfd = container_of(cons, struct kvm_kernel_irqfd, consumer); - irqfd->producer = prod; - ret =kvmppc_set_passthru_irq (irqfd->kvm, prod->irq, irqfd->gsi);if (ret)pr_info ("kvmppc_set_passthru_irq (irq %d, gsi %d) fails: %d\n" , prod->irq, irqfd->gsi, ret); +else + irqfd->producer = prod;return ret; }
Greg Kroah-Hartman
maintainerPATCH 643/1193 s390/qeth: allow bridgeport queries despite OS_MISMATCH
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nagamani PV <[email protected]>
commit 74f27fc8642b7e8d139796f8c18ee46df393c2b2 upstream.
When HiperSockets interfaces on the same VCHID span different OS families, reads of the sysfs attributes bridge_role and bridge_state fail with -EPERM if bridge port ownership belongs to another OS family.
As a result, userspace tools such as 'lszdev -ii' cannot retrieve bridge_role and bridge_state, even though firmware returns valid bridge port data for QUERY_BRIDGE_PORTS requests.
The firmware reports IPA_RC_SBP_IQD_OS_MISMATCH (0x0010) to indicate that bridge port ownership belongs to a different OS family. For QUERY_BRIDGE_PORTS operations, firmware still returns valid bridge port data (role=none, state=inactive) together with a primary return code of 0x0000 (success).
Allow QUERY_BRIDGE_PORTS requests to return the bridge port data provided by the firmware despite OS_MISMATCH. To make the OS family mismatch visible to userspace, represent the firmware-reported role "none" as "none (OS family mismatch)" while preserving the reported bridge_state.
The behavior for non-QUERY bridge port commands is unchanged; SET operations continue to return -EPERM when another OS family owns the bridge port.
This restores readability of bridge_role and bridge_state.
--- drivers/s390/net/qeth_l2.h | 3 ++- drivers/s390/net/qeth_l2_main.c | 26 ++++++++++++++++++++++---- drivers/s390/net/qeth_l2_sys.c | 7 ++++++- 3 files changed, 30 insertions(+), 6 deletions(-)
drivers/s390/net/qeth_l2.h +2 -1
@@ -13,7 +13,8 @@ extern const struct attribute_group *qetint qeth_bridgeport_query_ports (struct qeth_card *card,enum qeth_sbp_roles *role, -enum qeth_sbp_states *state); +enum qeth_sbp_states *state, +bool *os_mismatch);int qeth_bridgeport_setrole (struct qeth_card *card,enum qeth_sbp_roles role);int qeth_bridgeport_an_set (struct qeth_card *card,int enable);
drivers/s390/net/qeth_l2_main.c +22 -4
@@ -1157,7 +1157,7 @@ static void qeth_l2_setup_bridgeport_attqeth_bridgeport_setrole (card, card->options.sbp.role);/* Let the callback function refresh the stored role value. */ qeth_bridgeport_query_ports (card, &card->options.sbp.role, -NULL ); +NULL ,NULL ); }if (card->options.sbp.hostnotification) {if (qeth_bridgeport_an_set (card,1 ))
@@ -1544,6 +1544,7 @@ struct _qeth_sbp_cbctl {struct {enum qeth_sbp_roles *role;enum qeth_sbp_states *state; +bool *os_mismatch; } qports; } data; };
@@ -1720,10 +1721,19 @@ static int qeth_bridgeport_query_ports_cstruct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;struct qeth_sbp_port_data *qports; +u16 sbp_rc;int rc;QETH_CARD_TEXT (card,2 ,"brqprtcb" ); - rc =qeth_bridgeport_makerc (card, cmd); + sbp_rc = cmd->data.sbp.hdr.return_code; + +/* on OS family mismatch, query still returns valid port data; +* treat as success +*/ +if (sbp_rc ==IPA_RC_SBP_IQD_OS_MISMATCH && !cmd->hdr.return_code) + rc =0 ; +else + rc =qeth_bridgeport_makerc (card, cmd);if (rc)return rc;
@@ -1739,6 +1749,9 @@ static int qeth_bridgeport_query_ports_cif (cbctl->data.qports.state) *cbctl->data.qports.state = qports->entry[0 ].state; } +if (cbctl->data.qports.os_mismatch) + *cbctl->data.qports.os_mismatch = + (sbp_rc ==IPA_RC_SBP_IQD_OS_MISMATCH );return 0 ; }
@@ -1747,13 +1760,17 @@ static int qeth_bridgeport_query_ports_c* @card: qeth_card structure pointer. * @role: Role of the port: 0-none, 1-primary, 2-secondary. * @state: State of the port: 0-inactive, 1-standby, 2-active. +* @os_mismatch: if non-NULL, set to true when firmware reports +* OS family mismatch. * * Returns negative errno-compatible error indication or 0 on success. * -* 'role' and 'state' are not updated in case of hardware operation failure. +* 'role', 'state' and 'os_mismatch' are not updated in case of +* hardware operation failure. */ int qeth_bridgeport_query_ports (struct qeth_card *card, -enum qeth_sbp_roles *role,enum qeth_sbp_states *state) +enum qeth_sbp_roles *role,enum qeth_sbp_states *state, +bool *os_mismatch) {struct qeth_cmd_buffer *iob;struct _qeth_sbp_cbctl cbctl = {
@@ -1761,6 +1778,7 @@ int qeth_bridgeport_query_ports(struct q .qports = { .role = role, .state = state, + .os_mismatch = os_mismatch, }, }, };
drivers/s390/net/qeth_l2_sys.c +6 -1
@@ -15,6 +15,7 @@ static ssize_t qeth_bridge_port_role_sta {struct qeth_card *card =dev_get_drvdata (dev);enum qeth_sbp_states state =QETH_SBP_STATE_INACTIVE ; +bool os_mismatch = false;int rc =0 ;char *word;
@@ -25,7 +26,7 @@ static ssize_t qeth_bridge_port_role_staif (qeth_card_hw_is_reachable (card) && card->options.sbp.supported_funcs) rc =qeth_bridgeport_query_ports (card, - &card->options.sbp.role, &state); + &card->options.sbp.role, &state, &os_mismatch);if (!rc) {if (show_state)switch (state) {
@@ -52,6 +53,10 @@ static ssize_t qeth_bridge_port_role_staif (rc)QETH_CARD_TEXT_ (card,2 ,"SBP%02x:%02x" , card->options.sbp.role, state); +else if (!show_state && + card->options.sbp.role ==QETH_SBP_ROLE_NONE && + os_mismatch) + rc =sysfs_emit (buf,"%s (OS family mismatch)\n" , word);else rc =sysfs_emit (buf,"%s\n" , word); }
Greg Kroah-Hartman
maintainerPATCH 644/1193 s390/crypto: Fix missing scrub of temp buffers with AES ctr and gcm algorithm
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit 8b7c3b6914f19caf648d05726a86af6326d3c2c6 upstream.
In function ctr_aes_crypt() there is a buffer used to process remaining bytes < AES_BLOCK_SIZE. This buffer was not scrubbed and thus could lead to expose of unwanted data. When the buffer is used explicitly scrub it at the end of the code block to avoid exposure of maybe sensitive data.
In a similar way the function gcm_aes_crypt() hat an error path where the CPACF param block was not scrubbed. Instead of return early now these error paths go to end of function where explicit scrubbing is done. Similar with the buffers which are part of the gcm_sg_walk structs from the variables gw_in and gw_out.
--- arch/s390/crypto/aes_s390.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
arch/s390/crypto/aes_s390.c +12 -4
@@ -604,6 +604,7 @@ static int ctr_aes_crypt(struct skciphermemcpy (walk.dst.virt.addr, buf, nbytes);crypto_inc (walk.iv,AES_BLOCK_SIZE ); ret =skcipher_walk_done (&walk,0 ); +memzero_explicit (buf,sizeof (buf)); }return ret;
@@ -905,10 +906,14 @@ static int gcm_aes_crypt(struct aead_req gw_in.ptr, aad_bytes); n = aad_bytes + pc_bytes; -if (gcm_in_walk_done (&gw_in, n) != n) -return -ENOMEM ; -if (gcm_out_walk_done (&gw_out, n) != n) -return -ENOMEM ; +if (gcm_in_walk_done (&gw_in, n) != n) { + ret = -ENOMEM ; + goto out; + } +if (gcm_out_walk_done (&gw_out, n) != n) { + ret = -ENOMEM ; + goto out; + } aadlen -= aad_bytes; pclen -= pc_bytes; }while (aadlen + pclen >0 );
@@ -920,7 +925,10 @@ static int gcm_aes_crypt(struct aead_req }else scatterwalk_map_and_copy (param.t, req->dst, len, taglen,1 ); +out:memzero_explicit (¶m,sizeof (param)); +memzero_explicit (gw_in.buf,sizeof (gw_in.buf)); +memzero_explicit (gw_out.buf,sizeof (gw_out.buf));return ret; }
Greg Kroah-Hartman
maintainerPATCH 645/1193 hwmon: (applesmc) fix key backlight workqueue leak on register failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
commit 5a0aacaa2d593d7582ecfe289529b937b6dc5d3c upstream.
applesmc_create_key_backlight() allocates applesmc_led_wq before calling led_classdev_register(). When register fails, the error is returned to applesmc_init(), which jumps to out_light_sysfs and skips applesmc_release_key_backlight(), leaking the workqueue.
Destroy the workqueue on the register failure path. The bug was introduced when the inline init block was refactored into a helper that returns errors directly, dropping the old out_light_wq unwind label.
--- drivers/hwmon/applesmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hwmon/applesmc.c +6 -1
@@ -1249,12 +1249,17 @@ static void applesmc_release_light_sensostatic int applesmc_create_key_backlight (void ) { +int ret; +if (!smcreg.has_key_backlight)return 0 ; applesmc_led_wq =create_singlethread_workqueue ("applesmc-led" );if (!applesmc_led_wq)return -ENOMEM ; -return led_classdev_register (&pdev->dev, &applesmc_backlight); + ret =led_classdev_register (&pdev->dev, &applesmc_backlight); +if (ret) +destroy_workqueue (applesmc_led_wq); +return ret; }static void applesmc_release_key_backlight (void )
Greg Kroah-Hartman
maintainerPATCH 646/1193 hwmon: (gpio-fan) Fix use-after-free in alarm work
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit a2471ed17b0e6ff7bfb6b2ea8e6e5b04c309d293 upstream.
fan_alarm_irq_handler() queues fan_data->alarm_work, but nothing cancels it. fan_alarm_notify() dereferences fan_data and its hwmon device. On unbind, devres frees the interrupt, which only waits for the handler itself, and then releases the hwmon device and fan_data, so a pending fan_alarm_notify() can run after those frees.
Replace INIT_WORK() with devm_work_autocancel(), registered before devm_request_irq(). The devres cleanup then frees the interrupt first, so no new work can be queued, and cancels the work while fan_data and the hwmon device are still alive.
This issue was found by an in-house static analysis tool.
--- drivers/hwmon/gpio-fan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/hwmon/gpio-fan.c +7 -1
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/interrupt.h> #include <linux/irq.h> +#include <linux/devm-helpers.h> #include <linux/platform_device.h> #include <linux/err.h> #include <linux/kstrtox.h>
@@ -80,6 +81,7 @@ static DEVICE_ATTR_RO(fan1_alarm);static int fan_alarm_init (struct gpio_fan_data *fan_data) {int alarm_irq; +int err;struct device *dev = fan_data->dev;/*
@@ -90,7 +92,11 @@ static int fan_alarm_init(struct gpio_faif (alarm_irq <=0 )return 0 ; -INIT_WORK (&fan_data->alarm_work, fan_alarm_notify); + err =devm_work_autocancel (dev, &fan_data->alarm_work, + fan_alarm_notify); +if (err) +return err; +irq_set_irq_type (alarm_irq,IRQ_TYPE_EDGE_BOTH );return devm_request_irq (dev, alarm_irq, fan_alarm_irq_handler,IRQF_SHARED ,"GPIO fan alarm" , fan_data);
Greg Kroah-Hartman
maintainerPATCH 647/1193 hwmon: (pmbus) Clear generic status alarms with CLEAR_FAULTS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vishnu Razdan <[email protected]>
commit 6d760f8b41aed74de4402440e4db663d261478bd upstream.
Some hwmon alarms fall back to STATUS_WORD summary bits when no individual limit alarm is available. On PMBus 1.2 and newer devices, pmbus_get_boolean() acknowledges these alarms with the same byte-data write used for detailed status registers. For example, PB_STATUS_INPUT is 0x2000, so it is truncated to zero when passed to _pmbus_write_byte_data(). The resulting write cannot acknowledge the input alarm.
PMBus 1.3 Part II, sections 10.2.4 and 10.2.5, excludes ordinary STATUS_BYTE and STATUS_WORD summary bits from individual clearing. Their summary bits clear when the underlying status bits clear, so changing this to a word-data write would not fix the generic input alarm either.
Use the existing page CLEAR_FAULTS path for generic STATUS_WORD alarms, including devices whose status accessor uses STATUS_BYTE. Keep individual byte writes for detailed status registers on PMBus 1.2 and newer devices. As with the existing older-device fallback, CLEAR_FAULTS can clear other latched status; an active condition can reassert its status.
--- drivers/hwmon/pmbus/pmbus_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus_core.c +3 -1
@@ -1103,7 +1103,9 @@ static int pmbus_get_boolean(struct i2c_ regval = status & mask;if (regval) { -if (data->revision >=PMBUS_REV_12 ) { +/* Generic STATUS_WORD alarms are not individually clearable. */ +if (data->revision >=PMBUS_REV_12 && + reg !=PMBUS_STATUS_WORD ) { ret =_pmbus_write_byte_data (client, page, reg, regval);if (ret) goto unlock;
Greg Kroah-Hartman
maintainerPATCH 648/1193 media: hevc: add bounded tile-count helpers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 592dd4f8442a13bed6e946d73d3164ba38b33bbd upstream.
The stateless HEVC decoders compute the number of tile columns and rows from num_tile_columns_minus1 / num_tile_rows_minus1 and clamp it to the column_width_minus1[] / row_height_minus1[] capacity before using it as a loop bound. Add shared helpers in a new <media/v4l2-hevc.h> so the rkvdec and hantro drivers do not each open-code the min_t() clamp.
--- include/media/v4l2-hevc.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/media/v4l2-hevc.h
include/media/v4l2-hevc.h new file +41 -0
@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Helper functions for HEVC stateless codecs. +*/ + +#ifndef _MEDIA_V4L2_HEVC_H +#define _MEDIA_V4L2_HEVC_H + +#include <linux/minmax.h> +#include <media/v4l2-ctrls.h> + +/** +* v4l2_hevc_pps_num_tile_columns - number of HEVC tile columns, bounded +* @pps: the V4L2 HEVC PPS control +* +* Return the number of tile columns (num_tile_columns_minus1 + 1) clamped to +* the capacity of column_width_minus1[]. The control validation already +* rejects out-of-range counts; this keeps the consuming drivers bounded too. +*/ +static inline unsigned int +v4l2_hevc_pps_num_tile_columns (const struct v4l2_ctrl_hevc_pps *pps) +{ + return min_t(unsigned int, pps->num_tile_columns_minus1 + 1, +ARRAY_SIZE (pps->column_width_minus1)); +} + +/** +* v4l2_hevc_pps_num_tile_rows - number of HEVC tile rows, bounded +* @pps: the V4L2 HEVC PPS control +* +* Return the number of tile rows (num_tile_rows_minus1 + 1) clamped to the +* capacity of row_height_minus1[]. +*/ +static inline unsigned int +v4l2_hevc_pps_num_tile_rows (const struct v4l2_ctrl_hevc_pps *pps) +{ + return min_t(unsigned int, pps->num_tile_rows_minus1 + 1, +ARRAY_SIZE (pps->row_height_minus1)); +} + +#endif /* _MEDIA_V4L2_HEVC_H */
Greg Kroah-Hartman
maintainerPATCH 649/1193 media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer capacity
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 06236b094c899c22c12ac5097935eb6719293de8 upstream.
prepare_tile_info_buffer() writes one entry per tile into the tile_sizes DMA buffer, sized for a grid equal to the PPS uAPI array capacity. Use the bounded v4l2_hevc_pps_num_tile_columns() / v4l2_hevc_pps_num_tile_rows() helpers so the loops stay inside the buffer.
--- drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c +4 -2
@@ -5,6 +5,8 @@* Copyright (C) 2020 Safran Passenger Innovations LLC */ +#include <media/v4l2-hevc.h> +#include "hantro_hw.h" #include "hantro_g2_regs.h"
@@ -15,8 +17,8 @@ static void prepare_tile_info_buffer(strconst struct v4l2_ctrl_hevc_pps *pps = ctrls->pps;const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;u16 *p = (u16 *)((u8 *)ctx->hevc_dec.tile_sizes.cpu); -unsigned int num_tile_rows = pps->num_tile_rows_minus1 +1 ; -unsigned int num_tile_cols = pps->num_tile_columns_minus1 +1 ; +unsigned int num_tile_rows =v4l2_hevc_pps_num_tile_rows (pps); +unsigned int num_tile_cols =v4l2_hevc_pps_num_tile_columns (pps);unsigned int pic_width_in_ctbs, pic_height_in_ctbs;unsigned int max_log2_ctb_size, ctb_size;bool tiles_enabled, uniform_spacing;
Greg Kroah-Hartman
maintainerPATCH 650/1193 media: mediatek: vcodec: bound AV1 tile-start copy to the array capacity
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 37bef2170d4c88fc3d708eecf3ef0f4032bc1372 upstream.
vdec_av1_slice_setup_tile() copies tile_cols + 1 / tile_rows + 1 entries into mi_col_starts[] / mi_row_starts[] from the bitstream tile_info. Bound the copy to the array capacity.
--- .../mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c +3 -2
@@ -1299,11 +1299,12 @@ static void vdec_av1_slice_setup_tile(struct vdec_av1_slice_frame *frame, tile->uniform_tile_spacing_flag =BIT_FLAG (ctrl_tile,V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING ); -for (i =0 ; i < tile->tile_cols +1 ; i++) +/* Bound the copy to the mi_col_starts[]/mi_row_starts[] capacity. */ +for (i =0 ; i < tile->tile_cols +1 && i <V4L2_AV1_MAX_TILE_COLS +1 ; i++) tile->mi_col_starts[i] =ALIGN (ctrl_tile->mi_col_starts[i],BIT (mib_size_log2)) >> mib_size_log2; -for (i =0 ; i < tile->tile_rows +1 ; i++) +for (i =0 ; i < tile->tile_rows +1 && i <V4L2_AV1_MAX_TILE_ROWS +1 ; i++) tile->mi_row_starts[i] =ALIGN (ctrl_tile->mi_row_starts[i],BIT (mib_size_log2)) >> mib_size_log2; }
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 651/1193 media: v4l2-h264: Fix memcmp() size in B1 reference list comparison
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haotian Zhang <[email protected]>
commit 10e59fbdef13597836bd6459095caa02c80af3d7 upstream.
In v4l2_h264_build_b_ref_lists(), the B0/B1 list equality check passes the entry count builder->num_valid to memcmp() instead of a byte size. Since struct v4l2_h264_reference is two bytes (fields and index), only half of each list is compared, so distinct lists can be wrongly treated as equal and trigger an incorrect swap(b1_reflist[0], b1_reflist[1]).
Change the memcmp() size argument to sizeof(b1_reflist[0]) * builder->num_valid so that the full byte length of both reference lists is compared.
--- drivers/media/v4l2-core/v4l2-h264.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-h264.c +2 -1
@@ -440,7 +440,8 @@ v4l2_h264_build_b_ref_lists(const struct }if (builder->num_valid >1 && - !memcmp (b1_reflist, b0_reflist, builder->num_valid)) + !memcmp (b1_reflist, b0_reflist, +sizeof (b1_reflist[0 ]) * builder->num_valid))swap (b1_reflist[0 ], b1_reflist[1 ]);print_ref_list_b (builder, b0_reflist,0 );
Greg Kroah-Hartman
maintainerPATCH 652/1193 media: verisilicon: rockchip: guard VPU981 AV1 divisor and tile buffer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit b84f6533a8ed2fd7b282fc7ab4b8efadc745a89c upstream.
rockchip_vpu981_av1_dec_set_tile_info() divides context_update_tile_id by tile_info->tile_cols and writes one descriptor per tile into the tile_info DMA buffer, which holds AV1_MAX_TILES entries; tile_cols and tile_rows come from the bitstream. Guard the division against a zero tile_cols by initialising the context-update values to zero and computing them only when tile_cols is non-zero, and stop the descriptor writes once the tile_info buffer is full. The tile geometry written to the hardware registers is left unmodified; the per-dimension and total tile bounds are enforced by the control validation.
--- drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 32 ++++++++-- 1 file changed, 26 insertions(+), 6 deletions(-)
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +26 -6
@@ -577,16 +577,30 @@ static void rockchip_vpu981_av1_dec_set_const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info;const struct v4l2_ctrl_av1_tile_group_entry *group_entry = ctrls->tile_group_entry; -int context_update_y = - tile_info->context_update_tile_id / tile_info->tile_cols; -int context_update_x = - tile_info->context_update_tile_id % tile_info->tile_cols; -int context_update_tile_id = - context_update_x * tile_info->tile_rows + context_update_y; +int context_update_y =0 ; +int context_update_x =0 ; +int context_update_tile_id =0 ;u8 *dst = av1_dec->tile_info.cpu; +u8 *dst_end = dst + av1_dec->tile_info.size;struct hantro_dev *vpu = ctx->dev;int tile0, tile1; +/* +* tile_cols and tile_rows are bounded by the V4L2 control validation +* (V4L2_AV1_MAX_TILE_{COLS,ROWS} and V4L2_AV1_MAX_TILE_COUNT). Guard +* the divisor here, and keep the descriptor writes within the +* AV1_MAX_TILES tile_info buffer below; the register values use the +* unmodified tile geometry. +*/ +if (tile_info->tile_cols) { + context_update_y = + tile_info->context_update_tile_id / tile_info->tile_cols; + context_update_x = + tile_info->context_update_tile_id % tile_info->tile_cols; + context_update_tile_id = + context_update_x * tile_info->tile_rows + context_update_y; + } +memset (dst,0 , av1_dec->tile_info.size);for (tile0 =0 ; tile0 < tile_info->tile_cols; tile0++) {
@@ -597,6 +611,10 @@ static void rockchip_vpu981_av1_dec_set_ tile_info->height_in_sbs_minus_1[tile1] +1 ;u32 x0 = tile_info->width_in_sbs_minus_1[tile0] +1 ; +/* Stop once the tile_info descriptor buffer is full. */ +if (dst +16 > dst_end) +break ; +/* tile size in SB units (width,height) */ *dst++ = x0; *dst++ =0 ;
@@ -621,6 +639,8 @@ static void rockchip_vpu981_av1_dec_set_ *dst++ = (end >>16 ) &255 ; *dst++ = (end >>24 ) &255 ; } +if (dst +16 > dst_end) +break ; }hantro_reg_write (vpu, &av1_multicore_expect_context_update, !!(context_update_x ==0 ));
Greg Kroah-Hartman
maintainerPATCH 653/1193 media: verisilicon: rockchip: reject AV1 frames exceeding the tile capacity
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 367db8b23c26a913d76ed70457bbcd781c422b49 upstream.
rockchip_vpu981_av1_dec_set_tile_info() indexes the tile group entry array by tile1 * tile_cols + tile0, reading up to tile_cols * tile_rows entries, lays out one descriptor per tile in the AV1_MAX_TILES tile_info buffer, and programs the real tile_cols / tile_rows into the hardware.
The tile group entry control is a dynamic array sized to the number of entries userspace submitted, independent of tile_cols / tile_rows, so a frame that claims more tiles than entries reads past the array. A frame that claims more than AV1_MAX_TILES tiles also leaves the hardware programmed for more tiles than the descriptor buffer holds.
Reject both in prepare_run(): tile_cols * tile_rows must not exceed the submitted entry count or AV1_MAX_TILES. The entry count is read via v4l2_ctrl_find() (ctrl->elems). This mirrors the bound the mediatek AV1 decoder already enforces.
--- drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 25 ++++++++-- 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +22 -3
@@ -430,20 +430,39 @@ static int rockchip_vpu981_av1_dec_prepa {struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls; +const struct v4l2_av1_tile_info *tile_info; +struct v4l2_ctrl *tge; +u32 num_tiles; ctrls->sequence =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_AV1_SEQUENCE );if (WARN_ON (!ctrls->sequence))return -EINVAL ; - ctrls->tile_group_entry = -hantro_get_ctrl (ctx,V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY ); -if (WARN_ON (!ctrls->tile_group_entry)) + tge =v4l2_ctrl_find (&ctx->ctrl_handler, +V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY ); +if (WARN_ON (!tge))return -EINVAL ; + ctrls->tile_group_entry = tge->p_cur.p; ctrls->frame =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_AV1_FRAME );if (WARN_ON (!ctrls->frame))return -EINVAL ; +/* +* rockchip_vpu981_av1_dec_set_tile_info() indexes the tile group +* entry array by tile1 * tile_cols + tile0, so it reads up to +* tile_cols * tile_rows entries, and lays out one descriptor per tile +* in the AV1_MAX_TILES tile_info buffer while programming the real +* tile geometry into the hardware. Reject a frame that claims more +* tiles than userspace submitted, or more than the hardware tile +* buffer holds, so the read stays in bounds and the programmed +* geometry matches the descriptors written. +*/ + tile_info = &ctrls->frame->tile_info; + num_tiles = (u32 )tile_info->tile_cols * tile_info->tile_rows; +if (num_tiles > tge->elems || num_tiles >AV1_MAX_TILES ) +return -EINVAL ; + ctrls->film_grain =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_AV1_FILM_GRAIN );
Greg Kroah-Hartman
maintainerPATCH 654/1193 media: v4l2-ctrls: validate HEVC tile counts
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit dc694a9929f7cb9c88ef91e45eb982b7bbe5a477 upstream.
The stateless HEVC decoders read num_tile_columns_minus1 + 1 entries from column_width_minus1[] and num_tile_rows_minus1 + 1 from row_height_minus1[] and use them as tile-loop bounds, but std_validate_compound() does not bound these u8 counts. Reject a V4L2_CTRL_TYPE_HEVC_PPS with tiling enabled whose tile counts exceed the uAPI array capacity, mirroring the existing compound-control range checks.
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-core.c +12 -0
@@ -1080,6 +1080,18 @@ static int std_validate_compound(const s p_hevc_pps->flags &= ~V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED ; + }else { +/* +* These count the entries the stateless HEVC drivers +* read from column_width_minus1[] / row_height_minus1[] +* and use as tile-loop bounds. +*/ +if (p_hevc_pps->num_tile_columns_minus1 >= +ARRAY_SIZE (p_hevc_pps->column_width_minus1)) +return -EINVAL ; +if (p_hevc_pps->num_tile_rows_minus1 >= +ARRAY_SIZE (p_hevc_pps->row_height_minus1)) +return -EINVAL ; } if (p_hevc_pps->flags &
Greg Kroah-Hartman
maintainerPATCH 655/1193 media: v4l2-ctrls: validate AV1 tile counts
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 439058ced617fbb3febc017b9e93bb7387f309e0 upstream.
The stateless AV1 decoders use tile_info.tile_cols and tile_rows as loop bounds and as indices into the mi_*_starts[] and *_in_sbs_minus_1[] arrays, as the divisor for context_update_tile_id, and their product bounds the per-tile descriptor buffers, but std_validate_compound() does not bound these u8 fields. Reject a V4L2_CTRL_TYPE_AV1_FRAME whose tile_cols or tile_rows exceeds V4L2_AV1_MAX_TILE_COLS / _ROWS, or whose product exceeds V4L2_AV1_MAX_TILE_COUNT. A zero tile count is left to the consuming driver so the zero-initialised control that existing userspace submits is still accepted.
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-core.c +20 -0
@@ -705,10 +705,30 @@ static int validate_av1_film_grain(strucreturn 0 ; } +static int validate_av1_tile_info (struct v4l2_av1_tile_info *t) +{ +/* +* tile_cols and tile_rows index the per-tile descriptor arrays and +* bound the tile loops in the stateless AV1 drivers; the product +* bounds the total tile descriptor count. +*/ +if (t->tile_cols >V4L2_AV1_MAX_TILE_COLS || + t->tile_rows >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ; + +if ((u32 )t->tile_cols * t->tile_rows >V4L2_AV1_MAX_TILE_COUNT ) +return -EINVAL ; + +return 0 ; +} +static int validate_av1_frame (struct v4l2_ctrl_av1_frame *f) {int ret =0 ; + ret =validate_av1_tile_info (&f->tile_info); +if (ret) +return ret; ret =validate_av1_quantization (&f->quantization);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 656/1193 bnxt_en: Only restore LRO if the device supports TPA
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Damato <[email protected]>
commit 4e17b5007b6664559cdad2b2fe270526cf786b5b upstream.
With a P5+ device with firmware that reports max_aggs_supported == 0, it is possible to make LRO settable by attaching and detaching an XDP program even though the device does not support TPA.
Fix this by testing BNXT_SUPPORTS_TPA before restoring the feature bit.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -4045,7 +4045,8 @@ void bnxt_set_rx_skb_mode(struct bnxt *bbnxt_get_max_rings (bp, &rx, &tx, true);if (rx >1 ) { bp->flags &= ~BNXT_FLAG_NO_AGG_RINGS ; - bp->dev->hw_features |=NETIF_F_LRO ; +if (BNXT_SUPPORTS_TPA (bp)) + bp->dev->hw_features |=NETIF_F_LRO ; } }
Greg Kroah-Hartman
maintainerPATCH 657/1193 bnxt_en: Handle buffer allocation failure in bnxt_rx_ring_reset()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Damato <[email protected]>
commit 961e2a17c5e3559b3f8654d2daabdd25a42e770a upstream.
bnxt_rx_ring_reset() frees the ring buffers and then reallocates them, ignoring the result.
bnxt_alloc_one_rx_ring() can fail in bnxt_alloc_one_tpa_info_data(), which returns -ENOMEM on the first failed allocation and leaves the remaining rxr->rx_tpa[] entries zeroed.
The error isn't propagated up, so the loop in bnxt_rx_ring_reset continues and at the end the code re-enables TPA with partially unallocated rx_tpa array.
This means that when the agg_id from hardware is mapped to a SW index in rxr->rx_tpa[], an uninitialized slot can be chosen which would hand a zero DMA address to the device.
Fix this by falling back to a global reset, which is what the existing code already does when other functions fail, but unlike the other failure cases this particular failure has to return because TPA can't be re-enabled since the allocation failed.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -1
@@ -11827,7 +11827,14 @@ static void bnxt_rx_ring_reset(struct bn rxr->rx_sw_agg_prod =0 ; rxr->rx_next_cons =0 ; rxr->bnapi->in_reset = false; -bnxt_alloc_one_rx_ring (bp, i); + rc =bnxt_alloc_one_rx_ring (bp, i); +if (rc) { +netdev_warn (bp->dev,"RX ring reset failed to allocate buffers, rc = %d, falling back to global reset\n" , + rc); +bnxt_reset_task (bp, true); +bnxt_rtnl_unlock_sp (bp); +return ; + } cpr = &rxr->bnapi->cp_ring; cpr->sw_stats.rx.rx_resets++;if (bp->flags &BNXT_FLAG_AGG_RINGS )
Greg Kroah-Hartman
maintainerPATCH 658/1193 bnxt_en: Propagate RX ring init failures in bnxt_init_nic()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Damato <[email protected]>
commit 8e6a850c0746bb4be167aedf1ee57469fcda09a9 upstream.
bnxt_init_rx_rings() returns an error when bnxt_alloc_one_rx_ring() fails, but bnxt_init_nic() discards that return value and calls bnxt_init_chip(), which enables TPA.
If an allocation fails, this could leave rxr->rx_tpa[] partially zeroed and TPA would be enabled over an array with zeroed entries. This would lead to a zeroed DMA address being handed out if the agg_idx is translated to a SW index at a zeroed entry.
Fix this by propagating the error out of bnxt_init_nic(). Both callers already check its return value and unwind with bnxt_free_skbs() and bnxt_free_mem(), which tolerate a partially initialized RX ring.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -1
@@ -8946,8 +8946,13 @@ static int bnxt_shutdown_nic(struct bnxtstatic int bnxt_init_nic (struct bnxt *bp,bool irq_re_init) { +int rc; +bnxt_init_cp_rings (bp); -bnxt_init_rx_rings (bp); + rc =bnxt_init_rx_rings (bp); +if (rc) +return rc; +bnxt_init_tx_rings (bp);bnxt_init_ring_grps (bp, irq_re_init);bnxt_init_vnics (bp);
Greg Kroah-Hartman
maintainerPATCH 659/1193 mptcp: options: handle MPC data + csum reqd + no csum
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
commit ab36b1a80942c78ddb04d006ff38aa7ed3ec0e5e upstream.
Before this modification, a remote peer could send an MP_CAPABLE with data, with the checksum flag set, but without adding the actual 2 bytes of checksum. As a result, uninitialised bytes could be used for the 'csum' field.
That was not a critical issue, because this 'csum' field is only used to compare with the expected one, if previously negotiated in the 3WHS. Worst case, the checksum is likely wrong, a fallback is done without a reject if the negotiation was done earlier. That's OK.
Yet, better to take the expected path with this case: only look at the checksum flag for MP_CAPABLEs not carrying a data-len.
Such packet can be seen as a 3rd or 4th ACK. The RFC8684 mentions [1] that the 3rd packet should have the checksum flag set. When an MPC + ACK contains data, the checksum flag is redundant with the checksum field. It is not clear what should be done for the 4th ACK, nor if the flag has to be set if the checksum field is set.
Therefore, it seems fine to only look at the presence of the checksum field, not to break the interaction with stacks that were not setting both.
Note that linked to this checksum flag on the 3rd ACK, with the current implementation, we can have a situation where the SYN packets have no checksum flag, but the 3rd ACK has one, and this is the one that will be taken into account. First, that's clearly not directly linked to this patch, but Clashiko forced us to look at that. At the end, that seems fine to act like that: yes that's not how the negotiation should work, but being flexible without introducing side effects is also fine: fixing this would mean increasing the complexity, and that's not worth it.
--- net/mptcp/options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/options.c +2 -1
@@ -93,7 +93,8 @@ static void mptcp_parse_option(const str* In other words, the only way for checksums not to be used * is if both hosts in their SYNs set A=0." */ -if (flags &MPTCP_CAP_CHECKSUM_REQD ) +if ((flags &MPTCP_CAP_CHECKSUM_REQD ) && + opsize <TCPOLEN_MPTCP_MPC_ACK_DATA ) mp_opt->suboptions |=OPTION_MPTCP_CSUMREQD ; mp_opt->deny_join_id0 = !!(flags &MPTCP_CAP_DENY_JOIN_ID0 );
Greg Kroah-Hartman
maintainerPATCH 660/1193 mptcp: subflow: no need to copy thmac during ulp_clone
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
commit 29f641951be0d91036d77edf677807f1447dbe65 upstream.
'thmac' is not used after that point.
Indeed, subflow_ulp_clone() is called when the request on the passive side is over, so when the truncated HMAC is no longer needed.
Note that in case of SYN cookies, thmac will not be initialised. So better to remove it to avoid a warning from debug tools like KMSAN for reading uninitialised data.
--- net/mptcp/subflow.c | 1 - 1 file changed, 1 deletion(-)
net/mptcp/subflow.c +0 -1
@@ -2011,7 +2011,6 @@ static void subflow_ulp_clone(const stru new_ctx->request_bkup = subflow_req->request_bkup;WRITE_ONCE (new_ctx->remote_id, subflow_req->remote_id); new_ctx->token = subflow_req->token; - new_ctx->thmac = subflow_req->thmac;/* the subflow req id is valid, fetched via subflow_check_req() * and subflow_token_join_request()
Greg Kroah-Hartman
maintainerPATCH 661/1193 mptcp: syncookies: remember the request backup flag
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
commit b76c0e28b392620dfbaf92cdeedbf115820b44cb upstream.
Instead of using an uninitialised bit when copying the info in subflow_ulp_clone().
To fix this, no need to extend the join_entry structure: backup is coming from struct mptcp_subflow_request_sock, only one bit. Do the same here by using one bit for both.
--- net/mptcp/syncookies.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/mptcp/syncookies.c +4 -1
@@ -26,7 +26,8 @@ struct join_entry {u32 local_nonce;u8 join_id;u8 local_id; -u8 backup; + u8 backup:1, + request_bkup:1;u8 valid; };
@@ -63,6 +64,7 @@ static void mptcp_join_store_state(struc entry->remote_nonce = subflow_req->remote_nonce; entry->local_nonce = subflow_req->local_nonce; entry->backup = subflow_req->backup; + entry->request_bkup = subflow_req->request_bkup; entry->join_id = subflow_req->remote_id; entry->local_id = subflow_req->local_id; entry->valid =1 ;
@@ -117,6 +119,7 @@ bool mptcp_token_join_cookie_init_state( subflow_req->remote_nonce = e->remote_nonce; subflow_req->local_nonce = e->local_nonce; subflow_req->backup = e->backup; + subflow_req->request_bkup = e->request_bkup; subflow_req->remote_id = e->join_id; subflow_req->local_id = e->local_id; subflow_req->token = e->token;
Greg Kroah-Hartman
maintainerPATCH 662/1193 selftests: mptcp: fix an UAF in mptcp_connect.c
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gang Yan <[email protected]>
commit 730444f094b12052916ebd7e14fe57bc3d47bf38 upstream.
At the end of 'sock_connect_mptcp()', it calls 'freeaddrinfo(addr)', the 'peer' pointer (which points into 'addr') remains. Later, the main loop uses this peer pointer for reconnection attempts. If the memory has been freed and reused, the address data could be overwritten, resulting in an invalid remote address.
This patch keeps the addrinfo list allocated for the whole process lifetime so "peer" remains valid across reconnects; the memory will be released at exit() time.
--- tools/testing/selftests/net/mptcp/mptcp_connect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +3 -1
@@ -365,6 +365,9 @@ static int sock_connect_mptcp(const char hints.ai_family = pf; +/* Keep the resolved address alive for the whole execution: it is +* used again when reconnecting, and will be released at exit time. +*/ xgetaddrinfo (remoteaddr, port, &hints, &addr);for (a = addr; a; a = a->ai_next) { sock =socket (a->ai_family, a->ai_socktype, proto);
@@ -408,7 +411,6 @@ static int sock_connect_mptcp(const char } } -freeaddrinfo (addr);if (sock !=-1 )SOCK_TEST_TCPULP (sock, proto);return sock;
Greg Kroah-Hartman
maintainerPATCH 663/1193 smb: client: reject userspace cifs.idmap descriptions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aohan Mei <[email protected]>
commit d9d7eeb0cea5b55b82888f443622fd8d4ee064f3 upstream.
cifs.idmap key descriptions carry authority-bearing fields (owner and group SIDs and uid/gid values in "os:"/"gs:"/"oi:"/"gi:" form) that the cifs.idmap upcall helper treats as kernel-originating inputs. Unlike its sibling cifs.spnego, the cifs.idmap key type has no vet_description hook, so userspace can create keys of this type through request_key(2)/add_key(2) and supply those fields without CIFS origin. A request_key(2) call with a non-NULL callout then drives a root usermodehelper upcall (/sbin/request-key -> cifs.idmap) that consumes the unvetted description in root context.
Only accept cifs.idmap descriptions while CIFS is using its private root_cred to request the key. id_to_sid()/sid_to_id() already run under override_creds(root_cred), so the kernel-originated path is unaffected.
This mirrors commit 3da1fdf4efbc ("smb: client: reject userspace cifs.spnego descriptions"), which applied the same restriction to cifs.spnego.
--- fs/smb/client/cifsacl.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fs/smb/client/cifsacl.c +15 -0
@@ -101,8 +101,23 @@ cifs_idmap_key_destroy(struct key *key)kfree (key->payload.data[0 ]); } +static int +cifs_idmap_key_vet_description (const char *description) +{ +/* +* cifs.idmap descriptions are authority-bearing inputs to the +* cifs.idmap upcall helper. Only allow the kernel to create this +* type of key using the private root_cred installed in +* init_cifs_idmap; reject userspace request_key(2)/add_key(2). +*/ +if (current_cred () != root_cred) +return -EPERM ; +return 0 ; +} +static struct key_type cifs_idmap_key_type = { .name ="cifs.idmap" , + .vet_description = cifs_idmap_key_vet_description, .instantiate = cifs_idmap_key_instantiate, .destroy = cifs_idmap_key_destroy, .describe = user_describe,
Greg Kroah-Hartman
maintainerPATCH 664/1193 smb: client: pin DFS superblock in iterator callback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit d806d5a85dcbe2a0f181b2f0f9f61ddfbefa1818 upstream.
tcon_super_cb() stores a raw superblock pointer, but __cifs_get_super() takes its active reference only after iterate_supers_type() has dropped s_umount and its passive reference. Concurrent DFS automount expiry can therefore free the superblock before cifs_sb_active() uses it.
A deterministic KASAN test reproduces the race as:
BUG: KASAN: slab-use-after-free in cifs_sb_active+0x77/0x80
The same test passes with this change applied.
Take the active reference in the callback while iterate_supers_type() still holds s_umount shared. cifs_put_tcp_super() remains the matching release.
--- fs/smb/client/misc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
fs/smb/client/misc.c +8 -9
@@ -1269,8 +1269,14 @@ static void tcon_super_cb(struct super_bif (t1->ses == t2->ses && t1->ses->server == t2->ses->server && t2->origin_fullpath && -dfs_src_pathname_equal (t2->origin_fullpath, t1->origin_fullpath)) +dfs_src_pathname_equal (t2->origin_fullpath, t1->origin_fullpath)) { +/* +* Take the active reference while iterate_supers_type() still +* holds s_umount shared. +*/ +cifs_sb_active (sb); sd->sb = sb; + }spin_unlock (&t2->tc_lock); }
@@ -1287,15 +1293,8 @@ static struct super_block *__cifs_get_sufor (; *fs_type; fs_type++) {iterate_supers_type (*fs_type, f, &sd); -if (sd.sb) { -/* -* Grab an active reference in order to prevent automounts (DFS links) -* of expiring and then freeing up our cifs superblock pointer while -* we're doing failover. -*/ -cifs_sb_active (sd.sb); +if (sd.sb)return sd.sb; - } }pr_warn_once ("%s: could not find dfs superblock\n" , __func__);return ERR_PTR (-EINVAL );
Greg Kroah-Hartman
maintainerPATCH 665/1193 smb: client: fix one-byte OOB read in smb2_parse_native_symlink()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit cb26524ef4ac28fcfa554c0656e8dc412c38a8ff upstream.
When parsing a share-root relative native symlink, memcpy copies smb_target+1 (skipping the leading separator) but uses strlen(smb_target)+1 as the length, reading one byte past the allocated buffer.
This fixes the following KASAN splat when accessing an SMB symlink with a target of '\a\b':
BUG: KASAN: slab-out-of-bounds in smb2_parse_native_symlink+0x4f5/0xca0 Read of size 5 at addr ffff88800878fe21 by task netfsfuzz-execu/1 CPU: 1 UID: 0 PID: 1 Comm: netfsfuzz-execu Tainted: G N 7.2.0-11943-g2709dd5ae32f-dirty #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996) Call Trace: <TASK> dump_stack_lvl+0x7b/0xa0 print_report+0xd0/0x630 kasan_report+0xe5/0x120 kasan_check_range+0x105/0x1b0 __asan_memcpy+0x23/0x60 smb2_parse_native_symlink+0x4f5/0xca0 parse_reparse_point+0x68a/0x1530 reparse_info_to_fattr+0x752/0xa20 cifs_get_fattr+0x873/0x15b0 cifs_get_inode_info+0xc0/0x310 cifs_lookup+0x308/0xa70 __lookup_slow+0x122/0x2b0 lookup_slow+0x50/0x70 path_lookupat+0x525/0xaf0 filename_lookup+0x1f2/0x550 vfs_statx+0xd1/0x1a0 vfs_fstatat+0x65/0xc0 __do_sys_newfstatat+0x9a/0x120 do_syscall_64+0xdd/0x4a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
--- fs/smb/client/reparse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/smb/client/reparse.c +2 -1
@@ -580,7 +580,8 @@ int smb2_parse_native_symlink(char **tar linux_target[i*3 +1 ] ='.' ; linux_target[i*3 +2 ] = sep; } -memcpy (linux_target + levels*3 , smb_target+1 , smb_target_len);/* +1 to skip leading sep */ +/* +1 to skip leading sep */ +memcpy (linux_target + levels*3 , smb_target+1 , smb_target_len-1 ); }else { linux_target = smb_target; smb_target =NULL ;
Greg Kroah-Hartman
maintainerPATCH 666/1193 smb: client: fix file type corruption in cifs_reparse_point_to_fattr()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit 6bd360447941357e959414a525aa62576a448116 upstream.
Setting the file type in cf_mode without clearing the existing S_IFMT bits first is wrong as it corrupts the file type when cf_mode already has type bits set (e.g. S_IFREG | S_IFLNK == S_IFDIR | S_IFREG).
Clear S_IFMT before setting S_IFLNK for native and SMB1 symlinks.
--- fs/smb/client/reparse.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/reparse.c +1 -0
@@ -824,6 +824,7 @@ bool cifs_reparse_point_to_fattr(structbreak ;case 0 :/* SMB1 symlink */ case IO_REPARSE_TAG_SYMLINK : + fattr->cf_mode &= ~S_IFMT ; fattr->cf_mode |=S_IFLNK ;break ;default :
Greg Kroah-Hartman
maintainerPATCH 667/1193 smb: client: fix file type corruption in wsl_to_fattr()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit fa7a2cfcf1e6117fc478cae6809c66c518740969 upstream.
Setting the file type in cf_mode without clearing the existing S_IFMT bits first is wrong as it corrupts the file type when cf_mode already has type bits set (e.g. S_IFREG | S_IFCHR == S_IFLNK).
Clear S_IFMT before the switch statement.
--- fs/smb/client/reparse.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/reparse.c +1 -0
@@ -683,6 +683,7 @@ static bool wsl_to_fattr(struct cifs_opebool have_xattr_dev = false;u32 next =0 ; + fattr->cf_mode &= ~S_IFMT ;switch (tag) {case IO_REPARSE_TAG_LX_SYMLINK : fattr->cf_mode |=S_IFLNK ;
Greg Kroah-Hartman
maintainerPATCH 668/1193 smb: client: avoid leaking refcount in cifs_queue_oplock_break()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjoern Doebel <[email protected]>
commit 9f2e63f1b2d5fc5b5423424902c091123e220e7e upstream.
cifs_queue_oplock_break() unconditionally takes a reference on the target file before queueing cifs_oplock_break(). Only that work item decreases the reference counter again.
If another oplock break arrives while that work is still queued, queue_work() will return false and not queue this second work item. As a result, we will never reach the point to drop the file reference again and are leaking this reference. This can be triggered when interacting with a slow-responding server.
As a result, later unmount operations for this file system will fail with
BUG: Dentry ... still in use (1) [unmount of cifs cifs] VFS: Busy inodes after unmount of cifs (cifs) kernel BUG at fs/super.c:777!
Fix this by only incrementing the reference count if the work has been queued successfully. Taking it after queue_work() is safe because all three callers hold tcon->open_file_lock across the call and _cifsFileInfo_put() decrements under that same lock, so a worker that starts the handler in the window cannot drop the reference before it has been taken.
--- fs/smb/client/misc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/smb/client/misc.c +4 -3
@@ -654,10 +654,11 @@ void cifs_queue_oplock_break(struct cifs* open_file_lock to enforce the validity of it for the oplock * break handler. The matching put is done at the end of the * handler. +* +* Only take a reference if the work is actually queued. */ -cifsFileInfo_get (cfile); - -queue_work (cifsoplockd_wq, &cfile->oplock_break); +if (queue_work (cifsoplockd_wq, &cfile->oplock_break)) +cifsFileInfo_get (cfile); }void cifs_done_oplock_break (struct cifsInodeInfo *cinode)
Greg Kroah-Hartman
maintainerPATCH 669/1193 smb: client: avoid leaking refcount when cifs_sb_tlink() fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjoern Doebel <[email protected]>
commit 23b26f4408ac3f35a482d2e5cf6fc865d4201b71 upstream.
cifs_oplock_break() takes over the reference that cifs_queue_oplock_break() acquired when it queued the work, and drops it with _cifsFileInfo_put() once the break has been processed.
Only in setups with "-o multiuser", cifs_sb_tlink() may fail, at which point cifs_oplock_break() returns without putting the file reference, mirroring the reference leak we already fixed in the companion patch to cifs_queue_oplock_break().
This would trigger a crash due to busy inodes on the next unmount:
BUG: Dentry ... still in use (1) [unmount of cifs cifs] VFS: Busy inodes after unmount of cifs (cifs)
Drop the reference on that path as well. Doing so before the out label mirrors the normal path, which also puts the reference before cifs_done_oplock_break().
Found by Sashiko code review. The failure path was not exercised at runtime.
--- fs/smb/client/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/smb/client/file.c +4 -1
@@ -5154,8 +5154,11 @@ void cifs_oplock_break(struct work_struc TASK_UNINTERRUPTIBLE); tlink =cifs_sb_tlink (cifs_sb); -if (IS_ERR (tlink)) +if (IS_ERR (tlink)) { +/* drop the reference taken when the break was queued */ +_cifsFileInfo_put (cfile, false/* do not wait for ourself */ , false); goto out; + } tcon =tlink_tcon (tlink); server = tcon->ses->server;
Greg Kroah-Hartman
maintainerPATCH 670/1193 smb: client: fix heap overflow in DACL owner/group rewrite
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjoern Doebel <[email protected]>
commit 0ee150794c75bcd0be0e24ff3394f433cbae18cc upstream.
When id_mode_to_cifs_acl rewrites an existing DACL, it allocates a buffer sized according to the on-disk DACL length reported by dacl_ptr->size. However, replace_sids_and_copy_aces may rewrite each ACE with a new owner/group SID obtained from the cifs.idmap upcall. Those SIDs can have up to SID_MAX_SUB_AUTHORITIES (15) sub-authorities, making each ACE up to 76 bytes (sizeof(struct smb_ace)).
If the original DACL contains short SIDs (e.g., 1 sub-authority) while the replacement SIDs are long, the rewritten ACEs overflow the allocation.
Fix this by always budgeting for worst-case SID expansion: allocate sizeof(struct smb_acl) plus num_aces * sizeof(struct smb_ace), which covers the smb_acl header and room for every ACE at maximum SID size. This replaces the previous split logic that used dacl_ptr->size for cifsacl mounts but num_aces * sizeof(struct smb_ace) for mode_from_sid
mounts: both paths can trigger the same rewrite and need the same headroom.
KASAN reports this as:
BUG: KASAN: slab-out-of-bounds in build_sec_desc+0x1e8a/0x2680 [cifs] Write of size 4 at addr ffff8881a5e25374 by task chown/5298 ... The buggy address is located 0 bytes to the right of allocated 884-byte region [ffff8881a5e25000, ffff8881a5e25374)
--- fs/smb/client/cifsacl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/smb/client/cifsacl.c +7 -5
@@ -1769,11 +1769,13 @@ id_mode_to_cifs_acl(struct inode *inode,cifs_put_tlink (tlink);return rc; } -if (mode_from_sid) - nsecdesclen += -le16_to_cpu (dacl_ptr->num_aces) *sizeof (struct smb_ace ); -else /* cifsacl */ - nsecdesclen +=le16_to_cpu (dacl_ptr->size); +/* +* Worst case: every ACE is rewritten with a new SID of +* SID_MAX_SUB_AUTHORITIES sub-auths -> sizeof(smb_ace) each, +* plus the smb_acl header replace_sids_and_copy_aces() emits. +*/ + nsecdesclen +=sizeof (struct smb_acl ) + +le16_to_cpu (dacl_ptr->num_aces) *sizeof (struct smb_ace ); } }
Greg Kroah-Hartman
maintainerPATCH 671/1193 xfs: snapshot scrub stats when rendering them
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 568a1588b906780dc3e9be56a61217afb4f7800e upstream.
LOLLM complains about concurrency problems in the scrub stats code because xchk_stats_format doesn't synchronize in any way with updates. These stats are only reported through debugfs so I don't think it really matters, but I guess I exist to make bots happy now.
Note: We snapshot the entire stats object with a spinlock so that we don't have to worry about users seeing slightly weird numbers (e.g. invocations has incremented but none of the outcomes have been yet) if we race with xchk_stats_merge_one. This isn't a hot path.
--- fs/xfs/scrub/stats.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
fs/xfs/scrub/stats.c +19 -13
@@ -92,25 +92,31 @@ xchk_stats_format(int ret =0 ;for (i =0 ; i <XFS_SCRUB_TYPE_NR ; i++, css++) { +struct xchk_scrub_stats fss; +if (!name_map[i])continue ; +spin_lock (&css->css_lock); +memcpy (&fss, css, offsetof(struct xchk_scrub_stats , css_lock)); +spin_unlock (&css->css_lock); + ret =scnprintf (buf, remaining,"%s %u %u %u %u %u %u %u %u %u %llu %u %u %llu\n" , name_map[i], - (unsigned int )css->invocations, - (unsigned int )css->clean, - (unsigned int )css->corrupt, - (unsigned int )css->preen, - (unsigned int )css->xfail, - (unsigned int )css->xcorrupt, - (unsigned int )css->incomplete, - (unsigned int )css->warning, - (unsigned int )css->retries, - (unsigned long long )css->checktime_us, - (unsigned int )css->repair_invocations, - (unsigned int )css->repair_success, - (unsigned long long )css->repairtime_us); + (unsigned int )fss.invocations, + (unsigned int )fss.clean, + (unsigned int )fss.corrupt, + (unsigned int )fss.preen, + (unsigned int )fss.xfail, + (unsigned int )fss.xcorrupt, + (unsigned int )fss.incomplete, + (unsigned int )fss.warning, + (unsigned int )fss.retries, + (unsigned long long )fss.checktime_us, + (unsigned int )fss.repair_invocations, + (unsigned int )fss.repair_success, + (unsigned long long )fss.repairtime_us);if (ret <=0 )break ;
Greg Kroah-Hartman
maintainerPATCH 672/1193 xfs: snapshot old AGFL before rewriting it
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 3466dfef0a20f842363958deea55be9f1d26818a upstream.
LOLLM complains that we can't undo an attempt at fixing the AGFL if anything goes wrong during the rewrite, so take a snapshot of the whole buffer so that we can restore it. Move the xrep_agfl_update_agf call so that we only update the AGF if the AGFL update is 100% successful.
While we're at it, fix leaking the used_extents bitmap if the disunion operation fails.
--- fs/xfs/scrub/agheader_repair.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)
fs/xfs/scrub/agheader_repair.c +25 -10
@@ -677,14 +677,16 @@ xrep_agfl_init_header(struct xfs_scrub *sc, struct xfs_buf *agfl_bp, struct xagb_bitmap *agfl_extents, - xfs_agblock_t flcount) + xfs_agblock_t flcount, + struct xfs_agfl *old_agfl) { struct xrep_agfl_fill af = { .sc = sc, .flcount = flcount, };struct xfs_mount *mp = sc->mp; -struct xfs_agfl *agfl; +struct xfs_agfl *agfl =XFS_BUF_TO_AGFL (agfl_bp); +const size_t agfl_sz =BBTOB (agfl_bp->b_length);int error;ASSERT (flcount <=xfs_agfl_size (mp));
@@ -693,8 +695,8 @@ xrep_agfl_init_header(* Start rewriting the header by setting the bno[] array to * NULLAGBLOCK, then setting AGFL header fields. */ - agfl =XFS_BUF_TO_AGFL (agfl_bp); -memset (agfl,0xFF ,BBTOB (agfl_bp->b_length)); +memcpy (old_agfl, agfl, agfl_sz); +memset (agfl,0xFF , agfl_sz); agfl->agfl_magicnum =cpu_to_be32 (XFS_AGFL_MAGIC ); agfl->agfl_seqno =cpu_to_be32 (sc->sa.pag->pag_agno);uuid_copy (&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
@@ -709,13 +711,18 @@ xrep_agfl_init_header(xagb_bitmap_walk (agfl_extents, xrep_agfl_fill, &af); error =xagb_bitmap_disunion (agfl_extents, &af.used_extents);if (error) -return error; + goto err_undo;/* Write new AGFL to disk. */ xfs_trans_buf_set_type (sc->tp, agfl_bp,XFS_BLFT_AGFL_BUF ); -xfs_trans_log_buf (sc->tp, agfl_bp,0 ,BBTOB (agfl_bp->b_length) -1 ); +xfs_trans_log_buf (sc->tp, agfl_bp,0 , agfl_sz -1 );xagb_bitmap_destroy (&af.used_extents);return 0 ; + +err_undo: +xagb_bitmap_destroy (&af.used_extents); +memcpy (agfl, old_agfl, agfl_sz); +return error; }/* Repair the AGFL. */
@@ -727,6 +734,7 @@ xrep_agfl(struct xfs_mount *mp = sc->mp;struct xfs_buf *agf_bp;struct xfs_buf *agfl_bp; +struct xfs_agfl *old_agfl;xfs_agblock_t flcount;int error;
@@ -734,6 +742,10 @@ xrep_agfl(if (!xfs_has_rmapbt (mp))return -EOPNOTSUPP ; + old_agfl =kzalloc (BBTOB (XFS_FSS_TO_BB (mp,1 )),XCHK_GFP_FLAGS ); +if (!old_agfl) +return -ENOMEM ; +xagb_bitmap_init (&agfl_extents);/*
@@ -743,7 +755,7 @@ xrep_agfl(*/ error =xfs_alloc_read_agf (sc->sa.pag, sc->tp,0 , &agf_bp);if (error) -return error; + goto err_old_agfl;/* * Make sure we have the AGFL buffer, as scrub might have decided it
@@ -754,7 +766,7 @@ xrep_agfl( XFS_AGFL_DADDR(mp)), XFS_FSS_TO_BB(mp, 1), 0, &agfl_bp, NULL);if (error) -return error; + goto err_old_agfl; agfl_bp->b_ops = &xfs_agfl_buf_ops;/* Gather all the extents we're going to put on the new AGFL. */
@@ -771,10 +783,11 @@ xrep_agfl(* we adjust the AGF flcount (which can fail) so avoid updating any * buffers until we know that part works. */ -xrep_agfl_update_agf (sc, agf_bp, flcount); - error =xrep_agfl_init_header (sc, agfl_bp, &agfl_extents, flcount); + error =xrep_agfl_init_header (sc, agfl_bp, &agfl_extents, flcount, + old_agfl);if (error) goto err; +xrep_agfl_update_agf (sc, agf_bp, flcount);/* * Ok, the AGFL should be ready to go now. Roll the transaction to
@@ -791,6 +804,8 @@ xrep_agfl( XFS_AG_RESV_AGFL); err:xagb_bitmap_destroy (&agfl_extents); +err_old_agfl: +kfree (old_agfl);return error; }
Greg Kroah-Hartman
maintainerPATCH 673/1193 xfs: signal inode btree xref error if get_rec returns an error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 8c71ad4d4f3e20c30b663bd292526fcbc4d3913f upstream.
LOLLM points out that xchk_finobt_xref_inobt and xchk_inobt_xref_finobt both ignore errors being returned from the xfs_btree_get_rec function and proceed with a (possibly stale) "true" value for has_record. If the *simple* btree record checks fail during cross-referencing, we can immediately conclude that there's a cross-referncing error in the other btree. On those grounds, we can bubble up the returned error instead of wasting time cross-referencing with garbage.
--- fs/xfs/scrub/ialloc.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/xfs/scrub/ialloc.c +4 -0
@@ -85,6 +85,8 @@ xchk_inobt_xref_finobt( goto no_record; error =xfs_inobt_get_rec (cur, &frec, &has_record); +if (error) +return error;if (!has_record)return -EFSCORRUPTED ;
@@ -188,6 +190,8 @@ xchk_finobt_xref_inobt( goto no_record; error =xfs_inobt_get_rec (cur, &irec, &has_record); +if (error) +return error;if (!has_record)return -EFSCORRUPTED ;
Greg Kroah-Hartman
maintainerPATCH 674/1193 xfs: count escaped corruption errors in scrub stats
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 4d0624679ae29b469016f1ce4714be58582ed06a upstream.
The main scrub code will quietly turn bubbled-up EFSCORRUPTED and EFSBADCRC errors into corruption errors. These aren't recorded in the scrub stats code (says LOLLM) so do that now.
--- fs/xfs/scrub/scrub.c | 3 +-- fs/xfs/scrub/stats.c | 28 +++++++++++++++++++--------- fs/xfs/scrub/stats.h | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-)
fs/xfs/scrub/scrub.c +1 -2
@@ -588,8 +588,7 @@ out_nofix: out_teardown: error =xchk_teardown (sc, error); out_sc: -if (error != -ENOENT ) -xchk_stats_merge (mp, sm, &run); +xchk_stats_merge (mp, sm, error, &run);kfree (sc); out:trace_xchk_done (XFS_I (file_inode (file)), sm, error);
fs/xfs/scrub/stats.c +19 -9
@@ -187,31 +187,37 @@ STATIC voidxchk_stats_merge_one ( struct xchk_stats *cs, const struct xfs_scrub_metadata *sm, + int error, const struct xchk_stats_run *run) { struct xchk_scrub_stats *css; +unsigned int sm_flags = sm->sm_flags;if (sm->sm_type >=XFS_SCRUB_TYPE_NR ) {ASSERT (sm->sm_type <XFS_SCRUB_TYPE_NR );return ; } +/* caller applies this same transformation after we return */ +if (error == -EFSCORRUPTED || error == -EFSBADCRC ) + sm_flags |=XFS_SCRUB_OFLAG_CORRUPT ; + css = &cs->cs_stats[sm->sm_type];spin_lock (&css->css_lock); css->invocations++; -if (!(sm->sm_flags &XFS_SCRUB_OFLAG_UNCLEAN )) +if (!(sm_flags &XFS_SCRUB_OFLAG_UNCLEAN )) css->clean++; -if (sm->sm_flags &XFS_SCRUB_OFLAG_CORRUPT ) +if (sm_flags &XFS_SCRUB_OFLAG_CORRUPT ) css->corrupt++; -if (sm->sm_flags &XFS_SCRUB_OFLAG_PREEN ) +if (sm_flags &XFS_SCRUB_OFLAG_PREEN ) css->preen++; -if (sm->sm_flags &XFS_SCRUB_OFLAG_XFAIL ) +if (sm_flags &XFS_SCRUB_OFLAG_XFAIL ) css->xfail++; -if (sm->sm_flags &XFS_SCRUB_OFLAG_XCORRUPT ) +if (sm_flags &XFS_SCRUB_OFLAG_XCORRUPT ) css->xcorrupt++; -if (sm->sm_flags &XFS_SCRUB_OFLAG_INCOMPLETE ) +if (sm_flags &XFS_SCRUB_OFLAG_INCOMPLETE ) css->incomplete++; -if (sm->sm_flags &XFS_SCRUB_OFLAG_WARNING ) +if (sm_flags &XFS_SCRUB_OFLAG_WARNING ) css->warning++; css->retries += run->retries; css->checktime_us +=howmany_64 (run->scrub_ns,NSEC_PER_USEC );
@@ -229,10 +235,14 @@ voidxchk_stats_merge ( struct xfs_mount *mp, const struct xfs_scrub_metadata *sm, + int error, const struct xchk_stats_run *run) { - xchk_stats_merge_one(&global_stats, sm, run); -xchk_stats_merge_one (mp->m_scrub_stats, sm, run); + if (error == -ENOENT) + return; + + xchk_stats_merge_one(&global_stats, sm, error, run); +xchk_stats_merge_one (mp->m_scrub_stats, sm, error, run); }/* debugfs boilerplate */
fs/xfs/scrub/stats.h +2 -2
@@ -27,7 +27,7 @@ void xchk_stats_register(struct xchk_stavoid xchk_stats_unregister (struct xchk_stats *cs);void xchk_stats_merge (struct xfs_mount *mp,const struct xfs_scrub_metadata *sm, -const struct xchk_stats_run *run); +int error,const struct xchk_stats_run *run);static inline u64 xchk_stats_now (void ) {return ktime_get_ns (); }static inline u64 xchk_stats_elapsed_ns (u64 since)
@@ -53,7 +53,7 @@ static inline u64 xchk_stats_elapsed_ns(# define xchk_stats_unregister (cs) ((void)0)# define xchk_stats_now () (0)# define xchk_stats_elapsed_ns (x) (0 * (x)) -# define xchk_stats_merge (mp, sm, run) ((void)0) +# define xchk_stats_merge (mp, sm, error, run) ((void)0)#endif /* CONFIG_XFS_ONLINE_SCRUB_STATS */ #endif /* __XFS_SCRUB_STATS_H__ */
Greg Kroah-Hartman
maintainerPATCH 675/1193 xfs: bail out on bitmap errors in xrep_agfl_fill
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit eaf580538eb1be3d162400d04c4b7dc4c627296b upstream.
LOLLM also points out that the xagb_bitmap_set call in xrep_agfl_fill can fail, but we don't check the result of xagb_bitmap_walk, so we silently drop the error and proceed with inconsistent incore data. That shouldn't be allowed.
--- fs/xfs/scrub/agheader_repair.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/scrub/agheader_repair.c +3 -1
@@ -708,7 +708,9 @@ xrep_agfl_init_header(*/ xagb_bitmap_init (&af.used_extents); af.agfl_bno =xfs_buf_to_agfl_bno (agfl_bp); -xagb_bitmap_walk (agfl_extents, xrep_agfl_fill, &af); + error =xagb_bitmap_walk (agfl_extents, xrep_agfl_fill, &af); +if (error && error != -ECANCELED ) + goto err_undo; error =xagb_bitmap_disunion (agfl_extents, &af.used_extents);if (error) goto err_undo;
Greg Kroah-Hartman
maintainerPATCH 676/1193 Revert "arm64: dts: qcom: sm8550: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 76c695d6e923614e9490a3cb4f8538742f7493b8.
--- arch/arm64/boot/dts/qcom/sm8550.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8550.dtsi +4 -4
@@ -1736,8 +1736,8 @@ pcie0: pci@1c00000 { msi-map = <0x0 &gic_its 0x1400 0x1>, <0x100 &gic_its 0x1401 0x1>; - iommu-map = <0x0 &apps_smmu 0x1400 0x0 0x1>, - <0x100 &apps_smmu 0x1401 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1400 0x1>, + <0x100 &apps_smmu 0x1401 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -1834,8 +1834,8 @@ pcie1: pci@1c08000 { msi-map = <0x0 &gic_its 0x1480 0x1>, <0x100 &gic_its 0x1481 0x1>; - iommu-map = <0x0 &apps_smmu 0x1480 0x0 0x1>, - <0x100 &apps_smmu 0x1481 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1480 0x1>, + <0x100 &apps_smmu 0x1481 0x1>; resets = <&gcc GCC_PCIE_1_BCR>, <&gcc GCC_PCIE_1_LINK_DOWN_BCR>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 677/1193 Revert "arm64: dts: qcom: sm8450: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit de01d783368c5e11d384af51345b5745c82f352e.
--- arch/arm64/boot/dts/qcom/sm8450.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8450.dtsi +4 -4
@@ -1811,8 +1811,8 @@ pcie0: pci@1c00000 { "aggre0", "aggre1"; - iommu-map = <0x0 &apps_smmu 0x1c00 0x0 0x1>, - <0x100 &apps_smmu 0x1c01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c00 0x1>, + <0x100 &apps_smmu 0x1c01 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -1919,8 +1919,8 @@ pcie1: pci@1c08000 { "ddrss_sf_tbu", "aggre1"; - iommu-map = <0x0 &apps_smmu 0x1c80 0x0 0x1>, - <0x100 &apps_smmu 0x1c81 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c80 0x1>, + <0x100 &apps_smmu 0x1c81 0x1>; resets = <&gcc GCC_PCIE_1_BCR>; reset-names = "pci";
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 678/1193 Revert "arm64: dts: qcom: sm8350: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 4a2efff1ebdbeb8dfd765154ee1d975e786c6942.
--- arch/arm64/boot/dts/qcom/sm8350.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8350.dtsi +4 -4
@@ -1552,8 +1552,8 @@ pcie0: pci@1c00000 { "aggre1", "aggre0"; - iommu-map = <0x0 &apps_smmu 0x1c00 0x0 0x1>, - <0x100 &apps_smmu 0x1c01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c00 0x1>, + <0x100 &apps_smmu 0x1c01 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -1635,8 +1635,8 @@ pcie1: pci@1c08000 { "ddrss_sf_tbu", "aggre1"; - iommu-map = <0x0 &apps_smmu 0x1c80 0x0 0x1>, - <0x100 &apps_smmu 0x1c81 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c80 0x1>, + <0x100 &apps_smmu 0x1c81 0x1>; resets = <&gcc GCC_PCIE_1_BCR>; reset-names = "pci";
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 679/1193 Revert "arm64: dts: qcom: sm8250: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 9dedefe9d949ad0ba21c3d30998623223aafc7dd.
--- arch/arm64/boot/dts/qcom/sm8250.dtsi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm64/boot/dts/qcom/sm8250.dtsi +6 -6
@@ -1895,8 +1895,8 @@ pcie0: pci@1c00000 { "tbu", "ddrss_sf_tbu"; - iommu-map = <0x0 &apps_smmu 0x1c00 0x0 0x1>, - <0x100 &apps_smmu 0x1c01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c00 0x1>, + <0x100 &apps_smmu 0x1c01 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -2002,8 +2002,8 @@ pcie1: pci@1c08000 { assigned-clocks = <&gcc GCC_PCIE_1_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1c80 0x0 0x1>, - <0x100 &apps_smmu 0x1c81 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c80 0x1>, + <0x100 &apps_smmu 0x1c81 0x1>; resets = <&gcc GCC_PCIE_1_BCR>; reset-names = "pci";
@@ -2111,8 +2111,8 @@ pcie2: pci@1c10000 { assigned-clocks = <&gcc GCC_PCIE_2_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1d00 0x0 0x1>, - <0x100 &apps_smmu 0x1d01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1d00 0x1>, + <0x100 &apps_smmu 0x1d01 0x1>; resets = <&gcc GCC_PCIE_2_BCR>; reset-names = "pci";
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 680/1193 Revert "arm64: dts: qcom: sm8150: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 796fcf46d75515f920d3efe4a33540fc6523d940.
--- arch/arm64/boot/dts/qcom/sm8150.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8150.dtsi +4 -4
@@ -1865,8 +1865,8 @@ pcie0: pci@1c00000 { "slave_q2a", "tbu"; - iommu-map = <0x0 &apps_smmu 0x1d80 0x0 0x1>, - <0x100 &apps_smmu 0x1d81 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1d80 0x1>, + <0x100 &apps_smmu 0x1d81 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -1967,8 +1967,8 @@ pcie1: pci@1c08000 { assigned-clocks = <&gcc GCC_PCIE_1_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1e00 0x0 0x1>, - <0x100 &apps_smmu 0x1e01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1e00 0x1>, + <0x100 &apps_smmu 0x1e01 0x1>; resets = <&gcc GCC_PCIE_1_BCR>; reset-names = "pci";
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 681/1193 Revert "arm64: dts: qcom: sdm845: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 3c9cbf39055faf75b588f30aac5e409555075295.
--- arch/arm64/boot/dts/qcom/sdm845.dtsi | 64 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 32 deletions(-)
arch/arm64/boot/dts/qcom/sdm845.dtsi +32 -32
@@ -2349,22 +2349,22 @@ pcie0: pci@1c00000 { "slave_q2a", "tbu"; - iommu-map = <0x0 &apps_smmu 0x1c10 0x0 0x1>, - <0x100 &apps_smmu 0x1c11 0x0 0x1>, - <0x200 &apps_smmu 0x1c12 0x0 0x1>, - <0x300 &apps_smmu 0x1c13 0x0 0x1>, - <0x400 &apps_smmu 0x1c14 0x0 0x1>, - <0x500 &apps_smmu 0x1c15 0x0 0x1>, - <0x600 &apps_smmu 0x1c16 0x0 0x1>, - <0x700 &apps_smmu 0x1c17 0x0 0x1>, - <0x800 &apps_smmu 0x1c18 0x0 0x1>, - <0x900 &apps_smmu 0x1c19 0x0 0x1>, - <0xa00 &apps_smmu 0x1c1a 0x0 0x1>, - <0xb00 &apps_smmu 0x1c1b 0x0 0x1>, - <0xc00 &apps_smmu 0x1c1c 0x0 0x1>, - <0xd00 &apps_smmu 0x1c1d 0x0 0x1>, - <0xe00 &apps_smmu 0x1c1e 0x0 0x1>, - <0xf00 &apps_smmu 0x1c1f 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c10 0x1>, + <0x100 &apps_smmu 0x1c11 0x1>, + <0x200 &apps_smmu 0x1c12 0x1>, + <0x300 &apps_smmu 0x1c13 0x1>, + <0x400 &apps_smmu 0x1c14 0x1>, + <0x500 &apps_smmu 0x1c15 0x1>, + <0x600 &apps_smmu 0x1c16 0x1>, + <0x700 &apps_smmu 0x1c17 0x1>, + <0x800 &apps_smmu 0x1c18 0x1>, + <0x900 &apps_smmu 0x1c19 0x1>, + <0xa00 &apps_smmu 0x1c1a 0x1>, + <0xb00 &apps_smmu 0x1c1b 0x1>, + <0xc00 &apps_smmu 0x1c1c 0x1>, + <0xd00 &apps_smmu 0x1c1d 0x1>, + <0xe00 &apps_smmu 0x1c1e 0x1>, + <0xf00 &apps_smmu 0x1c1f 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -2459,22 +2459,22 @@ pcie1: pci@1c08000 { assigned-clocks = <&gcc GCC_PCIE_1_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1c00 0x0 0x1>, - <0x100 &apps_smmu 0x1c01 0x0 0x1>, - <0x200 &apps_smmu 0x1c02 0x0 0x1>, - <0x300 &apps_smmu 0x1c03 0x0 0x1>, - <0x400 &apps_smmu 0x1c04 0x0 0x1>, - <0x500 &apps_smmu 0x1c05 0x0 0x1>, - <0x600 &apps_smmu 0x1c06 0x0 0x1>, - <0x700 &apps_smmu 0x1c07 0x0 0x1>, - <0x800 &apps_smmu 0x1c08 0x0 0x1>, - <0x900 &apps_smmu 0x1c09 0x0 0x1>, - <0xa00 &apps_smmu 0x1c0a 0x0 0x1>, - <0xb00 &apps_smmu 0x1c0b 0x0 0x1>, - <0xc00 &apps_smmu 0x1c0c 0x0 0x1>, - <0xd00 &apps_smmu 0x1c0d 0x0 0x1>, - <0xe00 &apps_smmu 0x1c0e 0x0 0x1>, - <0xf00 &apps_smmu 0x1c0f 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c00 0x1>, + <0x100 &apps_smmu 0x1c01 0x1>, + <0x200 &apps_smmu 0x1c02 0x1>, + <0x300 &apps_smmu 0x1c03 0x1>, + <0x400 &apps_smmu 0x1c04 0x1>, + <0x500 &apps_smmu 0x1c05 0x1>, + <0x600 &apps_smmu 0x1c06 0x1>, + <0x700 &apps_smmu 0x1c07 0x1>, + <0x800 &apps_smmu 0x1c08 0x1>, + <0x900 &apps_smmu 0x1c09 0x1>, + <0xa00 &apps_smmu 0x1c0a 0x1>, + <0xb00 &apps_smmu 0x1c0b 0x1>, + <0xc00 &apps_smmu 0x1c0c 0x1>, + <0xd00 &apps_smmu 0x1c0d 0x1>, + <0xe00 &apps_smmu 0x1c0e 0x1>, + <0xf00 &apps_smmu 0x1c0f 0x1>; resets = <&gcc GCC_PCIE_1_BCR>; reset-names = "pci";
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 682/1193 Revert "arm64: dts: qcom: sc8180x: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 31db9b8610e3fe6367cca8e5aca23953ecaf1efa.
--- arch/arm64/boot/dts/qcom/sc8180x.dtsi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/arm64/boot/dts/qcom/sc8180x.dtsi +8 -8
@@ -1745,8 +1745,8 @@ pcie0: pci@1c00000 { assigned-clocks = <&gcc GCC_PCIE_0_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1d80 0x0 0x1>, - <0x100 &apps_smmu 0x1d81 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1d80 0x1>, + <0x100 &apps_smmu 0x1d81 0x1>; resets = <&gcc GCC_PCIE_0_BCR>; reset-names = "pci";
@@ -1842,8 +1842,8 @@ pcie3: pci@1c08000 { assigned-clocks = <&gcc GCC_PCIE_3_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1e00 0x0 0x1>, - <0x100 &apps_smmu 0x1e01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1e00 0x1>, + <0x100 &apps_smmu 0x1e01 0x1>; resets = <&gcc GCC_PCIE_3_BCR>; reset-names = "pci";
@@ -1940,8 +1940,8 @@ pcie1: pci@1c10000 { assigned-clocks = <&gcc GCC_PCIE_1_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1c80 0x0 0x1>, - <0x100 &apps_smmu 0x1c81 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1c80 0x1>, + <0x100 &apps_smmu 0x1c81 0x1>; resets = <&gcc GCC_PCIE_1_BCR>; reset-names = "pci";
@@ -2038,8 +2038,8 @@ pcie2: pci@1c18000 { assigned-clocks = <&gcc GCC_PCIE_2_AUX_CLK>; assigned-clock-rates = <19200000>; - iommu-map = <0x0 &apps_smmu 0x1d00 0x0 0x1>, - <0x100 &apps_smmu 0x1d01 0x0 0x1>; + iommu-map = <0x0 &apps_smmu 0x1d00 0x1>, + <0x100 &apps_smmu 0x1d01 0x1>; resets = <&gcc GCC_PCIE_2_BCR>; reset-names = "pci";
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 683/1193 Revert "nvme-apple: Reset q->sq_tail during queue init"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 85316d624f56573a6e278e1d8c10309f4fb6d2ae.
--- drivers/nvme/host/apple.c | 1 - 1 file changed, 1 deletion(-)
drivers/nvme/host/apple.c +0 -1
@@ -1023,7 +1023,6 @@ static void apple_nvme_init_queue(struct apple_nvme_queue *q)unsigned int depth =apple_nvme_queue_depth (q);struct apple_nvme *anv =queue_to_apple_nvme (q); - q->sq_tail =0 ; q->cq_head =0 ; q->cq_phase =1 ;if (anv->hw->has_lsq_nvmmu)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 684/1193 Revert "nvme-apple: Prevent shared tags across queues on Apple A11"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 073b9238fac4d1c7727c1d05e3fafad0fd40d451.
--- drivers/nvme/host/apple.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/nvme/host/apple.c +8 -4
@@ -239,7 +239,7 @@ static unsigned int apple_nvme_queue_depth(struct apple_nvme_queue *q) {struct apple_nvme *anv =queue_to_apple_nvme (q); -if (q->is_adminq) +if (q->is_adminq && anv->hw->has_lsq_nvmmu)return APPLE_NVME_AQ_DEPTH ;return anv->hw->max_queue_depth;
@@ -317,7 +317,7 @@ static void apple_nvme_submit_cmd_t8015(struct apple_nvme_queue *q,memcpy ((void *)q->sqes + (q->sq_tail <<APPLE_NVME_IOSQES ), cmd,sizeof (*cmd)); -if (++q->sq_tail ==apple_nvme_queue_depth (q)) +if (++q->sq_tail == anv->hw->max_queue_depth) q->sq_tail =0 ;writel (q->sq_tail, q->sq_db);
@@ -1128,7 +1128,10 @@ static void apple_nvme_reset_work(struct work_struct *work) }/* Setup the admin queue */ - aqa =APPLE_NVME_AQ_DEPTH -1 ; +if (anv->hw->has_lsq_nvmmu) + aqa =APPLE_NVME_AQ_DEPTH -1 ; +else + aqa = anv->hw->max_queue_depth -1 ; aqa |= aqa <<16 ;writel (aqa, anv->mmio_nvme +NVME_REG_AQA );writeq (anv->adminq.sq_dma_addr, anv->mmio_nvme +NVME_REG_ASQ );
@@ -1311,7 +1314,8 @@ static int apple_nvme_alloc_tagsets(struct apple_nvme *anv)* both queues. The admin queue gets the first APPLE_NVME_AQ_DEPTH which * must be marked as reserved in the IO queue. */ - anv->tagset.reserved_tags =APPLE_NVME_AQ_DEPTH ; +if (anv->hw->has_lsq_nvmmu) + anv->tagset.reserved_tags =APPLE_NVME_AQ_DEPTH ; anv->tagset.queue_depth = anv->hw->max_queue_depth -1 ; anv->tagset.timeout =NVME_IO_TIMEOUT ; anv->tagset.numa_node =NUMA_NO_NODE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 685/1193 Revert "nvme-apple: Drop the PRP null check chicken bit"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit ca6b14f01d0993992d2c4bfd972c1f5c46284745.
--- drivers/nvme/host/apple.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/nvme/host/apple.c +14 -0
@@ -47,6 +47,9 @@#define APPLE_ANS_BOOT_STATUS 0x1300#define APPLE_ANS_BOOT_STATUS_OK 0xde71ce55 +#define APPLE_ANS_UNKNOWN_CTRL 0x24008 +#define APPLE_ANS_PRP_NULL_CHECK BIT(11) +#define APPLE_ANS_LINEAR_SQ_CTRL 0x24908#define APPLE_ANS_LINEAR_SQ_EN BIT(0)
@@ -1125,6 +1128,17 @@ static void apple_nvme_reset_work(struct work_struct *work)/* Setup the NVMMU for the maximum admin and IO queue depth */ writel (anv->hw->max_queue_depth -1 , anv->mmio_nvme +APPLE_NVMMU_NUM_TCBS ); + +/* +* This is probably a chicken bit: without it all commands +* where any PRP is set to zero (including those that don't use +* that field) fail and the co-processor complains about +* "completed with err BAD_CMD-" or a "NULL_PRP_PTR_ERR" in the +* syslog +*/ +writel (readl (anv->mmio_nvme +APPLE_ANS_UNKNOWN_CTRL ) & + ~APPLE_ANS_PRP_NULL_CHECK , + anv->mmio_nvme +APPLE_ANS_UNKNOWN_CTRL ); }/* Setup the admin queue */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 686/1193 Revert "nvme: apple: Add Apple A11 support"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 7256eed48ce7d78ab9689d84135b77a15454de55.
--- drivers/nvme/host/apple.c | 197 ++++++++++++-------------------------- 1 file changed, 60 insertions(+), 137 deletions(-)
drivers/nvme/host/apple.c +60 -137
@@ -35,6 +35,7 @@#include "nvme.h" #define APPLE_ANS_BOOT_TIMEOUT USEC_PER_SEC +#define APPLE_ANS_MAX_QUEUE_DEPTH 64#define APPLE_ANS_COPROC_CPU_CONTROL 0x44#define APPLE_ANS_COPROC_CPU_CONTROL_RUN BIT(4)
@@ -74,8 +75,6 @@#define APPLE_NVME_AQ_DEPTH 2#define APPLE_NVME_AQ_MQ_TAG_DEPTH (APPLE_NVME_AQ_DEPTH - 1) -#define APPLE_NVME_IOSQES 7 -/* * These can be higher, but we need to ensure that any command doesn't * require an sg allocation that needs more than a page of data.
@@ -143,7 +142,6 @@ struct apple_nvme_queue {u32 __iomem *sq_db;u32 __iomem *cq_db; -u16 sq_tail;u16 cq_head;u8 cq_phase;
@@ -185,17 +183,11 @@ struct apple_nvme_iod {struct scatterlist *sg; }; -struct apple_nvme_hw { -bool has_lsq_nvmmu; -u32 max_queue_depth; -}; -struct apple_nvme {struct device *dev;void __iomem *mmio_coproc;void __iomem *mmio_nvme; -const struct apple_nvme_hw *hw;struct device **pd_dev;struct device_link **pd_link;
@@ -240,12 +232,10 @@ static inline struct apple_nvme *queue_to_apple_nvme(struct apple_nvme_queue *q)static unsigned int apple_nvme_queue_depth (struct apple_nvme_queue *q) { -struct apple_nvme *anv =queue_to_apple_nvme (q); - -if (q->is_adminq && anv->hw->has_lsq_nvmmu) +if (q->is_adminq)return APPLE_NVME_AQ_DEPTH ; -return anv->hw->max_queue_depth; +return APPLE_ANS_MAX_QUEUE_DEPTH ; }static void apple_nvme_rtkit_crashed (void *cookie)
@@ -307,28 +297,7 @@ static void apple_nvmmu_inval(struct apple_nvme_queue *q, unsigned int tag) "NVMMU TCB invalidation failed\n"); } -static void apple_nvme_submit_cmd_t8015 (struct apple_nvme_queue *q, -struct nvme_command *cmd) -{ -struct apple_nvme *anv =queue_to_apple_nvme (q); - -spin_lock_irq (&anv->lock); - -if (q->is_adminq) -memcpy (&q->sqes[q->sq_tail], cmd,sizeof (*cmd)); -else -memcpy ((void *)q->sqes + (q->sq_tail <<APPLE_NVME_IOSQES ), - cmd,sizeof (*cmd)); - -if (++q->sq_tail == anv->hw->max_queue_depth) - q->sq_tail =0 ; - -writel (q->sq_tail, q->sq_db); -spin_unlock_irq (&anv->lock); -} - - -static void apple_nvme_submit_cmd_t8103 (struct apple_nvme_queue *q, +static void apple_nvme_submit_cmd (struct apple_nvme_queue *q,struct nvme_command *cmd) {struct apple_nvme *anv =queue_to_apple_nvme (q);
@@ -640,8 +609,7 @@ static inline void apple_nvme_handle_cqe(struct apple_nvme_queue *q,__u16 command_id =READ_ONCE (cqe->command_id);struct request *req; -if (anv->hw->has_lsq_nvmmu) -apple_nvmmu_inval (q, command_id); +apple_nvmmu_inval (q, command_id); req =nvme_find_rq (apple_nvme_queue_tagset (anv, q), command_id);if (unlikely (!req)) {
@@ -735,7 +703,7 @@ static int apple_nvme_create_cq(struct apple_nvme *anv) c.create_cq.opcode = nvme_admin_create_cq; c.create_cq.prp1 =cpu_to_le64 (anv->ioq.cq_dma_addr); c.create_cq.cqid =cpu_to_le16 (1 ); - c.create_cq.qsize =cpu_to_le16 (anv->hw->max_queue_depth -1 ); + c.create_cq.qsize =cpu_to_le16 (APPLE_ANS_MAX_QUEUE_DEPTH -1 ); c.create_cq.cq_flags =cpu_to_le16 (NVME_QUEUE_PHYS_CONTIG |NVME_CQ_IRQ_ENABLED ); c.create_cq.irq_vector =cpu_to_le16 (0 );
@@ -763,7 +731,7 @@ static int apple_nvme_create_sq(struct apple_nvme *anv) c.create_sq.opcode = nvme_admin_create_sq; c.create_sq.prp1 =cpu_to_le64 (anv->ioq.sq_dma_addr); c.create_sq.sqid =cpu_to_le16 (1 ); - c.create_sq.qsize =cpu_to_le16 (anv->hw->max_queue_depth -1 ); + c.create_sq.qsize =cpu_to_le16 (APPLE_ANS_MAX_QUEUE_DEPTH -1 ); c.create_sq.sq_flags =cpu_to_le16 (NVME_QUEUE_PHYS_CONTIG ); c.create_sq.cqid =cpu_to_le16 (1 );
@@ -815,12 +783,7 @@ static blk_status_t apple_nvme_queue_rq(struct blk_mq_hw_ctx *hctx, }nvme_start_request (req); - -if (anv->hw->has_lsq_nvmmu) -apple_nvme_submit_cmd_t8103 (q, cmnd); -else -apple_nvme_submit_cmd_t8015 (q, cmnd); - +apple_nvme_submit_cmd (q, cmnd);return BLK_STS_OK ; out_free_cmd:
@@ -1024,13 +987,11 @@ static const struct blk_mq_ops apple_nvme_mq_ops = {static void apple_nvme_init_queue (struct apple_nvme_queue *q) {unsigned int depth =apple_nvme_queue_depth (q); -struct apple_nvme *anv =queue_to_apple_nvme (q); q->cq_head =0 ; q->cq_phase =1 ; -if (anv->hw->has_lsq_nvmmu) -memset (q->tcbs,0 , anv->hw->max_queue_depth - *sizeof (struct apple_nvmmu_tcb )); +memset (q->tcbs,0 , +APPLE_ANS_MAX_QUEUE_DEPTH *sizeof (struct apple_nvmmu_tcb ));memset (q->cqes,0 , depth *sizeof (struct nvme_completion ));apple_nvme_enable_queue (q); }
@@ -1112,55 +1073,49 @@ static void apple_nvme_reset_work(struct work_struct *work)dma_set_max_seg_size (anv->dev,0xffffffff ); -if (anv->hw->has_lsq_nvmmu) { -/* -* Enable NVMMU and linear submission queues which is required -* since T6000. -*/ -writel (APPLE_ANS_LINEAR_SQ_EN , - anv->mmio_nvme +APPLE_ANS_LINEAR_SQ_CTRL ); +/* +* Enable NVMMU and linear submission queues. +* While we could keep those disabled and pretend this is slightly +* more common NVMe controller we'd still need some quirks (e.g. +* sq entries will be 128 bytes) and Apple might drop support for +* that mode in the future. +*/ +writel (APPLE_ANS_LINEAR_SQ_EN , + anv->mmio_nvme +APPLE_ANS_LINEAR_SQ_CTRL ); -/* Allow as many pending command as possible for both queues */ -writel (anv->hw->max_queue_depth - | (anv->hw->max_queue_depth <<16 ), anv->mmio_nvme - +APPLE_ANS_MAX_PEND_CMDS_CTRL ); +/* Allow as many pending command as possible for both queues */ +writel (APPLE_ANS_MAX_QUEUE_DEPTH | (APPLE_ANS_MAX_QUEUE_DEPTH <<16 ), + anv->mmio_nvme +APPLE_ANS_MAX_PEND_CMDS_CTRL ); -/* Setup the NVMMU for the maximum admin and IO queue depth */ -writel (anv->hw->max_queue_depth -1 , - anv->mmio_nvme +APPLE_NVMMU_NUM_TCBS ); +/* Setup the NVMMU for the maximum admin and IO queue depth */ +writel (APPLE_ANS_MAX_QUEUE_DEPTH -1 , + anv->mmio_nvme +APPLE_NVMMU_NUM_TCBS ); -/* -* This is probably a chicken bit: without it all commands -* where any PRP is set to zero (including those that don't use -* that field) fail and the co-processor complains about -* "completed with err BAD_CMD-" or a "NULL_PRP_PTR_ERR" in the -* syslog -*/ -writel (readl (anv->mmio_nvme +APPLE_ANS_UNKNOWN_CTRL ) & - ~APPLE_ANS_PRP_NULL_CHECK , - anv->mmio_nvme +APPLE_ANS_UNKNOWN_CTRL ); - } +/* +* This is probably a chicken bit: without it all commands where any PRP +* is set to zero (including those that don't use that field) fail and +* the co-processor complains about "completed with err BAD_CMD-" or +* a "NULL_PRP_PTR_ERR" in the syslog +*/ +writel (readl (anv->mmio_nvme +APPLE_ANS_UNKNOWN_CTRL ) & + ~APPLE_ANS_PRP_NULL_CHECK , + anv->mmio_nvme +APPLE_ANS_UNKNOWN_CTRL );/* Setup the admin queue */ -if (anv->hw->has_lsq_nvmmu) - aqa =APPLE_NVME_AQ_DEPTH -1 ; -else - aqa = anv->hw->max_queue_depth -1 ; + aqa =APPLE_NVME_AQ_DEPTH -1 ; aqa |= aqa <<16 ;writel (aqa, anv->mmio_nvme +NVME_REG_AQA );writeq (anv->adminq.sq_dma_addr, anv->mmio_nvme +NVME_REG_ASQ );writeq (anv->adminq.cq_dma_addr, anv->mmio_nvme +NVME_REG_ACQ ); -if (anv->hw->has_lsq_nvmmu) { -/* Setup NVMMU for both queues */ -writeq (anv->adminq.tcb_dma_addr, - anv->mmio_nvme +APPLE_NVMMU_ASQ_TCB_BASE ); -writeq (anv->ioq.tcb_dma_addr, - anv->mmio_nvme +APPLE_NVMMU_IOSQ_TCB_BASE ); - } +/* Setup NVMMU for both queues */ +writeq (anv->adminq.tcb_dma_addr, + anv->mmio_nvme +APPLE_NVMMU_ASQ_TCB_BASE ); +writeq (anv->ioq.tcb_dma_addr, + anv->mmio_nvme +APPLE_NVMMU_IOSQ_TCB_BASE ); anv->ctrl.sqsize = - anv->hw->max_queue_depth -1 ;/* 0's based queue depth */ +APPLE_ANS_MAX_QUEUE_DEPTH -1 ;/* 0's based queue depth */ anv->ctrl.cap =readq (anv->mmio_nvme +NVME_REG_CAP );dev_dbg (anv->dev,"Enabling controller now" );
@@ -1328,9 +1283,8 @@ static int apple_nvme_alloc_tagsets(struct apple_nvme *anv)* both queues. The admin queue gets the first APPLE_NVME_AQ_DEPTH which * must be marked as reserved in the IO queue. */ -if (anv->hw->has_lsq_nvmmu) - anv->tagset.reserved_tags =APPLE_NVME_AQ_DEPTH ; - anv->tagset.queue_depth = anv->hw->max_queue_depth -1 ; + anv->tagset.reserved_tags =APPLE_NVME_AQ_DEPTH ; + anv->tagset.queue_depth =APPLE_ANS_MAX_QUEUE_DEPTH -1 ; anv->tagset.timeout =NVME_IO_TIMEOUT ; anv->tagset.numa_node =NUMA_NO_NODE ; anv->tagset.cmd_size =sizeof (struct apple_nvme_iod );
@@ -1355,7 +1309,6 @@ static int apple_nvme_queue_alloc(struct apple_nvme *anv, struct apple_nvme_queue *q) {unsigned int depth =apple_nvme_queue_depth (q); -size_t iosq_size; q->cqes = dmam_alloc_coherent(anv->dev, depth * sizeof(struct nvme_completion),
@@ -1363,28 +1316,22 @@ static int apple_nvme_queue_alloc(struct apple_nvme *anv,if (!q->cqes)return -ENOMEM ; -if (anv->hw->has_lsq_nvmmu) - iosq_size = depth *sizeof (struct nvme_command ); -else - iosq_size = depth <<APPLE_NVME_IOSQES ; - - q->sqes =dmam_alloc_coherent (anv->dev, iosq_size, + q->sqes =dmam_alloc_coherent (anv->dev, + depth *sizeof (struct nvme_command ), &q->sq_dma_addr,GFP_KERNEL );if (!q->sqes)return -ENOMEM ; -if (anv->hw->has_lsq_nvmmu) { -/* -* We need the maximum queue depth here because the NVMMU only -* has a single depth configuration shared between both queues. -*/ - q->tcbs =dmam_alloc_coherent (anv->dev, - anv->hw->max_queue_depth * -sizeof (struct apple_nvmmu_tcb ), - &q->tcb_dma_addr,GFP_KERNEL ); -if (!q->tcbs) -return -ENOMEM ; - } +/* +* We need the maximum queue depth here because the NVMMU only has a +* single depth configuration shared between both queues. +*/ + q->tcbs =dmam_alloc_coherent (anv->dev, +APPLE_ANS_MAX_QUEUE_DEPTH * +sizeof (struct apple_nvmmu_tcb ), + &q->tcb_dma_addr,GFP_KERNEL ); +if (!q->tcbs) +return -ENOMEM ;/* * initialize phase to make sure the allocated and empty memory
@@ -1468,12 +1415,6 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) anv->adminq.is_adminq = true;platform_set_drvdata (pdev, anv); - anv->hw =of_device_get_match_data (&pdev->dev); -if (!anv->hw) { - ret = -ENODEV ; - goto put_dev; - } - ret =apple_nvme_attach_genpd (anv);if (ret <0 ) {dev_err_probe (dev, ret,"Failed to attach power domains" );
@@ -1505,17 +1446,10 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) goto put_dev; } -if (anv->hw->has_lsq_nvmmu) { - anv->adminq.sq_db = anv->mmio_nvme +APPLE_ANS_LINEAR_ASQ_DB ; - anv->adminq.cq_db = anv->mmio_nvme +APPLE_ANS_ACQ_DB ; - anv->ioq.sq_db = anv->mmio_nvme +APPLE_ANS_LINEAR_IOSQ_DB ; - anv->ioq.cq_db = anv->mmio_nvme +APPLE_ANS_IOCQ_DB ; - }else { - anv->adminq.sq_db = anv->mmio_nvme +NVME_REG_DBS ; - anv->adminq.cq_db = anv->mmio_nvme +APPLE_ANS_ACQ_DB ; - anv->ioq.sq_db = anv->mmio_nvme +NVME_REG_DBS +8 ; - anv->ioq.cq_db = anv->mmio_nvme +APPLE_ANS_IOCQ_DB ; - } + anv->adminq.sq_db = anv->mmio_nvme +APPLE_ANS_LINEAR_ASQ_DB ; + anv->adminq.cq_db = anv->mmio_nvme +APPLE_ANS_ACQ_DB ; + anv->ioq.sq_db = anv->mmio_nvme +APPLE_ANS_LINEAR_IOSQ_DB ; + anv->ioq.cq_db = anv->mmio_nvme +APPLE_ANS_IOCQ_DB ; anv->sart =devm_apple_sart_get (dev);if (IS_ERR (anv->sart)) {
@@ -1692,19 +1626,8 @@ static int apple_nvme_suspend(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(apple_nvme_pm_ops, apple_nvme_suspend, apple_nvme_resume); -static const struct apple_nvme_hw apple_nvme_t8015_hw = { - .has_lsq_nvmmu = false, - .max_queue_depth =16 , -}; - -static const struct apple_nvme_hw apple_nvme_t8103_hw = { - .has_lsq_nvmmu = true, - .max_queue_depth =64 , -}; -static const struct of_device_id apple_nvme_of_match[] = { - { .compatible ="apple,t8015-nvme-ans2" , .data = &apple_nvme_t8015_hw }, - { .compatible ="apple,nvme-ans2" , .data = &apple_nvme_t8103_hw }, + { .compatible ="apple,nvme-ans2" }, {}, };MODULE_DEVICE_TABLE (of, apple_nvme_of_match);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 687/1193 Revert "selftests/mm: skip COW tmpfile cases when fallocate() is unsupported"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit bc8be70fdeb94a15a3cd534ac8eea69574b8149c.
--- tools/testing/selftests/mm/cow.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
tools/testing/selftests/mm/cow.c +2 -7
@@ -1670,13 +1670,8 @@ static void run_with_tmpfile(non_anon_test_fn fn, const char *desc)/* File consists of a single page filled with zeroes. */ if (fallocate (fd,0 ,0 , pagesize)) { -if (errno ==EOPNOTSUPP ) { -ksft_print_msg ("fallocate() not supported by filesystem\n" ); -log_test_result (KSFT_SKIP ); - }else { -ksft_perror ("fallocate() failed" ); -log_test_result (KSFT_FAIL ); - } +ksft_perror ("fallocate() failed" ); +log_test_result (KSFT_FAIL ); goto close; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 688/1193 Revert "selftests/mm: report unique test names for each cow test"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 4498f617a4948e6dd8a8bf5e94c1920acafbe70b.
--- tools/testing/selftests/mm/cow.c | 333 +++++++++++-------------------- 1 file changed, 116 insertions(+), 217 deletions(-)
tools/testing/selftests/mm/cow.c +116 -217
@@ -78,12 +78,9 @@ struct comm_pipes {static int setup_comm_pipes (struct comm_pipes *comm_pipes) { -if (pipe (comm_pipes->child_ready) <0 ) { -ksft_perror ("pipe()" ); +if (pipe (comm_pipes->child_ready) <0 )return -errno; - }if (pipe (comm_pipes->parent_ready) <0 ) { -ksft_perror ("pipe()" );close (comm_pipes->child_ready[0 ]);close (comm_pipes->child_ready[1 ]);return -errno;
@@ -176,14 +173,13 @@ static void do_test_cow_in_parent(char *mem, size_t size, bool do_mprotect, ret =setup_comm_pipes (&comm_pipes);if (ret) { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pipe() failed\n" );return ; } ret =fork ();if (ret <0 ) { -ksft_perror ("fork() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fork() failed\n" ); goto close_comm_pipes; }else if (!ret) {exit (fn (mem, size, &comm_pipes));
@@ -198,18 +194,9 @@ static void do_test_cow_in_parent(char *mem, size_t size, bool do_mprotect,* write-faults by directly mapping pages writable. */ ret =mprotect (mem, size,PROT_READ ); + ret |=mprotect (mem, size,PROT_READ |PROT_WRITE );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); -write (comm_pipes.parent_ready[1 ],"0" ,1 ); -wait (&ret); - goto close_comm_pipes; - } - - ret =mprotect (mem, size,PROT_READ |PROT_WRITE ); -if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" );write (comm_pipes.parent_ready[1 ],"0" ,1 );wait (&ret); goto close_comm_pipes;
@@ -227,16 +214,16 @@ static void do_test_cow_in_parent(char *mem, size_t size, bool do_mprotect, ret = -EINVAL ;if (!ret) { -log_test_result (KSFT_PASS ); +ksft_test_result_pass ("No leak from parent into child\n" ); }else if (xfail) {/* * With hugetlb, some vmsplice() tests are currently expected to * fail because (a) harder to fix and (b) nobody really cares. * Flag them as expected failure for now. */ -log_test_result (KSFT_XFAIL ); +ksft_test_result_xfail ("Leak from parent into child\n" ); }else { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("Leak from parent into child\n" ); } close_comm_pipes:close_comm_pipes (&comm_pipes);
@@ -285,29 +272,26 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, ret =setup_comm_pipes (&comm_pipes);if (ret) { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pipe() failed\n" ); goto free; }if (pipe (fds) <0 ) { -ksft_perror ("pipe() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pipe() failed\n" ); goto close_comm_pipes; }if (before_fork) { transferred =vmsplice (fds[1 ], &iov,1 ,0 );if (transferred <=0 ) { -ksft_print_msg ("vmsplice() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("vmsplice() failed\n" ); goto close_pipe; } } ret =fork ();if (ret <0 ) { -ksft_perror ("fork() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fork() failed\n" ); goto close_pipe; }else if (!ret) {write (comm_pipes.child_ready[1 ],"0" ,1 );
@@ -321,8 +305,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size,if (!before_fork) { transferred =vmsplice (fds[1 ], &iov,1 ,0 );if (transferred <=0 ) { -ksft_perror ("vmsplice() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("vmsplice() failed\n" );wait (&ret); goto close_pipe; }
@@ -331,8 +314,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size,while (read (comm_pipes.child_ready[0 ], &buf,1 ) !=1 ) ;if (munmap (mem, size) <0 ) { -ksft_perror ("munmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("munmap() failed\n" ); goto close_pipe; }write (comm_pipes.parent_ready[1 ],"0" ,1 );
@@ -340,8 +322,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size,/* Wait until the child is done writing. */ wait (&ret);if (!WIFEXITED (ret)) { -ksft_perror ("wait() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("wait() failed\n" ); goto close_pipe; }
@@ -349,23 +330,22 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size,for (total =0 ; total < transferred; total += cur) { cur =read (fds[0 ], new + total, transferred - total);if (cur <0 ) { -ksft_perror ("read() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("read() failed\n" ); goto close_pipe; } }if (!memcmp (old, new, transferred)) { -log_test_result (KSFT_PASS ); +ksft_test_result_pass ("No leak from child into parent\n" ); }else if (xfail) {/* * With hugetlb, some vmsplice() tests are currently expected to * fail because (a) harder to fix and (b) nobody really cares. * Flag them as expected failure for now. */ -log_test_result (KSFT_XFAIL ); +ksft_test_result_xfail ("Leak from child into parent\n" ); }else { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("Leak from child into parent\n" ); } close_pipe:close (fds[0 ]);
@@ -402,14 +382,13 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) ret =setup_comm_pipes (&comm_pipes);if (ret) { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pipe() failed\n" );return ; } file =tmpfile ();if (!file) { -ksft_perror ("tmpfile() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("tmpfile() failed\n" ); goto close_comm_pipes; } fd =fileno (file);
@@ -417,16 +396,14 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) tmp =malloc (size);if (!tmp) { -ksft_print_msg ("malloc() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("malloc() failed\n" ); goto close_file; }/* Skip on errors, as we might just lack kernel support. */ ret =io_uring_queue_init (1 , &ring,0 );if (ret <0 ) { -ksft_print_msg ("io_uring_queue_init() failed\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("io_uring_queue_init() failed\n" ); goto free_tmp; }
@@ -441,8 +418,7 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork) iov.iov_len = size; ret =io_uring_register_buffers (&ring, &iov,1 );if (ret) { -ksft_print_msg ("io_uring_register_buffers() failed\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("io_uring_register_buffers() failed\n" ); goto queue_exit; }
@@ -453,8 +429,7 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork)*/ ret =fork ();if (ret <0 ) { -ksft_perror ("fork() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fork() failed\n" ); goto unregister_buffers; }else if (!ret) {write (comm_pipes.child_ready[1 ],"0" ,1 );
@@ -474,17 +449,10 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork)* if the page is mapped R/O vs. R/W). */ ret =mprotect (mem, size,PROT_READ ); -if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); - goto unregister_buffers; - } -clear_softdirty (); - ret =mprotect (mem, size,PROT_READ |PROT_WRITE ); + ret |=mprotect (mem, size,PROT_READ |PROT_WRITE );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" ); goto unregister_buffers; } }
@@ -496,29 +464,25 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork)memset (mem,0xff , size); sqe =io_uring_get_sqe (&ring);if (!sqe) { -ksft_print_msg ("io_uring_get_sqe() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("io_uring_get_sqe() failed\n" ); goto quit_child; }io_uring_prep_write_fixed (sqe, fd, mem, size,0 ,0 ); ret =io_uring_submit (&ring);if (ret <0 ) { -ksft_print_msg ("io_uring_submit() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("io_uring_submit() failed\n" ); goto quit_child; } ret =io_uring_wait_cqe (&ring, &cqe);if (ret <0 ) { -ksft_print_msg ("io_uring_wait_cqe() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("io_uring_wait_cqe() failed\n" ); goto quit_child; }if (cqe->res != size) { -ksft_print_msg ("write_fixed failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("write_fixed failed\n" ); goto quit_child; }io_uring_cqe_seen (&ring, cqe);
@@ -528,18 +492,15 @@ static void do_test_iouring(char *mem, size_t size, bool use_fork)while (total < size) { cur =pread (fd, tmp + total, size - total, total);if (cur <0 ) { -ksft_print_msg ("pread() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pread() failed\n" ); goto quit_child; } total += cur; }/* Finally, check if we read what we expected. */ -if (!memcmp (mem, tmp, size)) -log_test_result (KSFT_PASS ); -else -log_test_result (KSFT_FAIL ); +ksft_test_result (!memcmp (mem, tmp, size), +"Longterm R/W pin is reliable\n" ); quit_child:if (use_fork) {
@@ -587,21 +548,19 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test,int ret;if (gup_fd <0 ) { -ksft_print_msg ("gup_test not available\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("gup_test not available\n" );return ; } tmp =malloc (size);if (!tmp) { -ksft_print_msg ("malloc() failed\n" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("malloc() failed\n" );return ; } ret =setup_comm_pipes (&comm_pipes);if (ret) { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pipe() failed\n" ); goto free_tmp; }
@@ -616,8 +575,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test,*/ ret =fork ();if (ret <0 ) { -ksft_perror ("fork() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fork() failed\n" ); goto close_comm_pipes; }else if (!ret) {write (comm_pipes.child_ready[1 ],"0" ,1 );
@@ -654,8 +612,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test,clear_softdirty (); ret |=mprotect (mem, size,PROT_READ |PROT_WRITE );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" ); goto close_comm_pipes; }break ;
@@ -670,11 +627,9 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test, ret =ioctl (gup_fd,PIN_LONGTERM_TEST_START , &args);if (ret) {if (errno ==EINVAL ) - ret =KSFT_SKIP ; +ksft_test_result_skip ("PIN_LONGTERM_TEST_START failed\n" );else - ret =KSFT_FAIL ; -ksft_perror ("PIN_LONGTERM_TEST_START failed" ); -log_test_result (ret); +ksft_test_result_fail ("PIN_LONGTERM_TEST_START failed\n" ); goto wait; }
@@ -687,26 +642,22 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test,*/ tmp_val = (__u64 )(uintptr_t )tmp; ret =ioctl (gup_fd,PIN_LONGTERM_TEST_READ , &tmp_val); -if (ret) { -ksft_perror ("PIN_LONGTERM_TEST_READ failed" ); -log_test_result (KSFT_FAIL ); - }else { -if (!memcmp (mem, tmp, size)) -log_test_result (KSFT_PASS ); -else -log_test_result (KSFT_FAIL ); - } +if (ret) +ksft_test_result_fail ("PIN_LONGTERM_TEST_READ failed\n" ); +else +ksft_test_result (!memcmp (mem, tmp, size), +"Longterm R/O pin is reliable\n" ); ret =ioctl (gup_fd,PIN_LONGTERM_TEST_STOP );if (ret) -ksft_perror ("PIN_LONGTERM_TEST_STOP failed" ); +ksft_print_msg ("[INFO] PIN_LONGTERM_TEST_STOP failed\n" ); wait:switch (test) {case RO_PIN_TEST_SHARED :write (comm_pipes.parent_ready[1 ],"0" ,1 );wait (&ret);if (!WIFEXITED (ret)) -ksft_perror ("wait() failed" ); +ksft_print_msg ("[INFO] wait() failed\n" );break ;default :break ;
@@ -761,16 +712,14 @@ static void do_run_with_base_page(test_fn fn, bool swapout) mem =mmap (NULL , pagesize,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );if (mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" );return ; } ret =madvise (mem, pagesize,MADV_NOHUGEPAGE );/* Ignore if not around on a kernel. */ if (ret && errno !=EINVAL ) { -ksft_perror ("MADV_NOHUGEPAGE failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_NOHUGEPAGE failed\n" ); goto munmap; }
@@ -780,8 +729,7 @@ static void do_run_with_base_page(test_fn fn, bool swapout)if (swapout) {madvise (mem, pagesize,MADV_PAGEOUT );if (!pagemap_is_swapped (pagemap_fd, mem)) { -ksft_print_msg ("MADV_PAGEOUT did not work, is swap enabled?\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("MADV_PAGEOUT did not work, is swap enabled?\n" ); goto munmap; } }
@@ -793,13 +741,13 @@ static void do_run_with_base_page(test_fn fn, bool swapout)static void run_with_base_page (test_fn fn,const char *desc) { -log_test_start ("%s ... with base page" , desc); +ksft_print_msg ("[RUN] %s ... with base page\n" , desc);do_run_with_base_page (fn, false); }static void run_with_base_page_swap (test_fn fn,const char *desc) { -log_test_start ("%s ... with swapped out base page" , desc); +ksft_print_msg ("[RUN] %s ... with swapped out base page\n" , desc);do_run_with_base_page (fn, true); }
@@ -825,8 +773,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) mmap_mem =mmap (NULL , mmap_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );if (mmap_mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" );return ; }
@@ -835,8 +782,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) ret =madvise (mem, thpsize,MADV_HUGEPAGE );if (ret) { -ksft_perror ("MADV_HUGEPAGE failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_HUGEPAGE failed\n" ); goto munmap; }
@@ -846,8 +792,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)*/ mem[0 ] =0 ;if (!pagemap_is_populated (pagemap_fd, mem + thpsize - pagesize)) { -ksft_print_msg ("Did not get a THP populated\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("Did not get a THP populated\n" ); goto munmap; }memset (mem,0 , thpsize);
@@ -867,14 +812,12 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)*/ ret =mprotect (mem + pagesize, pagesize,PROT_READ );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" ); goto munmap; } ret =mprotect (mem + pagesize, pagesize,PROT_READ |PROT_WRITE );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" ); goto munmap; }break ;
@@ -886,8 +829,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)*/ ret =madvise (mem + pagesize, thpsize - pagesize,MADV_DONTNEED );if (ret) { -ksft_perror ("MADV_DONTNEED failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_DONTNEED failed\n" ); goto munmap; } size = pagesize;
@@ -901,15 +843,13 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize) mremap_mem =mmap (NULL , mremap_size,PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );if (mremap_mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto munmap; } tmp =mremap (mem + mremap_size, mremap_size, mremap_size,MREMAP_MAYMOVE |MREMAP_FIXED , mremap_mem);if (tmp != mremap_mem) { -ksft_perror ("mremap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mremap() failed\n" ); goto munmap; } size = mremap_size;
@@ -922,14 +862,12 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)*/ ret =madvise (mem + pagesize, thpsize - pagesize,MADV_DONTFORK );if (ret) { -ksft_perror ("MADV_DONTFORK failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_DONTFORK failed\n" ); goto munmap; } ret =fork ();if (ret <0 ) { -ksft_perror ("fork() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fork() failed\n" ); goto munmap; }else if (!ret) {exit (0 );
@@ -938,8 +876,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)/* Allow for sharing all pages again. */ ret =madvise (mem + pagesize, thpsize - pagesize,MADV_DOFORK );if (ret) { -ksft_perror ("MADV_DOFORK failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_DOFORK failed\n" ); goto munmap; }break ;
@@ -953,8 +890,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)case THP_RUN_SINGLE_PTE_SWAPOUT :madvise (mem, size,MADV_PAGEOUT );if (!range_is_swapped (mem, size)) { -ksft_print_msg ("MADV_PAGEOUT did not work, is swap enabled?\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("MADV_PAGEOUT did not work, is swap enabled?\n" ); goto munmap; }break ;
@@ -971,56 +907,56 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)static void run_with_thp (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_PMD , size); }static void run_with_thp_swap (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with swapped-out THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with swapped-out THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_PMD_SWAPOUT , size); }static void run_with_pte_mapped_thp (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with PTE-mapped THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with PTE-mapped THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_PTE , size); }static void run_with_pte_mapped_thp_swap (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with swapped-out, PTE-mapped THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with swapped-out, PTE-mapped THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_PTE_SWAPOUT , size); }static void run_with_single_pte_of_thp (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with single PTE of THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with single PTE of THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_SINGLE_PTE , size); }static void run_with_single_pte_of_thp_swap (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with single PTE of swapped-out THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with single PTE of swapped-out THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_SINGLE_PTE_SWAPOUT , size); }static void run_with_partial_mremap_thp (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with partially mremap()'ed THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with partially mremap()'ed THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_PARTIAL_MREMAP , size); }static void run_with_partial_shared_thp (test_fn fn,const char *desc,size_t size) { -log_test_start ("%s ... with partially shared THP (%zu kB)" , +ksft_print_msg ("[RUN] %s ... with partially shared THP (%zu kB)\n" , desc, size /1024 );do_run_with_thp (fn,THP_RUN_PARTIAL_SHARED , size); }
@@ -1030,15 +966,14 @@ static void run_with_hugetlb(test_fn fn, const char *desc, size_t hugetlbsize)int flags =MAP_PRIVATE |MAP_ANONYMOUS |MAP_HUGETLB ;char *mem, *dummy; -log_test_start ("%s ... with hugetlb (%zu kB)" , desc, +ksft_print_msg ("[RUN] %s ... with hugetlb (%zu kB)\n" , desc, hugetlbsize /1024 ); flags |=__builtin_ctzll (hugetlbsize) <<MAP_HUGE_SHIFT ; mem =mmap (NULL , hugetlbsize,PROT_READ |PROT_WRITE , flags,-1 ,0 );if (mem ==MAP_FAILED ) { -ksft_perror ("need more free huge pages" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("need more free huge pages\n" );return ; }
@@ -1051,8 +986,7 @@ static void run_with_hugetlb(test_fn fn, const char *desc, size_t hugetlbsize)*/ dummy =mmap (NULL , hugetlbsize,PROT_READ |PROT_WRITE , flags,-1 ,0 );if (dummy ==MAP_FAILED ) { -ksft_perror ("need more free huge pages" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("need more free huge pages\n" ); goto munmap; }munmap (dummy, hugetlbsize);
@@ -1245,7 +1179,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, ret =setup_comm_pipes (&comm_pipes);if (ret) { -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("pipe() failed\n" );return ; }
@@ -1255,14 +1189,12 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,*/ ret =mprotect (mem + pagesize, pagesize,PROT_READ );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" ); goto close_comm_pipes; } ret =mprotect (mem + pagesize, pagesize,PROT_READ |PROT_WRITE );if (ret) { -ksft_perror ("mprotect() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mprotect() failed\n" ); goto close_comm_pipes; }
@@ -1271,8 +1203,8 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,/* Collapse before actually COW-sharing the page. */ ret =madvise (mem, size,MADV_COLLAPSE );if (ret) { -ksft_perror ("MADV_COLLAPSE failed" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("MADV_COLLAPSE failed: %s\n" , +strerror (errno)); goto close_comm_pipes; }break ;
@@ -1283,8 +1215,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,/* Don't COW-share the upper part of the THP. */ ret =madvise (mem + size /2 , size /2 ,MADV_DONTFORK );if (ret) { -ksft_perror ("MADV_DONTFORK failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_DONTFORK failed\n" ); goto close_comm_pipes; }break ;
@@ -1292,8 +1223,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,/* Don't COW-share the lower part of the THP. */ ret =madvise (mem, size /2 ,MADV_DONTFORK );if (ret) { -ksft_perror ("MADV_DONTFORK failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_DONTFORK failed\n" ); goto close_comm_pipes; }break ;
@@ -1303,8 +1233,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size, ret =fork ();if (ret <0 ) { -ksft_perror ("fork() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fork() failed\n" ); goto close_comm_pipes; }else if (!ret) {switch (test) {
@@ -1338,8 +1267,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,*/ ret =madvise (mem, size,MADV_DOFORK );if (ret) { -ksft_perror ("MADV_DOFORK failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("MADV_DOFORK failed\n" );write (comm_pipes.parent_ready[1 ],"0" ,1 );wait (&ret); goto close_comm_pipes;
@@ -1349,8 +1277,8 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,/* Collapse before anyone modified the COW-shared page. */ ret =madvise (mem, size,MADV_COLLAPSE );if (ret) { -ksft_perror ("MADV_COLLAPSE failed" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("MADV_COLLAPSE failed: %s\n" , +strerror (errno));write (comm_pipes.parent_ready[1 ],"0" ,1 );wait (&ret); goto close_comm_pipes;
@@ -1370,10 +1298,7 @@ static void do_test_anon_thp_collapse(char *mem, size_t size,else ret = -EINVAL ; -if (!ret) -log_test_result (KSFT_PASS ); -else -log_test_result (KSFT_FAIL ); +ksft_test_result (!ret,"No leak from parent into child\n" ); close_comm_pipes:close_comm_pipes (&comm_pipes); }
@@ -1458,7 +1383,7 @@ static void run_anon_thp_test_cases(void)for (i =0 ; i <ARRAY_SIZE (anon_thp_test_cases); i++) {struct test_case const *test_case = &anon_thp_test_cases[i]; -log_test_start ("%s" , test_case->desc); +ksft_print_msg ("[RUN] %s\n" , test_case->desc);do_run_with_thp (test_case->fn,THP_RUN_PMD , pmdsize); } }
@@ -1481,10 +1406,8 @@ static void test_cow(char *mem, const char *smem, size_t size)memset (mem,0xff , size);/* See if we still read the old values via the other mapping. */ -if (!memcmp (smem, old, size)) -log_test_result (KSFT_PASS ); -else -log_test_result (KSFT_FAIL ); +ksft_test_result (!memcmp (smem, old, size), +"Other mapping not modified\n" );free (old); }
@@ -1502,20 +1425,18 @@ static void run_with_zeropage(non_anon_test_fn fn, const char *desc) {char *mem, *smem, tmp; -log_test_start ("%s ... with shared zeropage" , desc); +ksft_print_msg ("[RUN] %s ... with shared zeropage\n" , desc); mem =mmap (NULL , pagesize,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANON ,-1 ,0 );if (mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" );return ; } smem =mmap (NULL , pagesize,PROT_READ ,MAP_PRIVATE |MAP_ANON ,-1 ,0 );if (smem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto munmap; }
@@ -1536,11 +1457,10 @@ static void run_with_huge_zeropage(non_anon_test_fn fn, const char *desc)size_t mmap_size;int ret; -log_test_start ("%s ... with huge zeropage" , desc); +ksft_print_msg ("[RUN] %s ... with huge zeropage\n" , desc);if (!has_huge_zeropage) { -ksft_print_msg ("Huge zeropage not enabled\n" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("Huge zeropage not enabled\n" );return ; }
@@ -1549,15 +1469,13 @@ static void run_with_huge_zeropage(non_anon_test_fn fn, const char *desc) mmap_mem =mmap (NULL , mmap_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );if (mmap_mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" );return ; } mmap_smem =mmap (NULL , mmap_size,PROT_READ ,MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );if (mmap_smem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto munmap; }
@@ -1566,15 +1484,9 @@ static void run_with_huge_zeropage(non_anon_test_fn fn, const char *desc) smem = (char *)(((uintptr_t )mmap_smem + pmdsize) & ~(pmdsize -1 )); ret =madvise (mem, pmdsize,MADV_HUGEPAGE ); -if (ret !=0 ) { -ksft_perror ("madvise()" ); -log_test_result (KSFT_FAIL ); - goto munmap; - } ret |=madvise (smem, pmdsize,MADV_HUGEPAGE ); -if (ret !=0 ) { -ksft_perror ("madvise()" ); -log_test_result (KSFT_FAIL ); +if (ret) { +ksft_test_result_fail ("MADV_HUGEPAGE failed\n" ); goto munmap; }
@@ -1603,33 +1515,29 @@ static void run_with_memfd(non_anon_test_fn fn, const char *desc)char *mem, *smem, tmp;int fd; -log_test_start ("%s ... with memfd" , desc); +ksft_print_msg ("[RUN] %s ... with memfd\n" , desc); fd =memfd_create ("test" ,0 );if (fd <0 ) { -ksft_perror ("memfd_create() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("memfd_create() failed\n" );return ; }/* File consists of a single page filled with zeroes. */ if (fallocate (fd,0 ,0 , pagesize)) { -ksft_perror ("fallocate() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fallocate() failed\n" ); goto close; }/* Create a private mapping of the memfd. */ mem =mmap (NULL , pagesize,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 );if (mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto close; } smem =mmap (NULL , pagesize,PROT_READ ,MAP_SHARED , fd,0 );if (smem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto munmap; }
@@ -1652,40 +1560,35 @@ static void run_with_tmpfile(non_anon_test_fn fn, const char *desc)FILE *file;int fd; -log_test_start ("%s ... with tmpfile" , desc); +ksft_print_msg ("[RUN] %s ... with tmpfile\n" , desc); file =tmpfile ();if (!file) { -ksft_perror ("tmpfile() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("tmpfile() failed\n" );return ; } fd =fileno (file);if (fd <0 ) { -ksft_perror ("fileno() failed" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("fileno() failed\n" );return ; }/* File consists of a single page filled with zeroes. */ if (fallocate (fd,0 ,0 , pagesize)) { -ksft_perror ("fallocate() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("fallocate() failed\n" ); goto close; }/* Create a private mapping of the memfd. */ mem =mmap (NULL , pagesize,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 );if (mem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto close; } smem =mmap (NULL , pagesize,PROT_READ ,MAP_SHARED , fd,0 );if (smem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto munmap; }
@@ -1709,22 +1612,20 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,char *mem, *smem, tmp;int fd; -log_test_start ("%s ... with memfd hugetlb (%zu kB)" , desc, +ksft_print_msg ("[RUN] %s ... with memfd hugetlb (%zu kB)\n" , desc, hugetlbsize /1024 ); flags |=__builtin_ctzll (hugetlbsize) <<MFD_HUGE_SHIFT ; fd =memfd_create ("test" , flags);if (fd <0 ) { -ksft_perror ("memfd_create() failed" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("memfd_create() failed\n" );return ; }/* File consists of a single page filled with zeroes. */ if (fallocate (fd,0 ,0 , hugetlbsize)) { -ksft_perror ("need more free huge pages" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("need more free huge pages\n" ); goto close; }
@@ -1732,14 +1633,12 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc, mem =mmap (NULL , hugetlbsize,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 );if (mem ==MAP_FAILED ) { -ksft_perror ("need more free huge pages" ); -log_test_result (KSFT_SKIP ); +ksft_test_result_skip ("need more free huge pages\n" ); goto close; } smem =mmap (NULL , hugetlbsize,PROT_READ ,MAP_SHARED , fd,0 );if (smem ==MAP_FAILED ) { -ksft_perror ("mmap() failed" ); -log_test_result (KSFT_FAIL ); +ksft_test_result_fail ("mmap() failed\n" ); goto munmap; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 689/1193 Revert "perf tests: Fix flakiness in BPF counters test on hybrid systems"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 1f27602b20119ae9261eb5c608bd1374af630f00.
--- tools/perf/tests/shell/stat_bpf_counters.sh | 28 ++++++++------------- 1 file changed, 10 insertions(+), 18 deletions(-)
tools/perf/tests/shell/stat_bpf_counters.sh +10 -18
@@ -4,26 +4,21 @@ set -e -# Get the first allowed CPU -CPU=$(taskset -c -p $$ | awk -F': ' '{print $2}' | awk -F'[,-]' '{print $1}') -if [ -z "$CPU" ]; then - CPU=0 -fi -workload=(taskset -c "$CPU" awk 'BEGIN { for (i=0; i<10000000; i++) sum+=i }') +workload="perf test -w sqrtloop" -# check whether $2 is within +/- 15% of $1 +# check whether $2 is within +/- 20% of $1 compare_number() { first_num=$1 second_num=$2 - # upper bound is first_num * 115% - upper=$(expr $first_num + $first_num / 20 \* 3 ) - # lower bound is first_num * 85% - lower=$(expr $first_num - $first_num / 20 \* 3 ) + # upper bound is first_num * 120% + upper=$(expr $first_num + $first_num / 5 ) + # lower bound is first_num * 80% + lower=$(expr $first_num - $first_num / 5 ) if [ $second_num -gt $upper ] || [ $second_num -lt $lower ]; then - echo "The difference between $first_num and $second_num are greater than 15%." + echo "The difference between $first_num and $second_num are greater than 20%." exit 1 fi }
@@ -46,12 +41,11 @@ check_counts() test_bpf_counters() { printf "Testing --bpf-counters " - base_instructions=$(perf stat --no-big-num -e instructions:u -- "${workload[@]}" 2>&1 | \ + base_instructions=$(perf stat --no-big-num -e instructions -- $workload 2>&1 | \ awk -v i=0 -v c=0 '/instructions/ { \ if ($1 != "<not") { i++; c += $1 } \ } END { if (i > 0) printf "%.0f", c; else print "<not" }') - bpf_instructions=$(perf stat --no-big-num --bpf-counters -e instructions:u \ - -- "${workload[@]}" 2>&1 | \ + bpf_instructions=$(perf stat --no-big-num --bpf-counters -e instructions -- $workload 2>&1 | \ awk -v i=0 -v c=0 '/instructions/ { \ if ($1 != "<not") { i++; c += $1 } \ } END { if (i > 0) printf "%.0f", c; else print "<not" }')
@@ -63,9 +57,7 @@ test_bpf_counters() test_bpf_modifier() { printf "Testing bpf event modifier " - stat_output=$(perf stat --no-big-num \ - -e instructions/name=base_instructions/u,instructions/name=bpf_instructions/bu \ - -- "${workload[@]}" 2>&1) + stat_output=$(perf stat --no-big-num -e instructions/name=base_instructions/,instructions/name=bpf_instructions/b -- $workload 2>&1) base_instructions=$(echo "$stat_output"| \ awk -v i=0 -v c=0 '/base_instructions/ { \ if ($1 != "<not") { i++; c += $1 } \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 690/1193 perf evsel: Add per-thread warning for EOPNOTSUPP open failues
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit f0869f31562bde2ed9131665f8f76ef7a3983383 ]
The mrvl_ddr_pmu will return EOPNOTSUPP if opened in per-thread mode. Give a warning for this similar to EINVAL.
Doing this better supports metric testing with limited permissions when the mrvl_ddr_pmu is present, as the failure to open causes the test to skip and not fail.
--- tools/perf/util/evsel.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/util/evsel.c +4 -0
@@ -3047,6 +3047,10 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,return scnprintf (msg, size,"%s" ,"No hardware sampling interrupt available.\n" );#endif +if (!target__has_cpu (target)) +return scnprintf (msg, size, +"Unsupported event (%s) in per-thread mode, enable system wide with '-a'." , +evsel__name (evsel));break ;case EBUSY :if (find_process ("oprofiled" ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 691/1193 usb: xusbatm: dont rely on id table pointer arithmetic
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit eb6cd6d3d8abeac5d7e8251b898067184afdad8a ]
The current code is broken when dynamic ID is involved; in such cases usb_device_id parameter of probe lives on the heap and the pointer arithmetic will get an index that is wildly out of bound. xusbatm initialize the USB device IDs dynamically so it can just use driver_info too.
Even with conversion, xusbatm still cannot support dynamic IDs, so also set no_dynamic_id.
--- drivers/usb/atm/xusbatm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/atm/xusbatm.c +4 -2
@@ -79,7 +79,7 @@ static int xusbatm_bind(struct usbatm_data *usbatm, struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *usb_dev = interface_to_usbdev(intf); -int drv_ix = id - xusbatm_usb_ids; +int drv_ix = id->driver_info;int rx_alt = rx_altsetting[drv_ix];int tx_alt = tx_altsetting[drv_ix];struct usb_interface *rx_intf =xusbatm_find_intf (usb_dev, rx_alt, rx_endpoint[drv_ix]);
@@ -168,7 +168,8 @@ static struct usb_driver xusbatm_usb_driver = { .name = xusbatm_driver_name, .probe = xusbatm_usb_probe, .disconnect = usbatm_usb_disconnect, - .id_table = xusbatm_usb_ids + .id_table = xusbatm_usb_ids, + .no_dynamic_id = 1, };static int __init xusbatm_init (void )
@@ -190,6 +191,7 @@ static int __init xusbatm_init(void) xusbatm_usb_ids[i].match_flags =USB_DEVICE_ID_MATCH_DEVICE ; xusbatm_usb_ids[i].idVendor = vendor[i]; xusbatm_usb_ids[i].idProduct = product[i]; + xusbatm_usb_ids[i].driver_info = i; xusbatm_drivers[i].driver_name = xusbatm_driver_name; xusbatm_drivers[i].bind = xusbatm_bind;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 692/1193 wifi: ath9k_htc: dont store usb_device_id
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit 14d2ac442d660e112efc0ce87ad10085013ed2b1 ]
usb_device_id is not guaranteed to live longer than probe due to presence of dynamic ID. All information apart from driver_data can be easily retrieved from usb_device, so just store driver_data.
--- drivers/net/wireless/ath/ath9k/hif_usb.c | 12 ++++++------ drivers/net/wireless/ath/ath9k/hif_usb.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath9k/hif_usb.c +6 -6
@@ -1097,7 +1097,7 @@ static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev) }kfree (buf); -if (IS_AR7010_DEVICE (hif_dev->usb_device_id->driver_info)) +if (IS_AR7010_DEVICE (hif_dev->id_info)) firm_offset =AR7010_FIRMWARE_TEXT ;else firm_offset =AR9271_FIRMWARE_TEXT ;
@@ -1192,7 +1192,7 @@ static int ath9k_hif_request_firmware(struct hif_device_usb *hif_dev,if (MAJOR_VERSION_REQ ==1 && hif_dev->fw_minor_index ==3 ) {const char *filename; -if (IS_AR7010_DEVICE (hif_dev->usb_device_id->driver_info)) +if (IS_AR7010_DEVICE (hif_dev->id_info)) filename =FIRMWARE_AR7010_1_1 ;else filename =FIRMWARE_AR9271 ;
@@ -1208,7 +1208,7 @@ static int ath9k_hif_request_firmware(struct hif_device_usb *hif_dev,return -ENOENT ; }else { -if (IS_AR7010_DEVICE (hif_dev->usb_device_id->driver_info)) +if (IS_AR7010_DEVICE (hif_dev->id_info)) chip ="7010" ;else chip ="9271" ;
@@ -1265,9 +1265,9 @@ static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context) ret =ath9k_htc_hw_init (hif_dev->htc_handle, &hif_dev->interface->dev, - hif_dev->usb_device_id->idProduct, +le16_to_cpu (hif_dev->udev->descriptor.idProduct), hif_dev->udev->product, - hif_dev->usb_device_id->driver_info); + hif_dev->id_info);if (ret) { ret = -EINVAL ; goto err_htc_hw_init;
@@ -1381,7 +1381,7 @@ static int ath9k_hif_usb_probe(struct usb_interface *interface, hif_dev->udev = udev; hif_dev->interface = interface; - hif_dev->usb_device_id = id; + hif_dev->id_info = id->driver_info;#ifdef CONFIG_PM udev->reset_resume =1 ;#endif
drivers/net/wireless/ath/ath9k/hif_usb.h +1 -1
@@ -115,7 +115,7 @@ struct cmd_buf {struct hif_device_usb {struct usb_device *udev;struct usb_interface *interface; -const struct usb_device_id *usb_device_id; +int id_info;const void *fw_data;size_t fw_size;struct completion fw_done;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 693/1193 usb: usbtmc: dont store usb_device_id
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit fc045acec1a501c97f84ae184aadce9dae4ba9b2 ]
usb_device_id is not guaranteed to live longer than probe due to presence of dynamic ID. This stored ID is unused so remove it.
--- drivers/usb/class/usbtmc.c | 2 -- 1 file changed, 2 deletions(-)
drivers/usb/class/usbtmc.c +0 -2
@@ -71,7 +71,6 @@ struct usbtmc_dev_capabilities {* allocated for each USBTMC device in the driver's probe function. */ struct usbtmc_device_data { -const struct usb_device_id *id;struct usb_device *usb_dev;struct usb_interface *intf;struct list_head file_list;
@@ -2398,7 +2397,6 @@ static int usbtmc_probe(struct usb_interface *intf,return -ENOMEM ; data->intf = intf; - data->id = id; data->usb_dev =usb_get_dev (interface_to_usbdev (intf));usb_set_intfdata (intf, data);kref_init (&data->kref);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 694/1193 usb: serial: spcp8x5: dont store usb_device_id
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit 934e1322f18c1b58bca431c0d5d01e002060c990 ]
USB probe functions should not keep usb_device_id for longer than probe due to presence of dynamic ID removal. USB serial does not support ID removal, however in this case only driver_data is ever needed, there is no reason keeping the usb_device_id in the first place, so convert it as well.
--- drivers/usb/serial/spcp8x5.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/serial/spcp8x5.c +3 -3
@@ -145,14 +145,14 @@ struct spcp8x5_private {static int spcp8x5_probe (struct usb_serial *serial,const struct usb_device_id *id) { -usb_set_serial_data (serial, (void *)id); +usb_set_serial_data (serial, (void *)id->driver_info);return 0 ; }static int spcp8x5_port_probe (struct usb_serial_port *port) { -const struct usb_device_id *id =usb_get_serial_data (port->serial); +unsigned int quirks = (unsigned int )(unsigned long )usb_get_serial_data (port->serial);struct spcp8x5_private *priv; priv =kzalloc (sizeof (*priv),GFP_KERNEL );
@@ -160,7 +160,7 @@ static int spcp8x5_port_probe(struct usb_serial_port *port)return -ENOMEM ;spin_lock_init (&priv->lock); - priv->quirks = id->driver_info; + priv->quirks = quirks;usb_set_serial_port_data (port, priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 695/1193 media: as102: do not rely on id table address comparison
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit 91a8c8c718889fc8ccf5c38b750d790e9f36f92d ]
The driver info should be retrieved using the driver_info field, not by address comparison.
--- drivers/media/usb/as102/as102_usb_drv.c | 73 ++++++++++--------------- 1 file changed, 30 insertions(+), 43 deletions(-)
drivers/media/usb/as102/as102_usb_drv.c +30 -43
@@ -24,35 +24,33 @@ static void as102_usb_stop_stream(struct as102_dev_t *dev);static int as102_open (struct inode *inode,struct file *file);static int as102_release (struct inode *inode,struct file *file); -static const struct usb_device_id as102_usb_id_table[] = { - {USB_DEVICE (AS102_USB_DEVICE_VENDOR_ID ,AS102_USB_DEVICE_PID_0001 ) }, - {USB_DEVICE (PCTV_74E_USB_VID ,PCTV_74E_USB_PID ) }, - {USB_DEVICE (ELGATO_EYETV_DTT_USB_VID ,ELGATO_EYETV_DTT_USB_PID ) }, - {USB_DEVICE (NBOX_DVBT_DONGLE_USB_VID ,NBOX_DVBT_DONGLE_USB_PID ) }, - {USB_DEVICE (SKY_IT_DIGITAL_KEY_USB_VID ,SKY_IT_DIGITAL_KEY_USB_PID ) }, - { }/* Terminating entry */ +struct as102_dev_info { +const char *name; +/* +* eLNA configuration: devices built on the reference design work best +* with 0xA0, while custom designs seem to require 0xC0 +*/ +uint8_t elna_cfg; }; -/* Note that this table must always have the same number of entries as the -as102_usb_id_table struct */ -static const char *const as102_device_names[] = { -AS102_REFERENCE_DESIGN , -AS102_PCTV_74E , -AS102_ELGATO_EYETV_DTT_NAME , -AS102_NBOX_DVBT_DONGLE_NAME , -AS102_SKY_IT_DIGITAL_KEY_NAME , -NULL /* Terminating entry */ -}; +#define DRIVER_INFO (dev_name, dev_elna_cfg) \ + .driver_info = (kernel_ulong_t)&(const struct as102_dev_info){ \ + .name = (dev_name), \ + .elna_cfg = (dev_elna_cfg), \ + } -/* eLNA configuration: devices built on the reference design work best -with 0xA0, while custom designs seem to require 0xC0 */ -static uint8_t const as102_elna_cfg[] = { -0xA0 , -0xC0 , -0xC0 , -0xA0 , -0xA0 , -0x00 /* Terminating entry */ +static const struct usb_device_id as102_usb_id_table[] = { + {USB_DEVICE (AS102_USB_DEVICE_VENDOR_ID ,AS102_USB_DEVICE_PID_0001 ), +DRIVER_INFO (AS102_REFERENCE_DESIGN ,0xA0 ) }, + {USB_DEVICE (PCTV_74E_USB_VID ,PCTV_74E_USB_PID ), +DRIVER_INFO (AS102_PCTV_74E ,0xC0 ) }, + {USB_DEVICE (ELGATO_EYETV_DTT_USB_VID ,ELGATO_EYETV_DTT_USB_PID ), +DRIVER_INFO (AS102_ELGATO_EYETV_DTT_NAME ,0xC0 ) }, + {USB_DEVICE (NBOX_DVBT_DONGLE_USB_VID ,NBOX_DVBT_DONGLE_USB_PID ), +DRIVER_INFO (AS102_NBOX_DVBT_DONGLE_NAME ,0xA0 ) }, + {USB_DEVICE (SKY_IT_DIGITAL_KEY_USB_VID ,SKY_IT_DIGITAL_KEY_USB_PID ), +DRIVER_INFO (AS102_SKY_IT_DIGITAL_KEY_NAME ,0xA0 ) }, + { }/* Terminating entry */ };struct usb_driver as102_usb_driver = {
@@ -336,29 +334,18 @@ static int as102_usb_probe(struct usb_interface *intf, {int ret;struct as102_dev_t *as102_dev; -int i; - -/* This should never actually happen */ -if (ARRAY_SIZE (as102_usb_id_table) != - (sizeof (as102_device_names) /sizeof (const char *))) { -pr_err ("Device names table invalid size" ); -return -EINVAL ; - } +const struct as102_dev_info *info = (const struct as102_dev_info *)id->driver_info; as102_dev =kzalloc (sizeof (struct as102_dev_t ),GFP_KERNEL );if (as102_dev ==NULL )return -ENOMEM ; -/* Assign the user-friendly device name */ -for (i =0 ; i <ARRAY_SIZE (as102_usb_id_table); i++) { -if (id == &as102_usb_id_table[i]) { - as102_dev->name = as102_device_names[i]; - as102_dev->elna_cfg = as102_elna_cfg[i]; - } - } - -if (as102_dev->name ==NULL ) +if (info) { + as102_dev->name = info->name; + as102_dev->elna_cfg = info->elna_cfg; + }else { as102_dev->name ="Unknown AS102 device" ; + }/* set private callback functions */ as102_dev->bus_adap.ops = &as102_priv_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 696/1193 net: usb: pegasus: dont rely on id table pointer arithmetic
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gary Guo <[email protected]>
[ Upstream commit ce8101c331956bbd3e20681331dfd22eb7c1c1ea ]
The current code is broken when dynamic ID is involved; in such cases usb_device_id parameter of probe lives on the heap and the pointer arithmetic will get an index that is wildly out of bound. Instead of keeping a side table for additional information, use driver_info field of the usb_device_id.
The dynamic ID parsing code needs to be updated for this; convert it to just write to the reserved entry for dynamic ID and remove the weird loop.
--- drivers/net/usb/pegasus.c | 54 ++++++++++++++++----------------------- drivers/net/usb/pegasus.h | 3 --- 2 files changed, 22 insertions(+), 35 deletions(-)
drivers/net/usb/pegasus.c +22 -32
@@ -46,21 +46,12 @@ static bool loopback;static bool mii_mode;static char *devid; -static struct usb_eth_dev usb_dev_id[] = { -#define PEGASUS_DEV(pn, vid, pid, flags) \ - {.name = pn, .vendor = vid, .device = pid, .private = flags}, -#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \ - PEGASUS_DEV(pn, vid, pid, flags) -#include "pegasus.h" -#undef PEGASUS_DEV -#undef PEGASUS_DEV_CLASS - {NULL ,0 ,0 ,0 }, - {NULL ,0 ,0 ,0 } -}; +static struct usb_eth_dev dynamic_id_info = {};static struct usb_device_id pegasus_ids[] = { #define PEGASUS_DEV(pn, vid, pid, flags) \ - {.match_flags =USB_DEVICE_ID_MATCH_DEVICE , .idVendor = vid, .idProduct = pid}, + {.match_flags =USB_DEVICE_ID_MATCH_DEVICE , .idVendor = vid, .idProduct = pid, \ + .driver_info = (kernel_ulong_t)&(const struct usb_eth_dev ) {.name = pn, .private = flags}},/* * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
@@ -69,7 +60,8 @@ static struct usb_device_id pegasus_ids[] = {*/ #define PEGASUS_DEV_CLASS (pn, vid, pid, dclass, flags) \ {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \ - .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass}, + .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass, \ + .driver_info = (kernel_ulong_t)&(const struct usb_eth_dev) {.name = pn, .private = flags}},#include "pegasus.h" #undef PEGASUS_DEV#undef PEGASUS_DEV_CLASS
@@ -405,12 +397,12 @@ static inline int reset_mac(pegasus_t *pegasus)if (i ==REG_TIMEOUT )return -ETIMEDOUT ; -if (usb_dev_id[pegasus->dev_index].vendor ==VENDOR_LINKSYS || - usb_dev_id[pegasus->dev_index].vendor ==VENDOR_DLINK ) { +if (le16_to_cpu (pegasus->usb->descriptor.idVendor) ==VENDOR_LINKSYS || +le16_to_cpu (pegasus->usb->descriptor.idVendor) ==VENDOR_DLINK ) {set_register (pegasus, Gpio0,0x24 );set_register (pegasus, Gpio0,0x26 ); } -if (usb_dev_id[pegasus->dev_index].vendor ==VENDOR_ELCON ) { +if (le16_to_cpu (pegasus->usb->descriptor.idVendor) ==VENDOR_ELCON ) {__u16 auxmode; ret =read_mii_word (pegasus,3 ,0x1b , &auxmode);if (ret <0 )
@@ -448,9 +440,9 @@ static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)memcpy (pegasus->eth_regs, data,sizeof (data)); ret =set_registers (pegasus, EthCtrl0,3 , data); -if (usb_dev_id[pegasus->dev_index].vendor ==VENDOR_LINKSYS || - usb_dev_id[pegasus->dev_index].vendor ==VENDOR_LINKSYS2 || - usb_dev_id[pegasus->dev_index].vendor ==VENDOR_DLINK ) { +if (le16_to_cpu (pegasus->usb->descriptor.idVendor) ==VENDOR_LINKSYS || +le16_to_cpu (pegasus->usb->descriptor.idVendor) ==VENDOR_LINKSYS2 || +le16_to_cpu (pegasus->usb->descriptor.idVendor) ==VENDOR_DLINK ) {u16 auxmode; ret =read_mii_word (pegasus,0 ,0x1b , &auxmode);if (ret <0 )
@@ -1156,7 +1148,7 @@ static int pegasus_probe(struct usb_interface *intf,struct usb_device *dev =interface_to_usbdev (intf);struct net_device *net;pegasus_t *pegasus; -int dev_index = id - pegasus_ids; +const struct usb_eth_dev *info = (const struct usb_eth_dev *)id->driver_info;int res = -ENOMEM ;static const u8 bulk_ep_addr[] = {PEGASUS_USB_EP_BULK_IN |USB_DIR_IN ,
@@ -1181,7 +1173,6 @@ static int pegasus_probe(struct usb_interface *intf, goto out; pegasus =netdev_priv (net); - pegasus->dev_index = dev_index; pegasus->intf = intf; res =alloc_urbs (pegasus);
@@ -1209,7 +1200,7 @@ static int pegasus_probe(struct usb_interface *intf, pegasus->msg_enable =netif_msg_init (msg_level,NETIF_MSG_DRV |NETIF_MSG_PROBE |NETIF_MSG_LINK ); - pegasus->features = usb_dev_id[dev_index].private; + pegasus->features = info ? info->private :DEFAULT_GPIO_RESET ; res =get_interrupt_interval (pegasus);if (res) goto out2;
@@ -1238,7 +1229,7 @@ static int pegasus_probe(struct usb_interface *intf,queue_delayed_work (system_long_wq, &pegasus->carrier_check,CARRIER_CHECK_DELAY );dev_info (&intf->dev,"%s, %s, %pM\n" , net->name, - usb_dev_id[dev_index].name, net->dev_addr); + info ? info->name :"(unknown)" , net->dev_addr);return 0 ; out3:
@@ -1328,8 +1319,9 @@ static struct usb_driver pegasus_driver = {static void __init parse_id (char *id) { -unsigned int vendor_id =0 , device_id =0 , flags =0 , i =0 ; +unsigned int vendor_id =0 , device_id =0 , flags =0 ;char *token, *name =NULL ; +int dyn_id_index =ARRAY_SIZE (pegasus_ids) -2 ;if ((token =strsep (&id,":" )) !=NULL ) name = token;
@@ -1347,14 +1339,12 @@ static void __init parse_id(char *id)if (device_id >0x10000 || device_id ==0 )return ; -for (i =0 ; usb_dev_id[i].name; i++); - usb_dev_id[i].name = name; - usb_dev_id[i].vendor = vendor_id; - usb_dev_id[i].device = device_id; - usb_dev_id[i].private = flags; - pegasus_ids[i].match_flags =USB_DEVICE_ID_MATCH_DEVICE ; - pegasus_ids[i].idVendor = vendor_id; - pegasus_ids[i].idProduct = device_id; + dynamic_id_info.name = name; + dynamic_id_info.private = flags; + pegasus_ids[dyn_id_index].match_flags =USB_DEVICE_ID_MATCH_DEVICE ; + pegasus_ids[dyn_id_index].idVendor = vendor_id; + pegasus_ids[dyn_id_index].idProduct = device_id; + pegasus_ids[dyn_id_index].driver_info = (kernel_ulong_t)&dynamic_id_info; }static int __init pegasus_init (void )
drivers/net/usb/pegasus.h +0 -3
@@ -85,7 +85,6 @@ typedef struct pegasus {unsigned features;u32 msg_enable;u32 wolopts; -int dev_index;int intr_interval;struct tasklet_struct rx_tl;struct delayed_work carrier_check;
@@ -102,8 +101,6 @@ typedef struct pegasus {struct usb_eth_dev {char *name; -__u16 vendor; -__u16 device;__u32 private;/* LSB is gpio reset value */ };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 697/1193 ALSA: us122l: Prevent write upgrades for read mappings
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kazuki Hanai <[email protected]>
[ Upstream commit 71c610aeb1770302ac9c9e0b9a4ecd37f1311928 ]
The hwdep mmap callback rejects read-buffer mappings that are initially writable, but leaves VM_MAYWRITE set on mappings created with PROT_READ. A process that can open the hwdep node O_RDWR can later use mprotect() to make the mapping writable.
The read allocation begins with struct usb_stream. Its read_size member is used by the fault handler to decide which pages belong to the read buffer. The read VMA intentionally remains expandable because pcm_usb_stream uses mremap() after reading that size. Changing read_size first can therefore map and access pages beyond the allocation. The same member is also consumed by usb_stream_free(), where changing it can make free_pages_exact() release pages outside the allocation.
Clear VM_MAYWRITE for read-buffer mappings after rejecting an initially writable VMA. This keeps the separate output-buffer mapping writable while preventing later permission upgrades.
--- sound/usb/usx2y/us122l.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
sound/usb/usx2y/us122l.c +6 -3
@@ -209,9 +209,12 @@ static int usb_stream_hwdep_mmap(struct snd_hwdep *hw,mutex_lock (&us122l->mutex); s = us122l->sk.s; read = offset < s->read_size; -if (read && area->vm_flags &VM_WRITE ) { - err = -EPERM ; - goto out; +if (read) { +if (area->vm_flags &VM_WRITE ) { + err = -EPERM ; + goto out; + } +vm_flags_clear (area,VM_MAYWRITE ); }snd_printdd (KERN_DEBUG "%lu %u\n" , size, read ? s->read_size : s->write_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 698/1193 i2c: smbus: reject oversized block transfers in the common path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit 3051cd060fa496df42954291fa2306ed2eab4ecc upstream.
The SMBus block transfer length data->block[0] is validated in i2c_smbus_xfer_emulated() but that check runs too late for tracepoints and is skipped entirely when the adapter provides a native smbus_xfer implementation. This allows user-controlled oversized block lengths to reach tracepoint memcpy calls and driver callbacks unchecked.
Add an early validation in __i2c_smbus_xfer() that rejects block transfers whose caller-supplied length is zero or exceeds I2C_SMBUS_BLOCK_MAX before any tracepoint fires or driver callback runs. data->block[0] is filled in by the device on SMBus block reads, so the check is scoped to operations where the length is actually supplied by the caller. This is consistent with the existing -EINVAL convention in the emulated path and protects all downstream consumers at once: the smbus_write tracepoint, all native smbus_xfer driver implementations, and the emulated path.
Two distinct bugs are fixed by this change:
Bug 1: smbus_write tracepoint OOB (include/trace/events/smbus.h)
trace_smbus_write() fires before any validation and copies data->block[0]+1 bytes into a 34-byte event buffer. With block[0]=0xfe the tracepoint copies 255 bytes, overflowing by 221.
BUG: KASAN: stack-out-of-bounds in trace_event_raw_event_smbus_write+0x27c/0x530 Read of size 255 at addr ffff88800d98fcf8 by task poc_smbus/91 Call Trace: <TASK> __asan_memcpy+0x23/0x80 trace_event_raw_event_smbus_write+0x27c/0x530 __i2c_smbus_xfer+0x43a/0xa40 i2c_smbus_xfer+0x19e/0x340 i2cdev_ioctl_smbus+0x38f/0x7f0 i2cdev_ioctl+0x35e/0x680 __x64_sys_ioctl+0x147/0x1e0 do_syscall_64+0xcf/0x15a0 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
Bug 2: i2c-stub I2C_SMBUS_I2C_BLOCK_DATA OOB (drivers/i2c/i2c-stub.c)
stub_xfer() implements .smbus_xfer directly and only clamps block[0] against 256-command, not I2C_SMBUS_BLOCK_MAX. With block[0]=0xff and command=0 the loop accesses block[1+i] for i up to 254, far past the 34-byte union.
UBSAN: array-index-out-of-bounds in drivers/i2c/i2c-stub.c:223:44 index 34 is out of range for type '__u8 [34]' Call Trace: <TASK> __ubsan_handle_out_of_bounds+0xd7/0x120 stub_xfer+0x1971/0x198f [i2c_stub] __i2c_smbus_xfer+0x306/0xa40 i2c_smbus_xfer+0x19e/0x340 i2cdev_ioctl_smbus+0x38f/0x7f0 i2cdev_ioctl+0x35e/0x680 __x64_sys_ioctl+0x147/0x1e0 do_syscall_64+0xcf/0x15a0 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
Both traces reproduced on v7.0-rc6+i2c/for-current with KASAN+UBSAN.
--- drivers/i2c/i2c-core-smbus.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/i2c/i2c-core-smbus.c +12 -0
@@ -565,6 +565,18 @@ s32 __i2c_smbus_xfer(struct i2c_adapterif (res)return res; +/* Reject invalid caller-supplied block lengths before any +* tracepoint or native smbus_xfer callback runs. +*/ +if (data && + (protocol ==I2C_SMBUS_I2C_BLOCK_DATA || + protocol ==I2C_SMBUS_BLOCK_PROC_CALL || + (protocol ==I2C_SMBUS_BLOCK_DATA && + read_write ==I2C_SMBUS_WRITE )) && + (data->block[0 ] ==0 || + data->block[0 ] >I2C_SMBUS_BLOCK_MAX )) +return -EINVAL ; +/* If enabled, the following two tracepoints are conditional on * read_write and protocol. */
Greg Kroah-Hartman
maintainerPATCH 699/1193 net: appletalk: fix NULL pointer dereference in aarp_send_ddp()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit 9e7f36ab5b7bf68463faa5f7b926fea8f35597bb upstream.
aarp_send_ddp() calls atalk_find_dev_addr(dev) in the LocalTalk fast path without checking for NULL. When the device has no AppleTalk interface configured (dev->atalk_ptr == NULL), this leads to a NULL pointer dereference at the at->s_net access.
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:aarp_send_ddp (net/appletalk/aarp.c:552 (discriminator 2)) Call Trace: <TASK> atalk_sendmsg (net/appletalk/ddp.c:1715) __sys_sendto (net/socket.c:2265 (discriminator 1)) __x64_sys_sendto (net/socket.c:2272) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Add a NULL check consistent with the other callers of atalk_find_dev_addr().
--- net/appletalk/aarp.c | 5 +++++ 1 file changed, 5 insertions(+)
net/appletalk/aarp.c +5 -0
@@ -573,6 +573,11 @@ int aarp_send_ddp(struct net_device *devstruct ddpehdr *ddp = (struct ddpehdr *)skb->data;int ft =2 ; +if (!at) { +kfree_skb (skb); +return NET_XMIT_DROP ; + } +/* * Compressible ? *
Greg Kroah-Hartman
maintainerPATCH 700/1193 fou: Fix use-after-free in fou_create()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xuanqiang Luo <[email protected]>
commit b14361aca6350ff7907b0e9903c7b94dc7d5d4a0 upstream.
fou_create() publishes struct fou through sk_user_data before adding the new FOU port to the per-netns list. If fou_add_to_port_list() fails, the error path frees fou while it is still reachable through sk_user_data. A concurrent receive can then dereference the freed object in fou_from_sock().
This ordering issue was previously noted in the linked discussion.
The failure is reachable when local port 0 is requested. Each socket binds to a different ephemeral port, but fou_cfg_cmp() compares the requested port 0 and reports -EALREADY once an entry already exists.
Release the tunnel socket before freeing fou so sk_user_data is cleared first, and defer reclamation with kfree_rcu() to protect concurrent RCU readers. This matches the lifetime handling in fou_release().
--- net/ipv4/fou_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fou_core.c +1 -1
@@ -636,9 +636,9 @@ static int fou_create(struct net *net, sreturn 0 ; error: -kfree (fou);if (sock)udp_tunnel_sock_release (sock); +kfree_rcu (fou, rcu);return err; }
Greg Kroah-Hartman
maintainerPATCH 701/1193 crypto: sun8i-ss - Remove crypto_rng interface
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit a78446ee6fae86ac8733f120e3ffce2e5d9384f5 upstream.
Since the crypto_rng interface for hardware PRNGs is unused and is redundant with hwrng and the actual Linux RNG, it's being phased out. Most drivers for it were already removed. Go ahead and remove the sun8i-ss support which is one of the only remaining ones.
As usual for crypto_rng, this driver was also buggy: its ->generate() function had a use-after-free vulnerability due to using wait_for_completion_interruptible_timeout() without handling shutting down the DMA operation if a signal is sent. Also, it had a buffer overread bug in the line 'memcpy(ctx->seed, d + dlen, ctx->slen);'. There's no point in fixing these bugs separately only to remove the code anyway, so this commit is marked with Fixes and Cc stable.
--- drivers/crypto/allwinner/Kconfig | 8 drivers/crypto/allwinner/sun8i-ss/Makefile | 1 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c | 39 ---- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c | 177 ---------------------- drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h | 23 -- 5 files changed, 248 deletions(-) delete mode 100644 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
drivers/crypto/allwinner/Kconfig +0 -8
@@ -113,14 +113,6 @@ config CRYPTO_DEV_SUN8I_SS_DEBUG This will create /sys/kernel/debug/sun8i-ss/stats for displaying the number of requests per flow and per algorithm. -config CRYPTO_DEV_SUN8I_SS_PRNG - bool "Support for Allwinner Security System PRNG" - depends on CRYPTO_DEV_SUN8I_SS - select CRYPTO_RNG - help - Select this option if you want to provide kernel-side support for - the Pseudo-Random Number Generator found in the Security System. - config CRYPTO_DEV_SUN8I_SS_HASH bool "Enable support for hash on sun8i-ss" depends on CRYPTO_DEV_SUN8I_SS
drivers/crypto/allwinner/sun8i-ss/Makefile +0 -1
@@ -1,4 +1,3 @@ obj-$(CONFIG_CRYPTO_DEV_SUN8I_SS) += sun8i-ss.o sun8i-ss-y += sun8i-ss-core.o sun8i-ss-cipher.o -sun8i-ss-$(CONFIG_CRYPTO_DEV_SUN8I_SS_PRNG) += sun8i-ss-prng.o sun8i-ss-$(CONFIG_CRYPTO_DEV_SUN8I_SS_HASH) += sun8i-ss-hash.o
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c +0 -39
@@ -11,7 +11,6 @@*/ #include <crypto/engine.h> -#include <crypto/internal/rng.h> #include <crypto/internal/skcipher.h> #include <linux/clk.h> #include <linux/delay.h>
@@ -283,25 +282,6 @@ static struct sun8i_ss_alg_template ss_a .do_one_request = sun8i_ss_handle_cipher_request, }, }, -#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_PRNG -{ - .type = CRYPTO_ALG_TYPE_RNG, - .alg.rng = { - .base = { - .cra_name = "stdrng", - .cra_driver_name = "sun8i-ss-prng", - .cra_priority = 300, - .cra_ctxsize = sizeof(struct sun8i_ss_rng_tfm_ctx), - .cra_module = THIS_MODULE, - .cra_init = sun8i_ss_prng_init, - .cra_exit = sun8i_ss_prng_exit, - }, - .generate = sun8i_ss_prng_generate, - .seed = sun8i_ss_prng_seed, - .seedsize =PRNG_SEED_SIZE , - } -}, -#endif#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_HASH { .type = CRYPTO_ALG_TYPE_AHASH, .ss_algo_id = SS_ID_HASH_MD5,
@@ -506,12 +486,6 @@ static int sun8i_ss_debugfs_show(structseq_printf (seq,"\tFallback due to SG numbers: %lu\n" , ss_algs[i].stat_fb_sgnum);break ; -case CRYPTO_ALG_TYPE_RNG : -seq_printf (seq,"%s %s reqs=%lu tsize=%lu\n" , - ss_algs[i].alg.rng.base.cra_driver_name, - ss_algs[i].alg.rng.base.cra_name, - ss_algs[i].stat_req, ss_algs[i].stat_bytes); -break ;case CRYPTO_ALG_TYPE_AHASH : seq_printf(seq, "%s %s reqs=%lu fallback=%lu\n", ss_algs[i].alg.hash.base.halg.base.cra_driver_name,
@@ -712,14 +686,6 @@ static int sun8i_ss_register_algs(structreturn err; }break ; -case CRYPTO_ALG_TYPE_RNG : - err =crypto_register_rng (&ss_algs[i].alg.rng); -if (err) { -dev_err (ss->dev,"Fail to register %s\n" , - ss_algs[i].alg.rng.base.cra_name); - ss_algs[i].ss =NULL ; - } -break ;case CRYPTO_ALG_TYPE_AHASH : id = ss_algs[i].ss_algo_id; ss_method = ss->variant->alg_hash[id];
@@ -761,11 +727,6 @@ static void sun8i_ss_unregister_algs(str ss_algs[i].alg.skcipher.base.base.cra_name);crypto_engine_unregister_skcipher (&ss_algs[i].alg.skcipher);break ; -case CRYPTO_ALG_TYPE_RNG : -dev_info (ss->dev,"Unregister %d %s\n" , i, - ss_algs[i].alg.rng.base.cra_name); -crypto_unregister_rng (&ss_algs[i].alg.rng); -break ;case CRYPTO_ALG_TYPE_AHASH :dev_info (ss->dev,"Unregister %d %s\n" , i, ss_algs[i].alg.hash.base.halg.base.cra_name);
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c deleted +0 -177
177 lines not on this page · raw message
drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h +0 -23
@@ -8,7 +8,6 @@#include <crypto/aes.h> #include <crypto/des.h> #include <crypto/engine.h> -#include <crypto/rng.h> #include <crypto/skcipher.h> #include <linux/atomic.h> #include <linux/debugfs.h>
@@ -27,7 +26,6 @@#define SS_ALG_DES (1 << 2)#define SS_ALG_3DES (2 << 2)#define SS_ALG_MD5 (3 << 2) -#define SS_ALG_PRNG (4 << 2)#define SS_ALG_SHA1 (6 << 2)#define SS_ALG_SHA224 (7 << 2)#define SS_ALG_SHA256 (8 << 2)
@@ -68,8 +66,6 @@#define SS_FLOW0 BIT(30)#define SS_FLOW1 BIT(31) -#define SS_PRNG_CONTINUE BIT(18) -#define MAX_SG 8#define MAXFLOW 2
@@ -79,9 +75,6 @@#define SS_DIE_ID_SHIFT 20#define SS_DIE_ID_MASK 0x07 -#define PRNG_DATA_SIZE (160 / 8) -#define PRNG_SEED_SIZE DIV_ROUND_UP(175, 8) -#define MAX_PAD_SIZE 4096/*
@@ -214,16 +207,6 @@ struct sun8i_cipher_tfm_ctx { };/* -* struct sun8i_ss_prng_ctx - context for PRNG TFM -* @seed: The seed to use -* @slen: The size of the seed -*/ -struct sun8i_ss_rng_tfm_ctx { -void *seed; -unsigned int slen; -}; - -/* * struct sun8i_ss_hash_tfm_ctx - context for an ahash TFM * @fallback_tfm: pointer to the fallback TFM * @ss: pointer to the private data of driver handling this TFM
@@ -272,7 +255,6 @@ struct sun8i_ss_alg_template {struct sun8i_ss_dev *ss;union {struct skcipher_engine_alg skcipher; -struct rng_alg rng;struct ahash_engine_alg hash; } alg;unsigned long stat_req;
@@ -298,11 +280,6 @@ int sun8i_ss_skencrypt(struct skcipher_rint sun8i_ss_get_engine_number (struct sun8i_ss_dev *ss);int sun8i_ss_run_task (struct sun8i_ss_dev *ss,struct sun8i_cipher_req_ctx *rctx,const char *name); -int sun8i_ss_prng_generate (struct crypto_rng *tfm,const u8 *src, -unsigned int slen,u8 *dst,unsigned int dlen); -int sun8i_ss_prng_seed (struct crypto_rng *tfm,const u8 *seed,unsigned int slen); -int sun8i_ss_prng_init (struct crypto_tfm *tfm); -void sun8i_ss_prng_exit (struct crypto_tfm *tfm);int sun8i_ss_hash_init_tfm (struct crypto_ahash *tfm);void sun8i_ss_hash_exit_tfm (struct crypto_ahash *tfm);
Greg Kroah-Hartman
maintainerPATCH 702/1193 crypto: sun8i-ce - Remove crypto_rng interface
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 011556f71d094da61379ae3672692cae2795304e upstream.
Since the crypto_rng interface for hardware PRNGs is unused and is redundant with hwrng and the actual Linux RNG, it's being phased out. Most drivers for it were already removed. Go ahead and remove the sun8i-ce support which is one of the only remaining ones.
Note that the sun8i-ce support for hwrng remains in place. That is the interface that actually matters.
As usual for crypto_rng, this driver was also buggy: its ->generate() function had a use-after-free vulnerability due to using wait_for_completion_interruptible_timeout() without handling shutting down the DMA operation if a signal is sent. There's no point in fixing this separately only to remove the code anyway, so this commit is marked with Fixes and Cc stable.
--- drivers/crypto/allwinner/Kconfig | 8 - drivers/crypto/allwinner/sun8i-ce/Makefile | 1 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 55 ------- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 159 ---------------------- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 29 ---- 5 files changed, 252 deletions(-) delete mode 100644 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
drivers/crypto/allwinner/Kconfig +0 -8
@@ -70,14 +70,6 @@ config CRYPTO_DEV_SUN8I_CE_HASH help Say y to enable support for hash algorithms. -config CRYPTO_DEV_SUN8I_CE_PRNG - bool "Support for Allwinner Crypto Engine PRNG" - depends on CRYPTO_DEV_SUN8I_CE - select CRYPTO_RNG - help - Select this option if you want to provide kernel-side support for - the Pseudo-Random Number Generator found in the Crypto Engine. - config CRYPTO_DEV_SUN8I_CE_TRNG bool "Support for Allwinner Crypto Engine TRNG" depends on CRYPTO_DEV_SUN8I_CE
drivers/crypto/allwinner/sun8i-ce/Makefile +0 -1
@@ -1,5 +1,4 @@ obj-$(CONFIG_CRYPTO_DEV_SUN8I_CE) += sun8i-ce.o sun8i-ce-y += sun8i-ce-core.o sun8i-ce-cipher.o sun8i-ce-$(CONFIG_CRYPTO_DEV_SUN8I_CE_HASH) += sun8i-ce-hash.o -sun8i-ce-$(CONFIG_CRYPTO_DEV_SUN8I_CE_PRNG) += sun8i-ce-prng.o sun8i-ce-$(CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG) += sun8i-ce-trng.o
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +0 -55
127 lines not on this page · raw message
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c deleted +0 -159
159 lines not on this page · raw message
drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +0 -29
@@ -15,7 +15,6 @@#include <linux/hw_random.h> #include <crypto/internal/hash.h> #include <crypto/md5.h> -#include <crypto/rng.h> #include <crypto/sha1.h> #include <crypto/sha2.h>
@@ -58,9 +57,7 @@#define CE_ALG_SHA384 20#define CE_ALG_SHA512 21#define CE_ALG_TRNG 48 -#define CE_ALG_PRNG 49#define CE_ALG_TRNG_V2 0x1c -#define CE_ALG_PRNG_V2 0x1d/* Used in ce_variant */ #define CE_ID_NOTSUPP 0xFF
@@ -96,10 +93,6 @@#define ESR_H6 4#define ESR_D1 5 -#define PRNG_DATA_SIZE (160 / 8) -#define PRNG_SEED_SIZE DIV_ROUND_UP(175, 8) -#define PRNG_LD BIT(17) -#define CE_DIE_ID_SHIFT 16#define CE_DIE_ID_MASK 0x07
@@ -133,13 +126,10 @@ struct ce_clock {* bytes or words * @hash_t_dlen_in_bytes: Does the request size for hash is in * bits or words -* @prng_t_dlen_in_bytes: Does the request size for PRNG is in -* bytes or words * @trng_t_dlen_in_bytes: Does the request size for TRNG is in * bytes or words * @ce_clks: list of clocks needed by this variant * @esr: The type of error register -* @prng: The CE_ALG_XXX value for the PRNG * @trng: The CE_ALG_XXX value for the TRNG */ struct ce_variant {
@@ -148,11 +138,9 @@ struct ce_variant {u32 op_mode[CE_ID_OP_MAX ];bool cipher_t_dlen_in_bytes;bool hash_t_dlen_in_bits; -bool prng_t_dlen_in_bytes;bool trng_t_dlen_in_bytes;struct ce_clock ce_clks[CE_MAX_CLOCKS ];int esr; -unsigned char prng;unsigned char trng; };
@@ -298,16 +286,6 @@ struct sun8i_ce_hash_reqctx { };/* -* struct sun8i_ce_prng_ctx - context for PRNG TFM -* @seed: The seed to use -* @slen: The size of the seed -*/ -struct sun8i_ce_rng_tfm_ctx { -void *seed; -unsigned int slen; -}; - -/* * struct sun8i_ce_alg_template - crypto_alg template * @type: the CRYPTO_ALG_TYPE for this template * @ce_algo_id: the CE_ID for this template
@@ -327,7 +305,6 @@ struct sun8i_ce_alg_template {union {struct skcipher_engine_alg skcipher;struct ahash_engine_alg hash; -struct rng_alg rng; } alg;unsigned long stat_req;unsigned long stat_fb;
@@ -368,11 +345,5 @@ int sun8i_ce_hash_finup(struct ahash_reqint sun8i_ce_hash_digest (struct ahash_request *areq);int sun8i_ce_hash_run (struct crypto_engine *engine,void *breq); -int sun8i_ce_prng_generate (struct crypto_rng *tfm,const u8 *src, -unsigned int slen,u8 *dst,unsigned int dlen); -int sun8i_ce_prng_seed (struct crypto_rng *tfm,const u8 *seed,unsigned int slen); -void sun8i_ce_prng_exit (struct crypto_tfm *tfm); -int sun8i_ce_prng_init (struct crypto_tfm *tfm); -int sun8i_ce_hwrng_register (struct sun8i_ce_dev *ce);void sun8i_ce_hwrng_unregister (struct sun8i_ce_dev *ce);
Greg Kroah-Hartman
maintainerPATCH 703/1193 netfilter: nft_set_pipapo_avx2: add missing vzeroupper
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 55dd20f0f4b1be5c9c8a0275d8d763c86563eac2 upstream.
Since pipapo_get_avx2() uses YMM registers, execute vzeroupper before returning from it. This is needed to avoid degrading the performance of any later SSE code that may happen to be executed.
--- net/netfilter/nft_set_pipapo_avx2.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nft_set_pipapo_avx2.c +1 -0
@@ -1261,6 +1261,7 @@ next_match: out:if (i %2 ) scratch->map_index = !map_index; + asmvolatile ("vzeroupper" );kernel_fpu_end ();local_bh_enable ();
Greg Kroah-Hartman
maintainerPATCH 704/1193 workqueue: Update documentation as per system_percpu_wq naming
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mallesh Koujalagi <[email protected]>
commit 4a91a33f15c634fb3477d122bdf1eef098d77ee3 upstream.
Update documentation to use "per-CPU workqueue" instead of "global workqueue" to match the system_wq to system_percpu_wq rename. The workqueue behavior remains unchanged; this just aligns terminology with the clearer naming.
--- include/linux/workqueue.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
include/linux/workqueue.h +8 -8
@@ -610,14 +610,14 @@ static inline bool schedule_work_on(int }/** -* schedule_work - put work task in global workqueue +* schedule_work - put work task in per-CPU workqueue * @work: job to be done * -* Returns %false if @work was already on the kernel-global workqueue and +* Returns %false if @work was already on the system per-CPU workqueue and * %true otherwise. * -* This puts a job in the kernel-global workqueue if it was not already -* queued and leaves it in the same position on the kernel-global +* This puts a job in the system per-CPU workqueue if it was not already +* queued and leaves it in the same position on the system per-CPU * workqueue otherwise. * * Shares the same memory-ordering properties of queue_work(), cf. the
@@ -668,12 +668,12 @@ extern void __warn_flushing_systemwide_w })/** -* schedule_delayed_work_on - queue work in global workqueue on CPU after delay +* schedule_delayed_work_on - queue work in per-CPU workqueue on CPU after delay * @cpu: cpu to use * @dwork: job to be done * @delay: number of jiffies to wait * -* After waiting for a given time this puts a job in the kernel-global +* After waiting for a given time this puts a job in the system per-CPU * workqueue on the specified CPU. */ static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
@@ -683,11 +683,11 @@ static inline bool schedule_delayed_work }/** -* schedule_delayed_work - put work task in global workqueue after delay +* schedule_delayed_work - put work task in per-CPU workqueue after delay * @dwork: job to be done * @delay: number of jiffies to wait or 0 for immediate execution * -* After waiting for a given time this puts a job in the kernel-global +* After waiting for a given time this puts a job in the system per-CPU * workqueue. */ static inline bool schedule_delayed_work(struct delayed_work *dwork,
Greg Kroah-Hartman
maintainerPATCH 705/1193 Bluetooth: btintel: Fix compiler warning for multi_v7_defconfig config
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiran K <[email protected]>
commit 36b1c9c35452d043ce2239a65393b3e7ee7101c5 upstream.
Fix the following compiler warning reported for ARCH=arm multi_v7_defconfig.
In file included from drivers/bluetooth/hci_ldisc.c:34:drivers/bluetooth/btintel.h:373:13: warning: 'btintel_hw_error' defined but not used [-Wunused-function]
373 | static void btintel_hw_error(struct hci_dev *hdev, u8 code)
| ^~~~~~~~~~~~~~~~
--- drivers/bluetooth/btintel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bluetooth/btintel.h +1 -1
@@ -364,7 +364,7 @@ static inline int btintel_shutdown_combi return -ENODEV; } -static void btintel_hw_error (struct hci_dev *hdev,u8 code) +static inline void btintel_hw_error (struct hci_dev *hdev,u8 code) { }#endif
Greg Kroah-Hartman
maintainerPATCH 706/1193 mptcp: fix bad accounting in __mptcp_subflow_push_pending()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit f3ef03357396d4b147d8e76c75fb612c2f264ffc upstream.
If __subflow_push_pending() errors out we should avoid updating the copied byte counters, to avoid mismatch push call later on.
--- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +2 -1
@@ -1748,7 +1748,8 @@ static void __mptcp_subflow_push_pending ret =__subflow_push_pending (sk, ssk, &info);if (ret <=0 ) keep_pushing = false; - copied += ret; +else + copied += ret; }mptcp_for_each_subflow (msk, subflow) {
Greg Kroah-Hartman
maintainerPATCH 707/1193 mptcp: avoid unneeded actions on subflow reset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit 2b0f561f21b27c40c91ea4975268a06092bd7e9c upstream.
Once in a blue moon, the mptcp receive path can recursively call mptcp_data_ready() via state change under unlucky error conditions, and then try to hold the data lock again.
Break the recursion loop explicitly checking for the exceptional condition.
Add a new flag instead of using an existing one like 'closing', to exit early in subflow_state_change(), and explicitly flush the RX queue at reset time.
This avoids unneeded processing to check for available data -- calling get_mapping_status() and more on a dying subflow -- but also in error reporting and worker scheduling.
Note that we must consume the currently peeked skb before invoking mptcp_dss_corruption to avoid consuming it again after the eventual reset has freed it.
[ Note: conflict in protocol.c, because commit e0ca4057e0ec ("mptcp:
micro-optimize __mptcp_move_skb()") is not in this version, and is part of a consequent rx path refactor. The conflict is in the context, and is easy to resolve, "done = true" can be moved along without consequences.
Also a conflict in protocol.h, because __unused is at a different number. Decrement the one from this version and add the new flag above.]
--- net/mptcp/protocol.c | 6 +++--- net/mptcp/protocol.h | 3 ++- net/mptcp/subflow.c | 11 +++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +3 -3
@@ -747,13 +747,13 @@ static bool __mptcp_move_skbs_from_subflmptcp_dss_corruption (msk, ssk); } }else { +sk_eat_skb (ssk, skb); + done = true; +if (unlikely (!fin)) {DEBUG_NET_WARN_ON_ONCE (1 );mptcp_dss_corruption (msk, ssk); } - -sk_eat_skb (ssk, skb); - done = true; }WRITE_ONCE (tp->copied_seq, seq);
net/mptcp/protocol.h +2 -1
@@ -510,7 +510,8 @@ struct mptcp_subflow_context { valid_csum_seen : 1, /* at least one csum validated */ is_mptfo : 1, /* subflow is doing TFO */ close_event_done : 1, /* has done the post-closed part */ - __unused : 8; + resetting : 1, /* subflow is resetting */ + __unused : 7;bool data_avail;bool scheduled;bool pm_listener;/* a listener managed by the kernel PM? */
net/mptcp/subflow.c +11 -0
@@ -421,6 +421,10 @@ void mptcp_subflow_reset(struct sock *ss/* must hold: tcp_done() could drop last reference on parent */ sock_hold (sk); + subflow->resetting =1 ; + +/* No need to delay the actual close for to-be discarded data. */ +__skb_queue_purge (&ssk->sk_receive_queue);tcp_send_active_reset (ssk,GFP_ATOMIC );tcp_done (ssk);if (!test_and_set_bit (MPTCP_WORK_CLOSE_SUBFLOW , &mptcp_sk (sk)->flags))
@@ -1802,6 +1806,13 @@ static void subflow_state_change(struct__subflow_state_change (sk); +/* Rx queue processing is unneeded, error reporting will take place at +* __mptcp_close_ssk() time and subflow reset can't happen in case of +* fallback: subflow_sched_work_if_closed() would be a no-op. +*/ +if (subflow->resetting) +return ; +/* as recvmsg() does not acquire the subflow socket for ssk selection * a fin packet carrying a DSS can be unnoticed if we don't trigger * the data available machinery here.
Greg Kroah-Hartman
maintainerPATCH 708/1193 mptcp: close race between scheduler and state change
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit 42064de57fb83231fcc89663a94885f228a1ee53 upstream.
The mptcp scheduler may race with subflow sockets state change: data transmission on the selected socket may fail and a later release could try to use mss_now reset to 0 for a divide operation.
Address the issue by explicitly checking for the critical scenario.
--- net/mptcp/protocol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +3 -1
@@ -1562,7 +1562,9 @@ struct sock *mptcp_subflow_get_send(strustatic void mptcp_push_release (struct sock *ssk,struct mptcp_sendmsg_info *info) { -tcp_push (ssk,0 , info->mss_now,tcp_sk (ssk)->nonagle, info->size_goal); +if (info->mss_now) +tcp_push (ssk,0 , info->mss_now,tcp_sk (ssk)->nonagle, + info->size_goal);release_sock (ssk); }
Greg Kroah-Hartman
maintainerPATCH 709/1193 Revert "hwmon: (emc1403) Drop hysteresis for low limit temperature"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 9281eb1e4ea31281c0230a5c74aacfc014241d10.
--- Documentation/hwmon/emc1403.rst | 8 ++++---- drivers/hwmon/emc1403.c | 27 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-)
Documentation/hwmon/emc1403.rst +4 -4
@@ -71,10 +71,10 @@ and EMC14x8 support eight sensors (one internal, seven external). The chips implement three limits for each sensor: low (tempX_min), high (tempX_max) and critical (tempX_crit.) The chips also implement an -hysteresis mechanism which applies to high and critical limits. The relative -difference is stored in a single register on the chip, which means that the -relative difference between the limit and its hysteresis is always the same -for high and critical limits. +hysteresis mechanism which applies to all limits. The relative difference +is stored in a single register on the chip, which means that the relative +difference between the limit and its hysteresis is always the same for +all three limits. This implementation detail implies the following:
drivers/hwmon/emc1403.c +16 -11
@@ -304,9 +304,10 @@ static int emc1403_get_hyst(struct thermal_data *data, int channel, ret =regmap_read (data->regmap,0x21 , &hyst);if (ret <0 )return ret; - - *val = limit - hyst *1000 ; - +if (map == temp_min) + *val = limit + hyst *1000 ; +else + *val = limit - hyst *1000 ;return 0 ; }
@@ -322,6 +323,9 @@ static int emc1403_temp_read(struct thermal_data *data, u32 attr, int channel, lcase hwmon_temp_input: ret =emc1403_get_temp (data, channel, ema1403_temp_map[attr], val);break ; +case hwmon_temp_min_hyst: + ret =emc1403_get_hyst (data, channel, temp_min, val); +break ;case hwmon_temp_max_hyst: ret =emc1403_get_hyst (data, channel, temp_max, val);break ;
@@ -490,6 +494,7 @@ static umode_t emc1403_temp_is_visible(const void *_data, u32 attr, int channel)case hwmon_temp_max_alarm:case hwmon_temp_crit_alarm:case hwmon_temp_fault: +case hwmon_temp_min_hyst:case hwmon_temp_max_hyst:return 0444 ;case hwmon_temp_min:
@@ -519,35 +524,35 @@ static umode_t emc1403_is_visible(const void *data, enum hwmon_sensor_types typestatic const struct hwmon_channel_info *const emc1403_info[] = {HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ,HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT |HWMON_T_MAX_HYST | +HWMON_T_CRIT |HWMON_T_MIN_HYST |HWMON_T_MAX_HYST |HWMON_T_CRIT_HYST |HWMON_T_MIN_ALARM |HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_FAULT ),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/1193 Revert "hwmon: (emc1403) Rely on subsystem locking"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit e43ba8be636ab54bcf3f90a0ccd36e2bc3df3274.
--- drivers/hwmon/emc1403.c | 46 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-)
drivers/hwmon/emc1403.c +36 -10
@@ -17,6 +17,7 @@#include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/sysfs.h> +#include <linux/mutex.h> #include <linux/regmap.h> #define THERMAL_PID_REG 0xfd
@@ -28,6 +29,7 @@ enum emc1403_chip { emc1402, emc1403, emc1404, emc1428 };struct thermal_data {enum emc1403_chip chip;struct regmap *regmap; +struct mutex mutex; };static ssize_t power_state_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -265,8 +267,8 @@ static s8 emc1403_temp_regs_low[][4] = { }, }; -static int emc1403_get_temp (struct thermal_data *data,int channel, -enum emc1403_reg_map map,long *val) +static int __emc1403_get_temp (struct thermal_data *data,int channel, +enum emc1403_reg_map map,long *val) {unsigned int regvalh;unsigned int regvall =0 ;
@@ -292,23 +294,38 @@ static int emc1403_get_temp(struct thermal_data *data, int channel,return 0 ; } +static int emc1403_get_temp (struct thermal_data *data,int channel, +enum emc1403_reg_map map,long *val) +{ +int ret; + +mutex_lock (&data->mutex); + ret =__emc1403_get_temp (data, channel, map, val); +mutex_unlock (&data->mutex); + +return ret; +} +static int emc1403_get_hyst (struct thermal_data *data,int channel,enum emc1403_reg_map map,long *val) {int hyst, ret;long limit; - ret =emc1403_get_temp (data, channel, map, &limit); +mutex_lock (&data->mutex); + ret =__emc1403_get_temp (data, channel, map, &limit);if (ret <0 ) -return ret; + goto unlock; ret =regmap_read (data->regmap,0x21 , &hyst);if (ret <0 ) -return ret; + goto unlock;if (map == temp_min) *val = limit + hyst *1000 ;else *val = limit - hyst *1000 ; -return 0 ; +unlock: +mutex_unlock (&data->mutex); +return ret; }static int emc1403_temp_read (struct thermal_data *data,u32 attr,int channel,long *val)
@@ -406,16 +423,20 @@ static int emc1403_set_hyst(struct thermal_data *data, long val)else val =clamp_val (val,0 ,255000 ); - ret =emc1403_get_temp (data,0 , temp_crit, &limit); +mutex_lock (&data->mutex); + ret =__emc1403_get_temp (data,0 , temp_crit, &limit);if (ret <0 ) -return ret; + goto unlock; hyst = limit - val;if (data->chip == emc1428) hyst =clamp_val (DIV_ROUND_CLOSEST (hyst,1000 ),0 ,127 );else hyst =clamp_val (DIV_ROUND_CLOSEST (hyst,1000 ),0 ,255 ); -return regmap_write (data->regmap,0x21 , hyst); + ret =regmap_write (data->regmap,0x21 , hyst); +unlock: +mutex_unlock (&data->mutex); +return ret; } static int emc1403_set_temp(struct thermal_data *data, int channel,
@@ -429,6 +450,7 @@ static int emc1403_set_temp(struct thermal_data *data, int channel, regh = emc1403_temp_regs[channel][map]; regl = emc1403_temp_regs_low[channel][map]; +mutex_lock (&data->mutex);if (regl >=0 ) {if (data->chip == emc1428) val =clamp_val (val,-128000 ,127875 );
@@ -437,7 +459,7 @@ static int emc1403_set_temp(struct thermal_data *data, int channel, regval =DIV_ROUND_CLOSEST (val,125 ); ret =regmap_write (data->regmap, regh, (regval >>3 ) &0xff );if (ret <0 ) -return ret; + goto unlock; ret =regmap_write (data->regmap, regl, (regval &0x07 ) <<5 ); }else {if (data->chip == emc1428)
@@ -447,6 +469,8 @@ static int emc1403_set_temp(struct thermal_data *data, int channel, regval =DIV_ROUND_CLOSEST (val,1000 ); ret =regmap_write (data->regmap, regh, regval); } +unlock: +mutex_unlock (&data->mutex);return ret; }
@@ -604,6 +628,8 @@ static int emc1403_probe(struct i2c_client *client)if (IS_ERR (data->regmap))return PTR_ERR (data->regmap); +mutex_init (&data->mutex); + hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, client->name, data, &emc1403_chip_info,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/1193 selftests/landlock: Add tests for access through disconnected paths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tingmao Wang <[email protected]>
[ Upstream commit a18ee3f31fd714173a62515d049d77e76ab55649 ]
This adds tests for the edge case discussed in [1], with specific ones for rename and link operations when the operands are through disconnected paths, as that go through a separate code path in Landlock.
This has resulted in a warning, due to collect_domain_accesses() not expecting to reach a different root from path->mnt:
# RUN layout1_bind.path_disconnected ...
# OK layout1_bind.path_disconnected
ok 96 layout1_bind.path_disconnected
# RUN layout1_bind.path_disconnected_rename ...
[..] ------------[ cut here ]------------
[..] WARNING: CPU: 3 PID: 385 at security/landlock/fs.c:1065 collect_domain_accesses
[..] ...
[..] RIP: 0010:collect_domain_accesses (security/landlock/fs.c:1065 (discriminator 2) security/landlock/fs.c:1031 (discriminator 2)) [..] current_check_refer_path (security/landlock/fs.c:1205)
[..] ...
[..] hook_path_rename (security/landlock/fs.c:1526)
[..] security_path_rename (security/security.c:2026 (discriminator 1))
[..] do_renameat2 (fs/namei.c:5264)
# OK layout1_bind.path_disconnected_rename
ok 97 layout1_bind.path_disconnected_rename
Move the const char definitions a bit above so that we can use the path for s4d1 in cleanup code.
--- tools/testing/selftests/landlock/fs_test.c | 423 ++++++++++++++++++++- 1 file changed, 415 insertions(+), 8 deletions(-)
tools/testing/selftests/landlock/fs_test.c +415 -8
@@ -3738,6 +3738,18 @@ TEST(memfd_ftruncate)FIXTURE (layout1_bind) {};/* clang-format on */ +static const char bind_dir_s1d3[] =TMP_DIR "/s2d1/s2d2/s1d3" ; +static const char bind_file1_s1d3[] =TMP_DIR "/s2d1/s2d2/s1d3/f1" ; + +/* Move targets for disconnected path tests. */ +static const char dir_s4d1[] =TMP_DIR "/s4d1" ; +static const char file1_s4d1[] =TMP_DIR "/s4d1/f1" ; +static const char file2_s4d1[] =TMP_DIR "/s4d1/f2" ; +static const char dir_s4d2[] =TMP_DIR "/s4d1/s4d2" ; +static const char file1_s4d2[] =TMP_DIR "/s4d1/s4d2/f1" ; +static const char file1_name[] ="f1" ; +static const char file2_name[] ="f2" ; +FIXTURE_SETUP (layout1_bind) {prepare_layout (_metadata);
@@ -3755,14 +3767,14 @@ FIXTURE_TEARDOWN(layout1_bind)EXPECT_EQ (0 ,umount (dir_s2d2));clear_cap (_metadata,CAP_SYS_ADMIN ); +remove_path (file1_s4d1); +remove_path (file2_s4d1); +remove_layout1 (_metadata);cleanup_layout (_metadata); } -static const char bind_dir_s1d3[] =TMP_DIR "/s2d1/s2d2/s1d3" ; -static const char bind_file1_s1d3[] =TMP_DIR "/s2d1/s2d2/s1d3/f1" ; -/* * layout1_bind hierarchy: *
@@ -3773,20 +3785,25 @@ static const char bind_file1_s1d3[] = TMP_DIR "/s2d1/s2d2/s1d3/f1";* │ └── s1d2 * │ ├── f1 * │ ├── f2 -* │ └── s1d3 +* │ └── s1d3 [disconnected by path_disconnected] * │ ├── f1 * │ └── f2 * ├── s2d1 * │ ├── f1 -* │ └── s2d2 +* │ └── s2d2 [bind mount from s1d2] * │ ├── f1 * │ ├── f2 * │ └── s1d3 * │ ├── f1 * │ └── f2 -* └── s3d1 -* └── s3d2 -* └── s3d3 +* ├── s3d1 +* │ └── s3d2 +* │ └── s3d3 +* └── s4d1 [renamed from s1d3 by path_disconnected] +* ├── f1 +* ├── f2 +* └── s4d2 +* └── f1 */ TEST_F_FORK (layout1_bind, no_restriction)
@@ -3985,6 +4002,396 @@ TEST_F_FORK(layout1_bind, reparent_cross_mount)ASSERT_EQ (0 ,rename (bind_file1_s1d3, file1_s2d2)); } +/* +* Make sure access to file through a disconnected path works as expected. +* This test moves s1d3 to s4d1. +*/ +TEST_F_FORK(layout1_bind, path_disconnected) +{ +const struct rule layer1_allow_all[] = { + { + .path =TMP_DIR , + .access =ACCESS_ALL , + }, + {}, + }; +const struct rule layer2_allow_just_f1[] = { + { + .path = file1_s1d3, + .access =LANDLOCK_ACCESS_FS_READ_FILE , + }, + {}, + }; +const struct rule layer3_only_s1d2[] = { + { + .path = dir_s1d2, + .access =LANDLOCK_ACCESS_FS_READ_FILE , + }, + {}, + }; + +/* Landlock should not deny access just because it is disconnected. */ +int ruleset_fd_l1 = +create_ruleset (_metadata,ACCESS_ALL , layer1_allow_all); + +/* Creates the new ruleset now before we move the dir containing the file. */ +int ruleset_fd_l2 = +create_ruleset (_metadata,ACCESS_RW , layer2_allow_just_f1); +int ruleset_fd_l3 = +create_ruleset (_metadata,ACCESS_RW , layer3_only_s1d2); +int bind_s1d3_fd; + +ASSERT_LE (0 , ruleset_fd_l1); +ASSERT_LE (0 , ruleset_fd_l2); +ASSERT_LE (0 , ruleset_fd_l3); + +enforce_ruleset (_metadata, ruleset_fd_l1); +EXPECT_EQ (0 ,close (ruleset_fd_l1)); + + bind_s1d3_fd =open (bind_dir_s1d3,O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , bind_s1d3_fd); + +/* Tests access is possible before we move. */ +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file2_name,O_RDONLY )); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd,".." ,O_RDONLY |O_DIRECTORY )); + +/* Makes it disconnected. */ + ASSERT_EQ(0, rename(dir_s1d3, dir_s4d1)) + { +TH_LOG ("Failed to rename %s to %s: %s" , dir_s1d3, dir_s4d1, +strerror (errno)); + } + +/* Tests that access is still possible. */ +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file2_name,O_RDONLY )); + +/* +* Tests that ".." is not possible (not because of Landlock, but just +* because it's disconnected). +*/ +EXPECT_EQ (ENOENT , +test_open_rel (bind_s1d3_fd,".." ,O_RDONLY |O_DIRECTORY )); + +/* This should still work with a narrower rule. */ +enforce_ruleset (_metadata, ruleset_fd_l2); +EXPECT_EQ (0 ,close (ruleset_fd_l2)); + +EXPECT_EQ (0 ,test_open (file1_s4d1,O_RDONLY )); +/* +* Accessing a file through a disconnected file descriptor can still be +* allowed by a rule tied to this file, even if it is no longer visible in +* its mount point. +*/ +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (EACCES ,test_open_rel (bind_s1d3_fd, file2_name,O_RDONLY )); + +enforce_ruleset (_metadata, ruleset_fd_l3); +EXPECT_EQ (0 ,close (ruleset_fd_l3)); + +EXPECT_EQ (EACCES ,test_open (file1_s4d1,O_RDONLY )); +/* +* Accessing a file through a disconnected file descriptor can still be +* allowed by a rule tied to the original mount point, even if it is no +* longer visible in its mount point. +*/ +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (EACCES ,test_open_rel (bind_s1d3_fd, file2_name,O_RDONLY )); +} + +/* +* Test that renameat with disconnected paths works under Landlock. This test +* moves s1d3 to s4d2, so that we can have a rule allowing refers on the move +* target's immediate parent. +*/ +TEST_F_FORK(layout1_bind, path_disconnected_rename) +{ +const struct rule layer1[] = { + { + .path = dir_s1d2, + .access =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_MAKE_DIR | +LANDLOCK_ACCESS_FS_REMOVE_DIR | +LANDLOCK_ACCESS_FS_MAKE_REG | +LANDLOCK_ACCESS_FS_REMOVE_FILE | +LANDLOCK_ACCESS_FS_READ_FILE , + }, + { + .path = dir_s4d1, + .access =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_MAKE_DIR | +LANDLOCK_ACCESS_FS_REMOVE_DIR | +LANDLOCK_ACCESS_FS_MAKE_REG | +LANDLOCK_ACCESS_FS_REMOVE_FILE | +LANDLOCK_ACCESS_FS_READ_FILE , + }, + {} + }; + +/* This layer only handles LANDLOCK_ACCESS_FS_READ_FILE. */ +const struct rule layer2_only_s1d2[] = { + { + .path = dir_s1d2, + .access =LANDLOCK_ACCESS_FS_READ_FILE , + }, + {}, + }; +int ruleset_fd_l1, ruleset_fd_l2; +pid_t child_pid; +int bind_s1d3_fd, status; + + ASSERT_EQ(0, mkdir(dir_s4d1, 0755)) + { +TH_LOG ("Failed to create %s: %s" , dir_s4d1,strerror (errno)); + } + ruleset_fd_l1 =create_ruleset (_metadata,ACCESS_ALL , layer1); + ruleset_fd_l2 =create_ruleset (_metadata,LANDLOCK_ACCESS_FS_READ_FILE , + layer2_only_s1d2); +ASSERT_LE (0 , ruleset_fd_l1); +ASSERT_LE (0 , ruleset_fd_l2); + +enforce_ruleset (_metadata, ruleset_fd_l1); +EXPECT_EQ (0 ,close (ruleset_fd_l1)); + + bind_s1d3_fd =open (bind_dir_s1d3,O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , bind_s1d3_fd); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); + +/* Tests ENOENT priority over EACCES for disconnected directory. */ +EXPECT_EQ (EACCES ,test_open_rel (bind_s1d3_fd,".." ,O_DIRECTORY )); + ASSERT_EQ(0, rename(dir_s1d3, dir_s4d2)) + { +TH_LOG ("Failed to rename %s to %s: %s" , dir_s1d3, dir_s4d2, +strerror (errno)); + } +EXPECT_EQ (ENOENT ,test_open_rel (bind_s1d3_fd,".." ,O_DIRECTORY )); + +/* +* The file is no longer under s1d2 but we should still be able to access it +* with layer 2 because its mount point is evaluated as the first valid +* directory because it was initially a parent. Do a fork to test this so +* we don't prevent ourselves from renaming it back later. +*/ + child_pid =fork (); +ASSERT_LE (0 , child_pid); +if (child_pid ==0 ) { +enforce_ruleset (_metadata, ruleset_fd_l2); +EXPECT_EQ (0 ,close (ruleset_fd_l2)); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (EACCES ,test_open (file1_s4d2,O_RDONLY )); + +/* +* Tests that access widening checks indeed prevents us from renaming it +* back. +*/ +EXPECT_EQ (-1 ,rename (dir_s4d2, dir_s1d3)); +EXPECT_EQ (EXDEV , errno); + +/* +* Including through the now disconnected fd (but it should return +* EXDEV). +*/ +EXPECT_EQ (-1 ,renameat (bind_s1d3_fd, file1_name,AT_FDCWD , + file1_s2d2)); +EXPECT_EQ (EXDEV , errno); +_exit (_metadata->passed ?EXIT_SUCCESS :EXIT_FAILURE ); +return ; + } + +EXPECT_EQ (child_pid,waitpid (child_pid, &status,0 )); +EXPECT_EQ (1 ,WIFEXITED (status)); +EXPECT_EQ (EXIT_SUCCESS ,WEXITSTATUS (status)); + + ASSERT_EQ(0, rename(dir_s4d2, dir_s1d3)) + { +TH_LOG ("Failed to rename %s back to %s: %s" , dir_s4d1, dir_s1d3, +strerror (errno)); + } + +/* Now checks that we can access it under l2. */ + child_pid =fork (); +ASSERT_LE (0 , child_pid); +if (child_pid ==0 ) { +enforce_ruleset (_metadata, ruleset_fd_l2); +EXPECT_EQ (0 ,close (ruleset_fd_l2)); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (0 ,test_open (file1_s1d3,O_RDONLY )); +_exit (_metadata->passed ?EXIT_SUCCESS :EXIT_FAILURE ); +return ; + } + +EXPECT_EQ (child_pid,waitpid (child_pid, &status,0 )); +EXPECT_EQ (1 ,WIFEXITED (status)); +EXPECT_EQ (EXIT_SUCCESS ,WEXITSTATUS (status)); + +/* +* Also test that we can rename via a disconnected path. We move the +* dir back to the disconnected place first, then we rename file1 to +* file2 through our dir fd. +*/ + ASSERT_EQ(0, rename(dir_s1d3, dir_s4d2)) + { +TH_LOG ("Failed to rename %s to %s: %s" , dir_s1d3, dir_s4d2, +strerror (errno)); + } +ASSERT_EQ (0 , + renameat(bind_s1d3_fd, file1_name, bind_s1d3_fd, file2_name)) + { +TH_LOG ("Failed to rename %s to %s within disconnected %s: %s" , + file1_name, file2_name, bind_dir_s1d3,strerror (errno)); + } +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file2_name,O_RDONLY )); + ASSERT_EQ(0, renameat(bind_s1d3_fd, file2_name, AT_FDCWD, file1_s2d2)) + { +TH_LOG ("Failed to rename %s to %s through disconnected %s: %s" , + file2_name, file1_s2d2, bind_dir_s1d3,strerror (errno)); + } +EXPECT_EQ (0 ,test_open (file1_s2d2,O_RDONLY )); +EXPECT_EQ (0 ,test_open (file1_s1d2,O_RDONLY )); + +/* Move it back using the disconnected path as the target. */ + ASSERT_EQ(0, renameat(AT_FDCWD, file1_s2d2, bind_s1d3_fd, file1_name)) + { +TH_LOG ("Failed to rename %s to %s through disconnected %s: %s" , + file1_s1d2, file1_name, bind_dir_s1d3,strerror (errno)); + } + +/* Now make it connected again. */ + ASSERT_EQ(0, rename(dir_s4d2, dir_s1d3)) + { +TH_LOG ("Failed to rename %s back to %s: %s" , dir_s4d2, dir_s1d3, +strerror (errno)); + } + +/* Checks again that we can access it under l2. */ +enforce_ruleset (_metadata, ruleset_fd_l2); +EXPECT_EQ (0 ,close (ruleset_fd_l2)); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); +EXPECT_EQ (0 ,test_open (file1_s1d3,O_RDONLY )); +} + +/* +* Test that linkat(2) with disconnected paths works under Landlock. This +* test moves s1d3 to s4d1. +*/ +TEST_F_FORK(layout1_bind, path_disconnected_link) +{ +/* Ruleset to be applied after renaming s1d3 to s4d1. */ +const struct rule layer1[] = { + { + .path = dir_s4d1, + .access =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_MAKE_REG | +LANDLOCK_ACCESS_FS_REMOVE_FILE , + }, + { + .path = dir_s2d2, + .access =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_MAKE_REG | +LANDLOCK_ACCESS_FS_REMOVE_FILE , + }, + {} + }; +int ruleset_fd, bind_s1d3_fd; + +/* Removes unneeded files created by layout1, otherwise it will EEXIST. */ +ASSERT_EQ (0 ,unlink (file1_s1d2)); +ASSERT_EQ (0 ,unlink (file2_s1d3)); + + bind_s1d3_fd =open (bind_dir_s1d3,O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , bind_s1d3_fd); +EXPECT_EQ (0 ,test_open_rel (bind_s1d3_fd, file1_name,O_RDONLY )); + +/* Disconnects bind_s1d3_fd. */ + ASSERT_EQ(0, rename(dir_s1d3, dir_s4d1)) + { +TH_LOG ("Failed to rename %s to %s: %s" , dir_s1d3, dir_s4d1, +strerror (errno)); + } + +/* Need this later to test different parent link. */ + ASSERT_EQ(0, mkdir(dir_s4d2, 0755)) + { +TH_LOG ("Failed to create %s: %s" , dir_s4d2,strerror (errno)); + } + + ruleset_fd =create_ruleset (_metadata,ACCESS_ALL , layer1); +ASSERT_LE (0 , ruleset_fd); +enforce_ruleset (_metadata, ruleset_fd); +EXPECT_EQ (0 ,close (ruleset_fd)); + +/* From disconnected to connected. */ + ASSERT_EQ(0, linkat(bind_s1d3_fd, file1_name, AT_FDCWD, file1_s2d2, 0)) + { +TH_LOG ("Failed to link %s to %s via disconnected %s: %s" , + file1_name, file1_s2d2, bind_dir_s1d3,strerror (errno)); + } + +/* Tests that we can access via the new link... */ + EXPECT_EQ(0, test_open(file1_s2d2, O_RDONLY)) + { +TH_LOG ("Failed to open newly linked %s: %s" , file1_s2d2, +strerror (errno)); + } + +/* ...as well as the old one. */ + EXPECT_EQ(0, test_open(file1_s4d1, O_RDONLY)) + { +TH_LOG ("Failed to open original %s: %s" , file1_s4d1, +strerror (errno)); + } + +/* From connected to disconnected. */ +ASSERT_EQ (0 ,unlink (file1_s4d1)); + ASSERT_EQ(0, linkat(AT_FDCWD, file1_s2d2, bind_s1d3_fd, file2_name, 0)) + { +TH_LOG ("Failed to link %s to %s via disconnected %s: %s" , + file1_s2d2, file2_name, bind_dir_s1d3,strerror (errno)); + } +EXPECT_EQ (0 ,test_open (file2_s4d1,O_RDONLY )); +ASSERT_EQ (0 ,unlink (file1_s2d2)); + +/* From disconnected to disconnected (same parent). */ +ASSERT_EQ (0 , + linkat(bind_s1d3_fd, file2_name, bind_s1d3_fd, file1_name, 0)) + { +TH_LOG ("Failed to link %s to %s within disconnected %s: %s" , + file2_name, file1_name, bind_dir_s1d3,strerror (errno)); + } + EXPECT_EQ(0, test_open(file1_s4d1, O_RDONLY)) + { +TH_LOG ("Failed to open newly linked %s: %s" , file1_s4d1, +strerror (errno)); + } + EXPECT_EQ(0, test_open_rel(bind_s1d3_fd, file1_name, O_RDONLY)) + { +TH_LOG ("Failed to open %s through newly created link under disconnected path: %s" , + file1_name,strerror (errno)); + } +ASSERT_EQ (0 ,unlink (file2_s4d1)); + +/* From disconnected to disconnected (different parent). */ +ASSERT_EQ (0 , + linkat(bind_s1d3_fd, file1_name, bind_s1d3_fd, "s4d2/f1", 0)) + { +TH_LOG ("Failed to link %s to %s within disconnected %s: %s" , + file1_name,"s4d2/f1" , bind_dir_s1d3,strerror (errno)); + } + EXPECT_EQ(0, test_open(file1_s4d2, O_RDONLY)) + { +TH_LOG ("Failed to open %s after link: %s" , file1_s4d2, +strerror (errno)); + } + EXPECT_EQ(0, test_open_rel(bind_s1d3_fd, "s4d2/f1", O_RDONLY)) + { +TH_LOG ("Failed to open %s through disconnected path after link: %s" , +"s4d2/f1" ,strerror (errno)); + } +} +#define LOWER_BASE TMP_DIR "/lower"#define LOWER_DATA LOWER_BASE "/data"static const char lower_fl1[] =LOWER_DATA "/fl1" ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/1193 selftests/landlock: Add disconnected leafs and branch test suites
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mickaël Salaün <[email protected]>
[ Upstream commit 54f9baf537b0a091adad860ec92e3e18e0a0754c ]
Test disconnected directories with two test suites (layout4_disconnected_leafs and layout5_disconnected_branch) and 43 variants to cover the main corner cases.
These tests are complementary to the previous commit.
Add test_renameat() and test_exchangeat() helpers.
Test coverage for security/landlock is 92.1% of 1927 lines according to LLVM 20.
[mic: Backport: skip empty rules, use the older fixture teardown, and explicitly detach nested mounts]
--- tools/testing/selftests/landlock/fs_test.c | 1064 ++++++++++++++++++++ 1 file changed, 1064 insertions(+)
tools/testing/selftests/landlock/fs_test.c +1064 -0
@@ -296,6 +296,16 @@ static void cleanup_layout(struct __test_metadata *const _metadata)EXPECT_EQ (0 ,remove_path (TMP_DIR )); } +static void +cleanup_layout_with_nested_mounts (struct __test_metadata *const _metadata) +{ +set_cap (_metadata,CAP_SYS_ADMIN ); +/* Also detaches disconnected bind mounts nested below TMP_DIR. */ +EXPECT_EQ (0 ,umount2 (TMP_DIR ,MNT_DETACH )); +clear_cap (_metadata,CAP_SYS_ADMIN ); +EXPECT_EQ (0 ,remove_path (TMP_DIR )); +} +/* clang-format off */ FIXTURE (layout0) {};/* clang-format on */
@@ -673,6 +683,9 @@ static int create_ruleset(struct __test_metadata *const _metadata, }for (i =0 ; rules[i].path; i++) { +if (!rules[i].access) +continue ; +add_path_beneath (_metadata, ruleset_fd, rules[i].access, rules[i].path); }
@@ -1967,6 +1980,22 @@ static int test_exchange(const char *const oldpath, const char *const newpath)return 0 ; } +static int test_renameat (int olddirfd,const char *oldpath,int newdirfd, +const char *newpath) +{ +if (renameat2 (olddirfd, oldpath, newdirfd, newpath,0 )) +return errno; +return 0 ; +} + +static int test_exchangeat (int olddirfd,const char *oldpath,int newdirfd, +const char *newpath) +{ +if (renameat2 (olddirfd, oldpath, newdirfd, newpath,RENAME_EXCHANGE )) +return errno; +return 0 ; +} + TEST_F_FORK(layout1, rename_file) {const struct rule rules[] = {
@@ -4392,6 +4421,1041 @@ TEST_F_FORK(layout1_bind, path_disconnected_link) } } +/* +* layout4_disconnected_leafs with bind mount and renames: +* +* tmp +* ├── s1d1 +* │ └── s1d2 [source of the bind mount] +* │ ├── s1d31 +* │ │ └── s1d41 [now renamed beneath s3d1] +* │ │ ├── f1 +* │ │ └── f2 +* │ └── s1d32 +* │ └── s1d42 [now renamed beneath s4d1] +* │ ├── f3 +* │ └── f4 +* ├── s2d1 +* │ └── s2d2 [bind mount of s1d2] +* │ ├── s1d31 +* │ │ └── s1d41 [opened FD, now renamed beneath s3d1] +* │ │ ├── f1 +* │ │ └── f2 +* │ └── s1d32 +* │ └── s1d42 [opened FD, now renamed beneath s4d1] +* │ ├── f3 +* │ └── f4 +* ├── s3d1 +* │ └── s1d41 [renamed here] +* │ ├── f1 +* │ └── f2 +* └── s4d1 +* └── s1d42 [renamed here] +* ├── f3 +* └── f4 +*/ +/* clang-format off */ +FIXTURE (layout4_disconnected_leafs) { +int s2d2_fd; +}; +/* clang-format on */ + +FIXTURE_SETUP (layout4_disconnected_leafs) +{ +prepare_layout (_metadata); + +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d31/s1d41/f1" ); +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d31/s1d41/f2" ); +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d32/s1d42/f3" ); +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d32/s1d42/f4" ); +create_directory (_metadata,TMP_DIR "/s2d1/s2d2" ); +create_directory (_metadata,TMP_DIR "/s3d1" ); +create_directory (_metadata,TMP_DIR "/s4d1" ); + + self->s2d2_fd = +open (TMP_DIR "/s2d1/s2d2" ,O_DIRECTORY |O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , self->s2d2_fd); + +set_cap (_metadata,CAP_SYS_ADMIN ); +ASSERT_EQ (0 ,mount (TMP_DIR "/s1d1/s1d2" ,TMP_DIR "/s2d1/s2d2" ,NULL , +MS_BIND ,NULL )); +clear_cap (_metadata,CAP_SYS_ADMIN ); +} + +FIXTURE_TEARDOWN (layout4_disconnected_leafs) +{ +/* Teardown runs before this mount namespace exits. */ + +/* Removes files after renames. */ +remove_path (TMP_DIR "/s3d1/s1d41/f1" ); +remove_path (TMP_DIR "/s3d1/s1d41/f2" ); +remove_path (TMP_DIR "/s4d1/s1d42/f1" ); +remove_path (TMP_DIR "/s4d1/s1d42/f3" ); +remove_path (TMP_DIR "/s4d1/s1d42/f4" ); +remove_path (TMP_DIR "/s4d1/s1d42/f5" ); + +cleanup_layout_with_nested_mounts (_metadata); +} + +FIXTURE_VARIANT (layout4_disconnected_leafs) +{ +/* +* Parent of the bind mount source. It should always be ignored when +* testing against files under the s1d41 or s1d42 disconnected directories. +*/ +const __u64 allowed_s1d1; +/* +* Source of bind mount (to s2d2). It should always be enforced when +* testing against files under the s1d41 or s1d42 disconnected directories. +*/ +const __u64 allowed_s1d2; +/* +* Original parent of s1d41. It should always be ignored when testing +* against files under the s1d41 disconnected directory. +*/ +const __u64 allowed_s1d31; +/* +* Original parent of s1d42. It should always be ignored when testing +* against files under the s1d42 disconnected directory. +*/ +const __u64 allowed_s1d32; +/* +* Opened and disconnected source directory. It should always be enforced +* when testing against files under the s1d41 disconnected directory. +*/ +const __u64 allowed_s1d41; +/* +* Opened and disconnected source directory. It should always be enforced +* when testing against files under the s1d42 disconnected directory. +*/ +const __u64 allowed_s1d42; +/* +* File in the s1d41 disconnected directory. It should always be enforced +* when testing against itself under the s1d41 disconnected directory. +*/ +const __u64 allowed_f1; +/* +* File in the s1d41 disconnected directory. It should always be enforced +* when testing against itself under the s1d41 disconnected directory. +*/ +const __u64 allowed_f2; +/* +* File in the s1d42 disconnected directory. It should always be enforced +* when testing against itself under the s1d42 disconnected directory. +*/ +const __u64 allowed_f3; +/* +* Parent of the bind mount destination. It should always be enforced when +* testing against files under the s1d41 or s1d42 disconnected directories. +*/ +const __u64 allowed_s2d1; +/* +* Directory covered by the bind mount. It should always be ignored when +* testing against files under the s1d41 or s1d42 disconnected directories. +*/ +const __u64 allowed_s2d2; +/* +* New parent of the renamed s1d41. It should always be ignored when +* testing against files under the s1d41 disconnected directory. +*/ +const __u64 allowed_s3d1; +/* +* New parent of the renamed s1d42. It should always be ignored when +* testing against files under the s1d42 disconnected directory. +*/ +const __u64 allowed_s4d1; + +/* Expected result of the call to open([fd:s1d41]/f1, O_RDONLY). */ +const int expected_read_result; +/* Expected result of the call to renameat([fd:s1d41]/f1, [fd:s1d42]/f1). */ +const int expected_rename_result; +/* +* Expected result of the call to renameat([fd:s1d41]/f2, [fd:s1d42]/f3, +* RENAME_EXCHANGE). +*/ +const int expected_exchange_result; +/* Expected result of the call to renameat([fd:s1d42]/f4, [fd:s1d42]/f5). */ +const int expected_same_dir_rename_result; +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d1_mount_src_parent) { +/* clang-format on */ + .allowed_s1d1 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result =EACCES , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d2_mount_src_refer) { +/* clang-format on */ + .allowed_s1d2 =LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_READ_FILE , + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d2_mount_src_create) { +/* clang-format on */ + .allowed_s1d2 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result =EXDEV , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d2_mount_src_rename) { +/* clang-format on */ + .allowed_s1d2 =LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_MAKE_REG , + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d31_s1d32_old_parent) { +/* clang-format on */ + .allowed_s1d31 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .allowed_s1d32 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result =EACCES , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d41_s1d42_disconnected_refer) { +/* clang-format on */ + .allowed_s1d41 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE , + .allowed_s1d42 = LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE , + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d41_s1d42_disconnected_create) { +/* clang-format on */ + .allowed_s1d41 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .allowed_s1d42 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result =EXDEV , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d41_s1d42_disconnected_rename_even) { +/* clang-format on */ + .allowed_s1d41 =LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_MAKE_REG , + .allowed_s1d42 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* The destination directory has more access right. */ +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d41_s1d42_disconnected_rename_more) { +/* clang-format on */ + .allowed_s1d41 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .allowed_s1d42 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_MAKE_REG | + LANDLOCK_ACCESS_FS_EXECUTE, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, +/* Access denied. */ + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* The destination directory has less access right. */ +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s1d41_s1d42_disconnected_rename_less) { +/* clang-format on */ + .allowed_s1d41 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_MAKE_REG | + LANDLOCK_ACCESS_FS_EXECUTE, + .allowed_s1d42 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, +/* Access allowed. */ + .expected_rename_result = 0, + .expected_exchange_result =EXDEV , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s2d1_mount_dst_parent_create) { +/* clang-format on */ + .allowed_s2d1 =LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_MAKE_REG , + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s2d1_mount_dst_parent_refer) { +/* clang-format on */ + .allowed_s2d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result =EACCES , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s2d1_mount_dst_parent_mini) { +/* clang-format on */ + .allowed_s2d1 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_MAKE_REG , + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s2d2_covered_by_mount) { +/* clang-format on */ + .allowed_s2d2 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* Tests collect_domain_accesses(). */ +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s3d1_s4d1_new_parent_refer) { +/* clang-format on */ + .allowed_s3d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result =EACCES , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s3d1_s4d1_new_parent_create) { +/* clang-format on */ + .allowed_s3d1 =LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_MAKE_REG , + .allowed_s4d1 = LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_MAKE_REG , + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +FIXTURE_VARIANT_ADD (layout4_disconnected_leafs, + s3d1_s4d1_disconnected_rename_even){ +/* clang-format on */ + .allowed_s3d1 =LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_MAKE_REG , + .allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* The destination directory has more access right. */ +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s3d1_s4d1_disconnected_rename_more) { +/* clang-format on */ + .allowed_s3d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .allowed_s4d1 =LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_MAKE_REG | + LANDLOCK_ACCESS_FS_EXECUTE, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, +/* Access denied. */ + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* The destination directory has less access right. */ +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s3d1_s4d1_disconnected_rename_less) { +/* clang-format on */ + .allowed_s3d1 =LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_MAKE_REG | + LANDLOCK_ACCESS_FS_EXECUTE, + .allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, +/* Access allowed. */ + .expected_rename_result = 0, + .expected_exchange_result =EXDEV , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, f1_f2_f3) { +/* clang-format on */ + .allowed_f1 =LANDLOCK_ACCESS_FS_READ_FILE , + .allowed_f2 = LANDLOCK_ACCESS_FS_READ_FILE, + .allowed_f3 = LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +TEST_F_FORK(layout4_disconnected_leafs, read_rename_exchange) +{ + const __u64 handled_access = +LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE |LANDLOCK_ACCESS_FS_MAKE_REG ; +const struct rule rules[] = { + { + .path =TMP_DIR "/s1d1" , + .access = variant->allowed_s1d1, + }, + { + .path =TMP_DIR "/s1d1/s1d2" , + .access = variant->allowed_s1d2, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d31" , + .access = variant->allowed_s1d31, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d32" , + .access = variant->allowed_s1d32, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d31/s1d41" , + .access = variant->allowed_s1d41, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d32/s1d42" , + .access = variant->allowed_s1d42, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d31/s1d41/f1" , + .access = variant->allowed_f1, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d31/s1d41/f2" , + .access = variant->allowed_f2, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d32/s1d42/f3" , + .access = variant->allowed_f3, + }, + { + .path =TMP_DIR "/s2d1" , + .access = variant->allowed_s2d1, + }, +/* s2d2_fd */ + { + .path =TMP_DIR "/s3d1" , + .access = variant->allowed_s3d1, + }, + { + .path =TMP_DIR "/s4d1" , + .access = variant->allowed_s4d1, + }, + {}, + }; +int ruleset_fd, s1d41_bind_fd, s1d42_bind_fd; + + ruleset_fd =create_ruleset (_metadata, handled_access, rules); +ASSERT_LE (0 , ruleset_fd); + +/* Adds rule for the covered directory. */ +if (variant->allowed_s2d2) { +ASSERT_EQ (0 ,landlock_add_rule ( + ruleset_fd,LANDLOCK_RULE_PATH_BENEATH , + &(struct landlock_path_beneath_attr ){ + .parent_fd = self->s2d2_fd, + .allowed_access = + variant->allowed_s2d2, + }, +0 )); + } +EXPECT_EQ (0 ,close (self->s2d2_fd)); + + s1d41_bind_fd =open (TMP_DIR "/s2d1/s2d2/s1d31/s1d41" , +O_DIRECTORY |O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , s1d41_bind_fd); + s1d42_bind_fd =open (TMP_DIR "/s2d1/s2d2/s1d32/s1d42" , +O_DIRECTORY |O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , s1d42_bind_fd); + +/* Disconnects and checks source and destination directories. */ +EXPECT_EQ (0 ,test_open_rel (s1d41_bind_fd,".." ,O_DIRECTORY )); +EXPECT_EQ (0 ,test_open_rel (s1d42_bind_fd,".." ,O_DIRECTORY )); +/* Renames to make it accessible through s3d1/s1d41 */ +ASSERT_EQ (0 ,test_renameat (AT_FDCWD ,TMP_DIR "/s1d1/s1d2/s1d31/s1d41" , +AT_FDCWD ,TMP_DIR "/s3d1/s1d41" )); +/* Renames to make it accessible through s4d1/s1d42 */ +ASSERT_EQ (0 ,test_renameat (AT_FDCWD ,TMP_DIR "/s1d1/s1d2/s1d32/s1d42" , +AT_FDCWD ,TMP_DIR "/s4d1/s1d42" )); +EXPECT_EQ (ENOENT ,test_open_rel (s1d41_bind_fd,".." ,O_DIRECTORY )); +EXPECT_EQ (ENOENT ,test_open_rel (s1d42_bind_fd,".." ,O_DIRECTORY )); + +enforce_ruleset (_metadata, ruleset_fd); +EXPECT_EQ (0 ,close (ruleset_fd)); + +EXPECT_EQ (variant->expected_read_result, +test_open_rel (s1d41_bind_fd,"f1" ,O_RDONLY )); + +EXPECT_EQ (variant->expected_rename_result, +test_renameat (s1d41_bind_fd,"f1" , s1d42_bind_fd,"f1" )); +EXPECT_EQ (variant->expected_exchange_result, +test_exchangeat (s1d41_bind_fd,"f2" , s1d42_bind_fd,"f3" )); + +EXPECT_EQ (variant->expected_same_dir_rename_result, +test_renameat (s1d42_bind_fd,"f4" , s1d42_bind_fd,"f5" )); +} + +/* +* layout5_disconnected_branch before rename: +* +* tmp +* ├── s1d1 +* │ └── s1d2 [source of the first bind mount] +* │ └── s1d3 +* │ ├── s1d41 +* │ │ ├── f1 +* │ │ └── f2 +* │ └── s1d42 +* │ ├── f3 +* │ └── f4 +* ├── s2d1 +* │ └── s2d2 [source of the second bind mount] +* │ └── s2d3 +* │ └── s2d4 [first s1d2 bind mount] +* │ └── s1d3 +* │ ├── s1d41 +* │ │ ├── f1 +* │ │ └── f2 +* │ └── s1d42 +* │ ├── f3 +* │ └── f4 +* ├── s3d1 +* │ └── s3d2 [second s2d2 bind mount] +* │ └── s2d3 +* │ └── s2d4 [first s1d2 bind mount] +* │ └── s1d3 +* │ ├── s1d41 +* │ │ ├── f1 +* │ │ └── f2 +* │ └── s1d42 +* │ ├── f3 +* │ └── f4 +* └── s4d1 +* +* After rename: +* +* tmp +* ├── s1d1 +* │ └── s1d2 [source of the first bind mount] +* │ └── s1d3 +* │ ├── s1d41 +* │ │ ├── f1 +* │ │ └── f2 +* │ └── s1d42 +* │ ├── f3 +* │ └── f4 +* ├── s2d1 +* │ └── s2d2 [source of the second bind mount] +* ├── s3d1 +* │ └── s3d2 [second s2d2 bind mount] +* └── s4d1 +* └── s2d3 [renamed here] +* └── s2d4 [first s1d2 bind mount] +* └── s1d3 +* ├── s1d41 +* │ ├── f1 +* │ └── f2 +* └── s1d42 +* ├── f3 +* └── f4 +* +* Decision path for access from the s3d1/s3d2/s2d3/s2d4/s1d3 file descriptor: +* 1. first bind mount: s1d3 -> s1d2 +* 2. second bind mount: s2d3 +* 3. tmp mount: s4d1 -> tmp [disconnected branch] +* 4. second bind mount: s2d2 +* 5. tmp mount: s3d1 -> tmp +* 6. parent mounts: [...] -> / +* +* The s4d1 directory is evaluated even if it is not in the s2d2 mount. +*/ + +/* clang-format off */ +FIXTURE (layout5_disconnected_branch) { +int s2d4_fd, s3d2_fd; +}; +/* clang-format on */ + +FIXTURE_SETUP (layout5_disconnected_branch) +{ +prepare_layout (_metadata); + +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d3/s1d41/f1" ); +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d3/s1d41/f2" ); +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d3/s1d42/f3" ); +create_file (_metadata,TMP_DIR "/s1d1/s1d2/s1d3/s1d42/f4" ); +create_directory (_metadata,TMP_DIR "/s2d1/s2d2/s2d3/s2d4" ); +create_directory (_metadata,TMP_DIR "/s3d1/s3d2" ); +create_directory (_metadata,TMP_DIR "/s4d1" ); + + self->s2d4_fd =open (TMP_DIR "/s2d1/s2d2/s2d3/s2d4" , +O_DIRECTORY |O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , self->s2d4_fd); + + self->s3d2_fd = +open (TMP_DIR "/s3d1/s3d2" ,O_DIRECTORY |O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , self->s3d2_fd); + +set_cap (_metadata,CAP_SYS_ADMIN ); +ASSERT_EQ (0 ,mount (TMP_DIR "/s1d1/s1d2" ,TMP_DIR "/s2d1/s2d2/s2d3/s2d4" , +NULL ,MS_BIND ,NULL )); +ASSERT_EQ (0 ,mount (TMP_DIR "/s2d1/s2d2" ,TMP_DIR "/s3d1/s3d2" ,NULL , +MS_BIND |MS_REC ,NULL )); +clear_cap (_metadata,CAP_SYS_ADMIN ); +} + +FIXTURE_TEARDOWN (layout5_disconnected_branch) +{ +/* Teardown runs before this mount namespace exits. */ + +/* Removes files after renames. */ +remove_path (TMP_DIR "/s1d1/s1d2/s1d3/s1d41/f1" ); +remove_path (TMP_DIR "/s1d1/s1d2/s1d3/s1d41/f2" ); +remove_path (TMP_DIR "/s1d1/s1d2/s1d3/s1d42/f1" ); +remove_path (TMP_DIR "/s1d1/s1d2/s1d3/s1d42/f3" ); +remove_path (TMP_DIR "/s1d1/s1d2/s1d3/s1d42/f4" ); +remove_path (TMP_DIR "/s1d1/s1d2/s1d3/s1d42/f5" ); + +cleanup_layout_with_nested_mounts (_metadata); +} + +FIXTURE_VARIANT (layout5_disconnected_branch) +{ +/* +* Parent of all files. It should always be enforced when testing against +* files under the s1d41 or s1d42 disconnected directories. +*/ +const __u64 allowed_base; +/* +* Parent of the first bind mount source. It should always be ignored when +* testing against files under the s1d41 or s1d42 disconnected directories. +*/ +const __u64 allowed_s1d1; +const __u64 allowed_s1d2; +const __u64 allowed_s1d3; +const __u64 allowed_s2d1; +const __u64 allowed_s2d2; +const __u64 allowed_s2d3; +const __u64 allowed_s2d4; +const __u64 allowed_s3d1; +const __u64 allowed_s3d2; +const __u64 allowed_s4d1; + +/* Expected result of the call to open([fd:s1d3]/s1d41/f1, O_RDONLY). */ +const int expected_read_result; +/* +* Expected result of the call to renameat([fd:s1d3]/s1d41/f1, +* [fd:s1d3]/s1d42/f1). +*/ +const int expected_rename_result; +/* +* Expected result of the call to renameat([fd:s1d3]/s1d41/f2, +* [fd:s1d3]/s1d42/f3, RENAME_EXCHANGE). +*/ +const int expected_exchange_result; +/* +* Expected result of the call to renameat([fd:s1d3]/s1d42/f4, +* [fd:s1d3]/s1d42/f5). +*/ +const int expected_same_dir_rename_result; +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d1_mount1_src_parent) { +/* clang-format on */ + .allowed_s1d1 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d2_mount1_src_refer) { +/* clang-format on */ + .allowed_s1d2 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d2_mount1_src_create) { +/* clang-format on */ + .allowed_s1d2 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d2_mount1_src_rename) { +/* clang-format on */ + .allowed_s1d2 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d3_fd_refer) { +/* clang-format on */ + .allowed_s1d3 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d3_fd_create) { +/* clang-format on */ + .allowed_s1d3 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d3_fd_rename) { +/* clang-format on */ + .allowed_s1d3 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s1d3_fd_full) { +/* clang-format on */ + .allowed_s1d3 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d1_mount2_src_parent) { +/* clang-format on */ + .allowed_s2d1 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d2_mount2_src_refer) { +/* clang-format on */ + .allowed_s2d2 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d2_mount2_src_create) { +/* clang-format on */ + .allowed_s2d2 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d2_mount2_src_rename) { +/* clang-format on */ + .allowed_s2d2 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d3_mount1_dst_parent_refer) { +/* clang-format on */ + .allowed_s2d3 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d3_mount1_dst_parent_create) { +/* clang-format on */ + .allowed_s2d3 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d3_mount1_dst_parent_rename) { +/* clang-format on */ + .allowed_s2d3 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s2d4_mount1_dst) { +/* clang-format on */ + .allowed_s2d4 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s3d1_mount2_dst_parent_refer) { +/* clang-format on */ + .allowed_s3d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s3d1_mount2_dst_parent_create) { +/* clang-format on */ + .allowed_s3d1 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s3d1_mount2_dst_parent_rename) { +/* clang-format on */ + .allowed_s3d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s3d2_mount1_dst) { +/* clang-format on */ + .allowed_s3d2 =LANDLOCK_ACCESS_FS_REFER | +LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s4d1_rename_parent_refer) { +/* clang-format on */ + .allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_READ_FILE, + .expected_read_result = 0, + .expected_same_dir_rename_result = EACCES, + .expected_rename_result = EACCES, + .expected_exchange_result = EACCES, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s4d1_rename_parent_create) { +/* clang-format on */ + .allowed_s4d1 =LANDLOCK_ACCESS_FS_READ_FILE | + LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = 0, + .expected_same_dir_rename_result = 0, + .expected_rename_result = EXDEV, + .expected_exchange_result = EXDEV, +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(layout5_disconnected_branch, s4d1_rename_parent_rename) { +/* clang-format on */ + .allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG, + .expected_read_result = EACCES, + .expected_same_dir_rename_result = 0, + .expected_rename_result = 0, + .expected_exchange_result = 0, +}; + +TEST_F_FORK(layout5_disconnected_branch, read_rename_exchange) +{ +const __u64 handled_access = +LANDLOCK_ACCESS_FS_REFER |LANDLOCK_ACCESS_FS_READ_FILE | +LANDLOCK_ACCESS_FS_EXECUTE |LANDLOCK_ACCESS_FS_MAKE_REG ; +const struct rule rules[] = { + { + .path =TMP_DIR "/s1d1" , + .access = variant->allowed_s1d1, + }, + { + .path =TMP_DIR "/s1d1/s1d2" , + .access = variant->allowed_s1d2, + }, + { + .path =TMP_DIR "/s1d1/s1d2/s1d3" , + .access = variant->allowed_s1d3, + }, + { + .path =TMP_DIR "/s2d1" , + .access = variant->allowed_s2d1, + }, + { + .path =TMP_DIR "/s2d1/s2d2" , + .access = variant->allowed_s2d2, + }, + { + .path =TMP_DIR "/s2d1/s2d2/s2d3" , + .access = variant->allowed_s2d3, + }, +/* s2d4_fd */ + { + .path =TMP_DIR "/s3d1" , + .access = variant->allowed_s3d1, + }, +/* s3d2_fd */ + { + .path =TMP_DIR "/s4d1" , + .access = variant->allowed_s4d1, + }, + {}, + }; +int ruleset_fd, s1d3_bind_fd; + + ruleset_fd =create_ruleset (_metadata, handled_access, rules); +ASSERT_LE (0 , ruleset_fd); + +/* Adds rules for the covered directories. */ +if (variant->allowed_s2d4) { +ASSERT_EQ (0 ,landlock_add_rule ( + ruleset_fd,LANDLOCK_RULE_PATH_BENEATH , + &(struct landlock_path_beneath_attr ){ + .parent_fd = self->s2d4_fd, + .allowed_access = + variant->allowed_s2d4, + }, +0 )); + } +EXPECT_EQ (0 ,close (self->s2d4_fd)); + +if (variant->allowed_s3d2) { +ASSERT_EQ (0 ,landlock_add_rule ( + ruleset_fd,LANDLOCK_RULE_PATH_BENEATH , + &(struct landlock_path_beneath_attr ){ + .parent_fd = self->s3d2_fd, + .allowed_access = + variant->allowed_s3d2, + }, +0 )); + } +EXPECT_EQ (0 ,close (self->s3d2_fd)); + + s1d3_bind_fd =open (TMP_DIR "/s3d1/s3d2/s2d3/s2d4/s1d3" , +O_DIRECTORY |O_PATH |O_CLOEXEC ); +ASSERT_LE (0 , s1d3_bind_fd); + +/* Disconnects and checks source and destination directories. */ +EXPECT_EQ (0 ,test_open_rel (s1d3_bind_fd,".." ,O_DIRECTORY )); +EXPECT_EQ (0 ,test_open_rel (s1d3_bind_fd,"../.." ,O_DIRECTORY )); +/* Renames to make it accessible through s3d1/s1d41 */ +ASSERT_EQ (0 ,test_renameat (AT_FDCWD ,TMP_DIR "/s2d1/s2d2/s2d3" , +AT_FDCWD ,TMP_DIR "/s4d1/s2d3" )); +EXPECT_EQ (0 ,test_open_rel (s1d3_bind_fd,".." ,O_DIRECTORY )); +EXPECT_EQ (ENOENT ,test_open_rel (s1d3_bind_fd,"../.." ,O_DIRECTORY )); + +enforce_ruleset (_metadata, ruleset_fd); +EXPECT_EQ (0 ,close (ruleset_fd)); + +EXPECT_EQ (variant->expected_read_result, +test_open_rel (s1d3_bind_fd,"s1d41/f1" ,O_RDONLY )); + +EXPECT_EQ (variant->expected_rename_result, +test_renameat (s1d3_bind_fd,"s1d41/f1" , s1d3_bind_fd, +"s1d42/f1" )); +EXPECT_EQ (variant->expected_exchange_result, +test_exchangeat (s1d3_bind_fd,"s1d41/f2" , s1d3_bind_fd, +"s1d42/f3" )); + +EXPECT_EQ (variant->expected_same_dir_rename_result, +test_renameat (s1d3_bind_fd,"s1d42/f4" , s1d3_bind_fd, +"s1d42/f5" )); +} +#define LOWER_BASE TMP_DIR "/lower"#define LOWER_DATA LOWER_BASE "/data"static const char lower_fl1[] =LOWER_DATA "/fl1" ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/1193 Revert "alpha: dont leak hardware-fabricated FP exception bits to user space"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 7b5771d0bf176c6090921785c56e23920b4ae614.
--- arch/alpha/kernel/traps.c | 6 +-- arch/alpha/math-emu/math.c | 88 +++++--------------------------------- 2 files changed, 14 insertions(+), 80 deletions(-)
arch/alpha/kernel/traps.c +3 -3
@@ -198,12 +198,12 @@ static long dummy_emul(void) { return 0; }long (*alpha_fp_emul_imprecise)(struct pt_regs *regs,unsigned long writemask) = (void *)dummy_emul;EXPORT_SYMBOL_GPL (alpha_fp_emul_imprecise); -long (*alpha_fp_emul) (unsigned long pc,unsigned long summary) +long (*alpha_fp_emul) (unsigned long pc) = (void *)dummy_emul;EXPORT_SYMBOL_GPL (alpha_fp_emul);#else long alpha_fp_emul_imprecise (struct pt_regs *regs,unsigned long writemask); -long alpha_fp_emul (unsigned long pc,unsigned long summary); +long alpha_fp_emul (unsigned long pc);#endif asmlinkage void
@@ -217,7 +217,7 @@ do_entArith(unsigned long summary, unsigned long write_mask,emulate the instruction. If the processor supports precise exceptions, we don't have to search. */ if (!amask (AMASK_PRECISE_TRAP )) - si_code =alpha_fp_emul (regs->pc -4 , summary); + si_code =alpha_fp_emul (regs->pc -4 );else si_code =alpha_fp_emul_imprecise (regs, write_mask);if (si_code ==0 )
arch/alpha/math-emu/math.c +11 -77
125 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/1193 Revert "alpha: fix ieee_swcr_to_fpcr setting FPCR_DNOD unconditionally"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit e5038d7f36037fc4ffc41b1a7dcd295bab7d7a04.
--- arch/alpha/include/uapi/asm/fpu.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
arch/alpha/include/uapi/asm/fpu.h +2 -6
@@ -101,12 +101,7 @@ ieee_swcr_to_fpcr(unsigned long sw) | IEEE_TRAP_ENABLE_OVF)) << 48; fp |= (~sw & (IEEE_TRAP_ENABLE_UNF |IEEE_TRAP_ENABLE_INE )) <<57 ; fp |= (sw &IEEE_MAP_UMZ ?FPCR_UNDZ |FPCR_UNFD :0 ); -/* -* Disable denormal operand traps only when denormal inputs are to be -* flushed to zero. Otherwise they must keep trapping, so that /S -* instructions reach the kernel emulation handler. -*/ - fp |= (sw &IEEE_MAP_DMZ ?FPCR_DNOD :0 ); + fp |= (~sw &IEEE_TRAP_ENABLE_DNO ) <<41 ;return fp; }
@@ -121,6 +116,7 @@ ieee_fpcr_to_swcr(unsigned long fp) | IEEE_TRAP_ENABLE_OVF); sw |= (~fp >>57 ) & (IEEE_TRAP_ENABLE_UNF |IEEE_TRAP_ENABLE_INE ); sw |= (fp >>47 ) &IEEE_MAP_UMZ ; + sw |= (~fp >>41 ) &IEEE_TRAP_ENABLE_DNO ;return sw; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/1193 selftests/landlock: Add tests for whiteout object creation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Günther Noack <[email protected]>
[ Upstream commit ee890889b30b22f9a21636061def7a04e4f89380 ]
Add tests to check that whiteout object creation is guarded by LANDLOCK_ACCESS_FS_MAKE_REG, in the cases where these are created from userspace:
* Conventional creation with mknod()
* Linking or renaming an existing whiteout object
* renameat2() with RENAME_WHITEOUT,
which creates a new whiteout object in the source location
* renameat2() with RENAME_EXCHANGE,
with one of the renamed objects being a whiteout object
[mic: Backport: adapt the tests to the older filesystem fixture and ruleset helper]
--- tools/testing/selftests/landlock/fs_test.c | 209 ++++++++++++++++++++- 1 file changed, 207 insertions(+), 2 deletions(-)
tools/testing/selftests/landlock/fs_test.c +207 -2
@@ -38,6 +38,10 @@ int renameat2(int olddirfd, const char *oldpath, int newdirfd,#define RENAME_EXCHANGE (1 << 1)#endif +#ifndef RENAME_WHITEOUT +#define RENAME_WHITEOUT (1 << 2) +#endif +#define TMP_DIR "tmp"#define BINARY_PATH "./true"
@@ -65,6 +69,8 @@ static const char file1_s3d1[] = TMP_DIR "/s3d1/f1";/* dir_s3d2 is a mount point. */ static const char dir_s3d2[] =TMP_DIR "/s3d1/s3d2" ;static const char dir_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3" ; +static const char file1_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3/f1" ; +static const char file1_s3d4[] =TMP_DIR "/s3d1/s3d2/s3d4/f1" ;/* * layout1 hierarchy:
@@ -340,7 +346,8 @@ static void create_layout1(struct __test_metadata *const _metadata)ASSERT_EQ (0 ,mount_opt (&mnt_tmp, dir_s3d2));clear_cap (_metadata,CAP_SYS_ADMIN ); -ASSERT_EQ (0 ,mkdir (dir_s3d3,0700 )); +create_file (_metadata, file1_s3d3); +create_file (_metadata, file1_s3d4); }static void remove_layout1 (struct __test_metadata *const _metadata)
@@ -360,7 +367,8 @@ static void remove_layout1(struct __test_metadata *const _metadata)EXPECT_EQ (0 ,remove_path (dir_s2d2));EXPECT_EQ (0 ,remove_path (file1_s3d1)); -EXPECT_EQ (0 ,remove_path (dir_s3d3)); +EXPECT_EQ (0 ,remove_path (file1_s3d3)); +EXPECT_EQ (0 ,remove_path (file1_s3d4));set_cap (_metadata,CAP_SYS_ADMIN );umount (dir_s3d2);clear_cap (_metadata,CAP_SYS_ADMIN );
@@ -702,6 +710,27 @@ static void enforce_ruleset(struct __test_metadata *const _metadata, } } +static void enforce_fs (struct __test_metadata *const _metadata, +const __u64 access_fs,const struct rule rules[]) +{ +int ruleset_fd; + +if (rules) { + ruleset_fd =create_ruleset (_metadata, access_fs, rules); + }else { +const struct landlock_ruleset_attr ruleset_attr = { + .handled_access_fs = access_fs, + }; + + ruleset_fd =landlock_create_ruleset (&ruleset_attr, +sizeof (ruleset_attr),0 ); +ASSERT_LE (0 , ruleset_fd); + } + +enforce_ruleset (_metadata, ruleset_fd); +EXPECT_EQ (0 ,close (ruleset_fd)); +} + TEST_F_FORK(layout0, proc_nsfs) {const struct rule rules[] = {
@@ -2078,6 +2107,170 @@ TEST_F_FORK(layout1, rename_file) RENAME_EXCHANGE)); } +TEST_F_FORK(layout1, rename_whiteout_denied) +{ +/* The affected file is a FIFO. */ +ASSERT_EQ (0 ,unlink (file1_s3d3)); +ASSERT_EQ (0 ,mknod (file1_s3d3,S_IFIFO |0600 ,0 )); + +/* Deny MAKE_REG, but allow MAKE_FIFO. */ +enforce_fs (_metadata,LANDLOCK_ACCESS_FS_MAKE_REG ,NULL ); + +/* +* Try to rename a file with RENAME_WHITEOUT. +* file1_s3d3 is in dir_s3d2 (tmpfs), so it supports RENAME_WHITEOUT. +* Denied, because whiteout creation is guarded with MAKE_REG. +*/ +EXPECT_EQ (-1 ,renameat2 (AT_FDCWD , file1_s3d3,AT_FDCWD , +TMP_DIR "/s3d1/s3d2/s3d3/f2" ,RENAME_WHITEOUT )); +EXPECT_EQ (EACCES , errno); +} + +static bool is_whiteout (const char *const path) +{ +struct stat st; + +if (stat (path, &st) ==-1 ) +return false; + +return S_ISCHR (st.st_mode) && st.st_rdev ==makedev (0 ,0 ); +} + +static bool is_fifo (const char *const path) +{ +struct stat st; + +return stat (path, &st) ==0 &&S_ISFIFO (st.st_mode); +} + +TEST_F_FORK(layout1, rename_whiteout_allowed) +{ +const struct rule rules[] = { + { + .path = dir_s3d3, + .access =LANDLOCK_ACCESS_FS_MAKE_REG , + }, + {}, + }; + +/* The affected file is a FIFO. */ +ASSERT_EQ (0 ,unlink (file1_s3d3)); +ASSERT_EQ (0 ,mknod (file1_s3d3,S_IFIFO |0600 ,0 )); + +/* Allow MAKE_REG below dir_s3d3. */ +enforce_fs (_metadata,LANDLOCK_ACCESS_FS_MAKE_REG , rules); + +/* +* Rename a file with RENAME_WHITEOUT within the same directory. +* Allowed, because MAKE_REG is granted for the whiteout object which +* gets created in the source location. +*/ +EXPECT_EQ (0 ,renameat2 (AT_FDCWD , file1_s3d3,AT_FDCWD , +TMP_DIR "/s3d1/s3d2/s3d3/f2" ,RENAME_WHITEOUT )); + +/* A whiteout object took the place of the moved FIFO. */ +EXPECT_TRUE (is_whiteout (file1_s3d3)); +EXPECT_TRUE (is_fifo (TMP_DIR "/s3d1/s3d2/s3d3/f2" )); +} + +TEST_F_FORK(layout1, rename_whiteout_reparenting) +{ +const struct rule rules[] = { + { + .path = dir_s3d2, + .access =LANDLOCK_ACCESS_FS_REFER , + }, + { + .path = dir_s3d3, + .access =LANDLOCK_ACCESS_FS_MAKE_REG , + }, + {}, + }; + +/* The moved files are FIFOs. */ +ASSERT_EQ (0 ,unlink (file1_s3d3)); +ASSERT_EQ (0 ,mknod (file1_s3d3,S_IFIFO |0600 ,0 )); +ASSERT_EQ (0 ,unlink (file1_s3d4)); +ASSERT_EQ (0 ,mknod (file1_s3d4,S_IFIFO |0600 ,0 )); + +/* Allow REFER below dir_s3d2, but MAKE_REG only below dir_s3d3. */ +enforce_fs (_metadata, +LANDLOCK_ACCESS_FS_MAKE_REG |LANDLOCK_ACCESS_FS_REFER , + rules); + +/* +* The whiteout object is created in the source directory: Moving the +* FIFO out of dir_s3d4 is denied because MAKE_REG is not granted +* there, even though it is granted in the destination directory +* dir_s3d3. +*/ +EXPECT_EQ (-1 ,renameat2 (AT_FDCWD , file1_s3d4,AT_FDCWD , +TMP_DIR "/s3d1/s3d2/s3d3/f2" ,RENAME_WHITEOUT )); +EXPECT_EQ (EACCES , errno); + +/* +* Moving the FIFO out of dir_s3d3 is allowed, because MAKE_REG is +* granted there for the created whiteout object. +*/ +EXPECT_EQ (0 ,renameat2 (AT_FDCWD , file1_s3d3,AT_FDCWD , +TMP_DIR "/s3d1/s3d2/s3d4/f2" ,RENAME_WHITEOUT )); + +/* A whiteout object took the place of the moved FIFO. */ +EXPECT_TRUE (is_whiteout (file1_s3d3)); +EXPECT_TRUE (is_fifo (TMP_DIR "/s3d1/s3d2/s3d4/f2" )); +} + +TEST_F_FORK(layout1, rename_whiteout_exchange) +{ +const char *const whiteout_s3d3 =TMP_DIR "/s3d1/s3d2/s3d3/f2" ; +const struct rule rules[] = { + { + .path = dir_s3d2, + .access =LANDLOCK_ACCESS_FS_REFER , + }, + { + .path = dir_s3d3, + .access =LANDLOCK_ACCESS_FS_MAKE_REG , + }, + {}, + }; + +/* The exchanged files are FIFOs and an existing whiteout object. */ +ASSERT_EQ (0 ,unlink (file1_s3d3)); +ASSERT_EQ (0 ,mknod (file1_s3d3,S_IFIFO |0600 ,0 )); +ASSERT_EQ (0 ,mknod (whiteout_s3d3,S_IFCHR |0600 ,makedev (0 ,0 ))); +ASSERT_EQ (0 ,unlink (file1_s3d4)); +ASSERT_EQ (0 ,mknod (file1_s3d4,S_IFIFO |0600 ,0 )); + +/* Allow REFER below dir_s3d2, but MAKE_REG only below dir_s3d3. */ +enforce_fs (_metadata, +LANDLOCK_ACCESS_FS_MAKE_REG |LANDLOCK_ACCESS_FS_REFER , + rules); + +/* +* With RENAME_EXCHANGE, the whiteout object moves into the source +* directory of the rename: Exchanging the FIFO in dir_s3d4 with the +* whiteout object is denied because MAKE_REG is not granted in +* dir_s3d4, even though it is granted in the whiteout object's own +* directory dir_s3d3. +*/ +EXPECT_EQ (-1 ,renameat2 (AT_FDCWD , file1_s3d4,AT_FDCWD , whiteout_s3d3, +RENAME_EXCHANGE )); +EXPECT_EQ (EACCES , errno); + +/* +* Exchanging the FIFO in dir_s3d3 with the whiteout object is +* allowed, because MAKE_REG is granted in the directory into which +* the whiteout object moves. +*/ +EXPECT_EQ (0 ,renameat2 (AT_FDCWD , file1_s3d3,AT_FDCWD , whiteout_s3d3, +RENAME_EXCHANGE )); + +/* The FIFO and the whiteout object swapped places. */ +EXPECT_TRUE (is_whiteout (file1_s3d3)); +EXPECT_TRUE (is_fifo (whiteout_s3d3)); +} + TEST_F_FORK(layout1, rename_dir) {const struct rule rules[] = {
@@ -3094,6 +3287,18 @@ TEST_F_FORK(layout1, make_char) makedev(1, 3)); } +TEST_F_FORK(layout1, make_whiteout) +{ +/* +* Creates a whiteout object (creation guarded by MAKE_REG). +* +* Contrary to the other character devices, this does not require +* CAP_MKNOD, cf. vfs_mknod(). +*/ +test_make_file (_metadata,LANDLOCK_ACCESS_FS_MAKE_REG ,S_IFCHR , +makedev (0 ,0 )); +} + TEST_F_FORK(layout1, make_block) {/* Creates a /dev/loop0 device. */
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerPATCH 716/1193 sunvdc: fix -EIO issue due to lack of retries
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit 5067d4ba713961d8ccea1e06cd4c453793f3121e ]
John reports that since commit:
a11f6ca9aef9 ("sunvdc: Do not spin in an infinite loop when vio_ldc_send() returns EAGAIN")
users of Linux inside Solaris ldom see occasional -EIO errors because the request send loop now times out. The current loop does 10 retries, and inside vio_ldc_send() a further 1000 1usec retries are done as well. Even with 10.5 msec of busy loop retries that's apparently not enough to always succeed.
Rather than introduce continued busy looping, requeue the request and have the delayed queue kicking retry the request after another 10ms. This obviously isn't ideal, but there's seemingly no way to wait for this type of event. And if 10ms of busy looping was not enough to make progress, then presumably this is an edge condition and we just need to guarantee to make forward progress at some later point in time. That's more suitably done through letting the CPU tend to other work, rather than sitting in a tight loop retrying.
[stian: rebased on top of the cookie-unmap fix, without which every
requeued attempt leaks LDC map table entries; tested on an UltraSPARC T4 LDOM where the vdc_tx_trigger failure condition was reproduced and absorbed by the requeue with no I/O error]
--- drivers/block/sunvdc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/block/sunvdc.c +8 -1
@@ -557,6 +557,7 @@ static blk_status_t vdc_queue_rq(struct blk_mq_hw_ctx *hctx,struct vdc_port *port = hctx->queue->queuedata;struct vio_dring_state *dr;unsigned long flags; +int ret; dr = &port->vio.drings[VIO_DRIVER_TX_RING ];
@@ -578,7 +579,13 @@ static blk_status_t vdc_queue_rq(struct blk_mq_hw_ctx *hctx,return BLK_STS_DEV_RESOURCE ; } -if (__send_request (bd->rq) <0 ) { + ret =__send_request (bd->rq); +if (ret == -EAGAIN ) { +spin_unlock_irqrestore (&port->vio.lock, flags); +/* already spun for 10msec, defer 10msec and retry */ +blk_mq_delay_kick_requeue_list (hctx->queue,10 ); +return BLK_STS_DEV_RESOURCE ; + }else if (ret <0 ) {spin_unlock_irqrestore (&port->vio.lock, flags);return BLK_STS_IOERR ; }
Signature · 1 line
2.53.0
PATCH 717/1193 media: video-i2c: fix buffer queue ordering
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arash Golgol <[email protected]>
[ Upstream commit bc4574c265ed738849e46d942617100580fcedd2 ]
Queued buffers are added to the tail of vid_cap_active in buffer_queue(), but the capture kthread also retrieves buffers from the tail of the list.
This makes the queue behave as LIFO instead of FIFO when multiple buffers are queued.
Fix this by retrieving buffers from the head of the list.
--- drivers/media/i2c/video-i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/video-i2c.c +3 -2
@@ -464,8 +464,9 @@ static int video_i2c_thread_vid_cap(void *priv)spin_lock (&data->slock);if (!list_empty (&data->vid_cap_active)) { - vid_cap_buf =list_last_entry (&data->vid_cap_active, - struct video_i2c_buffer, list); + vid_cap_buf =list_first_entry (&data->vid_cap_active, + struct video_i2c_buffer, + list);list_del (&vid_cap_buf->list); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/1193 ipv6: Select best matching nexthop object in fib6_table_lookup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 484bb9d164df397a53e0f533b262b27b1590efcb ]
Currently, when using multipath routes without nexthop objects, fib6_table_lookup() selects the nexthop with the highest score. This means that when both a source address and an oif are specified, the nexthop that is chosen is the one that matches in terms of oif:
# sysctl -wq net.ipv6.conf.all.forwarding=1 # ip address add 2001:db8:2::1/64 dev lo # ip route add 2001:db8:10::/64 nexthop via fe80::1 dev dummy1 nexthop via fe80::2 dev dummy2
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy1; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy1
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy2When using nexthop objects, fib6_table_lookup() selects the first matching nexthop and not necessarily the one with the highest score:
# ip nexthop add id 1 via fe80::1 dev dummy1 # ip nexthop add id 2 via fe80::2 dev dummy2 # ip nexthop add id 3 group 1/2 # ip route add 2001:db8:20::/64 nhid 3
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:20::${i} from 2001:db8:2::1 oif dummy1; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy1
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:20::${i} from 2001:db8:2::1 oif dummy2; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy1This is not very significant right now because the nexthop is later overwritten during path selection in fib6_select_path(). However, the next patch is going to skip path selection when we have an oif match during output route lookup.
As a preparation for this change, align the nexthop object behavior with the legacy one and make sure that fib6_table_lookup() always selects the best matching nexthop. Do that by always returning 0 from rt6_nh_find_match() in order not to terminate the loop in nexthop_for_each_fib6_nh() and storing in arg->nh the best matching nexthop so far.
Behavior after the change:
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:20::${i} from 2001:db8:2::1 oif dummy1; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy1
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:20::${i} from 2001:db8:2::1 oif dummy2; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy2--- net/ipv6/route.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
net/ipv6/route.c +9 -8
@@ -821,9 +821,11 @@ static int rt6_nh_find_match(struct fib6_nh *nh, void *_arg) {struct fib6_nh_frl_arg *arg = _arg; - arg->nh = nh; -return find_match (nh, arg->flags, arg->oif, arg->strict, - arg->mpri, arg->do_rr); +if (find_match (nh, arg->flags, arg->oif, arg->strict, arg->mpri, + arg->do_rr)) + arg->nh = nh; + +return 0 ; } static void __find_rr_leaf(struct fib6_info *f6i_start,
@@ -863,11 +865,10 @@ static void __find_rr_leaf(struct fib6_info *f6i_start, res->nh =nexthop_fib6_nh (f6i->nh);return ; } -if (nexthop_for_each_fib6_nh (f6i->nh, rt6_nh_find_match, - &arg)) { - matched = true; - nh = arg.nh; - } +nexthop_for_each_fib6_nh (f6i->nh, rt6_nh_find_match, + &arg); + matched = !!arg.nh; + nh = arg.nh; }else { nh = f6i->fib6_nh; if (find_match(nh, f6i->fib6_flags, oif, strict,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/1193 ipv6: Honor oif when choosing nexthop for locally generated traffic
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit d25e7e9d8a6c1e2afb854613e417c6aa1a28ce6f ]
Commit 741a11d9e410 ("net: ipv6: Add RT6_LOOKUP_F_IFACE flag if oif is set") made the kernel honor the oif parameter when specified as part of output route lookup:
# ip route add 2001:db8:1::/64 dev dummy1 # ip route add ::/0 dev dummy2 # ip route get 2001:db8:1::1 oif dummy2 fibmatch default dev dummy2 metric 1024 pref medium
Due to regression reports, the behavior was partially reverted in commit d46a9d678e4c ("net: ipv6: Dont add RT6_LOOKUP_F_IFACE flag if saddr set") to only honor the oif if source address is not specified:
# ip route get 2001:db8:1::1 from 2001:db8:2::1 oif dummy2 fibmatch 2001:db8:1::/64 dev dummy1 metric 1024 pref medium
That is, when source address is specified, the kernel will choose the most specific route even if its nexthop device does not match the specified oif.
This creates a problem for multipath routes. After looking up a route, when source address is not specified, the kernel will choose a nexthop whose nexthop device matches the specified oif:
# sysctl -wq net.ipv6.conf.all.forwarding=1
# ip route add 2001:db8:10::/64 nexthop via fe80::1 dev dummy1 nexthop via fe80::2 dev dummy2
# for i in {1..100}; do ip route get 2001:db8:10::${i} oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
100 dummy2But will disregard the oif when source address is specified despite the fact that a matching nexthop exists:
# for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
53 dummy1
47 dummy2This behavior differs from IPv4:
# ip address add 192.0.2.1/32 dev lo
# ip route add 198.51.100.0/24 nexthop via inet6 fe80::1 dev dummy1 nexthop via inet6 fe80::2 dev dummy2
# for i in {1..100}; do ip route get 198.51.100.${i} from 192.0.2.1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
100 dummy2What happens is that fib6_table_lookup() returns a route with a matching nexthop device (assuming it exists):
# perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done > /dev/null"
# perf script | grep -o dummy[0-9] | sort | uniq -c
100 dummy2But it is later overwritten during path selection in fib6_select_path() which instead chooses a nexthop according to the calculated hash.
Solve this by telling fib6_select_path() to skip path selection if we have an oif match during output route lookup (iif being LOOPBACK_IFINDEX).
Behavior after the change:
# sysctl -wq net.ipv6.conf.all.forwarding=1
# ip route add 2001:db8:10::/64 nexthop via fe80::1 dev dummy1 nexthop via fe80::2 dev dummy2
# for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
100 dummy2Note that enabling forwarding is only needed because we did not add neighbor entries for the gateway addresses. When forwarding is disabled and CONFIG_IPV6_ROUTER_PREF is not enabled in kernel config, the kernel will treat non-existing neighbor entries as errors and perform round-robin between the nexthops:
# sysctl -wq net.ipv6.conf.all.forwarding=0
# for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
50 dummy1
50 dummy2--- net/ipv6/route.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv6/route.c +4 -1
@@ -2257,6 +2257,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, {struct fib6_result res = {};struct rt6_info *rt =NULL ; +bool have_oif_match;int strict =0 ; WARN_ON_ONCE((flags & RT6_LOOKUP_F_DST_NOREF) &&
@@ -2273,7 +2274,9 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,if (res.f6i == net->ipv6.fib6_null_entry) goto out; -fib6_select_path (net, &res, fl6, oif, false, skb, strict); + have_oif_match = fl6->flowi6_iif ==LOOPBACK_IFINDEX && + oif == res.nh->fib_nh_dev->ifindex; +fib6_select_path (net, &res, fl6, oif, have_oif_match, skb, strict);/*Search through exception table */ rt =rt6_find_cached_rt (&res, &fl6->daddr, &fl6->saddr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/1193 xfrm: avoid RCU warnings around the per-netns netlink socket
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sabrina Dubroca <[email protected]>
[ Upstream commit d87f8bc47fbf012a7f115e311d0603d97e47c34c ]
net->xfrm.nlsk is used in 2 types of contexts:
- fully under RCU, with rcu_read_lock + rcu_dereference and a NULL check
- in the netlink handlers, with requests coming from a userspace socket
In the 2nd case, net->xfrm.nlsk is guaranteed to stay non-NULL and the object is alive, since we can't enter the netns destruction path while the user socket holds a reference on the netns.
After adding the __rcu annotation to netns_xfrm.nlsk (which silences sparse warnings in the RCU users and __net_init code), we need to tell sparse that the 2nd case is safe. Add a helper for that.
Stable-dep-of: d1ebd9081879 ("xfrm: fix compat ALLOCSPI request use-after-free")
--- include/net/netns/xfrm.h | 2 +- net/xfrm/xfrm_user.c | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-)
include/net/netns/xfrm.h +1 -1
@@ -59,7 +59,7 @@ struct netns_xfrm {struct list_head inexact_bins; -struct sock *nlsk; +struct sock __rcu *nlsk;struct sock *nlsk_stash;u32 sysctl_aevent_etime;
net/xfrm/xfrm_user.c +17 -8
@@ -35,6 +35,15 @@#endif #include <asm/unaligned.h> +static struct sock *xfrm_net_nlsk (const struct net *net,const struct sk_buff *skb) +{ +/* get the source of this request, see netlink_unicast_kernel */ +const struct sock *sk =NETLINK_CB (skb).sk; + +/* sk is refcounted, the netns stays alive and nlsk with it */ +return rcu_dereference_protected (net->xfrm.nlsk, sk->sk_net_refcnt); +} +static int verify_one_alg (struct nlattr **attrs,enum xfrm_attr_type_t type,struct netlink_ext_ack *extack) {
@@ -1483,7 +1492,7 @@ static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_spdinfo (r_skb, net, sportid, seq, *flags);BUG_ON (err <0 ); -return nlmsg_unicast (net->xfrm.nlsk, r_skb, sportid); +return nlmsg_unicast (xfrm_net_nlsk (net, skb), r_skb, sportid); }static inline unsigned int xfrm_sadinfo_msgsize (void )
@@ -1543,7 +1552,7 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_sadinfo (r_skb, net, sportid, seq, *flags);BUG_ON (err <0 ); -return nlmsg_unicast (net->xfrm.nlsk, r_skb, sportid); +return nlmsg_unicast (xfrm_net_nlsk (net, skb), r_skb, sportid); } static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1563,7 +1572,7 @@ static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,if (IS_ERR (resp_skb)) { err =PTR_ERR (resp_skb); }else { - err =nlmsg_unicast (net->xfrm.nlsk, resp_skb,NETLINK_CB (skb).portid); + err =nlmsg_unicast (xfrm_net_nlsk (net, skb), resp_skb,NETLINK_CB (skb).portid); }xfrm_state_put (x); out_noput:
@@ -1641,7 +1650,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, } } - err =nlmsg_unicast (net->xfrm.nlsk, resp_skb,NETLINK_CB (skb).portid); + err =nlmsg_unicast (xfrm_net_nlsk (net, skb), resp_skb,NETLINK_CB (skb).portid); out:xfrm_state_put (x);
@@ -2284,7 +2293,7 @@ static int xfrm_get_default(struct sk_buff *skb, struct nlmsghdr *nlh, r_up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (r_skb, r_nlh); -return nlmsg_unicast (net->xfrm.nlsk, r_skb, portid); +return nlmsg_unicast (xfrm_net_nlsk (net, skb), r_skb, portid); } static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -2350,7 +2359,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,if (IS_ERR (resp_skb)) { err =PTR_ERR (resp_skb); }else { - err =nlmsg_unicast (net->xfrm.nlsk, resp_skb, + err =nlmsg_unicast (xfrm_net_nlsk (net, skb), resp_skb,NETLINK_CB (skb).portid); } }else {
@@ -2510,7 +2519,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_aevent (r_skb, x, &c);BUG_ON (err <0 ); - err =nlmsg_unicast (net->xfrm.nlsk, r_skb,NETLINK_CB (skb).portid); + err =nlmsg_unicast (xfrm_net_nlsk (net, skb), r_skb,NETLINK_CB (skb).portid);spin_unlock_bh (&x->lock);xfrm_state_put (x);return err;
@@ -3151,7 +3160,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, goto err; } - err =netlink_dump_start (net->xfrm.nlsk, skb, nlh, &c); + err =netlink_dump_start (xfrm_net_nlsk (net, skb), skb, nlh, &c); goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/1193 xfrm: fix compat ALLOCSPI request use-after-free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit d1ebd9081879fd9ae9c8fb7e8928f19cc88ae320 ]
xfrm_state_netlink() builds the ALLOCSPI response with dump_one_state(), which already calls alloc_compat() with the response skb and header.
xfrm_alloc_userspi() then calls alloc_compat() again, but passes the original request skb and its header. For a compat request, the translator therefore interprets the 228-byte compat xfrm_userspi_info as the 232-byte native layout and reads four bytes past the declared payload. It also publishes the translated child through the request's frag_list.
A multicast clone of the request shares skb_shared_info and can observe that child. xfrm_user_rcv_msg() frees it after the request handler returns, racing a compat receiver which may still be copying from it and resulting in a use-after-free.
Remove the redundant conversion. The response keeps its correct compat translation from dump_one_state(), and no child is attached to the inbound request.
--- net/xfrm/xfrm_user.c | 12 ------------ 1 file changed, 12 deletions(-)
net/xfrm/xfrm_user.c +0 -12
@@ -1586,7 +1586,6 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,struct net *net =sock_net (skb->sk);struct xfrm_state *x;struct xfrm_userspi_info *p; -struct xfrm_translator *xtr;struct sk_buff *resp_skb;xfrm_address_t *daddr;int family;
@@ -1639,17 +1638,6 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } - xtr =xfrm_get_translator (); -if (xtr) { - err = xtr->alloc_compat (skb,nlmsg_hdr (skb)); - -xfrm_put_translator (xtr); -if (err) { -kfree_skb (resp_skb); - goto out; - } - } - err =nlmsg_unicast (xfrm_net_nlsk (net, skb), resp_skb,NETLINK_CB (skb).portid); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/1193 xfrm: add missing rcu_read_lock(), skb_dst_force() and dev_hold() for xfrm_trans_reinject()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit d2f5082f9e84653fa1a9e8aebaaff23e688f5e19 ]
syzbot reported a suspicious RCU usage warning in ip6_pkt_drop():
WARNING: suspicious RCU usage in ip6_pkt_drop include/net/addrconf.h:389 suspicious rcu_dereference_check() usage!
Call Trace: __in6_dev_get_safely include/net/addrconf.h:389 [inline] ip6_pkt_drop+0x596/0x610 net/ipv6/route.c:4620 ip6_pkt_discard+0x1c/0x30 net/ipv6/route.c:4651 xfrm_trans_reinject+0x324/0x630 net/xfrm/xfrm_input.c:806 process_one_work kernel/workqueue.c:3322 [inline] process_scheduled_works+0xa8e/0x14e0 kernel/workqueue.c:3405 worker_thread+0xa47/0xfb0 kernel/workqueue.c:3486
When commit 4f4920669d21 ("xfrm: Reinject transport-mode packets through workqueue") converted xfrm_trans_reinject from a tasklet to a workqueue, the reinjection loop ceased running in softirq context. Workqueue workers run in process context where local_bh_disable() does not enter an RCU read-side critical section under CONFIG_PREEMPT_RCU.
Because finish callbacks (such as ip6_rcv_finish) expect to run under an RCU read lock (performing route lookups, l3mdev lookups, and accessing RCU-protected data structures), invoking them in workqueue context without rcu_read_lock() triggers RCU lockdep warnings.
Furthermore, packets queued to the workqueue via xfrm_trans_queue_net() may carry non-refcounted (noref) dst entries (e.g. from ip_route_input_noref). Additionally, on netdevice unregistration, dst_dev_put() replaces dst->dev with blackhole_netdev, so dst entries do not keep skb->dev alive while queued in the workqueue.
Fix these issues by:
1. Calling skb_dst_force(skb) in xfrm_trans_queue_net() while still in the caller's RCU section to ensure dst is reference-counted before queuing.
2. Holding a reference on skb->dev via dev_hold()/dev_put() across workqueue deferral so skb->dev remains valid during finish() callback processing.
3. Acquiring rcu_read_lock() around the finish callback invocation loop in xfrm_trans_reinject().
--- net/xfrm/xfrm_input.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/xfrm/xfrm_input.c +11 -0
@@ -758,12 +758,17 @@ static void xfrm_trans_reinject(struct work_struct *work)spin_unlock_bh (&trans->queue_lock);local_bh_disable (); +rcu_read_lock ();while ((skb =__skb_dequeue (&queue))) {struct net *net =XFRM_TRANS_SKB_CB (skb)->net; +struct net_device *dev = skb->dev;XFRM_TRANS_SKB_CB (skb)->finish (net,NULL , skb); +if (dev) +dev_put (dev);put_net (net); } +rcu_read_unlock ();local_bh_enable (); }
@@ -779,12 +784,18 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb,if (skb_queue_len (&trans->queue) >=READ_ONCE (netdev_max_backlog))return -ENOBUFS ; +if (skb_dst (skb) && !skb_dst_force (skb)) +return -EHOSTUNREACH ; +BUILD_BUG_ON (sizeof (struct xfrm_trans_cb ) >sizeof (skb->cb)); hold_net =maybe_get_net (net);if (!hold_net)return -ENODEV ; +if (skb->dev) +dev_hold (skb->dev); +XFRM_TRANS_SKB_CB (skb)->finish = finish;XFRM_TRANS_SKB_CB (skb)->net = hold_net;spin_lock_bh (&trans->queue_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/1193 esp: downgrade zerocopy managed frags before mutating skb frags
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maher Azzouzi <[email protected]>
[ Upstream commit f89416eb3db151170a6f3c6dfc5239d26cdce4d2 ]
On the out-of-place output path (esp->inplace == false) ESP rewrites the skb frag array: esp_output_head() appends a trailer frag and esp_output_tail() replaces the frags with a destination page, both referenced with get_page().
When the skb carries zerocopy managed frags (SKBFL_MANAGED_FRAG_REFS) the payload frags are owned by the ubuf and must not be referenced or unreferenced individually, but ESP mutates the frag array without ever downgrading the skb. This breaks the managed-frag invariant two ways:
- esp_ssg_unref() walks the source scatterlist and drops a page reference for every frag, including the ubuf-owned payload frags, pushing their refcount below the GUP pin bias while the pages are still pinned, i.e. a use-after-free of the zerocopy pages;
- esp_output_tail() installs its destination page as frag 0 with get_page() but leaves SKBFL_MANAGED_FRAG_REFS set, so skb_release_data() takes the skip_unref branch and never drops that reference, leaking the x->xfrag page at packet rate.
Fix this the way every other frag-mutating site does (__ip_append_data(), __ip6_append_data(), tcp_sendmsg_locked()) and call skb_zcopy_downgrade_managed() before ESP touches the frag array: it takes a real reference on each existing frag and clears SKBFL_MANAGED_FRAG_REFS, so the per-frag unref in esp_ssg_unref() and the frag release in skb_release_data() are both balanced and no mixed-ownership frag array is left behind.
--- net/ipv4/esp4.c | 6 ++++++ net/ipv6/esp6.c | 6 ++++++ 2 files changed, 12 insertions(+)
net/ipv4/esp4.c +6 -0
@@ -438,6 +438,12 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * esp->inplace = false; +/* Take real page refs and clear SKBFL_MANAGED_FRAG_REFS before +* we mutate the frag array, so the per-frag unref stays balanced +* for zerocopy managed frags (see __ip_append_data()). +*/ +skb_zcopy_downgrade_managed (skb); + allocsize =ALIGN (tailen,L1_CACHE_BYTES );spin_lock_bh (&x->lock);
net/ipv6/esp6.c +6 -0
@@ -473,6 +473,12 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info esp->inplace = false; +/* Take real page refs and clear SKBFL_MANAGED_FRAG_REFS before +* we mutate the frag array, so the per-frag unref stays balanced +* for zerocopy managed frags (see __ip_append_data()). +*/ +skb_zcopy_downgrade_managed (skb); + allocsize =ALIGN (tailen,L1_CACHE_BYTES );spin_lock_bh (&x->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/1193 ARM: socfpga: select the PL310 erratum 753970 workaround
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit cfc1e9a543e3589ba200795b6e7fd8ef4314efdf ]
ARCH_INTEL_SOCFPGA selects CACHE_L2X0 and several PL310 erratum workarounds. The 753970 workaround is still conditioned on PL310, but that Kconfig symbol no longer exists, so this one selection is always disabled.
Select PL310_ERRATA_753970 directly, consistently with the other PL310 workarounds required by the platform.
--- arch/arm/mach-socfpga/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-socfpga/Kconfig +1 -1
@@ -16,7 +16,7 @@ menuconfig ARCH_INTEL_SOCFPGA select ARM_ERRATA_775420 select PL310_ERRATA_588369 select PL310_ERRATA_727915 - select PL310_ERRATA_753970 if PL310 + select PL310_ERRATA_753970 select PL310_ERRATA_769419 select RESET_CONTROLLER
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/1193 RDMA/siw: Introduce siw_cep_set_free_and_put
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guoqing Jiang <[email protected]>
[ Upstream commit b5c91543204c345f1b28af573854c4b7e699cc91 ]
Add the helper which can be used in some places.
Stable-dep-of: 32cd87f54dd1 ("RDMA/siw: Clear association under lock if siw_qp_modify fails in siw_accept")
--- drivers/infiniband/sw/siw/siw_cm.c | 31 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-)
drivers/infiniband/sw/siw/siw_cm.c +14 -17
@@ -453,6 +453,12 @@ void siw_cep_put(struct siw_cep *cep)kref_put (&cep->ref, __siw_cep_dealloc); } +static void siw_cep_set_free_and_put (struct siw_cep *cep) +{ +siw_cep_set_free (cep); +siw_cep_put (cep); +} +void siw_cep_get (struct siw_cep *cep) {kref_get (&cep->ref);
@@ -1522,9 +1528,7 @@ int siw_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params) cep->state =SIW_EPSTATE_CLOSED ; -siw_cep_set_free (cep); - -siw_cep_put (cep); +siw_cep_set_free_and_put (cep); }else if (s) {sock_release (s);
@@ -1572,16 +1576,14 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)if (cep->state !=SIW_EPSTATE_RECVD_MPAREQ ) {siw_dbg_cep (cep,"out of state\n" ); -siw_cep_set_free (cep); -siw_cep_put (cep); +siw_cep_set_free_and_put (cep);return -ECONNRESET ; } qp =siw_qp_id2obj (sdev, params->qpn);if (!qp) {WARN (1 ,"[QP %d] does not exist\n" , params->qpn); -siw_cep_set_free (cep); -siw_cep_put (cep); +siw_cep_set_free_and_put (cep);return -EINVAL ; }
@@ -1724,8 +1726,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params) cep->qp =NULL ;siw_qp_put (qp); -siw_cep_set_free (cep); -siw_cep_put (cep); +siw_cep_set_free_and_put (cep);return rv; }
@@ -1748,8 +1749,7 @@ int siw_reject(struct iw_cm_id *id, const void *pdata, u8 pd_len)if (cep->state !=SIW_EPSTATE_RECVD_MPAREQ ) {siw_dbg_cep (cep,"out of state\n" ); -siw_cep_set_free (cep); -siw_cep_put (cep);/* put last reference */ +siw_cep_set_free_and_put (cep);/* put last reference */ return -ECONNRESET ; }
@@ -1766,8 +1766,7 @@ int siw_reject(struct iw_cm_id *id, const void *pdata, u8 pd_len) cep->state =SIW_EPSTATE_CLOSED ; -siw_cep_set_free (cep); -siw_cep_put (cep); +siw_cep_set_free_and_put (cep);return 0 ; }
@@ -1899,8 +1898,7 @@ int siw_create_listen(struct iw_cm_id *id, int backlog)siw_socket_disassoc (s); cep->state =SIW_EPSTATE_CLOSED ; -siw_cep_set_free (cep); -siw_cep_put (cep); +siw_cep_set_free_and_put (cep); }sock_release (s);
@@ -1931,8 +1929,7 @@ static void siw_drop_listeners(struct iw_cm_id *id) cep->sock =NULL ; } cep->state =SIW_EPSTATE_CLOSED ; -siw_cep_set_free (cep); -siw_cep_put (cep); +siw_cep_set_free_and_put (cep); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/1193 RDMA/siw: Cleanup siw_accept
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guoqing Jiang <[email protected]>
[ Upstream commit 77b59bd932a026b64303d313d966decb0e9225fa ]
With the initialization of rv and the two added label, we can simplifiy code a bit.
Stable-dep-of: 32cd87f54dd1 ("RDMA/siw: Clear association under lock if siw_qp_modify fails in siw_accept")
--- drivers/infiniband/sw/siw/siw_cm.c | 41 ++++++++++-------------------- 1 file changed, 14 insertions(+), 27 deletions(-)
drivers/infiniband/sw/siw/siw_cm.c +14 -27
@@ -1559,7 +1559,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)struct siw_cep *cep = (struct siw_cep *)id->provider_data;struct siw_qp *qp;struct siw_qp_attrs qp_attrs; -int rv, max_priv_data =MPA_MAX_PRIVDATA ; +int rv = -EINVAL , max_priv_data =MPA_MAX_PRIVDATA ;bool wait_for_peer_rts = false;siw_cep_set_inuse (cep);
@@ -1575,24 +1575,17 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)if (cep->state !=SIW_EPSTATE_RECVD_MPAREQ ) {siw_dbg_cep (cep,"out of state\n" ); - -siw_cep_set_free_and_put (cep); - -return -ECONNRESET ; + rv = -ECONNRESET ; + goto free_cep; } qp =siw_qp_id2obj (sdev, params->qpn);if (!qp) {WARN (1 ,"[QP %d] does not exist\n" , params->qpn); -siw_cep_set_free_and_put (cep); - -return -EINVAL ; + goto free_cep; }down_write (&qp->state_lock); -if (qp->attrs.state >SIW_QP_STATE_RTR ) { - rv = -EINVAL ; -up_write (&qp->state_lock); - goto error; - } +if (qp->attrs.state >SIW_QP_STATE_RTR ) + goto error_unlock;siw_dbg_cep (cep,"[QP %d]\n" , params->qpn);if (try_gso && cep->mpa.hdr.params.bits &MPA_RR_FLAG_GSO_EXP ) {
@@ -1606,9 +1599,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)"[QP %u]: ord %d (max %d), ird %d (max %d)\n" ,qp_id (qp), params->ord, sdev->attrs.max_ord, params->ird, sdev->attrs.max_ird); - rv = -EINVAL ; -up_write (&qp->state_lock); - goto error; + goto error_unlock; }if (cep->enhanced_rdma_conn_est) max_priv_data -=sizeof (struct mpa_v2_data );
@@ -1618,9 +1609,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params) cep,"[QP %u]: private data length: %d (max %d)\n" , qp_id(qp), params->private_data_len, max_priv_data); - rv = -EINVAL ; -up_write (&qp->state_lock); - goto error; + goto error_unlock; }if (cep->enhanced_rdma_conn_est) {if (params->ord > cep->ord) {
@@ -1629,9 +1618,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params) }else { cep->ird = params->ird; cep->ord = params->ord; - rv = -EINVAL ; -up_write (&qp->state_lock); - goto error; + goto error_unlock; } }if (params->ird < cep->ird) {
@@ -1640,8 +1627,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params) params->ird = cep->ird; else { rv = -ENOMEM ; -up_write (&qp->state_lock); - goto error; + goto error_unlock; } } if (cep->mpa.v2_ctrl.ord &
@@ -1688,7 +1674,6 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)SIW_QP_ATTR_ORD |SIW_QP_ATTR_IRD | SIW_QP_ATTR_MPA);up_write (&qp->state_lock); -if (rv) goto error;
@@ -1711,6 +1696,9 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)siw_cep_set_free (cep);return 0 ; + +error_unlock: +up_write (&qp->state_lock); error:siw_socket_disassoc (cep->sock);sock_release (cep->sock);
@@ -1725,9 +1713,8 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params) } cep->qp =NULL ;siw_qp_put (qp); - +free_cep:siw_cep_set_free_and_put (cep); -return rv; }
Signature · 1 line
2.53.0