6.1.189-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 517/982 drm/i915: Fix memory leak in query_perf_config_list()
In reply to Greg Kroah-Hartman6.1-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
@@ -400,8 +400,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 518/982 ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters()
In reply to Greg Kroah-Hartman6.1-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
@@ -912,14 +912,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 519/982 net: hso: fix TIOCMIWAIT race
In reply to Greg Kroah-Hartman6.1-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
@@ -1555,10 +1555,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 520/982 net: mpls: clear inner_protocol when the last label is popped
In reply to Greg Kroah-Hartman6.1-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
@@ -6085,6 +6085,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 521/982 net: openvswitch: fix use-after-free of the flow table mask array
In reply to Greg Kroah-Hartman6.1-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
@@ -261,11 +261,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 522/982 netfilter: nf_log: unregister loggers before per-net teardown
In reply to Greg Kroah-Hartman6.1-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
@@ -1197,8 +1197,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 523/982 netfilter: report NLM_F_DUMP_FILTERED when all is filtered out
In reply to Greg Kroah-Hartman6.1-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 524/982 fbdev: vfb: defer cleanup until the last reference
In reply to Greg Kroah-Hartman6.1-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 = { .fb_read = fb_sys_read, .fb_write = fb_sys_write,
@@ -89,6 +96,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 int vfb_remove(struct platform_deif (info) {unregister_framebuffer (info); -vfree (videomemory); -fb_dealloc_cmap (&info->cmap); -framebuffer_release (info); }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 525/982 ieee802154: 6lowpan: fix NULL dereference in lowpan_newlink
In reply to Greg Kroah-Hartman6.1-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 526/982 ipv4: fib: bound automatic table ID allocation
In reply to Greg Kroah-Hartman6.1-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 527/982 ipvs: reject invalid states in connection template sync records
In reply to Greg Kroah-Hartman6.1-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 528/982 KVM: PPC: Book3S HV: Set irqfd->producer only on success
In reply to Greg Kroah-Hartman6.1-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
@@ -5756,12 +5756,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 529/982 s390/qeth: allow bridgeport queries despite OS_MISMATCH
In reply to Greg Kroah-Hartman6.1-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 ))
@@ -1543,6 +1543,7 @@ struct _qeth_sbp_cbctl {struct {enum qeth_sbp_roles *role;enum qeth_sbp_states *state; +bool *os_mismatch; } qports; } data; };
@@ -1719,10 +1720,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;
@@ -1738,6 +1748,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 ; }
@@ -1746,13 +1759,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 = {
@@ -1760,6 +1777,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 =sprintf (buf,"%s\n" , word); }
Greg Kroah-Hartman
maintainerPATCH 530/982 s390/crypto: Fix missing scrub of temp buffers with AES ctr and gcm algorithm
In reply to Greg Kroah-Hartman6.1-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
@@ -608,6 +608,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;
@@ -909,10 +910,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 );
@@ -924,7 +929,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 531/982 hwmon: (applesmc) fix key backlight workqueue leak on register failure
In reply to Greg Kroah-Hartman6.1-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 532/982 hwmon: (gpio-fan) Fix use-after-free in alarm work
In reply to Greg Kroah-Hartman6.1-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/mutex.h>
@@ -79,6 +80,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;/*
@@ -89,7 +91,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 533/982 hwmon: (pmbus) Clear generic status alarms with CLEAR_FAULTS
In reply to Greg Kroah-Hartman6.1-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
@@ -1095,7 +1095,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 534/982 media: hevc: add bounded tile-count helpers
In reply to Greg Kroah-Hartman6.1-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 535/982 media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer capacity
In reply to Greg Kroah-Hartman6.1-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"
@@ -29,8 +31,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 536/982 media: v4l2-h264: Fix memcmp() size in B1 reference list comparison
In reply to Greg Kroah-Hartman6.1-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 537/982 media: v4l2-ctrls: validate HEVC tile counts
In reply to Greg Kroah-Hartman6.1-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
@@ -837,6 +837,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 538/982 bnxt_en: Only restore LRO if the device supports TPA
In reply to Greg Kroah-Hartman6.1-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
@@ -4094,7 +4094,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 539/982 bnxt_en: Handle buffer allocation failure in bnxt_rx_ring_reset()
In reply to Greg Kroah-Hartman6.1-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 540/982 bnxt_en: Propagate RX ring init failures in bnxt_init_nic()
In reply to Greg Kroah-Hartman6.1-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
@@ -8964,8 +8964,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 541/982 mptcp: options: handle MPC data + csum reqd + no csum
In reply to Greg Kroah-Hartman6.1-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
@@ -80,7 +80,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 542/982 mptcp: subflow: no need to copy thmac during ulp_clone
In reply to Greg Kroah-Hartman6.1-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
@@ -1910,7 +1910,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 543/982 mptcp: syncookies: remember the request backup flag
In reply to Greg Kroah-Hartman6.1-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 544/982 selftests: mptcp: fix an UAF in mptcp_connect.c
In reply to Greg Kroah-Hartman6.1-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
@@ -344,6 +344,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);
@@ -367,7 +370,6 @@ static int sock_connect_mptcp(const char sock =-1 ; } -freeaddrinfo (addr);if (sock !=-1 )SOCK_TEST_TCPULP (sock, proto);return sock;
Greg Kroah-Hartman
maintainerPATCH 545/982 smb: client: reject userspace cifs.idmap descriptions
In reply to Greg Kroah-Hartman6.1-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
@@ -96,8 +96,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 546/982 smb: client: avoid leaking refcount in cifs_queue_oplock_break()
In reply to Greg Kroah-Hartman6.1-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
@@ -639,10 +639,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 547/982 smb: client: avoid leaking refcount when cifs_sb_tlink() fails
In reply to Greg Kroah-Hartman6.1-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
@@ -5188,8 +5188,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 548/982 bpftool: remove duplicate free_btf_vmlinux() definition
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suraj Jitindar Singh <[email protected]>
v6.1.188 backported
660a19e46942 ("tools/bpf/bpftool: Reset vmlinux BTF after map commands") [ upstream commit 66d7e39e49b0 ]
which re-adds free_btf_vmlinux(). However, the prerequisite cleanup
52df1a8aabad ("bpftool: remove function free_btf_vmlinux()")
was never backported to 6.1.y, so the tree still carried the original free_btf_vmlinux() definition. The backport therefore produced two identical-signature static definitions in tools/bpf/bpftool/map.c and the build fails:
map.c: error: redefinition of 'free_btf_vmlinux'
Remove the stale pre-existing definition, keeping the one reintroduced by 660a19e46942 (which also resets btf_vmlinux = NULL). This matches the current mainline end state.
--- tools/bpf/bpftool/map.c | 5 ----- 1 file changed, 5 deletions(-)
tools/bpf/bpftool/map.c +0 -5
@@ -817,11 +817,6 @@ static void free_map_kv_btf(struct btf *btf)btf__free (btf); } -static void free_btf_vmlinux (void ) -{ -btf__free (btf_vmlinux); -} -static int map_dump (int fd,struct bpf_map_info *info,json_writer_t *wtr,bool show_header)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/982 Revert "arm64: dts: qcom: sm8550: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit d831304f2079e114fa74e585bf667a83fdbc25c8.
--- arch/arm64/boot/dts/qcom/sm8550.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8550.dtsi +4 -4
@@ -1432,8 +1432,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";
@@ -1537,8 +1537,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 550/982 Revert "arm64: dts: qcom: sm8450: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 2eec945bc94f35ae597e4ce49bc4f4b581ee82a0.
--- arch/arm64/boot/dts/qcom/sm8450.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8450.dtsi +4 -4
@@ -1759,8 +1759,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";
@@ -1865,8 +1865,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 551/982 Revert "arm64: dts: qcom: sm8350: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 98d41e690de05a6367300ab85bdeddff1af933a4.
--- arch/arm64/boot/dts/qcom/sm8350.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8350.dtsi +4 -4
@@ -1635,8 +1635,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";
@@ -1718,8 +1718,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 552/982 Revert "arm64: dts: qcom: sm8250: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 6a8666fc1c629863022899046f8c46f3bb45a68e.
--- arch/arm64/boot/dts/qcom/sm8250.dtsi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm64/boot/dts/qcom/sm8250.dtsi +6 -6
@@ -1850,8 +1850,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";
@@ -1956,8 +1956,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";
@@ -2064,8 +2064,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 553/982 Revert "arm64: dts: qcom: sm8150: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 7312115432d2ad14ccf92b2359d57bb039a239e3.
--- arch/arm64/boot/dts/qcom/sm8150.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/sm8150.dtsi +4 -4
@@ -1810,8 +1810,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";
@@ -1912,8 +1912,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 554/982 Revert "arm64: dts: qcom: sdm845: Fix the PCIe iommu-map entries"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 34c6835023896943696e4f2c192dc850240982cc.
--- arch/arm64/boot/dts/qcom/sdm845.dtsi | 64 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 32 deletions(-)
arch/arm64/boot/dts/qcom/sdm845.dtsi +32 -32
@@ -2254,22 +2254,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";
@@ -2363,22 +2363,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 555/982 ipv6: mcast: extend RCU protection in igmp6_send()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 087c1faa594fa07a66933d750c0b2610aa1a2946 ]
igmp6_send() can be called without RTNL or RCU being held.
Extend RCU protection so that we can safely fetch the net pointer and avoid a potential UAF.
Note that we no longer can use sock_alloc_send_skb() because ipv6.igmp_sk uses GFP_KERNEL allocations which can sleep.
Instead use alloc_skb() and charge the net->ipv6.igmp_sk socket under RCU protection.
[ use IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, full_len)
instead of upstream's IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTPKTS). Older LTS kernels do not have commit b4a11b2033b7 ("net: fix IPSTATS_MIB_OUTPKGS increment in OutForwDatagrams"), so the legacy byte-based counter logic must be preserved. ]
--- net/ipv6/mcast.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
net/ipv6/mcast.c +15 -17
@@ -2154,21 +2154,21 @@ static void mld_send_cr(struct inet6_dev *idev)static void igmp6_send (struct in6_addr *addr,struct net_device *dev,int type) { -struct net *net =dev_net (dev); -struct sock *sk = net->ipv6.igmp_sk; +const struct in6_addr *snd_addr, *saddr; +int err, len, payload_len, full_len; +struct in6_addr addr_buf;struct inet6_dev *idev;struct sk_buff *skb;struct mld_msg *hdr; -const struct in6_addr *snd_addr, *saddr; -struct in6_addr addr_buf;int hlen =LL_RESERVED_SPACE (dev);int tlen = dev->needed_tailroom; -int err, len, payload_len, full_len;u8 ra[8 ] = {IPPROTO_ICMPV6 ,0 ,IPV6_TLV_ROUTERALERT ,2 ,0 ,0 ,IPV6_TLV_PADN ,0 }; -struct flowi6 fl6;struct dst_entry *dst; +struct flowi6 fl6; +struct net *net; +struct sock *sk;if (type ==ICMPV6_MGM_REDUCTION ) snd_addr = &in6addr_linklocal_allrouters;
@@ -2179,20 +2179,21 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) payload_len = len +sizeof (ra); full_len =sizeof (struct ipv6hdr ) + payload_len; -rcu_read_lock (); -IP6_UPD_PO_STATS (net,__in6_dev_get (dev), -IPSTATS_MIB_OUT , full_len); -rcu_read_unlock (); + skb =alloc_skb (hlen + tlen + full_len,GFP_KERNEL ); - skb =sock_alloc_send_skb (sk, hlen + tlen + full_len,1 , &err); +rcu_read_lock (); + net =dev_net_rcu (dev); + idev =__in6_dev_get (dev); +IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , full_len);if (!skb) { -rcu_read_lock (); -IP6_INC_STATS (net,__in6_dev_get (dev), -IPSTATS_MIB_OUTDISCARDS ); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTDISCARDS );rcu_read_unlock ();return ; } + sk = net->ipv6.igmp_sk; +skb_set_owner_w (skb, sk); + skb->priority =TC_PRIO_CONTROL ;skb_reserve (skb, hlen);
@@ -2217,9 +2218,6 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)IPPROTO_ICMPV6 , csum_partial(hdr, len, 0)); -rcu_read_lock (); - idev =__in6_dev_get (skb->dev); -icmpv6_flow_init (sk, &fl6, type, &ipv6_hdr (skb)->saddr, &ipv6_hdr (skb)->daddr, skb->dev->ifindex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/982 Revert "nvme-apple: Reset q->sq_tail during queue init"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 225b7af1dbd589c33faabe90b5bd85bd6a73b8b6.
--- drivers/nvme/host/apple.c | 1 - 1 file changed, 1 deletion(-)
drivers/nvme/host/apple.c +0 -1
@@ -1009,7 +1009,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 557/982 Revert "nvme-apple: Prevent shared tags across queues on Apple A11"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 91d3b243bffe5c94503c9a8ea478a080f79ec58e.
--- 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);
@@ -1114,7 +1114,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 );
@@ -1297,7 +1300,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 558/982 Revert "nvme-apple: Drop the PRP null check chicken bit"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 201edb5f22d4d126a48fb69850a2a7f190982e59.
--- 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)
@@ -1111,6 +1114,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 559/982 Revert "nvme: apple: Add Apple A11 support"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 655b6743bd900df39354e8bb6f1f2f8671fca004.
--- 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:
@@ -1010,13 +973,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); }
@@ -1098,55 +1059,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" );
@@ -1314,9 +1269,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 );
@@ -1341,7 +1295,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),
@@ -1349,28 +1302,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
@@ -1454,12 +1401,6 @@ static int apple_nvme_probe(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" );
@@ -1491,17 +1432,10 @@ static int apple_nvme_probe(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)) {
@@ -1659,19 +1593,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 560/982 Revert "perf tests: Fix flakiness in BPF counters test on hybrid systems"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 08c1316f983d3e1777f9087bb466dc5cf9a476f8.
--- 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 561/982 usb: xusbatm: dont rely on id table pointer arithmetic
In reply to Greg Kroah-Hartman6.1-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 562/982 wifi: ath9k_htc: dont store usb_device_id
In reply to Greg Kroah-Hartman6.1-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
@@ -1099,7 +1099,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 ;
@@ -1194,7 +1194,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 ;
@@ -1210,7 +1210,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" ;
@@ -1267,9 +1267,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;
@@ -1383,7 +1383,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 563/982 usb: usbtmc: dont store usb_device_id
In reply to Greg Kroah-Hartman6.1-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 564/982 media: as102: do not rely on id table address comparison
In reply to Greg Kroah-Hartman6.1-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 = {
@@ -338,29 +336,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 565/982 net: usb: pegasus: dont rely on id table pointer arithmetic
In reply to Greg Kroah-Hartman6.1-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 566/982 ALSA: us122l: Prevent write upgrades for read mappings
In reply to Greg Kroah-Hartman6.1-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; + } + area->vm_flags &= ~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 567/982 i2c: smbus: reject oversized block transfers in the common path
In reply to Greg Kroah-Hartman6.1-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 568/982 net: appletalk: fix NULL pointer dereference in aarp_send_ddp()
In reply to Greg Kroah-Hartman6.1-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 569/982 fou: Fix use-after-free in fou_create()
In reply to Greg Kroah-Hartman6.1-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 570/982 crypto: sun8i-ce - Remove crypto_rng interface
In reply to Greg Kroah-Hartman6.1-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 | 160 ---------------------- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 29 --- 5 files changed, 253 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 -160
160 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
@@ -132,13 +125,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 {
@@ -147,11 +137,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; };
@@ -302,16 +290,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
@@ -331,7 +309,6 @@ struct sun8i_ce_alg_template {union {struct skcipher_alg skcipher;struct ahash_alg hash; -struct rng_alg rng; } alg;unsigned long stat_req;unsigned long stat_fb;
@@ -374,11 +351,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 571/982 crypto: sun8i-ss - Remove crypto_rng interface
In reply to Greg Kroah-Hartman6.1-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 | 170 ---------------------- drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h | 23 -- 5 files changed, 241 deletions(-) delete mode 100644 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
drivers/crypto/allwinner/Kconfig +0 -8
@@ -105,14 +105,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
@@ -22,7 +22,6 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/reset.h> -#include <crypto/internal/rng.h> #include <crypto/internal/skcipher.h> #include "sun8i-ss.h"
@@ -269,25 +268,6 @@ static struct sun8i_ss_alg_template ss_a .decrypt = sun8i_ss_skdecrypt, } }, -#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,
@@ -473,12 +453,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.halg.base.cra_driver_name,
@@ -678,14 +652,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];
@@ -727,11 +693,6 @@ static void sun8i_ss_unregister_algs(str ss_algs[i].alg.skcipher.base.cra_name);crypto_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.halg.base.cra_name);
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c deleted +0 -170
170 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/*
@@ -218,16 +211,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 * @enginectx: crypto_engine used by this TFM * @fallback_tfm: pointer to the fallback TFM
@@ -280,7 +263,6 @@ struct sun8i_ss_alg_template {struct sun8i_ss_dev *ss;union {struct skcipher_alg skcipher; -struct rng_alg rng;struct ahash_alg hash; } alg;unsigned long stat_req;
@@ -307,11 +289,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_crainit (struct crypto_tfm *tfm);void sun8i_ss_hash_craexit (struct crypto_tfm *tfm);
Greg Kroah-Hartman
maintainerPATCH 572/982 netfilter: nft_set_pipapo_avx2: add missing vzeroupper
In reply to Greg Kroah-Hartman6.1-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 573/982 mptcp: consolidate subflow cleanup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit c3349a22c2002947d29a98a77bfb36d97cfbfac1 upstream.
Consolidate all the cleanup actions requiring the worker in a single helper and ensure the dummy data fin creation for fallback socket is performed only when the tcp rx queue is empty.
There are no functional changes intended, but this will simplify the next patch, when the tcp rx queue spooling could be delayed at release_cb time.
Stable-dep-of: 2b0f561f21b2 ("mptcp: avoid unneeded actions on subflow reset") [ Note: also remove struct mptcp_sock *msk from subflow_state_change: it
is no longer used after this modification. ]
--- net/mptcp/subflow.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
net/mptcp/subflow.c +18 -17
@@ -1159,7 +1159,12 @@ out: subflow->map_valid =0 ; } -/* sched mptcp worker to remove the subflow if no more data is pending */ +static bool subflow_is_done (const struct sock *sk) +{ +return sk->sk_shutdown &RCV_SHUTDOWN || sk->sk_state ==TCP_CLOSE ; +} + +/* sched mptcp worker for subflow cleanup if no more data is pending */ static void subflow_sched_work_if_closed (struct mptcp_sock *msk,struct sock *ssk) {struct sock *sk = (struct sock *)msk;
@@ -1169,8 +1174,18 @@ static void subflow_sched_work_if_closed inet_sk_state_load(sk) != TCP_ESTABLISHED))) return; -if (skb_queue_empty (&ssk->sk_receive_queue) && - !test_and_set_bit (MPTCP_WORK_CLOSE_SUBFLOW , &msk->flags)) +if (!skb_queue_empty (&ssk->sk_receive_queue)) +return ; + +if (!test_and_set_bit (MPTCP_WORK_CLOSE_SUBFLOW , &msk->flags)) +mptcp_schedule_work (sk); + +/* when the fallback subflow closes the rx side, trigger a 'dummy' +* ingress data fin, so that the msk state will follow along +*/ +if (__mptcp_check_fallback (msk) &&subflow_is_done (ssk) && + msk->first == ssk && +mptcp_update_rcv_data_fin (msk,READ_ONCE (msk->ack_seq), true))mptcp_schedule_work (sk); }
@@ -1688,20 +1703,13 @@ static void __subflow_state_change(strucrcu_read_unlock (); } -static bool subflow_is_done (const struct sock *sk) -{ -return sk->sk_shutdown &RCV_SHUTDOWN || sk->sk_state ==TCP_CLOSE ; -} -static void subflow_state_change (struct sock *sk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);struct sock *parent = subflow->conn; -struct mptcp_sock *msk;__subflow_state_change (sk); - msk =mptcp_sk (parent);/* 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.
@@ -1712,13 +1720,6 @@ static void subflow_state_change(structsubflow_error_report (sk);subflow_sched_work_if_closed (mptcp_sk (parent), sk); - -/* when the fallback subflow closes the rx side, trigger a 'dummy' -* ingress data fin, so that the msk state will follow along -*/ -if (__mptcp_check_fallback (msk) &&subflow_is_done (sk) && msk->first == sk && -mptcp_update_rcv_data_fin (msk,READ_ONCE (msk->ack_seq), true)) -mptcp_schedule_work (parent); }void mptcp_subflow_queue_clean (struct sock *listener_sk,struct sock *listener_ssk)
Greg Kroah-Hartman
maintainerPATCH 574/982 mptcp: avoid unneeded actions on subflow reset
In reply to Greg Kroah-Hartman6.1-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. The context is also a bit different with data_avail being an enum, but that's without consequences here. ]
--- 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
@@ -754,13 +754,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
@@ -492,7 +492,8 @@ struct mptcp_subflow_context { stale : 1, /* unable to snd/rcv data, do not use for xmit */ valid_csum_seen : 1, /* at least one csum validated */ close_event_done : 1, /* has done the post-closed part */ - __unused : 9; + resetting : 1, /* subflow is resetting */ + __unused : 8;enum mptcp_data_avail data_avail;bool pm_listener;/* a listener managed by the kernel PM? */ u32 remote_nonce;
net/mptcp/subflow.c +11 -0
@@ -379,6 +379,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))
@@ -1710,6 +1714,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 575/982 mptcp: close race between scheduler and state change
In reply to Greg Kroah-Hartman6.1-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
@@ -1636,7 +1636,9 @@ static struct sock *mptcp_subflow_get_sestatic 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 576/982 landlock: Fix handling of disconnected directories
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mickaël Salaün <[email protected]>
[ Upstream commit 49c9e09d961025b22e61ef9ad56aa1c21b6ce2f1 ]
Disconnected files or directories can appear when they are visible and opened from a bind mount, but have been renamed or moved from the source of the bind mount in a way that makes them inaccessible from the mount point (i.e. out of scope).
Previously, access rights tied to files or directories opened through a disconnected directory were collected by walking the related hierarchy down to the root of the filesystem, without taking into account the mount point because it couldn't be found. This could lead to inconsistent access results, potential access right widening, and hard-to-debug renames, especially since such paths cannot be printed.
For a sandboxed task to create a disconnected directory, it needs to have write access (i.e. FS_MAKE_REG, FS_REMOVE_FILE, and FS_REFER) to the underlying source of the bind mount, and read access to the related
mount point. Because a sandboxed task cannot acquire more access
rights than those defined by its Landlock domain, this could lead to inconsistent access rights due to missing permissions that should be inherited from the mount point hierarchy, while inheriting permissions from the filesystem hierarchy hidden by this mount point instead.
Landlock now handles files and directories opened from disconnected directories by taking into account the filesystem hierarchy when the mount point is not found in the hierarchy walk, and also always taking into account the mount point from which these disconnected directories were opened. This ensures that a rename is not allowed if it would widen access rights [1].
The rationale is that, even if disconnected hierarchies might not be visible or accessible to a sandboxed task, relying on the collected access rights from them improves the guarantee that access rights will not be widened during a rename because of the access right comparison between the source and the destination (see LANDLOCK_ACCESS_FS_REFER). It may look like this would grant more access on disconnected files and directories, but the security policies are always enforced for all the evaluated hierarchies. This new behavior should be less surprising to users and safer from an access control perspective.
Remove a wrong WARN_ON_ONCE() canary in collect_domain_accesses() and fix the related comment.
Because opened files have their access rights stored in the related file security properties, there is no impact for disconnected or unlinked files.
--- security/landlock/errata/abi-1.h | 15 ++++++++++++ security/landlock/fs.c | 40 +++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 11 deletions(-)
security/landlock/errata/abi-1.h +15 -0
@@ -1,5 +1,20 @@/* SPDX-License-Identifier: GPL-2.0-only */ +/** +* DOC: erratum_3 +* +* Erratum 3: Disconnected directory handling +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This fix addresses an issue with disconnected directories that occur when a +* directory is moved outside the scope of a bind mount. The change ensures +* that evaluated access rights include both those from the disconnected file +* hierarchy down to its filesystem root and those from the related mount point +* hierarchy. This prevents access right widening through rename or link +* actions. +*/ +LANDLOCK_ERRATUM (3 ) +/** * DOC: erratum_4 *
security/landlock/fs.c +29 -11
@@ -607,19 +607,31 @@ static int check_access_path_dual(break ; } } +if (unlikely (IS_ROOT (walker_path.dentry))) { +if (likely (walker_path.mnt->mnt_flags &MNT_INTERNAL )) { +/* +* Stops and allows access when reaching disconnected root +* directories that are part of internal filesystems (e.g. nsfs, +* which is reachable through /proc/<pid>/ns/<namespace>). +*/ + allowed_parent1 = true; + allowed_parent2 = true; +break ; + } +/* -* Stops at disconnected root directories. Only allows -* access to internal filesystems (e.g. nsfs, which is -* reachable through /proc/<pid>/ns/<namespace>). +* We reached a disconnected root directory from a bind mount. +* Let's continue the walk with the mount point we missed. */ - allowed_parent1 = allowed_parent2 = - !!(walker_path.mnt->mnt_flags &MNT_INTERNAL ); -break ; +dput (walker_path.dentry); + walker_path.dentry = walker_path.mnt->mnt_root; +dget (walker_path.dentry); + }else { + parent_dentry =dget_parent (walker_path.dentry); +dput (walker_path.dentry); + walker_path.dentry = parent_dentry; } - parent_dentry =dget_parent (walker_path.dentry); -dput (walker_path.dentry); - walker_path.dentry = parent_dentry; }path_put (&walker_path);
@@ -721,6 +733,9 @@ static inline access_mask_t maybe_remove(const struct dentry *const dentry)* file. While walking from @dir to @mnt_root, we record all the domain's * allowed accesses in @layer_masks_dom. * +* Because of disconnected directories, this walk may not reach @mnt_dir. In +* this case, the walk will continue to @mnt_dir after this call. +* * This is similar to check_access_path_dual() but much simpler because it only * handles walking on the same mount point and only checks one set of accesses. *
@@ -759,8 +774,11 @@ static bool collect_domain_accesses(break ; } -/* We should not reach a root other than @mnt_root. */ -if (dir == mnt_root ||WARN_ON_ONCE (IS_ROOT (dir))) +/* +* Stops at the mount point or the filesystem root for a disconnected +* directory. +*/ +if (dir == mnt_root ||unlikely (IS_ROOT (dir)))break ; parent_dentry =dget_parent (dir);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 577/982 selftests/landlock: Add tests for access through disconnected paths
In reply to Greg Kroah-Hartman6.1-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
@@ -3195,6 +3195,18 @@ TEST_F_FORK(layout1, proc_pipe)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);
@@ -3212,14 +3224,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: *
@@ -3230,20 +3242,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)
@@ -3442,6 +3459,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 578/982 selftests/landlock: Add disconnected leafs and branch test suites
In reply to Greg Kroah-Hartman6.1-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
@@ -229,6 +229,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 )); +} +static void create_layout1 (struct __test_metadata *const _metadata) {create_file (_metadata, file1_s1d1);
@@ -587,6 +597,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); }
@@ -1881,6 +1894,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[] = {
@@ -3849,6 +3878,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 579/982 Revert "alpha: dont leak hardware-fabricated FP exception bits to user space"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 096eeed5c31bcfcc04fda3faeb87fafad3890ba8.
--- 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 580/982 Revert "alpha: fix ieee_swcr_to_fpcr setting FPCR_DNOD unconditionally"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit a51363d8b28e3d05a2a63ea0c9167bc1494bf5af.
--- 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 581/982 net/smc: check v2_ext_offset/eid_cnt/ism_gid_cnt when receiving proposal msg
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangguan Wang <[email protected]>
commit 7863c9f3d24ba49dbead7e03dfbe40deb5888fdf upstream.
When receiving proposal msg in server, the fields v2_ext_offset/ eid_cnt/ism_gid_cnt in proposal msg are from the remote client and can not be fully trusted. Especially the field v2_ext_offset, once exceed the max value, there has the chance to access wrong address, and crash may happen.
This patch checks the fields v2_ext_offset/eid_cnt/ism_gid_cnt before using them.
[ jcao: SMCD_CLC_MAX_V2_GID_ENTRIES does not exist in 6.1;
SMC_MAX_ISM_DEVS is the same limit (8) under its pre-b40584d14570 name ]
--- net/smc/af_smc.c | 3 ++- net/smc/smc_clc.c | 8 +++++++- net/smc/smc_clc.h | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-)
net/smc/af_smc.c +2 -1
@@ -2225,7 +2225,8 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc, goto not_found; smc_v2_ext =smc_get_clc_v2_ext (pclc); -if (!smc_clc_match_eid (ini->negotiated_eid, smc_v2_ext,NULL ,NULL )) +if (!smc_v2_ext || + !smc_clc_match_eid (ini->negotiated_eid, smc_v2_ext,NULL ,NULL )) goto not_found;/* prepare RDMA check */
net/smc/smc_clc.c +7 -1
@@ -352,7 +352,6 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)struct smc_clc_msg_hdr *hdr = &pclc->hdr;struct smc_clc_v2_extension *v2_ext; - v2_ext =smc_get_clc_v2_ext (pclc); pclc_prfx =smc_clc_proposal_get_prefix (pclc);if (!pclc_prfx || pclc_prfx->ipv6_prefixes_cnt >SMC_CLC_MAX_V6_PREFIX )
@@ -369,6 +368,13 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc) sizeof(struct smc_clc_msg_trail))return false; } else { + v2_ext =smc_get_clc_v2_ext (pclc); +if ((hdr->typev2 !=SMC_TYPE_N && + (!v2_ext || v2_ext->hdr.eid_cnt >SMC_CLC_MAX_UEID )) || + (smcd_indicated (hdr->typev2) && + v2_ext->hdr.ism_gid_cnt >SMC_MAX_ISM_DEVS )) +return false; + if (ntohs(hdr->length) != sizeof(*pclc) + sizeof(struct smc_clc_msg_smcd) +
net/smc/smc_clc.h +7 -1
@@ -347,8 +347,14 @@ static inline struct smc_clc_v2_extension * smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop) {struct smc_clc_msg_smcd *prop_smcd =smc_get_clc_msg_smcd (prop); +u16 max_offset; -if (!prop_smcd || !ntohs (prop_smcd->v2_ext_offset)) + max_offset = offsetof(struct smc_clc_msg_proposal_area , pclc_v2_ext) - + offsetof(struct smc_clc_msg_proposal_area , pclc_smcd) - + offsetofend(struct smc_clc_msg_smcd, v2_ext_offset); + +if (!prop_smcd || !ntohs (prop_smcd->v2_ext_offset) || +ntohs (prop_smcd->v2_ext_offset) > max_offset)return NULL ; return (struct smc_clc_v2_extension *)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 582/982 selftests/landlock: Add tests for whiteout object creation
In reply to Greg Kroah-Hartman6.1-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
@@ -36,6 +36,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"
@@ -62,6 +66,8 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";/* 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:
@@ -258,7 +264,8 @@ static void create_layout1(struct __test_metadata *const _metadata)ASSERT_EQ (0 ,mount ("tmp" , dir_s3d2,"tmpfs" ,0 ,"size=4m,mode=700" ));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)
@@ -275,7 +282,8 @@ static void remove_layout1(struct __test_metadata *const _metadata)EXPECT_EQ (0 ,remove_path (file1_s2d2));EXPECT_EQ (0 ,remove_path (file1_s2d1)); -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 );
@@ -616,6 +624,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(layout1, proc_nsfs) {const struct rule rules[] = {
@@ -1992,6 +2021,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[] = {
@@ -3008,6 +3201,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 583/982 sunvdc: fix -EIO issue due to lack of retries
In reply to Greg Kroah-Hartman6.1-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
Greg Kroah-Hartman
maintainerPATCH 584/982 Revert "perf cs-etm: Avoid truncating AUX buffer sizes to int"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 9ccb4d7bd325012505d2d5d2456cad199417be57.
--- tools/perf/util/cs-etm.c | 46 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-)
tools/perf/util/cs-etm.c +20 -26
@@ -1087,7 +1087,8 @@ cs_etm__get_trace(struct cs_etm_queue *etmq) etmq->buf_used =0 ; etmq->buf_len = aux_buffer->size; etmq->buf = aux_buffer->data; -return 0 ; + +return etmq->buf_len; } static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm,
@@ -1684,33 +1685,26 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) {int ret; -/* The current block is not finished */ -if (etmq->buf_len) -return 1 ; - - ret =cs_etm__get_trace (etmq); -if (ret <0 ) -return ret; - -/* No more buffer to read */ -if (!etmq->buf_len) -return 0 ; - -/* -* We cannot assume consecutive blocks in the data file -* are contiguous, reset the decoder to force re-sync. -*/ - ret =cs_etm_decoder__reset (etmq->decoder); -if (ret) -return ret; +if (!etmq->buf_len) { + ret =cs_etm__get_trace (etmq); +if (ret <=0 ) +return ret; +/* +* We cannot assume consecutive blocks in the data file +* are contiguous, reset the decoder to force re-sync. +*/ + ret =cs_etm_decoder__reset (etmq->decoder); +if (ret) +return ret; -/* -* Since the decoder is reset, this causes a global trace -* discontinuity. Flush all thread stacks. -*/ -cs_etm__flush_all_stack (etmq); +/* +* Since the decoder is reset, this causes a global trace +* discontinuity. Flush all thread stacks. +*/ +cs_etm__flush_all_stack (etmq); + } -return 1 ; +return etmq->buf_len; } static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, u8 trace_chan_id,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 585/982 Revert "perf cs-etm: Flush thread stacks after decoder reset"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
This reverts commit 097df36140476ce86b23bfaa2fb9104a9c095752.
--- tools/perf/util/cs-etm.c | 45 ---------------------------------------- 1 file changed, 45 deletions(-)
tools/perf/util/cs-etm.c +0 -45
@@ -1635,45 +1635,6 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,return 0 ; } - -static int cs_etm__flush_stack_cb (struct thread *thread, -void *data__maybe_unused ) -{ -thread_stack__flush (thread); -return 0 ; -} - -static void cs_etm__flush_machine_stack (struct cs_etm_queue *etmq,pid_t pid) -{ -struct machine *machine; - - machine =machines__find (&etmq->etm->session->machines, pid); -if (machine) -machine__for_each_thread (machine, cs_etm__flush_stack_cb,NULL ); -} - -static void cs_etm__flush_all_stack (struct cs_etm_queue *etmq) -{ -enum cs_etm_pid_fmt pid_fmt =cs_etm__get_pid_fmt (etmq); - -if (!etmq->etm->synth_opts.last_branch) -return ; - -switch (pid_fmt) { -case CS_ETM_PIDFMT_CTXTID2 : -/* Clear the guest stack if virtualization is supported */ -cs_etm__flush_machine_stack (etmq,DEFAULT_GUEST_KERNEL_ID ); - fallthrough; -case CS_ETM_PIDFMT_CTXTID : -cs_etm__flush_machine_stack (etmq,HOST_KERNEL_ID ); -break ; -case CS_ETM_PIDFMT_NONE : -default : -break ; - - } -} -/* * cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue * if need be.
@@ -1696,12 +1657,6 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) ret =cs_etm_decoder__reset (etmq->decoder);if (ret)return ret; - -/* -* Since the decoder is reset, this causes a global trace -* discontinuity. Flush all thread stacks. -*/ -cs_etm__flush_all_stack (etmq); }return etmq->buf_len;
Signature · 1 line
2.53.0
PATCH 586/982 media: video-i2c: fix buffer queue ordering
In reply to Greg Kroah-Hartman6.1-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 587/982 ipv6: Select best matching nexthop object in fib6_table_lookup()
In reply to Greg Kroah-Hartman6.1-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
@@ -823,9 +823,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,
@@ -865,11 +867,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 588/982 ipv6: Honor oif when choosing nexthop for locally generated traffic
In reply to Greg Kroah-Hartman6.1-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
@@ -2249,6 +2249,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) &&
@@ -2265,7 +2266,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 589/982 xfrm: avoid RCU warnings around the per-netns netlink socket
In reply to Greg Kroah-Hartman6.1-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) {
@@ -1460,7 +1469,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 )
@@ -1520,7 +1529,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,
@@ -1540,7 +1549,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:
@@ -1616,7 +1625,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);
@@ -2246,7 +2255,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,
@@ -2312,7 +2321,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 {
@@ -2472,7 +2481,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;
@@ -3098,7 +3107,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 590/982 xfrm: fix compat ALLOCSPI request use-after-free
In reply to Greg Kroah-Hartman6.1-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
@@ -1563,7 +1563,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;
@@ -1614,17 +1613,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 591/982 xfrm: add missing rcu_read_lock(), skb_dst_force() and dev_hold() for xfrm_trans_reinject()
In reply to Greg Kroah-Hartman6.1-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
@@ -757,12 +757,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 (); }
@@ -778,12 +783,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 592/982 esp: downgrade zerocopy managed frags before mutating skb frags
In reply to Greg Kroah-Hartman6.1-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 593/982 ARM: socfpga: select the PL310 erratum 753970 workaround
In reply to Greg Kroah-Hartman6.1-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 594/982 RDMA/siw: Introduce siw_cep_set_free_and_put
In reply to Greg Kroah-Hartman6.1-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
@@ -450,6 +450,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);
@@ -1517,9 +1523,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);
@@ -1567,16 +1571,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 ; }
@@ -1719,8 +1721,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; }
@@ -1743,8 +1744,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 ; }
@@ -1761,8 +1761,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 ; }
@@ -1894,8 +1893,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);
@@ -1926,8 +1924,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 595/982 RDMA/siw: Cleanup siw_accept
In reply to Greg Kroah-Hartman6.1-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
@@ -1554,7 +1554,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);
@@ -1570,24 +1570,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 ) {
@@ -1601,9 +1594,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 );
@@ -1613,9 +1604,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) {
@@ -1624,9 +1613,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) {
@@ -1635,8 +1622,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 &
@@ -1683,7 +1669,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;
@@ -1706,6 +1691,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);
@@ -1720,9 +1708,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
Greg Kroah-Hartman
maintainerPATCH 596/982 RDMA/siw: Clear association under lock if siw_qp_modify fails in siw_accept
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guoqing Jiang <[email protected]>
[ Upstream commit 32cd87f54dd1070020e664ccb0312a9f0fea79b4 ]
We need to clear cep before release state_lock as siw_qp_llp_close and siw_qp_modify->siw_qp_llp_close did.
Otherwise if siw_qp_modify() fails in siw_accept(), the QP's state_lock is released before the error path cleanup. A concurrent ibv_modify_qp() transitioning the QP to ERROR can race in this window:
siw_accept() ibv_modify_qp(ERROR)
---------------------- ----------------------
siw_qp_modify() fails
up_write(&qp->state_lock)
down_write(&qp->state_lock)
nextstate_from_idle():
if (qp->cep)
siw_cep_put(qp->cep) <- frees cep
qp->cep = NULL
goto error
cep->qp = NULL <- UAFClear qp->cep and drop the association reference taken by siw_cep_get(), all under the write lock held from the initial down_write(&qp->state_lock). Thread B therefore sees qp->cep == NULL, skips its own put, and cannot free the cep before siw_accept() is done with it.
--- drivers/infiniband/sw/siw/siw_cm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/infiniband/sw/siw/siw_cm.c +5 -2
@@ -1668,9 +1668,12 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)SIW_QP_ATTR_STATE |SIW_QP_ATTR_LLP_HANDLE |SIW_QP_ATTR_ORD |SIW_QP_ATTR_IRD | SIW_QP_ATTR_MPA); +if (rv) { + qp->cep =NULL ; +siw_cep_put (cep); + goto error_unlock; + }up_write (&qp->state_lock); -if (rv) - goto error;siw_dbg_cep (cep,"[QP %u]: send mpa reply, %d byte pdata\n" ,qp_id (qp), params->private_data_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 597/982 firmware: arm_scpi: reject DVFS OPP count above MAX_DVFS_OPPS
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xixin Liu <[email protected]>
[ Upstream commit 32471d84a487c7fd74532bc96be56f8028cf4a3f ]
scpi_dvfs_get_info() already rejected a zero opp_count, but still trusted any larger value from the SCP firmware. The shared-memory reply only holds MAX_DVFS_OPPS entries in buf.opps[]; a bigger count over-reads that array and then sizes the allocated OPP table incorrectly (garbage OPPs / OOB). The missing upper bound dates back to the original SCPI DVFS support.
Reject zero and out-of-range counts in one check and return -EINVAL.
--- drivers/firmware/arm_scpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/arm_scpi.c +2 -2
@@ -628,8 +628,8 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)if (ret)return ERR_PTR (ret); -if (!buf.opp_count) -return ERR_PTR (-ENOENT ); +if (!buf.opp_count || buf.opp_count >MAX_DVFS_OPPS ) +return ERR_PTR (-EINVAL ); info =kmalloc (sizeof (*info),GFP_KERNEL );if (!info)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 598/982 clk: scpi: bound-check DVFS index in scpi_dvfs_recalc_rate
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xixin Liu <[email protected]>
[ Upstream commit 70f4b78d560e592cbf3325b162424737d032fc1d ]
dvfs_get_idx() may return an out-of-range index if the SCP firmware is buggy or returns a stale value. Only negative indexes were rejected, so a large index walked past info->opps and could treat garbage as a clock rate (KASAN OOB / wrong frequency to consumers). The missing upper bound dates back to the original SCPI clock driver.
Treat indexes >= opp count as invalid and return 0, same as idx < 0.
--- drivers/clk/clk-scpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-scpi.c +1 -1
@@ -86,7 +86,7 @@ static unsigned long scpi_dvfs_recalc_rate(struct clk_hw *hw,int idx = clk->scpi_ops->dvfs_get_idx (clk->id);const struct scpi_opp *opp; -if (idx <0 ) +if (idx <0 || idx >= clk->info->count)return 0 ; opp = clk->info->opps + idx;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 599/982 RDMA/rxe: insert mcg into mcg_tree only after rxe_mcast_add() succeeds
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 1caceeb2d74bbe88223aea55eb8626b4c5f076fd ]
rxe_get_mcg() publishes a newly allocated multicast group in rxe->mcg_tree before programming the backing Ethernet multicast address with rxe_mcast_add(), which runs outside mcg_lock. A local userspace RDMA client reaches this path with ATTACH_MCAST on a UD QP; if rxe_mcast_add() then returns an error (for example -ENODEV when the backing netdev has been removed, or a propagated dev_mc_add() error), the unwind frees the published group without removing it from the tree. A later lookup of the same MGID dereferences the freed struct rxe_mcg from __rxe_lookup_mcg().
Fix this by keeping the new mcg private until rxe_mcast_add() succeeds. Split the tree publication into __rxe_publish_mcg(), call rxe_mcast_add() before taking the tree reference, and free the still-private mcg on failure. Because the group is never visible in mcg_tree until the multicast address is programmed, no concurrent caller can look it up or attach a QP to a group that is about to be torn down, so the error path needs no conditional unwind. If another caller publishes the same MGID while the address is being programmed, the post-add re-check under mcg_lock finds the winner; this caller then drops its private object and balances its own rxe_mcast_add() with rxe_mcast_del() before returning the winner.
Reproduced by forcing the rxe_mcast_add() error return under KASAN:
without the change the next attach to the same MGID reports a slab-use-after-free in __rxe_lookup_mcg(); with it the forced failure returns cleanly. A no-injection attach/detach regression, including a two-QP shared join/leave and re-attach, stays KASAN- and leak-clean.
--- drivers/infiniband/sw/rxe/rxe_mcast.c | 50 +++++++++++++++++++-------- 1 file changed, 36 insertions(+), 14 deletions(-)
drivers/infiniband/sw/rxe/rxe_mcast.c +36 -14
@@ -157,7 +157,9 @@ struct rxe_mcg *rxe_lookup_mcg(struct rxe_dev *rxe, union ib_gid *mgid)* @mgid: multicast address as a gid * @mcg: new mcg object * -* Context: caller should hold rxe->mcg lock +* Initializes the mcg fields. The mcg is private and not yet visible in +* mcg_tree, so this may run without rxe->mcg_lock; __rxe_publish_mcg() +* makes it visible under the lock once it is ready. */ static void __rxe_init_mcg (struct rxe_dev *rxe,union ib_gid *mgid,struct rxe_mcg *mcg)
@@ -166,13 +168,22 @@ static void __rxe_init_mcg(struct rxe_dev *rxe, union ib_gid *mgid,memcpy (&mcg->mgid, mgid,sizeof (mcg->mgid));INIT_LIST_HEAD (&mcg->qp_list); mcg->rxe = rxe; +} -/* caller holds a ref on mcg but that will be -* dropped when mcg goes out of scope. We need to take a ref -* on the pointer that will be saved in the red-black tree -* by __rxe_insert_mcg and used to lookup mcg from mgid later. -* Inserting mcg makes it visible to outside so this should -* be done last after the object is ready. +/** +* __rxe_publish_mcg - make a fully initialized mcg visible in mcg_tree +* @mcg: the mcg object +* +* Context: caller must hold rxe->mcg_lock and a reference on mcg +*/ +static void __rxe_publish_mcg (struct rxe_mcg *mcg) +{ +/* caller holds a ref on mcg but that will be dropped when mcg goes +* out of scope. We need to take a ref on the pointer that will be +* saved in the red-black tree by __rxe_insert_mcg and used to lookup +* mcg from mgid later. Inserting mcg makes it visible to outside so +* this is done last after the object is ready and the multicast +* address has been programmed. */ kref_get (&mcg->ref_cnt);__rxe_insert_mcg (mcg);
@@ -210,26 +221,37 @@ static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid) err = -ENOMEM ; goto err_dec; } +__rxe_init_mcg (rxe, mgid, mcg); + +/* program the multicast address while mcg is still private, before +* it is inserted into mcg_tree. dev_mc_add() may sleep so this must +* run outside mcg_lock. On failure mcg was never published, so a +* plain free is correct and the tree is untouched. +*/ + err =rxe_mcast_add (rxe, mgid); +if (err) { +kfree (mcg); + goto err_dec; + }spin_lock_bh (&rxe->mcg_lock); -/* re-check to see if someone else just added it */ +/* re-check to see if someone else just added it while we were adding +* the multicast address; if so use theirs and drop ours +*/ tmp =__rxe_lookup_mcg (rxe, mgid);if (tmp) {spin_unlock_bh (&rxe->mcg_lock); +rxe_mcast_del (rxe, mgid);atomic_dec (&rxe->mcg_num);kfree (mcg);return tmp; } -__rxe_init_mcg (rxe, mgid, mcg); +__rxe_publish_mcg (mcg);spin_unlock_bh (&rxe->mcg_lock); -/* add mcast address outside of lock */ - err =rxe_mcast_add (rxe, mgid); -if (!err) -return mcg; +return mcg; -kfree (mcg); err_dec:atomic_dec (&rxe->mcg_num);return ERR_PTR (err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 600/982 net: devlink: convert devlink port type-specific pointers to union
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Pirko <[email protected]>
[ Upstream commit 3830c5719af66fac9849cf5fb04b03d4e4bb46ff ]
Instead of storing type_dev as a void pointer, convert it to union and use it to store either struct net_device or struct ib_device pointer.
Stable-dep-of: ef9fbe1b93f3 ("RDMA/core: Reject unregistering netdevs in ib_get_eth_speed")
--- include/net/devlink.h | 13 ++++++++++--- net/devlink/leftover.c | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-)
include/net/devlink.h +10 -3
@@ -121,12 +121,19 @@ struct devlink_port {struct list_head region_list;struct devlink *devlink;unsigned int index; -spinlock_t type_lock;/* Protects type and type_dev -* pointer consistency. +spinlock_t type_lock;/* Protects type and type_eth/ib +* structures consistency. */ enum devlink_port_type type;enum devlink_port_type desired_type; -void *type_dev; +union { +struct { +struct net_device *netdev; + } type_eth; +struct { +struct ib_device *ibdev; + } type_ib; + };struct devlink_port_attrs attrs; u8 attrs_set:1, switch_port:1,
net/devlink/leftover.c +13 -4
@@ -1283,7 +1283,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, goto nla_put_failure_type_locked;if (devlink_port->type ==DEVLINK_PORT_TYPE_ETH ) {struct net *net =devlink_net (devlink_port->devlink); -struct net_device *netdev = devlink_port->type_dev; +struct net_device *netdev = devlink_port->type_eth.netdev; if (netdev && net_eq(net, dev_net(netdev)) && (nla_put_u32(msg, DEVLINK_ATTR_PORT_NETDEV_IFINDEX,
@@ -1293,7 +1293,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, goto nla_put_failure_type_locked; } if (devlink_port->type == DEVLINK_PORT_TYPE_IB) { - struct ib_device *ibdev = devlink_port->type_dev; + struct ib_device *ibdev = devlink_port->type_ib.ibdev; if (ibdev && nla_put_string(msg, DEVLINK_ATTR_PORT_IBDEV_NAME,
@@ -9992,7 +9992,16 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,devlink_port_type_warn_cancel (devlink_port);spin_lock_bh (&devlink_port->type_lock); devlink_port->type = type; - devlink_port->type_dev = type_dev; +switch (type) { +case DEVLINK_PORT_TYPE_ETH : + devlink_port->type_eth.netdev = type_dev; +break ; +case DEVLINK_PORT_TYPE_IB : + devlink_port->type_ib.ibdev = type_dev; +break ; +default : +break ; + }spin_unlock_bh (&devlink_port->type_lock);devlink_port_notify (devlink_port,DEVLINK_CMD_PORT_NEW ); }
@@ -12009,7 +12018,7 @@ devlink_trap_report_metadata_set(struct devlink_trap_metadata *metadata,spin_lock (&in_devlink_port->type_lock);if (in_devlink_port->type ==DEVLINK_PORT_TYPE_ETH ) - metadata->input_dev = in_devlink_port->type_dev; + metadata->input_dev = in_devlink_port->type_eth.netdev;spin_unlock (&in_devlink_port->type_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 601/982 net: devlink: move port_type_warn_schedule() call to __devlink_port_type_set()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Pirko <[email protected]>
[ Upstream commit 8573a04404ddacb2d966eef09bf38b2ad6dbe86f ]
As __devlink_port_type_set() is going to be called directly from netdevice notifier event handle in one of the follow-up patches, move the port_type_warn_schedule() call there.
Stable-dep-of: ef9fbe1b93f3 ("RDMA/core: Reject unregistering netdevs in ib_get_eth_speed")
--- net/devlink/leftover.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/devlink/leftover.c +5 -2
@@ -9989,7 +9989,11 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port, {ASSERT_DEVLINK_PORT_REGISTERED (devlink_port); -devlink_port_type_warn_cancel (devlink_port); +if (type ==DEVLINK_PORT_TYPE_NOTSET ) +devlink_port_type_warn_schedule (devlink_port); +else +devlink_port_type_warn_cancel (devlink_port); +spin_lock_bh (&devlink_port->type_lock); devlink_port->type = type;switch (type) {
@@ -10084,7 +10088,6 @@ EXPORT_SYMBOL_GPL(devlink_port_type_ib_set);void devlink_port_type_clear (struct devlink_port *devlink_port) {__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_NOTSET ,NULL ); -devlink_port_type_warn_schedule (devlink_port); }EXPORT_SYMBOL_GPL (devlink_port_type_clear);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 602/982 net: devlink: move port_type_netdev_checks() call to __devlink_port_type_set()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Pirko <[email protected]>
[ Upstream commit 45791e0d00c445936bb19535fe847083b1edd26d ]
As __devlink_port_type_set() is going to be called directly from netdevice notifier event handle in one of the follow-up patches, move the port_type_netdev_checks() call there.
Stable-dep-of: ef9fbe1b93f3 ("RDMA/core: Reject unregistering netdevs in ib_get_eth_speed")
--- net/devlink/leftover.c | 63 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 30 deletions(-)
net/devlink/leftover.c +33 -30
@@ -9983,33 +9983,6 @@ void devlink_port_unregister(struct devlink_port *devlink_port) }EXPORT_SYMBOL_GPL (devlink_port_unregister); -static void __devlink_port_type_set (struct devlink_port *devlink_port, -enum devlink_port_type type, -void *type_dev) -{ -ASSERT_DEVLINK_PORT_REGISTERED (devlink_port); - -if (type ==DEVLINK_PORT_TYPE_NOTSET ) -devlink_port_type_warn_schedule (devlink_port); -else -devlink_port_type_warn_cancel (devlink_port); - -spin_lock_bh (&devlink_port->type_lock); - devlink_port->type = type; -switch (type) { -case DEVLINK_PORT_TYPE_ETH : - devlink_port->type_eth.netdev = type_dev; -break ; -case DEVLINK_PORT_TYPE_IB : - devlink_port->type_ib.ibdev = type_dev; -break ; -default : -break ; - } -spin_unlock_bh (&devlink_port->type_lock); -devlink_port_notify (devlink_port,DEVLINK_CMD_PORT_NEW ); -} -static void devlink_port_type_netdev_checks (struct devlink_port *devlink_port,struct net_device *netdev) {
@@ -10047,6 +10020,38 @@ static void devlink_port_type_netdev_checks(struct devlink_port *devlink_port, } } +static void __devlink_port_type_set (struct devlink_port *devlink_port, +enum devlink_port_type type, +void *type_dev) +{ +struct net_device *netdev = type_dev; + +ASSERT_DEVLINK_PORT_REGISTERED (devlink_port); + +if (type ==DEVLINK_PORT_TYPE_NOTSET ) { +devlink_port_type_warn_schedule (devlink_port); + }else { +devlink_port_type_warn_cancel (devlink_port); +if (type ==DEVLINK_PORT_TYPE_ETH && netdev) +devlink_port_type_netdev_checks (devlink_port, netdev); + } + +spin_lock_bh (&devlink_port->type_lock); + devlink_port->type = type; +switch (type) { +case DEVLINK_PORT_TYPE_ETH : + devlink_port->type_eth.netdev = netdev; +break ; +case DEVLINK_PORT_TYPE_IB : + devlink_port->type_ib.ibdev = type_dev; +break ; +default : +break ; + } +spin_unlock_bh (&devlink_port->type_lock); +devlink_port_notify (devlink_port,DEVLINK_CMD_PORT_NEW ); +} +/** * devlink_port_type_eth_set - Set port type to Ethernet *
@@ -10056,9 +10061,7 @@ static void devlink_port_type_netdev_checks(struct devlink_port *devlink_port,void devlink_port_type_eth_set (struct devlink_port *devlink_port,struct net_device *netdev) { -if (netdev) -devlink_port_type_netdev_checks (devlink_port, netdev); -else +if (!netdev)dev_warn (devlink_port->devlink->dev,"devlink port type for port %d set to Ethernet without a software interface reference, device type not supported by the kernel?\n" , devlink_port->index);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 603/982 net: devlink: take RTNL in port_fill() function only if it is not held
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Pirko <[email protected]>
[ Upstream commit d41c9dbd12745cfc1cb2946cd99016d83c2c5364 ]
Follow-up patch is going to introduce a netdevice notifier event processing which is called with RTNL mutex held. Processing of this will eventually lead to call to port_notity() and port_fill() which currently takes RTNL mutex internally. So as a temporary solution, propagate a bool indicating if the mutex is already held. This will go away in one of the follow-up patches.
Stable-dep-of: ef9fbe1b93f3 ("RDMA/core: Reject unregistering netdevs in ib_get_eth_speed")
--- net/devlink/leftover.c | 46 ++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-)
net/devlink/leftover.c +31 -15
@@ -1258,7 +1258,8 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *porstatic int devlink_nl_port_fill (struct sk_buff *msg,struct devlink_port *devlink_port,enum devlink_command cmd,u32 portid,u32 seq, -int flags,struct netlink_ext_ack *extack) +int flags,struct netlink_ext_ack *extack, +bool rtnl_held) {struct devlink *devlink = devlink_port->devlink;void *hdr;
@@ -1273,7 +1274,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg, goto nla_put_failure;/* Hold rtnl lock while accessing port's netdev attributes. */ -rtnl_lock (); +if (!rtnl_held) +rtnl_lock ();spin_lock_bh (&devlink_port->type_lock);if (nla_put_u16 (msg,DEVLINK_ATTR_PORT_TYPE , devlink_port->type)) goto nla_put_failure_type_locked;
@@ -1301,7 +1303,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg, goto nla_put_failure_type_locked; }spin_unlock_bh (&devlink_port->type_lock); -rtnl_unlock (); +if (!rtnl_held) +rtnl_unlock ();if (devlink_nl_port_attrs_put (msg, devlink_port)) goto nla_put_failure;if (devlink_nl_port_function_attrs_put (msg, devlink_port, extack))
@@ -1316,14 +1319,15 @@ static int devlink_nl_port_fill(struct sk_buff *msg, nla_put_failure_type_locked:spin_unlock_bh (&devlink_port->type_lock); -rtnl_unlock (); +if (!rtnl_held) +rtnl_unlock (); nla_put_failure:genlmsg_cancel (msg, hdr);return -EMSGSIZE ; } -static void devlink_port_notify (struct devlink_port *devlink_port, -enum devlink_command cmd) +static void __devlink_port_notify (struct devlink_port *devlink_port, +enum devlink_command cmd,bool rtnl_held) {struct devlink *devlink = devlink_port->devlink;struct sk_buff *msg;
@@ -1338,7 +1342,8 @@ static void devlink_port_notify(struct devlink_port *devlink_port,if (!msg)return ; - err =devlink_nl_port_fill (msg, devlink_port, cmd,0 ,0 ,0 ,NULL ); + err =devlink_nl_port_fill (msg, devlink_port, cmd,0 ,0 ,0 ,NULL , + rtnl_held);if (err) {nlmsg_free (msg);return ;
@@ -1348,6 +1353,12 @@ static void devlink_port_notify(struct devlink_port *devlink_port, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } +static void devlink_port_notify (struct devlink_port *devlink_port, +enum devlink_command cmd) +{ +__devlink_port_notify (devlink_port, cmd, false); +} +static void devlink_rate_notify (struct devlink_rate *devlink_rate,enum devlink_command cmd) {
@@ -1514,7 +1525,7 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, err =devlink_nl_port_fill (msg, devlink_port,DEVLINK_CMD_PORT_NEW , info->snd_portid, info->snd_seq,0 , - info->extack); + info->extack, false);if (err) {nlmsg_free (msg);return err;
@@ -1544,7 +1555,8 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,DEVLINK_CMD_NEW ,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq, - NLM_F_MULTI, cb->extack); +NLM_F_MULTI , cb->extack, + false);if (err) {devl_unlock (devlink);devlink_put (devlink);
@@ -1756,7 +1768,8 @@ static int devlink_port_new_notify(struct devlink *devlink, } err =devlink_nl_port_fill (msg, devlink_port,DEVLINK_CMD_NEW , - info->snd_portid, info->snd_seq,0 ,NULL ); + info->snd_portid, info->snd_seq,0 ,NULL , + false);if (err) goto out;
@@ -10022,7 +10035,7 @@ static void devlink_port_type_netdev_checks(struct devlink_port *devlink_port,static void __devlink_port_type_set (struct devlink_port *devlink_port,enum devlink_port_type type, -void *type_dev) +void *type_dev,bool rtnl_held) {struct net_device *netdev = type_dev;
@@ -10049,7 +10062,7 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,break ; }spin_unlock_bh (&devlink_port->type_lock); -devlink_port_notify (devlink_port,DEVLINK_CMD_PORT_NEW ); +__devlink_port_notify (devlink_port,DEVLINK_CMD_PORT_NEW , rtnl_held); }/**
@@ -10066,7 +10079,8 @@ void devlink_port_type_eth_set(struct devlink_port *devlink_port,"devlink port type for port %d set to Ethernet without a software interface reference, device type not supported by the kernel?\n" , devlink_port->index); -__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_ETH , netdev); +__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_ETH , netdev, + false); }EXPORT_SYMBOL_GPL (devlink_port_type_eth_set);
@@ -10079,7 +10093,8 @@ EXPORT_SYMBOL_GPL(devlink_port_type_eth_set);void devlink_port_type_ib_set (struct devlink_port *devlink_port,struct ib_device *ibdev) { -__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_IB , ibdev); +__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_IB , ibdev, + false); }EXPORT_SYMBOL_GPL (devlink_port_type_ib_set);
@@ -10090,7 +10105,8 @@ EXPORT_SYMBOL_GPL(devlink_port_type_ib_set);*/ void devlink_port_type_clear (struct devlink_port *devlink_port) { -__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_NOTSET ,NULL ); +__devlink_port_type_set (devlink_port,DEVLINK_PORT_TYPE_NOTSET ,NULL , + false); }EXPORT_SYMBOL_GPL (devlink_port_type_clear);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 604/982 net: convert dev->reg_state to u8
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 4d42b37def70327b2bb19f823d42289aed2cd7c7 ]
Prepares things so that dev->reg_state reads can be lockless, by adding WRITE_ONCE() on write side.
READ_ONCE()/WRITE_ONCE() do not support bitfields.
Stable-dep-of: ef9fbe1b93f3 ("RDMA/core: Reject unregistering netdevs in ib_get_eth_speed")
--- include/linux/netdevice.h | 23 ++++++++++++++--------- net/core/dev.c | 8 ++++---- 2 files changed, 18 insertions(+), 13 deletions(-)
include/linux/netdevice.h +14 -9
@@ -1756,6 +1756,15 @@ enum netdev_stat_type { NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */ }; +enum netdev_reg_state { +NETREG_UNINITIALIZED =0 , +NETREG_REGISTERED ,/* completed register_netdevice */ +NETREG_UNREGISTERING ,/* called unregister_netdevice */ +NETREG_UNREGISTERED ,/* completed unregister todo */ +NETREG_RELEASED ,/* called free_netdev */ +NETREG_DUMMY ,/* dummy device for NAPI poll */ +}; +/** * struct net_device - The DEVICE structure. *
@@ -2272,13 +2281,7 @@ struct net_device {struct list_head link_watch_list; -enum {NETREG_UNINITIALIZED =0 , -NETREG_REGISTERED ,/* completed register_netdevice */ -NETREG_UNREGISTERING ,/* called unregister_netdevice */ -NETREG_UNREGISTERED ,/* completed unregister todo */ -NETREG_RELEASED ,/* called free_netdev */ -NETREG_DUMMY ,/* dummy device for NAPI poll */ - } reg_state:8; +u8 reg_state;bool dismantle;
@@ -5169,7 +5172,9 @@ static inline bool netdev_unregistering(const struct net_device *dev)static inline const char *netdev_reg_state (const struct net_device *dev) { -switch (dev->reg_state) { +u8 reg_state =READ_ONCE (dev->reg_state); + +switch (reg_state) {case NETREG_UNINITIALIZED :return " (uninitialized)" ;case NETREG_REGISTERED :return "" ;case NETREG_UNREGISTERING :return " (unregistering)" ;
@@ -5178,7 +5183,7 @@ static inline const char *netdev_reg_state(const struct net_device *dev)case NETREG_DUMMY :return " (dummy)" ; } -WARN_ONCE (1 ,"%s: unknown reg_state %d\n" , dev->name, dev->reg_state); +WARN_ONCE (1 ,"%s: unknown reg_state %d\n" , dev->name, reg_state);return " (unknown)" ; }
net/core/dev.c +4 -4
@@ -10242,7 +10242,7 @@ int register_netdevice(struct net_device *dev) ret =netdev_register_kobject (dev);write_lock (&dev_base_lock); - dev->reg_state = ret ?NETREG_UNREGISTERED :NETREG_REGISTERED ; +WRITE_ONCE (dev->reg_state, ret ?NETREG_UNREGISTERED :NETREG_REGISTERED );write_unlock (&dev_base_lock);if (ret) goto err_free_pcpu;
@@ -10531,7 +10531,7 @@ void netdev_run_todo(void) }write_lock (&dev_base_lock); - dev->reg_state =NETREG_UNREGISTERED ; +WRITE_ONCE (dev->reg_state,NETREG_UNREGISTERED );write_unlock (&dev_base_lock);linkwatch_forget_dev (dev); }
@@ -10911,7 +10911,7 @@ void free_netdev(struct net_device *dev) }BUG_ON (dev->reg_state !=NETREG_UNREGISTERED ); - dev->reg_state =NETREG_RELEASED ; +WRITE_ONCE (dev->reg_state,NETREG_RELEASED );/* will free via device release */ put_device (&dev->dev);
@@ -11000,7 +11000,7 @@ void unregister_netdevice_many_notify(struct list_head *head,/* And unlink it from device chain. */ write_lock (&dev_base_lock);unlist_netdevice (dev, false); - dev->reg_state =NETREG_UNREGISTERING ; +WRITE_ONCE (dev->reg_state,NETREG_UNREGISTERING );write_unlock (&dev_base_lock); }flush_all_backlogs ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 605/982 RDMA/core: Reject unregistering netdevs in ib_get_eth_speed
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krystian Kaniewski <[email protected]>
[ Upstream commit ef9fbe1b93f3b617b96e86d5cd76b3fa44514cb5 ]
ib_device_get_netdev() intentionally returns a referenced net_device even when it is unregistering, so matching and cleanup callers can still find the association. The reference keeps struct net_device allocated, but does not guarantee that the device remains operational.
ib_get_eth_speed() uses the returned device operationally by invoking its ethtool callback. Although that call is made under RTNL, the function does not verify the registration state first. An asynchronous RDMA port query can therefore call into a netdev after NETDEV_UNREGISTER and ndo_uninit have completed.
Check for NETREG_REGISTERED while holding RTNL and return -ENODEV for a device which is being unregistered. Keeping RTNL across the check and the ethtool operation prevents unregister from starting between them.
Keep the speed fallback and warning under RTNL as well, so the warning can safely read netdev->name. Drop the netdev reference before releasing RTNL once all accesses to the device are complete.
--- drivers/infiniband/core/verbs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/infiniband/core/verbs.c +8 -4
@@ -1902,11 +1902,13 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)return -ENODEV ;rtnl_lock (); - rc =__ethtool_get_link_ksettings (netdev, &lksettings); -rtnl_unlock (); - -dev_put (netdev); +if (READ_ONCE (netdev->reg_state) !=NETREG_REGISTERED ) { +dev_put (netdev); +rtnl_unlock (); +return -ENODEV ; + } + rc =__ethtool_get_link_ksettings (netdev, &lksettings);if (!rc && lksettings.base.speed != (u32 )SPEED_UNKNOWN ) { netdev_speed = lksettings.base.speed; }else {
@@ -1914,6 +1916,8 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)pr_warn ("%s speed is unknown, defaulting to %u\n" , netdev->name, netdev_speed); } +dev_put (netdev); +rtnl_unlock ();if (netdev_speed <=SPEED_1000 ) { *width =IB_WIDTH_1X ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 606/982 IB/iser: reject a remote invalidation of an unregistered direction
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit d85f0f0a7c85756fc992c70d869706f19dac9259 ]
A write command whose data is sent entirely as immediate data is not registered. iser_reg_mem_fastreg() takes the DMA key path and leaves rdma_reg[ISER_DIR_OUT].desc at NULL, while iser_dma_map_task_data() has already set dir[ISER_DIR_OUT].
iser_check_remote_inv() looks at dir[] alone and hands the descriptor to iser_inv_desc(), which reads desc->sig_protected. A target that answers such a command with IB_WR_SEND_WITH_INV faults the initiator. Leaving those commands unregistered is deliberate.
The same function already terminates the connection when a target sends a remote invalidation the initiator did not ask for. A target that invalidates a direction that was never registered is in the same class, so give it the same answer.
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000004: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027] CPU: 0 UID: 0 PID: 40 Comm: kworker/u8:2 Not tainted 7.2.0-rc5-ISERHOST-gf5098b6bae76-dirty #3 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: rxe_wq do_work RIP: 0010:iser_task_rsp+0x6d6/0xec0 Code: 48 c1 ea 03 80 3c 02 00 0f 85 ba 06 00 00 48 8b 9b 78 01 00 00 48 b8 00 00 00 00 00 fc ff df 48 8d 7b 20 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 06 0f 8e 76 06 00 00 80 7b 20 00 0f 84 3d 04 RSP: 0018:ffff88811b008db8 EFLAGS: 00010202 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000001848 RDX: 0000000000000004 RSI: 1ffff11021587b12 RDI: 0000000000000020 RBP: ffff88810adc1ae4 R08: ffff888109b7f860 R09: ffffffff90a922c0 R10: ffff88810adc1a1c R11: 000000000000003c R12: ffff888109b7f800 R13: ffff88810adc1acc R14: ffff888109b7f820 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff88818a676000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000005afe2b CR3: 000000010af23005 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: <IRQ> __ib_process_cq+0xe1/0x390 ib_poll_handler+0x6e/0x200 irq_poll_softirq+0x1df/0x480 ? clockevents_program_event+0x2ba/0x860 ? __pfx_irq_poll_softirq+0x10/0x10 handle_softirqs+0x18e/0x590 ? __pfx_handle_softirqs+0x10/0x10 ? __hrtimer_rearm_deferred+0x156/0x450 do_softirq+0x3b/0x60 </IRQ> <TASK> __local_bh_enable_ip+0x61/0x70 __alloc_skb+0x732/0x890 ? _raw_spin_lock_irqsave+0x85/0xe0 ? __pfx___alloc_skb+0x10/0x10 ? _raw_read_unlock_irqrestore+0x16/0x50 rxe_init_packet+0x16b/0x4f0 prepare_ack_packet+0xb8/0x830 rxe_receiver+0x499/0x9980 ? __pfx_rxe_receiver+0x10/0x10 ? rxe_completer+0x29e5/0x38c0 ? hrtimer_start_range_ns_common+0x75f/0x1730 ? hrtimer_start_range_ns+0xa6/0x2c0 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 ? __pfx_rxe_receiver+0x10/0x10 do_work+0x144/0x470 process_one_work+0x633/0x1030 ? assign_work+0x11d/0x370 worker_thread+0x45b/0xd10 ? __pfx_worker_thread+0x10/0x10 kthread+0x2c6/0x3b0 ? recalc_sigpending+0x15c/0x1e0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x36e/0x5a0 ? __pfx_ret_from_fork+0x10/0x10 ? __switch_to+0x572/0xdd0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]---
--- drivers/infiniband/ulp/iser/iser_initiator.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/infiniband/ulp/iser/iser_initiator.c +11 -5
@@ -598,11 +598,8 @@ static int iser_check_remote_inv(struct iser_conn *iser_conn, struct ib_wc *wc,iser_dbg ("conn %p: remote invalidation for rkey %#x\n" , iser_conn, rkey); -if (unlikely (!iser_conn->snd_w_inv)) { -iser_err ("conn %p: unexpected remote invalidation, terminating connection\n" , - iser_conn); -return -EPROTO ; - } +if (unlikely (!iser_conn->snd_w_inv)) + goto bad_inv; task =iscsi_itt_to_ctask (iser_conn->iscsi_conn, hdr->itt);if (likely (task)) {
@@ -611,12 +608,16 @@ static int iser_check_remote_inv(struct iser_conn *iser_conn, struct ib_wc *wc,if (iser_task->dir[ISER_DIR_IN ]) { desc = iser_task->rdma_reg[ISER_DIR_IN ].desc; +if (unlikely (!desc)) + goto bad_inv;if (unlikely (iser_inv_desc (desc, rkey)))return -EINVAL ; }if (iser_task->dir[ISER_DIR_OUT ]) { desc = iser_task->rdma_reg[ISER_DIR_OUT ].desc; +if (unlikely (!desc)) + goto bad_inv;if (unlikely (iser_inv_desc (desc, rkey)))return -EINVAL ; }
@@ -627,6 +628,11 @@ static int iser_check_remote_inv(struct iser_conn *iser_conn, struct ib_wc *wc, }return 0 ; + +bad_inv: +iser_err ("conn %p: unexpected remote invalidation, terminating connection\n" , + iser_conn); +return -EPROTO ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 607/982 IB/isert: wait for deferred control PDU completions before releasing the connection
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit a8fe3dfce8c0d8a76dc3d8486a5bff5feebe156f ]
isert_send_done() hands ISTATE_SEND_TASKMGTRSP, ISTATE_SEND_REJECT and ISTATE_SEND_TEXTRSP completions off to isert_comp_wq and returns. The work item then runs isert_completion_put() -> isert_put_cmd(), which reads isert_conn->conn and takes conn->cmd_lock.
Nothing orders that work item against teardown. isert_wait_conn() queues isert_release_work, which frees isert_conn, and iscsit_close_connection() frees the iscsit_conn right after it returns, so the queued work can run against freed memory.
Count the deferred control PDU completions per connection and let isert_wait_conn() wait for them before the release work is queued.
ISTATE_SEND_LOGOUTRSP is deliberately not counted: that branch runs iscsit_logout_post_handler(), which ends up waiting for conn->conn_wait_comp, and that completion is only sent by iscsit_close_connection() after it has called iscsit_wait_conn(). Waiting for it here would deadlock. Its wait stays the existing isert_wait4logout().
The splat below is from a kernel with tracing printk()s and an msleep(200) injected into isert_do_control_comp() to widen the window:
BUG: KASAN: slab-use-after-free in isert_put_cmd+0x53d/0x620 Read of size 8 at addr ffff8881054f1038 by task kworker/u17:1/182 CPU: 0 UID: 0 PID: 182 Comm: kworker/u17:1 Tainted: G B 7.2.0-rc5-TWIDE-gb8babf08acc7 #1 PREEMPT(lazy) Tainted: [B]=BAD_PAGE Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: isert_comp_wq isert_do_control_comp Call Trace: <TASK> dump_stack_lvl+0x53/0x70 print_report+0xd0/0x630 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 ? _raw_spin_unlock_irqrestore+0x3e/0x70 ? isert_put_cmd+0x53d/0x620 kasan_report+0xce/0x100 ? isert_put_cmd+0x53d/0x620 isert_put_cmd+0x53d/0x620 ? isert_completion_put+0x305/0x330 ? isert_do_control_comp+0x2ef/0x310 process_one_work+0x633/0x1030 ? assign_work+0x11d/0x370 worker_thread+0x45b/0xd10 ? __pfx_worker_thread+0x10/0x10 ? __pfx_worker_thread+0x10/0x10 kthread+0x2c6/0x3b0 ? recalc_sigpending+0x15c/0x1e0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x36e/0x5a0 ? __pfx_ret_from_fork+0x10/0x10 ? __switch_to+0x572/0xdd0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 48: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0x8f/0xa0 __kmalloc_cache_noprof+0x158/0x370 isert_cma_handler+0x1e3/0x2ae0 cma_cm_event_handler+0x3e/0x240 cma_ib_req_handler+0x17d9/0x4490 cm_process_work+0x41/0x330 cm_work_handler+0x5727/0xc160 process_one_work+0x633/0x1030 worker_thread+0x45b/0xd10 kthread+0x2c6/0x3b0 ret_from_fork+0x36e/0x5a0 ret_from_fork_asm+0x1a/0x30 Freed by task 184: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x43/0x70 kfree+0x121/0x380 iscsit_close_connection+0x7cf/0x1e60 iscsit_take_action_for_connection_exit+0x1b6/0x360 iscsi_target_tx_thread+0x472/0x690 kthread+0x2c6/0x3b0 ret_from_fork+0x36e/0x5a0 ret_from_fork_asm+0x1a/0x30
--- drivers/infiniband/ulp/isert/ib_isert.c | 22 ++++++++++++++++++++++ drivers/infiniband/ulp/isert/ib_isert.h | 2 ++ 2 files changed, 24 insertions(+)
drivers/infiniband/ulp/isert/ib_isert.c +22 -0
@@ -21,6 +21,7 @@#include <target/target_core_fabric.h> #include <target/iscsi/iscsi_transport.h> #include <linux/semaphore.h> +#include <linux/wait_bit.h> #include "ib_isert.h"
@@ -314,6 +315,7 @@ isert_init_conn(struct isert_conn *isert_conn)init_completion (&isert_conn->login_req_comp);init_waitqueue_head (&isert_conn->rem_wait);kref_init (&isert_conn->kref); +atomic_set (&isert_conn->ctrl_comp_cnt,0 );mutex_init (&isert_conn->mutex);INIT_WORK (&isert_conn->release_work, isert_release_work); }
@@ -1701,6 +1703,8 @@ isert_do_control_comp(struct work_struct *work)struct isert_conn *isert_conn = isert_cmd->conn;struct ib_device *ib_dev = isert_conn->cm_id->device;struct iscsit_cmd *cmd = isert_cmd->iscsit_cmd; +/* The switch below may free isert_cmd. */ +bool counted = isert_cmd->ctrl_counted;isert_dbg ("Cmd %p i_state %d\n" , isert_cmd, cmd->i_state);
@@ -1722,6 +1726,14 @@ isert_do_control_comp(struct work_struct *work)dump_stack ();break ; } + +/* +* The count is what keeps isert_conn alive, so drop it last. The wait +* queue lives in the global hash table, not in isert_conn, so this is +* safe even if the waiter has already freed the connection. +*/ +if (counted &&atomic_dec_and_test (&isert_conn->ctrl_comp_cnt)) +wake_up_var (&isert_conn->ctrl_comp_cnt); } static void
@@ -1765,6 +1777,12 @@ isert_send_done(struct ib_cq *cq, struct ib_wc *wc)case ISTATE_SEND_TEXTRSP :isert_unmap_tx_desc (tx_desc, ib_dev); +/* Paired with the wait in isert_wait_conn(). */ + isert_cmd->ctrl_counted = + isert_cmd->iscsit_cmd->i_state !=ISTATE_SEND_LOGOUTRSP ; +if (isert_cmd->ctrl_counted) +atomic_inc (&isert_conn->ctrl_comp_cnt); +INIT_WORK (&isert_cmd->comp_work, isert_do_control_comp);queue_work (isert_comp_wq, &isert_cmd->comp_work);return ;
@@ -2609,6 +2627,10 @@ static void isert_wait_conn(struct iscsit_conn *conn)isert_wait4cmds (conn);isert_wait4logout (isert_conn); +/* Paired with the count taken in isert_send_done(). */ +wait_var_event (&isert_conn->ctrl_comp_cnt, + !atomic_read (&isert_conn->ctrl_comp_cnt)); +queue_work (isert_release_wq, &isert_conn->release_work); }
drivers/infiniband/ulp/isert/ib_isert.h +2 -0
@@ -153,6 +153,7 @@ struct isert_cmd {struct work_struct comp_work;struct scatterlist sg;bool ctx_init_done; +bool ctrl_counted; };static inline struct isert_cmd *tx_desc_to_cmd (struct iser_tx_desc *desc)
@@ -187,6 +188,7 @@ struct isert_conn {struct mutex mutex;struct kref kref;struct work_struct release_work; +atomic_t ctrl_comp_cnt;bool logout_posted;bool snd_w_inv;wait_queue_head_t rem_wait;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 608/982 RDMA/mad: Fix receive buffer leak when PKey enforcement fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 3476c28c9addfa253f505e6bd87f1f5598b961d0 ]
ib_mad_complete_recv() initializes mad_recv_wc->rmpp_list and then runs ib_mad_enforce_security() before linking recv_buf onto that list. On failure it calls ib_free_recv_mad(), which only walks rmpp_list and frees the ib_mad_private of every buffer found there. As the list is still empty at that point, nothing is freed at all.
The caller cannot clean up either: ib_mad_recv_done() sets recv to NULL right after ib_mad_complete_recv() returns, assuming the MAD layer took ownership of the buffer. Every MAD that fails the PKey check therefore leaks one ib_mad_private (about 300 bytes per IB port MAD, ~2K for OPA), and a remote node can trigger this repeatedly by sending MADs with a wrong PKey.
Link recv_buf onto rmpp_list right after the list is initialized, so the error path has something to free.
--- drivers/infiniband/core/mad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/core/mad.c +2 -1
@@ -1805,6 +1805,8 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,int ret;INIT_LIST_HEAD (&mad_recv_wc->rmpp_list); +list_add (&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list); + ret =ib_mad_enforce_security (mad_agent_priv, mad_recv_wc->wc->pkey_index);if (ret) {
@@ -1813,7 +1815,6 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,return ; } -list_add (&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list);if (is_kernel_rmpp_data_response (mad_agent_priv, mad_recv_wc)) {spin_lock_irqsave (&mad_agent_priv->lock, flags); mad_send_wr =ib_find_send_mad (mad_agent_priv, mad_recv_wc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 609/982 RDMA/irdma: Enforce local fence for IB_WR_REG_MR
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Moroni <[email protected]>
[ Upstream commit 3fb905f07ea45b31c8f67ba6e4668de46f527e65 ]
Enforce local fence for IB_WR_REG_MR to avoid spurious FASTREG_VALID_MKEY async events during heavy invalidation and registration activity.
Commit 69e8e429bca2 ("RDMA/irdma: Enforce local fence for LOCAL_INV WRs") was very similar, but was not sufficient to prevent all occurrences of these async events.
--- drivers/infiniband/hw/irdma/verbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/irdma/verbs.c +1 -1
@@ -3282,7 +3282,7 @@ static int irdma_post_send(struct ib_qp *ibqp, stag_info.total_len = iwmr->ibmr.length; stag_info.reg_addr_pa = *palloc->level1.addr; stag_info.first_pm_pbl_index = palloc->level1.idx; - stag_info.local_fence = ib_wr->send_flags &IB_SEND_FENCE ; + stag_info.local_fence = true;if (iwmr->npages >IRDMA_MIN_PAGES_PER_FMR ) stag_info.chunk_size =1 ; err = irdma_sc_mr_fast_register(&iwqp->sc_qp, &stag_info,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 610/982 RDMA/rtrs-clt: Fix CQ pool leak when connect is interrupted
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quanye Yang <[email protected]>
[ Upstream commit 2ae16aaa78b5edc6e6d0904c84fd9cdfb762bcda ]
The client borrows shared CQ credits in the ADDR_RESOLVED handler via ib_cq_pool_get(), before the peer is connected. create_cm() can return -ERESTARTSYS from wait_event_interruptible_timeout() without destroying the CM ID. The init_conns() and stop-and-destroy paths then call destroy_con_cq_qp() while cq is still NULL (no PUT) and only afterwards rdma_destroy_id().
CMA serializes the handler against rdma_destroy_id() with handler_mutex, but that does not order the GET against destroy_con_cq_qp(). If ADDR_RESOLVED has already passed the DESTROYING check, it can take con_mutex, GET credits, and then lose the con to kfree. Device unregister later hits WARN_ON(cq->cqe_used) in ib_cq_pool_cleanup().
Set a per-connection flag under con_mutex before CQ/QP teardown so a racing ADDR_RESOLVED cannot borrow credits after teardown has begun.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 8 ++++++++ drivers/infiniband/ulp/rtrs/rtrs-clt.h | 2 ++ 2 files changed, 10 insertions(+)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +8 -0
@@ -1738,6 +1738,8 @@ static void destroy_con_cq_qp(struct rtrs_clt_con *con)/* * Be careful here: destroy_con_cq_qp() can be called even * create_con_cq_qp() failed, see comments there. +* Caller must set con->destroyed under this lock first so a +* racing ADDR_RESOLVED cannot ib_cq_pool_get() after we PUT/SKIP. */ lockdep_assert_held (&con->con_mutex);rtrs_cq_qp_destroy (&con->c);
@@ -1772,6 +1774,10 @@ static int rtrs_rdma_addr_resolved(struct rtrs_clt_con *con)int err;mutex_lock (&con->con_mutex); +if (con->destroyed) { +mutex_unlock (&con->con_mutex); +return -ECONNABORTED ; + } err =create_con_cq_qp (con);mutex_unlock (&con->con_mutex);if (err) {
@@ -2202,6 +2208,7 @@ static void rtrs_clt_stop_and_destroy_conns(struct rtrs_clt_path *clt_path)break ; con =to_clt_con (clt_path->s.con[cid]);mutex_lock (&con->con_mutex); + con->destroyed = true;destroy_con_cq_qp (con);mutex_unlock (&con->con_mutex);destroy_cm (con);
@@ -2368,6 +2375,7 @@ static int init_conns(struct rtrs_clt_path *clt_path)if (con->c.cm_id) {stop_cm (con);mutex_lock (&con->con_mutex); + con->destroyed = true;destroy_con_cq_qp (con);mutex_unlock (&con->con_mutex);destroy_cm (con);
drivers/infiniband/ulp/rtrs/rtrs-clt.h +2 -0
@@ -75,6 +75,8 @@ struct rtrs_clt_con {unsigned int cpu;struct mutex con_mutex;int cm_err; +/* Set under con_mutex before CQ/QP teardown. */ +bool destroyed; };/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 611/982 dmaengine: sprd: Fix runtime PM reference leak in probe
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit a7df136ec529ee49a789c5029bc37b98b0d4bedd ]
pm_runtime_get_sync() increments a device's usage counter even when it fails. sprd_dma_probe() currently jumps directly to controller clock cleanup on that error, bypassing both pm_runtime_put_noidle() and pm_runtime_disable(). This can happen if the preceding unchecked pm_runtime_set_active() fails and the following runtime-resume attempt also returns an error.
Enter the existing runtime-PM unwind path instead. This drops the reference without idling the partially initialized device, disables runtime PM, and then releases the controller clocks. The success path and propagated error code are unchanged.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/dma/sprd-dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/sprd-dma.c +1 -2
@@ -1206,7 +1206,7 @@ static int sprd_dma_probe(struct platform_device *pdev) ret =pm_runtime_get_sync (&pdev->dev);if (ret <0 ) - goto err_rpm; + goto err_register; ret =dma_async_device_register (&sdev->dma_dev);if (ret <0 ) {
@@ -1228,7 +1228,6 @@ static int sprd_dma_probe(struct platform_device *pdev) err_register:pm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev); -err_rpm:sprd_dma_disable (sdev);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 612/982 wifi: virt_wifi: free skb when disconnected
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mariano Baragiola <[email protected]>
[ Upstream commit f9edf7cf63b96d2b776fca8d258d3c5256e40c8e ]
When the simulated link is disconnected, virt_wifi_start_xmit() returns NET_XMIT_DROP without freeing the skb. dev_hard_start_xmit() treats this return value as consumed, so every packet sent while disconnected leaks its skb.
Free the skb before returning the drop status.
--- drivers/net/wireless/virt_wifi.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/virt_wifi.c +1 -0
@@ -430,6 +430,7 @@ static netdev_tx_t virt_wifi_start_xmit(struct sk_buff *skb, priv->tx_packets++;if (!priv->is_connected) { priv->tx_failed++; +dev_kfree_skb_any (skb);return NET_XMIT_DROP ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 613/982 wifi: mwifiex: fix IRQ leak using wrong index in MSI-X error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peng Hao <[email protected]>
[ Upstream commit a3d722190cdef18da4878b5efc27c3c386dda248 ]
mwifiex_pcie_request_irq() registers each MSI-X vector with a per-index dev_id (&card->msix_ctx[i]). On a request_irq() failure the cleanup loop "for (j = 0; j < i; j++)" frees msix_entries[j].vector but passes the failed index's &card->msix_ctx[i] as the dev_id. free_irq() matches on (irq, dev_id), so it fails to find the action registered with &card->msix_ctx[j]: the already-requested IRQ j is not freed (leaked) and free_irq() warns about freeing a non-existent IRQ. Use &card->msix_ctx[j].
--- drivers/net/wireless/marvell/mwifiex/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/mwifiex/pcie.c +1 -1
@@ -3241,7 +3241,7 @@ static int mwifiex_pcie_request_irq(struct mwifiex_adapter *adapter) ret);for (j =0 ; j < i; j++)free_irq (card->msix_entries[j].vector, - &card->msix_ctx[i]); + &card->msix_ctx[j]);pci_disable_msix (pdev); }else {mwifiex_dbg (adapter,MSG ,"MSIx enabled!" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 614/982 wifi: libipw: reject too-short beacon and probe responses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shmulik Cohen <[email protected]>
[ Upstream commit 5ce5721e8cbe3e80db8f43851cc2a2a92485ef4b ]
libipw_process_probe_response() and the libipw_network_init() call it makes assume the frame contains the full 36-byte beacon and probe response prefix, but the ipw2100 and ipw2200 receive paths only establish that a management frame carries the generic 24-byte three-address header.
libipw_network_init() then computes the information element length as
stats->len - sizeof(*beacon)
stats->len is a u16 and sizeof() has type size_t, so the subtraction is evaluated as size_t and wraps instead of going negative. Truncating that to the u16 length parameter of libipw_parse_info_param() yields 65524 for a 24-byte beacon, and the parser then walks the receive buffer as if it held almost 64 KiB of information elements, reading past the allocation.
Reject the frame before any fixed field is touched.
Found by an AI-assisted review of length arithmetic in management frame parsers. Verified with a KUnit case under Generic KASAN on arm64 under QEMU; I do not have the hardware, so it is not tested on a real device.
--- drivers/net/wireless/intel/ipw2x00/libipw_rx.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/intel/ipw2x00/libipw_rx.c +3 -0
@@ -1514,6 +1514,9 @@ static void libipw_process_probe_response(struct libipw_device#endif unsigned long flags; +if (stats->len <sizeof (*beacon)) +return ; + LIBIPW_DEBUG_SCAN("'%*pE' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n", info_element->len, info_element->data, beacon->header.addr3,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 615/982 wifi: libipw: reject too-short association responses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shmulik Cohen <[email protected]>
[ Upstream commit adb7118b7d2cfd7e8213c17d7d2829f353017754 ]
libipw_handle_assoc_resp() reads the capability, status and aid fields of the 30-byte association response prefix and then computes the information element length as
stats->len - sizeof(*frame)
stats->len is a u16 and sizeof() has type size_t, so the subtraction is evaluated as size_t and wraps instead of going negative. Truncating that to the u16 length parameter of libipw_parse_info_param() turns a frame shorter than the fixed fields into a length near 64 KiB, and the parser then reads past the receive buffer.
Both the ipw2100 and ipw2200 management receive paths reach this function having established only that the frame carries the generic 24-byte three-address header.
Reject the frame before any fixed field is touched.
Found by an AI-assisted review of length arithmetic in management frame parsers. Verified with a KUnit case under Generic KASAN on arm64 under QEMU; I do not have the hardware, so it is not tested on a real device.
--- drivers/net/wireless/intel/ipw2x00/libipw_rx.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/intel/ipw2x00/libipw_rx.c +3 -0
@@ -1302,6 +1302,9 @@ static int libipw_handle_assoc_resp(struct libipw_device *ieee, struct libipw_asstruct libipw_network *network = &network_resp;struct net_device *dev = ieee->dev; +if (stats->len <sizeof (*frame)) +return 1 ; + network->flags =0 ; network->qos_data.active =0 ; network->qos_data.supported =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 616/982 IB/IPoIB: Avoid restoring OPER_UP after multicast flush
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 9a141d3dc869d18b2eab35e999f4790a9b84e40f ]
ipoib_ib_dev_flush_light() temporarily clears IPOIB_FLAG_OPER_UP to prevent multicast joins while ipoib_mcast_dev_flush() is running, and restores the flag afterwards if it was previously set.
This restore races with ipoib_ib_dev_down(). If the interface is brought down while the flush is in progress, ipoib_ib_dev_down() clears IPOIB_FLAG_OPER_UP, but the flush path may set it again after the device has already gone down.
Since commit 894021a75291 ("IB/ipoib: Make the carrier_on_task race aware"), ipoib_mcast_carrier_on_task() relies on IPOIB_FLAG_OPER_UP being cleared to terminate its rtnl_trylock() retry loop. If the flag is left set after shutdown, the workqueue retries forever, causing teardown to deadlock when ipoib_ndo_uninit() waits in destroy_workqueue() while holding RTNL.
Instead of overloading IPOIB_FLAG_OPER_UP to block multicast joins during a light flush, introduce a dedicated IPOIB_FLAG_MCAST_FLUSH flag. Use it together with IPOIB_FLAG_OPER_UP to determine whether multicast joins are allowed, avoiding the race with device shutdown.
--- drivers/infiniband/ulp/ipoib/ipoib.h | 7 +++++++ drivers/infiniband/ulp/ipoib/ipoib_ib.c | 12 +++++++----- drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 16 ++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib.h +7 -0
@@ -87,6 +87,7 @@ enum {IPOIB_FLAG_INITIALIZED =1 ,IPOIB_FLAG_ADMIN_UP =2 ,IPOIB_PKEY_ASSIGNED =3 , +IPOIB_FLAG_MCAST_FLUSH =4 ,IPOIB_FLAG_SUBINTERFACE =5 ,IPOIB_STOP_REAPER =7 , IPOIB_FLAG_ADMIN_CM = 9,
@@ -417,6 +418,12 @@ struct ipoib_dev_priv {const struct net_device_ops *rn_ops; }; +static inline bool ipoib_mcast_allowed (struct ipoib_dev_priv *priv) +{ +return test_bit (IPOIB_FLAG_OPER_UP , &priv->flags) && + !test_bit (IPOIB_FLAG_MCAST_FLUSH , &priv->flags); +} +struct ipoib_ah {struct net_device *dev;struct ib_ah *ah;
drivers/infiniband/ulp/ipoib/ipoib_ib.c +7 -5
@@ -1211,17 +1211,19 @@ static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv, }if (level ==IPOIB_FLUSH_LIGHT ) { -int oper_up;ipoib_mark_paths_invalid (dev); -/* Set IPoIB operation as down to prevent races between: +/* Set MCAST_FLUSH to prevent races between: * the flush flow which leaves MCG and on the fly joins * which can happen during that time. mcast restart task * should deal with join requests we missed. +* +* Do not clear OPER_UP for this; restoring it races with +* ipoib_ib_dev_down() and can leave OPER_UP set after the +* device is down. */ - oper_up =test_and_clear_bit (IPOIB_FLAG_OPER_UP , &priv->flags); +set_bit (IPOIB_FLAG_MCAST_FLUSH , &priv->flags);ipoib_mcast_dev_flush (dev); -if (oper_up) -set_bit (IPOIB_FLAG_OPER_UP , &priv->flags); +clear_bit (IPOIB_FLAG_MCAST_FLUSH , &priv->flags);ipoib_reap_dead_ahs (priv); }
drivers/infiniband/ulp/ipoib/ipoib_multicast.c +8 -8
@@ -74,7 +74,7 @@ static void __ipoib_mcast_schedule_join_thread(struct ipoib_dev_priv *priv, struct ipoib_mcast *mcast, bool delay) { -if (!test_bit (IPOIB_FLAG_OPER_UP , &priv->flags)) +if (!ipoib_mcast_allowed (priv))return ;/*
@@ -470,7 +470,7 @@ static int ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast)int ret =0 ;if (!priv->broadcast || - !test_bit (IPOIB_FLAG_OPER_UP , &priv->flags)) + !ipoib_mcast_allowed (priv))return -EINVAL ;init_completion (&mcast->done);
@@ -556,7 +556,7 @@ void ipoib_mcast_join_task(struct work_struct *work)unsigned long delay_until =0 ;struct ipoib_mcast *mcast =NULL ; -if (!test_bit (IPOIB_FLAG_OPER_UP , &priv->flags)) +if (!ipoib_mcast_allowed (priv))return ;if (ib_query_port (priv->ca, priv->port, &port_attr)) {
@@ -578,7 +578,7 @@ void ipoib_mcast_join_task(struct work_struct *work)netif_addr_unlock_bh (dev);spin_lock_irq (&priv->lock); -if (!test_bit (IPOIB_FLAG_OPER_UP , &priv->flags)) +if (!ipoib_mcast_allowed (priv)) goto out;if (!priv->broadcast) {
@@ -750,7 +750,7 @@ void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb)spin_lock_irqsave (&priv->lock, flags); -if (!test_bit (IPOIB_FLAG_OPER_UP , &priv->flags) || +if (!ipoib_mcast_allowed (priv) || !priv->broadcast || !test_bit (IPOIB_MCAST_FLAG_ATTACHED , &priv->broadcast->flags)) { ++dev->stats.tx_dropped;
@@ -872,7 +872,7 @@ void ipoib_mcast_restart_task(struct work_struct *work)LIST_HEAD (remove_list);struct ib_sa_mcmember_rec rec; -if (!test_bit (IPOIB_FLAG_OPER_UP , &priv->flags)) +if (!ipoib_mcast_allowed (priv))/* * shortcut...on shutdown flush is called next, just * let it do all the work
@@ -966,9 +966,9 @@ void ipoib_mcast_restart_task(struct work_struct *work)ipoib_mcast_remove_list (&remove_list);/* -* Double check that we are still up +* Double check that we are still up and not flushing */ -if (test_bit (IPOIB_FLAG_OPER_UP , &priv->flags)) { +if (ipoib_mcast_allowed (priv)) {spin_lock_irq (&priv->lock);__ipoib_mcast_schedule_join_thread (priv,NULL ,0 );spin_unlock_irq (&priv->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 617/982 wifi: cfg80211: check IP header size in cfg80211_classify8021d()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 48b2c5c628b09cf36cbeca53e0432fc2a7518be7 ]
A frame that looks like IP can be transmitted, but be too short, so the DS field is read incorrectly:
BUG: KMSAN: uninit-value in cfg80211_classify8021d+0x99d/0x12b0 net/wireless/util.c:1027 cfg80211_classify8021d+0x99d/0x12b0 net/wireless/util.c:1027 ieee80211_select_queue+0x37a/0x9e0 net/mac80211/wme.c:180 __ieee80211_subif_start_xmit+0x60f/0x1d90 net/mac80211/tx.c:4304 ieee80211_subif_start_xmit+0xa8/0x6d0 net/mac80211/tx.c:4538 ... packet_sendmsg+0x9173/0xa2a0 net/packet/af_packet.c:3108
Use skb_header_pointer() like the MPLS case.
--- net/wireless/util.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
net/wireless/util.c +22 -4
@@ -985,12 +985,30 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb, }switch (skb->protocol) { -case htons (ETH_P_IP ): - dscp =ipv4_get_dsfield (ip_hdr (skb)) &0xfc ; +case htons (ETH_P_IP ): { +const struct iphdr *iph; +struct iphdr _iph; + + iph =skb_header_pointer (skb,sizeof (struct ethhdr ), +sizeof (*iph), &_iph); +if (!iph) +return 0 ; + + dscp =ipv4_get_dsfield (iph) &0xfc ;break ; -case htons (ETH_P_IPV6 ): - dscp =ipv6_get_dsfield (ipv6_hdr (skb)) &0xfc ; + } +case htons (ETH_P_IPV6 ): { +const struct ipv6hdr *ip6h; +struct ipv6hdr _ip6h; + + ip6h =skb_header_pointer (skb,sizeof (struct ethhdr ), +sizeof (*ip6h), &_ip6h); +if (!ip6h) +return 0 ; + + dscp =ipv6_get_dsfield (ip6h) &0xfc ;break ; + }case htons (ETH_P_MPLS_UC ):case htons (ETH_P_MPLS_MC ): {struct mpls_label mpls_tmp, *mpls;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 618/982 soundwire: cadence_master: wait and cancel cdns->work before clock stop
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bard Liao <[email protected]>
[ Upstream commit aba7b41faeecb7692458095ce6fafc341fe0b80e ]
A peripheral event could happen during the clock stop process. We need to wait for the event be handled before stopping the bus clock. Otherwise, we will get the IO transfer timed out issue.
--- drivers/soundwire/cadence_master.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/soundwire/cadence_master.c +7 -0
@@ -1585,6 +1585,13 @@ int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake)return 0 ; } +/* +* wait for any in-flight peripheral event handling to complete before stopping the clock. +* No need to disable peripheral interrupts before canceling the work, as the peripheral +* interrupts are already masked before the work is scheduled. +*/ +cancel_work_sync (&cdns->work); +/* * Before entering clock stop we mask the Slave * interrupts. This helps avoid having to deal with e.g. a
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 619/982 MIPS: Octeon: apply USB FDT fixups also when USB is modular
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Orgad Shaneh <[email protected]>
[ Upstream commit 126f16e0a1b353c2ba5c7e2c8626cfa865934f9f ]
The uctl/usbn device-tree fixups in octeon_prune_device_tree() - which set the board's USB reference-clock frequency and type from __cvmx_helper_board_usb_get_clock_type() - are guarded by "#ifdef CONFIG_USB", which is false when USB is built as a module. The fixups then silently disappear and octeon-hcd sees whatever default the DTS carries (12MHz crystal in octeon_3xxx.dts), leaving the PHY dead or the bus erroring on boards with a different reference clock.
Use IS_ENABLED() so USB=m gets the same fixups as USB=y.
--- arch/mips/cavium-octeon/octeon-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/cavium-octeon/octeon-platform.c +2 -2
@@ -15,7 +15,7 @@#include <asm/octeon/octeon.h> #include <asm/octeon/cvmx-helper-board.h> -#ifdef CONFIG_USB +#if IS_ENABLED (CONFIG_USB )#include <linux/usb/ehci_def.h> #include <linux/usb/ehci_pdriver.h> #include <linux/usb/ohci_pdriver.h>
@@ -1079,7 +1079,7 @@ int __init octeon_prune_device_tree(void) ; } -#ifdef CONFIG_USB +#if IS_ENABLED (CONFIG_USB )/* OHCI/UHCI USB */ alias_prop =fdt_getprop (initial_boot_params, aliases,"uctl" ,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 620/982 dma-coherent: Warn if OF reserved memory is beyond current coherent DMA mask
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit 89461db349cc00816c01d55507d511466b3b7151 ]
When a reserved memory region described in the device tree is attached to a device, it is expected that the device's limitations are correctly included in that description.
However, if the device driver failed to implement DMA address masking or addressing beyond the default 32 bits (on arm64), then bad things could happen because the DMA address was truncated, such as playing back audio with no actual audio coming out, or DMA overwriting random blocks of kernel memory.
Check against the coherent DMA mask when the memory regions are attached to the device. Give a warning when the memory region can not be covered by the mask.
A warning instead of a hard error was chosen, because it is possible that existing drivers could be working fine even if they forgot to extend the coherent DMA mask.
Stable-dep-of: 504981db4f69 ("dma-coherent: report a failed reserved memory assignment")
--- kernel/dma/coherent.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
kernel/dma/coherent.c +9 -3
@@ -335,16 +335,22 @@ static struct reserved_mem *dma_reserved_default_memory __initdata;static int rmem_dma_device_init (struct reserved_mem *rmem,struct device *dev) { -if (!rmem->priv) { -struct dma_coherent_mem *mem; +struct dma_coherent_mem *mem = rmem->priv; +if (!mem) { mem =dma_init_coherent_memory (rmem->base, rmem->base, rmem->size, true);if (IS_ERR (mem))return PTR_ERR (mem); rmem->priv = mem; } -dma_assign_coherent_memory (dev, rmem->priv); + +/* Warn if the device potentially can't use the reserved memory */ +if (mem->device_base + rmem->size -1 > +min_not_zero (dev->coherent_dma_mask, dev->bus_dma_limit)) +dev_warn (dev,"reserved memory is beyond device's set DMA address range\n" ); + +dma_assign_coherent_memory (dev, mem);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 621/982 dma-coherent: report a failed reserved memory assignment
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 504981db4f69bdd28054fb98c96a3a67f7248dde ]
rmem_dma_device_init() drops the return value of dma_assign_coherent_memory() and always reports success. That call fails with -EBUSY when the device already has a coherent pool, and the file allows only "*one* such region of memory" per device.
of_reserved_mem_device_init_by_idx() reads the zero as success. It logs "assigned reserved memory node" for a region that was not assigned and records the pairing, so of_reserved_mem_device_release() later runs rmem_dma_device_release() for it. That clears dev->dma_mem without looking at which region it was called for, dropping the pool the device did get and leaving it on ordinary memory.
dma_declare_coherent_memory() checks the same call and releases the memory on failure, and rmem_swiotlb_device_init() propagates its own errors. Return the error here as well, so a device tree that assigns two pools to one device fails the probe instead of half working.
--- kernel/dma/coherent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/dma/coherent.c +1 -2
@@ -350,8 +350,7 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) min_not_zero(dev->coherent_dma_mask, dev->bus_dma_limit))dev_warn (dev,"reserved memory is beyond device's set DMA address range\n" ); -dma_assign_coherent_memory (dev, mem); -return 0 ; +return dma_assign_coherent_memory (dev, mem); } static void rmem_dma_device_release(struct reserved_mem *rmem,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 622/982 dmaengine: Fix device kref underflow in dma_chan_put()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivank Garg <[email protected]>
[ Upstream commit 44dab659064eb5c10adb0306510eebe848ed592d ]
dma_chan_get() takes chan->device->ref only on the slow path:
/* no kref on fast path */
if (chan->client_count) {
__module_get(owner);
chan->client_count++;
return 0;
}
if (!try_module_get(owner))
return -ENODEV;
if (!dma_device_get(chan->device)) { // calls kref_get_unless_zero()dma_chan_put() drops the ref unconditionally, so every fast-path get/put pair drops one extra device reference.
The bug fires when two conditions hold together: a non-private provider has a persistent client holding chan->client_count > 0 and another client cycles dmaengine_get()/dmaengine_put(). When the kref hits zero, the subsequent dma_find_channel() returns NULL even though the provider module is still loaded.
Fix this by dropping device->ref only on the last put, matching the single slow-path get.
--- drivers/dma/dmaengine.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dma/dmaengine.c +3 -1
@@ -513,7 +513,9 @@ static void dma_chan_put(struct dma_chan *chan) chan->route_data =NULL ; } -dma_device_put (chan->device); +/* This channel is not in use anymore, drop the device ref */ +if (!chan->client_count) +dma_device_put (chan->device);module_put (dma_chan_to_owner (chan)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 623/982 dmaengine: fix use-after-free in dma_chan_put() and dma_release_channel()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivank Garg <[email protected]>
[ Upstream commit e873c74132f0c5f1452816cd9bb26208f0bba1e1 ]
When dma_device_put() drops the last reference on chan->device->ref, dma_device_release() runs and may free the dma_device along with its channels.
dma_chan_put() then still reads chan->device->owner via dma_chan_to_owner() for the trailing module_put(). KASAN catches it:
slab-use-after-free in dma_chan_put+0x3e6/0x4c0 Read of size 8 by task insmod/6319 Freed by task 6319: kfree+0x225/0x470 dma_chan_put+0x395/0x4c0 dmaengine_put+0xf8/0x160
Cache the module owner in dma_chan_put() before the put so the trailing module_put() does not need chan->device.
--- drivers/dma/dmaengine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/dma/dmaengine.c +4 -1
@@ -493,10 +493,13 @@ static int dma_chan_get(struct dma_chan *chan)*/ static void dma_chan_put (struct dma_chan *chan) { +struct module *owner; +/* This channel is not in use, bail out */ if (!chan->client_count)return ; + owner =dma_chan_to_owner (chan); chan->client_count--;/* This channel is not in use anymore, free it */
@@ -516,7 +519,7 @@ static void dma_chan_put(struct dma_chan *chan)/* This channel is not in use anymore, drop the device ref */ if (!chan->client_count)dma_device_put (chan->device); -module_put (dma_chan_to_owner (chan)); +module_put (owner); }enum dma_status dma_sync_wait (struct dma_chan *chan,dma_cookie_t cookie)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 624/982 dmaengine: wait for RCU readers before releasing dma_device
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivank Garg <[email protected]>
[ Upstream commit dc750422170a563c7a81f6e49d36bb02c62ae37f ]
dma_issue_pending_all() walks the dma_device_list with list_for_each_entry_rcu() under rcu_read_lock(). dma_device_release() unlinks the device with list_del_rcu() and then calls device->device_release() (which in many drivers, such as plx_dma.c, directly calls kfree()).
Because there is no grace period between unlinking the device and freeing it, concurrent RCU readers in dma_issue_pending_all() can access the device after it has been freed.
The lockless walk originally relied on clients holding a dmaengine reference to pin the provider module, and therefore the device, for as long as they might traverse the list. Commit 8ad342a86359 ("dmaengine:
Add reference counting to dma_device struct") decoupled the dma_device lifetime from the module reference, so the device can now be released while a reader is still walking the list.
Add synchronize_rcu() before the device is freed, so RCU readers are guaranteed to have finished. Keep it unconditional: providers that do not implement device_release() free the device themselves once dma_async_device_unregister() returns. This call will delay for a grace period with dma_list_mutex held, which is safe and only teardown path is delayed.
--- drivers/dma/dmaengine.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/dmaengine.c +1 -0
@@ -426,6 +426,7 @@ static void dma_device_release(struct kref *ref)list_del_rcu (&device->global_node);dma_channel_rebalance (); +synchronize_rcu ();if (device->device_release) device->device_release (device);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 625/982 wifi: cfg80211: only group hidden BSSes with beacon entries
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 068843ed0902c552a13860c5ec6b2ca65b57a065 ]
When a probe response for an unknown BSS comes in, __cfg80211_bss_update() looks for an existing entry with the same BSSID and a hidden (zero-length or NUL-filled) SSID, and if it finds one it groups them, using the beacon IEs from the existing entry.
But that could find another entry without a beacon, if it was also from a probe response (with SSID), so there's a group without beacon elements.
If a beacon with a hidden SSID for that BSSID arrives later, cfg80211_combine_bsses() goes looking for the probe response entries that belong to it - i.e. entries with the same BSSID and channel that have no beacon IEs - and finds those two. They are already grouped with each other, so it hits its
WARN_ON_ONCE(bss->pub.hidden_beacon_bss)
WARN_ON_ONCE(!list_empty(&bss->hidden_list))
which are there because an entry without beacon elements is not supposed to be part of a group yet.
Only combine entries when a beacon was already received, ones that are kept separate will be combined when a beacon arrives.
--- net/wireless/scan.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/wireless/scan.c +7 -0
@@ -1879,6 +1879,13 @@ cfg80211_bss_update(struct cfg80211_registered_device *rdev,if (!hidden) hidden =rb_find_bss (rdev, tmp,BSS_CMP_HIDE_NUL ); +/* +* Only group with an entry with beacon data, otherwise +* beacon data can never be filled/updated. +*/ +if (hidden && + !rcu_access_pointer (hidden->pub.beacon_ies)) + hidden =NULL ;if (hidden) { new->pub.hidden_beacon_bss = &hidden->pub; list_add(&new->hidden_list,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 626/982 wifi: cfg80211: dont filter by BSS type when removing stale entries
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit b377e1000d963e7182a987082b4b06580bd7ac84 ]
When an assoc AP switches to a channel that already has a BSS entry, cfg80211_update_assoc_bss_entry() removes that entry before rehashing the real one, since the two would otherwise collide in the BSS rbtree.
The lookup for that entry also required it to match the connection's BSS type, so an entry advertising e.g. the IBSS capability bit was left in place, and the following cfg80211_rehash_bss() then ran into it:
WARN_ON(!cmp)
Changing the type shouldn't really happen, but can be triggered by a rogue AP/device, so drop the check and remove any entries matching the comparison.
--- net/wireless/scan.c | 5 ----- 1 file changed, 5 deletions(-)
net/wireless/scan.c +0 -5
@@ -2684,11 +2684,6 @@ void cfg80211_update_assoc_bss_entry(struct wireless_dev *wdev, cbss->pub.channel = chan;list_for_each_entry (bss, &rdev->bss_list, list) { -if (!cfg80211_bss_type_match (bss->pub.capability, - bss->pub.channel->band, - wdev->conn_bss_type)) -continue ; -if (bss == cbss)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 627/982 wifi: mac80211: suppress chanctx warning for debugfs reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit bf29d085e0eba92388518719d044f4702a8c6644 ]
Before suspend all the channel contexts should removed, so the warning makes sense and should be there, but during reset the same code is called without first removing. Limit the check to the real suspend case.
--- net/mac80211/cfg.c | 2 +- net/mac80211/debugfs.c | 2 +- net/mac80211/ieee80211_i.h | 2 +- net/mac80211/pm.c | 8 +++++--- 4 files changed, 8 insertions(+), 6 deletions(-)
net/mac80211/cfg.c +1 -1
@@ -2725,7 +2725,7 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,static int ieee80211_suspend (struct wiphy *wiphy,struct cfg80211_wowlan *wowlan) { -return __ieee80211_suspend (wiphy_priv (wiphy), wowlan); +return __ieee80211_suspend (wiphy_priv (wiphy), wowlan, false); }static int ieee80211_resume (struct wiphy *wiphy)
net/mac80211/debugfs.c +1 -1
@@ -417,7 +417,7 @@ static ssize_t reset_write(struct file *file, const char __user *user_buf,rtnl_lock ();wiphy_lock (local->hw.wiphy); -__ieee80211_suspend (&local->hw,NULL ); +__ieee80211_suspend (&local->hw,NULL , true); ret =__ieee80211_resume (&local->hw);wiphy_unlock (local->hw.wiphy);
net/mac80211/ieee80211_i.h +1 -1
@@ -2161,7 +2161,7 @@ int ieee80211_reconfig(struct ieee80211_local *local);void ieee80211_stop_device (struct ieee80211_local *local);int __ieee80211_suspend (struct ieee80211_hw *hw, -struct cfg80211_wowlan *wowlan); +struct cfg80211_wowlan *wowlan,bool reset);static inline int __ieee80211_resume (struct ieee80211_hw *hw) {
net/mac80211/pm.c +5 -3
@@ -18,7 +18,8 @@ static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)cfg80211_sched_scan_stopped_locked (local->hw.wiphy,0 ); } -int __ieee80211_suspend (struct ieee80211_hw *hw,struct cfg80211_wowlan *wowlan) +int __ieee80211_suspend (struct ieee80211_hw *hw,struct cfg80211_wowlan *wowlan, +bool reset) {struct ieee80211_local *local =hw_to_local (hw);struct ieee80211_sub_if_data *sdata;
@@ -167,9 +168,10 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)/* * We disconnected on all interfaces before suspend, all channel -* contexts should be released. +* contexts should be released, but on 'reset' debugfs that's +* not true so don't check there. */ -WARN_ON (!list_empty (&local->chanctx_list)); +WARN_ON (!reset && !list_empty (&local->chanctx_list));/* stop hardware - this must stop RX */ ieee80211_stop_device (local);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 628/982 wifi: mac80211: unlist vifs when their netdev is unregistered
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit eee2efd82867b623982ac51925b5a1812a74c50d ]
mac80211 only removes vifs from the local->interfaces list when an interface is removed via ieee80211_if_remove(), before it unregisters the netdev. However, it's possible for a netdev to be unregistered without going through that: When the netns that holds the wiphy is destroyed, the wiphy is supposed to move to the init_ns, but that can run into allocation failures.
Then, mac80211 has an interface listed that doesn't exist, and will eventually hit
BUG: failure at net/wireless/core.h:141/wiphy_to_rdev()! ... _cfg80211_unregister_wdev+0x24/0x36a [cfg80211] cfg80211_unregister_wdev+0x15/0x1d [cfg80211] ieee80211_remove_interfaces+0x1ff/0x257 [mac80211] ieee80211_unregister_hw+0x73/0x1d1 [mac80211] mac80211_hwsim_del_radio+0x114/0x166 [mac80211_hwsim]
Remove the interface from the list in ->ndo_uninit if it's still around to avoid this.
--- net/mac80211/iface.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
net/mac80211/iface.c +25 -1
@@ -861,9 +861,33 @@ static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)ieee80211_link_stop (&sdata->deflink); } +/* +* The netdev can be unregistered without mac80211 doing it, e.g. by the netdev +* core when cfg80211 couldn't move it out of a network namespace that's being +* destroyed. Drop it from the interface list either way. +*/ +static void ieee80211_unlist_sdata (struct ieee80211_sub_if_data *sdata) +{ +struct ieee80211_local *local = sdata->local; +struct ieee80211_sub_if_data *iter; + +ASSERT_RTNL (); + +list_for_each_entry (iter, &local->interfaces, list) { +if (iter != sdata) +continue ; +guard (mutex)(&local->iflist_mtx); +list_del_rcu (&sdata->list); +return ; + } +} +static void ieee80211_uninit (struct net_device *dev) { -ieee80211_teardown_sdata (IEEE80211_DEV_TO_SUB_IF (dev)); +struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev); + +ieee80211_unlist_sdata (sdata); +ieee80211_teardown_sdata (sdata); } static u16 ieee80211_netdev_select_queue(struct net_device *dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 629/982 wifi: mac80211_hwsim: dont hand frames to mac80211 while stopping
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 87840d4a3a21b1c19b867a80e16ba69dff284de2 ]
The code checks ->started for frames coming from wmediumd, but the radio can be stopped after the check and before frame delivery, causing mac80211 to hit the WARN_ON(!local->started).
Expand the mutex for this case and synchronise against it when the radio is stopped to avoid being able to hit the warning with hwsim.
Drop the error print that would've complicated the error path, it only triggers for allocation failures (already noisy) and malformed frames anyway.
--- drivers/net/wireless/mac80211_hwsim.c | 39 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/net/wireless/mac80211_hwsim.c +24 -15
@@ -1969,7 +1969,12 @@ static void mac80211_hwsim_stop(struct ieee80211_hw *hw)struct sk_buff *skb;int i; - data->started = false; +/* +* Serialise against wmediumd userspace, so no more frames +* can be handed to mac80211 after this returns. +*/ +scoped_guard (mutex, &data->mutex) + data->started = false;for (i =0 ; i <ARRAY_SIZE (data->link_data); i++)hrtimer_cancel (&data->link_data[i].beacon_timer);
@@ -4913,12 +4918,12 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,if (frame_data_len <sizeof (struct ieee80211_hdr_3addr ) || frame_data_len >IEEE80211_MAX_DATA_LEN ) - goto err; + goto out;/* Allocate new skb here */ skb =alloc_skb (frame_data_len,GFP_KERNEL );if (skb ==NULL ) - goto err; + goto out;/* Copy the data */ skb_put_data (skb, frame_data, frame_data_len);
@@ -4943,10 +4948,17 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, goto out; } +/* +* Serialise against mac80211_hwsim_stop() - mac80211 doesn't allow +* frames reported while the HW is down, hence the ->started check +* must be under mutex. +*/ +mutex_lock (&data2->mutex); +/* check if radio is configured properly */ if ((data2->idle && !data2->tmp_chan) || !data2->started) - goto out; + goto out_unlock;/* A frame is received from user space */ memset (&rx_status,0 ,sizeof (rx_status));
@@ -4962,22 +4974,18 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, iter_data.channel =ieee80211_get_channel (data2->hw->wiphy, rx_status.freq);if (!iter_data.channel) - goto out; + goto out_unlock; rx_status.band = iter_data.channel->band; -mutex_lock (&data2->mutex);if (!hwsim_chans_compat (iter_data.channel, channel)) {ieee80211_iterate_active_interfaces_atomic ( data2->hw,IEEE80211_IFACE_ITER_NORMAL , mac80211_hwsim_tx_iter, &iter_data); -if (!iter_data.receive) { -mutex_unlock (&data2->mutex); - goto out; - } +if (!iter_data.receive) + goto out_unlock; } -mutex_unlock (&data2->mutex); }else if (!channel) { - goto out; + goto out_unlock; }else { rx_status.freq = channel->center_freq; rx_status.band = channel->band;
@@ -4985,7 +4993,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, rx_status.rate_idx =nla_get_u32 (info->attrs[HWSIM_ATTR_RX_RATE ]);if (rx_status.rate_idx >= data2->hw->wiphy->bands[rx_status.band]->n_bitrates) - goto out; + goto out_unlock; rx_status.signal =nla_get_u32 (info->attrs[HWSIM_ATTR_SIGNAL ]); hdr = (void *)skb->data;
@@ -4995,10 +5003,11 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, rx_status.boottime_ns =ktime_get_boottime_ns ();mac80211_hwsim_rx (data2, &rx_status, skb); +mutex_unlock (&data2->mutex);return 0 ; -err: -pr_debug ("mac80211_hwsim: error occurred in %s\n" , __func__); +out_unlock: +mutex_unlock (&data2->mutex); out:dev_kfree_skb (skb);return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 630/982 wifi: mac80211: reset the AP_VLAN tailroom counter on ifdown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 4504f3960dc4501c73be9f99eabda2e26e9db41e ]
On ifup, AP_VLAN interfaces get crypto_tx_tailroom_needed_cnt from the AP interface, but it's never decremented again unless the AP is also brought down. Thus, bringing the same AP_VLAN up again will increment the counter again and eventually hit the sanity check:
WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt !=
master->crypto_tx_tailroom_needed_cnt);
Reset it on ifdown to avoid that.
--- net/mac80211/iface.c | 2 ++ 1 file changed, 2 insertions(+)
net/mac80211/iface.c +2 -0
@@ -623,6 +623,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_doRCU_INIT_POINTER (sdata->vif.bss_conf.chanctx_conf,NULL );/* see comment in the default case below */ ieee80211_free_keys (sdata, true); +/* increased by AP value on ifup, so reset on ifdown */ + sdata->crypto_tx_tailroom_needed_cnt =0 ;/* no need to tell driver */ break ;case NL80211_IFTYPE_MONITOR :
Signature · 1 line
2.53.0