7.2.6-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 1585/1815 fuse: check for NULL root inode in fuse_fill_super_submount
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
[ Upstream commit 928f659a3e3650978a5b4829cc982324f72b474b ]
fuse_iget() can return NULL when its inode allocation fails, but fuse_fill_super_submount() passed the result straight to get_fuse_inode() and decremented fi->nlookup without checking it:
root = fuse_iget(sb, parent_fi->nodeid, ...);
fi = get_fuse_inode(root);
fi->nlookup--;Inside fuse_iget() the inode allocation can fail and return NULL. The submount root takes the iget5_locked() path, whose alloc_inode() can fail under memory pressure (the auto-submount branch can fail the same way in new_inode() or fuse_alloc_submount_lookup()):
inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set,
&nodeid);
if (!inode)
return NULL;A NULL root makes get_fuse_inode() a container_of() on NULL and the nlookup decrement a write to a bogus address, oopsing the mount. With CONFIG_KASAN the following null pointer dereference is reported when the root inode allocation of an auto-submount fails (e.g. under memory pressure):
==================================================================
BUG: KASAN: null-ptr-deref in fuse_get_tree_submount+0x656/0x8b0 Read of size 8 at addr 00000000000002b0 by task ls/942 CPU: 0 PID: 942 Comm: ls Tainted: G W 6.6 #15 Call Trace: <TASK> fuse_get_tree_submount+0x656/0x8b0 vfs_get_tree+0x48/0x140 fc_mount+0x13/0x50 fuse_dentry_automount+0x7a/0xb0 __traverse_mounts+0xca/0x330 step_into+0x339/0xac0 path_lookupat+0xc5/0x2f0 filename_lookup+0x163/0x2a0 vfs_statx+0xd5/0x200 do_statx+0x83/0xd0 __x64_sys_statx+0xa0/0xc0 do_syscall_64+0x37/0x90 entry_SYSCALL_64_after_hwframe+0x78/0xe2 </TASK> ==================================================================
Return -ENOMEM instead; the caller tears down the partially built superblock on error, matching the other error returns in this function.
--- fs/fuse/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/fuse/inode.c +2 -0
@@ -1644,6 +1644,8 @@ static int fuse_fill_super_submount(struct super_block *sb,fuse_fill_attr_from_inode (&root_attr, parent_fi); root =fuse_iget (sb, parent_fi->nodeid,0 , &root_attr,0 ,0 ,fuse_get_evict_ctr (fm->fc)); +if (!root) +return -ENOMEM ;/* * This inode is just a duplicate, so it is not looked up and * its nlookup should not be incremented. fuse_iget() does
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1586/1815 ALSA: hda: Fix connection list comparison in proc output
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit c139e7e44f58a6f8ddc9d850ea9924d34963b5da ]
print_conn_list() compares the raw hardware connection list with the connection list cached by the HDA driver. When they differ, it prints an additional "In-driver Connection" line so that /proc/asound/card*/codec#* shows the topology actually used by the driver.
The comparison currently passes conn_len directly to memcmp(). However, conn_len is a number of connection-list entries, while memcmp() expects a size in bytes. Both list and conn are arrays of hda_nid_t, which is u16, so only half of the connection data is compared.
For example, for two-entry lists such as:
hardware: 0x0c 0x0d
cached: 0x0c 0x0e
conn_len is 2, and the current comparison checks only the first hda_nid_t. The lists are therefore incorrectly treated as identical even though the second connection differs.
This can happen legitimately when codec fixups replace a cached connection list with snd_hda_override_conn_list(). The codec routing used by the driver is not affected, but the proc output can hide the overridden driver-visible routing and provide misleading topology information during codec debugging.
Convert the entry count to a byte size so that memcmp() covers the complete connection list.
--- sound/hda/common/proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/common/proc.c +1 -1
@@ -624,7 +624,7 @@ static void print_conn_list(struct snd_info_buffer *buffer,/* Get Cache connections info */ cache_len =snd_hda_get_conn_list (codec, nid, &list);if (cache_len >=0 && (cache_len != conn_len || -memcmp (list, conn, conn_len) !=0 )) { +memcmp (list, conn, conn_len *sizeof (*conn)) !=0 )) {snd_iprintf (buffer," In-driver Connection: %d\n" , cache_len);if (cache_len >0 ) {snd_iprintf (buffer," " );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1587/1815 vxlan: mdb: Fix use-after-free in vxlan_mdb_flush()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baul Lee <[email protected]>
[ Upstream commit bc2dc66a6693a78f8c1e6ca2dbebd50f16e2c366 ]
vxlan_mdb_flush() iterates over the MDB entries using hlist_for_each_entry_safe(), which only tolerates the removal of the current entry. Contrary to the comment above the loop, the removal of an entry can trigger the removal of another entry.
Flushing the remotes of a (*, G) entry also removes the (S, G) entries that were created for its source list, once they are left without remotes:
vxlan_mdb_remotes_flush()
-> vxlan_mdb_remote_del()
-> vxlan_mdb_remote_srcs_del()
-> vxlan_mdb_remote_src_del()
-> vxlan_mdb_remote_src_fwd_del()
-> __vxlan_mdb_del()
-> vxlan_mdb_entry_put()Such an entry can be located after the (*, G) entry in the list, as vxlan_mdb_entry_get() returns an existing entry without moving it to the head of the list. This order is obtained by adding the (S, G) entry before the (*, G) entry, the latter with NLM_F_REPLACE, as the addition of the source otherwise fails with -EEXIST. The (S, G) entry is then the entry saved by hlist_for_each_entry_safe() and it is freed while the (*, G) entry is processed. The next iteration calls hlist_del() on it again, writing LIST_POISON1 to LIST_POISON2 [1].
Besides device deletion, the flush is also reachable from RTM_DELMDB with NLM_F_BULK.
Fix by re-reading the next entry after the remotes were flushed. The current entry cannot be removed by this flush, as source lists can only be configured on (*, G) entries and the removed entries are (S, G) entries. It is therefore still linked and its next pointer reflects the removals.
[1]
BUG: KASAN: wild-memory-access in vxlan_mdb_entry_put.part.0+0x328/0x588 Write of size 8 at addr dead000000000122 by task ip/327 CPU: 3 UID: 1000 PID: 327 Comm: ip Not tainted 7.2.0-rc7 #2 PREEMPT Call trace: vxlan_mdb_entry_put.part.0+0x328/0x588 vxlan_mdb_flush+0x1d8/0x25c vxlan_mdb_fini+0x8c/0x100 vxlan_uninit+0x1c/0x7c unregister_netdevice_many_notify+0x954/0xd4c rtnl_dellink+0x210/0x530 rtnetlink_rcv_msg+0x434/0x4d0 netlink_rcv_skb+0xc4/0x204 rtnetlink_rcv+0x18/0x24 netlink_unicast+0x4b8/0x548 netlink_sendmsg+0x29c/0x560 ____sys_sendmsg+0x390/0x3ec ___sys_sendmsg+0x114/0x188 __sys_sendmsg+0xf0/0x178 __arm64_sys_sendmsg+0x48/0x60 invoke_syscall.constprop.0+0x58/0x180 el0_svc_common.constprop.0+0x74/0x140 do_el0_svc+0x30/0x40 el0_svc+0x38/0x98 el0t_64_sync_handler+0xa0/0xe4 el0t_64_sync+0x198/0x19c
--- drivers/net/vxlan/vxlan_mdb.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_mdb.c +6 -3
@@ -1428,14 +1428,17 @@ static void vxlan_mdb_flush(struct vxlan_dev *vxlan,struct vxlan_mdb_entry *mdb_entry;struct hlist_node *tmp; -/* The removal of an entry cannot trigger the removal of another entry -* since entries are always added to the head of the list. -*/ hlist_for_each_entry_safe (mdb_entry, tmp, &vxlan->mdb_list, mdb_node) {if (desc->src_vni && desc->src_vni != mdb_entry->key.vni)continue ;vxlan_mdb_remotes_flush (vxlan, mdb_entry, desc); +/* The flush can remove the (S, G) entries created for the +* source list of this entry, including the one saved by +* hlist_for_each_entry_safe(), so re-read it while this entry +* is still linked. +*/ + tmp = mdb_entry->mdb_node.next;/* Entry will only be removed if its remotes list is empty. */ vxlan_mdb_entry_put (vxlan, mdb_entry); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1588/1815 8139cp: fix Rx and Tx not being disabled in cp_suspend
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit cb7643b78d35392f0f434774d78b4c77b80f677f ]
On QEMU rtl8139 model, frames that arrive while the interface is suspended still end up in the stack after resume. With pm_test=devices, which keeps devices suspended for 5s, 200 frames sent to interface during that time and 50 frames after resume, eth0 reports 113 received frames.
cp_suspend() is supposed to stop receiver and the transmitter, but the mask is wrong: (~RxOn | ~TxOn) is ~0, nothing is cleared and Cmd still reads 0x0d when cp_suspend() returns.
Use ~(RxOn | TxOn) so both bits are actually cleared.
--- drivers/net/ethernet/realtek/8139cp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/realtek/8139cp.c +1 -1
@@ -2066,7 +2066,7 @@ static int __maybe_unused cp_suspend(struct device *device)/* Disable Rx and Tx */ cpw16 (IntrMask,0 ); -cpw8 (Cmd,cpr8 (Cmd) & (~RxOn | ~TxOn)); +cpw8 (Cmd,cpr8 (Cmd) & ~(RxOn | TxOn));spin_unlock_irqrestore (&cp->lock, flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1589/1815 net/smc: hash socket only after full initialisation in smc_sk_init()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mahanta Jambigi <[email protected]>
[ Upstream commit 8acf691d8017012e1476c30e7381513c1e929c94 ]
smc_sk_init() calls sk->sk_prot->hash(sk) before several fields are fully initialised: clcsock_release_lock, the saved clcsk_* callbacks, use_fallback/fallback_rsn, and conn.close_work. Once hash() returns the socket is visible to concurrent hash walkers, which can then observe uninitialised state.
Move hash(sk) to the end of smc_sk_init() so the socket is published only after it is fully constructed.
--- net/smc/af_smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/smc/af_smc.c +1 -1
@@ -409,13 +409,13 @@ void smc_sk_init(struct net *net, struct sock *sk, int protocol) "sk_lock-AF_SMC", &smc_key);spin_lock_init (&smc->accept_q_lock);spin_lock_init (&smc->conn.send_lock); - sk->sk_prot->hash (sk);mutex_init (&smc->clcsock_release_lock);smc_init_saved_callbacks (smc); smc->limit_smc_hs = net->smc.limit_smc_hs; smc->use_fallback = false;/* assume rdma capability first */ smc->fallback_rsn =0 ;smc_close_init (smc); + sk->sk_prot->hash (sk); } static struct sock *smc_sock_alloc(struct net *net, struct socket *sock,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1590/1815 platform/x86: dell-wmi-sysman: Fix instance ID bounds
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 5ab078e3241da0beec2022254b5811a8a52cff84 ]
The get_instance_id() macro walks the per-type attribute array with 'i <= instances_count'. Each array is allocated with exactly instances_count entries, so the valid range is [0, instances_count) and the last iteration reads one element past the end. On a name miss that out-of-bounds attribute_name is handed to strcmp(), which reads on until it finds a NUL byte.
Every kobject in these ksets is built from an entry that was populated, so a miss does not look reachable from sysfs today. The bound is wrong either way and the read is out of bounds.
The matching macro in hp-bioscfg carried the same off-by-one and was corrected by commit 25150715e0b0 ("platform/x86: hp-bioscfg: Fix kernel panic in GET_INSTANCE_ID macro"). That macro takes a kobject pointer out of the out-of-bounds element and dereferences it, so it could fault. This one reads a char array.
Use '<' to match the allocation.
--- drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h +1 -1
@@ -107,7 +107,7 @@ enum { static int get_##type##_instance_id(struct kobject *kobj) \ { \ int i; \ - for (i = 0; i <= wmi_priv.type##_instances_count; i++) { \ + for (i = 0; i < wmi_priv.type##_instances_count; i++) { \ if (!(strcmp(kobj->name, wmi_priv.type##_data[i].attribute_name)))\ return i; \ } \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1591/1815 vsock: dont check the listeners sk_err in vsock_accept()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Dinh Phi <[email protected]>
[ Upstream commit b8c899cf5e7be29840a172c183dedd8d3e7a0287 ]
Syzbot reported an issue which can be reproduced with these steps:
r0 = socket(AF_VSOCK, SOCK_STREAM, 0)
bind(r0, {VMADDR_CID_ANY, PORT})
connect(r0, {VMADDR_CID_LOCAL, PORT}) -> -1, EPROTO (self-connect)
listen(r0, backlog) -> 0
r1 = socket(AF_VSOCK, SOCK_STREAM, 0)
connect(r1, {VMADDR_CID_LOCAL, PORT}) -> 0
accept(r0) -> -1, EPROTO (stale sk_err)Basically, it creates a socket (r0) and triggers a self-connect after binding it. This self-connect fails with EPROTO because it loops back to r0 while the socket is still in the TCP_SYN_SENT state, causing it to be incorrectly dispatched to the connecting-client path. The unexpected packet type encountered there sets sk_err to EPROTO.
After that, it invokes a listen() call on the same socket. This listen() call succeeds because the kernel's listening path never inspects or clears sk_err. Then, a new socket (r1) is created as a normal client and connects to r0. However, vsock_accept() rejects this incoming connection because the listener's sk_err still holds the EPROTO error from the earlier failed self-connect.
This rejection causes the child socket created for r1's connection to never be freed on virtio or hyperv transports; only the VMCI transport implements pending_work to revisit and clean up a rejected socket.
For a non-blocking connect(), vsock_connect() may return -EINPROGRESS immediately, and vsock_connect_timeout() can later set sk->sk_err asynchronously.
Since no vsock transport ever sets sk_err on a socket while it is in TCP_LISTEN state, checking it in vsock_accept() serves no purpose and only carries forward errors left behind by earlier, unrelated connection attempts on the same socket. Remove the checks so accept() no longer rejects valid incoming connections because of a stale error, which also avoids the resource leak described above.
--- net/vmw_vsock/af_vsock.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
net/vmw_vsock/af_vsock.c +3 -7
@@ -1893,7 +1893,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, timeout =sock_rcvtimeo (listener, arg->flags &O_NONBLOCK );while ((connected =vsock_dequeue_accept (listener)) ==NULL && - listener->sk_err ==0 && timeout !=0 ) { + timeout !=0 ) {prepare_to_wait (sk_sleep (listener), &wait,TASK_INTERRUPTIBLE );release_sock (listener); timeout =schedule_timeout (timeout);
@@ -1906,13 +1906,9 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, } } -if (listener->sk_err) { - err = -listener->sk_err; - }else if (!connected) { +if (!connected) { err = -EAGAIN ; - } - -if (connected) { + }else {sk_acceptq_removed (listener);lock_sock_nested (connected,SINGLE_DEPTH_NESTING );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1592/1815 vsock: use sock_error() to consume sk_err after a failed connect
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Dinh Phi <[email protected]>
[ Upstream commit 96cbf89993091a163bfedec52a3bd683dc94b3b4 ]
vsock_connect() returns sk_err to userspace but does not clear it:
if (sk->sk_err) {
err = -sk->sk_err;For a blocking connect() the error has already been delivered as connect()'s return value, so leaving it set causes subsequent operations like poll()/epoll() to keep reporting POLLERR even though the connect failure was already delivered.
The error should be consumed once it has been returned to userspace. Switch to sock_error(), which reads and clears sk_err atomically, matching the behavior of other protocol implementations such as __inet_stream_connect().
--- net/vmw_vsock/af_vsock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/vmw_vsock/af_vsock.c +2 -4
@@ -1847,12 +1847,10 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,prepare_to_wait (sk_sleep (sk), &wait,TASK_INTERRUPTIBLE ); } -if (sk->sk_err) { - err = -sk->sk_err; + err =sock_error (sk); +if (err) { sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ; - }else { - err =0 ; } out_wait:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1593/1815 platform/x86: hp-bioscfg: fix password encoding bounds check
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit e213939ed9e6e6badf7aa48c4c8dd9a9cdf00615 ]
The password PSWD_ENCODINGS parser reads password_obj[elem + pos_values] while copying the supported password encodings from the ACPI package.
The outer loop only guarantees that elem is within password_obj_count. The encoding count is bounded by MAX_ENCODINGS_SIZE, but that does not guarantee that the ACPI package contains enough entries for all elem + pos_values accesses.
A malformed package can therefore declare a non-zero encoding count without providing enough string objects, causing the parser to read past the ACPI package array and pass an out-of-bounds string pointer and length to hp_convert_hexstr_to_str().
Add the same computed-index bounds check used by the other offset-based package parsing loops before reading password_obj[elem + pos_values].
--- drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +5 -0
@@ -353,6 +353,11 @@ static int hp_populate_password_elements_from_package(union acpi_object *passworcase PSWD_ENCODINGS : size =min_t (u32, password_data->encodings_size,MAX_ENCODINGS_SIZE );for (pos_values =0 ; pos_values < size; pos_values++) { +if (elem + pos_values >= password_obj_count) { +pr_err ("Error elem-objects package is too small\n" ); +return -EINVAL ; + } + ret =hp_convert_hexstr_to_str (password_obj[elem + pos_values].string.pointer, password_obj[elem + pos_values].string.length, &str_value, &value_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1594/1815 platform/x86/amd/hsmp: Reject negative power cap writes in hwmon
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hemanth Selam <[email protected]>
[ Upstream commit 3921bb8635ff2836622df1cdf3194d4f3c1835a4 ]
hsmp_hwmon_write() takes the user-supplied hwmon value as a signed long and assigns "val / MICROWATT_PER_MILLIWATT" to msg.args[0], which is a __u32. MICROWATT_PER_MILLIWATT is an unsigned long, so a negative write to power1_cap (e.g. "echo -1 > power1_cap") is first converted to a huge unsigned value by the division and then stored into the u32 argument.
As a result a nonsensical, multi-gigawatt socket power limit is sent to the SMU via HSMP_SET_SOCKET_POWER_LIMIT instead of the write being rejected.
Reject negative values with -EINVAL before the conversion.
Tested with HSMP enabled:
CAP=$(dirname $(grep -l amd_hsmp_hwmon \
/sys/class/hwmon/hwmon*/name | head -1))/power1_cap# negative write echo -1000000 > $CAP ; echo "ret=$?" # valid positive write must still work echo 400000000 > $CAP ; echo "ret=$?"
Before:
# echo -1000000 > $CAP ; echo "ret=$?" ret=0 <- accepted; bogus limit sent to SMU # echo 400000000 > $CAP ; echo "ret=$?" ret=0
After:
# echo -1000000 > $CAP ; echo "ret=$?" bash: echo: write error: Invalid argument ret=1 <- rejected with -EINVAL # echo 400000000 > $CAP ; echo "ret=$?" ret=0 <- valid write still works
--- drivers/platform/x86/amd/hsmp/hwmon.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/platform/x86/amd/hsmp/hwmon.c +3 -0
@@ -31,6 +31,9 @@ static int hsmp_hwmon_write(struct device *dev, enum hwmon_sensor_types type,if (attr != hwmon_power_cap)return -EOPNOTSUPP ; +if (val <0 ) +return -EINVAL ; + msg.num_args =1 ; msg.args[0 ] = val /MICROWATT_PER_MILLIWATT ; msg.msg_id =HSMP_SET_SOCKET_POWER_LIMIT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1595/1815 mlxbf-bootctl: fix the build error with FIELD_PREP()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Kulikov <[email protected]>
[ Upstream commit 46b14c6f11f558362391e308f4f184ee867ef58f ]
rsh_log_store() calls the FIELD_PREP() macro without including the required header file, resulting a build error:
CC drivers/platform/mellanox/mlxbf-bootctl.odrivers/platform/mellanox/mlxbf-bootctl.c: In function ‘rsh_log_store’:drivers/platform/mellanox/mlxbf-bootctl.c:429:16: error: implicit declaration of function ‘FIELD_PREP’ [-Wimplicit-function-declaration]
429 | data = FIELD_PREP(MLXBF_RSH_LOG_TYPE_MASK, MLXBF_RSH_LOG_TYPE_MSG);
| ^~~~~~~~~~Fix this by including the <linux/bitfield.h> file.
--- drivers/platform/mellanox/mlxbf-bootctl.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/mellanox/mlxbf-bootctl.c +1 -0
@@ -10,6 +10,7 @@#include <linux/acpi.h> #include <linux/arm-smccc.h> +#include <linux/bitfield.h> #include <linux/delay.h> #include <linux/if_ether.h> #include <linux/iopoll.h>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1596/1815 bonding: initialize err for empty target lists
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 8ccc9bf9afeeb46a437081c07154fbf5964682b2 ]
Empty NLA_NESTED attributes are valid, and bonding uses them to clear the ARP and NS target lists. When either target attribute is empty, nla_for_each_nested() does not execute, so err retains an uninitialized value before it is tested. The request can consequently return an unpredictable error after clearing the targets.
Initialize err to zero so an empty target list completes successfully. Non-empty lists still propagate errors from __bond_opt_set() unchanged.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/net/bonding/bond_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_netlink.c +1 -1
@@ -220,7 +220,7 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],struct bonding *bond =netdev_priv (bond_dev);struct bond_opt_value newval;int miimon =0 ; -int err; +int err =0 ;if (!data)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1597/1815 net: add missing ref_tracker_dir_exit() to alloc_netdev_mqs()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
[ Upstream commit 0b1c2af8a22c35cb099c735c2f63ea3ba757557d ]
sashiko is reporting that trying to read /sys/kernel/debug/ref_tracker/* causes use-afer-free crash when either alloc_percpu() or dev_addr_init() in alloc_netdev_mqs() failed, for commit 4d92b95ff2f9 ("net: add net device refcount tracker infrastructure") added ref_tracker_dir_exit() to only free_netdev() path.
--- net/core/dev.c | 1 + 1 file changed, 1 insertion(+)
net/core/dev.c +1 -0
@@ -12167,6 +12167,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,free_percpu (dev->pcpu_refcnt); free_dev:#endif +ref_tracker_dir_exit (&dev->refcnt_tracker);kvfree (dev);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1598/1815 i3c: mipi-i3c-hci: Fix missing STAT_IBI_STATUS_THLD in PIO mode
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jian-Ming Liao <[email protected]>
[ Upstream commit 308ecb824db329a8e22dd0b10f2a3411a6fbbde3 ]
In PIO mode initialization, STAT_IBI_STATUS_THLD was missing from pio->enabled_irqs. As a result, the host controller interrupt signal for IBI threshold was never enabled when transfer starts, preventing IBI status descriptors from being properly processed in PIO mode.
Include STAT_IBI_STATUS_THLD in pio->enabled_irqs so that the IBI threshold interrupt is activated alongside error interrupts upon the first transfer.
--- drivers/i3c/master/mipi-i3c-hci/pio.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/i3c/master/mipi-i3c-hci/pio.c +5 -2
@@ -185,8 +185,11 @@ static void __hci_pio_init(struct i3c_hci *hci, u32 *size_val_ptr)pio_reg_write (INTR_SIGNAL_ENABLE ,0x0 );pio_reg_write (INTR_STATUS_ENABLE ,0xffffffff ); -/* Always accept error interrupts (will be activated on first xfer) */ - pio->enabled_irqs =STAT_ALL_ERRORS ; +/* +* Always accept error interrupts and IBI threshold interrupt +* (will be activated on first xfer). +*/ + pio->enabled_irqs =STAT_ALL_ERRORS |STAT_IBI_STATUS_THLD ; }static void hci_pio_suspend (struct i3c_hci *hci)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1599/1815 perf vendor events arm64: fix swapped MetricGroup for Tegra410 L1 prefetcher metrics
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Saurav Sachidanand <[email protected]>
[ Upstream commit 2d85e13c5526eee5f4d5670472a949f1489707ed ]
The L1D prefetcher metrics (l1d_cache_rw_miss_ratio, l1d_demand_accesses, etc.) were incorrectly assigned to MetricGroup "L1I_Prefetcher_Effectiveness" and vice versa. This causes 'perf stat --metric-group L1D_Prefetcher_Effectiveness' to display L1I metrics, which is misleading.
Swap the MetricGroup assignments so L1D metrics are in the L1D group and L1I metrics are in the L1I group.
--- .../arch/arm64/nvidia/t410/metrics.json | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-)
tools/perf/pmu-events/arch/arm64/nvidia/t410/metrics.json +14 -14
@@ -346,42 +346,42 @@ "MetricExpr": "l1d_demand_misses / l1d_demand_accesses", "BriefDescription": "This metric measures the ratio of L1 D-cache Read accesses missed to the total number of L1 D-cache accesses. This gives an indication of the effectiveness of the L1 D-cache for demand Load or Store traffic.", "ScaleUnit": "1per cache access", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1d_demand_accesses", "MetricExpr": "L1D_CACHE_RW", "BriefDescription": "This metric measures the count of L1 D-cache accesses incurred on Load or Store by the instruction stream of the program.", "ScaleUnit": "1count", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1d_demand_misses", "MetricExpr": "L1D_CACHE_REFILL_RW", "BriefDescription": "This metric measures the count of L1 D-cache misses incurred on a Load or Store by the instruction stream of the program.", "ScaleUnit": "1count", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1d_prf_accuracy", "MetricExpr": "100 * (l1d_useful_prf / l1d_refilled_prf)", "BriefDescription": "This metric measures the fraction of prefetched memory addresses that are used by the instruction stream.", "ScaleUnit": "1percent of prefetch", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1d_prf_coverage", "MetricExpr": "100 * (l1d_useful_prf / (l1d_demand_misses + l1d_refilled_prf))", "BriefDescription": "This metric measures the baseline demand cache misses which the prefetcher brings into the cache.", "ScaleUnit": "1percent of cache access", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1d_refilled_prf", "MetricExpr": "L1D_CACHE_REFILL_HWPRF + L1D_CACHE_REFILL_PRFM + L1D_LFB_HIT_RW_FHWPRF + L1D_LFB_HIT_RW_FPRFM", "BriefDescription": "This metric measures the count of cache lines refilled by L1 data prefetcher (hardware prefetches or software preload) into L1 D-cache.", "ScaleUnit": "1count", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1d_tlb_miss_ratio",
@@ -402,7 +402,7 @@ "MetricExpr": "L1D_CACHE_HIT_RW_FPRF + L1D_LFB_HIT_RW_FHWPRF + L1D_LFB_HIT_RW_FPRFM", "BriefDescription": "This metric measures the count of cache lines refilled by L1 data prefetcher (hardware prefetches or software preload) into L1 D-cache which are further used by Load or Store from the instruction stream of the program.", "ScaleUnit": "1count", - "MetricGroup": "L1I_Prefetcher_Effectiveness" + "MetricGroup": "L1D_Prefetcher_Effectiveness" }, { "MetricName": "l1i_cache_miss_ratio",
@@ -423,42 +423,42 @@ "MetricExpr": "l1i_demand_misses / l1i_demand_accesses", "BriefDescription": "This metric measures the ratio of L1 I-cache Read accesses missed to the total number of L1 I-cache accesses. This gives an indication of the effectiveness of the L1 I-cache for demand instruction fetch traffic. Note that cache accesses in this cache are demand instruction fetch.", "ScaleUnit": "1per cache access", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l1i_demand_accesses", "MetricExpr": "L1I_CACHE_RD", "BriefDescription": "This metric measures the count of L1 I-cache accesses caused by an instruction fetch by the instruction stream of the program.", "ScaleUnit": "1count", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l1i_demand_misses", "MetricExpr": "L1I_CACHE_REFILL_RD", "BriefDescription": "This metric measures the count of L1 I-cache misses caused by an instruction fetch by the instruction stream of the program.", "ScaleUnit": "1count", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l1i_prf_accuracy", "MetricExpr": "100 * (l1i_useful_prf / l1i_refilled_prf)", "BriefDescription": "This metric measures the fraction of prefetched memory addresses that are used by the instruction stream.", "ScaleUnit": "1percent of prefetch", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l1i_prf_coverage", "MetricExpr": "100 * (l1i_useful_prf / (l1i_demand_misses + l1i_refilled_prf))", "BriefDescription": "This metric measures the baseline demand cache misses which the prefetcher brings into the cache.", "ScaleUnit": "1percent of cache access", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l1i_refilled_prf", "MetricExpr": "L1I_CACHE_REFILL_HWPRF + L1I_CACHE_REFILL_PRFM", "BriefDescription": "This metric measures the count of cache lines refilled by L1 instruction prefetcher (hardware prefetches or software preload) into L1 I-cache.", "ScaleUnit": "1count", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l1i_tlb_miss_ratio",
@@ -479,7 +479,7 @@ "MetricExpr": "L1I_CACHE_HIT_RD_FPRF", "BriefDescription": "This metric measures the count of cache lines refilled by L1 instruction prefetcher (hardware prefetches or software preload) into L1 I-cache which are further used by instruction stream of the program.", "ScaleUnit": "1count", - "MetricGroup": "L1D_Prefetcher_Effectiveness" + "MetricGroup": "L1I_Prefetcher_Effectiveness" }, { "MetricName": "l2_cache_miss_ratio",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1600/1815 perf vendor events arm64: Fix Tegra410 Olympus event 0x0197
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Besar Wicaksono <[email protected]>
[ Upstream commit 9453bc6a69ef43755f1c28d5688cacdd69fa16bd ]
The name and description for NVIDIA Tegra410 Olympus implementation-defined event 0x0197 incorrectly indicate a TXREQ limit between one quarter and one half. Correct them to describe a TXREQ limit below one half.
--- tools/perf/pmu-events/arch/arm64/nvidia/t410/misc.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/pmu-events/arch/arm64/nvidia/t410/misc.json +3 -3
@@ -316,8 +316,8 @@ }, { "EventCode": "0x0197", - "EventName": "TXREQ_LIMIT_1QUARTER_CYCLES", - "PublicDescription": "Number of cycles in which the dynamic TXREQ limit is between 1/4 of the L2_TQ_SIZE and 1/2 of the L2_TQ_SIZE." + "EventName": "TXREQ_LIMIT_BELOW_HALF_CYCLES", + "PublicDescription": "Number of cycles in which the dynamic TXREQ limit is between 0 and 1/2 of the L2_TQ_SIZE." }, { "EventCode": "0x019d",
@@ -517,7 +517,7 @@ { "EventCode": "0x01cc", "EventName": "TXREQ_LIMIT_COUNT_CYCLES", - "PublicDescription": "This event increments by the dynamic TXREQ value, in each cycle.\nThis is a companion event of TXREQ_LIMIT_MAX_CYCLES, TXREQ_LIMIT_3QUARTER_CYCLES, TXREQ_LIMIT_HALF_CYCLES, and TXREQ_LIMIT_1QUARTER_CYCLES." + "PublicDescription": "This event increments by the dynamic TXREQ value, in each cycle.\nThis is a companion event of TXREQ_LIMIT_MAX_CYCLES, TXREQ_LIMIT_3QUARTER_CYCLES, TXREQ_LIMIT_HALF_CYCLES, and TXREQ_LIMIT_BELOW_HALF_CYCLES." }, { "EventCode": "0x01ce",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1601/1815 ntfs: validate final EA attribute size
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 650a2751c9ae179fe0d8e5b5194a2b1c0d09412c ]
A replacement first removes the existing EA record, then adds the replacement. Check the size of that final $EA stream before mutating the current stream.
This avoids committing the shortened $EA stream or $EA_INFORMATION before discovering that the replacement exceeds the AttrDef size limit.
--- fs/ntfs/ea.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
fs/ntfs/ea.c +15 -2
@@ -250,6 +250,14 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, goto out; } +/* Check the final $EA size before removing the old entry. */ +if (val_size && +ntfs_attr_size_bounds_check (ni->vol,AT_EA , + ea_info_qsize - ea_size + new_ea_size)) { + err = -EFBIG ; + goto out; + } + p_ea = (struct ea_attr *)(ea_buf + ea_off); if (val_size &&
@@ -285,6 +293,12 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, err = -ENODATA ; goto out; } + +if (ntfs_attr_size_bounds_check (ni->vol,AT_EA , + ea_info_qsize + new_ea_size)) { + err = -EFBIG ; + goto out; + } }kvfree (ea_buf);
@@ -312,8 +326,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, p_ea_info->ea_length =cpu_to_le16 (ea_packed); p_ea_info->ea_query_length =cpu_to_le32 (ea_info_qsize + new_ea_size); -if (ea_packed >0xffff || -ntfs_attr_size_bounds_check (ni->vol,AT_EA , new_ea_size)) { +if (ea_packed >0xffff ) { err = -EFBIG ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1602/1815 ntfs: remove empty EA attribute pair
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 772e4c8f25559e3b5c6c526253b3f771a4a4c02c ]
Removing the final xattr leaves an empty $EA stream. An empty $EA attribute paired with $EA_INFORMATION is not a valid EA chain and ntfsck reports it as corrupt.
Remove both attributes when the final EA entry is deleted.
--- fs/ntfs/ea.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ntfs/ea.c +9 -0
@@ -275,6 +275,15 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, ea_info_qsize -= ea_size; p_ea_info->ea_query_length =cpu_to_le32 (ea_info_qsize); +if ((flags &XATTR_REPLACE ) && !val_size && !ea_info_qsize) { + err =ntfs_attr_remove (ni,AT_EA ,AT_UNNAMED ,0 ); +if (err) + goto out; + + err =ntfs_attr_remove (ni,AT_EA_INFORMATION ,AT_UNNAMED ,0 ); + goto out; + } + err =ntfs_write_ea (ni,AT_EA_INFORMATION , (char *)p_ea_info,0 ,sizeof (struct ea_information ), false);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1603/1815 ntfs: rewrite EA stream before updating metadata
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 41e1cf4ec10d2338f9a206af0300c34ca63160c7 ]
Updating an EA removes the old record and appends its replacement. Build the complete $EA stream in memory and rewrite it from offset zero, rather than committing a compacted stream followed by a separate append. generic/642 shows that the append path can leave an invalid record layout on disk, including when a new EA entry is added.
When removing an EA, write the compacted stream before updating $EA_INFORMATION and restore the original pair if the metadata update fails.
When the final EA entry is removed the $EA/$EA_INFORMATION pair is torn down. If removing $EA_INFORMATION fails after $EA has already been removed, the original $EA is restored so the two attributes stay consistent.
--- fs/ntfs/ea.c | 65 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 19 deletions(-)
fs/ntfs/ea.c +46 -19
@@ -196,6 +196,9 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,struct ea_attr *p_ea;u32 ea_info_qsize =0 ;char *ea_buf =NULL ; +char *new_ea_buf; +char *old_ea_buf =NULL ; +struct ea_information old_ea_info;size_t new_ea_size =ALIGN (struct_size (p_ea, ea_name,1 + name_len + val_size),4 );s64 ea_off, ea_info_size, all_ea_size, ea_size;
@@ -249,6 +252,14 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, err = -EEXIST ; goto out; } +if ((flags &XATTR_REPLACE ) && !val_size) { + old_ea_info = *p_ea_info; + old_ea_buf =kvmemdup (ea_buf, all_ea_size,GFP_NOFS ); +if (!old_ea_buf) { + err = -ENOMEM ; + goto out; + } + }/* Check the final $EA size before removing the old entry. */ if (val_size &&
@@ -281,20 +292,33 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, goto out; err =ntfs_attr_remove (ni,AT_EA_INFORMATION ,AT_UNNAMED ,0 ); +if (err) { +/* Restore the original $EA if $EA_INFORMATION removal failed. */ +ntfs_attr_add (ni,AT_EA ,AT_UNNAMED ,0 , old_ea_buf, + all_ea_size); + ea_info_qsize =le32_to_cpu (old_ea_info.ea_query_length); + } goto out; } - err =ntfs_write_ea (ni,AT_EA_INFORMATION , (char *)p_ea_info,0 , -sizeof (struct ea_information ), false); -if (err) - goto out; - - err =ntfs_write_ea (ni,AT_EA , ea_buf,0 , ea_info_qsize, true); -if (err) - goto out; -if ((flags &XATTR_REPLACE ) && !val_size) { -/* Remove xattr. */ + err =ntfs_write_ea (ni,AT_EA , ea_buf,0 , ea_info_qsize, + true); +if (err) { +ntfs_write_ea (ni,AT_EA , old_ea_buf,0 , + all_ea_size, false); + goto out; + } + + err =ntfs_write_ea (ni,AT_EA_INFORMATION , (char *)p_ea_info, +0 ,sizeof (struct ea_information ), false); +if (err) { +ntfs_write_ea (ni,AT_EA , old_ea_buf,0 , + all_ea_size, false); +ntfs_write_ea (ni,AT_EA_INFORMATION , + (char *)&old_ea_info,0 , +sizeof (old_ea_info), false); + } goto out; } }else {
@@ -309,21 +333,23 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len, goto out; } } -kvfree (ea_buf); - alloc_new_ea: - ea_buf =kzalloc (new_ea_size,GFP_NOFS ); -if (!ea_buf) { + new_ea_buf =kvzalloc (ea_info_qsize + new_ea_size,GFP_NOFS ); +if (!new_ea_buf) { err = -ENOMEM ; goto out; } +if (ea_info_qsize) +memcpy (new_ea_buf, ea_buf, ea_info_qsize); +kvfree (ea_buf); + ea_buf = new_ea_buf; + p_ea = (struct ea_attr *)(ea_buf + ea_info_qsize);/* * EA and REPARSE_POINT compatibility not checked any more, * required by Windows 10, but having both may lead to * problems with earlier versions. */ - p_ea = (struct ea_attr *)ea_buf;memcpy (p_ea->ea_name, name, name_len); p_ea->ea_name_length = name_len; p_ea->ea_name[name_len] =0 ;
@@ -344,13 +370,13 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,* no EA or EA_INFORMATION : add them */ if (!ntfs_attr_exist (ni,AT_EA ,AT_UNNAMED ,0 )) { - err =ntfs_attr_add (ni,AT_EA ,AT_UNNAMED ,0 , (char *)p_ea, - new_ea_size); + err =ntfs_attr_add (ni,AT_EA ,AT_UNNAMED ,0 , ea_buf, + ea_info_qsize + new_ea_size);if (err) goto out; }else { - err =ntfs_write_ea (ni,AT_EA , (char *)p_ea, ea_info_qsize, - new_ea_size, false); + err =ntfs_write_ea (ni,AT_EA , ea_buf,0 , + ea_info_qsize + new_ea_size, true);if (err) goto out; }
@@ -370,6 +396,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,NInoClearHasEA (ni);kvfree (ea_buf); +kvfree (old_ea_buf);kvfree (p_ea_info);return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1604/1815 ntfs: Inline zero_partial_compressed_page()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit f98d80d51777e2c8a26efec9b86541b3b5a154ae ]
zero_partial_compressed_page() has one caller and the next commit will make changes to it that make it inelegant to split across two functions.
--- fs/ntfs/compress.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
fs/ntfs/compress.c +12 -22
@@ -96,26 +96,6 @@ void free_compression_buffers(void)mutex_unlock (&ntfs_cb_lock); } -/* -* zero_partial_compressed_page - zero out of bounds compressed page region -* @page: page to zero -* @initialized_size: initialized size of the attribute -*/ -static void zero_partial_compressed_page (struct page *page, -const s64 initialized_size) -{ -u8 *kp =page_address (page); -unsigned int kp_ofs; - -ntfs_debug ("Zeroing page region outside initialized size." ); -if (((s64 )page->__folio_index <<PAGE_SHIFT ) >= initialized_size) { -clear_page (kp); -return ; - } - kp_ofs = initialized_size & ~PAGE_MASK ; -memset (kp + kp_ofs,0 ,PAGE_SIZE - kp_ofs); -} -/* * handle_bounds_compressed_page - test for&handle out of bounds compressed page * @page: page to check and handle
@@ -126,8 +106,18 @@ static inline void handle_bounds_compressed_page(struct page *page, const loff_t i_size, const s64 initialized_size) {if ((page->__folio_index >= (initialized_size >>PAGE_SHIFT )) && - (initialized_size < i_size)) -zero_partial_compressed_page (page, initialized_size); + (initialized_size < i_size)) { +u8 *kp =page_address (page); +unsigned int kp_ofs; + +ntfs_debug ("Zeroing page region outside initialized size." ); +if (((s64 )page->__folio_index <<PAGE_SHIFT ) >= initialized_size) { +clear_page (kp); +return ; + } + kp_ofs = initialized_size & ~PAGE_MASK ; +memset (kp + kp_ofs,0 ,PAGE_SIZE - kp_ofs); + } }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1605/1815 ntfs: Remove use of __folio_index in handle_bounds_compressed_page()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit a3976da121aef2b9bf0709e0fd257b2a7ae2749c ]
Nobody is supposed to use page->__folio_index. Use page_offset() instead, and simplify by working exclusively in loff_t instead of mixing up loff_t and pgoff_t.
--- fs/ntfs/compress.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ntfs/compress.c +4 -2
@@ -105,13 +105,15 @@ void free_compression_buffers(void)static inline void handle_bounds_compressed_page (struct page *page,const loff_t i_size,const s64 initialized_size) { -if ((page->__folio_index >= (initialized_size >>PAGE_SHIFT )) && +loff_t pos =page_offset (page); + +if ((pos +PAGE_SIZE > initialized_size) && (initialized_size < i_size)) {u8 *kp =page_address (page);unsigned int kp_ofs;ntfs_debug ("Zeroing page region outside initialized size." ); -if (((s64 )page->__folio_index <<PAGE_SHIFT ) >= initialized_size) { +if (pos >= initialized_size) {clear_page (kp);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1606/1815 ntfs: Use zero_user_segment() in handle_bounds_compressed_page()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit 8a81803f87504ffd735f2a77f1299eadf2cbdf32 ]
This fixes handle_bounds_compressed_page() on highmem memory as page_address() does not work on memory which has been kmap_local(), only on kmap() memory.
--- fs/ntfs/compress.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
fs/ntfs/compress.c +8 -10
@@ -109,16 +109,16 @@ static inline void handle_bounds_compressed_page(struct page *page,if ((pos +PAGE_SIZE > initialized_size) && (initialized_size < i_size)) { -u8 *kp =page_address (page); -unsigned int kp_ofs; +size_t offset;ntfs_debug ("Zeroing page region outside initialized size." ); -if (pos >= initialized_size) { -clear_page (kp); -return ; - } - kp_ofs = initialized_size & ~PAGE_MASK ; -memset (kp + kp_ofs,0 ,PAGE_SIZE - kp_ofs); +if (pos >= initialized_size) + offset =0 ; +else + offset =offset_in_page (initialized_size); +zero_user_segment (page, offset,PAGE_SIZE ); + }else { +flush_dcache_page (page); } }
@@ -223,7 +223,6 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],*/ handle_bounds_compressed_page (dp, i_size, initialized_size); -flush_dcache_page (dp);kunmap_local (page_address (dp));SetPageUptodate (dp);unlock_page (dp);
@@ -759,7 +758,6 @@ int ntfs_read_compressed_block(struct folio *folio)*/ handle_bounds_compressed_page (page, i_size, initialized_size); -flush_dcache_page (page);kunmap_local (page_address (page));SetPageUptodate (page);unlock_page (page);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1607/1815 ntfs: Remove references to page->__folio_index
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit f6ce4cbcc53cf258ae0c8f77106f2eab40a1e412 ]
Pages don't have indexes, folios have indexes. Correct this in ntfs_read_compressed_block() and also remove a use of page->mapping while I'm in here. Also convert the calls to unlock_page() and flush_dcache_page().
--- fs/ntfs/compress.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/ntfs/compress.c +8 -6
@@ -456,14 +456,14 @@ int ntfs_read_compressed_block(struct folio *folio)struct page *page = &folio->page;loff_t i_size;s64 initialized_size; -struct address_space *mapping = page->mapping; +struct address_space *mapping = folio->mapping;struct ntfs_inode *ni =NTFS_I (mapping->host);struct ntfs_volume *vol = ni->vol;struct super_block *sb = vol->sb;struct runlist_element *rl;unsigned long flags;u8 *cb, *cb_pos, *cb_end; -unsigned long offset, index = page->__folio_index; +unsigned long offset, index = folio->index;u32 cb_size = ni->itype.compressed.block_size;u64 cb_size_mask = cb_size -1UL ;s64 vcn;
@@ -812,14 +812,16 @@ int ntfs_read_compressed_block(struct folio *folio)for (cur_page =0 ; cur_page < max_page; cur_page++) { page = pages[cur_page];if (page) { + folio =page_folio (page); +ntfs_error (vol->sb,"Still have pages left! Terminating them with extreme prejudice. Inode 0x%llx, page index 0x%lx." , - ni->mft_no, page->__folio_index); -flush_dcache_page (page); + ni->mft_no, folio->index); +flush_dcache_folio (folio);kunmap_local (page_address (page)); -unlock_page (page); +folio_unlock (folio);if (cur_page != xpage) -put_page (page); +folio_put (folio); pages[cur_page] =NULL ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1608/1815 ntfs: fix kmap_local_page() usage in compress
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 6e03fbd5f772ad24ea64f7632e4d0d73184787ca ]
Several compressed I/O paths discard the address returned by kmap_local_page() and later access or unmap the page using page_address(). This is invalid for highmem pages, and local mappings must also be unmapped using the address returned by kmap_local_page().
Map each destination page in ntfs_decompress() only while producing the current sub-block. Use memcpy_from_page(), memcpy_to_page(), and memzero_page() for the other page accesses. Remove unnecessary local mappings from ntfs_write_cb(), where pages are accessed through the vmap() mapping.
--- fs/ntfs/compress.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-)
fs/ntfs/compress.c +15 -23
@@ -177,6 +177,7 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],/* Variables for uncompressed data / destination. */ struct page *dp;/* Current destination page being worked on. */ +u8 *dp_kaddr;/* Local kmap for the current destination page. */ u8 *dp_addr;/* Current pointer into dp. */ u8 *dp_sb_start;/* Start of current sub-block in dp. */ u8 *dp_sb_end;/* End of current sb in dp (dp_sb_start + NTFS_SB_SIZE). */
@@ -191,6 +192,7 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],/* Default error code. */ int err = -EOVERFLOW ; + dp_kaddr =NULL ;ntfs_debug ("Entering, cb_size = 0x%x." , cb_size); do_next_sb: ntfs_debug("Beginning sub-block at offset = 0x%zx in the cb.",
@@ -223,7 +225,6 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],*/ handle_bounds_compressed_page (dp, i_size, initialized_size); -kunmap_local (page_address (dp));SetPageUptodate (dp);unlock_page (dp);if (di == xpage)
@@ -269,7 +270,8 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[], }/* We have a valid destination page. Setup the destination pointers. */ - dp_addr = (u8 *)page_address (dp) + do_sb_start; + dp_kaddr =kmap_local_page (dp); + dp_addr = dp_kaddr + do_sb_start;/* Now, we are ready to process the current sub-block (sb). */ if (!(le16_to_cpup ((__le16 *)cb) &NTFS_SB_IS_COMPRESSED )) {
@@ -290,6 +292,8 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],/* Advance destination position to next sub-block. */ *dest_ofs +=NTFS_SB_SIZE ; *dest_ofs &= ~PAGE_MASK ; +kunmap_local (dp_kaddr); + dp_kaddr =NULL ;if (!(*dest_ofs)) { finalize_page:/*
@@ -324,6 +328,8 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[], }/* We have finished the current sub-block. */ *dest_ofs &= ~PAGE_MASK ; +kunmap_local (dp_kaddr); + dp_kaddr =NULL ;if (!(*dest_ofs)) goto finalize_page; goto do_next_sb;
@@ -429,6 +435,8 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[], goto do_next_tag; return_overflow: +if (dp_kaddr) +kunmap_local (dp_kaddr);ntfs_error (NULL ,"Failed. Returning -EOVERFLOW." ); goto return_error; }
@@ -557,7 +565,6 @@ int ntfs_read_compressed_block(struct folio *folio)* least wasting our time. */ if (!PageDirty (page) && (!PageUptodate (page))) { -kmap_local_page (page);continue ; }unlock_page (page);
@@ -643,8 +650,7 @@ int ntfs_read_compressed_block(struct folio *folio) }lock_page (lpage); -memcpy (cb_pos,page_address (lpage) + page_ofs, - vol->cluster_size); +memcpy_from_page (cb_pos, lpage, page_ofs, vol->cluster_size);unlock_page (lpage);put_page (lpage); cb_pos += vol->cluster_size;
@@ -683,14 +689,7 @@ int ntfs_read_compressed_block(struct folio *folio)for (; cur_page < cb_max_page; cur_page++) { page = pages[cur_page];if (page) { -if (likely (!cur_ofs)) -clear_page (page_address (page)); -else -memset (page_address (page) + cur_ofs,0 , -PAGE_SIZE - - cur_ofs); -flush_dcache_page (page); -kunmap_local (page_address (page)); +memzero_page (page, cur_ofs,PAGE_SIZE - cur_ofs);SetPageUptodate (page);unlock_page (page);if (cur_page == xpage)
@@ -708,8 +707,7 @@ int ntfs_read_compressed_block(struct folio *folio)if (cb_max_ofs && cb_pos < cb_end) { page = pages[cur_page];if (page) -memset (page_address (page) + cur_ofs,0 , - cb_max_ofs - cur_ofs); +memzero_page (page, cur_ofs, cb_max_ofs - cur_ofs);/* * No need to update cb_pos at this stage: * cb_pos += cb_max_ofs - cur_ofs;
@@ -730,7 +728,7 @@ int ntfs_read_compressed_block(struct folio *folio)for (; cur_page < cb_max_page; cur_page++) { page = pages[cur_page];if (page) -memcpy (page_address (page) + cur_ofs, cb_pos, +memcpy_to_page (page, cur_ofs, cb_pos,PAGE_SIZE - cur_ofs); cb_pos +=PAGE_SIZE - cur_ofs; cur_ofs =0 ;
@@ -741,7 +739,7 @@ int ntfs_read_compressed_block(struct folio *folio)if (cb_max_ofs && cb_pos < cb_end) { page = pages[cur_page];if (page) -memcpy (page_address (page) + cur_ofs, cb_pos, +memcpy_to_page (page, cur_ofs, cb_pos, cb_max_ofs - cur_ofs); cb_pos += cb_max_ofs - cur_ofs; cur_ofs = cb_max_ofs;
@@ -758,7 +756,6 @@ int ntfs_read_compressed_block(struct folio *folio)*/ handle_bounds_compressed_page (page, i_size, initialized_size); -kunmap_local (page_address (page));SetPageUptodate (page);unlock_page (page);if (cur2_page == xpage)
@@ -794,7 +791,6 @@ int ntfs_read_compressed_block(struct folio *folio) page = pages[prev_cur_page];if (page) {flush_dcache_page (page); -kunmap_local (page_address (page));unlock_page (page);if (prev_cur_page != xpage)put_page (page);
@@ -818,7 +814,6 @@ int ntfs_read_compressed_block(struct folio *folio)"Still have pages left! Terminating them with extreme prejudice. Inode 0x%llx, page index 0x%lx." , ni->mft_no, folio->index);flush_dcache_folio (folio); -kunmap_local (page_address (page));folio_unlock (folio);if (cur_page != xpage)folio_put (folio);
@@ -856,7 +851,6 @@ int ntfs_read_compressed_block(struct folio *folio) page = pages[i];if (page) {flush_dcache_page (page); -kunmap_local (page_address (page));unlock_page (page);if (i != xpage)put_page (page);
@@ -1308,7 +1302,6 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages, } pages_disk[i] = pg;lock_page (pg); -kmap_local_page (pg); } outbuf =vmap (pages_disk, pages_count,VM_MAP ,PAGE_KERNEL );
@@ -1443,7 +1436,6 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages,for (i =0 ; i < pages_count; i++) { pg = pages_disk[i];if (pg) { -kunmap_local (page_address (pg));unlock_page (pg);put_page (pg); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1609/1815 ntfs: Fix index_root heap OOB write in ntfs_ir_to_ib()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandro Calo <[email protected]>
[ Upstream commit dc09bf79b76f9a7157e225f449655f3f62f96c9c ]
ntfs_ir_to_ib copies all entries from index_root into a freshly allocated index_block_size-byte buffer without verifying that the entries fit in the available space. The entries in index_root may be larger than the usable entry space in the index block.
This can cause OOB writes past the end of the allocation.
The validator ntfs_index_root_inconsistent() checks that entries are self-consistent within the IR value, but never cross-checks them against index_block_size. There is no bounds check in ntfs_ir_to_ib() before the memcpy.
Fixing this at the sink in ntfs_ir_to_ib() since ntfs_index_root_inconsistent() validates the logical consistency of index_root as a structure and a root with large entries is a structurally valid root. The bug is a size conflict of ntfs_ir_to_ib(). Also, the validator is called once per inode load in ntfs_read_locked_inode() while ntfs_ir_to_ib() is only called during a reparent, a check there adds no overhead to the common path. Moreover, even a future call path that bypasses the validator would still be protected.
With NULL as first parameter of ntfs_error(), the volume error flag is never set by this call, so the device name will be absent from the error message. In any case, that the caller, ntfs_ir_reparent(), prints an error message that includes the device name on NULL returns.
I think this is the best solution available without adding 'struct super_block *sb' as a parameter to ntfs_ir_to_ib().
This heap out-of-bounds write is triggered by a crafted filesystem image, which is not in the kernel threat model, anyway, fixing memory errors would be nice to keep things secure.
--- fs/ntfs/index.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/ntfs/index.c +11 -0
@@ -1112,6 +1112,7 @@ static struct index_block *ntfs_ir_to_ib(struct index_root *ir, s64 ib_vcn)struct index_entry *ie_last;char *ies_start, *ies_end;int i; +u32 ib_cap;ntfs_debug ("Entering\n" );
@@ -1127,6 +1128,16 @@ static struct index_block *ntfs_ir_to_ib(struct index_root *ir, s64 ib_vcn)* as well, which can never have any data. */ i = (char *)ie_last - ies_start +le16_to_cpu (ie_last->length); + +/* Entries must fit in the allocated index block */ + ib_cap =le32_to_cpu (ib->index.allocated_size) - +le32_to_cpu (ib->index.entries_offset); +if ((u32 )i > ib_cap) { +ntfs_error (NULL ,"Entries (%d B) exceed IB capacity" , i); +kvfree (ib); +return NULL ; + } +memcpy (ntfs_ie_get_first (&ib->index), ies_start, i); ib->index.flags = ir->index.flags;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1610/1815 ntfs: apply Windows name checks only with windows_names
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 71feaa7686fb9cc08fc81c8a09d120b6204b51a0 ]
The windows_names mount option is documented to reject names containing characters forbidden by Windows. However, ntfs_check_bad_windows_name() unconditionally rejects those characters before checking the mount option.
Move the character validation after the option check so a default NTFS mount accepts POSIX names such as names containing ':'. Mounts using windows_names retain the existing Windows-compatible validation, including reserved device names and trailing spaces or dots.
--- fs/ntfs/namei.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ntfs/namei.c +3 -3
@@ -61,12 +61,12 @@ static int ntfs_check_bad_windows_name(struct ntfs_volume *vol, const __le16 *wc, unsigned int wc_len) { - if (ntfs_check_bad_char(wc, wc_len)) - return -EINVAL; - if (!NVolCheckWindowsNames(vol)) return 0; + if (ntfs_check_bad_char(wc, wc_len)) + return -EINVAL; +/* Check for trailing space or dot. */ if (wc_len > 0 && (wc[wc_len - 1] == cpu_to_le16(' ') ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1611/1815 ntfs: respect per-file chmod mode over mount masks
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 4d730a4dd78caa7bf29dda36fa5340a0237a8689 ]
fmask and dmask provide the default permissions for files without WSL metadata. Once chmod stores a mode in $LXMOD, however, that per-file mode must take precedence so selected files can retain permissions such as execute across remounts.
Record whether $LXMOD was found while loading an inode and apply the mount masks only when it is absent. Do not remask the in-memory mode after setattr persists it. Continue loading $LXMOD even when optional $LXUID or $LXGID metadata is missing, since chmod may create only $LXMOD.
--- fs/ntfs/ea.c | 20 +++++++++----------- fs/ntfs/ea.h | 3 ++- fs/ntfs/file.c | 10 ++++------ fs/ntfs/inode.c | 15 +++++++++------ fs/ntfs/namei.c | 4 ---- 5 files changed, 24 insertions(+), 28 deletions(-)
fs/ntfs/ea.c +9 -11
@@ -406,37 +406,35 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,* Check for the presence of an EA "$LXDEV" (used by WSL) * and return its value as a device address */ -int ntfs_ea_get_wsl_inode (struct inode *inode,dev_t *rdevp,unsigned int flags) +int ntfs_ea_get_wsl_inode (struct inode *inode,dev_t *rdevp,unsigned int flags, +bool *has_lxmod) {int err;__le32 v; + *has_lxmod = false; +if (!(flags &NTFS_VOL_UID )) {/* Load uid to lxuid EA */ err =ntfs_get_ea (inode,"$LXUID" ,sizeof ("$LXUID" ) -1 , &v,sizeof (v)); -if (err <0 ) -return err; -if (err !=sizeof (v)) -return -EIO ; -i_uid_write (inode,le32_to_cpu (v)); +if (err ==sizeof (v)) +i_uid_write (inode,le32_to_cpu (v)); }if (!(flags &NTFS_VOL_GID )) {/* Load gid to lxgid EA */ err =ntfs_get_ea (inode,"$LXGID" ,sizeof ("$LXGID" ) -1 , &v,sizeof (v)); -if (err <0 ) -return err; -if (err !=sizeof (v)) -return -EIO ; -i_gid_write (inode,le32_to_cpu (v)); +if (err ==sizeof (v)) +i_gid_write (inode,le32_to_cpu (v)); }/* Load mode to lxmod EA */ err =ntfs_get_ea (inode,"$LXMOD" ,sizeof ("$LXMOD" ) -1 , &v,sizeof (v));if (err ==sizeof (v)) { inode->i_mode =le32_to_cpu (v); + *has_lxmod = true; }else {/* Everyone gets all permissions. */ inode->i_mode |=0777 ;
fs/ntfs/ea.h +2 -1
@@ -10,7 +10,8 @@extern const struct xattr_handler *const ntfs_xattr_handlers[];int ntfs_ea_set_wsl_not_symlink (struct ntfs_inode *ni,mode_t mode,dev_t dev); -int ntfs_ea_get_wsl_inode (struct inode *inode,dev_t *rdevp,unsigned int flags); +int ntfs_ea_get_wsl_inode (struct inode *inode,dev_t *rdevp,unsigned int flags, +bool *has_lxmod);int ntfs_ea_set_wsl_inode (struct inode *inode,dev_t rdev,__le16 *ea_size,unsigned int flags);ssize_t ntfs_listxattr (struct dentry *dentry,char *buffer,size_t size);
fs/ntfs/file.c +4 -6
@@ -346,14 +346,12 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,if (ia_valid &ATTR_MODE ) flags |=NTFS_EA_MODE ; -if (S_ISDIR (vi->i_mode)) - vi->i_mode &= ~vol->dmask; -else - vi->i_mode &= ~vol->fmask; -mutex_lock (&ni->mrec_lock); -ntfs_ea_set_wsl_inode (vi,0 ,NULL , flags); + err =ntfs_ea_set_wsl_inode (vi,0 ,NULL , flags);mutex_unlock (&ni->mrec_lock); +if (err) + goto out; + }mark_inode_dirty (vi);
fs/ntfs/inode.c +9 -6
@@ -682,6 +682,7 @@ static int ntfs_read_locked_inode(struct inode *vi)unsigned int name_len =4 , flags =0 ;int extend_sys =0 ;dev_t dev =0 ; +bool has_lxmod = false;bool vol_err = true;ntfs_debug ("Entering for i_ino 0x%llx." , ni->mft_no);
@@ -862,7 +863,7 @@ static int ntfs_read_locked_inode(struct inode *vi) err =ntfs_attr_lookup (AT_EA_INFORMATION ,NULL ,0 ,0 ,0 ,NULL ,0 , ctx);if (!err) {NInoSetHasEA (ni); -ntfs_ea_get_wsl_inode (vi, &dev, flags); +ntfs_ea_get_wsl_inode (vi, &dev, flags, &has_lxmod); }if (ni->flags &FILE_ATTR_REPARSE_POINT ) {
@@ -886,16 +887,18 @@ static int ntfs_read_locked_inode(struct inode *vi)if (S_ISDIR (vi->i_mode)) {/* -* Apply the directory permissions mask set in the mount -* options. +* Apply the directory permissions mask set in the mount options +* when no per-file WSL mode is present. */ - vi->i_mode &= ~vol->dmask; +if (!has_lxmod) + vi->i_mode &= ~vol->dmask;/* Things break without this kludge! */ if (vi->i_nlink >1 )set_nlink (vi,1 ); }else { -/* Apply the file permissions mask set in the mount options. */ - vi->i_mode &= ~vol->fmask; +/* Apply the file permissions mask when no WSL mode is present. */ +if (!has_lxmod) + vi->i_mode &= ~vol->fmask; }/*
fs/ntfs/namei.c +0 -4
@@ -424,8 +424,6 @@ static struct ntfs_inode *__ntfs_create(struct mnt_idmap *idmap, struct inode *d* directories, also setup the index values to the defaults. */ if (S_ISDIR (mode)) { - mode &= ~vol->dmask; -NInoSetMstProtected (ni); ni->itype.index.block_size =4096 ; ni->itype.index.block_size_bits =ntfs_ffs (4096 ) -1 ;
@@ -439,8 +437,6 @@ static struct ntfs_inode *__ntfs_create(struct mnt_idmap *idmap, struct inode *d ni->itype.index.vcn_size_bits = vol->sector_size_bits; } - }else { - mode &= ~vol->fmask; }if (IS_RDONLY (vi))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1612/1815 ntfs: reject unprivileged writes to reserved $LX* xattrs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pisit Preechapramoth <[email protected]>
[ Upstream commit ea6a67ef64451d2da298f15baa35865b4bb6372a ]
Reject setxattr of the reserved $LXUID, $LXGID, $LXMOD and $LXDEV names from userspace unless the caller has CAP_SYS_ADMIN.
--- fs/ntfs/ea.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ntfs/ea.c +9 -0
@@ -751,6 +751,12 @@ static int ntfs_new_attr_flags(struct ntfs_inode *ni, __le32 fattr)return err; } +static bool ntfs_is_reserved_lxattr (const char *name) +{ +return !strcmp (name,"$LXUID" ) || !strcmp (name,"$LXGID" ) || + !strcmp (name,"$LXMOD" ) || !strcmp (name,"$LXDEV" ); +} + static int ntfs_setxattr(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode, const char *name, const void *value,
@@ -763,6 +769,9 @@ static int ntfs_setxattr(const struct xattr_handler *handler,if (NVolShutdown (ni->vol))return -EIO ; +if (ntfs_is_reserved_lxattr (name) && !capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (!strcmp (name,SYSTEM_DOS_ATTRIB )) {if (sizeof (u8) != size) { err = -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1613/1815 ntfs: allow index root relocation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 9badcfb91bc3bd5edb530fbcdd16f25d66640f33 ]
Allow a resident attribute record to move to an extent MFT record when the base record needs room for an attribute list. Retry the root conversion after creating the list, but do not relocate a root that is already external.
Roll the root back to the base record if persisting the attribute list fails, and free extent MFT records left empty by relocation or rollback. Also preserve bitmap allocation errors in index operations.
--- fs/ntfs/attrib.c | 7 +++- fs/ntfs/index.c | 85 +++++++++++++++++++++++++++++++++++++++--------- fs/ntfs/inode.c | 64 ++++++++++++++++++++++++++++++++++-- fs/ntfs/inode.h | 1 + 4 files changed, 137 insertions(+), 20 deletions(-)
fs/ntfs/attrib.c +6 -1
@@ -3553,8 +3553,13 @@ int ntfs_attr_record_move_away(struct ntfs_attr_search_ctx *ctx, int extra)unmap_mft_record (ni); err =ntfs_attr_record_move_to (ctx, ni); -if (err) +if (err) {ntfs_error (sb,"Couldn't move attribute to MFT record" ); +if (ntfs_mft_record_free (base_ni->vol, ni)) +ntfs_error (sb,"Couldn't free empty MFT record" ); +else +ntfs_inode_close (ni); + }return err; }
fs/ntfs/index.c +69 -16
147 lines not on this page · raw message
fs/ntfs/inode.c +61 -3
106 lines not on this page · raw message
fs/ntfs/inode.h +1 -0
@@ -338,6 +338,7 @@ int ntfs_get_block_mft_record(struct ntfs_inode *mft_ni, struct ntfs_inode *ni);int __ntfs_write_inode (struct inode *vi,int sync);int ntfs_inode_attach_all_extents (struct ntfs_inode *ni);int ntfs_inode_add_attrlist (struct ntfs_inode *ni); +int ntfs_inode_free_empty_extents (struct ntfs_inode *ni);void ntfs_destroy_ext_inode (struct ntfs_inode *ni);int ntfs_inode_free_space (struct ntfs_inode *ni,int size);s64 ntfs_inode_attr_pread (struct inode *vi,s64 pos,s64 count,u8 *buf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1614/1815 iomap: split iomap_iter() logic into iomap_iter_next()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit 19eb9f6ab5ce1d15c7f5e48ca16804a6d7740084 ]
In preparation for changing iomap to use an in-iter (->iomap_next()) model, move the iomap_iter() logic out into the new iomap_iter_next() helper function.
iomap_iter_next() is added as an inlined helper so it can be called directly by ->iomap_next() implementations where the begin()/end() callbacks can be direct calls.
The DEFINE_IOMAP_ITER_NEXT() and DEFINE_IOMAP_ITER_NEXT_END() macros are also provided to generate the boilerplate ->iomap_next() wrapper functions that simply forward to iomap_iter_next() with the appropriate begin/end callbacks. DEFINE_IOMAP_ITER_NEXT() is for the common case where there is no end() callback. DEFINE_IOMAP_ITER_NEXT_END() is for the case where there is an explicit end() callback.
No functional change intended. The one would-be behavioral difference is that on the iomap_end() error path (ret < 0 && !advanced), the old code returned with iter.status left as the caller's last value whereas the new code zeroes it, but this is not observable in practice as there are no in-tree callers that read iter.status after the iteration loop.
Stable-dep-of: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock")
--- fs/iomap/iter.c | 116 ++++++++++++++++++++++-------------------- include/linux/iomap.h | 102 ++++++++++++++++++++++++++++++------- 2 files changed, 145 insertions(+), 73 deletions(-)
fs/iomap/iter.c +60 -56
@@ -10,11 +10,12 @@* Release the iter folio batch. Note that the iomap flag is meant to control * the I/O path for the mapping and may not be set in error situations. */ -static inline void iomap_iter_clean_fbatch (struct iomap_iter *iter) +static inline void iomap_iter_clean_fbatch (const struct iomap_iter *iter, +struct iomap *iomap) {if (!iter->fbatch)return ; - iter->iomap.flags &= ~IOMAP_F_FOLIO_BATCH ; + iomap->flags &= ~IOMAP_F_FOLIO_BATCH ;if (folio_batch_count (iter->fbatch)) {folio_batch_release (iter->fbatch);folio_batch_reinit (iter->fbatch);
@@ -46,51 +47,27 @@ static inline void iomap_iter_done(struct iomap_iter *iter) }/** -* iomap_iter - iterate over a ranges in a file -* @iter: iteration structue -* @ops: iomap ops provided by the file system +* iomap_iter_continue - decide whether iteration should continue +* @iter: iteration structure +* @iomap: the mapping that was just processed +* @srcmap: the source mapping that was just processed * -* Iterate over filesystem-provided space mappings for the provided file range. +* Helper normally called via iomap_iter_next(). Called after the previous +* mapping has been finished to determine whether there is more of the file +* range left to process. * -* This function handles cleanup of resources acquired for iteration when the -* filesystem indicates there are no more space mappings, which means that this -* function must be called in a loop that continues as long it returns a -* positive value. If 0 or a negative value is returned, the caller must not -* return to the loop body. Within a loop body, there are two ways to break out -* of the loop body: leave @iter.status unchanged, or set it to a negative -* errno. +* Returns 1 if there is more work to do, in which case @iomap and @srcmap are +* cleared so the caller can produce the next mapping; zero if the range is +* fully consumed; or a negative errno on error. */ -int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops) +int iomap_iter_continue (const struct iomap_iter *iter,struct iomap *iomap, +struct iomap *srcmap,int ret) { -bool stale = iter->iomap.flags &IOMAP_F_STALE ; -ssize_t advanced; -u64 olen; -int ret; - -trace_iomap_iter (iter, ops, _RET_IP_); +const bool stale = iomap->flags &IOMAP_F_STALE ; +const ssize_t advanced = iter->pos - iter->iter_start_pos; -if (!iter->iomap.length) - goto begin; - -/* -* Calculate how far the iter was advanced and the original length bytes -* for ->iomap_end(). -*/ - advanced = iter->pos - iter->iter_start_pos; - olen = iter->len + advanced; - -if (ops->iomap_end) { - ret = ops->iomap_end (iter->inode, iter->iter_start_pos, -iomap_length_trim (iter, iter->iter_start_pos, - olen), - advanced, iter->flags, &iter->iomap); -if (ret <0 && !advanced) - goto error; - } - -/* detect old return semantics where this would advance */ -if (WARN_ON_ONCE (iter->status >0 )) - iter->status = -EIO ; +if (ret <0 && !advanced) +return ret;/* * Use iter->len to determine whether to continue onto the next mapping.
@@ -98,29 +75,56 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)* advanced at all (i.e. no work was done for some reason) unless the * mapping has been marked stale and needs to be reprocessed. */ -if (iter->status <0 ) +if (WARN_ON_ONCE (iter->status >0 )) +/* detect old return semantics where this would advance */ + ret = -EIO ; +else if (iter->status <0 ) ret = iter->status;else if (iter->len ==0 || (!advanced && !stale)) ret =0 ;else ret =1 ; -iomap_iter_clean_fbatch (iter); - iter->status =0 ; + +iomap_iter_clean_fbatch (iter, iomap); +if (ret <=0 )return ret; -memset (&iter->iomap,0 ,sizeof (iter->iomap)); -memset (&iter->srcmap,0 ,sizeof (iter->srcmap)); +memset (iomap,0 ,sizeof (*iomap)); +memset (srcmap,0 ,sizeof (*srcmap)); -begin: - ret = ops->iomap_begin (iter->inode, iter->pos, iter->len, iter->flags, - &iter->iomap, &iter->srcmap); -if (ret <0 ) - goto error; -iomap_iter_done (iter); -return 1 ; +return ret; +} +EXPORT_SYMBOL_GPL (iomap_iter_continue); + +/** +* iomap_iter - iterate over ranges in a file +* @iter: iteration structure +* @ops: iomap ops provided by the filesystem +* +* Iterate over filesystem-provided space mappings for the provided file range. +* +* This function handles cleanup of resources acquired for iteration when the +* filesystem indicates there are no more space mappings, which means that this +* function must be called in a loop that continues as long it returns a +* positive value. If 0 or a negative value is returned, the caller must not +* return to the loop body. Within a loop body, there are two ways to break out +* of the loop body: leave @iter.status unchanged, or set it to a negative +* errno. +*/ +int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops) +{ +int ret; + +trace_iomap_iter (iter, ops, _RET_IP_); + + ret =iomap_iter_next (iter, &iter->iomap, &iter->srcmap, + ops->iomap_begin, ops->iomap_end); + iter->status =0 ; +if (ret >0 ) +iomap_iter_done (iter); +else if (ret <0 ) +iomap_iter_clean_fbatch (iter, &iter->iomap); -error: -iomap_iter_clean_fbatch (iter);return ret; }
include/linux/iomap.h +85 -17
115 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1615/1815 iomap: add ->iomap_next()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit 26dfed9c7a289089b76cff9ab9e4c66b6f90e872 ]
Have one ->iomap_next() callback instead of ->iomap_begin() and ->iomap_end(). ->iomap_next() finishes the previous mapping if needed, and produces the next mapping.
Collapsing to a single callback lets a performance-critical caller inline its iteration loop and pass its ->iomap_next() function as a compile-time constant, so the compiler can devirtualize that callback into a direct call instead of an indirect call through a function pointer.
iomap_iter() uses ->iomap_next() when the filesystem provides that callback and otherwise falls back to the ->iomap_begin()/->iomap_end() path, so filesystems can be converted one at a time.
Stable-dep-of: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock")
--- fs/iomap/iter.c | 8 ++++++-- include/linux/iomap.h | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
fs/iomap/iter.c +6 -2
@@ -118,8 +118,12 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)trace_iomap_iter (iter, ops, _RET_IP_); - ret =iomap_iter_next (iter, &iter->iomap, &iter->srcmap, - ops->iomap_begin, ops->iomap_end); +if (ops->iomap_next) + ret = ops->iomap_next (iter, &iter->iomap, &iter->srcmap); +else + ret =iomap_iter_next (iter, &iter->iomap, &iter->srcmap, + ops->iomap_begin, ops->iomap_end); + iter->status =0 ;if (ret >0 )iomap_iter_done (iter);
include/linux/iomap.h +9 -0
@@ -230,9 +230,18 @@ typedef int (*iomap_iter_begin_fn)(struct inode *inode, loff_t pos,typedef int (*iomap_iter_end_fn )(struct inode *inode,loff_t pos,loff_t length,ssize_t written,unsigned flags,struct iomap *iomap); +/* +* Produce the next mapping (finishing the previous one if needed). +* Return 1 to continue iterating, 0 if the range is fully consumed, or a +* negative error on failure. +*/ +typedef int (*iomap_iter_next_fn )(const struct iomap_iter *iter, +struct iomap *iomap,struct iomap *srcmap); +struct iomap_ops {iomap_iter_begin_fn iomap_begin;iomap_iter_end_fn iomap_end; +iomap_iter_next_fn iomap_next; };/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1616/1815 ntfs: convert iomap ops to ->iomap_next()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit 7a7bf7551624f8e7e1877f1b6ca088499b5ad25e ]
Convert ntfs iomap_ops to the new ->iomap_next() callback. Each callback is generated with the DEFINE_IOMAP_ITER_NEXT()/DEFINE_IOMAP_ITER_NEXT_END() macros, which wrap the iomap_iter_next() helper to finish the previous mapping if needed and produce the next one. No functional changes are intended.
Stable-dep-of: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock")
--- fs/ntfs/iomap.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
fs/ntfs/iomap.c +22 -10
@@ -277,8 +277,10 @@ static int ntfs_read_iomap_begin(struct inode *inode, loff_t offset, loff_t leng srcmap, true); } +static DEFINE_IOMAP_ITER_NEXT(ntfs_read_iomap_next, ntfs_read_iomap_begin); +const struct iomap_ops ntfs_read_iomap_ops = { - .iomap_begin = ntfs_read_iomap_begin, + .iomap_next = ntfs_read_iomap_next, };/*
@@ -329,13 +331,17 @@ static int ntfs_zero_read_iomap_end(struct inode *inode, loff_t pos, loff_t lengreturn written; } +static DEFINE_IOMAP_ITER_NEXT_END(ntfs_zero_read_iomap_next, + ntfs_seek_iomap_begin, ntfs_zero_read_iomap_end); +static const struct iomap_ops ntfs_zero_read_iomap_ops = { - .iomap_begin = ntfs_seek_iomap_begin, - .iomap_end = ntfs_zero_read_iomap_end, + .iomap_next = ntfs_zero_read_iomap_next, }; +static DEFINE_IOMAP_ITER_NEXT(ntfs_seek_iomap_next, ntfs_seek_iomap_begin); +const struct iomap_ops ntfs_seek_iomap_ops = { - .iomap_begin = ntfs_seek_iomap_begin, + .iomap_next = ntfs_seek_iomap_next, };int ntfs_dio_zero_range (struct inode *inode,loff_t offset,loff_t length)
@@ -764,9 +770,11 @@ static int ntfs_write_iomap_end(struct inode *inode, loff_t pos, loff_t length,return written; } +static DEFINE_IOMAP_ITER_NEXT_END(ntfs_write_iomap_next, + ntfs_write_iomap_begin, ntfs_write_iomap_end); +const struct iomap_ops ntfs_write_iomap_ops = { - .iomap_begin = ntfs_write_iomap_begin, - .iomap_end = ntfs_write_iomap_end, + .iomap_next = ntfs_write_iomap_next, }; static int ntfs_page_mkwrite_iomap_begin(struct inode *inode, loff_t offset,
@@ -777,9 +785,11 @@ static int ntfs_page_mkwrite_iomap_begin(struct inode *inode, loff_t offset, NTFS_IOMAP_FLAGS_MKWRITE); } +static DEFINE_IOMAP_ITER_NEXT_END(ntfs_page_mkwrite_iomap_next, + ntfs_page_mkwrite_iomap_begin, ntfs_write_iomap_end); +const struct iomap_ops ntfs_page_mkwrite_iomap_ops = { - .iomap_begin = ntfs_page_mkwrite_iomap_begin, - .iomap_end = ntfs_write_iomap_end, + .iomap_next = ntfs_page_mkwrite_iomap_next, }; static int ntfs_dio_iomap_begin(struct inode *inode, loff_t offset,
@@ -790,9 +800,11 @@ static int ntfs_dio_iomap_begin(struct inode *inode, loff_t offset, NTFS_IOMAP_FLAGS_DIO); } +static DEFINE_IOMAP_ITER_NEXT_END(ntfs_dio_iomap_next, + ntfs_dio_iomap_begin, ntfs_write_iomap_end); +const struct iomap_ops ntfs_dio_iomap_ops = { - .iomap_begin = ntfs_dio_iomap_begin, - .iomap_end = ntfs_write_iomap_end, + .iomap_next = ntfs_dio_iomap_next, }; static ssize_t ntfs_writeback_range(struct iomap_writepage_ctx *wpc,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1617/1815 ntfs: serialize resident iomap reads with mrec_lock
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyeontae Lee <[email protected]>
[ Upstream commit d9e00c457d4ab8ab59c6e4b8554c921260e4e16c ]
ntfs_read_iomap_begin_resident() walks the MFT record through ntfs_attr_lookup() -> ntfs_attr_find() without taking ni->mrec_lock, while ntfs_attr_record_resize(), ntfs_make_room_for_attr() and ntfs_resident_attr_record_add() memmove() the same base_ni->mrec buffer under that lock. map_mft_record() only takes a reference and does not serialize, so the reader can observe torn attribute length and offset fields while a writer is relocating the records.
KCSAN reports the race between the mmap read fault path and both link() and unlink():
BUG: KCSAN: data-race in ntfs_attr_find / ntfs_attr_record_resize
write to 0xffff888100af1018 of 4 bytes by task 96 on cpu 1:
ntfs_attr_record_resize+0xd2/0x130 ntfs_attr_record_rm+0xad/0x530 ntfs_delete+0x224/0x640 ntfs_unlink+0x14d/0x280 vfs_unlink+0x157/0x520
read to 0xffff888100af1018 of 4 bytes by task 95 on cpu 0:
ntfs_attr_find+0x104/0x5b0 ntfs_attr_lookup+0x39c/0x10c0 ntfs_read_iomap_begin_resident+0xc6/0x230 ntfs_read_iomap_begin+0x5d/0xa0 iomap_iter+0x2e2/0x6e0 iomap_read_folio+0x147/0x2a0 ntfs_read_folio+0x108/0x170 filemap_read_folio+0x35/0x100 filemap_fault+0x993/0x1000
value changed: 0x00000250 -> 0x000001f0
The address is mrec + 0x18, i.e. mft_record.bytes_in_use, and the change is the 96 bytes of one $FILE_NAME attribute being removed.
Keep base_ni->mrec_lock from the resident read iomap lookup through iomap_end(). This protects both the attribute walk and the subsequent copy from iomap->inline_data, which points into the MFT record. The non-resident path is left alone: ntfs_lookup() already holds the directory inode's mrec_lock when it reads an index folio through read_mapping_folio(), and taking the lock in the shared wrapper deadlocks there with recursive locking on mrec_lock. The comment above the read_mapping_folio() call in fs/ntfs/dir.c notes the same hazard.
The seek path uses the same lookup helper but does not dereference iomap->inline_data. Release the lock before returning from that path, whereas the regular read path records base_ni in iomap->private and releases the lock from its iomap_end() callback.
Tested with a reproducer that faults in a 16-byte resident file while another thread runs link()/unlink() on it. Before: 40 KCSAN reports in about one second. After: no reports in 180 seconds over 206,090 read iterations and 423,540 link/unlink cycles. A PROVE_LOCKING build shows no lockdep splat with the same reproducer running for 60 seconds.
--- fs/ntfs/iomap.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
fs/ntfs/iomap.c +26 -6
@@ -81,7 +81,7 @@ const struct iomap_write_ops ntfs_iomap_folio_ops = { };static int ntfs_read_iomap_begin_resident (struct inode *inode,loff_t offset,loff_t length, -unsigned int flags,struct iomap *iomap) +unsigned int flags,struct iomap *iomap,bool keep_mrec_lock) {struct ntfs_inode *base_ni, *ni =NTFS_I (inode);struct ntfs_attr_search_ctx *ctx;
@@ -95,6 +95,8 @@ static int ntfs_read_iomap_begin_resident(struct inode *inode, loff_t offset, loelse base_ni = ni; +mutex_lock (&base_ni->mrec_lock); + ctx =ntfs_attr_get_search_ctx (base_ni,NULL );if (!ctx) { err = -ENOMEM ;
@@ -138,6 +140,13 @@ static int ntfs_read_iomap_begin_resident(struct inode *inode, loff_t offset, loif (ctx)ntfs_attr_put_search_ctx (ctx); +if (!err && keep_mrec_lock && iomap->type ==IOMAP_INLINE ) { + iomap->private = base_ni; +return 0 ; + } + +mutex_unlock (&base_ni->mrec_lock); +return err; }
@@ -261,23 +270,34 @@ static int ntfs_read_iomap_begin_non_resident(struct inode *inode, loff_t offsetstatic int __ntfs_read_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap, -bool need_unwritten) +bool need_unwritten,bool keep_mrec_lock) {if (NInoNonResident (NTFS_I (inode)))return ntfs_read_iomap_begin_non_resident (inode, offset, length, flags, iomap, need_unwritten);return ntfs_read_iomap_begin_resident (inode, offset, length, - flags, iomap); + flags, iomap, keep_mrec_lock); }static int ntfs_read_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {return __ntfs_read_iomap_begin (inode, offset, length, flags, iomap, - srcmap, true); + srcmap, true, true); +} + +static int ntfs_read_iomap_end (struct inode *inode,loff_t pos,loff_t length, +ssize_t written,unsigned int flags,struct iomap *iomap) +{ +struct ntfs_inode *base_ni = iomap->private; + +if (base_ni) +mutex_unlock (&base_ni->mrec_lock); +return written; } -static DEFINE_IOMAP_ITER_NEXT(ntfs_read_iomap_next, ntfs_read_iomap_begin); +static DEFINE_IOMAP_ITER_NEXT_END(ntfs_read_iomap_next, + ntfs_read_iomap_begin, ntfs_read_iomap_end);const struct iomap_ops ntfs_read_iomap_ops = { .iomap_next = ntfs_read_iomap_next,
@@ -320,7 +340,7 @@ static int ntfs_seek_iomap_begin(struct inode *inode, loff_t offset, loff_t leng unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { return __ntfs_read_iomap_begin(inode, offset, length, flags, iomap, -srcmap ,false ); +srcmap ,false ,false ); } static int ntfs_zero_read_iomap_end(struct inode *inode, loff_t pos, loff_t length,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1618/1815 ntfs: do not update ctime when setxattr fails
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baolin Liu <[email protected]>
[ Upstream commit 60038154b40e03fdfade1eb975f0305c4c887d5e ]
ntfs_setxattr() updates ctime and marks the inode dirty even when the operation fails. A failed setxattr(2) must not change file metadata.
Update ctime only on success.
--- fs/ntfs/ea.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ntfs/ea.c +4 -2
@@ -824,8 +824,10 @@ static int ntfs_setxattr(const struct xattr_handler *handler,mutex_unlock (&ni->mrec_lock); out: -inode_set_ctime_current (inode); -mark_inode_dirty (inode); +if (!err) { +inode_set_ctime_current (inode); +mark_inode_dirty (inode); + }return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1619/1815 virtio_balloon: disable indirect descriptors
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael S. Tsirkin <[email protected]>
[ Upstream commit 281eb4732aae5473141b84e106fe906c69b2ff3d ]
The page reporting callback submits an sg list to the reporting virtqueue. With VIRTIO_RING_F_INDIRECT_DESC negotiated and total_sg > 1 (which it typically is), virtqueue_add reports it to the host by allocating an indirect descriptor via kmalloc(GFP_KERNEL).
This is not pretty: the reporting worker isolates potentially hundreds of MB of free pages from the buddy allocator (reported pages are at least pageblock_order, and the sg can contain up to PAGE_REPORTING_CAPACITY entries of varying orders). As the result, very theoretically, the kmalloc might trigger OOM when we have in fact a ton of free memory.
Clear VIRTIO_RING_F_INDIRECT_DESC, to avoid using indirect descriptors.
Message-ID: <73fac8a629fd9aca7bb3265ac243a769c28af25d.1783232420.git.mst@redhat.com>
--- drivers/virtio/virtio_balloon.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/virtio/virtio_balloon.c +6 -0
@@ -7,6 +7,7 @@*/ #include <linux/virtio.h> +#include <uapi/linux/virtio_ring.h> #include <linux/virtio_balloon.h> #include <linux/swap.h> #include <linux/workqueue.h>
@@ -1165,6 +1166,11 @@ static int virtballoon_validate(struct virtio_device *vdev)else if (!virtio_has_feature (vdev,VIRTIO_BALLOON_F_PAGE_POISON ))__virtio_clear_bit (vdev,VIRTIO_BALLOON_F_REPORTING ); +/* +* Disable indirect descriptors to avoid memory allocation in +* virtqueue_add during page reporting. +*/ +__virtio_clear_bit (vdev,VIRTIO_RING_F_INDIRECT_DESC );__virtio_clear_bit (vdev,VIRTIO_F_ACCESS_PLATFORM );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1620/1815 vdpa_sim: fix cleanup after worker creation failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linfeng Sun <[email protected]>
[ Upstream commit bd670e5dfd2b01fd9692f61fa1456434c54026a4 ]
vdpasim_create() leaves vdpasim->worker as an ERR_PTR when kthread_run_worker() fails. The error path then drops the device reference, which releases the partially initialized simulator.
vdpasim_free() unconditionally passes the worker pointer to kthread_destroy_worker(), so the ERR_PTR is dereferenced and can trigger a general protection fault.
Store the worker error, clear the pointer, and only clean up the worker when it was successfully initialized. Also make the release path tolerate partially initialized objects by guarding virtqueue and IOTLB cleanup, since the same release path can be reached from other initialization failures.
I found this bug myself, though the patch was written with AI assistance.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_sim/vdpa_sim.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +17 -8
@@ -233,8 +233,11 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,kthread_init_work (&vdpasim->work, vdpasim_work_fn); vdpasim->worker =kthread_run_worker (0 ,"vDPA sim worker: %s" , dev_attr->name); -if (IS_ERR (vdpasim->worker)) +if (IS_ERR (vdpasim->worker)) { + ret =PTR_ERR (vdpasim->worker); + vdpasim->worker =NULL ; goto err_iommu; + }mutex_init (&vdpasim->mutex);spin_lock_init (&vdpasim->iommu_lock);
@@ -746,18 +749,24 @@ static void vdpasim_free(struct vdpa_device *vdpa)struct vdpasim *vdpasim =vdpa_to_sim (vdpa);int i; -kthread_cancel_work_sync (&vdpasim->work); -kthread_destroy_worker (vdpasim->worker); +if (vdpasim->worker) { +kthread_cancel_work_sync (&vdpasim->work); +kthread_destroy_worker (vdpasim->worker); + } -for (i =0 ; i < vdpasim->dev_attr.nvqs; i++) { -vringh_kiov_cleanup (&vdpasim->vqs[i].out_iov); -vringh_kiov_cleanup (&vdpasim->vqs[i].in_iov); +if (vdpasim->vqs) { +for (i =0 ; i < vdpasim->dev_attr.nvqs; i++) { +vringh_kiov_cleanup (&vdpasim->vqs[i].out_iov); +vringh_kiov_cleanup (&vdpasim->vqs[i].in_iov); + } } vdpasim->dev_attr.free (vdpasim); -for (i =0 ; i < vdpasim->dev_attr.nas; i++) -vhost_iotlb_reset (&vdpasim->iommu[i]); +if (vdpasim->iommu) { +for (i =0 ; i < vdpasim->dev_attr.nas; i++) +vhost_iotlb_reset (&vdpasim->iommu[i]); + }kfree (vdpasim->iommu);kfree (vdpasim->iommu_pt);kfree (vdpasim->vqs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1621/1815 virtio: add virtio_device_shutdown() helper
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis V. Lunev <[email protected]>
[ Upstream commit 0d8aebe089b4ba887e792884cf041ce9f1040ff4 ]
The generic virtio bus .shutdown handler, virtio_dev_shutdown(), breaks and resets a device once it has established that the driver has no .shutdown of its own. A driver that does implement .shutdown, to quiesce its own activity first, still needs the same break and reset afterwards and would otherwise have to open code it.
Factor the break + synchronize_cbs + reset sequence out of virtio_dev_shutdown() into an exported virtio_device_shutdown() helper so such drivers can reuse it instead of duplicating the core logic.
No functional change.
Message-ID: <[email protected]>
Stable-dep-of: 7e17eef04600 ("virtio_balloon: quiesce balloon work before device shutdown")
--- drivers/virtio/virtio.c | 41 +++++++++++++++++++++++++++-------------- include/linux/virtio.h | 1 + 2 files changed, 28 insertions(+), 14 deletions(-)
drivers/virtio/virtio.c +27 -14
@@ -401,6 +401,32 @@ static const struct cpumask *virtio_irq_get_affinity(struct device *_d,return dev->config->get_vq_affinity (dev, irq_vec); } +/** +* virtio_device_shutdown - break and reset a device on shutdown +* @dev: the device +* +* Drivers with their own .shutdown method should quiesce their activity and +* then call this to stop the device the way the generic shutdown path does. +*/ +void virtio_device_shutdown (struct virtio_device *dev) +{ +/* +* Some devices get wedged if you kick them after they are +* reset. Mark all vqs as broken to make sure we don't. +*/ +virtio_break_device (dev); +/* +* Guarantee that any callback will see vq->broken as true. +*/ +virtio_synchronize_cbs (dev); +/* +* As IOMMUs are reset on shutdown, this will block device access to memory. +* Some devices get wedged if this happens, so reset to make sure it does not. +*/ + dev->config->reset (dev); +} +EXPORT_SYMBOL_GPL (virtio_device_shutdown); +static void virtio_dev_shutdown (struct device *_d) {struct virtio_device *dev =dev_to_virtio (_d);
@@ -419,20 +445,7 @@ static void virtio_dev_shutdown(struct device *_d)return ; } -/* -* Some devices get wedged if you kick them after they are -* reset. Mark all vqs as broken to make sure we don't. -*/ -virtio_break_device (dev); -/* -* Guarantee that any callback will see vq->broken as true. -*/ -virtio_synchronize_cbs (dev); -/* -* As IOMMUs are reset on shutdown, this will block device access to memory. -* Some devices get wedged if this happens, so reset to make sure it does not. -*/ - dev->config->reset (dev); +virtio_device_shutdown (dev); }static int virtio_dev_num_vf (struct device *dev)
include/linux/virtio.h +1 -0
@@ -213,6 +213,7 @@ int virtio_device_freeze(struct virtio_device *dev);int virtio_device_restore (struct virtio_device *dev);#endif void virtio_reset_device (struct virtio_device *dev); +void virtio_device_shutdown (struct virtio_device *dev);int virtio_device_reset_prepare (struct virtio_device *dev);int virtio_device_reset_done (struct virtio_device *dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1622/1815 virtio_balloon: factor out virtballoon_quiesce()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis V. Lunev <[email protected]>
[ Upstream commit 29536a923a9412812eb3e378258019b54538a220 ]
virtballoon_remove() stops all of the balloon's asynchronous work (the free page reporting worker, the inflate/deflate and stats workers, the OOM notifier and the free page shrinker) before tearing the device down. A following change needs the same teardown from a .shutdown handler, so move it into a virtballoon_quiesce() helper.
No functional change.
Message-ID: <[email protected]>
Stable-dep-of: 7e17eef04600 ("virtio_balloon: quiesce balloon work before device shutdown")
--- drivers/virtio/virtio_balloon.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
drivers/virtio/virtio_balloon.c +20 -7
@@ -1096,26 +1096,39 @@ static void remove_common(struct virtio_balloon *vb) vb->vdev->config->del_vqs (vb->vdev); } -static void virtballoon_remove (struct virtio_device *vdev) +/* +* Stop all asynchronous balloon work. The device must still be alive so that +* in-flight requests can drain via the host before it is reset or freed. +*/ +static void virtballoon_quiesce (struct virtio_balloon *vb) { -struct virtio_balloon *vb = vdev->priv; +struct virtio_device *vdev = vb->vdev; -if (virtio_has_feature (vb->vdev,VIRTIO_BALLOON_F_REPORTING )) +if (virtio_has_feature (vdev,VIRTIO_BALLOON_F_REPORTING ))page_reporting_unregister (&vb->pr_dev_info); -if (virtio_has_feature (vb->vdev,VIRTIO_BALLOON_F_DEFLATE_ON_OOM )) +if (virtio_has_feature (vdev,VIRTIO_BALLOON_F_DEFLATE_ON_OOM ))unregister_oom_notifier (&vb->oom_nb); -if (virtio_has_feature (vb->vdev,VIRTIO_BALLOON_F_FREE_PAGE_HINT )) +if (virtio_has_feature (vdev,VIRTIO_BALLOON_F_FREE_PAGE_HINT ))virtio_balloon_unregister_shrinker (vb); +spin_lock_irq (&vb->stop_update_lock); vb->stop_update = true;spin_unlock_irq (&vb->stop_update_lock);cancel_work_sync (&vb->update_balloon_size_work);cancel_work_sync (&vb->update_balloon_stats_work); -if (virtio_has_feature (vdev,VIRTIO_BALLOON_F_FREE_PAGE_HINT )) { +if (virtio_has_feature (vdev,VIRTIO_BALLOON_F_FREE_PAGE_HINT ))cancel_work_sync (&vb->report_free_page_work); +} + +static void virtballoon_remove (struct virtio_device *vdev) +{ +struct virtio_balloon *vb = vdev->priv; + +virtballoon_quiesce (vb); + +if (virtio_has_feature (vdev,VIRTIO_BALLOON_F_FREE_PAGE_HINT ))destroy_workqueue (vb->balloon_wq); - }remove_common (vb);mutex_destroy (&vb->balloon_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1623/1815 virtio_balloon: quiesce balloon work before device shutdown
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis V. Lunev <[email protected]>
[ Upstream commit 7e17eef04600c399c7e0f5ce765da5cf9d40d8e1 ]
Commit 8bd2fa086a04 ("virtio: break and reset virtio devices on device_shutdown()") added a generic virtio bus .shutdown handler that breaks and resets every virtio device during device_shutdown(), i.e. on reboot and kexec.
virtio_balloon provides no .shutdown of its own, so that generic path runs while the balloon's asynchronous work is still armed. Once the device has been broken, virtqueue_add_inbuf() in virtballoon_free_page_report() returns -EIO and trips its WARN_ON_ONCE(). On a kernel booted with panic_on_warn that turns an ordinary reboot, for example a kexec based upgrade, into a fatal panic in the middle of device_shutdown(), so the machine never reaches the new kernel.
Relaxing that single WARN_ON_ONCE() would only hide the symptom: the inflate/deflate and OOM paths do not warn, they call wait_event(vb->acked, ...) and would instead block forever on a broken queue that can no longer complete. The device has to be quiesced, not just kept quiet.
Add a .shutdown handler that quiesces the balloon via the shared virtballoon_quiesce() helper while the device is still alive, and only then breaks and resets it via virtio_device_shutdown(). Unlike virtballoon_remove() the balloon workqueue is not destroyed, as shutdown does not free the device and cancel_work_sync() together with stop_update already prevent any further work from being queued.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_balloon.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/virtio/virtio_balloon.c +7 -0
@@ -1135,6 +1135,12 @@ static void virtballoon_remove(struct virtio_device *vdev)kfree (vb); } +static void virtballoon_shutdown (struct virtio_device *vdev) +{ +virtballoon_quiesce (vdev->priv); +virtio_device_shutdown (vdev); +} +#ifdef CONFIG_PM_SLEEP static int virtballoon_freeze (struct virtio_device *vdev) {
@@ -1205,6 +1211,7 @@ static struct virtio_driver virtio_balloon_driver = { .validate = virtballoon_validate, .probe = virtballoon_probe, .remove = virtballoon_remove, + .shutdown = virtballoon_shutdown, .config_changed = virtballoon_changed, #ifdef CONFIG_PM_SLEEP .freeze = virtballoon_freeze,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1624/1815 vhost/net: fix clear_user start address in VHOST_GET_FEATURES_ARRAY
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yufeng Wang <[email protected]>
[ Upstream commit 92a7b138f2453bf067628de0c5ec563cc8ad16d5 ]
The clear_user() call in VHOST_GET_FEATURES_ARRAY incorrectly starts at argp, which is the beginning of the features array, overwriting the data just written by copy_to_user(). It should start after the copied elements at argp + copied * sizeof(u64) to only zero the trailing unused space.
Use size_mul() for both the offset and length calculations so the arithmetic stays consistent with the surrounding code and remains overflow-safe.
Message-ID: <[email protected]>
--- drivers/vhost/net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/net.c +2 -1
@@ -1777,7 +1777,8 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,return -EFAULT ;/* Zero the trailing space provided by user-space, if any */ -if (clear_user (argp,size_mul (count - copied,sizeof (u64)))) +if (clear_user (argp +size_mul (copied,sizeof (u64)), +size_mul (count - copied,sizeof (u64))))return -EFAULT ;return 0 ;case VHOST_SET_FEATURES_ARRAY :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1625/1815 virtio_pci: fix wrong queue index for admin vq in intx path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit dc3f1eef9ab678c396baf5df12aba61db061aa8c ]
In vp_find_vqs_intx(), the admin vq was set up using the local queue_idx counter instead of avq->vq_index (the actual queue index obtained from the device). This differs from vp_find_vqs_msix() which correctly uses avq->vq_index. Using the wrong index causes the admin virtqueue to be mapped to an incorrect hardware queue.
Fix it by using avq->vq_index consistent with the msix path.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_pci_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.c +1 -1
@@ -499,7 +499,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,if (!avq_num)return 0 ;sprintf (avq->name,"avq.%u" , avq->vq_index); - vq =vp_setup_vq (vdev, queue_idx++, vp_modern_avq_done, avq->name, + vq =vp_setup_vq (vdev, avq->vq_index, vp_modern_avq_done, avq->name, false,VIRTIO_MSI_NO_VECTOR , &vp_dev->admin_vq.info);if (IS_ERR (vq)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1626/1815 vdpa/mlx5: fix wrong list iterated in add_direct_chain error path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 23ae56d9e74c122f95cae71ae3b9fc259fb88446 ]
In add_direct_chain(), newly allocated direct MR entries are added to the local list 'tmp', which is spliced into mr->head only on success. On the error path, the cleanup loop was incorrectly iterating over mr->head instead of tmp.
Fix by iterating over 'tmp' in the err_alloc cleanup path.
Message-ID: <[email protected]>
--- drivers/vdpa/mlx5/core/mr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/mlx5/core/mr.c +1 -1
@@ -481,7 +481,7 @@ static int add_direct_chain(struct mlx5_vdpa_dev *mvdev,return 0 ; err_alloc: -list_for_each_entry_safe (dmr, n, &mr->head, list) { +list_for_each_entry_safe (dmr, n, &tmp, list) {list_del_init (&dmr->list);unmap_direct_mr (mvdev, dmr);kfree (dmr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1627/1815 virtio: rtc: time out alarm requests
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: GuoHan Zhao <[email protected]>
[ Upstream commit 68e00d9212929805b40dcb9166755610f4f4acee ]
RTC class operations run with rtc_device.ops_lock held. The virtio RTC alarm requests currently wait without a timeout for the device to return their requestq buffers.
On surprise removal, virtio-pci marks the virtqueues broken before unregistering the virtio device. If an alarm request is waiting when the device stops responding, viortc_remove() blocks in viortc_class_stop() while trying to acquire ops_lock. The request cannot complete and device removal hangs until the waiting task is signalled.
Use the same 60-second timeout as clock read requests for alarm reads, alarm programming, and alarm interrupt enable requests. The existing message reference counting keeps a timed-out request alive until a late response or device teardown.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_rtc_driver.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/virtio/virtio_rtc_driver.c +7 -7
@@ -574,8 +574,8 @@ static int viortc_msg_xfer(struct viortc_vq *vq, struct viortc_msg *msg,* read requests */ -/** timeout for clock readings, where timeouts are considered non-fatal */ -#define VIORTC_MSG_READ_TIMEOUT secs_to_jiffies(60) +/** timeout for runtime requests, where timeouts are considered non-fatal */ +#define VIORTC_MSG_TIMEOUT secs_to_jiffies(60)/** * viortc_read() - VIRTIO_RTC_REQ_READ wrapper
@@ -600,7 +600,7 @@ int viortc_read(struct viortc_dev *viortc, u16 vio_clk_id, u64 *reading)VIORTC_MSG_WRITE (hdl, clock_id, &vio_clk_id); ret =viortc_msg_xfer (&viortc->vqs[VIORTC_REQUESTQ ],VIORTC_MSG (hdl), -VIORTC_MSG_READ_TIMEOUT ); +VIORTC_MSG_TIMEOUT );if (ret) {dev_dbg (&viortc->vdev->dev,"%s: xfer returned %d\n" , __func__, ret);
@@ -642,7 +642,7 @@ int viortc_read_cross(struct viortc_dev *viortc, u16 vio_clk_id, u8 hw_counter,VIORTC_MSG_WRITE (hdl, hw_counter, &hw_counter); ret =viortc_msg_xfer (&viortc->vqs[VIORTC_REQUESTQ ],VIORTC_MSG (hdl), -VIORTC_MSG_READ_TIMEOUT ); +VIORTC_MSG_TIMEOUT );if (ret) {dev_dbg (&viortc->vdev->dev,"%s: xfer returned %d\n" , __func__, ret);
@@ -809,7 +809,7 @@ int viortc_read_alarm(struct viortc_dev *viortc, u16 vio_clk_id,VIORTC_MSG_WRITE (hdl, clock_id, &vio_clk_id); ret =viortc_msg_xfer (&viortc->vqs[VIORTC_REQUESTQ ],VIORTC_MSG (hdl), -0 ); +VIORTC_MSG_TIMEOUT );if (ret) {dev_dbg (&viortc->vdev->dev,"%s: xfer returned %d\n" , __func__, ret);
@@ -858,7 +858,7 @@ int viortc_set_alarm(struct viortc_dev *viortc, u16 vio_clk_id, u64 alarm_time,VIORTC_MSG_WRITE (hdl, flags, &flags); ret =viortc_msg_xfer (&viortc->vqs[VIORTC_REQUESTQ ],VIORTC_MSG (hdl), -0 ); +VIORTC_MSG_TIMEOUT );if (ret) {dev_dbg (&viortc->vdev->dev,"%s: xfer returned %d\n" , __func__, ret);
@@ -900,7 +900,7 @@ int viortc_set_alarm_enabled(struct viortc_dev *viortc, u16 vio_clk_id,VIORTC_MSG_WRITE (hdl, flags, &flags); ret =viortc_msg_xfer (&viortc->vqs[VIORTC_REQUESTQ ],VIORTC_MSG (hdl), -0 ); +VIORTC_MSG_TIMEOUT );if (ret) {dev_dbg (&viortc->vdev->dev,"%s: xfer returned %d\n" , __func__, ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1628/1815 rtc: pcf8563: fix clock provider leak on unbind
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yi Ding <[email protected]>
[ Upstream commit 9c48a53685040bb0de45a640b34055cbbfc69d4f ]
pcf8563_clkout_register_clk() registers the CLKOUT clock provider with of_clk_add_provider(), but nothing ever unwinds it: there is no of_clk_del_provider() call and the driver has no remove callback. Each of_clk_add_provider() allocates a struct of_clk_provider, takes a reference on the OF node and adds an entry to the global of_clk_providers list, none of which is released when the device is unbound. Every bind/unbind (or module reload) therefore leaks a provider structure and an of_node reference.
The clock itself is already device-managed (devm_clk_register()); only the provider registration was not. Use devm_of_clk_add_hw_provider() so the provider is removed automatically on unbind. Tie it to the parent i2c device, whose OF node carries the #clock-cells and clock-output-names properties (the RTC class device has no OF node of its own).
--- drivers/rtc/rtc-pcf8563.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/rtc/rtc-pcf8563.c +3 -1
@@ -449,7 +449,9 @@ static struct clk *pcf8563_clkout_register_clk(struct pcf8563 *pcf8563) clk =devm_clk_register (&pcf8563->rtc->dev, &pcf8563->clkout_hw);if (!IS_ERR (clk)) -of_clk_add_provider (node, of_clk_src_simple_get, clk); +devm_of_clk_add_hw_provider (pcf8563->rtc->dev.parent, + of_clk_hw_simple_get, + &pcf8563->clkout_hw);return clk; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1629/1815 rtc: spacemit: handle regmap_test_bits() error return
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Surendra Singh Chouhan <[email protected]>
[ Upstream commit 092755367e1a5fcf0f5405e9425e86907199dfce ]
p1_rtc_read_time() called if (!regmap_test_bits(regmap, RTC_CTRL, RTC_EN)) to check if the RTC was enabled.
regmap_test_bits() returns 1 if the bit is set, 0 if not set, and a negative error code (e.g. -EIO) if reading the control register fails. Using !regmap_test_bits(...) evaluates a negative error code as boolean false, causing I2C/regmap read failures to be ignored and incorrectly proceeding to read time registers from a failing device.
Fix this by capturing the return value of regmap_test_bits() and returning the error code if negative, or -EINVAL if the RTC is disabled.
--- drivers/rtc/rtc-spacemit-p1.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/rtc/rtc-spacemit-p1.c +3 -2
@@ -57,8 +57,9 @@ static int p1_rtc_read_time(struct device *dev, struct rtc_time *t)u8 time[6 ];int ret; -if (!regmap_test_bits (regmap,RTC_CTRL ,RTC_EN )) -return -EINVAL ;/* RTC is disabled */ + ret =regmap_test_bits (regmap,RTC_CTRL ,RTC_EN ); +if (ret <=0 ) +return ret ?: -EINVAL ;/* RTC is disabled or error */ ret =regmap_bulk_read (regmap,RTC_TIME , time,sizeof (time));if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1630/1815 smb/client: return EOPNOTSUPP for unsupported O_TMPFILE
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: ChenXiaoSong <[email protected]>
[ Upstream commit a2f9fb451c68adf2b3f7cae1bb66fb5801769ac6 ]
Some SMB servers return STATUS_OBJECT_NAME_NOT_FOUND or STATUS_DELETE_PENDING when creating an O_TMPFILE. The SMB client maps them to ENOENT.
The ENOENT error is supposed to be returned when the path (a target directory in this case) does not exist, while a lack of support of O_TMPFILE by the target file system should be indicated by EOPNOTSUPP.
--- fs/smb/client/dir.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/dir.c +2 -0
@@ -1138,6 +1138,8 @@ int cifs_tmpfile(struct mnt_idmap *idmap, struct inode *dir, }while (unlikely (rc == -EEXIST ) && ++retries < max_retries);if (rc) { +if (rc == -ENOENT ) + rc = -EOPNOTSUPP ;cifs_del_pending_open (&open); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1631/1815 smb: client: fix request buffer leak in smb2_new_read_req()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christopher Lusk <[email protected]>
[ Upstream commit deb6468f4164640e4dc875f008aa449cf55987a5 ]
smb2_new_read_req() allocates the request buffer with smb2_plain_req_init() but only publishes it to the caller with *buf = req at the very end of the function. Two error returns sit in between:
rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, server, (void **) &req, total_len); if (rc) return rc; if (server == NULL) return -ECONNABORTED; [...] rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter, true, need_invalidate); if (!rdata->mr) return -EAGAIN;
On either of them the buffer is neither released nor handed back, so it is leaked. The caller cannot clean up after it: smb2_async_readv() does 'goto out' on a non-zero return, which skips the cifs_small_buf_release(buf) at async_readv_out, and buf has not been assigned at that point in any case.
The write path has never had this problem. smb2_async_writev() registers the memory region inline and jumps to its release label instead of returning:
wdata->mr = smbd_register_mr(...);
if (!wdata->mr) {
rc = -EAGAIN;
goto async_writev_out;
}Commit b7972092199f ("cifs: smbd: Retry on memory registration failure") changed both sides from -ENOBUFS to -EAGAIN in a single patch, which puts the two shapes next to each other.
Only the -EAGAIN return is reachable in practice, because smb2_plain_req_init() calls smb2_reconnect() first and that already fails with -EIO when server is NULL, before anything is allocated. Both returns are given the same treatment here rather than leaving one of them correct only by accident.
Because -EAGAIN is a replayable error, the failure also reaches the retry block at the end of smb2_async_readv(), which marks the subrequest NETFS_SREQ_NEED_RETRY, so a failing registration can be retried rather than ending the I/O, and every attempt that reaches it leaks another buffer. smb2_should_replay() short-circuits on tcon->retry, so on a hard mount the attempt count is not bounded by the retrans setting.
Only the asynchronous read path is affected. The synchronous SMB2_read() caller passes rdata == NULL and the memory registration block is guarded on rdata.
The memory registration failure path was pointed out by the Sashiko AI reviewer while it was reviewing an unrelated patch to smb2_async_readv().
--- fs/smb/client/smb2pdu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/smb/client/smb2pdu.c +12 -4
@@ -4564,8 +4564,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len,if (rc)return rc; -if (server ==NULL ) -return -ECONNABORTED ; +if (!server) { + rc = -ECONNABORTED ; + goto free_req; + } shdr = &req->hdr; shdr->Id.SyncId.ProcessId =cpu_to_le32 (io_parms->pid);
@@ -4596,8 +4598,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, rdata->mr =smbd_register_mr (server->smbd_conn, &rdata->subreq.io_iter, true, need_invalidate); -if (!rdata->mr) -return -EAGAIN ; +if (!rdata->mr) { + rc = -EAGAIN ; + goto free_req; + } req->Channel =SMB2_CHANNEL_RDMA_V1_INVALIDATE ;if (need_invalidate)
@@ -4638,6 +4642,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, *buf = req;return rc; + +free_req: +cifs_small_buf_release (req); +return rc; } static void
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1632/1815 smb: client: set replay flag on the read send-error retry path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christopher Lusk <[email protected]>
[ Upstream commit 45f84cf25a0879a4d4e3ec3079982537be57c564 ]
smb2_async_readv() and smb2_async_writev() end with the same send-error block: if the error is replayable and smb2_should_replay() agrees, tell netfs to retry the subrequest. The write path also sets wdata->replay. The read path does not set rdata->replay.
smb2_should_replay() is not a pure predicate. It consumes the retry budget and computes the exponential back-off, doubling cur_sleep up to CIFS_MAX_SLEEP. That back-off is only applied where the replay flag is tested at the top of the reissued request:
if (rdata->replay) {
/* Back-off before retry */
if (rdata->cur_sleep)
msleep(rdata->cur_sleep);
smb2_set_replay(server, &rqst);
}So on the read path the back-off is recomputed on every send-error retry and then discarded, and SMB2_FLAGS_REPLAY_OPERATION is not set on the reissued request.
netfs does not pace the retry either. netfs_reissue_read() calls ->issue_read() directly, and fs/netfs/read_retry.c contains no delay of its own, so read send-error retries reissue immediately while the equivalent write retries back off.
The read response callback already sets rdata->replay under the same conditions, so the read path does use the replay mechanism. Only this send-error path omits it.
Where the back-off belongs was settled while the commit below was under review. David Howells asked whether netfslib should be doing the back-off [1], and objected to sleeping inside the response callback because that runs in the cifsd thread and would stall the socket [2]. The sleep was therefore taken out of smb2_should_replay() and moved to just before the replay in smb2_async_readv() and smb2_async_writev() [3]. Setting the flag here preserves that arrangement: the sleep still happens at the top of the reissued request, not in a callback.
Set rdata->replay here, matching smb2_async_writev().
--- fs/smb/client/smb2pdu.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2pdu.c +1 -0
@@ -4893,6 +4893,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) smb2_should_replay(tcon, &rdata->retries, &rdata->cur_sleep)) { + rdata->replay = true;trace_netfs_sreq (&rdata->subreq, netfs_sreq_trace_io_retry_needed);__set_bit (NETFS_SREQ_NEED_RETRY , &rdata->subreq.flags); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1633/1815 cifs: remove dead size-update blocks in cifs_setattr_unix/nounix
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
[ Upstream commit 60be95527bc8d1b33dca25d2a849268cca11d139 ]
Commit 110fee6b9bb5 ("smb: client: fix missing timestamp updates with O_TRUNC") introduced cifs_file_set_size(), which calls netfs_resize_file() and cifs_setsize() on success. cifs_setsize() calls i_size_write(), updating i_size to the new value. The subsequent blocks in both cifs_setattr_unix() and cifs_setattr_nounix():
if ((attrs->ia_valid & ATTR_SIZE) &&
attrs->ia_size != i_size_read(inode)) {
truncate_setsize(inode, attrs->ia_size);
netfs_resize_file(&cifsInode->netfs, attrs->ia_size, true);
fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size);
}are therefore unreachable on the success path: attrs->ia_size == i_size_read(inode) always holds after cifs_file_set_size() succeeds. On the failure path, execution jumps to out/cifs_setattr_exit before reaching these blocks.
truncate_setsize() and netfs_resize_file() are redundant with what cifs_file_set_size() already did; fscache_resize_cookie() was moved there by commit fa724e235cfd ("cifs: add fscache_resize_cookie() to cifs_setsize()"). Remove both dead blocks.
--- fs/smb/client/inode.c | 14 -------------- 1 file changed, 14 deletions(-)
fs/smb/client/inode.c +0 -14
@@ -3310,13 +3310,6 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)if (rc) goto out; -if ((attrs->ia_valid &ATTR_SIZE ) && - attrs->ia_size !=i_size_read (inode)) { -truncate_setsize (inode, attrs->ia_size); -netfs_resize_file (&cifsInode->netfs, attrs->ia_size, true); -fscache_resize_cookie (cifs_inode_cookie (inode), attrs->ia_size); - } -setattr_copy (&nop_mnt_idmap, inode, attrs);mark_inode_dirty (inode);
@@ -3537,13 +3530,6 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)if (rc) goto cifs_setattr_exit; -if ((attrs->ia_valid &ATTR_SIZE ) && - attrs->ia_size !=i_size_read (inode)) { -truncate_setsize (inode, attrs->ia_size); -netfs_resize_file (&cifsInode->netfs, attrs->ia_size, true); -fscache_resize_cookie (cifs_inode_cookie (inode), attrs->ia_size); - } -setattr_copy (&nop_mnt_idmap, inode, attrs);mark_inode_dirty (inode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1634/1815 rtc: zynqmp: Return optional clock lookup errors
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 5904c4109554582ce8ded6a4dcfede48b21dbe4d ]
devm_clk_get_optional() returns NULL when the optional clock is absent, but returns an ERR_PTR when the clock provider lookup fails. Probe currently keeps the ERR_PTR and then passes it to clk_get_rate().
Return the lookup error instead. A truly absent optional clock still reaches the existing calibration fallback through clk_get_rate(NULL).
--- drivers/rtc/rtc-zynqmp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/rtc/rtc-zynqmp.c +3 -4
@@ -334,10 +334,9 @@ static int xlnx_rtc_probe(struct platform_device *pdev)/* Getting the rtc info */ xrtcdev->rtc_clk =devm_clk_get_optional (&pdev->dev,"rtc" ); -if (IS_ERR (xrtcdev->rtc_clk)) { -if (PTR_ERR (xrtcdev->rtc_clk) != -EPROBE_DEFER ) -dev_warn (&pdev->dev,"Device clock not found.\n" ); - } +if (IS_ERR (xrtcdev->rtc_clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (xrtcdev->rtc_clk), +"Failed to get rtc clock\n" ); xrtcdev->freq =clk_get_rate (xrtcdev->rtc_clk);if (!xrtcdev->freq) { ret = of_property_read_u32(pdev->dev.of_node, "calibration",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1635/1815 irqchip/renesas-rzg2l: Fix loss of interrupt
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Biju Das <[email protected]>
[ Upstream commit 50b10bd0c2d721ad38abd1abe3acdefb6caa0944 ]
rzg2l_clear_irq_int() and rzg2l_clear_tint_int() perform a read-modify-write on the ISCR/TSCR status registers to clear the bit for the interrupt just handled. Since these registers are write-0-to-clear per bit, this is racy:
If another interrupt's status bit gets set between the read and the write, that bit is written back as 0 by the software-constructed value, clearing an interrupt that hasn't been serviced yet and losing it.
This can be reproduced by triggering multiple interrupts at once, e.g.:
gpioset -c gpiochip0 355=0 353=0 328=0 352=0
Fix this by writing back only the bit being cleared, with all other bits set to 1, instead of read-modify-writing the whole register. Since 1-bits are left unchanged by hardware, concurrently-set status bits for other interrupts are preserved.
--- drivers/irqchip/irq-renesas-rzg2l.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-renesas-rzg2l.c +2 -2
@@ -161,7 +161,7 @@ static void rzg2l_clear_irq_int(struct rzg2l_irqc_priv *priv, unsigned int hwirq* falling/rising-edge. */ if ((iscr & bit) && (iitsr &IITSR_IITSEL_MASK (hw_irq))) { -writel_relaxed (iscr & ~bit, priv->base +ISCR ); +writel_relaxed (~bit, priv->base +ISCR );/* * Enforce that the posted write is flushed to prevent that the * just handled interrupt is raised again.
@@ -177,7 +177,7 @@ static void rzg2l_clear_tint_int(struct rzg2l_irqc_priv *priv, unsigned int hwir reg =readl_relaxed (priv->base +TSCR );if (reg & bit) { -writel_relaxed (reg & ~bit, priv->base +TSCR ); +writel_relaxed (~bit, priv->base +TSCR );/* * Enforce that the posted write is flushed to prevent that the * just handled interrupt is raised again.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1636/1815 irqchip/ast2700-intc: Avoid allocating in the irq_domain activate() callback
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Chen <[email protected]>
[ Upstream commit b76eee9c2157223aa4aac42ceebb563288e078aa ]
The interrupt core calls the irq_domain_activate() callback from __setup_irq() with desc->lock held and interrupts disabled. Both aspeed_intc1_irq_domain_activate() and aspeed_intc0_resolve_route() test a compatible string with fwnode_device_is_compatible().
fwnode_device_is_compatible() invokes fwnode_property_match_string(), which allocates with GFP_KERNEL. That's obviously not possible with interrupts disabled and a raw spinlock held.
Both call sites are only ever handed OF nodes, so use of_device_is_compatible() instead: it walks the property in place and does not allocate.
--- drivers/irqchip/irq-ast2700-intc0.c | 2 +- drivers/irqchip/irq-ast2700-intc1.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/irqchip/irq-ast2700-intc0.c +1 -1
@@ -312,7 +312,7 @@ int aspeed_intc0_resolve_route(const struct irq_domain *c0domain, size_t nc1outsreturn -ENOENT ;if (!IS_ENABLED (CONFIG_ASPEED_AST2700_INTC_TEST ) && - !fwnode_device_is_compatible (c0domain->fwnode,"aspeed,ast2700-intc0" )) + !of_device_is_compatible (to_of_node (c0domain->fwnode),"aspeed,ast2700-intc0" ))return -ENODEV ; intc0 = c0domain->host_data;
drivers/irqchip/irq-ast2700-intc1.c +2 -1
@@ -157,7 +157,8 @@ static int aspeed_intc1_irq_domain_activate(struct irq_domain *domain, intc1->ranges.nranges, intc1->ranges.ranges, &resolved);if (rc <0 ) { -if (!fwnode_device_is_compatible (intc1->upstream->fwnode,"riscv,aplic" )) { +if (!of_device_is_compatible (to_of_node (intc1->upstream->fwnode), +"riscv,aplic" )) {dev_warn (intc1->dev,"Failed to resolve interrupt route for hwirq %lu in domain %s\n" , data->hwirq, domain->name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1637/1815 i2c: ocores: Disable clock on failed resume
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 43eb13f13385a1e7251978a1977ac61b99edef01 ]
ocores_i2c_resume() enables the controller clock before reinitializing the hardware. If the clock rate changed while the device was suspended, ocores_init() may reject the resulting prescaler. The callback then returns an error with the clock still enabled, while the controller itself remains disabled.
Disable and unprepare the clock when ocores_init() fails so the failed resume path balances the successful clk_prepare_enable() call.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/i2c/busses/i2c-ocores.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-ocores.c +5 -1
@@ -755,7 +755,11 @@ static int ocores_i2c_resume(struct device *dev) rate =clk_get_rate (i2c->clk) /1000 ;if (rate) i2c->ip_clock_khz = rate; -return ocores_init (dev, i2c); + ret =ocores_init (dev, i2c); +if (ret) +clk_disable_unprepare (i2c->clk); + +return ret; } static DEFINE_NOIRQ_DEV_PM_OPS(ocores_i2c_pm,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1638/1815 rtc: gamecube: check return value of devm_rtc_register_device()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit ca45cfa74370644d371b552bef57938c19e3c80c ]
gamecube_rtc_probe() ignored the return value of devm_rtc_register_device() and always returned success. Propagate the error so probe fails when RTC registration fails.
--- drivers/rtc/rtc-gamecube.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/rtc/rtc-gamecube.c +1 -3
@@ -355,9 +355,7 @@ static int gamecube_rtc_probe(struct platform_device *pdev) rtc->range_max =U32_MAX ; rtc->ops = &gamecube_rtc_ops; -devm_rtc_register_device (rtc); - -return 0 ; +return devm_rtc_register_device (rtc); }static const struct of_device_id gamecube_rtc_of_match[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1639/1815 lib/interval_tree: fix allocation warning messages
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit d9c0fd5533fb23bc445bd581feb140e966195936 ]
WARN_ON_ONCE() takes a condition, not a message. The string literals are always true, so the warnings still trigger but the messages are never printed.
Use WARN_ONCE(1, ...) instead to print the messages and keep the once-only behavior.
Found with a Coccinelle script. Clang's -Wstring-conversion also flags such calls but is not enabled in kernel builds.
--- lib/interval_tree_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/interval_tree_test.c +2 -2
@@ -140,13 +140,13 @@ static int intersection_range_check(void) intxn1 =bitmap_alloc (nnodes,GFP_KERNEL );if (!intxn1) { -WARN_ON_ONCE ("Failed to allocate intxn1\n" ); +WARN_ONCE (1 ,"Failed to allocate intxn1\n" );return -ENOMEM ; } intxn2 =bitmap_alloc (nnodes,GFP_KERNEL );if (!intxn2) { -WARN_ON_ONCE ("Failed to allocate intxn2\n" ); +WARN_ONCE (1 ,"Failed to allocate intxn2\n" );bitmap_free (intxn1);return -ENOMEM ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1640/1815 prctl: fix PR_SET_MM_AUXV losing the forced AT_NULL terminator
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 5146e0688d86f0654263e4b0e4ff1719b4072f16 ]
prctl_set_auxv() copies the user vector into a stack buffer, forces AT_NULL on the last two entries there, and then copies only len bytes into mm->saved_auxv. Which is fine until the vector is shorter than the buffer, because then the forced terminator sits past the end of the copy and never lands in saved_auxv at all.
The code even says
/* Make sure the last entry is always AT_NULL */
and it does, just not in the part that gets copied.
So mm->saved_auxv keeps the stale tail from exec. Reproducing it is easy:
from a process with CAP_SYS_RESOURCE (just run it as root), call prctl(PR_SET_MM, PR_SET_MM_AUXV, ...) with a vector that has a couple of entries and no AT_NULL inside len (32 bytes on arm64), and then hexdump /proc/self/auxv, or gcore the process and look at the AUXV note with readelf -n. This is arm64, the new vector was just { AT_UID, 0x1111, AT_GID, 0x2222 }:
idx before (from exec) after the prctl
[0] AT_SYSINFO_EHDR 0x7ed1d6e000 AT_UID 0x1111 <- new
[1] AT_MINSIGSTKSZ 0x1270 AT_GID 0x2222 <- new
[2] AT_HWCAP 0x119fff AT_HWCAP 0x119fff <- stale
[3] AT_PAGESZ 0x1000 AT_PAGESZ 0x1000 <- stale
... 16 more entries ... <- stale
[20] AT_NULL 0x0 AT_NULL 0x021 entries before the prctl, still 21 after: the two new ones plus all 19 left over from exec.
Every consumer walks the vector until AT_NULL, so what they get now is a vector that never existed at exec, the head from the prctl glued onto the tail of the old binary. gdb and crash pull the AUXV note out of coredumps to find AT_PHDR, AT_ENTRY, AT_SYSINFO_EHDR and friends, and a mixed vector points them at the wrong layout. /proc/<pid>/auxv and PR_GET_AUXV hand the same mess out to live processes too. Nothing crashes, everything just quietly reads a frankenstein auxv.
And callers that terminate their own vector hide the whole thing, which is likely why nobody noticed since PR_SET_MM_AUXV landed in 2012. Nothing exciting security wise either, I mean it needs CAP_SYS_RESOURCE to begin with.
prctl_set_mm_map() right above already copies the whole buffer for exactly this reason, so just do the same here. user_auxv is zero initialized and only partially filled from userspace, so the rest is zeros and nothing leaks.
--- kernel/sys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +1 -1
@@ -2189,7 +2189,7 @@ static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr,BUILD_BUG_ON (sizeof (user_auxv) !=sizeof (mm->saved_auxv));task_lock (current); -memcpy (mm->saved_auxv, user_auxv, len); +memcpy (mm->saved_auxv, user_auxv,sizeof (user_auxv));task_unlock (current);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1641/1815 clk: ti: Make sure clk_init_data is fully initialized
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
[ Upstream commit 3ae1674975d48fb6d343d03ff7961abd6904af1a ]
The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.
_register_mux() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter is uninitialized, and thus may cause a crash.
Make sure all members are fully initialized, to fix such bugs, and to avoid future breakage when converting drivers to a different method for specifying the parents.
--- drivers/clk/ti/adpll.c | 4 ++-- drivers/clk/ti/divider.c | 2 +- drivers/clk/ti/mux.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/clk/ti/adpll.c +2 -2
@@ -483,7 +483,7 @@ static const struct clk_ops ti_adpll_ops = {static int ti_adpll_init_dco (struct ti_adpll_data *d) { -struct clk_init_data init; +struct clk_init_data init = {};struct clk *clock;const char *postfix;int width, err;
@@ -576,7 +576,7 @@ static int ti_adpll_init_clkout(struct ti_adpll_data *d, struct clk *clk1) {struct ti_adpll_clkout_data *co; -struct clk_init_data init; +struct clk_init_data init = {};struct clk_ops *ops;const char *parent_names[2 ];const char *child_name;
drivers/clk/ti/divider.c +1 -1
@@ -311,7 +311,7 @@ static struct clk *_register_divider(struct device_node *node,u32 flags, struct clk_omap_divider *div) { - struct clk_init_data init; + struct clk_init_data init = {};const char *parent_name;const char *name;
drivers/clk/ti/mux.c +1 -1
@@ -124,9 +124,9 @@ static struct clk *_register_mux(struct device_node *node, const char *name, struct clk_omap_reg *reg, u8 shift, u32 mask, s8 latch, u8 clk_mux_flags, u32 *table) { + struct clk_init_data init = {};struct clk_omap_mux *mux;struct clk *clk; -struct clk_init_data init;/* allocate the mux */ mux =kzalloc_obj (*mux);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1642/1815 clk: visconti: Make sure clk_init_data is fully initialized
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
[ Upstream commit 39c0e6c844a14945040cca4ccf6997792ab764c4 ]
The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.
visconti_clk_register_gate() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.
Make sure all members are fully initialized, to fix such bugs, and to avoid future breakage when converting drivers to a different method for specifying the parents.
--- drivers/clk/visconti/clkc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/visconti/clkc.c +1 -1
@@ -81,9 +81,9 @@ static struct clk_hw *visconti_clk_register_gate(struct device *dev,u8 rs_idx, spinlock_t *lock) { + struct clk_init_data init = {};struct visconti_clk_gate *gate;struct clk_parent_data *pdata; -struct clk_init_data init;struct clk_hw *hw;int ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1643/1815 irqchip/ast2700-intc: Disable all interrupt merge banks on probe
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Pesa <[email protected]>
[ Upstream commit 34b7e953d19a39515f8fc6c0820ebf243ea6b026 ]
The INTC0 interrupt-merge (INTM) space has 50 sources at 10 per bank, i.e. INTC0_INTM_NUM / INTM_IRQS_PER_BANK = 5 banks. This is reflected everywhere the banks are indexed: the aspeed_intc0_intm_routes[] table has 5 valid entries, and the mask/unmask/eoi paths compute the bank as (hwirq - INTM_BASE) / INTM_IRQS_PER_BANK, spanning banks 0-4.
However, INTC0_INTM_BANK_NUM is hardcoded to 3, so aspeed_intc0_disable_intm() only clears IER for banks 0-2 at probe. Banks 3 and 4 are left in whatever state the firmware configured them , which can leave interrupts enabled before a handler is installed.
Derive the bank count from the source count so the probe-time disable covers every bank.
--- drivers/irqchip/irq-ast2700-intc0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-ast2700-intc0.c +1 -1
@@ -48,9 +48,9 @@#define INTC0_INTMX_IER 0x1b00#define INTC0_INTMX_ISR 0x1b04#define INTC0_INTMX_BANK_SIZE 0x10 -#define INTC0_INTM_BANK_NUM 3#define INTC0_IRQS_PER_BANK 32#define INTM_IRQS_PER_BANK 10 +#define INTC0_INTM_BANK_NUM (INTC0_INTM_NUM / INTM_IRQS_PER_BANK)#define INTC0_SEL_BASE 0x200#define INTC0_SEL_BANK_SIZE 0x4#define INTC0_SEL_ROUTE_SIZE 0x100
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1644/1815 irqchip/gic-v5: Clear per-CPU IRS data on teardown
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sascha Bischoff <[email protected]>
[ Upstream commit 3dfc0ab5fefd052c6028c4632b1fad8bdaf7967e ]
IRS affinity setup publishes an IRS pointer and IAFFID state in the per-CPU data before the remaining IRS initialization can fail. The error path then frees the IRS data without clearing that published state, leaving CPUs associated with freed memory.
On initialization failure and normal IRS teardown, clear the per-CPU IRS association by removing the stale pointer to irs_data. Also invalidate the per-CPU IAFFID state for any CPUs that were tied to the IRS before it was freed.
--- drivers/irqchip/irq-gic-v5-irs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/irqchip/irq-gic-v5-irs.c +15 -0
@@ -651,6 +651,18 @@ static int __init gicv5_irs_of_init_affinity(struct device_node *node,return ret; } +static void __init gicv5_irs_clear_affinity (struct gicv5_irs_chip_data *irs_data) +{ +int cpu; + +for_each_possible_cpu (cpu) { +if (per_cpu (per_cpu_irs_data, cpu) == irs_data) { +per_cpu (cpu_iaffid, cpu).valid = false; +per_cpu (per_cpu_irs_data, cpu) =NULL ; + } + } +} +static void irs_setup_pri_bits (u32 idr1) {switch (FIELD_GET (GICV5_IRS_IDR1_PRIORITY_BITS , idr1)) {
@@ -773,6 +785,7 @@ static int __init gicv5_irs_of_init(struct device_node *node)return ret; out_iomem: +gicv5_irs_clear_affinity (irs_data);iounmap (irs_base); out_err:kfree (irs_data);
@@ -787,6 +800,7 @@ void __init gicv5_irs_remove(void)gicv5_deinit_lpis ();list_for_each_entry_safe (irs_data, tmp_data, &irs_nodes, entry) { +gicv5_irs_clear_affinity (irs_data);iounmap (irs_data->irs_base);list_del (&irs_data->entry);kfree (irs_data);
@@ -951,6 +965,7 @@ static int __init gic_acpi_parse_madt_irs(union acpi_subtable_headers *header,return 0 ; out_map: +gicv5_irs_clear_affinity (irs_data);iounmap (irs_base); out_release:release_mem_region (r->start,resource_size (r));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1645/1815 irqchip/gic-v5: Synchronize CPU interface disable
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sascha Bischoff <[email protected]>
[ Upstream commit ac6db0e0bee18cd4385418c752a007e1aba4ec14 ]
The write disabling the GICv5 CPU interface is only guaranteed to take effect after a context synchronization event. Without one, execution can return from gicv5_cpu_disable_interrupts() while an interrupt is still able to be taken.
Add an ISB after the ICC_CR0_EL1 write to ensure interrupts are disabled before the function returns. No corresponding ISB is added when enabling the interface, as interrupt delivery is asynchronous and there is no obvious benefit to waiting for it.
--- drivers/irqchip/irq-gic-v5.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v5.c +1 -0
@@ -983,6 +983,7 @@ static void gicv5_cpu_disable_interrupts(void) cr0 =FIELD_PREP (ICC_CR0_EL1_EN ,0 );write_sysreg_s (cr0,SYS_ICC_CR0_EL1 ); +isb (); }static void gicv5_cpu_enable_interrupts (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1646/1815 irqchip/gic-v5: Check get_logical_index() return value in MADT IAFFID parsing
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit 328affc639ce9873a7a0a3fd6b8339f19767529b ]
In gic_acpi_parse_iaffid() a given MADT GICC entry might not correspond to a logical cpu recognized by the kernel, resulting in the cpu variable initialization to an error value.
Currently, the get_logical_index() return value is not checked for failure, which might result in out-of-bounds memory corruption while trying to index a per_cpu variable array.
Add a check to evaluate get_logical_index() return value.
--- drivers/irqchip/irq-gic-v5-irs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/irqchip/irq-gic-v5-irs.c +2 -0
@@ -874,6 +874,8 @@ static int __init gic_acpi_parse_iaffid(union acpi_subtable_headers *header,return 0 ; cpu =get_logical_index (gicc->arm_mpidr); +if (cpu <0 ) +return 0 ;if (gicc->iaffid & ~GENMASK (current_iaffid_bits -1 ,0 )) {pr_warn ("CPU %d iaffid 0x%x exceeds IRS iaffid bits\n" , cpu, gicc->iaffid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1647/1815 irqchip/gic-v5: Check for NULL LPI domain on domain teardown
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit aa079dbf4c2598c2613a0e464efcb2c232753c51 ]
In gicv5_free_lpi_domain() the LPI domain being freed can be NULL.
Check it and return before trying to free it if it is.
--- drivers/irqchip/irq-gic-v5.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v5.c +3 -0
@@ -862,6 +862,9 @@ void __init gicv5_init_lpi_domain(void)void __init gicv5_free_lpi_domain (void ) { +if (!gicv5_global_data.lpi_domain) +return ; +irq_domain_remove (gicv5_global_data.lpi_domain); gicv5_global_data.lpi_domain =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1648/1815 irqchip/gic-v5: Disable IRSes on probe failures
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit 79b115c2a29204cb7e836b0df0b8c466be4b2250 ]
GICv5 driver probe failures cause IRSes initialized by the kernel to be unmapped and their data structures to be destroyed but the current driver leaves the probed IRSes enabled, whereas they should be disabled.
Disable IRSes on driver probe failures so that the IRSes are brought back to their quiescent HW state.
--- drivers/irqchip/irq-gic-v5-irs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/irqchip/irq-gic-v5-irs.c +9 -0
@@ -488,6 +488,12 @@ static int gicv5_irs_wait_for_idle(struct gicv5_irs_chip_data *irs_data) GICV5_IRS_CR0_IDLE, NULL); } +static void __init gicv5_irs_disable (struct gicv5_irs_chip_data *irs_data) +{ +irs_writel_relaxed (irs_data,0 ,GICV5_IRS_CR0 ); +gicv5_irs_wait_for_idle (irs_data); +} +void gicv5_irs_syncr (void ) {struct gicv5_irs_chip_data *irs_data;
@@ -786,6 +792,7 @@ static int __init gicv5_irs_of_init(struct device_node *node) out_iomem:gicv5_irs_clear_affinity (irs_data); +gicv5_irs_disable (irs_data);iounmap (irs_base); out_err:kfree (irs_data);
@@ -801,6 +808,7 @@ void __init gicv5_irs_remove(void)list_for_each_entry_safe (irs_data, tmp_data, &irs_nodes, entry) {gicv5_irs_clear_affinity (irs_data); +gicv5_irs_disable (irs_data);iounmap (irs_data->irs_base);list_del (&irs_data->entry);kfree (irs_data);
@@ -968,6 +976,7 @@ static int __init gic_acpi_parse_madt_irs(union acpi_subtable_headers *header, out_map:gicv5_irs_clear_affinity (irs_data); +gicv5_irs_disable (irs_data);iounmap (irs_base); out_release:release_mem_region (r->start,resource_size (r));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1649/1815 irqchip/gic-v5: Fix gicv5_init_common() error paths
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit 183750b276c229c5253b3b11581f6cd8877b753e ]
Current code fails to disable interrupts on gicv5_starting_cpu() failure and to set the handle_arch_irq pointer to NULL if gicv5_irs_enable() fails.
Update the respective error paths to fix them.
--- drivers/irqchip/irq-gic-v5.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/irqchip/irq-gic-v5.c +4 -3
@@ -1174,7 +1174,7 @@ static int __init gicv5_init_common(struct fwnode_handle *parent_domain) ret =gicv5_starting_cpu (smp_processor_id ());if (ret) - goto out_dom; + goto out_int; ret =set_handle_irq (gicv5_handle_irq);if (ret)
@@ -1182,16 +1182,17 @@ static int __init gicv5_init_common(struct fwnode_handle *parent_domain) ret =gicv5_irs_enable ();if (ret) - goto out_int; + goto out_handle;gicv5_smp_init ();gicv5_irs_its_probe ();return 0 ; +out_handle: +set_handle_irq (NULL ); out_int:gicv5_cpu_disable_interrupts (); -out_dom:gicv5_free_domains ();return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1650/1815 irqchip/gic-v5: Release IRS iomem region on driver init failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit dc2eae1620bdb4562aa43f1c34c8427308ab4436 ]
In gicv5_irs_of_init(), an IRS is set-up using of_io_request_and_map() to request its memory region (corresponding to the configuration frame) and map the IRS configuration frame.
On gicv5_irs_of_init() failure, the driver unmaps the IRS iomem region but does not release the requested memory region leaving it allocated in the iomem resource tree.
Fix it by releasing the iomem region on gicv5_irs_of_init() probe failure.
Likewise, on both OF and ACPI driver init failure, IRS iomem regions are requested but never released in gicv5_irs_remove().
Stash a copy of the IRS iomem region in a struct resource in struct gicv5_irs_chip_data and use it to release the requested region in gicv5_irs_remove() if the driver probe fails.
--- drivers/irqchip/irq-gic-v5-irs.c | 10 ++++++++++ include/linux/irqchip/arm-gic-v5.h | 2 ++ 2 files changed, 12 insertions(+)
drivers/irqchip/irq-gic-v5-irs.c +10 -0
@@ -740,6 +740,7 @@ static int __init gicv5_irs_init(struct gicv5_irs_chip_data *irs_data)static int __init gicv5_irs_of_init (struct device_node *node) {struct gicv5_irs_chip_data *irs_data; +struct resource res;void __iomem *irs_base;u8 iaffid_bits;u32 idr;
@@ -757,6 +758,11 @@ static int __init gicv5_irs_of_init(struct device_node *node) goto out_err; } +if (of_address_to_resource (node, ret, &res)) { + ret = -EINVAL ; + goto out_err; + } + irs_base =of_io_request_and_map (node, ret,of_node_full_name (node));if (IS_ERR (irs_base)) {pr_err ("%pOF: unable to map GICv5 IRS registers\n" , node);
@@ -765,6 +771,7 @@ static int __init gicv5_irs_of_init(struct device_node *node) } irs_data->fwnode =of_fwnode_handle (node); + irs_data->res = res;gicv5_irs_init_bases (irs_data, irs_base,of_property_read_bool (node,"dma-noncoherent" )); idr =irs_readl_relaxed (irs_data,GICV5_IRS_IDR1 );
@@ -794,6 +801,7 @@ static int __init gicv5_irs_of_init(struct device_node *node)gicv5_irs_clear_affinity (irs_data);gicv5_irs_disable (irs_data);iounmap (irs_base); +release_mem_region (res.start,resource_size (&res)); out_err:kfree (irs_data);return ret;
@@ -810,6 +818,7 @@ void __init gicv5_irs_remove(void)gicv5_irs_clear_affinity (irs_data);gicv5_irs_disable (irs_data);iounmap (irs_data->irs_base); +release_mem_region (irs_data->res.start,resource_size (&irs_data->res));list_del (&irs_data->entry);kfree (irs_data); }
@@ -958,6 +967,7 @@ static int __init gic_acpi_parse_madt_irs(union acpi_subtable_headers *header, }gicv5_irs_init_bases (irs_data, irs_base, irs->flags &ACPI_MADT_IRS_NON_COHERENT ); + irs_data->res = *r;gicv5_irs_acpi_init_affinity (irs->irs_id, irs_data);
include/linux/irqchip/arm-gic-v5.h +2 -0
@@ -6,6 +6,7 @@#define __LINUX_IRQCHIP_ARM_GIC_V5_H#include <linux/iopoll.h> +#include <linux/ioport.h> #include <asm/cacheflush.h> #include <asm/smp.h>
@@ -324,6 +325,7 @@ struct gicv5_irs_chip_data {struct list_head entry;struct fwnode_handle *fwnode;void __iomem *irs_base; +struct resource res;u32 flags;u32 spi_min;u32 spi_range;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1651/1815 irqchip/gic-v5: Use logical cpu 0 irs_data for dynamic IST allocation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit 9dfcc2187282816d42b9f8aa2b689c732ebbcc01 ]
In set-ups with a 2-level IST, L1 table entries are created dynamically when LPIs are allocated.
The L1 allocation and mapping, implemented in gicv5_irs_iste_alloc() is carried out in preemtible context and can be carried out on any IRS in the system.
Current code indexes the per_cpu_irs_data per cpu array using smp_processor_id() to retrieve the IRS that is local to the core executing gicv5_irs_iste_alloc().
Since that's preemptible context, the core executing that function can change on preemption. Given that every IRS in the system is equivalent to each core, this is not really an issue in that even if the thread is preempted and resumed on a different cpu, the table allocation and mapping to an IRS would work seamlessly regardless.
On the other hand, smp_processor_id() spits a legitimate splat on DEBUG_PREEMPT kernels when used in preemtible context and this should be fixed.
Given that all IRSes are equivalent from a core perspective in terms of IST initialization, always choose as a policy the IRS local to logical cpu 0, preventing the smp_processor_id() splat.
--- drivers/irqchip/irq-gic-v5-irs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v5-irs.c +1 -1
@@ -199,7 +199,7 @@ int gicv5_irs_iste_alloc(const u32 lpi)if (!gicv5_global_data.ist.l2)return 0 ; - irs_data =per_cpu (per_cpu_irs_data,smp_processor_id ()); + irs_data =per_cpu (per_cpu_irs_data,0 );if (!irs_data)return -ENOENT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1652/1815 irqchip/gic-v5: Defer default SPI and LPI IAFFID programming
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Pieralisi <[email protected]>
[ Upstream commit a1ee1a1ca75b674f503c74eb8b3ca77612ba3c0c ]
SPI and LPI interrupts do not have an architected default value for their IAFFID (interrupt affinity ID) - the property that determines an IRQ affinity.
Current code awkwardly tries to set a default IAFFID value corresponding to the logical cpu executing the gicv5_hwirq_init() function at SPI/LPI allocation time.
There are two issues with this approach:
- gicv5_hwirq_init() is called in preemptible context and current code uses smp_processor_id() to check the logical cpu executing the function. Whilst that's harmless, it can spit a splat on DEBUG_PREEMPT kernels
- Setting the default SPI/LPI IAFFID to the one belonging to the cpu executing the IRQ allocation is a completely arbitrary choice
It is saner to remove the SPI/LPI IAFFID set-up in the SPI/LPI domain IRQ allocation code and flag SPI/LPI irqchips as IRQCHIP_AFFINITY_PRE_STARTUP so that the SPI/LPI affinity is initialized by IRQ core to a sane value before an IRQ is started up using the respective irq_chip irq_set_affinity() callback.
--- drivers/irqchip/irq-gic-v5.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/irqchip/irq-gic-v5.c +4 -14
@@ -87,25 +87,13 @@ static void gicv5_ppi_priority_init(void)static void gicv5_hwirq_init (irq_hw_number_t hwirq,u8 priority,u8 hwirq_type) { -u64 cdpri, cdaff; -u16 iaffid; -int ret; +u64 cdpri;if (hwirq_type ==GICV5_HWIRQ_TYPE_LPI || hwirq_type ==GICV5_HWIRQ_TYPE_SPI ) { cdpri =FIELD_PREP (GICV5_GIC_CDPRI_PRIORITY_MASK , priority) |FIELD_PREP (GICV5_GIC_CDPRI_TYPE_MASK , hwirq_type) |FIELD_PREP (GICV5_GIC_CDPRI_ID_MASK , hwirq);gic_insn (cdpri,CDPRI ); - - ret =gicv5_irs_cpu_to_iaffid (smp_processor_id (), &iaffid); - -if (WARN_ON_ONCE (ret)) -return ; - - cdaff =FIELD_PREP (GICV5_GIC_CDAFF_IAFFID_MASK , iaffid) | -FIELD_PREP (GICV5_GIC_CDAFF_TYPE_MASK , hwirq_type) | -FIELD_PREP (GICV5_GIC_CDAFF_ID_MASK , hwirq); -gic_insn (cdaff,CDAFF ); } }
@@ -548,6 +536,7 @@ static const struct irq_chip gicv5_spi_irq_chip = { .irq_get_irqchip_state = gicv5_spi_irq_get_irqchip_state, .irq_set_irqchip_state = gicv5_spi_irq_set_irqchip_state, .flags =IRQCHIP_SET_TYPE_MASKED | +IRQCHIP_AFFINITY_PRE_STARTUP |IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND, };
@@ -561,7 +550,8 @@ static const struct irq_chip gicv5_lpi_irq_chip = { .irq_retrigger = gicv5_lpi_irq_retrigger, .irq_get_irqchip_state = gicv5_lpi_irq_get_irqchip_state, .irq_set_irqchip_state = gicv5_lpi_irq_set_irqchip_state, - .flags = IRQCHIP_SKIP_SET_WAKE | + .flags =IRQCHIP_AFFINITY_PRE_STARTUP | +IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1653/1815 ALSA: ice1712: Fix the card leak at probe error with the auto-cleanup
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haotian Zhang <[email protected]>
[ Upstream commit d736eba9c453fedce664fdf592c8b71ecff1932b ]
snd_ice1712_probe() performs multiple initialization steps after snd_card_new(), but directly returns on failures from later steps without releasing the ALSA card, causing resource leaks when probing fails.
Use snd_devm_card_new() together with scope-based cleanup via __free(snd_card_unref), and clear the card pointer after successful registration to keep it alive.
--- sound/pci/ice1712/ice1712.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
sound/pci/ice1712/ice1712.c +4 -3
@@ -2523,7 +2523,7 @@ static int snd_ice1712_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) {static int dev; -struct snd_card *card; + struct snd_card *card __free(snd_card_unref) = NULL;struct snd_ice1712 *ice;int pcm_dev =0 , err;const struct snd_ice1712_card_info *const *tbl, *c;
@@ -2535,8 +2535,8 @@ static int snd_ice1712_probe(struct pci_dev *pci,return -ENOENT ; } - err =snd_card_new (&pci->dev, index[dev], id[dev],THIS_MODULE , -sizeof (*ice), &card); + err =snd_devm_card_new (&pci->dev, index[dev], id[dev],THIS_MODULE , +sizeof (*ice), &card);if (err <0 )return err; ice = card->private_data;
@@ -2640,6 +2640,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,if (err <0 )return err;pci_set_drvdata (pci, card); + card =NULL ;/* probe succeeded, don't release as error */ dev++;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1654/1815 sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 666a32836c8f9daf9b0067c49b04d5201fb8f3ba ]
A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).
sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).
There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.
This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.
Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.
--- include/linux/cpuset.h | 1 + 1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)static inline void rebuild_sched_domains (void ) { +guard (cpus_read_lock)();partition_sched_domains (1 ,NULL ,NULL ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1655/1815 ntfs: fix off-by-one page overflow in ntfs_decompress()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dennis Tighe <[email protected]>
[ Upstream commit 98716c9fce21f6c8a9d71e08cf53e7504fa562f4 ]
The per-token range check in ntfs_decompress() uses
if (cb >= cb_sb_end || dp_addr > dp_sb_end) break;
so dp_addr == dp_sb_end falls through to the symbol copy *dp_addr++ = *cb++, writing one byte past the destination page. Since NTFS_SB_SIZE == PAGE_SIZE the destination is a single page, so the byte lands in the adjacent page, and *dest_ofs is left one past the sub-block end (the later *dest_ofs &= ~PAGE_MASK then yields 1, not 0, so the page is never finalized and later sub-blocks keep writing further past it). A corrupted compressed $DATA attribute thus produces a bounded run of out-of-bounds writes when the file is read.
Break as soon as dp_addr reaches dp_sb_end; a full sub-block still completes, as its final copy advances dp_addr to exactly dp_sb_end.
--- fs/ntfs/compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/compress.c +1 -1
@@ -349,7 +349,7 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],u8 *dp_back_addr;/* Check if we are done / still in range. */ -if (cb >= cb_sb_end || dp_addr > dp_sb_end) +if (cb >= cb_sb_end || dp_addr >= dp_sb_end)break ;/* Determine token type and parse appropriately.*/
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1656/1815 ntfs: validate usa_ofs before preserving the update sequence number
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dennis Tighe <[email protected]>
[ Upstream commit 81684340963da2e898eabb8c1e274433d9375bc6 ]
When ntfs_mft_record_alloc() reuses a free mft record it reads the old update sequence number straight from the on-disk record:
usn = *(__le16 *)((u8 *)m + le16_to_cpu(m->usa_ofs));
Here m points into the raw $MFT page-cache folio, which still holds unvalidated, MST-protected bytes: the folio is read by a plain iomap_read_folio() and neither post_read_mst_fixup() nor ntfs_mft_record_check() has run on it (both work on private copies). m->usa_ofs is therefore an untrusted u16, and a corrupted record can put it past the end of the record so the two-byte read lands outside the folio. Reading such a record while creating a file gives, under KASAN:
BUG: KASAN: use-after-free in ntfs_mft_record_alloc+...
Read of size 2 at addr ...
ntfs_mft_record_alloc -> __ntfs_create -> ntfs_create -> path_openatOnly preserve the old update sequence number when usa_ofs is even and in range, mirroring the check ntfs_mft_record_check() already applies; otherwise leave usn zero, which the existing restore below skips.
--- fs/ntfs/mft.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
fs/ntfs/mft.c +11 -1
@@ -2333,7 +2333,17 @@ int ntfs_mft_record_alloc(struct ntfs_volume *vol, const int mode,* wrong with the previous mft record. */ seq_no = m->sequence_number; - usn = *(__le16 *)((u8 *)m +le16_to_cpu (m->usa_ofs)); +/* +* The mft record still holds unvalidated, MST-protected on-disk +* bytes, so m->usa_ofs is untrusted here. Only preserve the old +* update sequence number if that offset is in bounds; otherwise +* leave usn zero so it is not restored below. +*/ +if (!(le16_to_cpu (m->usa_ofs) &1 ) && +le16_to_cpu (m->usa_ofs) +sizeof (usn) <= vol->mft_record_size) + usn = *(__le16 *)((u8 *)m +le16_to_cpu (m->usa_ofs)); +else + usn =0 ; err =ntfs_mft_record_layout (vol, bit, m);if (unlikely (err)) { ntfs_error(vol->sb, "Failed to layout allocated mft record 0x%llx.",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1657/1815 RDMA/ucma: Allow path records to exactly fit the output buffer
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 8049741ac93acd3a590dac070e12571fddf0e294 ]
ucma_query_path() emits a path record only when the remaining output buffer is strictly larger than struct ib_path_rec_data. A buffer sized exactly for the response header and N complete records therefore gets only N - 1 records, while resp->num_paths still advertises N. A caller sizing its buffer for a single record gets a header claiming one path and no path data at all.
ucma_query_ib_service() in the same file computes the record count with a plain division and so accepts an exact fit; make ucma_query_path() behave the same way.
Current librdmacm is unaffected because it always sizes the response for six records while the kernel currently reports at most two paths. Other users of the UAPI that provide an exactly sized buffer can observe the truncated response.
--- drivers/infiniband/core/ucma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/ucma.c +1 -1
@@ -951,7 +951,7 @@ static ssize_t ucma_query_path(struct ucma_context *ctx, resp->num_paths = ctx->cm_id->route.num_pri_alt_paths;for (i =0 , out_len -=sizeof (*resp); - i < resp->num_paths && out_len >sizeof (struct ib_path_rec_data ); + i < resp->num_paths && out_len >=sizeof (struct ib_path_rec_data ); i++, out_len -=sizeof (struct ib_path_rec_data )) {struct sa_path_rec *rec = &ctx->cm_id->route.path_rec[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1658/1815 spi: amlogic-spisg: Make sure clk_init_data is fully initialized
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
[ Upstream commit b2702908ee23ef31bfcf241a2e07ace0eb76bd71 ]
The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled.
aml_spisg_clk_init() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash.
Make sure all members are fully initialized, to fix such bugs, and to avoid future breakage when converting drivers to a different method for specifying the parents.
--- drivers/spi/spi-amlogic-spisg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-amlogic-spisg.c +1 -1
@@ -636,7 +636,7 @@ static int aml_spisg_target_abort(struct spi_controller *ctlr)static int aml_spisg_clk_init (struct spisg_device *spisg,void __iomem *base) {struct device *dev = &spisg->pdev->dev; -struct clk_init_data init; +struct clk_init_data init = {};struct clk_divider *div;struct clk_div_table *tbl;char name[32 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1659/1815 drm/xe: dont WARN on kernel job timeout when device already wedged
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nitin Gote <[email protected]>
[ Upstream commit 13087ad7817e6e5f210064518bfc4d6d58a9c2f3 ]
igt@xe_wedged@wedged-at-any-timeout wedges the device in mode 2 (UPON_ANY_HANG_NO_RESET) and then rebinds the driver. During unbind, a GSC proxy kernel submission can still time out; with the device wedged and the GuC CT stopped it can never complete, so its kernel job times out.
Tile0: GT1: Kernel-submitted job timed out
WARNING: drivers/gpu/drm/xe/xe_guc_submit.c:... at guc_exec_queue_timedout_job() Workqueue: gt-ordered-wq drm_sched_job_timedout
Killed queues skip guc_submit_hint_wedged(), leaving 'wedged' false even though the device is already wedged. The timeout handler then treats the kernel queue timeout as unexpected and taints the kernel.
Honour an already-wedged device even for killed queues so the expected teardown timeout no longer trips the WARN.
--- drivers/gpu/drm/xe/xe_guc_submit.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/xe/xe_guc_submit.c +6 -0
@@ -1537,8 +1537,14 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)if (!skip_timeout_check && !check_timeout (q, job)) goto rearm; +/* +* Killed queues must not newly wedge the device, but preserve an +* already-wedged state to avoid warning on teardown timeouts. +*/ if (!exec_queue_killed (q)) wedged =guc_submit_hint_wedged (exec_queue_to_guc (q)); +else + wedged =xe_device_wedged (xe);set_exec_queue_banned (q);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1660/1815 ALSA: mtpav: shut down output timer before card teardown
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit c73cb5b7c159246dd572277c668851a56e516019 ]
snd_mtpav_output_timer() rearms chip->timer while holding chip->spinlock and accesses the card-private mtpav state.
snd_mtpav_free() currently takes the same lock and calls timer_delete() when the timer is active. This only removes a pending timer; it does not wait for a callback that is already running and does not prevent the callback from rearming the timer.
A callback running on another CPU can therefore continue after snd_mtpav_free() releases the lock and access the card-private state while the card is being torn down. It can also rearm the timer after timer_delete() has returned.
Call timer_shutdown_sync() without holding chip->spinlock. This waits for any running callback to finish and prevents further rearming before the card-private mtpav state is released.
--- sound/drivers/mtpav.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/drivers/mtpav.c +1 -3
@@ -642,9 +642,7 @@ static void snd_mtpav_free(struct snd_card *card) {struct mtpav *crd = card->private_data; -guard (spinlock_irqsave)(&crd->spinlock); -if (crd->istimer >0 ) -snd_mtpav_remove_output_timer (crd); +timer_shutdown_sync (&crd->timer); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1661/1815 smb: server: Remove obsolete "select CRYPTO_LIB_DES" from Kconfig file
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Huth <[email protected]>
[ Upstream commit ed91d80242358ffdf127a34e3b7c9fc445c9e5d1 ]
The DES encryption in the smb server code has been removed in 2021 with the removal of the insecure NTLMv1 authentication code. Thus we don't need this "select" statement here anymore.
--- fs/smb/server/Kconfig | 1 - 1 file changed, 1 deletion(-)
fs/smb/server/Kconfig +0 -1
@@ -9,7 +9,6 @@ config SMB_SERVER select CRYPTO select CRYPTO_LIB_AES_CBC_MACS select CRYPTO_LIB_ARC4 - select CRYPTO_LIB_DES select CRYPTO_LIB_MD5 select CRYPTO_LIB_SHA256 select CRYPTO_LIB_SHA512
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1662/1815 smb: server: remove unused DES crypto header
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit c5e640fe346177372ff4a51a45b01fcd48c29207 ]
The DES crypto header is no longer used after the removal of NTLMv1 authentication. Remove it now that the server no longer selects CRYPTO_LIB_DES.
--- fs/smb/server/auth.c | 1 - 1 file changed, 1 deletion(-)
fs/smb/server/auth.c +0 -1
@@ -24,7 +24,6 @@#include <linux/fips.h> #include <crypto/arc4.h> -#include <crypto/des.h> #include "server.h" #include "smb_common.h"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1663/1815 irqchip/irq-realtek-rtl: Split out parent setup code
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Stockhausen <[email protected]>
[ Upstream commit d36c1d1657113fcf442c50e074593d7b712bada1 ]
The parent interrupt setup will be extended to support multiple parents.
To prepare for that, relocate the code into a separate helper. Although it still works only for a single interrupt prepare the coding so it can be easily extended with a loop for multi parent support. For this reduce the line lengths so that the upcoming indentation still leaves the width below 100 characters.
Stable-dep-of: 58b34b72b64b ("irqchip/irq-realtek-rtl: Use readl_be()/writel_be() instead of readl()/writel()")
--- drivers/irqchip/irq-realtek-rtl.c | 60 +++++++++++++++++-------------- 1 file changed, 33 insertions(+), 27 deletions(-)
drivers/irqchip/irq-realtek-rtl.c +33 -27
@@ -147,48 +147,35 @@ static void realtek_irq_dispatch(struct irq_desc *desc)chained_irq_exit (chip, desc); } -static int __init realtek_rtl_of_init (struct device_node *node,struct device_node *parent) +static int __init realtek_setup_parents (struct device_node *node) { +int parent_irq, num_parents =of_irq_count (node);struct of_phandle_args oirq;struct irq_domain *domain; -int cpu, parent_irq; -for_each_present_cpu (cpu) { - realtek_ictl_base[cpu] =of_iomap (node, cpu); -if (!realtek_ictl_base[cpu]) -return -ENXIO ; - -/* Disable all cascaded interrupts and clear routing */ -for (unsigned int hw_irq =0 ; hw_irq <RTL_ICTL_NUM_INPUTS ; hw_irq++) { -disable_gimr (cpu, hw_irq); -write_irr (cpu, hw_irq,0 ); - } - } - -if (WARN_ON (!of_irq_count (node))) { +if (WARN_ON (!num_parents)) {/* -* If DT contains no parent interrupts, assume MIPS CPU IRQ 2 -* (HW0) is connected to the first output. This is the case for -* all known hardware anyway. "interrupt-map" is deprecated, so -* don't bother trying to parse that. +* If DT contains no parent interrupts, assume MIPS IRQ 2 (HW0) is +* connected to the first output. This is the case for all known hardware. */ - oirq.np =of_find_compatible_node (NULL ,NULL ,"mti,cpu-interrupt-controller" ); + oirq.np =of_find_compatible_node (NULL ,NULL , +"mti,cpu-interrupt-controller" ); +if (!oirq.np) +return -EINVAL ; + oirq.args_count =1 ; oirq.args[0 ] =2 ; - parent_irq =irq_create_of_mapping (&oirq); -of_node_put (oirq.np); }else { parent_irq =of_irq_get (node,0 ); } -if (parent_irq <0 ) -return parent_irq; -else if (!parent_irq) -return -ENODEV ; +if (parent_irq <=0 ) +return parent_irq ? parent_irq : -ENODEV ; - domain =irq_domain_create_linear (of_fwnode_handle (node),RTL_ICTL_NUM_INPUTS , &irq_domain_ops,NULL ); + domain =irq_domain_create_linear (of_fwnode_handle (node),RTL_ICTL_NUM_INPUTS , + &irq_domain_ops,NULL );if (!domain)return -ENOMEM ;
@@ -197,4 +184,23 @@ static int __init realtek_rtl_of_init(struct device_node *node, struct device_noreturn 0 ; } +static int __init realtek_rtl_of_init (struct device_node *node,struct device_node *parent) +{ +unsigned int cpu; + +for_each_present_cpu (cpu) { + realtek_ictl_base[cpu] =of_iomap (node, cpu); +if (!realtek_ictl_base[cpu]) +return -ENXIO ; + +/* Disable all cascaded interrupts and clear routing */ +for (unsigned int hw_irq =0 ; hw_irq <RTL_ICTL_NUM_INPUTS ; hw_irq++) { +disable_gimr (cpu, hw_irq); +write_irr (cpu, hw_irq,0 ); + } + } + +return realtek_setup_parents (node); +} +IRQCHIP_DECLARE (realtek_rtl_intc,"realtek,rtl-intc" , realtek_rtl_of_init);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1664/1815 irqchip/irq-realtek-rtl: Add interrupt data structure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Stockhausen <[email protected]>
[ Upstream commit 2568f6926c667e0b4ecf523cb4015acefc40409a ]
To prepare for multiple parent interrupt domains add an intermediate data structure. For now this will only host the link to the domain. Additionally adapt a deviating variable name to driver standard "hw_irq".
Stable-dep-of: 58b34b72b64b ("irqchip/irq-realtek-rtl: Use readl_be()/writel_be() instead of readl()/writel()")
--- drivers/irqchip/irq-realtek-rtl.c | 48 ++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-)
drivers/irqchip/irq-realtek-rtl.c +34 -14
@@ -25,6 +25,10 @@#define REG (cpu, x) (realtek_ictl_base[cpu] + x) +struct realtek_ictl_output { +struct irq_domain *domain; +}; +static DEFINE_RAW_SPINLOCK (irq_lock);static void __iomem *realtek_ictl_base[NR_CPUS ];
@@ -125,11 +129,11 @@ static const struct irq_domain_ops irq_domain_ops = {static void realtek_irq_dispatch (struct irq_desc *desc) { +struct realtek_ictl_output *output =irq_desc_get_handler_data (desc);struct irq_chip *chip =irq_desc_get_chip (desc);unsigned int cpu =smp_processor_id (); -struct irq_domain *domain;unsigned long pending; -unsigned int soc_int; +unsigned int hw_irq;chained_irq_enter (chip, desc); pending =readl (REG (cpu,RTL_ICTL_GIMR )) &readl (REG (cpu,RTL_ICTL_GISR ));
@@ -139,9 +143,8 @@ static void realtek_irq_dispatch(struct irq_desc *desc) goto out; } - domain =irq_desc_get_handler_data (desc); -for_each_set_bit (soc_int, &pending,RTL_ICTL_NUM_INPUTS ) -generic_handle_domain_irq (domain, soc_int); +for_each_set_bit (hw_irq, &pending,RTL_ICTL_NUM_INPUTS ) +generic_handle_domain_irq (output->domain, hw_irq); out:chained_irq_exit (chip, desc);
@@ -149,10 +152,15 @@ static void realtek_irq_dispatch(struct irq_desc *desc)static int __init realtek_setup_parents (struct device_node *node) { -int parent_irq, num_parents =of_irq_count (node); +int err, parent_irq, num_parents =of_irq_count (node); +struct realtek_ictl_output *output;struct of_phandle_args oirq;struct irq_domain *domain; + output =kcalloc (1 ,sizeof (*output),GFP_KERNEL ); +if (!output) +return -ENOMEM ; +if (WARN_ON (!num_parents)) {/* * If DT contains no parent interrupts, assume MIPS IRQ 2 (HW0) is
@@ -160,8 +168,10 @@ static int __init realtek_setup_parents(struct device_node *node)*/ oirq.np =of_find_compatible_node (NULL ,NULL ,"mti,cpu-interrupt-controller" ); -if (!oirq.np) -return -EINVAL ; +if (!oirq.np) { + err = -EINVAL ; + goto err_out; + } oirq.args_count =1 ; oirq.args[0 ] =2 ;
@@ -171,17 +181,27 @@ static int __init realtek_setup_parents(struct device_node *node) parent_irq =of_irq_get (node,0 ); } -if (parent_irq <=0 ) -return parent_irq ? parent_irq : -ENODEV ; +if (parent_irq <=0 ) { + err = parent_irq ? parent_irq : -ENODEV ; + goto err_out; + } domain =irq_domain_create_linear (of_fwnode_handle (node),RTL_ICTL_NUM_INPUTS , - &irq_domain_ops,NULL ); -if (!domain) -return -ENOMEM ; + &irq_domain_ops, output); +if (!domain) { + err = -ENOMEM ; + goto err_out; + } -irq_set_chained_handler_and_data (parent_irq, realtek_irq_dispatch, domain); + output->domain = domain; +irq_set_chained_handler_and_data (parent_irq, realtek_irq_dispatch, output);return 0 ; + +err_out: +kfree (output); + +return err; }static int __init realtek_rtl_of_init (struct device_node *node,struct device_node *parent)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1665/1815 irqchip/irq-realtek-rtl: Add mask for interrupt handling
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Stockhausen <[email protected]>
[ Upstream commit 2a3fa7f31f43580edcba5ee9f97473801aa3deec ]
When using multiple domains for the Interrupt controller, each one must know which hardware interrupts it serves. Add a mask that is filled during setup and apply it during interrupt handling.
Stable-dep-of: 58b34b72b64b ("irqchip/irq-realtek-rtl: Use readl_be()/writel_be() instead of readl()/writel()")
--- drivers/irqchip/irq-realtek-rtl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/irqchip/irq-realtek-rtl.c +6 -3
@@ -27,6 +27,7 @@struct realtek_ictl_output {struct irq_domain *domain; +u32 mask; };static DEFINE_RAW_SPINLOCK (irq_lock);
@@ -109,15 +110,17 @@ static struct irq_chip realtek_ictl_irq = { .irq_set_affinity = realtek_ictl_irq_affinity, }; -static int intc_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hw) +static int intc_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hw_irq) { +struct realtek_ictl_output *output = d->host_data;unsigned int cpu;irq_set_chip_and_handler (irq, &realtek_ictl_irq, handle_level_irq);guard (raw_spinlock_irqsave)(&irq_lock); + output->mask |=BIT (hw_irq);for_each_present_cpu (cpu) -write_irr (cpu, hw,1 ); +write_irr (cpu, hw_irq,1 );return 0 ; }
@@ -136,7 +139,7 @@ static void realtek_irq_dispatch(struct irq_desc *desc)unsigned int hw_irq;chained_irq_enter (chip, desc); - pending =readl (REG (cpu,RTL_ICTL_GIMR )) &readl (REG (cpu,RTL_ICTL_GISR )); + pending =readl (REG (cpu,RTL_ICTL_GIMR )) &readl (REG (cpu,RTL_ICTL_GISR )) & output->mask;if (unlikely (!pending)) {spurious_interrupt ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1666/1815 irqchip/irq-realtek-rtl: Use readl_be()/writel_be() instead of readl()/writel()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rustam Adilov <[email protected]>
[ Upstream commit 58b34b72b64bfbfc5f8ad4d8f229942aff76597e ]
When CONFIG_SWAP_IO_SPACE is enabled, readl() performs a swap from little endian device to big endian CPU and vice versa for writel().
This is incorrect for Realtek Interrupt controller as that is a big endian device and so the LE to BE conversions are unwanted.
Fix this by converting the MMIO accesses to readl_be() and writel_be().
--- drivers/irqchip/irq-realtek-rtl.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/irqchip/irq-realtek-rtl.c +13 -7
@@ -1,5 +1,10 @@// SPDX-License-Identifier: GPL-2.0-only /* +* Realtek Interrupt controller. +* +* The Realtek Interrupt controller is a big endian device found in the +* Realtek MIPS SoCs. +* * Copyright (C) 2020 Birger Koblitz <[email protected]> * Copyright (C) 2020 Bert Vermeulen <[email protected]> * Copyright (C) 2020 John Crispin <[email protected]>
@@ -46,18 +51,18 @@ static inline void enable_gimr(unsigned int cpu, unsigned int hw_irq) {u32 gimr; - gimr =readl (REG (cpu,RTL_ICTL_GIMR )); + gimr =readl_be (REG (cpu,RTL_ICTL_GIMR )); gimr |=BIT (hw_irq); -writel (gimr,REG (cpu,RTL_ICTL_GIMR )); +writel_be (gimr,REG (cpu,RTL_ICTL_GIMR )); }static inline void disable_gimr (unsigned int cpu,unsigned int hw_irq) {u32 gimr; - gimr =readl (REG (cpu,RTL_ICTL_GIMR )); + gimr =readl_be (REG (cpu,RTL_ICTL_GIMR )); gimr &= ~BIT (hw_irq); -writel (gimr,REG (cpu,RTL_ICTL_GIMR )); +writel_be (gimr,REG (cpu,RTL_ICTL_GIMR )); }static void write_irr (unsigned int cpu,int hw_irq,u32 value)
@@ -67,9 +72,9 @@ static void write_irr(unsigned int cpu, int hw_irq, u32 value)unsigned int shift =IRR_SHIFT (hw_irq);u32 irr; - irr =readl (irr0 + offset) & ~(0xf << shift); + irr =readl_be (irr0 + offset) & ~(0xf << shift); irr |= (value &0xf ) << shift; -writel (irr, irr0 + offset); +writel_be (irr, irr0 + offset); }static void realtek_ictl_unmask_irq (struct irq_data *i)
@@ -139,7 +144,8 @@ static void realtek_irq_dispatch(struct irq_desc *desc)unsigned int hw_irq;chained_irq_enter (chip, desc); - pending =readl (REG (cpu,RTL_ICTL_GIMR )) &readl (REG (cpu,RTL_ICTL_GISR )) & output->mask; + pending =readl_be (REG (cpu,RTL_ICTL_GIMR )) & +readl_be (REG (cpu,RTL_ICTL_GISR )) & output->mask;if (unlikely (!pending)) {spurious_interrupt ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1667/1815 xsk: fix NULL pointer dereference in __xsk_rcv()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit e37b2abca80473e106176e41712a369fd2f72117 ]
In the __xsk_rcv() multi-buffer path, xsk_buff_alloc() is called in a loop without checking its return value. xsk_buff_can_alloc() only counts fill queue entries without validating their addresses, so it can succeed while xsk_buff_alloc() rejects all remaining entries and returns NULL.
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000 KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:__xsk_rcv+0x426/0xc20 (net/xdp/xsk.c:350) Call Trace: xsk_generic_rcv+0x26d/0x5f0 xdp_do_generic_redirect+0x3c5/0xcf0 do_xdp_generic+0x92f/0xe70 __netif_receive_skb_core.constprop.0+0xf7e/0x2b30
Fix this with a two-stage transaction. First allocate and stage all buffers required for the packet, recycling all staged buffers with xsk_buff_free() if any allocation fails. Only after this stage succeeds, copy the data, reserve the RX descriptors, and release the buffers in an error-free loop.
--- net/xdp/xsk.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
net/xdp/xsk.c +27 -3
@@ -298,9 +298,11 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)u32 frame_size =__xsk_pool_get_rx_frame_size (xs->pool);void *copy_from =xsk_copy_xdp_start (xdp), *copy_to;u32 from_len, meta_len, rem, num_desc; -struct xdp_buff_xsk *xskb; +struct xdp_buff_xsk *xskb, *tmp;struct xdp_buff *xsk_xdp; +LIST_HEAD (xsk_buffs);skb_frag_t *frag; +u32 i; from_len = xdp->data_end - copy_from; meta_len = xdp->data - copy_from;
@@ -343,23 +345,45 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len) frag = &sinfo->frags[0 ]; } +for (i =0 ; i < num_desc; i++) { + xsk_xdp =xsk_buff_alloc (xs->pool); +if (!xsk_xdp) + goto err_alloc; + + xskb = container_of(xsk_xdp, struct xdp_buff_xsk, xdp); +if (unlikely (!list_empty (&xskb->list_node))) + goto err_alloc; + +list_add_tail (&xskb->list_node, &xsk_buffs); + } +do {u32 to_len = frame_size + meta_len;u32 copied; - xsk_xdp =xsk_buff_alloc (xs->pool); + xskb = list_first_entry(&xsk_buffs, struct xdp_buff_xsk, + list_node); +list_del_init (&xskb->list_node); + xsk_xdp = &xskb->xdp; copy_to = xsk_xdp->data - meta_len; copied =xsk_copy_xdp (copy_to, ©_from, to_len, &from_len, &frag, rem); rem -= copied; - xskb = container_of(xsk_xdp, struct xdp_buff_xsk, xdp);__xsk_rcv_zc_safe (xs, xskb, copied - meta_len, rem ?XDP_PKT_CONTD :0 ); meta_len =0 ; }while (rem);return 0 ; + +err_alloc: +list_for_each_entry_safe (xskb, tmp, &xsk_buffs, list_node) { +list_del_init (&xskb->list_node); +xsk_buff_free (&xskb->xdp); + } + xs->rx_dropped++; +return -ENOMEM ; }static bool xsk_tx_writeable (struct xdp_sock *xs)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1668/1815 net: bridge: Reject descending VLAN tunnel ranges
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit b74a072d8fb71d3c9ffba4a17d5943e63266fb38 ]
A pair of descending VLAN and tunnel IDs can pass the tunnel range span check. The VLAN subtraction produces a negative int, which is converted to unsigned when compared with the u32 tunnel ID subtraction. It can therefore equal the wrapped tunnel ID delta.
The range loop then performs no iterations. Since the batched notification handling added a post-loop error check, this leaves err uninitialized and makes the request's return value unpredictable.
Reject descending VLAN ranges before comparing the spans. Valid ascending and single-entry ranges remain unchanged, while malformed descending ranges consistently return -EINVAL.
This issue was found by a static analysis checker and confirmed by manual source review.
--- net/bridge/br_netlink_tunnel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/bridge/br_netlink_tunnel.c +2 -1
@@ -302,7 +302,8 @@ int br_process_vlan_tunnel_info(const struct net_bridge *br,if (!(tinfo_last->flags &BRIDGE_VLAN_INFO_RANGE_BEGIN ))return -EINVAL ; -if ((tinfo_curr->vid - tinfo_last->vid) != +if (tinfo_curr->vid < tinfo_last->vid || + (tinfo_curr->vid - tinfo_last->vid) != (tinfo_curr->tunid - tinfo_last->tunid))return -EINVAL ; t = tinfo_last->tunid;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1669/1815 net/sched: add get_fill_size callbacks for actions missing them
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit 8e2efb3f45a5c6f7c8f68685c1c4709040aa2fa0 ]
Several tc actions - act_police, act_bpf, act_pedit, act_ife, act_sample, act_ct, act_ctinfo and act_tunnel_key among them - provide no get_fill_size() callback, so tcf_action_fill_size() falls back to tcf_action_shared_attrs_size() which does not account for the action-specific netlink attributes emitted inside TCA_ACT_OPTIONS by their dump functions.
When an RTM_NEWACTION request with NLM_F_ECHO (or an RTNLGRP_TC listener) creates several actions, tcf_add_notify_msg() allocates the echo skb from this underestimated size. When this happens, the act_api code fails to add all of the fields to the netlink message and, thus, fails to send it. Issue is that, when that happens, this failure doesn't stop the action instances from being added. So any user watching these events will be under the false impression that no actions were created at all.
For example, act_pedit overruns with 32 actions of four munge keys each, act_police with 32 policers once the optional rate/peakrate/result/avrate attributes are present.
To fix this, add the missing get_fill_size callbacks returning the worst-case size of each action's dump attributes, following the pattern used by act_gact/act_skbedit/act_vlan. Also widen the TCA_GACT_TM accounting in tcf_action_shared_attrs_size() to nla_total_size_64bit(), since actions dump their tcf_t with nla_put_64bit(), which may be preceded by an NLA_PAD attribute.
Note: We only provided fixes for the actions we reproduced this bug with as of today. We can send a separate hardening patch for the remaining actions to net-next later. The other pre-existing issues, pointed out by Clashiko [1], will be fixed in upcoming patches.
[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260810164357.1653956-1-victor%40mojatatu.com
--- net/sched/act_api.c | 5 ++- net/sched/act_bpf.c | 26 +++++++++++++ net/sched/act_ct.c | 46 ++++++++++++++++++++++ net/sched/act_ctinfo.c | 11 ++++++ net/sched/act_ife.c | 23 +++++++++++ net/sched/act_pedit.c | 24 ++++++++++++ net/sched/act_police.c | 12 ++++++ net/sched/act_sample.c | 9 +++++ net/sched/act_tunnel_key.c | 80 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 235 insertions(+), 1 deletion(-)
net/sched/act_api.c +4 -1
@@ -452,7 +452,10 @@ static size_t tcf_action_shared_attrs_size(const struct tc_action *act)/* TCA_STATS_QUEUE */ +nla_total_size_64bit (sizeof (struct gnet_stats_queue )) +nla_total_size (0 )/* TCA_ACT_OPTIONS nested */ - +nla_total_size (sizeof (struct tcf_t ));/* TCA_GACT_TM */ +/* TCA_GACT_TM; actions dump their tcf_t with nla_put_64bit(), +* which may emit an extra NLA_PAD attribute. +*/ + +nla_total_size_64bit (sizeof (struct tcf_t )); }static size_t tcf_action_full_attrs_size (size_t sz)
net/sched/act_bpf.c +26 -0
@@ -389,6 +389,31 @@ static void tcf_bpf_cleanup(struct tc_action *act)tcf_bpf_cfg_cleanup (&tmp); } +static size_t tcf_bpf_get_fill_size (const struct tc_action *act) +{ +struct tcf_bpf *prog =to_bpf (act); +size_t size =nla_total_size (sizeof (struct tc_act_bpf )); + +/* bpf_ops and bpf_num_ops are published as separate stores under +* tcf_lock, so take it here as tcf_bpf_dump() does. +*/ +spin_lock_bh (&prog->tcf_lock); +if (tcf_bpf_is_ebpf (prog)) { +/* TCA_ACT_BPF_NAME */ + size +=nla_total_size (ACT_BPF_NAME_LEN +1 ); + size +=nla_total_size (sizeof (u32));/* TCA_ACT_BPF_ID */ + size +=nla_total_size (BPF_TAG_SIZE );/* TCA_ACT_BPF_TAG */ + }else { + size +=nla_total_size (sizeof (u16));/* TCA_ACT_BPF_OPS_LEN */ +/* TCA_ACT_BPF_OPS */ + size +=nla_total_size (prog->bpf_num_ops * +sizeof (struct sock_filter )); + } +spin_unlock_bh (&prog->tcf_lock); + +return size; +} +static struct tc_action_ops act_bpf_ops__read_mostly = { .kind ="bpf" , .id =TCA_ID_BPF ,
@@ -397,6 +422,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = { .dump = tcf_bpf_dump, .cleanup = tcf_bpf_cleanup, .init = tcf_bpf_init, + .get_fill_size = tcf_bpf_get_fill_size, .size = sizeof(struct tcf_bpf), };MODULE_ALIAS_NET_ACT ("bpf" );
net/sched/act_ct.c +46 -0
58 lines not on this page · raw message
net/sched/act_ctinfo.c +11 -0
@@ -356,6 +356,16 @@ static void tcf_ctinfo_cleanup(struct tc_action *a)kfree_rcu (cp, rcu); } +static size_t tcf_ctinfo_get_fill_size (const struct tc_action *act) +{ +return nla_total_size (sizeof (struct tc_ctinfo ))/* TCA_CTINFO_ACT */ + +nla_total_size (sizeof (u16))/* TCA_CTINFO_ZONE */ +/* TCA_CTINFO_PARMS_{DSCP_MASK,DSCP_STATEMASK,CPMARK_MASK} */ + +3 *nla_total_size (sizeof (u32)) +/* TCA_CTINFO_STATS_{DSCP_SET,DSCP_ERROR,CPMARK_SET} */ + +3 *nla_total_size_64bit (sizeof (u64)); +} +static struct tc_action_ops act_ctinfo_ops = { .kind ="ctinfo" , .id =TCA_ID_CTINFO ,
@@ -364,6 +374,7 @@ static struct tc_action_ops act_ctinfo_ops = { .dump = tcf_ctinfo_dump, .init = tcf_ctinfo_init, .cleanup= tcf_ctinfo_cleanup, + .get_fill_size = tcf_ctinfo_get_fill_size, .size = sizeof(struct tcf_ctinfo), };MODULE_ALIAS_NET_ACT ("ctinfo" );
net/sched/act_ife.c +23 -0
@@ -878,6 +878,28 @@ TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb,return tcf_ife_decode (skb, a, res); } +static size_t tcf_ife_get_fill_size (const struct tc_action *act) +{ +struct tcf_ife_info *ife =to_ife (act); +const struct tcf_ife_params *p; +struct tcf_meta_info *e; +size_t size =nla_total_size (sizeof (struct tc_ife ))/* TCA_IFE_PARMS */ + +nla_total_size (ETH_ALEN )/* TCA_IFE_DMAC */ + +nla_total_size (ETH_ALEN )/* TCA_IFE_SMAC */ + +nla_total_size (2 )/* TCA_IFE_TYPE */ + +nla_total_size (0 );/* TCA_IFE_METALST */ + +rcu_read_lock (); + p =rcu_dereference (ife->params); +if (p) { +list_for_each_entry_rcu (e, &p->metalist, metalist) + size +=nla_total_size (sizeof (u32)); + } +rcu_read_unlock (); + +return size; +} +static struct tc_action_ops act_ife_ops = { .kind ="ife" , .id =TCA_ID_IFE ,
@@ -886,6 +908,7 @@ static struct tc_action_ops act_ife_ops = { .dump = tcf_ife_dump, .cleanup = tcf_ife_cleanup, .init = tcf_ife_init, + .get_fill_size = tcf_ife_get_fill_size, .size = sizeof(struct tcf_ife_info), };MODULE_ALIAS_NET_ACT ("ife" );
net/sched/act_pedit.c +24 -0
@@ -626,6 +626,29 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,return 0 ; } +static size_t tcf_pedit_get_fill_size (const struct tc_action *act) +{ +const struct tcf_pedit_parms *parms; +size_t size; + +rcu_read_lock (); + parms =rcu_dereference (to_pedit (act)->parms); + size = nla_total_size(struct_size_t(struct tc_pedit, keys, + parms->tcfp_nkeys)); +if (parms->tcfp_keys_ex) { +/* TCA_PEDIT_KEYS_EX, holding one TCA_PEDIT_KEY_EX nest with a +* HTYPE and a CMD attribute per key. +*/ + size +=nla_total_size (0 ) + + parms->tcfp_nkeys * (nla_total_size (0 ) + +nla_total_size (sizeof (u16)) + +nla_total_size (sizeof (u16))); + } +rcu_read_unlock (); + +return size; +} +static struct tc_action_ops act_pedit_ops = { .kind ="pedit" , .id =TCA_ID_PEDIT ,
@@ -635,6 +658,7 @@ static struct tc_action_ops act_pedit_ops = { .dump = tcf_pedit_dump, .cleanup = tcf_pedit_cleanup, .init = tcf_pedit_init, + .get_fill_size = tcf_pedit_get_fill_size, .offload_act_setup = tcf_pedit_offload_act_setup, .size = sizeof(struct tcf_pedit), };
net/sched/act_police.c +12 -0
@@ -490,6 +490,17 @@ static int tcf_police_offload_act_setup(struct tc_action *act, void *entry_data,return 0 ; } +static size_t tcf_police_get_fill_size (const struct tc_action *act) +{ +return nla_total_size (sizeof (struct tc_police ))/* TCA_POLICE_TBF */ + +nla_total_size_64bit (sizeof (u64))/* TCA_POLICE_RATE64 */ + +nla_total_size_64bit (sizeof (u64))/* TCA_POLICE_PEAKRATE64 */ + +nla_total_size_64bit (sizeof (u64))/* TCA_POLICE_PKTRATE64 */ + +nla_total_size_64bit (sizeof (u64))/* TCA_POLICE_PKTBURST64 */ + +nla_total_size (sizeof (u32))/* TCA_POLICE_RESULT */ + +nla_total_size (sizeof (u32));/* TCA_POLICE_AVRATE */ +} +MODULE_AUTHOR ("Alexey Kuznetsov" );MODULE_DESCRIPTION ("Policing actions" );MODULE_LICENSE ("GPL" );
@@ -503,6 +514,7 @@ static struct tc_action_ops act_police_ops = { .dump = tcf_police_dump, .init = tcf_police_init, .cleanup = tcf_police_cleanup, + .get_fill_size = tcf_police_get_fill_size, .offload_act_setup = tcf_police_offload_act_setup, .size = sizeof(struct tcf_police), };
net/sched/act_sample.c +9 -0
@@ -315,6 +315,14 @@ static int tcf_sample_offload_act_setup(struct tc_action *act, void *entry_data,return 0 ; } +static size_t tcf_sample_get_fill_size (const struct tc_action *act) +{ +return nla_total_size (sizeof (struct tc_sample ))/* TCA_SAMPLE_PARMS */ + +nla_total_size (sizeof (u32))/* TCA_SAMPLE_RATE */ + +nla_total_size (sizeof (u32))/* TCA_SAMPLE_TRUNC_SIZE */ + +nla_total_size (sizeof (u32));/* TCA_SAMPLE_PSAMPLE_GROUP */ +} +static struct tc_action_ops act_sample_ops = { .kind ="sample" , .id =TCA_ID_SAMPLE ,
@@ -324,6 +332,7 @@ static struct tc_action_ops act_sample_ops = { .dump = tcf_sample_dump, .init = tcf_sample_init, .cleanup = tcf_sample_cleanup, + .get_fill_size = tcf_sample_get_fill_size, .get_psample_group = tcf_sample_get_group, .offload_act_setup = tcf_sample_offload_act_setup, .size = sizeof(struct tcf_sample),
net/sched/act_tunnel_key.c +80 -0
92 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1670/1815 net: thunderbolt: Count delivered packets in rx_packets and rx_bytes
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Ye <[email protected]>
[ Upstream commit c5ae83ee02c04487b1be1d143b791ec2caca888e ]
tbnet_poll() increments rx_packets once per received frame because that is the NAPI work unit, and then adds the same number to stats.rx_packets. An skb is handed to the stack only when the last frame of a packet arrives, so once the MTU exceeds TBNET_MAX_PAYLOAD_SIZE the statistic reports frames. tx_packets is bumped once per skb, so the two ends of a link
disagree: at MTU 65330 the receiver reports 16 times the packets its sender sent.
rx_bytes has the matching problem: frames of a packet that is later dropped mid-assembly are already accounted, so it does not correspond to rx_packets as documented. Account for both where the packet is completed, and leave the NAPI work counter alone.
--- drivers/net/thunderbolt/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/thunderbolt/main.c +3 -3
@@ -904,9 +904,11 @@ static int tbnet_poll(struct napi_struct *napi, int budget)le32_to_cpu (net->rx_hdr.frame_count) -1 ; rx_packets++; - net->stats.rx_bytes += frame_size;if (last) { +/* Before eth_type_trans() pulls the Ethernet header. */ + net->stats.rx_packets++; + net->stats.rx_bytes += skb->len; skb->protocol =eth_type_trans (skb, net->dev);trace_tbnet_rx_skb (skb);napi_gro_receive (&net->napi, skb);
@@ -914,8 +916,6 @@ static int tbnet_poll(struct napi_struct *napi, int budget) } } - net->stats.rx_packets += rx_packets; -if (cleaned_count)tbnet_alloc_rx_buffers (net, cleaned_count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1671/1815 net/mlx5: E-Switch, use state lock for vport state changes
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Bloch <[email protected]>
[ Upstream commit ff0f9b7aa1c756e24a8023eaf684e93774c64194 ]
Protect vport admin state modifications and vport iteration with the eswitch state_lock mutex to ensure proper serialization of concurrent vport state changes.
Currently, calls to mlx5_modify_vport_admin_state() and loops iterating over eswitch vports can race with each other, potentially leading to inconsistent vport state. Fix this by acquiring esw->state_lock
--- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 20 ++++++++++++++----- .../mellanox/mlx5/core/esw/adj_vport.c | 2 ++ .../mellanox/mlx5/core/eswitch_offloads.c | 4 ++++ .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 2 ++ .../net/ethernet/mellanox/mlx5/core/vport.c | 8 ++++++++ 5 files changed, 31 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +15 -5
@@ -689,11 +689,13 @@ static int mlx5e_rep_open(struct net_device *dev)if (err) goto unlock; +mutex_lock (&rep->esw->state_lock);if (!mlx5_modify_vport_admin_state (priv->mdev,MLX5_VPORT_STATE_OP_MOD_ESW_VPORT , rep->vport,1 ,MLX5_VPORT_ADMIN_STATE_UP ))netif_carrier_on (dev); +mutex_unlock (&rep->esw->state_lock); unlock:mutex_unlock (&priv->state_lock);
@@ -708,10 +710,12 @@ static int mlx5e_rep_close(struct net_device *dev)int ret;mutex_lock (&priv->state_lock); +mutex_lock (&rep->esw->state_lock);mlx5_modify_vport_admin_state (priv->mdev,MLX5_VPORT_STATE_OP_MOD_ESW_VPORT , rep->vport,1 ,MLX5_VPORT_ADMIN_STATE_DOWN ); +mutex_unlock (&rep->esw->state_lock); ret =mlx5e_close_locked (dev);mutex_unlock (&priv->state_lock);return ret;
@@ -783,22 +787,25 @@ static int mlx5e_rep_change_carrier(struct net_device *dev, bool new_carrier)struct mlx5e_priv *priv =netdev_priv (dev);struct mlx5e_rep_priv *rpriv = priv->ppriv;struct mlx5_eswitch_rep *rep = rpriv->rep; -int err; +int err =0 ; +mutex_lock (&rep->esw->state_lock);if (new_carrier) { err =mlx5_modify_vport_admin_state (priv->mdev,MLX5_VPORT_STATE_OP_MOD_ESW_VPORT , rep->vport,1 ,MLX5_VPORT_ADMIN_STATE_UP );if (err) -return err; + goto unlock;netif_carrier_on (dev); }else { err =mlx5_modify_vport_admin_state (priv->mdev,MLX5_VPORT_STATE_OP_MOD_ESW_VPORT , rep->vport,1 ,MLX5_VPORT_ADMIN_STATE_DOWN );if (err) -return err; + goto unlock;netif_carrier_off (dev); } -return 0 ; +unlock: +mutex_unlock (&rep->esw->state_lock); +return err; }static const struct net_device_ops mlx5e_netdev_ops_rep = {
@@ -1337,9 +1344,12 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)mlx5e_rep_tc_enable (priv); -if (MLX5_CAP_GEN (mdev, uplink_follow)) +if (MLX5_CAP_GEN (mdev, uplink_follow)) { +mutex_lock (&mdev->priv.eswitch->state_lock);mlx5_modify_vport_admin_state (mdev,MLX5_VPORT_STATE_OP_MOD_UPLINK ,0 ,0 ,MLX5_VPORT_ADMIN_STATE_AUTO ); +mutex_unlock (&mdev->priv.eswitch->state_lock); + }mlx5_lag_add_netdev (mdev, netdev); priv->events_nb.notifier_call = uplink_rep_async_event;mlx5_notifier_register (mdev, &priv->events_nb);
drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c +2 -0
@@ -9,6 +9,8 @@ int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport, {u32 in[MLX5_ST_SZ_DW (modify_vport_state_in)] = {}; +lockdep_assert_held (&dev->priv.eswitch->state_lock); +MLX5_SET (modify_vport_state_in, in, opcode,MLX5_CMD_OP_MODIFY_VPORT_STATE ); MLX5_SET(modify_vport_state_in, in, op_mod,
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +4 -0
@@ -2567,6 +2567,7 @@ static void mlx5_esw_fdb_active(struct mlx5_eswitch *esw)mlx5_esw_fdb_drop_destroy (esw);mlx5_mpfs_enable (esw->dev); +mutex_lock (&esw->state_lock);mlx5_esw_for_each_vf_vport (esw, i, vport,U16_MAX ) {if (!vport->adjacent)continue ;
@@ -2574,6 +2575,7 @@ static void mlx5_esw_fdb_active(struct mlx5_eswitch *esw) vport->vport);mlx5_esw_adj_vport_modify (esw->dev, vport->vport, true); } +mutex_unlock (&esw->state_lock); esw->offloads_inactive = false;esw_warn (esw->dev,"MPFS/FDB active\n" );
@@ -2587,6 +2589,7 @@ static void mlx5_esw_fdb_inactive(struct mlx5_eswitch *esw)mlx5_mpfs_disable (esw->dev);mlx5_esw_fdb_drop_create (esw); +mutex_lock (&esw->state_lock);mlx5_esw_for_each_vf_vport (esw, i, vport,U16_MAX ) {if (!vport->adjacent)continue ;
@@ -2595,6 +2598,7 @@ static void mlx5_esw_fdb_inactive(struct mlx5_eswitch *esw)mlx5_esw_adj_vport_modify (esw->dev, vport->vport, false); } +mutex_unlock (&esw->state_lock); esw->offloads_inactive = true;esw_warn (esw->dev,"MPFS/FDB inactive\n" );
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +2 -0
@@ -1471,6 +1471,7 @@ static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,if (!MLX5_CAP_ESW (mdev, esw_vport_state_max_tx_speed))return ; +mutex_lock (&esw->state_lock);mlx5_esw_for_each_vport (esw, i, vport) {if (!vport)continue ;
@@ -1490,6 +1491,7 @@ static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,"Failed to set vport %d speed %d, err=%d\n" , vport->vport, speed, ret); } +mutex_unlock (&esw->state_lock); }void mlx5_lag_set_vports_agg_speed (struct mlx5_lag *ldev)
drivers/net/ethernet/mellanox/mlx5/core/vport.c +8 -0
@@ -89,6 +89,10 @@ int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod, {u32 in[MLX5_ST_SZ_DW (modify_vport_state_in)] = {}; +#ifdef CONFIG_MLX5_ESWITCH +lockdep_assert_held (&mdev->priv.eswitch->state_lock); +#endif +MLX5_SET (modify_vport_state_in, in, opcode,MLX5_CMD_OP_MODIFY_VPORT_STATE );MLX5_SET (modify_vport_state_in, in, op_mod, opmod);
@@ -106,6 +110,10 @@ int mlx5_modify_vport_max_tx_speed(struct mlx5_core_dev *mdev, u8 opmod,u8 admin_state;int err; +#ifdef CONFIG_MLX5_ESWITCH +lockdep_assert_held (&mdev->priv.eswitch->state_lock); +#endif + err =mlx5_query_vport_admin_state (mdev, opmod, vport, other_vport, &admin_state);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1672/1815 net/mlx5: Move vport DOWN state check out of mlx5_query_vport_max_tx_speed()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Or Har-Toov <[email protected]>
[ Upstream commit 20f11b5cfa429ba3a2b8ef463d47e820687b4d2e ]
mlx5_query_vport_max_tx_speed() was introduced to serve the query_port_speed path, which uses max_tx_speed == 0 when port is down.
This is incorrect for callers that need the actual configured speed regardless of vport state, such as modify-vport-state helpers that must preserve the speed across state transitions.
Move this logic to the caller function in the verb flow and let mlx5_query_vport_max_tx_speed() return the raw firmware value unconditionally.
--- drivers/infiniband/hw/mlx5/main.c | 5 +++-- drivers/net/ethernet/mellanox/mlx5/core/vport.c | 12 ++++-------- include/linux/mlx5/vport.h | 3 ++- 3 files changed, 9 insertions(+), 11 deletions(-)
drivers/infiniband/hw/mlx5/main.c +3 -2
@@ -1631,14 +1631,15 @@ static int mlx5_ib_query_port_speed_from_vport(struct mlx5_core_dev *mdev, u32 port_num) {u32 max_tx_speed; +u8 vport_state;int err; err =mlx5_query_vport_max_tx_speed (mdev, op_mod, vport, other_vport, - &max_tx_speed); + &max_tx_speed, &vport_state);if (err)return err; -if (max_tx_speed ==0 ) +if (vport_state ==VPORT_STATE_DOWN || max_tx_speed ==0 )/* Value 0 indicates field not supported, fallback */ return mlx5_ib_query_port_speed_from_port (dev, port_num, speed);
drivers/net/ethernet/mellanox/mlx5/core/vport.c +4 -8
@@ -131,11 +131,11 @@ int mlx5_modify_vport_max_tx_speed(struct mlx5_core_dev *mdev, u8 opmod, }int mlx5_query_vport_max_tx_speed (struct mlx5_core_dev *mdev,u8 op_mod, -u16 vport,u8 other_vport,u32 *max_tx_speed) +u16 vport,u8 other_vport, +u32 *max_tx_speed,u8 *state) {u32 out[MLX5_ST_SZ_DW (query_vport_state_out)] = {};u32 in[MLX5_ST_SZ_DW (query_vport_state_in)] = {}; -u32 state;int err; MLX5_SET(query_vport_state_in, in, opcode,
@@ -148,13 +148,9 @@ int mlx5_query_vport_max_tx_speed(struct mlx5_core_dev *mdev, u8 op_mod,if (err)return err; - state =MLX5_GET (query_vport_state_out, out, state); -if (state ==VPORT_STATE_DOWN ) { - *max_tx_speed =0 ; -return 0 ; - } - *max_tx_speed =MLX5_GET (query_vport_state_out, out, max_tx_speed); +if (state) + *state =MLX5_GET (query_vport_state_out, out, state);return 0 ; }EXPORT_SYMBOL_GPL (mlx5_query_vport_max_tx_speed);
include/linux/mlx5/vport.h +2 -1
@@ -61,7 +61,8 @@ u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport);int mlx5_modify_vport_admin_state (struct mlx5_core_dev *mdev,u8 opmod,u16 vport,u8 other_vport,u8 state);int mlx5_query_vport_max_tx_speed (struct mlx5_core_dev *mdev,u8 op_mod, -u16 vport,u8 other_vport,u32 *max_tx_speed); +u16 vport,u8 other_vport, +u32 *max_tx_speed,u8 *state);int mlx5_modify_vport_max_tx_speed (struct mlx5_core_dev *mdev,u8 opmod,u16 vport,u8 other_vport,u16 max_tx_speed); int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1673/1815 net/mlx5: E-Switch, preserve max tx speed on vport state modification
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Or Har-Toov <[email protected]>
[ Upstream commit ad0ae7aefa7a6ede28a549d8dac87456d87ef6d4 ]
When modifying vport state, the firmware interprets a zero in the max tx speed field as an intentional reset, which can overwrite previously set values. This patch attempts to fix this by querying the current max tx speed from firmware before modifying the vport state and passing it back in the modification command. If the query fails, fall back to the cached agg_max_tx_speed value to avoid inadvertently resetting the speed.
--- .../mellanox/mlx5/core/esw/adj_vport.c | 20 ++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/vport.c | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c +20 -0
@@ -11,6 +11,26 @@ int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport,lockdep_assert_held (&dev->priv.eswitch->state_lock); +if (MLX5_CAP_ESW (dev, esw_vport_state_max_tx_speed)) { +u8 op_mod =MLX5_VPORT_STATE_OP_MOD_ESW_VPORT ; +struct mlx5_vport *esw_vport; +u32 speed =0 ; +int err; + + err =mlx5_query_vport_max_tx_speed (dev, op_mod, vport, + true, &speed,NULL ); +if (err) { + esw_vport =mlx5_eswitch_get_vport (dev->priv.eswitch, + vport); + speed =IS_ERR (esw_vport) ?0 : + esw_vport->agg_max_tx_speed; +mlx5_core_dbg (dev, +"Failed to query vport %d max tx speed, err=%d, using cached %u\n" , + vport, err, speed); + } +MLX5_SET (modify_vport_state_in, in, max_tx_speed, speed); + } +MLX5_SET (modify_vport_state_in, in, opcode,MLX5_CMD_OP_MODIFY_VPORT_STATE ); MLX5_SET(modify_vport_state_in, in, op_mod,
drivers/net/ethernet/mellanox/mlx5/core/vport.c +24 -0
@@ -93,6 +93,30 @@ int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,lockdep_assert_held (&mdev->priv.eswitch->state_lock);#endif +if (MLX5_CAP_ESW (mdev, esw_vport_state_max_tx_speed) && + opmod ==MLX5_VPORT_STATE_OP_MOD_ESW_VPORT && + vport !=MLX5_VPORT_UPLINK ) { +u32 speed =0 ; +int err; + + err =mlx5_query_vport_max_tx_speed (mdev, opmod, vport, + other_vport, &speed,NULL ); +if (err) { +#ifdef CONFIG_MLX5_ESWITCH +struct mlx5_vport *esw_vport; + + esw_vport =mlx5_eswitch_get_vport (mdev->priv.eswitch, + vport); + speed =IS_ERR (esw_vport) ?0 : + esw_vport->agg_max_tx_speed; +#endif +mlx5_core_dbg (mdev, +"Failed to query vport %d max tx speed, err=%d, using cached %u\n" , + vport, err, speed); + } +MLX5_SET (modify_vport_state_in, in, max_tx_speed, speed); + } +MLX5_SET (modify_vport_state_in, in, opcode,MLX5_CMD_OP_MODIFY_VPORT_STATE );MLX5_SET (modify_vport_state_in, in, op_mod, opmod);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1674/1815 forcedeth: stop the tx_timeout register dump past the requested window
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Czernohous <[email protected]>
[ Upstream commit cfa9178ce2e5b4f2e2a9e8b577a6cff841665aa0 ]
nv_tx_timeout() dumps the register window in rows of eight dwords:
for (i = 0; i <= np->register_size; i += 32) {
netdev_info(dev, "%3x: %08x ... %08x\n", i,
readl(base + i + 0), ..., readl(base + i + 28));The loop bound only checks the row's starting offset, so the final row reads a full 32 bytes from a position that is below the end of the window but too close to it. base is mapped with exactly that length:
np->base = ioremap(addr, np->register_size);
so the tail of that row is read from beyond the length the driver asked for. Per variant, the last iteration reads past register_size by:
NV_PCI_REGSZ_VER1 (0x270): row 0x260 reads to 0x27f, 16 bytes over NV_PCI_REGSZ_VER2 (0x2d4): row 0x2c0 reads to 0x2df, 12 bytes over NV_PCI_REGSZ_VER3 (0x604): row 0x600 reads to 0x61f, 28 bytes over
This happens on every supported device, not just one of them. Note that it is not a consequence of the sizes being odd: with i <= register_size the offending row is reached whatever the size, and a size that were a multiple of 32 would overrun by a full row rather than by a remainder.
To be precise about the severity: the reads stay inside the BAR. Memory BAR sizes are powers of two, the driver only accepts a region with pci_resource_len() >= register_size (forcedeth.c:5757-5762), and the next power of two at or above each register_size already covers the offending row: 0x400 for 0x270 and 0x2d4, 0x800 for 0x604. ioremap() also rounds the mapped length up to page granularity, so the reads land inside the mapping the CPU has as well. What they leave is the window the driver asked for, not the BAR and not the mapping. That is still a driver reading registers it did not ask for, and it is trivial to avoid, but nobody should expect a fault from it.
Changing <= to < is not enough: register_size is a length and every size above is larger than its last row start, so i still reaches the offending row. Check that the whole row fits instead.
The trade-off is that a partial trailing row is no longer dumped: 16 bytes for VER1, 20 for VER2, 4 for VER3. That seemed preferable to reading outside the requested window, and to open-coding a second, narrower dump for the remainder in what is a debug-only path. Extending the dump to cover the tail can be done on top if anyone misses those registers.
Only reachable with the debug_tx_timeout module parameter, which defaults to false. It has not been observed at runtime: forcing a genuine TX timeout on the reference machine is not something I can do safely, so this rests on the arithmetic above and on a build test, not on a reproduction. UBSAN does not catch it either, since these are MMIO reads rather than an array access. It was found by reading the function while fixing the saved_config_space off-by-one in nv_suspend() and nv_resume().
The dump was introduced with a fixed 0x400 bound while ioremap() mapped only NV_PCI_REGSZ (0x270), so it read about 0x190 bytes too far from the start. Commit 86a0f04387bf ("[PATCH] forcedeth: fix initialization") later replaced 0x400 with np->register_size, which shrank the overrun to the remainder but did not remove it.
--- drivers/net/ethernet/nvidia/forcedeth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/nvidia/forcedeth.c +1 -1
@@ -2740,7 +2740,7 @@ static void nv_tx_timeout(struct net_device *dev, unsigned int txqueue)netdev_info (dev,"Ring at %lx\n" , (unsigned long )np->ring_addr);netdev_info (dev,"Dumping tx registers\n" ); -for (i =0 ; i <= np->register_size; i +=32 ) { +for (i =0 ; i +32 <= np->register_size; i +=32 ) { netdev_info(dev, "%3x: %08x %08x %08x %08x " "%08x %08x %08x %08x\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1675/1815 net: ipa: balance runtime PM reference on remove error
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 6b9eaa61ff2df63c6eb35d5cd025e2cef0861d76 ]
ipa_remove() takes a runtime PM reference before accessing IPA hardware during teardown. If a concurrent modem start or stop keeps ipa_modem_stop() busy across both attempts, the callback intentionally returns without releasing the remaining resources because proceeding with teardown could crash. That return also skips the matching pm_runtime_put_noidle(), leaving the callback's usage-count reference held.
Drop only this runtime PM reference before returning. pm_runtime_put_noidle() does not request an idle transition, so the hardware and resources retained on this exceptional path remain untouched while the usage count stays balanced.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/net/ipa/ipa_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ipa/ipa_main.c +3 -3
@@ -969,12 +969,12 @@ static void ipa_remove(struct platform_device *pdev) }if (ret) {/* -* Not cleaning up here properly might also yield a -* crash later on. As the device is still unregistered -* in this case, this might even yield a crash later on. +* Continuing teardown after failing to stop the modem +* could crash, so leave the remaining resources allocated. */ dev_err (dev,"Failed to stop modem (%pe), leaking resources\n" ,ERR_PTR (ret)); +pm_runtime_put_noidle (dev);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1676/1815 netdevsim: update queue NAPI association on queue reset
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 07e98a4d5e9c292eae97c9cc5ab0937384e48492 ]
In netdevsim, receive queues (struct nsim_rq) embed their own struct napi_struct. When queue reset is performed (e.g. via queue_reset debugfs), nsim_queue_start() swaps in a newly allocated struct nsim_rq, and nsim_queue_mem_free() later deletes and frees the old one.
However, nsim_queue_start() failed to update the queue-to-NAPI mapping via netif_queue_set_napi(). As a result, dev->_rx[idx].napi continued to point to the old NAPI struct. After the old queue was freed, a subsequent queue dump via Netlink (NETDEV_CMD_QUEUE_GET) triggered a KASAN slab-use-after-free read in nla_put_napi_id() when accessing rxq->napi->napi_id.
Fix this by calling netif_queue_set_napi() in nsim_queue_start() to associate the new NAPI with the RX queue, and clear the association with netif_queue_set_napi(..., NULL) in nsim_del_napi() during teardown.
--- drivers/net/netdevsim/netdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/netdevsim/netdev.c +2 -0
@@ -529,6 +529,7 @@ static void nsim_del_napi(struct netdevsim *ns)for (i =0 ; i < dev->num_rx_queues; i++) {struct nsim_rq *rq = ns->rq[i]; +netif_queue_set_napi (dev, i,NETDEV_QUEUE_TYPE_RX ,NULL );napi_disable_locked (&rq->napi);__netif_napi_del_locked (&rq->napi); }
@@ -826,6 +827,7 @@ nsim_queue_start(struct net_device *dev, struct netdev_queue_config *qcfg, } ns->rq[idx] = qmem->rq; +netif_queue_set_napi (dev, idx,NETDEV_QUEUE_TYPE_RX , &ns->rq[idx]->napi);napi_enable_locked (&ns->rq[idx]->napi);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1677/1815 ipv6: avoid divide by zero in rt6_multipath_rebalance
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit d2c26c2911dd1a363c488add4fb63eb5f0f28f87 ]
rt6_multipath_rebalance() calculates the total eligible nexthop weight in one pass and programs upper bounds in a second pass. Since RTM_NEWROUTE is RTNL-free, a concurrent ignore_routes_with_linkdown update can make the first pass return zero while the second sees an eligible nexthop, causing rt6_upper_bound_set() to divide by zero.
UBSAN: division-overflow in net/ipv6/route.c:4845:17 Oops: divide error: 0000 [#1] SMP KASAN NOPTI rt6_upper_bound_set() net/ipv6/route.c:4845 rt6_multipath_rebalance() fib6_add_rt2node() ip6_route_multipath_add() inet6_rtm_newroute()
Skip upper-bound calculation when the first pass reports a zero total. This respects the lock-free performance considerations here and solves insecure scenarios.
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -4840,7 +4840,7 @@ static void rt6_upper_bound_set(struct fib6_info *rt, int *weight, int total) {int upper_bound =-1 ; -if (!rt6_is_dead (rt)) { +if (total && !rt6_is_dead (rt)) { *weight += rt->fib6_nh->fib_nh_weight; upper_bound =DIV_ROUND_CLOSEST_ULL ((u64) (*weight) <<31 , total) -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1678/1815 net: add missing ref_tracker_dir_exit() to net_passive_dec()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
[ Upstream commit f85dc137aabf357bf3d9fe4c9712121039d83798 ]
I found that trying to read /sys/kernel/debug/ref_tracker/* causes NULL pointer dereference crash when alloc_netdev_mqs() via unshare() returned NULL, for commit 9ba74e6c9e9d ("net: add networking namespace refcount tracker") added ref_tracker_dir_exit(&net->refcnt_tracker) to only __put_net() path whereas commit 65b584f53611 ("ref_tracker: automatically register a file in debugfs for a ref_tracker_dir") added ref_tracker_dir_debugfs() to ref_tracker_dir_init() path.
Since preinit_net() calls ref_tracker_dir_init(&net->refcnt_tracker) and ref_tracker_dir_init(&net->notrefcnt_tracker), we need to make sure that both ref_tracker_dir_exit(&net->refcnt_tracker) and ref_tracker_dir_exit(&net->notrefcnt_tracker) are called before net_passive_dec() schedules for kmem_cache_free() via net_complete_free().
ref_tracker_dir_exit(&net->refcnt_tracker) is called via put_net() when ns_ref_put() returned true. But put_net() is not called when copy_net_ns() fails. Therefore, call ref_tracker_dir_exit() from net_passive_dec() if put_net() is not yet called.
--- net/core/net_namespace.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/net_namespace.c +4 -0
@@ -532,8 +532,12 @@ void net_passive_dec(struct net *net)if (refcount_dec_and_test (&net->passive)) {kfree (rcu_access_pointer (net->gen)); +#ifdef CONFIG_REF_TRACKER /* There should not be any trackers left there. */ ref_tracker_dir_exit (&net->notrefcnt_tracker); +if (!net->refcnt_tracker.dead) +ref_tracker_dir_exit (&net->refcnt_tracker); +#endif /* Wait for an extra rcu_barrier() before final free. */ llist_add (&net->defer_free_list, &defer_free_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1679/1815 net: qlcnic: validate unified ROM sections before loading
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 5e8076e4e4124dae75a3e080ddc20404700d7585 ]
The unified ROM parser reads directory, product, and data-descriptor fields from the firmware file. Existing validation forms table and data ends with unchecked additions and multiplications. Malformed values can wrap before they are compared with the firmware size. The parser also dereferences typed pointers at firmware-controlled offsets.
Valid descriptor extents alone are insufficient for the consumers. The loader reads a fixed-size bootloader regardless of its declared size, the version parser assumes a 17-byte tail, and a partial final firmware word is read as a full u64. A truncated image can therefore make the driver read beyond the firmware allocation during validation or loading.
Replace the pointer-returning parser with bounded range helpers. Validate table entry sizes, descriptor indices, section ranges, the fixed bootloader load length, and the version tail before exposing any section. Read all file fields with unaligned little-endian accessors and assemble a partial final word from only the bytes that remain. Apply the same range checks to the legacy image before reading its fixed fields.
--- .../net/ethernet/qlogic/qlcnic/qlcnic_init.c | 445 ++++++++++-------- 1 file changed, 248 insertions(+), 197 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_init.c +248 -197
@@ -6,6 +6,7 @@#include "qlcnic.h" #include "qlcnic_hw.h" +#include <linux/unaligned.h> struct crb_addr_pair {u32 addr;
@@ -740,159 +741,212 @@ qlcnic_has_mn(struct qlcnic_adapter *adapter)return 0 ; } -static -struct uni_table_desc *qlcnic_get_table_desc (const u8 *unirom,int section) -{ -u32 i, entries; -struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0 ]; - entries =le32_to_cpu (directory->num_entries); - -for (i =0 ; i < entries; i++) { +#define FILEHEADER_SIZE (14 * 4) +#define QLCNIC_UNI_DIR_TYPE_OFF (8 * sizeof(__le32)) +#define QLCNIC_UNI_DIR_ENTRY_MIN_SIZE (9 * sizeof(__le32)) +#define QLCNIC_UNI_PRODUCT_ENTRY_MIN_SIZE \ + ((QLCNIC_UNI_FIRMWARE_IDX_OFF + 1) * sizeof(__le32)) +#define QLCNIC_UNI_VERSION_TAIL_SIZE 17 +#define QLCNIC_UNI_BOOTLD_SIZE \ + (QLCNIC_IMAGE_START - QLCNIC_BOOTLD_START) + +struct qlcnic_uni_data { +u32 offset; +u32 size; +}; -u32 offs =le32_to_cpu (directory->findex) + - i *le32_to_cpu (directory->entry_size); -u32 tab_type =le32_to_cpu (*((__le32 *)&unirom[offs] +8 )); +static bool qlcnic_rom_range_valid (size_t size,size_t offset,size_t len) +{ +return offset <= size && len <= size - offset; +} -if (tab_type == section) -return (struct uni_table_desc *) &unirom[offs]; - } +static bool qlcnic_rom_table_valid (size_t size,u32 offset,u32 entries, +u32 entry_size,u32 min_entry_size) +{ +if (entry_size < min_entry_size || offset > size) +return false; -return NULL ; +return entries <= (size - offset) / entry_size; } -#define FILEHEADER_SIZE (14 * 4) - -static int -qlcnic_validate_header (struct qlcnic_adapter *adapter) +static int qlcnic_get_directory (struct qlcnic_adapter *adapter, +size_t *offset,u32 *entries,u32 *entry_size) { -const u8 *unirom = adapter->fw->data; -struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0 ]; -u32 entries, entry_size, tab_size, fw_file_size; - - fw_file_size = adapter->fw->size; +const struct firmware *fw = adapter->fw; +const u8 *directory = fw->data; -if (fw_file_size <FILEHEADER_SIZE ) +if (fw->size <FILEHEADER_SIZE )return -EINVAL ; - entries =le32_to_cpu (directory->num_entries); - entry_size =le32_to_cpu (directory->entry_size); - tab_size =le32_to_cpu (directory->findex) + (entries * entry_size); + *offset =get_unaligned_le32 (directory + + offsetof(struct uni_table_desc , findex)); + *entries =get_unaligned_le32 (directory + + offsetof(struct uni_table_desc , num_entries)); + *entry_size =get_unaligned_le32 (directory + + offsetof(struct uni_table_desc , entry_size)); -if (fw_file_size < tab_size) +if (!qlcnic_rom_table_valid (fw->size, *offset, *entries, *entry_size, +QLCNIC_UNI_DIR_ENTRY_MIN_SIZE ))return -EINVAL ;return 0 ; } -static int -qlcnic_validate_bootld (struct qlcnic_adapter *adapter) +static int qlcnic_get_table_desc (struct qlcnic_adapter *adapter,int section, +size_t *desc_offset) { -struct uni_table_desc *tab_desc; -struct uni_data_desc *descr; -u32 offs, tab_size, data_size, idx;const u8 *unirom = adapter->fw->data; -__le32 temp; - - temp = *((__le32 *)&unirom[adapter->file_prd_off] + -QLCNIC_UNI_BOOTLD_IDX_OFF ); - idx =le32_to_cpu (temp); - tab_desc =qlcnic_get_table_desc (unirom,QLCNIC_UNI_DIR_SECT_BOOTLD ); - -if (!tab_desc) -return -EINVAL ; - - tab_size =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * (idx +1 ); - -if (adapter->fw->size < tab_size) -return -EINVAL ; +size_t directory_offset; +u32 entries, entry_size; +size_t i; +int ret; - offs =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * idx; - descr = (struct uni_data_desc *)&unirom[offs]; + ret =qlcnic_get_directory (adapter, &directory_offset, &entries, + &entry_size); +if (ret) +return ret; - data_size =le32_to_cpu (descr->findex) +le32_to_cpu (descr->size); +for (i =0 ; i < entries; i++) { +size_t offset = directory_offset + i * entry_size; +u32 table_type; -if (adapter->fw->size < data_size) -return -EINVAL ; + table_type =get_unaligned_le32 (unirom + offset + +QLCNIC_UNI_DIR_TYPE_OFF ); +if (table_type == section) { + *desc_offset = offset; +return 0 ; + } + } -return 0 ; +return -ENOENT ; }static int -qlcnic_validate_fw (struct qlcnic_adapter *adapter) +qlcnic_validate_header (struct qlcnic_adapter *adapter) { -struct uni_table_desc *tab_desc; -struct uni_data_desc *descr; -const u8 *unirom = adapter->fw->data; -u32 offs, tab_size, data_size, idx; -__le32 temp; +u32 entries, entry_size; +size_t offset; + +return qlcnic_get_directory (adapter, &offset, &entries, &entry_size); +} - temp = *((__le32 *)&unirom[adapter->file_prd_off] + -QLCNIC_UNI_FIRMWARE_IDX_OFF ); - idx =le32_to_cpu (temp); - tab_desc =qlcnic_get_table_desc (unirom,QLCNIC_UNI_DIR_SECT_FW ); +static int qlcnic_get_data_desc (struct qlcnic_adapter *adapter,u32 section, +u32 index_offset,struct qlcnic_uni_data *data) +{ +size_t table_desc_offset, table_offset, desc_offset; +const struct firmware *fw = adapter->fw; +const u8 *unirom = fw->data; +size_t product_index_offset; +u32 entries, entry_size, idx; +int ret; -if (!tab_desc) + product_index_offset = adapter->file_prd_off + + (size_t )index_offset *sizeof (__le32); +if (!qlcnic_rom_range_valid (fw->size, product_index_offset, +sizeof (__le32)))return -EINVAL ; - tab_size =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * (idx +1 ); + idx =get_unaligned_le32 (unirom + product_index_offset); + ret =qlcnic_get_table_desc (adapter, section, &table_desc_offset); +if (ret) +return ret; -if (adapter->fw->size < tab_size) + table_offset =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , findex)); + entries =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , num_entries)); + entry_size =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , entry_size)); +if (!qlcnic_rom_table_valid (fw->size, table_offset, entries, + entry_size,sizeof (struct uni_data_desc )) || + idx >= entries)return -EINVAL ; - offs =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * idx; - descr = (struct uni_data_desc *)&unirom[offs]; - data_size =le32_to_cpu (descr->findex) +le32_to_cpu (descr->size); + desc_offset = table_offset + (size_t )idx * entry_size; + data->offset =get_unaligned_le32 (unirom + desc_offset + + offsetof(struct uni_data_desc , findex)); + data->size =get_unaligned_le32 (unirom + desc_offset + + offsetof(struct uni_data_desc , size)); -if (adapter->fw->size < data_size) +if (!qlcnic_rom_range_valid (fw->size, data->offset, data->size))return -EINVAL ;return 0 ; } +static int qlcnic_validate_bootld (struct qlcnic_adapter *adapter) +{ +struct qlcnic_uni_data data; +int ret; + + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_BOOTLD , +QLCNIC_UNI_BOOTLD_IDX_OFF , &data); +if (ret) +return ret; + +return data.size <QLCNIC_UNI_BOOTLD_SIZE ? -EINVAL :0 ; +} + +static int qlcnic_validate_fw (struct qlcnic_adapter *adapter) +{ +struct qlcnic_uni_data data; +int ret; + + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , +QLCNIC_UNI_FIRMWARE_IDX_OFF , &data); +if (ret) +return ret; + +return data.size <QLCNIC_UNI_VERSION_TAIL_SIZE ? -EINVAL :0 ; +} +static int qlcnic_validate_product_offs (struct qlcnic_adapter *adapter) { -struct uni_table_desc *ptab_descr; +size_t table_desc_offset, table_offset;const u8 *unirom = adapter->fw->data;int mn_present =qlcnic_has_mn (adapter); -u32 entries, entry_size, tab_size, i; -__le32 temp; - - ptab_descr =qlcnic_get_table_desc (unirom, -QLCNIC_UNI_DIR_SECT_PRODUCT_TBL ); -if (!ptab_descr) -return -EINVAL ; +u32 entries, entry_size; +size_t i; +int ret; - entries =le32_to_cpu (ptab_descr->num_entries); - entry_size =le32_to_cpu (ptab_descr->entry_size); - tab_size =le32_to_cpu (ptab_descr->findex) + (entries * entry_size); + ret =qlcnic_get_table_desc (adapter,QLCNIC_UNI_DIR_SECT_PRODUCT_TBL , + &table_desc_offset); +if (ret) +return ret; -if (adapter->fw->size < tab_size) + table_offset =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , findex)); + entries =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , num_entries)); + entry_size =get_unaligned_le32 (unirom + table_desc_offset + + offsetof(struct uni_table_desc , entry_size)); +if (!qlcnic_rom_table_valid (adapter->fw->size, table_offset, entries, + entry_size, +QLCNIC_UNI_PRODUCT_ENTRY_MIN_SIZE ))return -EINVAL ; nomn:for (i =0 ; i < entries; i++) { - -u32 flags, file_chiprev, offs; +size_t offset = table_offset + i * entry_size;u8 chiprev = adapter->ahw->revision_id; +u32 flags, file_chiprev;u32 flagbit; - offs =le32_to_cpu (ptab_descr->findex) + - i *le32_to_cpu (ptab_descr->entry_size); - temp = *((__le32 *)&unirom[offs] +QLCNIC_UNI_FLAGS_OFF ); - flags =le32_to_cpu (temp); - temp = *((__le32 *)&unirom[offs] +QLCNIC_UNI_CHIP_REV_OFF ); - file_chiprev =le32_to_cpu (temp); + flags =get_unaligned_le32 (unirom + offset + +QLCNIC_UNI_FLAGS_OFF *sizeof (__le32)); + file_chiprev =get_unaligned_le32 (unirom + offset + +QLCNIC_UNI_CHIP_REV_OFF * +sizeof (__le32)); flagbit = mn_present ?1 :2 ;if ((chiprev == file_chiprev) && ((1ULL << flagbit) & flags)) { - adapter->file_prd_off = offs; +if (offset >U32_MAX ) +return -EINVAL ; + + adapter->file_prd_off = offset;return 0 ; } }
@@ -933,93 +987,81 @@ qlcnic_validate_unified_romimage(struct qlcnic_adapter *adapter)return 0 ; } -static -struct uni_data_desc *qlcnic_get_data_desc (struct qlcnic_adapter *adapter, -u32 section,u32 idx_offset) -{ -const u8 *unirom = adapter->fw->data; -struct uni_table_desc *tab_desc; -u32 offs, idx; -__le32 temp; - - temp = *((__le32 *)&unirom[adapter->file_prd_off] + idx_offset); - idx =le32_to_cpu (temp); - - tab_desc =qlcnic_get_table_desc (unirom, section); - -if (tab_desc ==NULL ) -return NULL ; - - offs =le32_to_cpu (tab_desc->findex) + -le32_to_cpu (tab_desc->entry_size) * idx; - -return (struct uni_data_desc *)&unirom[offs]; -} - -static u8 * -qlcnic_get_bootld_offs (struct qlcnic_adapter *adapter) +static int qlcnic_get_bootld_data (struct qlcnic_adapter *adapter, +const u8 **bootld) {u32 offs =QLCNIC_BOOTLD_START ; -struct uni_data_desc *data_desc; - - data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_BOOTLD , -QLCNIC_UNI_BOOTLD_IDX_OFF ); +struct qlcnic_uni_data data; +int ret; -if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) - offs =le32_to_cpu (data_desc->findex); +if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) { + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_BOOTLD , +QLCNIC_UNI_BOOTLD_IDX_OFF , &data); +if (ret || data.size <QLCNIC_UNI_BOOTLD_SIZE ) +return -EINVAL ; + offs = data.offset; + }else if (!qlcnic_rom_range_valid (adapter->fw->size, offs, +QLCNIC_UNI_BOOTLD_SIZE )) { +return -EINVAL ; + } -return (u8 *)&adapter->fw->data[offs]; + *bootld = adapter->fw->data + offs; +return 0 ; } -static u8 * -qlcnic_get_fw_offs (struct qlcnic_adapter *adapter) +static int qlcnic_get_fw_data (struct qlcnic_adapter *adapter, +const u8 **image,u32 *image_size) {u32 offs =QLCNIC_IMAGE_START ; -struct uni_data_desc *data_desc; - - data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , -QLCNIC_UNI_FIRMWARE_IDX_OFF ); -if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) - offs =le32_to_cpu (data_desc->findex); - -return (u8 *)&adapter->fw->data[offs]; -} +struct qlcnic_uni_data data; +int ret; -static u32 qlcnic_get_fw_size (struct qlcnic_adapter *adapter) -{ -struct uni_data_desc *data_desc; -const u8 *unirom = adapter->fw->data; +if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) { + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , +QLCNIC_UNI_FIRMWARE_IDX_OFF , &data); +if (ret) +return ret; + offs = data.offset; + *image_size = data.size; + }else { +if (!qlcnic_rom_range_valid (adapter->fw->size, +QLCNIC_FW_SIZE_OFFSET , +sizeof (__le32))) +return -EINVAL ; + *image_size =get_unaligned_le32 (adapter->fw->data + +QLCNIC_FW_SIZE_OFFSET ); + } - data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , -QLCNIC_UNI_FIRMWARE_IDX_OFF ); +if (!qlcnic_rom_range_valid (adapter->fw->size, offs, *image_size)) +return -EINVAL ; -if (adapter->ahw->fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) -return le32_to_cpu (data_desc->size); -else -return le32_to_cpu (*(__le32 *)&unirom[QLCNIC_FW_SIZE_OFFSET ]); + *image = adapter->fw->data + offs; +return 0 ; }static u32 qlcnic_get_fw_version (struct qlcnic_adapter *adapter) { -struct uni_data_desc *fw_data_desc; +char ver_str[QLCNIC_UNI_VERSION_TAIL_SIZE +1 ];const struct firmware *fw = adapter->fw; +struct qlcnic_uni_data data;u32 major, minor, sub; -__le32 version_offset; -const u8 *ver_str;int i, ret; -if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) { - version_offset = *(__le32 *)&fw->data[QLCNIC_FW_VERSION_OFFSET ]; -return le32_to_cpu (version_offset); - } +if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) +return get_unaligned_le32 (fw->data +QLCNIC_FW_VERSION_OFFSET ); + + ret =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , +QLCNIC_UNI_FIRMWARE_IDX_OFF , &data); +if (ret || data.size <QLCNIC_UNI_VERSION_TAIL_SIZE ) +return 0 ; - fw_data_desc =qlcnic_get_data_desc (adapter,QLCNIC_UNI_DIR_SECT_FW , -QLCNIC_UNI_FIRMWARE_IDX_OFF ); - ver_str = fw->data +le32_to_cpu (fw_data_desc->findex) + -le32_to_cpu (fw_data_desc->size) -17 ; +memcpy (ver_str, fw->data + data.offset + data.size - +QLCNIC_UNI_VERSION_TAIL_SIZE , +QLCNIC_UNI_VERSION_TAIL_SIZE ); + ver_str[QLCNIC_UNI_VERSION_TAIL_SIZE ] ='\0' ;for (i =0 ; i <12 ; i++) { -if (!strncmp (&ver_str[i],"REV=" ,4 )) { +if (!strncmp (ver_str + i,"REV=" ,4 )) { ret =sscanf (&ver_str[i+4 ],"%u.%u.%u " , &major, &minor, &sub);if (ret !=3 )
@@ -1034,18 +1076,15 @@ static u32 qlcnic_get_fw_version(struct qlcnic_adapter *adapter)static u32 qlcnic_get_bios_version (struct qlcnic_adapter *adapter) { -const struct firmware *fw = adapter->fw;u32 bios_ver, prd_off = adapter->file_prd_off; -u8 *version_offset; -__le32 temp; +const struct firmware *fw = adapter->fw; -if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) { - version_offset = (u8 *)&fw->data[QLCNIC_BIOS_VERSION_OFFSET ]; -return le32_to_cpu (*(__le32 *)version_offset); - } +if (adapter->ahw->fw_type !=QLCNIC_UNIFIED_ROMIMAGE ) +return get_unaligned_le32 (fw->data +QLCNIC_BIOS_VERSION_OFFSET ); - temp = *((__le32 *)(&fw->data[prd_off]) +QLCNIC_UNI_BIOS_VERSION_OFF ); - bios_ver =le32_to_cpu (temp); + bios_ver =get_unaligned_le32 (fw->data + prd_off + +QLCNIC_UNI_BIOS_VERSION_OFF * +sizeof (__le32));return (bios_ver <<16 ) + ((bios_ver >>8 ) &0xff00 ) + (bios_ver >>24 ); }
@@ -1106,24 +1145,26 @@ static const char *fw_name[] = {int qlcnic_load_firmware (struct qlcnic_adapter *adapter) { -__le64 *ptr64; -u32 i, flashaddr, size;const struct firmware *fw = adapter->fw;struct pci_dev *pdev = adapter->pdev; +const u8 *bootld, *image; +u32 i, flashaddr, image_size; +int ret;dev_info (&pdev->dev,"loading firmware from %s\n" , fw_name[adapter->ahw->fw_type]);if (fw) { +u32 words, remainder;u64 data; - size = (QLCNIC_IMAGE_START -QLCNIC_BOOTLD_START ) /8 ; - - ptr64 = (__le64 *)qlcnic_get_bootld_offs (adapter); + ret =qlcnic_get_bootld_data (adapter, &bootld); +if (ret) +return ret; flashaddr =QLCNIC_BOOTLD_START ; -for (i =0 ; i < size; i++) { - data =le64_to_cpu (ptr64[i]); +for (i =0 ; i <QLCNIC_UNI_BOOTLD_SIZE /sizeof (u64); i++) { + data =get_unaligned_le64 (bootld + i *sizeof (u64));if (qlcnic_pci_mem_write_2M (adapter, flashaddr, data))return -EIO ;
@@ -1131,13 +1172,15 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter) flashaddr +=8 ; } - size =qlcnic_get_fw_size (adapter) /8 ; - - ptr64 = (__le64 *)qlcnic_get_fw_offs (adapter); + ret =qlcnic_get_fw_data (adapter, &image, &image_size); +if (ret) +return ret; + words = image_size /sizeof (u64); + remainder = image_size %sizeof (u64); flashaddr =QLCNIC_IMAGE_START ; -for (i =0 ; i < size; i++) { - data =le64_to_cpu (ptr64[i]); +for (i =0 ; i < words; i++) { + data =get_unaligned_le64 (image + i *sizeof (u64));if (qlcnic_pci_mem_write_2M (adapter, flashaddr, data))
@@ -1146,9 +1189,11 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter) flashaddr +=8 ; } - size =qlcnic_get_fw_size (adapter) %8 ; -if (size) { - data =le64_to_cpu (ptr64[i]); +if (remainder) { +__le64 tail =0 ; + +memcpy (&tail, image + words *sizeof (u64), remainder); + data =le64_to_cpu (tail);if (qlcnic_pci_mem_write_2M (adapter, flashaddr, data))
@@ -1156,10 +1201,9 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter) } }else { -u64 data; -u32 hi, lo; -int ret;struct qlcnic_flt_entry bootld_entry; +u32 hi, lo, size; +u64 data; ret =qlcnic_get_flt_entry (adapter,QLCNIC_BOOTLD_REGION , &bootld_entry);
@@ -1200,26 +1244,33 @@ qlcnic_load_firmware(struct qlcnic_adapter *adapter)static int qlcnic_validate_firmware (struct qlcnic_adapter *adapter) { -u32 val; -u32 ver, bios, min_size; -struct pci_dev *pdev = adapter->pdev;const struct firmware *fw = adapter->fw; +struct pci_dev *pdev = adapter->pdev;u8 fw_type = adapter->ahw->fw_type; +u32 ver, bios, min_size; +const u8 *data; +u32 data_size; +u32 val; + +if (fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) + min_size =QLCNIC_UNI_FW_MIN_SIZE ; +else + min_size =QLCNIC_FW_MIN_SIZE ; + +if (fw->size < min_size) +return -EINVAL ;if (fw_type ==QLCNIC_UNIFIED_ROMIMAGE ) {if (qlcnic_validate_unified_romimage (adapter))return -EINVAL ; - - min_size =QLCNIC_UNI_FW_MIN_SIZE ; }else { - val =le32_to_cpu (*(__le32 *)&fw->data[QLCNIC_FW_MAGIC_OFFSET ]); + val =get_unaligned_le32 (fw->data +QLCNIC_FW_MAGIC_OFFSET );if (val !=QLCNIC_BDINFO_MAGIC )return -EINVAL ; - - min_size =QLCNIC_FW_MIN_SIZE ; } -if (fw->size < min_size) +if (qlcnic_get_bootld_data (adapter, &data) || +qlcnic_get_fw_data (adapter, &data, &data_size))return -EINVAL ; val =qlcnic_get_fw_version (adapter);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1680/1815 ip6mr: do not clone dst in ip6mr_cache_report()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 235b42b5860189eb8c27c36435ad932cae65a734 ]
IPv6 input attaches a non-refcounted (NOREF) dst to skbs under RCU. When an ingress multicast packet misses MFC lookup, ip6mr_cache_unresolved() places the skb onto the unresolved queue, escaping the receive-side RCU grace period.
If the underlying route is deleted and freed, and the MFC queue is later resolved with a wrong parent interface, ip6_mr_forward() invokes ip6mr_cache_report(..., MRT6MSG_WRONGMIF), which executes dst_clone(skb_dst(pkt)) on the freed dst entry, triggering a slab use-after-free.
Report packets queued to mroute6_sk (a raw socket) and netlink notifications do not require an attached dst entry.
Fix this by:
1. Removing dst_clone() in ip6mr_cache_report() and ensuring report skbs do not hold a dst.
2. Dropping skb_dst before queuing unresolved skbs in ip6mr_cache_unresolved(), matching the fact that multicast forwarding resolves outgoing routes anew via ip6_route_output().
--- net/ipv6/ip6mr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/ip6mr.c +2 -1
@@ -1162,10 +1162,10 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, msg->im6_src =ipv6_hdr (pkt)->saddr; msg->im6_dst =ipv6_hdr (pkt)->daddr; -skb_dst_set (skb,dst_clone (skb_dst (pkt))); skb->ip_summed =CHECKSUM_UNNECESSARY ; } +skb_dst_drop (skb);mrt6msg_netlink_event (mrt, skb);/* Deliver to user space multicast routing algorithms */
@@ -1246,6 +1246,7 @@ static int ip6mr_cache_unresolved(struct mr_table *mrt, mifi_t mifi, skb->skb_iif = dev->ifindex; } +skb_dst_drop (skb);skb_queue_tail (&c->_c.mfc_un.unres.unresolved, skb);spin_unlock_bh (&mfc_unres_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1681/1815 inetpeer: randomize RB-tree node comparison using SipHash
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 2ee66e9487172fcd189bc52a767c30dad7141c09 ]
The inetpeer rate limiting system stores peer entries in a Red-Black tree keyed deterministically on the remote IP address. Because tree lookups walk the RB-tree using standard lexicographical comparisons (inetpeer_addr_cmp), an off-path adversary can predict the exact topology of the tree and the sequence of nodes traversed during lookups (the gc_stack candidate list).
By combining deterministic tree traversal with aggressive garbage collection (triggered when tree size exceeds inet_peer_threshold), an attacker can selectively force the eviction of targeted inet_peer nodes. When an evicted node is subsequently re-created upon receiving a new packet, its rate-limiting token bucket (rate_tokens, rate_last) is reset to full capacity. This creates a side-channel primitive allowing off-path attackers to bypass IP-keyed ICMP rate limits and infer open UDP ports (similar to SAD DNS style attacks).
Mitigate this by randomizing the RB-tree node comparison logic using SipHash with a secret key (inetpeer_hash_key) initialized via net_get_random_once(). Nodes are ordered in the tree by SipHash(addr, key) rather than raw IP addresses. Because the secret key is unknown to external entities, the tree layout and lookup traversal paths are unpredictable to off-path adversaries, breaking the deterministic eviction gadget.
Cache the computed 64-bit SipHash (hash) in struct inet_peer and compute the target hash (dhash) once at the beginning of inet_getpeer() to avoid recomputing SipHash at every step of the RB-tree walk.
--- include/net/inetpeer.h | 4 ++++ net/ipv4/inetpeer.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-)
include/net/inetpeer.h +4 -0
@@ -35,6 +35,7 @@ struct inetpeer_addr {struct inet_peer {struct rb_node rb_node; +u64 hash;struct inetpeer_addr daddr;u32 metrics[RTAX_MAX ];
@@ -125,6 +126,9 @@ static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, {int i, n; +if (a->family != b->family) +return a->family < b->family ?-1 :1 ; +if (a->family ==AF_INET ) n =sizeof (a->a4) /sizeof (u32);else
net/ipv4/inetpeer.c +35 -3
@@ -21,6 +21,7 @@#include <net/ip.h> #include <net/inetpeer.h> #include <net/secure_seq.h> +#include <linux/siphash.h> /* * Theory of operations.
@@ -52,6 +53,34 @@*/ static struct kmem_cache *peer_cachep__ro_after_init ; +static siphash_aligned_key_t inetpeer_hash_key__read_mostly ; + +static u64 inetpeer_addr_hash (const struct inetpeer_addr *a) +{ +net_get_random_once (&inetpeer_hash_key,sizeof (inetpeer_hash_key)); + +if (a->family ==AF_INET ) +return siphash_2u32 ((__force u32 )a->a4.addr, a->a4.vif, + &inetpeer_hash_key); + +return siphash_4u32 ((__force u32 )a->a6.s6_addr32[0 ], + (__force u32 )a->a6.s6_addr32[1 ], + (__force u32 )a->a6.s6_addr32[2 ], + (__force u32 )a->a6.s6_addr32[3 ], + &inetpeer_hash_key); +} + +static int inetpeer_entry_cmp (u64 dhash, +const struct inetpeer_addr *daddr, +const struct inet_peer *p) +{ +if (dhash < p->hash) +return -1 ; +if (dhash > p->hash) +return 1 ; + +return inetpeer_addr_cmp (daddr, &p->daddr); +}void inet_peer_base_init (struct inet_peer_base *bp) {
@@ -84,6 +113,7 @@ void __init inet_initpeers(void)/* Called with rcu_read_lock() or base->lock held */ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, + u64 dhash, struct inet_peer_base *base, unsigned int seq, struct inet_peer *gc_stack[],
@@ -105,7 +135,7 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr,break ; parent = next; p = rb_entry(parent, struct inet_peer, rb_node); - cmp =inetpeer_addr_cmp (daddr, &p->daddr); + cmp =inetpeer_entry_cmp (dhash, daddr, p);if (cmp ==0 ) { now = jiffies;if (READ_ONCE (p->dtime) != now)
@@ -170,6 +200,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, const struct inetpeer_addr *daddr) {struct inet_peer *p, *gc_stack[PEER_MAX_GC ]; +u64 dhash =inetpeer_addr_hash (daddr);struct rb_node **pp, *parent;unsigned int gc_cnt, seq;
@@ -177,7 +208,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base,* Because of a concurrent writer, we might not find an existing entry. */ seq =read_seqbegin (&base->lock); - p =lookup (daddr, base, seq,NULL , &gc_cnt, &parent, &pp); + p =lookup (daddr, dhash, base, seq,NULL , &gc_cnt, &parent, &pp);/* Make sure tree was not modified during our lookup. */ if (p && !read_seqretry (&base->lock, seq))
@@ -190,11 +221,12 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base,write_seqlock_bh (&base->lock); gc_cnt =0 ; - p =lookup (daddr, base, seq, gc_stack, &gc_cnt, &parent, &pp); + p =lookup (daddr, dhash, base, seq, gc_stack, &gc_cnt, &parent, &pp);if (!p) { p =kmem_cache_alloc (peer_cachep,GFP_ATOMIC );if (p) { p->daddr = *daddr; + p->hash = dhash; p->dtime = (__u32 )jiffies;refcount_set (&p->refcnt,1 );atomic_set (&p->rid,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1682/1815 net: tcp: block mixing readable and unreadable frags
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mina Almasry <[email protected]>
[ Upstream commit d9c56501c72fdac937e8b770f31655c46832f1a5 ]
Protect tcp_sendmsg_locked() from mistakenly mixing readable and unreadable page fragments in the same SKB.
Check that the devmem binding matches the existing SKB's readability. If a mismatch is detected, avoid collapsing and create a new segment.
--- net/ipv4/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp.c +2 -1
@@ -1240,7 +1240,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)trace_tcp_sendmsg_locked (sk, msg, skb, size_goal); -if (copy <=0 || !tcp_skb_can_collapse_to (skb)) { +if (copy <=0 || !tcp_skb_can_collapse_to (skb) || +unlikely (skb_frags_readable (skb) != !binding)) {bool first_skb; new_segment:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1683/1815 net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 4c660ee8c809637909f4f7eb1017f7b9401c75c4 ]
gred_enqueue(), bfifo_enqueue() and plug_enqueue() admit a packet when the current backlog plus the packet length fits within the queue limit:
sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit (gred default VQ) gred_backlog+qdisc_pkt_len(skb) <= q->limit (gred configured VQ) sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit (bfifo)
sch->qstats.backlog + skb->len <= q->limit (plug)
sch->qstats.backlog and q->backlog are u32, and qdisc_pkt_len()/skb->len are unsigned int, so all sums are computed in 32 bits and wrap at 2^32. Once the true backlog exceeds 4 GiB the wrapped sum becomes small and admission keeps succeeding, so the queue grows without bound and the kernel can be driven to OOM.
Promote the sums to u64 so admission stops once the true backlog exceeds the limit. The limit is u32, so the bounded queue stays below 2^32 and the stored u32 backlog never wraps.
The bug can only be reproduced as root (albeit with ridiculous setup):
attach a gred (or bfifo/plug) qdisc with a limit near 4 GiB, leaving the default VQ unconfigured (for gred), and drive >4 GiB of queued traffic (e.g. via a size table / stab to inflate qdisc_pkt_len, or sustained high-rate traffic). The u32 backlog+len sum wraps at 2^32, admission keeps succeeding, and the queue grows unboundedly to OOM.
--- net/sched/sch_fifo.c | 2 +- net/sched/sch_gred.c | 4 ++-- net/sched/sch_plug.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
net/sched/sch_fifo.c +1 -1
@@ -19,7 +19,7 @@static int bfifo_enqueue (struct sk_buff *skb,struct Qdisc *sch,struct sk_buff **to_free) { -if (likely (sch->qstats.backlog +qdisc_pkt_len (skb) <= +if (likely ((u64 )sch->qstats.backlog +qdisc_pkt_len (skb) <=READ_ONCE (sch->limit)))return qdisc_enqueue_tail (skb, sch);
net/sched/sch_gred.c +2 -2
@@ -179,7 +179,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,* if no default DP has been configured. This * allows for DP flows to be left untouched. */ -if (likely (sch->qstats.backlog +qdisc_pkt_len (skb) <= +if (likely ((u64 )sch->qstats.backlog +qdisc_pkt_len (skb) <= sch->limit))return qdisc_enqueue_tail (skb, sch);else
@@ -244,7 +244,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,break ; } -if (gred_backlog (t, q, sch) +qdisc_pkt_len (skb) <= q->limit) { +if ((u64 )gred_backlog (t, q, sch) +qdisc_pkt_len (skb) <= q->limit) { q->backlog +=qdisc_pkt_len (skb);return qdisc_enqueue_tail (skb, sch); }
net/sched/sch_plug.c +1 -1
@@ -89,7 +89,7 @@ static int plug_enqueue(struct sk_buff *skb, struct Qdisc *sch, {struct plug_sched_data *q =qdisc_priv (sch); -if (likely (sch->qstats.backlog + skb->len <= q->limit)) { +if (likely ((u64 )sch->qstats.backlog + skb->len <= q->limit)) {if (!q->unplug_indefinite) q->pkts_current_epoch++;return qdisc_enqueue_tail (skb, sch);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1684/1815 powercap: intel_rapl: Sign-extend the PMU delta on counter wraparound
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li, Yifan <[email protected]>
[ Upstream commit a8b842366f8ff469fe0fc700ba53770ded847ea9 ]
The RAPL PMU misreports energy when the hardware energy counter overflows and wraps back to zero. perf event counts are defined to increase monotonically, but a single wraparound makes the PMU event count jump backwards by nearly the full counter range, and consumers that take the difference of two reads in unsigned arithmetic then underflow and report an absurd value.
On a Panther Lake system (energy unit 61.035 uJ, counter range 262144 J) the package counter wraps every ~2.9 hours at 25 W, and turbostat prints one bogus sample per wraparound, per domain:
PkgTmp PkgWatt CorWatt GFXWatt RAMWatt SysWatt 44 24.97 16.30 3.90 1.87 2145386370.35 43 2145240612.10 16.13 4.02 1.91 40.46
The RAPL energy counters are 32-bit wide on every register interface:
MSR, MMIO and TPMI all describe ENERGY_COUNTER with a GENMASK(31, 0) mask. rapl_read_data_raw() applies that mask, so event_read_counter() returns the counter zero-extended in a u64.
rapl_event_update() then computes
delta = new_raw_count - prev_raw_count;
without reducing the result modulo 2^32. While the counter does not wrap this is correct, but once the hardware counter wraps, new_raw_count < prev_raw_count and delta becomes (true_delta - 2^32), a large negative value. Declaring delta as s64 only makes that value representable; it does not correct it. That bogus delta is scaled and added to event->count, which is where the backwards jump comes from.
Fix it the way arch/x86/events/rapl.c has done since the RAPL PMU was first introduced: shift both values up so that the 64-bit subtraction reduces modulo 2^32, then shift the difference back down with an arithmetic shift to sign-extend it.
This is correct as long as at most one wraparound happens between two updates, which the existing overflow hrtimer already guarantees: its period is half of the counter range at the 200 W reference used in rapl_package_add_pmu_locked().
The problem has been present since the powercap RAPL PMU was added, but only affected TPMI RAPL until commit 748d6ba43afd ("powercap:intel_rapl: Enable MSR-based RAPL PMU support") routed MSR RAPL through the same PMU, which exposed it on client platforms such as Panther Lake.
--- drivers/powercap/intel_rapl_common.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/powercap/intel_rapl_common.c +10 -1
@@ -32,6 +32,9 @@#define ENERGY_STATUS_MASK GENMASK(31, 0) +/* Width of the RAPL energy counters, see the *_ENERGY_STATUS_MASK defines */ +#define RAPL_CNTR_WIDTH 32 +#define POWER_UNIT_OFFSET 0x00#define POWER_UNIT_MASK GENMASK(3, 0)
@@ -1227,6 +1230,7 @@ static u64 rapl_event_update(struct perf_event *event)struct rapl_package_pmu_data *data =event_to_pmu_data (event);u64 prev_raw_count, new_raw_count;s64 delta, sdelta; +int shift =64 -RAPL_CNTR_WIDTH ;/* * Follow the generic code to drain hwc->prev_count.
@@ -1243,8 +1247,13 @@ static u64 rapl_event_update(struct perf_event *event)* Now we have the new raw value and have updated the prev * timestamp already. We can now calculate the elapsed delta * (event-)time and add that to the generic event. +* +* Careful, the counter is narrower than u64 and is not +* sign-extended above its physical width. Shift both values up +* so that the subtraction wraps, then shift the result back down. */ - delta = new_raw_count - prev_raw_count; + delta = (new_raw_count << shift) - (prev_raw_count << shift); + delta >>= shift;/* * Scale delta to smallest unit (2^-32)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1685/1815 net/smc: free stashed qentry before overwrite in REQ_ADD_LINK to ADD_LINK transition
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mahanta Jambigi <[email protected]>
[ Upstream commit 036322025d6e440cb75fc6fecbba9a16b271a2ae ]
When smc_llc_event_handler() transitions the local LLC flow from SMC_LLC_FLOW_REQ_ADD_LINK to SMC_LLC_FLOW_ADD_LINK on arrival of an ADD_LINK request, it calls smc_llc_flow_qentry_set() unconditionally:
if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_REQ_ADD_LINK) {
lgr->llc_flow_lcl.type = SMC_LLC_FLOW_ADD_LINK;
smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry);
...
}A CONFIRM_LINK or ADD_LINK_CONT arriving while flow->type is SMC_LLC_FLOW_REQ_ADD_LINK is stashed into flow->qentry via the SMC_LLC_CONFIRM_LINK / SMC_LLC_ADD_LINK_CONT handler (which stores into flow->qentry for any non-NONE flow type). When the subsequent ADD_LINK arrives, the REQ_ADD_LINK branch overwrites flow->qentry with the new pointer without first freeing the stashed allocation, leaking one kmalloc object.
The stashed entry has no consumer: smc_llc_wait() is only called from llc_add_link_work, which is not yet scheduled while the flow type remains REQ_ADD_LINK. No waiter is sleeping on llc_msg_waiter at this point. It is safe to unconditionally free any stashed qentry before the overwrite.
Call smc_llc_flow_qentry_del() before smc_llc_flow_qentry_set() in the REQ_ADD_LINK branch. smc_llc_flow_qentry_del() already checks flow->qentry before freeing, so the normal path where no entry is stashed is a no-op.
--- net/smc/smc_llc.c | 2 ++ 1 file changed, 2 insertions(+)
net/smc/smc_llc.c +2 -0
@@ -1945,6 +1945,8 @@ static void smc_llc_event_handler(struct smc_llc_qentry *qentry)if (lgr->llc_flow_lcl.type ==SMC_LLC_FLOW_REQ_ADD_LINK ) {/* server started add_link processing */ +/* free any qentry stashed in REQ_ADD_LINK state */ +smc_llc_flow_qentry_del (&lgr->llc_flow_lcl); lgr->llc_flow_lcl.type =SMC_LLC_FLOW_ADD_LINK ;smc_llc_flow_qentry_set (&lgr->llc_flow_lcl, qentry);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1686/1815 net/smc: free pending qentry in smc_llc_flow_stop() before memset
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mahanta Jambigi <[email protected]>
[ Upstream commit 5ee0ceddc7785c6dcf4a8107fef01f0414a354f4 ]
smc_llc_flow_stop() resets a flow struct with a blind memset:
spin_lock_bh(&lgr->llc_flow_lock); memset(flow, 0, sizeof(*flow)); flow->type = SMC_LLC_FLOW_NONE; spin_unlock_bh(&lgr->llc_flow_lock);
If flow->qentry is non-NULL at this point the pointer is overwritten without the allocation being freed, leaking one kmalloc object.
A late-arriving duplicate CONFIRM_LINK or ADD_LINK_CONT message can set flow->qentry after the legitimate message has been consumed by the waiter via smc_llc_flow_qentry_clr() (which NULLs the pointer but leaves flow->type non-zero) but before the flow completes and smc_llc_flow_stop() runs. In that window the duplicate is stashed into flow->qentry, and then lost when smc_llc_flow_stop() zeros the struct.
Call smc_llc_flow_qentry_del() inside the lock before the memset. smc_llc_flow_qentry_del() already checks flow->qentry before freeing, so the normal case where no entry is pending is a no-op.
--- net/smc/smc_llc.c | 1 + 1 file changed, 1 insertion(+)
net/smc/smc_llc.c +1 -0
@@ -341,6 +341,7 @@ int smc_llc_flow_initiate(struct smc_link_group *lgr,void smc_llc_flow_stop (struct smc_link_group *lgr,struct smc_llc_flow *flow) {spin_lock_bh (&lgr->llc_flow_lock); +smc_llc_flow_qentry_del (flow);memset (flow,0 ,sizeof (*flow)); flow->type =SMC_LLC_FLOW_NONE ;spin_unlock_bh (&lgr->llc_flow_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1687/1815 net: bridge: arp/nd proxy: fix reading neigh ha
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Aleksandrov <[email protected]>
[ Upstream commit 57549ab9079122991dfa0f8248ca00e101e8e69b ]
Currently neigh ha address is read directly, but that can result in torn/partial reads if the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address.
--- net/bridge/br_arp_nd_proxy.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
net/bridge/br_arp_nd_proxy.c +14 -10
@@ -195,13 +195,15 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, n =neigh_lookup (&arp_tbl, &tip, vlandev);if (n) {struct net_bridge_fdb_entry *f; +u8 ha[ETH_ALEN ]__aligned(2) ;if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_release (n);return ; } - f =br_fdb_find_rcu (br, n->ha, vid); +neigh_ha_snapshot (ha, n, n->dev); + f =br_fdb_find_rcu (br, ha, vid);if (f) {const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;
@@ -211,10 +213,10 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, br_is_neigh_suppress_enabled(dst, vid)) {if (!vid)br_arp_send (br, p, skb->dev, sip, tip, - sha, n->ha, sha,0 ,0 ); + sha, ha, sha,0 ,0 );else br_arp_send (br, p, skb->dev, sip, tip, - sha, n->ha, sha, + sha, ha, sha, skb->vlan_proto,skb_vlan_tag_get (skb)); replied = true;
@@ -252,7 +254,7 @@ struct nd_msg *br_is_nd_neigh_msg(const struct sk_buff *skb, struct nd_msg *msg) }static void br_nd_send (struct net_bridge *br,struct net_bridge_port *p, -struct sk_buff *request,struct neighbour *n, +struct sk_buff *request,struct neighbour *n,u8 *ha,__be16 vlan_proto,u16 vlan_tci) {struct net_device *dev = request->dev;
@@ -310,7 +312,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,ipv6_eth_mc_map (&in6addr_linklocal_allnodes,eth_hdr (reply)->h_dest); else ether_addr_copy(eth_hdr(reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -340,7 +342,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited = dad ?0 :1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -369,7 +371,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,__vlan_hwaccel_put_tag (reply, vlan_proto, vlan_tci);netdev_dbg (dev,"nd send dev %s dst %pI6 dst_hw %pM src %pI6 src_hw %pM\n" , - dev->name, &pip6->daddr, daddr, &pip6->saddr, n->ha); + dev->name, &pip6->daddr, daddr, &pip6->saddr, ha);if (p) {dev_queue_xmit (reply);
@@ -472,24 +474,26 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, n =neigh_lookup (&nd_tbl, &msg->target, vlandev);if (n) {struct net_bridge_fdb_entry *f; +u8 ha[ETH_ALEN ]__aligned(2) ;if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_release (n);return ; } - f =br_fdb_find_rcu (br, n->ha, vid); +neigh_ha_snapshot (ha, n, n->dev); + f =br_fdb_find_rcu (br, ha, vid);if (f) {const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;if (br_is_neigh_suppress_enabled (dst, vid)) {if (vid !=0 ) -br_nd_send (br, p, skb, n, +br_nd_send (br, p, skb, n, ha, skb->vlan_proto,skb_vlan_tag_get (skb));else -br_nd_send (br, p, skb, n,0 ,0 ); +br_nd_send (br, p, skb, n, ha,0 ,0 ); replied = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1688/1815 vxlan: fix reading neigh ha
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Aleksandrov <[email protected]>
[ Upstream commit b824059a673b2283e78c7aae2c7d257aad7f0e1d ]
Currently arp/neigh_reduce read neigh ha directly which can lead to partial reads while the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address similar to route_shortcircuit which already does the right thing.
--- drivers/net/vxlan/vxlan_core.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/vxlan/vxlan_core.c +13 -7
@@ -1881,6 +1881,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -1889,8 +1890,10 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } +neigh_ha_snapshot (ha, n, n->dev); +rcu_read_lock (); - f =vxlan_find_mac_tx (vxlan, n->ha, vni); + f =vxlan_find_mac_tx (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -1902,7 +1905,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)rcu_read_unlock (); reply =arp_create (ARPOP_REPLY ,ETH_P_ARP , sip, dev, tip, sha, - n->ha, sha); + ha, sha);neigh_release (n);
@@ -1935,7 +1938,8 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)#if IS_ENABLED (CONFIG_IPV6 )static struct sk_buff *vxlan_na_create (struct sk_buff *request, -struct neighbour *n,bool isrouter) +struct neighbour *n,u8 *ha, +bool isrouter) {struct net_device *dev = request->dev;struct sk_buff *reply;
@@ -1981,7 +1985,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request,/* Ethernet header */ ether_addr_copy (eth_hdr (reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -2010,7 +2014,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited =1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -2051,6 +2055,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -2059,7 +2064,8 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - f =vxlan_find_mac_tx (vxlan, n->ha, vni); +neigh_ha_snapshot (ha, n, n->dev); + f =vxlan_find_mac_tx (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -2068,7 +2074,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - reply =vxlan_na_create (skb, n, + reply =vxlan_na_create (skb, n, ha, !!(f ? f->flags &NTF_ROUTER :0 ));neigh_release (n);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1689/1815 NFSv4.1: zero referring call lists before decoding
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 8fa4804fe62ca4155a2d8fc2789d630376cbf2fc ]
decode_cb_sequence_args() allocates csa_rclists with kmalloc_objs(), so each referring_call_list starts uninitialized. decode_rc_list() assigns rcl_refcalls only when rcl_nrefcalls is nonzero. A valid list with zero referring calls therefore leaves the pointer uninitialized, and nfs4_callback_sequence() later passes stale slab contents to kfree().
Allocate csa_rclists with kzalloc_objs() so every rcl_refcalls member is NULL from the beginning, including valid empty referring call lists.
--- fs/nfs/callback_xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/callback_xdr.c +1 -1
@@ -417,7 +417,7 @@ static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, args->csa_nrclists =ntohl (*p++); args->csa_rclists =NULL ;if (args->csa_nrclists) { - args->csa_rclists =kmalloc_objs (*args->csa_rclists, + args->csa_rclists =kzalloc_objs (*args->csa_rclists, args->csa_nrclists);if (unlikely (args->csa_rclists ==NULL ))return htonl (NFS4ERR_RESOURCE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1690/1815 NFSv4.2: fix LAYOUTSTATS send buffer exhaustion
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit c75ef2137e749f2673f0617cfdaae53b2bb7195a ]
encode_layoutstats_maxsz budgets XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE), i.e. 256 bytes, for the layoutupdate4 body written by the layout driver. The flexfiles record can exceed that.
ff_layout_encode_ff_layoutupdate() emits, per data server, a netaddr4, an nfs_fh4, two ff_io_latency4, an nfstime4 and a bool. A data server whose filehandle is NFS_MAXFHSIZE bytes long already accounts for 132 of those bytes, and the two ff_io_latency4 at 64 bytes each, the nfstime4 and the bool add a further 144, so the body passes 256 bytes before the netaddr4 is encoded at all. encode_layoutstats() additionally writes the deviceid4 and the layoutupdate4 lou_type word, neither of which the macro accounts for.
The filehandle and the address are both chosen by the server, through LAYOUTGET and GETDEVICEINFO, so it can drive the encoder past the end of the send buffer. xdr_reserve_space() returns NULL once that happens, and the two ff_layout_encode_io_latency() calls run with dss_info->mirror->lock held, so a NULL return there leaves the lock permanently held.
Raise PNFS_LAYOUTSTATS_MAXSIZE to 384 so that the record fits inside the reservation.
--- include/linux/nfs_xdr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/nfs_xdr.h +1 -1
@@ -354,7 +354,7 @@ struct nfs4_layoutreturn {struct nfs4_xdr_opaque_data ld_private; }; -#define PNFS_LAYOUTSTATS_MAXSIZE 256 +#define PNFS_LAYOUTSTATS_MAXSIZE 384struct nfs42_layoutstat_args ;struct nfs42_layoutstat_devinfo ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1691/1815 NFSv4/pnfs: key the data server cache on the NFS version
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 13c23c5cb977f66390795437fd3837887ce1fd75 ]
nfs4_pnfs_ds_add() keys the per-net data server cache on the multipath address set alone, and struct nfs4_pnfs_ds records no version. That suffices for the files layout driver, which always connects with version 4, but flexfiles takes its version tuple from GETDEVICEINFO per device, and one address can legitimately serve both NFSv3 and NFSv4.
Two deviceids on one address with different ds_versions[0].version therefore share a single nfs4_pnfs_ds, and whichever mirror connects first pins ds_clp to its own version. The other one is handed that client anyway, so it selects rpc_call_ops for a version the connection does not speak, and the mismatched sequence-slot handling dereferences NULL.
Add the version to the cache key so the two cannot alias, giving each version its own nfs4_pnfs_ds and connection while both mirrors stay usable. Only the major version is compared, since that is what selects rpc_call_ops and rpc_ops; v4.0 and v4.1 keep sharing a client. The files layout driver passes the 4 it already hardcodes at connect time.
--- fs/nfs/filelayout/filelayoutdev.c | 3 ++- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 3 ++- fs/nfs/pnfs.h | 3 ++- fs/nfs/pnfs_nfs.c | 14 +++++++++----- 4 files changed, 15 insertions(+), 8 deletions(-)
fs/nfs/filelayout/filelayoutdev.c +2 -1
@@ -170,7 +170,8 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, goto out_err_free_deviceid; } - dsaddr->ds_list[i] =nfs4_pnfs_ds_add (net, &dsaddrs, gfp_flags); + dsaddr->ds_list[i] =nfs4_pnfs_ds_add (net, &dsaddrs,4 , + gfp_flags);if (!dsaddr->ds_list[i]) goto out_err_drain_dsaddrs;trace_fl_getdevinfo (server, &pdev->dev_id, dsaddr->ds_list[i]->ds_remotestr);
fs/nfs/flexfilelayout/flexfilelayoutdev.c +2 -1
@@ -153,7 +153,8 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, new_ds->ds_versions = ds_versions; new_ds->ds_versions_cnt = version_count; - new_ds->ds =nfs4_pnfs_ds_add (net, &dsaddrs, gfp_flags); + new_ds->ds =nfs4_pnfs_ds_add (net, &dsaddrs, ds_versions[0 ].version, + gfp_flags);if (!new_ds->ds) goto out_err_drain_dsaddrs;
fs/nfs/pnfs.h +2 -1
@@ -63,6 +63,7 @@ struct nfs4_pnfs_ds {const struct net *ds_net;struct nfs_client *ds_clp;refcount_t ds_count; +u32 ds_version;/* cache key, with ds_addrs */ unsigned long ds_state;#define NFS4DS_CONNECTING 0/* ds is establishing connection */ };
@@ -417,7 +418,7 @@ void pnfs_generic_write_commit_done(struct rpc_task *task, void *data);void nfs4_pnfs_ds_put (struct nfs4_pnfs_ds *ds);struct nfs4_pnfs_ds *nfs4_pnfs_ds_add (const struct net *net,struct list_head *dsaddrs, -gfp_t gfp_flags); +u32 version,gfp_t gfp_flags);void nfs4_pnfs_v3_ds_connect_unload (void ); int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds, struct nfs4_deviceid_node *devid, unsigned int timeo,
fs/nfs/pnfs_nfs.c +9 -5
@@ -603,15 +603,17 @@ _same_data_server_addrs_locked(const struct list_head *dsaddrs1, }/* -* Lookup DS by addresses. nfs4_ds_cache_lock is held +* Lookup DS by addresses and NFS version. nfs4_ds_cache_lock is held */ static struct nfs4_pnfs_ds * -_data_server_lookup_locked (const struct nfs_net *nn,const struct list_head *dsaddrs) +_data_server_lookup_locked (const struct nfs_net *nn, +const struct list_head *dsaddrs,u32 version) {struct nfs4_pnfs_ds *ds;list_for_each_entry (ds, &nn->nfs4_data_server_cache, ds_node) -if (_same_data_server_addrs_locked (&ds->ds_addrs, dsaddrs)) +if (ds->ds_version == version && +_same_data_server_addrs_locked (&ds->ds_addrs, dsaddrs))return ds;return NULL ; }
@@ -719,7 +721,8 @@ nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags)* uncached and return cached struct nfs4_pnfs_ds. */ struct nfs4_pnfs_ds * -nfs4_pnfs_ds_add (const struct net *net,struct list_head *dsaddrs,gfp_t gfp_flags) +nfs4_pnfs_ds_add (const struct net *net,struct list_head *dsaddrs,u32 version, +gfp_t gfp_flags) {struct nfs_net *nn =net_generic (net, nfs_net_id);struct nfs4_pnfs_ds *tmp_ds, *ds =NULL ;
@@ -738,7 +741,7 @@ nfs4_pnfs_ds_add(const struct net *net, struct list_head *dsaddrs, gfp_t gfp_fla remotestr =nfs4_pnfs_remotestr (dsaddrs, gfp_flags);spin_lock (&nn->nfs4_data_server_lock); - tmp_ds =_data_server_lookup_locked (nn, dsaddrs); + tmp_ds =_data_server_lookup_locked (nn, dsaddrs, version);if (tmp_ds ==NULL ) {INIT_LIST_HEAD (&ds->ds_addrs);list_splice_init (dsaddrs, &ds->ds_addrs);
@@ -747,6 +750,7 @@ nfs4_pnfs_ds_add(const struct net *net, struct list_head *dsaddrs, gfp_t gfp_flaINIT_LIST_HEAD (&ds->ds_node); ds->ds_net = net; ds->ds_clp =NULL ; + ds->ds_version = version;list_add (&ds->ds_node, &nn->nfs4_data_server_cache);dprintk ("%s add new data server %s\n" , __func__, ds->ds_remotestr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1692/1815 rtc: pcf85363: Add error checking to regmap calls in probe()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmo Chou <[email protected]>
[ Upstream commit 78acddfde75177a27000f076e3e828743e38877e ]
The probe() function ignores errors returned by regmap operations. If an I2C transport error occurs (e.g., -ENXIO), the driver continues probing and may register a non-functional RTC device.
Propagate errors from all unchecked regmap calls in probe() using dev_err_probe().
--- drivers/rtc/rtc-pcf85363.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/rtc/rtc-pcf85363.c +12 -5
@@ -426,8 +426,8 @@ static int pcf85363_probe(struct i2c_client *client) err =pcf85363_load_capacitance (pcf85363, client->dev.of_node);if (err <0 ) -dev_warn (&client->dev,"failed to set xtal load capacitance: %d" , - err); +return dev_err_probe (&client->dev, err, +"failed to set xtal load capacitance\n" ); pcf85363->rtc->ops = &rtc_ops; pcf85363->rtc->range_min =RTC_TIMESTAMP_BEGIN_2000 ;
@@ -436,9 +436,16 @@ static int pcf85363_probe(struct i2c_client *client) wakeup_source =device_property_read_bool (&client->dev,"wakeup-source" );if (client->irq >0 || wakeup_source) { -regmap_write (pcf85363->regmap,CTRL_FLAGS ,0 ); -regmap_update_bits (pcf85363->regmap,CTRL_PIN_IO , -PIN_IO_INTAPM ,PIN_IO_INTA_OUT ); + err =regmap_write (pcf85363->regmap,CTRL_FLAGS ,0 ); +if (err) +return dev_err_probe (&client->dev, err, +"failed to clear flags\n" ); + + err =regmap_update_bits (pcf85363->regmap,CTRL_PIN_IO , +PIN_IO_INTAPM ,PIN_IO_INTA_OUT ); +if (err) +return dev_err_probe (&client->dev, err, +"failed to set interrupt pin mode\n" ); }if (client->irq >0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1693/1815 ASoC: fix unmet dependencies on PPC_BESTCOMM and SND_SOC_AC97_BUS
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Braha <[email protected]>
[ Upstream commit 72cc574aa3791aa4f05d247b4e884cdbd135819a ]
SND_MPC52xx_SOC_PCM030 and SND_MPC52xx_SOC_EFIKA both select SND_SOC_MPC5200_AC97 without ensuring its dependency on PPC_BESTCOMM is met. This causes unmet dependencies such as:
WARNING: unmet direct dependencies detected for SND_SOC_MPC5200_AC97
Depends on [n]: SOUND [=m] && SND [=m] && SND_SOC [=m] && SND_POWERPC_SOC [=m] && PPC_BESTCOMM [=n] Selected by [m]:
- SND_MPC52xx_SOC_PCM030 [=m] && SOUND [=m] && SND [=m] && SND_SOC [=m] && SND_POWERPC_SOC [=m] && PPC_MPC5200_SIMPLE [=y]
In v1, Rosen pointed out that the import of "mpc5200_dma.h" is actually unnecessary, and Arnd suggested that the 'select' of SND_SOC_MPC5200_AC97 be changed to 'depends on'.
This resolves all 3 unmet dependencies.
These unmet dependency bugs were detected by kconfirm, a static analysis tool for Kconfig.
--- sound/soc/fsl/Kconfig | 4 ++-- sound/soc/fsl/efika-audio-fabric.c | 2 -- sound/soc/fsl/pcm030-audio-fabric.c | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-)
sound/soc/fsl/Kconfig +2 -2
@@ -244,7 +244,7 @@ config SND_SOC_MPC5200_AC97 config SND_MPC52xx_SOC_PCM030 tristate "SoC AC97 Audio support for Phytec pcm030 and WM9712" depends on PPC_MPC5200_SIMPLE - select SND_SOC_MPC5200_AC97 + depends on SND_SOC_MPC5200_AC97 select SND_SOC_WM9712 help Say Y if you want to add support for sound on the Phytec pcm030
@@ -253,7 +253,7 @@ config SND_MPC52xx_SOC_PCM030 config SND_MPC52xx_SOC_EFIKA tristate "SoC AC97 Audio support for bbplan Efika and STAC9766" depends on PPC_EFIKA - select SND_SOC_MPC5200_AC97 + depends on SND_SOC_MPC5200_AC97 select SND_SOC_STAC9766 help Say Y if you want to add support for sound on the Efika.
sound/soc/fsl/efika-audio-fabric.c +0 -2
@@ -22,8 +22,6 @@#include <sound/initval.h> #include <sound/soc.h> -#include "mpc5200_dma.h" -#define DRV_NAME "efika-audio-fabric" SND_SOC_DAILINK_DEFS(analog,
sound/soc/fsl/pcm030-audio-fabric.c +0 -2
@@ -13,8 +13,6 @@#include <sound/soc.h> -#include "mpc5200_dma.h" -#define DRV_NAME "pcm030-audio-fabric"struct pcm030_audio_data {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1694/1815 bnxt_en: Fix call to hardware monitoring event handler
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 622d698df4239fef3e0eb51fe59f4198f957f28a ]
The first parameter of hwmon_notify_event() is supposed to be the hardware monitoring device. The bnxt driver calls it with the platform device as first parameter instead. This API break results in undefined behavior and may result in a crash.
Pass the hardware monitoring device as parameter instead to fix the problem.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c +1 -1
@@ -40,7 +40,7 @@ void bnxt_hwmon_notify_event(struct bnxt *bp)return ; } -hwmon_notify_event (&bp->pdev->dev, hwmon_temp, attr,0 ); +hwmon_notify_event (bp->hwmon_dev, hwmon_temp, attr,0 ); }static int bnxt_hwrm_temp_query (struct bnxt *bp,u8 *temp)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1695/1815 bnxt_en: Gate TPH enablement behind BNXT_SUPPORTS_QUEUE_API check
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Walsh <[email protected]>
[ Upstream commit a70859cf31214e546cb73da7142f190138dae9ab ]
In bnxt_request_irq(), pcie_enable_tph() is called unconditionally to enable PCIe TPH when setting up interrupts.
If the NIC hardware or firmware capabilities do not support queue ops, attempting to enable TPH during bnxt_request_irq() is unnecessary.
As a result a flood of "RX queue restart failed: err=-95" messages is seen upon boot.
Older NICs (pre-Thor / BCM57414) do not support TPH or queue management. TPH requires queue management to restart the queue. NICs that support queue management (with updated FW) all support TPH.
Gate the call to pcie_enable_tph() and setting of bp->tph_mode behind BNXT_SUPPORTS_QUEUE_API(bp) to ensure TPH is only initialized on devices capable of supporting queue ops. This prevents a guaranteed -EOPNOTSUPP error from occurring due to NULL operations.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -3
@@ -11923,9 +11923,11 @@ static int bnxt_request_irq(struct bnxt *bp)#endif /* Enable TPH support as part of IRQ request */ - rc =pcie_enable_tph (bp->pdev,PCI_TPH_ST_IV_MODE ); -if (!rc) - bp->tph_mode =PCI_TPH_ST_IV_MODE ; +if (BNXT_SUPPORTS_QUEUE_API (bp)) { + rc =pcie_enable_tph (bp->pdev,PCI_TPH_ST_IV_MODE ); +if (!rc) + bp->tph_mode =PCI_TPH_ST_IV_MODE ; + }for (i =0 , j =0 ; i < bp->cp_nr_rings; i++) {int map_idx =bnxt_cp_num_to_irq_num (bp, i);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1696/1815 ptp: netc: fix period truncation and potential divide-by-zero in PEROUT
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Fang <[email protected]>
[ Upstream commit 777dbc9914b2f003f1d44af80c7a4a395c5961b2 ]
The max_period bound in net_timer_enable_perout() was computed as:
max_period = (u64)NETC_TMR_DEFAULT_FIPER + integral_period;
which exceeds U32_MAX when integral_period > 0 (e.g. 0x100000002 for the default 333333333 Hz clock). A period_ns that passes this check but exceeds U32_MAX is then silently truncated when stored into the u32 struct netc_pp::period field.
A truncated value of zero can reach netc_timer_set_perout_alarm(), where the local u32 period variable would also be 0, causing a divide-by-zero in roundup_u64(delta, period) whenever the stime < min_time branch is taken (which always happens for a start time of {0, 0}).
Additionally, netc_timer_enable_periodic_pulse() and netc_timer_enable_fiper() both compute:
fiper = pp->period - integral_period;
A zero pp->period results in an unsigned wraparound to 0xFFFFFFFD, mis-programming the FIPER hardware register.
Fix all three issues by capping max_period at NETC_TMR_DEFAULT_FIPER (0xFFFFFFFF). This ensures that any period_ns passing the range check fits in a u32 without truncation, so the stored value is always valid and non-zero. The accepted range is reduced by integral_period ns (typically only a few nanoseconds), which is negligible in practice.
--- drivers/ptp/ptp_netc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/ptp/ptp_netc.c +5 -5
@@ -440,7 +440,7 @@ static int net_timer_enable_perout(struct netc_timer *priv, }if (on) { -u64 period_ns, gclk_period, max_period, min_period; +u64 period_ns, gclk_period, min_period;struct timespec64 period, stime;u32 integral_period;int alarm_id;
@@ -450,12 +450,12 @@ static int net_timer_enable_perout(struct netc_timer *priv, period_ns =timespec64_to_ns (&period); integral_period =netc_timer_get_integral_period (priv); - max_period = (u64 )NETC_TMR_DEFAULT_FIPER + integral_period; gclk_period =netc_timer_get_gclk_period (priv); min_period = gclk_period *4 + integral_period; -if (period_ns > max_period || period_ns < min_period) { -dev_err (dev,"The period range is %llu ~ %llu\n" , - min_period, max_period); +if (period_ns >NETC_TMR_DEFAULT_FIPER || + period_ns < min_period) { +dev_err (dev,"The period range is %llu ~ %lu\n" , + min_period,NETC_TMR_DEFAULT_FIPER ); err = -EINVAL ; goto unlock_spinlock; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1697/1815 net/sched: account classifier filter allocations to memcg
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 1beb81947eb486716af80db7a584f9e9fef7e003 ]
Allocations in the tc classifier *_change() paths (filter objects, per-CPU counters, and per-filter aux data) use plain GFP_KERNEL without __GFP_ACCOUNT, allowing unprivileged users to pin kernel memory outside memcg charging. The shared tcf_exts_init_ex() action array allocation in cls_api.c was also uncharged; this patch closes it along with the per-classifier filter-object/percpu/aux allocations that remain unaccounted.
Add GFP_KERNEL_ACCOUNT to:
- the shared tcf_exts_init_ex() action array (cls_api.c), common to every filter of every classifier (32 pointers, 256 bytes);
- the filter-object, per-CPU-counter, and per-filter aux allocations in cls_basic, cls_bpf, cls_cgroup, cls_flow, cls_flower, cls_fw, cls_matchall, cls_route and cls_u32;
- the u32_init_knode() replace-path knode allocation (cls_u32.c), which allocates the same struct tc_u_knode + sel.keys on every replace of an existing knode and was missed by the create-path-only conversion.
Also fix the cls_basic error path: basic_change() inserts fnew into the IDR before allocating the per-CPU counter. If alloc_percpu() fails the errout path kfree'd fnew without idr_remove, leaving a dangling pointer in the IDR. With GFP_KERNEL_ACCOUNT the percpu alloc becomes failable on demand (memcg at memory.max), making the dead path attacker-reachable and burning the handle permanently. Add the idr_remove on the percpu failure path, matching the basic_set_parms failure-path pattern.
Note: [email protected] provided a poc for basic_cls, but it was easy to extend to the other classifiers.
Conditions to recreate the bug:
- CONFIG_NET_SCHED, CONFIG_NET_CLS_* (the classifier being used), CONFIG_NET_CLS_ACT, CONFIG_MEMCG, CONFIG_USER_NS, CONFIG_NET_NS.
- Unprivileged user in a fresh user+network namespace (unshare -Urn), or root with CAP_NET_ADMIN.
- Create a large number of tc filters (e.g. tc filter add dev lo ingress ... <classifier> ...) while watching a memcg-limited cgroup:
system slab grows far faster than memory.current, pinning kernel memory outside memcg charging.
--- net/sched/cls_api.c | 3 ++- net/sched/cls_basic.c | 6 ++++-- net/sched/cls_bpf.c | 6 +++--- net/sched/cls_cgroup.c | 2 +- net/sched/cls_flow.c | 2 +- net/sched/cls_flower.c | 4 ++-- net/sched/cls_fw.c | 4 ++-- net/sched/cls_matchall.c | 4 ++-- net/sched/cls_route.c | 4 ++-- net/sched/cls_u32.c | 11 ++++++----- 10 files changed, 25 insertions(+), 21 deletions(-)
net/sched/cls_api.c +2 -1
@@ -3372,7 +3372,8 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,* This reference might be taken later from tcf_exts_get_net(). */ exts->net = net; - exts->actions = kzalloc_objs(struct tc_action *, TCA_ACT_MAX_PRIO); + exts->actions = kzalloc_objs(struct tc_action *, TCA_ACT_MAX_PRIO, +GFP_KERNEL_ACCOUNT );if (!exts->actions)return -ENOMEM ;#endif
net/sched/cls_basic.c +4 -2
@@ -193,7 +193,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } - fnew =kzalloc_obj (*fnew); + fnew =kzalloc_obj (*fnew,GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
@@ -212,9 +212,11 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,if (err) goto errout; fnew->handle = handle; - fnew->pf = alloc_percpu(struct tc_basic_pcnt); + fnew->pf = alloc_percpu_gfp(struct tc_basic_pcnt, GFP_KERNEL_ACCOUNT);if (!fnew->pf) { err = -ENOMEM ; +if (!fold) +idr_remove (&head->handle_idr, fnew->handle); goto errout; }
net/sched/cls_bpf.c +3 -3
@@ -352,7 +352,7 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)if (bpf_size !=nla_len (tb[TCA_BPF_OPS ]))return -EINVAL ; - bpf_ops =kmemdup (nla_data (tb[TCA_BPF_OPS ]), bpf_size,GFP_KERNEL ); + bpf_ops =kmemdup (nla_data (tb[TCA_BPF_OPS ]), bpf_size,GFP_KERNEL_ACCOUNT );if (bpf_ops ==NULL )return -ENOMEM ;
@@ -403,7 +403,7 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, }if (tb[TCA_BPF_NAME ]) { - name =nla_memdup (tb[TCA_BPF_NAME ],GFP_KERNEL ); + name =nla_memdup (tb[TCA_BPF_NAME ],GFP_KERNEL_ACCOUNT );if (!name) {bpf_prog_put (fp);return -ENOMEM ;
@@ -443,7 +443,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,if (ret <0 )return ret; - prog =kzalloc_obj (*prog); + prog =kzalloc_obj (*prog,GFP_KERNEL_ACCOUNT );if (!prog)return -ENOBUFS ;
net/sched/cls_cgroup.c +1 -1
@@ -95,7 +95,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (head && handle != head->handle)return -ENOENT ; - new =kzalloc_obj (*head); + new =kzalloc_obj (*head,GFP_KERNEL_ACCOUNT );if (!new)return -ENOBUFS ;
net/sched/cls_flow.c +1 -1
@@ -438,7 +438,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,return -EOPNOTSUPP ; } - fnew =kzalloc_obj (*fnew); + fnew =kzalloc_obj (*fnew,GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
net/sched/cls_flower.c +2 -2
@@ -2233,7 +2233,7 @@ static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,struct fl_flow_mask *newmask;int err; - newmask =kzalloc_obj (*newmask); + newmask =kzalloc_obj (*newmask,GFP_KERNEL_ACCOUNT );if (!newmask)return ERR_PTR (-ENOMEM );
@@ -2394,7 +2394,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout_tb; } - fnew =kzalloc_obj (*fnew); + fnew =kzalloc_obj (*fnew,GFP_KERNEL_ACCOUNT );if (!fnew) { err = -ENOBUFS ; goto errout_tb;
net/sched/cls_fw.c +2 -2
@@ -276,7 +276,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,if (f->id != handle && handle)return -EINVAL ; - fnew = kzalloc_obj(struct fw_filter); + fnew = kzalloc_obj(struct fw_filter, GFP_KERNEL_ACCOUNT);if (!fnew)return -ENOBUFS ;
@@ -330,7 +330,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,rcu_assign_pointer (tp->root, head); } - f = kzalloc_obj(struct fw_filter); + f = kzalloc_obj(struct fw_filter, GFP_KERNEL_ACCOUNT);if (f ==NULL )return -ENOBUFS ;
net/sched/cls_matchall.c +2 -2
@@ -189,7 +189,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } - new =kzalloc_obj (*new); + new =kzalloc_obj (*new,GFP_KERNEL_ACCOUNT );if (!new)return -ENOBUFS ;
@@ -201,7 +201,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, handle =1 ; new->handle = handle; new->flags = userflags; - new->pf = alloc_percpu(struct tc_matchall_pcnt); + new->pf = alloc_percpu_gfp(struct tc_matchall_pcnt, GFP_KERNEL_ACCOUNT);if (!new->pf) { err = -ENOMEM ; goto err_alloc_percpu;
net/sched/cls_route.c +2 -2
@@ -455,7 +455,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, h1 =to_hash (nhandle); b =rtnl_dereference (head->table[h1]);if (!b) { - b = kzalloc_obj(struct route4_bucket); + b = kzalloc_obj(struct route4_bucket, GFP_KERNEL_ACCOUNT);if (b ==NULL )return -ENOBUFS ;
@@ -524,7 +524,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; err = -ENOBUFS ; - f = kzalloc_obj(struct route4_filter); + f = kzalloc_obj(struct route4_filter, GFP_KERNEL_ACCOUNT);if (!f) goto errout;
net/sched/cls_u32.c +6 -5
@@ -825,7 +825,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,struct tc_u32_sel *s = &n->sel;struct tc_u_knode *new; - new =kzalloc_flex (*new, sel.keys, s->nkeys); + new =kzalloc_flex (*new, sel.keys, s->nkeys,GFP_KERNEL_ACCOUNT );if (!new)return NULL ;
@@ -1114,15 +1114,16 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, goto erridr; } - n =kzalloc_flex (*n, sel.keys, s->nkeys); + n =kzalloc_flex (*n, sel.keys, s->nkeys,GFP_KERNEL_ACCOUNT );if (n ==NULL ) { err = -ENOBUFS ; goto erridr; }#ifdef CONFIG_CLS_U32_PERF - n->pf =__alloc_percpu (struct_size (n->pf, kcnts, s->nkeys), - __alignof__(struct tc_u32_pcnt )); + n->pf =__alloc_percpu_gfp (struct_size (n->pf, kcnts, s->nkeys), + __alignof__(struct tc_u32_pcnt ), +GFP_KERNEL_ACCOUNT );if (!n->pf) { err = -ENOBUFS ; goto errfree;
@@ -1144,7 +1145,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, goto errout;#ifdef CONFIG_CLS_U32_MARK - n->pcpu_success =alloc_percpu (u32); + n->pcpu_success =alloc_percpu_gfp (u32,GFP_KERNEL_ACCOUNT );if (!n->pcpu_success) { err = -ENOMEM ; goto errout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1698/1815 net: microchip: vcap: use port number instead of netdev name for debugfs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit b7adcc56fd3db4f5ddaf8c01069d26136d61e5c8 ]
sparx5_vcap_init() runs before sparx5_register_netdevs() in probe, and its debugfs setup calls vcap_port_debugfs() for every port using netdev_name(ndev) as the debugfs file name. At that point the netdevs have only been allocated, not registered, so dev->name still holds the "eth%d" template and netdev_name() returns "(unnamed net_device)". Every port tries to create the same file under vcaps/, producing a flood of warnings at boot:
debugfs: '(unnamed net_device)' already exists in 'vcaps'
debugfs: '(unnamed net_device)' already exists in 'vcaps'
...
Add vcap_port_debugfs_portno(), a variant of vcap_port_debugfs() that takes the port's stable hardware port number and uses "p%u" as the debugfs file name instead of netdev_name(ndev). This makes the file name independent of registration order; the file still stores and later dereferences the netdev itself, same as before. sparx5 already reports the same "p%d" string via ndo_get_phys_port_name(), so the debugfs name now matches that.
Only sparx5 (and lan969x, which shares this code) is switched to the new function. lan966x keeps calling vcap_port_debugfs() unchanged, so this fix does not rename any of its existing debugfs files.
--- .../microchip/sparx5/sparx5_vcap_impl.c | 5 +++-- .../microchip/vcap/vcap_api_debugfs.c | 21 +++++++++++++++++++ .../microchip/vcap/vcap_api_debugfs.h | 14 +++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c +3 -2
@@ -2077,8 +2077,9 @@ int sparx5_vcap_init(struct sparx5 *sparx5) dir =vcap_debugfs (sparx5->dev, sparx5->debugfs_root, ctrl);for (idx =0 ; idx < consts->n_ports; ++idx)if (sparx5->ports[idx]) -vcap_port_debugfs (sparx5->dev, dir, ctrl, - sparx5->ports[idx]->ndev); +vcap_port_debugfs_portno (sparx5->dev, dir, ctrl, + sparx5->ports[idx]->ndev, + sparx5->ports[idx]->portno);return err; }
drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +21 -0
@@ -400,6 +400,27 @@ void vcap_port_debugfs(struct device *dev, struct dentry *parent, }EXPORT_SYMBOL_GPL (vcap_port_debugfs); +void vcap_port_debugfs_portno (struct device *dev, +struct dentry *parent, +struct vcap_control *vctrl, +struct net_device *ndev, +unsigned int portno) +{ +struct vcap_port_debugfs_info *info; +char name[16 ]; + + info =devm_kzalloc (dev,sizeof (*info),GFP_KERNEL ); +if (!info) +return ; + + info->vctrl = vctrl; + info->ndev = ndev; + +snprintf (name,sizeof (name),"p%u" , portno); +debugfs_create_file (name,0444 , parent, info, &vcap_port_debugfs_fops); +} +EXPORT_SYMBOL_GPL (vcap_port_debugfs_portno); +/* Show the full VCAP instance data (rules with all fields) */ static int vcap_debugfs_show (struct seq_file *m,void *unused) {
drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.h +14 -0
@@ -18,6 +18,12 @@ void vcap_port_debugfs(struct device *dev, struct dentry *parent,struct vcap_control *vctrl, struct net_device *ndev); +void vcap_port_debugfs_portno (struct device *dev, +struct dentry *parent, +struct vcap_control *vctrl, +struct net_device *ndev, +unsigned int portno); +/* Create a debugFS entry for a vcap instance */ struct dentry *vcap_debugfs (struct device *dev,struct dentry *parent,struct vcap_control *vctrl);
@@ -30,6 +36,14 @@ static inline void vcap_port_debugfs(struct device *dev, struct dentry *parent, { } +static inline void vcap_port_debugfs_portno (struct device *dev, +struct dentry *parent, +struct vcap_control *vctrl, +struct net_device *ndev, +unsigned int portno) +{ +} +static inline struct dentry *vcap_debugfs (struct device *dev,struct dentry *parent,struct vcap_control *vctrl)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1699/1815 net: sparx5: fix sleep in atomic context in MAC table access
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit b62793a7baeea9cf20209c9fd2e333311aaf3b8d ]
sparx5_set_rx_mode() runs with netif_addr_lock_bh held and iterates dev->mc via __dev_mc_sync(), which per address calls sparx5_mc_sync() / sparx5_mc_unsync() -> sparx5_mact_learn() / sparx5_mact_forget(). These take sparx5->lock, a mutex, and then poll the MAC access command register with readx_poll_timeout(). A mutex may block, which is not allowed from atomic context.
Convert the driver to the new .ndo_set_rx_mode_async callback introduced in commit 3554b4345d85 ("net: introduce ndo_set_rx_mode_async and netdev_rx_mode_work"). The async callback is invoked from process context, so the mutex and sleeping completion poll can remain.
Observed with CONFIG_PROVE_LOCKING, CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_MUTEXES and CONFIG_DEBUG_ATOMIC_SLEEP enabled:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:591 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 217, name: ip preempt_count: 201, expected: 0 Call trace: __might_resched+0x144/0x248 __might_sleep+0x48/0x7c __mutex_lock+0x74/0x850 mutex_lock_nested+0x24/0x30 sparx5_mact_learn+0x78/0x100 sparx5_mc_sync+0x40/0x54 __hw_addr_sync_dev+0xc4/0x170 sparx5_set_rx_mode+0x4c/0x58 __dev_set_rx_mode+0x64/0xa4 __dev_open+0x1ec/0x26c
--- drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +8 -3
@@ -162,13 +162,18 @@ static int sparx5_port_stop(struct net_device *ndev)return 0 ; } -static void sparx5_set_rx_mode (struct net_device *dev) +static int sparx5_set_rx_mode (struct net_device *dev, +struct netdev_hw_addr_list *uc, +struct netdev_hw_addr_list *mc) {struct sparx5_port *port =netdev_priv (dev);struct sparx5 *sparx5 = port->sparx5;if (!test_bit (port->portno, sparx5->bridge_mask)) -__dev_mc_sync (dev, sparx5_mc_sync, sparx5_mc_unsync); +return __hw_addr_sync_dev (mc, dev, sparx5_mc_sync, + sparx5_mc_unsync); + +return 0 ; } static int sparx5_port_get_phys_port_name(struct net_device *dev,
@@ -249,7 +254,7 @@ static const struct net_device_ops sparx5_port_netdev_ops = { .ndo_open = sparx5_port_open, .ndo_stop = sparx5_port_stop, .ndo_start_xmit = sparx5_port_xmit_impl, - .ndo_set_rx_mode = sparx5_set_rx_mode, + .ndo_set_rx_mode_async = sparx5_set_rx_mode, .ndo_get_phys_port_name = sparx5_port_get_phys_port_name, .ndo_set_mac_address = sparx5_set_mac_address, .ndo_validate_addr = eth_validate_addr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1700/1815 net: txgbe: fix MISC interrupt unmasking in non-MSI-X mode and device shutdown
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiawen Wu <[email protected]>
[ Upstream commit 7bf29145d7a9564162c6b18f8d23760e141e2d15 ]
In txgbe_misc_irq_thread_fn(), the driver unmasks the miscellaneous interrupt at the end of the handler using TXGBE_INTR_MISC(wx) (which resolves to BIT(wx->num_q_vectors)). While this is correct for MSI-X mode, it is incorrect for legacy INTx or single MSI modes.
Due to hardware behavior, the WX_PX_MISC_IVAR register is completely ignored by the hardware when MSI-X is disabled. In non-MSI-X mode, the hardware forcibly merges all interrupt causes (both Queue and MISC) into a single bit: BIT(0) of the interrupt register.
Unconditionally unmasking TXGBE_INTR_MISC(wx) (e.g., BIT(1)) in non-MSI-X mode means the actual MISC interrupt bit (BIT(0)) is not unmasked promptly at the end of the MISC thread. Instead, it remains masked until NAPI completes its polling and unmasks the shared BIT(0). This delays the assertion of subsequent MISC interrupts, preventing timely handling of events like link state changes.
Fix this by explicitly checking pdev->msix_enabled and falling back to BIT(0) as the interrupt mask for the MISC cause when MSI-X is disabled.
Additionally, unconditionally unmasking the interrupt at the end of the thread introduces a race condition during device teardown. Guarding the wx_intr_enable() call with a check for the WX_STATE_DOWN bit, to prevent re-arming the interrupt during device shutdown.
--- drivers/net/ethernet/wangxun/txgbe/txgbe_irq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/wangxun/txgbe/txgbe_irq.c +4 -1
@@ -164,6 +164,7 @@ static irqreturn_t txgbe_misc_irq_thread_fn(int irq, void *data)struct wx *wx = txgbe->wx;unsigned int nhandled =0 ;unsigned int sub_irq; +u64 misc_mask;u32 eicr; eicr = txgbe->eicr;
@@ -183,7 +184,9 @@ static irqreturn_t txgbe_misc_irq_thread_fn(int irq, void *data) nhandled++; } -wx_intr_enable (wx,TXGBE_INTR_MISC (wx)); + misc_mask = wx->pdev->msix_enabled ?TXGBE_INTR_MISC (wx) :BIT (0 ); +if (!test_bit (WX_STATE_DOWN , wx->state)) +wx_intr_enable (wx, misc_mask);return (nhandled >0 ?IRQ_HANDLED :IRQ_NONE ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1701/1815 net: libwx: fix concurrent bitmap overwrite in PTP setup
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiawen Wu <[email protected]>
[ Upstream commit f05516dd7b865666ea7d67e90d0edb588ae9ad18 ]
In wx_ptp_set_timestamp_mode(), the driver copies the global wx->flags bitmap to a local variable, modifies the PTP-related bits, and then writes the entire bitmap back using memcpy().
This Read-Copy-Update pattern is unsafe and introduces a critical race condition. Other asynchronous contexts (such as Tx timeout routines or GPIO IRQ handlers) update individual bits in wx->flags concurrently using atomic bitops like set_bit() or clear_bit(). The memcpy() write-back can silently overwrite and drop these concurrent changes, potentially causing the driver to miss critical module reset or PCIe recovery requests.
Fix this by removing the local bitmap copy. Instead, evaluate the intended PTP flag states locally and apply them directly to wx->flags using atomic set_bit() and clear_bit() operations only after the hardware is successfully configured.
--- drivers/net/ethernet/wangxun/libwx/wx_ptp.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/net/ethernet/wangxun/libwx/wx_ptp.c +6 -12
@@ -555,13 +555,11 @@ static int wx_ptp_set_timestamp_mode(struct wx *wx, {u32 tsync_tx_ctl =WX_TSC_1588_CTL_ENABLED ;u32 tsync_rx_ctl =WX_PSR_1588_CTL_ENABLED ; -DECLARE_BITMAP (flags,WX_PF_FLAGS_NBITS );u32 tsync_rx_mtrl =PTP_EV_PORT <<16 ; +bool rx_tstamp = false;bool is_l2 = false;u32 regval; -memcpy (flags, wx->flags,sizeof (wx->flags)); -switch (config->tx_type) {case HWTSTAMP_TX_OFF : tsync_tx_ctl =0 ;
@@ -576,20 +574,16 @@ static int wx_ptp_set_timestamp_mode(struct wx *wx,case HWTSTAMP_FILTER_NONE : tsync_rx_ctl =0 ; tsync_rx_mtrl =0 ; -clear_bit (WX_FLAG_RX_HWTSTAMP_ENABLED , flags); -clear_bit (WX_FLAG_RX_HWTSTAMP_IN_REGISTER , flags);break ;case HWTSTAMP_FILTER_PTP_V1_L4_SYNC : tsync_rx_ctl |=WX_PSR_1588_CTL_TYPE_L4_V1 ; tsync_rx_mtrl |=WX_PSR_1588_MSG_V1_SYNC ; -set_bit (WX_FLAG_RX_HWTSTAMP_ENABLED , flags); -set_bit (WX_FLAG_RX_HWTSTAMP_IN_REGISTER , flags); + rx_tstamp = true;break ;case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ : tsync_rx_ctl |=WX_PSR_1588_CTL_TYPE_L4_V1 ; tsync_rx_mtrl |=WX_PSR_1588_MSG_V1_DELAY_REQ ; -set_bit (WX_FLAG_RX_HWTSTAMP_ENABLED , flags); -set_bit (WX_FLAG_RX_HWTSTAMP_IN_REGISTER , flags); + rx_tstamp = true;break ;case HWTSTAMP_FILTER_PTP_V2_EVENT :case HWTSTAMP_FILTER_PTP_V2_L2_EVENT :
@@ -602,9 +596,8 @@ static int wx_ptp_set_timestamp_mode(struct wx *wx,case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ : tsync_rx_ctl |=WX_PSR_1588_CTL_TYPE_EVENT_V2 ; is_l2 = true; + rx_tstamp = true; config->rx_filter =HWTSTAMP_FILTER_PTP_V2_EVENT ; -set_bit (WX_FLAG_RX_HWTSTAMP_ENABLED , flags); -set_bit (WX_FLAG_RX_HWTSTAMP_IN_REGISTER , flags);break ;default :/* register PSR_1588_MSG must be set in order to do V1 packets,
@@ -643,7 +636,8 @@ static int wx_ptp_set_timestamp_mode(struct wx *wx,WX_WRITE_FLUSH (wx);/* configure adapter flags only when HW is actually configured */ -memcpy (wx->flags, flags,sizeof (wx->flags)); +assign_bit (WX_FLAG_RX_HWTSTAMP_ENABLED , wx->flags, rx_tstamp); +assign_bit (WX_FLAG_RX_HWTSTAMP_IN_REGISTER , wx->flags, rx_tstamp);/* clear TX/RX timestamp state, just to be sure */ wx_ptp_clear_tx_timestamp (wx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1702/1815 net: page_pool: Remove zone/policy GFP flags when allocating XArray entries
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rong Zhang <[email protected]>
[ Upstream commit 039f248a6cc1f4dec895c001de2c600842022e58 ]
Net drivers request GFP flags according to both the current context and the device constraints, but the XArray entry itself is by no mean used by the device. Passing though device constraints to XArray allocation is a bug and will be warned and fixed up by slab, e.g.:
Unexpected gfp: 0x4 (GFP_DMA32). Fixing up to gfp: 0x82820 (GFP_ATOMIC|__GFP_NOWARN|__GFP_NOMEMALLOC). Fix your code!
CPU: 2 UID: 0 PID: 1071629 Comm: kworker/u80:1 Not tainted 7.2.0-rc7+ #1 PREEMPT(lazy)
Hardware name: LENOVO 21Q4/LNVNB161216, BIOS PXCN27WW 10/20/2025
Workqueue: mt76 mt792x_pm_wake_work [mt792x_lib]
Call Trace:
<TASK>
dump_stack_lvl+0x6e/0x90
kmalloc_fix_flags+0x4d/0x6a
refill_objects+0x10a/0x330
__pcs_replace_empty_main+0x292/0x5c0
kmem_cache_alloc_lru_noprof+0x4c2/0x680
? __xas_nomem+0x3a/0x120
__xas_nomem+0x3a/0x120
__xa_alloc+0xd4/0x190
page_pool_dma_map+0xef/0x400
__page_pool_alloc_netmems_slow+0xed/0x480
? lock_release+0x280/0x490
page_pool_alloc_frag_netmem+0xe0/0x3a0
page_pool_alloc_frag+0xe/0x20
mt76_dma_rx_fill_buf+0x1f6/0x580 [mt76]
mt76_dma_rx_reset+0x1cf/0x230 [mt76]
mt792x_wpdma_reset+0x183/0x1b0 [mt792x_lib]
mt792x_wpdma_reinit_cond+0x5e/0xa0 [mt792x_lib]
mt792xe_mcu_drv_pmctrl+0x28/0x60 [mt792x_lib]
mt792x_mcu_drv_pmctrl+0x3e/0x90 [mt792x_lib]
mt792x_pm_wake_work+0x2d/0x1d0 [mt792x_lib]
? process_one_work+0x20e/0x600
process_one_work+0x230/0x600
? process_one_work+0x256/0x600
worker_thread+0x1ec/0x3c0
? rescuer_thread+0x610/0x610
kthread+0xf2/0x130
? kthread_affine_node+0x140/0x140
ret_from_fork+0x2a5/0x380
? kthread_affine_node+0x140/0x140
ret_from_fork_asm+0x11/0x20
</TASK>Currently mt76 and stmmac may allocate page pool pages with GFP_DMA32.
Fix it by removing zone/policy GFP flags when allocating XArray entries. This is inspired by commit 96d578088085 ("iommu/dma: Use the gfp parameter in __iommu_dma_alloc_noncontiguous()").
--- net/core/page_pool.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/page_pool.c +7 -0
@@ -484,6 +484,13 @@ static int page_pool_register_dma_index(struct page_pool *pool,if (unlikely (!PP_DMA_INDEX_BITS )) goto out; +/* +* Drivers request GFP flags according to both the current context and +* the device constraints, but the XArray entry itself is by no mean +* used by the device, so remove zone/policy flags. +*/ + gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_COMP); +if (in_softirq ()) err =xa_alloc (&pool->dma_mapped, &id,netmem_to_page (netmem),PP_DMA_INDEX_LIMIT , gfp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1703/1815 net_sched: sch_fq: fix pacing delay underflow with pacing offload
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 137b8ae233cabe7fc77cce86f5ba33bf1b369e26 ]
When pacing offload is enabled (q->offload_horizon > 0), FQ can dequeue packets early (now < f->time_next_packet).
In this case, the drift calculation (now - f->time_next_packet) underflows to a large unsigned value.
min(len/2, now - f->time_next_packet) then evaluates to len/2, incorrectly halving the pacing delay for the next packet.
Fix this by only applying drift compensation if now > f->time_next_packet.
This bug was triggered when flow_max_rate was set on the qdisc or for non EDT packets (packets with a zero skb->tstamp).
--- net/sched/sch_fq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/sched/sch_fq.c +6 -2
@@ -828,8 +828,12 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch)* f->time_next_packet was set when prior packet was sent, * and current time (@now) can be too late by tens of us. */ -if (f->time_next_packet) - len -=min (len/2 , now - f->time_next_packet); +if (f->time_next_packet) { +s64 drift = now - f->time_next_packet; + +if (drift >0 ) + len -=min_t (u64, len /2 , drift); + } f->time_next_packet = now + len; } out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1704/1815 net: hibmcge: fix page_pool DMA direction mismatch
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jian Shen <[email protected]>
[ Upstream commit 11efd7963dac9b036a7c9a435ab0e621188910e8 ]
The driver memsets the RX buffer page head to zero before submitting it to hardware, then calls dma_sync_single_for_device() with DMA_TO_DEVICE. This sync direction does not match the pool dma_dir which is DMA_FROM_DEVICE, violating the DMA API contract that the sync direction must match the mapping direction.
On swiotlb platforms the mismatch can cause incorrect bounce-buffer behaviour, and CONFIG_DMA_API_DEBUG emits a warning.
Switch the page_pool dma_dir to DMA_BIDIRECTIONAL so that the CPU-to-device memset sync becomes legal.
--- drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c +1 -1
@@ -553,7 +553,7 @@ static int hbg_ring_page_pool_init(struct hbg_priv *priv, struct hbg_ring *ring) .nid = dev_to_node(&priv->pdev->dev), .dev = &priv->pdev->dev, .napi = &ring->napi, - .dma_dir = DMA_FROM_DEVICE, + .dma_dir = DMA_BIDIRECTIONAL, .offset = 0, .max_len = hbg_get_page_size(ring), };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1705/1815 net/sched: sch_cake: fix autorate reconfiguration throttling
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giuseppe Piscitelli <[email protected]>
[ Upstream commit 7cbfb180945ce529608e4d4e24a6d483699fab1e ]
CAKE's autorate-ingress path intends to limit shaper reconfiguration to once per 250 ms, but last_reconfig_time is only checked and never updated. Since the field stays zero, every qualifying capacity-estimate window can call cake_reconfigure(), causing avoidable rate churn and scheduler work under bursty traffic.
Store the current timestamp when autorate actually reconfigures the qdisc so the guard enforces the intended interval.
--- net/sched/sch_cake.c | 1 + 1 file changed, 1 insertion(+)
net/sched/sch_cake.c +1 -0
@@ -1907,6 +1907,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, ktime_add_ms(q->last_reconfig_time, 250))) { q->config->rate_bps = (q->avg_peak_bandwidth *15 ) >>4 ; + q->last_reconfig_time = now;cake_reconfigure (sch); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1706/1815 Drivers: hv: vmbus: Skip VMBus module cleanup for non-nested root partition
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Kelley <[email protected]>
[ Upstream commit cee0d90bceae1dee3bcc70f8d6b2ceb5b87deb42 ]
The VMBus module initialization function, hv_acpi_init(), currently does nothing when running in the root partition and root is not nested in another VM. But the initialization function reports success, so the VMBus module is indeed loaded. VMBus functionality is not actually needed, but the VMBus module must be loaded so that hv_vmbus_exists() can answer correctly. Furthermore, the mshv_root dependency on the VMBus module is needed as described in the commit message for 840b740a35bf ("mshv: Add conditional VMBus dependency").
Loading the VMBus module without actually initializing it causes failures if the module should later be unloaded. The module unload code tries to clean up things that were never initialized, resulting in memory faults and a panic.
Fix this by having VMBus module exit function perform the same check for non-nested root partition, and do nothing in such a case, just like hv_acpi_init().
In the long run, the code that manages the Hyper-V provided SynIC should be refactored to better coordinate the requirements of root partition scenarios and normal VM scenarios, and to hopefully remove the hv_vmbus_exists() dependnecy between mshv_root and VMBus modules. Preventing the current unload failure scenario is an expediency until such a refactoring is done.
--- drivers/hv/vmbus_drv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/hv/vmbus_drv.c +15 -0
@@ -2982,6 +2982,13 @@ static int __init hv_acpi_init(void)return -ENODEV ;if (hv_root_partition () && !hv_nested) +/* +* A non-nested root partition does not need VMBus client +* functionality. However, the mshv_root module may have +* a dependency on the VMBus module as described in +* commit 840b740a35bf. Return success so the module +* loads even though no VMBus initialization is done. +*/ return 0 ;/*
@@ -3030,6 +3037,14 @@ static void __exit vmbus_exit(void) {int cpu; +if (hv_root_partition () && !hv_nested) +/* +* If a non-nested root partition loaded the VMBus module, +* hv_acpi_init() did not do any VMBus initialization. +* There's nothing to clean up, so just return. +*/ +return ; +unregister_syscore (&hv_synic_syscore);hv_remove_kexec_handler ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1707/1815 scsi: qla2xxx: Fix an loop timeout test
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 11e48f5201fd86ffa038809dd9c41144d43ee2e4 ]
This loop timeout with "retries" set to -1, not 0. Fix the test for failure.
--- drivers/scsi/qla2xxx/qla_nx2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_nx2.c +1 -1
@@ -3507,7 +3507,7 @@ qla8044_poll_flash_status_reg(struct scsi_qla_host *vha)msleep (QLA8044_FLASH_STATUS_REG_POLL_DELAY ); } -if (!retries) +if (retries ==-1 ) ret_val =QLA_FUNCTION_FAILED ;return ret_val;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1708/1815 erofs: Fix EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS default logic
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
[ Upstream commit ab74edaeb1ae7c7194e79007e6afdfe788111a3f ]
When NR_CPUS is less than 16, or when SMP is disabled, the default value of 16 is invalid.
While actual configuration picks up a sensible and valid default (NR_CPUS or 1), "make savedefconfig" will still write a line like
CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS=1
to the defconfig file, even if that matches the sensible default.
Avoid needlessly enlarging the defconfig files, and reduce churn for updating them, by specifying valid defaults depending on SMP and NR_CPUS.
While at it, make the prompt depend on SMP, as there is no point in asking the user about the maximum number of decompression streams if there is only one valid answer.
--- fs/erofs/Kconfig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/erofs/Kconfig +5 -3
@@ -132,11 +132,13 @@ config EROFS_FS_ZIP_LZMA Say N if you want to disable LZMA compression support. config EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS - int "EROFS LZMA default maximum decompression streams" + int "EROFS LZMA default maximum decompression streams" if SMP depends on EROFS_FS_ZIP_LZMA range 1 NR_CPUS if SMP range 1 1 if !SMP - default 16 + default 16 if SMP && NR_CPUS >= 16 + default NR_CPUS if SMP + default 1 help By default EROFS allocates one LZMA decompression stream per CPU. Each stream can hold a dictionary of up to 8 MiB taken from the
@@ -144,7 +146,7 @@ config EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS of memory. This caps the default; the lzma_streams module parameter still overrides it. - If unsure, keep the default of 16. + If unsure, keep the suggested default (16 or lower). config EROFS_FS_ZIP_DEFLATE bool "EROFS DEFLATE compressed data support"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1709/1815 fuse: invalidate the correct range after O_APPEND direct write
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
[ Upstream commit 26d7e1f5c407b5859122b5cd47d7ebbf4b4c1cd2 ]
fuse_direct_write_iter() captures pos before generic_write_checks(), which moves ki_pos to EOF for O_APPEND writes:
fuse_direct_write_iter()
{
pos = iocb->ki_pos; /* 0 (user-supplied) */
generic_write_checks(); /* ki_pos -> EOF */
fuse_direct_io(); /* writes at EOF, correct */
invalidate(pos, pos + res); /* [0, res) -- wrong */
}The post-write invalidation targets a stale range instead of the actual written range at EOF.
This can cause data inconsistency when the file size is not page-aligned. The tail page straddling EOF has a valid portion before EOF that concurrent readers can fault back in during the DIO write window:
Tail page (file size X not page-aligned):
page_start X (EOF) page_end
|--- valid data ----|-- stale --|
CPU0 (O_APPEND DIO writer) CPU1 (buffered reader)
-------------------------- ----------------------
invalidate [X, X+len)
tail page evicted
FUSE_WRITE in flight ...
read [page_start, X)
tail page re-faulted [X, page_end) = stale
FUSE_WRITE completes
i_size = X + len
invalidate [0, len) <- WRONG
tail page still cached
read [X, X+len)
hits stale tail page returns old data
Fix by reading pos back from iocb->ki_pos after generic_write_checks(), as generic_file_direct_write() does.
Also fix a typo in the comment ("may have" -> "may have competed").
--- fs/fuse/file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/fuse/file.c +3 -2
@@ -1801,13 +1801,14 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) {struct inode *inode =file_inode (iocb->ki_filp);struct address_space *mapping = inode->i_mapping; -loff_t pos = iocb->ki_pos;ssize_t res;bool exclusive;fuse_dio_lock (iocb, from, &exclusive); res =generic_write_checks (iocb, from);if (res >0 ) { +loff_t pos = iocb->ki_pos; +task_io_account_write (res);if (!is_sync_kiocb (iocb)) { res =fuse_direct_IO (iocb, from);
@@ -1822,7 +1823,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)/* * As in generic_file_direct_write(), invalidate after * write, to invalidate read-ahead cache that may have -* with the write. +* competed with the write. */ invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1710/1815 fuse: use release/acquire for fch->initialized
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit 4ef7c8cc9894fccc7aa5fdaf6b39faa45c58c23e ]
fuse_chan_set_initialized() sets values for the connection state and then sets fch->initialized to true, but lockless readers read fch->initialized and if true, go to read the connection state values, without using any barriers.
There are a few instances where this happens (fuse_uring_cmd() before dispatching register / commit-and-fetch cmds, fuse_dev_do_wriite() for handling notify retrieves, etc).
To make this as simple as possible, use release/acquire semantics for writing/reading fch->initialized. Add the missing read barriers. This is not marked for stable as these are not realistically reachable on a well-behaved server, and buggy/malicious servers who trigger this path fail benignly rather than crash or deadlock the kernel.
Stable-dep-of: 1f59015e9581 ("fuse: Fix the condition to enable over-io-uring")
--- fs/fuse/cuse.c | 3 ++- fs/fuse/dev.c | 14 ++++++-------- fs/fuse/dev_uring.c | 4 +++- 3 files changed, 11 insertions(+), 10 deletions(-)
fs/fuse/cuse.c +2 -1
@@ -530,7 +530,8 @@ static int cuse_channel_open(struct inode *inode, struct file *file)INIT_LIST_HEAD (&cc->list); - cc->fc.chan->initialized =1 ; +/* Pairs with smp_load_acquire() readers of fch->initialized */ +smp_store_release (&cc->fc.chan->initialized,1 ); rc =cuse_send_init (cc);if (rc) {fuse_dev_put (fud);
fs/fuse/dev.c +6 -8
@@ -80,20 +80,17 @@ void fuse_chan_set_initialized(struct fuse_chan *fch, struct fuse_chan_param *pafuse_uring_conn_init (fch); } -/* Make sure stores before this are seen on another CPU */ -smp_wmb (); - fch->initialized =1 ; +/* Pairs with smp_load_acquire() readers of fch->initialized */ +smp_store_release (&fch->initialized,1 );wake_up_all (&fch->blocked_waitq); }static bool fuse_block_alloc (struct fuse_chan *fch,bool for_background) { -if (!fch->initialized) +/* Pairs with smp_store_release() in fuse_chan_set_initialized() */ +if (!smp_load_acquire (&fch->initialized))return true; -/* Pairs with smp_wmb() in fuse_chan_set_initialized() */ -smp_rmb (); -return (for_background && fch->blocked) || (fch->io_uring && fch->connected && !fuse_uring_ready (fch)); }
@@ -1891,7 +1888,8 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,* initialized and connected state */ err = -EINVAL ; -if (!fch->initialized || !fch->connected) +/* Pairs with smp_store_release() in fuse_chan_set_initialized() */ +if (!smp_load_acquire (&fch->initialized) || !fch->connected) goto copy_finish;/* Don't try to move folios (yet) */
fs/fuse/dev_uring.c +3 -1
@@ -1251,8 +1251,10 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)/* * fuse_uring_register() needs the ring to be initialized, * we need to know the max payload size +* +* Pairs with smp_store_release() in fuse_chan_set_initialized() */ -if (!fch->initialized) +if (!smp_load_acquire (&fch->initialized))return -EAGAIN ;switch (cmd_op) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1711/1815 fuse: Fix the condition to enable over-io-uring
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernd Schubert <[email protected]>
[ Upstream commit 1f59015e958174e89be58cc8db16d70a60d17255 ]
The existing condition in fuse_uring_cmd() is there only to avoid disabling io-uring for connections that already run with it, missing was a condition to refuse any IORING_OP_URING_CMD if the connection/channel didn't get enabled because of missing FUSE_INIT reply flag FUSE_OVER_IO_URING. Without the reply flag the barrier in fuse_uring_ready() doesn't work and IO could already be going on and cause deadlock states (at a minimum one between fch->bg_lock and queue->lock).
The change itself is trivial, but brings behavior change, FUSE_OVER_IO_URING has to be set in the FUSE_INIT_REPLY by fuse servers to accept any IORING_OP_URING_CMD. Libfuse does that and the only non-libfuse implementation I found (fractal-fuse) also does it. Qemu patches for fuse-io-uring are not merged yet, as far as I know.
Moved up is the smp_load_acquire(&fch->initialized) check, as a fuse-server implementation might try to setup io-uring before FUSE_INIT is processed and might have gotten -EOPNOTSUPP instead of -EAGAIN.
Also fixed is a stale comment that explains the handling of the FUSE_OVER_IO_URING flag in early RFC versions.
If there should be a report from any library or application we probably need to revert this commit.
--- fs/fuse/dev_uring.c | 31 ++++++++++++++++++------------- fs/fuse/inode.c | 4 ---- 2 files changed, 18 insertions(+), 17 deletions(-)
fs/fuse/dev_uring.c +18 -13
@@ -1237,26 +1237,31 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) } fch = fud->chan; -/* Once a connection has io-uring enabled on it, it can't be disabled */ -if (!enable_uring && !fch->io_uring) { -pr_info_ratelimited ("fuse-io-uring is disabled\n" ); -return -EOPNOTSUPP ; - } - -if (fch->abort_with_err) -return -ECONNABORTED ; -if (!fch->connected) -return -ENOTCONN ; -/* -* fuse_uring_register() needs the ring to be initialized, -* we need to know the max payload size +* The ring is sized from values negotiated by FUSE_INIT * * Pairs with smp_store_release() in fuse_chan_set_initialized() */ if (!smp_load_acquire (&fch->initialized))return -EAGAIN ; +if (fch->abort_with_err) +return -ECONNABORTED ; +if (!fch->connected) +return -ENOTCONN ; + +/* Once a connection has io-uring enabled on it, it can't be disabled */ +if (!enable_uring && !fch->io_uring) { +pr_info_ratelimited ("fuse-io-uring is disabled by module parameter\n" ); +return -EOPNOTSUPP ; + } + +if (!fch->io_uring) { +pr_info_ratelimited ( +"fuse-io-uring not enabled on this connection\n" ); +return -EOPNOTSUPP ; + } +switch (cmd_op) {case FUSE_IO_URING_CMD_REGISTER : err =fuse_uring_register (cmd, issue_flags, fch);
fs/fuse/inode.c +0 -4
@@ -1479,10 +1479,6 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)if (IS_ENABLED (CONFIG_FUSE_PASSTHROUGH )) flags |=FUSE_PASSTHROUGH ; -/* -* This is just an information flag for fuse server. No need to check -* the reply - server is either sending IORING_OP_URING_CMD or not. -*/ if (fuse_uring_enabled ()) flags |=FUSE_OVER_IO_URING ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1712/1815 arm64: ptdump: Make note_page_flush() range aware
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei-Lin Chang <[email protected]>
[ Upstream commit 902caade3cfd60f99bf71b355e7c86344bd831e5 ]
note_page_flush() calls note_page() with addr == 0 and level == -1 to dump the last row of a ptdump. addr == 0 (1 << 64 wrapped around) renders a huge region with enormous size for address spaces with IA bits < 64. For example the stage-2 page tables and the EFI runtime page table.
More importantly, the last region of the address space and everything after the address space up to 1 << 64 are merged into one row of output. If the last region within the address space is valid, it will appear to remain valid up to 1 << 64 with the same attributes.
Currently only the EFI runtime ptdump is affected by this, but KVM will soon fix its stage-2 ptdump by using note_page_flush(). Here is an example of an EFI runtime ptdump (last row):
0x0000008000000000-0x0000000000000000 17179868672G PGD
With this patch:
0x0000008000000000-0x0001000000000000 261632G PGD
To fix this, cache the end address of a ptdump in ptdump_pg_state so note_page_flush() can call the final note_page() with the correct end address.
--- arch/arm64/include/asm/ptdump.h | 2 ++ arch/arm64/mm/ptdump.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
arch/arm64/include/asm/ptdump.h +2 -0
@@ -50,6 +50,8 @@ struct ptdump_pg_state {const struct addr_marker *marker;const struct mm_struct *mm;unsigned long start_address; +/* exclusive end, ULONG_MAX represents an end at 1 << 64 */ +unsigned long end_address;int level;ptval_t current_prot;bool check_wx;
arch/arm64/mm/ptdump.c +13 -1
@@ -278,9 +278,19 @@ void note_page_pgd(struct ptdump_state *pt_st, unsigned long addr, pgd_t pgd)void note_page_flush (struct ptdump_state *pt_st) { + struct ptdump_pg_state *st = container_of(pt_st, struct ptdump_pg_state, ptdump); +unsigned long end = st->end_address;pte_t pte_zero = {0 }; -note_page (pt_st,0 ,-1 ,pte_val (pte_zero)); +/* +* Address spaces that end at 1 << 64 have end_address == ULONG_MAX, +* but note_page() expects the exclusive end. In this case adjust end +* to the wraparound value 0. +*/ +if (end ==ULONG_MAX ) + end =0 ; + +note_page (pt_st, end,-1 ,pte_val (pte_zero)); }void ptdump_walk (struct seq_file *s,struct ptdump_info *info)
@@ -296,6 +306,7 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) .marker = info->markers, .mm = info->mm, .pg_level = &kernel_pg_levels[0], + .end_address = end, .level = -1, .ptdump = { .note_page_pte = note_page_pte,
@@ -337,6 +348,7 @@ bool ptdump_check_wx(void) { -1, NULL}, }, .pg_level = &kernel_pg_levels[0], + .end_address = ~0UL, .level = -1, .check_wx = true, .ptdump = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1713/1815 arm64: process: Fix context switching MTE store-only tag check
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Murzin <[email protected]>
[ Upstream commit b8f070ac3167595069feb1f794c127b805115645 ]
SCTLR_EL1.TCSO0 is set when user opt-in for MTE store-only tag check mode. However, it is not part of SCTLR_USER_MASK which imply that on context switch we never clear SCTLR_EL1.TCSO0, so we are leaking that setting into another task.
Fix that by including SCTLR_EL1_TCSO0_MASK into SCTLR_USER_MASK
--- arch/arm64/include/asm/processor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/processor.h +1 -1
@@ -264,7 +264,7 @@ static inline void task_set_sve_vl_onexec(struct task_struct *task,#define SCTLR_USER_MASK \ (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | \ - SCTLR_EL1_TCF0_MASK) + SCTLR_EL1_TCF0_MASK | SCTLR_EL1_TCSO0_MASK)static inline void arch_thread_struct_whitelist (unsigned long *offset,unsigned long *size)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1714/1815 f2fs: use adjusted write range after f2fs_write_checks()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seongjae Jeong <[email protected]>
[ Upstream commit 3b2c5d35cf4398edf47c4a3ad076838654a30015 ]
generic_write_checks() in f2fs_write_checks() can adjust iocb->ki_pos for append writes and truncate the iterator to limit the number of bytes to write.
In f2fs_file_write_iter(), the pinned-file overwrite check currently uses the position and count saved before f2fs_write_checks(), so it can check a range different from the actual write range.
The forced buffered I/O cleanup also uses orig_pos saved before f2fs_write_checks(). For O_APPEND writes, this can make the cleanup flush and invalidate the wrong page cache range.
Move the pinned-file overwrite check after f2fs_write_checks() and use the adjusted iocb->ki_pos and iov_iter_count(from). Also save the adjusted write position and use it for the forced buffered I/O cleanup.
--- fs/f2fs/file.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
fs/f2fs/file.c +9 -8
@@ -5379,9 +5379,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)bool dio;bool may_need_sync = true;int preallocated; -const loff_t pos = iocb->ki_pos; -const ssize_t count =iov_iter_count (from);ssize_t ret; +loff_t bufio_start_pos;if (unlikely (f2fs_cp_error (F2FS_I_SB (inode)))) { ret = -EIO ;
@@ -5402,15 +5401,17 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)inode_lock (inode); } + ret =f2fs_write_checks (iocb, from); +if (ret <=0 ) + goto out_unlock; +if (f2fs_is_pinned_file (inode) && - !f2fs_overwrite_io (inode, pos, count)) { + !f2fs_overwrite_io (inode, iocb->ki_pos,iov_iter_count (from))) { ret = -EIO ; goto out_unlock; } - ret =f2fs_write_checks (iocb, from); -if (ret <=0 ) - goto out_unlock; + bufio_start_pos = iocb->ki_pos;/* Determine whether we will do a direct write or a buffered write. */ dio =f2fs_should_use_dio (inode, iocb, from);
@@ -5465,8 +5466,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)*/ if (ret >0 && !dio && (iocb->ki_flags &IOCB_DIRECT ))f2fs_flush_buffered_write (iocb->ki_filp->f_mapping, - orig_pos, - orig_pos + ret -1 ); + bufio_start_pos, + bufio_start_pos + ret -1 );return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1715/1815 Bluetooth: L2CAP: access chan->conn safely in get/setsockopt
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit ca2c4c26498643f421d35ffe258fafbd3ed461c3 ]
Since commit b66774b48dd9 ("Bluetooth: L2CAP: Fix UAF in channel timeout by holding conn ref") l2cap_chan::conn has held reference and remains non-NULL also after the corresponding hci_conn is deleted. In this state accessing various
fields eg. hci_conn::hdev is invalid, which leads to KASAN crash in l2cap_sock_setsockopt() access of conn->hcon->hdev.
Check l2cap_chan::conn.hcon corresponds to an alive hci_conn before trying to use it in l2cap_sock.c. Hold l2cap_chan_lock() in getsockopt/setsockopt to ensure it stays alive, and to avoid data races in l2cap_chan fields.
--- net/bluetooth/l2cap_sock.c | 64 ++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-)
net/bluetooth/l2cap_sock.c +48 -16
@@ -436,11 +436,26 @@ static int l2cap_get_mode(struct l2cap_chan *chan)return -EINVAL ; } +static struct l2cap_conn *l2cap_chan_conn (struct l2cap_chan *chan) +{ +lockdep_assert_held (&chan->lock); + +/* l2cap_conn_del() sets FLAG_DEL while holding chan->lock before +* conn->hcon is deleted. If not set and conn is non-NULL, conn->hcon +* remains alive during this chan->lock critical section. +*/ +if (test_bit (FLAG_DEL , &chan->flags)) +return NULL ; + +return chan->conn; +} +static int l2cap_sock_getsockopt_old (struct socket *sock,int optname,sockopt_t *sopt) {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan; +struct l2cap_conn *conn;struct l2cap_options opts;struct l2cap_conninfo cinfo;int err =0 ;
@@ -451,6 +466,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, len = sopt->optlen; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -537,9 +553,15 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,break ; } + conn =l2cap_chan_conn (chan); +if (!conn) { + err = -ENOTCONN ; +break ; + } +memset (&cinfo,0 ,sizeof (cinfo)); - cinfo.hci_handle = chan->conn->hcon->handle; -memcpy (cinfo.dev_class, chan->conn->hcon->dev_class,3 ); + cinfo.hci_handle = conn->hcon->handle; +memcpy (cinfo.dev_class, conn->hcon->dev_class,3 ); len =min (len,sizeof (cinfo));if (copy_to_iter (&cinfo, len, &sopt->iter_out) != len)
@@ -553,6 +575,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, }release_sock (sk); +l2cap_chan_unlock (chan); +return err; }
@@ -561,6 +585,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan; +struct l2cap_conn *conn;struct bt_security sec;struct bt_power pwr;int len, mode, err =0 ;
@@ -578,6 +603,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, len = sopt->optlen; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -589,12 +615,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } + conn =l2cap_chan_conn (chan); +memset (&sec,0 ,sizeof (sec)); -if (chan->conn) { - sec.level = chan->conn->hcon->sec_level; +if (conn) { + sec.level = conn->hcon->sec_level;if (sk->sk_state ==BT_CONNECTED ) - sec.key_size = chan->conn->hcon->enc_key_size; + sec.key_size = conn->hcon->enc_key_size; }else { sec.level = chan->sec_level; }
@@ -678,12 +706,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ;case BT_PHY : -if (sk->sk_state !=BT_CONNECTED ) { + conn =l2cap_chan_conn (chan); + +if (sk->sk_state !=BT_CONNECTED || !conn) { err = -ENOTCONN ;break ; } - opt =hci_conn_get_phy (chan->conn->hcon); + opt =hci_conn_get_phy (conn->hcon);if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) !=sizeof (opt))
@@ -719,6 +749,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
@@ -749,6 +780,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,BT_DBG ("sk %p" , sk); +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -850,6 +882,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
@@ -913,6 +946,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,if (level !=SOL_BLUETOOTH )return -ENOPROTOOPT ; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -938,11 +972,10 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, chan->sec_level = sec.level; -if (!chan->conn) + conn =l2cap_chan_conn (chan); +if (!conn)break ; - conn = chan->conn; -/* change security for LE channels */ if (chan->scid ==L2CAP_CID_ATT ) {if (smp_conn_security (conn->hcon, sec.level)) {
@@ -997,7 +1030,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, }if (opt ==BT_FLUSHABLE_OFF ) { - conn = chan->conn; + conn =l2cap_chan_conn (chan); +/* proceed further only when we have l2cap_conn and No Flush support in the LM */ if (!conn || !lmp_no_flush_capable (conn->hcon->hdev)) {
@@ -1083,7 +1117,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,break ;case BT_PHY : -if (sk->sk_state !=BT_CONNECTED ) { + conn =l2cap_chan_conn (chan); +if (sk->sk_state !=BT_CONNECTED || !conn) { err = -ENOTCONN ;break ; }
@@ -1093,10 +1128,6 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,if (err)break ; -if (!chan->conn) -break ; - - conn = chan->conn; err =hci_conn_set_phy (conn->hcon, phys);break ;
@@ -1139,6 +1170,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1716/1815 Bluetooth: L2CAP: reject accept queue add unless BT_LISTEN
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit d4bfa78fd67929b62b02013c107973e0c5b7aa9a ]
New sk should not be added to parent socket accept queue after last l2cap_sock_cleanup_listen() has run in l2cap_sock_teardown_cb() and state set to BT_CLOSED, as that can result to UAF on dereferencing the dangling parent reference.
l2cap_sock_new_connection_cb() may race with parent l2cap_chan teardown, due to chan->state accessed without consistent locking:
[Task 1] [Task 2]
l2cap_sock_release(parent) l2cap_connect
l2cap_sock_shutdown pchan = l2cap_global_chan_by_psm
l2cap_chan_lock(pchan)
l2cap_chan_close
l2cap_sock_teardown_cb
pchan->state = BT_CLOSED
l2cap_chan_unlock(pchan) ------> l2cap_chan_lock(pchan)
l2cap_new_connection
l2cap_sock_new_connection_cb
l2cap_chan_lock(pchan) <-------- l2cap_chan_unlock(pchan)
l2cap_sock_kill(parent) /* bt_sk(sk)->parent dangling */Fix by adding check for sk_state == BT_LISTEN after acquiring sk lock in l2cap_sock_new_connection_cb(). Add lock_sock() around sk_state writes where missing, to avoid data races.
Although the data races on pchan->state should be fixed too, this defensive sk_state check probably makes sense in any case.
--- net/bluetooth/l2cap_sock.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
net/bluetooth/l2cap_sock.c +13 -0
@@ -1599,6 +1599,11 @@ static int l2cap_sock_new_connection_cb(struct l2cap_chan *chan,lock_sock (parent); +if (parent->sk_state !=BT_LISTEN ) { +release_sock (parent); +return -EINVAL ; + } +/* Check for backlog size */ if (sk_acceptq_is_full (parent)) {BT_DBG ("backlog full %d" , parent->sk_ack_backlog);
@@ -1762,10 +1767,14 @@ static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state,if (!sk)return ; +lock_sock (sk); + sk->sk_state = state;if (err) sk->sk_err = err; + +release_sock (sk); } static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
@@ -1841,6 +1850,8 @@ static void l2cap_sock_resume_cb(struct l2cap_chan *chan)if (!sk)return ; +lock_sock (sk); +if (test_and_clear_bit (FLAG_PENDING_SECURITY , &chan->flags)) { sk->sk_state =BT_CONNECTED ; chan->state =BT_CONNECTED ;
@@ -1848,6 +1859,8 @@ static void l2cap_sock_resume_cb(struct l2cap_chan *chan)clear_bit (BT_SK_SUSPEND , &bt_sk (sk)->flags); sk->sk_state_change (sk); + +release_sock (sk); }static void l2cap_sock_set_shutdown_cb (struct l2cap_chan *chan)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1717/1815 Bluetooth: mgmt: fix hdev->discovery.uuids NULL dereference
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Shpakovskiy <[email protected]>
[ Upstream commit 59eecbe2f2f38d8f3e1104bd11da97f9a2c58998 ]
'uuid_count' member of struct 'discovery_state' is assigned and read without any locks, so there is a chance of situation when uuid_count != 0, but uuids is NULL and there will be NULL pointer dereference.
Possible race:
'hci_update_passive_scan_sync'
'hci_discovery_filter_clear'
hdev->discovery.uuid_count = 0;
<----------------------preempted----------------------------->
'start_service_discovery'
// Set uuid_count to value != 0
hdev->discovery.uuid_count = uuid_count;
hdev->discovery.uuids = kmemdup(...);
<----------------------preempted----------------------------->
spin_lock(&hdev->discovery.lock);
kfree(hdev->discovery.uuids);
hdev->discovery.uuids = NULL;
spin_unlock(&hdev->discovery.lock);Now uuids == NULL and uuid_count != 0.
So 'mgmt_device_found' -> 'is_filter_match' -> 'eir_has_uuids' receives non consistent discovery state, where NULL dereference of uuids happens.
To fix it let's add discovery.lock around every read/write of uuid_count, uuids pair of struct members. It is also important to assign uuid_count value only after success kmemdup() allocation in start_service_discovery(), otherwise uuids is NULL, because kmemdup failed, but uuid_count is already assigned to non zero value.
The following panic happens:
[ ] ------------[ cut here ]------------
[ ] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
[ ] Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP [ ] CPU: 0 PID: 15056 Comm: kworker/u9:2
[ ] Workqueue: hci0 hci_rx_work
[ ] pstate: 10400009 (nzcV daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ ] pc : eir_has_uuids+0x2d8/0x590
[ ] lr : is_filter_match+0x258/0x320
...
[ ] Call trace:
[ ] eir_has_uuids+0x2d8/0x590 [ ] is_filter_match+0x258/0x320 [ ] mgmt_device_found+0x5b0/0xafc [ ] process_adv_report.part.0+0x8c8/0xf14 [ ] hci_le_adv_report_evt+0x338/0x3f0 [ ] hci_le_meta_evt+0x1f0/0x4c8 [ ] hci_event_packet+0x440/0xc9c [ ] hci_rx_work+0x44c/0xaf8 [ ] process_one_work+0x54c/0x103c [ ] worker_thread+0x6c4/0x10c4 [ ] kthread+0x274/0x2ec [ ] ret_from_fork+0x10/0x20
[ ] Code: 14000004 91004021 eb14003f 54000180 (f9400024) [ ] ---[ end trace 0000000000000000 ]---
--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/mgmt.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
@@ -919,9 +919,9 @@ static inline void hci_discovery_filter_clear(struct hci_dev *hdev) hdev->discovery.result_filtering = false; hdev->discovery.report_invalid_rssi = true; hdev->discovery.rssi =HCI_RSSI_INVALID ; - hdev->discovery.uuid_count =0 ;spin_lock (&hdev->discovery.lock); + hdev->discovery.uuid_count =0 ;kfree (hdev->discovery.uuids); hdev->discovery.uuids =NULL ;spin_unlock (&hdev->discovery.lock);
net/bluetooth/mgmt.c +13 -5
@@ -6163,6 +6163,7 @@ static int start_service_discovery(struct sock *sk, struct hci_dev *hdev,struct mgmt_pending_cmd *cmd;const u16 max_uuid_count = ((U16_MAX -sizeof (*cp)) /16 );u16 uuid_count, expected_len; +u8 (*uuids)[16 ] =NULL ;u8 status;int err;
@@ -6239,12 +6240,10 @@ static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, hdev->discovery.result_filtering = true; hdev->discovery.type = cp->type; hdev->discovery.rssi = cp->rssi; - hdev->discovery.uuid_count = uuid_count;if (uuid_count >0 ) { - hdev->discovery.uuids =kmemdup (cp->uuids, uuid_count *16 , -GFP_KERNEL ); -if (!hdev->discovery.uuids) { + uuids =kmemdup (cp->uuids, uuid_count *sizeof (*uuids),GFP_KERNEL ); +if (!uuids) { err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_START_SERVICE_DISCOVERY, MGMT_STATUS_FAILED,
@@ -6254,6 +6253,11 @@ static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, } } +spin_lock (&hdev->discovery.lock); + hdev->discovery.uuids = uuids; + hdev->discovery.uuid_count = uuid_count; +spin_unlock (&hdev->discovery.lock); + err =hci_cmd_sync_queue (hdev, start_discovery_sync, cmd, start_discovery_complete);if (err <0 ) {
@@ -10383,6 +10387,7 @@ static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, !hci_test_quirk(hdev, HCI_QUIRK_STRICT_DUPLICATE_FILTER))))return false; +spin_lock (&hdev->discovery.lock);if (hdev->discovery.uuid_count !=0 ) {/* If a list of UUIDs is provided in filter, results with no * matching UUID should be dropped.
@@ -10391,9 +10396,12 @@ static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, hdev->discovery.uuids) && !eir_has_uuids(scan_rsp, scan_rsp_len, hdev->discovery.uuid_count, - hdev->discovery.uuids)) + hdev->discovery.uuids)) { +spin_unlock (&hdev->discovery.lock);return false; + } } +spin_unlock (&hdev->discovery.lock);/* If duplicate filtering does not report RSSI changes, then restart * scanning to ensure updated result with updated RSSI values.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1718/1815 Bluetooth: L2CAP: fix race l2cap_sock_cleanup_listen() vs. put_chan
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit 66d6ef18548ae6d7dd452b84115fc82c0a73a4ea ]
For L2CAP sockets without owning sk->sk_socket, reading l2cap_pi(sk)->chan may race against concurrent l2cap_sock_kill() -> l2cap_sock_put_chan(). This excludes simultaneous proto_ops callbacks, but access in l2cap_sock_cleanup_listen() has unsafe lockless read.
[Task 1] [Task 2 (hdev->workqueue)]
l2cap_sock_release(parent) l2cap_disconn_cfm
l2cap_sock_cleanup_listen l2cap_conn_del
bt_accept_dequeue l2cap_chan_del
lock_sock(sk) l2cap_sock_teardown_cb
bt_accept_unlink
bt_sk(sk)->parent = NULL
release_sock(sk) ----------------> lock_sock(sk)
parent = /* NULL */
lock_sock(sk) <--------------------- release_sock(sk)
sock_set_flag(sk, SOCK_ZAPPED)
l2cap_sock_close_cb
l2cap_sock_kill(sk)
l2cap_sock_put_chan
chan = READ l2cap_pi(sk)->chan l2cap_pi(sk)->chan = NULL
l2cap_chan_hold_unless_zero l2cap_put_chan(chan)
kref_get_unless_zero(&chan->ref)Task 1 may observe NULL which causes null-ptr-deref.
Fix the race by taking lock_sock() in l2cap_sock_kill() to synchronize with l2cap_sock_cleanup_listen(). hold_unless_zero() is not needed here, l2cap_pi(sk)->chan owns reference if it is non-NULL.
Clarify code comments vs. locking.
--- include/net/bluetooth/l2cap.h | 5 +++++ net/bluetooth/l2cap_sock.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-)
include/net/bluetooth/l2cap.h +5 -0
@@ -699,7 +699,12 @@ struct l2cap_rx_busy {struct l2cap_pinfo {struct bt_sock bt; + +/* With owning sk_socket chan may be read without lock, other access +* should hold lock_sock. +*/ struct l2cap_chan *chan; +struct list_head rx_busy; };
net/bluetooth/l2cap_sock.c +13 -10
@@ -1344,7 +1344,12 @@ static void l2cap_sock_kill(struct sock *sk)BT_DBG ("sk %p state %s" , sk,state_to_string (sk->sk_state)); +/* Take lock to synchronize against access without owning sk->sk_socket, +* eg. in l2cap_sock_cleanup_listen(). proto_ops etc. don't need lock. +*/ +lock_sock (sk);l2cap_sock_put_chan (sk); +release_sock (sk);/* Kill poor orphan */ sock_set_flag (sk,SOCK_DEAD );
@@ -1547,14 +1552,10 @@ static void l2cap_sock_cleanup_listen(struct sock *parent)* establish sk_lock -> conn->lock and invert the established * conn->lock -> chan->lock -> sk_lock order (lockdep deadlock). * -* Instead, briefly take the child sk lock to fetch and pin its chan. -* l2cap_conn_del() reaches the chan free only via -* l2cap_chan_del() -> l2cap_sock_teardown_cb(), which itself takes -* the child sk lock; holding it across l2cap_chan_hold_unless_zero() -* therefore guarantees the chan cannot be freed while we read and -* pin it (hold_unless_zero() additionally skips a chan already past -* its last reference). We then drop the sk lock before taking -* chan->lock, so sk and chan locks are never held together. +* Instead, briefly take the child sk lock to synchronize vs. +* l2cap_sock_kill that puts l2cap_pi(sk)->chan. We then drop the sk +* lock before taking chan->lock, so sk and chan locks are never held +* together. * * Since we cannot call l2cap_chan_close() without conn->lock, * schedule l2cap_chan_timeout to close the channel; it already
@@ -1564,10 +1565,12 @@ static void l2cap_sock_cleanup_listen(struct sock *parent)struct l2cap_chan *chan;lock_sock_nested (sk,L2CAP_NESTING_NORMAL ); - chan =l2cap_chan_hold_unless_zero (l2cap_pi (sk)->chan); + chan =l2cap_pi (sk)->chan; +if (chan) +l2cap_chan_hold (chan);release_sock (sk);if (!chan) { -/* l2cap_conn_del() already tearing this child down */ +/* Already torn down */ sock_put (sk);continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1719/1815 Bluetooth: btmtk: Do not report success when subsys reset fails
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ismail Tarim <[email protected]>
[ Upstream commit 59c3ee19ca88210bfc0e22ce59218091cb1a3c48 ]
btmtk_usb_subsys_reset() validates the subsystem reset by reading the chip id back. When that read succeeds at the bus level but yields an id of zero, the reset has demonstrably not taken effect: the function logs "Can't get device id, subsys reset fail." and then returns the return value of btmtk_usb_id_get(), which in that case is zero, i.e. success.
btusb_mtk_reset() returns that value unchanged, so its caller cannot tell a completed reset from a failed one.
Return -ENODEV when the chip id reads back as zero, leaving the existing MT6639 exemption intact.
Observed on an MT7902 [13d3:3579]. The path can be reached on demand by asking the controller for a coredump, since btmtk requests a reset once the dump completes:
# echo 1 > /sys/class/bluetooth/hci0/device/coredump
Bluetooth: hci0: Mediatek coredump end
Bluetooth: hci0: Can't get device id, subsys reset fail. usb 3-10: reset high-speed USB device number 5 using xhci_hcd usb 3-10: device descriptor read/64, error -110
usb usb3-port10: attempt power cycle
usb usb3-port10: unable to enumerate USB device
The same sequence occurs unprompted when the controller firmware asserts on its own.
Note that this corrects the error reporting only; it does not by itself make the controller recoverable in the case above.
--- drivers/bluetooth/btmtk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bluetooth/btmtk.c +3 -1
@@ -968,8 +968,10 @@ int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id) } err =btmtk_usb_id_get (hdev,0x70010200 , &val); -if (err || (!val && dev_id !=0x6639 )) +if (err || (!val && dev_id !=0x6639 )) {bt_dev_err (hdev,"Can't get device id, subsys reset fail." ); +return err ? err : -ENODEV ; + }return err; }
Signature · 1 line
2.53.0